summaryrefslogtreecommitdiffstats
path: root/commands/barebox-update.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-10-15 12:28:53 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-10-17 20:23:41 +0200
commitbed8fb6de1a1a98d25f3a8289b35395227a652e1 (patch)
tree6a651a5e154527b8785df70020a14e93d88ee9bd /commands/barebox-update.c
parent73e56c348954246a1f633d10335d10fe605f586f (diff)
downloadbarebox-bed8fb6de1a1a98d25f3a8289b35395227a652e1.tar.gz
barebox-bed8fb6de1a1a98d25f3a8289b35395227a652e1.tar.xz
Add in-system barebox update infrastructure
Currently in-system update means to write an arbitrary file to an arbitrary device. There is no sanity check if the flashed image is of the right type or will fit onto the device. Furthermore some SoCs need a special preparation step for their images before flashing them. This adds a barebox in-system update infrastructure. Boards can register update handlers which know how to make the board bootable. The available handlers can be listed to be able to select one, different force levels give the user the chance to know it better. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/barebox-update.c')
-rw-r--r--commands/barebox-update.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/commands/barebox-update.c b/commands/barebox-update.c
new file mode 100644
index 0000000000..f550572c90
--- /dev/null
+++ b/commands/barebox-update.c
@@ -0,0 +1,86 @@
+/*
+ * barebox-update.c - update barebox
+ *
+ * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+#include <common.h>
+#include <command.h>
+#include <getopt.h>
+#include <malloc.h>
+#include <errno.h>
+#include <bbu.h>
+#include <fs.h>
+
+static int do_barebox_update(int argc, char *argv[])
+{
+ int opt, ret;
+ struct bbu_data data = {};
+
+ while ((opt = getopt(argc, argv, "t:yf:ld:")) > 0) {
+ switch (opt) {
+ case 'd':
+ data.devicefile = optarg;
+ break;
+ case 'f':
+ data.force = simple_strtoul(optarg, NULL, 0);
+ data.flags |= BBU_FLAG_FORCE;
+ break;
+ case 't':
+ data.handler_name = optarg;
+ break;
+ case 'y':
+ data.flags |= BBU_FLAG_YES;
+ break;
+ case 'l':
+ printf("registered update handlers:\n");
+ bbu_handlers_list();
+ return 0;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ if (!(argc - optind))
+ return COMMAND_ERROR_USAGE;
+
+ data.imagefile = argv[optind];
+
+ data.image = read_file(data.imagefile, &data.len);
+ if (!data.image)
+ return -errno;
+
+ ret = barebox_update(&data);
+
+ free(data.image);
+
+ return ret;
+}
+
+BAREBOX_CMD_HELP_START(barebox_update)
+BAREBOX_CMD_HELP_USAGE("barebox_update [OPTIONS] <image>\n")
+BAREBOX_CMD_HELP_SHORT("Update barebox to persistent media\n")
+BAREBOX_CMD_HELP_OPT("-t <target>", "\n")
+BAREBOX_CMD_HELP_OPT("-d <device>", "write image to <device> instead of handler default\n")
+BAREBOX_CMD_HELP_OPT(" ", "Can be used for debugging purposes (-d /tmpfile)\n")
+BAREBOX_CMD_HELP_OPT("-y\t", "yes. Do not ask for confirmation\n")
+BAREBOX_CMD_HELP_OPT("-f <level>", "Set force level\n")
+BAREBOX_CMD_HELP_OPT("-l\t", "list registered targets\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(barebox_update)
+ .cmd = do_barebox_update,
+ .usage = "update barebox",
+ BAREBOX_CMD_HELP(cmd_barebox_update_help)
+BAREBOX_CMD_END