bootm: refactor entry point code
authorKumar Gala <galak@kernel.crashing.org>
Fri, 15 Aug 2008 13:24:36 +0000 (08:24 -0500)
committerWolfgang Denk <wd@denx.de>
Tue, 26 Aug 2008 21:31:33 +0000 (23:31 +0200)
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>
12 files changed:
common/cmd_bootm.c
include/image.h
lib_arm/bootm.c
lib_avr32/bootm.c
lib_blackfin/bootm.c
lib_m68k/bootm.c
lib_microblaze/bootm.c
lib_mips/bootm.c
lib_nios2/bootm.c
lib_ppc/bootm.c
lib_sh/bootm.c
lib_sparc/bootm.c

index 0b14b06..3f63b84 100644 (file)
@@ -205,6 +205,23 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                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;
        load_end = 0;
        type_name = genimg_get_type_name (type);
@@ -942,7 +959,7 @@ static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
                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",
                (ulong)loader);
@@ -981,7 +998,6 @@ static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
                           int argc, char *argv[],
                           bootm_headers_t *images)
 {
-       image_header_t *hdr = &images->legacy_hdr_os_copy;
        void (*entry_point)(bd_t *);
 
 #if defined(CONFIG_FIT)
@@ -991,7 +1007,7 @@ static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
        }
 #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",
                (ulong)entry_point);
@@ -1011,7 +1027,6 @@ static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
                             bootm_headers_t *images)
 {
        char str[80];
-       image_header_t *hdr = &images->legacy_hdr_os_copy;
 
 #if defined(CONFIG_FIT)
        if (!images->legacy_hdr_valid) {
@@ -1020,7 +1035,7 @@ static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
        }
 #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);
        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 str[16];
-       image_header_t *hdr = &images->legacy_hdr_os_copy;
 
 #if defined(CONFIG_FIT)
        if (!images->legacy_hdr_valid) {
@@ -1040,7 +1054,7 @@ static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
        }
 #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[1] = str;    /* and provide it via the arguments */
        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;
        bd_t *kbd;
        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 (!images->legacy_hdr_valid) {
@@ -1133,7 +1146,7 @@ static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
        }
        *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);
 }
 #endif
index 4b9c582..e16c253 100644 (file)
@@ -219,6 +219,8 @@ typedef struct bootm_headers {
 #endif
 #endif
 
+       ulong           ep;             /* entry point of OS */
+
        int             verify;         /* getenv("verify")[0] != 'n' */
        struct lmb      *lmb;           /* for memory mgmt */
 } bootm_headers_t;
