How to create single binary containing firmware and application code?


#1

Hi folks,

I’m trying to figure out how to create a single binary that contains both the particle firmware and my application code (to make it easier to burn firmware with a JTAG programmer on a large number of boards), while still maintaining my application source code in a directory outside of the firmware directory. It wasn’t obvious to me how to do this after looking at the readme in the firmware repo. Can anyone point me in the right direction?

Thanks,
Alan


#2

Hello @alanwells!

We do this for our own manufacturing binaries, which are many images combined into one.

Which platform are you targeting?

Thanks,
mat.


#3

@alanwells, while Mat will definetly give you the pro answer, I can only point you to the make parameter MODULAR=n when building locally, which generates a combined bin for system-part1, system-part2 and your user-part.

So this should help out till Mat gets your input to provide the pro answer

cd <repo-root>/main
make clean all PLATFORM=<yourPlatform> MODULAR=n ... 

#4

Hi @mdma! I’m targeting the electron platform (we have a a custom board that is electron-compatible).

Thanks!
-Alan


#5

@ScruffR Thanks, will give that a try!


#6

Hi @alanwells,

It’s best to keep the system and application firmware separate (i.e. use our modular system) so that your electron follows the standard layout for devices, allowing application code to be separately compiled without also needing to flash the system firmware, which avoid additional data usage.

To create a complete image for the electron, we use

This combines the bootloader, as well as system and default application firmware for flashing via JTAG on a manufacturing line.

To use the makefile, pull the firmware repo, checkout the branch and then run:

cd hal/src/electron
make -f combined.mk

This will build the manufacturing image to firmware/build/releases/release-0.4.9-p10/

Flashing the manufacturing image

Ensure OPENOCD_HOME is defined that points to the location of your openOCD installation.

Hook up the Electron to the programmer shield and run

make -f combined.mk all openocd-flash

This will build the manufacturing image and flash it to the device, erasing all previous flash contents.

To build a custom application, you will need to edit the application part to include APPDIR= which will then build the application from your sources. The source line that builds the application part is https://github.com/spark/firmware/blob/develop/hal/src/stm32/combined.mk#L88

I hope that’s clear, but just let me know if you need more detail.


#7

Thanks @mdma, will give that a try.


#8

@mdma The above instructions made sense, but I’m getting a file error on the user-part.bin file:

dd if=../../../../firmware/build/target/user-part/platform-10-m/user-part.bin of=../../../../firmware/build/releases/release-0.4.8-rc.6-p10/user-part.bin conv=notrunc
dd: ../../../../firmware/build/target/user-part/platform-10-m/user-part.bin: No such file or directory
make: *** [user] Error 1

It appears the makefile is attempting to copy user-part.bin from /firmware/build/target/user-part.bin to /firmware/build/releases/release-0.4.8-rc.6-p10/user-part.bin. This file exists in the location where it is trying to copy it to, but not where it is trying to copy it from. Is it possible the paths for these two locations are accidentally reversed in this line: https://github.com/spark/firmware/blob/develop/hal/src/stm32/combined.mk#L90?


#9

Hi @mdma, I was able to figure this out and wanted to share my changes here in case it’s useful for others.

  1. On this line: https://github.com/spark/firmware/blob/develop/hal/src/stm32/combined.mk#L88
    I added the APPDIR=path/to/our/app flag as you mentioned above.

  2. On this line: https://github.com/spark/firmware/blob/develop/hal/src/stm32/combined.mk#L90
    I replaced if=$(USER_BIN) with if=path/to/our/app_binary.bin (points to our application code binary created by the makefile)

  3. On this line: https://github.com/spark/firmware/blob/develop/hal/src/stm32/combined.mk#L106

I removed the three (extra?) $(USER_MEM) statements (there were 4 total on the line, which I think added 4 copies of our app firmware to the final binary.

Is there a reason there should be 4 copies of the app binary added to the combined binary?

Thanks again for the help!
Alan


#10

@mdma

Is this still the recommended way to program the combined bootloader & system firmware for a ‘custom’ electron?

Running

make -f combined.mk

results in error “region `APP_FLASH’ overflowed by 892 bytes”

I believe I’m on the most recent branch of firmware.


#11

Can you be more precise please - which branch?

This looks like an intermediate problem - sometimes firmware overflows the space available until we have time to optimize.

It’s recommended you stick to use release branches unless there is a specific reason to use development branches. The latest release is found under master with other releases found under release/vX.Y.Z.


#12

Apologies for the ambiguous post, I had tried several branches including develop and latest.
I’ve just tried again on the master branch and still getting the overflow error.

I’m using arm-none-eabi-gcc version 4.9.3

I’ve managed to upload the firmware separately anyway so no dramas, would be a useful feature if I could get it working though.


#14

@mdma Can you confirm that you intended to refer to 2 different make files in this post?

You refer to:
hal/src/electron/combined.mk for making a combined binary
hal/src/stm32/combined.mk for flashing the image

Which combined-build code path does Particle use for official manufacturing binaries? Both the above seem to be throwing errors in the latest release branch for the electron.