[U-Boot] [PATCH 1/4] spl: spl_mmc: provide one weak function spl_boot_partition

The spl_boot_partition function has been added in order to have the possibility to boot on a same binary from different mmc devices with different partitions.
By default keep the current behavior, SPL use the partition defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION.
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com Signed-off-by: Christophe KERELLO christophe.kerello@st.com ---
common/spl/spl_mmc.c | 15 +++++++++++++-- include/spl.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 351f4ed..4aa0b2c 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -292,6 +292,14 @@ u32 __weak spl_boot_mode(const u32 boot_device) #endif }
+#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION +__weak +int spl_boot_partition(const u32 boot_device) +{ + return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION; +} +#endif + int spl_mmc_load_image(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { @@ -347,8 +355,11 @@ int spl_mmc_load_image(struct spl_image_info *spl_image, return err; } #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION - err = mmc_load_image_raw_partition(spl_image, mmc, - CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION); + err = spl_boot_partition(bootdev->boot_device); + if (!err) + return err; + + err = mmc_load_image_raw_partition(spl_image, mmc, err); if (!err) return err; #endif diff --git a/include/spl.h b/include/spl.h index c14448b..5754012 100644 --- a/include/spl.h +++ b/include/spl.h @@ -82,6 +82,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, void preloader_console_init(void); u32 spl_boot_device(void); u32 spl_boot_mode(const u32 boot_device); +int spl_boot_partition(const u32 boot_device); void spl_set_bd(void);
/**

Add command GPT support Add EMMC boot support Add the 2 other SDMMC instances for ED1: - SDMMC2 = mmc 1, eMMC on the ED1 board - SDMMC3 = extension connector, deactivated by default
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com ---
arch/arm/dts/stm32mp157.dtsi | 28 +++++++++++ arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi | 21 ++++++++ arch/arm/dts/stm32mp157c-ed1.dts | 37 ++++++++++++++ board/st/stm32mp1/README | 83 +++++++++++++++++++++++--------- configs/stm32mp15_basic_defconfig | 1 + include/configs/stm32mp1.h | 1 + 6 files changed, 147 insertions(+), 24 deletions(-)
diff --git a/arch/arm/dts/stm32mp157.dtsi b/arch/arm/dts/stm32mp157.dtsi index 32d3984..77953c8 100644 --- a/arch/arm/dts/stm32mp157.dtsi +++ b/arch/arm/dts/stm32mp157.dtsi @@ -86,6 +86,20 @@ status = "disabled"; };
+ sdmmc3: sdmmc@48004000 { + compatible = "st,stm32-sdmmc2"; + reg = <0x48004000 0x400>, <0x48005000 0x400>; + reg-names = "sdmmc", "delay"; + interrupts = <GIC_SPI 137 IRQ_TYPE_NONE>; + clocks = <&rcc_clk SDMMC3_K>; + resets = <&rcc_rst SDMMC3_R>; + st,idma = <1>; + cap-sd-highspeed; + cap-mmc-highspeed; + max-frequency = <120000000>; + status = "disabled"; + }; + rcc: rcc@50000000 { compatible = "syscon", "simple-mfd";
@@ -288,6 +302,20 @@ status = "disabled"; };
+ sdmmc2: sdmmc@58007000 { + compatible = "st,stm32-sdmmc2"; + reg = <0x58007000 0x1000>, <0x58008000 0x1000>; + reg-names = "sdmmc", "delay"; + interrupts = <GIC_SPI 124 IRQ_TYPE_NONE>; + clocks = <&rcc_clk SDMMC2_K>; + resets = <&rcc_rst SDMMC2_R>; + st,idma = <1>; + cap-sd-highspeed; + cap-mmc-highspeed; + max-frequency = <120000000>; + status = "disabled"; + }; + i2c4: i2c@5c002000 { compatible = "st,stm32f7-i2c"; reg = <0x5c002000 0x400>; diff --git a/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi b/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi index 94d27fb..5d43753 100644 --- a/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi +++ b/arch/arm/dts/stm32mp157c-ed1-u-boot.dtsi @@ -11,6 +11,7 @@ / { aliases { mmc0 = &sdmmc1; + mmc1 = &sdmmc2; i2c3 = &i2c4; }; }; @@ -77,6 +78,7 @@ CLK_SDMMC12_PLL3R CLK_I2C46_PCLK5 CLK_I2C12_PCLK1 + CLK_SDMMC3_PLL3R CLK_I2C35_PCLK1 CLK_UART1_PCLK5 CLK_UART24_PCLK1 @@ -131,3 +133,22 @@ &sdmmc1 { u-boot,dm-spl; }; + +/* MMC2 boot */ +&sdmmc2_b4_pins_a { + u-boot,dm-spl; + pins { + u-boot,dm-spl; + }; +}; + +&sdmmc2_d47_pins_a { + u-boot,dm-spl; + pins { + u-boot,dm-spl; + }; +}; + +&sdmmc2 { + u-boot,dm-spl; +}; diff --git a/arch/arm/dts/stm32mp157c-ed1.dts b/arch/arm/dts/stm32mp157c-ed1.dts index 4b20fab..129cd02 100644 --- a/arch/arm/dts/stm32mp157c-ed1.dts +++ b/arch/arm/dts/stm32mp157c-ed1.dts @@ -112,6 +112,31 @@ bias-pull-up; }; }; + sdmmc2_b4_pins_a: sdmmc2-b4@0 { + pins { + pinmux = <STM32_PINMUX('B', 14, AF9)>, /* SDMMC2_D0 */ + <STM32_PINMUX('B', 15, AF9)>, /* SDMMC2_D1 */ + <STM32_PINMUX('B', 3, AF9)>, /* SDMMC2_D2 */ + <STM32_PINMUX('B', 4, AF9)>, /* SDMMC2_D3 */ + <STM32_PINMUX('E', 3, AF9)>, /* SDMMC2_CK */ + <STM32_PINMUX('G', 6, AF10)>; /* SDMMC2_CMD */ + slew-rate = <3>; + drive-push-pull; + bias-pull-up; + }; + }; + + sdmmc2_d47_pins_a: sdmmc2-d47@0 { + pins { + pinmux = <STM32_PINMUX('A', 8, AF9)>, /* SDMMC2_D4 */ + <STM32_PINMUX('A', 9, AF10)>, /* SDMMC2_D5 */ + <STM32_PINMUX('E', 5, AF9)>, /* SDMMC2_D6 */ + <STM32_PINMUX('D', 3, AF9)>; /* SDMMC2_D7 */ + slew-rate = <3>; + drive-push-pull; + bias-pull-up; + }; + }; };
&pinctrl_z { @@ -160,6 +185,18 @@ status = "okay"; };
+&sdmmc2 { + pinctrl-names = "default"; + pinctrl-0 = <&sdmmc2_b4_pins_a &sdmmc2_d47_pins_a>; + non-removable; + no-sd; + no-sdio; + st,dirpol; + st,negedge; + bus-width = <8>; + status = "okay"; +}; + &uart4 { pinctrl-names = "default"; pinctrl-0 = <&uart4_pins_a>; diff --git a/board/st/stm32mp1/README b/board/st/stm32mp1/README index 4adc978..42a39d0 100644 --- a/board/st/stm32mp1/README +++ b/board/st/stm32mp1/README @@ -115,7 +115,31 @@ the supported device trees for stm32mp157 are: + FSBL = spl/u-boot-spl.stm32 + SSBL = u-boot.img
-6. Prepare an SDCard +6. Switch Setting for Boot Mode +=============================== + +You can select the boot mode, on the board ed1 with the switch SW1 + + ----------------------------------- + Boot Mode BOOT2 BOOT1 BOOT0 + ----------------------------------- + Reserved 0 0 0 + NOR 0 0 1 + SD-Card 1 1 1 + SD-Card 1 0 1 + eMMC 0 1 0 + NAND 0 1 1 + Recovery 1 1 0 + Recovery 0 0 0 + +Recovery is a boot from serial link (UART/USB) and it is used with +STM32CubeProgrammer tool to load executable in RAM and to update the flash +devices available on the board (NOR/NAND/eMMC/SDCARD). +The communication between HOST and board is based on +- for UARTs : the uart protocol used with all MCU STM32 +- for USB : based on USB DFU 1.1 (without the ST extensions used on MCU STM32) + +7. Prepare an SDCard ===================
The minimal requirements for STMP32MP1 boot up to U-Boot are: @@ -147,13 +171,13 @@ for example: with gpt table with 128 entries # sgdisk -o /dev/<SDCard dev>
b) create minimal image - # sgdisk --resize-table=128 -a 1 \ + # sgdisk --resize-table=128 -a 1 \ -n 1:34:545 -c 1:fsbl1 \ -n 2:546:1057 -c 2:fsbl2 \ -n 3:1058:5153 -c 3:ssbl \ -p /dev/<SDCard dev>
- you can add other partition for kernel (rootfs) + you can add other partition for kernel (rootfs for example)
c) copy the FSBL (2 times) and SSBL file on the correct partition. in this example in partition 1 to 3 @@ -163,29 +187,40 @@ for example: with gpt table with 128 entries # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p2 # dd if=u-boot.img of=/dev/mmcblk0p3
-7. Switch Setting -================== - -You can select the boot mode, on the board ed1 with the switch SW1 +To boot from SDCard, select BootPinMode = 1 1 1 and reset.
- ----------------------------------- - Boot Mode BOOT2 BOOT1 BOOT0 - ----------------------------------- - Reserved 0 0 0 - NOR 0 0 1 - SD-Card 1 1 1 - SD-Card 1 0 1 - eMMC 0 1 0 - NAND 0 1 1 - Recovery 1 1 0 - Recovery 0 0 0 +8. Prepare eMMC +=============== +You can use U-Boot to copy binary in eMMC.
+In the next example, you need to boot from SDCARD and the images (u-boot-spl.stm32, u-boot.img) +are presents on SDCARD (mmc 0) in ext4 partition 4 (bootfs).
To boot from SDCard, select BootPinMode = 1 1 1 and reset.
-Recovery is a boot from serial link (UART/USB) and it is used with -STM32CubeProgrammer tool to load executable in RAM and to update the flash -devices available on the board (NOR/NAND/eMMC/SDCARD). -The communication between HOST and board is based on -- for UARTs : the uart protocol used with all MCU STM32 -- for USB : based on USB DFU 1.1 (without the ST extensions used on MCU STM32) +Then you update the eMMC with the next U-Boot command : + +a) prepare GPT on eMMC, + example with 2 partitions, bootfs and roots: + + # setenv emmc_part "name=ssbl,size=2MiB;name=bootfs,type=linux,bootable,size=64MiB;name=rootfs,type=linux,size=512" + # gpt write mmc 1 ${emmc_part} + +b) copy SPL on eMMC on firts boot partition + (SPL max size is 256kB, with LBA 512, 0x200) + + # ext4load mmc 0:4 0xC0000000 u-boot-spl.stm32 + # mmc dev 1 + # mmc partconf 1 1 1 1 + # mmc write ${fileaddr} 0 200 + # mmc partconf 1 1 1 0 + +b) copy U-Boot in first GPT partition of eMMC + + # ext4load mmc 0:4 0xC0000000 u-boot.img + # mmc dev 1 + # part start mmc 1 1 partstart + # part size mmc 1 1 partsize + # mmc write ${fileaddr} ${partstart} ${partsize} + +To boot from eMMC, select BootPinMode = 0 1 0 and reset. diff --git a/configs/stm32mp15_basic_defconfig b/configs/stm32mp15_basic_defconfig index 4ab1d4c..0f5950f 100644 --- a/configs/stm32mp15_basic_defconfig +++ b/configs/stm32mp15_basic_defconfig @@ -19,6 +19,7 @@ CONFIG_SYS_PROMPT="STM32MP> " # CONFIG_CMD_IMPORTENV is not set CONFIG_CMD_MEMINFO=y CONFIG_CMD_GPIO=y +CONFIG_CMD_GPT=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y CONFIG_CMD_PMIC=y diff --git a/include/configs/stm32mp1.h b/include/configs/stm32mp1.h index aae2cb8..6281dd5 100644 --- a/include/configs/stm32mp1.h +++ b/include/configs/stm32mp1.h @@ -71,6 +71,7 @@
/*MMC SD*/ #define CONFIG_SYS_MMC_MAX_DEVICE 3 +#define CONFIG_SUPPORT_EMMC_BOOT
#if !defined(CONFIG_SPL) || !defined(CONFIG_SPL_BUILD)

