1
2
3
4
5
6#include <common.h>
7#include <dm.h>
8#include <mmc.h>
9#include <spl.h>
10
11#if CONFIG_IS_ENABLED(OF_CONTROL)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31static int spl_node_to_boot_device(int node)
32{
33 struct udevice *parent;
34
35
36
37
38
39
40 if (!uclass_get_device_by_of_offset(UCLASS_MMC, node, &parent)) {
41 struct udevice *dev;
42 struct blk_desc *desc = NULL;
43
44 for (device_find_first_child(parent, &dev);
45 dev;
46 device_find_next_child(&dev)) {
47 if (device_get_uclass_id(dev) == UCLASS_BLK) {
48 desc = dev_get_uclass_platdata(dev);
49 break;
50 }
51 }
52
53 if (!desc)
54 return -ENOENT;
55
56 switch (desc->devnum) {
57 case 0:
58 return BOOT_DEVICE_MMC1;
59 case 1:
60 return BOOT_DEVICE_MMC2;
61 default:
62 return -ENOSYS;
63 }
64 }
65
66
67
68
69
70
71
72 if (!uclass_get_device_by_of_offset(UCLASS_SPI_FLASH, node, &parent))
73 return BOOT_DEVICE_SPI;
74
75 return -1;
76}
77
78
79
80
81
82
83
84
85
86
87
88
89
90__weak const char *board_spl_was_booted_from(void)
91{
92 debug("%s: no support for 'same-as-spl' for this board\n", __func__);
93 return NULL;
94}
95
96void board_boot_order(u32 *spl_boot_list)
97{
98 const void *blob = gd->fdt_blob;
99 int chosen_node = fdt_path_offset(blob, "/chosen");
100 int idx = 0;
101 int elem;
102 int boot_device;
103 int node;
104 const char *conf;
105
106 if (chosen_node < 0) {
107 debug("%s: /chosen not found, using spl_boot_device()\n",
108 __func__);
109 spl_boot_list[0] = spl_boot_device();
110 return;
111 }
112
113 for (elem = 0;
114 (conf = fdt_stringlist_get(blob, chosen_node,
115 "u-boot,spl-boot-order", elem, NULL));
116 elem++) {
117 const char *alias;
118
119
120 if (strncmp(conf, "same-as-spl", 11) == 0) {
121 conf = board_spl_was_booted_from();
122 if (!conf)
123 continue;
124 }
125
126
127 alias = fdt_get_alias(blob, conf);
128 if (alias)
129 conf = alias;
130
131
132 node = fdt_path_offset(blob, conf);
133 if (node < 0) {
134 debug("%s: could not find %s in FDT", __func__, conf);
135 continue;
136 }
137
138
139 boot_device = spl_node_to_boot_device(node);
140 if (boot_device < 0) {
141 debug("%s: could not map node @%x to a boot-device\n",
142 __func__, node);
143 continue;
144 }
145
146 spl_boot_list[idx++] = boot_device;
147 }
148
149
150 if (idx == 0)
151 spl_boot_list[0] = spl_boot_device();
152}
153#endif
154