gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Trying to link a binary file to a GCC rom???? Help?

#287 - notron - Sun Jan 05, 2003 11:11 pm

I am trying to link a pure binary file to a compiled C image using GCC (G++) and following the instructions from the FAQ at DEVRS/GBA.
quoting....................................................................................
5) *** Convert your data to .o (gcc object) file #2 ***
If you are using DevKitAdv, or crtls v1.2 or later, then you can use the following technique without needing to modify your lnkscript. Do the following:
objcopy -I binary -O elf32-little in_file out_file.all.rodata.ext
(Ignore the "architecture UNKNOWN" warning message.)
This will force the lnkscript to put all sections in this file into the .rodata (read-only data / ROM) section. To be able to access this data from your C code use the following:
typedef unsigned char u8;
extern const u8 _binary_outname_all_rodata_ext_start [ ];
(The symbols _binary_outname_all_rodata_ext_size & _binary_outname_all_rodata_ext_end are also available. However, the "size" symbol seems to be an address to a value rather than the value itself so you may need to do -> (u32)&_binary..._size )
endquoting...................................................................................

Everything works fine as far as actually causing the binary image to be appended to the rom image. But when I try to access the binary data using the predefined _binary_<outname>_all_rodata_<ext>_start[] construct, the linker always gives me an unresolved external reference.
It seems like the objcopy routine does not create the symbol in its symbol table using the method above.

Any help on resolving this would be much appreciated.
_________________
MysticX is The Defender

#293 - Touchstone - Mon Jan 06, 2003 1:12 am

Not that this really helps but a generic tip is to open your object file in a binary editor and search for something that looks like your symbol. I'm thinking that maybe there's something like an additional underscore or something in the symbolname that's causing your headache. You could try and remove the reference to your symbol so you can atleast link the executable and generate a mapfile, that way you can have a look in the map file and search for your symbol there. This isn't really recommended because the data might get optimized away so the symbol don't even make it to the mapfile. Uhm.

#295 - notron - Mon Jan 06, 2003 1:39 am

Touch,
thanks again. I searched out the label in the 'o' file for the binary that i was trying to append and found that the label that objcopy is creating for the section of data is entitled:
_binary_<infile_name>_<infile_ext>_start

rather than the
_binary_<outfile_name>_all_roda_<outfile_ext>_start

construction that is posted in the FAQ on the DEVERS/GBA website.

I will send Jeff F a note to let him know of the difference. Once I changed it, Presto! everything linked perfectly!
_________________
MysticX is The Defender

#299 - MrMr[iCE] - Mon Jan 06, 2003 2:36 am

On gbadev.org, in tools, misc section, theres a file called bin2o, by Anli (Not to be confused with the bin2o that comes with devkit advance, the packaged bin2o is not too useable from what I hear)
This program has worked perfectly for me everytime to generate .o files
to link to my projects (for const data at least):

bin2o /const /interwork infile.bin outfile.o identifier

for example, if I had a file of raw pixel data for an image:

bin2o /const /interwork image.raw image.o imageData

and in C you would:
extern const u16 imageData[];

if you happen to have lots of little .o files and dont wish to change your
link line everytime you add another .o, you could also do:

ar rc resource.a file1.o file2.o file3.o....

That will create the file resource.a, which is an archive of all the .o files
you passed in to ar. Link to your project as you would a .o file, and you're
set.
_________________
Does the corpse have a familiar face?

#306 - notron - Mon Jan 06, 2003 3:05 am

MrMr,

Thanks for the tip. I will check it out as well as the archive creator.
_________________
MysticX is The Defender