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,
34 #include <asm/byteorder.h>
37 do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
39 ulong addr = load_addr;
41 ulong data, len, count;
46 #if defined(CONFIG_FIT)
47 const char *uname = NULL;
54 verify = getenv_yesno ("verify");
57 addr = simple_strtoul(argv[1], NULL, 16);
60 part = simple_strtoul(argv[2], NULL, 16);
61 #if defined(CONFIG_FIT)
66 dest = simple_strtoul(argv[3], NULL, 16);
69 switch (genimg_get_format ((void *)addr)) {
70 case IMAGE_FORMAT_LEGACY:
72 printf("## Copying part %d from legacy image "
73 "at %08lx ...\n", part, addr);
75 hdr = (image_header_t *)addr;
76 if (!image_check_magic (hdr)) {
77 printf("Bad Magic Number\n");
81 if (!image_check_hcrc (hdr)) {
82 printf("Bad Header Checksum\n");
86 image_print_contents (hdr);
89 if (!image_check_type (hdr, IH_TYPE_MULTI)) {
90 printf("Wrong Image Type for %s command\n",
95 if (image_get_comp (hdr) != IH_COMP_NONE) {
96 printf("Wrong Compression Type for %s command\n",
102 printf(" Verifying Checksum ... ");
103 if (!image_check_dcrc (hdr)) {
104 printf("Bad Data CRC\n");
110 count = image_multi_count (hdr);
112 printf("Bad Image Part\n");
116 image_multi_getimg (hdr, part, &data, &len);
118 #if defined(CONFIG_FIT)
119 case IMAGE_FORMAT_FIT:
121 puts ("No FIT subimage unit name\n");
125 printf("## Copying '%s' subimage from FIT image "
126 "at %08lx ...\n", uname, addr);
128 fit_hdr = (const void *)addr;
129 if (!fit_check_format (fit_hdr)) {
130 puts ("Bad FIT image format\n");
134 /* get subimage node offset */
135 noffset = fit_image_get_node (fit_hdr, uname);
137 printf ("Can't find '%s' FIT subimage\n", uname);
141 if (fit_image_check_comp (fit_hdr, noffset, IH_COMP_NONE)) {
142 printf("Wrong Compression Type for %s command\n",
147 /* verify integrity */
149 if (!fit_image_check_hashes (fit_hdr, noffset)) {
150 puts ("Bad Data Hash\n");
155 /* get subimage data address and length */
156 if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) {
157 puts ("Could not find script subimage data\n");
161 data = (ulong)fit_data;
162 len = (ulong)fit_len;
166 puts ("Invalid image type for imxtract\n");
171 memcpy((char *) dest, (char *) data, len);
174 sprintf(pbuf, "%8lx", data);
175 setenv("fileaddr", pbuf);
176 sprintf(pbuf, "%8lx", len);
177 setenv("filesize", pbuf);
182 U_BOOT_CMD(imxtract, 4, 1, do_imgextract,
183 "extract a part of a multi-image",
185 " - extract <part> from legacy image at <addr> and copy to <dest>"
186 #if defined(CONFIG_FIT)
188 "addr uname [dest]\n"
189 " - extract <uname> subimage from FIT image at <addr> and copy to <dest>"