Blame view
cmd/ximg.c
5.85 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
48abe7bfa Patch by Robert S... |
2 3 4 5 6 7 |
/* * (C) Copyright 2000-2004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * (C) Copyright 2003 * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de> |
48abe7bfa Patch by Robert S... |
8 |
*/ |
48abe7bfa Patch by Robert S... |
9 10 11 12 13 14 15 |
/* * Multi Image extract */ #include <common.h> #include <command.h> #include <image.h> |
0eb25b619 common: Make sure... |
16 |
#include <mapmem.h> |
5912d3650 add ability to ha... |
17 18 19 20 |
#include <watchdog.h> #if defined(CONFIG_BZIP2) #include <bzlib.h> #endif |
48abe7bfa Patch by Robert S... |
21 |
#include <asm/byteorder.h> |
628af1790 sandbox: Correct ... |
22 |
#include <asm/io.h> |
48abe7bfa Patch by Robert S... |
23 |
|
5912d3650 add ability to ha... |
24 25 26 27 |
#ifndef CONFIG_SYS_XIMG_LEN /* use 8MByte as default max gunzip size */ #define CONFIG_SYS_XIMG_LEN 0x800000 #endif |
088f1b199 common/cmd_*.c: s... |
28 |
static int |
54841ab50 Make sure that ar... |
29 |
do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
48abe7bfa Patch by Robert S... |
30 |
{ |
1b7897f28 [new uImage] Add ... |
31 32 |
ulong addr = load_addr; ulong dest = 0; |
21d29f7f9 bootm: make use o... |
33 |
ulong data, len; |
fbe7a1550 [new uImage] Comp... |
34 |
int verify; |
1b7897f28 [new uImage] Add ... |
35 |
int part = 0; |
21d29f7f9 bootm: make use o... |
36 37 |
#if defined(CONFIG_IMAGE_FORMAT_LEGACY) ulong count; |
628af1790 sandbox: Correct ... |
38 |
image_header_t *hdr = NULL; |
21d29f7f9 bootm: make use o... |
39 |
#endif |
1b7897f28 [new uImage] Add ... |
40 |
#if defined(CONFIG_FIT) |
fbe7a1550 [new uImage] Comp... |
41 |
const char *uname = NULL; |
1b7897f28 [new uImage] Add ... |
42 43 44 45 46 |
const void* fit_hdr; int noffset; const void *fit_data; size_t fit_len; #endif |
a92181b39 x86: Fix warning ... |
47 |
#ifdef CONFIG_GZIP |
5912d3650 add ability to ha... |
48 |
uint unc_len = CONFIG_SYS_XIMG_LEN; |
a92181b39 x86: Fix warning ... |
49 |
#endif |
5912d3650 add ability to ha... |
50 |
uint8_t comp; |
48abe7bfa Patch by Robert S... |
51 |
|
bfebc8c96 env: Rename geten... |
52 |
verify = env_get_yesno("verify"); |
48abe7bfa Patch by Robert S... |
53 54 55 56 57 58 |
if (argc > 1) { addr = simple_strtoul(argv[1], NULL, 16); } if (argc > 2) { part = simple_strtoul(argv[2], NULL, 16); |
1b7897f28 [new uImage] Add ... |
59 60 61 |
#if defined(CONFIG_FIT) uname = argv[2]; #endif |
48abe7bfa Patch by Robert S... |
62 63 64 65 |
} if (argc > 3) { dest = simple_strtoul(argv[3], NULL, 16); } |
712fbcf38 checkpatch whites... |
66 |
switch (genimg_get_format((void *)addr)) { |
21d29f7f9 bootm: make use o... |
67 |
#if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
d5934ad77 [new uImage] Add ... |
68 |
case IMAGE_FORMAT_LEGACY: |
48abe7bfa Patch by Robert S... |
69 |
|
1b7897f28 [new uImage] Add ... |
70 71 72 |
printf("## Copying part %d from legacy image " "at %08lx ... ", part, addr); |
d5934ad77 [new uImage] Add ... |
73 |
hdr = (image_header_t *)addr; |
712fbcf38 checkpatch whites... |
74 |
if (!image_check_magic(hdr)) { |
d5934ad77 [new uImage] Add ... |
75 76 77 78 |
printf("Bad Magic Number "); return 1; } |
48abe7bfa Patch by Robert S... |
79 |
|
712fbcf38 checkpatch whites... |
80 |
if (!image_check_hcrc(hdr)) { |
d5934ad77 [new uImage] Add ... |
81 82 83 84 |
printf("Bad Header Checksum "); return 1; } |
1b7897f28 [new uImage] Add ... |
85 |
#ifdef DEBUG |
712fbcf38 checkpatch whites... |
86 |
image_print_contents(hdr); |
1b7897f28 [new uImage] Add ... |
87 |
#endif |
48abe7bfa Patch by Robert S... |
88 |
|
83636fa09 Allow imxtract to... |
89 90 |
if (!image_check_type(hdr, IH_TYPE_MULTI) && !image_check_type(hdr, IH_TYPE_SCRIPT)) { |
d5934ad77 [new uImage] Add ... |
91 92 93 94 95 |
printf("Wrong Image Type for %s command ", cmdtp->name); return 1; } |
48abe7bfa Patch by Robert S... |
96 |
|
712fbcf38 checkpatch whites... |
97 |
comp = image_get_comp(hdr); |
5912d3650 add ability to ha... |
98 99 100 101 |
if ((comp != IH_COMP_NONE) && (argc < 4)) { printf("Must specify load address for %s command " "with compressed image ", |
d5934ad77 [new uImage] Add ... |
102 |
cmdtp->name); |
48abe7bfa Patch by Robert S... |
103 104 |
return 1; } |
48abe7bfa Patch by Robert S... |
105 |
|
d5934ad77 [new uImage] Add ... |
106 107 |
if (verify) { printf(" Verifying Checksum ... "); |
712fbcf38 checkpatch whites... |
108 |
if (!image_check_dcrc(hdr)) { |
d5934ad77 [new uImage] Add ... |
109 110 111 |
printf("Bad Data CRC "); return 1; |
48abe7bfa Patch by Robert S... |
112 |
} |
d5934ad77 [new uImage] Add ... |
113 114 |
printf("OK "); |
48abe7bfa Patch by Robert S... |
115 |
} |
d5934ad77 [new uImage] Add ... |
116 |
|
712fbcf38 checkpatch whites... |
117 |
count = image_multi_count(hdr); |
1b7897f28 [new uImage] Add ... |
118 |
if (part >= count) { |
d5934ad77 [new uImage] Add ... |
119 120 121 122 |
printf("Bad Image Part "); return 1; } |
1b7897f28 [new uImage] Add ... |
123 |
|
712fbcf38 checkpatch whites... |
124 |
image_multi_getimg(hdr, part, &data, &len); |
1b7897f28 [new uImage] Add ... |
125 |
break; |
21d29f7f9 bootm: make use o... |
126 |
#endif |
d5934ad77 [new uImage] Add ... |
127 128 |
#if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: |
1b7897f28 [new uImage] Add ... |
129 |
if (uname == NULL) { |
712fbcf38 checkpatch whites... |
130 131 |
puts("No FIT subimage unit name "); |
1b7897f28 [new uImage] Add ... |
132 133 134 135 136 137 138 139 |
return 1; } printf("## Copying '%s' subimage from FIT image " "at %08lx ... ", uname, addr); fit_hdr = (const void *)addr; |
712fbcf38 checkpatch whites... |
140 141 142 |
if (!fit_check_format(fit_hdr)) { puts("Bad FIT image format "); |
1b7897f28 [new uImage] Add ... |
143 144 145 146 |
return 1; } /* get subimage node offset */ |
712fbcf38 checkpatch whites... |
147 |
noffset = fit_image_get_node(fit_hdr, uname); |
1b7897f28 [new uImage] Add ... |
148 |
if (noffset < 0) { |
712fbcf38 checkpatch whites... |
149 150 |
printf("Can't find '%s' FIT subimage ", uname); |
1b7897f28 [new uImage] Add ... |
151 152 |
return 1; } |
240e58ee5 cmd: ximg: Invert... |
153 |
if (!fit_image_check_comp(fit_hdr, noffset, IH_COMP_NONE) |
5912d3650 add ability to ha... |
154 155 156 157 158 |
&& (argc < 4)) { printf("Must specify load address for %s command " "with compressed image ", cmdtp->name); |
1b7897f28 [new uImage] Add ... |
159 160 161 162 163 |
return 1; } /* verify integrity */ if (verify) { |
b8da83665 image: Rename fit... |
164 |
if (!fit_image_verify(fit_hdr, noffset)) { |
712fbcf38 checkpatch whites... |
165 166 |
puts("Bad Data Hash "); |
1b7897f28 [new uImage] Add ... |
167 168 169 170 171 |
return 1; } } /* get subimage data address and length */ |
712fbcf38 checkpatch whites... |
172 |
if (fit_image_get_data(fit_hdr, noffset, |
5912d3650 add ability to ha... |
173 |
&fit_data, &fit_len)) { |
712fbcf38 checkpatch whites... |
174 175 |
puts("Could not find script subimage data "); |
1b7897f28 [new uImage] Add ... |
176 177 |
return 1; } |
712fbcf38 checkpatch whites... |
178 179 |
if (fit_image_get_comp(fit_hdr, noffset, &comp)) { puts("Could not find script subimage " |
5912d3650 add ability to ha... |
180 181 182 183 |
"compression type "); return 1; } |
fbe7a1550 [new uImage] Comp... |
184 |
data = (ulong)fit_data; |
1b7897f28 [new uImage] Add ... |
185 186 |
len = (ulong)fit_len; break; |
d5934ad77 [new uImage] Add ... |
187 188 |
#endif default: |
712fbcf38 checkpatch whites... |
189 190 |
puts("Invalid image type for imxtract "); |
48abe7bfa Patch by Robert S... |
191 192 |
return 1; } |
48abe7bfa Patch by Robert S... |
193 194 |
if (argc > 3) { |
5912d3650 add ability to ha... |
195 196 197 198 199 200 201 202 |
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; |
712fbcf38 checkpatch whites... |
203 |
printf(" Loading part %d ... ", part); |
5912d3650 add ability to ha... |
204 205 206 207 |
while (l > 0) { tail = (l > CHUNKSZ) ? CHUNKSZ : l; WATCHDOG_RESET(); |
712fbcf38 checkpatch whites... |
208 |
memmove(to, from, tail); |
5912d3650 add ability to ha... |
209 210 211 212 213 214 |
to += tail; from += tail; l -= tail; } } #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ |
712fbcf38 checkpatch whites... |
215 216 |
printf(" Loading part %d ... ", part); memmove((char *) dest, (char *)data, len); |
5912d3650 add ability to ha... |
217 218 |
#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ break; |
0e0996ef4 common/cmd_ximg.c... |
219 |
#ifdef CONFIG_GZIP |
5912d3650 add ability to ha... |
220 |
case IH_COMP_GZIP: |
712fbcf38 checkpatch whites... |
221 222 223 224 225 |
printf(" Uncompressing part %d ... ", part); if (gunzip((void *) dest, unc_len, (uchar *) data, &len) != 0) { puts("GUNZIP ERROR - image not loaded "); |
5912d3650 add ability to ha... |
226 227 228 |
return 1; } break; |
0e0996ef4 common/cmd_ximg.c... |
229 |
#endif |
21d29f7f9 bootm: make use o... |
230 |
#if defined(CONFIG_BZIP2) && defined(CONFIG_IMAGE_FORMAT_LEGACY) |
5912d3650 add ability to ha... |
231 |
case IH_COMP_BZIP2: |
5f566f454 cmd_ximg.c: fix e... |
232 233 |
{ int i; |
712fbcf38 checkpatch whites... |
234 |
printf(" Uncompressing part %d ... ", part); |
5f566f454 cmd_ximg.c: fix e... |
235 |
/* |
93910edb5 Prepare v2010.03-rc1 |
236 |
* If we've got less than 4 MB of malloc() |
5f566f454 cmd_ximg.c: fix e... |
237 238 239 240 |
* space, use slower decompression algorithm * which requires at most 2300 KB of memory. */ i = BZ2_bzBuffToBuffDecompress( |
628af1790 sandbox: Correct ... |
241 |
map_sysmem(ntohl(hdr->ih_load), 0), |
5f566f454 cmd_ximg.c: fix e... |
242 243 244 245 |
&unc_len, (char *)data, len, CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0); if (i != BZ_OK) { |
712fbcf38 checkpatch whites... |
246 |
printf("BUNZIP2 ERROR %d - " |
5f566f454 cmd_ximg.c: fix e... |
247 248 249 250 |
"image not loaded ", i); return 1; } |
5912d3650 add ability to ha... |
251 252 253 254 |
} break; #endif /* CONFIG_BZIP2 */ default: |
712fbcf38 checkpatch whites... |
255 256 |
printf("Unimplemented compression type %d ", comp); |
5912d3650 add ability to ha... |
257 258 |
return 1; } |
712fbcf38 checkpatch whites... |
259 260 |
puts("OK "); |
48abe7bfa Patch by Robert S... |
261 |
} |
8354aa278 cmd: ximg: Respec... |
262 |
flush_cache(dest, ALIGN(len, ARCH_DMA_MINALIGN)); |
c72b65ccd common: add cache... |
263 |
|
018f53032 env: Rename commo... |
264 265 |
env_set_hex("fileaddr", data); env_set_hex("filesize", len); |
48abe7bfa Patch by Robert S... |
266 267 268 |
return 0; } |
088f1b199 common/cmd_*.c: s... |
269 270 |
#ifdef CONFIG_SYS_LONGHELP static char imgextract_help_text[] = |
a89c33db9 General help mess... |
271 272 273 |
"addr part [dest] " " - extract <part> from legacy image at <addr> and copy to <dest>" |
1b7897f28 [new uImage] Add ... |
274 |
#if defined(CONFIG_FIT) |
a89c33db9 General help mess... |
275 276 277 278 279 |
" " "addr uname [dest] " " - extract <uname> subimage from FIT image at <addr> and copy to <dest>" |
1b7897f28 [new uImage] Add ... |
280 |
#endif |
088f1b199 common/cmd_*.c: s... |
281 282 283 284 285 286 |
""; #endif U_BOOT_CMD( imxtract, 4, 1, do_imgextract, "extract a part of a multi-image", imgextract_help_text |
1b7897f28 [new uImage] Add ... |
287 |
); |