blob: a6da56b00decbefc52a8475037df9e1a049c5a98 [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>
12#include <libfdt.h>
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010013#include <plat/common/platform.h>
Louis Mayencourt944ade82019-08-08 12:03:26 +010014#include <platform_def.h>
15
Louis Mayencourt81bd9162019-10-17 15:14:25 +010016struct fconf_dtb_info_t fconf_dtb_info;
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010017
18void fconf_load_config(void)
19{
20 int err;
Louis Mayencourt6d2b5732019-12-17 13:17:25 +000021 /* fconf FW_CONFIG and TB_FW_CONFIG are currently the same DTB */
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010022 image_info_t arm_tb_fw_info = {
23 .h.type = (uint8_t)PARAM_IMAGE_BINARY,
24 .h.version = (uint8_t)VERSION_2,
25 .h.size = (uint16_t)sizeof(image_info_t),
26 .h.attr = 0,
27 .image_base = ARM_TB_FW_CONFIG_BASE,
28 .image_max_size = (uint32_t)
Louis Mayencourt81bd9162019-10-17 15:14:25 +010029 (ARM_TB_FW_CONFIG_LIMIT - ARM_TB_FW_CONFIG_BASE)
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010030 };
31
32 VERBOSE("FCONF: Loading FW_CONFIG\n");
33 err = load_auth_image(TB_FW_CONFIG_ID, &arm_tb_fw_info);
34 if (err != 0) {
35 /* Return if FW_CONFIG is not loaded */
36 VERBOSE("Failed to load FW_CONFIG\n");
37 return;
38 }
39
40 /* At this point we know that a DTB is indeed available */
Louis Mayencourt81bd9162019-10-17 15:14:25 +010041 fconf_dtb_info.base_addr = arm_tb_fw_info.image_base;
42 fconf_dtb_info.size = (size_t)arm_tb_fw_info.image_size;
43
44#if !BL2_AT_EL3
45 image_desc_t *desc;
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010046
47 /* The BL2 ep_info arg0 is modified to point to FW_CONFIG */
48 desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
49 assert(desc != NULL);
Louis Mayencourt81bd9162019-10-17 15:14:25 +010050 desc->ep_info.args.arg0 = arm_tb_fw_info.image_base;
51#endif
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010052
Louis Mayencourt81bd9162019-10-17 15:14:25 +010053 INFO("FCONF: FW_CONFIG loaded at address = 0x%lx\n", arm_tb_fw_info.image_base);
Louis Mayencourt5a15b2d2019-10-17 14:46:51 +010054}
55
Louis Mayencourt944ade82019-08-08 12:03:26 +010056void fconf_populate(uintptr_t config)
57{
58 assert(config != 0UL);
59
60 /* Check if the pointer to DTB is correct */
61 if (fdt_check_header((void *)config) != 0) {
62 ERROR("FCONF: Invalid DTB file passed for FW_CONFIG\n");
63 panic();
64 }
65
66 INFO("FCONF: Reading firmware configuration file from: 0x%lx\n", config);
67
68 /* Go through all registered populate functions */
69 IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_START__, start);
70 IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_END__, end);
71 const struct fconf_populator *populator;
72
73 for (populator = start; populator != end; populator++) {
74 assert((populator->info != NULL) && (populator->populate != NULL));
75
76 INFO("FCONF: Reading firmware configuration information for: %s\n", populator->info);
77 if (populator->populate(config) != 0) {
78 /* TODO: handle property miss */
79 panic();
80 }
81 }
Louis Mayencourt81bd9162019-10-17 15:14:25 +010082
83 /* save local pointer to the config dtb */
84 fconf_dtb_info.base_addr = config;
Louis Mayencourt944ade82019-08-08 12:03:26 +010085}