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