]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/common_fit.c
Convert CONFIG_ENV_IS_IN_FLASH to Kconfig
[people/ms/u-boot.git] / common / common_fit.c
CommitLineData
3863f840
CJF
1/*
2 * Copyright (C) 2016 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <errno.h>
10#include <image.h>
11#include <libfdt.h>
12#include <spl.h>
13
14ulong fdt_getprop_u32(const void *fdt, int node, const char *prop)
15{
16 const u32 *cell;
17 int len;
18
19 cell = fdt_getprop(fdt, node, prop, &len);
20 if (!cell || len != sizeof(*cell))
21 return FDT_ERROR;
22
23 return fdt32_to_cpu(*cell);
24}
25
26/*
27 * Iterate over all /configurations subnodes and call a platform specific
28 * function to find the matching configuration.
29 * Returns the node offset or a negative error number.
30 */
31int fit_find_config_node(const void *fdt)
32{
33 const char *name;
34 int conf, node, len;
35
36 conf = fdt_path_offset(fdt, FIT_CONFS_PATH);
37 if (conf < 0) {
38 debug("%s: Cannot find /configurations node: %d\n", __func__,
39 conf);
40 return -EINVAL;
41 }
42 for (node = fdt_first_subnode(fdt, conf);
43 node >= 0;
44 node = fdt_next_subnode(fdt, node)) {
45 name = fdt_getprop(fdt, node, "description", &len);
46 if (!name) {
47#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
48 printf("%s: Missing FDT description in DTB\n",
49 __func__);
50#endif
51 return -EINVAL;
52 }
53 if (board_fit_config_name_match(name))
54 continue;
55
56 debug("Selecting config '%s'", name);
57
58 return node;
59 }
60
61 return -ENOENT;
62}