fconf.c 2.18 KB
Newer Older
Louis Mayencourt's avatar
Louis Mayencourt committed
1
2
3
4
5
6
7
8
9
/*
 * Copyright (c) 2019-2020, ARM Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>

#include <common/debug.h>
10
#include <common/fdt_wrappers.h>
Louis Mayencourt's avatar
Louis Mayencourt committed
11
#include <lib/fconf/fconf.h>
12
#include <lib/fconf/fconf_dyn_cfg_getter.h>
Louis Mayencourt's avatar
Louis Mayencourt committed
13
#include <libfdt.h>
14
#include <plat/common/platform.h>
Louis Mayencourt's avatar
Louis Mayencourt committed
15
16
#include <platform_def.h>

17
int fconf_load_config(unsigned int image_id)
18
19
{
	int err;
20
	const struct dyn_cfg_dtb_info_t *config_info;
21
22
23

	assert((image_id == FW_CONFIG_ID) || (image_id == TB_FW_CONFIG_ID));

24
	image_info_t config_image_info = {
25
26
27
		.h.type = (uint8_t)PARAM_IMAGE_BINARY,
		.h.version = (uint8_t)VERSION_2,
		.h.size = (uint16_t)sizeof(image_info_t),
28
		.h.attr = 0
29
30
	};

31
	config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, image_id);
32
33
	assert(config_info != NULL);

34
	config_image_info.image_base = config_info->config_addr;
35
36
	config_image_info.image_max_size =
		(uint32_t)config_info->config_max_size;
37
38

	VERBOSE("FCONF: Loading config with image ID: %d\n", image_id);
39
	err = load_auth_image(image_id, &config_image_info);
40
	if (err != 0) {
41
42
		VERBOSE("Failed to load config %d\n", image_id);
		return err;
43
44
	}

45
	INFO("FCONF: Config file with image ID:%d loaded at address = 0x%lx\n",
46
		image_id, config_image_info.image_base);
47

48
	return 0;
49
50
}

51
void fconf_populate(const char *config_type, uintptr_t config)
Louis Mayencourt's avatar
Louis Mayencourt committed
52
53
54
55
56
{
	assert(config != 0UL);

	/* Check if the pointer to DTB is correct */
	if (fdt_check_header((void *)config) != 0) {
57
		ERROR("FCONF: Invalid DTB file passed for %s\n", config_type);
Louis Mayencourt's avatar
Louis Mayencourt committed
58
59
60
		panic();
	}

61
	INFO("FCONF: Reading %s firmware configuration file from: 0x%lx\n", config_type, config);
Louis Mayencourt's avatar
Louis Mayencourt committed
62
63
64
65
66
67
68
69
70

	/* Go through all registered populate functions */
	IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_START__, start);
	IMPORT_SYM(struct fconf_populator *, __FCONF_POPULATOR_END__, end);
	const struct fconf_populator *populator;

	for (populator = start; populator != end; populator++) {
		assert((populator->info != NULL) && (populator->populate != NULL));

71
72
73
74
75
76
		if (strcmp(populator->config_type, config_type) == 0) {
			INFO("FCONF: Reading firmware configuration information for: %s\n", populator->info);
			if (populator->populate(config) != 0) {
				/* TODO: handle property miss */
				panic();
			}
Louis Mayencourt's avatar
Louis Mayencourt committed
77
78
79
		}
	}
}