Adding Metadata to GBL Files

Background

This code example has a related User's Guide here: Adding Metadata to GBL Files.

Description

The attached example code demonstrates how to extend the application uploader (Uploading Images to Internal/External Flash Using OTA DFU) with metadata parsing functionality. You can choose from 3 modes with the #defines at the beginning of ota_dfu_multislot.c:

  1. ON_THE_FLY_PARSING: in this case the metadata callback function will be called during OTA image upload.

  2. AFTER_UPLOAD_PARSING: in this case the metadata callback will be called right after OTA image upload.

  3. STORED_GBL_PARSING: in this case you have to write the slot number into the “Read Metadata from Slot” characteristic to initiate a metadata parsing in that storage slot.

In this example, the content of the metadata is copied to the Metadata Test Characteristic. As a result, after parsing you can read this characteristic with your smartphone to check if parsing was successful.

Setting up

To create a project with metadata parsing functionality, follow these steps:

  1. Create an Internal Storage Bootloader or a SPI Flash Storage Bootloader project in Simplicity Studio.

  2. Check the Storage Slot configuration in AppBuilder and modify it according to your needs.

  3. Generate and build the project.

  4. Create a SoC–Empty project.

  5. Import the attached gatt.xml file with the Visual GATT Editor. Your GATT database should look like this:

  6. Click Generate to build the GATT database.

  7. Copy the attached ota_dfu_multislot.c and ota_dfu_multislot.h files into the project.

  8. Copy btl_interface.c and btl_interface_storage.c from C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v2.3\platform\bootloader\api to your project.

  9. Go to Project Properties > C/C++ Build > Settings and add the following folders to the Includes: "$/platform/bootloader" "$/platform/bootloader/api" or copy the .h files from these folders to your project

  10. Add the followings to main.c

    • Add #include “ota_dfu_multislot.h” to the beginning of main.c
    • Add ota_dfu_handle_event(evt); after evt = gecko_wait_event();
    • Remove the code that implements resetting into DFU mode (case gecko_evt_gatt_server_user_write_request_id:)
  11. Save main.c.

  12. Build the project.

  13. Add the bootloader image to your application image as described here: Adding Gecko Bootloader to Bluetooth Projects.

  14. Flash the image to your device.

Usage

To use the example code, do the following:

  1. Create a new file with the content of the metadata, e.g., metadata.bin. The content can be anything, e.g., a text saying “this is my metadata”.

  2. Copy this file into your project.

  3. Edit the create_bl_files.bat file. Add the --metadata metadata.bin phrase to all commander gbl create commands, or at least to those you know you will use.

  4. Run the batch file, which will create the GBL files.

  5. Copy the GBL files to your smartphone and do a (partial) OTA update as you would normally do (Using EFR Connect Mobile App for OTA DFU). By default, this will upload your application.gbl file into Slot 0.

  6. After successful update, connect to your device.

  7. Find the last characteristic within the penultimate service.

  8. Write 0x00 into this characteristic. This will trigger the parsing of Slot 0. Meanwhile, parsing the metadata gets written into the Metadata Test Characteristic.

  9. Find and read the characteristic within the last service. You should see your metadata written into this characteristic.

Source