diff --git a/commands/Kconfig b/commands/Kconfig index 78b9d2a0e..93f14b278 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -309,6 +309,12 @@ config CMD_BOOTM_SHOW_TYPE depends on CMD_BOOTM prompt "show image information" +config CMD_IMINFO + bool + prompt "iminfo" + help + Show information about uImages + config CMD_BOOTZ tristate default y diff --git a/commands/Makefile b/commands/Makefile index 9b3a349bd..45f9ccfd5 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -1,4 +1,5 @@ obj-$(CONFIG_CMD_BOOTM) += bootm.o +obj-$(CONFIG_CMD_IMINFO) += iminfo.o obj-$(CONFIG_CMD_LINUX16) += linux16.o obj-$(CONFIG_CMD_LOADB) += loadb.o xyzModem.o obj-$(CONFIG_CMD_LOADY) += loadb.o xyzModem.o diff --git a/commands/bootm.c b/commands/bootm.c index d0bb35062..8936897a0 100644 --- a/commands/bootm.c +++ b/commands/bootm.c @@ -321,85 +321,6 @@ BAREBOX_CMD_END BAREBOX_MAGICVAR(bootargs, "Linux Kernel parameters"); -/** - * @page bootm_command - -\todo What does bootm do, what kind of image does it boot? - - */ - -#ifdef CONFIG_CMD_IMI -static int do_iminfo(struct command *cmdtp, int argc, char *argv[]) -{ - int arg; - ulong addr; - int rcode=0; - - if (argc < 2) { - return image_info (load_addr); - } - - for (arg=1; arg ih_hcrc = 0; - - if (crc32 (0, (uchar *)data, len) != checksum) { - puts (" Bad Header Checksum\n"); - return 1; - } - - /* for multi-file images we need the data part, too */ - print_image_hdr ((image_header_t *)addr); - - data = addr + image_get_header_size(); - len = image_get_size(hdr); - - puts (" Verifying Checksum ... "); - if (crc32 (0, (uchar *)data, len) != image_get_dcrc(hdr)) { - puts (" Bad Data CRC\n"); - return 1; - } - puts ("OK\n"); - return 0; -} - -BAREBOX_CMD_HELP_START(iminfo) -BAREBOX_CMD_HELP_USAGE("iminfo\n") -BAREBOX_CMD_HELP_SHORT("Print header information for an application image.\n") -BAREBOX_CMD_HELP_END - -BAREBOX_CMD_START(iminfo) - .cmd = do_iminfo, - .usage = "print header information for an application image", - BAREBOX_CMD_HELP(cmd_iminfo_help) -BAREBOX_CMD_END - -#endif /* CONFIG_CMD_IMI */ - #ifdef CONFIG_BZLIB void bz_internal_error(int errcode) { diff --git a/commands/iminfo.c b/commands/iminfo.c new file mode 100644 index 000000000..2fde9bc09 --- /dev/null +++ b/commands/iminfo.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include +#include + +static int image_info(image_header_t *hdr) +{ + u32 len, checksum; + + if (image_get_magic(hdr) != IH_MAGIC) { + puts (" Bad Magic Number\n"); + return 1; + } + + len = image_get_header_size(); + + checksum = image_get_hcrc(hdr); + hdr->ih_hcrc = 0; + + if (crc32 (0, hdr, len) != checksum) { + puts (" Bad Header Checksum\n"); + return 1; + } + + image_print_contents(hdr, NULL); + + return 0; +} + +static int do_iminfo(struct command *cmdtp, int argc, char *argv[]) +{ + int rcode = 1; + int fd; + int ret; + image_header_t hdr; + + if (argc != 2) + return COMMAND_ERROR_USAGE; + + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + perror("open"); + return 1; + } + + ret = read(fd, &hdr, sizeof(image_header_t)); + if (ret != sizeof(image_header_t)) + goto err_out; + + printf("Image at %s:\n", argv[1]); + image_info(&hdr); + +err_out: + close(fd); + + return rcode; +} + +BAREBOX_CMD_HELP_START(iminfo) +BAREBOX_CMD_HELP_USAGE("iminfo\n") +BAREBOX_CMD_HELP_SHORT("Print header information for an application image.\n") +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(iminfo) + .cmd = do_iminfo, + .usage = "print header information for an application image", + BAREBOX_CMD_HELP(cmd_iminfo_help) +BAREBOX_CMD_END diff --git a/common/image.c b/common/image.c index 4a6402d8b..939fe4b75 100644 --- a/common/image.c +++ b/common/image.c @@ -290,7 +290,7 @@ void image_print_contents(const image_header_t *hdr, void *data) printf ("%sEntry Point: %08x\n", p, image_get_ep(hdr)); type = image_get_type(hdr); - if (type == IH_TYPE_MULTI || type == IH_TYPE_SCRIPT) { + if (data && (type == IH_TYPE_MULTI || type == IH_TYPE_SCRIPT)) { int i; ulong img_data, len; ulong count = image_multi_count(data); diff --git a/include/image.h b/include/image.h index 691bf2d88..f3a9949e5 100644 --- a/include/image.h +++ b/include/image.h @@ -335,9 +335,6 @@ void image_print_size(uint32_t size); void image_print_contents(const image_header_t *hdr, void *data); -/* commamds/bootm.c */ -void print_image_hdr (image_header_t *hdr); - /* * Load an image into memory. Returns a pointer to the loaded * image.