[arm-gnu] how to locate a const struct in memory (ld question)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[arm-gnu] how to locate a const struct in memory (ld question)
- To: arm-gnu@xxxxxxxxxxxxxxxx
- Subject: [arm-gnu] how to locate a const struct in memory (ld question)
- From: "Andrew Kohlsmith (mailing lists account)" <aklists@xxxxxxxxxx>
- Date: Fri, 7 May 2010 15:17:13 -0400
Good afternoon, everyone,
I'm working on an ARM7 (LPC2103) design and have a generic linker question
regarding locating a data structure in ROM.
Essentially I have a bootloader in flash sector 0 which will never be
overwritten. The bootloader is much smaller than the 4kB sector size, so I
have padded it out with some low-level functions which are unlikely to ever
need to be updated. (If the end up needing to be updated, the application can
just use its own version instead of calling the bootloader's version.
I've built up a structure of function pointers which the bootloader has in its
memory space:
bootloader_funcs.h:
typedef struct {
void (* const cli)(void);
void (* const sti)(void);
void (* const doze)(void)
void (* const oled_init)(void);
int (* const timer_get_ms)(void);
/* etc */
} bl_func_struct;
extern const bl_func_struct bl_funcs;
And then the bootloader has a .c file which actually allocates and initializes
this structure:
bootloader_funcs.c:
const bl_func_struct bl_funcs = {
.cli = cli,
.sti = sti,
.doze = doze,
/* etc. */
};
Now this compiles and the code looks about right for what I'd expect. The main
(upgradeable) application accesses this structure like this:
#include <bootloader_funcs.h>
#define cli bl_funcs.cli()
#define doze bl_funcs.doze()
etc. I've experimented with using inline void cli(void) { bl.funcs.cli(); }
and other means, and if anyone has any suggestions on how to better write this
I'm open to suggestions. :-) I don't like the #defines, personally.
Now, much to my chagrin, I find that when I use -ffunction-sections and -fdata-
sections so that I can place the bl_funcs struct at a specific location that it
does not work. I don't get a specific section for bl_funcs, although I do get
specific sections for the various functions (cli, sti, etc.) and also for their
variables. Objdump -t shows me that bl_funcs has no section name at all:
0000e20 g O 00000068 bl_funcs
'g' says it's global and O says it's an object, which I suppose is right.
Is there a way to specify a specific location for a specific object, or perhaps
should I be declaring the structure differently so that I can get a section out
of it for ld to put at a specific location?
Finally, right now the bootloader and the application are built at the same
time, so the linker is resolving bl_funcs for the application's extern
declaration. Do I use the linker PROVIDE() function to do this when the
bootloader is removed from the image?
Thanks for your assistance,
-A.