From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH v2 3/4] bbu: command: Make sure specified update handler exists
Date: Sun, 7 Oct 2018 23:35:17 -0700 [thread overview]
Message-ID: <20181008063518.18164-4-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20181008063518.18164-1-andrew.smirnov@gmail.com>
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>
---
commands/barebox-update.c | 46 ++++++++++++++++++++++++++++++---------
1 file changed, 36 insertions(+), 10 deletions(-)
diff --git a/commands/barebox-update.c b/commands/barebox-update.c
index 903b4068d..53af2a851 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) {
p+ 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);
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-10-08 6:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-08 6:35 [PATCH v2 0/4] Additional error checking for barebox_update Andrey Smirnov
2018-10-08 6:35 ` [PATCH v2 1/4] bbu: Expose bbu_find_handler_by_*() functions Andrey Smirnov
2018-10-08 6:35 ` [PATCH v2 2/4] bbu: Add "handler" parameter to barebox_update() Andrey Smirnov
2018-10-08 6:35 ` Andrey Smirnov [this message]
2018-10-08 6:35 ` [PATCH v2 4/4] bbu: Simplify bbu_find_handler_by_device() Andrey Smirnov
2018-10-08 8:08 ` [PATCH v2 0/4] Additional error checking for barebox_update 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=20181008063518.18164-4-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--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