1 // SPDX-License-Identifier: GPL-2.0+
4 * Texas Instruments, <www.ti.com>
6 * Aneesh V <aneesh@ti.com>
11 #include <binman_sym.h>
12 #include <bootstage.h>
22 #include <system-constants.h>
23 #include <asm/global_data.h>
24 #include <asm-generic/gpio.h>
25 #include <asm/u-boot.h>
28 #include <u-boot/crc.h>
29 #if CONFIG_IS_ENABLED(BANNER_PRINT)
30 #include <timestamp.h>
38 #include <dm/device-internal.h>
39 #include <dm/uclass-internal.h>
40 #include <linux/compiler.h>
41 #include <fdt_support.h>
42 #include <bootcount.h>
45 DECLARE_GLOBAL_DATA_PTR;
46 DECLARE_BINMAN_MAGIC_SYM;
48 u32 *boot_params_ptr = NULL;
50 #if CONFIG_IS_ENABLED(BINMAN_UBOOT_SYMBOLS)
51 /* See spl.h for information about this */
52 binman_sym_declare(ulong, u_boot_any, image_pos);
53 binman_sym_declare(ulong, u_boot_any, size);
56 binman_sym_declare(ulong, u_boot_spl_any, image_pos);
57 binman_sym_declare(ulong, u_boot_spl_any, size);
61 binman_sym_declare(ulong, u_boot_vpl_any, image_pos);
62 binman_sym_declare(ulong, u_boot_vpl_any, size);
65 #endif /* BINMAN_UBOOT_SYMBOLS */
67 /* Define board data structure */
68 static struct bd_info bdata __attribute__ ((section(".data")));
70 #if CONFIG_IS_ENABLED(SHOW_BOOT_PROGRESS)
72 * Board-specific Platform code can reimplement show_boot_progress () if needed
74 __weak void show_boot_progress(int val) {}
77 #if defined(CONFIG_SPL_OS_BOOT) || CONFIG_IS_ENABLED(HANDOFF) || \
78 defined(CONFIG_SPL_ATF)
79 /* weak, default platform-specific function to initialize dram banks */
80 __weak int dram_init_banksize(void)
87 * Default function to determine if u-boot or the OS should
88 * be started. This implementation always returns 1.
90 * Please implement your own board specific funcion to do this.
93 * 0 to not start u-boot
94 * positive if u-boot should start
96 #if CONFIG_IS_ENABLED(OS_BOOT)
97 __weak int spl_start_uboot(void)
100 "Please implement spl_start_uboot() for your board\n");
101 puts(SPL_TPL_PROMPT "Direct Linux boot not active!\n");
106 * Weak default function for arch specific zImage check. Return zero
107 * and fill start and end address if image is recognized.
109 int __weak bootz_setup(ulong image, ulong *start, ulong *end)
114 int __weak booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool force_reloc)
120 /* Weak default function for arch/board-specific fixups to the spl_image_info */
121 void __weak spl_perform_fixups(struct spl_image_info *spl_image)
125 void spl_fixup_fdt(void *fdt_blob)
127 #if defined(CONFIG_SPL_OF_LIBFDT)
133 err = fdt_check_header(fdt_blob);
135 printf("fdt_root: %s\n", fdt_strerror(err));
139 /* fixup the memory dt node */
140 err = fdt_shrink_to_minimum(fdt_blob, 0);
142 printf(SPL_TPL_PROMPT "fdt_shrink_to_minimum err - %d\n", err);
146 err = arch_fixup_fdt(fdt_blob);
148 printf(SPL_TPL_PROMPT "arch_fixup_fdt err - %d\n", err);
154 ulong spl_get_image_pos(void)
156 if (!CONFIG_IS_ENABLED(BINMAN_UBOOT_SYMBOLS))
157 return BINMAN_SYM_MISSING;
160 if (spl_next_phase() == PHASE_VPL)
161 return binman_sym(ulong, u_boot_vpl_any, image_pos);
163 return spl_next_phase() == PHASE_SPL ?
164 binman_sym(ulong, u_boot_spl_any, image_pos) :
165 binman_sym(ulong, u_boot_any, image_pos);
168 ulong spl_get_image_size(void)
170 if (!CONFIG_IS_ENABLED(BINMAN_UBOOT_SYMBOLS))
171 return BINMAN_SYM_MISSING;
174 if (spl_next_phase() == PHASE_VPL)
175 return binman_sym(ulong, u_boot_vpl_any, size);
177 return spl_next_phase() == PHASE_SPL ?
178 binman_sym(ulong, u_boot_spl_any, size) :
179 binman_sym(ulong, u_boot_any, size);
182 ulong spl_get_image_text_base(void)
185 if (spl_next_phase() == PHASE_VPL)
186 return CONFIG_VPL_TEXT_BASE;
188 return spl_next_phase() == PHASE_SPL ? CONFIG_SPL_TEXT_BASE :
193 * Weak default function for board specific cleanup/preparation before
194 * Linux boot. Some boards/platforms might not need it, so just provide
195 * an empty stub here.
197 __weak void spl_board_prepare_for_linux(void)
202 __weak void spl_board_prepare_for_optee(void *fdt)
206 __weak const char *spl_board_loader_name(u32 boot_device)
211 #if CONFIG_IS_ENABLED(OPTEE_IMAGE)
212 __weak void __noreturn jump_to_image_optee(struct spl_image_info *spl_image)
214 spl_optee_entry(NULL, NULL, spl_image->fdt_addr,
215 (void *)spl_image->entry_point);
219 __weak void spl_board_prepare_for_boot(void)
224 __weak struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size)
226 return map_sysmem(CONFIG_TEXT_BASE + offset, 0);
229 #ifdef CONFIG_SPL_RAW_IMAGE_SUPPORT
230 void spl_set_header_raw_uboot(struct spl_image_info *spl_image)
232 ulong u_boot_pos = spl_get_image_pos();
234 #if CONFIG_SYS_MONITOR_LEN != 0
235 spl_image->size = CONFIG_SYS_MONITOR_LEN;
237 /* Unknown U-Boot size, let's assume it will not be more than 200 KB */
238 spl_image->size = 200 * 1024;
242 * Binman error cases: address of the end of the previous region or the
243 * start of the image's entry area (usually 0) if there is no previous
246 if (u_boot_pos && u_boot_pos != BINMAN_SYM_MISSING) {
247 /* Binman does not support separated entry addresses */
248 spl_image->entry_point = u_boot_pos;
249 spl_image->load_addr = u_boot_pos;
251 spl_image->entry_point = CONFIG_SYS_UBOOT_START;
252 spl_image->load_addr = CONFIG_TEXT_BASE;
254 spl_image->os = IH_OS_U_BOOT;
255 spl_image->name = "U-Boot";
259 #if CONFIG_IS_ENABLED(LOAD_FIT_FULL)
260 /* Parse and load full fitImage in SPL */
261 static int spl_load_fit_image(struct spl_image_info *spl_image,
262 const struct legacy_img_hdr *header)
264 struct bootm_headers images;
265 const char *fit_uname_config = NULL;
268 ulong fw_data = 0, dt_data = 0, img_data = 0;
269 ulong fw_len = 0, dt_len = 0, img_len = 0;
270 int idx, conf_noffset;
273 #ifdef CONFIG_SPL_FIT_SIGNATURE
276 ret = fit_image_load(&images, (ulong)header,
277 NULL, &fit_uname_config,
278 IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1,
279 FIT_LOAD_OPTIONAL, &fw_data, &fw_len);
281 printf("DEPRECATED: 'standalone = ' property.");
282 printf("Please use either 'firmware =' or 'kernel ='\n");
284 ret = fit_image_load(&images, (ulong)header, NULL,
285 &fit_uname_config, IH_ARCH_DEFAULT,
286 IH_TYPE_FIRMWARE, -1, FIT_LOAD_OPTIONAL,
291 ret = fit_image_load(&images, (ulong)header, NULL,
292 &fit_uname_config, IH_ARCH_DEFAULT,
293 IH_TYPE_KERNEL, -1, FIT_LOAD_OPTIONAL,
300 spl_image->size = fw_len;
301 spl_image->entry_point = fw_data;
302 spl_image->load_addr = fw_data;
303 if (fit_image_get_os(header, ret, &spl_image->os))
304 spl_image->os = IH_OS_INVALID;
305 spl_image->name = genimg_get_os_name(spl_image->os);
307 debug(SPL_TPL_PROMPT "payload image: %32s load addr: 0x%lx size: %d\n",
308 spl_image->name, spl_image->load_addr, spl_image->size);
310 #ifdef CONFIG_SPL_FIT_SIGNATURE
313 ret = fit_image_load(&images, (ulong)header, NULL, &fit_uname_config,
314 IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1,
315 FIT_LOAD_OPTIONAL, &dt_data, &dt_len);
317 spl_image->fdt_addr = (void *)dt_data;
319 if (spl_image->os == IH_OS_U_BOOT) {
320 /* HACK: U-Boot expects FDT at a specific address */
321 fdt_hack = spl_image->load_addr + spl_image->size;
322 fdt_hack = (fdt_hack + 3) & ~3;
323 debug("Relocating FDT to %p\n", spl_image->fdt_addr);
324 memcpy((void *)fdt_hack, spl_image->fdt_addr, dt_len);
328 conf_noffset = fit_conf_get_node((const void *)header,
330 if (conf_noffset < 0)
334 uname = fdt_stringlist_get((const void *)header, conf_noffset,
335 FIT_LOADABLE_PROP, idx,
339 #ifdef CONFIG_SPL_FIT_SIGNATURE
342 ret = fit_image_load(&images, (ulong)header,
343 &uname, &fit_uname_config,
344 IH_ARCH_DEFAULT, IH_TYPE_LOADABLE, -1,
345 FIT_LOAD_OPTIONAL_NON_ZERO,
346 &img_data, &img_len);
355 __weak int spl_parse_board_header(struct spl_image_info *spl_image,
356 const struct spl_boot_device *bootdev,
357 const void *image_header, size_t size)
362 __weak int spl_parse_legacy_header(struct spl_image_info *spl_image,
363 const struct legacy_img_hdr *header)
365 /* LEGACY image not supported */
366 debug("Legacy boot image support not enabled, proceeding to other boot methods\n");
370 int spl_parse_image_header(struct spl_image_info *spl_image,
371 const struct spl_boot_device *bootdev,
372 const struct legacy_img_hdr *header)
374 #if CONFIG_IS_ENABLED(LOAD_FIT_FULL)
375 int ret = spl_load_fit_image(spl_image, header);
380 if (image_get_magic(header) == IH_MAGIC) {
383 ret = spl_parse_legacy_header(spl_image, header);
387 #ifdef CONFIG_SPL_PANIC_ON_RAW_IMAGE
389 * CONFIG_SPL_PANIC_ON_RAW_IMAGE is defined when the
390 * code which loads images in SPL cannot guarantee that
391 * absolutely all read errors will be reported.
392 * An example is the LPC32XX MLC NAND driver, which
393 * will consider that a completely unreadable NAND block
394 * is bad, and thus should be skipped silently.
396 panic("** no mkimage signature but raw image not supported");
399 #if CONFIG_IS_ENABLED(OS_BOOT)
400 #if defined(CMD_BOOTI)
403 if (!booti_setup((ulong)header, &start, &size, 0)) {
404 spl_image->name = "Linux";
405 spl_image->os = IH_OS_LINUX;
406 spl_image->load_addr = start;
407 spl_image->entry_point = start;
408 spl_image->size = size;
410 "payload Image, load addr: 0x%lx size: %d\n",
411 spl_image->load_addr, spl_image->size);
414 #elif defined(CMD_BOOTZ)
417 if (!bootz_setup((ulong)header, &start, &end)) {
418 spl_image->name = "Linux";
419 spl_image->os = IH_OS_LINUX;
420 spl_image->load_addr = CONFIG_SYS_LOAD_ADDR;
421 spl_image->entry_point = CONFIG_SYS_LOAD_ADDR;
422 spl_image->size = end - start;
424 "payload zImage, load addr: 0x%lx size: %d\n",
425 spl_image->load_addr, spl_image->size);
431 if (!spl_parse_board_header(spl_image, bootdev, (const void *)header, sizeof(*header)))
434 #ifdef CONFIG_SPL_RAW_IMAGE_SUPPORT
435 /* Signature not found - assume u-boot.bin */
436 debug("mkimage signature not found - ih_magic = %x\n",
438 spl_set_header_raw_uboot(spl_image);
440 /* RAW image not supported, proceed to other boot methods. */
441 debug("Raw boot image support not enabled, proceeding to other boot methods\n");
449 __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
451 typedef void __noreturn (*image_entry_noargs_t)(void);
453 image_entry_noargs_t image_entry =
454 (image_entry_noargs_t)spl_image->entry_point;
456 debug("image entry point: 0x%lx\n", spl_image->entry_point);
460 #if CONFIG_IS_ENABLED(HANDOFF)
462 * Set up the SPL hand-off information
464 * This is initially empty (zero) but can be written by
466 static int setup_spl_handoff(void)
468 struct spl_handoff *ho;
470 ho = bloblist_ensure(BLOBLISTT_U_BOOT_SPL_HANDOFF, sizeof(struct spl_handoff));
477 __weak int handoff_arch_save(struct spl_handoff *ho)
482 static int write_spl_handoff(void)
484 struct spl_handoff *ho;
487 ho = bloblist_find(BLOBLISTT_U_BOOT_SPL_HANDOFF, sizeof(struct spl_handoff));
490 handoff_save_dram(ho);
491 ret = handoff_arch_save(ho);
494 debug(SPL_TPL_PROMPT "Wrote SPL handoff\n");
499 static inline int setup_spl_handoff(void) { return 0; }
500 static inline int write_spl_handoff(void) { return 0; }
505 * get_bootstage_id() - Get the bootstage ID to emit
507 * @start: true if this is for starting SPL, false for ending it
508 * Return: bootstage ID to use
510 static enum bootstage_id get_bootstage_id(bool start)
512 enum u_boot_phase phase = spl_phase();
514 if (IS_ENABLED(CONFIG_TPL_BUILD) && phase == PHASE_TPL)
515 return start ? BOOTSTAGE_ID_START_TPL : BOOTSTAGE_ID_END_TPL;
516 else if (IS_ENABLED(CONFIG_VPL_BUILD) && phase == PHASE_VPL)
517 return start ? BOOTSTAGE_ID_START_VPL : BOOTSTAGE_ID_END_VPL;
519 return start ? BOOTSTAGE_ID_START_SPL : BOOTSTAGE_ID_END_SPL;
522 static int spl_common_init(bool setup_malloc)
526 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
528 #ifdef CFG_MALLOC_F_ADDR
529 gd->malloc_base = CFG_MALLOC_F_ADDR;
531 gd->malloc_limit = CONFIG_VAL(SYS_MALLOC_F_LEN);
535 ret = bootstage_init(u_boot_first_phase());
537 debug("%s: Failed to set up bootstage: ret=%d\n", __func__,
541 #ifdef CONFIG_BOOTSTAGE_STASH
542 if (!u_boot_first_phase()) {
543 const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
544 CONFIG_BOOTSTAGE_STASH_SIZE);
546 ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
548 debug("%s: Failed to unstash bootstage: ret=%d\n",
551 #endif /* CONFIG_BOOTSTAGE_STASH */
552 bootstage_mark_name(get_bootstage_id(true),
553 spl_phase_name(spl_phase()));
554 #if CONFIG_IS_ENABLED(LOG)
557 debug("%s: Failed to set up logging\n", __func__);
561 if (CONFIG_IS_ENABLED(OF_REAL)) {
562 ret = fdtdec_setup();
564 debug("fdtdec_setup() returned error %d\n", ret);
568 if (CONFIG_IS_ENABLED(DM)) {
569 bootstage_start(BOOTSTAGE_ID_ACCUM_DM_SPL,
570 spl_phase() == PHASE_TPL ? "dm tpl" : "dm_spl");
571 /* With CONFIG_SPL_OF_PLATDATA, bring in all devices */
572 ret = dm_init_and_scan(!CONFIG_IS_ENABLED(OF_PLATDATA));
573 bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_SPL);
575 debug("dm_init_and_scan() returned error %d\n", ret);
583 void spl_set_bd(void)
586 * NOTE: On some platforms (e.g. x86) bdata may be in flash and not
593 int spl_early_init(void)
597 debug("%s\n", __func__);
599 ret = spl_common_init(true);
602 gd->flags |= GD_FLG_SPL_EARLY_INIT;
610 bool setup_malloc = !(IS_ENABLED(CONFIG_SPL_STACK_R) &&
611 IS_ENABLED(CONFIG_SPL_SYS_MALLOC_SIMPLE));
613 debug("%s\n", __func__);
615 if (!(gd->flags & GD_FLG_SPL_EARLY_INIT)) {
616 ret = spl_common_init(setup_malloc);
620 gd->flags |= GD_FLG_SPL_INIT;
625 #ifndef BOOT_DEVICE_NONE
626 #define BOOT_DEVICE_NONE 0xdeadbeef
629 __weak void board_boot_order(u32 *spl_boot_list)
631 spl_boot_list[0] = spl_boot_device();
634 __weak int spl_check_board_image(struct spl_image_info *spl_image,
635 const struct spl_boot_device *bootdev)
640 static int spl_load_image(struct spl_image_info *spl_image,
641 struct spl_image_loader *loader)
644 struct spl_boot_device bootdev;
646 bootdev.boot_device = loader->boot_device;
647 bootdev.boot_device_name = NULL;
649 ret = loader->load_image(spl_image, &bootdev);
650 #ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
651 if (!ret && spl_image->dcrc_length) {
653 ulong dcrc = crc32_wd(0, (unsigned char *)spl_image->dcrc_data,
654 spl_image->dcrc_length, CHUNKSZ_CRC32);
655 if (dcrc != spl_image->dcrc) {
656 puts("SPL: Image data CRC check failed!\n");
662 ret = spl_check_board_image(spl_image, &bootdev);
668 * boot_from_devices() - Try loading a booting U-Boot from a list of devices
670 * @spl_image: Place to put the image details if successful
671 * @spl_boot_list: List of boot devices to try
672 * @count: Number of elements in spl_boot_list
673 * Return: 0 if OK, -ENODEV if there were no boot devices
674 * if CONFIG_SHOW_ERRORS is enabled, returns -ENXIO if there were
675 * devices but none worked
677 static int boot_from_devices(struct spl_image_info *spl_image,
678 u32 spl_boot_list[], int count)
680 struct spl_image_loader *drv =
681 ll_entry_start(struct spl_image_loader, spl_image_loader);
683 ll_entry_count(struct spl_image_loader, spl_image_loader);
687 for (i = 0; i < count && spl_boot_list[i] != BOOT_DEVICE_NONE; i++) {
688 struct spl_image_loader *loader;
689 int bootdev = spl_boot_list[i];
691 if (CONFIG_IS_ENABLED(SHOW_ERRORS))
693 for (loader = drv; loader != drv + n_ents; loader++) {
694 if (bootdev != loader->boot_device)
696 if (!CONFIG_IS_ENABLED(SILENT_CONSOLE)) {
698 printf("Trying to boot from %s\n",
699 spl_loader_name(loader));
700 else if (CONFIG_IS_ENABLED(SHOW_ERRORS)) {
701 printf(SPL_TPL_PROMPT
702 "Unsupported Boot Device %d\n",
706 "Unsupported Boot Device!\n");
710 !spl_load_image(spl_image, loader)) {
711 spl_image->boot_device = bootdev;
720 #if defined(CONFIG_SPL_FRAMEWORK_BOARD_INIT_F)
721 void board_init_f(ulong dummy)
723 if (CONFIG_IS_ENABLED(OF_CONTROL)) {
726 ret = spl_early_init();
728 debug("spl_early_init() failed: %d\n", ret);
733 preloader_console_init();
737 void board_init_r(gd_t *dummy1, ulong dummy2)
739 u32 spl_boot_list[] = {
746 struct spl_image_info spl_image;
749 debug(">>" SPL_TPL_PROMPT "board_init_r()\n");
753 #if defined(CONFIG_SPL_SYS_MALLOC)
754 mem_malloc_init(SPL_SYS_MALLOC_START, CONFIG_SPL_SYS_MALLOC_SIZE);
755 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
757 if (!(gd->flags & GD_FLG_SPL_INIT)) {
761 #if !defined(CONFIG_PPC) && !defined(CONFIG_ARCH_MX6)
763 * timer_init() does not exist on PPC systems. The timer is initialized
764 * and enabled (decrementer) in interrupt_init() here.
768 if (CONFIG_IS_ENABLED(BLOBLIST)) {
769 ret = bloblist_init();
771 debug("%s: Failed to set up bloblist: ret=%d\n",
773 puts(SPL_TPL_PROMPT "Cannot set up bloblist\n");
777 if (CONFIG_IS_ENABLED(HANDOFF)) {
780 ret = setup_spl_handoff();
782 puts(SPL_TPL_PROMPT "Cannot set up SPL handoff\n");
787 #if CONFIG_IS_ENABLED(BOARD_INIT)
791 #if defined(CONFIG_SPL_WATCHDOG) && CONFIG_IS_ENABLED(WDT)
795 if (IS_ENABLED(CONFIG_SPL_OS_BOOT) || CONFIG_IS_ENABLED(HANDOFF) ||
796 IS_ENABLED(CONFIG_SPL_ATF))
797 dram_init_banksize();
799 if (CONFIG_IS_ENABLED(PCI) && !(gd->flags & GD_FLG_DM_DEAD)) {
802 puts(SPL_TPL_PROMPT "Cannot initialize PCI\n");
803 /* Don't fail. We still can try other boot methods. */
808 /* Dump driver model states to aid analysis */
809 if (CONFIG_IS_ENABLED(DM_STATS)) {
816 memset(&spl_image, '\0', sizeof(spl_image));
817 #ifdef CONFIG_SYS_SPL_ARGS_ADDR
818 spl_image.arg = (void *)CONFIG_SYS_SPL_ARGS_ADDR;
820 spl_image.boot_device = BOOT_DEVICE_NONE;
821 board_boot_order(spl_boot_list);
823 ret = boot_from_devices(&spl_image, spl_boot_list,
824 ARRAY_SIZE(spl_boot_list));
826 if (CONFIG_IS_ENABLED(SHOW_ERRORS) &&
827 CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT))
828 printf(SPL_TPL_PROMPT "failed to boot from all boot devices (err=%d)\n",
831 puts(SPL_TPL_PROMPT "failed to boot from all boot devices\n");
835 spl_perform_fixups(&spl_image);
836 if (CONFIG_IS_ENABLED(HANDOFF)) {
837 ret = write_spl_handoff();
839 printf(SPL_TPL_PROMPT
840 "SPL hand-off write failed (err=%d)\n", ret);
842 if (CONFIG_IS_ENABLED(BLOBLIST)) {
843 ret = bloblist_finish();
845 printf("Warning: Failed to finish bloblist (ret=%d)\n",
849 switch (spl_image.os) {
851 debug("Jumping to %s...\n", spl_phase_name(spl_next_phase()));
853 #if CONFIG_IS_ENABLED(ATF)
854 case IH_OS_ARM_TRUSTED_FIRMWARE:
855 debug("Jumping to U-Boot via ARM Trusted Firmware\n");
856 spl_fixup_fdt(spl_image.fdt_addr);
857 spl_invoke_atf(&spl_image);
860 #if CONFIG_IS_ENABLED(OPTEE_IMAGE)
862 debug("Jumping to U-Boot via OP-TEE\n");
863 spl_board_prepare_for_optee(spl_image.fdt_addr);
864 jump_to_image_optee(&spl_image);
867 #if CONFIG_IS_ENABLED(OPENSBI)
869 debug("Jumping to U-Boot via RISC-V OpenSBI\n");
870 spl_invoke_opensbi(&spl_image);
873 #if CONFIG_IS_ENABLED(OS_BOOT)
875 debug("Jumping to Linux\n");
876 #if defined(CONFIG_SYS_SPL_ARGS_ADDR)
877 spl_fixup_fdt((void *)CONFIG_SYS_SPL_ARGS_ADDR);
879 spl_board_prepare_for_linux();
880 jump_to_image_linux(&spl_image);
883 debug("Unsupported OS image.. Jumping nevertheless..\n");
885 #if CONFIG_VAL(SYS_MALLOC_F_LEN) && !defined(CONFIG_SPL_SYS_MALLOC_SIZE)
886 debug("SPL malloc() used 0x%lx bytes (%ld KB)\n", gd->malloc_ptr,
887 gd->malloc_ptr / 1024);
889 bootstage_mark_name(get_bootstage_id(false), "end phase");
890 #ifdef CONFIG_BOOTSTAGE_STASH
891 ret = bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
892 CONFIG_BOOTSTAGE_STASH_SIZE);
894 debug("Failed to stash bootstage: err=%d\n", ret);
897 if (IS_ENABLED(CONFIG_SPL_VIDEO_REMOVE)) {
901 rc = uclass_find_device(UCLASS_VIDEO, 0, &dev);
903 rc = device_remove(dev, DM_REMOVE_NORMAL);
905 printf("Cannot remove video device '%s' (err=%d)\n",
910 spl_board_prepare_for_boot();
911 jump_to_image_no_args(&spl_image);
915 * This requires UART clocks to be enabled. In order for this to work the
916 * caller must ensure that the gd pointer is valid.
918 void preloader_console_init(void)
920 #ifdef CONFIG_SPL_SERIAL
921 gd->baudrate = CONFIG_BAUDRATE;
923 serial_init(); /* serial communications setup */
925 gd->have_console = 1;
927 #if CONFIG_IS_ENABLED(BANNER_PRINT)
928 puts("\nU-Boot " SPL_TPL_NAME " " PLAIN_VERSION " (" U_BOOT_DATE " - "
929 U_BOOT_TIME " " U_BOOT_TZ ")\n");
931 #ifdef CONFIG_SPL_DISPLAY_PRINT
938 * This function is called before the stack is changed from initial stack to
939 * relocated stack. It tries to dump the stack size used
941 __weak void spl_relocate_stack_check(void)
943 #if CONFIG_IS_ENABLED(SYS_REPORT_STACK_F_USAGE)
944 ulong init_sp = gd->start_addr_sp;
945 ulong stack_bottom = init_sp - CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK);
946 u8 *ptr = (u8 *)stack_bottom;
949 for (i = 0; i < CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK); i++) {
950 if (*ptr != CONFIG_VAL(SYS_STACK_F_CHECK_BYTE))
954 printf("SPL initial stack usage: %lu bytes\n",
955 CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK) - i);
960 * spl_relocate_stack_gd() - Relocate stack ready for board_init_r() execution
962 * Sometimes board_init_f() runs with a stack in SRAM but we want to use SDRAM
963 * for the main board_init_r() execution. This is typically because we need
964 * more stack space for things like the MMC sub-system.
966 * This function calculates the stack position, copies the global_data into
967 * place, sets the new gd (except for ARM, for which setting GD within a C
968 * function may not always work) and returns the new stack position. The
969 * caller is responsible for setting up the sp register and, in the case
970 * of ARM, setting up gd.
972 * All of this is done using the same layout and alignments as done in
973 * board_init_f_init_reserve() / board_init_f_alloc_reserve().
975 * Return: new stack location, or 0 to use the same stack
977 ulong spl_relocate_stack_gd(void)
979 #ifdef CONFIG_SPL_STACK_R
981 ulong ptr = CONFIG_SPL_STACK_R_ADDR;
983 if (CONFIG_IS_ENABLED(SYS_REPORT_STACK_F_USAGE))
984 spl_relocate_stack_check();
986 #if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE) && CONFIG_VAL(SYS_MALLOC_F_LEN)
987 if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) {
988 debug("SPL malloc() before relocation used 0x%lx bytes (%ld KB)\n",
989 gd->malloc_ptr, gd->malloc_ptr / 1024);
990 ptr -= CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;
991 gd->malloc_base = ptr;
992 gd->malloc_limit = CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;
996 /* Get stack position: use 8-byte alignment for ABI compliance */
997 ptr = CONFIG_SPL_STACK_R_ADDR - roundup(sizeof(gd_t),16);
998 gd->start_addr_sp = ptr;
999 new_gd = (gd_t *)ptr;
1000 memcpy(new_gd, (void *)gd, sizeof(gd_t));
1001 #if CONFIG_IS_ENABLED(DM)
1002 dm_fixup_for_gd_move(new_gd);
1004 #if !defined(CONFIG_ARM) && !defined(CONFIG_RISCV)
1013 #if defined(CONFIG_BOOTCOUNT_LIMIT) && \
1014 ((!defined(CONFIG_TPL_BUILD) && !defined(CONFIG_SPL_BOOTCOUNT_LIMIT)) || \
1015 (defined(CONFIG_TPL_BUILD) && !defined(CONFIG_TPL_BOOTCOUNT_LIMIT)))
1016 void bootcount_store(ulong a)
1020 ulong bootcount_load(void)