[U-Boot] [PATCH 15/15] bootm: refactor do_reset and os boot function args

Kumar Gala
2008-08-15T13:24:45Z

There is no need for each OS specific function to call do_reset()
we can just do it once in bootm. This means its feasible on an
error for the os boot function to return.

Also, remove passing in cmd_tbl_t as its not needed by the OS
boot functions. flag isn't currently used but might be in the future
so we left it alone.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
---
common/cmd_bootm.c | 67 +++++++++++++++++++++++++-----------------------
lib_arm/bootm.c | 10 +-----
lib_avr32/bootm.c | 10 +-----
lib_blackfin/bootm.c | 11 ++-----
lib_i386/bootm.c | 9 +-----
lib_m68k/bootm.c | 10 +-----
lib_microblaze/bootm.c | 10 +-----
lib_mips/bootm.c | 12 +-------
lib_nios/bootm.c | 4 +-
lib_nios2/bootm.c | 9 +-----
lib_ppc/bootm.c | 11 +++-----
lib_sh/bootm.c | 9 +-----
lib_sparc/bootm.c | 7 +---
13 files changed, 62 insertions(+), 117 deletions(-)

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 5f7458b..0db7b75 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -92,8 +92,7 @@ extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
* - loaded (first part of) image to header load address,
* - disabled interrupts.
*/
-typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
- int argc, char *argv[],
+typedef int boot_os_fn (int flag, int argc, char *argv[],
bootm_headers_t *images); /* pointers to os/initrd/fdt */

extern boot_os_fn do_bootm_linux;
@@ -428,36 +427,36 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
#ifdef CONFIG_SILENT_CONSOLE
fixup_silent_linux();
#endif
- do_bootm_linux (cmdtp, flag, argc, argv, &images);
+ do_bootm_linux (0, argc, argv, &images);
break;

case IH_OS_NETBSD:
- do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
+ do_bootm_netbsd (0, argc, argv, &images);
break;

#ifdef CONFIG_LYNXKDI
case IH_OS_LYNXOS:
- do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
+ do_bootm_lynxkdi (0, argc, argv, &images);
break;
#endif

case IH_OS_RTEMS:
- do_bootm_rtems (cmdtp, flag, argc, argv, &images);
+ do_bootm_rtems (0, argc, argv, &images);
break;

#if defined(CONFIG_CMD_ELF)
case IH_OS_VXWORKS:
- do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
+ do_bootm_vxworks (0, argc, argv, &images);
break;

case IH_OS_QNX:
- do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
+ do_bootm_qnxelf (0, argc, argv, &images);
break;
#endif

#ifdef CONFIG_ARTOS
case IH_OS_ARTOS:
- do_bootm_artos (cmdtp, flag, argc, argv, &images);
+ do_bootm_artos (0, argc, argv, &images);
break;
#endif
}
@@ -465,10 +464,8 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
show_boot_progress (-9);
#ifdef DEBUG
puts ("\n## Control returned to monitor - resetting...\n");
- do_reset (cmdtp, flag, argc, argv);
#endif
- if (iflag)
- enable_interrupts();
+ do_reset (cmdtp, flag, argc, argv);

return 1;
}
@@ -983,8 +980,7 @@ static void fixup_silent_linux ()
/* OS booting routines */
/*******************************************************************/

-static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
- int argc, char *argv[],
+static int do_bootm_netbsd (int flag, int argc, char *argv[],
bootm_headers_t *images)
{
void (*loader)(bd_t *, image_header_t *, char *, char *);
@@ -996,7 +992,7 @@ static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
#if defined(CONFIG_FIT)
if (!images->legacy_hdr_valid) {
fit_unsupported_reset ("NetBSD");
- do_reset (cmdtp, flag, argc, argv);
+ return 1;
}
#endif
hdr = images->legacy_hdr_os;
@@ -1063,11 +1059,12 @@ static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
* r6: boot args string
*/
(*loader) (gd->bd, os_hdr, consdev, cmdline);
+
+ return 1;
}

