bootm: refactor entry point code

Move entry point code out of each arch and into common code.
Keep the entry point in the bootm_headers_t images struct.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
This commit is contained in:
Kumar Gala 2008-08-15 08:24:36 -05:00 committed by Wolfgang Denk
parent 20220d22b9
commit c160a95447
12 changed files with 37 additions and 182 deletions

View File

@ -205,6 +205,23 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
return 1; return 1;
} }
/* find kernel entry point */
if (images.legacy_hdr_valid) {
images.ep = image_get_ep (&images.legacy_hdr_os_copy);
#if defined(CONFIG_FIT)
} else if (images.fit_uname_os) {
ret = fit_image_get_entry (images.fit_hdr_os,
images.fit_noffset_os, &images.ep);
if (ret) {
puts ("Can't get entry point property!\n");
return 1;
}
#endif
} else {
puts ("Could not find kernel entry point!\n");
return 1;
}
image_start = (ulong)os_hdr; image_start = (ulong)os_hdr;
load_end = 0; load_end = 0;
type_name = genimg_get_type_name (type); type_name = genimg_get_type_name (type);
@ -942,7 +959,7 @@ static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
cmdline = ""; cmdline = "";
} }
loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr); loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n", printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
(ulong)loader); (ulong)loader);
@ -981,7 +998,6 @@ static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
int argc, char *argv[], int argc, char *argv[],
bootm_headers_t *images) bootm_headers_t *images)
{ {
image_header_t *hdr = &images->legacy_hdr_os_copy;
void (*entry_point)(bd_t *); void (*entry_point)(bd_t *);
#if defined(CONFIG_FIT) #if defined(CONFIG_FIT)
@ -991,7 +1007,7 @@ static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
} }
#endif #endif
entry_point = (void (*)(bd_t *))image_get_ep (hdr); entry_point = (void (*)(bd_t *))images->ep;
printf ("## Transferring control to RTEMS (at address %08lx) ...\n", printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
(ulong)entry_point); (ulong)entry_point);
@ -1011,7 +1027,6 @@ static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
bootm_headers_t *images) bootm_headers_t *images)
{ {
char str[80]; char str[80];
image_header_t *hdr = &images->legacy_hdr_os_copy;
#if defined(CONFIG_FIT) #if defined(CONFIG_FIT)
if (!images->legacy_hdr_valid) { if (!images->legacy_hdr_valid) {
@ -1020,7 +1035,7 @@ static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
} }
#endif #endif
sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ sprintf(str, "%lx", images->ep); /* write entry-point into string */
setenv("loadaddr", str); setenv("loadaddr", str);
do_bootvx(cmdtp, 0, 0, NULL); do_bootvx(cmdtp, 0, 0, NULL);
} }
@ -1031,7 +1046,6 @@ static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
{ {
char *local_args[2]; char *local_args[2];
char str[16]; char str[16];
image_header_t *hdr = &images->legacy_hdr_os_copy;
#if defined(CONFIG_FIT) #if defined(CONFIG_FIT)
if (!images->legacy_hdr_valid) { if (!images->legacy_hdr_valid) {
@ -1040,7 +1054,7 @@ static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
} }
#endif #endif
sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ sprintf(str, "%lx", images->ep); /* write entry-point into string */
local_args[0] = argv[0]; local_args[0] = argv[0];
local_args[1] = str; /* and provide it via the arguments */ local_args[1] = str; /* and provide it via the arguments */
do_bootelf(cmdtp, 0, 2, local_args); do_bootelf(cmdtp, 0, 2, local_args);
@ -1058,7 +1072,6 @@ static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
int i, j, nxt, len, envno, envsz; int i, j, nxt, len, envno, envsz;
bd_t *kbd; bd_t *kbd;
void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top); void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
image_header_t *hdr = &images->legacy_hdr_os_copy;
#if defined(CONFIG_FIT) #if defined(CONFIG_FIT)
if (!images->legacy_hdr_valid) { if (!images->legacy_hdr_valid) {
@ -1133,7 +1146,7 @@ static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
} }
*ss++ = NULL; /* terminate */ *ss++ = NULL; /* terminate */
entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr); entry = (void (*)(bd_t *, char *, char **, ulong))images->ep;
(*entry) (kbd, cmdline, fwenv, top); (*entry) (kbd, cmdline, fwenv, top);
} }
#endif #endif

