diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-06-02 11:01:30 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-06-03 09:17:27 +0200 |
commit | cfe5484eb2cac97373da85706732678ab34cedc7 (patch) | |
tree | 18b2b243b96886afe78f4dfd58880dc1aeb7fcdb /common | |
parent | 5005f599ca88519dfa5139d4e90f3f5c5290bf31 (diff) | |
download | barebox-cfe5484eb2cac97373da85706732678ab34cedc7.tar.gz barebox-cfe5484eb2cac97373da85706732678ab34cedc7.tar.xz |
bbu: export bbu_std_file_handler for use in custom handlers
bbu_register_std_file_update() registers an update handler that updates
a single file, usually a partition. Depending on SoC, we may want to
compute the file path at install time. To save custom bbu code the
hassle of reimplementing bbu_std_file_handler(), export it.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20220602090133.3190450-5-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/bbu.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/common/bbu.c b/common/bbu.c index 26b997c02e..d243ac89dd 100644 --- a/common/bbu.c +++ b/common/bbu.c @@ -371,23 +371,13 @@ out: return ret; } -static int bbu_std_file_handler(struct bbu_handler *handler, - struct bbu_data *data) +int bbu_std_file_handler(struct bbu_handler *handler, + struct bbu_data *data) { - struct bbu_std *std = container_of(handler, struct bbu_std, handler); int fd, ret; - enum filetype filetype; struct stat s; unsigned oflags = O_WRONLY; - filetype = file_detect_type(data->image, data->len); - if (filetype != std->filetype) { - if (!bbu_force(data, "incorrect image type. Expected: %s, got %s", - file_type_to_string(std->filetype), - file_type_to_string(filetype))) - return -EINVAL; - } - device_detect_by_name(devpath_to_name(data->devicefile)); ret = stat(data->devicefile, &s); @@ -436,6 +426,23 @@ err_close: return ret; } +static int bbu_std_file_handler_checked(struct bbu_handler *handler, + struct bbu_data *data) +{ + struct bbu_std *std = container_of(handler, struct bbu_std, handler); + enum filetype filetype; + + filetype = file_detect_type(data->image, data->len); + if (filetype != std->filetype) { + if (!bbu_force(data, "incorrect image type. Expected: %s, got %s", + file_type_to_string(std->filetype), + file_type_to_string(filetype))) + return -EINVAL; + } + + return bbu_std_file_handler(handler, data); +} + /** * bbu_register_std_file_update() - register a barebox update handler for a * standard file-to-device-copy operation @@ -466,7 +473,7 @@ int bbu_register_std_file_update(const char *name, unsigned long flags, handler->flags = flags; handler->devicefile = devicefile; handler->name = name; - handler->handler = bbu_std_file_handler; + handler->handler = bbu_std_file_handler_checked; ret = bbu_register_handler(handler); if (ret) |