fconf_tbbr_getter.c 2.3 KB

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