This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

UCD3138A: Qustion about erasing checksum code posted by TI staff

Part Number: UCD3138A

Dear TI guys:

I saw a different way to erase checksum posted by a TI staff as shows below. I don't understand why there is no need to consider the instruction set switch from ARM to Thumb by using these code.

A way of grantee to avoid this problem is that just copy the size of zero_out_integrity_word from flash to ram.
Here is the steps of implementing this solution:
1. In cyclone.cmd file, add a group section like this:
SECTIONS
{

… …
UNION : run = RAM, RUN_START(_ram_run_start)
{
.zero_out_integrity_word_0 : load = PFLASH,
LOAD_START(_zero_out_integrity_word_start),
LOAD_END(_zero_out_integrity_word_end),
LOAD_SIZE(_zero_out_integrity_word_size)
}
… …
}
2. Clarify those symbols in header file or at the beginning of the source file referenced
extern Uint8 zero_out_integrity_word_start, zero_out_integrity_word_end, zero_out_integrity_word_size;
extern Uint8 ram_run_start;

3. Use a program to allocate the function into the section defined in above.
#pragma CODE_SECTION(zero_out_integrity_word, ".zero_out_integrity_word_0")
void zero_out_integrity_word(void)
{

DecRegs.FLASHILOCK.all = 0x42DC157E;// Write key to Program Flash Interlock Register
DecRegs.MFBALR1.all = MFBALRX_BYTE0_BLOCK_SIZE_32K; //enable program flash write
program_flash_integrity_word = 0;
DecRegs.MFBALR1.all = MFBALRX_BYTE0_BLOCK_SIZE_32K + //expand program flash out to 4x real size
MFBALRX_BYTE0_RONLY;
while(DecRegs.PFLASHCTRL.bit.BUSY != 0)
{
; //do nothing while it programs
}
// interrupt_time = TimerRegs.T24CNTDAT.bit.CNT_DAT - interrupt_time;
SysRegs.SYSECR.bit.RESET = 2; //now reset processor.
return;
}

4. Use memcpy function to copy the code from flash into ram, and then call the function directlly.
case 12: // clear integrity word.
{
memcpy((void *)&ram_run_start, (void *)&zero_out_integrity_word_start, (int32)&zero_out_integrity_word_size);
zero_out_integrity_word();
return;
}

There are several advantages of using this way,
- No need to consider the instruction set switch from ARM to Thumb.
- No worries about don’t have copied the whole code or more than the code itself into ram

Looking forward to your reply

Best regard

Dana Huang

  • I have noticed my colleague to get back to you.
  • I'm not sure which original post you are referring to.  We do have codes where we do something similar, except we define a fixed dedicated section, and use a union that specifies files

    It looks like you did a union with a section defined in RAM, so it is adjustable in size, and then you also have a variable size for the copy.  I like that instead of having the union pick files, you defined the section with a union, and then used pragmas to put functions in the pragma.  Have you verified that this works correctly for multiple functions - that only one gets loaded at a time?  If this is true, this will be helpful.

    I think that the adjustable size is mainly a matter of taste.  I defined with a fixed RAM size  so that I would get notified if things got bigger.  I worry about running out of RAM.  Floating sizes for RAM are great on PCs where there's plenty, but I've seen trouble on small systems like this one. 

    I don't understand why you say that this removes any necessity to worry about switching from ARM to Thumb mode.  In that regard the code seems exactly the same as what we are already doing. 

  • Mr.Bower

    Sorry, I forgot to attached the original post address. This is from e2e.ti.com/.../431509 backdoor
    Posted by Jack Tan26 at May 24, 2016
    I didn't verify this method to erase checksum. As for stoping running out of RAM, I think the demo code is more reliable.
    Thank you very much for your help.

    Dana Huang