[U-Boot] [PATCHv2 0/6] Falcon boot mode for spl_mmc

This patch series adds falcon boot mode for MMC (raw and FAT), similar to the existing nand support.
As an example, it adds falcon boot support for the am335x evm board, which is the platform that has been used to test the series.
Changes since V1: - Adjusted am335x parameters according to Tom Rini's feedback. Added spl command for easy kernel parameter area snapshot creation.
Peter Korsgaard (6): spl_mmc: return error from mmc_load_image_{raw,fat} rather than hanging spl_mmc: mmc_load_image_fat(): Add filename argument and move fat init out spl_mmc: add Falcon mode support for FAT variant spl_mmc: mmc_load_image_raw(): Add sector argument spl_mmc: add Falcon mode support for raw variant RFC: am335x: enable falcon boot mode for mmc (raw and fat) and nand
README | 18 +++++++++ board/ti/am335x/board.c | 9 +++++ drivers/mmc/spl_mmc.c | 91 ++++++++++++++++++++++++++++++------------ include/configs/am335x_evm.h | 27 ++++++++++++- 4 files changed, 117 insertions(+), 28 deletions(-)

So we can instead fallback to doing something else on errors.
Signed-off-by: Peter Korsgaard peter.korsgaard@barco.com --- drivers/mmc/spl_mmc.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/mmc/spl_mmc.c b/drivers/mmc/spl_mmc.c index 7efdcb8..0c50657 100644 --- a/drivers/mmc/spl_mmc.c +++ b/drivers/mmc/spl_mmc.c @@ -32,7 +32,7 @@
DECLARE_GLOBAL_DATA_PTR;
-static void mmc_load_image_raw(struct mmc *mmc) +static int mmc_load_image_raw(struct mmc *mmc) { unsigned long err; u32 image_size_sectors; @@ -61,14 +61,14 @@ static void mmc_load_image_raw(struct mmc *mmc) image_size_sectors, (void *)spl_image.load_addr);
end: - if (err == 0) { + if (err == 0) printf("spl: mmc blk read err - %lu\n", err); - hang(); - } + + return (err == 0); }
#ifdef CONFIG_SPL_FAT_SUPPORT -static void mmc_load_image_fat(struct mmc *mmc) +static int mmc_load_image_fat(struct mmc *mmc) { int err; struct image_header *header; @@ -94,11 +94,11 @@ static void mmc_load_image_fat(struct mmc *mmc) (u8 *)spl_image.load_addr, 0);
end: - if (err <= 0) { + if (err <= 0) printf("spl: error reading image %s, err - %d\n", CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, err); - hang(); - } + + return (err <= 0); } #endif
@@ -121,17 +121,21 @@ void spl_mmc_load_image(void) printf("spl: mmc init failed: err - %d\n", err); hang(); } + boot_mode = spl_boot_mode(); if (boot_mode == MMCSD_MODE_RAW) { debug("boot mode - RAW\n"); - mmc_load_image_raw(mmc); + err = mmc_load_image_raw(mmc); #ifdef CONFIG_SPL_FAT_SUPPORT } else if (boot_mode == MMCSD_MODE_FAT) { debug("boot mode - FAT\n"); - mmc_load_image_fat(mmc); + err = mmc_load_image_fat(mmc); #endif } else { puts("spl: wrong MMC boot mode\n"); hang(); } + + if (err) + hang(); }

So we can use it for falcon mode as well.
Signed-off-by: Peter Korsgaard peter.korsgaard@barco.com --- drivers/mmc/spl_mmc.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/drivers/mmc/spl_mmc.c b/drivers/mmc/spl_mmc.c index 0c50657..fac6f2d 100644 --- a/drivers/mmc/spl_mmc.c +++ b/drivers/mmc/spl_mmc.c @@ -68,7 +68,7 @@ end: }
#ifdef CONFIG_SPL_FAT_SUPPORT -static int mmc_load_image_fat(struct mmc *mmc) +static int mmc_load_image_fat(struct mmc *mmc, const char *filename) { int err; struct image_header *header; @@ -76,27 +76,18 @@ static int mmc_load_image_fat(struct mmc *mmc) header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
- err = fat_register_device(&mmc->block_dev, - CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION); - if (err) { - printf("spl: fat register err - %d\n", err); - hang(); - } - - err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, - header, sizeof(struct image_header)); + err = file_fat_read(filename, header, sizeof(struct image_header)); if (err <= 0) goto end;
spl_parse_image_header(header);
- err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, - (u8 *)spl_image.load_addr, 0); + err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);
end: if (err <= 0) printf("spl: error reading image %s, err - %d\n", - CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, err); + filename, err);
return (err <= 0); } @@ -129,7 +120,15 @@ void spl_mmc_load_image(void) #ifdef CONFIG_SPL_FAT_SUPPORT } else if (boot_mode == MMCSD_MODE_FAT) { debug("boot mode - FAT\n"); - err = mmc_load_image_fat(mmc); + + err = fat_register_device(&mmc->block_dev, + CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION); + if (err) { + printf("spl: fat register err - %d\n", err); + hang(); + } + + err = mmc_load_image_fat(mmc, CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME); #endif } else { puts("spl: wrong MMC boot mode\n");

