summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2011-11-25 19:09:07 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2011-11-29 20:55:50 +0100
commitac4854be5e67b4d19884fb4462982d91ca9bc815 (patch)
tree13c49579edc3ab7edeafcfae7c97433255d7a6ca /commands
parent88611e7448842749ccdd7193f4e0fc4d0a2bbe6c (diff)
downloadbarebox-ac4854be5e67b4d19884fb4462982d91ca9bc815.tar.gz
barebox-ac4854be5e67b4d19884fb4462982d91ca9bc815.tar.xz
factor out iminfo command
The rests of U-Boots iminfo command are sitting in commands/bootm.c and are in a nonusable state. Factor it out to its own file and make it work again. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/Kconfig6
-rw-r--r--commands/Makefile1
-rw-r--r--commands/bootm.c79
-rw-r--r--commands/iminfo.c71
4 files changed, 78 insertions, 79 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index 78b9d2a0e6..93f14b278e 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 9b3a349bd2..45f9ccfd56 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 d0bb35062a..8936897a04 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 <argc; ++arg) {
- addr = simple_strtoul(argv[arg], NULL, 16);
- if (image_info (addr) != 0) rcode = 1;
- }
- return rcode;
-}
-
-static int image_info (ulong addr)
-{
- ulong data, len, checksum;
- image_header_t *hdr = &header;
-
- printf ("\n## Checking Image at %08lx ...\n", addr);
-
- /* Copy header so we can blank CRC field for re-calculation */
- memmove (&header, (char *)addr, image_get_header_size());
-
- if (image_get_magic(hdr) != IH_MAGIC) {
- puts (" Bad Magic Number\n");
- return 1;
- }
-
- data = (ulong)&header;
- len = image_get_header_size();
-
- checksum = image_get_hcrc(hdr);
- hdr->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 0000000000..2fde9bc09c
--- /dev/null
+++ b/commands/iminfo.c
@@ -0,0 +1,71 @@
+#include <common.h>
+#include <command.h>
+#include <image.h>
+#include <fs.h>
+#include <malloc.h>
+#include <fcntl.h>
+#include <errno.h>
+
+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