7 years, 7 months ago.

Custom Bootloader

Has anyone successfully written a bootloader using the mbed online compiler? We're currently using the Nucleo-144 STM32F412 development board, but plan to cut over to a custom board soon, which will have SPI flash for software updates. Is it possible to link the firmware to a different address so the bootloader can boot it?

3 Answers

7 years, 7 months ago.

Yes and No.

Yes someone has written a succesfull bootloader in the online compiler (me for example :P). No you cannot let the online compiler link firmware to a different address. Solution: Don't put the bootloader at the start of your flash memory, but at the end.

Mine wasn't for your device, but still can give you a hint: https://developer.mbed.org/users/Sissors/code/Bootloader_K64F/. Send me a message if something is unclear.

7 years, 7 months ago.

Hi Eric, thanks for your great bootloader article, it gives me as well some ideas how it can be done.

Hi Joe, I have the same problem in front of me for an STM32L4 MCU. I use an external SPI flash to include the original firmware/app for a factory restore. For updates I plan to download via WiFi the new firmware into my extern flash, once the download is completed I can reboot and the bootloader could detect that it needs to be flashed with the new release. Via a button hold option I can also decide to do a factory restore of my app.

In case of a problem (power outage) during flashing the boot loader could verify the MCU program memory and re-flashes it if it is broken.

The STM devices program flash starts at 0x08000000. I believe we can even do the boot loader with mbed 2.0 by compiling the boot loader offline with the start address 0x08000000+225kB (my flash has 250k), so 25k are available for a mini boot loader. The boot loader can basically be a regular mbed .bin file. Compiled offline mbed using with a different flash start address.

For the main App we can write a little assembler handler which is located in the first 2K, this handler overwrites the reset handler which means we can jump into the reset code of the boot loader, run the boot loader to check if some TODO tasks and reset again and launch the regular app after ensuring the right version is active, etc.

For course every device needs to be flashed with the boot loader, first. Even reprogramming the device via a regular mbed USB drive image copy would not overwrite the boot loader because it is at end,

One weak part of this is that the first 2K of the App must be always working with the correct reset hook to launch the boot loader. For my external flash I am using a FAT file system which means I preferably use an mbed based boot loader which allows me to reuse all my mbed developed and tested code.

This is just an idea for discussion, I am not experienced enough with this topic, however sometimes an idea develops.

Regards Helmut

I just checked the reset handler. It is weak which means we can overwrite it. Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT SystemInit IMPORT main

posted by Helmut Tschemernjak 02 Feb 2017