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

Can I relocate code

I'm designing a application downloader that can be run from the main application. The mechanism I want to employ would be to load a replacement application into a secondary "bank" of flash and then do a soft reboot into that region without having to copy it into the normal running location. Does this chip have a mechanism that would allow me to do this, I'm assuming that the Interupt vector table would have to move also. Also would the compiler produce relocatable code using relative instead of fixed location jumps?

  • John
    Thanks for this information. It is usfull but does not answer my question, which I may not have expressed very well. What I am trying to find out is can I have two application loads in the main flash and have the ability to switch from one to the other just by calling their start address from the boot loader. Something like this
    +++++++++++++++
    ISP Boot Loader
    +++++++++++++++
    Application 1
    ...
    ...
    +++++++++++++++
    Application 2
    ...
    ...
    +++++++++++++++
    Now these applications may be identical but if the bootloader finds a crc error in one image it could just run the other, with out any copying, say. They could also hold different images during an upgrade, so there could be a simple switch from the old App ( which did the upgrade ) to the New. Then the new image could commit it self into the other region when it is all good.
    So what I want to know is can I relocate the image to any other part of the Flash other than the normal place?

  • It is quite simple to write a tiny boot loader that computes crc32 or similar and optionally looks into a EEPROM or a flash configuration sector to select which application version to start.

    You may even decide that this boot loader does not have any transfer support. Let the two applications have transfer support, to allow application A to download a new application into area B and application B handle download of new data into area A.

    If B is newer than A then you may decide to start B instead of A, unless area B has invalid CRC32 or has resulted in multiple watchdog resets, in which case it may be better to try to step down to the previous version.

  • So the answer is I can run an Application from any position of the flash? If so thats great news. BTW I'm using a ST32-with cortex core. How do I make sure that all the internal jumps are relative? How do I change the Interrupt vectors so they point into the relocated load?

  • You either inform your compiler to generate position-independent code. Or you create two targets - one for application area A and one for application area B.

    I don't work with your specific processor, but I would guess it has a mapping to move the interrupt vectors into RAM. Your two applications will then be responsible to copy their vectors into this RAM region before switching the mapping and activating interrupts.

  • could I change the interrupt vectors to secondary loads ISRs. I assume the vectors are at the top of the code, I could back them up, copy them from the secondary top to the primary with an added offset then just jump to the new image? If it fails then here would be a reboot and I could get the boot loader to re-configure the vectors back. How does that sound?

  • Look at the description of the vector table for your specific processor. But if the processor can map the vectors to RAM (which I believe it can) then the two applications can copy the vector table from their flash region and into this RAM region.

    If you get a watchdog reset (provided you let your boot loader activate the boot loader and configured it for resetting the processor), you will arrive back into your boot loader again and the boot loader may then decide to start the other application.