blob: ff16f676a64d538991048b28aa1b83e2b133426f [file] [log] [blame]
Louis Mayencourt944ade82019-08-08 12:03:26 +01001/*
2 * Copyright (c) 2019-2020, ARM Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8
9#include <common/debug.h>
Louis Mayencourt81bd9162019-10-17 15:14:25 +010010#include <common/fdt_wrappers.h>
Louis Mayencourt944ade82019-08-08 12:03:26 +010011#include <lib/fconf/fconf.h>
Manish V Badarkhebb533c72020-06-11 22:17:30 +010012#include <lib/fconf/fconf_dyn_cfg_getter.h>
Louis Mayencourt944ade82019-08-08 12:03:26 +010013#include <libfdt.h>
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010014#include <plat/common/platform.h>
Louis Mayencourt944ade82019-08-08 12:03:26 +010015#include <platform_def.h>
16
Manish V Badarkhebb533c72020-06-11 22:17:30 +010017void fconf_load_config(unsigned int image_id)
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010018{
19 int err;
Manish V Badarkhebb533c72020-06-11 22:17:30 +010020 struct dyn_cfg_dtb_info_t *config_info;
21
22 assert((image_id == FW_CONFIG_ID) || (image_id == TB_FW_CONFIG_ID));
23
24 image_info_t image_info = {
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010025 .h.type = (uint8_t)PARAM_IMAGE_BINARY,
26 .h.version = (uint8_t)VERSION_2,
27 .h.size = (uint16_t)sizeof(image_info_t),
Manish V Badarkhebb533c72020-06-11 22:17:30 +010028 .h.attr = 0
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010029 };
30
Manish V Badarkhebb533c72020-06-11 22:17:30 +010031 config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, image_id);
32 image_info.image_base = config_info->config_addr;
33 image_info.image_max_size = config_info->config_max_size;
34
35 VERBOSE("FCONF: Loading config with image ID: %d\n", image_id);
36 err = load_auth_image(image_id, &image_info);
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010037 if (err != 0) {
Manish V Badarkhebb533c72020-06-11 22:17:30 +010038 VERBOSE("Failed to load config %d, continuing without it\n",
39 image_id);
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010040 return;
41 }
42
Manish V Badarkhebb533c72020-06-11 22:17:30 +010043 INFO("FCONF: Config file with image ID:%d loaded at address = 0x%lx\n",
44 image_id, image_info.image_base);
Louis Mayencourt81bd9162019-10-17 15:14:25 +010045
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010046}
47
Madhukar Pappireddy81519692019-12-06 15:46:42 -060048void fconf_populate(const char *config_type, uintptr_t config)
Louis Mayencourt944ade82019-08-08 12:03:26 +010049{
50 assert(config != 0UL);
51
52 /* Check if the pointer to DTB is correct */
53 if (fdt_check_header((void *)config) != 0) {
Madhukar Pappireddy81519692019-12-06 15:46:42 -060054 ERROR("FCONF: Invalid DTB file passed for %s\n", config_type);
Louis Mayencourt944ade82019-08-08 12:03:26 +010055 panic();
56 }
57
Madhukar Pappireddy81519692019-12-06 15:46:42 -060058 INFO("FCONF: Reading %s firmware configuration file from: 0x%lx\n", config_type, config);
Louis Mayencourt944ade82019-08-08 12:03:26 +010059
60 /* Go through all registered populate functions */
61 IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_START__, start);
62 IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_END__, end);
63 const struct fconf_populator *populator;
64
65 for (populator = start; populator != end; populator++) {
66 assert((populator->info != NULL) && (populator->populate != NULL));
67
Madhukar Pappireddy81519692019-12-06 15:46:42 -060068 if (strcmp(populator->config_type, config_type) == 0) {
69 INFO("FCONF: Reading firmware configuration information for: %s\n", populator->info);
70 if (populator->populate(config) != 0) {
71 /* TODO: handle property miss */
72 panic();
73 }
Louis Mayencourt944ade82019-08-08 12:03:26 +010074 }
75 }
Louis Mayencourt944ade82019-08-08 12:03:26 +010076}