xref: /rk3399_ARM-atf/lib/fconf/fconf.c (revision 0a0a7a9ac82cb79af91f098cedc69cc67bca3978)
1 /*
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>
10 #include <common/fdt_wrappers.h>
11 #include <lib/fconf/fconf.h>
12 #include <libfdt.h>
13 #include <plat/common/platform.h>
14 #include <platform_def.h>
15 
16 struct fconf_dtb_info_t fconf_dtb_info;
17 
18 void fconf_load_config(void)
19 {
20 	int err;
21 	/* fconf FW_CONFIG and TB_FW_CONFIG are currently the same DTB */
22 	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)
29 				(ARM_TB_FW_CONFIG_LIMIT - ARM_TB_FW_CONFIG_BASE)
30 	};
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("FW_CONFIG not loaded, continuing without it\n");
37 		return;
38 	}
39 
40 	/* At this point we know that a DTB is indeed available */
41 	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;
46 
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);
50 	desc->ep_info.args.arg0 = arm_tb_fw_info.image_base;
51 #endif
52 
53 	INFO("FCONF: FW_CONFIG loaded at address = 0x%lx\n", arm_tb_fw_info.image_base);
54 }
55 
56 void fconf_populate(const char *config_type, 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 %s\n", config_type);
63 		panic();
64 	}
65 
66 	INFO("FCONF: Reading %s firmware configuration file from: 0x%lx\n", config_type, 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 		if (strcmp(populator->config_type, config_type) == 0) {
77 			INFO("FCONF: Reading firmware configuration information for: %s\n", populator->info);
78 			if (populator->populate(config) != 0) {
79 				/* TODO: handle property miss */
80 				panic();
81 			}
82 		}
83 	}
84 
85 	/* save local pointer to the config dtb */
86 	fconf_dtb_info.base_addr = config;
87 }
88