diff --git a/arch/arm/lib32/bootm.c b/arch/arm/lib32/bootm.c index 1806244..d64e705 100644 --- a/arch/arm/lib32/bootm.c +++ b/arch/arm/lib32/bootm.c @@ -137,16 +137,10 @@ static int optee_verify_header_request_region(struct image_data *data, struct optee_header *hdr) { int ret = 0; - if (hdr->magic != OPTEE_MAGIC) { - pr_err("Invalid header magic 0x%08x, expected 0x%08x\n", - hdr->magic, OPTEE_MAGIC); - return -EINVAL; - } - if (hdr->arch != OPTEE_ARCH_ARM32 || hdr->init_load_addr_hi) { - pr_err("Only 32bit supported\n"); - return -EINVAL; - } + ret = optee_verify_header(hdr); + if (ret < 0) + return ret; data->tee_res = request_sdram_region("TEE", hdr->init_load_addr_lo, hdr->init_size); if (!data->tee_res) { diff --git a/common/Makefile b/common/Makefile index 11c91dd..c86db71 100644 --- a/common/Makefile +++ b/common/Makefile @@ -67,6 +67,7 @@ obj-$(CONFIG_BOOT) += boot.o obj-$(CONFIG_SERIAL_DEV_BUS) += serdev.o obj-$(CONFIG_USBGADGET_START) += usbgadget.o +obj-$(CONFIG_BOOTM_OPTEE) += optee.o ifdef CONFIG_PASSWORD diff --git a/common/optee.c b/common/optee.c new file mode 100644 index 0000000..d542dde --- /dev/null +++ b/common/optee.c @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define pr_fmt(fmt) "optee: " fmt + +#include +#include +#include + +int optee_verify_header(struct optee_header *hdr) +{ + if (hdr->magic != OPTEE_MAGIC) { + pr_err("Invalid header magic 0x%08x, expected 0x%08x\n", + hdr->magic, OPTEE_MAGIC); + return -EINVAL; + } + + if (hdr->arch != OPTEE_ARCH_ARM32 || hdr->init_load_addr_hi) { + pr_err("Only 32bit supported\n"); + return -EINVAL; + } + + return 0; +} diff --git a/include/tee/optee.h b/include/tee/optee.h index 8cfe06d..9fb27fc 100644 --- a/include/tee/optee.h +++ b/include/tee/optee.h @@ -10,6 +10,9 @@ #ifndef _OPTEE_H #define _OPTEE_H +#include +#include + #define OPTEE_MAGIC 0x4554504f #define OPTEE_VERSION 1 #define OPTEE_ARCH_ARM32 0 @@ -27,4 +30,6 @@ uint32_t paged_size; }; +int optee_verify_header (struct optee_header *hdr); + #endif /* _OPTEE_H */