Blame view

common/common_fit.c 1.75 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
3863f840f   Cooper Jr., Franklin   spl: fit: Break o...
2
3
4
  /*
   * Copyright (C) 2016 Google, Inc
   * Written by Simon Glass <sjg@chromium.org>
3863f840f   Cooper Jr., Franklin   spl: fit: Break o...
5
6
7
8
9
   */
  
  #include <common.h>
  #include <errno.h>
  #include <image.h>
b08c8c487   Masahiro Yamada   libfdt: move head...
10
  #include <linux/libfdt.h>
3863f840f   Cooper Jr., Franklin   spl: fit: Break o...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  
  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;
02035d008   Jean-Jacques Hiblot   fit: If no matchi...
33
34
35
  	const char *dflt_conf_name;
  	const char *dflt_conf_desc = NULL;
  	int dflt_conf_node = -ENOENT;
3863f840f   Cooper Jr., Franklin   spl: fit: Break o...
36
37
38
39
40
41
42
43
  
  	conf = fdt_path_offset(fdt, FIT_CONFS_PATH);
  	if (conf < 0) {
  		debug("%s: Cannot find /configurations node: %d
  ", __func__,
  		      conf);
  		return -EINVAL;
  	}
02035d008   Jean-Jacques Hiblot   fit: If no matchi...
44
45
  
  	dflt_conf_name = fdt_getprop(fdt, conf, "default", &len);
3863f840f   Cooper Jr., Franklin   spl: fit: Break o...
46
47
48
49
50
51
52
53
54
55
56
57
  	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
  ",
  			       __func__);
  #endif
  			return -EINVAL;
  		}
02035d008   Jean-Jacques Hiblot   fit: If no matchi...
58
59
60
61
62
63
64
65
  
  		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;
  			}
  		}
3863f840f   Cooper Jr., Franklin   spl: fit: Break o...
66
67
68
69
70
71
72
  		if (board_fit_config_name_match(name))
  			continue;
  
  		debug("Selecting config '%s'", name);
  
  		return node;
  	}
02035d008   Jean-Jacques Hiblot   fit: If no matchi...
73
  	if (dflt_conf_node != -ENOENT) {
6514bfc29   Stefan Roese   fit: Add missing ...
74
75
  		debug("Selecting default config '%s'
  ", dflt_conf_desc);
02035d008   Jean-Jacques Hiblot   fit: If no matchi...
76
77
  		return dflt_conf_node;
  	}
3863f840f   Cooper Jr., Franklin   spl: fit: Break o...
78
79
  	return -ENOENT;
  }