[PATCH 10/18] optee: add helper functions to set/get the optee memory base
Marco Felsch
m.felsch at pengutronix.de
Thu Jan 11 03:48:33 PST 2024
Provide helper functions to set/get the optee memory base address
gathered previously from the builtin optee binary header.
Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
common/optee.c | 27 +++++++++++++++++++++++++++
include/tee/optee.h | 2 ++
2 files changed, 29 insertions(+)
diff --git a/common/optee.c b/common/optee.c
index 6a8084839619..2ae28b172bbb 100644
--- a/common/optee.c
+++ b/common/optee.c
@@ -6,8 +6,13 @@
#include <linux/printk.h>
#include <linux/errno.h>
+static u64 optee_membase = U64_MAX;
+
int optee_verify_header(struct optee_header *hdr)
{
+ if (!hdr)
+ return -EINVAL;
+
if (hdr->magic != OPTEE_MAGIC) {
pr_err("Invalid header magic 0x%08x, expected 0x%08x\n",
hdr->magic, OPTEE_MAGIC);
@@ -32,3 +37,25 @@ int optee_verify_header(struct optee_header *hdr)
return 0;
}
+
+int optee_get_membase(u64 *membase)
+{
+ if (optee_membase == U64_MAX)
+ return -EINVAL;
+
+ *membase = optee_membase;
+
+ return 0;
+}
+
+void optee_set_membase(const struct optee_header *hdr)
+{
+ int ret;
+
+ ret = optee_verify_header(hdr);
+ if (ret)
+ return;
+
+ optee_membase = (u64)hdr->init_load_addr_hi << 32;
+ optee_membase |= hdr->init_load_addr_lo;
+}
diff --git a/include/tee/optee.h b/include/tee/optee.h
index b5ba0a71d7c9..7bd6638f8559 100644
--- a/include/tee/optee.h
+++ b/include/tee/optee.h
@@ -32,6 +32,8 @@ struct optee_header {
};
int optee_verify_header (struct optee_header *hdr);
+void optee_set_membase(const struct optee_header *hdr);
+int optee_get_membase(u64 *membase);
#ifdef __PBL__
--
2.39.2
More information about the barebox
mailing list