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.

TM4C129XNCZAD: Running main code from two different locations in flash

Part Number: TM4C129XNCZAD


I have been looking a while, but I'm not sure how to handle this case.  I have a small boot program that I wrote that I load at 0x00000000.  It runs fine, and from that program, I want to either jump to main code at 0x8000 or 0x14000.  The idea is that I would always have a known good version on the device, but could upgrade the software in the other bank, and use that on boot.  The main reason I have my own boot loader is that I'm doing the updating via a proprietary interface, not serial, usb, etc.

I have the boot program selecting the code at 0x8000 and running it correctly.  This main code has been compiled with the .cmd file telling it that it's loading at 0x8000.  From a practical standpoint, it doesn't make sense to have two different compiled versions each assuming they are loading at different address, especially since I don't know which bank will me upgraded next.  The boot software is going to load new code into the bank that doesn't contain the last known good version.

How do I get around this?  I have loaded the same main code into 0x8000 and 0x14000, and the boot loader will run either one, but for example, if I deleted the code at 0x8000, it would not run the code at 0x14000.

This seems like a fairly common use case, so there must be a way to tackle it that I haven't found.

-James

  • There should be a compiler/link option for position independent code if your compiler supports it.

    Robert
  • James,

    I am not too sure you can do things the way you describe. When you compile/link your program, the addresses are all "hard" defined. If you compile the application to run on bank starting on 0x8000, it will not work if you copy that exact code to 0x14000 location.

    What we do for the very same purpose is to always run the "good" program from a fixed location. The bootloader resides at 0x00 and the valid program runs at 0x4000. If we send an update, it will be temporarily stored in a separate area of flash (it could also be on external memory), and the bootloader will transfer the contents on next boot, guided by flags that indicate the presence of new firmware.

    Bruno

  • James is right Bruno, it should be possible. Whether his compiler supports it is another question (IAR does appear to support it).

    Calls to absolute addresses become calls to offsets, jumps must be relative etc...

    Robert