Categories
Torrox News

Updating the Bootloader

Once in a while a customer asks how we would update the bootloader itself, if needed? Well, the short answer is: Usually you don’t.

Torrox provides bootloaders off-the-shelf for STM32 and C2000 microcontrollers. These bootloaders are flashed onto the device during production and then sit there for the rest of the device’s life to enable the update of the firmware.

Longer answer: But if you really, really need to, I would write a small firmware that has the new bootloader embedded and that would then erase the old bootloader and install the new bootloader that was embedded in that small firmware.

Step by Step

Initially, we have a firmware (version 2.2) on a device with bootloader version 1.0 and we want (for whatever reason) to update this bootloader to version 1.1.

The initial situation is depicted as a memory layout, where at the start of the flash memory, a bootloader with version 1.0. is located. At the start of the application flash memory, a firmware version 2.2. is located.
Initial Situation

We build a firmware, a bootloader updater, and give it version V99.99 to clearly mark this version as something that is something special. Any firmware update process could use this version information to see that the bootloader updater is correctly installed.

That firmware contains the new version of the bootloader:

After installing the firmware updater, at the start of the the flash memory, the bootloader V1.0 is installed. At the start of the application flash memory, the updater with version 99.99 and the embedded bootloader is located.
After Installing the Updater

Once firmware V99.99 has been correctly installed by bootloader V1.0, it compares the embedded bootloader binary with the installed bootloader at “Start of Flash Memory”. If there are differences, that firmware (the bootloader updater) erases the bootloader and flashes the embedded bootloader:

At the start of the flash memory, bootloader version 1.1 is located, at the start of the application flash memory, the updater with version 99.99 and the embedded bootloader is located.
New Bootloader Version is installed

Once the new bootloader is installed, the new bootloader can be used to install the regular firmware again:

After installing firmware V2.2, the start of the flash memory contains the bootloader version V1.1 and the firmware at the firmware start location is version 2.2.
After Update Procedure

When Does Updating a Bootloader Make Sense?

We, and I guess all other authors of bootloaders as well, do our best to not have any bug in our bootloaders. However, should a bootloader have a bug that needs to be fixed, it’s good to have a plan for how to handle such situation.

There might be other reasons, such as adding a nice-to-have feature or supporting a new interface.

Caveats

When the bootloader updater installs the new bootloader, the old bootloader gets erased from flash memory and the new bootloader gets flashed. If that sequence is somehow interrupted, the device will be bricked.

Good News for our Customers

We are starting to add this bootloader updater to our standard deliveries with all new versions of our bootloaders! That means that customers do not only get new bootloader binaries with a new version, but also an updater to install the new bootloader on devices that already run our bootloader.

Leave a Reply

Your email address will not be published. Required fields are marked *