fconf.c 2.27 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
12
#include <lib/fconf/fconf.h>
#include <libfdt.h>
13
#include <plat/common/platform.h>
Louis Mayencourt's avatar
Louis Mayencourt committed
14
15
#include <platform_def.h>

16
struct fconf_dtb_info_t fconf_dtb_info;
17
18
19
20
21
22
23
24
25
26
27
28

void fconf_load_config(void)
{
	int err;

	image_info_t arm_tb_fw_info = {
		.h.type = (uint8_t)PARAM_IMAGE_BINARY,
		.h.version = (uint8_t)VERSION_2,
		.h.size = (uint16_t)sizeof(image_info_t),
		.h.attr = 0,
		.image_base = ARM_TB_FW_CONFIG_BASE,
		.image_max_size = (uint32_t)
29
				(ARM_TB_FW_CONFIG_LIMIT - ARM_TB_FW_CONFIG_BASE)
30
31
32
33
34
35
36
37
38
39
40
	};

	VERBOSE("FCONF: Loading FW_CONFIG\n");
	err = load_auth_image(TB_FW_CONFIG_ID, &arm_tb_fw_info);
	if (err != 0) {
		/* Return if FW_CONFIG is not loaded */
		VERBOSE("Failed to load FW_CONFIG\n");
		return;
	}

	/* At this point we know that a DTB is indeed available */
41
42
43
44
45
	fconf_dtb_info.base_addr = arm_tb_fw_info.image_base;
	fconf_dtb_info.size = (size_t)arm_tb_fw_info.image_size;

#if !BL2_AT_EL3
	image_desc_t *desc;
46
47
48
49

	/* The BL2 ep_info arg0 is modified to point to FW_CONFIG */
	desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
	assert(desc != NULL);
50
51
	desc->ep_info.args.arg0 = arm_tb_fw_info.image_base;
#endif
52

53
	INFO("FCONF: FW_CONFIG loaded at address = 0x%lx\n", arm_tb_fw_info.image_base);
54
55
}

Louis Mayencourt's avatar
Louis Mayencourt committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
void fconf_populate(uintptr_t config)
{
	assert(config != 0UL);

	/* Check if the pointer to DTB is correct */
	if (fdt_check_header((void *)config) != 0) {
		ERROR("FCONF: Invalid DTB file passed for FW_CONFIG\n");
		panic();
	}

	INFO("FCONF: Reading firmware configuration file from: 0x%lx\n", config);

	/* 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));

		INFO("FCONF: Reading firmware configuration information for: %s\n", populator->info);
		if (populator->populate(config) != 0) {
			/* TODO: handle property miss */
			panic();
		}
	}
82
83
84

	/* save local pointer to the config dtb */
	fconf_dtb_info.base_addr = config;
Louis Mayencourt's avatar
Louis Mayencourt committed
85
}