avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Including a binary file as resource


From: Andy Warner
Subject: Re: [avr-gcc-list] Including a binary file as resource
Date: Fri, 17 Dec 2004 10:32:01 -0600
User-agent: Mutt/1.2.5i

Marek Michalkiewicz wrote:
> [...]
> No need to write a special converter, it can be done with existing
> tools - see linux/arch/mips/ramdisk/ for an example, where a simple
> ld script is used for linking a ramdisk image into the kernel.

Excellent reference.. let me try and take it closer to our world:

That example puts the entire file in it's own section (".initrd")
within the elf file. For avr work, we probably want to just dump
in in either flash or eeprom (sections .text or .eeprom respectively.)

If we mutate ld.script to be something like:

OUTPUT_FORMAT("elf32-avr")
OUTPUT_ARCH(avr:2)
SECTIONS
{
        .text :
        {
        *(.data)
        }
}

Which, used with this avr-ld command will create a .o file:

avr-ld -T ld.script -b binary -o foo.o testdata

(where "testdata" is the name of the file containing the binary data)

Which gives us a .o file that we can link in with
our other object files.

$ avr-nm foo.o
0000000e T _binary_testdata_end
0000000e A _binary_testdata_size
00000000 T _binary_testdata_start
$

The linker has conveniently supplied variables with the
start address, end address and size of the data. The
names seem to be fixed as _binary_<filename>_end etc.
To access these variables from within your program,
you will probably need a declaration along the lines of

extern PGM_VOID_P       _binary_testdata_start ;

And access it using the standard program space functions,
e.g. pgm_read_byte(), memcpy_P(), strcat_P() etc.

With minor modifications, the same would apply to .eeprom, I
believe.

My example hardcodes the effect of the -mcu=xxxx gcc switch
on the choice of linker arguments (resulting in the hardcoded
OUTPUT_FORMAT/ARCH statements above.) Can someone more
versed in the gcc->ld invocation runes help out with
the avr-gcc line that will let us drop this into a standard
makefile with $(CC) $(CFLAGS) etc, instead of hardcoding that
knowledge into ld.script ?
-- 
address@hidden

Andy Warner             Voice: (612) 801-8549   Fax: (208) 575-5634


reply via email to

[Prev in Thread] Current Thread [Next in Thread]