summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-10-07 23:35:17 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-10-08 10:07:53 +0200
commit0ad523bdb9f8380b9841c9f3078e318ae4792847 (patch)
tree39199374d11a7e9779383a9bd34158334fba2fc6 /commands
parentc4ed3b223126e69d697fbf482ab60e125bbe3d43 (diff)
downloadbarebox-0ad523bdb9f8380b9841c9f3078e318ae4792847.tar.gz
bbu: command: Make sure specified update handler exists
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@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/barebox-update.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/commands/barebox-update.c b/commands/barebox-update.c
index 903b406..53af2a8 100644
--- a/commands/barebox-update.c
+++ b/commands/barebox-update.c
@@ -24,12 +24,20 @@
#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;
struct bbu_data data = {};
struct bbu_handler *handler;
void *image = NULL;
+ const char *name;
+ const char *fmt;
while ((opt = getopt(argc, argv, "t:yf:ld:r")) > 0) {
switch (opt) {
@@ -47,8 +55,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;
@@ -58,6 +65,33 @@ 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) {
+ handler = bbu_find_handler_by_name(data.handler_name);
+ fmt = "handler '%s' does not exist\n";
+ name = data.handler_name;
+ } else if (data.devicefile) {
+ handler = bbu_find_handler_by_device(data.devicefile);
+ fmt = "handler for '%s' does not exist\n";
+ name = data.devicefile;
+ } else {
+ handler = bbu_find_handler_by_name(NULL);
+ fmt = "default handler does not exist\n";
+ name = NULL;
+ }
+
+ if (!handler) {
+ printf(fmt, name);
+ print_handlers_list();
+ return COMMAND_ERROR;
+ }
+
if (argc - optind > 0) {
data.imagefile = argv[optind];
@@ -70,14 +104,6 @@ static int do_barebox_update(int argc, char *argv[])
return COMMAND_ERROR_USAGE;
}
- handler = bbu_find_handler_by_device(data.devicefile);
-
- if (!handler)
- handler = bbu_find_handler_by_name(data.handler_name);
-
- if (!handler)
- return COMMAND_ERROR_USAGE;
-
ret = barebox_update(&data, handler);
free(image);