summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/avb_verify.c125
-rw-r--r--common/board_f.c2
-rw-r--r--common/board_r.c4
-rw-r--r--common/bootstage.c7
-rw-r--r--common/cli.c1
-rw-r--r--common/command.c14
-rw-r--r--common/image-fdt.c33
-rw-r--r--common/spl/Kconfig7
-rw-r--r--common/spl/spl.c5
9 files changed, 181 insertions, 17 deletions
diff --git a/common/avb_verify.c b/common/avb_verify.c
index a8c5a3e7db..32034d927c 100644
--- a/common/avb_verify.c
+++ b/common/avb_verify.c
@@ -647,6 +647,10 @@ static AvbIOResult invoke_func(struct AvbOpsData *ops_data, u32 func,
return AVB_IO_RESULT_OK;
case TEE_ERROR_OUT_OF_MEMORY:
return AVB_IO_RESULT_ERROR_OOM;
+ case TEE_ERROR_STORAGE_NO_SPACE:
+ return AVB_IO_RESULT_ERROR_INSUFFICIENT_SPACE;
+ case TEE_ERROR_ITEM_NOT_FOUND:
+ return AVB_IO_RESULT_ERROR_NO_SUCH_VALUE;
case TEE_ERROR_TARGET_DEAD:
/*
* The TA has paniced, close the session to reload the TA
@@ -847,6 +851,123 @@ static AvbIOResult get_size_of_partition(AvbOps *ops,
return AVB_IO_RESULT_OK;
}
+static AvbIOResult read_persistent_value(AvbOps *ops,
+ const char *name,
+ size_t buffer_size,
+ u8 *out_buffer,
+ size_t *out_num_bytes_read)
+{
+ AvbIOResult rc;
+ struct tee_shm *shm_name;
+ struct tee_shm *shm_buf;
+ struct tee_param param[2];
+ struct udevice *tee;
+ size_t name_size = strlen(name) + 1;
+
+ if (get_open_session(ops->user_data))
+ return AVB_IO_RESULT_ERROR_IO;
+
+ tee = ((struct AvbOpsData *)ops->user_data)->tee;
+
+ rc = tee_shm_alloc(tee, name_size,
+ TEE_SHM_ALLOC, &shm_name);
+ if (rc)
+ return AVB_IO_RESULT_ERROR_OOM;
+
+ rc = tee_shm_alloc(tee, buffer_size,
+ TEE_SHM_ALLOC, &shm_buf);
+ if (rc) {
+ rc = AVB_IO_RESULT_ERROR_OOM;
+ goto free_name;
+ }
+
+ memcpy(shm_name->addr, name, name_size);
+
+ memset(param, 0, sizeof(param));
+ param[0].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT;
+ param[0].u.memref.shm = shm_name;
+ param[0].u.memref.size = name_size;
+ param[1].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INOUT;
+ param[1].u.memref.shm = shm_buf;
+ param[1].u.memref.size = buffer_size;
+
+ rc = invoke_func(ops->user_data, TA_AVB_CMD_READ_PERSIST_VALUE,
+ 2, param);
+ if (rc)
+ goto out;
+
+ if (param[1].u.memref.size > buffer_size) {
+ rc = AVB_IO_RESULT_ERROR_NO_SUCH_VALUE;
+ goto out;
+ }
+
+ *out_num_bytes_read = param[1].u.memref.size;
+
+ memcpy(out_buffer, shm_buf->addr, *out_num_bytes_read);
+
+out:
+ tee_shm_free(shm_buf);
+free_name:
+ tee_shm_free(shm_name);
+
+ return rc;
+}
+
+static AvbIOResult write_persistent_value(AvbOps *ops,
+ const char *name,
+ size_t value_size,
+ const u8 *value)
+{
+ AvbIOResult rc;
+ struct tee_shm *shm_name;
+ struct tee_shm *shm_buf;
+ struct tee_param param[2];
+ struct udevice *tee;
+ size_t name_size = strlen(name) + 1;
+
+ if (get_open_session(ops->user_data))
+ return AVB_IO_RESULT_ERROR_IO;
+
+ tee = ((struct AvbOpsData *)ops->user_data)->tee;
+
+ if (!value_size)
+ return AVB_IO_RESULT_ERROR_NO_SUCH_VALUE;
+
+ rc = tee_shm_alloc(tee, name_size,
+ TEE_SHM_ALLOC, &shm_name);
+ if (rc)
+ return AVB_IO_RESULT_ERROR_OOM;
+
+ rc = tee_shm_alloc(tee, value_size,
+ TEE_SHM_ALLOC, &shm_buf);
+ if (rc) {
+ rc = AVB_IO_RESULT_ERROR_OOM;
+ goto free_name;
+ }
+
+ memcpy(shm_name->addr, name, name_size);
+ memcpy(shm_buf->addr, value, value_size);
+
+ memset(param, 0, sizeof(param));
+ param[0].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT;
+ param[0].u.memref.shm = shm_name;
+ param[0].u.memref.size = name_size;
+ param[1].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT;
+ param[1].u.memref.shm = shm_buf;
+ param[1].u.memref.size = value_size;
+
+ rc = invoke_func(ops->user_data, TA_AVB_CMD_WRITE_PERSIST_VALUE,
+ 2, param);
+ if (rc)
+ goto out;
+
+out:
+ tee_shm_free(shm_buf);
+free_name:
+ tee_shm_free(shm_name);
+
+ return rc;
+}
/**
* ============================================================================
* AVB2.0 AvbOps alloc/initialisation/free
@@ -870,6 +991,10 @@ AvbOps *avb_ops_alloc(int boot_device)
ops_data->ops.read_is_device_unlocked = read_is_device_unlocked;
ops_data->ops.get_unique_guid_for_partition =
get_unique_guid_for_partition;
+#ifdef CONFIG_OPTEE_TA_AVB
+ ops_data->ops.write_persistent_value = write_persistent_value;
+ ops_data->ops.read_persistent_value = read_persistent_value;
+#endif
ops_data->ops.get_size_of_partition = get_size_of_partition;
ops_data->mmc_dev = boot_device;
diff --git a/common/board_f.c b/common/board_f.c
index 149a7229e8..7ef20f2042 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -714,7 +714,7 @@ static int setup_reloc(void)
* just after the default vector table location, so at 0x400
*/
gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
-#else
+#elif !defined(CONFIG_SANDBOX)
gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
#endif
#endif
diff --git a/common/board_r.c b/common/board_r.c
index 1ad44bbe3f..150e8cd424 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -48,6 +48,7 @@
#include <linux/compiler.h>
#include <linux/err.h>
#include <efi_loader.h>
+#include <wdt.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -677,6 +678,9 @@ static init_fnc_t init_sequence_r[] = {
#ifdef CONFIG_DM
initr_dm,
#endif
+#if defined(CONFIG_WDT)
+ initr_watchdog,
+#endif
#if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV) || \
defined(CONFIG_SANDBOX)
board_init, /* Setup chipselects */
diff --git a/common/bootstage.c b/common/bootstage.c
index 9793b85d4e..56ef91ad85 100644
--- a/common/bootstage.c
+++ b/common/bootstage.c
@@ -99,6 +99,13 @@ ulong bootstage_add_record(enum bootstage_id id, const char *name,
struct bootstage_data *data = gd->bootstage;
struct bootstage_record *rec;
+ /*
+ * initf_bootstage() is called very early during boot but since hang()
+ * calls bootstage_error() we can be called before bootstage is set up.
+ * Add a check to avoid this.
+ */
+ if (!data)
+ return mark;
if (flags & BOOTSTAGEF_ALLOC)
id = data->next_id++;
diff --git a/common/cli.c b/common/cli.c
index fea8f8004c..f4054fb1fc 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -213,6 +213,7 @@ err:
void cli_loop(void)
{
+ bootstage_mark(BOOTSTAGE_ID_ENTER_CLI_LOOP);
#ifdef CONFIG_HUSH_PARSER
parse_file_outer();
/* This point is never reached */
diff --git a/common/command.c b/common/command.c
index e14d1fa1d6..e192bb2a61 100644
--- a/common/command.c
+++ b/common/command.c
@@ -574,6 +574,20 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
enum command_ret_t rc = CMD_RET_SUCCESS;
cmd_tbl_t *cmdtp;
+#if defined(CONFIG_SYS_XTRACE)
+ char *xtrace;
+
+ xtrace = env_get("xtrace");
+ if (xtrace) {
+ puts("+");
+ for (int i = 0; i < argc; i++) {
+ puts(" ");
+ puts(argv[i]);
+ }
+ puts("\n");
+ }
+#endif
+
/* Look up command in command table */
cmdtp = find_cmd(argv[0]);
if (cmdtp == NULL) {
diff --git a/common/image-fdt.c b/common/image-fdt.c
index 9ed00b7d5b..eb552ca207 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -279,7 +279,6 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
int fdt_noffset;
#endif
const char *select = NULL;
- int ok_no_fdt = 0;
*of_flat_tree = NULL;
*of_size = 0;
@@ -462,17 +461,24 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
struct andr_img_hdr *hdr = buf;
ulong fdt_data, fdt_len;
- if (android_image_get_second(hdr, &fdt_data, &fdt_len) != 0)
- goto no_fdt;
+ if (!android_image_get_second(hdr, &fdt_data, &fdt_len) &&
+ !fdt_check_header((char *)fdt_data)) {
+ fdt_blob = (char *)fdt_data;
+ if (fdt_totalsize(fdt_blob) != fdt_len)
+ goto error;
- fdt_blob = (char *)fdt_data;
- if (fdt_check_header(fdt_blob) != 0)
- goto no_fdt;
+ debug("## Using FDT in Android image second area\n");
+ } else {
+ fdt_addr = env_get_hex("fdtaddr", 0);
+ if (!fdt_addr)
+ goto no_fdt;
- if (fdt_totalsize(fdt_blob) != fdt_len)
- goto error;
+ fdt_blob = map_sysmem(fdt_addr, 0);
+ if (fdt_check_header(fdt_blob))
+ goto no_fdt;
- debug("## Using FDT found in Android image second area\n");
+ debug("## Using FDT at ${fdtaddr}=Ox%lx\n", fdt_addr);
+ }
#endif
} else {
debug("## No Flattened Device Tree\n");
@@ -487,14 +493,9 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
return 0;
no_fdt:
- ok_no_fdt = 1;
+ debug("Continuing to boot without FDT\n");
+ return 0;
error:
- *of_flat_tree = NULL;
- *of_size = 0;
- if (!select && ok_no_fdt) {
- debug("Continuing to boot without FDT\n");
- return 0;
- }
return 1;
}
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 206c24076d..dd078fe79d 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -56,6 +56,13 @@ config SPL_LDSCRIPT
U-Boot stage. Set this to the path of the linker-script to
be used for SPL.
+config SPL_TEXT_BASE
+ hex "SPL Text Base"
+ default ISW_ENTRY_ADDR if AM43XX || AM33XX || OMAP54XX || ARCH_KEYSTONE
+ default 0x0
+ help
+ The address in memory that SPL will be running from.
+
config SPL_BOARD_INIT
bool "Call board-specific initialization in SPL"
help
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 88d4b8a9bf..0a6a47c202 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -22,6 +22,7 @@
#include <linux/compiler.h>
#include <fdt_support.h>
#include <bootcount.h>
+#include <wdt.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -600,6 +601,10 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
spl_board_init();
#endif
+#if defined(CONFIG_SPL_WATCHDOG_SUPPORT) && defined(CONFIG_WDT)
+ initr_watchdog();
+#endif
+
if (IS_ENABLED(CONFIG_SPL_OS_BOOT) || CONFIG_IS_ENABLED(HANDOFF))
dram_init_banksize();