Dual bootloader - how to?
Hi everyone!
I have to implement a dual bootloader system on different stm32 microcontrollers in STM32cube ide, and I have some questions…
The idea is the following:
There is a “pre-bootloader�? at the beginning of the flash. When it starts, it gets some data from a specified memory (flash) area: the address, size and crc of the actual “real�? bootloader. (Let’s name this area BL_DATA). Calculates the crc of the bootloader, compares it to the stored value, and if it’s ok, jumps to that address.
The bootloader waits for messages over u(s)art. If the arrived message is a command to flash the user app, it gets the app binary in chunks, and after some validation it writes the new user app to the specified address.
The address, size and crc of the user app are stored in BL_DATA. After flashing the user app, the bootloader refreshes user app crc and size. The address of the user app is constant.
If the command is to flash the bootloader, it writes the arriving program to the proper address: there are 2 bootloader addresses stored in BL_DATA, the new bootloader address is which is not equal to the actual bootloader address. After writing to flash, the bootloader sets the actual bootloader address to the other’s (and also the size and a calculated crc).
If no message arrives in time, it simply jumps to the user application (after reading its address, crc and things like that from BL_DATA, just like the pre-bootloader).
I started with implementing the jumping feature. It works, but I needed some workarounds to make it work:
In the debug configurations of the pre-bootloader on the startup tab I added the bootloader too. In the pre-bootloader program I check what’s on the address in BL_DATA where the actual bootloader address needs to be, and if nothing is set there I write the actual bootloader address to there and then jump to it.
- First question: is it possible to link a binary content (in the linker script?) to make it being stored at a specified memory area? (I guess it is, but I need some keywords to search with…) or it’s just simpler to commit this “initial write�??
- It’s necessary to spearate BL_DATA from other areas in flash because when i want to flash a new bootloader or user app, i have to erase that area first. E.g. with stm32f767zi the smallest “section�? to erase is a 32K sector, so in this case I have to reserve a whole sector for BL_DATA. Am I right? (To store all the data I need only 64 bytes so it seems to be a bit wasteful - despite it’s 2M flash memory…)
- The bootloader’s address in the memory depends on what’s the actual bootloader address stored in BL_DATA. How can I configure the bootloader project’s linker file to achieve this?
I’d be really glad if someone gave me some explanations and/or keywords in these topics…
