Skip to contentSkip to conversation

SPL mmc refactor and alternate boot device feature

PATCH New Nikita Kiryanov 5 participants 37 messages Nov 8, 2015 – Nov 20, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover SPL mmc refactor and alternate boot device feature

This series has two parts: patches 1-7 perform refactors aimed at reducing the ifdef complexity of SPL mmc code (and some nand as well). This refactor also addresses a few design issues I noticed while working on the refactor.

Image size comparison for arm modules can be seen here:
http://patchwork.ozlabs.org/patch/534387/
Since the changes in V2 are minimal, the V1 results should still be valid for the V2 as well.

The rest of the series introduces a new SPL feature that allows board code to define a list of boot devices that SPL will try before failing (instead of the only one device it attempts now). This feature is useful for implementing fallbacks, as well as reacting to bootROM sequences. For example:

On CM-FX6, if boot from the alternate boot device (MMC) fails, the bootROM proceeds to try boot from SPI flash. If the SPI flash boot is succesful, SPL will still try to load U-Boot from MMC, instead of from the actual boot device SPI flash), and probably fail and hang. The alternate boot feature makes it possible for SPL to follow the MMC boot attempt with boot from the SPI flash. The CM-FX6 based miniature PC Utilite depends on this capability for its SPI flash boot to work, since SPI flash boot is only attempted if MMC boot fails.

Finally, patch 13 makes SPL look at the specific BOOT_DEVICE_MMCx, and search for the correct mmc device, instead of always going for mmc0.

This series was compile tested for arm and powerpc (patches 1-12). Patch 13 compile tested for sunxi.
Tested on CM-FX6.

Cc Igor Grinberg <[email protected]>
Cc Tom Rini <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Otavio Salvador <[email protected]>

Changes in V4:
- Rebased over current mainline. Rerun compile test for arm and powerpc
- Fixed typo in a commit message
- Moved announce_boot_device() code to after #ifndef BOOT_DEVICE_NONE
- Replaced one puts with printf

Changes in V3:
- Added documentation for spl_board_load_image().
- Reworked announce_boot_device() to make the code less repititive by utilizing a table of boot_device --> name.

Changes in V2:
- Per request I went over the changes to see if they should cause documentation updates or board updates, but found none to be necessary.
- Slight modification in patch 2 (and consequentially patch 8): removal of hang() in default switch case, and enclosing of default case in #ifdef LIBCONFIG to avoid compiler complaints if LIBCONFIG support not compiled in.
- Patch 13 is a new patch which makes SPL look at the value of BOOT_DEVICE_MMCx instead of always working with mmc0. A hack in sunxi boards that attempted to circumvent this issue is thus removed.
- Rebased over current mainline.

Nikita Kiryanov (13):
spl: nand: remove code duplication
spl: mmc: add break statements in spl_mmc_load_image()
spl: mmc: refactor device location code to its own function
spl: mmc: remove #ifdef CONFIG_SPL_OS_BOOT check
spl: mmc: get rid of #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
check
spl: mmc: move fs boot into its own function
spl: mmc: get rid of emmc boot code duplication
spl: change return values of spl_*_load_image()
common: spl: move image load to its own function
spl: add support for alternative boot device
spl: announce boot devices
arm: mx6: cm-fx6: define fallback boot devices for spl
spl: mmc: add support for BOOT_DEVICE_MMC2

 arch/arm/cpu/armv7/sunxi/board.c |  14 +-
 arch/arm/include/asm/spl.h       |  10 +-
 board/compulab/cm_fx6/spl.c      |  19 +--
 common/spl/spl.c                 | 194 +++++++++++++++++++-------
 common/spl/spl_ext.c             |   6 +
 common/spl/spl_fat.c             |   6 +
 common/spl/spl_mmc.c             | 290 ++++++++++++++++++++++++---------------
 common/spl/spl_nand.c            |  47 ++++---
 common/spl/spl_net.c             |   9 +-
 common/spl/spl_nor.c             |   6 +-
 common/spl/spl_onenand.c         |   4 +-
 common/spl/spl_sata.c            |  11 +-
 common/spl/spl_usb.c             |  17 ++-
 common/spl/spl_ymodem.c          |   5 +-
 drivers/mtd/spi/spi_spl_load.c   |  17 ++-
 include/configs/cm_fx6.h         |   1 -
 include/spl.h                    |  18 +--
 17 files changed, 446 insertions(+), 228 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 1/13 spl: nand: remove code duplication

Remove code duplication in spl_nand_load_image().

No functional changes.

---
Changes in V4:
- No changes.

Changes in V3:
- No changes.

Changes in V2:
- No changes.

 common/spl/spl_nand.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)
common/spl/spl_nand.c +16 -15
index b8c369d..6e4e641 100644
@@ -22,6 +22,19 @@ void spl_nand_load_image(void)
 	nand_deselect();
 }
 #else
+static int spl_nand_load_element(int offset, struct image_header *header)
+{
+	int err;
+
+	err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
+	if (err)
+		return err;
+
+	spl_parse_image_header(header);
+	return nand_spl_load_image(offset, spl_image.size,
+				   (void *)spl_image.load_addr);
+}
+
 void spl_nand_load_image(void)
 {
 	struct image_header *header;
@@ -73,25 +86,13 @@ void spl_nand_load_image(void)
 	}
 #endif
 #ifdef CONFIG_NAND_ENV_DST
-	nand_spl_load_image(CONFIG_ENV_OFFSET,
-		sizeof(*header), (void *)header);
-	spl_parse_image_header(header);
-	nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
-		(void *)spl_image.load_addr);
+	spl_nand_load_element(CONFIG_ENV_OFFSET, header);
 #ifdef CONFIG_ENV_OFFSET_REDUND
-	nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
-		sizeof(*header), (void *)header);
-	spl_parse_image_header(header);
-	nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
-		(void *)spl_image.load_addr);
+	spl_nand_load_element(CONFIG_ENV_OFFSET_REDUND, header);
 #endif
 #endif
 	/* Load u-boot */
-	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
-		sizeof(*header), (void *)header);
-	spl_parse_image_header(header);
-	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
-		spl_image.size, (void *)(unsigned long)spl_image.load_addr);
+	spl_nand_load_element(CONFIG_SYS_NAND_U_BOOT_OFFS, header);
 	nand_deselect();
 }
 #endif
Signature · 1 line
1.9.1
#2 lore raw

PATCH v4 1/13 spl: nand: remove code duplication

Hello Nikita,

Am 08.11.2015 um 16:11 schrieb Nikita Kiryanov:

Quoted 13 lines

Remove code duplication in spl_nand_load_image().

No functional changes.

---
Changes in V4:
- No changes.

Quoted 8 lines

Changes in V3:
- No changes.

Changes in V2:
- No changes.

  common/spl/spl_nand.c | 31 ++++++++++++++++---------------
  1 file changed, 16 insertions(+), 15 deletions(-)

bye,
Heiko

Quoted 55 lines
common/spl/spl_nand.c +16 -15
index b8c369d..6e4e641 100644
@@ -22,6 +22,19 @@ void spl_nand_load_image(void)
  	nand_deselect();
  }
  #else
+static int spl_nand_load_element(int offset, struct image_header *header)
+{
+	int err;
+
+	err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
+	if (err)
+		return err;
+
+	spl_parse_image_header(header);
+	return nand_spl_load_image(offset, spl_image.size,
+				   (void *)spl_image.load_addr);
+}
+
  void spl_nand_load_image(void)
  {
  	struct image_header *header;
@@ -73,25 +86,13 @@ void spl_nand_load_image(void)
  	}
  #endif
  #ifdef CONFIG_NAND_ENV_DST
-	nand_spl_load_image(CONFIG_ENV_OFFSET,
-		sizeof(*header), (void *)header);
-	spl_parse_image_header(header);
-	nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
-		(void *)spl_image.load_addr);
+	spl_nand_load_element(CONFIG_ENV_OFFSET, header);
  #ifdef CONFIG_ENV_OFFSET_REDUND
-	nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
-		sizeof(*header), (void *)header);
-	spl_parse_image_header(header);
-	nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
-		(void *)spl_image.load_addr);
+	spl_nand_load_element(CONFIG_ENV_OFFSET_REDUND, header);
  #endif
  #endif
  	/* Load u-boot */
-	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
-		sizeof(*header), (void *)header);
-	spl_parse_image_header(header);
-	nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
-		spl_image.size, (void *)(unsigned long)spl_image.load_addr);
+	spl_nand_load_element(CONFIG_SYS_NAND_U_BOOT_OFFS, header);
  	nand_deselect();
  }
  #endif
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#3 lore raw

PATCH v4 1/13 spl: nand: remove code duplication

In reply to Nikita Kiryanov
Quoted 10 lines · Nikita Kiryanov

Remove code duplication in spl_nand_load_image().

No functional changes.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/c2577b0f/attachment.sig>
#4 lore raw

PATCH v4 2/13 spl: mmc: add break statements in spl_mmc_load_image()

In reply to Nikita Kiryanov

The original intention of the mmc load_image() function was to try multiple boot modes before failing. This is evident by the lack of break statements in the switch, and the following line in the default case:
puts("spl: mmc: no boot mode left to try\n");

This implementation is problematic because:
- The availability of alternative boot modes is very arbitrary since it depends on the specific order of the switch cases. If your boot mode happens to be the first case, then you'll have a bunch of other boot modes as alternatives. If it happens to be the last case, then you have none.
- Opting in/out is tied to config options, so the only way for you to prevent an alternative boot mode from being attempted is to give up on the feature completely.
- This implementation makes the code more complicated and difficult to understand.

