X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fcmd_ximg.c;h=dceb975498beef93c2941afcbeacf5ba6a204ec2;hb=e3c78c9b3c6a984934f98d3d622618edaa149fbd;hp=7916fc1972dcee52de85a29720afcbbf2daa63a5;hpb=27f33e9f45ef7f9685cbdc65066a1828e85dde4f;p=u-boot diff --git a/common/cmd_ximg.c b/common/cmd_ximg.c index 7916fc1972..dceb975498 100644 --- a/common/cmd_ximg.c +++ b/common/cmd_ximg.c @@ -31,10 +31,19 @@ #include #include #include +#include +#if defined(CONFIG_BZIP2) +#include +#endif #include +#ifndef CONFIG_SYS_XIMG_LEN +/* use 8MByte as default max gunzip size */ +#define CONFIG_SYS_XIMG_LEN 0x800000 +#endif + int -do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) +do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { ulong addr = load_addr; ulong dest = 0; @@ -50,8 +59,10 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) const void *fit_data; size_t fit_len; #endif + uint unc_len = CONFIG_SYS_XIMG_LEN; + uint8_t comp; - verify = getenv_verify (); + verify = getenv_yesno ("verify"); if (argc > 1) { addr = simple_strtoul(argv[1], NULL, 16); @@ -92,8 +103,10 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return 1; } - if (image_get_comp (hdr) != IH_COMP_NONE) { - printf("Wrong Compression Type for %s command\n", + comp = image_get_comp (hdr); + if ((comp != IH_COMP_NONE) && (argc < 4)) { + printf("Must specify load address for %s command " + "with compressed image\n", cmdtp->name); return 1; } @@ -138,9 +151,11 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return 1; } - if (fit_image_check_comp (fit_hdr, noffset, IH_COMP_NONE)) { - printf("Wrong Compression Type for %s command\n", - cmdtp->name); + if (fit_image_check_comp (fit_hdr, noffset, IH_COMP_NONE) + && (argc < 4)) { + printf("Must specify load address for %s command " + "with compressed image\n", + cmdtp->name); return 1; } @@ -153,11 +168,18 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) } /* get subimage data address and length */ - if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) { + if (fit_image_get_data (fit_hdr, noffset, + &fit_data, &fit_len)) { puts ("Could not find script subimage data\n"); return 1; } + if (fit_image_get_comp (fit_hdr, noffset, &comp)) { + puts ("Could not find script subimage " + "compression type\n"); + return 1; + } + data = (ulong)fit_data; len = (ulong)fit_len; break; @@ -168,7 +190,68 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) } if (argc > 3) { - memcpy((char *) dest, (char *) data, len); + switch (comp) { + case IH_COMP_NONE: +#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) + { + size_t l = len; + size_t tail; + void *to = (void *) dest; + void *from = (void *)data; + + printf (" Loading part %d ... ", part); + + while (l > 0) { + tail = (l > CHUNKSZ) ? CHUNKSZ : l; + WATCHDOG_RESET(); + memmove (to, from, tail); + to += tail; + from += tail; + l -= tail; + } + } +#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ + printf (" Loading part %d ... ", part); + memmove ((char *) dest, (char *)data, len); +#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ + break; + case IH_COMP_GZIP: + printf (" Uncompressing part %d ... ", part); + if (gunzip ((void *) dest, unc_len, + (uchar *) data, &len) != 0) { + puts ("GUNZIP ERROR - image not loaded\n"); + return 1; + } + break; +#if defined(CONFIG_BZIP2) + case IH_COMP_BZIP2: + { + int i; + + printf (" Uncompressing part %d ... ", part); + /* + * If we've got less than 4 MB of malloc() + * space, use slower decompression algorithm + * which requires at most 2300 KB of memory. + */ + i = BZ2_bzBuffToBuffDecompress( + (char*)ntohl(hdr->ih_load), + &unc_len, (char *)data, len, + CONFIG_SYS_MALLOC_LEN < (4096 * 1024), + 0); + if (i != BZ_OK) { + printf ("BUNZIP2 ERROR %d - " + "image not loaded\n", i); + return 1; + } + } + break; +#endif /* CONFIG_BZIP2 */ + default: + printf ("Unimplemented compression type %d\n", comp); + return 1; + } + puts ("OK\n"); } sprintf(pbuf, "%8lx", data); @@ -179,12 +262,14 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return 0; } -U_BOOT_CMD(imxtract, 4, 1, do_imgextract, - "imxtract- extract a part of a multi-image\n", - "addr part [dest]\n" - " - extract from legacy image at and copy to \n" +U_BOOT_CMD( + imxtract, 4, 1, do_imgextract, + "extract a part of a multi-image", + "addr part [dest]\n" + " - extract from legacy image at and copy to " #if defined(CONFIG_FIT) - "addr uname [dest]\n" - " - extract subimage from FIT image at and copy to \n" + "\n" + "addr uname [dest]\n" + " - extract subimage from FIT image at and copy to " #endif );