mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] common: bbu: only add available handlers
@ 2021-06-18 12:05 Rouven Czerwinski
  2021-06-18 12:05 ` [PATCH 2/2] common: bbu: add pr_fmt Rouven Czerwinski
  2021-06-21  4:38 ` [PATCH 1/2] common: bbu: only add available handlers Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Rouven Czerwinski @ 2021-06-18 12:05 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

A board may have multiple handlers registered:

  registered update handlers:
    SD          -> /dev/mmc0.barebox
  * eMMC        -> /dev/mmc1

However when using the usbgadget with the -b command line argument,
fastboot will stat all devicefiles listed in the handlers and will fail
if i.e. the SD card is not available:

  usbgadget -A /dev/mmc1(root) -b
  udc0: registering UDC driver [g_multi]
  multi_bind: creating Fastboot function
  ERROR: g_multi udc0: failed to start g_multi: -2
  usbgadget: No such file or directory

To fix this, check the availability of handlers before adding them to
the list and skip those that are not available with an info level message.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 common/bbu.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/common/bbu.c b/common/bbu.c
index 1a1edda96b..a66be553e9 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -32,12 +32,31 @@ static void append_bbu_entry(struct bbu_handler *handler, struct file_list *file
 	free(name);
 }
 
+static bool bbu_handler_is_available(struct bbu_handler *handler)
+{
+	struct stat s;
+	int ret;
+
+	device_detect_by_name(devpath_to_name(handler->devicefile));
+	ret = stat(handler->devicefile, &s);
+
+	if(ret)
+		return false;
+	return true;
+}
+
 void bbu_append_handlers_to_file_list(struct file_list *files)
 {
 	struct bbu_handler *handler;
 
-	list_for_each_entry(handler, &bbu_image_handlers, list)
-		append_bbu_entry(handler, files);
+	list_for_each_entry(handler, &bbu_image_handlers, list) {
+		if(bbu_handler_is_available(handler)) {
+			append_bbu_entry(handler, files);
+		} else {
+			pr_info("Skipping unavailable handler bbu-%s\n",
+				handler->name);
+		}
+	}
 }
 
 int bbu_force(struct bbu_data *data, const char *fmt, ...)
-- 
2.31.1


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] common: bbu: add pr_fmt
  2021-06-18 12:05 [PATCH 1/2] common: bbu: only add available handlers Rouven Czerwinski
@ 2021-06-18 12:05 ` Rouven Czerwinski
  2021-06-21  4:38 ` [PATCH 1/2] common: bbu: only add available handlers Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Rouven Czerwinski @ 2021-06-18 12:05 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

This makes it easier to identify where messages are coming from.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 common/bbu.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/common/bbu.c b/common/bbu.c
index a66be553e9..deb6a007c9 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -4,6 +4,9 @@
  *
  * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
  */
+
+#define pr_fmt(fmt) "bbu: " fmt
+
 #include <common.h>
 #include <bbu.h>
 #include <linux/list.h>
-- 
2.31.1


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] common: bbu: only add available handlers
  2021-06-18 12:05 [PATCH 1/2] common: bbu: only add available handlers Rouven Czerwinski
  2021-06-18 12:05 ` [PATCH 2/2] common: bbu: add pr_fmt Rouven Czerwinski
@ 2021-06-21  4:38 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2021-06-21  4:38 UTC (permalink / raw)
  To: Rouven Czerwinski; +Cc: barebox

On Fri, Jun 18, 2021 at 02:05:57PM +0200, Rouven Czerwinski wrote:
> A board may have multiple handlers registered:
> 
>   registered update handlers:
>     SD          -> /dev/mmc0.barebox
>   * eMMC        -> /dev/mmc1
> 
> However when using the usbgadget with the -b command line argument,
> fastboot will stat all devicefiles listed in the handlers and will fail
> if i.e. the SD card is not available:
> 
>   usbgadget -A /dev/mmc1(root) -b
>   udc0: registering UDC driver [g_multi]
>   multi_bind: creating Fastboot function
>   ERROR: g_multi udc0: failed to start g_multi: -2
>   usbgadget: No such file or directory
> 
> To fix this, check the availability of handlers before adding them to
> the list and skip those that are not available with an info level message.
> 
> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> ---
>  common/bbu.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)

Applied with some whitespace changes, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-21  4:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 12:05 [PATCH 1/2] common: bbu: only add available handlers Rouven Czerwinski
2021-06-18 12:05 ` [PATCH 2/2] common: bbu: add pr_fmt Rouven Czerwinski
2021-06-21  4:38 ` [PATCH 1/2] common: bbu: only add available handlers Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox