1 /*
2  * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <platform_def.h>
8 
9 #include <common/desc_image_load.h>
10 #include <plat/common/platform.h>
11 
12 /*******************************************************************************
13  * Following descriptor provides BL image/ep information that gets used
14  * by BL2 to load the images and also subset of this information is
15  * passed to next BL image. The image loading sequence is managed by
16  * populating the images in required loading order. The image execution
17  * sequence is managed by populating the `next_handoff_image_id` with
18  * the next executable image id.
19  ******************************************************************************/
20 static bl_mem_params_node_t bl2_mem_params_descs[] = {
21 #ifdef EL3_PAYLOAD_BASE
22 	/* Fill EL3 payload related information (BL31 is EL3 payload) */
23 	{ .image_id = BL31_IMAGE_ID,
24 
25 	  SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP, VERSION_2,
26 				entry_point_info_t,
27 				SECURE | EXECUTABLE | EP_FIRST_EXE),
28 	  .ep_info.pc = EL3_PAYLOAD_BASE,
29 	  .ep_info.spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
30 				  DISABLE_ALL_EXCEPTIONS),
31 
32 	  SET_STATIC_PARAM_HEAD(image_info, PARAM_EP, VERSION_2, image_info_t,
33 				IMAGE_ATTRIB_PLAT_SETUP | IMAGE_ATTRIB_SKIP_LOADING),
34 
35 	  .next_handoff_image_id = INVALID_IMAGE_ID,
36 	},
37 #else /* EL3_PAYLOAD_BASE */
38 #ifdef __aarch64__
39 	/* Fill BL31 related information */
40 	{ .image_id = BL31_IMAGE_ID,
41 
42 	  SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP, VERSION_2,
43 				entry_point_info_t,
44 				SECURE | EXECUTABLE | EP_FIRST_EXE),
45 	  .ep_info.pc = BL31_BASE,
46 	  .ep_info.spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
47 				  DISABLE_ALL_EXCEPTIONS),
48 # if DEBUG
49 	  .ep_info.args.arg1 = QEMU_BL31_PLAT_PARAM_VAL,
50 # endif
51 	  SET_STATIC_PARAM_HEAD(image_info, PARAM_EP, VERSION_2, image_info_t,
52 				IMAGE_ATTRIB_PLAT_SETUP),
53 	  .image_info.image_base = BL31_BASE,
54 	  .image_info.image_max_size = BL31_LIMIT - BL31_BASE,
55 
56 # ifdef QEMU_LOAD_BL32
57 	  .next_handoff_image_id = BL32_IMAGE_ID,
58 # else
59 	  .next_handoff_image_id = BL33_IMAGE_ID,
60 # endif
61 	},
62 #endif /* __aarch64__ */
63 # ifdef QEMU_LOAD_BL32
64 
65 #ifdef __aarch64__
66 #define BL32_EP_ATTRIBS		(SECURE | EXECUTABLE)
67 #define BL32_IMG_ATTRIBS	0
68 #else
69 #define BL32_EP_ATTRIBS		(SECURE | EXECUTABLE | EP_FIRST_EXE)
70 #define BL32_IMG_ATTRIBS	IMAGE_ATTRIB_PLAT_SETUP
71 #endif
72 
73 	/* Fill BL32 related information */
74 	{ .image_id = BL32_IMAGE_ID,
75 
76 	  SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP, VERSION_2,
77 				entry_point_info_t, BL32_EP_ATTRIBS),
78 	  .ep_info.pc = BL32_BASE,
79 
80 	  SET_STATIC_PARAM_HEAD(image_info, PARAM_EP, VERSION_2,
81 				image_info_t, BL32_IMG_ATTRIBS),
82 
83 	  .image_info.image_base = BL32_BASE,
84 	  .image_info.image_max_size = BL32_LIMIT - BL32_BASE,
85 
86 	  .next_handoff_image_id = BL33_IMAGE_ID,
87 	},
88 
89 	/*
90 	 * Fill BL32 external 1 related information.
91 	 * A typical use for extra1 image is with OP-TEE where it is the
92 	 * pager image.
93 	 */
94 	{ .image_id = BL32_EXTRA1_IMAGE_ID,
95 
96 	   SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP, VERSION_2,
97 				 entry_point_info_t, SECURE | NON_EXECUTABLE),
98 
99 	   SET_STATIC_PARAM_HEAD(image_info, PARAM_EP, VERSION_2,
100 				 image_info_t, IMAGE_ATTRIB_SKIP_LOADING),
101 	   .image_info.image_base = BL32_BASE,
102 	   .image_info.image_max_size = BL32_LIMIT - BL32_BASE,
103 
104 	   .next_handoff_image_id = INVALID_IMAGE_ID,
105 	},
106 
107 	/*
108 	 * Fill BL32 external 2 related information.
109 	 * A typical use for extra2 image is with OP-TEE where it is the
110 	 * paged image.
111 	 */
112 	{ .image_id = BL32_EXTRA2_IMAGE_ID,
113 
114 	   SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP, VERSION_2,
115 				 entry_point_info_t, SECURE | NON_EXECUTABLE),
116 
117 	   SET_STATIC_PARAM_HEAD(image_info, PARAM_EP, VERSION_2,
118 				 image_info_t, IMAGE_ATTRIB_SKIP_LOADING),
119 #if defined(SPD_opteed) || defined(AARCH32_SP_OPTEE)
120 	   .image_info.image_base = QEMU_OPTEE_PAGEABLE_LOAD_BASE,
121 	   .image_info.image_max_size = QEMU_OPTEE_PAGEABLE_LOAD_SIZE,
122 #endif
123 	   .next_handoff_image_id = INVALID_IMAGE_ID,
124 	},
125 # endif /* QEMU_LOAD_BL32 */
126 
127 	/* Fill BL33 related information */
128 	{ .image_id = BL33_IMAGE_ID,
129 	  SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP, VERSION_2,
130 				entry_point_info_t, NON_SECURE | EXECUTABLE),
131 # ifdef PRELOADED_BL33_BASE
132 	  .ep_info.pc = PRELOADED_BL33_BASE,
133 
134 	  SET_STATIC_PARAM_HEAD(image_info, PARAM_EP, VERSION_2, image_info_t,
135 				IMAGE_ATTRIB_SKIP_LOADING),
136 # else /* PRELOADED_BL33_BASE */
137 	  .ep_info.pc = NS_IMAGE_OFFSET,
138 
139 	  SET_STATIC_PARAM_HEAD(image_info, PARAM_EP, VERSION_2, image_info_t,
140 				0),
141 	  .image_info.image_base = NS_IMAGE_OFFSET,
142 	  .image_info.image_max_size = NS_IMAGE_MAX_SIZE,
143 # endif /* !PRELOADED_BL33_BASE */
144 
145 	  .next_handoff_image_id = INVALID_IMAGE_ID,
146 	}
147 #endif /* !EL3_PAYLOAD_BASE */
148 };
149 
150 REGISTER_BL_IMAGE_DESCS(bl2_mem_params_descs)
151