[new uImage] Add new uImage format support to autoscript routine
authorMarian Balakowicz <m8@semihalf.com>
Wed, 12 Mar 2008 09:33:00 +0000 (10:33 +0100)
committerMarian Balakowicz <m8@semihalf.com>
Wed, 12 Mar 2008 09:33:00 +0000 (10:33 +0100)
autoscript() routine is updated to accept second argument, which
is only used for FIT images and provides a FIT subimage unit name.

autoscript() routine callers must now pass two arguments. For
non-interactive use (like in cmd_load.c, cmd_net.c), new environment
variable 'autoscript_uname' is introduced and used as a FIT
subimage unit name source.

autoscript command accepts extended syntax of the addr argument:
addr:<subimg_uname>

Signed-off-by: Marian Balakowicz <m8@semihalf.com>
board/pn62/cmd_pn62.c
common/cmd_autoscript.c
common/cmd_load.c
common/cmd_net.c
include/common.h

index ffa20cde3b33fd2da3ed7b45a302c4661fedb64c..3f53e4b7cad90a39472d42b88784aa3fa3695652 100644 (file)
@@ -157,8 +157,15 @@ int do_loadpci (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        char *s;
 
        if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
-           printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
-           rcode = autoscript (bd, load_addr);
+               printf ("Running autoscript at addr 0x%08lX", load_addr);
+
+               s = getenv ("autoscript_uname");
+               if (s)
+                       printf (":%s ...\n", s);
+               else
+                       puts (" ...\n");
+
+               rcode = autoscript (load_addr, s);
        }
     }
 #endif
index 60ffc7dbce84d3c974ab3ef44ca2997d056eee6d..5163d57cc4d9f3ce994f6ca6ad337791ae70fa9b 100644 (file)
 #if defined(CONFIG_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)
 
 int
-autoscript (ulong addr)
+autoscript (ulong addr, const char *fit_uname)
 {
-       ulong len;
-       image_header_t *hdr;
-       ulong *data;
-       char *cmd;
-       int rcode = 0;
-       int verify;
+       ulong           len;
+       image_header_t  *hdr;
+       ulong           *data;
+       char            *cmd;
+       int             rcode = 0;
+       int             verify;
+#if defined(CONFIG_FIT)
+       const void*     fit_hdr;
+       int             noffset;
+       const void      *fit_data;
+       size_t          fit_len;
+#endif
 
        verify = getenv_verify ();
 
@@ -97,8 +103,46 @@ autoscript (ulong addr)
                break;
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
-               fit_unsupported ("autoscript");
-               return 1;
+               if (fit_uname == NULL) {
+                       puts ("No FIT subimage unit name\n");
+                       return 1;
+               }
+
+               fit_hdr = (const void *)addr;
+               if (!fit_check_format (fit_hdr)) {
+                       puts ("Bad FIT image format\n");
+                       return 1;
+               }
+
+               /* get script component image node offset */
+               noffset = fit_image_get_node (fit_hdr, fit_uname);
+               if (noffset < 0) {
+                       printf ("Can't find '%s' FIT subimage\n", fit_uname);
+                       return 1;
+               }
+
+               if (!fit_image_check_type (fit_hdr, noffset, IH_TYPE_SCRIPT)) {
+                       puts ("Not a image image\n");
+                       return 1;
+               }
+
+               /* verify integrity */
+               if (verify) {
+                       if (!fit_image_check_hashes (fit_hdr, noffset)) {
+                               puts ("Bad Data Hash\n");
+                               return 1;
+                       }
+               }
+
+               /* get script subimage data address and length */
+               if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) {
+                       puts ("Could not find script subimage data\n");
+                       return 1;
+               }
+
+               data = (ulong *)fit_data;
+               len = (ulong)fit_len;
+               break;
 #endif
        default:
                puts ("Wrong image format for autoscript\n");
@@ -160,25 +204,35 @@ do_autoscript (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        ulong addr;
        int rcode;
+       const char *fit_uname = NULL;
 
+       /* Find script image */
        if (argc < 2) {
                addr = CFG_LOAD_ADDR;
+               debug ("*  autoscr: default load address = 0x%08lx\n", addr);
+#if defined(CONFIG_FIT)
+       } else if (fit_parse_subimage (argv[1], load_addr, &addr, &fit_uname)) {
+               debug ("*  autoscr: subimage '%s' from FIT image at 0x%08lx\n",
+                               fit_uname, addr);
+#endif
        } else {
-               addr = simple_strtoul (argv[1],0,16);
+               addr = simple_strtoul(argv[1], NULL, 16);
+               debug ("*  autoscr: cmdline image address = 0x%08lx\n", addr);
        }
 
-       printf ("## Executing script at %08lx\n",addr);
-       rcode = autoscript (addr);
+       printf ("## Executing script at %08lx\n", addr);
+       rcode = autoscript (addr, fit_uname);
        return rcode;
 }
 
-#if defined(CONFIG_CMD_AUTOSCRIPT)
 U_BOOT_CMD(
        autoscr, 2, 0,  do_autoscript,
        "autoscr - run script from memory\n",
        "[addr] - run script starting at addr"
        " - A valid autoscr header must be present\n"
-);
+#if defined(CONFIG_FIT)
+       "For FIT format uImage addr must include subimage\n"
+       "unit name in the form of addr:<subimg_uname>\n"
 #endif
-
+);
 #endif
index 204c3ebf1930ddbb3dcce843402e1a3be9a558f4..1b75a7b5eccf15289e03d9f341efd5c193ba444e 100644 (file)
@@ -521,8 +521,15 @@ int do_load_serial_bin (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                char *s;
 
                if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
-                       printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
-                       rcode = autoscript (load_addr);
+                       printf ("Running autoscript at addr 0x%08lX", load_addr);
+
+                       s = getenv ("autoscript_uname");
+                       if (s)
+                               printf (":%s ...\n", s);
+                       else
+                               puts (" ...\n");
+
+                       rcode = autoscript (load_addr, s);
                }
        }
 #endif
index dbf6b861b1bdd9b6b0c62ce637e4869eabb4fbf9..79e910c764095f9ec441707940506fa3e7f72a25 100644 (file)
@@ -220,9 +220,16 @@ netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
 
 #ifdef CONFIG_AUTOSCRIPT
        if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
-               printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
+               printf ("Running autoscript at addr 0x%08lX", load_addr);
+
+               s = getenv ("autoscript_uname");
+               if (s)
+                       printf (":%s ...\n", s);
+               else
+                       puts (" ...\n");
+
                show_boot_progress (83);
-               rcode = autoscript (load_addr);
+               rcode = autoscript (load_addr, s);
        }
 #endif
        if (rcode < 0)
index 3f05b5e4669d216c1a5698f21d33b1317bbf9ae8..3351e2c0a6abd6551d4605a78974ad411db263d4 100644 (file)
@@ -222,7 +222,7 @@ int mac_read_from_eeprom(void);
 void flash_perror (int);
 
 /* common/cmd_autoscript.c */
-int    autoscript (ulong addr);
+int    autoscript (ulong addr, const char *fit_uname);
 
 extern ulong load_addr;                /* Default Load Address */