diff options
Diffstat (limited to 'common/bbu.c')
-rw-r--r-- | common/bbu.c | 134 |
1 files changed, 91 insertions, 43 deletions
diff --git a/common/bbu.c b/common/bbu.c index d243ac89dd..ba2566acdf 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); } } @@ -96,17 +95,23 @@ out: int bbu_confirm(struct bbu_data *data) { int key; + const char *prompt; if (data->flags & BBU_FLAG_YES) - return 0; + prompt = "."; + else + prompt = " (y/n)?"; if (data->imagefile) - printf("update barebox from %s using handler %s to %s (y/n)?\n", - data->imagefile, data->handler_name, - data->devicefile); + printf("update barebox on %s from %s using handler %s%s\n", + data->devicefile, data->imagefile, + data->handler_name, prompt); else - printf("Refresh barebox on %s using handler %s (y/n)?\n", - data->devicefile, data->handler_name); + printf("Refresh barebox on %s using handler %s%s\n", + data->devicefile, data->handler_name, prompt); + + if (data->flags & BBU_FLAG_YES) + return 0; key = read_key(); @@ -155,36 +160,47 @@ struct bbu_handler *bbu_find_handler_by_device(const char *devicepath) return NULL; } -static int bbu_check_of_compat(struct bbu_data *data) +static int bbu_check_of_compat(struct bbu_data *data, unsigned short of_compat_nr) { + const struct imd_header *imd = data->imd_data; + const struct imd_header *of_compat; struct device_node *root_node; const char *machine, *str; int ret; - const struct imd_header *of_compat; if (!IS_ENABLED(CONFIG_OFDEVICE) || !IS_ENABLED(CONFIG_IMD)) return 0; - of_compat = imd_find_type(data->imd_data, IMD_TYPE_OF_COMPATIBLE); - if (!of_compat) - return 0; - root_node = of_get_root_node(); if (!root_node) return 0; - str = imd_string_data(of_compat, 0); - - if (of_machine_is_compatible(str)) { - pr_info("Devicetree compatible \"%s\" matches current machine\n", str); + if (!of_compat_nr) return 0; - } ret = of_property_read_string(root_node, "compatible", &machine); if (ret) return 0; - if (!bbu_force(data, "machine is incompatible with \"%s\", have \"%s\"\n", str, machine)) + for (; of_compat_nr; of_compat_nr--) { + of_compat = imd_find_type(imd, IMD_TYPE_OF_COMPATIBLE); + if (!of_compat) + return 0; + + str = imd_string_data(of_compat, 0); + + if (of_machine_is_compatible(str)) { + pr_info("Devicetree compatible \"%s\" matches current machine\n", str); + return 0; + } + + pr_debug("machine is incompatible with \"%s\", have \"%s\"\n", + str, machine); + + imd = of_compat; + } + + if (!bbu_force(data, "incompatible machine \"%s\"\n", machine)) return -EINVAL; return 0; @@ -192,6 +208,7 @@ static int bbu_check_of_compat(struct bbu_data *data) static int bbu_check_metadata(struct bbu_data *data) { + unsigned short imd_of_compat_nr = 0; const struct imd_header *imd; int ret; char *str; @@ -212,6 +229,9 @@ static int bbu_check_metadata(struct bbu_data *data) imd_for_each(data->imd_data, imd) { uint32_t type = imd_read_type(imd); + if (imd_read_type(imd) == IMD_TYPE_OF_COMPATIBLE) + imd_of_compat_nr++; + if (!imd_is_string(type)) continue; @@ -221,7 +241,7 @@ static int bbu_check_metadata(struct bbu_data *data) free(str); } - ret = bbu_check_of_compat(data); + ret = bbu_check_of_compat(data, imd_of_compat_nr); if (ret) return ret; @@ -346,11 +366,7 @@ int bbu_mmcboot_handler(struct bbu_handler *handler, struct bbu_data *data, if (ret < 0) goto out; - /* - * This flag can be set in the chained handler or by - * bbu_mmcboot_handler's caller - */ - if ((_data.flags | data->flags) & BBU_FLAG_MMC_BOOT_ACK) { + if (handler->flags & BBU_HANDLER_FLAG_MMC_BOOT_ACK) { ret = asprintf(&bootackvar, "%s.boot_ack", devname); if (ret < 0) goto out; @@ -371,6 +387,38 @@ out: return ret; } +static int bbu_internal_mmcboot_update(struct bbu_handler *handler, + struct bbu_data *data) +{ + int ret; + + ret = bbu_mmcboot_handler(handler, data, bbu_std_file_handler); + if (ret == -ENOENT) + pr_err("Couldn't read the value of .boot parameter\n"); + + return ret; +} + +int bbu_mmcboot_register_handler(const char *name, + const char *devicefile, + unsigned long flags) +{ + struct bbu_handler *handler; + int ret; + + handler = xzalloc(sizeof(*handler)); + handler->devicefile = devicefile; + handler->name = name; + handler->handler = bbu_internal_mmcboot_update; + handler->flags = flags; + + ret = bbu_register_handler(handler); + if (ret) + free(handler); + + return ret; +} + int bbu_std_file_handler(struct bbu_handler *handler, struct bbu_data *data) { |