linkerstm32bootloaderflash-memory

Dynamically build STM32 application but for two different partitions of flash


I'm using the STM32L496 and have a bootloader at 0x08000000 of flash. After that, I have two partitions for applications, one at 0x08040000 which is the main application, and one at 0x080C0000 for a "golden image" that the bootloader can use if the main application is corrupted (the idea being the main app can be re-programmed with IAP). I've been able to modify the linker and scb->vtor setting so it will build the application to boot from either partition (golden image when main app is blank).

My question is, is there a way to do this without changing the linker and vector offset manually? Let's say I have a new build that is the new "golden image", I'd like to be able to build that so I can program it to each partition.


Solution

  • I think what you mean is Position Independant Code. It's possible to generate PIC code with ARM cortex GCC though I never did it myself.

    It is pretty complicated: see here for example.

    However as others wrote already, I don't really see the benefit to do that especially on a small STM32L4 MCU. It is inefficient and complex (so error prone).

    Moreover the STM32L4 provide a functionality to do (more or less) what you need: there are two flash banks and you can swap them. It means the HW changes the aliased adress of bank2: you can link your software always to the same adress 0x0800 0000 but load it either in bank 1 or in bank 2. It is meant to ease software update.