2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-06-16 22:25:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <image.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2017-06-16 22:25:05 +00:00
|
|
|
|
|
|
|
ulong fdt_getprop_u32(const void *fdt, int node, const char *prop)
|
|
|
|
{
|
|
|
|
const u32 *cell;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
cell = fdt_getprop(fdt, node, prop, &len);
|
|
|
|
if (!cell || len != sizeof(*cell))
|
|
|
|
return FDT_ERROR;
|
|
|
|
|
|
|
|
return fdt32_to_cpu(*cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over all /configurations subnodes and call a platform specific
|
|
|
|
* function to find the matching configuration.
|
|
|
|
* Returns the node offset or a negative error number.
|
|
|
|
*/
|
|
|
|
int fit_find_config_node(const void *fdt)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
int conf, node, len;
|
2017-09-15 10:57:27 +00:00
|
|
|
const char *dflt_conf_name;
|
|
|
|
const char *dflt_conf_desc = NULL;
|
|
|
|
int dflt_conf_node = -ENOENT;
|
2017-06-16 22:25:05 +00:00
|
|
|
|
|
|
|
conf = fdt_path_offset(fdt, FIT_CONFS_PATH);
|
|
|
|
if (conf < 0) {
|
|
|
|
debug("%s: Cannot find /configurations node: %d\n", __func__,
|
|
|
|
conf);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-09-15 10:57:27 +00:00
|
|
|
|
|
|
|
dflt_conf_name = fdt_getprop(fdt, conf, "default", &len);
|
|
|
|
|
2017-06-16 22:25:05 +00:00
|
|
|
for (node = fdt_first_subnode(fdt, conf);
|
|
|
|
node >= 0;
|
|
|
|
node = fdt_next_subnode(fdt, node)) {
|
|
|
|
name = fdt_getprop(fdt, node, "description", &len);
|
|
|
|
if (!name) {
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
|
|
|
printf("%s: Missing FDT description in DTB\n",
|
|
|
|
__func__);
|
|
|
|
#endif
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-09-15 10:57:27 +00:00
|
|
|
|
|
|
|
if (dflt_conf_name) {
|
|
|
|
const char *node_name = fdt_get_name(fdt, node, NULL);
|
|
|
|
if (strcmp(dflt_conf_name, node_name) == 0) {
|
|
|
|
dflt_conf_node = node;
|
|
|
|
dflt_conf_desc = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 22:25:05 +00:00
|
|
|
if (board_fit_config_name_match(name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
debug("Selecting config '%s'", name);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2017-09-15 10:57:27 +00:00
|
|
|
if (dflt_conf_node != -ENOENT) {
|
2018-11-08 06:00:31 +00:00
|
|
|
debug("Selecting default config '%s'\n", dflt_conf_desc);
|
2017-09-15 10:57:27 +00:00
|
|
|
return dflt_conf_node;
|
|
|
|
}
|
|
|
|
|
2017-06-16 22:25:05 +00:00
|
|
|
return -ENOENT;
|
|
|
|
}
|