rpi: use board_early_init_r to init PCI/USB and detect boot device
authorMarek Szyprowski <m.szyprowski@samsung.com>
Fri, 29 Jan 2021 12:03:03 +0000 (13:03 +0100)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Tue, 16 Nov 2021 12:00:22 +0000 (13:00 +0100)
Move initialization of the PCI and the USB subsystems from the 'preboot'
command to the board's early_init_r() function and then try to detect a
boot device by accessing the MMC0 device. If it works, then set boot
device interface to 'mmc', if not, use 'usb'.

This allows the environment variales to be loaded from the proper
storage interface.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: Idf06ba827167479510206587308875c8eedce892

board/raspberrypi/rpi/rpi.c
configs/rpi_4_32b_defconfig
configs/rpi_4_defconfig

index 2e0e475..bc3cc59 100644 (file)
@@ -23,6 +23,7 @@
 #ifdef CONFIG_ARM64
 #include <asm/armv8/mmu.h>
 #endif
+#include <usb.h>
 #include <watchdog.h>
 #include <dm/pinctrl.h>
 
@@ -461,6 +462,30 @@ static void set_serial_number(void)
        env_set("serial#", serial_string);
 }
 
+#if defined(CONFIG_PCI) && defined(CONFIG_BOARD_EARLY_INIT_R)
+static char *boot_interface;
+int board_early_init_r(void)
+{
+       /*
+        * Currently there is not way to detect which device (SD card or
+        * USB Mass Storage) has been used by VideoCore to load the uboot,
+        * so just try MMC0 first, if not then use USB.
+        */
+       mmc_init_device(0);
+       boot_interface = (blk_get_dev("mmc", 0)) ? "mmc" : "usb";
+
+       pci_init();
+       usb_init();
+
+       return 0;
+}
+
+char *env_fat_get_interface(void)
+{
+       return boot_interface;
+}
+#endif
+
 int misc_init_r(void)
 {
        set_fdt_addr();
index c9d4099..54b1e8a 100644 (file)
@@ -7,11 +7,12 @@ CONFIG_ENV_SIZE=0x4000
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="pci enum; usb start"
+CONFIG_PREBOOT=""
 CONFIG_SYS_STDIO_DEREGISTER=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_MISC_INIT_R=y
+CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_SYS_PROMPT="U-Boot> "
 CONFIG_CMD_THOR_DOWNLOAD=y
 CONFIG_CMD_ASKENV=y
index 46f2bc2..c9e2500 100644 (file)
@@ -7,11 +7,12 @@ CONFIG_ENV_SIZE=0x4000
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="pci enum; usb start"
+CONFIG_PREBOOT=""
 CONFIG_SYS_STDIO_DEREGISTER=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_MISC_INIT_R=y
+CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_SYS_PROMPT="U-Boot> "
 CONFIG_CMD_THOR_DOWNLOAD=y
 CONFIG_CMD_ASKENV=y