FOTA standalone image automated

You have successfully implemented FOTA support, so when the toolchain generates your appli.fota it also provides the software parts composing it:

  • appli.hex (your application relying on the binary providing the library code)
  • fota.bin (the library code - dependent on SDK version)

But then you need to flash it with your bootloader or upgrade it using FOTA. In any case, starting from scratch is a bit fastidious whereas it would be so easy if a complete standalone image (FOTA compliant) were available.

The good news is that you already have everything to do it:

  • bootloader.hex is your customized version of the bootloader.
  • fota_signed.bin is the signed version of fota.bin (patched to embed the public key) - I propose to rename it this way not to confuse it with the unsigned version. This binary image must be loaded at address 0x102000 (no base address is required for hex files but they are for raw binaries).
  • appli.hex your application. Note that the SDK ensures it won’t overlap with the library!

You then just have to merge those three files using the interactive executable JFlash from SEGGER:

Or the best solution is to perform this as post processing each time you generate a new image (using for example srec_cat utility). You then always obtain appli.fota and standalone.hex up to date!

6 Likes

Hi @rvs,

Thank you for your excellent contribution to our Community Forum.

2 Likes

Hello, I could not understand fota.bin file.
You are trying to say <cmsis_pack_root>/ONSemiconductor/RSL10/
/source/firmware/fota. this file ?

You can find this information at RSL10 Firmware Over the air document page 20.

Extracted from the .cproject file of “MyProject” generated with SDK3.2.
Not ported yet to SDK3.5 (I’m waiting for SDK3.6).
In the postbuild step, you can find all the details on what to copy, how to perform the merge and so on…
It isn’t very readable due to the XML conversion (&amp;, &quot;) but if you translate them you’ll find that the logic matches what I summed up with the figure.

<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="${cross_rm} -rf" description="MyAppli" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.577327443.1531956973.1046985776" name="IMD04-Debug-LOG_BLE-RTT" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.enablement=null,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.image=null,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=null" parent="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug" postannouncebuildStep="Create both FOTA + Standalone Image" postbuildStep="${cross_prefix}objcopy -O ihex &quot;${BuildArtifactFileName}&quot; &quot;${BuildArtifactFileBaseName}.hex&quot; &amp;&amp; ${cross_prefix}objcopy -O binary &quot;${BuildArtifactFileName}&quot; &quot;${BuildArtifactFileBaseName}.bin&quot; &amp;&amp; &quot;${ProjDirPath}/RTE/Device/RSL10/mkfotaimg.py&quot; -s &quot;${ProjDirPath}/configs/key/key.pem&quot; -o &quot;${BuildArtifactFileBaseName}.fota&quot; &quot;${ProjDirPath}/RTE/Device/RSL10/fota.bin&quot; &quot;${BuildArtifactFileBaseName}.bin&quot; &amp;&amp; cp &quot;${BuildArtifactFileBaseName}.fota&quot; &quot;fota_signed.bin&quot; &amp;&amp; truncate -s `stat -c %s &quot;${ProjDirPath}/RTE/Device/RSL10/fota.bin&quot;` &quot;fota_signed.bin&quot; &amp;&amp; ${cross_prefix}objcopy -O ihex --change-addresses=0x102000 -I binary &quot;fota_signed.bin&quot; &quot;fota_signed.hex&quot; &amp;&amp; srec_cat &quot;../bootloader/bootloader.hex&quot; -Intel &quot;fota_signed.hex&quot; -Intel &quot;appli.hex&quot; -Intel -o &quot;standalone.hex&quot; -Intel" preannouncebuildStep="Replace startup and section files for FOTA" prebuildStep="cp &quot;${ProjDirPath}/app/sections.ld&quot; &quot;${ProjDirPath}/RTE/Device/RSL10&quot; &amp;&amp; cp &quot;${ProjDirPath}/app/startup_rsl10.S&quot; &quot;${ProjDirPath}/RTE/Device/RSL10&quot;">

Can you explain it step-by-step for me ? it is not clear now

Main postbuild steps

Generate the “appli.fota” with a signature

"${ProjDirPath}/RTE/Device/RSL10/mkfotaimg.py" -s "${ProjDirPath}/configs/key/key.pem" -o "${BuildArtifactFileBaseName}.fota" "${ProjDirPath}/RTE/Device/RSL10/fota.bin" "${BuildArtifactFileBaseName}.bin"

The FOTA image format merges the fota binary followed by a padding (up to the next 2K boundary) followed by the appli binary…
So, if we want to extract the fota signed, we just need to truncate the .fota file up to a size corresponding to fota.bin size (the signature area is present but padded with zeros in fota.bin).

cp "${BuildArtifactFileBaseName}.fota" "fota_signed.bin" && truncate -s `stat -c %s "${ProjDirPath}/RTE/Device/RSL10/fota.bin"` "fota_signed.bin"

Convert fota_signed.bin to fota_signed.hex

${cross_prefix}objcopy -O ihex --change-addresses=0x102000 -I binary "fota_signed.bin" "fota_signed.hex"

Used srec_cat to merge all 3 files: bootloader.hex + fota_signed.hex + appli.hex => standalone.hex

srec_cat "../bootloader/bootloader.hex" -Intel "fota_signed.hex" -Intel "appli.hex" -Intel -o "standalone.hex" -Intel
2 Likes