#ifdef CONFIG_LYNXKDI
-static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
- int argc, char *argv[],
+static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
bootm_headers_t *images)
{
image_header_t *hdr = &images->legacy_hdr_os_copy;
@@ -1075,16 +1072,17 @@ static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
#if defined(CONFIG_FIT)
if (!images->legacy_hdr_valid) {
fit_unsupported_reset ("Lynx");
- do_reset (cmdtp, flag, argc, argv);
+ return 1;
}
#endif

lynxkdi_boot ((image_header_t *)hdr);
+
+ return 1;
}
#endif /* CONFIG_LYNXKDI */

-static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
- int argc, char *argv[],
+static int do_bootm_rtems (int flag, int argc, char *argv[],
bootm_headers_t *images)
{
void (*entry_point)(bd_t *);
@@ -1092,7 +1090,7 @@ static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
#if defined(CONFIG_FIT)
if (!images->legacy_hdr_valid) {
fit_unsupported_reset ("RTEMS");
- do_reset (cmdtp, flag, argc, argv);
+ return 1;
}
#endif

@@ -1108,11 +1106,12 @@ static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
* r3: ptr to board info data
*/
(*entry_point)(gd->bd);
+
+ return 1;
}

#if defined(CONFIG_CMD_ELF)
-static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
- int argc, char *argv[],
+static int do_bootm_vxworks (int flag, int argc, char *argv[],
bootm_headers_t *images)
{
char str[80];
@@ -1120,17 +1119,18 @@ static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
#if defined(CONFIG_FIT)
if (!images->legacy_hdr_valid) {
fit_unsupported_reset ("VxWorks");
- do_reset (cmdtp, flag, argc, argv);
+ return 1;
}
#endif

sprintf(str, "%lx", images->ep); /* write entry-point into string */
setenv("loadaddr", str);
- do_bootvx(cmdtp, 0, 0, NULL);
+ do_bootvx(NULL, 0, 0, NULL);
+
+ return 1;
}

-static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
- int argc, char *argv[],
+static int do_bootm_qnxelf(int flag, int argc, char *argv[],
bootm_headers_t *images)
{
char *local_args[2];
@@ -1139,20 +1139,21 @@ static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
#if defined(CONFIG_FIT)
if (!images->legacy_hdr_valid) {
fit_unsupported_reset ("QNX");
- do_reset (cmdtp, flag, argc, argv);
+ return 1;
}
#endif

sprintf(str, "%lx", images->ep); /* write entry-point into string */
local_args[0] = argv[0];
local_args[1] = str; /* and provide it via the arguments */
- do_bootelf(cmdtp, 0, 2, local_args);
+ do_bootelf(NULL, 0, 2, local_args);
+
+ return 1;
}
#endif

#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
-static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
- int argc, char *argv[],
+static int do_bootm_artos (int flag, int argc, char *argv[],
bootm_headers_t *images)
{
ulong top;
@@ -1165,7 +1166,7 @@ static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
#if defined(CONFIG_FIT)
if (!images->legacy_hdr_valid) {
fit_unsupported_reset ("ARTOS");
- do_reset (cmdtp, flag, argc, argv);
+ return 1;
}
#endif

@@ -1237,5 +1238,7 @@ static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,

entry = (void (*)(bd_t *, char *, char **, ulong))images->ep;
(*entry) (kbd, cmdline, fwenv, top);
+
+ return 1;
}
#endif
diff --git a/lib_arm/bootm.c b/lib_arm/bootm.c
index f9f702f..6c2f37e 100644
--- a/lib_arm/bootm.c
+++ b/lib_arm/bootm.c
@@ -56,10 +56,7 @@ static void setup_videolfb_tag (gd_t *gd);
static struct tag *params;
#endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */

-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
-
-void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
bd_t *bd = gd->bd;
char *s;
@@ -128,11 +125,8 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],

theKernel (0, machid, bd->bi_boot_params);
/* does not return */
- return;
-
error:
- do_reset (cmdtp, flag, argc, argv);
- return;
+ return 1;
}

