X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=common%2Fcmd_autoscript.c;h=4517ac83c76980bbb380bd8bd02de19d941e43f0;hb=f82642e33899766892499b163e60560fbbf87773;hp=f9ab1d9a13b15e7956d4acb518932ed17242a26c;hpb=e18489e8c27e843e337258fb00f2652ff0f43b92;p=platform%2Fkernel%2Fu-boot.git diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c index f9ab1d9..4517ac8 100644 --- a/common/cmd_autoscript.c +++ b/common/cmd_autoscript.c @@ -43,25 +43,29 @@ #if defined(CONFIG_8xx) #include #endif -#ifdef CFG_HUSH_PARSER +#ifdef CONFIG_SYS_HUSH_PARSER #include #endif -#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 (); + verify = getenv_yesno ("verify"); - switch (gen_image_get_format ((void *)addr)) { + switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; @@ -90,15 +94,60 @@ autoscript (ulong addr) /* get length of script */ data = (ulong *)image_get_data (hdr); - if ((len = image_to_cpu (*data)) == 0) { + if ((len = uimage_to_cpu (*data)) == 0) { puts ("Empty Script\n"); return 1; } + + /* + * scripts are just multi-image files with one component, seek + * past the zero-terminated sequence of image lengths to get + * to the actual image data + */ + while (*data++); 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"); @@ -111,13 +160,11 @@ autoscript (ulong addr) return 1; } - while (*data++); - /* make sure cmd is null terminated */ memmove (cmd, (char *)data, len); *(cmd + len) = 0; -#ifdef CFG_HUSH_PARSER /*?? */ +#ifdef CONFIG_SYS_HUSH_PARSER /*?? */ rcode = parse_string_outer (cmd, FLAG_PARSE_SEMICOLON); #else { @@ -133,7 +180,7 @@ autoscript (ulong addr) if (*next == '\n') { *next = '\0'; /* run only non-empty commands */ - if ((next - line) > 1) { + if (*line) { debug ("** exec: \"%s\"\n", line); if (run_command (line, 0) < 0) { @@ -145,14 +192,14 @@ autoscript (ulong addr) } ++next; } + if (rcode == 0 && *line) + rcode = (run_command(line, 0) >= 0); } #endif free (cmd); return rcode; } -#endif - /**************************************************/ #if defined(CONFIG_CMD_AUTOSCRIPT) int @@ -160,25 +207,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; + addr = CONFIG_SYS_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:\n" #endif - +); #endif