[U-Boot] [WIP, PATCH] initcall: An outline of the idea

Laurence Withers lwithers at guralp.com
Sun Mar 4 12:58:27 CET 2012

On Sat, Mar 03, 2012 at 11:46:01PM +1100, Graeme Russ wrote:
> > Perhaps the macro could be expanded to include a prototype for the function,
> How so - Can you provide a code example?

Sure, since all the functions are int(*)(void), just something like this:

+#define INIT_FUNC(fn, init_name, deps) \
+    static int ##fn (void); \
+    static const char __init_func_ ## fn[] __used \
+    __attribute__((__section__(".initfuncs"))) = \
+    "(" #fn ":" #init_name ";" #deps ")\n";

(I'm guessing static is OK for this use case?).

The patch overall looks like it will make it a lot simpler to understand and
change the sequence initialisation functions are called, which is a very good
thing. I'm just mindful of getting easy-to-diagnose error messages back when
things go wrong.

An example:

	static int f1(int x)
		return x + 1;

	#define INIT_FUNC(fn) \
		static void fn(int)


gcc immediately throws the following error:

	t2.c:9: error: conflicting types for ‘f1’
	t2.c:1: note: previous definition of ‘f1’ was here

which is pretty clear.

Bye for now,
Laurence Withers, <lwithers at guralp.com>                http://www.guralp.com/
Direct tel:+447753988197 or tel:+443333408643               Software Engineer
General support queries: <support at guralp.com>         CMG-DCM CMG-EAM CMG-NAM

More information about the U-Boot mailing list