diff --git a/lib_avr32/bootm.c b/lib_avr32/bootm.c
index 762701f..8a6109d 100644
--- a/lib_avr32/bootm.c
+++ b/lib_avr32/bootm.c
@@ -34,8 +34,6 @@ DECLARE_GLOBAL_DATA_PTR;
/* CPU-specific hook to allow flushing of caches, etc. */
extern void prepare_to_boot(void);

-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
-
static struct tag *setup_start_tag(struct tag *params)
{
params->hdr.tag = ATAG_CORE;
@@ -173,8 +171,7 @@ static void setup_end_tag(struct tag *params)
params->hdr.size = 0;
}

-void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
void (*theKernel)(int magic, void *tagtable);
struct tag *params, *params_start;
@@ -205,9 +202,6 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],

theKernel(ATAG_MAGIC, params_start);
/* does not return */
- return;
-
error:
- do_reset (cmdtp, flag, argc, argv);
- return;
+ return 1;
}
diff --git a/lib_blackfin/bootm.c b/lib_blackfin/bootm.c
index f789e24..d0afb21 100644
--- a/lib_blackfin/bootm.c
+++ b/lib_blackfin/bootm.c
@@ -14,8 +14,6 @@
#include <image.h>
#include <asm/blackfin.h>

-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
-
#ifdef SHARED_RESOURCES
extern void swap_to(int device_id);
#endif
@@ -33,8 +31,7 @@ static char *make_command_line(void)
return dest;
}

-void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
int (*appl) (char *cmdline);
char *cmdline;
@@ -51,8 +48,6 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
dcache_disable();
(*appl) (cmdline);
/* does not return */
- return;
-
- error:
- do_reset (cmdtp, flag, argc, argv);
+error:
+ return 1;
}
diff --git a/lib_i386/bootm.c b/lib_i386/bootm.c
index 8c0b225..522d7ad 100644
--- a/lib_i386/bootm.c
+++ b/lib_i386/bootm.c
@@ -29,10 +29,7 @@
#include <asm/zimage.h>

/*cmd_boot.c*/
-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
-
-void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
void *base_ptr;
ulong os_data, os_len;
@@ -88,9 +85,7 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],

boot_zimage(base_ptr);
/* does not return */
- return;

error:
- do_reset (cmdtp, flag, argc, argv);
- return;
+ return 1;
}
diff --git a/lib_m68k/bootm.c b/lib_m68k/bootm.c
index 1c3b9c9..6504cc9 100644
--- a/lib_m68k/bootm.c
+++ b/lib_m68k/bootm.c
@@ -42,11 +42,8 @@ DECLARE_GLOBAL_DATA_PTR;

static ulong get_sp (void);
static void set_clocks_in_mhz (bd_t *kbd);
-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);

-void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
- int argc, char *argv[],
- bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
ulong sp;

@@ -116,11 +113,8 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
*/
(*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
/* does not return */
- return ;
-
error:
- do_reset (cmdtp, flag, argc, argv);
- return ;
+ return 1;
}

static ulong get_sp (void)
diff --git a/lib_microblaze/bootm.c b/lib_microblaze/bootm.c
index baf6d77..5986a31 100644
--- a/lib_microblaze/bootm.c
+++ b/lib_microblaze/bootm.c
@@ -32,10 +32,7 @@

DECLARE_GLOBAL_DATA_PTR;

-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
-
-void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
/* First parameter is mapped to $r5 for kernel boot args */
void (*theKernel) (char *);
@@ -52,9 +49,6 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],

theKernel (commandline);
/* does not return */
- return;
-
error:
- do_reset (cmdtp, flag, argc, argv);
- return;
+ return 1;
}
diff --git a/lib_mips/bootm.c b/lib_mips/bootm.c
index 9869c33..c1bf21e 100644
--- a/lib_mips/bootm.c
+++ b/lib_mips/bootm.c
@@ -43,15 +43,11 @@ static int linux_env_idx;
static void linux_params_init (ulong start, char * commandline);
static void linux_env_set (char * env_name, char * env_val);

