#include <asm/global_data.h>
#include <asm/spl.h>
#include <handoff.h>
+#include <mmc.h>
struct blk_desc;
-struct image_header;
+struct legacy_img_hdr;
/* Value in r0 indicates we booted from U-Boot */
#define UBOOT_NOT_LOADED_FROM_SPL 0x13578642
#define MMCSD_MODE_EMMCBOOT 3
struct blk_desc;
-struct image_header;
+struct legacy_img_hdr;
+struct spl_boot_device;
/*
* u_boot_first_phase() - check if this is the first U-Boot phase
}
enum u_boot_phase {
+ PHASE_NONE, /* Invalid phase, signifying before U-Boot */
PHASE_TPL, /* Running in TPL */
+ PHASE_VPL, /* Running in VPL */
PHASE_SPL, /* Running in SPL */
PHASE_BOARD_F, /* Running in U-Boot before relocation */
PHASE_BOARD_R, /* Running in U-Boot after relocation */
+
+ PHASE_COUNT,
};
/**
* ...
* }
*
- * @return U-Boot phase
+ * Return: U-Boot phase
*/
static inline enum u_boot_phase spl_phase(void)
{
#ifdef CONFIG_TPL_BUILD
return PHASE_TPL;
-#elif CONFIG_SPL_BUILD
+#elif defined(CONFIG_VPL_BUILD)
+ return PHASE_VPL;
+#elif defined(CONFIG_SPL_BUILD)
return PHASE_SPL;
#else
DECLARE_GLOBAL_DATA_PTR;
#endif
}
+/**
+ * spl_prev_phase() - Figure out the previous U-Boot phase
+ *
+ * Return: the previous phase from this one, e.g. if called in SPL this returns
+ * PHASE_TPL, if TPL is enabled
+ */
+static inline enum u_boot_phase spl_prev_phase(void)
+{
+#ifdef CONFIG_TPL_BUILD
+ return PHASE_NONE;
+#elif defined(CONFIG_VPL_BUILD)
+ return PHASE_TPL; /* VPL requires TPL */
+#elif defined(CONFIG_SPL_BUILD)
+ return IS_ENABLED(CONFIG_VPL) ? PHASE_VPL :
+ IS_ENABLED(CONFIG_TPL) ? PHASE_TPL :
+ PHASE_NONE;
+#else
+ return IS_ENABLED(CONFIG_SPL) ? PHASE_SPL :
+ PHASE_NONE;
+#endif
+}
+
+/**
+ * spl_next_phase() - Figure out the next U-Boot phase
+ *
+ * Return: the next phase from this one, e.g. if called in TPL this returns
+ * PHASE_SPL
+ */
+static inline enum u_boot_phase spl_next_phase(void)
+{
+#ifdef CONFIG_TPL_BUILD
+ return IS_ENABLED(CONFIG_VPL) ? PHASE_VPL : PHASE_SPL;
+#elif defined(CONFIG_VPL_BUILD)
+ return PHASE_SPL;
+#else
+ return PHASE_BOARD_F;
+#endif
+}
+
+/**
+ * spl_phase_name() - Get the name of the current phase
+ *
+ * Return: phase name
+ */
+static inline const char *spl_phase_name(enum u_boot_phase phase)
+{
+ switch (phase) {
+ case PHASE_TPL:
+ return "TPL";
+ case PHASE_VPL:
+ return "VPL";
+ case PHASE_SPL:
+ return "SPL";
+ case PHASE_BOARD_F:
+ case PHASE_BOARD_R:
+ return "U-Boot";
+ default:
+ return "phase?";
+ }
+}
+
+/**
+ * spl_phase_prefix() - Get the prefix of the current phase
+ *
+ * @phase: Phase to look up
+ * Return: phase prefix ("spl", "tpl", etc.)
+ */
+static inline const char *spl_phase_prefix(enum u_boot_phase phase)
+{
+ switch (phase) {
+ case PHASE_TPL:
+ return "tpl";
+ case PHASE_VPL:
+ return "vpl";
+ case PHASE_SPL:
+ return "spl";
+ case PHASE_BOARD_F:
+ case PHASE_BOARD_R:
+ return "";
+ default:
+ return "phase?";
+ }
+}
+
/* A string name for SPL or TPL */
#ifdef CONFIG_SPL_BUILD
# ifdef CONFIG_TPL_BUILD
# define SPL_TPL_NAME "TPL"
+# elif defined(CONFIG_VPL_BUILD)
+# define SPL_TPL_NAME "VPL"
# else
# define SPL_TPL_NAME "SPL"
# endif
# define SPL_TPL_PROMPT ""
#endif
+/**
+ * enum spl_sandbox_flags - flags for sandbox's use of spl_image_info->flags
+ *
+ * @SPL_SANDBOXF_ARG_IS_FNAME: arg is the filename to jump to (default)
+ * @SPL_SANDBOXF_ARG_IS_BUF: arg is the containing image to jump to, @offset is
+ * the start offset within the image, @size is the size of the image
+ */
+enum spl_sandbox_flags {
+ SPL_SANDBOXF_ARG_IS_FNAME = 0,
+ SPL_SANDBOXF_ARG_IS_BUF,
+};
+
struct spl_image_info {
const char *name;
u8 os;
void *fdt_addr;
#endif
u32 boot_device;
+ u32 offset;
u32 size;
u32 flags;
void *arg;
void *priv;
int bl_len;
const char *filename;
+ /**
+ * read() - Read from device
+ *
+ * @load: Information about the load state
+ * @sector: Sector number to read from (each @load->bl_len bytes)
+ * @count: Number of sectors to read
+ * @buf: Buffer to read into
+ * @return number of sectors read, 0 on error
+ */
ulong (*read)(struct spl_load_info *load, ulong sector, ulong count,
void *buf);
};
*/
binman_sym_extern(ulong, u_boot_any, image_pos);
binman_sym_extern(ulong, u_boot_any, size);
-binman_sym_extern(ulong, spl, image_pos);
-binman_sym_extern(ulong, spl, size);
+binman_sym_extern(ulong, u_boot_spl_any, image_pos);
+binman_sym_extern(ulong, u_boot_spl_any, size);
+binman_sym_extern(ulong, u_boot_vpl_any, image_pos);
+binman_sym_extern(ulong, u_boot_vpl_any, size);
/**
* spl_get_image_pos() - get the image position of the next phase
ulong spl_get_image_size(void);
/**
+ * spl_get_image_text_base() - get the text base of the next phase
+ *
+ * This returns the address that the next stage is linked to run at, i.e.
+ * CONFIG_SPL_TEXT_BASE or CONFIG_TEXT_BASE
+ *
+ * Return: text-base address
+ */
+ulong spl_get_image_text_base(void);
+
+/**
* spl_load_simple_fit_skip_processing() - Hook to allow skipping the FIT
* image processing during spl_load_simple_fit().
*
bool spl_load_simple_fit_skip_processing(void);
/**
+ * spl_load_simple_fit_fix_load() - Hook to make fixes
+ * after fit image header is loaded
+ *
+ * Returns pointer to fit
+ */
+void *spl_load_simple_fit_fix_load(const void *fit);
+
+/**
* spl_load_simple_fit() - Loads a fit image from a device.
* @spl_image: Image description to set up
* @info: Structure containing the information required to load data.
* spl_load_legacy_img() - Loads a legacy image from a device.
* @spl_image: Image description to set up
* @load: Structure containing the information required to load data.
- * @header: Pointer to image header (including appended image)
+ * @offset: Pointer to image
+ * @hdr: Pointer to image header
*
* Reads an legacy image from the device. Loads u-boot image to
* specified load address.
* Returns 0 on success.
*/
int spl_load_legacy_img(struct spl_image_info *spl_image,
- struct spl_load_info *load, ulong header);
+ struct spl_boot_device *bootdev,
+ struct spl_load_info *load, ulong offset,
+ struct legacy_img_hdr *hdr);
+
/**
* spl_load_imx_container() - Loads a imx container image from a device.
u32 spl_boot_device(void);
/**
+ * spl_spi_boot_bus() - Lookup function for the SPI boot bus source.
+ *
+ * This function returns the SF bus to load from.
+ * If not overridden, it is weakly defined in common/spl/spl_spi.c.
+ */
+u32 spl_spi_boot_bus(void);
+
+/**
+ * spl_spi_boot_cs() - Lookup function for the SPI boot CS source.
+ *
+ * This function returns the SF CS to load from.
+ * If not overridden, it is weakly defined in common/spl/spl_spi.c.
+ */
+u32 spl_spi_boot_cs(void);
+
+/**
* spl_mmc_boot_mode() - Lookup function for the mode of an MMC boot source.
* @boot_device: ID of the device which the MMC driver wants to read
* from. Common values are e.g. BOOT_DEVICE_MMC1,
* Note: It is important to use the boot_device parameter instead of e.g.
* spl_boot_device() as U-Boot is not always loaded from the same device as SPL.
*/
-u32 spl_mmc_boot_mode(const u32 boot_device);
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device);
/**
* spl_mmc_boot_partition() - MMC partition to load U-Boot from.
* If not overridden, it is weakly defined in common/spl/spl_mmc.c.
*/
int spl_mmc_boot_partition(const u32 boot_device);
+
+struct mmc;
+/**
+ * default_spl_mmc_emmc_boot_partition() - eMMC boot partition to load U-Boot from.
+ * mmc: Pointer for the mmc device structure
+ *
+ * This function should return the eMMC boot partition number which
+ * the SPL should load U-Boot from (on the given boot_device).
+ */
+int default_spl_mmc_emmc_boot_partition(struct mmc *mmc);
+
+/**
+ * spl_mmc_emmc_boot_partition() - eMMC boot partition to load U-Boot from.
+ * mmc: Pointer for the mmc device structure
+ *
+ * This function should return the eMMC boot partition number which
+ * the SPL should load U-Boot from (on the given boot_device).
+ *
+ * If not overridden, it is weakly defined in common/spl/spl_mmc.c
+ * and calls default_spl_mmc_emmc_boot_partition();
+ */
+int spl_mmc_emmc_boot_partition(struct mmc *mmc);
+
void spl_set_bd(void);
/**
*
* This sets up the given spl_image which the standard values obtained from
* config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START,
- * CONFIG_SYS_TEXT_BASE.
+ * CONFIG_TEXT_BASE.
*
* @spl_image: Image description to set up
*/
*
* @spl_image: Image description to set up
* @header image header to parse
- * @return 0 if a header was correctly parsed, -ve on error
+ * Return: 0 if a header was correctly parsed, -ve on error
*/
int spl_parse_image_header(struct spl_image_info *spl_image,
- const struct image_header *header);
+ const struct spl_boot_device *bootdev,
+ const struct legacy_img_hdr *header);
void spl_board_prepare_for_linux(void);
+
+/**
+ * spl_board_prepare_for_optee() - Prepare board for an OPTEE payload
+ *
+ * Prepares the board for booting an OP-TEE payload. Initialization is platform
+ * specific, and may include configuring the TrustZone memory, and other
+ * initialization steps required by OP-TEE.
+ * Note that @fdt is not used directly by OP-TEE. OP-TEE passes this @fdt to
+ * its normal world target. This target is not guaranteed to be u-boot, so @fdt
+ * changes that would normally be done by u-boot should be done in this step.
+ *
+ * @fdt: Devicetree that will be passed on, or NULL
+ */
+void spl_board_prepare_for_optee(void *fdt);
void spl_board_prepare_for_boot(void);
int spl_board_ubi_load_image(u32 boot_device);
int spl_board_boot_device(u32 boot_device);
/**
+ * spl_board_loader_name() - Return a name for the loader
+ *
+ * This is a weak function which might be overridden by the board code. With
+ * that a board specific value for the device where the U-Boot will be loaded
+ * from can be set. By default it returns NULL.
+ *
+ * @boot_device: ID of the device which SPL wants to load U-Boot from.
+ */
+const char *spl_board_loader_name(u32 boot_device);
+
+/**
* jump_to_image_linux() - Jump to a Linux kernel from SPL
*
* This jumps into a Linux kernel using the information in @spl_image.
void __noreturn jump_to_image_linux(struct spl_image_info *spl_image);
/**
+ * jump_to_image_linux() - Jump to OP-TEE OS from SPL
+ *
+ * This jumps into OP-TEE OS using the information in @spl_image.
+ *
+ * @spl_image: Image description to set up
+ */
+void __noreturn jump_to_image_optee(struct spl_image_info *spl_image);
+
+/**
* spl_start_uboot() - Check if SPL should start the kernel or U-Boot
*
* This is called by the various SPL loaders to determine whether the board
* wants to load the kernel or U-Boot. This function should be provided by
* the board.
*
- * @return 0 if SPL should start the kernel, 1 if U-Boot must be started
+ * Return: 0 if SPL should start the kernel, 1 if U-Boot must be started
*/
int spl_start_uboot(void);
struct spl_boot_device *bootdev);
};
+/* Helper function for accessing the name */
+static inline const char *spl_loader_name(const struct spl_image_loader *loader)
+{
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+ const char *name;
+ name = spl_board_loader_name(loader->boot_device);
+ return name ?: loader->name;
+#else
+ return NULL;
+#endif
+}
+
/* Declare an SPL image loader */
#define SPL_LOAD_IMAGE(__name) \
ll_entry_declare(struct spl_image_loader, __name, spl_image_loader)
/* SPL FAT image functions */
int spl_load_image_fat(struct spl_image_info *spl_image,
+ struct spl_boot_device *bootdev,
struct blk_desc *block_dev, int partition,
const char *filename);
int spl_load_image_fat_os(struct spl_image_info *spl_image,
+ struct spl_boot_device *bootdev,
struct blk_desc *block_dev, int partition);
void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image);
/* SPL EXT image functions */
int spl_load_image_ext(struct spl_image_info *spl_image,
+ struct spl_boot_device *bootdev,
struct blk_desc *block_dev, int partition,
const char *filename);
int spl_load_image_ext_os(struct spl_image_info *spl_image,
+ struct spl_boot_device *bootdev,
struct blk_desc *block_dev, int partition);
/**
* This will normally be true, but if U-Boot jumps to second U-Boot, it will
* be false. This should be implemented by board-specific code.
*
- * @return true if U-Boot booted from SPL, else false
+ * Return: true if U-Boot booted from SPL, else false
*/
bool spl_was_boot_source(void);
* @param usb_index - usb controller number
* @param mmc_dev - mmc device nubmer
*
- * @return 0 on success, otherwise error code
+ * Return: 0 on success, otherwise error code
*/
int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr);
* @param raw_part Partition to load from (in RAW mode)
* @param raw_sect Sector to load from (in RAW mode)
*
- * @return 0 on success, otherwise error code
+ * Return: 0 on success, otherwise error code
*/
int spl_mmc_load(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev,
* @param raw_part Fat partition to load from
* @param filename Name of file to load
*
- * @return 0 on success, otherwise error code
+ * Return: 0 on success, otherwise error code
*/
int spl_usb_load(struct spl_image_info *spl_image,
struct spl_boot_device *bootdev,
* @arg2: device tree address, (ARMv7 standard bootarg #2)
* @arg3: non-secure entry address (ARMv7 bootarg #0)
*/
-void spl_optee_entry(void *arg0, void *arg1, void *arg2, void *arg3);
+void __noreturn spl_optee_entry(void *arg0, void *arg1, void *arg2, void *arg3);
/**
* spl_invoke_opensbi - boot using a RISC-V OpenSBI image
/**
* board_spl_fit_post_load - allow process images after loading finished
- *
+ * @fit: Pointer to a valid Flattened Image Tree blob
*/
-void board_spl_fit_post_load(ulong load_addr, size_t length);
+void board_spl_fit_post_load(const void *fit);
/**
* board_spl_fit_size_align - specific size align before processing payload
* Returns memory area which can be populated by partial image data,
* ie. uImage or fitImage header.
*/
-struct image_header *spl_get_load_buffer(ssize_t offset, size_t size);
+struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size);
void spl_save_restore_data(void);
#endif