[U-Boot] initcall revisited - A new idea to discuss

Wolfgang Denk wd at denx.de
Tue Jan 3 15:44:13 CET 2012


Dear Graeme,

In message <4F02DA64.60502 at 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

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Life sucks, but it's better than the alternative."
- Peter da Silva


More information about the U-Boot mailing list