1 /* SPDX-License-Identifier: GPL-2.0+ */
4 * Texas Instruments, <www.ti.com>
9 #include <binman_sym.h>
10 #include <linker_lists.h>
12 /* Platform-specific defines */
13 #include <linux/compiler.h>
14 #include <asm/global_data.h>
20 struct legacy_img_hdr;
22 /* Value in r0 indicates we booted from U-Boot */
23 #define UBOOT_NOT_LOADED_FROM_SPL 0x13578642
26 #define MMCSD_MODE_UNDEFINED 0
27 #define MMCSD_MODE_RAW 1
28 #define MMCSD_MODE_FS 2
29 #define MMCSD_MODE_EMMCBOOT 3
32 struct legacy_img_hdr;
33 struct spl_boot_device;
37 * xpl_is_first_phase() - check if this is the first U-Boot phase
39 * U-Boot has up to four phases: TPL, VPL, SPL and U-Boot proper. Depending on
40 * the build flags we can determine whether the current build is for the first
41 * phase of U-Boot or not. If there is no SPL, then this is U-Boot proper. If
42 * there is SPL but no TPL, the the first phase is SPL. If there is TPL, then
43 * it is the first phase, etc.
45 * Note that VPL can never be the first phase. If it exists, it is loaded from
48 * Return: true if this is the first phase of U-Boot
50 static inline bool xpl_is_first_phase(void)
52 if (IS_ENABLED(CONFIG_TPL)) {
53 if (IS_ENABLED(CONFIG_TPL_BUILD))
55 } else if (IS_ENABLED(CONFIG_SPL)) {
56 if (IS_ENABLED(CONFIG_XPL_BUILD))
66 PHASE_NONE, /* Invalid phase, signifying before U-Boot */
67 PHASE_TPL, /* Running in TPL */
68 PHASE_VPL, /* Running in VPL */
69 PHASE_SPL, /* Running in SPL */
70 PHASE_BOARD_F, /* Running in U-Boot before relocation */
71 PHASE_BOARD_R, /* Running in U-Boot after relocation */
77 * xpl_phase() - Find out the phase of U-Boot
79 * This can be used to avoid #ifdef logic and use if() instead.
81 * For example, to include code only in TPL, you might do:
83 * #ifdef CONFIG_TPL_BUILD
87 * but with this you can use:
89 * if (xpl_phase() == PHASE_TPL) {
93 * To include code only in SPL, you might do:
95 * #if defined(CONFIG_XPL_BUILD) && !defined(CONFIG_TPL_BUILD)
99 * but with this you can use:
101 * if (xpl_phase() == PHASE_SPL) {
105 * To include code only in U-Boot proper, you might do:
107 * #ifndef CONFIG_XPL_BUILD
111 * but with this you can use:
113 * if (xpl_phase() == PHASE_BOARD_F) {
117 * Return: U-Boot phase
119 static inline enum xpl_phase_t xpl_phase(void)
121 #ifdef CONFIG_TPL_BUILD
123 #elif defined(CONFIG_VPL_BUILD)
125 #elif defined(CONFIG_XPL_BUILD)
128 DECLARE_GLOBAL_DATA_PTR;
130 if (!(gd->flags & GD_FLG_RELOC))
131 return PHASE_BOARD_F;
133 return PHASE_BOARD_R;
137 /* returns true if in U-Boot proper, false if in xPL */
138 static inline bool not_xpl(void)
140 #ifdef CONFIG_XPL_BUILD
147 /* returns true if in xPL, false if in U-Boot proper */
148 static inline bool is_xpl(void)
150 #ifdef CONFIG_XPL_BUILD
158 * xpl_prev_phase() - Figure out the previous U-Boot phase
160 * Return: the previous phase from this one, e.g. if called in SPL this returns
161 * PHASE_TPL, if TPL is enabled
163 static inline enum xpl_phase_t xpl_prev_phase(void)
165 #ifdef CONFIG_TPL_BUILD
167 #elif defined(CONFIG_VPL_BUILD)
168 return PHASE_TPL; /* VPL requires TPL */
169 #elif defined(CONFIG_XPL_BUILD)
170 return IS_ENABLED(CONFIG_VPL) ? PHASE_VPL :
171 IS_ENABLED(CONFIG_TPL) ? PHASE_TPL :
174 return IS_ENABLED(CONFIG_SPL) ? PHASE_SPL :
180 * xpl_next_phase() - Figure out the next U-Boot phase
182 * Return: the next phase from this one, e.g. if called in TPL this returns
185 static inline enum xpl_phase_t xpl_next_phase(void)
187 #ifdef CONFIG_TPL_BUILD
188 return IS_ENABLED(CONFIG_VPL) ? PHASE_VPL : PHASE_SPL;
189 #elif defined(CONFIG_VPL_BUILD)
192 return PHASE_BOARD_F;
197 * xpl_name() - Get the name of a phase
201 static inline const char *xpl_name(enum xpl_phase_t phase)
219 * xpl_prefix() - Get the prefix of the current phase
221 * @phase: Phase to look up
222 * Return: phase prefix ("spl", "tpl", etc.)
224 static inline const char *xpl_prefix(enum xpl_phase_t phase)
241 /* A string name for SPL or TPL */
242 #ifdef CONFIG_XPL_BUILD
243 # ifdef CONFIG_TPL_BUILD
244 # define PHASE_NAME "TPL"
245 # elif defined(CONFIG_VPL_BUILD)
246 # define PHASE_NAME "VPL"
247 # elif defined(CONFIG_SPL_BUILD)
248 # define PHASE_NAME "SPL"
250 # define PHASE_PROMPT PHASE_NAME ": "
252 # define PHASE_NAME ""
253 # define PHASE_PROMPT ""
257 * enum spl_sandbox_flags - flags for sandbox's use of spl_image_info->flags
259 * @SPL_SANDBOXF_ARG_IS_FNAME: arg is the filename to jump to (default)
260 * @SPL_SANDBOXF_ARG_IS_BUF: arg is the containing image to jump to, @offset is
261 * the start offset within the image, @size is the size of the image
263 enum spl_sandbox_flags {
264 SPL_SANDBOXF_ARG_IS_FNAME = 0,
265 SPL_SANDBOXF_ARG_IS_BUF,
268 struct spl_image_info {
272 uintptr_t entry_point;
273 #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
281 #ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
288 static inline void *spl_image_fdt_addr(struct spl_image_info *info)
290 #if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
291 return info->fdt_addr;
297 struct spl_load_info;
300 * spl_load_reader() - Read from device
302 * @load: Information about the load state
303 * @offset: Offset to read from in bytes. This must be a multiple of
305 * @count: Number of bytes to read. This must be a multiple of
307 * @buf: Buffer to read into
308 * @return number of bytes read, 0 on error
310 typedef ulong (*spl_load_reader)(struct spl_load_info *load, ulong sector,
311 ulong count, void *buf);
314 * Information required to load data from a device
316 * @read: Function to call to read from the device
317 * @priv: Private data for the device
318 * @bl_len: Block length for reading in bytes
320 struct spl_load_info {
321 spl_load_reader read;
323 #if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK)
328 static inline int spl_get_bl_len(struct spl_load_info *info)
330 #if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK)
337 static inline void spl_set_bl_len(struct spl_load_info *info, int bl_len)
339 #if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK)
340 info->bl_len = bl_len;
343 panic("CONFIG_SPL_LOAD_BLOCK not enabled");
348 * spl_load_init() - Set up a new spl_load_info structure
350 static inline void spl_load_init(struct spl_load_info *load,
351 spl_load_reader h_read, void *priv,
356 spl_set_bl_len(load, bl_len);
360 * We need to know the position of U-Boot in memory so we can jump to it. We
361 * allow any U-Boot binary to be used (u-boot.bin, u-boot-nodtb.bin,
362 * u-boot.img), hence the '_any'. These is no checking here that the correct
363 * image is found. For example if u-boot.img is used we don't check that
364 * spl_parse_image_header() can parse a valid header.
366 * Similarly for SPL, so that TPL can jump to SPL.
368 binman_sym_extern(ulong, u_boot_any, image_pos);
369 binman_sym_extern(ulong, u_boot_any, size);
370 binman_sym_extern(ulong, u_boot_spl_any, image_pos);
371 binman_sym_extern(ulong, u_boot_spl_any, size);
372 binman_sym_extern(ulong, u_boot_vpl_any, image_pos);
373 binman_sym_extern(ulong, u_boot_vpl_any, size);
376 * spl_get_image_pos() - get the image position of the next phase
378 * This returns the image position to use to load the next phase of U-Boot
380 ulong spl_get_image_pos(void);
383 * spl_get_image_size() - get the size of the next phase
385 * This returns the size to use to load the next phase of U-Boot
387 ulong spl_get_image_size(void);
390 * spl_get_image_text_base() - get the text base of the next phase
392 * This returns the address that the next stage is linked to run at, i.e.
393 * CONFIG_SPL_TEXT_BASE or CONFIG_TEXT_BASE
395 * Return: text-base address
397 ulong spl_get_image_text_base(void);
400 * spl_load_simple_fit_skip_processing() - Hook to allow skipping the FIT
401 * image processing during spl_load_simple_fit().
403 * Return true to skip FIT processing, false to preserve the full code flow
404 * of spl_load_simple_fit().
406 bool spl_load_simple_fit_skip_processing(void);
409 * spl_load_simple_fit_fix_load() - Hook to make fixes
410 * after fit image header is loaded
412 * Returns pointer to fit
414 void *spl_load_simple_fit_fix_load(const void *fit);
417 * spl_load_simple_fit() - Loads a fit image from a device.
418 * @spl_image: Image description to set up
419 * @info: Structure containing the information required to load data.
420 * @offset: Offset where FIT image is located in the device. Must be aligned
421 * to the device's bl_len.
422 * @fdt: Pointer to the copied FIT header.
424 * Reads the FIT image @sector in the device. Loads u-boot image to
425 * specified load address and copies the dtb to end of u-boot image.
426 * Returns 0 on success.
428 int spl_load_simple_fit(struct spl_image_info *spl_image,
429 struct spl_load_info *info, ulong offset, void *fdt);
431 #define SPL_COPY_PAYLOAD_ONLY 1
432 #define SPL_FIT_FOUND 2
435 * spl_load_legacy_lzma() - Load an LZMA-compressed legacy image
436 * @spl_image: Image description (already set up)
437 * @load: Structure containing the information required to load data.
438 * @offset: Pointer to image
440 * Load/decompress an LZMA-compressed legacy image from the device.
442 * Return: 0 on success, or a negative error on failure
444 int spl_load_legacy_lzma(struct spl_image_info *spl_image,
445 struct spl_load_info *load, ulong offset);
448 * spl_load_legacy_img() - Loads a legacy image from a device.
449 * @spl_image: Image description to set up
450 * @load: Structure containing the information required to load data.
451 * @offset: Pointer to image
452 * @hdr: Pointer to image header
454 * Reads an legacy image from the device. Loads u-boot image to
455 * specified load address.
456 * Returns 0 on success.
458 int spl_load_legacy_img(struct spl_image_info *spl_image,
459 struct spl_boot_device *bootdev,
460 struct spl_load_info *load, ulong offset,
461 struct legacy_img_hdr *hdr);
464 * spl_load_imx_container() - Loads a imx container image from a device.
465 * @spl_image: Image description to set up
466 * @info: Structure containing the information required to load data.
467 * @sector: Offset where container image is located in the device. Must be
468 * aligned to the device block size.
470 * Reads the container image @sector in the device. Loads u-boot image to
471 * specified load address.
473 int spl_load_imx_container(struct spl_image_info *spl_image,
474 struct spl_load_info *info, ulong offset);
476 /* SPL common functions */
477 void preloader_console_init(void);
478 u32 spl_boot_device(void);
483 * spl_spi_get_uboot_offs() - Lookup function for the SPI boot offset
484 * @flash: The spi flash to boot from
486 * Return: The offset of U-Boot within the SPI flash
488 unsigned int spl_spi_get_uboot_offs(struct spi_flash *flash);
491 * spl_spi_boot_bus() - Lookup function for the SPI boot bus source.
493 * This function returns the SF bus to load from.
494 * If not overridden, it is weakly defined in common/spl/spl_spi.c.
496 u32 spl_spi_boot_bus(void);
499 * spl_spi_boot_cs() - Lookup function for the SPI boot CS source.
501 * This function returns the SF CS to load from.
502 * If not overridden, it is weakly defined in common/spl/spl_spi.c.
504 u32 spl_spi_boot_cs(void);
507 * spl_mmc_boot_mode() - Lookup function for the mode of an MMC boot source.
508 * @boot_device: ID of the device which the MMC driver wants to read
509 * from. Common values are e.g. BOOT_DEVICE_MMC1,
510 * BOOT_DEVICE_MMC2, BOOT_DEVICE_MMC2_2.
512 * This function should return one of MMCSD_MODE_FS, MMCSD_MODE_EMMCBOOT, or
513 * MMCSD_MODE_RAW for each MMC boot source which is defined for the target. The
514 * boot_device parameter tells which device the MMC driver is interested in.
516 * If not overridden, it is weakly defined in common/spl/spl_mmc.c.
518 * Note: It is important to use the boot_device parameter instead of e.g.
519 * spl_boot_device() as U-Boot is not always loaded from the same device as SPL.
521 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device);
524 * spl_mmc_boot_partition() - MMC partition to load U-Boot from.
525 * @boot_device: ID of the device which the MMC driver wants to load
528 * This function should return the partition number which the SPL
529 * should load U-Boot from (on the given boot_device) when
530 * CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION is set.
532 * If not overridden, it is weakly defined in common/spl/spl_mmc.c.
534 int spl_mmc_boot_partition(const u32 boot_device);
538 * default_spl_mmc_emmc_boot_partition() - eMMC boot partition to load U-Boot from.
539 * mmc: Pointer for the mmc device structure
541 * This function should return the eMMC boot partition number which
542 * the SPL should load U-Boot from (on the given boot_device).
544 int default_spl_mmc_emmc_boot_partition(struct mmc *mmc);
547 * spl_mmc_emmc_boot_partition() - eMMC boot partition to load U-Boot from.
548 * mmc: Pointer for the mmc device structure
550 * This function should return the eMMC boot partition number which
551 * the SPL should load U-Boot from (on the given boot_device).
553 * If not overridden, it is weakly defined in common/spl/spl_mmc.c
554 * and calls default_spl_mmc_emmc_boot_partition();
556 int spl_mmc_emmc_boot_partition(struct mmc *mmc);
558 void spl_set_bd(void);
561 * spl_mmc_get_uboot_raw_sector() - Provide raw sector of the start of U-Boot (architecture override)
563 * This is a weak function which by default will provide the raw sector that is
564 * where the start of the U-Boot image has been written to.
566 * @mmc: struct mmc that describes the devie where U-Boot resides
567 * @raw_sect: The raw sector number where U-Boot is by default.
568 * Return: The raw sector location that U-Boot resides at
570 unsigned long arch_spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
571 unsigned long raw_sect);
574 * spl_mmc_get_uboot_raw_sector() - Provide raw sector of the start of U-Boot (board override)
576 * This is a weak function which by default will provide the raw sector that is
577 * where the start of the U-Boot image has been written to.
579 * @mmc: struct mmc that describes the devie where U-Boot resides
580 * @raw_sect: The raw sector number where U-Boot is by default.
581 * Return: The raw sector location that U-Boot resides at
583 unsigned long board_spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
584 unsigned long raw_sect);
587 * spl_mmc_get_uboot_raw_sector() - Provide raw sector of the start of U-Boot
589 * This is a weak function which by default will provide the raw sector that is
590 * where the start of the U-Boot image has been written to.
592 * @mmc: struct mmc that describes the devie where U-Boot resides
593 * @raw_sect: The raw sector number where U-Boot is by default.
594 * Return: The raw sector location that U-Boot resides at
596 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
597 unsigned long raw_sect);
600 * spl_set_header_raw_uboot() - Set up a standard SPL image structure
602 * This sets up the given spl_image which the standard values obtained from
603 * config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START,
606 * @spl_image: Image description to set up
608 void spl_set_header_raw_uboot(struct spl_image_info *spl_image);
611 * spl_parse_image_header() - parse the image header and set up info
613 * This parses the legacy image header information at @header and sets up
614 * @spl_image according to what is found. If no image header is found, then
615 * a raw image or bootz is assumed. If CONFIG_SPL_PANIC_ON_RAW_IMAGE is
616 * enabled, then this causes a panic. If CONFIG_SPL_RAW_IMAGE_SUPPORT is not
617 * enabled then U-Boot gives up. Otherwise U-Boot sets up the image using
618 * spl_set_header_raw_uboot(), or possibly the bootz header.
620 * @spl_image: Image description to set up
621 * @header image header to parse
622 * Return: 0 if a header was correctly parsed, -ve on error
624 int spl_parse_image_header(struct spl_image_info *spl_image,
625 const struct spl_boot_device *bootdev,
626 const struct legacy_img_hdr *header);
628 void spl_board_prepare_for_linux(void);
631 * spl_board_prepare_for_optee() - Prepare board for an OPTEE payload
633 * Prepares the board for booting an OP-TEE payload. Initialization is platform
634 * specific, and may include configuring the TrustZone memory, and other
635 * initialization steps required by OP-TEE.
636 * Note that @fdt is not used directly by OP-TEE. OP-TEE passes this @fdt to
637 * its normal world target. This target is not guaranteed to be u-boot, so @fdt
638 * changes that would normally be done by u-boot should be done in this step.
640 * @fdt: Devicetree that will be passed on, or NULL
642 void spl_board_prepare_for_optee(void *fdt);
643 void spl_board_prepare_for_boot(void);
644 int spl_board_ubi_load_image(u32 boot_device);
645 int spl_board_boot_device(enum boot_device boot_dev_spl);
648 * spl_board_loader_name() - Return a name for the loader
650 * This is a weak function which might be overridden by the board code. With
651 * that a board specific value for the device where the U-Boot will be loaded
652 * from can be set. By default it returns NULL.
654 * @boot_device: ID of the device which SPL wants to load U-Boot from.
656 const char *spl_board_loader_name(u32 boot_device);
659 * jump_to_image_linux() - Jump to a Linux kernel from SPL
661 * This jumps into a Linux kernel using the information in @spl_image.
663 * @spl_image: Image description to set up
665 void __noreturn jump_to_image_linux(struct spl_image_info *spl_image);
668 * jump_to_image_optee() - Jump to OP-TEE OS from SPL
670 * This jumps into OP-TEE OS using the information in @spl_image.
672 * @spl_image: Image description to set up
674 void __noreturn jump_to_image_optee(struct spl_image_info *spl_image);
677 * spl_start_uboot() - Check if SPL should start the kernel or U-Boot
679 * This is called by the various SPL loaders to determine whether the board
680 * wants to load the kernel or U-Boot. This function should be provided by
683 * Return: 0 if SPL should start the kernel, 1 if U-Boot must be started
685 int spl_start_uboot(void);
688 * spl_display_print() - Display a board-specific message in SPL
690 * If CONFIG_SPL_DISPLAY_PRINT is enabled, U-Boot will call this function
691 * immediately after displaying the SPL console banner ("U-Boot SPL ...").
692 * This function should be provided by the board.
694 void spl_display_print(void);
697 * struct spl_boot_device - Describes a boot device used by SPL
699 * @boot_device: A number indicating the BOOT_DEVICE type. There are various
700 * BOOT_DEVICE... #defines and enums in U-Boot and they are not consistently
702 * @boot_device_name: Named boot device, or NULL if none.
704 * Note: Additional fields can be added here, bearing in mind that SPL is
705 * size-sensitive and common fields will be present on all boards. This
706 * struct can also be used to return additional information about the load
707 * process if that becomes useful.
709 struct spl_boot_device {
711 const char *boot_device_name;
715 * Holds information about a way of loading an SPL image
717 * @name: User-friendly name for this method (e.g. "MMC")
718 * @boot_device: Boot device that this loader supports
719 * @load_image: Function to call to load image
721 struct spl_image_loader {
722 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
727 * load_image() - Load an SPL image
729 * @spl_image: place to put image information
730 * @bootdev: describes the boot device to load from
732 int (*load_image)(struct spl_image_info *spl_image,
733 struct spl_boot_device *bootdev);
736 /* Helper function for accessing the name */
737 static inline const char *spl_loader_name(const struct spl_image_loader *loader)
739 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
741 name = spl_board_loader_name(loader->boot_device);
742 return name ?: loader->name;
748 /* Declare an SPL image loader */
749 #define SPL_LOAD_IMAGE(__name) \
750 ll_entry_declare(struct spl_image_loader, __name, spl_image_loader)
753 * _priority is the priority of this method, 0 meaning it will be the top
754 * choice for this device, 9 meaning it is the bottom choice.
755 * _boot_device is the BOOT_DEVICE_... value
756 * _method is the load_image function to call
758 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
759 #define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \
760 SPL_LOAD_IMAGE(_boot_device ## _priority ## _method) = { \
762 .boot_device = _boot_device, \
763 .load_image = _method, \
766 #define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \
767 SPL_LOAD_IMAGE(_boot_device ## _priority ## _method) = { \
768 .boot_device = _boot_device, \
769 .load_image = _method, \
773 #define SPL_LOAD_IMAGE_GET(_priority, _boot_device, _method) \
774 ll_entry_get(struct spl_image_loader, \
775 _boot_device ## _priority ## _method, spl_image_loader)
777 /* SPL FAT image functions */
780 * spl_fat_force_reregister() - Force reregistration of FAT block devices
782 * To avoid repeatedly looking up block devices, spl_load_image_fat keeps track
783 * of whether it has already registered a block device. This is fine for most
784 * cases, but when running unit tests all devices are removed and recreated
785 * in-between tests. This function will force re-registration of any block
786 * devices, ensuring that we don't try to use an invalid block device.
788 void spl_fat_force_reregister(void);
790 int spl_load_image_fat(struct spl_image_info *spl_image,
791 struct spl_boot_device *bootdev,
792 struct blk_desc *block_dev, int partition,
793 const char *filename);
794 int spl_load_image_fat_os(struct spl_image_info *spl_image,
795 struct spl_boot_device *bootdev,
796 struct blk_desc *block_dev, int partition);
798 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image);
800 /* SPL EXT image functions */
801 int spl_load_image_ext(struct spl_image_info *spl_image,
802 struct spl_boot_device *bootdev,
803 struct blk_desc *block_dev, int partition,
804 const char *filename);
805 int spl_load_image_ext_os(struct spl_image_info *spl_image,
806 struct spl_boot_device *bootdev,
807 struct blk_desc *block_dev, int partition);
808 int spl_blk_load_image(struct spl_image_info *spl_image,
809 struct spl_boot_device *bootdev,
810 enum uclass_id uclass_id, int devnum, int partnum);
813 * spl_early_init() - Set up device tree and driver model in SPL if enabled
815 * Call this function in board_init_f() if you want to use device tree and
816 * driver model early, before board_init_r() is called.
818 * If this is not called, then driver model will be inactive in SPL's
819 * board_init_f(), and no device tree will be available.
821 int spl_early_init(void);
824 * spl_init() - Set up device tree and driver model in SPL if enabled
826 * You can optionally call spl_early_init(), then optionally call spl_init().
827 * This function will be called from board_init_r() if not called earlier.
829 * Both spl_early_init() and spl_init() perform a similar function except that
830 * the latter will not set up the malloc() area if
831 * CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN is enabled, since it is assumed to
832 * already be done by a calll to spl_relocate_stack_gd() before board_init_r()
835 * This function will be called from board_init_r() if not called earlier.
837 * If this is not called, then driver model will be inactive in SPL's
838 * board_init_f(), and no device tree will be available.
843 * spl_soc_init() - Do architecture-specific init in SPL
845 * If SPL_SOC_INIT is enabled, this is called from board_init_r() before
846 * jumping to the next phase.
848 void spl_soc_init(void);
851 * spl_board_init() - Do board-specific init in SPL
853 * If xPL_BOARD_INIT is enabled, this is called from board_init_r() before
854 * jumping to the next phase.
856 void spl_board_init(void);
859 * spl_was_boot_source() - check if U-Boot booted from SPL
861 * This will normally be true, but if U-Boot jumps to second U-Boot, it will
862 * be false. This should be implemented by board-specific code.
864 * Return: true if U-Boot booted from SPL, else false
866 bool spl_was_boot_source(void);
869 * spl_dfu_cmd- run dfu command with chosen mmc device interface
870 * @param usb_index - usb controller number
871 * @param mmc_dev - mmc device nubmer
873 * Return: 0 on success, otherwise error code
875 int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr);
878 * spl_mmc_clear_cache() - Clear cached MMC devices
880 * To avoid reinitializing MMCs, spl_mmc_load caches the most-recently-used MMC
881 * device. This is fine for most cases, but when running unit tests all devices
882 * are removed and recreated in-between tests. This function will clear any
883 * cached state, ensuring that we don't try to use an invalid MMC.
885 void spl_mmc_clear_cache(void);
887 int spl_mmc_load_image(struct spl_image_info *spl_image,
888 struct spl_boot_device *bootdev);
891 * spl_mmc_load() - Load an image file from MMC/SD media
893 * @param spl_image Image data filled in by loading process
894 * @param bootdev Describes which device to load from
895 * @param filename Name of file to load (in FS mode)
896 * @param raw_part Partition to load from (in RAW mode)
897 * @param raw_sect Sector to load from (in RAW mode)
899 * Return: 0 on success, otherwise error code
901 int spl_mmc_load(struct spl_image_info *spl_image,
902 struct spl_boot_device *bootdev,
903 const char *filename,
905 unsigned long raw_sect);
908 * spl_usb_load() - Load an image file from USB mass storage
910 * @param spl_image Image data filled in by loading process
911 * @param bootdev Describes which device to load from
912 * @param raw_part Fat partition to load from
913 * @param filename Name of file to load
915 * Return: 0 on success, otherwise error code
917 int spl_usb_load(struct spl_image_info *spl_image,
918 struct spl_boot_device *bootdev,
919 int partition, const char *filename);
921 int spl_ymodem_load_image(struct spl_image_info *spl_image,
922 struct spl_boot_device *bootdev);
924 * spl_reserve_video_from_ram_top() - Reserve framebuffer memory from end of RAM
926 * This enforces framebuffer reservation at SPL stage from end of RAM so that
927 * next stage can directly skip this pre-reserved area before carrying out
928 * further reservations. The allocation address is stored in struct video_uc_plat.
930 * Return: 0 on success, otherwise error code
932 int spl_reserve_video_from_ram_top(void);
935 * spl_invoke_atf - boot using an ARM trusted firmware image
937 void __noreturn spl_invoke_atf(struct spl_image_info *spl_image);
940 * bl2_plat_get_bl31_params() - return params for bl31.
941 * @bl32_entry: address of BL32 executable (secure)
942 * @bl33_entry: address of BL33 executable (non secure)
943 * @fdt_addr: address of Flat Device Tree
945 * This is a weak function which might be overridden by the board code. By
946 * default it will just call bl2_plat_get_bl31_params_default().
948 * If you just want to manipulate or add some parameters, you can override
949 * this function, call bl2_plat_get_bl31_params_default and operate on the
950 * returned bl31 params.
952 * Return: bl31 params structure pointer
954 struct bl31_params *bl2_plat_get_bl31_params(uintptr_t bl32_entry,
955 uintptr_t bl33_entry,
959 * bl2_plat_get_bl31_params_default() - prepare params for bl31.
960 * @bl32_entry: address of BL32 executable (secure)
961 * @bl33_entry: address of BL33 executable (non secure)
962 * @fdt_addr: address of Flat Device Tree
964 * This is the default implementation of bl2_plat_get_bl31_params(). It assigns
965 * a pointer to the memory that the platform has kept aside to pass platform
966 * specific and trusted firmware related information to BL31. This memory is
967 * allocated by allocating memory to bl2_to_bl31_params_mem structure which is
968 * a superset of all the structure whose information is passed to BL31
970 * NOTE: The memory is statically allocated, thus this function should be
971 * called only once. All subsequent calls will overwrite any changes.
973 * Return: bl31 params structure pointer
975 struct bl31_params *bl2_plat_get_bl31_params_default(uintptr_t bl32_entry,
976 uintptr_t bl33_entry,
980 * bl2_plat_get_bl31_params_v2() - return params for bl31
981 * @bl32_entry: address of BL32 executable (secure)
982 * @bl33_entry: address of BL33 executable (non secure)
983 * @fdt_addr: address of Flat Device Tree
985 * This function does the same as bl2_plat_get_bl31_params() except that is is
986 * used for the new LOAD_IMAGE_V2 option, which uses a slightly different
987 * method to pass the parameters.
989 * Return: bl31 params structure pointer
991 struct bl_params *bl2_plat_get_bl31_params_v2(uintptr_t bl32_entry,
992 uintptr_t bl33_entry,
996 * bl2_plat_get_bl31_params_v2_default() - prepare params for bl31.
997 * @bl32_entry: address of BL32 executable (secure)
998 * @bl33_entry: address of BL33 executable (non secure)
999 * @fdt_addr: address of Flat Device Tree
1001 * This is the default implementation of bl2_plat_get_bl31_params_v2(). It
1002 * prepares the linked list of the bl31 params, populates the image types and
1003 * set the entry points for bl32 and bl33 (if available).
1005 * NOTE: The memory is statically allocated, thus this function should be
1006 * called only once. All subsequent calls will overwrite any changes.
1008 * Return: bl31 params structure pointer
1010 struct bl_params *bl2_plat_get_bl31_params_v2_default(uintptr_t bl32_entry,
1011 uintptr_t bl33_entry,
1012 uintptr_t fdt_addr);
1014 * spl_optee_entry - entry function for optee
1016 * args defind in op-tee project
1017 * https://github.com/OP-TEE/optee_os/
1018 * core/arch/arm/kernel/generic_entry_a32.S
1020 * @arg1: (ARMv7 standard bootarg #1)
1021 * @arg2: device tree address, (ARMv7 standard bootarg #2)
1022 * @arg3: non-secure entry address (ARMv7 bootarg #0)
1024 void __noreturn spl_optee_entry(void *arg0, void *arg1, void *arg2, void *arg3);
1027 * spl_invoke_opensbi - boot using a RISC-V OpenSBI image
1029 void __noreturn spl_invoke_opensbi(struct spl_image_info *spl_image);
1032 * board_return_to_bootrom - allow for boards to continue with the boot ROM
1034 * If a board (e.g. the Rockchip RK3368 boards) provide some
1035 * supporting functionality for SPL in their boot ROM and the SPL
1036 * stage wants to return to the ROM code to continue booting, boards
1037 * can implement 'board_return_to_bootrom'.
1039 int board_return_to_bootrom(struct spl_image_info *spl_image,
1040 struct spl_boot_device *bootdev);
1043 * board_spl_fit_size_align - specific size align before processing payload
1046 ulong board_spl_fit_size_align(ulong size);
1049 * spl_perform_fixups() - arch/board-specific callback before processing
1052 void spl_perform_fixups(struct spl_image_info *spl_image);
1055 * spl_get_load_buffer() - get buffer for loading partial image data
1057 * Returns memory area which can be populated by partial image data,
1058 * ie. uImage or fitImage header.
1060 struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size);
1063 * board_spl_fit_append_fdt_skip(): test whether DTO application should be skipped
1064 * @name: DTO node name within fitImage images node
1066 * A board-specific function used to indicate whether a DTO from fitImage
1067 * configuration node 'fdt' property DT and DTO list should be applied onto
1068 * the base DT or not applied.
1070 * This is useful in case of DTOs which implement e.g. different board revision
1071 * details, where such DTO should be applied on one board revision, and should
1072 * not be applied on another board revision.
1074 * Return: 0 to indicate DTO is not skipped, all else to indicate DTO is skipped.
1076 int board_spl_fit_append_fdt_skip(const char *name);
1078 void board_boot_order(u32 *spl_boot_list);
1079 void spl_save_restore_data(void);
1082 * spl_load_fit_image() - Fully parse and a FIT image in SPL
1084 * @spl_image: SPL Image data to fill in
1085 * @header: Pointer to FIT image
1086 * Return 0 if OK, -ve on error
1088 int spl_load_fit_image(struct spl_image_info *spl_image,
1089 const struct legacy_img_hdr *header);
1092 * spl_decompression_enabled() - check decompression support is enabled for SPL build
1094 * Returns true if decompression support is enabled, else False
1096 static inline bool spl_decompression_enabled(void)
1098 return IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA);
1102 * spl_write_upl_handoff() - Write a Universal Payload hand-off structure
1104 * @spl_image: Information about the image being booted
1105 * Return: 0 if OK, -ve on error
1107 int spl_write_upl_handoff(struct spl_image_info *spl_image);
1110 * spl_upl_init() - Get UPL ready for information to be added
1112 * This must be called before upl_add_image(), etc.
1114 void spl_upl_init(void);