u-boot/include/tee/optee.h
Alexandru Gagniuc 26fc66709c lib: optee: Avoid CONFIG_TZDRAM_* in optee_verify_bootm_image()
The configs TZDRAM_BASE and TZDRAM_SIZE are expected to describe the
memory allocated to the OPTEE region. according to according to commit
c5a6e8bd00 ("optee: Add optee_verify_bootm_image()"). The TZDRAM is
with some limitations, described by "/reserved-memory" nodes in the
devicetree.

Consequently TZDRAM_BASE and TZDRAM_SIZE can point to imaginary
regions which have nothing to do with actual DRAM. They are not used
to configure the hardware or set up the Trust Zone Controller (TZC)
for OP-TEE -- the devicetree values are used instead.

When a valid OP-TEE image does not fall within the region described by
these configs, u-boot will refuse to load it. In fact, it mostly
serves to cause "bootm" to reject perfectly good OP-TEE images.

Ironically, someone has to correctly configure the devicetree for
TZDRAM, then go back and enter the same information in Kconfig for
"bootm". To remedy this, do not use TZDRAM_BASE and TZDRAM_SIZE in the
verification of OPTEE images.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
2021-10-05 08:46:23 -04:00

68 lines
1.5 KiB
C

/* SPDX-License-Identifier: BSD-2-Clause */
/*
* OP-TEE related definitions
*
* (C) Copyright 2016 Linaro Limited
* Andrew F. Davis <andrew.davis@linaro.org>
*/
#ifndef _OPTEE_H
#define _OPTEE_H
#include <linux/errno.h>
#include <image.h>
#define OPTEE_MAGIC 0x4554504f
#define OPTEE_VERSION 1
#define OPTEE_ARCH_ARM32 0
#define OPTEE_ARCH_ARM64 1
struct optee_header {
uint32_t magic;
uint8_t version;
uint8_t arch;
uint16_t flags;
uint32_t init_size;
uint32_t init_load_addr_hi;
uint32_t init_load_addr_lo;
uint32_t init_mem_usage;
uint32_t paged_size;
};
static inline uint32_t
optee_image_get_entry_point(const struct image_header *hdr)
{
struct optee_header *optee_hdr = (struct optee_header *)(hdr + 1);
return optee_hdr->init_load_addr_lo;
}
static inline uint32_t
optee_image_get_load_addr(const struct image_header *hdr)
{
return optee_image_get_entry_point(hdr) - sizeof(struct optee_header);
}
#if defined(CONFIG_OPTEE_IMAGE)
int optee_verify_bootm_image(unsigned long image_addr,
unsigned long image_load_addr,
unsigned long image_len);
#else
static inline int optee_verify_bootm_image(unsigned long image_addr,
unsigned long image_load_addr,
unsigned long image_len)
{
return -EPERM;
}
#endif
#if defined(CONFIG_OPTEE_LIB) && defined(CONFIG_OF_LIBFDT)
int optee_copy_fdt_nodes(void *new_blob);
#else
static inline int optee_copy_fdt_nodes(void *new_blob)
{
return 0;
}
#endif
#endif /* _OPTEE_H */