public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] ppc: transform init_sequence into a function.
@ 2010-12-06 17:59 Joakim Tjernlund
  2010-12-06 20:09 ` Wolfgang Denk
  0 siblings, 1 reply; 33+ messages in thread
From: Joakim Tjernlund @ 2010-12-06 17:59 UTC (permalink / raw)
  To: u-boot

init_sequence is an array with function pointers which
are really hard to follow when you need to debug this area.
Turn it into plain function calls instead which makes
the code a bit uglier but I find the simpler debugging
much more valuable.

An added bonus is that it is smaller too:
   text	   data	    bss	    dec	    hex	filename
   1268	    212	      0	   1480	    5c8	lib_ppc/board.org
   1224	     92	      0	   1316	    524	lib_ppc/board.new

Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
---

 So I had to do debug this area again and I am getting really
 tiered of following function pointers so here goes
 my old patch again.

 arch/powerpc/lib/board.c |  123 +++++++++++++++++++++++++++++++++---------------------
 1 files changed, 75 insertions(+), 48 deletions(-)

diff --git a/arch/powerpc/lib/board.c b/arch/powerpc/lib/board.c
index 765f97a..f0160e6 100644
--- a/arch/powerpc/lib/board.c
+++ b/arch/powerpc/lib/board.c
@@ -157,7 +157,6 @@ ulong monitor_flash_len;
  * argument, and returns an integer return code, where 0 means
  * "continue" and != 0 means "fatal error, hang the system".
  */
-typedef int (init_fnc_t) (void);
 
 /************************************************************************
  * Init Utilities							*
@@ -236,17 +235,17 @@ static int init_func_watchdog_init (void)
 	WATCHDOG_RESET ();
 	return (0);
 }
-# define INIT_FUNC_WATCHDOG_INIT	init_func_watchdog_init,
+# define INIT_FUNC_WATCHDOG_INIT	init_func_watchdog_init()
 
 static int init_func_watchdog_reset (void)
 {
 	WATCHDOG_RESET ();
 	return (0);
 }
-# define INIT_FUNC_WATCHDOG_RESET	init_func_watchdog_reset,
+# define INIT_FUNC_WATCHDOG_RESET	init_func_watchdog_reset()
 #else
-# define INIT_FUNC_WATCHDOG_INIT	/* undef */
-# define INIT_FUNC_WATCHDOG_RESET	/* undef */
+# define INIT_FUNC_WATCHDOG_INIT	0 /* undef */
+# define INIT_FUNC_WATCHDOG_RESET	0 /* undef */
 #endif /* CONFIG_WATCHDOG */
 
 /************************************************************************
@@ -254,76 +253,110 @@ static int init_func_watchdog_reset (void)
  ************************************************************************
  */
 
-init_fnc_t *init_sequence[] = {
+void init_sequence(void)
+{
 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
-	probecpu,
+	if (probecpu())
+		goto err_out;
 #endif
 #if defined(CONFIG_BOARD_EARLY_INIT_F)
-	board_early_init_f,
+	if (board_early_init_f())
+		goto err_out;
 #endif
 #if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
-	get_clocks,		/* get CPU and bus clocks (etc.) */
+	if (get_clocks())
+		goto err_out;	/* get CPU and bus clocks (etc.) */
 #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M) \
     && !defined(CONFIG_TQM885D)
-	adjust_sdram_tbs_8xx,
+	if (adjust_sdram_tbs_8xx())
+		goto err_out;
 #endif
-	init_timebase,
+	if (init_timebase())
+		goto err_out;
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
 #if !defined(CONFIG_CPM2)
-	dpram_init,
+	if (dpram_init())
+		goto err_out;
 #endif
 #endif
 #if defined(CONFIG_BOARD_POSTCLK_INIT)
-	board_postclk_init,
+	if (board_postclk_init())
+		goto err_out;
 #endif
-	env_init,
+	if (env_init())
+		goto err_out;
 #if defined(CONFIG_8xx_CPUCLK_DEFAULT)
-	get_clocks_866,		/* get CPU and bus clocks according to the environment variable */
-	sdram_adjust_866,	/* adjust sdram refresh rate according to the new clock */
-	init_timebase,
-#endif
-	init_baudrate,
-	serial_init,
-	console_init_f,
-	display_options,
+	if (get_clocks_866())
+		goto err_out;	/* get CPU and bus clocks according to the environment variable */
+	if (sdram_adjust_866())
+		goto err_out;	/* adjust sdram refresh rate according to the new clock */
+	if (init_timebase())
+		goto err_out;
+#endif
+	if (init_baudrate())
+		goto err_out;
+	if (serial_init())
+		goto err_out;
+	if (console_init_f())
+		goto err_out;
+	if (display_options())
+		goto err_out;
 #if defined(CONFIG_8260)
-	prt_8260_rsr,
-	prt_8260_clks,
+	if (prt_8260_rsr())
+		goto err_out;
+	if (prt_8260_clks())
+		goto err_out;
 #endif /* CONFIG_8260 */
 #if defined(CONFIG_MPC83xx)
-	prt_83xx_rsr,
+	if (prt_83xx_rsr())
+		goto err_out;
 #endif
-	checkcpu,
+	if (checkcpu())
+		goto err_out;
 #if defined(CONFIG_MPC5xxx)
-	prt_mpc5xxx_clks,
+	if (prt_mpc5xxx_clks())
+		goto err_out;
 #endif /* CONFIG_MPC5xxx */
 #if defined(CONFIG_MPC8220)
-	prt_mpc8220_clks,
+	if (prt_mpc8220_clks())
+		goto err_out;
 #endif
-	checkboard,
-	INIT_FUNC_WATCHDOG_INIT
+	if (checkboard())
+		goto err_out;
+	if (INIT_FUNC_WATCHDOG_INIT)
+		goto err_out;
 #if defined(CONFIG_MISC_INIT_F)
-	misc_init_f,
+	if (misc_init_f())
+		goto err_out;
 #endif
-	INIT_FUNC_WATCHDOG_RESET
+	if (INIT_FUNC_WATCHDOG_RESET)
+		goto err_out;
 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
-	init_func_i2c,
+	if (init_func_i2c())
+		goto err_out;
 #endif
 #if defined(CONFIG_HARD_SPI)
-	init_func_spi,
+	if (init_func_spi())
+		goto err_out;
 #endif
 #ifdef CONFIG_POST
-	post_init_f,
+	if (post_init_f())
+		goto err_out;
 #endif
-	INIT_FUNC_WATCHDOG_RESET
-	init_func_ram,
+	if (INIT_FUNC_WATCHDOG_RESET)
+		goto err_out;
+	if (init_func_ram())
+		goto err_out;
 #if defined(CONFIG_SYS_DRAM_TEST)
-	testdram,
+	if (testdram())
+		goto err_out;
 #endif /* CONFIG_SYS_DRAM_TEST */
-	INIT_FUNC_WATCHDOG_RESET
-
-	NULL,			/* Terminate this list */
+	if (INIT_FUNC_WATCHDOG_RESET)
+		goto err_out;
+	return;
+err_out:
+	hang();
 };
 
 ulong get_effective_memsize(void)
@@ -366,7 +399,6 @@ void board_init_f (ulong bootflag)
 	ulong len, addr, addr_sp;
 	ulong *s;
 	gd_t *id;
-	init_fnc_t **init_fnc_ptr;
 #ifdef CONFIG_PRAM
 	int i;
 	ulong reg;
@@ -383,12 +415,7 @@ void board_init_f (ulong bootflag)
 	/* Clear initial global data */
 	memset ((void *) gd, 0, sizeof (gd_t));
 #endif
-
-	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
-		if ((*init_fnc_ptr) () != 0) {
-			hang ();
-		}
-	}
+	init_sequence();
 
 	/*
 	 * Now that we have DRAM mapped and working, we can
-- 
1.6.4.4

^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2010-12-07 13:57 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <OF012B1DA7.446FFBCD-ONC125767B.004DD4EE-C125767B.00508FF3@trans mode.se>
2009-11-27 10:32 ` [U-Boot] [PATCH] ppc: transform init_sequence into a function Joakim Tjernlund
2009-11-27 14:06   ` Wolfgang Denk
2009-11-27 14:39     ` Joakim Tjernlund
2009-11-27 20:18       ` Wolfgang Denk
2009-11-28 13:56         ` Joakim Tjernlund
2009-11-30 12:36         ` Joakim Tjernlund
2009-11-30 21:02           ` Wolfgang Denk
2009-11-30 22:27             ` Joakim Tjernlund
2009-11-30 23:27               ` Wolfgang Denk
2009-12-01 10:43                 ` Detlev Zundel
     [not found]     ` <OF012B1DA7.446FFBCD-ONC125767B.004DD4EE-C125767B.00508FF3@tran smode.se>
