Louis Mayencourt | 4da9b31 | 2019-09-30 10:57:24 +0100 | [diff] [blame] | 1 | /* |
Manish V Badarkhe | 3ff0f79 | 2021-08-10 20:51:55 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2021, Arm Limited. All rights reserved. |
Louis Mayencourt | 4da9b31 | 2019-09-30 10:57:24 +0100 | [diff] [blame] | 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; |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 20 | uint64_t val64; |
| 21 | uint32_t val32; |
Louis Mayencourt | 4da9b31 | 2019-09-30 10:57:24 +0100 | [diff] [blame] | 22 | |
| 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 Fedorov | 40e7d6c | 2020-07-13 14:10:00 +0100 | [diff] [blame] | 30 | ERROR("FCONF: Can't find `%s` compatible in dtb\n", |
| 31 | compatible_str); |
Louis Mayencourt | 4da9b31 | 2019-09-30 10:57:24 +0100 | [diff] [blame] | 32 | return node; |
| 33 | } |
| 34 | |
| 35 | /* Locate the disable_auth cell and read the value */ |
Alexei Fedorov | 40e7d6c | 2020-07-13 14:10:00 +0100 | [diff] [blame] | 36 | err = fdt_read_uint32(dtb, node, "disable_auth", |
| 37 | &tbbr_dyn_config.disable_auth); |
Louis Mayencourt | 4da9b31 | 2019-09-30 10:57:24 +0100 | [diff] [blame] | 38 | if (err < 0) { |
Alexei Fedorov | 40e7d6c | 2020-07-13 14:10:00 +0100 | [diff] [blame] | 39 | WARN("FCONF: Read %s failed for `%s`\n", |
| 40 | "cell", "disable_auth"); |
Louis Mayencourt | 4da9b31 | 2019-09-30 10:57:24 +0100 | [diff] [blame] | 41 | return err; |
| 42 | } |
| 43 | |
| 44 | /* Check if the value is boolean */ |
Alexei Fedorov | 40e7d6c | 2020-07-13 14:10:00 +0100 | [diff] [blame] | 45 | 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 Mayencourt | 4da9b31 | 2019-09-30 10:57:24 +0100 | [diff] [blame] | 49 | 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 Mayencourt | 5b9055f | 2019-10-01 10:45:14 +0100 | [diff] [blame] | 57 | /* Retrieve the Mbed TLS heap details from the DTB */ |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 58 | err = fdt_read_uint64(dtb, node, "mbedtls_heap_addr", &val64); |
Louis Mayencourt | 5b9055f | 2019-10-01 10:45:14 +0100 | [diff] [blame] | 59 | if (err < 0) { |
Alexei Fedorov | 40e7d6c | 2020-07-13 14:10:00 +0100 | [diff] [blame] | 60 | ERROR("FCONF: Read %s failed for `%s`\n", |
| 61 | "cell", "mbedtls_heap_addr"); |
Louis Mayencourt | 5b9055f | 2019-10-01 10:45:14 +0100 | [diff] [blame] | 62 | return err; |
| 63 | } |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 64 | tbbr_dyn_config.mbedtls_heap_addr = (void *)(uintptr_t)val64; |
Louis Mayencourt | 5b9055f | 2019-10-01 10:45:14 +0100 | [diff] [blame] | 65 | |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 66 | err = fdt_read_uint32(dtb, node, "mbedtls_heap_size", &val32); |
Louis Mayencourt | 5b9055f | 2019-10-01 10:45:14 +0100 | [diff] [blame] | 67 | if (err < 0) { |
Alexei Fedorov | 40e7d6c | 2020-07-13 14:10:00 +0100 | [diff] [blame] | 68 | ERROR("FCONF: Read %s failed for `%s`\n", |
| 69 | "cell", "mbedtls_heap_size"); |
Louis Mayencourt | 5b9055f | 2019-10-01 10:45:14 +0100 | [diff] [blame] | 70 | return err; |
| 71 | } |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 72 | tbbr_dyn_config.mbedtls_heap_size = val32; |
Louis Mayencourt | 5b9055f | 2019-10-01 10:45:14 +0100 | [diff] [blame] | 73 | |
Alexei Fedorov | 40e7d6c | 2020-07-13 14:10:00 +0100 | [diff] [blame] | 74 | VERBOSE("%s%s%s %d\n", "FCONF: `tbbr.", "disable_auth", |
| 75 | "` cell found with value =", tbbr_dyn_config.disable_auth); |
| 76 | VERBOSE("%s%s%s %p\n", "FCONF: `tbbr.", "mbedtls_heap_addr", |
| 77 | "` cell found with value =", tbbr_dyn_config.mbedtls_heap_addr); |
| 78 | VERBOSE("%s%s%s %zu\n", "FCONF: `tbbr.", "mbedtls_heap_size", |
| 79 | "` cell found with value =", tbbr_dyn_config.mbedtls_heap_size); |
Manish V Badarkhe | 3ff0f79 | 2021-08-10 20:51:55 +0100 | [diff] [blame] | 80 | |
Louis Mayencourt | 4da9b31 | 2019-09-30 10:57:24 +0100 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 84 | FCONF_REGISTER_POPULATOR(TB_FW, tbbr, fconf_populate_tbbr_dyn_config); |