spl: Convert boot_device into a struct

At present some spl_xxx_load_image() functions take a parameter and some
don't. Of those that do, most take an integer but one takes a string.

Convert this parameter into a struct so that we can pass all functions the
same thing. This will allow us to use a common function signature.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
Simon Glass 2016-09-24 18:19:57 -06:00 committed by Tom Rini
parent a807ab3303
commit ecdfd69a4b
16 changed files with 71 additions and 48 deletions

View file

@ -133,7 +133,7 @@ static int gpio_init(void)
return 0; return 0;
} }
int spl_board_load_image(void) int spl_board_load_image(struct spl_boot_device *bootdev)
{ {
debug("Returning to FEL sp=%x, lr=%x\n", fel_stash.sp, fel_stash.lr); 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_to_fel(fel_stash.sp, fel_stash.lr);

View file

@ -65,7 +65,7 @@ int uniphier_rom_get_mmc_funcptr(int (**send_cmd)(u32, u32),
return 0; return 0;
} }
int spl_board_load_image(void) int spl_board_load_image(struct spl_boot_device *bootdev)
{ {
int (*send_cmd)(u32 cmd, u32 arg); int (*send_cmd)(u32 cmd, u32 arg);
int (*card_blockaddr)(u32 rca); int (*card_blockaddr)(u32 rca);

View file

@ -38,7 +38,7 @@ void spl_board_announce_boot_device(void)
printf("%s\n", fname); printf("%s\n", fname);
} }
int spl_board_load_image(void) int spl_board_load_image(struct spl_boot_device *bootdev)
{ {
char fname[256]; char fname[256];
int ret; int ret;

View file

@ -185,7 +185,7 @@ static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector,
return count; return count;
} }
static int spl_ram_load_image(void) static int spl_ram_load_image(struct spl_boot_device *bootdev)
{ {
struct image_header *header; struct image_header *header;
@ -349,71 +349,76 @@ static inline void announce_boot_device(u32 boot_device) { }
static int spl_load_image(u32 boot_device) static int spl_load_image(u32 boot_device)
{ {
struct spl_boot_device bootdev;
bootdev.boot_device = boot_device;
bootdev.boot_device_name = NULL;
switch (boot_device) { switch (boot_device) {
#ifdef CONFIG_SPL_RAM_DEVICE #ifdef CONFIG_SPL_RAM_DEVICE
case BOOT_DEVICE_RAM: case BOOT_DEVICE_RAM:
return spl_ram_load_image(); return spl_ram_load_image(&bootdev);
#endif #endif
#ifdef CONFIG_SPL_MMC_SUPPORT #ifdef CONFIG_SPL_MMC_SUPPORT
case BOOT_DEVICE_MMC1: case BOOT_DEVICE_MMC1:
case BOOT_DEVICE_MMC2: case BOOT_DEVICE_MMC2:
case BOOT_DEVICE_MMC2_2: case BOOT_DEVICE_MMC2_2:
return spl_mmc_load_image(boot_device); return spl_mmc_load_image(&bootdev);
#endif #endif
#ifdef CONFIG_SPL_UBI #ifdef CONFIG_SPL_UBI
case BOOT_DEVICE_NAND: case BOOT_DEVICE_NAND:
case BOOT_DEVICE_ONENAND: case BOOT_DEVICE_ONENAND:
return spl_ubi_load_image(boot_device); return spl_ubi_load_image(&bootdev);
#else #else
#ifdef CONFIG_SPL_NAND_SUPPORT #ifdef CONFIG_SPL_NAND_SUPPORT
case BOOT_DEVICE_NAND: case BOOT_DEVICE_NAND:
return spl_nand_load_image(); return spl_nand_load_image(&bootdev);
#endif #endif
#ifdef CONFIG_SPL_ONENAND_SUPPORT #ifdef CONFIG_SPL_ONENAND_SUPPORT
case BOOT_DEVICE_ONENAND: case BOOT_DEVICE_ONENAND:
return spl_onenand_load_image(); return spl_onenand_load_image(&bootdev);
#endif #endif
#endif #endif
#ifdef CONFIG_SPL_NOR_SUPPORT #ifdef CONFIG_SPL_NOR_SUPPORT
case BOOT_DEVICE_NOR: case BOOT_DEVICE_NOR:
return spl_nor_load_image(); return spl_nor_load_image(&bootdev);
#endif #endif
#ifdef CONFIG_SPL_YMODEM_SUPPORT #ifdef CONFIG_SPL_YMODEM_SUPPORT
case BOOT_DEVICE_UART: case BOOT_DEVICE_UART:
return spl_ymodem_load_image(); return spl_ymodem_load_image(&bootdev);
#endif #endif
#if defined(CONFIG_SPL_SPI_SUPPORT) || defined(CONFIG_SPL_SPI_FLASH_SUPPORT) #if defined(CONFIG_SPL_SPI_SUPPORT) || defined(CONFIG_SPL_SPI_FLASH_SUPPORT)
case BOOT_DEVICE_SPI: case BOOT_DEVICE_SPI:
return spl_spi_load_image(); return spl_spi_load_image(&bootdev);
#endif #endif
#ifdef CONFIG_SPL_ETH_SUPPORT #ifdef CONFIG_SPL_ETH_SUPPORT
case BOOT_DEVICE_CPGMAC: case BOOT_DEVICE_CPGMAC:
#ifdef CONFIG_SPL_ETH_DEVICE #ifdef CONFIG_SPL_ETH_DEVICE
return spl_net_load_image(CONFIG_SPL_ETH_DEVICE); bootdev.boot_device_name = CONFIG_SPL_ETH_DEVICE;
#else
return spl_net_load_image(NULL);
#endif #endif
return spl_net_load_image(&bootdev);
#endif #endif
#ifdef CONFIG_SPL_USBETH_SUPPORT #ifdef CONFIG_SPL_USBETH_SUPPORT
case BOOT_DEVICE_USBETH: case BOOT_DEVICE_USBETH:
return spl_net_load_image("usb_ether"); bootdev.boot_device_name = "usb_ether";
return spl_net_load_image(&bootdev);
#endif #endif
#ifdef CONFIG_SPL_USB_SUPPORT #ifdef CONFIG_SPL_USB_SUPPORT
case BOOT_DEVICE_USB: case BOOT_DEVICE_USB:
return spl_usb_load_image(); return spl_usb_load_image(&bootdev);
#endif #endif
#ifdef CONFIG_SPL_DFU_SUPPORT #ifdef CONFIG_SPL_DFU_SUPPORT
case BOOT_DEVICE_DFU: case BOOT_DEVICE_DFU:
spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0"); spl_dfu_cmd(0, "dfu_alt_info_ram", "ram", "0");
return spl_ram_load_image(); return spl_ram_load_image(&bootdev);
#endif #endif
#ifdef CONFIG_SPL_SATA_SUPPORT #ifdef CONFIG_SPL_SATA_SUPPORT
case BOOT_DEVICE_SATA: case BOOT_DEVICE_SATA:
return spl_sata_load_image(); return spl_sata_load_image(&bootdev);
#endif #endif
#ifdef CONFIG_SPL_BOARD_LOAD_IMAGE #ifdef CONFIG_SPL_BOARD_LOAD_IMAGE
case BOOT_DEVICE_BOARD: case BOOT_DEVICE_BOARD:
return spl_board_load_image(); return spl_board_load_image(&bootdev);
#endif #endif
default: default:
#if defined(CONFIG_SPL_SERIAL_SUPPORT) && defined(CONFIG_SPL_LIBCOMMON_SUPPORT) #if defined(CONFIG_SPL_SERIAL_SUPPORT) && defined(CONFIG_SPL_LIBCOMMON_SUPPORT)

View file

@ -267,14 +267,14 @@ int spl_mmc_do_fs_boot(struct mmc *mmc)
} }
#endif #endif
int spl_mmc_load_image(u32 boot_device) int spl_mmc_load_image(struct spl_boot_device *bootdev)
{ {
struct mmc *mmc = NULL; struct mmc *mmc = NULL;
u32 boot_mode; u32 boot_mode;
int err = 0; int err = 0;
__maybe_unused int part; __maybe_unused int part;
err = spl_mmc_find_device(&mmc, boot_device); err = spl_mmc_find_device(&mmc, bootdev->boot_device);
if (err) if (err)
return err; return err;
@ -286,7 +286,7 @@ int spl_mmc_load_image(u32 boot_device)
return err; return err;
} }
boot_mode = spl_boot_mode(boot_device); boot_mode = spl_boot_mode(bootdev->boot_device);
err = -EINVAL; err = -EINVAL;
switch (boot_mode) { switch (boot_mode) {
case MMCSD_MODE_EMMCBOOT: case MMCSD_MODE_EMMCBOOT:

View file

@ -13,7 +13,7 @@
#include <fdt.h> #include <fdt.h>
#if defined(CONFIG_SPL_NAND_RAW_ONLY) #if defined(CONFIG_SPL_NAND_RAW_ONLY)
int spl_nand_load_image(void) int spl_nand_load_image(struct spl_boot_device *bootdev)
{ {
nand_init(); nand_init();

View file

@ -14,7 +14,7 @@
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
int spl_net_load_image(const char *device) int spl_net_load_image(struct spl_boot_device *bootdev)
{ {
int rv; int rv;
@ -27,8 +27,8 @@ int spl_net_load_image(const char *device)
printf("No Ethernet devices found\n"); printf("No Ethernet devices found\n");
return -ENODEV; return -ENODEV;
} }
if (device) if (bootdev->boot_device_name)
setenv("ethact", device); setenv("ethact", bootdev->boot_device_name);
rv = net_loop(BOOTP); rv = net_loop(BOOTP);
if (rv < 0) { if (rv < 0) {
printf("Problem booting with BOOTP\n"); printf("Problem booting with BOOTP\n");

View file

@ -7,7 +7,7 @@
#include <common.h> #include <common.h>
#include <spl.h> #include <spl.h>
int spl_nor_load_image(void) int spl_nor_load_image(struct spl_boot_device *bootdev)
{ {
int ret; int ret;
/* /*

View file

@ -14,7 +14,7 @@
#include <asm/io.h> #include <asm/io.h>
#include <onenand_uboot.h> #include <onenand_uboot.h>
int spl_onenand_load_image(void) int spl_onenand_load_image(struct spl_boot_device *bootdev)
{ {
struct image_header *header; struct image_header *header;
int ret; int ret;

View file

@ -20,7 +20,7 @@
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
int spl_sata_load_image(void) int spl_sata_load_image(struct spl_boot_device *bootdev)
{ {
int err; int err;
struct blk_desc *stor_dev; struct blk_desc *stor_dev;

View file

@ -12,14 +12,14 @@
#include <ubispl.h> #include <ubispl.h>
#include <spl.h> #include <spl.h>
int spl_ubi_load_image(u32 boot_device) int spl_ubi_load_image(struct spl_boot_device *bootdev)
{ {
struct image_header *header; struct image_header *header;
struct ubispl_info info; struct ubispl_info info;
struct ubispl_load volumes[2]; struct ubispl_load volumes[2];
int ret = 1; int ret = 1;
switch (boot_device) { switch (bootdev->boot_device) {
#ifdef CONFIG_SPL_NAND_SUPPORT #ifdef CONFIG_SPL_NAND_SUPPORT
case BOOT_DEVICE_NAND: case BOOT_DEVICE_NAND:
nand_init(); nand_init();
@ -71,7 +71,7 @@ int spl_ubi_load_image(u32 boot_device)
spl_parse_image_header(&spl_image, header); spl_parse_image_header(&spl_image, header);
out: out:
#ifdef CONFIG_SPL_NAND_SUPPORT #ifdef CONFIG_SPL_NAND_SUPPORT
if (boot_device == BOOT_DEVICE_NAND) if (bootdev->boot_device == BOOT_DEVICE_NAND)
nand_deselect(); nand_deselect();
#endif #endif
return ret; return ret;

View file

@ -22,7 +22,7 @@ DECLARE_GLOBAL_DATA_PTR;
static int usb_stor_curr_dev = -1; /* current device */ static int usb_stor_curr_dev = -1; /* current device */
#endif #endif
int spl_usb_load_image(void) int spl_usb_load_image(struct spl_boot_device *bootdev)
{ {
int err; int err;
struct blk_desc *stor_dev; struct blk_desc *stor_dev;

View file

@ -68,7 +68,7 @@ static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset,
return size; return size;
} }
int spl_ymodem_load_image(void) int spl_ymodem_load_image(struct spl_boot_device *bootdev)
{ {
int size = 0; int size = 0;
int err; int err;

View file

@ -65,7 +65,7 @@ static ulong spl_spi_fit_read(struct spl_load_info *load, ulong sector,
* configured and available since this code loads the main U-Boot image * configured and available since this code loads the main U-Boot image
* from SPI into SDRAM and starts it from there. * from SPI into SDRAM and starts it from there.
*/ */
int spl_spi_load_image(void) int spl_spi_load_image(struct spl_boot_device *bootdev)
{ {
int err = 0; int err = 0;
struct spi_flash *flash; struct spi_flash *flash;

View file

@ -262,7 +262,7 @@ static void spi0_read_data(void *buf, u32 addr, u32 len)
/*****************************************************************************/ /*****************************************************************************/
int spl_spi_load_image(void) int spl_spi_load_image(struct spl_boot_device *bootdev)
{ {
int err; int err;
struct image_header *header; struct image_header *header;

View file

@ -131,35 +131,53 @@ int spl_start_uboot(void);
*/ */
void spl_display_print(void); void spl_display_print(void);
/**
* struct spl_boot_device - Describes a boot device used by SPL
*
* @boot_device: A number indicating the BOOT_DEVICE type. There are various
* BOOT_DEVICE... #defines and enums in U-Boot and they are not consistently
* numbered.
* @boot_device_name: Named boot device, or NULL if none.
*
* Note: Additional fields can be added here, bearing in mind that SPL is
* size-sensitive and common fields will be present on all boards. This
* struct can also be used to return additional information about the load
* process if that becomes useful.
*/
struct spl_boot_device {
uint boot_device;
const char *boot_device_name;
};
/* NAND SPL functions */ /* NAND SPL functions */
int spl_nand_load_image(void); int spl_nand_load_image(struct spl_boot_device *bootdev);
/* OneNAND SPL functions */ /* OneNAND SPL functions */
int spl_onenand_load_image(void); int spl_onenand_load_image(struct spl_boot_device *bootdev);
/* NOR SPL functions */ /* NOR SPL functions */
int spl_nor_load_image(void); int spl_nor_load_image(struct spl_boot_device *bootdev);
/* UBI SPL functions */ /* UBI SPL functions */
int spl_ubi_load_image(u32 boot_device); int spl_ubi_load_image(struct spl_boot_device *bootdev);
/* MMC SPL functions */ /* MMC SPL functions */
int spl_mmc_load_image(u32 boot_device); int spl_mmc_load_image(struct spl_boot_device *bootdev);
/* YMODEM SPL functions */ /* YMODEM SPL functions */
int spl_ymodem_load_image(void); int spl_ymodem_load_image(struct spl_boot_device *bootdev);
/* SPI SPL functions */ /* SPI SPL functions */
int spl_spi_load_image(void); int spl_spi_load_image(struct spl_boot_device *bootdev);
/* Ethernet SPL functions */ /* Ethernet SPL functions */
int spl_net_load_image(const char *device); int spl_net_load_image(struct spl_boot_device *bootdev);
/* USB SPL functions */ /* USB SPL functions */
int spl_usb_load_image(void); int spl_usb_load_image(struct spl_boot_device *bootdev);
/* SATA SPL functions */ /* SATA SPL functions */
int spl_sata_load_image(void); int spl_sata_load_image(struct spl_boot_device *bootdev);
/* SPL FAT image functions */ /* SPL FAT image functions */
int spl_load_image_fat(struct blk_desc *block_dev, int partition, int spl_load_image_fat(struct blk_desc *block_dev, int partition,
@ -214,6 +232,6 @@ int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr);
* *
* @return 0 on success, negative errno value on failure. * @return 0 on success, negative errno value on failure.
*/ */
int spl_board_load_image(void); int spl_board_load_image(struct spl_boot_device *bootdev);
#endif #endif