Address these issues by inserting a break statements between the cases to make the function try only one boot mode.

Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>

---
Changes in V4:
- No changes.

Changes in V3:
- No changes.

Changes in V2:
- Removed hang() in default cases, moved default case into ifdef LIBCOMMON.

 common/spl/spl_mmc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
common/spl/spl_mmc.c +7 -6
index ce58c58..6011f77 100644
@@ -164,6 +164,7 @@ void spl_mmc_load_image(void)
 		if (!err)
 			return;
 #endif
+		break;
 	case MMCSD_MODE_FS:
 		debug("spl: mmc boot mode: fs\n");
 
@@ -203,6 +204,7 @@ void spl_mmc_load_image(void)
 #endif
 #endif
 #endif
+		break;
 #ifdef CONFIG_SUPPORT_EMMC_BOOT
 	case MMCSD_MODE_EMMCBOOT:
 		/*
@@ -240,15 +242,14 @@ void spl_mmc_load_image(void)
 		if (!err)
 			return;
 #endif
+		break;
 #endif
 	case MMCSD_MODE_UNDEFINED:
-	default:
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-		if (err)
-			puts("spl: mmc: no boot mode left to try\n");
-		else
-			puts("spl: mmc: wrong boot mode\n");
+	default:
+		puts("spl: mmc: wrong boot mode\n");
 #endif
-		hang();
 	}
+
+	hang();
 }
Signature · 1 line
1.9.1
#5 lore raw

PATCH v4 2/13 spl: mmc: add break statements in spl_mmc_load_image()

Quoted 18 lines · Nikita Kiryanov

The original intention of the mmc load_image() function was to try multiple boot modes before failing. This is evident by the lack of break statements in the switch, and the following line in the default case:
puts("spl: mmc: no boot mode left to try\n");

This implementation is problematic because:
- The availability of alternative boot modes is very arbitrary since it depends on the specific order of the switch cases. If your boot mode happens to be the first case, then you'll have a bunch of other boot modes as alternatives. If it happens to be the last case, then you have none.
- Opting in/out is tied to config options, so the only way for you to prevent an alternative boot mode from being attempted is to give up on the feature completely.
- This implementation makes the code more complicated and difficult to understand.

Address these issues by inserting a break statements between the cases to make the function try only one boot mode.

Quoted 8 lines
Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/52185286/attachment.sig>
#6 lore raw

PATCH v4 3/13 spl: mmc: refactor device location code to its own function

In reply to Nikita Kiryanov

Simplify spl_mmc_load_image() code by moving the part that finds the mmc device into its own function spl_mmc_find_device(), available in two flavors: DM and non-DM.

This refactor fixes a bug in which an error in the device location sequence does not necessarily aborts the rest of the code. With this refactor, we fail the moment there is an error.

Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>

---
Changes in V4:
- s/puts/printf/

Changes in V3:
- No changes.

Changes in V2:
- No changes.

 common/spl/spl_mmc.c | 77 +++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 55 insertions(+), 22 deletions(-)
common/spl/spl_mmc.c +55 -22
index 6011f77..9d3c09e 100644
@@ -11,6 +11,7 @@
 #include <spl.h>
 #include <linux/compiler.h>
 #include <asm/u-boot.h>
+#include <errno.h>
 #include <mmc.h>
 #include <image.h>
 
@@ -59,6 +60,58 @@ end:
 	return 0;
 }
 
+#ifdef CONFIG_DM_MMC
+static int spl_mmc_find_device(struct mmc **mmc)
+{
+	struct udevice *dev;
+	int err;
+
+	err = mmc_initialize(NULL);
+	if (err) {
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+		printf("spl: could not initialize mmc. error: %d\n", err);
+#endif
+		return err;
+	}
+
+	err = uclass_get_device(UCLASS_MMC, 0, &dev);
+	if (err) {
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+		printf("spl: could not find mmc device. error: %d\n", err);
+#endif
+		return err;
+	}
+
+	*mmc = NULL;
+	*mmc = mmc_get_mmc_dev(dev);
+	return *mmc != NULL ? 0 : -ENODEV;
+}
+#else
+static int spl_mmc_find_device(struct mmc **mmc)
+{
+	int err;
+
+	err = mmc_initialize(gd->bd);
+	if (err) {
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+		printf("spl: could not initialize mmc. error: %d\n", err);
+#endif
+		return err;
+	}
+
+	/* We register only one device. So, the dev id is always 0 */
+	*mmc = find_mmc_device(0);
+	if (!*mmc) {
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+		puts("spl: mmc device not found\n");
+#endif
+		return -ENODEV;
+	}
+
+	return 0;
+}
+#endif
+
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
 static int mmc_load_image_raw_partition(struct mmc *mmc, int partition)
 {
@@ -110,30 +163,10 @@ void spl_mmc_load_image(void)
 	int err = 0;
 	__maybe_unused int part;
 
-#ifdef CONFIG_DM_MMC
-	struct udevice *dev;
-
-	mmc_initialize(NULL);
-	err = uclass_get_device(UCLASS_MMC, 0, &dev);
-	mmc = NULL;
-	if (!err)
-		mmc = mmc_get_mmc_dev(dev);
-#else
-	mmc_initialize(gd->bd);
-
-	/* We register only one device. So, the dev id is always 0 */
-	mmc = find_mmc_device(0);
-	if (!mmc) {
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-		puts("spl: mmc device not found\n");
-#endif
+	if (spl_mmc_find_device(&mmc))
 		hang();
-	}
-#endif
-
-	if (!err)
-		err = mmc_init(mmc);
 
+	err = mmc_init(mmc);
 	if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
 		printf("spl: mmc init failed with error: %d\n", err);
Signature · 1 line
1.9.1
#7 lore raw

PATCH v4 3/13 spl: mmc: refactor device location code to its own function

Quoted 8 lines · Nikita Kiryanov

Simplify spl_mmc_load_image() code by moving the part that finds the mmc device into its own function spl_mmc_find_device(), available in two flavors: DM and non-DM.

This refactor fixes a bug in which an error in the device location sequence does not necessarily aborts the rest of the code. With this refactor, we fail the moment there is an error.

Quoted 7 lines
Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151108/98b19400/attachment.sig>
#8 lore raw

PATCH v4 3/13 spl: mmc: refactor device location code to its own function

In reply to Nikita Kiryanov
Quoted 8 lines · Nikita Kiryanov

Simplify spl_mmc_load_image() code by moving the part that finds the mmc device into its own function spl_mmc_find_device(), available in two flavors: DM and non-DM.

This refactor fixes a bug in which an error in the device location sequence does not necessarily aborts the rest of the code. With this refactor, we fail the moment there is an error.

Quoted 8 lines
Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/f0a46b20/attachment.sig>
#9 lore raw

PATCH v4 4/13 spl: mmc: remove #ifdef CONFIG_SPL_OS_BOOT check

In reply to Nikita Kiryanov

Implement default versions of falcon mode functions to make the CONFIG_SPL_OS_BOOT check in spl_mmc_load_image() unnecessary, thus reducing its #ifdef complexity.

No functional changes.

Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Guillaume GARDET <[email protected]>
Cc Suriyan Ramasami <[email protected]>

---
Changes in V4:
- No changes.

Changes in V3:
- No changes.

Changes in V2:
- No changes.

 common/spl/spl_ext.c |  6 ++++++
 common/spl/spl_fat.c |  6 ++++++
 common/spl/spl_mmc.c | 17 +++++++++--------
 3 files changed, 21 insertions(+), 8 deletions(-)
common/spl/spl_ext.c +6 -0
index 9d37fd3..a42fbd0 100644
@@ -6,6 +6,7 @@
 #include <spl.h>
 #include <asm/u-boot.h>
 #include <ext4fs.h>
+#include <errno.h>
 #include <image.h>
 
 #ifdef CONFIG_SPL_EXT_SUPPORT
@@ -135,5 +136,10 @@ defaults:
 	return spl_load_image_ext(block_dev, partition,
 			CONFIG_SPL_FS_LOAD_KERNEL_NAME);
 }
+#else
+int spl_load_image_ext_os(block_dev_desc_t *block_dev, int partition)
+{
+	return -ENOSYS;
+}
 #endif
 #endif
common/spl/spl_fat.c +6 -0
index 350f7d9..0daadbe 100644
@@ -13,6 +13,7 @@
 #include <spl.h>
 #include <asm/u-boot.h>
 #include <fat.h>
+#include <errno.h>
 #include <image.h>
 
 static int fat_registered;
@@ -119,5 +120,10 @@ defaults:
 	return spl_load_image_fat(block_dev, partition,
 			CONFIG_SPL_FS_LOAD_KERNEL_NAME);
 }
+#else
+int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition)
+{
+	return -ENOSYS;
+}
 #endif
 #endif
common/spl/spl_mmc.c +9 -8
index 9d3c09e..837fa0d 100644
@@ -154,6 +154,15 @@ static int mmc_load_image_raw_os(struct mmc *mmc)
 	return mmc_load_image_raw_sector(mmc,
 		CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR);
 }
+#else
+int spl_start_uboot(void)
+{
+	return 1;
+}
+static int mmc_load_image_raw_os(struct mmc *mmc)
+{
+	return -ENOSYS;
+}
 #endif
 
 void spl_mmc_load_image(void)
@@ -179,13 +188,11 @@ void spl_mmc_load_image(void)
 	case MMCSD_MODE_RAW:
 		debug("spl: mmc boot mode: raw\n");
 
