u-boot/common/common_fit.c
Masahiro Yamada b08c8c4870 libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>
Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
  include/libfdt.h         -> include/linux/libfdt.h
  include/libfdt_env.h     -> include/linux/libfdt_env.h

and replaces include directives:
  #include <libfdt.h>      -> #include <linux/libfdt.h>
  #include <libfdt_env.h>  -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-03-05 10:16:28 -05:00

83 lines
1.8 KiB
C

/*
* Copyright (C) 2016 Google, Inc
* Written by Simon Glass <sjg@chromium.org>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <errno.h>
#include <image.h>
#include <linux/libfdt.h>
#include <spl.h>
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;
const char *dflt_conf_name;
const char *dflt_conf_desc = NULL;
int dflt_conf_node = -ENOENT;
conf = fdt_path_offset(fdt, FIT_CONFS_PATH);
if (conf < 0) {
debug("%s: Cannot find /configurations node: %d\n", __func__,
conf);
return -EINVAL;
}
dflt_conf_name = fdt_getprop(fdt, conf, "default", &len);
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;
}
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;
}
}
if (board_fit_config_name_match(name))
continue;
debug("Selecting config '%s'", name);
return node;
}
if (dflt_conf_node != -ENOENT) {
debug("Selecting default config '%s'", dflt_conf_desc);
return dflt_conf_node;
}
return -ENOENT;
}