xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_bl2_setup.c (revision 47bf3ac31ec84d4b221fdef760c04b5f4416cba4)
1 /*
2  * Copyright (c) 2013-2021, Arm Limited and Contributors. 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/desc_image_load.h>
11 #include <drivers/arm/sp804_delay_timer.h>
12 #include <lib/fconf/fconf.h>
13 #include <lib/fconf/fconf_dyn_cfg_getter.h>
14 
15 #include <plat/arm/common/plat_arm.h>
16 #include <plat/common/platform.h>
17 #include <platform_def.h>
18 
19 #include "fvp_private.h"
20 
21 void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, u_register_t arg2, u_register_t arg3)
22 {
23 	arm_bl2_early_platform_setup((uintptr_t)arg0, (meminfo_t *)arg1);
24 
25 	/* Initialize the platform config for future decision making */
26 	fvp_config_setup();
27 }
28 
29 void bl2_platform_setup(void)
30 {
31 	arm_bl2_platform_setup();
32 
33 	/* Initialize System level generic or SP804 timer */
34 	fvp_timer_init();
35 }
36 
37 /*******************************************************************************
38  * This function returns the list of executable images
39  ******************************************************************************/
40 struct bl_params *plat_get_next_bl_params(void)
41 {
42 	struct bl_params *arm_bl_params;
43 
44 	arm_bl_params = arm_get_next_bl_params();
45 
46 #if __aarch64__ && !BL2_AT_EL3
47 	const struct dyn_cfg_dtb_info_t *fw_config_info;
48 	bl_mem_params_node_t *param_node;
49 	uintptr_t fw_config_base = 0U;
50 	entry_point_info_t *ep_info;
51 
52 	/* Get BL31 image node */
53 	param_node = get_bl_mem_params_node(BL31_IMAGE_ID);
54 	assert(param_node != NULL);
55 
56 	/* get fw_config load address */
57 	fw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, FW_CONFIG_ID);
58 	assert(fw_config_info != NULL);
59 
60 	fw_config_base = fw_config_info->config_addr;
61 	assert(fw_config_base != 0U);
62 
63 	/*
64 	 * Get the entry point info of BL31 image and override
65 	 * arg1 of entry point info with fw_config base address
66 	 */
67 	ep_info = &param_node->ep_info;
68 	ep_info->args.arg1 = (uint32_t)fw_config_base;
69 #endif /* __aarch64__ && !BL2_AT_EL3 */
70 
71 	return arm_bl_params;
72 }
73 #if MEASURED_BOOT
74 static int fvp_bl2_plat_handle_post_image_load(unsigned int image_id)
75 {
76 	const bl_mem_params_node_t *bl_mem_params =
77 				get_bl_mem_params_node(image_id);
78 
79 	assert(bl_mem_params != NULL);
80 
81 	image_info_t info = bl_mem_params->image_info;
82 	int err;
83 
84 	if ((info.h.attr & IMAGE_ATTRIB_SKIP_LOADING) == 0U) {
85 		/* Calculate image hash and record data in Event Log */
86 		err = event_log_measure_and_record(info.image_base,
87 						   info.image_size, image_id);
88 		if (err != 0) {
89 			ERROR("%s%s image id %u (%i)\n",
90 				"BL2: Failed to ", "record", image_id, err);
91 			return err;
92 		}
93 	}
94 
95 	err = arm_bl2_handle_post_image_load(image_id);
96 	if (err != 0) {
97 		ERROR("%s%s image id %u (%i)\n",
98 			"BL2: Failed to ", "handle", image_id, err);
99 	}
100 
101 	return err;
102 }
103 
104 int arm_bl2_plat_handle_post_image_load(unsigned int image_id)
105 {
106 	int err = fvp_bl2_plat_handle_post_image_load(image_id);
107 
108 	if (err != 0) {
109 		ERROR("%s() returns %i\n", __func__, err);
110 	}
111 
112 	return err;
113 }
114 #endif	/* MEASURED_BOOT */
115