2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-07-21 13:10:21 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2010
|
|
|
|
* Texas Instruments, <www.ti.com>
|
|
|
|
*
|
|
|
|
* Aneesh V <aneesh@ti.com>
|
|
|
|
*/
|
2017-06-30 17:02:53 +00:00
|
|
|
|
2011-07-21 13:10:21 +00:00
|
|
|
#include <common.h>
|
2018-11-16 01:43:51 +00:00
|
|
|
#include <bloblist.h>
|
2017-11-14 01:55:03 +00:00
|
|
|
#include <binman_sym.h>
|
2020-05-10 17:40:00 +00:00
|
|
|
#include <bootstage.h>
|
2014-11-11 00:16:46 +00:00
|
|
|
#include <dm.h>
|
2018-11-16 01:44:09 +00:00
|
|
|
#include <handoff.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2019-11-14 19:57:41 +00:00
|
|
|
#include <irq_func.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2021-03-08 00:35:14 +00:00
|
|
|
#include <mapmem.h>
|
2019-11-14 19:57:24 +00:00
|
|
|
#include <serial.h>
|
2012-08-13 19:03:19 +00:00
|
|
|
#include <spl.h>
|
2022-05-27 16:48:32 +00:00
|
|
|
#include <system-constants.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2022-02-07 23:09:01 +00:00
|
|
|
#include <asm-generic/gpio.h>
|
2011-07-21 13:10:21 +00:00
|
|
|
#include <asm/u-boot.h>
|
2011-09-14 19:29:26 +00:00
|
|
|
#include <nand.h>
|
2011-07-21 13:10:27 +00:00
|
|
|
#include <fat.h>
|
2019-11-14 19:57:16 +00:00
|
|
|
#include <u-boot/crc.h>
|
2021-08-02 13:18:38 +00:00
|
|
|
#if CONFIG_IS_ENABLED(BANNER_PRINT)
|
|
|
|
#include <timestamp.h>
|
|
|
|
#endif
|
Move timestamp and version files into 'generated' subdir
There is a rather subtle build problem where the build time stamp is not
updated for out-of-tree builds if there exists an in-tree build which
has a valid timestamp file. So if you do an in-tree build, then an
out-of-tree build your timestamp will not change.
The correct timestamp_autogenerated.h lives in the object tree, but it
is not always found there. The source still lives in the source tree and
when compiling version.h, it includes timestamp_autogenerated.h. Since
the current directory is always searched first, this will come from the
source tree rather than the object tree if it exists there. This affects
dependency generation also, which means that common/cmd_version.o will not
even be rebuilt if you have ever done an in-tree build.
A similar problem exists with the version file.
This change moves both files into the 'generated' subdir, which is already
used for asm-offsets.h. Then timestamp.h and version.h are updated to
include the files from there.
There are other places where these generated files are included, but I
cannot see why these don't just use the timestamp.h and version.h headers.
So this change also tidies that up.
I have tested this with in- and out-of-tree builds, but not SPL. I have
looked at various other options for fixing this, including sed on the dep
files, -I- and -include flags to gcc, but I don't think they can be made
to work. Comments welcome.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>
2011-10-10 08:55:19 +00:00
|
|
|
#include <version.h>
|
2011-07-21 13:10:27 +00:00
|
|
|
#include <image.h>
|
2011-10-21 16:29:34 +00:00
|
|
|
#include <malloc.h>
|
2019-10-21 23:26:52 +00:00
|
|
|
#include <mapmem.h>
|
2014-11-11 00:16:46 +00:00
|
|
|
#include <dm/root.h>
|
2022-05-08 10:39:27 +00:00
|
|
|
#include <dm/util.h>
|
2023-04-10 08:49:13 +00:00
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <dm/uclass-internal.h>
|
2012-01-04 15:26:24 +00:00
|
|
|
#include <linux/compiler.h>
|
2017-04-18 11:57:27 +00:00
|
|
|
#include <fdt_support.h>
|
2018-05-02 14:10:54 +00:00
|
|
|
#include <bootcount.h>
|
2019-04-11 13:58:44 +00:00
|
|
|
#include <wdt.h>
|
2011-07-21 13:10:21 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
spl: binman: Check at runtime if binman symbols were filled in
Binman lets us declare symbols in SPL/TPL that refer to other entries in
the same binman image as them. These symbols are filled in with the
correct values while binman assembles the images, but this is done
in-memory only. Symbols marked as optional can be filled with
BINMAN_SYM_MISSING as an error value if their referred entry is missing.
However, the unmodified SPL/TPL binaries are still available on disk,
and can be used by people. For these files, nothing ensures that the
symbols are set to this error value, and they will be considered valid
when they are not.
Empirically, all symbols show up as zero in a sandbox_vpl build when we
run e.g. tpl/u-boot-tpl directly. On the other hand, zero is a perfectly
fine value for a binman-written symbol, so we cannot say the symbols
have wrong values based on that.
Declare a magic symbol that binman always fills in with a fixed value.
Check this value as an indicator that symbols were filled in correctly.
Return the error value for all symbols when this magic symbol has the
wrong value.
For binman tests, we need to make room for the new symbol in the mocked
SPL/TPL data by extending them by four bytes. This messes up some test
image layouts. Fix the affected values, and check the magic symbol
wherever it makes sense.
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2022-06-18 12:13:11 +00:00
|
|
|
DECLARE_BINMAN_MAGIC_SYM;
|
2011-07-21 13:10:21 +00:00
|
|
|
|
2012-08-13 19:03:19 +00:00
|
|
|
u32 *boot_params_ptr = NULL;
|
2011-09-14 19:33:34 +00:00
|
|
|
|
2022-06-18 12:13:09 +00:00
|
|
|
#if CONFIG_IS_ENABLED(BINMAN_UBOOT_SYMBOLS)
|
2017-11-14 01:55:03 +00:00
|
|
|
/* See spl.h for information about this */
|
2018-08-01 21:22:42 +00:00
|
|
|
binman_sym_declare(ulong, u_boot_any, image_pos);
|
2019-12-09 00:40:12 +00:00
|
|
|
binman_sym_declare(ulong, u_boot_any, size);
|
|
|
|
|
|
|
|
#ifdef CONFIG_TPL
|
2022-10-21 00:22:41 +00:00
|
|
|
binman_sym_declare(ulong, u_boot_spl_any, image_pos);
|
|
|
|
binman_sym_declare(ulong, u_boot_spl_any, size);
|
2019-12-09 00:40:12 +00:00
|
|
|
#endif
|
2017-11-14 01:55:03 +00:00
|
|
|
|
2022-04-30 06:56:52 +00:00
|
|
|
#ifdef CONFIG_VPL
|
2022-10-21 00:22:41 +00:00
|
|
|
binman_sym_declare(ulong, u_boot_vpl_any, image_pos);
|
|
|
|
binman_sym_declare(ulong, u_boot_vpl_any, size);
|
2022-04-30 06:56:52 +00:00
|
|
|
#endif
|
|
|
|
|
2022-06-18 12:13:09 +00:00
|
|
|
#endif /* BINMAN_UBOOT_SYMBOLS */
|
|
|
|
|
2021-04-08 16:56:11 +00:00
|
|
|
/* Define board data structure */
|
|
|
|
static struct bd_info bdata __attribute__ ((section(".data")));
|
|
|
|
|
2021-10-23 01:06:03 +00:00
|
|
|
#if CONFIG_IS_ENABLED(SHOW_BOOT_PROGRESS)
|
2016-06-07 06:31:20 +00:00
|
|
|
/*
|
|
|
|
* Board-specific Platform code can reimplement show_boot_progress () if needed
|
|
|
|
*/
|
|
|
|
__weak void show_boot_progress(int val) {}
|
2021-05-03 20:48:58 +00:00
|
|
|
#endif
|
2016-06-07 06:31:20 +00:00
|
|
|
|
2020-05-25 17:57:25 +00:00
|
|
|
#if defined(CONFIG_SPL_OS_BOOT) || CONFIG_IS_ENABLED(HANDOFF) || \
|
|
|
|
defined(CONFIG_SPL_ATF)
|
2018-11-16 01:44:09 +00:00
|
|
|
/* weak, default platform-specific function to initialize dram banks */
|
|
|
|
__weak int dram_init_banksize(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-15 04:01:38 +00:00
|
|
|
/*
|
|
|
|
* Default function to determine if u-boot or the OS should
|
|
|
|
* be started. This implementation always returns 1.
|
|
|
|
*
|
|
|
|
* Please implement your own board specific funcion to do this.
|
|
|
|
*
|
|
|
|
* RETURN
|
|
|
|
* 0 to not start u-boot
|
|
|
|
* positive if u-boot should start
|
|
|
|
*/
|
2021-10-31 03:03:48 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OS_BOOT)
|
2012-03-15 04:01:38 +00:00
|
|
|
__weak int spl_start_uboot(void)
|
|
|
|
{
|
2018-11-16 01:43:56 +00:00
|
|
|
puts(SPL_TPL_PROMPT
|
|
|
|
"Please implement spl_start_uboot() for your board\n");
|
|
|
|
puts(SPL_TPL_PROMPT "Direct Linux boot not active!\n");
|
2012-03-15 04:01:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2016-07-12 18:28:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Weak default function for arch specific zImage check. Return zero
|
|
|
|
* and fill start and end address if image is recognized.
|
|
|
|
*/
|
|
|
|
int __weak bootz_setup(ulong image, ulong *start, ulong *end)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2022-02-02 20:05:18 +00:00
|
|
|
|
|
|
|
int __weak booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool force_reloc)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-03-15 04:01:38 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-24 15:15:50 +00:00
|
|
|
/* Weak default function for arch/board-specific fixups to the spl_image_info */
|
|
|
|
void __weak spl_perform_fixups(struct spl_image_info *spl_image)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-25 17:57:25 +00:00
|
|
|
void spl_fixup_fdt(void *fdt_blob)
|
2017-04-18 11:57:27 +00:00
|
|
|
{
|
2020-05-25 17:57:25 +00:00
|
|
|
#if defined(CONFIG_SPL_OF_LIBFDT)
|
2017-04-18 11:57:27 +00:00
|
|
|
int err;
|
|
|
|
|
2020-05-25 17:57:25 +00:00
|
|
|
if (!fdt_blob)
|
|
|
|
return;
|
|
|
|
|
2017-04-18 11:57:27 +00:00
|
|
|
err = fdt_check_header(fdt_blob);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("fdt_root: %s\n", fdt_strerror(err));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fixup the memory dt node */
|
|
|
|
err = fdt_shrink_to_minimum(fdt_blob, 0);
|
|
|
|
if (err == 0) {
|
2018-11-16 01:43:56 +00:00
|
|
|
printf(SPL_TPL_PROMPT "fdt_shrink_to_minimum err - %d\n", err);
|
2017-04-18 11:57:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = arch_fixup_fdt(fdt_blob);
|
|
|
|
if (err) {
|
2018-11-16 01:43:56 +00:00
|
|
|
printf(SPL_TPL_PROMPT "arch_fixup_fdt err - %d\n", err);
|
2017-04-18 11:57:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-12-09 00:40:12 +00:00
|
|
|
ulong spl_get_image_pos(void)
|
|
|
|
{
|
2022-06-18 12:13:09 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(BINMAN_UBOOT_SYMBOLS))
|
2022-06-18 12:13:06 +00:00
|
|
|
return BINMAN_SYM_MISSING;
|
|
|
|
|
2022-04-30 06:56:52 +00:00
|
|
|
#ifdef CONFIG_VPL
|
|
|
|
if (spl_next_phase() == PHASE_VPL)
|
2022-10-21 00:22:41 +00:00
|
|
|
return binman_sym(ulong, u_boot_vpl_any, image_pos);
|
2022-04-30 06:56:52 +00:00
|
|
|
#endif
|
|
|
|
return spl_next_phase() == PHASE_SPL ?
|
2022-10-21 00:22:41 +00:00
|
|
|
binman_sym(ulong, u_boot_spl_any, image_pos) :
|
2019-12-09 00:40:12 +00:00
|
|
|
binman_sym(ulong, u_boot_any, image_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong spl_get_image_size(void)
|
|
|
|
{
|
2022-06-18 12:13:09 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(BINMAN_UBOOT_SYMBOLS))
|
2022-06-18 12:13:06 +00:00
|
|
|
return BINMAN_SYM_MISSING;
|
|
|
|
|
2022-04-30 06:56:52 +00:00
|
|
|
#ifdef CONFIG_VPL
|
|
|
|
if (spl_next_phase() == PHASE_VPL)
|
2022-10-21 00:22:41 +00:00
|
|
|
return binman_sym(ulong, u_boot_vpl_any, size);
|
2022-04-30 06:56:52 +00:00
|
|
|
#endif
|
|
|
|
return spl_next_phase() == PHASE_SPL ?
|
2022-10-21 00:22:41 +00:00
|
|
|
binman_sym(ulong, u_boot_spl_any, size) :
|
2019-12-09 00:40:12 +00:00
|
|
|
binman_sym(ulong, u_boot_any, size);
|
|
|
|
}
|
|
|
|
|
2021-01-24 17:06:03 +00:00
|
|
|
ulong spl_get_image_text_base(void)
|
|
|
|
{
|
2022-04-30 06:56:52 +00:00
|
|
|
#ifdef CONFIG_VPL
|
|
|
|
if (spl_next_phase() == PHASE_VPL)
|
|
|
|
return CONFIG_VPL_TEXT_BASE;
|
|
|
|
#endif
|
|
|
|
return spl_next_phase() == PHASE_SPL ? CONFIG_SPL_TEXT_BASE :
|
2022-10-21 00:22:39 +00:00
|
|
|
CONFIG_TEXT_BASE;
|
2021-01-24 17:06:03 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 06:34:21 +00:00
|
|
|
/*
|
|
|
|
* Weak default function for board specific cleanup/preparation before
|
|
|
|
* Linux boot. Some boards/platforms might not need it, so just provide
|
|
|
|
* an empty stub here.
|
|
|
|
*/
|
|
|
|
__weak void spl_board_prepare_for_linux(void)
|
|
|
|
{
|
|
|
|
/* Nothing to do! */
|
|
|
|
}
|
|
|
|
|
2021-07-15 19:19:24 +00:00
|
|
|
__weak void spl_board_prepare_for_optee(void *fdt)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-17 15:25:41 +00:00
|
|
|
__weak const char *spl_board_loader_name(u32 boot_device)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-20 12:12:06 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OPTEE_IMAGE)
|
|
|
|
__weak void __noreturn jump_to_image_optee(struct spl_image_info *spl_image)
|
|
|
|
{
|
|
|
|
spl_optee_entry(NULL, NULL, spl_image->fdt_addr,
|
|
|
|
(void *)spl_image->entry_point);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-10 05:54:20 +00:00
|
|
|
__weak void spl_board_prepare_for_boot(void)
|
|
|
|
{
|
|
|
|
/* Nothing to do! */
|
|
|
|
}
|
|
|
|
|
2022-09-07 02:26:52 +00:00
|
|
|
__weak struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size)
|
2018-08-14 09:27:02 +00:00
|
|
|
{
|
2022-10-21 00:22:39 +00:00
|
|
|
return map_sysmem(CONFIG_TEXT_BASE + offset, 0);
|
2018-08-14 09:27:02 +00:00
|
|
|
}
|
|
|
|
|
2022-10-29 00:27:07 +00:00
|
|
|
#ifdef CONFIG_SPL_RAW_IMAGE_SUPPORT
|
2016-09-25 00:19:52 +00:00
|
|
|
void spl_set_header_raw_uboot(struct spl_image_info *spl_image)
|
2014-10-31 07:31:00 +00:00
|
|
|
{
|
2022-06-18 12:13:06 +00:00
|
|
|
ulong u_boot_pos = spl_get_image_pos();
|
2017-11-14 01:55:03 +00:00
|
|
|
|
2022-10-29 00:27:07 +00:00
|
|
|
#if CONFIG_SYS_MONITOR_LEN != 0
|
2016-09-25 00:19:52 +00:00
|
|
|
spl_image->size = CONFIG_SYS_MONITOR_LEN;
|
2022-10-29 00:27:07 +00:00
|
|
|
#else
|
|
|
|
/* Unknown U-Boot size, let's assume it will not be more than 200 KB */
|
|
|
|
spl_image->size = 200 * 1024;
|
|
|
|
#endif
|
2018-02-28 19:51:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Binman error cases: address of the end of the previous region or the
|
|
|
|
* start of the image's entry area (usually 0) if there is no previous
|
|
|
|
* region.
|
|
|
|
*/
|
|
|
|
if (u_boot_pos && u_boot_pos != BINMAN_SYM_MISSING) {
|
|
|
|
/* Binman does not support separated entry addresses */
|
2017-11-14 01:55:03 +00:00
|
|
|
spl_image->entry_point = u_boot_pos;
|
|
|
|
spl_image->load_addr = u_boot_pos;
|
|
|
|
} else {
|
2023-08-25 01:59:48 +00:00
|
|
|
spl_image->entry_point = CONFIG_SYS_UBOOT_START;
|
2022-10-21 00:22:39 +00:00
|
|
|
spl_image->load_addr = CONFIG_TEXT_BASE;
|
2017-11-14 01:55:03 +00:00
|
|
|
}
|
2016-09-25 00:19:52 +00:00
|
|
|
spl_image->os = IH_OS_U_BOOT;
|
|
|
|
spl_image->name = "U-Boot";
|
2014-10-31 07:31:00 +00:00
|
|
|
}
|
2022-10-29 00:27:07 +00:00
|
|
|
#endif
|
2014-10-31 07:31:00 +00:00
|
|
|
|
2021-07-23 09:14:28 +00:00
|
|
|
__weak int spl_parse_board_header(struct spl_image_info *spl_image,
|
2022-01-14 13:31:38 +00:00
|
|
|
const struct spl_boot_device *bootdev,
|
2021-07-23 09:14:28 +00:00
|
|
|
const void *image_header, size_t size)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-04-21 07:28:41 +00:00
|
|
|
__weak int spl_parse_legacy_header(struct spl_image_info *spl_image,
|
2022-09-07 02:26:52 +00:00
|
|
|
const struct legacy_img_hdr *header)
|
2020-04-21 07:28:41 +00:00
|
|
|
{
|
|
|
|
/* LEGACY image not supported */
|
|
|
|
debug("Legacy boot image support not enabled, proceeding to other boot methods\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-09-25 00:19:53 +00:00
|
|
|
int spl_parse_image_header(struct spl_image_info *spl_image,
|
2022-01-14 13:31:38 +00:00
|
|
|
const struct spl_boot_device *bootdev,
|
2022-09-07 02:26:52 +00:00
|
|
|
const struct legacy_img_hdr *header)
|
2011-07-21 13:10:27 +00:00
|
|
|
{
|
2023-09-26 14:14:34 +00:00
|
|
|
int ret;
|
2018-05-12 22:23:17 +00:00
|
|
|
|
2023-09-26 14:14:34 +00:00
|
|
|
if (CONFIG_IS_ENABLED(LOAD_FIT_FULL)) {
|
|
|
|
ret = spl_load_fit_image(spl_image, header);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-27 10:50:57 +00:00
|
|
|
if (image_get_magic(header) == IH_MAGIC) {
|
2020-04-21 07:28:41 +00:00
|
|
|
int ret;
|
2019-02-10 20:34:37 +00:00
|
|
|
|
2020-04-21 07:28:41 +00:00
|
|
|
ret = spl_parse_legacy_header(spl_image, header);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-07-21 13:10:27 +00:00
|
|
|
} else {
|
2015-03-31 09:40:50 +00:00
|
|
|
#ifdef CONFIG_SPL_PANIC_ON_RAW_IMAGE
|
|
|
|
/*
|
|
|
|
* CONFIG_SPL_PANIC_ON_RAW_IMAGE is defined when the
|
|
|
|
* code which loads images in SPL cannot guarantee that
|
|
|
|
* absolutely all read errors will be reported.
|
|
|
|
* An example is the LPC32XX MLC NAND driver, which
|
|
|
|
* will consider that a completely unreadable NAND block
|
|
|
|
* is bad, and thus should be skipped silently.
|
|
|
|
*/
|
|
|
|
panic("** no mkimage signature but raw image not supported");
|
2016-08-24 18:04:42 +00:00
|
|
|
#endif
|
|
|
|
|
2021-10-31 03:03:48 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OS_BOOT)
|
2022-02-02 20:05:18 +00:00
|
|
|
#if defined(CMD_BOOTI)
|
|
|
|
ulong start, size;
|
|
|
|
|
|
|
|
if (!booti_setup((ulong)header, &start, &size, 0)) {
|
|
|
|
spl_image->name = "Linux";
|
|
|
|
spl_image->os = IH_OS_LINUX;
|
|
|
|
spl_image->load_addr = start;
|
|
|
|
spl_image->entry_point = start;
|
|
|
|
spl_image->size = size;
|
|
|
|
debug(SPL_TPL_PROMPT
|
|
|
|
"payload Image, load addr: 0x%lx size: %d\n",
|
|
|
|
spl_image->load_addr, spl_image->size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#elif defined(CMD_BOOTZ)
|
2016-07-12 18:28:14 +00:00
|
|
|
ulong start, end;
|
|
|
|
|
|
|
|
if (!bootz_setup((ulong)header, &start, &end)) {
|
2016-09-25 00:19:53 +00:00
|
|
|
spl_image->name = "Linux";
|
|
|
|
spl_image->os = IH_OS_LINUX;
|
|
|
|
spl_image->load_addr = CONFIG_SYS_LOAD_ADDR;
|
|
|
|
spl_image->entry_point = CONFIG_SYS_LOAD_ADDR;
|
|
|
|
spl_image->size = end - start;
|
2018-11-16 01:43:56 +00:00
|
|
|
debug(SPL_TPL_PROMPT
|
|
|
|
"payload zImage, load addr: 0x%lx size: %d\n",
|
2016-09-25 00:19:53 +00:00
|
|
|
spl_image->load_addr, spl_image->size);
|
2016-07-12 18:28:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2022-02-02 20:05:18 +00:00
|
|
|
#endif
|
2016-07-12 18:28:14 +00:00
|
|
|
#endif
|
2016-08-24 18:04:42 +00:00
|
|
|
|
2022-01-14 13:31:38 +00:00
|
|
|
if (!spl_parse_board_header(spl_image, bootdev, (const void *)header, sizeof(*header)))
|
2021-07-23 09:14:28 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-02-16 17:18:38 +00:00
|
|
|
#ifdef CONFIG_SPL_RAW_IMAGE_SUPPORT
|
2011-07-21 13:10:27 +00:00
|
|
|
/* Signature not found - assume u-boot.bin */
|
2012-08-14 19:06:43 +00:00
|
|
|
debug("mkimage signature not found - ih_magic = %x\n",
|
2011-07-21 13:10:27 +00:00
|
|
|
header->ih_magic);
|
2016-09-25 00:19:53 +00:00
|
|
|
spl_set_header_raw_uboot(spl_image);
|
2017-02-16 17:18:38 +00:00
|
|
|
#else
|
|
|
|
/* RAW image not supported, proceed to other boot methods. */
|
2017-08-01 14:17:12 +00:00
|
|
|
debug("Raw boot image support not enabled, proceeding to other boot methods\n");
|
2017-02-16 17:18:38 +00:00
|
|
|
return -EINVAL;
|
2015-03-31 09:40:50 +00:00
|
|
|
#endif
|
2011-07-21 13:10:27 +00:00
|
|
|
}
|
2017-02-16 17:18:38 +00:00
|
|
|
|
2016-04-28 22:44:54 +00:00
|
|
|
return 0;
|
2011-07-21 13:10:27 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 21:08:22 +00:00
|
|
|
__weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
|
2011-07-21 13:10:27 +00:00
|
|
|
{
|
2013-04-24 00:41:24 +00:00
|
|
|
typedef void __noreturn (*image_entry_noargs_t)(void);
|
|
|
|
|
2011-07-21 13:10:27 +00:00
|
|
|
image_entry_noargs_t image_entry =
|
2017-01-02 11:48:31 +00:00
|
|
|
(image_entry_noargs_t)spl_image->entry_point;
|
2011-07-21 13:10:27 +00:00
|
|
|
|
2018-11-02 20:49:52 +00:00
|
|
|
debug("image entry point: 0x%lx\n", spl_image->entry_point);
|
2013-04-24 00:41:24 +00:00
|
|
|
image_entry();
|
2011-07-21 13:10:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 01:44:09 +00:00
|
|
|
#if CONFIG_IS_ENABLED(HANDOFF)
|
|
|
|
/**
|
|
|
|
* Set up the SPL hand-off information
|
|
|
|
*
|
|
|
|
* This is initially empty (zero) but can be written by
|
|
|
|
*/
|
|
|
|
static int setup_spl_handoff(void)
|
|
|
|
{
|
|
|
|
struct spl_handoff *ho;
|
|
|
|
|
2022-01-13 02:26:17 +00:00
|
|
|
ho = bloblist_ensure(BLOBLISTT_U_BOOT_SPL_HANDOFF, sizeof(struct spl_handoff));
|
2018-11-16 01:44:09 +00:00
|
|
|
if (!ho)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-25 14:11:18 +00:00
|
|
|
__weak int handoff_arch_save(struct spl_handoff *ho)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-16 01:44:09 +00:00
|
|
|
static int write_spl_handoff(void)
|
|
|
|
{
|
|
|
|
struct spl_handoff *ho;
|
2019-09-25 14:11:18 +00:00
|
|
|
int ret;
|
2018-11-16 01:44:09 +00:00
|
|
|
|
2022-01-13 02:26:17 +00:00
|
|
|
ho = bloblist_find(BLOBLISTT_U_BOOT_SPL_HANDOFF, sizeof(struct spl_handoff));
|
2018-11-16 01:44:09 +00:00
|
|
|
if (!ho)
|
|
|
|
return -ENOENT;
|
|
|
|
handoff_save_dram(ho);
|
2019-09-25 14:11:18 +00:00
|
|
|
ret = handoff_arch_save(ho);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-11-16 01:44:09 +00:00
|
|
|
debug(SPL_TPL_PROMPT "Wrote SPL handoff\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int setup_spl_handoff(void) { return 0; }
|
|
|
|
static inline int write_spl_handoff(void) { return 0; }
|
|
|
|
|
|
|
|
#endif /* HANDOFF */
|
|
|
|
|
2021-03-15 05:11:15 +00:00
|
|
|
/**
|
|
|
|
* get_bootstage_id() - Get the bootstage ID to emit
|
|
|
|
*
|
|
|
|
* @start: true if this is for starting SPL, false for ending it
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: bootstage ID to use
|
2021-03-15 05:11:15 +00:00
|
|
|
*/
|
|
|
|
static enum bootstage_id get_bootstage_id(bool start)
|
|
|
|
{
|
|
|
|
enum u_boot_phase phase = spl_phase();
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_TPL_BUILD) && phase == PHASE_TPL)
|
|
|
|
return start ? BOOTSTAGE_ID_START_TPL : BOOTSTAGE_ID_END_TPL;
|
2022-04-30 06:56:52 +00:00
|
|
|
else if (IS_ENABLED(CONFIG_VPL_BUILD) && phase == PHASE_VPL)
|
|
|
|
return start ? BOOTSTAGE_ID_START_VPL : BOOTSTAGE_ID_END_VPL;
|
2021-03-15 05:11:15 +00:00
|
|
|
else
|
|
|
|
return start ? BOOTSTAGE_ID_START_SPL : BOOTSTAGE_ID_END_SPL;
|
|
|
|
}
|
|
|
|
|
2017-03-15 14:43:28 +00:00
|
|
|
static int spl_common_init(bool setup_malloc)
|
2011-07-21 13:10:21 +00:00
|
|
|
{
|
2015-02-28 05:06:42 +00:00
|
|
|
int ret;
|
|
|
|
|
2023-09-26 14:14:27 +00:00
|
|
|
#if CONFIG_IS_ENABLED(SYS_MALLOC_F)
|
2017-03-15 14:43:28 +00:00
|
|
|
if (setup_malloc) {
|
2022-12-04 15:04:49 +00:00
|
|
|
#ifdef CFG_MALLOC_F_ADDR
|
|
|
|
gd->malloc_base = CFG_MALLOC_F_ADDR;
|
2016-05-25 00:14:56 +00:00
|
|
|
#endif
|
2017-07-24 09:43:34 +00:00
|
|
|
gd->malloc_limit = CONFIG_VAL(SYS_MALLOC_F_LEN);
|
2017-03-15 14:43:28 +00:00
|
|
|
gd->malloc_ptr = 0;
|
|
|
|
}
|
2012-08-13 21:13:07 +00:00
|
|
|
#endif
|
2019-10-21 23:26:52 +00:00
|
|
|
ret = bootstage_init(u_boot_first_phase());
|
2017-05-22 11:05:35 +00:00
|
|
|
if (ret) {
|
|
|
|
debug("%s: Failed to set up bootstage: ret=%d\n", __func__,
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-10-21 23:26:52 +00:00
|
|
|
if (!u_boot_first_phase()) {
|
2023-09-26 14:14:32 +00:00
|
|
|
ret = bootstage_unstash_default();
|
2019-10-21 23:26:52 +00:00
|
|
|
if (ret)
|
2023-09-26 14:14:32 +00:00
|
|
|
log_debug("Failed to unstash bootstage: ret=%d\n", ret);
|
2019-10-21 23:26:52 +00:00
|
|
|
}
|
2021-03-15 05:11:15 +00:00
|
|
|
bootstage_mark_name(get_bootstage_id(true),
|
|
|
|
spl_phase_name(spl_phase()));
|
2018-11-16 01:43:49 +00:00
|
|
|
#if CONFIG_IS_ENABLED(LOG)
|
|
|
|
ret = log_init();
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: Failed to set up logging\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
2021-08-07 13:24:03 +00:00
|
|
|
if (CONFIG_IS_ENABLED(OF_REAL)) {
|
2015-02-28 05:06:42 +00:00
|
|
|
ret = fdtdec_setup();
|
|
|
|
if (ret) {
|
|
|
|
debug("fdtdec_setup() returned error %d\n", ret);
|
2015-06-23 21:39:10 +00:00
|
|
|
return ret;
|
2015-02-28 05:06:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-30 17:02:53 +00:00
|
|
|
if (CONFIG_IS_ENABLED(DM)) {
|
2020-05-10 17:39:59 +00:00
|
|
|
bootstage_start(BOOTSTAGE_ID_ACCUM_DM_SPL,
|
bootstage: Mark the start/end of TPL and SPL separately
At present bootstage in TPL and SPL use the same ID so it is not possible
to see the timing of each. Separate out the IDs and use the correct one
depending on which phase we are at.
Example output:
Timer summary in microseconds (14 records):
Mark Elapsed Stage
0 0 reset
224,787 224,787 TPL
282,248 57,461 end TPL
341,067 58,819 SPL
925,436 584,369 end SPL
931,710 6,274 board_init_f
1,035,482 103,772 board_init_r
1,387,852 352,370 main_loop
1,387,911 59 id=175
Accumulated time:
196 dm_r
8,300 dm_spl
14,139 dm_f
229,121 fsp-m
262,992 fsp-s
Signed-off-by: Simon Glass <sjg@chromium.org>
2019-10-21 23:26:51 +00:00
|
|
|
spl_phase() == PHASE_TPL ? "dm tpl" : "dm_spl");
|
2017-01-14 17:20:23 +00:00
|
|
|
/* With CONFIG_SPL_OF_PLATDATA, bring in all devices */
|
2016-07-04 17:58:14 +00:00
|
|
|
ret = dm_init_and_scan(!CONFIG_IS_ENABLED(OF_PLATDATA));
|
2020-05-10 17:39:59 +00:00
|
|
|
bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_SPL);
|
2015-02-28 05:06:42 +00:00
|
|
|
if (ret) {
|
|
|
|
debug("dm_init_and_scan() returned error %d\n", ret);
|
2015-06-23 21:39:10 +00:00
|
|
|
return ret;
|
2015-02-28 05:06:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-15 14:43:28 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-04-08 16:56:11 +00:00
|
|
|
void spl_set_bd(void)
|
2017-09-28 15:42:10 +00:00
|
|
|
{
|
2018-11-16 01:43:58 +00:00
|
|
|
/*
|
|
|
|
* NOTE: On some platforms (e.g. x86) bdata may be in flash and not
|
|
|
|
* writeable.
|
|
|
|
*/
|
2021-04-08 16:56:11 +00:00
|
|
|
if (!gd->bd)
|
|
|
|
gd->bd = &bdata;
|
2017-09-28 15:42:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 14:43:28 +00:00
|
|
|
int spl_early_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2018-08-13 09:24:05 +00:00
|
|
|
debug("%s\n", __func__);
|
|
|
|
|
2017-03-15 14:43:28 +00:00
|
|
|
ret = spl_common_init(true);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
gd->flags |= GD_FLG_SPL_EARLY_INIT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int spl_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
2017-03-20 18:19:27 +00:00
|
|
|
bool setup_malloc = !(IS_ENABLED(CONFIG_SPL_STACK_R) &&
|
|
|
|
IS_ENABLED(CONFIG_SPL_SYS_MALLOC_SIMPLE));
|
2017-03-15 14:43:28 +00:00
|
|
|
|
2018-08-13 09:24:05 +00:00
|
|
|
debug("%s\n", __func__);
|
|
|
|
|
2017-03-15 14:43:28 +00:00
|
|
|
if (!(gd->flags & GD_FLG_SPL_EARLY_INIT)) {
|
2017-03-20 18:19:27 +00:00
|
|
|
ret = spl_common_init(setup_malloc);
|
2017-03-15 14:43:28 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2015-06-23 21:39:10 +00:00
|
|
|
gd->flags |= GD_FLG_SPL_INIT;
|
2011-10-21 16:29:34 +00:00
|
|
|
|
2015-06-23 21:39:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-08 15:11:51 +00:00
|
|
|
#ifndef BOOT_DEVICE_NONE
|
|
|
|
#define BOOT_DEVICE_NONE 0xdeadbeef
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__weak void board_boot_order(u32 *spl_boot_list)
|
|
|
|
{
|
|
|
|
spl_boot_list[0] = spl_boot_device();
|
|
|
|
}
|
|
|
|
|
2022-01-14 13:31:40 +00:00
|
|
|
__weak int spl_check_board_image(struct spl_image_info *spl_image,
|
|
|
|
const struct spl_boot_device *bootdev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-30 22:30:52 +00:00
|
|
|
static int spl_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_image_loader *loader)
|
2015-06-23 21:39:10 +00:00
|
|
|
{
|
2019-02-10 20:34:37 +00:00
|
|
|
int ret;
|
2016-09-25 00:19:57 +00:00
|
|
|
struct spl_boot_device bootdev;
|
|
|
|
|
2016-11-30 22:30:52 +00:00
|
|
|
bootdev.boot_device = loader->boot_device;
|
2016-09-25 00:19:57 +00:00
|
|
|
bootdev.boot_device_name = NULL;
|
|
|
|
|
2019-02-10 20:34:37 +00:00
|
|
|
ret = loader->load_image(spl_image, &bootdev);
|
|
|
|
#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
|
|
|
|
if (!ret && spl_image->dcrc_length) {
|
|
|
|
/* check data crc */
|
|
|
|
ulong dcrc = crc32_wd(0, (unsigned char *)spl_image->dcrc_data,
|
|
|
|
spl_image->dcrc_length, CHUNKSZ_CRC32);
|
|
|
|
if (dcrc != spl_image->dcrc) {
|
|
|
|
puts("SPL: Image data CRC check failed!\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2022-01-14 13:31:40 +00:00
|
|
|
if (!ret)
|
|
|
|
ret = spl_check_board_image(spl_image, &bootdev);
|
|
|
|
|
2019-02-10 20:34:37 +00:00
|
|
|
return ret;
|
2016-11-30 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-07 12:18:43 +00:00
|
|
|
* boot_from_devices() - Try loading a booting U-Boot from a list of devices
|
2016-11-30 22:30:51 +00:00
|
|
|
*
|
|
|
|
* @spl_image: Place to put the image details if successful
|
|
|
|
* @spl_boot_list: List of boot devices to try
|
|
|
|
* @count: Number of elements in spl_boot_list
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ENODEV if there were no boot devices
|
2021-07-05 22:32:57 +00:00
|
|
|
* if CONFIG_SHOW_ERRORS is enabled, returns -ENXIO if there were
|
|
|
|
* devices but none worked
|
2016-11-30 22:30:51 +00:00
|
|
|
*/
|
|
|
|
static int boot_from_devices(struct spl_image_info *spl_image,
|
|
|
|
u32 spl_boot_list[], int count)
|
|
|
|
{
|
2022-10-21 00:23:07 +00:00
|
|
|
struct spl_image_loader *drv =
|
|
|
|
ll_entry_start(struct spl_image_loader, spl_image_loader);
|
|
|
|
const int n_ents =
|
|
|
|
ll_entry_count(struct spl_image_loader, spl_image_loader);
|
2021-07-05 22:32:57 +00:00
|
|
|
int ret = -ENODEV;
|
2016-11-30 22:30:51 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count && spl_boot_list[i] != BOOT_DEVICE_NONE; i++) {
|
|
|
|
struct spl_image_loader *loader;
|
2021-07-05 22:32:57 +00:00
|
|
|
int bootdev = spl_boot_list[i];
|
|
|
|
|
|
|
|
if (CONFIG_IS_ENABLED(SHOW_ERRORS))
|
|
|
|
ret = -ENXIO;
|
2022-10-21 00:23:07 +00:00
|
|
|
for (loader = drv; loader != drv + n_ents; loader++) {
|
|
|
|
if (bootdev != loader->boot_device)
|
|
|
|
continue;
|
|
|
|
if (!CONFIG_IS_ENABLED(SILENT_CONSOLE)) {
|
|
|
|
if (loader)
|
|
|
|
printf("Trying to boot from %s\n",
|
|
|
|
spl_loader_name(loader));
|
|
|
|
else if (CONFIG_IS_ENABLED(SHOW_ERRORS)) {
|
|
|
|
printf(SPL_TPL_PROMPT
|
|
|
|
"Unsupported Boot Device %d\n",
|
|
|
|
bootdev);
|
|
|
|
} else {
|
|
|
|
puts(SPL_TPL_PROMPT
|
|
|
|
"Unsupported Boot Device!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (loader &&
|
|
|
|
!spl_load_image(spl_image, loader)) {
|
|
|
|
spl_image->boot_device = bootdev;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-05-24 15:15:50 +00:00
|
|
|
}
|
2016-11-30 22:30:51 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 22:32:57 +00:00
|
|
|
return ret;
|
2015-11-08 15:11:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 14:18:39 +00:00
|
|
|
#if defined(CONFIG_SPL_FRAMEWORK_BOARD_INIT_F)
|
|
|
|
void board_init_f(ulong dummy)
|
|
|
|
{
|
|
|
|
if (CONFIG_IS_ENABLED(OF_CONTROL)) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = spl_early_init();
|
|
|
|
if (ret) {
|
|
|
|
debug("spl_early_init() failed: %d\n", ret);
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 23:08:10 +00:00
|
|
|
preloader_console_init();
|
2019-09-19 14:18:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-11-08 15:11:50 +00:00
|
|
|
void board_init_r(gd_t *dummy1, ulong dummy2)
|
|
|
|
{
|
2016-09-25 00:20:17 +00:00
|
|
|
u32 spl_boot_list[] = {
|
|
|
|
BOOT_DEVICE_NONE,
|
|
|
|
BOOT_DEVICE_NONE,
|
|
|
|
BOOT_DEVICE_NONE,
|
|
|
|
BOOT_DEVICE_NONE,
|
|
|
|
BOOT_DEVICE_NONE,
|
|
|
|
};
|
|
|
|
struct spl_image_info spl_image;
|
2023-09-26 14:14:22 +00:00
|
|
|
int ret, os;
|
2015-11-08 15:11:50 +00:00
|
|
|
|
2018-11-16 01:43:56 +00:00
|
|
|
debug(">>" SPL_TPL_PROMPT "board_init_r()\n");
|
2017-09-28 15:42:10 +00:00
|
|
|
|
2021-04-08 16:56:11 +00:00
|
|
|
spl_set_bd();
|
|
|
|
|
2023-09-26 14:14:18 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-11-08 15:11:50 +00:00
|
|
|
if (!(gd->flags & GD_FLG_SPL_INIT)) {
|
|
|
|
if (spl_init())
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
timer_init();
|
2019-09-25 14:11:19 +00:00
|
|
|
if (CONFIG_IS_ENABLED(BLOBLIST)) {
|
|
|
|
ret = bloblist_init();
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: Failed to set up bloblist: ret=%d\n",
|
|
|
|
__func__, ret);
|
|
|
|
puts(SPL_TPL_PROMPT "Cannot set up bloblist\n");
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CONFIG_IS_ENABLED(HANDOFF)) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = setup_spl_handoff();
|
|
|
|
if (ret) {
|
|
|
|
puts(SPL_TPL_PROMPT "Cannot set up SPL handoff\n");
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
}
|
2015-11-08 15:11:50 +00:00
|
|
|
|
2023-09-26 14:14:20 +00:00
|
|
|
if (CONFIG_IS_ENABLED(BOARD_INIT))
|
|
|
|
spl_board_init();
|
2015-11-08 15:11:50 +00:00
|
|
|
|
2023-09-26 14:14:20 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SPL_WATCHDOG) && CONFIG_IS_ENABLED(WDT))
|
|
|
|
initr_watchdog();
|
2019-04-11 13:58:44 +00:00
|
|
|
|
2020-05-25 17:57:25 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SPL_OS_BOOT) || CONFIG_IS_ENABLED(HANDOFF) ||
|
|
|
|
IS_ENABLED(CONFIG_SPL_ATF))
|
2018-11-16 01:44:09 +00:00
|
|
|
dram_init_banksize();
|
|
|
|
|
2023-09-07 15:58:13 +00:00
|
|
|
if (CONFIG_IS_ENABLED(PCI) && !(gd->flags & GD_FLG_DM_DEAD)) {
|
2023-07-24 20:18:41 +00:00
|
|
|
ret = pci_init();
|
|
|
|
if (ret)
|
|
|
|
puts(SPL_TPL_PROMPT "Cannot initialize PCI\n");
|
|
|
|
/* Don't fail. We still can try other boot methods. */
|
|
|
|
}
|
|
|
|
|
2018-05-02 14:10:54 +00:00
|
|
|
bootcount_inc();
|
|
|
|
|
2022-05-08 10:39:27 +00:00
|
|
|
/* Dump driver model states to aid analysis */
|
|
|
|
if (CONFIG_IS_ENABLED(DM_STATS)) {
|
|
|
|
struct dm_stats mem;
|
|
|
|
|
|
|
|
dm_get_mem(&mem);
|
|
|
|
dm_dump_mem(&mem);
|
|
|
|
}
|
|
|
|
|
2016-09-25 00:20:17 +00:00
|
|
|
memset(&spl_image, '\0', sizeof(spl_image));
|
2023-09-26 14:14:21 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SPL_OS_BOOT))
|
|
|
|
spl_image.arg = (void *)SPL_PAYLOAD_ARGS_ADDR;
|
2018-05-24 15:15:50 +00:00
|
|
|
spl_image.boot_device = BOOT_DEVICE_NONE;
|
2015-11-08 15:11:51 +00:00
|
|
|
board_boot_order(spl_boot_list);
|
|
|
|
|
2021-07-05 22:32:57 +00:00
|
|
|
ret = boot_from_devices(&spl_image, spl_boot_list,
|
|
|
|
ARRAY_SIZE(spl_boot_list));
|
|
|
|
if (ret) {
|
|
|
|
if (CONFIG_IS_ENABLED(SHOW_ERRORS) &&
|
|
|
|
CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT))
|
|
|
|
printf(SPL_TPL_PROMPT "failed to boot from all boot devices (err=%d)\n",
|
|
|
|
ret);
|
|
|
|
else
|
|
|
|
puts(SPL_TPL_PROMPT "failed to boot from all boot devices\n");
|
2015-11-08 15:11:50 +00:00
|
|
|
hang();
|
2015-11-08 15:11:51 +00:00
|
|
|
}
|
2015-11-08 15:11:50 +00:00
|
|
|
|
2018-05-24 15:15:50 +00:00
|
|
|
spl_perform_fixups(&spl_image);
|
|
|
|
|
2023-09-26 14:14:22 +00:00
|
|
|
os = spl_image.os;
|
|
|
|
if (os == IH_OS_U_BOOT) {
|
2021-02-06 16:57:27 +00:00
|
|
|
debug("Jumping to %s...\n", spl_phase_name(spl_next_phase()));
|
2023-09-26 14:14:22 +00:00
|
|
|
} else if (CONFIG_IS_ENABLED(ATF) && os == IH_OS_ARM_TRUSTED_FIRMWARE) {
|
2017-09-13 19:29:35 +00:00
|
|
|
debug("Jumping to U-Boot via ARM Trusted Firmware\n");
|
2023-09-26 14:14:22 +00:00
|
|
|
spl_fixup_fdt(spl_image_fdt_addr(&spl_image));
|
2017-09-13 19:29:35 +00:00
|
|
|
spl_invoke_atf(&spl_image);
|
2023-09-26 14:14:22 +00:00
|
|
|
} else if (CONFIG_IS_ENABLED(OPTEE_IMAGE) && os == IH_OS_TEE) {
|
2018-08-23 09:17:59 +00:00
|
|
|
debug("Jumping to U-Boot via OP-TEE\n");
|
2023-09-26 14:14:22 +00:00
|
|
|
spl_board_prepare_for_optee(spl_image_fdt_addr(&spl_image));
|
2021-10-20 12:12:06 +00:00
|
|
|
jump_to_image_optee(&spl_image);
|
2023-09-26 14:14:22 +00:00
|
|
|
} else if (CONFIG_IS_ENABLED(OPENSBI) && os == IH_OS_OPENSBI) {
|
2019-08-21 19:14:44 +00:00
|
|
|
debug("Jumping to U-Boot via RISC-V OpenSBI\n");
|
|
|
|
spl_invoke_opensbi(&spl_image);
|
2023-09-26 14:14:22 +00:00
|
|
|
} else if (CONFIG_IS_ENABLED(OS_BOOT) && os == IH_OS_LINUX) {
|
2012-03-15 04:01:38 +00:00
|
|
|
debug("Jumping to Linux\n");
|
2023-09-26 14:14:21 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SPL_OS_BOOT))
|
|
|
|
spl_fixup_fdt((void *)SPL_PAYLOAD_ARGS_ADDR);
|
2012-03-15 04:01:38 +00:00
|
|
|
spl_board_prepare_for_linux();
|
2017-04-07 22:38:13 +00:00
|
|
|
jump_to_image_linux(&spl_image);
|
2023-09-26 14:14:22 +00:00
|
|
|
} else {
|
2012-08-27 21:58:28 +00:00
|
|
|
debug("Unsupported OS image.. Jumping nevertheless..\n");
|
2011-07-21 13:10:27 +00:00
|
|
|
}
|
2023-09-26 14:14:31 +00:00
|
|
|
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);
|
|
|
|
|
2021-03-15 05:11:15 +00:00
|
|
|
bootstage_mark_name(get_bootstage_id(false), "end phase");
|
2023-09-26 14:14:32 +00:00
|
|
|
ret = bootstage_stash_default();
|
2017-05-22 11:05:35 +00:00
|
|
|
if (ret)
|
|
|
|
debug("Failed to stash bootstage: err=%d\n", ret);
|
2017-09-13 10:24:24 +00:00
|
|
|
|
2023-07-18 08:57:33 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SPL_VIDEO_REMOVE)) {
|
|
|
|
struct udevice *dev;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = uclass_find_device(UCLASS_VIDEO, 0, &dev);
|
|
|
|
if (!rc && dev) {
|
|
|
|
rc = device_remove(dev, DM_REMOVE_NORMAL);
|
|
|
|
if (rc)
|
|
|
|
printf("Cannot remove video device '%s' (err=%d)\n",
|
|
|
|
dev->name, rc);
|
|
|
|
}
|
2023-04-10 08:49:13 +00:00
|
|
|
}
|
2023-09-26 14:14:36 +00:00
|
|
|
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);
|
|
|
|
}
|
2023-04-10 08:49:13 +00:00
|
|
|
|
2016-05-10 05:54:20 +00:00
|
|
|
spl_board_prepare_for_boot();
|
2012-10-19 21:08:22 +00:00
|
|
|
jump_to_image_no_args(&spl_image);
|
2011-07-21 13:10:21 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 22:31:05 +00:00
|
|
|
/*
|
|
|
|
* This requires UART clocks to be enabled. In order for this to work the
|
|
|
|
* caller must ensure that the gd pointer is valid.
|
|
|
|
*/
|
2011-07-21 13:10:21 +00:00
|
|
|
void preloader_console_init(void)
|
|
|
|
{
|
2021-08-08 18:20:12 +00:00
|
|
|
#ifdef CONFIG_SPL_SERIAL
|
2011-07-21 13:10:21 +00:00
|
|
|
gd->baudrate = CONFIG_BAUDRATE;
|
|
|
|
|
|
|
|
serial_init(); /* serial communications setup */
|
|
|
|
|
2011-11-01 13:16:03 +00:00
|
|
|
gd->have_console = 1;
|
|
|
|
|
2018-11-16 01:43:57 +00:00
|
|
|
#if CONFIG_IS_ENABLED(BANNER_PRINT)
|
2018-11-16 01:43:56 +00:00
|
|
|
puts("\nU-Boot " SPL_TPL_NAME " " PLAIN_VERSION " (" U_BOOT_DATE " - "
|
|
|
|
U_BOOT_TIME " " U_BOOT_TZ ")\n");
|
2018-01-25 17:45:22 +00:00
|
|
|
#endif
|
2012-08-13 18:37:56 +00:00
|
|
|
#ifdef CONFIG_SPL_DISPLAY_PRINT
|
|
|
|
spl_display_print();
|
|
|
|
#endif
|
2018-04-19 04:32:51 +00:00
|
|
|
#endif
|
2020-05-07 23:08:10 +00:00
|
|
|
}
|
2015-03-03 15:03:00 +00:00
|
|
|
|
2019-07-16 20:30:36 +00:00
|
|
|
/**
|
|
|
|
* This function is called before the stack is changed from initial stack to
|
|
|
|
* relocated stack. It tries to dump the stack size used
|
|
|
|
*/
|
|
|
|
__weak void spl_relocate_stack_check(void)
|
|
|
|
{
|
|
|
|
#if CONFIG_IS_ENABLED(SYS_REPORT_STACK_F_USAGE)
|
|
|
|
ulong init_sp = gd->start_addr_sp;
|
|
|
|
ulong stack_bottom = init_sp - CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK);
|
|
|
|
u8 *ptr = (u8 *)stack_bottom;
|
|
|
|
ulong i;
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK); i++) {
|
|
|
|
if (*ptr != CONFIG_VAL(SYS_STACK_F_CHECK_BYTE))
|
|
|
|
break;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
printf("SPL initial stack usage: %lu bytes\n",
|
|
|
|
CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK) - i);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-03 15:03:00 +00:00
|
|
|
/**
|
|
|
|
* spl_relocate_stack_gd() - Relocate stack ready for board_init_r() execution
|
|
|
|
*
|
|
|
|
* Sometimes board_init_f() runs with a stack in SRAM but we want to use SDRAM
|
|
|
|
* for the main board_init_r() execution. This is typically because we need
|
|
|
|
* more stack space for things like the MMC sub-system.
|
|
|
|
*
|
|
|
|
* This function calculates the stack position, copies the global_data into
|
arm: move gd handling outside of C code
As of gcc 5.2.1 for Thumb-1, it is not possible any
more to assign gd from C code, as gd is mapped to r9,
and r9 may now be saved in the prolog sequence, and
restored in the epilog sequence, of any C functions.
Therefore arch_setup_gd(), which is supposed to set
r9, may actually have no effect, causing U-Boot to
use a bad address to access GD.
Fix this by never calling arch_setup_gd() for ARM,
and instead setting r9 in arch/arm/lib/crt0.S, to
the value returned by board_init_f_alloc_reserve().
Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
Reviewed-by: Simon Glass <sjg@chromium.org>
2015-11-25 16:56:33 +00:00
|
|
|
* place, sets the new gd (except for ARM, for which setting GD within a C
|
|
|
|
* function may not always work) and returns the new stack position. The
|
|
|
|
* caller is responsible for setting up the sp register and, in the case
|
|
|
|
* of ARM, setting up gd.
|
|
|
|
*
|
|
|
|
* All of this is done using the same layout and alignments as done in
|
|
|
|
* board_init_f_init_reserve() / board_init_f_alloc_reserve().
|
2015-03-03 15:03:00 +00:00
|
|
|
*
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: new stack location, or 0 to use the same stack
|
2015-03-03 15:03:00 +00:00
|
|
|
*/
|
|
|
|
ulong spl_relocate_stack_gd(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SPL_STACK_R
|
|
|
|
gd_t *new_gd;
|
arm: move gd handling outside of C code
As of gcc 5.2.1 for Thumb-1, it is not possible any
more to assign gd from C code, as gd is mapped to r9,
and r9 may now be saved in the prolog sequence, and
restored in the epilog sequence, of any C functions.
Therefore arch_setup_gd(), which is supposed to set
r9, may actually have no effect, causing U-Boot to
use a bad address to access GD.
Fix this by never calling arch_setup_gd() for ARM,
and instead setting r9 in arch/arm/lib/crt0.S, to
the value returned by board_init_f_alloc_reserve().
Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
Reviewed-by: Simon Glass <sjg@chromium.org>
2015-11-25 16:56:33 +00:00
|
|
|
ulong ptr = CONFIG_SPL_STACK_R_ADDR;
|
2015-03-03 15:03:00 +00:00
|
|
|
|
2019-07-16 20:30:36 +00:00
|
|
|
if (CONFIG_IS_ENABLED(SYS_REPORT_STACK_F_USAGE))
|
|
|
|
spl_relocate_stack_check();
|
|
|
|
|
2023-09-26 14:14:27 +00:00
|
|
|
#if defined(CONFIG_SPL_SYS_MALLOC_SIMPLE) && CONFIG_IS_ENABLED(SYS_MALLOC_F)
|
2015-09-13 13:04:17 +00:00
|
|
|
if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) {
|
2019-02-26 21:27:52 +00:00
|
|
|
debug("SPL malloc() before relocation used 0x%lx bytes (%ld KB)\n",
|
|
|
|
gd->malloc_ptr, gd->malloc_ptr / 1024);
|
2015-09-13 13:04:17 +00:00
|
|
|
ptr -= CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;
|
|
|
|
gd->malloc_base = ptr;
|
|
|
|
gd->malloc_limit = CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN;
|
|
|
|
gd->malloc_ptr = 0;
|
|
|
|
}
|
|
|
|
#endif
|
arm: move gd handling outside of C code
As of gcc 5.2.1 for Thumb-1, it is not possible any
more to assign gd from C code, as gd is mapped to r9,
and r9 may now be saved in the prolog sequence, and
restored in the epilog sequence, of any C functions.
Therefore arch_setup_gd(), which is supposed to set
r9, may actually have no effect, causing U-Boot to
use a bad address to access GD.
Fix this by never calling arch_setup_gd() for ARM,
and instead setting r9 in arch/arm/lib/crt0.S, to
the value returned by board_init_f_alloc_reserve().
Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
Reviewed-by: Simon Glass <sjg@chromium.org>
2015-11-25 16:56:33 +00:00
|
|
|
/* Get stack position: use 8-byte alignment for ABI compliance */
|
|
|
|
ptr = CONFIG_SPL_STACK_R_ADDR - roundup(sizeof(gd_t),16);
|
2023-07-18 08:57:27 +00:00
|
|
|
gd->start_addr_sp = ptr;
|
arm: move gd handling outside of C code
As of gcc 5.2.1 for Thumb-1, it is not possible any
more to assign gd from C code, as gd is mapped to r9,
and r9 may now be saved in the prolog sequence, and
restored in the epilog sequence, of any C functions.
Therefore arch_setup_gd(), which is supposed to set
r9, may actually have no effect, causing U-Boot to
use a bad address to access GD.
Fix this by never calling arch_setup_gd() for ARM,
and instead setting r9 in arch/arm/lib/crt0.S, to
the value returned by board_init_f_alloc_reserve().
Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
Reviewed-by: Simon Glass <sjg@chromium.org>
2015-11-25 16:56:33 +00:00
|
|
|
new_gd = (gd_t *)ptr;
|
|
|
|
memcpy(new_gd, (void *)gd, sizeof(gd_t));
|
2016-11-13 21:21:58 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM)
|
|
|
|
dm_fixup_for_gd_move(new_gd);
|
|
|
|
#endif
|
2019-08-21 19:14:46 +00:00
|
|
|
#if !defined(CONFIG_ARM) && !defined(CONFIG_RISCV)
|
arm: move gd handling outside of C code
As of gcc 5.2.1 for Thumb-1, it is not possible any
more to assign gd from C code, as gd is mapped to r9,
and r9 may now be saved in the prolog sequence, and
restored in the epilog sequence, of any C functions.
Therefore arch_setup_gd(), which is supposed to set
r9, may actually have no effect, causing U-Boot to
use a bad address to access GD.
Fix this by never calling arch_setup_gd() for ARM,
and instead setting r9 in arch/arm/lib/crt0.S, to
the value returned by board_init_f_alloc_reserve().
Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
Reviewed-by: Simon Glass <sjg@chromium.org>
2015-11-25 16:56:33 +00:00
|
|
|
gd = new_gd;
|
|
|
|
#endif
|
2015-03-03 15:03:00 +00:00
|
|
|
return ptr;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
2019-11-14 19:57:17 +00:00
|
|
|
|
2020-12-11 18:56:47 +00:00
|
|
|
#if defined(CONFIG_BOOTCOUNT_LIMIT) && \
|
|
|
|
((!defined(CONFIG_TPL_BUILD) && !defined(CONFIG_SPL_BOOTCOUNT_LIMIT)) || \
|
|
|
|
(defined(CONFIG_TPL_BUILD) && !defined(CONFIG_TPL_BOOTCOUNT_LIMIT)))
|
2019-11-14 19:57:17 +00:00
|
|
|
void bootcount_store(ulong a)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong bootcount_load(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|