Switching between Firmware Images#
Description#
EFR32xG12 and EFR32xG21 devices have 1MB internal flash memory, which makes it possible to store multiple firmware images in the internal flash (the Bluetooth stack size is around 128kB + application) and to switch between the firmware images at boot time.
For a device with smaller flash size, you can store multiple firmware images in an external flash and load one of them into the application area at boot time.
For two firmware images, the flash is split into 4 section:
The actual application that is executed (starting at 0x0000 or 0x4000 based on device family)
The first firmware image packed into GBL format (in slot0)
The second firmware image packed into GBL format (in slot1)
The Gecko bootloader (placed into the bootloader section)
Before rebooting the device, the bootloader can be instructed to boot an image from slot0 or from slot1 to the application area. In this case, the bootloader parses the corresponding GBL file upon reboot, copies the application image from it to the application area, and starts execution.
This article shows how to program the flash for this use case and how to switch between firmware images.
Setting up#
The Gecko Bootloader#
The Gecko Bootloader is a common bootloader for EFR32xG devices that can be configured in a number of ways. This use case requires the Internal Storage Bootloader (multiple images) configuration, or SPI Flash Storage Bootloader (multiple images) configuration if using an external flash.
Connect your device to your PC.
Open Simplicity Studio.
Select your device in the Devices tab.
Find Internal Storage Bootloader (multiple images) between the Software Examples and click on it. This will create a new Gecko Bootloader project. The AppBuilder opens automatically.
Click on the Storage tab. Check the address of Slot0 and Slot1. (You may also rearrange the slots and create new slots for firmware images).
Click Generate in the upper right corner. This will generate the full Bootloader project.
Click Project > Build project.
Start Simplicity Commander.
Connect to your device with Simplicity Commander.
Click on the Flash tab.
Browse for bootloader-storage-internal**-combined**.s37 in your workspace (this image contains the whole bootloader).
Click Flash to flash the bootloader image into the device.
Creating Application Images#
As a simple example, use the SoC-Empty app. This application implements a simple Bluetooth server, which is advertising and can be connected to. A new characteristic will be added to the app with which the device can be instructed to boot from another slot.
Connect your device to your PC.
Open Simplicity Studio.
Select your device in the Devices tab.
Find SoC-Empty between the software examples and click on it. This will create a new Bluetooth application project.
Open the GATT Configurator and import the attached gatt.xml file with the import button found on the right side. The GATT database has the additional characteristic and the device name is set to "Application 1".
Press Generate in the upper right corner.
Copy the attached app.c file into your project overwriting the existing one. It contains the control code which will reboot the device from a given slot, when the Boot Slot characteristic is written:
case gecko_evt_gatt_server_attribute_value_id: if (evt->data.evt_gatt_server_attribute_value.attribute == gattdb_boot_slot) { bootloader_setImageToBootload((int32_t)(evt->data.evt_gatt_server_attribute_value.value.data[0])); bootloader_rebootAndInstall(); } break;
Copy all the .c and .h files from C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v2.x\platform\bootloader\api into your project.
Press Project > Build project.
Run create_bl_files.bat by double clicking on it.
Find soc-empty.bin in the output folder of the compiler. Rename it to app1.bin.
Find full.gbl in the output_gbl folder, and rename it to app1.gbl.bin. It is important to rename it to a .bin file to be able to flash it into the internal flash.
Now the first firmware image is ready. To create a second image, slightly modify this project, as follows:
Double click on the .isc file in your project. This will open the AppBuilder with the GATT configurator.
Select the Device Name characteristic.
Change its value to „Application 2”.
Save and Press Generate.
Press Project > Build project.
Run create_bl_files.bat by double clicking on it.
Find soc-empty.bin in the output folder of the compiler. Rename it to app2.bin.
Find full.gbl in the output_gbl folder, and rename it to app2.gbl.bin.
Programming the Flash#
To program the flash with these images, do the following:
Open Simplicity Commander.
Connect to your device.
Click on the Flash tab.
Browse for app1.bin in your workspace.
Set the Flash start address to the start of the application area (0x00000000 on an EFR32xG12 device).
Click Flash to flash the application image into the device.
Browse for app1.gbl.bin in your workspace.
Set the Flash start address to the address of Slot0 (0x0005a000 by default). Be careful, Commander expects a hexadecimal address.
Click Flash to flash the gbl file into the device.
Browse for app2.gbl.bin in your workspace.
Set the Flash start address to the address of Slot1 (0x000ac800 by default). Be careful, Commander expects a hexadecimal address.
Click Flash to flash the gbl file into the device.
Note: you may also upload GBL files OTA to the slots following the instructions of this article:
Uploading Images to Internal/External Flash Using OTA DFU.
Usage#
You can test the application with the Blue Gecko Android/iOS app, as follows:
Open the EFR Connect app on your smartphone.
Click on Bluetooth Browser.
You will see the device advertising as Application 1.
Click on it to connect.
Find the Unknown Characteristic within the Unknown Service.
Click the Edit icon and write 01 to the Characteristic. This will trigger the device to reboot from Slot 1.
Disconnect from the device by clicking on the Back arrow.
Now you will see the device advertising as Application 2.