mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 01/11] bbu: Allow to refresh/repair images
Date: Tue, 15 Mar 2016 12:19:04 +0100	[thread overview]
Message-ID: <1458040754-32240-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1458040754-32240-1-git-send-email-s.hauer@pengutronix.de>

Some SoCs allow to store multiple boot images on a device in order to
improve robustness. This adds a -r option to barebox_update to indicate
we do not want to make an update but instead repair/refresh an existing
image. Handlers which want to support this feature must set the
BBU_HANDLER_CAN_REFRESH flag during registration.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 Documentation/user/updating.rst |  8 ++++++++
 commands/barebox-update.c       | 26 ++++++++++++++++----------
 common/bbu.c                    | 12 +++++++++++-
 include/bbu.h                   |  1 +
 4 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/Documentation/user/updating.rst b/Documentation/user/updating.rst
index 6a1a733..7aac0a9 100644
--- a/Documentation/user/updating.rst
+++ b/Documentation/user/updating.rst
@@ -30,3 +30,11 @@ commands. The exact commands are board specific.
 
 **NOTE** barebox images can be enriched with metadata which can be used to check
 if a given image is suitable for updating barebox, see :ref:`imd`.
+
+Repairing existing boot images
+------------------------------
+
+Some SoCs allow to store multiple boot images on a device in order to
+improve robustness. When an update handler supports it the handler can
+repair and/or refresh an image from this redundant information. This is
+done with the '-r' option to :ref:`command_barebox_update`.
diff --git a/commands/barebox-update.c b/commands/barebox-update.c
index 92e0efa..c2f2b68 100644
--- a/commands/barebox-update.c
+++ b/commands/barebox-update.c
@@ -26,10 +26,10 @@
 
 static int do_barebox_update(int argc, char *argv[])
 {
-	int opt, ret;
+	int opt, ret, repair = 0;
 	struct bbu_data data = {};
 
-	while ((opt = getopt(argc, argv, "t:yf:ld:")) > 0) {
+	while ((opt = getopt(argc, argv, "t:yf:ld:r")) > 0) {
 		switch (opt) {
 		case 'd':
 			data.devicefile = optarg;
@@ -48,19 +48,24 @@ static int do_barebox_update(int argc, char *argv[])
 			printf("registered update handlers:\n");
 			bbu_handlers_list();
 			return 0;
+		case 'r':
+			repair = 1;
+			break;
 		default:
 			return COMMAND_ERROR_USAGE;
 		}
 	}
 
-	if (!(argc - optind))
-		return COMMAND_ERROR_USAGE;
-
-	data.imagefile = argv[optind];
+	if (argc - optind > 0) {
+		data.imagefile = argv[optind];
 
-	data.image = read_file(data.imagefile, &data.len);
-	if (!data.image)
-		return -errno;
+		data.image = read_file(data.imagefile, &data.len);
+		if (!data.image)
+			return -errno;
+	} else {
+		if (!repair)
+			return COMMAND_ERROR_USAGE;
+	}
 
 	ret = barebox_update(&data);
 
@@ -74,6 +79,7 @@ BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT("-l\t", "list registered targets")
 BAREBOX_CMD_HELP_OPT("-t TARGET", "specify data target handler name")
 BAREBOX_CMD_HELP_OPT("-d DEVICE", "write image to DEVICE")
+BAREBOX_CMD_HELP_OPT("-r\t", "refresh or repair. Do not update, but repair an existing image")
 BAREBOX_CMD_HELP_OPT("-y\t", "autom. use 'yes' when asking confirmations")
 BAREBOX_CMD_HELP_OPT("-f LEVEL", "set force level")
 BAREBOX_CMD_HELP_END
@@ -81,7 +87,7 @@ BAREBOX_CMD_HELP_END
 BAREBOX_CMD_START(barebox_update)
 	.cmd		= do_barebox_update,
 	BAREBOX_CMD_DESC("update barebox to persistent media")
-	BAREBOX_CMD_OPTS("[-ltdyf] [IMAGE]")
+	BAREBOX_CMD_OPTS("[-ltdyfr] [IMAGE]")
 	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
 	BAREBOX_CMD_HELP(cmd_barebox_update_help)
 BAREBOX_CMD_END
diff --git a/common/bbu.c b/common/bbu.c
index 68812a7..09c96bb 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -65,9 +65,13 @@ int bbu_confirm(struct bbu_data *data)
 	if (data->flags & BBU_FLAG_YES)
 		return 0;
 
-	printf("update barebox from %s using handler %s to %s (y/n)?\n",
+	if (data->imagefile)
+		printf("update barebox from %s using handler %s to %s (y/n)?\n",
 			data->imagefile, data->handler_name,
 			data->devicefile);
+	else
+		printf("Refresh barebox on %s using handler %s (y/n)?\n",
+			data->devicefile, data->handler_name);
 
 	key = read_key();
 
@@ -141,6 +145,12 @@ int barebox_update(struct bbu_data *data)
 	if (!handler)
 		return -ENODEV;
 
+	if (!data->image && !data->imagefile &&
+	    !(handler->flags & BBU_HANDLER_CAN_REFRESH)) {
+		pr_err("No Image file given\n");
+		return -EINVAL;
+	}
+
 	if (!data->handler_name)
 		data->handler_name = handler->name;
 
diff --git a/include/bbu.h b/include/bbu.h
index 0fe7a1a..971fc14 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -23,6 +23,7 @@ struct bbu_handler {
 	const char *name;
 	struct list_head list;
 #define BBU_HANDLER_FLAG_DEFAULT	(1 << 0)
+#define BBU_HANDLER_CAN_REFRESH		(1 << 1)
 	unsigned long flags;
 
 	/* default device file, can be overwritten on the command line */
-- 
2.7.0


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

  reply	other threads:[~2016-03-15 11:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-15 11:19 i.MX NAND Boot: Make update robust against power failures Sascha Hauer
2016-03-15 11:19 ` Sascha Hauer [this message]
2016-03-15 11:19 ` [PATCH 02/11] mtd: nand: export nand_check_erased_buf Sascha Hauer
2016-03-15 11:19 ` [PATCH 03/11] imx-bbu-nand-fcb: factor out layout functions Sascha Hauer
2016-03-15 11:19 ` [PATCH 04/11] imx-bbu-nand-fcb: Use mtd-peb API to write firmware Sascha Hauer
2016-03-15 11:19 ` [PATCH 05/11] imx-bbu-nand-fcb: factor out a fcb write function Sascha Hauer
2016-03-15 11:19 ` [PATCH 06/11] imx-bbu-nand-fcb: erase on demand Sascha Hauer
2016-03-15 11:19 ` [PATCH 07/11] imx-bbu-nand-fcb: Only write FCBs/DBBTs when necessary Sascha Hauer
2016-03-15 11:19 ` [PATCH 08/11] imx-bbu-nand-fcb: When writing firmware return new bad blocks Sascha Hauer
2016-03-15 11:19 ` [PATCH 09/11] imx-bbu-nand-fcb: Print error when writing blocks fails Sascha Hauer
2016-03-15 11:19 ` [PATCH 10/11] imx-bbu-nand-fcb: Make robust against power cuts Sascha Hauer
2016-03-15 11:19 ` [PATCH 11/11] imx-bbu-nand-fcb: Print error message when out of pebs 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=1458040754-32240-2-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