-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
-
-void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
void (*theKernel) (int, char **, char **, int *);
char *commandline = getenv ("bootargs");
char env_buf[12];
- int ret;
char *cp;

/* find kernel entry point */
@@ -103,11 +99,7 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],

theKernel (linux_argc, linux_argv, linux_env, 0);
/* does not return */
- return;
-
-error:
- do_reset (cmdtp, flag, argc, argv);
- return;
+ return 1;
}

static void linux_params_init (ulong start, char *line)
diff --git a/lib_nios/bootm.c b/lib_nios/bootm.c
index fb2e9b5..b0d5b82 100644
--- a/lib_nios/bootm.c
+++ b/lib_nios/bootm.c
@@ -28,7 +28,7 @@
* we can get this working. ;-)
*
*/
-void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
+ return 1;
}
diff --git a/lib_nios2/bootm.c b/lib_nios2/bootm.c
index c74b5d6..c0be4fd 100644
--- a/lib_nios2/bootm.c
+++ b/lib_nios2/bootm.c
@@ -25,10 +25,7 @@
#include <command.h>
#include <asm/byteorder.h>

-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
-
-void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
void (*kernel)(void) = (void (*)(void))images->ep;

@@ -37,9 +34,7 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
*/
kernel ();
/* does not return */
- return;

error:
- do_reset (cmdtp, flag, argc, argv);
- return;
+ return 1;
}
diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c
index 9892afa..348421f 100644
--- a/lib_ppc/bootm.c
+++ b/lib_ppc/bootm.c
@@ -47,7 +47,6 @@

DECLARE_GLOBAL_DATA_PTR;

-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
extern ulong get_effective_memsize(void);
static ulong get_sp (void);
static void set_clocks_in_mhz (bd_t *kbd);
@@ -56,9 +55,8 @@ static void set_clocks_in_mhz (bd_t *kbd);
#define CFG_LINUX_LOWMEM_MAX_SIZE (768*1024*1024)
#endif

-void __attribute__((noinline))
-do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t *images)
+__attribute__((noinline))
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
ulong sp;

@@ -234,11 +232,10 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
cmd_start, cmd_end, 0, 0);
/* does not return */
}
- return ;
+ return 1;

error:
- do_reset (cmdtp, flag, argc, argv);
- return ;
+ return 1;
}

static ulong get_sp (void)
diff --git a/lib_sh/bootm.c b/lib_sh/bootm.c
index 9d2c908..e92c848 100644
--- a/lib_sh/bootm.c
+++ b/lib_sh/bootm.c
@@ -43,8 +43,6 @@

#define RAMDISK_IMAGE_START_MASK 0x07FF

-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
-
#ifdef CFG_DEBUG
static void hexdump (unsigned char *buf, int len)
{
@@ -59,8 +57,7 @@ static void hexdump (unsigned char *buf, int len)
}
#endif

-void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
{
char *bootargs = getenv("bootargs");

@@ -72,9 +69,7 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],

kernel();
/* does not return */
- return;

error:
- do_reset (cmdtp, flag, argc, argv);
- return;
+ return 1;
}
diff --git a/lib_sparc/bootm.c b/lib_sparc/bootm.c
index f3abdcf..4e8c920 100644
--- a/lib_sparc/bootm.c
+++ b/lib_sparc/bootm.c
@@ -33,7 +33,6 @@
extern image_header_t header;
extern void srmmu_init_cpu(unsigned int entry);
extern void prepare_bootargs(char *bootargs);
-extern int do_reset(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);

#ifdef CONFIG_USB_UHCI
extern int usb_lowlevel_stop(void);
@@ -83,8 +82,7 @@ struct __attribute__ ((packed)) {
image_header_t ihdr;

/* boot the linux kernel */
-void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
- bootm_headers_t * images)
+int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t * images)
{
char *bootargs;
ulong initrd_start, initrd_end;
@@ -181,6 +179,5 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
while (1) ;

error:
- do_reset(cmdtp, flag, argc, argv);
- return;
+ return 1;
}
--
1.5.5.1