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,
27 #if (CONFIG_COMMANDS & CFG_CMD_XIMG)
35 #include <asm/byteorder.h>
38 do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
40 ulong addr = load_addr, dest = 0;
41 ulong data, len, checksum;
43 int i, verify, part = 0;
45 image_header_t header;
48 verify = (s && (*s == 'n')) ? 0 : 1;
51 addr = simple_strtoul(argv[1], NULL, 16);
54 part = simple_strtoul(argv[2], NULL, 16);
57 dest = simple_strtoul(argv[3], NULL, 16);
60 printf("## Copying from image at %08lx ...\n", addr);
62 /* Copy header so we can blank CRC field for re-calculation */
63 memmove(&header, (char *) addr, sizeof (image_header_t));
65 if (ntohl(header.ih_magic) != IH_MAGIC) {
66 printf("Bad Magic Number\n");
70 data = (ulong) & header;
71 len = sizeof (image_header_t);
73 checksum = ntohl(header.ih_hcrc);
76 if (crc32(0, (char *) data, len) != checksum) {
77 printf("Bad Header Checksum\n");
81 print_image_hdr((image_header_t *) addr);
84 data = addr + sizeof (image_header_t);
85 len = ntohl(header.ih_size);
87 if (header.ih_type != IH_TYPE_MULTI) {
88 printf("Wrong Image Type for %s command\n", cmdtp->name);
92 if (header.ih_comp != IH_COMP_NONE) {
93 printf("Wrong Compression Type for %s command\n", cmdtp->name);
98 printf(" Verifying Checksum ... ");
99 if (crc32(0, (char *) data, len) != ntohl(header.ih_dcrc)) {
100 printf("Bad Data CRC\n");
106 len_ptr = (ulong *) data;
108 data += 4; /* terminator */
109 for (i = 0; len_ptr[i]; ++i) {
111 if (argc > 2 && part > i) {
113 len = ntohl(len_ptr[i]);
121 if (argc > 2 && part >= i) {
122 printf("Bad Image Part\n");
125 len = ntohl(len_ptr[part]);
128 memcpy((char *) dest, (char *) data, len);
131 sprintf(pbuf, "%8lx", data);
132 setenv("fileaddr", pbuf);
133 sprintf(pbuf, "%8lx", len);
134 setenv("filesize", pbuf);
139 U_BOOT_CMD(imxtract, 4, 1, do_imgextract,
140 "imxtract- extract a part of a multi-image\n",
142 " - extract <part> from image at <addr> and copy to <dest>\n");
144 #endif /* CONFIG_COMMANDS & CFG_CMD_XIMG */