Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2004 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
| 6 | * (C) Copyright 2003 |
| 7 | * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de> |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 10 | /* |
| 11 | * Multi Image extract |
| 12 | */ |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 13 | #include <command.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 14 | #include <cpu_func.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 15 | #include <env.h> |
Simon Glass | 1a974af | 2019-08-01 09:46:36 -0600 | [diff] [blame] | 16 | #include <gzip.h> |
Dmitry Gerasimov | f57988d | 2024-06-02 17:25:52 +0200 | [diff] [blame] | 17 | #if IS_ENABLED(CONFIG_ZSTD) |
| 18 | #include <linux/zstd.h> |
| 19 | #endif |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 20 | #include <image.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 21 | #include <malloc.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 22 | #include <mapmem.h> |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 23 | #include <watchdog.h> |
| 24 | #if defined(CONFIG_BZIP2) |
| 25 | #include <bzlib.h> |
| 26 | #endif |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 27 | #include <asm/byteorder.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 28 | #include <asm/cache.h> |
Simon Glass | 208d8e8 | 2013-08-30 11:00:09 -0600 | [diff] [blame] | 29 | #include <asm/io.h> |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 30 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 31 | static int |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 32 | do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 33 | { |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 34 | ulong addr = image_load_addr; |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 35 | ulong dest = 0; |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 36 | ulong data, len; |
Bartlomiej Sieka | 3b8cc71 | 2008-03-20 19:38:45 +0100 | [diff] [blame] | 37 | int verify; |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 38 | int part = 0; |
Tom Rini | c220bd9 | 2019-05-23 07:14:07 -0400 | [diff] [blame] | 39 | #if defined(CONFIG_LEGACY_IMAGE_FORMAT) |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 40 | ulong count; |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 41 | struct legacy_img_hdr *hdr = NULL; |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 42 | #endif |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 43 | #if defined(CONFIG_FIT) |
Bartlomiej Sieka | 3b8cc71 | 2008-03-20 19:38:45 +0100 | [diff] [blame] | 44 | const char *uname = NULL; |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 45 | const void* fit_hdr; |
| 46 | int noffset; |
| 47 | const void *fit_data; |
| 48 | size_t fit_len; |
| 49 | #endif |
Simon Glass | a039527 | 2013-04-17 16:13:45 +0000 | [diff] [blame] | 50 | #ifdef CONFIG_GZIP |
Nikita Shubin | 25498ed | 2022-12-19 11:05:27 +0300 | [diff] [blame] | 51 | uint unc_len = CONFIG_SYS_XIMG_LEN; |
Simon Glass | a039527 | 2013-04-17 16:13:45 +0000 | [diff] [blame] | 52 | #endif |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 53 | uint8_t comp; |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 54 | |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 55 | verify = env_get_yesno("verify"); |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 56 | |
| 57 | if (argc > 1) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 58 | addr = hextoul(argv[1], NULL); |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 59 | } |
| 60 | if (argc > 2) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 61 | part = hextoul(argv[2], NULL); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 62 | #if defined(CONFIG_FIT) |
| 63 | uname = argv[2]; |
| 64 | #endif |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 65 | } |
| 66 | if (argc > 3) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 67 | dest = hextoul(argv[3], NULL); |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 70 | switch (genimg_get_format((void *)addr)) { |
Tom Rini | c220bd9 | 2019-05-23 07:14:07 -0400 | [diff] [blame] | 71 | #if defined(CONFIG_LEGACY_IMAGE_FORMAT) |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 72 | case IMAGE_FORMAT_LEGACY: |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 73 | |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 74 | printf("## Copying part %d from legacy image " |
| 75 | "at %08lx ...\n", part, addr); |
| 76 | |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 77 | hdr = (struct legacy_img_hdr *)addr; |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 78 | if (!image_check_magic(hdr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 79 | printf("Bad Magic Number\n"); |
| 80 | return 1; |
| 81 | } |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 82 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 83 | if (!image_check_hcrc(hdr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 84 | printf("Bad Header Checksum\n"); |
| 85 | return 1; |
| 86 | } |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 87 | #ifdef DEBUG |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 88 | image_print_contents(hdr); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 89 | #endif |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 90 | |
Pierre Aubert | de4e949 | 2015-09-16 08:29:11 +0200 | [diff] [blame] | 91 | if (!image_check_type(hdr, IH_TYPE_MULTI) && |
| 92 | !image_check_type(hdr, IH_TYPE_SCRIPT)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 93 | printf("Wrong Image Type for %s command\n", |
| 94 | cmdtp->name); |
| 95 | return 1; |
| 96 | } |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 97 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 98 | comp = image_get_comp(hdr); |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 99 | if ((comp != IH_COMP_NONE) && (argc < 4)) { |
| 100 | printf("Must specify load address for %s command " |
| 101 | "with compressed image\n", |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 102 | cmdtp->name); |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 103 | return 1; |
| 104 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 105 | |
| 106 | if (verify) { |
| 107 | printf(" Verifying Checksum ... "); |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 108 | if (!image_check_dcrc(hdr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 109 | printf("Bad Data CRC\n"); |
| 110 | return 1; |
| 111 | } |
| 112 | printf("OK\n"); |
| 113 | } |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 114 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 115 | count = image_multi_count(hdr); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 116 | if (part >= count) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 117 | printf("Bad Image Part\n"); |
| 118 | return 1; |
| 119 | } |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 120 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 121 | image_multi_getimg(hdr, part, &data, &len); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 122 | break; |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 123 | #endif |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 124 | #if defined(CONFIG_FIT) |
| 125 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 126 | if (uname == NULL) { |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 127 | puts("No FIT subimage unit name\n"); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 128 | return 1; |
| 129 | } |
| 130 | |
| 131 | printf("## Copying '%s' subimage from FIT image " |
| 132 | "at %08lx ...\n", uname, addr); |
| 133 | |
| 134 | fit_hdr = (const void *)addr; |
Simon Glass | d563c25 | 2021-02-15 17:08:09 -0700 | [diff] [blame] | 135 | if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) { |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 136 | puts("Bad FIT image format\n"); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 137 | return 1; |
| 138 | } |
| 139 | |
| 140 | /* get subimage node offset */ |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 141 | noffset = fit_image_get_node(fit_hdr, uname); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 142 | if (noffset < 0) { |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 143 | printf("Can't find '%s' FIT subimage\n", uname); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 144 | return 1; |
| 145 | } |
| 146 | |
Stefan Theil | 69b0ef5 | 2019-01-07 10:25:52 +0100 | [diff] [blame] | 147 | if (!fit_image_check_comp(fit_hdr, noffset, IH_COMP_NONE) |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 148 | && (argc < 4)) { |
| 149 | printf("Must specify load address for %s command " |
| 150 | "with compressed image\n", |
| 151 | cmdtp->name); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 152 | return 1; |
| 153 | } |
| 154 | |
| 155 | /* verify integrity */ |
| 156 | if (verify) { |
Simon Glass | 7428ad1 | 2013-05-07 06:11:57 +0000 | [diff] [blame] | 157 | if (!fit_image_verify(fit_hdr, noffset)) { |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 158 | puts("Bad Data Hash\n"); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 159 | return 1; |
| 160 | } |
| 161 | } |
| 162 | |
Tien Fong Chee | 8a86958 | 2019-02-12 20:49:30 +0800 | [diff] [blame] | 163 | /* get subimage/external data address and length */ |
| 164 | if (fit_image_get_data_and_size(fit_hdr, noffset, |
| 165 | &fit_data, &fit_len)) { |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 166 | puts("Could not find script subimage data\n"); |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 167 | return 1; |
| 168 | } |
| 169 | |
Daniel Golle | 2ebfd22 | 2022-08-27 04:17:28 +0100 | [diff] [blame] | 170 | if (fit_image_get_comp(fit_hdr, noffset, &comp)) |
| 171 | comp = IH_COMP_NONE; |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 172 | |
Bartlomiej Sieka | 3b8cc71 | 2008-03-20 19:38:45 +0100 | [diff] [blame] | 173 | data = (ulong)fit_data; |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 174 | len = (ulong)fit_len; |
| 175 | break; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 176 | #endif |
| 177 | default: |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 178 | puts("Invalid image type for imxtract\n"); |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 179 | return 1; |
| 180 | } |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 181 | |
| 182 | if (argc > 3) { |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 183 | switch (comp) { |
| 184 | case IH_COMP_NONE: |
| 185 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
| 186 | { |
| 187 | size_t l = len; |
| 188 | size_t tail; |
| 189 | void *to = (void *) dest; |
| 190 | void *from = (void *)data; |
| 191 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 192 | printf(" Loading part %d ... ", part); |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 193 | |
| 194 | while (l > 0) { |
| 195 | tail = (l > CHUNKSZ) ? CHUNKSZ : l; |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 196 | schedule(); |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 197 | memmove(to, from, tail); |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 198 | to += tail; |
| 199 | from += tail; |
| 200 | l -= tail; |
| 201 | } |
| 202 | } |
| 203 | #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 204 | printf(" Loading part %d ... ", part); |
| 205 | memmove((char *) dest, (char *)data, len); |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 206 | #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ |
| 207 | break; |
Matthew McClintock | c93a754 | 2011-05-24 05:48:26 +0000 | [diff] [blame] | 208 | #ifdef CONFIG_GZIP |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 209 | case IH_COMP_GZIP: |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 210 | printf(" Uncompressing part %d ... ", part); |
| 211 | if (gunzip((void *) dest, unc_len, |
| 212 | (uchar *) data, &len) != 0) { |
| 213 | puts("GUNZIP ERROR - image not loaded\n"); |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 214 | return 1; |
| 215 | } |
| 216 | break; |
Matthew McClintock | c93a754 | 2011-05-24 05:48:26 +0000 | [diff] [blame] | 217 | #endif |
Tom Rini | c220bd9 | 2019-05-23 07:14:07 -0400 | [diff] [blame] | 218 | #if defined(CONFIG_BZIP2) && defined(CONFIG_LEGACY_IMAGE_FORMAT) |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 219 | case IH_COMP_BZIP2: |
Wolfgang Denk | 3207afd | 2010-01-31 21:51:43 +0100 | [diff] [blame] | 220 | { |
| 221 | int i; |
| 222 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 223 | printf(" Uncompressing part %d ... ", part); |
Wolfgang Denk | 3207afd | 2010-01-31 21:51:43 +0100 | [diff] [blame] | 224 | /* |
Wolfgang Denk | a2cfb24 | 2010-03-12 23:06:04 +0100 | [diff] [blame] | 225 | * If we've got less than 4 MB of malloc() |
Wolfgang Denk | 3207afd | 2010-01-31 21:51:43 +0100 | [diff] [blame] | 226 | * space, use slower decompression algorithm |
| 227 | * which requires at most 2300 KB of memory. |
| 228 | */ |
| 229 | i = BZ2_bzBuffToBuffDecompress( |
Simon Glass | 208d8e8 | 2013-08-30 11:00:09 -0600 | [diff] [blame] | 230 | map_sysmem(ntohl(hdr->ih_load), 0), |
Wolfgang Denk | 3207afd | 2010-01-31 21:51:43 +0100 | [diff] [blame] | 231 | &unc_len, (char *)data, len, |
| 232 | CONFIG_SYS_MALLOC_LEN < (4096 * 1024), |
| 233 | 0); |
| 234 | if (i != BZ_OK) { |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 235 | printf("BUNZIP2 ERROR %d - " |
Wolfgang Denk | 3207afd | 2010-01-31 21:51:43 +0100 | [diff] [blame] | 236 | "image not loaded\n", i); |
| 237 | return 1; |
| 238 | } |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 239 | } |
| 240 | break; |
| 241 | #endif /* CONFIG_BZIP2 */ |
Dmitry Gerasimov | f57988d | 2024-06-02 17:25:52 +0200 | [diff] [blame] | 242 | #if IS_ENABLED(CONFIG_ZSTD) |
| 243 | case IH_COMP_ZSTD: |
| 244 | { |
| 245 | int ret; |
| 246 | struct abuf in, out; |
| 247 | |
| 248 | printf(" Uncompressing part %d ... ", part); |
| 249 | |
| 250 | abuf_init_set(&in, (void *)data, len); |
| 251 | abuf_init_set(&out, (void *)dest, unc_len); |
| 252 | ret = zstd_decompress(&in, &out); |
| 253 | if (ret < 0) { |
| 254 | printf("ZSTD ERROR %d - " |
| 255 | "image not loaded\n", ret); |
| 256 | return 1; |
| 257 | } |
| 258 | len = ret; |
| 259 | } |
| 260 | break; |
| 261 | #endif |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 262 | default: |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 263 | printf("Unimplemented compression type %d\n", comp); |
Wolfgang Wegner | 781afa9 | 2009-12-10 10:11:21 +0100 | [diff] [blame] | 264 | return 1; |
| 265 | } |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 266 | puts("OK\n"); |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Mario Six | 7feefe4 | 2018-03-28 14:39:10 +0200 | [diff] [blame] | 269 | flush_cache(dest, ALIGN(len, ARCH_DMA_MINALIGN)); |
Pieter Voorthuijsen | f52d281 | 2015-01-12 16:23:18 +0100 | [diff] [blame] | 270 | |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 271 | env_set_hex("fileaddr", data); |
| 272 | env_set_hex("filesize", len); |
wdenk | 0359dde | 2004-06-09 10:15:00 +0000 | [diff] [blame] | 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 277 | U_BOOT_LONGHELP(imgextract, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 278 | "addr part [dest]\n" |
| 279 | " - extract <part> from legacy image at <addr> and copy to <dest>" |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 280 | #if defined(CONFIG_FIT) |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 281 | "\n" |
| 282 | "addr uname [dest]\n" |
| 283 | " - extract <uname> subimage from FIT image at <addr> and copy to <dest>" |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 284 | #endif |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 285 | ); |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 286 | |
| 287 | U_BOOT_CMD( |
| 288 | imxtract, 4, 1, do_imgextract, |
| 289 | "extract a part of a multi-image", imgextract_help_text |
Marian Balakowicz | 2321ed0 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 290 | ); |