Skip to content

Commit

Permalink
core: dt: add option to generate DTB overlay at boot
Browse files Browse the repository at this point in the history
When using a memory persistent across reboots for external dtb overlay
(DRAM for instance) OP-TEE will reuse the existing dtb overlay if
CFG_EXTERNAL_DTB_OVERLAY is used. This will result in a big overlay
with duplicated nodes. In order to allow having a fresh DTB overlay
at boot, add CFG_GENERATE_DTB_OVERLAY to generate the DTB overlay at
OP-TEE boot time.
Both CFG_GENERATE_DTB_OVERLAY and CFG_EXTERNAL_DTB_OVERLAY will now
consider using the dtb address provided in r2 as well as CFG_DT_ADDR
to create the overlay if not existing.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
clementleger authored and jforissier committed Sep 8, 2021
1 parent 5c50d1f commit c454414
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
24 changes: 10 additions & 14 deletions core/arch/arm/kernel/boot.c
Expand Up @@ -75,7 +75,7 @@ DECLARE_KEEP_PAGER(sem_cpu_sync);
#ifdef CFG_DT
struct dt_descriptor {
void *blob;
#ifdef CFG_EXTERNAL_DTB_OVERLAY
#ifdef _CFG_USE_DTB_OVERLAY
int frag_id;
#endif
};
Expand Down Expand Up @@ -632,7 +632,7 @@ static TEE_Result release_external_dt(void)
}
boot_final(release_external_dt);

#ifdef CFG_EXTERNAL_DTB_OVERLAY
#ifdef _CFG_USE_DTB_OVERLAY
static int add_dt_overlay_fragment(struct dt_descriptor *dt, int ioffs)
{
char frag[32];
Expand All @@ -656,20 +656,16 @@ static int add_dt_overlay_fragment(struct dt_descriptor *dt, int ioffs)
static int init_dt_overlay(struct dt_descriptor *dt, int __maybe_unused dt_size)
{
int fragment;
int ret;

ret = fdt_check_header(dt->blob);
if (!ret) {
fdt_for_each_subnode(fragment, dt->blob, 0)
dt->frag_id += 1;
return ret;
if (IS_ENABLED(CFG_EXTERNAL_DTB_OVERLAY)) {
if (!fdt_check_header(dt->blob)) {
fdt_for_each_subnode(fragment, dt->blob, 0)
dt->frag_id += 1;
return 0;
}
}

#ifdef CFG_DT_ADDR
return fdt_create_empty_tree(dt->blob, dt_size);
#else
return -1;
#endif
}
#else
static int add_dt_overlay_fragment(struct dt_descriptor *dt __unused, int offs)
Expand All @@ -682,7 +678,7 @@ static int init_dt_overlay(struct dt_descriptor *dt __unused,
{
return 0;
}
#endif /* CFG_EXTERNAL_DTB_OVERLAY */
#endif /* _CFG_USE_DTB_OVERLAY */

static int add_dt_path_subnode(struct dt_descriptor *dt, const char *path,
const char *subnode)
Expand Down Expand Up @@ -858,7 +854,7 @@ static int add_res_mem_dt_node(struct dt_descriptor *dt, const char *name,
offs = 0;
}

if (IS_ENABLED(CFG_EXTERNAL_DTB_OVERLAY)) {
if (IS_ENABLED(_CFG_USE_DTB_OVERLAY)) {
len_size = sizeof(paddr_t) / sizeof(uint32_t);
addr_size = sizeof(paddr_t) / sizeof(uint32_t);
} else {
Expand Down
20 changes: 14 additions & 6 deletions mk/config.mk
Expand Up @@ -425,14 +425,22 @@ CFG_DT ?= n
CFG_DTB_MAX_SIZE ?= 0x10000

# Device Tree Overlay support.
# This define enables support for an OP-TEE provided DTB overlay.
# One of two modes is supported in this case:
# 1. Append OP-TEE nodes to an existing DTB overlay located at CFG_DT_ADDR or
# passed in arg2
# 2. Generate a new DTB overlay at CFG_DT_ADDR
# A subsequent boot stage must then merge the generated overlay DTB into a main
# CFG_EXTERNAL_DTB_OVERLAY allows to append a DTB overlay into an existing
# external DTB. The overlay is created when no valid DTB overlay is found.
# CFG_GENERATE_DTB_OVERLAY allows to create a DTB overlay at external
# DTB location.
# External DTB location (physical address) is provided either by boot
# argument arg2 or from CFG_DT_ADDR if defined.
# A subsequent boot stage can then merge the generated overlay DTB into a main
# DTB using the standard fdt_overlay_apply() method.
CFG_EXTERNAL_DTB_OVERLAY ?= n
CFG_GENERATE_DTB_OVERLAY ?= n

ifeq (y-y,$(CFG_EXTERNAL_DTB_OVERLAY)-$(CFG_GENERATE_DTB_OVERLAY))
$(error CFG_EXTERNAL_DTB_OVERLAY and CFG_GENERATE_DTB_OVERLAY are exclusive)
endif
_CFG_USE_DTB_OVERLAY := $(call cfg-one-enabled,CFG_EXTERNAL_DTB_OVERLAY \
CFG_GENERATE_DTB_OVERLAY)

# All embedded tests are supposed to be disabled by default, this flag
# is used to control the default value of all other embedded tests
Expand Down

0 comments on commit c454414

Please sign in to comment.