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