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