*/
-
/*
* Multi Image extract
*/
-#include <common.h>
#include <command.h>
#include <cpu_func.h>
#include <env.h>
#include <gzip.h>
+#if IS_ENABLED(CONFIG_ZSTD)
+#include <linux/zstd.h>
+#endif
#include <image.h>
#include <malloc.h>
#include <mapmem.h>
#include <asm/cache.h>
#include <asm/io.h>
-#ifndef CONFIG_SYS_XIMG_LEN
-/* use 8MByte as default max gunzip size */
-#define CONFIG_SYS_XIMG_LEN 0x800000
-#endif
-
static int
do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
int part = 0;
#if defined(CONFIG_LEGACY_IMAGE_FORMAT)
ulong count;
- image_header_t *hdr = NULL;
+ struct legacy_img_hdr *hdr = NULL;
#endif
#if defined(CONFIG_FIT)
const char *uname = NULL;
verify = env_get_yesno("verify");
if (argc > 1) {
- addr = simple_strtoul(argv[1], NULL, 16);
+ addr = hextoul(argv[1], NULL);
}
if (argc > 2) {
- part = simple_strtoul(argv[2], NULL, 16);
+ part = hextoul(argv[2], NULL);
#if defined(CONFIG_FIT)
uname = argv[2];
#endif
}
if (argc > 3) {
- dest = simple_strtoul(argv[3], NULL, 16);
+ dest = hextoul(argv[3], NULL);
}
switch (genimg_get_format((void *)addr)) {
printf("## Copying part %d from legacy image "
"at %08lx ...\n", part, addr);
- hdr = (image_header_t *)addr;
+ hdr = (struct legacy_img_hdr *)addr;
if (!image_check_magic(hdr)) {
printf("Bad Magic Number\n");
return 1;
return 1;
}
- if (fit_image_get_comp(fit_hdr, noffset, &comp)) {
- puts("Could not find script subimage "
- "compression type\n");
- return 1;
- }
+ if (fit_image_get_comp(fit_hdr, noffset, &comp))
+ comp = IH_COMP_NONE;
data = (ulong)fit_data;
len = (ulong)fit_len;
while (l > 0) {
tail = (l > CHUNKSZ) ? CHUNKSZ : l;
- WATCHDOG_RESET();
+ schedule();
memmove(to, from, tail);
to += tail;
from += tail;
}
break;
#endif /* CONFIG_BZIP2 */
+#if IS_ENABLED(CONFIG_ZSTD)
+ case IH_COMP_ZSTD:
+ {
+ int ret;
+ struct abuf in, out;
+
+ printf(" Uncompressing part %d ... ", part);
+
+ abuf_init_set(&in, (void *)data, len);
+ abuf_init_set(&out, (void *)dest, unc_len);
+ ret = zstd_decompress(&in, &out);
+ if (ret < 0) {
+ printf("ZSTD ERROR %d - "
+ "image not loaded\n", ret);
+ return 1;
+ }
+ len = ret;
+ }
+ break;
+#endif
default:
printf("Unimplemented compression type %d\n", comp);
return 1;
return 0;
}
-#ifdef CONFIG_SYS_LONGHELP
-static char imgextract_help_text[] =
+U_BOOT_LONGHELP(imgextract,
"addr part [dest]\n"
" - extract <part> from legacy image at <addr> and copy to <dest>"
#if defined(CONFIG_FIT)
"addr uname [dest]\n"
" - extract <uname> subimage from FIT image at <addr> and copy to <dest>"
#endif
- "";
-#endif
+ );
U_BOOT_CMD(
imxtract, 4, 1, do_imgextract,