aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSandrine Bailleux <sandrine.bailleux@arm.com>2020-02-11 16:15:45 +0000
committerTrustedFirmware Code Review <review@review.trustedfirmware.org>2020-02-11 16:15:45 +0000
commit21c4f56fa7335fbfd3aeb1175b38b84ef9c798ec (patch)
treeaa6c50e7b657592f39dc2c4286095575eda0a5c6 /lib
parent63aa4094fb08d262546afa51d33611a8be0bc4d2 (diff)
parent97399821256653115c9d6b5d3233934aa7689c0c (diff)
downloadplatform_external_arm-trusted-firmware-21c4f56fa7335fbfd3aeb1175b38b84ef9c798ec.tar.gz
platform_external_arm-trusted-firmware-21c4f56fa7335fbfd3aeb1175b38b84ef9c798ec.tar.bz2
platform_external_arm-trusted-firmware-21c4f56fa7335fbfd3aeb1175b38b84ef9c798ec.zip
Merge changes from topic "lm/fconf" into integration
* changes: arm-io: Panic in case of io setup failure MISRA fix: Use boolean essential type fconf: Add documentation fconf: Move platform io policies into fconf fconf: Add mbedtls shared heap as property fconf: Add TBBR disable_authentication property fconf: Add dynamic config DTBs info as property fconf: Populate properties from dtb during bl2 setup fconf: Load config dtb from bl1 fconf: initial commit
Diffstat (limited to 'lib')
-rw-r--r--lib/fconf/fconf.c85
-rw-r--r--lib/fconf/fconf.mk12
-rw-r--r--lib/fconf/fconf_dyn_cfg_getter.c95
-rw-r--r--lib/fconf/fconf_tbbr_getter.c75
4 files changed, 267 insertions, 0 deletions
diff --git a/lib/fconf/fconf.c b/lib/fconf/fconf.c
new file mode 100644
index 000000000..a6da56b00
--- /dev/null
+++ b/lib/fconf/fconf.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2019-2020, ARM Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+
+#include <common/debug.h>
+#include <common/fdt_wrappers.h>
+#include <lib/fconf/fconf.h>
+#include <libfdt.h>
+#include <plat/common/platform.h>
+#include <platform_def.h>
+
+struct fconf_dtb_info_t fconf_dtb_info;
+
+void fconf_load_config(void)
+{
+ int err;
+ /* fconf FW_CONFIG and TB_FW_CONFIG are currently the same DTB */
+ image_info_t arm_tb_fw_info = {
+ .h.type = (uint8_t)PARAM_IMAGE_BINARY,
+ .h.version = (uint8_t)VERSION_2,
+ .h.size = (uint16_t)sizeof(image_info_t),
+ .h.attr = 0,
+ .image_base = ARM_TB_FW_CONFIG_BASE,
+ .image_max_size = (uint32_t)
+ (ARM_TB_FW_CONFIG_LIMIT - ARM_TB_FW_CONFIG_BASE)
+ };
+
+ VERBOSE("FCONF: Loading FW_CONFIG\n");
+ err = load_auth_image(TB_FW_CONFIG_ID, &arm_tb_fw_info);
+ if (err != 0) {
+ /* Return if FW_CONFIG is not loaded */
+ VERBOSE("Failed to load FW_CONFIG\n");
+ return;
+ }
+
+ /* At this point we know that a DTB is indeed available */
+ fconf_dtb_info.base_addr = arm_tb_fw_info.image_base;
+ fconf_dtb_info.size = (size_t)arm_tb_fw_info.image_size;
+
+#if !BL2_AT_EL3
+ image_desc_t *desc;
+
+ /* The BL2 ep_info arg0 is modified to point to FW_CONFIG */
+ desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
+ assert(desc != NULL);
+ desc->ep_info.args.arg0 = arm_tb_fw_info.image_base;
+#endif
+
+ INFO("FCONF: FW_CONFIG loaded at address = 0x%lx\n", arm_tb_fw_info.image_base);
+}
+
+void fconf_populate(uintptr_t config)
+{
+ assert(config != 0UL);
+
+ /* Check if the pointer to DTB is correct */
+ if (fdt_check_header((void *)config) != 0) {
+ ERROR("FCONF: Invalid DTB file passed for FW_CONFIG\n");
+ panic();
+ }
+
+ INFO("FCONF: Reading firmware configuration file from: 0x%lx\n", config);
+
+ /* Go through all registered populate functions */
+ IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_START__, start);
+ IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_END__, end);
+ const struct fconf_populator *populator;
+
+ for (populator = start; populator != end; populator++) {
+ assert((populator->info != NULL) && (populator->populate != NULL));
+
+ INFO("FCONF: Reading firmware configuration information for: %s\n", populator->info);
+ if (populator->populate(config) != 0) {
+ /* TODO: handle property miss */
+ panic();
+ }
+ }
+
+ /* save local pointer to the config dtb */
+ fconf_dtb_info.base_addr = config;
+}
diff --git a/lib/fconf/fconf.mk b/lib/fconf/fconf.mk
new file mode 100644
index 000000000..703196949
--- /dev/null
+++ b/lib/fconf/fconf.mk
@@ -0,0 +1,12 @@
+#
+# Copyright (c) 2019-2020, ARM Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Add Firmware Configuration files
+FCONF_SOURCES := lib/fconf/fconf.c \
+ lib/fconf/fconf_dyn_cfg_getter.c
+
+BL1_SOURCES += ${FCONF_SOURCES}
+BL2_SOURCES += ${FCONF_SOURCES}
diff --git a/lib/fconf/fconf_dyn_cfg_getter.c b/lib/fconf/fconf_dyn_cfg_getter.c
new file mode 100644
index 000000000..d313a5618
--- /dev/null
+++ b/lib/fconf/fconf_dyn_cfg_getter.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+
+#include <common/debug.h>
+#include <common/fdt_wrappers.h>
+#include <lib/fconf/fconf_dyn_cfg_getter.h>
+#include <lib/object_pool.h>
+#include <libfdt.h>
+
+/* We currently use TB_FW, SOC_FW, TOS_FW, NS_fw and HW configs */
+#define MAX_DTB_INFO U(5)
+
+static struct dyn_cfg_dtb_info_t dtb_infos[MAX_DTB_INFO];
+static OBJECT_POOL_ARRAY(dtb_info_pool, dtb_infos);
+
+struct dyn_cfg_dtb_info_t *dyn_cfg_dtb_info_getter(unsigned int config_id)
+{
+ unsigned int index;
+ struct dyn_cfg_dtb_info_t *info;
+
+ /* Positions index to the proper config-id */
+ for (index = 0; index < MAX_DTB_INFO; index++) {
+ if (dtb_infos[index].config_id == config_id) {
+ info = &dtb_infos[index];
+ break;
+ }
+ }
+
+ if (index == MAX_DTB_INFO) {
+ WARN("FCONF: Invalid config id %u\n", config_id);
+ info = NULL;
+ }
+
+ return info;
+}
+
+int fconf_populate_dtb_registry(uintptr_t config)
+{
+ int rc;
+ int node, child;
+ struct dyn_cfg_dtb_info_t *dtb_info;
+
+ /* As libfdt use void *, we can't avoid this cast */
+ const void *dtb = (void *)config;
+
+ /* Find the node offset point to "arm,dyn_cfg-dtb_registry" compatible property */
+ const char *compatible_str = "arm,dyn_cfg-dtb_registry";
+ node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
+ if (node < 0) {
+ ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
+ return node;
+ }
+
+ fdt_for_each_subnode(child, dtb, node) {
+ dtb_info = pool_alloc(&dtb_info_pool);
+
+ /* Read configuration dtb information */
+ rc = fdtw_read_cells(dtb, child, "load-address", 2, &dtb_info->config_addr);
+ if (rc < 0) {
+ ERROR("FCONF: Incomplete configuration property in dtb-registry.\n");
+ return rc;
+ }
+
+ rc = fdtw_read_cells(dtb, child, "max-size", 1, &dtb_info->config_max_size);
+ if (rc < 0) {
+ ERROR("FCONF: Incomplete configuration property in dtb-registry.\n");
+ return rc;
+ }
+
+ rc = fdtw_read_cells(dtb, child, "id", 1, &dtb_info->config_id);
+ if (rc < 0) {
+ ERROR("FCONF: Incomplete configuration property in dtb-registry.\n");
+ return rc;
+ }
+
+ VERBOSE("FCONF: dyn_cfg.dtb_registry cell found with:\n");
+ VERBOSE("\tload-address = %lx\n", dtb_info->config_addr);
+ VERBOSE("\tmax-size = 0x%zx\n", dtb_info->config_max_size);
+ VERBOSE("\tconfig-id = %u\n", dtb_info->config_id);
+ }
+
+ if ((child < 0) && (child != -FDT_ERR_NOTFOUND)) {
+ ERROR("%d: fdt_for_each_subnode(): %d\n", __LINE__, node);
+ return child;
+ }
+
+ return 0;
+}
+
+FCONF_REGISTER_POPULATOR(dyn_cfg, fconf_populate_dtb_registry);
diff --git a/lib/fconf/fconf_tbbr_getter.c b/lib/fconf/fconf_tbbr_getter.c
new file mode 100644
index 000000000..c6df9c876
--- /dev/null
+++ b/lib/fconf/fconf_tbbr_getter.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2019-2020, ARM Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+#include <assert.h>
+
+#include <common/bl_common.h>
+#include <common/debug.h>
+#include <common/fdt_wrappers.h>
+#include <lib/fconf/fconf_tbbr_getter.h>
+#include <libfdt.h>
+
+struct tbbr_dyn_config_t tbbr_dyn_config;
+
+int fconf_populate_tbbr_dyn_config(uintptr_t config)
+{
+ int err;
+ int node;
+
+ /* As libfdt use void *, we can't avoid this cast */
+ const void *dtb = (void *)config;
+
+ /* Assert the node offset point to "arm,tb_fw" compatible property */
+ const char *compatible_str = "arm,tb_fw";
+ node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
+ if (node < 0) {
+ ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
+ return node;
+ }
+
+ /* Locate the disable_auth cell and read the value */
+ err = fdtw_read_cells(dtb, node, "disable_auth", 1, &tbbr_dyn_config.disable_auth);
+ if (err < 0) {
+ WARN("FCONF: Read cell failed for `disable_auth`\n");
+ return err;
+ }
+
+ /* Check if the value is boolean */
+ if ((tbbr_dyn_config.disable_auth != 0U) && (tbbr_dyn_config.disable_auth != 1U)) {
+ WARN("Invalid value for `disable_auth` cell %d\n", tbbr_dyn_config.disable_auth);
+ return -1;
+ }
+
+#if defined(DYN_DISABLE_AUTH)
+ if (tbbr_dyn_config.disable_auth == 1)
+ dyn_disable_auth();
+#endif
+
+ /* Retrieve the Mbed TLS heap details from the DTB */
+ err = fdtw_read_cells(dtb, node,
+ "mbedtls_heap_addr", 2, &tbbr_dyn_config.mbedtls_heap_addr);
+ if (err < 0) {
+ ERROR("FCONF: Read cell failed for mbedtls_heap\n");
+ return err;
+ }
+
+ err = fdtw_read_cells(dtb, node,
+ "mbedtls_heap_size", 1, &tbbr_dyn_config.mbedtls_heap_size);
+ if (err < 0) {
+ ERROR("FCONF: Read cell failed for mbedtls_heap\n");
+ return err;
+ }
+
+ VERBOSE("FCONF:tbbr.disable_auth cell found with value = %d\n",
+ tbbr_dyn_config.disable_auth);
+ VERBOSE("FCONF:tbbr.mbedtls_heap_addr cell found with value = %p\n",
+ tbbr_dyn_config.mbedtls_heap_addr);
+ VERBOSE("FCONF:tbbr.mbedtls_heap_size cell found with value = %zu\n",
+ tbbr_dyn_config.mbedtls_heap_size);
+
+ return 0;
+}
+
+FCONF_REGISTER_POPULATOR(tbbr, fconf_populate_tbbr_dyn_config);