Support for BiDiB

Creating hex files for firmware updates

Usually, projects will be compiled from source code files. The compiled files (so called "object files") will be linked together and the binary file for the target device is obtained. The data format for BiDiB is an Intel hex file, which allows to transfer this binary file easily to the device by using the standardized firmware update process.

Usually this process (often called 'build') is done with the program ('make'), which verifies the dependencies of the source files and performs all necessary calls.

The result of such a process is typically a file with the following name: my_project.hex.

Filenames for BiDiB

Filenames for BiDiB should be structured as follows:


project describes the name of the firmware and version indicates the revision which is usually 3-digit number. 000 describes the target memory area. This means, the build result must be renamed in order to match the above filename structure.

Automatic compiling by make

The example below shows how this file name convention can be generated with the make command. This example uses gawk and cp, which is included in the gcc utils.

1. Creating a revision file inside the source code (version.h).

#define MAIN_VERSION                0
#define SUB_VERSION                 13
#define COMPILE_RUN                 01

This file will be read from the source code and the containing defines will be used for the BiDiB version query.

2. Reading of version.h with make:

A variable MYVERSION will be created inside the makefile. This variable will be assigned with a shell command from version.h. For this purpose, we get the third paramter in the line below by searching the file for matching keywords with gawk:

MYVERSION := $(shell gawk '/MAIN_VERSION/ {printf $$3 "."} /SUB_VERSION/ {printf $$3 "."} /COMPILE_RUN/ {printf $$3}' ../version.h )

Note that the $ sign for parameter needs to be write twice. It will drop out once, because of the substitution of make. Now, MYVERSION contains the character string: 0.13.01

3. Creating a hex-file:

Here we use the variable and add a copy command inside the makefile. This command copies the output files accordingly:

%.hex: $(TARGET)
        avr-objcopy -O ihex $(HEX_FLASH_FLAGS)  $< $@
        cp $(PROJECT).hex $(PROJECT)_$(MYVERSION).000.hex

%.eep: $(TARGET)
        -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
        cp $(PROJECT).eep $(PROJECT)_$(MYVERSION).001.hex

And we get: my_project_0.13.01.000.hex and my_project_0.13.01.001.hex.