123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- #include <assert.h>
- #include <string.h>
- #include <libfdt.h>
- #if CRYPTO_SUPPORT
- #include <mbedtls/version.h>
- #endif
- #include <common/debug.h>
- #include <common/desc_image_load.h>
- #include <common/tbbr/tbbr_img_def.h>
- #include <lib/fconf/fconf.h>
- #include <lib/fconf/fconf_dyn_cfg_getter.h>
- #include <lib/fconf/fconf_tbbr_getter.h>
- #include <plat/arm/common/arm_dyn_cfg_helpers.h>
- #include <plat/arm/common/plat_arm.h>
- #include <platform_def.h>
- #if CRYPTO_SUPPORT && !TRANSFER_LIST
- static void *mbedtls_heap_addr;
- static size_t mbedtls_heap_size;
- int arm_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
- {
- assert(heap_addr != NULL);
- assert(heap_size != NULL);
- #if defined(IMAGE_BL1) || RESET_TO_BL2 || defined(IMAGE_BL31)
-
- static unsigned char heap[TF_MBEDTLS_HEAP_SIZE];
- *heap_addr = heap;
- *heap_size = sizeof(heap);
- mbedtls_heap_addr = heap;
- mbedtls_heap_size = sizeof(heap);
- #elif defined(IMAGE_BL2)
-
- *heap_addr = FCONF_GET_PROPERTY(tbbr, dyn_config, mbedtls_heap_addr);
- *heap_size = FCONF_GET_PROPERTY(tbbr, dyn_config, mbedtls_heap_size);
- #endif
- return 0;
- }
- void arm_bl1_set_mbedtls_heap(void)
- {
- int err;
- uintptr_t tb_fw_cfg_dtb;
- const struct dyn_cfg_dtb_info_t *tb_fw_config_info;
-
- tb_fw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, TB_FW_CONFIG_ID);
- assert(tb_fw_config_info != NULL);
- tb_fw_cfg_dtb = tb_fw_config_info->config_addr;
- if ((tb_fw_cfg_dtb != 0UL) && (mbedtls_heap_addr != NULL)) {
-
- void *dtb = (void *)tb_fw_cfg_dtb;
- err = arm_set_dtb_mbedtls_heap_info(dtb,
- mbedtls_heap_addr, mbedtls_heap_size);
- if (err < 0) {
- ERROR("%swrite shared Mbed TLS heap information%s",
- "BL1: unable to ", " to DTB\n");
- panic();
- }
- #if !MEASURED_BOOT
-
- flush_dcache_range(tb_fw_cfg_dtb, fdt_totalsize(dtb));
- #endif
- }
- }
- #endif
- #if IMAGE_BL2
- void arm_bl2_dyn_cfg_init(void)
- {
- unsigned int i;
- bl_mem_params_node_t *cfg_mem_params = NULL;
- uintptr_t image_base;
- uint32_t image_size;
- unsigned int error_config_id = MAX_IMAGE_IDS;
- const unsigned int config_ids[] = {
- HW_CONFIG_ID,
- SOC_FW_CONFIG_ID,
- NT_FW_CONFIG_ID,
- TOS_FW_CONFIG_ID
- };
- const struct dyn_cfg_dtb_info_t *dtb_info;
-
- for (i = 0; i < ARRAY_SIZE(config_ids); i++) {
-
- cfg_mem_params = get_bl_mem_params_node(config_ids[i]);
- if (cfg_mem_params == NULL) {
- VERBOSE("%sconfig_id = %d in bl_mem_params_node\n",
- "Couldn't find ", config_ids[i]);
- continue;
- }
- dtb_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, config_ids[i]);
- if (dtb_info == NULL) {
- VERBOSE("%sconfig_id %d load info in FW_CONFIG\n",
- "Couldn't find ", config_ids[i]);
- continue;
- }
- image_base = dtb_info->config_addr;
- image_size = dtb_info->config_max_size;
-
- if (config_ids[i] != HW_CONFIG_ID) {
- if (check_uptr_overflow(image_base, image_size)) {
- VERBOSE("%s=%d as its %s is overflowing uptr\n",
- "skip loading of firmware config",
- config_ids[i],
- "load-address");
- error_config_id = config_ids[i];
- continue;
- }
- #ifdef BL31_BASE
-
- if ((image_base >= BL31_BASE) &&
- (image_base <= BL31_LIMIT)) {
- VERBOSE("%s=%d as its %s is overlapping BL31\n",
- "skip loading of firmware config",
- config_ids[i],
- "load-address");
- error_config_id = config_ids[i];
- continue;
- }
- #endif
-
- if (image_base < ARM_BL_RAM_BASE) {
- VERBOSE("%s=%d as its %s is invalid\n",
- "skip loading of firmware config",
- config_ids[i],
- "load-address");
- error_config_id = config_ids[i];
- continue;
- }
- #ifdef BL32_BASE
-
- if ((image_base >= BL32_BASE) &&
- (image_base <= BL32_LIMIT)) {
- VERBOSE("%s=%d as its %s is overlapping BL32\n",
- "skip loading of firmware config",
- config_ids[i],
- "load-address");
- error_config_id = config_ids[i];
- continue;
- }
- #endif
- }
- cfg_mem_params->image_info.image_base = image_base;
- cfg_mem_params->image_info.image_max_size = (uint32_t)image_size;
-
- cfg_mem_params->image_info.h.attr &= ~IMAGE_ATTRIB_SKIP_LOADING;
- }
- if (error_config_id != MAX_IMAGE_IDS) {
- ERROR("Invalid config file %u\n", error_config_id);
- panic();
- }
- }
- #endif
|