-#ifdef CONFIG_SPL_OS_BOOT
 		if (!spl_start_uboot()) {
 			err = mmc_load_image_raw_os(mmc);
 			if (!err)
 				return;
 		}
-#endif
 #if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION)
 		err = mmc_load_image_raw_partition(mmc,
 			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION);
@@ -203,14 +210,12 @@ void spl_mmc_load_image(void)
 
 #ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION
 #ifdef CONFIG_SPL_FAT_SUPPORT
-#ifdef CONFIG_SPL_OS_BOOT
 		if (!spl_start_uboot()) {
 			err = spl_load_image_fat_os(&mmc->block_dev,
 				CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
 			if (!err)
 				return;
 		}
-#endif
 #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
 		err = spl_load_image_fat(&mmc->block_dev,
 					 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
@@ -220,14 +225,12 @@ void spl_mmc_load_image(void)
 #endif
 #endif
 #ifdef CONFIG_SPL_EXT_SUPPORT
-#ifdef CONFIG_SPL_OS_BOOT
 		if (!spl_start_uboot()) {
 			err = spl_load_image_ext_os(&mmc->block_dev,
 				CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
 			if (!err)
 				return;
 		}
-#endif
 #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
 		err = spl_load_image_ext(&mmc->block_dev,
 					 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
@@ -257,13 +260,11 @@ void spl_mmc_load_image(void)
 			hang();
 		}
 
-#ifdef CONFIG_SPL_OS_BOOT
 		if (!spl_start_uboot()) {
 			err = mmc_load_image_raw_os(mmc);
 			if (!err)
 				return;
 		}
-#endif
 #if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION)
 		err = mmc_load_image_raw_partition(mmc,
 			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION);
Signature · 1 line
1.9.1
#10 lore raw

PATCH v4 4/13 spl: mmc: remove #ifdef CONFIG_SPL_OS_BOOT check

Quoted 6 lines · Nikita Kiryanov

Implement default versions of falcon mode functions to make the CONFIG_SPL_OS_BOOT check in spl_mmc_load_image() unnecessary, thus reducing its #ifdef complexity.

No functional changes.

Quoted 10 lines
Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Guillaume GARDET <[email protected]>
Cc Suriyan Ramasami <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/2338e4b2/attachment.sig>
#11 lore raw

PATCH v4 5/13 spl: mmc: get rid of #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION check

In reply to Nikita Kiryanov

Implement defaults for the raw partition image loading so that the #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION in spl_mmc_load_image() will no longer be necessary.

This change makes it possible for mmc_load_image_raw_partition() and mmc_load_image_raw_sector() to coexist.

Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>

---
Changes in V4:
- No changes.

Changes in V3:
- No changes.

Changes in V2:
- No changes.

 common/spl/spl_mmc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
common/spl/spl_mmc.c +9 -4
index 837fa0d..d646dc8 100644
@@ -133,6 +133,12 @@ static int mmc_load_image_raw_partition(struct mmc *mmc, int partition)
 	return mmc_load_image_raw_sector(mmc, info.start);
 #endif
 }
+#else
+#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION -1
+static int mmc_load_image_raw_partition(struct mmc *mmc, int partition)
+{
+	return -ENOSYS;
+}
 #endif
 
 #ifdef CONFIG_SPL_OS_BOOT
@@ -193,12 +199,12 @@ void spl_mmc_load_image(void)
 			if (!err)
 				return;
 		}
-#if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION)
+
 		err = mmc_load_image_raw_partition(mmc,
 			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION);
 		if (!err)
 			return;
-#elif defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR)
+#if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR)
 		err = mmc_load_image_raw_sector(mmc,
 			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
 		if (!err)
@@ -265,12 +271,11 @@ void spl_mmc_load_image(void)
 			if (!err)
 				return;
 		}
-#if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION)
 		err = mmc_load_image_raw_partition(mmc,
 			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION);
 		if (!err)
 			return;
-#elif defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR)
+#if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR)
 		err = mmc_load_image_raw_sector(mmc,
 			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
 		if (!err)
Signature · 1 line
1.9.1
#12 lore raw

PATCH v4 5/13 spl: mmc: get rid of #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION check

Quoted 7 lines · Nikita Kiryanov

Implement defaults for the raw partition image loading so that the #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION in spl_mmc_load_image() will no longer be necessary.

This change makes it possible for mmc_load_image_raw_partition() and mmc_load_image_raw_sector() to coexist.

Quoted 8 lines
Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/9f62fcb9/attachment.sig>
#13 lore raw

PATCH v4 6/13 spl: mmc: move fs boot into its own function

In reply to Nikita Kiryanov

Move the code that handles fs boot out of spl_mmc_load_image() and into its own function to reduce the #ifdef complexity of spl_mmc_load_image().

No functional changes.

Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>

---
Changes in V4:
- Fixed typo in commit message.

Changes in V3:
- No changes.

Changes in V2:
- No changes.

 common/spl/spl_mmc.c | 81 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 51 insertions(+), 30 deletions(-)
common/spl/spl_mmc.c +51 -30
index d646dc8..5dc576b 100644
@@ -171,6 +171,55 @@ static int mmc_load_image_raw_os(struct mmc *mmc)
 }
 #endif
 
+#ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION
+int spl_mmc_do_fs_boot(struct mmc *mmc)
+{
+	int err = -ENOSYS;
+
+#ifdef CONFIG_SPL_FAT_SUPPORT
+	if (!spl_start_uboot()) {
+		err = spl_load_image_fat_os(&mmc->block_dev,
+			CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
+		if (!err)
+			return err;
+	}
+#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
+	err = spl_load_image_fat(&mmc->block_dev,
+				 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
+				 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
+	if (!err)
+		return err;
+#endif
+#endif
+#ifdef CONFIG_SPL_EXT_SUPPORT
+	if (!spl_start_uboot()) {
+		err = spl_load_image_ext_os(&mmc->block_dev,
+			CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
+		if (!err)
+			return err;
+	}
+#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
+	err = spl_load_image_ext(&mmc->block_dev,
+				 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
+				 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
+	if (!err)
+		return err;
+#endif
+#endif
+
+#if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT)
+	err = -ENOENT;
+#endif
+
+	return err;
+}
+#else
+int spl_mmc_do_fs_boot(struct mmc *mmc)
+{
+	return -ENOSYS;
+}
+#endif
+
 void spl_mmc_load_image(void)
 {
 	struct mmc *mmc;
@@ -214,38 +263,10 @@ void spl_mmc_load_image(void)
 	case MMCSD_MODE_FS:
 		debug("spl: mmc boot mode: fs\n");
 
-#ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION
-#ifdef CONFIG_SPL_FAT_SUPPORT
-		if (!spl_start_uboot()) {
-			err = spl_load_image_fat_os(&mmc->block_dev,
-				CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
-			if (!err)
-				return;
-		}
-#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
-		err = spl_load_image_fat(&mmc->block_dev,
-					 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
-					 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
-		if (!err)
-			return;
-#endif
-#endif
-#ifdef CONFIG_SPL_EXT_SUPPORT
-		if (!spl_start_uboot()) {
-			err = spl_load_image_ext_os(&mmc->block_dev,
-				CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
-			if (!err)
-				return;
-		}
-#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
-		err = spl_load_image_ext(&mmc->block_dev,
-					 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
-					 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
+		err = spl_mmc_do_fs_boot(mmc);
 		if (!err)
 			return;
-#endif
-#endif
-#endif
+
 		break;
 #ifdef CONFIG_SUPPORT_EMMC_BOOT
 	case MMCSD_MODE_EMMCBOOT:
Signature · 1 line
1.9.1
#14 lore raw

PATCH v4 6/13 spl: mmc: move fs boot into its own function

Quoted 5 lines · Nikita Kiryanov

Move the code that handles fs boot out of spl_mmc_load_image() and into its own function to reduce the #ifdef complexity of spl_mmc_load_image().

No functional changes.

Quoted 8 lines
Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/06a11c5d/attachment.sig>
#15 lore raw

PATCH v4 7/13 spl: mmc: get rid of emmc boot code duplication

In reply to Nikita Kiryanov

Get rid of emmc boot code duplication in spl_mmc_load_image() using a switch case fallthrough into MMCSD_MODE_RAW. Since the #ifdef CONFIG_SUPPORT_EMMC_BOOT check is not really necessary, remove it in the process.

No functional changes.

Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>

---
Changes in V4:
- No changes.

Changes in V3:
- No changes.

Changes in V2:
- No changes.

 common/spl/spl_mmc.c | 54 ++++++++++++++++++----------------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)
common/spl/spl_mmc.c +18 -36
index 5dc576b..7d100fa 100644
@@ -240,6 +240,24 @@ void spl_mmc_load_image(void)
 
 	boot_mode = spl_boot_mode();
 	switch (boot_mode) {
+	case MMCSD_MODE_EMMCBOOT:
+			/*
+			 * We need to check what the partition is configured to.
+			 * 1 and 2 match up to boot0 / boot1 and 7 is user data
+			 * which is the first physical partition (0).
+			 */
+			part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
+
+			if (part == 7)
+				part = 0;
+
+			if (mmc_switch_part(0, part)) {
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+				puts("spl: mmc partition switch failed\n");
+#endif
+				hang();
+			}
+			/* Fall through */
 	case MMCSD_MODE_RAW:
 		debug("spl: mmc boot mode: raw\n");
 
@@ -268,42 +286,6 @@ void spl_mmc_load_image(void)
 			return;
 
 		break;
-#ifdef CONFIG_SUPPORT_EMMC_BOOT
-	case MMCSD_MODE_EMMCBOOT:
-		/*
-		 * We need to check what the partition is configured to.
-		 * 1 and 2 match up to boot0 / boot1 and 7 is user data
-		 * which is the first physical partition (0).
-		 */
-		part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
-
-		if (part == 7)
-			part = 0;
-
-		if (mmc_switch_part(0, part)) {
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-			puts("spl: mmc partition switch failed\n");
-#endif
-			hang();
-		}
-
-		if (!spl_start_uboot()) {
-			err = mmc_load_image_raw_os(mmc);
-			if (!err)
-				return;
-		}
-		err = mmc_load_image_raw_partition(mmc,
-			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION);
-		if (!err)
-			return;
-#if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR)
-		err = mmc_load_image_raw_sector(mmc,
-			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
-		if (!err)
-			return;
-#endif
-		break;
-#endif
 	case MMCSD_MODE_UNDEFINED:
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
 	default:
Signature · 1 line
1.9.1
#16 lore raw

PATCH v4 7/13 spl: mmc: get rid of emmc boot code duplication

Quoted 6 lines · Nikita Kiryanov

Get rid of emmc boot code duplication in spl_mmc_load_image() using a switch case fallthrough into MMCSD_MODE_RAW. Since the #ifdef CONFIG_SUPPORT_EMMC_BOOT check is not really necessary, remove it in the process.

No functional changes.

Quoted 8 lines
Cc Igor Grinberg <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/84d1f036/attachment.sig>
#17 lore raw

PATCH v4 8/13 spl: change return values of spl_*_load_image()

In reply to Nikita Kiryanov

Make spl_*_load_image() functions return a value instead of hanging if a problem is encountered. This enables main spl code to make the decision whether to hang or not, thus preparing it to support alternative boot devices.

Some boot devices (namely nand and spi) do not hang on error. Instead, they return normally and SPL proceeds to boot the contents of the load address. This is considered a bug and is rectified by hanging on error for these devices as well.

Cc Igor Grinberg <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Hans De Goede <[email protected]>
Cc Albert Aribaud <[email protected]>
Cc Jagan Teki <[email protected]>

---
Changes in V4:
- No changes.

Changes in V3:
- Added documentation for spl_board_load_image().

Changes in V2:
- Minor collateral adjustments from changes in patch 2 (only one return statement at the end of spl_mmc_load_image).

 arch/arm/cpu/armv7/sunxi/board.c |  4 +++-
 arch/arm/include/asm/spl.h       | 10 ++++++++--
 common/spl/spl.c                 | 43 +++++++++++++++++++++++++++-------------
 common/spl/spl_mmc.c             | 26 ++++++++++++++----------
 common/spl/spl_nand.c            | 18 +++++++++++------
 common/spl/spl_net.c             |  9 ++++++---
 common/spl/spl_nor.c             |  6 ++++--
 common/spl/spl_onenand.c         |  4 +++-
 common/spl/spl_sata.c            | 11 +++++++---
 common/spl/spl_usb.c             | 17 ++++++++++------
 common/spl/spl_ymodem.c          |  5 +++--
 drivers/mtd/spi/spi_spl_load.c   | 17 +++++++++++-----
 include/spl.h                    | 18 ++++++++---------
 13 files changed, 123 insertions(+), 65 deletions(-)
arch/arm/cpu/armv7/sunxi/board.c +3 -1
index 4785ac6..9b5c46b 100644
@@ -95,10 +95,12 @@ static int gpio_init(void)
 	return 0;
 }
 
-void spl_board_load_image(void)
+int spl_board_load_image(void)
 {
 	debug("Returning to FEL sp=%x, lr=%x\n", fel_stash.sp, fel_stash.lr);
 	return_to_fel(fel_stash.sp, fel_stash.lr);
+
+	return 0;
 }
 
 void s_init(void)
arch/arm/include/asm/spl.h +8 -2
index 6db405d..5c5d33f 100644
@@ -31,8 +31,14 @@ enum {
 };
 #endif
 
-/* Board-specific load method */
-void spl_board_load_image(void);
+/**
+ * Board specific load method for boards that have a special way of loading
+ * U-Boot, which does not fit with the existing SPL code.
+ *
+ * @return 0 on success, negative errno value on failure.
+ */
+
+int spl_board_load_image(void);
 
 /* Linker symbols. */
 extern char __bss_start[], __bss_end[];
common/spl/spl.c +29 -14

110 lines not on this page · raw message

common/spl/spl_mmc.c +15 -11
index 7d100fa..b68190a 100644
@@ -10,6 +10,7 @@
 #include <dm.h>
 #include <spl.h>
 #include <linux/compiler.h>
+#include <errno.h>
 #include <asm/u-boot.h>
 #include <errno.h>
 #include <mmc.h>
@@ -220,25 +221,27 @@ int spl_mmc_do_fs_boot(struct mmc *mmc)
 }
 #endif
 
-void spl_mmc_load_image(void)
+int spl_mmc_load_image(void)
 {
 	struct mmc *mmc;
 	u32 boot_mode;
 	int err = 0;
 	__maybe_unused int part;
 
-	if (spl_mmc_find_device(&mmc))
-		hang();
+	err = spl_mmc_find_device(&mmc);
+	if (err)
+		return err;
 
 	err = mmc_init(mmc);
 	if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
 		printf("spl: mmc init failed with error: %d\n", err);
 #endif
-		hang();
+		return err;
 	}
 
 	boot_mode = spl_boot_mode();
+	err = -EINVAL;
 	switch (boot_mode) {
 	case MMCSD_MODE_EMMCBOOT:
 			/*
@@ -251,11 +254,12 @@ void spl_mmc_load_image(void)
 			if (part == 7)
 				part = 0;
 
-			if (mmc_switch_part(0, part)) {
+			err = mmc_switch_part(0, part);
+			if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
 				puts("spl: mmc partition switch failed\n");
 #endif
-				hang();
+				return err;
 			}
 			/* Fall through */
 	case MMCSD_MODE_RAW:
@@ -264,18 +268,18 @@ void spl_mmc_load_image(void)
 		if (!spl_start_uboot()) {
 			err = mmc_load_image_raw_os(mmc);
 			if (!err)
-				return;
+				return err;
 		}
 
 		err = mmc_load_image_raw_partition(mmc,
 			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION);
 		if (!err)
-			return;
+			return err;
 #if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR)
 		err = mmc_load_image_raw_sector(mmc,
 			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
 		if (!err)
-			return;
+			return err;
 #endif
 		break;
 	case MMCSD_MODE_FS:
@@ -283,7 +287,7 @@ void spl_mmc_load_image(void)
 
 		err = spl_mmc_do_fs_boot(mmc);
 		if (!err)
-			return;
+			return err;
 
 		break;
 	case MMCSD_MODE_UNDEFINED:
@@ -293,5 +297,5 @@ void spl_mmc_load_image(void)
 #endif
 	}
 
-	hang();
+	return err;
 }
common/spl/spl_nand.c +12 -6
index 6e4e641..ad69db7 100644
@@ -11,7 +11,7 @@
 #include <nand.h>
 
 #if defined(CONFIG_SPL_NAND_RAW_ONLY)
-void spl_nand_load_image(void)
+int spl_nand_load_image(void)
 {
 	nand_init();
 
@@ -20,6 +20,8 @@ void spl_nand_load_image(void)
 			    (void *)CONFIG_SYS_NAND_U_BOOT_DST);
 	spl_set_header_raw_uboot();
 	nand_deselect();
+
+	return 0;
 }
 #else
 static int spl_nand_load_element(int offset, struct image_header *header)
@@ -35,8 +37,9 @@ static int spl_nand_load_element(int offset, struct image_header *header)
 				   (void *)spl_image.load_addr);
 }
 
-void spl_nand_load_image(void)
+int spl_nand_load_image(void)
 {
+	int err;
 	struct image_header *header;
 	int *src __attribute__((unused));
 	int *dst __attribute__((unused));
@@ -73,10 +76,12 @@ void spl_nand_load_image(void)
 		spl_parse_image_header(header);
 		if (header->ih_os == IH_OS_LINUX) {
 			/* happy - was a linux */
-			nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
-				spl_image.size, (void *)spl_image.load_addr);
+			err = nand_spl_load_image(
+				CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
+				spl_image.size,
+				(void *)spl_image.load_addr);
 			nand_deselect();
-			return;
+			return err;
 		} else {
 			puts("The Expected Linux image was not "
 				"found. Please check your NAND "
@@ -92,7 +97,8 @@ void spl_nand_load_image(void)
 #endif
 #endif
 	/* Load u-boot */
-	spl_nand_load_element(CONFIG_SYS_NAND_U_BOOT_OFFS, header);
+	err = spl_nand_load_element(CONFIG_SYS_NAND_U_BOOT_OFFS, header);
 	nand_deselect();
+	return err;
 }
 #endif
common/spl/spl_net.c +6 -3
index 217a435..63b20d8 100644
@@ -8,12 +8,13 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 #include <common.h>
+#include <errno.h>
 #include <spl.h>
 #include <net.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-void spl_net_load_image(const char *device)
+int spl_net_load_image(const char *device)
 {
 	int rv;
 
@@ -24,14 +25,16 @@ void spl_net_load_image(const char *device)
 	rv = eth_initialize();
 	if (rv == 0) {
 		printf("No Ethernet devices found\n");
-		hang();
+		return -ENODEV;
 	}
 	if (device)
 		setenv("ethact", device);
 	rv = net_loop(BOOTP);
 	if (rv < 0) {
 		printf("Problem booting with BOOTP\n");
-		hang();
+		return rv;
 	}
 	spl_parse_image_header((struct image_header *)load_addr);
+
+	return 0;
 }
common/spl/spl_nor.c +4 -2
index c2fee01..e08afe2 100644
@@ -7,7 +7,7 @@
 #include <common.h>
 #include <spl.h>
 
-void spl_nor_load_image(void)
+int spl_nor_load_image(void)
 {
 	/*
 	 * Loading of the payload to SDRAM is done with skipping of
@@ -43,7 +43,7 @@ void spl_nor_load_image(void)
 			       (void *)(CONFIG_SYS_FDT_BASE),
 			       (16 << 10));
 
-			return;
+			return 0;
 		} else {
 			puts("The Expected Linux image was not found.\n"
 			     "Please check your NOR configuration.\n"
@@ -62,4 +62,6 @@ void spl_nor_load_image(void)
 	memcpy((void *)spl_image.load_addr,
 	       (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
 	       spl_image.size);
+
+	return 0;
 }
common/spl/spl_onenand.c +3 -1
index d8d8097..af7d82e 100644
@@ -14,7 +14,7 @@
 #include <asm/io.h>
 #include <onenand_uboot.h>
 
-void spl_onenand_load_image(void)
+int spl_onenand_load_image(void)
 {
 	struct image_header *header;
 
@@ -28,4 +28,6 @@ void spl_onenand_load_image(void)
 	spl_parse_image_header(header);
 	onenand_spl_load_image(CONFIG_SYS_ONENAND_U_BOOT_OFFS,
 		spl_image.size, (void *)spl_image.load_addr);
+
+	return 0;
 }
common/spl/spl_sata.c +8 -3
index 2a5eb29..3ba4c24 100644
@@ -14,12 +14,13 @@
 #include <asm/u-boot.h>
 #include <sata.h>
 #include <scsi.h>
+#include <errno.h>
 #include <fat.h>
 #include <image.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-void spl_sata_load_image(void)
+int spl_sata_load_image(void)
 {
 	int err;
 	block_dev_desc_t *stor_dev;
@@ -29,11 +30,13 @@ void spl_sata_load_image(void)
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
 		printf("spl: sata init failed: err - %d\n", err);
 #endif
-		hang();
+		return err;
 	} else {
 		/* try to recognize storage devices immediately */
 		scsi_scan(0);
 		stor_dev = scsi_get_dev(0);
+		if (!stor_dev)
+			return -ENODEV;
 	}
 
 #ifdef CONFIG_SPL_OS_BOOT
@@ -45,6 +48,8 @@ void spl_sata_load_image(void)
 				CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
 	if (err) {
 		puts("Error loading sata device\n");
-		hang();
+		return err;
 	}
+
+	return 0;
 }
common/spl/spl_usb.c +11 -6
index c81672b..588b85c 100644
@@ -12,6 +12,7 @@
 #include <common.h>
 #include <spl.h>
 #include <asm/u-boot.h>
+#include <errno.h>
 #include <usb.h>
 #include <fat.h>
 
@@ -21,7 +22,7 @@ DECLARE_GLOBAL_DATA_PTR;
 static int usb_stor_curr_dev = -1; /* current device */
 #endif
 
-void spl_usb_load_image(void)
+int spl_usb_load_image(void)
 {
 	int err;
 	block_dev_desc_t *stor_dev;
@@ -32,13 +33,15 @@ void spl_usb_load_image(void)
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
 		printf("%s: usb init failed: err - %d\n", __func__, err);
 #endif
-		hang();
+		return err;
 	}
 
 #ifdef CONFIG_USB_STORAGE
 	/* try to recognize storage devices immediately */
 	usb_stor_curr_dev = usb_stor_scan(1);
 	stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
+	if (!stor_dev)
+		return -ENODEV;
 #endif
 
 	debug("boot mode - FAT\n");
@@ -51,8 +54,10 @@ void spl_usb_load_image(void)
 				CONFIG_SYS_USB_FAT_BOOT_PARTITION,
 				CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
 
-		if (err) {
-			puts("Error loading USB device\n");
-			hang();
-		}
+	if (err) {
+		puts("Error loading from USB device\n");
+		return err;
+	}
+
+	return 0;
 }
common/spl/spl_ymodem.c +3 -2
index 0f1e9970..380d8dd 100644
@@ -23,7 +23,7 @@ static int getcymodem(void) {
 	return -1;
 }
 
-void spl_ymodem_load_image(void)
+int spl_ymodem_load_image(void)
 {
 	int size = 0;
 	int err;
@@ -49,11 +49,12 @@ void spl_ymodem_load_image(void)
 		}
 	} else {
 		printf("spl: ymodem err - %s\n", xyzModem_error(err));
-		hang();
+		return ret;
 	}
 
 	xyzModem_stream_close(&err);
 	xyzModem_stream_terminate(false, &getcymodem);
 
 	printf("Loaded %d bytes\n", size);
+	return 0;
 }
drivers/mtd/spi/spi_spl_load.c +12 -5
index 2e0c871..ca56fe9 100644
@@ -12,6 +12,7 @@
 #include <common.h>
 #include <spi.h>
 #include <spi_flash.h>
+#include <errno.h>
 #include <spl.h>
 
 #ifdef CONFIG_SPL_OS_BOOT
@@ -48,8 +49,9 @@ static int spi_load_image_os(struct spi_flash *flash,
  * configured and available since this code loads the main U-Boot image
  * from SPI into SDRAM and starts it from there.
  */
-void spl_spi_load_image(void)
+int spl_spi_load_image(void)
 {
+	int err = 0;
 	struct spi_flash *flash;
 	struct image_header *header;
 
@@ -63,7 +65,7 @@ void spl_spi_load_image(void)
 				CONFIG_SF_DEFAULT_MODE);
 	if (!flash) {
 		puts("SPI probe failed.\n");
-		hang();
+		return -ENODEV;
 	}
 
 	/* use CONFIG_SYS_TEXT_BASE as temporary storage area */
@@ -74,10 +76,15 @@ void spl_spi_load_image(void)
 #endif
 	{
 		/* Load u-boot, mkimage header is 64 bytes. */
-		spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40,
-			       (void *)header);
+		err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40,
+				     (void *)header);
+		if (err)
+			return err;
+
 		spl_parse_image_header(header);
-		spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS,
+		err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS,
 			       spl_image.size, (void *)spl_image.load_addr);
 	}
+
+	return err;
 }
include/spl.h +9 -9
index 8e53426..46fc454 100644
@@ -45,31 +45,31 @@ int spl_start_uboot(void);
 void spl_display_print(void);
 
 /* NAND SPL functions */
-void spl_nand_load_image(void);
+int spl_nand_load_image(void);
 
 /* OneNAND SPL functions */
-void spl_onenand_load_image(void);
+int spl_onenand_load_image(void);
 
 /* NOR SPL functions */
-void spl_nor_load_image(void);
+int spl_nor_load_image(void);
 
 /* MMC SPL functions */
-void spl_mmc_load_image(void);
+int spl_mmc_load_image(void);
 
 /* YMODEM SPL functions */
-void spl_ymodem_load_image(void);
+int spl_ymodem_load_image(void);
 
 /* SPI SPL functions */
-void spl_spi_load_image(void);
+int spl_spi_load_image(void);
 
 /* Ethernet SPL functions */
-void spl_net_load_image(const char *device);
+int spl_net_load_image(const char *device);
 
 /* USB SPL functions */
-void spl_usb_load_image(void);
+int spl_usb_load_image(void);
 
 /* SATA SPL functions */
-void spl_sata_load_image(void);
+int spl_sata_load_image(void);
 
 /* SPL FAT image functions */
 int spl_load_image_fat(block_dev_desc_t *block_dev, int partition, const char *filename);
Signature · 1 line
1.9.1
#18 lore raw

PATCH v4 8/13 spl: change return values of spl_*_load_image()

Quoted 10 lines · Nikita Kiryanov

Make spl_*_load_image() functions return a value instead of hanging if a problem is encountered. This enables main spl code to make the decision whether to hang or not, thus preparing it to support alternative boot devices.

Some boot devices (namely nand and spi) do not hang on error. Instead, they return normally and SPL proceeds to boot the contents of the load address. This is considered a bug and is rectified by hanging on error for these devices as well.

Quoted 10 lines
Cc Igor Grinberg <[email protected]>
Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Hans De Goede <[email protected]>
Cc Albert Aribaud <[email protected]>
Cc Jagan Teki <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/22108db7/attachment.sig>
#19 lore raw

PATCH v4 9/13 common: spl: move image load to its own function

In reply to Nikita Kiryanov

Refactor spl image load code out of board_init_r and into its own function. This is a preparation for supporting alternative boot devices.

---
Changes in V4:
- No changes.

Changes in V3:
- No changes.

Changes in V2:
- No changes.

 common/spl/spl.c | 117 ++++++++++++++++++++++++-------------------------------
 1 file changed, 50 insertions(+), 67 deletions(-)
common/spl/spl.c +50 -67
index ff1bad2..56fccca 100644
@@ -178,122 +178,105 @@ int spl_init(void)
 	return 0;
 }
 
