Add code to verify that update handler specified with either -t or of -d exists before commencing the update procedure. Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx> Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> --- commands/barebox-update.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/commands/barebox-update.c b/commands/barebox-update.c index 84798ab0d..c5c11c27e 100644 --- a/commands/barebox-update.c +++ b/commands/barebox-update.c @@ -24,6 +24,12 @@ #include <bbu.h> #include <fs.h> +static void print_handlers_list(void) +{ + printf("registered update handlers:\n"); + bbu_handlers_list(); +} + static int do_barebox_update(int argc, char *argv[]) { int opt, ret, repair = 0; @@ -46,8 +52,7 @@ static int do_barebox_update(int argc, char *argv[]) data.flags |= BBU_FLAG_YES; break; case 'l': - printf("registered update handlers:\n"); - bbu_handlers_list(); + print_handlers_list(); return 0; case 'r': repair = 1; @@ -57,6 +62,30 @@ static int do_barebox_update(int argc, char *argv[]) } } + if (data.handler_name && data.devicefile) { + printf("Both TARGET and DEVICE are provided. " + "Ignoring the latter\n"); + + data.devicefile = NULL; + } + + if (data.handler_name && + !bbu_find_handler_by_name(data.handler_name)) { + printf("handler '%s' does not exist\n", + data.handler_name); + goto error; + } else if (data.devicefile && + !bbu_find_handler_by_device(data.devicefile)) { + printf("handler for '%s' does not exist\n", + data.devicefile); + goto error; + } if (!data.handler_name && + !data.devicefile && + !bbu_find_handler_by_name(NULL)) { + printf("default handler does not exist\n"); + goto error; + } + if (argc - optind > 0) { data.imagefile = argv[optind]; @@ -74,6 +103,9 @@ static int do_barebox_update(int argc, char *argv[]) free(image); return ret; +error: + print_handlers_list(); + return COMMAND_ERROR; } BAREBOX_CMD_HELP_START(barebox_update) -- 2.17.1 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox