Include a binary file into a section

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

Include a binary file into a section

3,126 Views
jul
Contributor I

Hello all,

 

I'm trying to include a binary file into the data section of my program using the INCLUDE directive in my linker script.

Everything seems ok except that the linker seems to treat the binary file as a text file.

 

My linker script looks like this:

 

blabla...

 

_RAMDISK_START = .;

INCLUDE ramdisk.img;

_RAMDISK_END=.;

 

blabla...

 

When i look in the linker map file, i can see that the difference between _RAMDISK_END and RAMDISK_START is correctly set to the size of my binary file but in the elf file, all the bytes are set to 0 (except the first ones which are text).

 

I'm using Codewarrior 10 (Eclipse). When i use CodeWarrior 7.2, everything is ok.

 

Can someone help me please?

 

Thank you.

Labels (1)
0 Kudos
1 Reply

474 Views
carlp
Contributor I

jul,

 

I am utterly amazed and befuddled by the gaping hole of accurate information on this subject given that this MIGHT be a somewhat common requirement in system firmware.

 

The CodeWarrior manuals have more than a couple of gaps in their many sections, watch your step.

 

Follow these directions... 

1) open the 'Settings' window for the project

2) move to the 'File Mappings' tab

    A) add the file extension type ('.img' for this example)

    B) set 'Compiler:' field to 'None'

    C) leave the 'File Type:' field empty

    D) set 'Edit Language:' field to 'None'

    E) set 'Flags:' to 'Resource File'

    F) press the 'Add' button

    G) press the 'Apply' button

2) move to the 'Access Paths' tab

    A) select 'User Paths'

    B) add the path to the binary file, and ensure that a checkmark is in the left column next to that path

    C) select the checkbox labelled 'Always Search User Paths'

3) in the Linker Command File (.LCF) DO NOT use the 'include' command, simply place the file name on a blank line by itself

    A) NOTE: the entire file name MUST be enclosed in double quotes ( " ) if there are any spaces or special characters in it.

    B) no semicolon ( ; ) is necessary, but it might not cause any stumbles ( not fully tested )

    C) simple file names may be included alone on their own line

    D) several binary files may be collected in a standard (and barely mentioned) '.BINARY' section similar to this (note the ALIGN command and symbol definitions):

 

  .BINARY :
  {
    /*
     the bitmaps need to be aligned on 32 byte boundaries
    */

    . = ALIGN (32);
    _BITMAP_A_IMG = .;  /* symbol available within program */
    "bitmap A.img"      /* note the double quotes */

    . = ALIGN (32);
    _BITMAP_B_IMG = .;  /* symbol available within program */
    bitmapB.img         /* note the lack of double quotes */

  } > dram_lo  /* MEMORY section defined somewhere above */



 

 

I believe I covered the major gaps to prevent injuries, but caution is the keyword.

 

Carl

 

0 Kudos