
Dear Graeme,
In message 4F02DA64.60502@gmail.com you wrote:
INITCALL(display_banner, "banner", "dram,board_early")
Which says that the display_banner() function, when completed fulfils the 'banner' dependency, and requires both the 'dram' and 'board_early' dependencies to be fulfilled in order to run
Sounds great!
OK, I think I can do this...
#define INIT_FUNC(fn, stage, reqs, prereqs, postreqs) \ static const char *__initfunc_ ## fn __used \ __attribute__((__section__(".initfuncs"))) = \ #stage ":" #fn ":" #reqs ":" #prereqs ":" #postreqs
'postreq' are requisite functions that the given function must be run before (USB init priot to console if using a USB serial dongle for example)
Then:
INIT_FUNC(cpu_init_f, f, "fred", "blah", "foo");
Generates the string: f:cpu_init_f:"fred":"blah":"foo"
and we can parse each of the elf archives to obtain a list of string pointers from the .initfuncs, extract the strings and process them to generate the init arrays
and add:
/DISCARD/ : { *(.initfuncs*) }
to the linker script to throw away the strings
It's a tad ugly under the hood, but the output will be very clean
Does this sound like a plan?
Yes. Looks good to me.
One thing comes to mind: it would be nice if we can find a way that the INIT_FUNC definitions behave similar to "weak" functions - if an init_func can be redefined / overwritten / modified by board specific code we eventually have a very nice way to get rid of the related #ifdef's.
Best regards,
Wolfgang Denk