Arm Mbed OS support forum

Application Header with Update image

In my project I have a custom bootloader and specify an application header (in both bootloader and main project). When compiling the main application there are three .bin images in the BUILD directory:

  1. app.bin
  2. app_update.bin
  3. app_application.bin

app.bin contains the bootloader + application header + application as expected. The other two images appear to be the application only.

Shouldn’t image 2 or 3 have the application header prepended??

I can’t figure out if this is just a half implemented feature or if I’m missing something. If I load app.bin then wish to perform a firmware update via the bootloader, the update image should contain the header - the header contains a hash for verifying the image so will definitely need updating along with the new firmware.

I can combine the hex file and binary image myself, but it takes away half of the convenience of having the header generated by Mbed Studio.

Just an additional point which just adds to the ambiguity of how this feature is used - the Bootloader tutorial / bootloader config reference pages seem to suggest that the application header size is the size of the structure specified by the config values rounded up to a multiple of 8 bytes.

On inspection of the BUILD linker file and hex dump of the .bin file shows me that my 64 byte header structure is in a header section 128 bytes in size. When combining the header myself, knowing this is important - just looking at the app_header.hex file would hide the fact that the bootloader and application expect the header to be padded from it’s actual 64 bytes in size to 128.

I’m not 100% confident this post is in the correct topic, maybe tools is better suited?

3 Likes

I have the same problem. Without combining hex with binary app_application.bin file, the application header functionality is useless for me. How do you combine both files (cli)?

Some discussion here: Bootloader: Is there a way to include the image header in the generated *_update.bin? · Issue #12190 · ARMmbed/mbed-os · GitHub

Hi Phlegx,

so I just happen to need to do this again for a different platform, and thankfully I’d made a little script the first time. It’s just a CMD script for Windows but can be adapted however you need. A couple of notes:

  • I’m using mbed-os-5.15.5 (support for my board dropped in v6 :frowning: )
  • Replace the values in angled brackets with your own project specific
  • Replace the APP_HEADER final address to reflect your header size - remember this is the final size as decided by the tools. Mine was 128 Bytes.
  • I had this in a scripts directory in my project root, so my build directory path is relative to that
  • You will want to set the path to the hex2bin.py Python script which I think is in the MBED OS tools folder somewhere. I copied a version into the same directory as my script below.
  • Add a copy/ export step or change the final destination as the default below will be in the BUILD_DIR which is volatile/ can be cleaned out or removed by the build process.
@REM Mbed OS Bootloader header prepend & merge tool
@REM will convert header .hex to bin (with padding) and prepend to application.bin

@echo off

SET BUILD_DIR=..\BUILD\<platform>\ARMC6\
SET HEADER_FILE=<project_name>_header
SET UPDATE_FILE=<project_name>_update
@REM see .profile-ld in BUILD folder to find out the header size / app start location
@REM END should be the last address of the header section!
SET HEADER_END=0x801007F

python .\hex2bin.py --pad=FF --range=":%HEADER_END%" %BUILD_DIR%%HEADER_FILE%.hex %BUILD_DIR%%HEADER_FILE%.bin

@REM concatenate the header and update binaries..
cat %BUILD_DIR%%HEADER_FILE%.bin > %BUILD_DIR%%UPDATE_FILE%_with_header.bin
cat %BUILD_DIR%%UPDATE_FILE%.bin >> %BUILD_DIR%%UPDATE_FILE%_with_header.bin

@echo on

Edit: Removed my own copyright, feel free to use / alter etc. Added my OS version.

1 Like