View File

@ -219,6 +219,8 @@ typedef struct bootm_headers {
#endif #endif
#endif #endif
ulong ep; /* entry point of OS */
int verify; /* getenv("verify")[0] != 'n' */ int verify; /* getenv("verify")[0] != 'n' */
struct lmb *lmb; /* for memory mgmt */ struct lmb *lmb; /* for memory mgmt */
} bootm_headers_t; } bootm_headers_t;

View File

@ -62,7 +62,6 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
bootm_headers_t *images) bootm_headers_t *images)
{ {
ulong initrd_start, initrd_end; ulong initrd_start, initrd_end;
ulong ep = 0;
bd_t *bd = gd->bd; bd_t *bd = gd->bd;
char *s; char *s;
int machid = bd->bi_arch_number; int machid = bd->bi_arch_number;
@ -73,23 +72,7 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
char *commandline = getenv ("bootargs"); char *commandline = getenv ("bootargs");
#endif #endif
/* find kernel entry point */ theKernel = (void (*)(int, int, uint))images->ep;
if (images->legacy_hdr_valid) {
ep = image_get_ep (&images->legacy_hdr_os_copy);
#if defined(CONFIG_FIT)
} else if (images->fit_uname_os) {
ret = fit_image_get_entry (images->fit_hdr_os,
images->fit_noffset_os, &ep);
if (ret) {
puts ("Can't get entry point property!\n");
goto error;
}
#endif
} else {
puts ("Could not find kernel entry point!\n");
goto error;
}
theKernel = (void (*)(int, int, uint))ep;
s = getenv ("machid"); s = getenv ("machid");
if (s) { if (s) {

View File

@ -177,29 +177,12 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
bootm_headers_t *images) bootm_headers_t *images)
{ {
ulong initrd_start, initrd_end; ulong initrd_start, initrd_end;
ulong ep = 0;
void (*theKernel)(int magic, void *tagtable); void (*theKernel)(int magic, void *tagtable);
struct tag *params, *params_start; struct tag *params, *params_start;
char *commandline = getenv("bootargs"); char *commandline = getenv("bootargs");
int ret; int ret;
/* find kernel entry point */ theKernel = (void *)images->ep;
if (images->legacy_hdr_valid) {
ep = image_get_ep (&images->legacy_hdr_os_copy);
#if defined(CONFIG_FIT)
} else if (images->fit_uname_os) {
ret = fit_image_get_entry (images->fit_hdr_os,
images->fit_noffset_os, &ep);
if (ret) {
puts ("Can't get entry point property!\n");
goto error;
}
#endif
} else {
puts ("Could not find kernel entry point!\n");
goto error;
}
theKernel = (void *)ep;
ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_AVR32, ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_AVR32,
&initrd_start, &initrd_end); &initrd_start, &initrd_end);

View File

@ -38,29 +38,12 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
{ {
int (*appl) (char *cmdline); int (*appl) (char *cmdline);
char *cmdline; char *cmdline;
ulong ep = 0;
#ifdef SHARED_RESOURCES #ifdef SHARED_RESOURCES
swap_to(FLASH); swap_to(FLASH);
#endif #endif
/* find kernel entry point */ appl = (int (*)(char *))images->ep;
if (images->legacy_hdr_valid) {
ep = image_get_ep (&images->legacy_hdr_os_copy);
#if defined(CONFIG_FIT)
} else if (images->fit_uname_os) {
int ret = fit_image_get_entry (images->fit_hdr_os,
images->fit_noffset_os, &ep);
if (ret) {
puts ("Can't get entry point property!\n");
goto error;
}
#endif
} else {
puts ("Could not find kernel entry point!\n");
goto error;
}
appl = (int (*)(char *))ep;
printf("Starting Kernel at = %x\n", appl); printf("Starting Kernel at = %x\n", appl);
cmdline = make_command_line(); cmdline = make_command_line();

View File

@ -57,7 +57,6 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
ulong cmd_start, cmd_end; ulong cmd_start, cmd_end;
ulong bootmap_base; ulong bootmap_base;
bd_t *kbd; bd_t *kbd;
ulong ep = 0;
void (*kernel) (bd_t *, ulong, ulong, ulong, ulong); void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
struct lmb *lmb = images->lmb; struct lmb *lmb = images->lmb;
@ -94,23 +93,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
} }
set_clocks_in_mhz(kbd); set_clocks_in_mhz(kbd);
/* find kernel entry point */ kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
if (images->legacy_hdr_valid) {
ep = image_get_ep (&images->legacy_hdr_os_copy);
#if defined(CONFIG_FIT)
} else if (images->fit_uname_os) {
ret = fit_image_get_entry (images->fit_hdr_os,
images->fit_noffset_os, &ep);
if (ret) {
puts ("Can't get entry point property!\n");
goto error;
}
#endif
} else {
puts ("Could not find kernel entry point!\n");
goto error;
}
kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep;
/* find ramdisk */ /* find ramdisk */
ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_M68K, ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_M68K,

View File

@ -40,25 +40,8 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
/* First parameter is mapped to $r5 for kernel boot args */ /* First parameter is mapped to $r5 for kernel boot args */
void (*theKernel) (char *); void (*theKernel) (char *);
char *commandline = getenv ("bootargs"); char *commandline = getenv ("bootargs");
ulong ep = 0;
/* find kernel entry point */ theKernel = (void (*)(char *))images->ep;
if (images->legacy_hdr_valid) {
ep = image_get_ep (&images->legacy_hdr_os_copy);
#if defined(CONFIG_FIT)
} else if (images->fit_uname_os) {
int ret = fit_image_get_entry (images->fit_hdr_os,
images->fit_noffset_os, &ep);
if (ret) {
puts ("Can't get entry point property!\n");
goto error;
}
#endif
} else {
puts ("Could not find kernel entry point!\n");
goto error;
}
theKernel = (void (*)(char *))ep;
show_boot_progress (15); show_boot_progress (15);

View File

@ -49,7 +49,6 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
bootm_headers_t *images) bootm_headers_t *images)
{ {
ulong initrd_start, initrd_end; ulong initrd_start, initrd_end;
ulong ep = 0;
void (*theKernel) (int, char **, char **, int *); void (*theKernel) (int, char **, char **, int *);
char *commandline = getenv ("bootargs"); char *commandline = getenv ("bootargs");
char env_buf[12]; char env_buf[12];
@ -57,22 +56,7 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
char *cp; char *cp;
/* find kernel entry point */ /* find kernel entry point */
if (images->legacy_hdr_valid) { theKernel = (void (*)(int, char **, char **, int *))images->ep;
ep = image_get_ep (&images->legacy_hdr_os_copy);
#if defined(CONFIG_FIT)
} else if (images->fit_uname_os) {
ret = fit_image_get_entry (images->fit_hdr_os,
images->fit_noffset_os, &ep);
if (ret) {
puts ("Can't get entry point property!\n");
goto error;
}
#endif
} else {
puts ("Could not find kernel entry point!\n");
goto error;
}
theKernel = (void (*)(int, char **, char **, int *))ep;
ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_MIPS, ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_MIPS,
&initrd_start, &initrd_end); &initrd_start, &initrd_end);

