mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 08/12] add uimage command
Date: Thu, 15 Dec 2011 11:30:30 +0100	[thread overview]
Message-ID: <1323945034-19687-9-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1323945034-19687-1-git-send-email-s.hauer@pengutronix.de>

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 <s.hauer@pengutronix.de>
---
 commands/Kconfig  |    6 +++
 commands/Makefile |    1 +
 commands/uimage.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 commands/uimage.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 3cf2d08..fc37971 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 aa013de..01cd1a2 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 0000000..82efd78
--- /dev/null
+++ b/commands/uimage.c
@@ -0,0 +1,108 @@
+#include <common.h>
+#include <command.h>
+#include <image.h>
+#include <libbb.h>
+#include <fcntl.h>
+#include <fs.h>
+#include <malloc.h>
+#include <errno.h>
+#include <getopt.h>
+
+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] <file>\n")
+BAREBOX_CMD_HELP_OPT  ("-i",  "show information about image\n")
+BAREBOX_CMD_HELP_OPT  ("-v",  "verify image\n")
+BAREBOX_CMD_HELP_OPT  ("-e <outfile>",  "extract image to <outfile>\n")
+BAREBOX_CMD_HELP_OPT  ("-n <no>",  "use image number <no> 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
-- 
1.7.7.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2011-12-15 10:31 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-15 10:30 reimplement bootm support Sascha Hauer
2011-12-15 10:30 ` [PATCH 01/12] oftree: add of_fix_tree() Sascha Hauer
2011-12-18 13:07   ` *** PROBABLY SPAM *** " Jean-Christophe PLAGNIOL-VILLARD
2011-12-19 10:31     ` Sascha Hauer
2011-12-20 14:03       ` Jean-Christophe PLAGNIOL-VILLARD
2011-12-23 17:14         ` Sascha Hauer
2011-12-25  6:09           ` Jean-Christophe PLAGNIOL-VILLARD
2012-01-02 11:49             ` Sascha Hauer
2011-12-15 10:30 ` [PATCH 02/12] filetype: Add oftree detection Sascha Hauer
2011-12-15 10:30 ` [PATCH 03/12] uncompress: implement uncompress_fd_to_buf Sascha Hauer
2011-12-15 10:30 ` [PATCH 04/12] libbb: add read_full/write_full functions Sascha Hauer
2011-12-15 10:30 ` [PATCH 05/12] ARM: call start_linux directly with initrd start/size and oftree Sascha Hauer
2011-12-15 10:30 ` [PATCH 06/12] reimplement uImage code Sascha Hauer
2011-12-15 13:33   ` *** PROBABLY SPAM *** " Jean-Christophe PLAGNIOL-VILLARD
2011-12-15 15:27     ` Sascha Hauer
2011-12-15 16:20       ` Jean-Christophe PLAGNIOL-VILLARD
2011-12-15 16:39         ` Sascha Hauer
2011-12-15 10:30 ` [PATCH 07/12] bootm: use new uimage code Sascha Hauer
2011-12-15 10:30 ` Sascha Hauer [this message]
2011-12-15 10:30 ` [PATCH 09/12] remove now obsolete iminfo command Sascha Hauer
2011-12-15 10:30 ` [PATCH 10/12] remove now unused uImage code Sascha Hauer
2011-12-15 10:30 ` [PATCH 11/12] move code now only used in mkimage to mkimage Sascha Hauer
2011-12-15 10:30 ` [PATCH 12/12] defaultenv: simplify boot Sascha Hauer
2011-12-15 13:37 ` *** PROBABLY SPAM *** reimplement bootm support Jean-Christophe PLAGNIOL-VILLARD
2011-12-15 14:47   ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323945034-19687-9-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox