blob: 21278019eb4b974ef340b19c05889db6d9a85704 [file] [log] [blame]
Louis Mayencourt4da9b312019-09-30 10:57:24 +01001/*
2 * Copyright (c) 2019-2020, ARM Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#include <assert.h>
7
8#include <common/bl_common.h>
9#include <common/debug.h>
10#include <common/fdt_wrappers.h>
11#include <lib/fconf/fconf_tbbr_getter.h>
12#include <libfdt.h>
13
14struct tbbr_dyn_config_t tbbr_dyn_config;
15
16int fconf_populate_tbbr_dyn_config(uintptr_t config)
17{
18 int err;
19 int node;
Andre Przywarafe5bdf52020-03-26 11:22:37 +000020 uint64_t val64;
21 uint32_t val32;
Louis Mayencourt4da9b312019-09-30 10:57:24 +010022
23 /* As libfdt use void *, we can't avoid this cast */
24 const void *dtb = (void *)config;
25
26 /* Assert the node offset point to "arm,tb_fw" compatible property */
27 const char *compatible_str = "arm,tb_fw";
28 node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
29 if (node < 0) {
30 ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
31 return node;
32 }
33
34 /* Locate the disable_auth cell and read the value */
Andre Przywarafe5bdf52020-03-26 11:22:37 +000035 err = fdt_read_uint32(dtb, node, "disable_auth", &tbbr_dyn_config.disable_auth);
Louis Mayencourt4da9b312019-09-30 10:57:24 +010036 if (err < 0) {
37 WARN("FCONF: Read cell failed for `disable_auth`\n");
38 return err;
39 }
40
41 /* Check if the value is boolean */
42 if ((tbbr_dyn_config.disable_auth != 0U) && (tbbr_dyn_config.disable_auth != 1U)) {
43 WARN("Invalid value for `disable_auth` cell %d\n", tbbr_dyn_config.disable_auth);
44 return -1;
45 }
46
47#if defined(DYN_DISABLE_AUTH)
48 if (tbbr_dyn_config.disable_auth == 1)
49 dyn_disable_auth();
50#endif
51
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010052 /* Retrieve the Mbed TLS heap details from the DTB */
Andre Przywarafe5bdf52020-03-26 11:22:37 +000053 err = fdt_read_uint64(dtb, node, "mbedtls_heap_addr", &val64);
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010054 if (err < 0) {
55 ERROR("FCONF: Read cell failed for mbedtls_heap\n");
56 return err;
57 }
Andre Przywarafe5bdf52020-03-26 11:22:37 +000058 tbbr_dyn_config.mbedtls_heap_addr = (void *)(uintptr_t)val64;
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010059
Andre Przywarafe5bdf52020-03-26 11:22:37 +000060 err = fdt_read_uint32(dtb, node, "mbedtls_heap_size", &val32);
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010061 if (err < 0) {
62 ERROR("FCONF: Read cell failed for mbedtls_heap\n");
63 return err;
64 }
Andre Przywarafe5bdf52020-03-26 11:22:37 +000065 tbbr_dyn_config.mbedtls_heap_size = val32;
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010066
Louis Mayencourt4da9b312019-09-30 10:57:24 +010067 VERBOSE("FCONF:tbbr.disable_auth cell found with value = %d\n",
68 tbbr_dyn_config.disable_auth);
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010069 VERBOSE("FCONF:tbbr.mbedtls_heap_addr cell found with value = %p\n",
70 tbbr_dyn_config.mbedtls_heap_addr);
71 VERBOSE("FCONF:tbbr.mbedtls_heap_size cell found with value = %zu\n",
72 tbbr_dyn_config.mbedtls_heap_size);
Louis Mayencourt4da9b312019-09-30 10:57:24 +010073
74 return 0;
75}
76
Madhukar Pappireddy81519692019-12-06 15:46:42 -060077FCONF_REGISTER_POPULATOR(TB_FW, tbbr, fconf_populate_tbbr_dyn_config);