View File

@ -30,25 +30,7 @@ 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[], void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
bootm_headers_t *images) bootm_headers_t *images)
{ {
ulong ep = 0; void (*kernel)(void) = (void (*)(void))images->ep;
/* find kernel entry point */
if (images->legacy_hdr_valid) {
ep = image_get_ep (&images->legacy_hdr_os_copy);
#if defined(CONFIG_FIT)
} else if (images->fit_uname_os) {
int ret = fit_image_get_entry (images->fit_hdr_os,
images->fit_noffset_os, &ep);
if (ret) {
puts ("Can't get entry point property!\n");
goto error;
}
#endif
} else {
puts ("Could not find kernel entry point!\n");
goto error;
}
void (*kernel)(void) = (void (*)(void))ep;
/* For now we assume the Microtronix linux ... which only /* For now we assume the Microtronix linux ... which only
* needs to be called ;-) * needs to be called ;-)

View File

@ -79,7 +79,6 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
ulong cmd_start, cmd_end, bootmap_base; ulong cmd_start, cmd_end, bootmap_base;
bd_t *kbd; bd_t *kbd;
ulong ep = 0;
void (*kernel)(bd_t *, ulong r4, ulong r5, ulong r6, void (*kernel)(bd_t *, ulong r4, ulong r5, ulong r6,
ulong r7, ulong r8, ulong r9); ulong r7, ulong r8, ulong r9);
int ret; int ret;
@ -90,6 +89,9 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
char *of_flat_tree = NULL; char *of_flat_tree = NULL;
#endif #endif
kernel = (void (*)(bd_t *, ulong, ulong, ulong,
ulong, ulong, ulong))images->ep;
bootmap_base = getenv_bootm_low(); bootmap_base = getenv_bootm_low();
bootm_size = getenv_bootm_size(); bootm_size = getenv_bootm_size();
@ -151,24 +153,6 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
set_clocks_in_mhz(kbd); set_clocks_in_mhz(kbd);
} }
/* find kernel entry point */
if (images->legacy_hdr_valid) {
ep = image_get_ep (&images->legacy_hdr_os_copy);
#if defined(CONFIG_FIT)
} else if (images->fit_uname_os) {
ret = fit_image_get_entry (images->fit_hdr_os,
images->fit_noffset_os, &ep);
if (ret) {
puts ("Can't get entry point property!\n");
goto error;
}
#endif
} else {
puts ("Could not find kernel entry point!\n");
goto error;
}
kernel = (void (*)(bd_t *, ulong, ulong, ulong,
ulong, ulong, ulong))ep;
/* find ramdisk */ /* find ramdisk */
ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_PPC, ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_PPC,
&rd_data_start, &rd_data_end); &rd_data_start, &rd_data_end);

