1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
12 #if CONFIG_IS_ENABLED(OF_LIBFDT)
14 * spl_node_to_boot_device() - maps from a DT-node to a SPL boot device
15 * @node: of_offset of the node
17 * The SPL framework uses BOOT_DEVICE_... constants to identify its boot
18 * sources. These may take on a device-specific meaning, depending on
19 * what nodes are enabled in a DTS (e.g. BOOT_DEVICE_MMC1 may refer to
20 * different controllers/block-devices, depending on which SD/MMC controllers
21 * are enabled in any given DTS). This function maps from a DT-node back
22 * onto a BOOT_DEVICE_... constant, considering the currently active devices.
25 * -ENOENT, if no device matching the node could be found
26 * -ENOSYS, if the device matching the node can not be mapped onto a
27 * SPL boot device (e.g. the third MMC device)
28 * -1, for unspecified failures
29 * a positive integer (from the BOOT_DEVICE_... family) on succes.
32 static int spl_node_to_boot_device(int node)
34 struct udevice *parent;
37 * This should eventually move into the SPL code, once SPL becomes
38 * aware of the block-device layer. Until then (and to avoid unneeded
39 * delays in getting this feature out), it lives at the board-level.
41 if (!uclass_get_device_by_of_offset(UCLASS_MMC, node, &parent)) {
43 struct blk_desc *desc = NULL;
45 for (device_find_first_child(parent, &dev);
47 device_find_next_child(&dev)) {
48 if (device_get_uclass_id(dev) == UCLASS_BLK) {
49 desc = dev_get_uclass_plat(dev);
57 switch (desc->devnum) {
59 return BOOT_DEVICE_MMC1;
61 return BOOT_DEVICE_MMC2;
65 } else if (!uclass_get_device_by_of_offset(UCLASS_SPI_FLASH, node,
67 return BOOT_DEVICE_SPI;
71 * SPL doesn't differentiate SPI flashes, so we keep the detection
72 * brief and inaccurate... hopefully, the common SPL layer can be
73 * extended with awareness of the BLK layer (and matching OF_CONTROL)
76 if (!uclass_get_device_by_of_offset(UCLASS_SPI_FLASH, node, &parent))
77 return BOOT_DEVICE_SPI;
83 * board_spl_was_booted_from() - retrieves the of-path the SPL was loaded from
85 * To support a 'same-as-spl' specification in the search-order for the next
86 * stage, we need a SoC- or board-specific way to handshake with what 'came
87 * before us' (either a BROM or TPL stage) and map the info retrieved onto
91 * NULL, on failure or if the device could not be identified
92 * a of_path (a string), on success
94 __weak const char *board_spl_was_booted_from(void)
96 debug("%s: no support for 'same-as-spl' for this board\n", __func__);
100 void board_boot_order(u32 *spl_boot_list)
102 /* In case of no fdt (or only plat), use spl_boot_device() */
103 if (!CONFIG_IS_ENABLED(OF_CONTROL) || CONFIG_IS_ENABLED(OF_PLATDATA)) {
104 spl_boot_list[0] = spl_boot_device();
108 const void *blob = gd->fdt_blob;
109 int chosen_node = fdt_path_offset(blob, "/chosen");
116 if (chosen_node < 0) {
117 debug("%s: /chosen not found, using spl_boot_device()\n",
119 spl_boot_list[0] = spl_boot_device();
124 (conf = fdt_stringlist_get(blob, chosen_node,
125 "u-boot,spl-boot-order", elem, NULL));
129 /* Handle the case of 'same device the SPL was loaded from' */
130 if (strncmp(conf, "same-as-spl", 11) == 0) {
131 conf = board_spl_was_booted_from();
136 /* First check if the list element is an alias */
137 alias = fdt_get_alias(blob, conf);
141 /* Try to resolve the config item (or alias) as a path */
142 node = fdt_path_offset(blob, conf);
144 debug("%s: could not find %s in FDT\n", __func__, conf);
148 /* Try to map this back onto SPL boot devices */
149 boot_device = spl_node_to_boot_device(node);
150 if (boot_device < 0) {
151 debug("%s: could not map node @%x to a boot-device\n",
156 spl_boot_list[idx++] = boot_device;
159 /* If we had no matches, fall back to spl_boot_device */
161 spl_boot_list[0] = spl_boot_device();