xref: /rk3399_ARM-atf/lib/fconf/fconf_tbbr_getter.c (revision 0a0a7a9ac82cb79af91f098cedc69cc67bca3978)
1 /*
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 
14 struct tbbr_dyn_config_t tbbr_dyn_config;
15 
16 int fconf_populate_tbbr_dyn_config(uintptr_t config)
17 {
18 	int err;
19 	int node;
20 
21 	/* As libfdt use void *, we can't avoid this cast */
22 	const void *dtb = (void *)config;
23 
24 	/* Assert the node offset point to "arm,tb_fw" compatible property */
25 	const char *compatible_str = "arm,tb_fw";
26 	node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
27 	if (node < 0) {
28 		ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
29 		return node;
30 	}
31 
32 	/* Locate the disable_auth cell and read the value */
33 	err = fdtw_read_cells(dtb, node, "disable_auth", 1, &tbbr_dyn_config.disable_auth);
34 	if (err < 0) {
35 		WARN("FCONF: Read cell failed for `disable_auth`\n");
36 		return err;
37 	}
38 
39 	/* Check if the value is boolean */
40 	if ((tbbr_dyn_config.disable_auth != 0U) && (tbbr_dyn_config.disable_auth != 1U)) {
41 		WARN("Invalid value for `disable_auth` cell %d\n", tbbr_dyn_config.disable_auth);
42 		return -1;
43 	}
44 
45 #if defined(DYN_DISABLE_AUTH)
46 	if (tbbr_dyn_config.disable_auth == 1)
47 		dyn_disable_auth();
48 #endif
49 
50 	/* Retrieve the Mbed TLS heap details from the DTB */
51 	err = fdtw_read_cells(dtb, node,
52 		"mbedtls_heap_addr", 2, &tbbr_dyn_config.mbedtls_heap_addr);
53 	if (err < 0) {
54 		ERROR("FCONF: Read cell failed for mbedtls_heap\n");
55 		return err;
56 	}
57 
58 	err = fdtw_read_cells(dtb, node,
59 		"mbedtls_heap_size", 1, &tbbr_dyn_config.mbedtls_heap_size);
60 	if (err < 0) {
61 		ERROR("FCONF: Read cell failed for mbedtls_heap\n");
62 		return err;
63 	}
64 
65 	VERBOSE("FCONF:tbbr.disable_auth cell found with value = %d\n",
66 					tbbr_dyn_config.disable_auth);
67 	VERBOSE("FCONF:tbbr.mbedtls_heap_addr cell found with value = %p\n",
68 					tbbr_dyn_config.mbedtls_heap_addr);
69 	VERBOSE("FCONF:tbbr.mbedtls_heap_size cell found with value = %zu\n",
70 					tbbr_dyn_config.mbedtls_heap_size);
71 
72 	return 0;
73 }
74 
75 FCONF_REGISTER_POPULATOR(TB_FW, tbbr, fconf_populate_tbbr_dyn_config);
76