View File

@ -62,26 +62,9 @@ static void hexdump (unsigned char *buf, int len)
void do_bootm_linux (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) bootm_headers_t *images)
{ {
ulong ep = 0;
char *bootargs = getenv("bootargs"); char *bootargs = getenv("bootargs");
/* find kernel entry point */ void (*kernel) (void) = (void (*)(void))images->ep;
if (images->legacy_hdr_valid) {
ep = image_get_ep (&images->legacy_hdr_os_copy);
#if defined(CONFIG_FIT)
} else if (images->fit_uname_os) {
int ret = fit_image_get_entry (images->fit_hdr_os,
images->fit_noffset_os, &ep);
if (ret) {
puts ("Can't get entry point property!\n");
goto error;
}
#endif
} else {
puts ("Could not find kernel entry point!\n");
goto error;
}
void (*kernel) (void) = (void (*)(void))ep;
/* Setup parameters */ /* Setup parameters */
memset(PARAM, 0, 0x1000); /* Clear zero page */ memset(PARAM, 0, 0x1000); /* Clear zero page */

View File

@ -87,7 +87,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
bootm_headers_t * images) bootm_headers_t * images)
{ {
char *bootargs; char *bootargs;
ulong ep, load; ulong load;
ulong initrd_start, initrd_end; ulong initrd_start, initrd_end;
ulong rd_data_start, rd_data_end, rd_len; ulong rd_data_start, rd_data_end, rd_len;
unsigned int data, len, checksum; unsigned int data, len, checksum;
@ -97,17 +97,9 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
int ret; int ret;
if (images->legacy_hdr_valid) { if (images->legacy_hdr_valid) {
ep = image_get_ep(images->legacy_hdr_os);
load = image_get_load(images->legacy_hdr_os); load = image_get_load(images->legacy_hdr_os);
#if defined(CONFIG_FIT) #if defined(CONFIG_FIT)
} else if (images->fit_uname_os) { } else if (images->fit_uname_os) {
int ret = fit_image_get_entry(images->fit_hdr_os,
images->fit_noffset_os, &ep);
if (ret) {
puts("Can't get entry point property!\n");
goto error;
}
ret = fit_image_get_load(images->fit_hdr_os, ret = fit_image_get_load(images->fit_hdr_os,
images->fit_noffset_os, &load); images->fit_noffset_os, &load);
if (ret) { if (ret) {
@ -124,7 +116,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
linux_hdr = (void *)load; linux_hdr = (void *)load;
/* */ /* */
kernel = (void (*)(struct linux_romvec *, void *))ep; kernel = (void (*)(struct linux_romvec *, void *))images->ep;
/* check for a SPARC kernel */ /* check for a SPARC kernel */
if ((linux_hdr->hdr[0] != 'H') || if ((linux_hdr->hdr[0] != 'H') ||