Skip to contentSkip to conversation

Falcon boot mode for spl_mmc

PATCH New Peter Korsgaard 2 participants 8 messages May 13, 2013 – Jun 7, 2013 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

v3 cover 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 (FAT and raw).

Changes since V2:
- Drop RFC and adjust am335x nand MTDPARTS_DEFAULT settings according to Tom Rini's feedback.

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
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 |   30 ++++++++++++--
 4 files changed, 119 insertions(+), 29 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v3 1/6 spl_mmc: return error from mmc_load_image_{raw, fat} rather than hanging

So we can instead fallback to doing something else on errors.

---
 drivers/mmc/spl_mmc.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/mmc/spl_mmc.c +14 -10
index 7efdcb8..0c50657 100644
@@ -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();
 }
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v3 2/6 spl_mmc: mmc_load_image_fat(): Add filename argument and move fat init out

In reply to Peter Korsgaard

So we can use it for falcon mode as well.

---
 drivers/mmc/spl_mmc.c |   27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/mmc/spl_mmc.c +13 -14
index 0c50657..fac6f2d 100644
@@ -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");
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v3 3/6 spl_mmc: add Falcon mode support for FAT variant

In reply to Peter Korsgaard

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.

---
 README                |    8 ++++++++
 drivers/mmc/spl_mmc.c |   21 +++++++++++++++++++++
 2 files changed, 29 insertions(+)
README +8 -0
index 0d37d56..595c05d 100644
@@ -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
drivers/mmc/spl_mmc.c +21 -0
index fac6f2d..d250b40 100644
@@ -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 {
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH v3 4/6 spl_mmc: mmc_load_image_raw(): Add sector argument

In reply to Peter Korsgaard

So we can use it for falcon mode as well.

---
 drivers/mmc/spl_mmc.c |   15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/mmc/spl_mmc.c +6 -9
index d250b40..d710c0d 100644
@@ -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");
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH v3 5/6 spl_mmc: add Falcon mode support for raw variant

In reply to Peter Korsgaard

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.

---
 README                |   10 ++++++++++
 drivers/mmc/spl_mmc.c |   18 ++++++++++++++++++
 2 files changed, 28 insertions(+)
README +10 -0
index 595c05d..3bac95b 100644
@@ -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
 
drivers/mmc/spl_mmc.c +18 -0
index d710c0d..170fa38 100644
@@ -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
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH v3 6/6 am335x: enable falcon boot mode for mmc (raw and fat) and nand

In reply to Peter Korsgaard

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.

---
 board/ti/am335x/board.c      |    9 +++++++++
 include/configs/am335x_evm.h |   30 +++++++++++++++++++++++++++---
 2 files changed, 36 insertions(+), 3 deletions(-)
board/ti/am335x/board.c +9 -0
index b371376..23fe188 100644
@@ -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
 
 /*
include/configs/am335x_evm.h +27 -3
index ef00306..034e5e6 100644
@@ -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,
@@ -471,7 +494,8 @@
 #define MTDPARTS_DEFAULT		"mtdparts=omap2-nand.0:128k(SPL)," \
 					"128k(SPL.backup1)," \
 					"128k(SPL.backup2)," \
-					"128k(SPL.backup3),1920k(u-boot)," \
+					"128k(SPL.backup3),1792k(u-boot)," \
+					"128k(u-boot-spl-os)," \
 					"128k(u-boot-env),5m(kernel),-(rootfs)"
 #define CONFIG_NAND_OMAP_GPMC
 #define GPMC_NAND_ECC_LP_x16_LAYOUT	1
Signature · 1 line
1.7.10.4
#7 lore raw

v3 cover Falcon boot mode for spl_mmc

In reply to Peter Korsgaard
Quoted 25 lines · Peter Korsgaard

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 (FAT and raw).

Changes since V2:
- Drop RFC and adjust am335x nand MTDPARTS_DEFAULT settings according to Tom Rini's feedback.

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
am335x: enable falcon boot mode for mmc (raw and fat) and nand

Quoted 5 lines
 README                       |   18 +++++++++
 board/ti/am335x/board.c      |    9 +++++
 drivers/mmc/spl_mmc.c        |   91 ++++++++++++++++++++++++++++++------------
 include/configs/am335x_evm.h |   30 ++++++++++++--
 4 files changed, 119 insertions(+), 29 deletions(-)

Applied to u-boot/master, with the following additional patch: