1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2019-2022, Arm Limited. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu #include <assert.h> 7*91f16700Schasinglulu 8*91f16700Schasinglulu #include <common/bl_common.h> 9*91f16700Schasinglulu #include <common/debug.h> 10*91f16700Schasinglulu #include <common/fdt_wrappers.h> 11*91f16700Schasinglulu #include <lib/fconf/fconf_tbbr_getter.h> 12*91f16700Schasinglulu #include <libfdt.h> 13*91f16700Schasinglulu 14*91f16700Schasinglulu struct tbbr_dyn_config_t tbbr_dyn_config; 15*91f16700Schasinglulu 16*91f16700Schasinglulu int fconf_populate_tbbr_dyn_config(uintptr_t config) 17*91f16700Schasinglulu { 18*91f16700Schasinglulu int err; 19*91f16700Schasinglulu int node; 20*91f16700Schasinglulu uint64_t val64; 21*91f16700Schasinglulu uint32_t val32; 22*91f16700Schasinglulu 23*91f16700Schasinglulu /* As libfdt use void *, we can't avoid this cast */ 24*91f16700Schasinglulu const void *dtb = (void *)config; 25*91f16700Schasinglulu 26*91f16700Schasinglulu /* Assert the node offset point to "arm,tb_fw" compatible property */ 27*91f16700Schasinglulu const char *compatible_str = "arm,tb_fw"; 28*91f16700Schasinglulu node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); 29*91f16700Schasinglulu if (node < 0) { 30*91f16700Schasinglulu ERROR("FCONF: Can't find `%s` compatible in dtb\n", 31*91f16700Schasinglulu compatible_str); 32*91f16700Schasinglulu return node; 33*91f16700Schasinglulu } 34*91f16700Schasinglulu 35*91f16700Schasinglulu /* Locate the disable_auth cell and read the value */ 36*91f16700Schasinglulu err = fdt_read_uint32(dtb, node, "disable_auth", 37*91f16700Schasinglulu &tbbr_dyn_config.disable_auth); 38*91f16700Schasinglulu if (err < 0) { 39*91f16700Schasinglulu WARN("FCONF: Read %s failed for `%s`\n", 40*91f16700Schasinglulu "cell", "disable_auth"); 41*91f16700Schasinglulu return err; 42*91f16700Schasinglulu } 43*91f16700Schasinglulu 44*91f16700Schasinglulu /* Check if the value is boolean */ 45*91f16700Schasinglulu if ((tbbr_dyn_config.disable_auth != 0U) && 46*91f16700Schasinglulu (tbbr_dyn_config.disable_auth != 1U)) { 47*91f16700Schasinglulu WARN("Invalid value for `%s` cell %u\n", 48*91f16700Schasinglulu "disable_auth", tbbr_dyn_config.disable_auth); 49*91f16700Schasinglulu return -1; 50*91f16700Schasinglulu } 51*91f16700Schasinglulu 52*91f16700Schasinglulu #if defined(DYN_DISABLE_AUTH) 53*91f16700Schasinglulu if (tbbr_dyn_config.disable_auth == 1) 54*91f16700Schasinglulu dyn_disable_auth(); 55*91f16700Schasinglulu #endif 56*91f16700Schasinglulu 57*91f16700Schasinglulu /* Retrieve the Mbed TLS heap details from the DTB */ 58*91f16700Schasinglulu err = fdt_read_uint64(dtb, node, "mbedtls_heap_addr", &val64); 59*91f16700Schasinglulu if (err < 0) { 60*91f16700Schasinglulu ERROR("FCONF: Read %s failed for `%s`\n", 61*91f16700Schasinglulu "cell", "mbedtls_heap_addr"); 62*91f16700Schasinglulu return err; 63*91f16700Schasinglulu } 64*91f16700Schasinglulu tbbr_dyn_config.mbedtls_heap_addr = (void *)(uintptr_t)val64; 65*91f16700Schasinglulu 66*91f16700Schasinglulu err = fdt_read_uint32(dtb, node, "mbedtls_heap_size", &val32); 67*91f16700Schasinglulu if (err < 0) { 68*91f16700Schasinglulu ERROR("FCONF: Read %s failed for `%s`\n", 69*91f16700Schasinglulu "cell", "mbedtls_heap_size"); 70*91f16700Schasinglulu return err; 71*91f16700Schasinglulu } 72*91f16700Schasinglulu tbbr_dyn_config.mbedtls_heap_size = val32; 73*91f16700Schasinglulu 74*91f16700Schasinglulu VERBOSE("%s%s%s %u\n", "FCONF: `tbbr.", "disable_auth", 75*91f16700Schasinglulu "` cell found with value =", tbbr_dyn_config.disable_auth); 76*91f16700Schasinglulu VERBOSE("%s%s%s %p\n", "FCONF: `tbbr.", "mbedtls_heap_addr", 77*91f16700Schasinglulu "` cell found with value =", tbbr_dyn_config.mbedtls_heap_addr); 78*91f16700Schasinglulu VERBOSE("%s%s%s %zu\n", "FCONF: `tbbr.", "mbedtls_heap_size", 79*91f16700Schasinglulu "` cell found with value =", tbbr_dyn_config.mbedtls_heap_size); 80*91f16700Schasinglulu 81*91f16700Schasinglulu return 0; 82*91f16700Schasinglulu } 83*91f16700Schasinglulu 84*91f16700Schasinglulu FCONF_REGISTER_POPULATOR(TB_FW, tbbr, fconf_populate_tbbr_dyn_config); 85