If Falcon mode support is enabled (and the system isn't directed into booting u-boot), it will instead try to load kernel from CONFIG_SPL_FAT_LOAD_KERNEL_NAME file and kernel argument parameters from CONFIG_SPL_FAT_LOAD_ARGS_NAME, both from the same partition as u-boot.
Signed-off-by: Peter Korsgaard peter.korsgaard@barco.com --- README | 8 ++++++++ drivers/mmc/spl_mmc.c | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+)
diff --git a/README b/README index 0d37d56..595c05d 100644 --- a/README +++ b/README @@ -2921,6 +2921,14 @@ FIT uImage format: CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME Filename to read to load U-Boot when reading from FAT
+ CONFIG_SPL_FAT_LOAD_KERNEL_NAME + Filename to read to load kernel uImage when reading + from FAT (for Falcon mode) + + CONFIG_SPL_FAT_LOAD_ARGS_NAME + Filename to read to load kernel argument parameters + when reading from FAT (for Falcon mode) + CONFIG_SPL_MPC83XX_WAIT_FOR_NAND Set this for NAND SPL on PPC mpc83xx targets, so that start.S waits for the rest of the SPL to load before diff --git a/drivers/mmc/spl_mmc.c b/drivers/mmc/spl_mmc.c index fac6f2d..d250b40 100644 --- a/drivers/mmc/spl_mmc.c +++ b/drivers/mmc/spl_mmc.c @@ -91,6 +91,24 @@ end:
return (err <= 0); } + +#ifdef CONFIG_SPL_OS_BOOT +static int mmc_load_image_fat_os(struct mmc *mmc) +{ + int err; + + err = file_fat_read(CONFIG_SPL_FAT_LOAD_ARGS_NAME, + (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0); + if (err <= 0) { + printf("spl: error reading image %s, err - %d\n", + CONFIG_SPL_FAT_LOAD_ARGS_NAME, err); + return -1; + } + + return mmc_load_image_fat(mmc, CONFIG_SPL_FAT_LOAD_KERNEL_NAME); +} +#endif + #endif
void spl_mmc_load_image(void) @@ -128,6 +146,9 @@ void spl_mmc_load_image(void) hang(); }
+#ifdef CONFIG_SPL_OS_BOOT + if (spl_start_uboot() || mmc_load_image_fat_os(mmc)) +#endif err = mmc_load_image_fat(mmc, CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME); #endif } else {