-void board_init_r(gd_t *dummy1, ulong dummy2)
+static int spl_load_image(u32 boot_device)
 {
-	u32 boot_device;
-
-	debug(">>spl:board_init_r()\n");
-
-#if defined(CONFIG_SYS_SPL_MALLOC_START)
-	mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
-			CONFIG_SYS_SPL_MALLOC_SIZE);
-	gd->flags |= GD_FLG_FULL_MALLOC_INIT;
-#endif
-	if (!(gd->flags & GD_FLG_SPL_INIT)) {
-		if (spl_init())
-			hang();
-	}
-#ifndef CONFIG_PPC
-	/*
-	 * timer_init() does not exist on PPC systems. The timer is initialized
-	 * and enabled (decrementer) in interrupt_init() here.
-	 */
-	timer_init();
-#endif
-
-#ifdef CONFIG_SPL_BOARD_INIT
-	spl_board_init();
-#endif
-
-	boot_device = spl_boot_device();
-	debug("boot device - %d\n", boot_device);
 	switch (boot_device) {
 #ifdef CONFIG_SPL_RAM_DEVICE
 	case BOOT_DEVICE_RAM:
-		if (spl_ram_load_image())
-			hang();
-		break;
+		return spl_ram_load_image();
 #endif
 #ifdef CONFIG_SPL_MMC_SUPPORT
 	case BOOT_DEVICE_MMC1:
 	case BOOT_DEVICE_MMC2:
 	case BOOT_DEVICE_MMC2_2:
-		if (spl_mmc_load_image())
-			hang();
-		break;
+		return spl_mmc_load_image();
 #endif
 #ifdef CONFIG_SPL_NAND_SUPPORT
 	case BOOT_DEVICE_NAND:
-		if (spl_nand_load_image())
-			hang();
-		break;
+		return spl_nand_load_image();
 #endif
 #ifdef CONFIG_SPL_ONENAND_SUPPORT
 	case BOOT_DEVICE_ONENAND:
-		if (spl_onenand_load_image())
-			hang();
-		break;
+		return spl_onenand_load_image();
 #endif
 #ifdef CONFIG_SPL_NOR_SUPPORT
 	case BOOT_DEVICE_NOR:
-		if (spl_nor_load_image())
-			hang();
-		break;
+		return spl_nor_load_image();
 #endif
 #ifdef CONFIG_SPL_YMODEM_SUPPORT
 	case BOOT_DEVICE_UART:
-		if (spl_ymodem_load_image())
-			hang();
-		break;
+		return spl_ymodem_load_image();
 #endif
 #ifdef CONFIG_SPL_SPI_SUPPORT
 	case BOOT_DEVICE_SPI:
-		if (spl_spi_load_image())
-			hang();
-		break;
+		return spl_spi_load_image();
 #endif
 #ifdef CONFIG_SPL_ETH_SUPPORT
 	case BOOT_DEVICE_CPGMAC:
 #ifdef CONFIG_SPL_ETH_DEVICE
-		if (spl_net_load_image(CONFIG_SPL_ETH_DEVICE))
-			hang();
+		return spl_net_load_image(CONFIG_SPL_ETH_DEVICE);
 #else
-		if (spl_net_load_image(NULL))
-			hang();
+		return spl_net_load_image(NULL);
 #endif
-		break;
 #endif
 #ifdef CONFIG_SPL_USBETH_SUPPORT
 	case BOOT_DEVICE_USBETH:
-		if (spl_net_load_image("usb_ether"))
-			hang();
-		break;
+		return spl_net_load_image("usb_ether");
 #endif
 #ifdef CONFIG_SPL_USB_SUPPORT
 	case BOOT_DEVICE_USB:
-		if (spl_usb_load_image())
-			hang();
-		break;
+		return spl_usb_load_image();
 #endif
 #ifdef CONFIG_SPL_SATA_SUPPORT
 	case BOOT_DEVICE_SATA:
-		if (spl_sata_load_image())
-			hang();
-		break;
+		return spl_sata_load_image();
 #endif
 #ifdef CONFIG_SPL_BOARD_LOAD_IMAGE
 	case BOOT_DEVICE_BOARD:
-		if (spl_board_load_image())
-			hang();
-		break;
+		return spl_board_load_image();
 #endif
 	default:
 #if defined(CONFIG_SPL_SERIAL_SUPPORT) && defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
 		puts("SPL: Unsupported Boot Device!\n");
 #endif
-		hang();
+		return -ENODEV;
 	}
 
+	return -EINVAL;
+}
+
+void board_init_r(gd_t *dummy1, ulong dummy2)
+{
+	u32 boot_device;
+
+	debug(">>spl:board_init_r()\n");
+
+#if defined(CONFIG_SYS_SPL_MALLOC_START)
+	mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
+			CONFIG_SYS_SPL_MALLOC_SIZE);
+	gd->flags |= GD_FLG_FULL_MALLOC_INIT;
+#endif
+	if (!(gd->flags & GD_FLG_SPL_INIT)) {
+		if (spl_init())
+			hang();
+	}
+#ifndef CONFIG_PPC
+	/*
+	 * timer_init() does not exist on PPC systems. The timer is initialized
+	 * and enabled (decrementer) in interrupt_init() here.
+	 */
+	timer_init();
+#endif
+
+#ifdef CONFIG_SPL_BOARD_INIT
+	spl_board_init();
+#endif
+
+	boot_device = spl_boot_device();
+	debug("boot device - %d\n", boot_device);
+	if (spl_load_image(boot_device))
+		hang();
+
 	switch (spl_image.os) {
 	case IH_OS_U_BOOT:
 		debug("Jumping to U-Boot\n");
Signature · 1 line
1.9.1
#20 lore raw

PATCH v4 9/13 common: spl: move image load to its own function

Quoted 10 lines · Nikita Kiryanov

Refactor spl image load code out of board_init_r and into its own function. This is a preparation for supporting alternative boot devices.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/01f9dccd/attachment.sig>
#21 lore raw

PATCH v4 10/13 spl: add support for alternative boot device

In reply to Nikita Kiryanov

Introduce spl_boot_list array, which defines a list of boot devices that SPL will try before hanging. By default this list will consist of only spl_boot_device(), but board_boot_order() can be overridden by board code to populate the array with custom values.

---
Changes in V4:
- No changes.

Changes in V3:
- No changes.

Changes in V2:
- No changes.

 common/spl/spl.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)
common/spl/spl.c +29 -4
index 56fccca..7913c52 100644
@@ -178,6 +178,23 @@ int spl_init(void)
 	return 0;
 }
 
