Fix whitespace issues.
[platform/kernel/u-boot.git] / common / cmd_bootm.c
index 8bb524b..652d843 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;
@@ -521,7 +528,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
        void    (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
        image_header_t *hdr = &header;
 #ifdef CONFIG_OF_FLAT_TREE
-       char    *of_flat_tree;
+       char    *of_flat_tree = NULL;
 #endif
 
        if ((s = getenv ("initrd_high")) != NULL) {
@@ -611,7 +618,17 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
        /*
         * 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);
@@ -719,6 +736,77 @@ 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);
+               hdr = (image_header_t *)of_flat_tree;
+
+               if  (*(ulong *)of_flat_tree == OF_DT_HEADER) {
+#ifndef CFG_NO_FLASH
+                       if (addr2info((ulong)of_flat_tree) != NULL) {
+                               printf ("Cannot modify flat device tree stored in flash\n" \
+                                       "Copy to memory before using the bootm command\n");
+                               return;
+                       }
+#endif
+               } else if (ntohl(hdr->ih_magic) == IH_MAGIC) {
+                       printf("## Flat Device Tree Image at %08lX\n", hdr);
+                       print_image_hdr(hdr);
+
+                       if ((ntohl(hdr->ih_load) <  ((unsigned long)hdr + ntohl(hdr->ih_size) + sizeof(hdr))) &&
+                          ((ntohl(hdr->ih_load) + ntohl(hdr->ih_size)) > (unsigned long)hdr)) {
+                               printf ("ERROR: Load address overwrites Flat Device Tree uImage\n");
+                               return;
+                       }
+
+                       printf("   Verifying Checksum ... ");
+                       memmove (&header, (char *)hdr, sizeof(image_header_t));
+                       checksum = ntohl(header.ih_hcrc);
+                       header.ih_hcrc = 0;
+
+                       if(checksum != crc32(0, (uchar *)&header, sizeof(image_header_t))) {
+                               printf("ERROR: Flat Device Tree header checksum is invalid\n");
+                               return;
+                       }
+
+                       checksum = ntohl(hdr->ih_dcrc);
+                       addr = (ulong)((uchar *)(hdr) + sizeof(image_header_t));
+                       len = ntohl(hdr->ih_size);
+
+                       if(checksum != crc32(0, (uchar *)addr, len)) {
+                               printf("ERROR: Flat Device Tree checksum is invalid\n");
+                               return;
+                       }
+                       printf("OK\n");
+
+                       if (ntohl(hdr->ih_type) != IH_TYPE_FLATDT) {
+                               printf ("ERROR: uImage not Flat Device Tree type\n");
+                               return;
+                       }
+                       if (ntohl(hdr->ih_comp) != IH_COMP_NONE) {
+                               printf("ERROR: uImage is not uncompressed\n");
+                               return;
+                       }
+                       if (*((ulong *)(of_flat_tree + sizeof(image_header_t))) != OF_DT_HEADER) {
+                               printf ("ERROR: uImage data is not a flat device tree\n");
+                               return;
+                       }
+
+                       memmove((void *)ntohl(hdr->ih_load),
+                               (void *)(of_flat_tree + sizeof(image_header_t)),
+                               ntohl(hdr->ih_size));
+                       of_flat_tree = (char *)ntohl(hdr->ih_load);
+               } else {
+                       printf ("Did not find a flat flat device tree at address %08lX\n", of_flat_tree);
+                       return;
+               }
+               printf ("   Booting using flat device tree at 0x%x\n",
+                               of_flat_tree);
+       } else if(getenv("disable_of") == NULL) {
+               printf ("ERROR: bootm needs flat device tree as third argument\n");
+               return;
+       }
+#endif
        if (!data) {
                debug ("No initrd\n");
        }
@@ -788,15 +876,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 +898,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);
+       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)
@@ -828,12 +907,16 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
        /*
         * Linux Kernel Parameters:
         *   r3: ptr to OF flat tree, followed by the board info data
-        *   r4: initrd_start or 0 if no initrd
-        *   r5: initrd_end - unused if r4 is 0
-        *   r6: Start of command line string
-        *   r7: End   of command line string
+        *   r4: physical pointer to the kernel itself
+        *   r5: NULL
+        *   r6: NULL
+        *   r7: NULL
         */
-       (*kernel) ((bd_t *)of_flat_tree, initrd_start, initrd_end, cmd_start, cmd_end);
+       if (getenv("disable_of") != NULL)
+               (*kernel) ((bd_t *)of_flat_tree, initrd_start, initrd_end,
+                       cmd_start, cmd_end);
+       else
+               (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0);
 
 #endif
 }
@@ -846,8 +929,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 *);
@@ -931,7 +1012,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;
@@ -1254,6 +1334,7 @@ print_type (image_header_t *hdr)
        case IH_TYPE_MULTI:     type = "Multi-File Image";      break;
        case IH_TYPE_FIRMWARE:  type = "Firmware";              break;
        case IH_TYPE_SCRIPT:    type = "Script";                break;
+       case IH_TYPE_FLATDT:    type = "Flat Device Tree";      break;
        default:                type = "Unknown Image";         break;
        }
 
@@ -1360,7 +1441,6 @@ 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 *);