diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-09-28 10:56:22 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-09-30 14:37:39 +0200 |
commit | df22a22f84b668da75bf14095ff4ebc475dfe79a (patch) | |
tree | e7f7c99d8898c5b8c0ea12fc6f6a60d0a7907074 | |
parent | c7428c02d72d1c74295226e7c9483e0f62f6a2aa (diff) | |
download | barebox-df22a22f84b668da75bf14095ff4ebc475dfe79a.tar.gz barebox-df22a22f84b668da75bf14095ff4ebc475dfe79a.tar.xz |
bbu: fix exporting i.MX NAND bbu handler over fastboot
handler->devicefile for i.MX NAND is nand0.barebox, which lacks a /dev/
prefix. This is ok for detection, as device_detect_by_name expects the
cdev name and devpath_to_name() will strip a /dev/ if available.
For stat() however, we need to add back /dev/, otherwise the file can't
be found. Rework the code to do that.
This fixes an issue where usbgadget -A '' -b would not export a i.MX
NAND barebox update handler.
Fixes: 726a802456bc ("common: bbu: only add available handlers")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20220928085622.2677478-1-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | common/bbu.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/common/bbu.c b/common/bbu.c index d243ac89dd..3ec17216cb 100644 --- a/common/bbu.c +++ b/common/bbu.c @@ -24,43 +24,42 @@ static LIST_HEAD(bbu_image_handlers); -static void append_bbu_entry(struct bbu_handler *handler, struct file_list *files) +static void append_bbu_entry(const char *_name, + const char *devicefile, + struct file_list *files) { char *name; - name = basprintf("bbu-%s", handler->name); + name = basprintf("bbu-%s", _name); - if (file_list_add_entry(files, name, handler->devicefile, 0)) + if (file_list_add_entry(files, name, devicefile, 0)) pr_warn("duplicate partition name %s\n", name); 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) { - if (bbu_handler_is_available(handler)) { - append_bbu_entry(handler, files); + const char *cdevname; + struct stat s; + char *devpath; + + cdevname = devpath_to_name(handler->devicefile); + device_detect_by_name(cdevname); + + devpath = basprintf("/dev/%s", cdevname); + + if (stat(devpath, &s) == 0) { + append_bbu_entry(handler->name, devpath, files); } else { pr_info("Skipping unavailable handler bbu-%s\n", handler->name); } + + free(devpath); } } |