summaryrefslogtreecommitdiff
path: root/common/spl
diff options
context:
space:
mode:
authorNikita Kiryanov <nikita@compulab.co.il>2015-11-08 17:11:50 +0200
committerTom Rini <trini@konsulko.com>2015-11-18 14:50:03 -0500
commit5211b87e0c323e7474be9c817c9880f51459fbb9 (patch)
tree940d35ea0a1ef16bf84ae7922078cb766ca8f119 /common/spl
parent36afd451361dd4386c5527154d94bff4c6c538da (diff)
common: spl: move image load to its own function
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: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'common/spl')
-rw-r--r--common/spl/spl.c117
1 files changed, 50 insertions, 67 deletions
diff --git a/common/spl/spl.c b/common/spl/spl.c
index ff1bad23de..56fccca6d0 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");