Merge branch 'mpc86xx'
[platform/kernel/u-boot.git] / common / cmd_bootm.c
index 9562dbe..f1c0eb4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2000-2002
+ * (C) Copyright 2000-2006
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
  * See file CREDITS for list of people who contributed to this
@@ -38,6 +38,8 @@
 #include <ft_build.h>
 #endif
 
+DECLARE_GLOBAL_DATA_PTR;
+
  /*cmd_boot.c*/
  extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
 
@@ -140,6 +142,10 @@ static boot_os_Fcn do_bootm_lynxkdi;
 extern void lynxkdi_boot( image_header_t * );
 #endif
 
+#ifndef CFG_BOOTM_LEN
+#define CFG_BOOTM_LEN  0x800000        /* use 8MByte as default max gunzip size */
+#endif
+
 image_header_t header;
 
 ulong load_addr = CFG_LOAD_ADDR;               /* Default Load Address */
@@ -150,7 +156,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        ulong   addr;
        ulong   data, len, checksum;
        ulong  *len_ptr;
-       uint    unc_len = 0x400000;
+       uint    unc_len = CFG_BOOTM_LEN;
        int     i, verify;
        char    *name, *s;
        int     (*appl)(int, char *[]);
@@ -252,6 +258,8 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        if (hdr->ih_arch != IH_CPU_MICROBLAZE)
 #elif defined(__nios2__)
        if (hdr->ih_arch != IH_CPU_NIOS2)
+#elif defined(__blackfin__)
+       if (hdr->ih_arch != IH_CPU_BLACKFIN)
 #else
 # error Unknown CPU type
 #endif
@@ -457,13 +465,19 @@ U_BOOT_CMD(
        "[addr [arg ...]]\n    - boot application image stored in memory\n"
        "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
        "\t'arg' can be the address of an initrd image\n"
+#ifdef CONFIG_OF_FLAT_TREE
+       "\tWhen booting a Linux kernel which requires a flat device-tree\n"
+       "\ta third argument is required which is the address of the of the\n"
+       "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
+       "\tuse a '-' for the second argument. If you do not pass a third\n"
+       "\ta bd_info struct will be passed instead\n"
+#endif
 );
 
 #ifdef CONFIG_SILENT_CONSOLE
 static void
 fixup_silent_linux ()
 {
-       DECLARE_GLOBAL_DATA_PTR;
        char buf[256], *start, *end;
        char *cmdline = getenv ("bootargs");
 
@@ -493,11 +507,6 @@ fixup_silent_linux ()
 }
 #endif /* CONFIG_SILENT_CONSOLE */
 
-#ifdef CONFIG_OF_FLAT_TREE
-extern const unsigned char oftree_dtb[];
-extern const unsigned int oftree_dtb_len;
-#endif
-
 #ifdef CONFIG_PPC
 static void
 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
@@ -506,8 +515,6 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
                ulong   *len_ptr,
                int     verify)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        ulong   sp;
        ulong   len, checksum;
        ulong   initrd_start, initrd_end;
@@ -606,12 +613,22 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
 #endif /* CONFIG_MPC5xxx */
        }
 
-       kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
+       kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong)) ntohl(hdr->ih_ep);
 
        /*
         * Check if there is an initrd image
         */
