diff options
Diffstat (limited to 'common/spl/spl.c')
-rw-r--r-- | common/spl/spl.c | 226 |
1 files changed, 51 insertions, 175 deletions
diff --git a/common/spl/spl.c b/common/spl/spl.c index cd294e81b2..0cf887fd62 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -256,102 +256,6 @@ void spl_set_header_raw_uboot(struct spl_image_info *spl_image) } #endif -#if CONFIG_IS_ENABLED(LOAD_FIT_FULL) -/* Parse and load full fitImage in SPL */ -static int spl_load_fit_image(struct spl_image_info *spl_image, - const struct legacy_img_hdr *header) -{ - struct bootm_headers images; - const char *fit_uname_config = NULL; - uintptr_t fdt_hack; - const char *uname; - ulong fw_data = 0, dt_data = 0, img_data = 0; - ulong fw_len = 0, dt_len = 0, img_len = 0; - int idx, conf_noffset; - int ret; - -#ifdef CONFIG_SPL_FIT_SIGNATURE - images.verify = 1; -#endif - ret = fit_image_load(&images, (ulong)header, - NULL, &fit_uname_config, - IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1, - FIT_LOAD_OPTIONAL, &fw_data, &fw_len); - if (ret >= 0) { - printf("DEPRECATED: 'standalone = ' property."); - printf("Please use either 'firmware =' or 'kernel ='\n"); - } else { - ret = fit_image_load(&images, (ulong)header, NULL, - &fit_uname_config, IH_ARCH_DEFAULT, - IH_TYPE_FIRMWARE, -1, FIT_LOAD_OPTIONAL, - &fw_data, &fw_len); - } - - if (ret < 0) { - ret = fit_image_load(&images, (ulong)header, NULL, - &fit_uname_config, IH_ARCH_DEFAULT, - IH_TYPE_KERNEL, -1, FIT_LOAD_OPTIONAL, - &fw_data, &fw_len); - } - - if (ret < 0) - return ret; - - spl_image->size = fw_len; - spl_image->entry_point = fw_data; - spl_image->load_addr = fw_data; - if (fit_image_get_os(header, ret, &spl_image->os)) - spl_image->os = IH_OS_INVALID; - spl_image->name = genimg_get_os_name(spl_image->os); - - debug(SPL_TPL_PROMPT "payload image: %32s load addr: 0x%lx size: %d\n", - spl_image->name, spl_image->load_addr, spl_image->size); - -#ifdef CONFIG_SPL_FIT_SIGNATURE - images.verify = 1; -#endif - ret = fit_image_load(&images, (ulong)header, NULL, &fit_uname_config, - IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1, - FIT_LOAD_OPTIONAL, &dt_data, &dt_len); - if (ret >= 0) { - spl_image->fdt_addr = (void *)dt_data; - - if (spl_image->os == IH_OS_U_BOOT) { - /* HACK: U-Boot expects FDT at a specific address */ - fdt_hack = spl_image->load_addr + spl_image->size; - fdt_hack = (fdt_hack + 3) & ~3; - debug("Relocating FDT to %p\n", spl_image->fdt_addr); - memcpy((void *)fdt_hack, spl_image->fdt_addr, dt_len); - } - } - - conf_noffset = fit_conf_get_node((const void *)header, - fit_uname_config); - if (conf_noffset < 0) - return 0; - - for (idx = 0; - uname = fdt_stringlist_get((const void *)header, conf_noffset, - FIT_LOADABLE_PROP, idx, - NULL), uname; - idx++) - { -#ifdef CONFIG_SPL_FIT_SIGNATURE - images.verify = 1; -#endif - ret = fit_image_load(&images, (ulong)header, - &uname, &fit_uname_config, - IH_ARCH_DEFAULT, IH_TYPE_LOADABLE, -1, - FIT_LOAD_OPTIONAL_NON_ZERO, - &img_data, &img_len); - if (ret < 0) - return ret; - } - - return 0; -} -#endif - __weak int spl_parse_board_header(struct spl_image_info *spl_image, const struct spl_boot_device *bootdev, const void *image_header, size_t size) @@ -371,12 +275,14 @@ int spl_parse_image_header(struct spl_image_info *spl_image, const struct spl_boot_device *bootdev, const struct legacy_img_hdr *header) { -#if CONFIG_IS_ENABLED(LOAD_FIT_FULL) - int ret = spl_load_fit_image(spl_image, header); + int ret; - if (!ret) - return ret; -#endif + if (CONFIG_IS_ENABLED(LOAD_FIT_FULL)) { + ret = spl_load_fit_image(spl_image, header); + + if (!ret) + return ret; + } if (image_get_magic(header) == IH_MAGIC) { int ret; @@ -523,7 +429,7 @@ static int spl_common_init(bool setup_malloc) { int ret; -#if CONFIG_VAL(SYS_MALLOC_F_LEN) +#if CONFIG_IS_ENABLED(SYS_MALLOC_F) if (setup_malloc) { #ifdef CFG_MALLOC_F_ADDR gd->malloc_base = CFG_MALLOC_F_ADDR; @@ -538,17 +444,11 @@ static int spl_common_init(bool setup_malloc) ret); return ret; } -#ifdef CONFIG_BOOTSTAGE_STASH if (!u_boot_first_phase()) { - const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR, - CONFIG_BOOTSTAGE_STASH_SIZE); - - ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE); + ret = bootstage_unstash_default(); if (ret) - debug("%s: Failed to unstash bootstage: ret=%d\n", - __func__, ret); + log_debug("Failed to unstash bootstage: ret=%d\n", ret); } -#endif /* CONFIG_BOOTSTAGE_STASH */ bootstage_mark_name(get_bootstage_id(true), spl_phase_name(spl_phase())); #if CONFIG_IS_ENABLED(LOG) @@ -744,27 +644,21 @@ void board_init_r(gd_t *dummy1, ulong dummy2) BOOT_DEVICE_NONE, }; struct spl_image_info spl_image; - int ret; + int ret, os; debug(">>" SPL_TPL_PROMPT "board_init_r()\n"); spl_set_bd(); -#if defined(CONFIG_SYS_SPL_MALLOC) - mem_malloc_init(SYS_SPL_MALLOC_START, CONFIG_SYS_SPL_MALLOC_SIZE); - gd->flags |= GD_FLG_FULL_MALLOC_INIT; -#endif + if (IS_ENABLED(CONFIG_SPL_SYS_MALLOC)) { + mem_malloc_init(SPL_SYS_MALLOC_START, SPL_SYS_MALLOC_SIZE); + gd->flags |= GD_FLG_FULL_MALLOC_INIT; + } if (!(gd->flags & GD_FLG_SPL_INIT)) { if (spl_init()) hang(); } -#if !defined(CONFIG_PPC) && !defined(CONFIG_ARCH_MX6) - /* - * timer_init() does not exist on PPC systems. The timer is initialized - * and enabled (decrementer) in interrupt_init() here. - */ timer_init(); -#endif if (CONFIG_IS_ENABLED(BLOBLIST)) { ret = bloblist_init(); if (ret) { @@ -784,13 +678,11 @@ void board_init_r(gd_t *dummy1, ulong dummy2) } } -#if CONFIG_IS_ENABLED(BOARD_INIT) - spl_board_init(); -#endif + if (CONFIG_IS_ENABLED(BOARD_INIT)) + spl_board_init(); -#if defined(CONFIG_SPL_WATCHDOG) && CONFIG_IS_ENABLED(WDT) - initr_watchdog(); -#endif + if (IS_ENABLED(CONFIG_SPL_WATCHDOG) && CONFIG_IS_ENABLED(WDT)) + initr_watchdog(); if (IS_ENABLED(CONFIG_SPL_OS_BOOT) || CONFIG_IS_ENABLED(HANDOFF) || IS_ENABLED(CONFIG_SPL_ATF)) @@ -814,9 +706,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2) } memset(&spl_image, '\0', sizeof(spl_image)); -#ifdef CONFIG_SYS_SPL_ARGS_ADDR - spl_image.arg = (void *)CONFIG_SYS_SPL_ARGS_ADDR; -#endif + if (IS_ENABLED(CONFIG_SPL_OS_BOOT)) + spl_image.arg = (void *)SPL_PAYLOAD_ARGS_ADDR; spl_image.boot_device = BOOT_DEVICE_NONE; board_boot_order(spl_boot_list); @@ -833,66 +724,39 @@ void board_init_r(gd_t *dummy1, ulong dummy2) } spl_perform_fixups(&spl_image); - if (CONFIG_IS_ENABLED(HANDOFF)) { - ret = write_spl_handoff(); - if (ret) - printf(SPL_TPL_PROMPT - "SPL hand-off write failed (err=%d)\n", ret); - } - if (CONFIG_IS_ENABLED(BLOBLIST)) { - ret = bloblist_finish(); - if (ret) - printf("Warning: Failed to finish bloblist (ret=%d)\n", - ret); - } - switch (spl_image.os) { - case IH_OS_U_BOOT: + os = spl_image.os; + if (os == IH_OS_U_BOOT) { debug("Jumping to %s...\n", spl_phase_name(spl_next_phase())); - break; -#if CONFIG_IS_ENABLED(ATF) - case IH_OS_ARM_TRUSTED_FIRMWARE: + } else if (CONFIG_IS_ENABLED(ATF) && os == IH_OS_ARM_TRUSTED_FIRMWARE) { debug("Jumping to U-Boot via ARM Trusted Firmware\n"); - spl_fixup_fdt(spl_image.fdt_addr); + spl_fixup_fdt(spl_image_fdt_addr(&spl_image)); spl_invoke_atf(&spl_image); - break; -#endif -#if CONFIG_IS_ENABLED(OPTEE_IMAGE) - case IH_OS_TEE: + } else if (CONFIG_IS_ENABLED(OPTEE_IMAGE) && os == IH_OS_TEE) { debug("Jumping to U-Boot via OP-TEE\n"); - spl_board_prepare_for_optee(spl_image.fdt_addr); + spl_board_prepare_for_optee(spl_image_fdt_addr(&spl_image)); jump_to_image_optee(&spl_image); - break; -#endif -#if CONFIG_IS_ENABLED(OPENSBI) - case IH_OS_OPENSBI: + } else if (CONFIG_IS_ENABLED(OPENSBI) && os == IH_OS_OPENSBI) { debug("Jumping to U-Boot via RISC-V OpenSBI\n"); spl_invoke_opensbi(&spl_image); - break; -#endif -#if CONFIG_IS_ENABLED(OS_BOOT) - case IH_OS_LINUX: + } else if (CONFIG_IS_ENABLED(OS_BOOT) && os == IH_OS_LINUX) { debug("Jumping to Linux\n"); -#if defined(CONFIG_SYS_SPL_ARGS_ADDR) - spl_fixup_fdt((void *)CONFIG_SYS_SPL_ARGS_ADDR); -#endif + if (IS_ENABLED(CONFIG_SPL_OS_BOOT)) + spl_fixup_fdt((void *)SPL_PAYLOAD_ARGS_ADDR); spl_board_prepare_for_linux(); jump_to_image_linux(&spl_image); -#endif - default: + } else { debug("Unsupported OS image.. Jumping nevertheless..\n"); } -#if CONFIG_VAL(SYS_MALLOC_F_LEN) && !defined(CONFIG_SYS_SPL_MALLOC_SIZE) - debug("SPL malloc() used 0x%lx bytes (%ld KB)\n", gd->malloc_ptr, - gd->malloc_ptr / 1024); -#endif + if (CONFIG_IS_ENABLED(SYS_MALLOC_F) && + !IS_ENABLED(CONFIG_SPL_SYS_MALLOC_SIZE)) + debug("SPL malloc() used 0x%lx bytes (%ld KB)\n", + gd_malloc_ptr(), gd_malloc_ptr() / 1024); + bootstage_mark_name(get_bootstage_id(false), "end phase"); -#ifdef CONFIG_BOOTSTAGE_STASH - ret = bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR, - CONFIG_BOOTSTAGE_STASH_SIZE); + ret = bootstage_stash_default(); if (ret) debug("Failed to stash bootstage: err=%d\n", ret); -#endif if (IS_ENABLED(CONFIG_SPL_VIDEO_REMOVE)) { struct udevice *dev; @@ -906,6 +770,18 @@ void board_init_r(gd_t *dummy1, ulong dummy2) dev->name, rc); } } + if (CONFIG_IS_ENABLED(HANDOFF)) { + ret = write_spl_handoff(); + if (ret) + printf(SPL_TPL_PROMPT + "SPL hand-off write failed (err=%d)\n", ret); + } + if (CONFIG_IS_ENABLED(BLOBLIST)) { + ret = bloblist_finish(); + if (ret) + printf("Warning: Failed to finish bloblist (ret=%d)\n", + ret); + } spl_board_prepare_for_boot(); jump_to_image_no_args(&spl_image); @@ -983,7 +859,7 @@ ulong spl_relocate_stack_gd(void) if (CONFIG_IS_ENABLED(SYS_REPORT_STACK_F_USAGE)) spl_relocate_stack_check(); -#if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE) && CONFIG_VAL(SYS_MALLOC_F_LEN) +#if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE) && CONFIG_IS_ENABLED(SYS_MALLOC_F) if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) { debug("SPL malloc() before relocation used 0x%lx bytes (%ld KB)\n", gd->malloc_ptr, gd->malloc_ptr / 1024); |