So we can use it for falcon mode as well.
Signed-off-by: Peter Korsgaard peter.korsgaard@barco.com --- drivers/mmc/spl_mmc.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/mmc/spl_mmc.c b/drivers/mmc/spl_mmc.c index d250b40..d710c0d 100644 --- a/drivers/mmc/spl_mmc.c +++ b/drivers/mmc/spl_mmc.c @@ -32,7 +32,7 @@
DECLARE_GLOBAL_DATA_PTR;
-static int mmc_load_image_raw(struct mmc *mmc) +static int mmc_load_image_raw(struct mmc *mmc, unsigned long sector) { unsigned long err; u32 image_size_sectors; @@ -42,10 +42,7 @@ static int mmc_load_image_raw(struct mmc *mmc) sizeof(struct image_header));
/* read image header to find the image size & load address */ - err = mmc->block_dev.block_read(0, - CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, 1, - header); - + err = mmc->block_dev.block_read(0, sector, 1, header); if (err == 0) goto end;
@@ -56,9 +53,8 @@ static int mmc_load_image_raw(struct mmc *mmc) mmc->read_bl_len;
/* Read the header too to avoid extra memcpy */ - err = mmc->block_dev.block_read(0, - CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, - image_size_sectors, (void *)spl_image.load_addr); + err = mmc->block_dev.block_read(0, sector, image_size_sectors, + (void *)spl_image.load_addr);
end: if (err == 0) @@ -134,7 +130,8 @@ void spl_mmc_load_image(void) boot_mode = spl_boot_mode(); if (boot_mode == MMCSD_MODE_RAW) { debug("boot mode - RAW\n"); - err = mmc_load_image_raw(mmc); + err = mmc_load_image_raw(mmc, + CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); #ifdef CONFIG_SPL_FAT_SUPPORT } else if (boot_mode == MMCSD_MODE_FAT) { debug("boot mode - FAT\n");

If Falcon mode support is enabled (and the system isn't directed into booting u-boot), it will instead try to load kernel from sector CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR and CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS of kernel argument parameters starting from sector CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR.
Signed-off-by: Peter Korsgaard peter.korsgaard@barco.com --- README | 10 ++++++++++ drivers/mmc/spl_mmc.c | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+)
diff --git a/README b/README index 595c05d..3bac95b 100644 --- a/README +++ b/README @@ -2915,6 +2915,16 @@ FIT uImage format: Address, size and partition on the MMC to load U-Boot from when the MMC is being used in raw mode.
+ CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR + Sector to load kernel uImage from when MMC is being + used in raw mode (for Falcon mode) + + CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR, + CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS + Sector and number of sectors to load kernel argument + parameters from when MMC is being used in raw mode + (for falcon mode) + CONFIG_SPL_FAT_SUPPORT Support for fs/fat/libfat.o in SPL binary
diff --git a/drivers/mmc/spl_mmc.c b/drivers/mmc/spl_mmc.c index d710c0d..170fa38 100644 --- a/drivers/mmc/spl_mmc.c +++ b/drivers/mmc/spl_mmc.c @@ -63,6 +63,21 @@ end: return (err == 0); }
+#ifdef CONFIG_SPL_OS_BOOT +static int mmc_load_image_raw_os(struct mmc *mmc) +{ + if (!mmc->block_dev.block_read(0, + CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR, + CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS, + (void *)CONFIG_SYS_SPL_ARGS_ADDR)) { + printf("mmc args blk read error\n"); + return -1; + } + + return mmc_load_image_raw(mmc, CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR); +} +#endif + #ifdef CONFIG_SPL_FAT_SUPPORT static int mmc_load_image_fat(struct mmc *mmc, const char *filename) { @@ -130,6 +145,9 @@ void spl_mmc_load_image(void) boot_mode = spl_boot_mode(); if (boot_mode == MMCSD_MODE_RAW) { debug("boot mode - RAW\n"); +#ifdef CONFIG_SPL_OS_BOOT + if (spl_start_uboot() || mmc_load_image_raw_os(mmc)) +#endif err = mmc_load_image_raw(mmc, CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); #ifdef CONFIG_SPL_FAT_SUPPORT

