This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Executing code from RAM (without LX51)

Hi All,

Working with a uPSD33xx.

I am writing a bootloader which performs IAP. Once I have downloaded an app, each time I reset the device I need to be able to 1) determine that an application is actually present before trying to execute it and 2) verify the integrity of said application.

To do this I want to use a block of boot flash to act as NV storage for details about the image, i.e. start address, length, checksum, etc.

My bootloader executes out of boot flash and so to have RW access to the NV 'image table' I guess I will need to execute my flash erase/programming routines out of RAM.

Alternatively I could waste a whole block of main flash on storing only a few 10's of bytes of data.

Has anyone acheive such a thing without the use of LX51 and friends?

Any help appreciated.

Andy

Parents
  • Andy,

    What you do here depends a bit on how big your main application is going to be. If it just consumes a single main flash bank (32kB), then you can actually have MORE than one application programmed and just use some technique to mark which one is valid.

    What I'd recommend is this: Within your application, make a C code constant named, say, statusbyte that is initialized to 0xFF. Put this in its own module and have the linker locate it to a known address. Use the LSB to indicate whether the application has been programmed (that is, if it is "0" the application exists, or if it is 1 it does not). When a flash is blank and all 0xFF's your startup code will know that there's no app there. Have another bit (maybe the MSB) represent "image bad." It's important to have this distinct from the "image good" bit since without erasing flash, all you can do is set bits to zero, not back to 1.

    When you program a flash bank, do your checksums right then and there and if everything looks ok, program the "application exists" bit of your statusbyte to a 0 to indicate that the application exists. If you previously had an application in another bank, then program ITS statusbyte's "application bad" bit to 0. This way your startup code can do the following: 1. Check application area 1's "application bad" bit. If it's zero, check application area 2's "application bad bit. If it's also zero, just stay in the bootloader and wait for a download.

    2. If one or more of the areas has an "application bad" bit set to one (meaning the application might be ok), check the "application exists" bit to make sure it's zero. Just run the first image that has this bit set to zero.

    I don't know if that makes any sense, but it's one way to make sure that A.)If your IAP fails, the previous version will still be runnable. B.)You can always recognize the latest successfully programmed application C.) You won't be messing around with the boot area and rendering your system unusable.

    -Jay D.

Reply
  • Andy,

    What you do here depends a bit on how big your main application is going to be. If it just consumes a single main flash bank (32kB), then you can actually have MORE than one application programmed and just use some technique to mark which one is valid.

    What I'd recommend is this: Within your application, make a C code constant named, say, statusbyte that is initialized to 0xFF. Put this in its own module and have the linker locate it to a known address. Use the LSB to indicate whether the application has been programmed (that is, if it is "0" the application exists, or if it is 1 it does not). When a flash is blank and all 0xFF's your startup code will know that there's no app there. Have another bit (maybe the MSB) represent "image bad." It's important to have this distinct from the "image good" bit since without erasing flash, all you can do is set bits to zero, not back to 1.

    When you program a flash bank, do your checksums right then and there and if everything looks ok, program the "application exists" bit of your statusbyte to a 0 to indicate that the application exists. If you previously had an application in another bank, then program ITS statusbyte's "application bad" bit to 0. This way your startup code can do the following: 1. Check application area 1's "application bad" bit. If it's zero, check application area 2's "application bad bit. If it's also zero, just stay in the bootloader and wait for a download.

    2. If one or more of the areas has an "application bad" bit set to one (meaning the application might be ok), check the "application exists" bit to make sure it's zero. Just run the first image that has this bit set to zero.

    I don't know if that makes any sense, but it's one way to make sure that A.)If your IAP fails, the previous version will still be runnable. B.)You can always recognize the latest successfully programmed application C.) You won't be messing around with the boot area and rendering your system unusable.

    -Jay D.

Children
No data