From 1d1618a11b33f3c88b5e9f52b3b4c38199eedec0 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sun, 11 Dec 2011 13:48:52 +0100 Subject: add uimage command The uimage command superseeds the iminfo command. Unlike the iminfo command the uimage command can also be used to verify the data crc on demand and to extract uImages to files. Signed-off-by: Sascha Hauer --- commands/Kconfig | 6 +++ commands/Makefile | 1 + commands/uimage.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 commands/uimage.c (limited to 'commands') diff --git a/commands/Kconfig b/commands/Kconfig index 3cf2d085f3..fc37971288 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -338,6 +338,12 @@ config CMD_IMINFO help Show information about uImages +config CMD_UIMAGE + tristate + prompt "uimage" + help + Show information about uImage and also extract and verify uImages. + config CMD_BOOTZ tristate default y diff --git a/commands/Makefile b/commands/Makefile index aa013de107..01cd1a2e74 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -1,5 +1,6 @@ obj-$(CONFIG_CMD_BOOTM) += bootm.o obj-$(CONFIG_CMD_IMINFO) += iminfo.o +obj-$(CONFIG_CMD_UIMAGE) += uimage.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/uimage.c b/commands/uimage.c new file mode 100644 index 0000000000..82efd78349 --- /dev/null +++ b/commands/uimage.c @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int uimage_fd; + +static int uimage_flush(void *buf, unsigned int len) +{ + int ret; + + ret = write_full(uimage_fd, buf, len); + + return ret; +} + +static int do_uimage(struct command *cmdtp, int argc, char *argv[]) +{ + struct uimage_handle *handle; + int ret; + int verify = 0; + int fd; + int opt; + char *extract = NULL; + int info = 0; + int image_no = 0; + + while ((opt = getopt(argc, argv, "ve:in:")) > 0) { + switch (opt) { + case 'v': + verify = 1; + break; + case 'i': + info = 1; + break; + case 'e': + extract = optarg; + break; + case 'n': + image_no = simple_strtoul(optarg, NULL, 0); + break; + } + } + + if (optind == argc) + return COMMAND_ERROR_USAGE; + + handle = uimage_open(argv[optind]); + if (!handle) + return 1; + + if (info) { + printf("Image at %s:\n", argv[optind]); + uimage_print_contents(handle); + } + + if (verify) { + printf("verifying data crc... "); + ret = uimage_verify(handle); + if (ret) { + goto err; + printf("Bad Data CRC\n"); + } else { + printf("ok\n"); + } + } + + if (extract) { + fd = open(extract, O_WRONLY | O_CREAT | O_TRUNC); + if (fd < 0) { + perror("open"); + ret = fd; + goto err; + } + uimage_fd = fd; + ret = uimage_load(handle, image_no, uimage_flush); + if (ret) { + printf("loading uImage failed with %d\n", ret); + close(fd); + goto err; + } + + close(fd); + } +err: + uimage_close(handle); + + return ret ? 1 : 0; +} + +BAREBOX_CMD_HELP_START(uimage) +BAREBOX_CMD_HELP_USAGE("uimage [OPTIONS] \n") +BAREBOX_CMD_HELP_OPT ("-i", "show information about image\n") +BAREBOX_CMD_HELP_OPT ("-v", "verify image\n") +BAREBOX_CMD_HELP_OPT ("-e ", "extract image to \n") +BAREBOX_CMD_HELP_OPT ("-n ", "use image number in multifile images\n") +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(uimage) + .cmd = do_uimage, + .usage = "extract/verify uImage", + BAREBOX_CMD_HELP(cmd_uimage_help) +BAREBOX_CMD_END -- cgit v1.2.3