bbu: Allow to refresh/repair images
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>
This commit is contained in:
parent
1e6955fdb8
commit
fa61152d97
|
@ -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`.
|
||||
|
|
|
@ -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;
|
||||
if (argc - optind > 0) {
|
||||
data.imagefile = argv[optind];
|
||||
|
||||
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
|
||||
|
|
12
common/bbu.c
12
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;
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue