Binary File as resource for project

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Binary File as resource for project

1,831 Views
lonniewalker
Contributor I

I am wanting to include a binary graphic binary file into my C application and haven't found anyway to do this yet with the LPCXpresso IDE as a resource manager.

Can someone explain how I could possibly include the binary file into my project tree as a 'Resource' which will get bound into the project and assigned flash memory which could be accessed by my application for a data transfer operation??

The only why I know right now is to write a PC application which will open up the binary file and create and generate a 'C' module defining an initialized array with the data.   

 binary file contents in hexadecimal: 02234323590AFFE0

C code:

static unsigned char  FileData[] = {0x02, 0x23, 0x43, 0x23, 0x59, 0x0a, 0xff, 0e0};

There has got to be a way Xpresso could manage the binary file as a resource which gets coded to Flash on build?

Thanks in advance-

Lon

0 Kudos
4 Replies

1,323 Views
lpcxpresso_supp
NXP Employee
NXP Employee

One way would be to use the incbin assembler directive to pull the binary into an assembler file that is part of your project:

or you could look at the arm-none-eabi-objcopy -I binary option:

There is quite a lot around on the web on importing binary blobs like this that you might find useful, for example:

Linking a binary blob with GCC | Freedom Embedded 

Regards,

LPCXpresso Support

0 Kudos

1,323 Views
jdupre
Contributor II

I have followed the instructions as per Linking a binary blob with GCC | Freedom Embedded and have created the BLOB object that I want to include in a different project:

BootLoader.o:     file format elf32-littlearm

SYMBOL TABLE:
00000000 l    d  .data    00000000 .data
00000000 g       .data    00000000 _binary_BootLoader_bin_start
00002b54 g       .data    00000000 _binary_BootLoader_bin_end
00002b54 g       *ABS*    00000000 _binary_BootLoader_bin_size

The question is, how do I tell LPCXpresso where to find this object file, or where do I put it in the project directory so that the linker can find it?  I tried putting it in the same directory as the project's other object files, but I still get undefined reference error:

...ReplaceBootloader\Debug/../example/src/main.c:181: undefined reference to `_binary_BootLoader_bin_start'

[ Background:  I have a "bootloader" at the beginning of flash that loads and/or executes  a "firmware" image that follows.  I need to create a special firmware image that replaces the existing bootloader in flash.  So the bootloader binary needs to be embedded within the special firmware file so it can be copied to flash. The "bootloader" and "ReplaceBootloader" are separate projects in the same workspace. ]

- Joe

0 Kudos

1,323 Views
converse
Senior Contributor V

In my projcts, I use 'incbin'. as if the binary file changes, it is easily rebuilt, without having to remember to do it manually. Also, the IDE will automatically include it in the linker.

But if you want to do it your way, you just need to add the blob object files to the linker by adding it to the list of 'Other objects' on the Linker 'Miscellaneous' settings.

0 Kudos

1,323 Views
jdupre
Contributor II

Thanks.  Can you provide a sample of how you used incbin?  I'm not that versed in assembly.

I was able to add the extra object file as you described.  I only had to add

     --rename-section .data=.rodata,alloc,load,readonly,data,contents

to my objcopy command so that the binary object stayed in flash rather than getting loaded to RAM.

0 Kudos