Jump into full u-boot mode if a 'c' character is received on the uart.
We need to adjust the spl bss/malloc area to not overlap with the loadaddr of the kernel (sdram + 32k), so move it past u-boot instead.
For raw mmc, we store the kernel parameter area in the free space after the MBR (if used). For nand, we use the last sector of the partition reserved for u-boot.
This also enables the spl command in the full u-boot so the kernel parameter area snapshot can be created.
Signed-off-by: Peter Korsgaard peter.korsgaard@barco.com --- board/ti/am335x/board.c | 9 +++++++++ include/configs/am335x_evm.h | 27 +++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c index b371376..23fe188 100644 --- a/board/ti/am335x/board.c +++ b/board/ti/am335x/board.c @@ -297,6 +297,15 @@ static struct emif_regs ddr3_evm_emif_reg_data = { .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY | PHY_EN_DYN_PWRDN, }; + +#ifdef CONFIG_SPL_OS_BOOT +int spl_start_uboot(void) +{ + /* break into full u-boot on 'c' */ + return (serial_tstc() && serial_getc() == 'c'); +} +#endif + #endif
/* diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h index ef00306..3b90211 100644 --- a/include/configs/am335x_evm.h +++ b/include/configs/am335x_evm.h @@ -307,13 +307,36 @@ #define CONFIG_SPL_MAX_SIZE (101 * 1024) #define CONFIG_SPL_STACK CONFIG_SYS_INIT_SP_ADDR
-#define CONFIG_SPL_BSS_START_ADDR 0x80000000 +#define CONFIG_SPL_OS_BOOT + +#define CONFIG_SPL_BSS_START_ADDR 0x80a00000 #define CONFIG_SPL_BSS_MAX_SIZE 0x80000 /* 512 KB */
#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR 0x300 /* address 0x60000 */ #define CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS 0x200 /* 256 KB */ #define CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION 1 #define CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME "u-boot.img" + +#ifdef CONFIG_SPL_OS_BOOT +/* fat */ +#define CONFIG_SPL_FAT_LOAD_KERNEL_NAME "uImage" +#define CONFIG_SPL_FAT_LOAD_ARGS_NAME "args" +#define CONFIG_SYS_SPL_ARGS_ADDR (PHYS_DRAM_1 + 0x100) + +/* raw mmc */ +#define CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR 0x500 /* address 0xa0000 */ +#define CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR 0x8 /* address 0x1000 */ +#define CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS 8 /* 4KB */ + +/* nand */ +#define CONFIG_CMD_SPL_NAND_OFS 0x240000 /* end of u-boot */ +#define CONFIG_SYS_NAND_SPL_KERNEL_OFFS 0x280000 +#define CONFIG_CMD_SPL_WRITE_SIZE 0x1000 + +/* spl export command */ +#define CONFIG_CMD_SPL +#endif + #define CONFIG_SPL_MMC_SUPPORT #define CONFIG_SPL_FAT_SUPPORT #define CONFIG_SPL_I2C_SUPPORT @@ -375,7 +398,7 @@ * other needs. */ #define CONFIG_SYS_TEXT_BASE 0x80800000 -#define CONFIG_SYS_SPL_MALLOC_START 0x80208000 +#define CONFIG_SYS_SPL_MALLOC_START 0x80a08000 #define CONFIG_SYS_SPL_MALLOC_SIZE 0x100000
/* Since SPL did pll and ddr initialization for us,

On Wed, May 08, 2013 at 09:09:56PM +0200, Peter Korsgaard wrote:
Jump into full u-boot mode if a 'c' character is received on the uart.
We need to adjust the spl bss/malloc area to not overlap with the loadaddr of the kernel (sdram + 32k), so move it past u-boot instead.
For raw mmc, we store the kernel parameter area in the free space after the MBR (if used). For nand, we use the last sector of the partition reserved for u-boot.
This also enables the spl command in the full u-boot so the kernel parameter area snapshot can be created.
Signed-off-by: Peter Korsgaard peter.korsgaard@barco.com
You forgot to drop the RFC part :)
+/* nand */ +#define CONFIG_CMD_SPL_NAND_OFS 0x240000 /* end of u-boot */
This is fine but please update MTDPARTS_DEFAULT with this change as well (call it u-boot-spl-os). Thanks!

"Tom" == Tom Rini trini@ti.com writes:
Hi,
This also enables the spl command in the full u-boot so the kernel parameter area snapshot can be created.
Signed-off-by: Peter Korsgaard peter.korsgaard@barco.com
Tom> You forgot to drop the RFC part :)
Argh, indeed.
+/* nand */ +#define CONFIG_CMD_SPL_NAND_OFS 0x240000 /* end of u-boot */
Tom> This is fine but please update MTDPARTS_DEFAULT with this change Tom> as well (call it u-boot-spl-os). Thanks!
Ok, I will give it a day or two to see if there's more feedback and then send a v3 with this fixed.
Thanks for the review.
participants (3)
-
Peter Korsgaard
-
Peter Korsgaard
-
Tom Rini