Sometimes it is needed or desired just to add or link a piece of data or BLOB (Binary Large OBject) to the application. For example I have created a .bin file of my code and constant data, and I need to add it to an application using the linker file. How to do this?

First, I have to create the .bin file, for example have a look at MCUXpresso IDE: S-Record, Intel Hex and Binary Files.
Next, edit the linker .ld file and add the following, usually at the beginning of the file:
TARGET(binary) /* specify the file format of binary file */
INPUT ("<your file name here>") /* include the file */
OUTPUT_FORMAT(default) /* restore the out file format */
The TARGET() directive changes the file format for the linker to the binary format, and with OUTPUT_FORMAT() it switches back to the default format. With the INPUT() the file gets loaded.
Below is an example:
TARGET(binary) /* specify the file format of binary file */
INPUT ("../RomLib.bin") /* include the file */
OUTPUT_FORMAT(default) /* restore the out file format */
Lastly, the data needs to be placed somewhere. I prefer the following notation which places it at an absolute address:
.text <address> : {
"<your file name here>"
}
For example:
.text 0xF000 : {
"../RomLib.bin"
}
Below is an example I’m using:

The result then looks like below, with an entry in map file telling that the data has been loaded to the correct address:

That’s it!
Happy Blobing 🙂
Links
- Using GNU ld: https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_toc.html
- Enhancing Binary Utilities in MCUXpresso IDE
- Converting Binary Files to Intel Hex Format with the SRecord Tool
- Using Eclipse to Program Binary Files to an Embedded Target
- Converting a Raw Binary File into an ELF/Dwarf File for Loading and Debugging
- MCUXpresso IDE: S-Record, Intel Hex and Binary Files
Thanks Erich for your useful and helpful article. I am wondering if we can have a parametrized path of the binary file in the linker script. Is it possible to set the path of the binary file in a CMakelist.txt such that it becomes visible to the linker script (e.g. add link options)?
LikeLike
Hi Mehrdad,
I’m not aware of such an option. The easiest thing would be that you would write a pre-processing script which would update the linker .ld file. In Eclipse you can use the pre-build steps for this: https://mcuoneclipse.com/2021/03/28/using-linux-shell-commands-on-windows-with-mcuxpresso-pre-post-build-steps/
LikeLike