+
+#ifdef CONFIG_OF_FLAT_TREE
+       /* Look for a '-' which indicates to ignore the ramdisk argument */
+       if (argc >= 3 && strcmp(argv[2], "-") ==  0) {
+                       debug ("Skipping initrd\n");
+                       data = 0;
+               }
+       else
+#endif
        if (argc >= 3) {
+               debug ("Not skipping initrd\n");
                SHOW_BOOT_PROGRESS (9);
 
                addr = simple_strtoul(argv[2], NULL, 16);
@@ -621,7 +638,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
                /* Copy header so we can blank CRC field for re-calculation */
                memmove (&header, (char *)addr, sizeof(image_header_t));
 
-               if (hdr->ih_magic  != IH_MAGIC) {
+               if (ntohl(hdr->ih_magic)  != IH_MAGIC) {
                        puts ("Bad Magic Number\n");
                        SHOW_BOOT_PROGRESS (-10);
                        do_reset (cmdtp, flag, argc, argv);
@@ -630,7 +647,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
                data = (ulong)&header;
                len  = sizeof(image_header_t);
 
-               checksum = hdr->ih_hcrc;
+               checksum = ntohl(hdr->ih_hcrc);
                hdr->ih_hcrc = 0;
 
                if (crc32 (0, (uchar *)data, len) != checksum) {
@@ -644,7 +661,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
                print_image_hdr (hdr);
 
                data = addr + sizeof(image_header_t);
-               len  = hdr->ih_size;
+               len  = ntohl(hdr->ih_size);
 
                if (verify) {
                        ulong csum = 0;
@@ -670,7 +687,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
                        csum = crc32 (0, (uchar *)data, len);
 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
 
-                       if (csum != hdr->ih_dcrc) {
+                       if (csum != ntohl(hdr->ih_dcrc)) {
                                puts ("Bad Data CRC\n");
                                SHOW_BOOT_PROGRESS (-12);
                                do_reset (cmdtp, flag, argc, argv);
@@ -719,6 +736,15 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
                len = data = 0;
        }
 
+#ifdef CONFIG_OF_FLAT_TREE
+       if (argc >= 3)
+       {
+               of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16);
+               printf ("Booting using flat device tree at 0x%x\n",
+                               of_flat_tree);
+       }
+#endif
+
        if (!data) {
                debug ("No initrd\n");
        }
@@ -788,15 +814,6 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
                initrd_end = 0;
        }
 
-#ifdef CONFIG_OF_FLAT_TREE
-       if (initrd_start == 0)
-               of_flat_tree = (char *)(((ulong)kbd - OF_FLAT_TREE_MAX_SIZE -
-                                       sizeof(bd_t)) & ~0xF);
-       else
-               of_flat_tree = (char *)((initrd_start - OF_FLAT_TREE_MAX_SIZE -
-                                       sizeof(bd_t)) & ~0xF);
-#endif
-
        debug ("## Transferring control to Linux (at address %08lx) ...\n",
                (ulong)kernel);
 
@@ -819,7 +836,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
        (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
 
 #else
-       ft_setup(of_flat_tree, OF_FLAT_TREE_MAX_SIZE, kbd, initrd_start, initrd_end);
+       ft_setup(of_flat_tree, kbd, initrd_start, initrd_end);
        /* ft_dump_blob(of_flat_tree); */
 
 #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
@@ -850,8 +867,6 @@ do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
                ulong   *len_ptr,
                int     verify)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        image_header_t *hdr = &header;
 
        void    (*loader)(bd_t *, image_header_t *, char *, char *);
@@ -906,7 +921,7 @@ do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
                cmdline = "";
        }
 
-       loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
+       loader = (void (*)(bd_t *, image_header_t *, char *, char *)) ntohl(hdr->ih_ep);
 
        printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
                (ulong)loader);
@@ -935,7 +950,6 @@ do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
                ulong   *len_ptr,
                int     verify)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        ulong top;
        char *s, *cmdline;
        char **fwenv, **ss;
@@ -1364,11 +1378,10 @@ static void
 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
                ulong addr, ulong *len_ptr, int verify)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        image_header_t *hdr = &header;
        void    (*entry_point)(bd_t *);
 
-       entry_point = (void (*)(bd_t *)) hdr->ih_ep;
+       entry_point = (void (*)(bd_t *)) ntohl(hdr->ih_ep);
 
        printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
                (ulong)entry_point);
@@ -1391,7 +1404,7 @@ do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
        image_header_t *hdr = &header;
        char str[80];
 
-       sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
+       sprintf(str, "%x", ntohl(hdr->ih_ep)); /* write entry-point into string */
        setenv("loadaddr", str);
        do_bootvx(cmdtp, 0, 0, NULL);
 }
@@ -1404,7 +1417,7 @@ do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
        char *local_args[2];
        char str[16];
 
-       sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
+       sprintf(str, "%x", ntohl(hdr->ih_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);