cmd/imxtract: Move decompression part to separate function
PATCH 1/2 cmd/imxtract: Move decompression part to separate function
--- cmd/ximg.c | 142 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 76 insertions(+), 66 deletions(-)
cmd/ximg.c +76 -66
@@ -28,6 +28,81 @@#define CONFIG_SYS_XIMG_LEN 0x800000#endif +static int decompress_data (ulong dest,ulong data,ulong len, +uint8_t comp,int part) +{ +#ifdef CONFIG_GZIP +uint unc_len =CONFIG_SYS_XIMG_LEN ; +#endif + +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 ; +#ifdef CONFIG_GZIP +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 ; +#endif +#if defined(CONFIG_BZIP2 ) && defined(CONFIG_IMAGE_FORMAT_LEGACY ) +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 ( +map_sysmem (ntohl (hdr->ih_load),0 ), + &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" ); + +return 0 ; +} +static int do_imgextract (cmd_tbl_t * cmdtp,int flag,int argc,char *const argv[]) {
@@ -47,9 +122,6 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])const void *fit_data;size_t fit_len;#endif -#ifdef CONFIG_GZIP -uint unc_len =CONFIG_SYS_XIMG_LEN ; -#endif uint8_t comp; verify =getenv_yesno ("verify" );
@@ -183,70 +255,8 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) }if (argc >3 ) { -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 ; -#ifdef CONFIG_GZIP -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 ; -#endif -#if defined(CONFIG_BZIP2 ) && defined(CONFIG_IMAGE_FORMAT_LEGACY ) -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 ( -map_sysmem (ntohl (hdr->ih_load),0 ), - &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); +if (!decompress_data (dest, data, len, comp, part))return 1 ; - } -puts ("OK\n" ); }flush_cache (dest, len);
Signature · 1 line
2.12.2
PATCH 2/2 cmd: fsfitxtract: Extract a part of a FIT multi-image stored on a filesystem
Sometimes we interested only in one single small subimage from big multipart FIT. This command tries to avoid reading out the whole FIT because of memory or time considerations.
Since we don't have mmap() in U-Boot, this is done by reading the file in small chunks and trying to parse FIT until requested image is found or total read size limit exceeded.
--- cmd/Kconfig | 7 ++ cmd/ximg.c | 226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 233 insertions(+)
cmd/Kconfig +7 -0
@@ -265,6 +265,13 @@ config CMD_XIMG help Extract a part of a multi-image. +config CMD_FSFITXIMG + bool "fsfitxtract" + default y + depends on FIT + help + Extract a part of a FIT multi-image stored on a filesystem + config CMD_POWEROFF bool
cmd/ximg.c +226 -0
235 lines not on this page · raw message
Signature · 1 line
2.12.2
PATCH 2/2 cmd: fsfitxtract: Extract a part of a FIT multi-image stored on a filesystem
Quoted 7 lines · Alexey Ignatov
Sometimes we interested only in one single small subimage from big multipart FIT. This command tries to avoid reading out the whole FIT because of memory or time considerations.
Since we don't havemmap()in U-Boot, this is done by reading the file in small chunks and trying to parse FIT until requested image is found or total read size limit exceeded.
Quoted 5 lines
Signed-off-by Alexey Ignatov <[email protected]>--- cmd/Kconfig | 7 ++ cmd/ximg.c | 226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 233 insertions(+)
We need to add an entry for cmd/Makefile as CMD_XIMG and CMD_FSFITXIMG do not depend on eachother. I also think you need to guard the CMD_XIMG specific code in cmd/ximg.c when adding this for when the old command is disabled and the new one is enabled, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170522/ab68d619/attachment.sig>
PATCH 1/2 cmd/imxtract: Move decompression part to separate function
In reply to Alexey IgnatovQuoted 1 line · Alexey Ignatov
Signed-off-by Alexey Ignatov <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170522/1cf95c25/attachment.sig>