From 726a802456bc200698cf921763cc27668eb3b649 Mon Sep 17 00:00:00 2001 From: Rouven Czerwinski Date: Fri, 18 Jun 2021 14:05:57 +0200 Subject: common: bbu: only add available handlers 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 Link: https://lore.barebox.org/20210618120557.2192098-1-r.czerwinski@pengutronix.de Signed-off-by: Sascha Hauer --- common/bbu.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/bbu.c b/common/bbu.c index 1a1edda96b..b6a0e623e2 100644 --- a/common/bbu.c +++ b/common/bbu.c @@ -32,12 +32,32 @@ 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, ...) -- cgit v1.2.3 From 589f4236c53e299f735aecee472e01a49e26f0d1 Mon Sep 17 00:00:00 2001 From: Rouven Czerwinski Date: Fri, 18 Jun 2021 14:05:58 +0200 Subject: common: bbu: add pr_fmt This makes it easier to identify where messages are coming from. Signed-off-by: Rouven Czerwinski Link: https://lore.barebox.org/20210618120557.2192098-2-r.czerwinski@pengutronix.de Signed-off-by: Sascha Hauer --- common/bbu.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'common') diff --git a/common/bbu.c b/common/bbu.c index b6a0e623e2..cd7bdc40b7 100644 --- a/common/bbu.c +++ b/common/bbu.c @@ -4,6 +4,9 @@ * * Copyright (c) 2012 Sascha Hauer , Pengutronix */ + +#define pr_fmt(fmt) "bbu: " fmt + #include #include #include -- cgit v1.2.3