diff options
author | Steffen Trumtrar <s.trumtrar@pengutronix.de> | 2017-03-29 09:59:27 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-03-31 07:56:34 +0200 |
commit | 65ecf17f72015848175650f110aed160e913e4e5 (patch) | |
tree | a22bb58e482d7ea69c406fb51c27d5c682610eb5 /common/image-fit.c | |
parent | 462f2af3a08f71223e78b5d406dd1a1ba02dd113 (diff) | |
download | barebox-65ecf17f72015848175650f110aed160e913e4e5.tar.gz barebox-65ecf17f72015848175650f110aed160e913e4e5.tar.xz |
bootm: fit: support multiple configuration nodes
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/image-fit.c')
-rw-r--r-- | common/image-fit.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/common/image-fit.c b/common/image-fit.c index 0536c49b12..81433e6ecf 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -491,6 +491,38 @@ static int fit_config_verify_signature(struct fit_handle *handle, struct device_ return ret; } +static int fit_find_compatible_unit(struct device_node *conf_node, + const char **unit) +{ + struct device_node *child = NULL; + struct device_node *barebox_root; + const char *machine; + int ret; + + barebox_root = of_get_root_node(); + if (!barebox_root) + goto default_unit; + + ret = of_property_read_string(barebox_root, "compatible", &machine); + if (ret) + return -ENOENT; + + for_each_child_of_node(conf_node, child) { + if (of_device_is_compatible(child, machine)) { + *unit = child->name; + pr_info("matching unit '%s' found\n", *unit); + return 0; + } + } + +default_unit: + pr_info("No match found. Trying default.\n"); + if (of_property_read_string(conf_node, "default", unit) == 0) + return 0; + + return -ENOENT; +} + static int fit_open_configuration(struct fit_handle *handle, const char *name) { struct device_node *conf_node = NULL; @@ -503,8 +535,12 @@ static int fit_open_configuration(struct fit_handle *handle, const char *name) if (name) { unit = name; - } else if (of_property_read_string(conf_node, "default", &unit)) { - unit = "conf@1"; + } else { + ret = fit_find_compatible_unit(conf_node, &unit); + if (ret) { + pr_info("Couldn't get a valid configuration. Aborting.\n"); + return ret; + } } conf_node = of_get_child_by_name(conf_node, unit); |