Adding Metadata to GBL Files
This code example has a related User's Guide here: Adding Metadata to GBL Files.
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:
ON_THE_FLY_PARSING: in this case the metadata callback function will be called during OTA image upload.
AFTER_UPLOAD_PARSING: in this case the metadata callback will be called right after OTA image upload.
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.
To create a project with metadata parsing functionality, follow these steps:
Create an Internal Storage Bootloader or a SPI Flash Storage Bootloader project in Simplicity Studio.
Check the Storage Slot configuration in AppBuilder and modify it according to your needs.
Generate and build the project.
Create a SoC–Empty project.
Import the attached gatt.xml file with the Visual GATT Editor. Your GATT database should look like this:
Click Generate to build the GATT database.
Copy the attached ota_dfu_multislot.c and ota_dfu_multislot.h files into the project.
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.
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
Add the followings to main.c
#include “ota_dfu_multislot.h”to the beginning of main.c
evt = gecko_wait_event();
- Remove the code that implements resetting into DFU mode (
Build the project.
Add the bootloader image to your application image as described here: Adding Gecko Bootloader to Bluetooth Projects.
Flash the image to your device.
To use the example code, do the following:
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”.
Copy this file into your project.
Edit the create_bl_files.bat file. Add the
--metadata metadata.binphrase to all
commander gbl createcommands, or at least to those you know you will use.
Run the batch file, which will create the GBL files.
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.
After successful update, connect to your device.
Find the last characteristic within the penultimate service.
Write 0x00 into this characteristic. This will trigger the parsing of Slot 0. Meanwhile, parsing the metadata gets written into the Metadata Test Characteristic.
Find and read the characteristic within the last service. You should see your metadata written into this characteristic.