+#ifndef BOOT_DEVICE_NONE
+#define BOOT_DEVICE_NONE 0xdeadbeef
+#endif
+
+static u32 spl_boot_list[] = {
+	BOOT_DEVICE_NONE,
+	BOOT_DEVICE_NONE,
+	BOOT_DEVICE_NONE,
+	BOOT_DEVICE_NONE,
+	BOOT_DEVICE_NONE,
+};
+
+__weak void board_boot_order(u32 *spl_boot_list)
+{
+	spl_boot_list[0] = spl_boot_device();
+}
+
 static int spl_load_image(u32 boot_device)
 {
 	switch (boot_device) {
@@ -247,7 +264,7 @@ static int spl_load_image(u32 boot_device)
 
 void board_init_r(gd_t *dummy1, ulong dummy2)
 {
-	u32 boot_device;
+	int i;
 
 	debug(">>spl:board_init_r()\n");
 
@@ -272,10 +289,18 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	spl_board_init();
 #endif
 
-	boot_device = spl_boot_device();
-	debug("boot device - %d\n", boot_device);
-	if (spl_load_image(boot_device))
+	board_boot_order(spl_boot_list);
+	for (i = 0; i < ARRAY_SIZE(spl_boot_list) &&
+			spl_boot_list[i] != BOOT_DEVICE_NONE; i++) {
+		if (!spl_load_image(spl_boot_list[i]))
+			break;
+	}
+
+	if (i == ARRAY_SIZE(spl_boot_list) ||
+	    spl_boot_list[i] == BOOT_DEVICE_NONE) {
+		puts("SPL: failed to boot from all boot devices\n");
 		hang();
+	}
 
 	switch (spl_image.os) {
 	case IH_OS_U_BOOT:
Signature · 1 line
1.9.1
#22 lore raw

PATCH v4 10/13 spl: add support for alternative boot device

Quoted 14 lines · Nikita Kiryanov

Introduce spl_boot_list array, which defines a list of boot devices that SPL will try before hanging. By default this list will consist of only spl_boot_device(), but board_boot_order() can be overridden by board code to populate the array with custom values.

---
Changes in V4:
- No changes.

Quoted 8 lines

Changes in V3:
- No changes.

Changes in V2:
- No changes.

 common/spl/spl.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)
#23 lore raw

PATCH v4 10/13 spl: add support for alternative boot device

In reply to Nikita Kiryanov
Quoted 11 lines · Nikita Kiryanov

Introduce spl_boot_list array, which defines a list of boot devices that SPL will try before hanging. By default this list will consist of only spl_boot_device(), but board_boot_order() can be overridden by board code to populate the array with custom values.

So, a problem with this patch is that we push the x600 board, which is an 8KiB SPL target, over the line. I feel like maybe we need a follow-up patch that makes announcing depend not on libcommon (which x600 needs) but something else to know that there's a reason to announce.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/890f30f5/attachment.sig>
#24 lore raw

PATCH v4 10/13 spl: add support for alternative boot device

Hi Tom,

Quoted 14 lines · Tom Rini
Quoted 11 lines · Nikita Kiryanov

Introduce spl_boot_list array, which defines a list of boot devices that SPL will try before hanging. By default this list will consist of only spl_boot_device(), but board_boot_order() can be overridden by board code to populate the array with custom values.

Quoted 5 lines

So, a problem with this patch is that we push the x600 board, which is an 8KiB SPL target, over the line. I feel like maybe we need a follow-up patch that makes announcing depend not on libcommon (which x600 needs) but something else to know that there's a reason to announce.

Based on the content of your reply I'm guessing you're referring to the next patch, not this one.

I suppose that announcing can be made into an optional feature. However, I also think that since printing is an optional feature that can greatly increase binary size, it shouldn't be coupled with other, often non-optional libcommon features the way it currently is via CONFIG_SPL_LIBCOMMON_SUPPORT. The best fix in my opinion would be to implement a way to exclude printing support from SPL even if libcommon is included (CONFIG_SPL_SILENT that replaces printfs with empty stubs?).

This will also make it possible to remove all those #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT checks that appear all over the SPL code.

Quoted 3 lines
Signature · 2 lines
-- 
Tom
#25 lore raw

PATCH v4 10/13 spl: add support for alternative boot device

Quoted 34 lines · Nikita Kiryanov

Hi Tom,

Quoted 14 lines · Tom Rini
Quoted 11 lines · Nikita Kiryanov

Introduce spl_boot_list array, which defines a list of boot devices that SPL will try before hanging. By default this list will consist of only spl_boot_device(), but board_boot_order() can be overridden by board code to populate the array with custom values.

Quoted 5 lines

So, a problem with this patch is that we push the x600 board, which is an 8KiB SPL target, over the line. I feel like maybe we need a follow-up patch that makes announcing depend not on libcommon (which x600 needs) but something else to know that there's a reason to announce.

Based on the content of your reply I'm guessing you're referring to the next patch, not this one.

I suppose that announcing can be made into an optional feature. However, I also think that since printing is an optional feature that can greatly increase binary size, it shouldn't be coupled with other, often non-optional libcommon features the way it currently is via CONFIG_SPL_LIBCOMMON_SUPPORT. The best fix in my opinion would be to implement a way to exclude printing support from SPL even if libcommon is included (CONFIG_SPL_SILENT that replaces printfs with empty stubs?).

Quoted 2 lines

This will also make it possible to remove all those #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT checks that appear all over the SPL code.

I think that my recently posted tiny-printf patches:

https://patchwork.ozlabs.org/patch/545034/
https://patchwork.ozlabs.org/patch/545033/
https://patchwork.ozlabs.org/patch/545036/
https://patchwork.ozlabs.org/patch/545035/

can solve this size issue on x600 (and perhaps other) board.

Comments welcome...

Thanks,
Stefan

#26 lore raw

PATCH v4 10/13 spl: add support for alternative boot device

Quoted 38 lines · Stefan Roese
Quoted 34 lines · Nikita Kiryanov

Hi Tom,

Quoted 14 lines · Tom Rini
Quoted 11 lines · Nikita Kiryanov

Introduce spl_boot_list array, which defines a list of boot devices that SPL will try before hanging. By default this list will consist of only spl_boot_device(), but board_boot_order() can be overridden by board code to populate the array with custom values.

Quoted 5 lines

So, a problem with this patch is that we push the x600 board, which is an 8KiB SPL target, over the line. I feel like maybe we need a follow-up patch that makes announcing depend not on libcommon (which x600 needs) but something else to know that there's a reason to announce.

Based on the content of your reply I'm guessing you're referring to the next patch, not this one.

I suppose that announcing can be made into an optional feature. However, I also think that since printing is an optional feature that can greatly increase binary size, it shouldn't be coupled with other, often non-optional libcommon features the way it currently is via CONFIG_SPL_LIBCOMMON_SUPPORT. The best fix in my opinion would be to implement a way to exclude printing support from SPL even if libcommon is included (CONFIG_SPL_SILENT that replaces printfs with empty stubs?).

Quoted 2 lines

This will also make it possible to remove all those #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT checks that appear all over the SPL code.

Quoted 8 lines

I think that my recently posted tiny-printf patches:

https://patchwork.ozlabs.org/patch/545034/
https://patchwork.ozlabs.org/patch/545033/
https://patchwork.ozlabs.org/patch/545036/
https://patchwork.ozlabs.org/patch/545035/

can solve this size issue on x600 (and perhaps other) board.

If you can see if x600 builds again in mainline that would be good :)

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151119/8ffdd81f/attachment.sig>
#27 lore raw

PATCH v4 10/13 spl: add support for alternative boot device

Hi Tom,

Quoted 41 lines · Tom Rini
Quoted 40 lines · Stefan Roese
Quoted 34 lines · Nikita Kiryanov

Hi Tom,

Quoted 14 lines · Tom Rini
Quoted 11 lines · Nikita Kiryanov

Introduce spl_boot_list array, which defines a list of boot devices that SPL will try before hanging. By default this list will consist of only spl_boot_device(), but board_boot_order() can be overridden by board code to populate the array with custom values.

Quoted 5 lines

So, a problem with this patch is that we push the x600 board, which is an 8KiB SPL target, over the line. I feel like maybe we need a follow-up patch that makes announcing depend not on libcommon (which x600 needs) but something else to know that there's a reason to announce.

Based on the content of your reply I'm guessing you're referring to the next patch, not this one.

I suppose that announcing can be made into an optional feature. However, I also think that since printing is an optional feature that can greatly increase binary size, it shouldn't be coupled with other, often non-optional libcommon features the way it currently is via CONFIG_SPL_LIBCOMMON_SUPPORT. The best fix in my opinion would be to implement a way to exclude printing support from SPL even if libcommon is included (CONFIG_SPL_SILENT that replaces printfs with empty stubs?).

Quoted 2 lines

This will also make it possible to remove all those #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT checks that appear all over the SPL code.

I think that my recently posted tiny-printf patches:

Quoted 8 lines
Quoted 6 lines

https://patchwork.ozlabs.org/patch/545034/
https://patchwork.ozlabs.org/patch/545033/
https://patchwork.ozlabs.org/patch/545036/
https://patchwork.ozlabs.org/patch/545035/

can solve this size issue on x600 (and perhaps other) board.

If you can see if x600 builds again in mainline that would be good :)

Yes, I can confirm, that build with the tiny-printf fixes the build issue on x600. So once you add this tiny-printf patchset, I'll send a patch to move x600 over to use this smaller version.

Thanks,
Stefan

#28 lore raw

PATCH v4 10/13 spl: add support for alternative boot device

In reply to Nikita Kiryanov
Quoted 17 lines · Nikita Kiryanov

Hi Tom,

Quoted 14 lines · Tom Rini
Quoted 11 lines · Nikita Kiryanov

Introduce spl_boot_list array, which defines a list of boot devices that SPL will try before hanging. By default this list will consist of only spl_boot_device(), but board_boot_order() can be overridden by board code to populate the array with custom values.

Quoted 8 lines
Quoted 5 lines

So, a problem with this patch is that we push the x600 board, which is an 8KiB SPL target, over the line. I feel like maybe we need a follow-up patch that makes announcing depend not on libcommon (which x600 needs) but something else to know that there's a reason to announce.

Based on the content of your reply I'm guessing you're referring to the next patch, not this one.

Oh yes, oops.

Quoted 10 lines

I suppose that announcing can be made into an optional feature. However, I also think that since printing is an optional feature that can greatly increase binary size, it shouldn't be coupled with other, often non-optional libcommon features the way it currently is via CONFIG_SPL_LIBCOMMON_SUPPORT. The best fix in my opinion would be to implement a way to exclude printing support from SPL even if libcommon is included (CONFIG_SPL_SILENT that replaces printfs with empty stubs?).

This will also make it possible to remove all those #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT checks that appear all over the SPL code.

So the reason I'm thinking that we want this announce thing separate is that (due to the way you re-worked it I think, based on Simons' request) this added a huge amount of space. We went from OK to overflowing by more than 1KiB. So I'm not immediately sure that we can regain that space with a more (space) efficient printing infrastructure.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151119/8c906c6b/attachment.sig>
#29 lore raw

PATCH v4 10/13 spl: add support for alternative boot device

In reply to Nikita Kiryanov
Quoted 11 lines · Nikita Kiryanov

Introduce spl_boot_list array, which defines a list of boot devices that SPL will try before hanging. By default this list will consist of only spl_boot_device(), but board_boot_order() can be overridden by board code to populate the array with custom values.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/5334ebbc/attachment.sig>
#30 lore raw

PATCH v4 11/13 spl: announce boot devices

In reply to Nikita Kiryanov

Now that we support alternative boot devices, it can sometimes be unclear which boot devices was actually used. Provide a function to announce which boot devices are attempted during boot.

---
Changes in V2:
- Moved new code to be located after #ifndef BOOT_DEVICE_NONE

Changes in V3:

	- Reworked announce_boot_device() to make the code less repititive by
	  utilizing a table of boot_device --> name.

Changes in V2:
- No changes.

 common/spl/spl.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
common/spl/spl.c +79 -0
index 7913c52..b522c8b 100644
@@ -195,6 +195,84 @@ __weak void board_boot_order(u32 *spl_boot_list)
 	spl_boot_list[0] = spl_boot_device();
 }
 
