blob: 9a20ced4ebf7cbf732fd493b7e2adf8545fae7b5 [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) {
Alexei Fedorov40e7d6c2020-07-13 14:10:00 +010030 ERROR("FCONF: Can't find `%s` compatible in dtb\n",
31 compatible_str);
Louis Mayencourt4da9b312019-09-30 10:57:24 +010032 return node;
33 }
34
35 /* Locate the disable_auth cell and read the value */
Alexei Fedorov40e7d6c2020-07-13 14:10:00 +010036 err = fdt_read_uint32(dtb, node, "disable_auth",
37 &tbbr_dyn_config.disable_auth);
Louis Mayencourt4da9b312019-09-30 10:57:24 +010038 if (err < 0) {
Alexei Fedorov40e7d6c2020-07-13 14:10:00 +010039 WARN("FCONF: Read %s failed for `%s`\n",
40 "cell", "disable_auth");
Louis Mayencourt4da9b312019-09-30 10:57:24 +010041 return err;
42 }
43
44 /* Check if the value is boolean */
Alexei Fedorov40e7d6c2020-07-13 14:10:00 +010045 if ((tbbr_dyn_config.disable_auth != 0U) &&
46 (tbbr_dyn_config.disable_auth != 1U)) {
47 WARN("Invalid value for `%s` cell %d\n",
48 "disable_auth", tbbr_dyn_config.disable_auth);
Louis Mayencourt4da9b312019-09-30 10:57:24 +010049 return -1;
50 }
51
52#if defined(DYN_DISABLE_AUTH)
53 if (tbbr_dyn_config.disable_auth == 1)
54 dyn_disable_auth();
55#endif
56
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010057 /* Retrieve the Mbed TLS heap details from the DTB */
Andre Przywarafe5bdf52020-03-26 11:22:37 +000058 err = fdt_read_uint64(dtb, node, "mbedtls_heap_addr", &val64);
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010059 if (err < 0) {
Alexei Fedorov40e7d6c2020-07-13 14:10:00 +010060 ERROR("FCONF: Read %s failed for `%s`\n",
61 "cell", "mbedtls_heap_addr");
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010062 return err;
63 }
Andre Przywarafe5bdf52020-03-26 11:22:37 +000064 tbbr_dyn_config.mbedtls_heap_addr = (void *)(uintptr_t)val64;
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010065
Andre Przywarafe5bdf52020-03-26 11:22:37 +000066 err = fdt_read_uint32(dtb, node, "mbedtls_heap_size", &val32);
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010067 if (err < 0) {
Alexei Fedorov40e7d6c2020-07-13 14:10:00 +010068 ERROR("FCONF: Read %s failed for `%s`\n",
69 "cell", "mbedtls_heap_size");
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010070 return err;
71 }
Andre Przywarafe5bdf52020-03-26 11:22:37 +000072 tbbr_dyn_config.mbedtls_heap_size = val32;
Louis Mayencourt5b9055f2019-10-01 10:45:14 +010073
Alexei Fedorov40e7d6c2020-07-13 14:10:00 +010074#if MEASURED_BOOT
75 /* Retrieve BL2 hash data details from the DTB */
76 err = fdtw_read_bytes(dtb, node, "bl2_hash_data", TCG_DIGEST_SIZE,
77 &tbbr_dyn_config.bl2_hash_data);
78 if (err < 0) {
79 ERROR("FCONF: Read %s failed for '%s'\n",
80 "bytes", "bl2_hash_data");
81 return err;
82 }
83#endif
84 VERBOSE("%s%s%s %d\n", "FCONF: `tbbr.", "disable_auth",
85 "` cell found with value =", tbbr_dyn_config.disable_auth);
86 VERBOSE("%s%s%s %p\n", "FCONF: `tbbr.", "mbedtls_heap_addr",
87 "` cell found with value =", tbbr_dyn_config.mbedtls_heap_addr);
88 VERBOSE("%s%s%s %zu\n", "FCONF: `tbbr.", "mbedtls_heap_size",
89 "` cell found with value =", tbbr_dyn_config.mbedtls_heap_size);
90#if MEASURED_BOOT
91 VERBOSE("%s%s%s %p\n", "FCONF: `tbbr.", "bl2_hash_data",
92 "` array found at address =", tbbr_dyn_config.bl2_hash_data);
93#endif
Louis Mayencourt4da9b312019-09-30 10:57:24 +010094 return 0;
95}
96
Madhukar Pappireddy81519692019-12-06 15:46:42 -060097FCONF_REGISTER_POPULATOR(TB_FW, tbbr, fconf_populate_tbbr_dyn_config);