Insert a binary resource

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

Insert a binary resource

2,282 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pfc on Tue Mar 18 05:26:04 MST 2014
I need to insert a binary image from file into my project. I just can't see how to add this as a resource into the IDE.  I have tried Properties - Resource - Linked Resources but I can't add anything here as there is no 'Add' button. I am going round in circles and I'm sure I'm missing something obvious.  A pointer in right direction would be appreciated. 
Labels (1)
0 Kudos
15 Replies

1,372 Views
ratheesht
Contributor II

Hi,

          Can someone give your suggestion ?

0 Kudos

1,372 Views
converse
Senior Contributor V

Create an assembler file (.s) and include something like this. The variable mydata and mydata_size are used to reference your binary data. Of course, these can be called anything that you want.

.section rodata
.global mydata
.type mydata, @object
.align 4

mydata:
.incbin "data.bin"

.global mydata_size
.type mydata_size, @object
.align 4
mydata_size:
.int mydata_size - mydata

1,372 Views
ratheesht
Contributor II

Hi

When I use object

i.e  .type mydata_size, @object

       .type mydata, @object

I get the following error

../src/aaa.s:11: Error: unrecognized symbol type " "

Can someone help me to solve the error explain with an example?

0 Kudos

1,372 Views
converse
Senior Contributor V

use

.type mydata, "object"

instead. The @ symbol is a comment, so it ignored the following text in my original example.

in C you want to use

extern int mydata, mydata_size ;

and then use &mydata for the start address of your data and mydata_size as the length of your data

0 Kudos

1,372 Views
ratheesht
Contributor II

Hi,

             I have tried that like below,

1. Created an assembly file and included the data as below

.section rodata

.global mydata
.type mydata, "object"
.align 4

mydata:
.incbin "blinky.bin"

.global mydata_size
.type mydata_size, "object"
.align 4

mydata_size:
.int mydata_size - mydata

NOTE : blinky.bin is my bin file with 3276 bytes in size

2. I have used the below in main .c file

extern int mydata,mydata_size;
static const int *ata ;

unsigned char flash[20];

int main(void) {

    ata  = &mydata;

memcpy(&flash, ata, 16);

}

It is building without error and warning.

here i am trying to copy of first 16 bytes of ata's data into array flash but is giving some wrong data.

i.e.

I have opened the blinky.bin file using HEX editor NEO.  It is having values like below (shown first 16 bytes only)

00 98 00 20 a5 04 00 20 ad 04 00 20 c5 04 00 20 but it is not matching with the values of array flash which was copied by ata (pointed by address of mydata).

3.

Without adding bin file (assembly file is not added), it shows the below at console tab.

make --no-print-directory post-build
Performing post-build steps
arm-none-eabi-size "ProxM_GTL.axf"; # arm-none-eabi-objcopy -v -O binary "ProxM_GTL.axf" "ProxM_GTL.bin" ; # checksum -p LPC54101J512 -d "ProxM_GTL.bin";
   text       data        bss        dec        hex    filename
  13148          0        408      13556       34f4    ProxM_GTL.axf

After Adding bin file (added of assembly file), it shows the below at console tab.

make --no-print-directory post-build
Performing post-build steps
arm-none-eabi-size "ProxM_GTL.axf"; # arm-none-eabi-objcopy -v -O binary "ProxM_GTL.axf" "ProxM_GTL.bin" ; # checksum -p LPC54101J512 -d "ProxM_GTL.bin";
   text       data        bss        dec        hex    filename
  13148          0        408      13556       34f4    ProxM_GTL.axf

My questions are ,

1. Whether i missed anything there in section 1&2 ? if it is correct what i have to do next ?

2. is there any other ways to complete this?

3. In section 3, both ways hex file size (34f4) was same, but I think it should be greater of 3276 in the bin file added project ,  is it correct or bin file is not included?

0 Kudos

1,372 Views
converse
Senior Contributor V

Perhaps you could post your project (export it, and attach the zip file to your post) so we can see what you are missing.

0 Kudos

1,372 Views
ratheesht
Contributor II

Hi,

I have attached my project here for your reference

here I have blocked .section sampleData in assembler file for checking and forget to remove while attaching .

Please enable that line in assembler file

0 Kudos

1,372 Views
converse
Senior Contributor V

You project, as supplied, works perfectly. The contents of the "flash" array is exactly the same as the first 20 bytes of the binary image.

What do you think is wrong?

0 Kudos

1,372 Views
ratheesht
Contributor II

Hi ,

             Thank you ...

it is working if i block .section rodata in the assembler file, then .section rodata line is required or not

0 Kudos

1,372 Views
ratheesht
Contributor II

Hi,  

      Thanks to your reply

I have followed your instructions and have some doubts. 

My questions are 

1. what do you mean object in both mydata & mydata_size ?

2. how can I utilise those in main.c file to retrieve bin file datas?

3. Can you explain that with an example? 

0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pfc on Tue Mar 18 07:36:50 MST 2014
Thanks - it has to be simple.  I will givge this a try.
0 Kudos

1,372 Views
ratheesht
Contributor II

Hi,

          I am using LPCXpresso_8.1.0_597 and LPC54102 board.

I am also in the same situation like above but not able to find the answer. 

my questions are

1. how do i create assembler file ?

2. How do i use .incbin directives? or .incbin is available anywhere in the project directory?

3. where i have to define labels of my bin file?

I have seen & understand the below descriptions from help but i don't know how to use this

Incbin - Using as

.incbin "file"[,skip[,count]]

The incbin directive includes file verbatim at the current location. You can control the search paths used with the ‘-I’ command-line option (see Command-Line Options). Quotation marks are required around file.

The skip argument skips a number of bytes from the start of the file. The count argument indicates the maximum number of bytes to read. Note that the data is not aligned in any way, so it is the user's responsibility to make sure that proper alignment is provided both before and after the incbin directive

Please guide me in a proper direction

0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Tue Mar 18 07:18:00 MST 2014
I'm not sure I understand why you think you need to do this, but you probably want to use the .incbin directive in the assembler. Basically,
- create an assembler file in your project
- use the assembler ".incbin" directive to include your binary data (search the Help for more information)
- define labels around your binary data so you know where this data starts and ends
- reference these labels in your C source
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pfc on Tue Mar 18 06:49:36 MST 2014
I have a project with a secondary bootloader that is working, and I can upload code from file on USB and execute this code.  However I now need to make some changes to the secondary bootloader so I plan to include the new .bin file for the secondary bootloader with the main project and then use this to flash the new sec. bootloader code in.  I need to be able to include this binary data and get a pointer to it so I can reprogram the sec. bootloader from it. 
0 Kudos

1,372 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Tue Mar 18 05:41:11 MST 2014
What type of resource are you trying to add? And what will you do with it once you have added it to the project?

If it is just a file, you can drag/drop it from a file browser into the Project Explorer.
0 Kudos