index 955a1ae..5660a50 100644 (file)
@@ -62,7 +62,6 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
                     bootm_headers_t *images)
 {
        ulong   initrd_start, initrd_end;
-       ulong   ep = 0;
        bd_t    *bd = gd->bd;
        char    *s;
        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");
 #endif
 
-       /* 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;
-       }
-       theKernel = (void (*)(int, int, uint))ep;
+       theKernel = (void (*)(int, int, uint))images->ep;
 
        s = getenv ("machid");
        if (s) {
index 60e6b36..7beab99 100644 (file)
@@ -177,29 +177,12 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
                    bootm_headers_t *images)
 {
        ulong   initrd_start, initrd_end;
-       ulong   ep = 0;
        void    (*theKernel)(int magic, void *tagtable);
        struct  tag *params, *params_start;
        char    *commandline = getenv("bootargs");
        int     ret;
 
-       /* 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;
-       }
-       theKernel = (void *)ep;
+       theKernel = (void *)images->ep;
 
        ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_AVR32,
                        &initrd_start, &initrd_end);
index 54f69a9..f789e24 100644 (file)
@@ -38,29 +38,12 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 {
        int     (*appl) (char *cmdline);
        char    *cmdline;
-       ulong   ep = 0;
 
 #ifdef SHARED_RESOURCES
        swap_to(FLASH);
 #endif
 
-       /* 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;
-       }
-       appl = (int (*)(char *))ep;
+       appl = (int (*)(char *))images->ep;
 
        printf("Starting Kernel at = %x\n", appl);
        cmdline = make_command_line();
index b45203d..fe658fe 100644 (file)
@@ -57,7 +57,6 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
        ulong cmd_start, cmd_end;
        ulong bootmap_base;
        bd_t  *kbd;
-       ulong ep = 0;
        void  (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
        struct lmb *lmb = images->lmb;
 
@@ -94,23 +93,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
        }
        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))ep;
+       kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
 
        /* find ramdisk */
        ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_M68K,
index 68edcdb..baf6d77 100644 (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 */
        void    (*theKernel) (char *);
        char    *commandline = getenv ("bootargs");
-       ulong   ep = 0;
 
-       /* 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;
-       }
-       theKernel = (void (*)(char *))ep;
+       theKernel = (void (*)(char *))images->ep;
 
        show_boot_progress (15);
 
index 53e8e19..7df6ce6 100644 (file)
@@ -49,7 +49,6 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
                     bootm_headers_t *images)
 {
        ulong   initrd_start, initrd_end;
-       ulong   ep = 0;
        void    (*theKernel) (int, char **, char **, int *);
        char    *commandline = getenv ("bootargs");
        char    env_buf[12];
@@ -57,22 +56,7 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
        char    *cp;
 
        /* 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;
-       }
-       theKernel = (void (*)(int, char **, char **, int *))ep;
+       theKernel = (void (*)(int, char **, char **, int *))images->ep;
 
        ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_MIPS,
                        &initrd_start, &initrd_end);
index 18cf773..c74b5d6 100644 (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[],
                bootm_headers_t *images)
 {
-       ulong   ep = 0;
-
-       /* 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;
+       void (*kernel)(void) = (void (*)(void))images->ep;
 
        /* For now we assume the Microtronix linux ... which only
         * needs to be called ;-)
index e83c860..b08ee0d 100644 (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;
        bd_t    *kbd;
-       ulong   ep = 0;
        void    (*kernel)(bd_t *, ulong r4, ulong r5, ulong r6,
                          ulong r7, ulong r8, ulong r9);
        int     ret;
@@ -90,6 +89,9 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
        char    *of_flat_tree = NULL;
 #endif
 
+       kernel = (void (*)(bd_t *, ulong, ulong, ulong,
+                          ulong, ulong, ulong))images->ep;
+
        bootmap_base = getenv_bootm_low();
        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);
        }
 
-       /* 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 */
        ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_PPC,
                        &rd_data_start, &rd_data_end);
index 4ee7ff3..9d2c908 100644 (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[],
                     bootm_headers_t *images)
 {
-       ulong   ep = 0;
        char    *bootargs = getenv("bootargs");
 
-       /* 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;
+       void (*kernel) (void) = (void (*)(void))images->ep;
 
        /* Setup parameters */
        memset(PARAM, 0, 0x1000);       /* Clear zero page */
index b1a3d98..ac15396 100644 (file)
@@ -87,7 +87,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
                    bootm_headers_t * images)
 {
        char *bootargs;
-       ulong ep, load;
+       ulong load;
        ulong initrd_start, initrd_end;
        ulong rd_data_start, rd_data_end, rd_len;
        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;
 
        if (images->legacy_hdr_valid) {
-               ep = image_get_ep(images->legacy_hdr_os);
                load = image_get_load(images->legacy_hdr_os);
 #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;
-               }
-
                ret = fit_image_get_load(images->fit_hdr_os,
                                         images->fit_noffset_os, &load);
                if (ret) {
@@ -124,7 +116,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
        linux_hdr = (void *)load;
 
        /* */
-       kernel = (void (*)(struct linux_romvec *, void *))ep;
+       kernel = (void (*)(struct linux_romvec *, void *))images->ep;
 
        /* check for a SPARC kernel */
        if ((linux_hdr->hdr[0] != 'H') ||