cancel
Showing results for 
Search instead for 
Did you mean: 

Integrating OTA into an existing project

Daniel L
Associate III

Hi,

I am in the process of integrating OTA functionality into my project using the examples in STM32Cube_FW_WB_V1.2.0. With reference to AN5247, I have added the Reboot Characteristic and changed my Flash start address to 0x08007000.

I have also noticed that in the BLE_HeartRate project, that there is the "MagicKeywordValue", "MagicKeywordAddress" and "BleApplicationContext" placed in various different sections in flash ("TAG_OTA_END", "TAG_OTA_START" & "BLE_APP_CONTEXT"). I have a few questions as these do not seem to mentioned in the App Note.

  1. What memory address should these sections be placed in a how is that done in the linker file? GCC Linker File attached.
  2. How and where is the "BleApplicationContext" utilised in the BLE_OTA project?
  3. As the "MagicKeywordValue" & "MagicKeywordAddress" is used for Firmware Validity, should the value and address be changed for security?

Thanks,

Daniel

4 REPLIES 4
Daniel L
Associate III

I have successfully got my applications working with the OTA. Added the following code to my app_ble.c and configured the linker file to position the "TAG_OTA_START" at 0x08007140 and "TAG_OTA_END" at the end of the application. Linker file attached. More information would be greatly appreciated.

/**
 * These are the two tags used to manage a power failure during OTA
 * The MagicKeywordAdress shall be mapped @0x140 from start of the binary image
 * The MagicKeywordvalue is checked in the ble_ota application
 */
PLACE_IN_SECTION("TAG_OTA_END") const uint32_t MagicKeywordValue = 0x94448A29 ;
PLACE_IN_SECTION("TAG_OTA_START") const uint32_t MagicKeywordAddress = (uint32_t)&MagicKeywordValue;

Christophe Arnal
ST Employee

​Hello,

Here are some clarification how it works :

The section "BLE_APP_CONTEXT" is unused so you can just forget it. ( It is there for historical reason)

The Ble_Ota project implements a simple mechanism to ensure the full application has been flashed in the device. The goal was to have the exact same application code (eg Heart Rate) whether it is used alone in the device or downloaded with OTA. The only difference is the link address. A standalone application is linked @0x0800 0000 whereas an application to be downloaded by OTA is linked @0x0800 7000.

In order to check if the full firmware has been written, a magic keyword is written at the end of the firmware. At startup, the Ble_Ota application checks whether this magic keyword is there or not at the end of the application. In case a reset occurred during upload which could result on a partial image to be written, the magic keyword will not be there and the corrupted application will be ignored by the Ble_Ota startup.

As the application length information is not present, the address of the Magic Keyword is written @0x0800 7140.

In order to make the calculation transparent to the user, two constants are defined in the firmware.  One is holding the address of the magic Keyword and is associated with section TAG_OTA_START and the other one is holding the magic keyword and is associated with TAG_OTA_END.

The linker file is updated with these two sections and the address of the magic keyword is calculated automatically by the linker.

Regards

Aishwarya
Associate III

hello @Christophe Arnal​ 

how to update linker file according to OTA application in stm32wb55, code is generated by STM32CubeIDE(STM32Cube_FW_WB_V1.8.0).

There is two linker files for Flash(STM32WB55RGVX_FLASH.ld) and RAM(STM32WB55RGVX_RAM.ld).

​Hello,

I would recommend to check the provided linker file of either BLE_HeartRate_ota or BLE_p2pServer_ota.

I extracted from the linker provided the important section related to OTA

You basically need to :

  • make sure the first flash address start @0x08007000
  • The TAG_OTA_START section is @0x08007140 where in you binary you should find the address of TAG_OTA_END
  • The TAG_OTA_END section mapped at the very end of the binary and that should hold the keyword
  • The section MAPPING_TABLE shall be loacted at first address of SRAM2
  • The sections MB_MEM1 and MB_MEM2 shall be anywhere in SRAM2

I would recommend to study the linker file of either IAR or KEIL which are much more easy to understand.

MEMORY
{
FLASH (rx)                 : ORIGIN = 0x08007000, LENGTH = 484k
RAM1 (xrw)                 : ORIGIN = 0x20000004, LENGTH = 191k
RAM_SHARED (xrw)           : ORIGIN = 0x20030000, LENGTH = 10K
}
.ota_region 0x08007140:
  {
	KEEP(*(TAG_OTA_START))
	. = ALIGN(4);
  } >FLASH
.ota_region_end :
  {
	. = ALIGN(4);
	KEEP(*(TAG_OTA_END))
	. = ALIGN(4);
  } >FLASH
   MAPPING_TABLE (NOLOAD) : { *(MAPPING_TABLE) } >RAM_SHARED
   MB_MEM1 (NOLOAD)       : { *(MB_MEM1) } >RAM_SHARED
   MB_MEM2 (NOLOAD)       : { _sMB_MEM2 = . ; *(MB_MEM2) ; _eMB_MEM2 = . ; } >RAM_SHARED
   TAG_OTA_END(NOLOAD)    : { KEEP (*(TAG_OTA_END)) } >FLASH

Regards