summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Kconfig84
-rw-r--r--common/Makefile5
-rw-r--r--common/bloblist.c239
-rw-r--r--common/board_f.c49
-rw-r--r--common/console.c7
-rw-r--r--common/init/Makefile1
-rw-r--r--common/init/handoff.c47
-rw-r--r--common/spl/Kconfig95
-rw-r--r--common/spl/spl.c135
9 files changed, 626 insertions, 36 deletions
diff --git a/common/Kconfig b/common/Kconfig
index ba460d9150d..57bd16d9623 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -299,6 +299,10 @@ config SPL_LOGLEVEL
int
default LOGLEVEL
+config TPL_LOGLEVEL
+ int
+ default LOGLEVEL
+
config SILENT_CONSOLE
bool "Support a silent console"
help
@@ -505,6 +509,24 @@ config SPL_LOG_MAX_LEVEL
6 - detail
7 - debug
+config TPL_LOG_MAX_LEVEL
+ int "Maximum log level to record in TPL"
+ depends on TPL_LOG
+ default 3
+ help
+ This selects the maximum log level that will be recorded. Any value
+ higher than this will be ignored. If possible log statements below
+ this level will be discarded at build time. Levels:
+
+ 0 - panic
+ 1 - critical
+ 2 - error
+ 3 - warning
+ 4 - note
+ 5 - info
+ 6 - detail
+ 7 - debug
+
config LOG_CONSOLE
bool "Allow log output to the console"
depends on LOG
@@ -515,9 +537,19 @@ config LOG_CONSOLE
log message is shown - other details like level, category, file and
line number are omitted.
-config LOG_SPL_CONSOLE
+config SPL_LOG_CONSOLE
+ bool "Allow log output to the console in SPL"
+ depends on SPL_LOG
+ default y
+ help
+ Enables a log driver which writes log records to the console.
+ Generally the console is the serial port or LCD display. Only the
+ log message is shown - other details like level, category, file and
+ line number are omitted.
+
+config TPL_LOG_CONSOLE
bool "Allow log output to the console in SPL"
- depends on LOG_SPL
+ depends on TPL_LOG
default y
help
Enables a log driver which writes log records to the console.
@@ -718,4 +750,52 @@ config UPDATE_TFTP_MSEC_MAX
endmenu
+menu "Blob list"
+
+config BLOBLIST
+ bool "Support for a bloblist"
+ help
+ This enables support for a bloblist in U-Boot, which can be passed
+ from TPL to SPL to U-Boot proper (and potentially to Linux). The
+ blob list supports multiple binary blobs of data, each with a tag,
+ so that different U-Boot components can store data which can survive
+ through to the next stage of the boot.
+
+config SPL_BLOBLIST
+ bool "Support for a bloblist in SPL"
+ depends on BLOBLIST
+ default y if SPL
+ help
+ This enables a bloblist in SPL. If this is the first part of U-Boot
+ to run, then the bloblist is set up in SPL and passed to U-Boot
+ proper. If TPL also has a bloblist, then SPL uses the one from there.
+
+config TPL_BLOBLIST
+ bool "Support for a bloblist in TPL"
+ depends on BLOBLIST
+ default y if TPL
+ help
+ This enables a bloblist in TPL. The bloblist is set up in TPL and
+ passed to SPL and U-Boot proper.
+
+config BLOBLIST_SIZE
+ hex "Size of bloblist"
+ depends on BLOBLIST
+ default 0x400
+ help
+ Sets the size of the bloblist in bytes. This must include all
+ overhead (alignment, bloblist header, record header). The bloblist
+ is set up in the first part of U-Boot to run (TPL, SPL or U-Boot
+ proper), and this sane bloblist is used for subsequent stages.
+
+config BLOBLIST_ADDR
+ hex "Address of bloblist"
+ depends on BLOBLIST
+ default 0xe000 if SANDBOX
+ help
+ Sets the address of the bloblist, set up by the first part of U-Boot
+ which runs. Subsequent U-Boot stages typically use the same address.
+
+endmenu
+
source "common/spl/Kconfig"
diff --git a/common/Makefile b/common/Makefile
index bbe2a6e2390..88079d1072c 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_CMDLINE) += cli_readline.o cli_simple.o
endif # !CONFIG_SPL_BUILD
obj-$(CONFIG_$(SPL_TPL_)BOOTSTAGE) += bootstage.o
+obj-$(CONFIG_$(SPL_TPL_)BLOBLIST) += bloblist.o
ifdef CONFIG_SPL_BUILD
ifdef CONFIG_SPL_DFU_SUPPORT
@@ -122,8 +123,8 @@ obj-y += cli.o
obj-$(CONFIG_FSL_DDR_INTERACTIVE) += cli_simple.o cli_readline.o
obj-$(CONFIG_DFU_OVER_USB) += dfu.o
obj-y += command.o
-obj-$(CONFIG_$(SPL_)LOG) += log.o
-obj-$(CONFIG_$(SPL_)LOG_CONSOLE) += log_console.o
+obj-$(CONFIG_$(SPL_TPL_)LOG) += log.o
+obj-$(CONFIG_$(SPL_TPL_)LOG_CONSOLE) += log_console.o
obj-y += s_record.o
obj-$(CONFIG_CMD_LOADB) += xyzModem.o
obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o
diff --git a/common/bloblist.c b/common/bloblist.c
new file mode 100644
index 00000000000..b4cf169b05a
--- /dev/null
+++ b/common/bloblist.c
@@ -0,0 +1,239 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <bloblist.h>
+#include <log.h>
+#include <mapmem.h>
+#include <spl.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct bloblist_rec *bloblist_first_blob(struct bloblist_hdr *hdr)
+{
+ if (hdr->alloced <= hdr->hdr_size)
+ return NULL;
+ return (struct bloblist_rec *)((void *)hdr + hdr->hdr_size);
+}
+
+struct bloblist_rec *bloblist_next_blob(struct bloblist_hdr *hdr,
+ struct bloblist_rec *rec)
+{
+ ulong offset;
+
+ offset = (void *)rec - (void *)hdr;
+ offset += rec->hdr_size + ALIGN(rec->size, BLOBLIST_ALIGN);
+ if (offset >= hdr->alloced)
+ return NULL;
+ return (struct bloblist_rec *)((void *)hdr + offset);
+}
+
+#define foreach_rec(_rec, _hdr) \
+ for (_rec = bloblist_first_blob(_hdr); \
+ _rec; \
+ _rec = bloblist_next_blob(_hdr, _rec))
+
+static struct bloblist_rec *bloblist_findrec(uint tag)
+{
+ struct bloblist_hdr *hdr = gd->bloblist;
+ struct bloblist_rec *rec;
+
+ if (!hdr)
+ return NULL;
+
+ foreach_rec(rec, hdr) {
+ if (rec->tag == tag)
+ return rec;
+ }
+
+ return NULL;
+}
+
+static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp)
+{
+ struct bloblist_hdr *hdr = gd->bloblist;
+ struct bloblist_rec *rec;
+ int new_alloced;
+
+ new_alloced = hdr->alloced + sizeof(*rec) +
+ ALIGN(size, BLOBLIST_ALIGN);
+ if (new_alloced >= hdr->size) {
+ log(LOGC_BLOBLIST, LOGL_ERR,
+ "Failed to allocate %x bytes size=%x, need size>=%x\n",
+ size, hdr->size, new_alloced);
+ return log_msg_ret("bloblist add", -ENOSPC);
+ }
+ rec = (void *)hdr + hdr->alloced;
+ hdr->alloced = new_alloced;
+
+ rec->tag = tag;
+ rec->hdr_size = sizeof(*rec);
+ rec->size = size;
+ rec->spare = 0;
+ *recp = rec;
+
+ return 0;
+}
+
+static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size)
+{
+ struct bloblist_rec *rec;
+
+ rec = bloblist_findrec(tag);
+ if (rec) {
+ if (size && size != rec->size)
+ return -ESPIPE;
+ } else {
+ int ret;
+
+ ret = bloblist_addrec(tag, size, &rec);
+ if (ret)
+ return ret;
+ }
+ *recp = rec;
+
+ return 0;
+}
+
+void *bloblist_find(uint tag, int size)
+{
+ struct bloblist_rec *rec;
+
+ rec = bloblist_findrec(tag);
+ if (!rec)
+ return NULL;
+ if (size && size != rec->size)
+ return NULL;
+
+ return (void *)rec + rec->hdr_size;
+}
+
+void *bloblist_add(uint tag, int size)
+{
+ struct bloblist_rec *rec;
+
+ if (bloblist_addrec(tag, size, &rec))
+ return NULL;
+
+ return rec + 1;
+}
+
+int bloblist_ensure_size(uint tag, int size, void **blobp)
+{
+ struct bloblist_rec *rec;
+ int ret;
+
+ ret = bloblist_ensurerec(tag, &rec, size);
+ if (ret)
+ return ret;
+ *blobp = (void *)rec + rec->hdr_size;
+
+ return 0;
+}
+
+void *bloblist_ensure(uint tag, int size)
+{
+ struct bloblist_rec *rec;
+
+ if (bloblist_ensurerec(tag, &rec, size))
+ return NULL;
+
+ return (void *)rec + rec->hdr_size;
+}
+
+static u32 bloblist_calc_chksum(struct bloblist_hdr *hdr)
+{
+ struct bloblist_rec *rec;
+ u32 chksum;
+
+ chksum = crc32(0, (unsigned char *)hdr,
+ offsetof(struct bloblist_hdr, chksum));
+ foreach_rec(rec, hdr) {
+ chksum = crc32(chksum, (void *)rec, rec->hdr_size);
+ chksum = crc32(chksum, (void *)rec + rec->hdr_size, rec->size);
+ }
+
+ return chksum;
+}
+
+int bloblist_new(ulong addr, uint size, uint flags)
+{
+ struct bloblist_hdr *hdr;
+
+ if (size < sizeof(*hdr))
+ return log_ret(-ENOSPC);
+ if (addr & (BLOBLIST_ALIGN - 1))
+ return log_ret(-EFAULT);
+ hdr = map_sysmem(addr, size);
+ memset(hdr, '\0', sizeof(*hdr));
+ hdr->version = BLOBLIST_VERSION;
+ hdr->hdr_size = sizeof(*hdr);
+ hdr->flags = flags;
+ hdr->magic = BLOBLIST_MAGIC;
+ hdr->size = size;
+ hdr->alloced = hdr->hdr_size;
+ hdr->chksum = 0;
+ gd->bloblist = hdr;
+
+ return 0;
+}
+
+int bloblist_check(ulong addr, uint size)
+{
+ struct bloblist_hdr *hdr;
+ u32 chksum;
+
+ hdr = map_sysmem(addr, sizeof(*hdr));
+ if (hdr->magic != BLOBLIST_MAGIC)
+ return log_msg_ret("Bad magic", -ENOENT);
+ if (hdr->version != BLOBLIST_VERSION)
+ return log_msg_ret("Bad version", -EPROTONOSUPPORT);
+ if (size && hdr->size != size)
+ return log_msg_ret("Bad size", -EFBIG);
+ chksum = bloblist_calc_chksum(hdr);
+ if (hdr->chksum != chksum) {
+ log(LOGC_BLOBLIST, LOGL_ERR, "Checksum %x != %x\n", hdr->chksum,
+ chksum);
+ return log_msg_ret("Bad checksum", -EIO);
+ }
+ gd->bloblist = hdr;
+
+ return 0;
+}
+
+int bloblist_finish(void)
+{
+ struct bloblist_hdr *hdr = gd->bloblist;
+
+ hdr->chksum = bloblist_calc_chksum(hdr);
+
+ return 0;
+}
+
+int bloblist_init(void)
+{
+ bool expected;
+ int ret = -ENOENT;
+
+ /**
+ * Wed expect to find an existing bloblist in the first phase of U-Boot
+ * that runs
+ */
+ expected = !u_boot_first_phase();
+ if (expected)
+ ret = bloblist_check(CONFIG_BLOBLIST_ADDR,
+ CONFIG_BLOBLIST_SIZE);
+ if (ret) {
+ log(LOGC_BLOBLIST, expected ? LOGL_WARNING : LOGL_DEBUG,
+ "Existing bloblist not found: creating new bloblist\n");
+ ret = bloblist_new(CONFIG_BLOBLIST_ADDR, CONFIG_BLOBLIST_SIZE,
+ 0);
+ } else {
+ log(LOGC_BLOBLIST, LOGL_DEBUG, "Found existing bloblist\n");
+ }
+
+ return ret;
+}
diff --git a/common/board_f.c b/common/board_f.c
index f1a1432d869..835b7247c58 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -10,6 +10,7 @@
*/
#include <common.h>
+#include <bloblist.h>
#include <console.h>
#include <cpu.h>
#include <dm.h>
@@ -24,6 +25,9 @@
#include <post.h>
#include <relocate.h>
#include <spi.h>
+#ifdef CONFIG_SPL
+#include <spl.h>
+#endif
#include <status_led.h>
#include <sysreset.h>
#include <timer.h>
@@ -285,6 +289,17 @@ static int setup_mon_len(void)
return 0;
}
+static int setup_spl_handoff(void)
+{
+#if CONFIG_IS_ENABLED(HANDOFF)
+ gd->spl_handoff = bloblist_find(BLOBLISTT_SPL_HANDOFF,
+ sizeof(struct spl_handoff));
+ debug("Found SPL hand-off info %p\n", gd->spl_handoff);
+#endif
+
+ return 0;
+}
+
__weak int arch_cpu_init(void)
{
return 0;
@@ -560,6 +575,16 @@ static int reserve_stacks(void)
return arch_reserve_stacks();
}
+static int reserve_bloblist(void)
+{
+#ifdef CONFIG_BLOBLIST
+ gd->start_addr_sp -= CONFIG_BLOBLIST_SIZE;
+ gd->new_bloblist = map_sysmem(gd->start_addr_sp, CONFIG_BLOBLIST_SIZE);
+#endif
+
+ return 0;
+}
+
static int display_new_sp(void)
{
debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
@@ -666,6 +691,24 @@ static int reloc_bootstage(void)
return 0;
}
+static int reloc_bloblist(void)
+{
+#ifdef CONFIG_BLOBLIST
+ if (gd->flags & GD_FLG_SKIP_RELOC)
+ return 0;
+ if (gd->new_bloblist) {
+ int size = CONFIG_BLOBLIST_SIZE;
+
+ debug("Copying bloblist from %p to %p, size %x\n",
+ gd->bloblist, gd->new_bloblist, size);
+ memcpy(gd->new_bloblist, gd->bloblist, size);
+ gd->bloblist = gd->new_bloblist;
+ }
+#endif
+
+ return 0;
+}
+
static int setup_reloc(void)
{
if (gd->flags & GD_FLG_SKIP_RELOC) {
@@ -813,6 +856,10 @@ static const init_fnc_t init_sequence_f[] = {
initf_malloc,
log_init,
initf_bootstage, /* uses its own timer, so does not need DM */
+#ifdef CONFIG_BLOBLIST
+ bloblist_init,
+#endif
+ setup_spl_handoff,
initf_console_record,
#if defined(CONFIG_HAVE_FSP)
arch_fsp_init,
@@ -913,6 +960,7 @@ static const init_fnc_t init_sequence_f[] = {
reserve_global_data,
reserve_fdt,
reserve_bootstage,
+ reserve_bloblist,
reserve_arch,
reserve_stacks,
dram_init_banksize,
@@ -932,6 +980,7 @@ static const init_fnc_t init_sequence_f[] = {
INIT_FUNC_WATCHDOG_RESET
reloc_fdt,
reloc_bootstage,
+ reloc_bloblist,
setup_reloc,
#if defined(CONFIG_X86) || defined(CONFIG_ARC)
copy_uboot_to_ram,
diff --git a/common/console.c b/common/console.c
index 9a94f321922..0b0dd76256c 100644
--- a/common/console.c
+++ b/common/console.c
@@ -535,6 +535,13 @@ void putc(const char c)
void puts(const char *s)
{
+#ifdef CONFIG_SANDBOX
+ /* sandbox can send characters to stdout before it has a console */
+ if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
+ os_puts(s);
+ return;
+ }
+#endif
#ifdef CONFIG_DEBUG_UART
if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
while (*s) {
diff --git a/common/init/Makefile b/common/init/Makefile
index 4902635f535..853b56d1e57 100644
--- a/common/init/Makefile
+++ b/common/init/Makefile
@@ -5,3 +5,4 @@
#
obj-y += board_init.o
+obj-$(CONFIG_$(SPL_TPL_)HANDOFF) += handoff.o
diff --git a/common/init/handoff.c b/common/init/handoff.c
new file mode 100644
index 00000000000..e00b43e6a7b
--- /dev/null
+++ b/common/init/handoff.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Passing basic information from SPL to U-Boot proper
+ *
+ * Copyright 2018 Google, Inc
+ */
+
+#include <common.h>
+#include <handoff.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+void handoff_save_dram(struct spl_handoff *ho)
+{
+ ho->ram_size = gd->ram_size;
+#ifdef CONFIG_NR_DRAM_BANKS
+ {
+ struct bd_info *bd = gd->bd;
+ int i;
+
+ for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+ ho->ram_bank[i].start = bd->bi_dram[i].start;
+ ho->ram_bank[i].size = bd->bi_dram[i].size;
+ }
+ }
+#endif
+}
+
+void handoff_load_dram_size(struct spl_handoff *ho)
+{
+ gd->ram_size = ho->ram_size;
+}
+
+void handoff_load_dram_banks(struct spl_handoff *ho)
+{
+#ifdef CONFIG_NR_DRAM_BANKS
+ {
+ struct bd_info *bd = gd->bd;
+ int i;
+
+ for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+ bd->bi_dram[i].start = ho->ram_bank[i].start;
+ bd->bi_dram[i].size = ho->ram_bank[i].size;
+ }
+ }
+#endif
+}
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index d0564621d4d..0ddbffc7d1c 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -25,8 +25,28 @@ config SPL_FRAMEWORK
supports MMC, NAND and YMODEM and other methods loading of U-Boot
and the Linux Kernel. If unsure, say Y.
+config HANDOFF
+ bool "Pass hand-off information from SPL to U-Boot proper"
+ depends on BLOBLIST
+ help
+ It is useful to be able to pass information from SPL to U-Boot
+ proper to preserve state that is known in SPL and is needed in U-Boot.
+ Enable this to locate the handoff information in U-Boot proper, early
+ in boot. It is available in gd->handoff. The state state is set up
+ in SPL (or TPL if that is being used).
+
if SPL
+config SPL_HANDOFF
+ bool "Pass hand-off information from SPL to U-Boot proper"
+ depends on HANDOFF
+ default y
+ help
+ This option enables SPL to write handoff information. This can be
+ used to pass information like the size of SDRAM from SPL to U-Boot
+ proper. Also SPL can receive information from TPL in the same place
+ if that is enabled.
+
config SPL_LDSCRIPT
string "Linker script for the SPL stage"
default "arch/$(ARCH)/cpu/u-boot-spl.lds"
@@ -135,12 +155,21 @@ config SPL_SEPARATE_BSS
location is used. Normally we put the device tree at the end of BSS
but with this option enabled, it goes at _image_binary_end.
-config SPL_DISABLE_BANNER_PRINT
- bool "Disable output of the SPL banner 'U-Boot SPL ...'"
+config SPL_BANNER_PRINT
+ bool "Enable output of the SPL banner 'U-Boot SPL ...'"
+ default y
+ help
+ If this option is enabled, SPL will print the banner with version
+ info. Disabling this option could be useful to reduce TPL boot time
+ (e.g. approx. 6 ms faster, when output on i.MX6 with 115200 baud).
+
+config TPL_BANNER_PRINT
+ bool "Enable output of the TPL banner 'U-Boot TPL ...'"
+ default y
help
If this option is enabled, SPL will not print the banner with version
- info. Selecting this option could be useful to reduce SPL boot time
- (e.g. approx. 6 ms slower, when output on i.MX6 with 115200 baud).
+ info. Disabling this option could be useful to reduce SPL boot time
+ (e.g. approx. 6 ms faster, when output on i.MX6 with 115200 baud).
config SPL_DISPLAY_PRINT
bool "Display a board-specific message in SPL"
@@ -295,6 +324,16 @@ config SPL_HASH_SUPPORT
this option to build system-specific drivers for hash acceleration
as part of an SPL build.
+config TPL_HASH_SUPPORT
+ bool "Support hashing drivers in TPL"
+ select SHA1
+ select SHA256
+ help
+ Enable hashing drivers in SPL. These drivers can be used to
+ accelerate secure boot processing in secure applications. Enable
+ this option to build system-specific drivers for hash acceleration
+ as part of an SPL build.
+
config SPL_DMA_SUPPORT
bool "Support DMA drivers"
help
@@ -376,7 +415,7 @@ config SPL_FPGA_SUPPORT
within SPL.
config SPL_GPIO_SUPPORT
- bool "Support GPIO"
+ bool "Support GPIO in SPL"
help
Enable support for GPIOs (General-purpose Input/Output) in SPL.
GPIOs allow U-Boot to read the state of an input line (high or
@@ -848,6 +887,16 @@ config TPL
if TPL
+config TPL_HANDOFF
+ bool "Pass hand-off information from TPL to SPL and U-Boot proper"
+ depends on HANDOFF
+ default y
+ help
+ This option enables TPL to write handoff information. This can be
+ used to pass information like the size of SDRAM from TPL to U-Boot
+ proper. The information is also available to SPL if it is useful
+ there.
+
config TPL_BOARD_INIT
bool "Call board-specific initialization in TPL"
help
@@ -928,6 +977,17 @@ config TPL_ENV_SUPPORT
help
Enable environment support in TPL. See SPL_ENV_SUPPORT for details.
+config TPL_GPIO_SUPPORT
+ bool "Support GPIO in TPL"
+ help
+ Enable support for GPIOs (General-purpose Input/Output) in TPL.
+ GPIOs allow U-Boot to read the state of an input line (high or
+ low) and set the state of an output line. This can be used to
+ drive LEDs, control power to various system parts and read user
+ input. GPIOs can be useful in TPL to enable a 'sign-of-life' LED,
+ for example. Enable this option to build the drivers in
+ drivers/gpio as part of an TPL build.
+
config TPL_I2C_SUPPORT
bool "Support I2C"
help
@@ -963,6 +1023,22 @@ config TPL_NAND_SUPPORT
help
Enable support for NAND in TPL. See SPL_NAND_SUPPORT for details.
+config TPL_PCI_SUPPORT
+ bool "Support PCI drivers"
+ help
+ Enable support for PCI in TPL. For platforms that need PCI to boot,
+ or must perform some init using PCI in SPL, this provides the
+ necessary driver support. This enables the drivers in drivers/pci
+ as part of a TPL build.
+
+config TPL_PCH_SUPPORT
+ bool "Support PCH drivers"
+ help
+ Enable support for PCH (Platform Controller Hub) devices in TPL.
+ These are used to set up GPIOs and the SPI peripheral early in
+ boot. This enables the drivers in drivers/pch as part of a TPL
+ build.
+
config TPL_RAM_SUPPORT
bool "Support booting from RAM"
help
@@ -977,6 +1053,15 @@ config TPL_RAM_DEVICE
be already in memory when TPL takes over, e.g. loaded by the boot
ROM.
+config TPL_RTC_SUPPORT
+ bool "Support RTC drivers"
+ help
+ Enable RTC (Real-time Clock) support in TPL. This includes support
+ for reading and setting the time. Some RTC devices also have some
+ non-volatile (battery-backed) memory which is accessible if
+ needed. This enables the drivers in drivers/rtc as part of an TPL
+ build.
+
config TPL_SERIAL_SUPPORT
bool "Support serial"
select TPL_PRINTF
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 12f9359c0ac..35120b6efd1 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -7,8 +7,10 @@
*/
#include <common.h>
+#include <bloblist.h>
#include <binman_sym.h>
#include <dm.h>
+#include <handoff.h>
#include <spl.h>
#include <asm/u-boot.h>
#include <nand.h>
@@ -44,6 +46,14 @@ static bd_t bdata __attribute__ ((section(".data")));
*/
__weak void show_boot_progress(int val) {}
+#if defined(CONFIG_SPL_OS_BOOT) || CONFIG_IS_ENABLED(HANDOFF)
+/* weak, default platform-specific function to initialize dram banks */
+__weak int dram_init_banksize(void)
+{
+ return 0;
+}
+#endif
+
/*
* Default function to determine if u-boot or the OS should
* be started. This implementation always returns 1.
@@ -57,19 +67,12 @@ __weak void show_boot_progress(int val) {}
#ifdef CONFIG_SPL_OS_BOOT
__weak int spl_start_uboot(void)
{
- puts("SPL: Please implement spl_start_uboot() for your board\n");
- puts("SPL: Direct Linux boot not active!\n");
+ puts(SPL_TPL_PROMPT
+ "Please implement spl_start_uboot() for your board\n");
+ puts(SPL_TPL_PROMPT "Direct Linux boot not active!\n");
return 1;
}
-/* weak default platform specific function to initialize
- * dram banks
- */
-__weak int dram_init_banksize(void)
-{
- return 0;
-}
-
/*
* Weak default function for arch specific zImage check. Return zero
* and fill start and end address if image is recognized.
@@ -100,13 +103,13 @@ void spl_fixup_fdt(void)
/* fixup the memory dt node */
err = fdt_shrink_to_minimum(fdt_blob, 0);
if (err == 0) {
- printf("spl: fdt_shrink_to_minimum err - %d\n", err);
+ printf(SPL_TPL_PROMPT "fdt_shrink_to_minimum err - %d\n", err);
return;
}
err = arch_fixup_fdt(fdt_blob);
if (err) {
- printf("spl: arch_fixup_fdt err - %d\n", err);
+ printf(SPL_TPL_PROMPT "arch_fixup_fdt err - %d\n", err);
return;
}
#endif
@@ -185,7 +188,7 @@ static int spl_load_fit_image(struct spl_image_info *spl_image,
spl_image->os = IH_OS_U_BOOT;
spl_image->name = "U-Boot";
- debug("spl: payload image: %32s load addr: 0x%lx size: %d\n",
+ 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
@@ -255,7 +258,8 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
}
spl_image->os = image_get_os(header);
spl_image->name = image_get_name(header);
- debug("spl: payload image: %32s load addr: 0x%lx size: %d\n",
+ debug(SPL_TPL_PROMPT
+ "payload image: %32s load addr: 0x%lx size: %d\n",
spl_image->name, spl_image->load_addr, spl_image->size);
#else
/* LEGACY image not supported */
@@ -284,7 +288,8 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
spl_image->load_addr = CONFIG_SYS_LOAD_ADDR;
spl_image->entry_point = CONFIG_SYS_LOAD_ADDR;
spl_image->size = end - start;
- debug("spl: payload zImage, load addr: 0x%lx size: %d\n",
+ debug(SPL_TPL_PROMPT
+ "payload zImage, load addr: 0x%lx size: %d\n",
spl_image->load_addr, spl_image->size);
return 0;
}
@@ -316,6 +321,44 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
image_entry();
}
+#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;
+
+ ho = bloblist_ensure(BLOBLISTT_SPL_HANDOFF, sizeof(struct spl_handoff));
+ if (!ho)
+ return -ENOENT;
+
+ return 0;
+}
+
+static int write_spl_handoff(void)
+{
+ struct spl_handoff *ho;
+
+ ho = bloblist_find(BLOBLISTT_SPL_HANDOFF, sizeof(struct spl_handoff));
+ if (!ho)
+ return -ENOENT;
+ handoff_save_dram(ho);
+#ifdef CONFIG_SANDBOX
+ ho->arch.magic = TEST_HANDOFF_MAGIC;
+#endif
+ 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 */
+
static int spl_common_init(bool setup_malloc)
{
int ret;
@@ -336,6 +379,30 @@ static int spl_common_init(bool setup_malloc)
return ret;
}
bootstage_mark_name(BOOTSTAGE_ID_START_SPL, "spl");
+#if CONFIG_IS_ENABLED(LOG)
+ ret = log_init();
+ if (ret) {
+ debug("%s: Failed to set up logging\n", __func__);
+ return ret;
+ }
+#endif
+ if (CONFIG_IS_ENABLED(BLOBLIST)) {
+ ret = bloblist_init();
+ if (ret) {
+ debug("%s: Failed to set up bloblist: ret=%d\n",
+ __func__, ret);
+ return ret;
+ }
+ }
+ if (CONFIG_IS_ENABLED(HANDOFF)) {
+ int ret;
+
+ ret = setup_spl_handoff();
+ if (ret) {
+ puts(SPL_TPL_PROMPT "Cannot set up SPL handoff\n");
+ hang();
+ }
+ }
if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) {
ret = fdtdec_setup();
if (ret) {
@@ -359,6 +426,10 @@ static int spl_common_init(bool setup_malloc)
void spl_set_bd(void)
{
+ /*
+ * NOTE: On some platforms (e.g. x86) bdata may be in flash and not
+ * writeable.
+ */
if (!gd->bd)
gd->bd = &bdata;
}
@@ -453,7 +524,7 @@ static int boot_from_devices(struct spl_image_info *spl_image,
if (loader)
printf("Trying to boot from %s\n", loader->name);
else
- puts("SPL: Unsupported Boot Device!\n");
+ puts(SPL_TPL_PROMPT "Unsupported Boot Device!\n");
#endif
if (loader && !spl_load_image(spl_image, loader)) {
spl_image->boot_device = spl_boot_list[i];
@@ -474,15 +545,12 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
BOOT_DEVICE_NONE,
};
struct spl_image_info spl_image;
+ int ret;
- debug(">>spl:board_init_r()\n");
+ debug(">>" SPL_TPL_PROMPT "board_init_r()\n");
spl_set_bd();
-#ifdef CONFIG_SPL_OS_BOOT
- dram_init_banksize();
-#endif
-
#if defined(CONFIG_SYS_SPL_MALLOC_START)
mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
CONFIG_SYS_SPL_MALLOC_SIZE);
@@ -504,6 +572,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
spl_board_init();
#endif
+ if (IS_ENABLED(CONFIG_SPL_OS_BOOT) || CONFIG_IS_ENABLED(HANDOFF))
+ dram_init_banksize();
+
bootcount_inc();
memset(&spl_image, '\0', sizeof(spl_image));
@@ -515,11 +586,23 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
if (boot_from_devices(&spl_image, spl_boot_list,
ARRAY_SIZE(spl_boot_list))) {
- puts("SPL: failed to boot from all boot devices\n");
+ puts(SPL_TPL_PROMPT "failed to boot from all boot devices\n");
hang();
}
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);
+ }
#ifdef CONFIG_CPU_V7M
spl_image.entry_point |= 0x1;
@@ -556,8 +639,6 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
gd->malloc_ptr / 1024);
#endif
#ifdef CONFIG_BOOTSTAGE_STASH
- int ret;
-
bootstage_mark_name(BOOTSTAGE_ID_END_SPL, "end_spl");
ret = bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
CONFIG_BOOTSTAGE_STASH_SIZE);
@@ -583,9 +664,9 @@ void preloader_console_init(void)
gd->have_console = 1;
-#ifndef CONFIG_SPL_DISABLE_BANNER_PRINT
- puts("\nU-Boot SPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
- U_BOOT_TIME " " U_BOOT_TZ ")\n");
+#if CONFIG_IS_ENABLED(BANNER_PRINT)
+ puts("\nU-Boot " SPL_TPL_NAME " " PLAIN_VERSION " (" U_BOOT_DATE " - "
+ U_BOOT_TIME " " U_BOOT_TZ ")\n");
#endif
#ifdef CONFIG_SPL_DISPLAY_PRINT
spl_display_print();