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:

Slots

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.

  1. Connect your device to your PC.

  2. Open Simplicity Studio.

  3. Select your device in the Devices tab.

  4. 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.

  5. 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).

  6. Click Generate in the upper right corner. This will generate the full Bootloader project.

  7. Click Project > Build project.

  8. Start Simplicity Commander.

  9. Connect to your device with Simplicity Commander.

  10. Click on the Flash tab.

  11. Browse for bootloader-storage-internal-combined.s37 in your workspace (this image contains the whole bootloader).

  12. 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.

  1. Connect your device to your PC.

  2. Open Simplicity Studio.

  3. Select your device in the Devices tab.

  4. Find SoC-Empty between the software examples and click on it. This will create a new Bluetooth application project.

  5. 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".

    GATT Database

  6. Press Generate in the upper right corner.

  7. 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;
  8. 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.

  9. Press Project > Build project.

  10. Run create_bl_files.bat by double clicking on it.

  11. Find soc-empty.bin in the output folder of the compiler. Rename it to app1.bin.

  12. 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:

  1. Double click on the .isc file in your project. This will open the AppBuilder with the GATT configurator.

  2. Select the Device Name characteristic.

  3. Change its value to „Application 2”.

  4. Save and Press Generate.

  5. Press Project > Build project.

  6. Run create_bl_files.bat by double clicking on it.

  7. Find soc-empty.bin in the output folder of the compiler. Rename it to app2.bin.

  8. 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:

  1. Open Simplicity Commander.

  2. Connect to your device.

  3. Click on the Flash tab.

  4. Browse for app1.bin in your workspace.

  5. Set the Flash start address to the start of the application area (0x00000000 on an EFR32xG12 device).

  6. Click Flash to flash the application image into the device.

  7. Browse for app1.gbl.bin in your workspace.

  8. Set the Flash start address to the address of Slot0 (0x0005a000 by default). Be careful, Commander expects a hexadecimal address.

  9. Click Flash to flash the gbl file into the device.

  10. Browse for app2.gbl.bin in your workspace.

  11. Set the Flash start address to the address of Slot1 (0x000ac800 by default). Be careful, Commander expects a hexadecimal address.

  12. 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 (http://silabs.com/bluegeckoapp), as follows:

  1. Open the Blue Gecko app on your smartphone.

  2. Click on Bluetooth Browser.

  3. You will see the device advertising as Application 1.

  4. Click on it to connect.

  5. Find the Unknown Characteristic within the Unknown Service.

  6. Click the Edit icon and write 01 to the Characteristic. This will trigger the device to reboot from Slot 1.

  7. Disconnect from the device by clicking on the Back arrow.

  8. Now you will see the device advertising as Application 2.

Testing with Blue Gecko App

Source