fconf.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/debug.h>
  8. #include <common/fdt_wrappers.h>
  9. #include <lib/fconf/fconf.h>
  10. #include <lib/fconf/fconf_dyn_cfg_getter.h>
  11. #include <libfdt.h>
  12. #include <plat/common/platform.h>
  13. #include <platform_def.h>
  14. int fconf_load_config(unsigned int image_id)
  15. {
  16. int err;
  17. const struct dyn_cfg_dtb_info_t *config_info;
  18. assert((image_id == FW_CONFIG_ID) || (image_id == TB_FW_CONFIG_ID));
  19. image_info_t config_image_info = {
  20. .h.type = (uint8_t)PARAM_IMAGE_BINARY,
  21. .h.version = (uint8_t)VERSION_2,
  22. .h.size = (uint16_t)sizeof(image_info_t),
  23. .h.attr = 0
  24. };
  25. config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, image_id);
  26. assert(config_info != NULL);
  27. config_image_info.image_base = config_info->config_addr;
  28. config_image_info.image_max_size = config_info->config_max_size;
  29. VERBOSE("FCONF: Loading config with image ID: %u\n", image_id);
  30. err = load_auth_image(image_id, &config_image_info);
  31. if (err != 0) {
  32. VERBOSE("Failed to load config %u\n", image_id);
  33. return err;
  34. }
  35. INFO("FCONF: Config file with image ID:%u loaded at address = 0x%lx\n",
  36. image_id, config_image_info.image_base);
  37. return 0;
  38. }
  39. void fconf_populate(const char *config_type, uintptr_t config)
  40. {
  41. assert(config != 0UL);
  42. /* Check if the pointer to DTB is correct */
  43. if (fdt_check_header((void *)config) != 0) {
  44. ERROR("FCONF: Invalid DTB file passed for %s\n", config_type);
  45. panic();
  46. }
  47. INFO("FCONF: Reading %s firmware configuration file from: 0x%lx\n", config_type, config);
  48. /* Go through all registered populate functions */
  49. IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_START__, start);
  50. IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_END__, end);
  51. const struct fconf_populator *populator;
  52. for (populator = start; populator != end; populator++) {
  53. assert((populator->info != NULL) && (populator->populate != NULL));
  54. if (strcmp(populator->config_type, config_type) == 0) {
  55. INFO("FCONF: Reading firmware configuration information for: %s\n", populator->info);
  56. if (populator->populate(config) != 0) {
  57. /* TODO: handle property miss */
  58. panic();
  59. }
  60. }
  61. }
  62. }