+#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE
+__weak void spl_board_announce_boot_device(void) { }
+#endif
+
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+struct boot_device_name {
+	u32 boot_dev;
+	const char *name;
+};
+
+struct boot_device_name boot_name_table[] = {
+#ifdef CONFIG_SPL_RAM_DEVICE
+	{ BOOT_DEVICE_RAM, "RAM" },
+#endif
+#ifdef CONFIG_SPL_MMC_SUPPORT
+	{ BOOT_DEVICE_MMC1, "MMC" },
+	{ BOOT_DEVICE_MMC2, "MMC" },
+	{ BOOT_DEVICE_MMC2_2, "MMC" },
+#endif
+#ifdef CONFIG_SPL_NAND_SUPPORT
+	{ BOOT_DEVICE_NAND, "NAND" },
+#endif
+#ifdef CONFIG_SPL_ONENAND_SUPPORT
+	{ BOOT_DEVICE_ONENAND, "OneNAND" },
+#endif
+#ifdef CONFIG_SPL_NOR_SUPPORT
+	{ BOOT_DEVICE_NOR, "NOR" },
+#endif
+#ifdef CONFIG_SPL_YMODEM_SUPPORT
+	{ BOOT_DEVICE_UART, "UART" },
+#endif
+#ifdef CONFIG_SPL_SPI_SUPPORT
+	{ BOOT_DEVICE_SPI, "SPI" },
+#endif
+#ifdef CONFIG_SPL_ETH_SUPPORT
+#ifdef CONFIG_SPL_ETH_DEVICE
+	{ BOOT_DEVICE_CPGMAC, "eth device" },
+#else
+	{ BOOT_DEVICE_CPGMAC, "net" },
+#endif
+#endif
+#ifdef CONFIG_SPL_USBETH_SUPPORT
+	{ BOOT_DEVICE_USBETH, "USB eth" },
+#endif
+#ifdef CONFIG_SPL_USB_SUPPORT
+	{ BOOT_DEVICE_USB, "USB" },
+#endif
+#ifdef CONFIG_SPL_SATA_SUPPORT
+	{ BOOT_DEVICE_SATA, "SATA" },
+#endif
+	/* Keep this entry last */
+	{ BOOT_DEVICE_NONE, "unknown boot device" },
+};
+
+static void announce_boot_device(u32 boot_device)
+{
+	int i;
+
+	puts("Trying to boot from ");
+
+#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE
+	if (boot_device == BOOT_DEVICE_BOARD) {
+		spl_board_announce_boot_device();
+		puts("\n");
+		return;
+	}
+#endif
+	for (i = 0; i < ARRAY_SIZE(boot_name_table) - 1; i++) {
+		if (boot_name_table[i].boot_dev == boot_device)
+			break;
+	}
+
+	printf("%s\n", boot_name_table[i].name);
+}
+#else
+static inline void announce_boot_device(u32 boot_device) { }
+#endif
+
 static int spl_load_image(u32 boot_device)
 {
 	switch (boot_device) {
@@ -292,6 +370,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	board_boot_order(spl_boot_list);
 	for (i = 0; i < ARRAY_SIZE(spl_boot_list) &&
 			spl_boot_list[i] != BOOT_DEVICE_NONE; i++) {
+		announce_boot_device(spl_boot_list[i]);
 		if (!spl_load_image(spl_boot_list[i]))
 			break;
 	}
Signature · 1 line
1.9.1
#31 lore raw

PATCH v4 11/13 spl: announce boot devices

Quoted 17 lines · Nikita Kiryanov

Now that we support alternative boot devices, it can sometimes be unclear which boot devices was actually used. Provide a function to announce which boot devices are attempted during boot.

---
Changes in V2:
- Moved new code to be located after #ifndef BOOT_DEVICE_NONE

Changes in V3:
- Reworked announce_boot_device() to make the code less repititive by utilizing a table of boot_device --> name.

Quoted 5 lines

Changes in V2:
- No changes.

 common/spl/spl.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
#32 lore raw

PATCH v4 11/13 spl: announce boot devices

In reply to Nikita Kiryanov
Quoted 10 lines · Nikita Kiryanov

Now that we support alternative boot devices, it can sometimes be unclear which boot devices was actually used. Provide a function to announce which boot devices are attempted during boot.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/1575ebfe/attachment.sig>
#33 lore raw

PATCH v4 12/13 arm: mx6: cm-fx6: define fallback boot devices for spl

In reply to Nikita Kiryanov

Use spl alternate boot device feature to define fallback to the main boot device as it is defined by hardware.

---
Changes in V4:
- No changes.

Changes in V3:
- No changes.

Changes in V2:
- No changes.

 board/compulab/cm_fx6/spl.c | 19 ++++++++++---------
 include/configs/cm_fx6.h    |  1 -
 2 files changed, 10 insertions(+), 10 deletions(-)
board/compulab/cm_fx6/spl.c +10 -9
index d94ced9..d8328fd 100644
@@ -337,16 +337,17 @@ void board_init_f(ulong dummy)
 	board_init_r(NULL, 0);
 }
 
-void spl_board_init(void)
+void board_boot_order(u32 *spl_boot_list)
 {
-	u32 boot_device = spl_boot_device();
-
-	if (boot_device == BOOT_DEVICE_SPI)
-		puts("Booting from SPI flash\n");
-	else if (boot_device == BOOT_DEVICE_MMC1)
-		puts("Booting from MMC\n");
-	else
-		puts("Unknown boot device\n");
+	spl_boot_list[0] = spl_boot_device();
+	switch (spl_boot_list[0]) {
+	case BOOT_DEVICE_SPI:
+		spl_boot_list[1] = BOOT_DEVICE_MMC1;
+		break;
+	case BOOT_DEVICE_MMC1:
+		spl_boot_list[1] = BOOT_DEVICE_SPI;
+		break;
+	}
 }
 
 #ifdef CONFIG_SPL_MMC_SUPPORT
include/configs/cm_fx6.h +0 -1
index 0513204..180ea28 100644
@@ -230,7 +230,6 @@
 
 /* SPL */
 #include "imx6_spl.h"
-#define CONFIG_SPL_BOARD_INIT
 #define CONFIG_SPL_MMC_SUPPORT
 #define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR	0x80 /* offset 64 kb */
 #define CONFIG_SYS_MONITOR_LEN	(CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS / 2 * 1024)
Signature · 1 line
1.9.1
#34 lore raw

PATCH v4 12/13 arm: mx6: cm-fx6: define fallback boot devices for spl

Quoted 9 lines · Nikita Kiryanov

Use spl alternate boot device feature to define fallback to the main boot device as it is defined by hardware.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/404aa6f6/attachment.sig>
#35 lore raw

PATCH v4 13/13 spl: mmc: add support for BOOT_DEVICE_MMC2

In reply to Nikita Kiryanov

Currently the mmc device that SPL looks at is always mmc0, regardless of the BOOT_DEVICE_MMCx value. This forces some boards to implement hacks in order to boot from other mmc devices.

Make SPL take into account the correct mmc device.

---
Changes in V4:
- No changes.

Changes in V3:
- No changes.

Changes in V2:
- New patch.

 arch/arm/cpu/armv7/sunxi/board.c | 10 +---------
 common/spl/spl.c                 |  2 +-
 common/spl/spl_mmc.c             | 41 ++++++++++++++++++++++++++++++++--------
 include/spl.h                    |  2 +-
 4 files changed, 36 insertions(+), 19 deletions(-)
arch/arm/cpu/armv7/sunxi/board.c +1 -9
index 9b5c46b..794b829 100644
@@ -173,16 +173,8 @@ u32 spl_boot_device(void)
 #ifdef CONFIG_MMC
 	if (CONFIG_MMC_SUNXI_SLOT_EXTRA == 2) {
 		mmc1 = find_mmc_device(1);
-		if (sunxi_mmc_has_egon_boot_signature(mmc1)) {
-			/*
-			 * spl_mmc.c: spl_mmc_load_image() is hard-coded to
-			 * use find_mmc_device(0), no matter what we
-			 * return. Swap mmc0 and mmc2 to make this work.
-			 */
-			mmc0->block_dev.dev = 1;
-			mmc1->block_dev.dev = 0;
+		if (sunxi_mmc_has_egon_boot_signature(mmc1))
 			return BOOT_DEVICE_MMC2;
-		}
 	}
 #endif
 
common/spl/spl.c +1 -1
index b522c8b..7a393dc 100644
@@ -284,7 +284,7 @@ static int spl_load_image(u32 boot_device)
 	case BOOT_DEVICE_MMC1:
 	case BOOT_DEVICE_MMC2:
 	case BOOT_DEVICE_MMC2_2:
-		return spl_mmc_load_image();
+		return spl_mmc_load_image(boot_device);
 #endif
 #ifdef CONFIG_SPL_NAND_SUPPORT
 	case BOOT_DEVICE_NAND:
common/spl/spl_mmc.c +33 -8

81 lines not on this page · raw message

include/spl.h +1 -1
index 46fc454..92cdc04 100644
@@ -54,7 +54,7 @@ int spl_onenand_load_image(void);
 int spl_nor_load_image(void);
 
 /* MMC SPL functions */
-int spl_mmc_load_image(void);
+int spl_mmc_load_image(u32 boot_device);
 
 /* YMODEM SPL functions */
 int spl_ymodem_load_image(void);
Signature · 1 line
1.9.1
#36 lore raw

PATCH v4 13/13 spl: mmc: add support for BOOT_DEVICE_MMC2

Quoted 8 lines · Nikita Kiryanov

Currently the mmc device that SPL looks at is always mmc0, regardless of the BOOT_DEVICE_MMCx value. This forces some boards to implement hacks in order to boot from other mmc devices.

Make SPL take into account the correct mmc device.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151118/39b70697/attachment.sig>