On Tue, Mar 20, 2018 at 10:54:52AM +0100, Patrick Delaunay wrote:
Add command GPT support Add EMMC boot support Add the 2 other SDMMC instances for ED1:
- SDMMC2 = mmc 1, eMMC on the ED1 board
- SDMMC3 = extension connector, deactivated by default
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com
Applied to u-boot/master, thanks!

SPL copy BootRom boot mode information in TAMP register 21.
This TAMP register information is used after relocation to set 2 env variables - boot_device - boot_instance
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com ---
arch/arm/Kconfig | 1 + arch/arm/mach-stm32mp/cpu.c | 92 ++++++++++++++++++++++++++++++ arch/arm/mach-stm32mp/include/mach/stm32.h | 53 +++++++++++++++++ 3 files changed, 146 insertions(+)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 14c13b4..425f533 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1150,6 +1150,7 @@ config ARCH_STI
config ARCH_STM32MP bool "Support STMicroelectronics STM32MP Socs with cortex A" + select ARCH_MISC_INIT select BOARD_LATE_INIT select CLK select DM diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c index 3e5ac15..4ba2aec 100644 --- a/arch/arm/mach-stm32mp/cpu.c +++ b/arch/arm/mach-stm32mp/cpu.c @@ -8,6 +8,7 @@ #include <asm/io.h> #include <asm/arch/stm32.h> #include <asm/arch/sys_proto.h> +#include <dm/uclass.h>
/* RCC register */ #define RCC_TZCR (STM32_RCC_BASE + 0x00) @@ -40,6 +41,16 @@ #define DBGMCU_IDC_REV_ID_MASK GENMASK(31, 16) #define DBGMCU_IDC_REV_ID_SHIFT 16
+/* boot interface from Bootrom + * - boot instance = bit 31:16 + * - boot device = bit 15:0 + */ +#define BOOTROM_PARAM_ADDR 0x2FFC0078 +#define BOOTROM_MODE_MASK GENMASK(15, 0) +#define BOOTROM_MODE_SHIFT 0 +#define BOOTROM_INSTANCE_MASK GENMASK(31, 16) +#define BOOTROM_INSTANCE_SHIFT 16 + #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) static void security_init(void) { @@ -109,6 +120,37 @@ static void dbgmcu_init(void) } #endif /* !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) */
+static u32 get_bootmode(void) +{ + u32 boot_mode; +#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) + u32 bootrom_itf = readl(BOOTROM_PARAM_ADDR); + u32 bootrom_device, bootrom_instance; + + bootrom_device = + (bootrom_itf & BOOTROM_MODE_MASK) >> BOOTROM_MODE_SHIFT; + bootrom_instance = + (bootrom_itf & BOOTROM_INSTANCE_MASK) >> BOOTROM_INSTANCE_SHIFT; + boot_mode = + ((bootrom_device << BOOT_TYPE_SHIFT) & BOOT_TYPE_MASK) | + ((bootrom_instance << BOOT_INSTANCE_SHIFT) & + BOOT_INSTANCE_MASK); + + /* save the boot mode in TAMP backup register */ + clrsetbits_le32(TAMP_BOOT_CONTEXT, + TAMP_BOOT_MODE_MASK, + boot_mode << TAMP_BOOT_MODE_SHIFT); +#else + /* read TAMP backup register */ + boot_mode = (readl(TAMP_BOOT_CONTEXT) & TAMP_BOOT_MODE_MASK) >> + TAMP_BOOT_MODE_SHIFT; +#endif + return boot_mode; +} + +/* + * Early system init + */ int arch_cpu_init(void) { /* early armv7 timer init: needed for polling */ @@ -119,6 +161,8 @@ int arch_cpu_init(void)
security_init(); #endif + /* get bootmode from BootRom context: saved in TAMP register */ + get_bootmode();
return 0; } @@ -178,6 +222,54 @@ int print_cpuinfo(void) } #endif /* CONFIG_DISPLAY_CPUINFO */
+static void setup_boot_mode(void) +{ + char cmd[60]; + u32 boot_ctx = readl(TAMP_BOOT_CONTEXT); + u32 boot_mode = + (boot_ctx & TAMP_BOOT_MODE_MASK) >> TAMP_BOOT_MODE_SHIFT; + int instance = (boot_mode & TAMP_BOOT_INSTANCE_MASK) - 1; + + pr_debug("%s: boot_ctx=0x%x => boot_mode=%x, instance=%d\n", + __func__, boot_ctx, boot_mode, instance); + + switch (boot_mode & TAMP_BOOT_DEVICE_MASK) { + case BOOT_SERIAL_UART: + sprintf(cmd, "%d", instance); + env_set("boot_device", "uart"); + env_set("boot_instance", cmd); + break; + case BOOT_SERIAL_USB: + env_set("boot_device", "usb"); + env_set("boot_instance", "0"); + break; + case BOOT_FLASH_SD: + case BOOT_FLASH_EMMC: + sprintf(cmd, "%d", instance); + env_set("boot_device", "mmc"); + env_set("boot_instance", cmd); + break; + case BOOT_FLASH_NAND: + env_set("boot_device", "nand"); + env_set("boot_instance", "0"); + break; + case BOOT_FLASH_NOR: + env_set("boot_device", "nor"); + env_set("boot_instance", "0"); + break; + default: + pr_debug("unexpected boot mode = %x\n", boot_mode); + break; + } +} + +int arch_misc_init(void) +{ + setup_boot_mode(); + + return 0; +} + void reset_cpu(ulong addr) { } diff --git a/arch/arm/mach-stm32mp/include/mach/stm32.h b/arch/arm/mach-stm32mp/include/mach/stm32.h index ffbe0b1..40faeb0 100644 --- a/arch/arm/mach-stm32mp/include/mach/stm32.h +++ b/arch/arm/mach-stm32mp/include/mach/stm32.h @@ -24,4 +24,57 @@ #define STM32_DDR_BASE 0xC0000000 #define STM32_DDR_SIZE SZ_1G
+#ifndef __ASSEMBLY__ + +/* + * enumerated for boot interface from Bootrom, used in TAMP_BOOT_CONTEXT + * - boot device = bit 8:4 + * - boot instance = bit 3:0 + */ +#define BOOT_TYPE_MASK 0xF0 +#define BOOT_TYPE_SHIFT 4 +#define BOOT_INSTANCE_MASK 0x0F +#define BOOT_INSTANCE_SHIFT 0 + +enum boot_device { + BOOT_FLASH_SD = 0x10, + BOOT_FLASH_SD_1 = 0x11, + BOOT_FLASH_SD_2 = 0x12, + BOOT_FLASH_SD_3 = 0x13, + + BOOT_FLASH_EMMC = 0x20, + BOOT_FLASH_EMMC_1 = 0x21, + BOOT_FLASH_EMMC_2 = 0x22, + BOOT_FLASH_EMMC_3 = 0x23, + + BOOT_FLASH_NAND = 0x30, + BOOT_FLASH_NAND_FMC = 0x31, + + BOOT_FLASH_NOR = 0x40, + BOOT_FLASH_NOR_QSPI = 0x41, + + BOOT_SERIAL_UART = 0x50, + BOOT_SERIAL_UART_1 = 0x51, + BOOT_SERIAL_UART_2 = 0x52, + BOOT_SERIAL_UART_3 = 0x53, + BOOT_SERIAL_UART_4 = 0x54, + BOOT_SERIAL_UART_5 = 0x55, + BOOT_SERIAL_UART_6 = 0x56, + BOOT_SERIAL_UART_7 = 0x57, + BOOT_SERIAL_UART_8 = 0x58, + + BOOT_SERIAL_USB = 0x60, + BOOT_SERIAL_USB_OTG = 0x62, +}; + +/* TAMP registers */ +#define TAMP_BACKUP_REGISTER(x) (STM32_TAMP_BASE + 0x100 + 4 * x) +#define TAMP_BOOT_CONTEXT TAMP_BACKUP_REGISTER(20) + +#define TAMP_BOOT_MODE_MASK GENMASK(15, 8) +#define TAMP_BOOT_MODE_SHIFT 8 +#define TAMP_BOOT_DEVICE_MASK GENMASK(7, 4) +#define TAMP_BOOT_INSTANCE_MASK GENMASK(3, 0) + +#endif /* __ASSEMBLY__*/ #endif /* _MACH_STM32_H_ */

