]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_ximg.c
2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
35 #if defined(CONFIG_BZIP2)
38 #include <asm/byteorder.h>
40 #ifndef CONFIG_SYS_XIMG_LEN
41 /* use 8MByte as default max gunzip size */
42 #define CONFIG_SYS_XIMG_LEN 0x800000
46 do_imgextract(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
48 ulong addr
= load_addr
;
50 ulong data
, len
, count
;
55 #if defined(CONFIG_FIT)
56 const char *uname
= NULL
;
62 uint unc_len
= CONFIG_SYS_XIMG_LEN
;
65 verify
= getenv_yesno("verify");
68 addr
= simple_strtoul(argv
[1], NULL
, 16);
71 part
= simple_strtoul(argv
[2], NULL
, 16);
72 #if defined(CONFIG_FIT)
77 dest
= simple_strtoul(argv
[3], NULL
, 16);
80 switch (genimg_get_format((void *)addr
)) {
81 case IMAGE_FORMAT_LEGACY
:
83 printf("## Copying part %d from legacy image "
84 "at %08lx ...\n", part
, addr
);
86 hdr
= (image_header_t
*)addr
;
87 if (!image_check_magic(hdr
)) {
88 printf("Bad Magic Number\n");
92 if (!image_check_hcrc(hdr
)) {
93 printf("Bad Header Checksum\n");
97 image_print_contents(hdr
);
100 if (!image_check_type(hdr
, IH_TYPE_MULTI
)) {
101 printf("Wrong Image Type for %s command\n",
106 comp
= image_get_comp(hdr
);
107 if ((comp
!= IH_COMP_NONE
) && (argc
< 4)) {
108 printf("Must specify load address for %s command "
109 "with compressed image\n",
115 printf(" Verifying Checksum ... ");
116 if (!image_check_dcrc(hdr
)) {
117 printf("Bad Data CRC\n");
123 count
= image_multi_count(hdr
);
125 printf("Bad Image Part\n");
129 image_multi_getimg(hdr
, part
, &data
, &len
);
131 #if defined(CONFIG_FIT)
132 case IMAGE_FORMAT_FIT
:
134 puts("No FIT subimage unit name\n");
138 printf("## Copying '%s' subimage from FIT image "
139 "at %08lx ...\n", uname
, addr
);
141 fit_hdr
= (const void *)addr
;
142 if (!fit_check_format(fit_hdr
)) {
143 puts("Bad FIT image format\n");
147 /* get subimage node offset */
148 noffset
= fit_image_get_node(fit_hdr
, uname
);
150 printf("Can't find '%s' FIT subimage\n", uname
);
154 if (fit_image_check_comp(fit_hdr
, noffset
, IH_COMP_NONE
)
156 printf("Must specify load address for %s command "
157 "with compressed image\n",
162 /* verify integrity */
164 if (!fit_image_check_hashes(fit_hdr
, noffset
)) {
165 puts("Bad Data Hash\n");
170 /* get subimage data address and length */
171 if (fit_image_get_data(fit_hdr
, noffset
,
172 &fit_data
, &fit_len
)) {
173 puts("Could not find script subimage data\n");
177 if (fit_image_get_comp(fit_hdr
, noffset
, &comp
)) {
178 puts("Could not find script subimage "
179 "compression type\n");
183 data
= (ulong
)fit_data
;
184 len
= (ulong
)fit_len
;
188 puts("Invalid image type for imxtract\n");
195 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
199 void *to
= (void *) dest
;
200 void *from
= (void *)data
;
202 printf(" Loading part %d ... ", part
);
205 tail
= (l
> CHUNKSZ
) ? CHUNKSZ
: l
;
207 memmove(to
, from
, tail
);
213 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
214 printf(" Loading part %d ... ", part
);
215 memmove((char *) dest
, (char *)data
, len
);
216 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
220 printf(" Uncompressing part %d ... ", part
);
221 if (gunzip((void *) dest
, unc_len
,
222 (uchar
*) data
, &len
) != 0) {
223 puts("GUNZIP ERROR - image not loaded\n");
228 #if defined(CONFIG_BZIP2)
233 printf(" Uncompressing part %d ... ", part
);
235 * If we've got less than 4 MB of malloc()
236 * space, use slower decompression algorithm
237 * which requires at most 2300 KB of memory.
239 i
= BZ2_bzBuffToBuffDecompress(
240 (char *)ntohl(hdr
->ih_load
),
241 &unc_len
, (char *)data
, len
,
242 CONFIG_SYS_MALLOC_LEN
< (4096 * 1024),
245 printf("BUNZIP2 ERROR %d - "
246 "image not loaded\n", i
);
251 #endif /* CONFIG_BZIP2 */
253 printf("Unimplemented compression type %d\n", comp
);
259 sprintf(pbuf
, "%8lx", data
);
260 setenv("fileaddr", pbuf
);
261 sprintf(pbuf
, "%8lx", len
);
262 setenv("filesize", pbuf
);
267 #ifdef CONFIG_SYS_LONGHELP
268 static char imgextract_help_text
[] =
270 " - extract <part> from legacy image at <addr> and copy to <dest>"
271 #if defined(CONFIG_FIT)
273 "addr uname [dest]\n"
274 " - extract <uname> subimage from FIT image at <addr> and copy to <dest>"
280 imxtract
, 4, 1, do_imgextract
,
281 "extract a part of a multi-image", imgextract_help_text