[U-Boot] [PATCH V2 00/13] 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 grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Hans de Goede hdegoede@redhat.com Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Otavio Salvador otavio.salvador@ossystems.com.br
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 | 2 +- board/compulab/cm_fx6/spl.c | 19 +-- common/spl/spl.c | 191 ++++++++++++++++++++------ 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, 441 insertions(+), 222 deletions(-)

Remove code duplication in spl_nand_load_image().
No functional changes.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Scott Wood scottwood@freescale.com Cc: Igor Grinberg grinberg@compulab.co.il Acked-by: Scott Wood scottwood@freescale.com --- Changes in V2: - No changes.
common/spl/spl_nand.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index b8c369d..6e4e641 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -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

On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
Remove code duplication in spl_nand_load_image().
No functional changes.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Scott Wood scottwood@freescale.com Cc: Igor Grinberg grinberg@compulab.co.il Acked-by: Scott Wood scottwood@freescale.com
Changes in V2: - No changes.
common/spl/spl_nand.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org --- 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(-)
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index ce58c58..6011f77 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -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(); }

On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
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(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 28, 2015 at 11:23:19AM +0200, Nikita Kiryanov wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org --- Changes in V2: - No changes.
common/spl/spl_mmc.c | 77 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 22 deletions(-)
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 6011f77..044be52 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -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 + puts("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);

Hi Nikita,
On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl_mmc.c | 77 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 22 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
But can we only have one spl_mmc_find_device() function, with the #ifdef CONFIG_DM_MMC inside it?
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 6011f77..044be52 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -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
puts("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); -- 1.9.1
Regards, Simon

Hi Simon,
On Thu, Oct 29, 2015 at 11:19:16AM -0600, Simon Glass wrote:
Hi Nikita,
On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl_mmc.c | 77 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 22 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
But can we only have one spl_mmc_find_device() function, with the #ifdef CONFIG_DM_MMC inside it?
I prefer to have as few #ifdefs inside a function as possible. Besides, once driver model becomes ubiquitous we're going to have only one spl_mmc_find_device() anyway.
-- 1.9.1
Regards, Simon

On Wed, Oct 28, 2015 at 11:23:20AM +0200, Nikita Kiryanov wrote:
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.
[snip]
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
puts("spl: could not find mmc device. error: %d\n", err);
+#endif
Should be printf. And this reminds me that after we dug into things before, there's really not a reason to use 'puts' sometimes and 'printf' another, we can always just do printf and it doesn't actually change the size.

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org Cc: Guillaume GARDET guillaume.gardet@free.fr Cc: Suriyan Ramasami suriyan.r@gmail.com --- 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(-)
diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c index 9d37fd3..a42fbd0 100644 --- a/common/spl/spl_ext.c +++ b/common/spl/spl_ext.c @@ -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 diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 350f7d9..0daadbe 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -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 diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 044be52..9fec2c4 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -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);

On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org Cc: Guillaume GARDET guillaume.gardet@free.fr Cc: Suriyan Ramasami suriyan.r@gmail.com
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(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 28, 2015 at 11:23:21AM +0200, Nikita Kiryanov wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org Cc: Guillaume GARDET guillaume.gardet@free.fr Cc: Suriyan Ramasami suriyan.r@gmail.com
Reviewed-by: Tom Rini trini@konsulko.com

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org --- Changes in V2: - No changes.
common/spl/spl_mmc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 9fec2c4..5d67952 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -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)

On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl_mmc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 28, 2015 at 11:23:22AM +0200, Nikita Kiryanov wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

Move the code that handles fs boot out of spl_mmc_load_image() and into its own function to reduce the #ifdef complexit of spl_mmc_load_image().
No functional changes.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org --- Changes in V2: - No changes.
common/spl/spl_mmc.c | 81 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 30 deletions(-)
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 5d67952..08aa4ae 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -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:

On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
Move the code that handles fs boot out of spl_mmc_load_image() and into its own function to reduce the #ifdef complexit of spl_mmc_load_image().
complexity
No functional changes.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl_mmc.c | 81 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 30 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 28, 2015 at 11:23:23AM +0200, Nikita Kiryanov wrote:
Move the code that handles fs boot out of spl_mmc_load_image() and into its own function to reduce the #ifdef complexit of spl_mmc_load_image().
No functional changes.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org --- Changes in V2: - No changes.
common/spl/spl_mmc.c | 54 ++++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 36 deletions(-)
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index 08aa4ae..eaba29b 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -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:

On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl_mmc.c | 54 ++++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 36 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 28, 2015 at 11:23:24AM +0200, Nikita Kiryanov wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Paul Kocialkowski contact@paulk.fr Cc: Pantelis Antoniou panto@antoniou-consulting.com Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org Cc: Ian Campbell ijc@hellion.org.uk Cc: Hans De Goede hdegoede@redhat.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Jagan Teki jteki@openedev.com --- 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 | 2 +- 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, 116 insertions(+), 64 deletions(-)
diff --git a/arch/arm/cpu/armv7/sunxi/board.c b/arch/arm/cpu/armv7/sunxi/board.c index 4785ac6..9b5c46b 100644 --- a/arch/arm/cpu/armv7/sunxi/board.c +++ b/arch/arm/cpu/armv7/sunxi/board.c @@ -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) diff --git a/arch/arm/include/asm/spl.h b/arch/arm/include/asm/spl.h index 6db405d..f8092c7 100644 --- a/arch/arm/include/asm/spl.h +++ b/arch/arm/include/asm/spl.h @@ -32,7 +32,7 @@ enum { #endif
/* Board-specific load method */ -void spl_board_load_image(void); +int spl_board_load_image(void);
/* Linker symbols. */ extern char __bss_start[], __bss_end[]; diff --git a/common/spl/spl.c b/common/spl/spl.c index 4b319d6..ff1bad2 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -132,7 +132,7 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) }
#ifdef CONFIG_SPL_RAM_DEVICE -static void spl_ram_load_image(void) +static int spl_ram_load_image(void) { const struct image_header *header;
@@ -145,6 +145,8 @@ static void spl_ram_load_image(void) (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
spl_parse_image_header(header); + + return 0; } #endif
@@ -208,68 +210,81 @@ void board_init_r(gd_t *dummy1, ulong dummy2) switch (boot_device) { #ifdef CONFIG_SPL_RAM_DEVICE case BOOT_DEVICE_RAM: - spl_ram_load_image(); + if (spl_ram_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_MMC_SUPPORT case BOOT_DEVICE_MMC1: case BOOT_DEVICE_MMC2: case BOOT_DEVICE_MMC2_2: - spl_mmc_load_image(); + if (spl_mmc_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_NAND_SUPPORT case BOOT_DEVICE_NAND: - spl_nand_load_image(); + if (spl_nand_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_ONENAND_SUPPORT case BOOT_DEVICE_ONENAND: - spl_onenand_load_image(); + if (spl_onenand_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_NOR_SUPPORT case BOOT_DEVICE_NOR: - spl_nor_load_image(); + if (spl_nor_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_YMODEM_SUPPORT case BOOT_DEVICE_UART: - spl_ymodem_load_image(); + if (spl_ymodem_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_SPI_SUPPORT case BOOT_DEVICE_SPI: - spl_spi_load_image(); + if (spl_spi_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_ETH_SUPPORT case BOOT_DEVICE_CPGMAC: #ifdef CONFIG_SPL_ETH_DEVICE - spl_net_load_image(CONFIG_SPL_ETH_DEVICE); + if (spl_net_load_image(CONFIG_SPL_ETH_DEVICE)) + hang(); #else - spl_net_load_image(NULL); + if (spl_net_load_image(NULL)) + hang(); #endif break; #endif #ifdef CONFIG_SPL_USBETH_SUPPORT case BOOT_DEVICE_USBETH: - spl_net_load_image("usb_ether"); + if (spl_net_load_image("usb_ether")) + hang(); break; #endif #ifdef CONFIG_SPL_USB_SUPPORT case BOOT_DEVICE_USB: - spl_usb_load_image(); + if (spl_usb_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_SATA_SUPPORT case BOOT_DEVICE_SATA: - spl_sata_load_image(); + if (spl_sata_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_BOARD_LOAD_IMAGE case BOOT_DEVICE_BOARD: - spl_board_load_image(); + if (spl_board_load_image()) + hang(); break; #endif default: diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index eaba29b..ab9ec88 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -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; } diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 6e4e641..ad69db7 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -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 diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c index 217a435..63b20d8 100644 --- a/common/spl/spl_net.c +++ b/common/spl/spl_net.c @@ -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; } diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c index c2fee01..e08afe2 100644 --- a/common/spl/spl_nor.c +++ b/common/spl/spl_nor.c @@ -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; } diff --git a/common/spl/spl_onenand.c b/common/spl/spl_onenand.c index d8d8097..af7d82e 100644 --- a/common/spl/spl_onenand.c +++ b/common/spl/spl_onenand.c @@ -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; } diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c index 2a5eb29..3ba4c24 100644 --- a/common/spl/spl_sata.c +++ b/common/spl/spl_sata.c @@ -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; } diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c index c81672b..588b85c 100644 --- a/common/spl/spl_usb.c +++ b/common/spl/spl_usb.c @@ -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; } diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c index 0f1e9970..380d8dd 100644 --- a/common/spl/spl_ymodem.c +++ b/common/spl/spl_ymodem.c @@ -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; } diff --git a/drivers/mtd/spi/spi_spl_load.c b/drivers/mtd/spi/spi_spl_load.c index 2e0c871..ca56fe9 100644 --- a/drivers/mtd/spi/spi_spl_load.c +++ b/drivers/mtd/spi/spi_spl_load.c @@ -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; } diff --git a/include/spl.h b/include/spl.h index 8e53426..46fc454 100644 --- a/include/spl.h +++ b/include/spl.h @@ -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);

Hi Nikita,
On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org Cc: Ian Campbell ijc@hellion.org.uk Cc: Hans De Goede hdegoede@redhat.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Jagan Teki jteki@openedev.com
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 | 2 +- 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, 116 insertions(+), 64 deletions(-)
diff --git a/arch/arm/cpu/armv7/sunxi/board.c b/arch/arm/cpu/armv7/sunxi/board.c index 4785ac6..9b5c46b 100644 --- a/arch/arm/cpu/armv7/sunxi/board.c +++ b/arch/arm/cpu/armv7/sunxi/board.c @@ -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) diff --git a/arch/arm/include/asm/spl.h b/arch/arm/include/asm/spl.h index 6db405d..f8092c7 100644 --- a/arch/arm/include/asm/spl.h +++ b/arch/arm/include/asm/spl.h @@ -32,7 +32,7 @@ enum { #endif
/* Board-specific load method */ -void spl_board_load_image(void); +int spl_board_load_image(void);
Please add a comment about what this does, and the return value.
/* Linker symbols. */ extern char __bss_start[], __bss_end[]; diff --git a/common/spl/spl.c b/common/spl/spl.c index 4b319d6..ff1bad2 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -132,7 +132,7 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) }
#ifdef CONFIG_SPL_RAM_DEVICE -static void spl_ram_load_image(void) +static int spl_ram_load_image(void) { const struct image_header *header;
@@ -145,6 +145,8 @@ static void spl_ram_load_image(void) (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
spl_parse_image_header(header);
return 0;
} #endif
@@ -208,68 +210,81 @@ void board_init_r(gd_t *dummy1, ulong dummy2) switch (boot_device) { #ifdef CONFIG_SPL_RAM_DEVICE case BOOT_DEVICE_RAM:
spl_ram_load_image();
if (spl_ram_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_MMC_SUPPORT case BOOT_DEVICE_MMC1: case BOOT_DEVICE_MMC2: case BOOT_DEVICE_MMC2_2:
spl_mmc_load_image();
if (spl_mmc_load_image())
hang();
Can you use something like:
ret = spl_mmc_load_image()
and put the hang() after the switch()?
break;
#endif #ifdef CONFIG_SPL_NAND_SUPPORT case BOOT_DEVICE_NAND:
spl_nand_load_image();
if (spl_nand_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_ONENAND_SUPPORT case BOOT_DEVICE_ONENAND:
spl_onenand_load_image();
if (spl_onenand_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_NOR_SUPPORT case BOOT_DEVICE_NOR:
spl_nor_load_image();
if (spl_nor_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_YMODEM_SUPPORT case BOOT_DEVICE_UART:
spl_ymodem_load_image();
if (spl_ymodem_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_SPI_SUPPORT case BOOT_DEVICE_SPI:
spl_spi_load_image();
if (spl_spi_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_ETH_SUPPORT case BOOT_DEVICE_CPGMAC: #ifdef CONFIG_SPL_ETH_DEVICE
spl_net_load_image(CONFIG_SPL_ETH_DEVICE);
if (spl_net_load_image(CONFIG_SPL_ETH_DEVICE))
hang();
#else
spl_net_load_image(NULL);
if (spl_net_load_image(NULL))
hang();
#endif break; #endif
[snip]
Regards, Simon

Hi Simon, On Thu, Oct 29, 2015 at 11:19:38AM -0600, Simon Glass wrote:
Hi Nikita,
On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org Cc: Ian Campbell ijc@hellion.org.uk Cc: Hans De Goede hdegoede@redhat.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Jagan Teki jteki@openedev.com
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 | 2 +- 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, 116 insertions(+), 64 deletions(-)
diff --git a/arch/arm/cpu/armv7/sunxi/board.c b/arch/arm/cpu/armv7/sunxi/board.c index 4785ac6..9b5c46b 100644 --- a/arch/arm/cpu/armv7/sunxi/board.c +++ b/arch/arm/cpu/armv7/sunxi/board.c @@ -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) diff --git a/arch/arm/include/asm/spl.h b/arch/arm/include/asm/spl.h index 6db405d..f8092c7 100644 --- a/arch/arm/include/asm/spl.h +++ b/arch/arm/include/asm/spl.h @@ -32,7 +32,7 @@ enum { #endif
/* Board-specific load method */ -void spl_board_load_image(void); +int spl_board_load_image(void);
Please add a comment about what this does, and the return value.
OK
/* Linker symbols. */ extern char __bss_start[], __bss_end[]; diff --git a/common/spl/spl.c b/common/spl/spl.c index 4b319d6..ff1bad2 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -132,7 +132,7 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) }
#ifdef CONFIG_SPL_RAM_DEVICE -static void spl_ram_load_image(void) +static int spl_ram_load_image(void) { const struct image_header *header;
@@ -145,6 +145,8 @@ static void spl_ram_load_image(void) (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
spl_parse_image_header(header);
return 0;
} #endif
@@ -208,68 +210,81 @@ void board_init_r(gd_t *dummy1, ulong dummy2) switch (boot_device) { #ifdef CONFIG_SPL_RAM_DEVICE case BOOT_DEVICE_RAM:
spl_ram_load_image();
if (spl_ram_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_MMC_SUPPORT case BOOT_DEVICE_MMC1: case BOOT_DEVICE_MMC2: case BOOT_DEVICE_MMC2_2:
spl_mmc_load_image();
if (spl_mmc_load_image())
hang();
Can you use something like:
ret = spl_mmc_load_image()
and put the hang() after the switch()?
The next patch takes care of that.
break;
#endif #ifdef CONFIG_SPL_NAND_SUPPORT case BOOT_DEVICE_NAND:
spl_nand_load_image();
if (spl_nand_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_ONENAND_SUPPORT case BOOT_DEVICE_ONENAND:
spl_onenand_load_image();
if (spl_onenand_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_NOR_SUPPORT case BOOT_DEVICE_NOR:
spl_nor_load_image();
if (spl_nor_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_YMODEM_SUPPORT case BOOT_DEVICE_UART:
spl_ymodem_load_image();
if (spl_ymodem_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_SPI_SUPPORT case BOOT_DEVICE_SPI:
spl_spi_load_image();
if (spl_spi_load_image())
hang(); break;
#endif #ifdef CONFIG_SPL_ETH_SUPPORT case BOOT_DEVICE_CPGMAC: #ifdef CONFIG_SPL_ETH_DEVICE
spl_net_load_image(CONFIG_SPL_ETH_DEVICE);
if (spl_net_load_image(CONFIG_SPL_ETH_DEVICE))
hang();
#else
spl_net_load_image(NULL);
if (spl_net_load_image(NULL))
hang();
#endif break; #endif
[snip]
Regards, Simon

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org Cc: Ian Campbell ijc@hellion.org.uk Cc: Hans De Goede hdegoede@redhat.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Jagan Teki jteki@openedev.com --- 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(-)
diff --git a/arch/arm/cpu/armv7/sunxi/board.c b/arch/arm/cpu/armv7/sunxi/board.c index 4785ac6..9b5c46b 100644 --- a/arch/arm/cpu/armv7/sunxi/board.c +++ b/arch/arm/cpu/armv7/sunxi/board.c @@ -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) diff --git a/arch/arm/include/asm/spl.h b/arch/arm/include/asm/spl.h index 6db405d..5c5d33f 100644 --- a/arch/arm/include/asm/spl.h +++ b/arch/arm/include/asm/spl.h @@ -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[]; diff --git a/common/spl/spl.c b/common/spl/spl.c index 4b319d6..ff1bad2 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -132,7 +132,7 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) }
#ifdef CONFIG_SPL_RAM_DEVICE -static void spl_ram_load_image(void) +static int spl_ram_load_image(void) { const struct image_header *header;
@@ -145,6 +145,8 @@ static void spl_ram_load_image(void) (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
spl_parse_image_header(header); + + return 0; } #endif
@@ -208,68 +210,81 @@ void board_init_r(gd_t *dummy1, ulong dummy2) switch (boot_device) { #ifdef CONFIG_SPL_RAM_DEVICE case BOOT_DEVICE_RAM: - spl_ram_load_image(); + if (spl_ram_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_MMC_SUPPORT case BOOT_DEVICE_MMC1: case BOOT_DEVICE_MMC2: case BOOT_DEVICE_MMC2_2: - spl_mmc_load_image(); + if (spl_mmc_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_NAND_SUPPORT case BOOT_DEVICE_NAND: - spl_nand_load_image(); + if (spl_nand_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_ONENAND_SUPPORT case BOOT_DEVICE_ONENAND: - spl_onenand_load_image(); + if (spl_onenand_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_NOR_SUPPORT case BOOT_DEVICE_NOR: - spl_nor_load_image(); + if (spl_nor_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_YMODEM_SUPPORT case BOOT_DEVICE_UART: - spl_ymodem_load_image(); + if (spl_ymodem_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_SPI_SUPPORT case BOOT_DEVICE_SPI: - spl_spi_load_image(); + if (spl_spi_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_ETH_SUPPORT case BOOT_DEVICE_CPGMAC: #ifdef CONFIG_SPL_ETH_DEVICE - spl_net_load_image(CONFIG_SPL_ETH_DEVICE); + if (spl_net_load_image(CONFIG_SPL_ETH_DEVICE)) + hang(); #else - spl_net_load_image(NULL); + if (spl_net_load_image(NULL)) + hang(); #endif break; #endif #ifdef CONFIG_SPL_USBETH_SUPPORT case BOOT_DEVICE_USBETH: - spl_net_load_image("usb_ether"); + if (spl_net_load_image("usb_ether")) + hang(); break; #endif #ifdef CONFIG_SPL_USB_SUPPORT case BOOT_DEVICE_USB: - spl_usb_load_image(); + if (spl_usb_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_SATA_SUPPORT case BOOT_DEVICE_SATA: - spl_sata_load_image(); + if (spl_sata_load_image()) + hang(); break; #endif #ifdef CONFIG_SPL_BOARD_LOAD_IMAGE case BOOT_DEVICE_BOARD: - spl_board_load_image(); + if (spl_board_load_image()) + hang(); break; #endif default: diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index eaba29b..ab9ec88 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -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; } diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c index 6e4e641..ad69db7 100644 --- a/common/spl/spl_nand.c +++ b/common/spl/spl_nand.c @@ -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 diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c index 217a435..63b20d8 100644 --- a/common/spl/spl_net.c +++ b/common/spl/spl_net.c @@ -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; } diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c index c2fee01..e08afe2 100644 --- a/common/spl/spl_nor.c +++ b/common/spl/spl_nor.c @@ -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; } diff --git a/common/spl/spl_onenand.c b/common/spl/spl_onenand.c index d8d8097..af7d82e 100644 --- a/common/spl/spl_onenand.c +++ b/common/spl/spl_onenand.c @@ -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; } diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c index 2a5eb29..3ba4c24 100644 --- a/common/spl/spl_sata.c +++ b/common/spl/spl_sata.c @@ -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; } diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c index c81672b..588b85c 100644 --- a/common/spl/spl_usb.c +++ b/common/spl/spl_usb.c @@ -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; } diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c index 0f1e9970..380d8dd 100644 --- a/common/spl/spl_ymodem.c +++ b/common/spl/spl_ymodem.c @@ -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; } diff --git a/drivers/mtd/spi/spi_spl_load.c b/drivers/mtd/spi/spi_spl_load.c index 2e0c871..ca56fe9 100644 --- a/drivers/mtd/spi/spi_spl_load.c +++ b/drivers/mtd/spi/spi_spl_load.c @@ -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; } diff --git a/include/spl.h b/include/spl.h index 8e53426..46fc454 100644 --- a/include/spl.h +++ b/include/spl.h @@ -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);

On Tue, Nov 03, 2015 at 02:19:53PM +0200, Nikita Kiryanov wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org Cc: Ian Campbell ijc@hellion.org.uk Cc: Hans De Goede hdegoede@redhat.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Jagan Teki jteki@openedev.com
Reviewed-by: Tom Rini trini@konsulko.com

On 3 November 2015 at 05:19, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org Cc: Ian Campbell ijc@hellion.org.uk Cc: Hans De Goede hdegoede@redhat.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Jagan Teki jteki@openedev.com
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(-)
Reviewed-by: Simon Glass sjg@chromium.org

Refactor spl image load code out of board_init_r and into its own function. This is a preparation for supporting alternative boot devices.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org --- Changes in V2: - No changes.
common/spl/spl.c | 117 ++++++++++++++++++++++++------------------------------- 1 file changed, 50 insertions(+), 67 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index ff1bad2..56fccca 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -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");

On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
Refactor spl image load code out of board_init_r and into its own function. This is a preparation for supporting alternative boot devices.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl.c | 117 ++++++++++++++++++++++++------------------------------- 1 file changed, 50 insertions(+), 67 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 28, 2015 at 11:23:26AM +0200, Nikita Kiryanov wrote:
Refactor spl image load code out of board_init_r and into its own function. This is a preparation for supporting alternative boot devices.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org --- Changes in V2: - No changes.
common/spl/spl.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 56fccca..7913c52 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -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:

Hi Nikita,
On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
How will we convert this to driver model? I'm worried that this might create a separate method which will live forever.
diff --git a/common/spl/spl.c b/common/spl/spl.c index 56fccca..7913c52 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -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:
-- 1.9.1
Regards, Simon

On Thu, Oct 29, 2015 at 11:19:51AM -0600, Simon Glass wrote:
Hi Nikita,
On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
How will we convert this to driver model? I'm worried that this might create a separate method which will live forever.
I don't see how this is related to driver model. This code just fills in an array and iterates over it. Can you elaborate?
diff --git a/common/spl/spl.c b/common/spl/spl.c index 56fccca..7913c52 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -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:
-- 1.9.1
Regards, Simon

On Sat, Oct 31, 2015 at 05:39:56PM +0200, Nikita Kiryanov wrote:
On Thu, Oct 29, 2015 at 11:19:51AM -0600, Simon Glass wrote:
Hi Nikita,
On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
How will we convert this to driver model? I'm worried that this might create a separate method which will live forever.
I don't see how this is related to driver model. This code just fills in an array and iterates over it. Can you elaborate?
Indeed. With DM we'd just want to make sure that we probe for the device before trying to use it, yes?

Hi,
On 3 November 2015 at 08:56, Tom Rini trini@konsulko.com wrote:
On Sat, Oct 31, 2015 at 05:39:56PM +0200, Nikita Kiryanov wrote:
On Thu, Oct 29, 2015 at 11:19:51AM -0600, Simon Glass wrote:
Hi Nikita,
On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
How will we convert this to driver model? I'm worried that this might create a separate method which will live forever.
I don't see how this is related to driver model. This code just fills in an array and iterates over it. Can you elaborate?
Indeed. With DM we'd just want to make sure that we probe for the device before trying to use it, yes?
I'm not sure, hence my question.
I imagine that we might have a 'boot device' as a child of each of these, but I'm really not sure. Let's worry about it later.
Regards, Simon

On Wed, Oct 28, 2015 at 11:23:27AM +0200, Nikita Kiryanov wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org --- Changes in V2: - No changes.
common/spl/spl.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 7913c52..ee30290 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -178,6 +178,91 @@ int spl_init(void) return 0; }
+#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE +__weak void spl_board_announce_boot_device(void) { } +#endif + +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT +static void announce_boot_device(u32 boot_device) +{ + puts("Trying to boot from "); + switch (boot_device) { +#ifdef CONFIG_SPL_RAM_DEVICE + case BOOT_DEVICE_RAM: + puts("RAM"); + break; +#endif +#ifdef CONFIG_SPL_MMC_SUPPORT + case BOOT_DEVICE_MMC1: + case BOOT_DEVICE_MMC2: + case BOOT_DEVICE_MMC2_2: + puts("MMC"); + break; +#endif +#ifdef CONFIG_SPL_NAND_SUPPORT + case BOOT_DEVICE_NAND: + puts("NAND"); + break; +#endif +#ifdef CONFIG_SPL_ONENAND_SUPPORT + case BOOT_DEVICE_ONENAND: + puts("OneNAND"); + break; +#endif +#ifdef CONFIG_SPL_NOR_SUPPORT + case BOOT_DEVICE_NOR: + puts("NOR"); + break; +#endif +#ifdef CONFIG_SPL_YMODEM_SUPPORT + case BOOT_DEVICE_UART: + puts("UART"); + break; +#endif +#ifdef CONFIG_SPL_SPI_SUPPORT + case BOOT_DEVICE_SPI: + puts("SPI"); + break; +#endif +#ifdef CONFIG_SPL_ETH_SUPPORT + case BOOT_DEVICE_CPGMAC: +#ifdef CONFIG_SPL_ETH_DEVICE + puts("eth device"); +#else + puts("net"); +#endif + break; +#endif +#ifdef CONFIG_SPL_USBETH_SUPPORT + case BOOT_DEVICE_USBETH: + puts("USB eth"); + break; +#endif +#ifdef CONFIG_SPL_USB_SUPPORT + case BOOT_DEVICE_USB: + puts("USB"); + break; +#endif +#ifdef CONFIG_SPL_SATA_SUPPORT + case BOOT_DEVICE_SATA: + puts("SATA"); + break; +#endif +#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE + case BOOT_DEVICE_BOARD: + spl_board_announce_boot_device(); + break; +#endif + default: + printf("%d (unknown boot device)", boot_device); + } + + puts("\n"); +} +#else +static inline void announce_boot_device(u32 boot_device) { } +#endif + #ifndef BOOT_DEVICE_NONE #define BOOT_DEVICE_NONE 0xdeadbeef #endif @@ -292,6 +377,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; }

Hi Nikita,
On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 7913c52..ee30290 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -178,6 +178,91 @@ int spl_init(void) return 0; }
+#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE +__weak void spl_board_announce_boot_device(void) { } +#endif
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT +static void announce_boot_device(u32 boot_device) +{
puts("Trying to boot from ");
switch (boot_device) {
+#ifdef CONFIG_SPL_RAM_DEVICE
case BOOT_DEVICE_RAM:
puts("RAM");
break;
+#endif +#ifdef CONFIG_SPL_MMC_SUPPORT
case BOOT_DEVICE_MMC1:
case BOOT_DEVICE_MMC2:
case BOOT_DEVICE_MMC2_2:
puts("MMC");
break;
+#endif
Perhaps we need a table of function pointers with the name for each? This code seems very repetitive.
+#ifdef CONFIG_SPL_NAND_SUPPORT
case BOOT_DEVICE_NAND:
puts("NAND");
break;
+#endif +#ifdef CONFIG_SPL_ONENAND_SUPPORT
case BOOT_DEVICE_ONENAND:
puts("OneNAND");
break;
+#endif +#ifdef CONFIG_SPL_NOR_SUPPORT
case BOOT_DEVICE_NOR:
puts("NOR");
break;
+#endif +#ifdef CONFIG_SPL_YMODEM_SUPPORT
case BOOT_DEVICE_UART:
puts("UART");
break;
+#endif +#ifdef CONFIG_SPL_SPI_SUPPORT
case BOOT_DEVICE_SPI:
puts("SPI");
break;
+#endif +#ifdef CONFIG_SPL_ETH_SUPPORT
case BOOT_DEVICE_CPGMAC:
+#ifdef CONFIG_SPL_ETH_DEVICE
puts("eth device");
+#else
puts("net");
+#endif
break;
+#endif +#ifdef CONFIG_SPL_USBETH_SUPPORT
case BOOT_DEVICE_USBETH:
puts("USB eth");
break;
+#endif +#ifdef CONFIG_SPL_USB_SUPPORT
case BOOT_DEVICE_USB:
puts("USB");
break;
+#endif +#ifdef CONFIG_SPL_SATA_SUPPORT
case BOOT_DEVICE_SATA:
puts("SATA");
break;
+#endif +#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE
case BOOT_DEVICE_BOARD:
spl_board_announce_boot_device();
break;
+#endif
default:
printf("%d (unknown boot device)", boot_device);
}
puts("\n");
+} +#else +static inline void announce_boot_device(u32 boot_device) { } +#endif
#ifndef BOOT_DEVICE_NONE #define BOOT_DEVICE_NONE 0xdeadbeef #endif @@ -292,6 +377,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; }
-- 1.9.1
Regards, Simon

On Thu, Oct 29, 2015 at 11:19:53AM -0600, Simon Glass wrote:
Hi Nikita,
On 28 October 2015 at 03:23, Nikita Kiryanov nikita@compulab.co.il wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Changes in V2: - No changes.
common/spl/spl.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 7913c52..ee30290 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -178,6 +178,91 @@ int spl_init(void) return 0; }
+#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE +__weak void spl_board_announce_boot_device(void) { } +#endif
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT +static void announce_boot_device(u32 boot_device) +{
puts("Trying to boot from ");
switch (boot_device) {
+#ifdef CONFIG_SPL_RAM_DEVICE
case BOOT_DEVICE_RAM:
puts("RAM");
break;
+#endif +#ifdef CONFIG_SPL_MMC_SUPPORT
case BOOT_DEVICE_MMC1:
case BOOT_DEVICE_MMC2:
case BOOT_DEVICE_MMC2_2:
puts("MMC");
break;
+#endif
Perhaps we need a table of function pointers with the name for each? This code seems very repetitive.
Or BOOT_DEVICE_* -> name. It'll still have a lot of repetitive lines but I guess the function itself will look nicer. I'll prepare something in a V3..
+#ifdef CONFIG_SPL_NAND_SUPPORT
case BOOT_DEVICE_NAND:
puts("NAND");
break;
+#endif +#ifdef CONFIG_SPL_ONENAND_SUPPORT
case BOOT_DEVICE_ONENAND:
puts("OneNAND");
break;
+#endif +#ifdef CONFIG_SPL_NOR_SUPPORT
case BOOT_DEVICE_NOR:
puts("NOR");
break;
+#endif +#ifdef CONFIG_SPL_YMODEM_SUPPORT
case BOOT_DEVICE_UART:
puts("UART");
break;
+#endif +#ifdef CONFIG_SPL_SPI_SUPPORT
case BOOT_DEVICE_SPI:
puts("SPI");
break;
+#endif +#ifdef CONFIG_SPL_ETH_SUPPORT
case BOOT_DEVICE_CPGMAC:
+#ifdef CONFIG_SPL_ETH_DEVICE
puts("eth device");
+#else
puts("net");
+#endif
break;
+#endif +#ifdef CONFIG_SPL_USBETH_SUPPORT
case BOOT_DEVICE_USBETH:
puts("USB eth");
break;
+#endif +#ifdef CONFIG_SPL_USB_SUPPORT
case BOOT_DEVICE_USB:
puts("USB");
break;
+#endif +#ifdef CONFIG_SPL_SATA_SUPPORT
case BOOT_DEVICE_SATA:
puts("SATA");
break;
+#endif +#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE
case BOOT_DEVICE_BOARD:
spl_board_announce_boot_device();
break;
+#endif
default:
printf("%d (unknown boot device)", boot_device);
}
puts("\n");
+} +#else +static inline void announce_boot_device(u32 boot_device) { } +#endif
#ifndef BOOT_DEVICE_NONE #define BOOT_DEVICE_NONE 0xdeadbeef #endif @@ -292,6 +377,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; }
-- 1.9.1
Regards, Simon

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org --- 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(+)
diff --git a/common/spl/spl.c b/common/spl/spl.c index 7913c52..11b452b 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -178,6 +178,84 @@ int spl_init(void) return 0; }
+#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 + #ifndef BOOT_DEVICE_NONE #define BOOT_DEVICE_NONE 0xdeadbeef #endif @@ -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; }

On Tue, Nov 03, 2015 at 02:20:41PM +0200, Nikita Kiryanov wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Tom Rini trini@konsulko.com Cc: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

Use spl alternate boot device feature to define fallback to the main boot device as it is defined by hardware.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Stefano Babic sbabic@denx.de Cc: Tom Rini trini@konsulko.com --- 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(-)
diff --git a/board/compulab/cm_fx6/spl.c b/board/compulab/cm_fx6/spl.c index d94ced9..d8328fd 100644 --- a/board/compulab/cm_fx6/spl.c +++ b/board/compulab/cm_fx6/spl.c @@ -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 diff --git a/include/configs/cm_fx6.h b/include/configs/cm_fx6.h index 0513204..180ea28 100644 --- a/include/configs/cm_fx6.h +++ b/include/configs/cm_fx6.h @@ -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)

On Wed, Oct 28, 2015 at 11:23:29AM +0200, Nikita Kiryanov wrote:
Use spl alternate boot device feature to define fallback to the main boot device as it is defined by hardware.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Stefano Babic sbabic@denx.de Cc: Tom Rini trini@konsulko.com
Reviewed-by: Tom Rini trini@konsulko.com

On 28/10/2015 10:23, Nikita Kiryanov wrote:
Use spl alternate boot device feature to define fallback to the main boot device as it is defined by hardware.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Igor Grinberg grinberg@compulab.co.il Cc: Stefano Babic sbabic@denx.de Cc: Tom Rini trini@konsulko.com
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(-)
diff --git a/board/compulab/cm_fx6/spl.c b/board/compulab/cm_fx6/spl.c index d94ced9..d8328fd 100644 --- a/board/compulab/cm_fx6/spl.c +++ b/board/compulab/cm_fx6/spl.c @@ -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 diff --git a/include/configs/cm_fx6.h b/include/configs/cm_fx6.h index 0513204..180ea28 100644 --- a/include/configs/cm_fx6.h +++ b/include/configs/cm_fx6.h @@ -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)
Reviewed-by: Stefano Babic sbabic@denx.de
Best regards, Stefano Babic

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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Hans De Goede hdegoede@redhat.com Cc: Tom Rini trini@konsulko.com Cc: Ian Campbell ijc@hellion.org.uk --- 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(-)
diff --git a/arch/arm/cpu/armv7/sunxi/board.c b/arch/arm/cpu/armv7/sunxi/board.c index 9b5c46b..794b829 100644 --- a/arch/arm/cpu/armv7/sunxi/board.c +++ b/arch/arm/cpu/armv7/sunxi/board.c @@ -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
diff --git a/common/spl/spl.c b/common/spl/spl.c index ee30290..189c8f7 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -291,7 +291,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: diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index ab9ec88..2f7e7aa 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -61,11 +61,32 @@ end: return 0; }
+int spl_mmc_get_device_index(u32 boot_device) +{ + switch (boot_device) { + case BOOT_DEVICE_MMC1: + return 0; + case BOOT_DEVICE_MMC2: + case BOOT_DEVICE_MMC2_2: + return 1; + } + +#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT + printf("spl: unsupported mmc boot device.\n"); +#endif + + return -ENODEV; +} + #ifdef CONFIG_DM_MMC -static int spl_mmc_find_device(struct mmc **mmc) +static int spl_mmc_find_device(struct mmc **mmc, u32 boot_device) { struct udevice *dev; - int err; + int err, mmc_dev; + + mmc_dev = spl_mmc_get_device_index(boot_device); + if (mmc_dev < 0) + return mmc_dev;
err = mmc_initialize(NULL); if (err) { @@ -75,7 +96,7 @@ static int spl_mmc_find_device(struct mmc **mmc) return err; }
- err = uclass_get_device(UCLASS_MMC, 0, &dev); + err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev); if (err) { #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT puts("spl: could not find mmc device. error: %d\n", err); @@ -88,9 +109,13 @@ static int spl_mmc_find_device(struct mmc **mmc) return *mmc != NULL ? 0 : -ENODEV; } #else -static int spl_mmc_find_device(struct mmc **mmc) +static int spl_mmc_find_device(struct mmc **mmc, u32 boot_device) { - int err; + int err, mmc_dev; + + mmc_dev = spl_mmc_get_device_index(boot_device); + if (mmc_dev < 0) + return mmc_dev;
err = mmc_initialize(gd->bd); if (err) { @@ -101,7 +126,7 @@ static int spl_mmc_find_device(struct mmc **mmc) }
/* We register only one device. So, the dev id is always 0 */ - *mmc = find_mmc_device(0); + *mmc = find_mmc_device(mmc_dev); if (!*mmc) { #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT puts("spl: mmc device not found\n"); @@ -221,14 +246,14 @@ int spl_mmc_do_fs_boot(struct mmc *mmc) } #endif
-int spl_mmc_load_image(void) +int spl_mmc_load_image(u32 boot_device) { struct mmc *mmc; u32 boot_mode; int err = 0; __maybe_unused int part;
- err = spl_mmc_find_device(&mmc); + err = spl_mmc_find_device(&mmc, boot_device); if (err) return err;
diff --git a/include/spl.h b/include/spl.h index 46fc454..92cdc04 100644 --- a/include/spl.h +++ b/include/spl.h @@ -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);

On Wed, Oct 28, 2015 at 11:23:30AM +0200, Nikita Kiryanov wrote:
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.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Hans De Goede hdegoede@redhat.com Cc: Tom Rini trini@konsulko.com Cc: Ian Campbell ijc@hellion.org.uk
Reviewed-by: Tom Rini trini@konsulko.com
participants (4)
-
Nikita Kiryanov
-
Simon Glass
-
Stefano Babic
-
Tom Rini