On Tue, Mar 20, 2018 at 10:54:53AM +0100, Patrick Delaunay wrote:
SPL copy BootRom boot mode information in TAMP register 21.
This TAMP register information is used after relocation to set 2 env variables
- boot_device
- boot_instance
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com
Applied to u-boot/master, thanks!

Bootrom loads SPL from SDCARD or eMMC according BootPin selection.
Then SPL loads U-Boot on the same mmc device with the following predefined GPT partitioning:
on SDCARD: gpt partitioning 1: SPL 2: SPL#2 3: U-Boot 4: bootable partition
on eMMC: The 2 boot partitions are used for SPL (2 copy) boot1: SPL boot2: SPL#2 The user partition use gpt partitioning 1: U-Boot 2: bootable partition
This patch select the correct SPL partition (3 for SDCARD on mmc0 and 1 for eMMC on mmc1) according the BootRom information saved in TAMP register and based on configuration flasg: - CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION => for BOOT_DEVICE_MMC1 or mmc 0 in U-Boot - CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2 (new) => for BOOT_DEVICE_MMC2 or mmc 1 in U-Boot
And the correct boot_targets is selected according the environment variables boot_device and boot_instance, with preboot command, to search the bootable partition with kernel on this device (generic distro support).
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com ---
arch/arm/mach-stm32mp/Kconfig | 8 ++++++++ arch/arm/mach-stm32mp/spl.c | 30 ++++++++++++++++++++++++++++++ include/configs/stm32mp1.h | 7 +++++++ 3 files changed, 45 insertions(+)
diff --git a/arch/arm/mach-stm32mp/Kconfig b/arch/arm/mach-stm32mp/Kconfig index 8c755f8..9771af9 100644 --- a/arch/arm/mach-stm32mp/Kconfig +++ b/arch/arm/mach-stm32mp/Kconfig @@ -38,6 +38,14 @@ config SYS_TEXT_BASE when DDR driver is used: DDR + 1MB (0xC0100000)
+config SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2 + hex "Partition on MMC2 to use to load U-Boot from" + depends on SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION + default 1 + help + Partition on the second MMC to load U-Boot from when the MMC is being + used in raw mode + source "board/st/stm32mp1/Kconfig"
endif diff --git a/arch/arm/mach-stm32mp/spl.c b/arch/arm/mach-stm32mp/spl.c index 8f5962a..bfb3e50 100644 --- a/arch/arm/mach-stm32mp/spl.c +++ b/arch/arm/mach-stm32mp/spl.c @@ -7,9 +7,27 @@ #include <common.h> #include <dm.h> #include <spl.h> +#include <asm/io.h>
u32 spl_boot_device(void) { + u32 boot_mode; + + boot_mode = (readl(TAMP_BOOT_CONTEXT) & TAMP_BOOT_MODE_MASK) >> + TAMP_BOOT_MODE_SHIFT; + clrsetbits_le32(TAMP_BOOT_CONTEXT, + TAMP_BOOT_MODE_MASK, + boot_mode << TAMP_BOOT_MODE_SHIFT); + + switch (boot_mode) { + case BOOT_FLASH_SD_1: + case BOOT_FLASH_EMMC_1: + return BOOT_DEVICE_MMC1; + case BOOT_FLASH_SD_2: + case BOOT_FLASH_EMMC_2: + return BOOT_DEVICE_MMC2; + } + return BOOT_DEVICE_MMC1; }
@@ -18,6 +36,18 @@ u32 spl_boot_mode(const u32 boot_device) return MMCSD_MODE_RAW; }
+int spl_boot_partition(const u32 boot_device) +{ + switch (boot_device) { + case BOOT_DEVICE_MMC1: + return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION; + case BOOT_DEVICE_MMC2: + return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2; + default: + return -EINVAL; + } +} + void board_init_f(ulong dummy) { struct udevice *dev; diff --git a/include/configs/stm32mp1.h b/include/configs/stm32mp1.h index 6281dd5..8159101 100644 --- a/include/configs/stm32mp1.h +++ b/include/configs/stm32mp1.h @@ -82,6 +82,12 @@
#include <config_distro_bootcmd.h>
+#define STM32MP_PREBOOT \ + "echo "Boot over ${boot_device}${boot_instance}!"; " \ + "if test "${boot_device}" = "mmc"; then " \ + "env set boot_targets "mmc${boot_instance}"; "\ + "fi;" + #define CONFIG_EXTRA_ENV_SETTINGS \ "scriptaddr=0xC0000000\0" \ "pxefile_addr_r=0xC0000000\0" \ @@ -90,6 +96,7 @@ "ramdisk_addr_r=0xC4100000\0" \ "fdt_high=0xffffffff\0" \ "initrd_high=0xffffffff\0" \ + "preboot=" STM32MP_PREBOOT "\0" \ BOOTENV
#endif /* ifndef CONFIG_SPL_BUILD */

On Tue, Mar 20, 2018 at 10:54:54AM +0100, Patrick Delaunay wrote:
Bootrom loads SPL from SDCARD or eMMC according BootPin selection.
Then SPL loads U-Boot on the same mmc device with the following predefined GPT partitioning:
on SDCARD: gpt partitioning 1: SPL 2: SPL#2 3: U-Boot 4: bootable partition
on eMMC: The 2 boot partitions are used for SPL (2 copy) boot1: SPL boot2: SPL#2 The user partition use gpt partitioning 1: U-Boot 2: bootable partition
This patch select the correct SPL partition (3 for SDCARD on mmc0 and 1 for eMMC on mmc1) according the BootRom information saved in TAMP register and based on configuration flasg:
- CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION => for BOOT_DEVICE_MMC1 or mmc 0 in U-Boot
- CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2 (new) => for BOOT_DEVICE_MMC2 or mmc 1 in U-Boot
And the correct boot_targets is selected according the environment variables boot_device and boot_instance, with preboot command, to search the bootable partition with kernel on this device (generic distro support).
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com
Applied to u-boot/master, thanks!

On Tue, Mar 20, 2018 at 10:54:51AM +0100, Patrick Delaunay wrote:
The spl_boot_partition function has been added in order to have the possibility to boot on a same binary from different mmc devices with different partitions.
By default keep the current behavior, SPL use the partition defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION.
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com Signed-off-by: Christophe KERELLO christophe.kerello@st.com
Reviewed-by: Tom Rini trini@konsulko.com

On Tue, 20 Mar 2018 10:54:51 +0100 Patrick Delaunay patrick.delaunay@st.com wrote:
The spl_boot_partition function has been added in order to have the possibility to boot on a same binary from different mmc devices with different partitions.
By default keep the current behavior, SPL use the partition defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION.
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com Signed-off-by: Christophe KERELLO christophe.kerello@st.com
common/spl/spl_mmc.c | 15 +++++++++++++-- include/spl.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 351f4ed..4aa0b2c 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -292,6 +292,14 @@ u32 __weak spl_boot_mode(const u32 boot_device) #endif }
+#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION +__weak +int spl_boot_partition(const u32 boot_device) +{
- return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
+} +#endif
int spl_mmc_load_image(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { @@ -347,8 +355,11 @@ int spl_mmc_load_image(struct spl_image_info *spl_image, return err; } #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
err = mmc_load_image_raw_partition(spl_image, mmc,
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION);
err = spl_boot_partition(bootdev->boot_device);
if (!err)
return err;
err = mmc_load_image_raw_partition(spl_image, mmc,
err); if (!err) return err; #endif diff --git a/include/spl.h b/include/spl.h index c14448b..5754012 100644 --- a/include/spl.h +++ b/include/spl.h @@ -82,6 +82,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, void preloader_console_init(void); u32 spl_boot_device(void); u32 spl_boot_mode(const u32 boot_device); +int spl_boot_partition(const u32 boot_device); void spl_set_bd(void);
/**
Reviewed-by: Lukasz Majewski lukma@denx.de
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

On Tue, Mar 20, 2018 at 10:54:51AM +0100, Patrick Delaunay wrote:
The spl_boot_partition function has been added in order to have the possibility to boot on a same binary from different mmc devices with different partitions.
By default keep the current behavior, SPL use the partition defined by CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION.
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com Signed-off-by: Christophe KERELLO christophe.kerello@st.com Reviewed-by: Tom Rini trini@konsulko.com Reviewed-by: Lukasz Majewski lukma@denx.de
Applied to u-boot/master, thanks!
participants (3)
-
Lukasz Majewski
-
Patrick Delaunay
-
Tom Rini