]>
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,
27 #if defined(CONFIG_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;
43 int i
, verify
, part
= 0;
47 verify
= getenv_verify ();
50 addr
= simple_strtoul(argv
[1], NULL
, 16);
53 part
= simple_strtoul(argv
[2], NULL
, 16);
56 dest
= simple_strtoul(argv
[3], NULL
, 16);
59 printf("## Copying from image at %08lx ...\n", addr
);
61 hdr
= (image_header_t
*)addr
;
63 if (!image_check_magic (hdr
)) {
64 printf("Bad Magic Number\n");
68 if (!image_check_hcrc (hdr
)) {
69 printf("Bad Header Checksum\n");
73 print_image_hdr (hdr
);
76 if (!image_check_type (hdr
, IH_TYPE_MULTI
)) {
77 printf("Wrong Image Type for %s command\n", cmdtp
->name
);
81 if (image_get_comp (hdr
) != IH_COMP_NONE
) {
82 printf("Wrong Compression Type for %s command\n", cmdtp
->name
);
87 printf(" Verifying Checksum ... ");
88 if (!image_check_dcrc (hdr
)) {
89 printf("Bad Data CRC\n");
95 data
= image_get_data (hdr
);
96 len_ptr
= (ulong
*) data
;
98 data
+= 4; /* terminator */
99 for (i
= 0; len_ptr
[i
]; ++i
) {
101 if (argc
> 2 && part
> i
) {
103 len
= image_to_cpu (len_ptr
[i
]);
111 if (argc
> 2 && part
>= i
) {
112 printf("Bad Image Part\n");
115 len
= image_to_cpu (len_ptr
[part
]);
118 memcpy((char *) dest
, (char *) data
, len
);
121 sprintf(pbuf
, "%8lx", data
);
122 setenv("fileaddr", pbuf
);
123 sprintf(pbuf
, "%8lx", len
);
124 setenv("filesize", pbuf
);
129 U_BOOT_CMD(imxtract
, 4, 1, do_imgextract
,
130 "imxtract- extract a part of a multi-image\n",
132 " - extract <part> from image at <addr> and copy to <dest>\n");