All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikita Kiryanov <nikita@compulab.co.il>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 09/12] common: spl: move image load to its own function
Date: Thu, 22 Oct 2015 15:01:17 +0300	[thread overview]
Message-ID: <1445515280-21389-10-git-send-email-nikita@compulab.co.il> (raw)
In-Reply-To: <1445515280-21389-1-git-send-email-nikita@compulab.co.il>

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>
---
 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");
-- 
1.9.1

  parent reply	other threads:[~2015-10-22 12:01 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-22 12:01 [U-Boot] [PATCH 00/12] SPL mmc refactor and alternate boot device feature Nikita Kiryanov
2015-10-22 12:01 ` [U-Boot] [PATCH 01/12] spl: nand: remove code duplication Nikita Kiryanov
2015-10-22 18:11   ` Scott Wood
2015-10-22 12:01 ` [U-Boot] [PATCH 02/12] spl: mmc: add break statements in spl_mmc_load_image() Nikita Kiryanov
2015-10-22 12:37   ` Hans de Goede
2015-10-22 13:08     ` Nikita Kiryanov
2015-10-22 13:23       ` Hans de Goede
2015-10-22 13:53         ` Nikita Kiryanov
2015-10-22 12:01 ` [U-Boot] [PATCH 03/12] spl: mmc: refactor device location code to its own function Nikita Kiryanov
2015-10-22 12:42   ` Hans de Goede
2015-10-22 14:15     ` Nikita Kiryanov
2015-10-22 12:01 ` [U-Boot] [PATCH 04/12] spl: mmc: remove #ifdef CONFIG_SPL_OS_BOOT check Nikita Kiryanov
2015-10-22 12:44   ` Hans de Goede
2015-10-22 12:01 ` [U-Boot] [PATCH 05/12] spl: mmc: get rid of #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION check Nikita Kiryanov
2015-10-22 12:47   ` Hans de Goede
2015-10-22 13:40     ` Nikita Kiryanov
2015-10-22 13:49       ` Tom Rini
2015-10-23  9:40         ` Nikita Kiryanov
2015-10-23 14:03           ` Hans de Goede
2015-10-23 14:11             ` Tom Rini
2015-10-22 12:01 ` [U-Boot] [PATCH 06/12] spl: mmc: move fs boot into its own function Nikita Kiryanov
2015-10-22 12:01 ` [U-Boot] [PATCH 07/12] spl: mmc: get rid of emmc boot code duplication Nikita Kiryanov
2015-10-22 12:01 ` [U-Boot] [PATCH 08/12] spl: change return values of spl_*_load_image() Nikita Kiryanov
2015-10-22 12:01 ` Nikita Kiryanov [this message]
2015-10-22 12:01 ` [U-Boot] [PATCH 10/12] spl: add support for alternative boot device Nikita Kiryanov
2015-10-22 12:01 ` [U-Boot] [PATCH 11/12] spl: announce boot devices Nikita Kiryanov
2015-10-22 12:01 ` [U-Boot] [PATCH 12/12] arm: mx6: cm-fx6: define fallback boot devices for spl Nikita Kiryanov
2015-10-22 12:24 ` [U-Boot] [PATCH 00/12] SPL mmc refactor and alternate boot device feature Otavio Salvador
2015-10-23  9:46   ` Nikita Kiryanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445515280-21389-10-git-send-email-nikita@compulab.co.il \
    --to=nikita@compulab.co.il \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.