[U-Boot-Users] [PATCH] Add 'imload' command
Kumar Gala
galak at kernel.crashing.org
Wed Feb 13 06:10:05 CET 2008
'imload' provides a more direct means to load from an image file.
Also created a load_image routine out of the code in do_bootm() that
is shared between do_bootm() and do_imload().
Signed-off-by: Kumar Gala <galak at kernel.crashing.org>
---
Note, this is against the u-boot-testing new-image branch.
common/cmd_bootm.c | 180 ++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 133 insertions(+), 47 deletions(-)
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 2ddb191..0211b86 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -112,6 +112,58 @@ static boot_os_fn do_bootm_artos;
ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
+int load_image(image_header_t *hdr, ulong img_data, ulong img_len, ulong dst)
+{
+ const char *type_name;
+ uint unc_len = CFG_BOOTM_LEN;
+ ulong end = 0;
+
+ type_name = image_get_type_name (image_get_type (hdr));
+
+ switch (image_get_comp (hdr)) {
+ case IH_COMP_NONE:
+ if (dst == (ulong)hdr) {
+ printf (" XIP %s ... ", type_name);
+ } else {
+ printf (" Loading %s ... ", type_name);
+
+ memmove_wd ((void *)dst, (void *)img_data,
+ img_len, CHUNKSZ);
+
+ end = dst + img_len;
+ }
+ break;
+ case IH_COMP_GZIP:
+ printf (" Uncompressing %s ... ", type_name);
+ if (gunzip ((void *)dst, unc_len,
+ (uchar *)img_data, &img_len) != 0)
+ return -1;
+
+ end = dst + img_len;
+ break;
+#ifdef CONFIG_BZIP2
+ case IH_COMP_BZIP2:
+ printf (" Uncompressing %s ... ", type_name);
+ /*
+ * If we've got less than 4 MB of malloc() space,
+ * use slower decompression algorithm which requires
+ * at most 2300 KB of memory.
+ */
+ if (BZ2_bzBuffToBuffDecompress ((char*)dst,
+ &unc_len, (char *)img_data, img_len,
+ CFG_MALLOC_LEN < (4096 * 1024), 0) != BZ_OK)
+ return -1;
+
+ end = dst + unc_len;
+ break;
+#endif /* CONFIG_BZIP2 */
+ default:
+ return -2;
+ }
+
+ puts ("OK\n");
+ return end;
+}
/*******************************************************************/
/* bootm - boot application image from image in memory */
@@ -120,7 +172,6 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
ulong iflag;
const char *type_name;
- uint unc_len = CFG_BOOTM_LEN;
int verify = getenv_verify();
image_header_t *hdr;
@@ -160,61 +211,23 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
image_start = (ulong)hdr;
image_end = image_get_image_end (hdr);
load_start = image_get_load (hdr);
- load_end = 0;
- switch (image_get_comp (hdr)) {
- case IH_COMP_NONE:
- if (image_get_load (hdr) == (ulong)hdr) {
- printf (" XIP %s ... ", type_name);
- } else {
- printf (" Loading %s ... ", type_name);
-
- memmove_wd ((void *)image_get_load (hdr),
- (void *)os_data, os_len, CHUNKSZ);
-
- load_end = load_start + os_len;
- puts("OK\n");
- }
- break;
- case IH_COMP_GZIP:
- printf (" Uncompressing %s ... ", type_name);
- if (gunzip ((void *)image_get_load (hdr), unc_len,
- (uchar *)os_data, &os_len) != 0) {
- puts ("GUNZIP ERROR - must RESET board to recover\n");
- show_boot_progress (-6);
- do_reset (cmdtp, flag, argc, argv);
- }
+ load_end = load_image(hdr, os_data, os_len, load_start);
- load_end = load_start + os_len;
- break;
-#ifdef CONFIG_BZIP2
- case IH_COMP_BZIP2:
- printf (" Uncompressing %s ... ", type_name);
- /*
- * If we've got less than 4 MB of malloc() space,
- * use slower decompression algorithm which requires
- * at most 2300 KB of memory.
- */
- int i = BZ2_bzBuffToBuffDecompress ((char*)image_get_load (hdr),
- &unc_len, (char *)os_data, os_len,
- CFG_MALLOC_LEN < (4096 * 1024), 0);
- if (i != BZ_OK) {
- printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
- show_boot_progress (-6);
- do_reset (cmdtp, flag, argc, argv);
- }
+ if (load_end == -1) {
+ printf("%s ERROR - must RESET board to recover\n", type_name);
+ show_boot_progress (-6);
+ do_reset (cmdtp, flag, argc, argv);
+ }
- load_end = load_start + unc_len;
- break;
-#endif /* CONFIG_BZIP2 */
- default:
+ if (load_end == -2) {
if (iflag)
enable_interrupts();
printf ("Unimplemented compression type %d\n", image_get_comp (hdr));
show_boot_progress (-7);
return 1;
}
- puts ("OK\n");
+
debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
show_boot_progress (7);
@@ -482,6 +495,79 @@ U_BOOT_CMD(
);
#endif
+/*******************************************************************/
+/* imload - load image file */
+/*******************************************************************/
+#if defined(CONFIG_CMD_IMLOAD)
+int do_imload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ ulong addr = load_addr;
+ int end;
+ int verify = getenv_verify();
+ char buf[12];
+ image_header_t *h;
+
+ if (argc > 1)
+ addr = simple_strtoul(argv[1], NULL, 16);
+
+ h = (image_header_t *)addr;
+
+ if (!image_check_magic (h)) {
+ puts (" Bad Magic Number\n");
+ return 1;
+ }
+
+ if (!image_check_hcrc (h)) {
+ puts (" Bad Header Checksum\n");
+ return 1;
+ }
+
+ print_image_hdr(h);
+
+ if (verify) {
+ puts (" Verifying Checksum ... ");
+ if (!image_check_dcrc (h)) {
+ printf ("Bad Data CRC\n");
+ return 1;
+ }
+ puts ("OK\n");
+ }
+
+ if (argc == 3)
+ addr = simple_strtoul(argv[2], NULL, 16);
+ else
+ addr = image_get_load(h);
+
+ printf("\n Loading image at %08x\n", addr);
+
+ end = load_image(h, image_get_data(h), image_get_data_size(h), addr);
+
+ if (end > 0) {
+ sprintf(buf, "%lX", addr);
+ setenv("fileaddr", buf);
+ sprintf(buf, "%lX", end - addr);
+ setenv("filesize", buf);
+ return 0;
+ }
+
+ if (end == -1)
+ puts("\n Decompression Error\n");
+
+ return 1;
+}
+
+U_BOOT_CMD(
+ imload, 3, 1, do_imload,
+ "imload - load image from application image\n",
+ "[addr] [load addr]\n"
+ " - load image from application image located at address 'addr'\n"
+ " or $loadaddr if 'addr' is not provided to either the load\n"
+ " address specified in the application image header or the\n"
+ " 'load addr' argument; this includes verification of the\n"
+ " image contents (magic number, header and payload checksums)\n"
+);
+#endif
+
/*******************************************************************/
/* imls - list all images found in flash */
--
1.5.3.8
More information about the U-Boot
mailing list