]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
amd: versal2: detect spi env bus from boot mode
authorSuraj Kakade <suraj.hanumantkakade@amd.com>
Wed, 10 Jun 2026 11:05:31 +0000 (16:35 +0530)
committerMichal Simek <michal.simek@amd.com>
Wed, 8 Jul 2026 06:55:50 +0000 (08:55 +0200)
Add spi_get_env_dev() to dynamically detect the correct SPI
bus based on the actual boot mode at runtime. This ensures
environment variables are always loaded from the correct SPI
flash controller regardless of the bus numbering.

For example, on some Versal Gen 2 boards, SPI is disabled in DTS
leaving bus 0 empty in DM. Only QSPI is enabled at bus 1. The
default CONFIG_ENV_SPI_BUS=0 causes U-Boot to search for environment
at bus 0 which does not exist, triggering the warning
"spi_flash_probe_bus_cs() failed, using default environment".

Signed-off-by: Suraj Kakade <suraj.hanumantkakade@amd.com>
Link: https://lore.kernel.org/r/20260610110557.2183203-1-suraj.hanumantkakade@amd.com
Signed-off-by: Michal Simek <michal.simek@amd.com>
board/amd/versal2/board.c

index ec28e60c4109dd6d4886a6670e2970d95cdcd00f..6e4f0c6e9b8f2a1d38300ae58dc07ce189f91de2 100644 (file)
@@ -605,3 +605,31 @@ void set_dfu_alt_info(char *interface, char *devstr)
        env_set("dfu_alt_info", buf);
 }
 #endif
+
+int spi_get_env_dev(void)
+{
+       struct udevice *dev;
+       const char *name;
+       int bootseq;
+
+       switch (versal2_get_bootmode()) {
+       case QSPI_MODE_24BIT:
+       case QSPI_MODE_32BIT:
+               name = "spi@f1030000";
+               break;
+       case OSPI_MODE:
+               name = "spi@f1010000";
+               break;
+       default:
+               return -1;
+       }
+
+       if (uclass_get_device_by_name(UCLASS_SPI, name, &dev)) {
+               debug("SPI driver for %s is not present\n", name);
+               return -1;
+       }
+
+       bootseq = dev_seq(dev);
+       debug("bootseq %d\n", bootseq);
+       return bootseq;
+}