mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH v2 2/4] bbu: Add "handler" parameter to barebox_update()
Date: Sun,  7 Oct 2018 23:35:16 -0700	[thread overview]
Message-ID: <20181008063518.18164-3-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20181008063518.18164-1-andrew.smirnov@gmail.com>

Add "handler" parameter to barebox_update() and remove the code that
was respondible for header lookup before. With this change finding
appropriate handler is caller's responsibility, which makes it
possible to implement custom handler lookup/existence check, chache
it, and then re-use it without calling handler_find_by_* functions for
the second time.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 commands/barebox-update.c       | 11 ++++++++++-
 common/bbu.c                    | 11 +----------
 drivers/usb/gadget/f_fastboot.c |  6 ++++--
 include/bbu.h                   |  2 +-
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/commands/barebox-update.c b/commands/barebox-update.c
index 84798ab0d..903b4068d 100644
--- a/commands/barebox-update.c
+++ b/commands/barebox-update.c
@@ -28,6 +28,7 @@ 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;
 
 	while ((opt = getopt(argc, argv, "t:yf:ld:r")) > 0) {
@@ -69,7 +70,15 @@ static int do_barebox_update(int argc, char *argv[])
 			return COMMAND_ERROR_USAGE;
 	}
 
-	ret = barebox_update(&data);
+	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);
 
diff --git a/common/bbu.c b/common/bbu.c
index fabd94966..75c3221d5 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -216,19 +216,10 @@ static int bbu_check_metadata(struct bbu_data *data)
 /*
  * do a barebox update with data from *data
  */
-int barebox_update(struct bbu_data *data)
+int barebox_update(struct bbu_data *data, struct bbu_handler *handler)
 {
-	struct bbu_handler *handler;
 	int ret;
 
-	handler = bbu_find_handler_by_device(data->devicefile);
-
-	if (!handler)
-		handler = bbu_find_handler_by_name(data->handler_name);
-
-	if (!handler)
-		return -ENODEV;
-
 	if (!data->image && !data->imagefile &&
 	    !(handler->flags & BBU_HANDLER_CAN_REFRESH)) {
 		pr_err("No Image file given\n");
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index ea36fc988..2c137fe7e 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -991,12 +991,14 @@ static void cb_flash(struct f_fastboot *f_fb, const char *cmd)
 	}
 
 	if (IS_ENABLED(CONFIG_BAREBOX_UPDATE) && filetype_is_barebox_image(filetype)) {
+		struct bbu_handler *handler;
 		struct bbu_data data = {
 			.devicefile = filename,
 			.flags = BBU_FLAG_YES,
 		};
 
-		if (!bbu_find_handler_by_device(data.devicefile))
+		handler = bbu_find_handler_by_device(data.devicefile);
+		if (!handler)
 			goto copy;
 
 		fastboot_tx_print(f_fb, "INFOThis is a barebox image...");
@@ -1015,7 +1017,7 @@ static void cb_flash(struct f_fastboot *f_fb, const char *cmd)
 		data.image = f_fb->buf;
 		data.imagefile = sourcefile;
 
-		ret = barebox_update(&data);
+		ret = barebox_update(&data, handler);
 
 		if (ret)
 			fastboot_tx_print(f_fb, "FAILupdate barebox: %s", strerror(-ret));
diff --git a/include/bbu.h b/include/bbu.h
index 775d7a310..0ed355b53 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -40,7 +40,7 @@ int bbu_force(struct bbu_data *, const char *fmt, ...)
 
 int bbu_confirm(struct bbu_data *);
 
-int barebox_update(struct bbu_data *);
+int barebox_update(struct bbu_data *, struct bbu_handler *);
 
 struct bbu_handler *bbu_find_handler_by_name(const char *name);
 struct bbu_handler *bbu_find_handler_by_device(const char *devicepath);
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  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 ` Andrey Smirnov [this message]
2018-10-08  6:35 ` [PATCH v2 3/4] bbu: command: Make sure specified update handler exists Andrey Smirnov
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-3-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