#include <mmc.h>
#include <spl.h>
#include <asm/global_data.h>
+#include <dm/uclass-internal.h>
#if CONFIG_IS_ENABLED(OF_LIBFDT)
/**
spl_boot_list[0] = spl_boot_device();
}
-__weak const char * const spl_boot_devices[BOOT_DEVICE_NONE + 1] = {};
-
-const char *spl_decode_boot_device(u32 boot_device)
+int spl_decode_boot_device(u32 boot_device, char *buf, size_t buflen)
{
- const char *spl_bootdevice_ofpath = NULL;
+ struct udevice *dev;
+#if CONFIG_IS_ENABLED(BLK)
+ int dev_num;
+#endif
+ int ret;
+
+ if (boot_device == BOOT_DEVICE_SPI) {
+ /* Revert spl_node_to_boot_device() logic to find appropriate SPI flash device */
+
+ /*
+ * Devices with multiple SPI flash devices will take the first SPI flash found in
+ * /chosen/u-boot,spl-boot-order.
+ */
+ const void *blob = gd->fdt_blob;
+ int chosen_node = fdt_path_offset(blob, "/chosen");
+ int elem;
+ int node;
+ const char *conf;
+
+ if (chosen_node < 0) {
+ debug("%s: /chosen not found\n", __func__);
+ return -ENODEV;
+ }
+
+ for (elem = 0;
+ (conf = fdt_stringlist_get(blob, chosen_node,
+ "u-boot,spl-boot-order", elem, NULL));
+ elem++) {
+ const char *alias;
+
+ /* Handle the case of 'same device the SPL was loaded from' */
+ if (strncmp(conf, "same-as-spl", 11) == 0) {
+ conf = board_spl_was_booted_from();
+ if (!conf)
+ continue;
+ }
+
+ /* First check if the list element is an alias */
+ alias = fdt_get_alias(blob, conf);
+ if (alias)
+ conf = alias;
+
+ /* Try to resolve the config item (or alias) as a path */
+ node = fdt_path_offset(blob, conf);
+ if (node < 0) {
+ debug("%s: could not find %s in FDT\n", __func__, conf);
+ continue;
+ }
- if (boot_device < ARRAY_SIZE(spl_boot_devices))
- spl_bootdevice_ofpath = spl_boot_devices[boot_device];
+ ret = uclass_find_device_by_of_offset(UCLASS_SPI_FLASH, node, &dev);
+ if (ret) {
+ debug("%s: could not find udevice for %s\n", __func__, conf);
+ continue;
+ }
- if (spl_bootdevice_ofpath)
- debug("%s: spl_bootdevice_id %x maps to '%s'\n",
- __func__, boot_device, spl_bootdevice_ofpath);
- else
- debug("%s: failed to resolve spl_bootdevice_id %x\n",
- __func__, boot_device);
+ return ofnode_get_path(dev_ofnode(dev), buf, buflen);
+ }
- return spl_bootdevice_ofpath;
+ return -ENODEV;
+ }
+
+#if CONFIG_IS_ENABLED(BLK)
+ dev_num = (boot_device == BOOT_DEVICE_MMC1) ? 0 : 1;
+
+ ret = blk_find_device(UCLASS_MMC, dev_num, &dev);
+ if (ret) {
+ debug("%s: could not find blk device for MMC device %d: %d\n",
+ __func__, dev_num, ret);
+ return ret;
+ }
+
+ dev = dev_get_parent(dev);
+ return ofnode_get_path(dev_ofnode(dev), buf, buflen);
+#else
+ return -ENODEV;
+#endif
}
void spl_perform_fixups(struct spl_image_info *spl_image)
{
void *blob = spl_image_fdt_addr(spl_image);
- const char *boot_ofpath;
- int chosen;
+ char boot_ofpath[512];
+ int chosen, ret;
/*
* Inject the ofpath of the device the full U-Boot (or Linux in
if (!blob)
return;
- boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
- if (!boot_ofpath) {
- pr_err("%s: could not map boot_device to ofpath\n", __func__);
+ ret = spl_decode_boot_device(spl_image->boot_device, boot_ofpath, sizeof(boot_ofpath));
+ if (ret) {
+ pr_err("%s: could not map boot_device to ofpath: %d\n", __func__, ret);
return;
}