]> Git Repo - J-u-boot.git/blame - include/spl.h
Merge patch series "vbe: Series part E"
[J-u-boot.git] / include / spl.h
CommitLineData
83d290c5 1/* SPDX-License-Identifier: GPL-2.0+ */
47f7bcae
TR
2/*
3 * (C) Copyright 2012
4 * Texas Instruments, <www.ti.com>
47f7bcae
TR
5 */
6#ifndef _SPL_H_
7#define _SPL_H_
8
8bee2d25 9#include <binman_sym.h>
f7ae49fc 10#include <linker_lists.h>
8bee2d25 11
47f7bcae 12/* Platform-specific defines */
6507f133 13#include <linux/compiler.h>
271cf2f4 14#include <asm/global_data.h>
47f7bcae 15#include <asm/spl.h>
b0edea3c 16#include <handoff.h>
59073573 17#include <mmc.h>
47f7bcae 18
271cf2f4 19struct blk_desc;
f3543e69 20struct legacy_img_hdr;
271cf2f4 21
32ba8952
SG
22/* Value in r0 indicates we booted from U-Boot */
23#define UBOOT_NOT_LOADED_FROM_SPL 0x13578642
773b5940 24
47f7bcae
TR
25/* Boot type */
26#define MMCSD_MODE_UNDEFINED 0
27#define MMCSD_MODE_RAW 1
205b4f33 28#define MMCSD_MODE_FS 2
7dbe63bc 29#define MMCSD_MODE_EMMCBOOT 3
47f7bcae 30
e6f6f9e6 31struct blk_desc;
f3543e69 32struct legacy_img_hdr;
2e0429bc 33struct spl_boot_device;
99fddf5c 34enum boot_device;
c3dc39a2 35
e945a726 36/*
713bfc58 37 * xpl_is_first_phase() - check if this is the first U-Boot phase
e945a726 38 *
713bfc58
SG
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
e945a726
SG
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
713bfc58 43 * it is the first phase, etc.
e945a726 44 *
713bfc58
SG
45 * Note that VPL can never be the first phase. If it exists, it is loaded from
46 * TPL
e945a726 47 *
713bfc58 48 * Return: true if this is the first phase of U-Boot
e945a726 49 */
713bfc58 50static inline bool xpl_is_first_phase(void)
e945a726
SG
51{
52 if (IS_ENABLED(CONFIG_TPL)) {
53 if (IS_ENABLED(CONFIG_TPL_BUILD))
54 return true;
55 } else if (IS_ENABLED(CONFIG_SPL)) {
f38956a6 56 if (IS_ENABLED(CONFIG_XPL_BUILD))
e945a726
SG
57 return true;
58 } else {
59 return true;
60 }
61
62 return false;
63}
64
41ea75aa 65enum xpl_phase_t {
09d9ba90 66 PHASE_NONE, /* Invalid phase, signifying before U-Boot */
59c871bc 67 PHASE_TPL, /* Running in TPL */
f86ca5ad 68 PHASE_VPL, /* Running in VPL */
59c871bc
SG
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 */
7f3470bf
SG
72
73 PHASE_COUNT,
8e83b76d
SG
74};
75
76/**
456bdb70 77 * xpl_phase() - Find out the phase of U-Boot
8e83b76d
SG
78 *
79 * This can be used to avoid #ifdef logic and use if() instead.
80 *
81 * For example, to include code only in TPL, you might do:
82 *
83 * #ifdef CONFIG_TPL_BUILD
84 * ...
85 * #endif
86 *
87 * but with this you can use:
88 *
456bdb70 89 * if (xpl_phase() == PHASE_TPL) {
8e83b76d
SG
90 * ...
91 * }
92 *
93 * To include code only in SPL, you might do:
94 *
f38956a6 95 * #if defined(CONFIG_XPL_BUILD) && !defined(CONFIG_TPL_BUILD)
8e83b76d
SG
96 * ...
97 * #endif
98 *
99 * but with this you can use:
100 *
456bdb70 101 * if (xpl_phase() == PHASE_SPL) {
8e83b76d
SG
102 * ...
103 * }
104 *
105 * To include code only in U-Boot proper, you might do:
106 *
f38956a6 107 * #ifndef CONFIG_XPL_BUILD
8e83b76d
SG
108 * ...
109 * #endif
110 *
111 * but with this you can use:
112 *
456bdb70 113 * if (xpl_phase() == PHASE_BOARD_F) {
8e83b76d
SG
114 * ...
115 * }
116 *
185f812c 117 * Return: U-Boot phase
8e83b76d 118 */
456bdb70 119static inline enum xpl_phase_t xpl_phase(void)
8e83b76d
SG
120{
121#ifdef CONFIG_TPL_BUILD
122 return PHASE_TPL;
f86ca5ad
SG
123#elif defined(CONFIG_VPL_BUILD)
124 return PHASE_VPL;
f38956a6 125#elif defined(CONFIG_XPL_BUILD)
8e83b76d
SG
126 return PHASE_SPL;
127#else
59c871bc
SG
128 DECLARE_GLOBAL_DATA_PTR;
129
130 if (!(gd->flags & GD_FLG_RELOC))
131 return PHASE_BOARD_F;
132 else
133 return PHASE_BOARD_R;
8e83b76d
SG
134#endif
135}
136
f86580fc
SG
137/* returns true if in U-Boot proper, false if in xPL */
138static inline bool not_xpl(void)
9031ba82 139{
f38956a6 140#ifdef CONFIG_XPL_BUILD
9031ba82
SG
141 return false;
142#endif
143
144 return true;
145}
146
44a4c8e9
SG
147/* returns true if in xPL, false if in U-Boot proper */
148static inline bool is_xpl(void)
149{
150#ifdef CONFIG_XPL_BUILD
151 return true;
152#endif
153
154 return false;
155}
156
09d9ba90 157/**
6c49fc58 158 * xpl_prev_phase() - Figure out the previous U-Boot phase
09d9ba90 159 *
185f812c 160 * Return: the previous phase from this one, e.g. if called in SPL this returns
09d9ba90
SG
161 * PHASE_TPL, if TPL is enabled
162 */
6c49fc58 163static inline enum xpl_phase_t xpl_prev_phase(void)
09d9ba90
SG
164{
165#ifdef CONFIG_TPL_BUILD
166 return PHASE_NONE;
f86ca5ad
SG
167#elif defined(CONFIG_VPL_BUILD)
168 return PHASE_TPL; /* VPL requires TPL */
f38956a6 169#elif defined(CONFIG_XPL_BUILD)
f86ca5ad
SG
170 return IS_ENABLED(CONFIG_VPL) ? PHASE_VPL :
171 IS_ENABLED(CONFIG_TPL) ? PHASE_TPL :
172 PHASE_NONE;
09d9ba90 173#else
f86ca5ad
SG
174 return IS_ENABLED(CONFIG_SPL) ? PHASE_SPL :
175 PHASE_NONE;
09d9ba90
SG
176#endif
177}
178
179/**
6c49fc58 180 * xpl_next_phase() - Figure out the next U-Boot phase
09d9ba90 181 *
185f812c 182 * Return: the next phase from this one, e.g. if called in TPL this returns
09d9ba90
SG
183 * PHASE_SPL
184 */
6c49fc58 185static inline enum xpl_phase_t xpl_next_phase(void)
09d9ba90
SG
186{
187#ifdef CONFIG_TPL_BUILD
f86ca5ad
SG
188 return IS_ENABLED(CONFIG_VPL) ? PHASE_VPL : PHASE_SPL;
189#elif defined(CONFIG_VPL_BUILD)
09d9ba90
SG
190 return PHASE_SPL;
191#else
192 return PHASE_BOARD_F;
193#endif
194}
195
196/**
80580cd9 197 * xpl_name() - Get the name of a phase
09d9ba90 198 *
185f812c 199 * Return: phase name
09d9ba90 200 */
80580cd9 201static inline const char *xpl_name(enum xpl_phase_t phase)
09d9ba90
SG
202{
203 switch (phase) {
204 case PHASE_TPL:
205 return "TPL";
f86ca5ad
SG
206 case PHASE_VPL:
207 return "VPL";
09d9ba90
SG
208 case PHASE_SPL:
209 return "SPL";
210 case PHASE_BOARD_F:
211 case PHASE_BOARD_R:
212 return "U-Boot";
213 default:
214 return "phase?";
215 }
216}
217
f178bebf 218/**
80580cd9 219 * xpl_prefix() - Get the prefix of the current phase
f178bebf
SG
220 *
221 * @phase: Phase to look up
185f812c 222 * Return: phase prefix ("spl", "tpl", etc.)
f178bebf 223 */
80580cd9 224static inline const char *xpl_prefix(enum xpl_phase_t phase)
f178bebf
SG
225{
226 switch (phase) {
227 case PHASE_TPL:
228 return "tpl";
f86ca5ad
SG
229 case PHASE_VPL:
230 return "vpl";
f178bebf
SG
231 case PHASE_SPL:
232 return "spl";
233 case PHASE_BOARD_F:
234 case PHASE_BOARD_R:
235 return "";
236 default:
237 return "phase?";
238 }
239}
240
d6330064 241/* A string name for SPL or TPL */
f38956a6 242#ifdef CONFIG_XPL_BUILD
d6330064 243# ifdef CONFIG_TPL_BUILD
96ed5b0e 244# define PHASE_NAME "TPL"
f86ca5ad 245# elif defined(CONFIG_VPL_BUILD)
96ed5b0e
SG
246# define PHASE_NAME "VPL"
247# elif defined(CONFIG_SPL_BUILD)
248# define PHASE_NAME "SPL"
d6330064 249# endif
96ed5b0e 250# define PHASE_PROMPT PHASE_NAME ": "
d6330064 251#else
96ed5b0e
SG
252# define PHASE_NAME ""
253# define PHASE_PROMPT ""
d6330064
SG
254#endif
255
830690d2
SG
256/**
257 * enum spl_sandbox_flags - flags for sandbox's use of spl_image_info->flags
258 *
259 * @SPL_SANDBOXF_ARG_IS_FNAME: arg is the filename to jump to (default)
f1459c36
SG
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
830690d2
SG
262 */
263enum spl_sandbox_flags {
264 SPL_SANDBOXF_ARG_IS_FNAME = 0,
f1459c36 265 SPL_SANDBOXF_ARG_IS_BUF,
830690d2
SG
266};
267
47f7bcae
TR
268struct spl_image_info {
269 const char *name;
270 u8 os;
7a585b9d
SG
271 ulong load_addr;
272 ulong entry_point;
a9a8271e 273#if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
75014470
PT
274 void *fdt_addr;
275#endif
de5dd4c4 276 u32 boot_device;
5fce2875 277 u32 offset;
47f7bcae 278 u32 size;
022b4975 279 u32 flags;
5bf5250e 280 void *arg;
dae5c2dc
SG
281#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
282 ulong dcrc_data;
283 ulong dcrc_length;
284 ulong dcrc;
285#endif
47f7bcae
TR
286};
287
f817e08f
SG
288static inline void *spl_image_fdt_addr(struct spl_image_info *info)
289{
290#if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
291 return info->fdt_addr;
292#else
293 return 0;
294#endif
295}
296
3fd11278
SG
297struct spl_load_info;
298
299/**
300 * spl_load_reader() - Read from device
301 *
302 * @load: Information about the load state
303 * @offset: Offset to read from in bytes. This must be a multiple of
304 * @load->bl_len.
305 * @count: Number of bytes to read. This must be a multiple of
306 * @load->bl_len.
307 * @buf: Buffer to read into
308 * @return number of bytes read, 0 on error
309 */
310typedef ulong (*spl_load_reader)(struct spl_load_info *load, ulong sector,
311 ulong count, void *buf);
312
146a17ad 313/**
f1dcee59
SG
314 * Information required to load data from a device
315 *
3fd11278 316 * @read: Function to call to read from the device
f1dcee59
SG
317 * @priv: Private data for the device
318 * @bl_len: Block length for reading in bytes
f1dcee59
SG
319 */
320struct spl_load_info {
3fd11278 321 spl_load_reader read;
f1dcee59 322 void *priv;
5271e359 323#if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK)
0c6c83e6 324 int bl_len;
50a1ed43 325#endif
f1dcee59
SG
326};
327
5271e359
SA
328static inline int spl_get_bl_len(struct spl_load_info *info)
329{
50a1ed43 330#if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK)
5271e359 331 return info->bl_len;
5271e359 332#else
5271e359 333 return 1;
50a1ed43 334#endif
5271e359
SA
335}
336
337static inline void spl_set_bl_len(struct spl_load_info *info, int bl_len)
338{
50a1ed43
SG
339#if IS_ENABLED(CONFIG_SPL_LOAD_BLOCK)
340 info->bl_len = bl_len;
341#else
5271e359
SA
342 if (bl_len != 1)
343 panic("CONFIG_SPL_LOAD_BLOCK not enabled");
5271e359 344#endif
50a1ed43 345}
5271e359 346
3fd11278
SG
347/**
348 * spl_load_init() - Set up a new spl_load_info structure
349 */
350static inline void spl_load_init(struct spl_load_info *load,
351 spl_load_reader h_read, void *priv,
352 uint bl_len)
353{
354 load->read = h_read;
355 load->priv = priv;
356 spl_set_bl_len(load, bl_len);
357}
358
8bee2d25
SG
359/*
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
e82c624d 363 * image is found. For example if u-boot.img is used we don't check that
8bee2d25 364 * spl_parse_image_header() can parse a valid header.
e82c624d
SG
365 *
366 * Similarly for SPL, so that TPL can jump to SPL.
8bee2d25 367 */
dbf6be9f 368binman_sym_extern(ulong, u_boot_any, image_pos);
e82c624d 369binman_sym_extern(ulong, u_boot_any, size);
2b8d2ccd
SG
370binman_sym_extern(ulong, u_boot_spl_any, image_pos);
371binman_sym_extern(ulong, u_boot_spl_any, size);
372binman_sym_extern(ulong, u_boot_vpl_any, image_pos);
373binman_sym_extern(ulong, u_boot_vpl_any, size);
e82c624d
SG
374
375/**
376 * spl_get_image_pos() - get the image position of the next phase
377 *
378 * This returns the image position to use to load the next phase of U-Boot
379 */
380ulong spl_get_image_pos(void);
381
382/**
383 * spl_get_image_size() - get the size of the next phase
384 *
385 * This returns the size to use to load the next phase of U-Boot
386 */
387ulong spl_get_image_size(void);
8bee2d25 388
86c372af
SG
389/**
390 * spl_get_image_text_base() - get the text base of the next phase
391 *
392 * This returns the address that the next stage is linked to run at, i.e.
98463903 393 * CONFIG_SPL_TEXT_BASE or CONFIG_TEXT_BASE
86c372af 394 *
185f812c 395 * Return: text-base address
86c372af
SG
396 */
397ulong spl_get_image_text_base(void);
398
e1eb6ada
AD
399/**
400 * spl_load_simple_fit_skip_processing() - Hook to allow skipping the FIT
401 * image processing during spl_load_simple_fit().
402 *
403 * Return true to skip FIT processing, false to preserve the full code flow
404 * of spl_load_simple_fit().
405 */
406bool spl_load_simple_fit_skip_processing(void);
407
884ba50a
HS
408/**
409 * spl_load_simple_fit_fix_load() - Hook to make fixes
410 * after fit image header is loaded
411 *
412 * Returns pointer to fit
413 */
414void *spl_load_simple_fit_fix_load(const void *fit);
415
eafd5410
LV
416/**
417 * spl_load_simple_fit() - Loads a fit image from a device.
f4d7d859 418 * @spl_image: Image description to set up
eafd5410 419 * @info: Structure containing the information required to load data.
73c40fcb
SA
420 * @offset: Offset where FIT image is located in the device. Must be aligned
421 * to the device's bl_len.
eafd5410
LV
422 * @fdt: Pointer to the copied FIT header.
423 *
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.
427 */
f4d7d859 428int spl_load_simple_fit(struct spl_image_info *spl_image,
73c40fcb 429 struct spl_load_info *info, ulong offset, void *fdt);
f1dcee59 430
022b4975 431#define SPL_COPY_PAYLOAD_ONLY 1
e246bfcf 432#define SPL_FIT_FOUND 2
022b4975 433
efe92cd2
SA
434/**
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
439 *
440 * Load/decompress an LZMA-compressed legacy image from the device.
441 *
442 * Return: 0 on success, or a negative error on failure
443 */
444int spl_load_legacy_lzma(struct spl_image_info *spl_image,
445 struct spl_load_info *load, ulong offset);
446
2fc91ed3
SR
447/**
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.
06377c5a
RQ
451 * @offset: Pointer to image
452 * @hdr: Pointer to image header
2fc91ed3
SR
453 *
454 * Reads an legacy image from the device. Loads u-boot image to
455 * specified load address.
456 * Returns 0 on success.
457 */
458int spl_load_legacy_img(struct spl_image_info *spl_image,
2e0429bc 459 struct spl_boot_device *bootdev,
06377c5a
RQ
460 struct spl_load_info *load, ulong offset,
461 struct legacy_img_hdr *hdr);
462
dd7d0911
PF
463/**
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.
73c40fcb
SA
467 * @sector: Offset where container image is located in the device. Must be
468 * aligned to the device block size.
dd7d0911
PF
469 *
470 * Reads the container image @sector in the device. Loads u-boot image to
471 * specified load address.
472 */
473int spl_load_imx_container(struct spl_image_info *spl_image,
73c40fcb 474 struct spl_load_info *info, ulong offset);
dd7d0911 475
47f7bcae
TR
476/* SPL common functions */
477void preloader_console_init(void);
478u32 spl_boot_device(void);
e9759065 479
60d76e33
SA
480struct spi_flash;
481
482/**
483 * spl_spi_get_uboot_offs() - Lookup function for the SPI boot offset
484 * @flash: The spi flash to boot from
485 *
486 * Return: The offset of U-Boot within the SPI flash
487 */
488unsigned int spl_spi_get_uboot_offs(struct spi_flash *flash);
489
6dd18a65
VA
490/**
491 * spl_spi_boot_bus() - Lookup function for the SPI boot bus source.
492 *
493 * This function returns the SF bus to load from.
494 * If not overridden, it is weakly defined in common/spl/spl_spi.c.
495 */
496u32 spl_spi_boot_bus(void);
497
498/**
499 * spl_spi_boot_cs() - Lookup function for the SPI boot CS source.
500 *
501 * This function returns the SF CS to load from.
502 * If not overridden, it is weakly defined in common/spl/spl_spi.c.
503 */
504u32 spl_spi_boot_cs(void);
505
e9759065
HS
506/**
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.
511 *
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.
515 *
516 * If not overridden, it is weakly defined in common/spl/spl_mmc.c.
517 *
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.
520 */
59073573 521u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device);
c51b7518
HS
522
523/**
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
526 * U-Boot from.
527 *
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.
531 *
532 * If not overridden, it is weakly defined in common/spl/spl_mmc.c.
533 */
534int spl_mmc_boot_partition(const u32 boot_device);
9b191591
MV
535
536struct mmc;
537/**
538 * default_spl_mmc_emmc_boot_partition() - eMMC boot partition to load U-Boot from.
539 * mmc: Pointer for the mmc device structure
540 *
541 * This function should return the eMMC boot partition number which
542 * the SPL should load U-Boot from (on the given boot_device).
543 */
544int default_spl_mmc_emmc_boot_partition(struct mmc *mmc);
545
546/**
547 * spl_mmc_emmc_boot_partition() - eMMC boot partition to load U-Boot from.
548 * mmc: Pointer for the mmc device structure
549 *
550 * This function should return the eMMC boot partition number which
551 * the SPL should load U-Boot from (on the given boot_device).
552 *
553 * If not overridden, it is weakly defined in common/spl/spl_mmc.c
554 * and calls default_spl_mmc_emmc_boot_partition();
555 */
556int spl_mmc_emmc_boot_partition(struct mmc *mmc);
557
58b504e5 558void spl_set_bd(void);
d95ceb97 559
e936db95
MV
560/**
561 * spl_mmc_get_uboot_raw_sector() - Provide raw sector of the start of U-Boot (architecture override)
562 *
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.
565 *
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
569 */
570unsigned long arch_spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
571 unsigned long raw_sect);
572
573/**
574 * spl_mmc_get_uboot_raw_sector() - Provide raw sector of the start of U-Boot (board override)
575 *
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.
578 *
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
582 */
583unsigned long board_spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
584 unsigned long raw_sect);
585
16d82d7b
TR
586/**
587 * spl_mmc_get_uboot_raw_sector() - Provide raw sector of the start of U-Boot
588 *
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.
591 *
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
595 */
596unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
597 unsigned long raw_sect);
598
d95ceb97
SG
599/**
600 * spl_set_header_raw_uboot() - Set up a standard SPL image structure
601 *
602 * This sets up the given spl_image which the standard values obtained from
6ab77bb1 603 * config options: CONFIG_SYS_MONITOR_LEN, CONFIG_SYS_UBOOT_START,
98463903 604 * CONFIG_TEXT_BASE.
d95ceb97 605 *
71316c1d 606 * @spl_image: Image description to set up
d95ceb97
SG
607 */
608void spl_set_header_raw_uboot(struct spl_image_info *spl_image);
609
71316c1d
SG
610/**
611 * spl_parse_image_header() - parse the image header and set up info
612 *
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
24eb39b5 616 * enabled, then this causes a panic. If CONFIG_SPL_RAW_IMAGE_SUPPORT is not
71316c1d
SG
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.
619 *
620 * @spl_image: Image description to set up
621 * @header image header to parse
185f812c 622 * Return: 0 if a header was correctly parsed, -ve on error
71316c1d
SG
623 */
624int spl_parse_image_header(struct spl_image_info *spl_image,
2e0429bc 625 const struct spl_boot_device *bootdev,
f3543e69 626 const struct legacy_img_hdr *header);
71316c1d 627
47f7bcae 628void spl_board_prepare_for_linux(void);
a25d6b65
AG
629
630/**
631 * spl_board_prepare_for_optee() - Prepare board for an OPTEE payload
632 *
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.
639 *
640 * @fdt: Devicetree that will be passed on, or NULL
641 */
642void spl_board_prepare_for_optee(void *fdt);
3a3b9147 643void spl_board_prepare_for_boot(void);
bf55cd4f 644int spl_board_ubi_load_image(u32 boot_device);
99fddf5c 645int spl_board_boot_device(enum boot_device boot_dev_spl);
ca12e65c 646
c5922923
HT
647/**
648 * spl_board_loader_name() - Return a name for the loader
649 *
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.
653 *
654 * @boot_device: ID of the device which SPL wants to load U-Boot from.
655 */
656const char *spl_board_loader_name(u32 boot_device);
657
ca12e65c
SG
658/**
659 * jump_to_image_linux() - Jump to a Linux kernel from SPL
660 *
661 * This jumps into a Linux kernel using the information in @spl_image.
662 *
663 * @spl_image: Image description to set up
ca12e65c 664 */
5bf5250e 665void __noreturn jump_to_image_linux(struct spl_image_info *spl_image);
f59961e3 666
949eb228 667/**
ebeb8d95 668 * jump_to_image_optee() - Jump to OP-TEE OS from SPL
949eb228
RS
669 *
670 * This jumps into OP-TEE OS using the information in @spl_image.
671 *
672 * @spl_image: Image description to set up
673 */
674void __noreturn jump_to_image_optee(struct spl_image_info *spl_image);
675
f59961e3
SG
676/**
677 * spl_start_uboot() - Check if SPL should start the kernel or U-Boot
678 *
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
681 * the board.
682 *
185f812c 683 * Return: 0 if SPL should start the kernel, 1 if U-Boot must be started
f59961e3 684 */
47f7bcae 685int spl_start_uboot(void);
f59961e3 686
a807ab33
SG
687/**
688 * spl_display_print() - Display a board-specific message in SPL
689 *
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.
693 */
47f7bcae
TR
694void spl_display_print(void);
695
ecdfd69a
SG
696/**
697 * struct spl_boot_device - Describes a boot device used by SPL
698 *
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
701 * numbered.
702 * @boot_device_name: Named boot device, or NULL if none.
703 *
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.
708 */
709struct spl_boot_device {
710 uint boot_device;
711 const char *boot_device_name;
712};
713
a0a80290
SG
714/**
715 * Holds information about a way of loading an SPL image
716 *
ebc4ef61 717 * @name: User-friendly name for this method (e.g. "MMC")
a0a80290
SG
718 * @boot_device: Boot device that this loader supports
719 * @load_image: Function to call to load image
720 */
721struct spl_image_loader {
ebc4ef61
SG
722#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
723 const char *name;
724#endif
a0a80290
SG
725 uint boot_device;
726 /**
727 * load_image() - Load an SPL image
728 *
2a2ee2ac 729 * @spl_image: place to put image information
a0a80290
SG
730 * @bootdev: describes the boot device to load from
731 */
2a2ee2ac
SG
732 int (*load_image)(struct spl_image_info *spl_image,
733 struct spl_boot_device *bootdev);
a0a80290
SG
734};
735
7d84fbb5
SG
736/* Helper function for accessing the name */
737static inline const char *spl_loader_name(const struct spl_image_loader *loader)
738{
739#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
c5922923
HT
740 const char *name;
741 name = spl_board_loader_name(loader->boot_device);
742 return name ?: loader->name;
7d84fbb5
SG
743#else
744 return NULL;
745#endif
746}
747
a0a80290
SG
748/* Declare an SPL image loader */
749#define SPL_LOAD_IMAGE(__name) \
750 ll_entry_declare(struct spl_image_loader, __name, spl_image_loader)
751
752/*
0d3b0591 753 * _priority is the priority of this method, 0 meaning it will be the top
a0a80290 754 * choice for this device, 9 meaning it is the bottom choice.
0d3b0591
SG
755 * _boot_device is the BOOT_DEVICE_... value
756 * _method is the load_image function to call
a0a80290 757 */
ebc4ef61
SG
758#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
759#define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \
e1500a6c 760 SPL_LOAD_IMAGE(_boot_device ## _priority ## _method) = { \
ebc4ef61
SG
761 .name = _name, \
762 .boot_device = _boot_device, \
763 .load_image = _method, \
764 }
765#else
766#define SPL_LOAD_IMAGE_METHOD(_name, _priority, _boot_device, _method) \
e1500a6c 767 SPL_LOAD_IMAGE(_boot_device ## _priority ## _method) = { \
0d3b0591
SG
768 .boot_device = _boot_device, \
769 .load_image = _method, \
a0a80290 770 }
ebc4ef61 771#endif
a0a80290 772
6ba8ecaa
SA
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)
776
773b5940 777/* SPL FAT image functions */
93caa3ef
SA
778
779/**
780 * spl_fat_force_reregister() - Force reregistration of FAT block devices
781 *
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.
787 */
788void spl_fat_force_reregister(void);
789
710e9ca5 790int spl_load_image_fat(struct spl_image_info *spl_image,
2e0429bc 791 struct spl_boot_device *bootdev,
710e9ca5 792 struct blk_desc *block_dev, int partition,
4101f687 793 const char *filename);
710e9ca5 794int spl_load_image_fat_os(struct spl_image_info *spl_image,
2e0429bc 795 struct spl_boot_device *bootdev,
710e9ca5 796 struct blk_desc *block_dev, int partition);
773b5940 797
ce048224
JH
798void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image);
799
592f9222 800/* SPL EXT image functions */
b4a6c2aa 801int spl_load_image_ext(struct spl_image_info *spl_image,
2e0429bc 802 struct spl_boot_device *bootdev,
b4a6c2aa 803 struct blk_desc *block_dev, int partition,
4101f687 804 const char *filename);
b4a6c2aa 805int spl_load_image_ext_os(struct spl_image_info *spl_image,
2e0429bc 806 struct spl_boot_device *bootdev,
b4a6c2aa 807 struct blk_desc *block_dev, int partition);
8ce6a2e1
MC
808int 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);
592f9222 811
070d00b8 812/**
340f418a 813 * spl_early_init() - Set up device tree and driver model in SPL if enabled
070d00b8
SG
814 *
815 * Call this function in board_init_f() if you want to use device tree and
340f418a
EC
816 * driver model early, before board_init_r() is called.
817 *
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.
820 */
821int spl_early_init(void);
822
823/**
824 * spl_init() - Set up device tree and driver model in SPL if enabled
825 *
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.
828 *
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()
833 * is reached.
834 *
835 * This function will be called from board_init_r() if not called earlier.
070d00b8
SG
836 *
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.
839 */
840int spl_init(void);
841
52ef6a9c
LF
842/*
843 * spl_soc_init() - Do architecture-specific init in SPL
844 *
845 * If SPL_SOC_INIT is enabled, this is called from board_init_r() before
846 * jumping to the next phase.
847 */
848void spl_soc_init(void);
849
6371c479
SG
850/*
851 * spl_board_init() - Do board-specific init in SPL
852 *
853 * If xPL_BOARD_INIT is enabled, this is called from board_init_r() before
854 * jumping to the next phase.
855 */
47f7bcae 856void spl_board_init(void);
32ba8952
SG
857
858/**
859 * spl_was_boot_source() - check if U-Boot booted from SPL
860 *
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.
863 *
185f812c 864 * Return: true if U-Boot booted from SPL, else false
32ba8952
SG
865 */
866bool spl_was_boot_source(void);
867
52f2acc5
R
868/**
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
872 *
185f812c 873 * Return: 0 on success, otherwise error code
52f2acc5
R
874 */
875int spl_dfu_cmd(int usbctrl, char *dfu_alt_info, char *interface, char *devstr);
e50d76cc 876
93caa3ef
SA
877/**
878 * spl_mmc_clear_cache() - Clear cached MMC devices
879 *
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.
884 */
885void spl_mmc_clear_cache(void);
886
09410c65
MV
887int spl_mmc_load_image(struct spl_image_info *spl_image,
888 struct spl_boot_device *bootdev);
889
e1eb6ada
AD
890/**
891 * spl_mmc_load() - Load an image file from MMC/SD media
892 *
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)
898 *
185f812c 899 * Return: 0 on success, otherwise error code
e1eb6ada
AD
900 */
901int spl_mmc_load(struct spl_image_info *spl_image,
902 struct spl_boot_device *bootdev,
903 const char *filename,
904 int raw_part,
905 unsigned long raw_sect);
906
c3ab97c1
FA
907/**
908 * spl_usb_load() - Load an image file from USB mass storage
909 *
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
914 *
185f812c 915 * Return: 0 on success, otherwise error code
c3ab97c1
FA
916 */
917int spl_usb_load(struct spl_image_info *spl_image,
918 struct spl_boot_device *bootdev,
919 int partition, const char *filename);
920
e413033d
AD
921int spl_ymodem_load_image(struct spl_image_info *spl_image,
922 struct spl_boot_device *bootdev);
1d3c2667
DT
923/**
924 * spl_reserve_video_from_ram_top() - Reserve framebuffer memory from end of RAM
925 *
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.
929 *
930 * Return: 0 on success, otherwise error code
931 */
932int spl_reserve_video_from_ram_top(void);
e413033d 933
f2efe678
PT
934/**
935 * spl_invoke_atf - boot using an ARM trusted firmware image
936 */
a60d9686 937void __noreturn spl_invoke_atf(struct spl_image_info *spl_image);
225d30b7 938
5c03c990 939/**
d2cb0c8f
MW
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
5c03c990 944 *
d2cb0c8f
MW
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().
5c03c990 947 *
d2cb0c8f
MW
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.
951 *
952 * Return: bl31 params structure pointer
5c03c990 953 */
7a585b9d
SG
954struct bl31_params *bl2_plat_get_bl31_params(ulong bl32_entry,
955 ulong bl33_entry,
956 ulong fdt_addr);
5c03c990 957
d2cb0c8f
MW
958/**
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
963 *
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
969 *
970 * NOTE: The memory is statically allocated, thus this function should be
971 * called only once. All subsequent calls will overwrite any changes.
972 *
973 * Return: bl31 params structure pointer
974 */
7a585b9d
SG
975struct bl31_params *bl2_plat_get_bl31_params_default(ulong bl32_entry,
976 ulong bl33_entry,
977 ulong fdt_addr);
7b866825
MW
978
979/**
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
984 *
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.
988 *
989 * Return: bl31 params structure pointer
990 */
7a585b9d
SG
991struct bl_params *bl2_plat_get_bl31_params_v2(ulong bl32_entry,
992 ulong bl33_entry,
993 ulong fdt_addr);
7b866825
MW
994
995/**
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
1000 *
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).
1004 *
1005 * NOTE: The memory is statically allocated, thus this function should be
1006 * called only once. All subsequent calls will overwrite any changes.
1007 *
1008 * Return: bl31 params structure pointer
1009 */
7a585b9d
SG
1010struct bl_params *bl2_plat_get_bl31_params_v2_default(ulong bl32_entry,
1011 ulong bl33_entry,
1012 ulong fdt_addr);
70fe2876
KY
1013/**
1014 * spl_optee_entry - entry function for optee
1015 *
1016 * args defind in op-tee project
1017 * https://github.com/OP-TEE/optee_os/
1018 * core/arch/arm/kernel/generic_entry_a32.S
1019 * @arg0: pagestore
1020 * @arg1: (ARMv7 standard bootarg #1)
1021 * @arg2: device tree address, (ARMv7 standard bootarg #2)
1022 * @arg3: non-secure entry address (ARMv7 bootarg #0)
1023 */
949eb228 1024void __noreturn spl_optee_entry(void *arg0, void *arg1, void *arg2, void *arg3);
70fe2876 1025
5e30e45c
LA
1026/**
1027 * spl_invoke_opensbi - boot using a RISC-V OpenSBI image
1028 */
ef08687e 1029void __noreturn spl_invoke_opensbi(struct spl_image_info *spl_image);
5e30e45c 1030
225d30b7
PT
1031/**
1032 * board_return_to_bootrom - allow for boards to continue with the boot ROM
1033 *
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'.
1038 */
cda789a5
PF
1039int board_return_to_bootrom(struct spl_image_info *spl_image,
1040 struct spl_boot_device *bootdev);
de5dd4c4 1041
28ded1f3
PF
1042/**
1043 * board_spl_fit_size_align - specific size align before processing payload
1044 *
1045 */
1046ulong board_spl_fit_size_align(ulong size);
1047
de5dd4c4
PT
1048/**
1049 * spl_perform_fixups() - arch/board-specific callback before processing
1050 * the boot-payload
1051 */
1052void spl_perform_fixups(struct spl_image_info *spl_image);
04ce5427
MV
1053
1054/*
1055 * spl_get_load_buffer() - get buffer for loading partial image data
1056 *
1057 * Returns memory area which can be populated by partial image data,
1058 * ie. uImage or fitImage header.
1059 */
f3543e69 1060struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size);
04ce5427 1061
b13eaf3b
MV
1062/**
1063 * board_spl_fit_append_fdt_skip(): test whether DTO application should be skipped
1064 * @name: DTO node name within fitImage images node
1065 *
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.
1069 *
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.
1073 *
1074 * Return: 0 to indicate DTO is not skipped, all else to indicate DTO is skipped.
1075 */
1076int board_spl_fit_append_fdt_skip(const char *name);
1077
ebea05e1 1078void board_boot_order(u32 *spl_boot_list);
6aead233 1079void spl_save_restore_data(void);
035ab46e
SG
1080
1081/**
1082 * spl_load_fit_image() - Fully parse and a FIT image in SPL
1083 *
1084 * @spl_image: SPL Image data to fill in
1085 * @header: Pointer to FIT image
1086 * Return 0 if OK, -ve on error
1087 */
1088int spl_load_fit_image(struct spl_image_info *spl_image,
1089 const struct legacy_img_hdr *header);
1090
ce6ab564
MS
1091/*
1092 * spl_decompression_enabled() - check decompression support is enabled for SPL build
1093 *
1094 * Returns true if decompression support is enabled, else False
1095 */
1096static inline bool spl_decompression_enabled(void)
1097{
a1b7fd7f 1098 return IS_ENABLED(CONFIG_SPL_GZIP) || IS_ENABLED(CONFIG_SPL_LZMA);
ce6ab564 1099}
fefb5349
SG
1100
1101/**
1102 * spl_write_upl_handoff() - Write a Universal Payload hand-off structure
1103 *
1104 * @spl_image: Information about the image being booted
1105 * Return: 0 if OK, -ve on error
1106 */
1107int spl_write_upl_handoff(struct spl_image_info *spl_image);
1108
1109/**
1110 * spl_upl_init() - Get UPL ready for information to be added
1111 *
1112 * This must be called before upl_add_image(), etc.
1113 */
1114void spl_upl_init(void);
1115
47f7bcae 1116#endif
This page took 0.960013 seconds and 4 git commands to generate.