2009-11-27 14:54       ` Alessandro Rubini
2009-11-27 15:01         ` Joakim Tjernlund
2010-12-06 17:59 Joakim Tjernlund
2010-12-06 20:09 ` Wolfgang Denk
2010-12-06 20:42   ` Joakim Tjernlund
2010-12-06 21:33     ` Scott Wood
2010-12-06 22:36       ` Graeme Russ
2010-12-06 22:49         ` Scott Wood
2010-12-06 23:04           ` Graeme Russ
2010-12-06 23:12             ` Scott Wood
2010-12-06 23:13             ` Wolfgang Denk
2010-12-07  0:07           ` Joakim Tjernlund
2010-12-07  0:21             ` Scott Wood
2010-12-07  0:41               ` Joakim Tjernlund
2010-12-07  0:59                 ` Scott Wood
2010-12-06 23:09         ` Wolfgang Denk
2010-12-06 22:36     ` Wolfgang Denk
2010-12-06 23:06       ` Graeme Russ
2010-12-07  0:32       ` Joakim Tjernlund
2010-12-07  6:34         ` Wolfgang Denk
2010-12-07  9:08           ` Joakim Tjernlund
2010-12-07 13:07             ` Wolfgang Denk
2010-12-07 13:57               ` Joakim Tjernlund

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox