[firmware] move board_init() to a gcc-type constructor
authorHarald Welte <laforge@gnumonks.org>
Thu, 24 Jun 2010 16:00:45 +0000 (18:00 +0200)
committerHarald Welte <laforge@gnumonks.org>
Thu, 24 Jun 2010 16:03:08 +0000 (18:03 +0200)
Instead of calling board_init() from every main() function explicitly,
we simply mark it as a constructor and have it called automagically

src/target/firmware/apps/compal_dsp_dump/main.c
src/target/firmware/apps/hello_world/main.c
src/target/firmware/apps/l1test/main.c
src/target/firmware/apps/layer1/main.c
src/target/firmware/board/compal_e88/init.c
src/target/firmware/board/compal_e99/init.c
src/target/firmware/board/gta0x/init.c
src/target/firmware/include/board.h
src/target/firmware/include/ctors.h

index a712611..282bce2 100644 (file)
@@ -57,9 +57,6 @@ const char *hr = "==============================================================
 
 int main(void)
 {
-       /* Initialize basic board support */
-       board_init();
-
        puts("\n\nCompal DSP data dumper\n");
        puts(hr);
 
index d1a566b..effbc90 100644 (file)
@@ -84,7 +84,6 @@ static void l1a_l23_rx_cb(uint8_t dlci, struct msgb *msg)
 
 int main(void)
 {
-       board_init();
        puts("\n\nHello World from " __FILE__ " program code\n");
        puts(hr);
        /* Dump device identification */
index 384820c..6e78f9c 100644 (file)
@@ -179,7 +179,6 @@ static void key_handler(enum key_codes code, enum key_states state);
 
 int main(void)
 {
-       board_init();
        puts("\n\nHello World from " __FILE__ " program code\n");
 
        puts(hr);
index a408123..cf45d7f 100644 (file)
@@ -68,7 +68,6 @@ static void key_handler(enum key_codes code, enum key_states state);
 
 int main(void)
 {
-       board_init();
        puts("\n\nHello World from " __FILE__ " program code\n");
 
        puts(hr);
index 83cb482..9458675 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 
 #include <debug.h>
+#include <ctors.h>
 #include <memory.h>
 #include <board.h>
 #include <keypad.h>
@@ -72,7 +73,7 @@ static void board_io_init(void)
        writew(reg, ARMIO_LATCH_OUT);
 }
 
-void board_init(void)
+static void __ctor_board board_init(void)
 {
        /* FIXME: this needs to go to board_e99/init.c once we have it */
        wdog_enable(0);
index 8e0ce13..b2cdd7b 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 
 #include <debug.h>
+#include <ctors.h>
 #include <memory.h>
 #include <board.h>
 #include <keypad.h>
@@ -73,7 +74,7 @@ static void board_io_init(void)
        writew(reg, ARMIO_LATCH_OUT);
 }
 
-void board_init(void)
+static void __ctor_board board_init(void)
 {
        /* FIXME: this needs to go to board_e99/init.c once we have it */
        wdog_enable(0);
index 12105c5..4dca2e1 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 
 #include <debug.h>
+#include <ctors.h>
 #include <memory.h>
 #include <board.h>
 #include <keypad.h>
@@ -72,7 +73,7 @@ static void board_io_init(void)
        writew(reg, ARMIO_LATCH_OUT);
 }
 
-void board_init(void)
+static void __ctor_board board_init(void)
 {
        /* FIXME: this needs to go to board_e99/init.c once we have it */
        wdog_enable(0);
index 3635621..c2fb601 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef _BOARD_H
 #define _BOARD_H
 
-void board_init(void);
-
 extern const char *target_board;
 
 #endif /* _BOARD_H */
index b0d738d..ee4c7b3 100644 (file)
@@ -1,6 +1,15 @@
 #ifndef _CTORS_H
 #define _CTORS_H
 
+#if 0
+/* only supported by gcc 3.4 or later */
+#define __ctor_data    __attribute__ ((constructor) (100))
+#define __ctor_board   __attribute__ ((constructor) (200))
+#else
+#define __ctor_data    __attribute__ ((constructor))
+#define __ctor_board   __attribute__ ((constructor))
+#endif
+
 /* iterate over list of constructor functions and call each element */
 void do_global_ctors(const char *ctors_start, const char *ctors_end);