xref: /rk3399_ARM-atf/plat/arm/common/arm_image_load.c (revision 5b8d50e40701ebb6a7ba548ccaa96ba879587fb9)
1a8aa7fecSYatharth Kochar /*
2cab0b5b0SSoby Mathew  * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
3a8aa7fecSYatharth Kochar  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5a8aa7fecSYatharth Kochar  */
6a8aa7fecSYatharth Kochar 
7*5b8d50e4SSathees Balya #include <assert.h>
809d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
909d40e0eSAntonio Nino Diaz #include <common/desc_image_load.h>
1009d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
11a8aa7fecSYatharth Kochar 
1209d40e0eSAntonio Nino Diaz #include <plat_arm.h>
13a8aa7fecSYatharth Kochar 
14a8aa7fecSYatharth Kochar #pragma weak plat_flush_next_bl_params
15a8aa7fecSYatharth Kochar #pragma weak plat_get_bl_image_load_info
16a8aa7fecSYatharth Kochar #pragma weak plat_get_next_bl_params
17a8aa7fecSYatharth Kochar 
18*5b8d50e4SSathees Balya static bl_params_t *next_bl_params_cpy_ptr;
19a8aa7fecSYatharth Kochar 
20a8aa7fecSYatharth Kochar /*******************************************************************************
21a8aa7fecSYatharth Kochar  * This function flushes the data structures so that they are visible
22a8aa7fecSYatharth Kochar  * in memory for the next BL image.
23a8aa7fecSYatharth Kochar  ******************************************************************************/
24a8aa7fecSYatharth Kochar void plat_flush_next_bl_params(void)
25a8aa7fecSYatharth Kochar {
26*5b8d50e4SSathees Balya 	assert(next_bl_params_cpy_ptr != NULL);
27*5b8d50e4SSathees Balya 
28*5b8d50e4SSathees Balya 	flush_bl_params_desc_args(bl_mem_params_desc_ptr,
29*5b8d50e4SSathees Balya 		bl_mem_params_desc_num,
30*5b8d50e4SSathees Balya 		next_bl_params_cpy_ptr);
31a8aa7fecSYatharth Kochar }
32a8aa7fecSYatharth Kochar 
33a8aa7fecSYatharth Kochar /*******************************************************************************
34a8aa7fecSYatharth Kochar  * This function returns the list of loadable images.
35a8aa7fecSYatharth Kochar  ******************************************************************************/
366c77e749SSandrine Bailleux struct bl_load_info *plat_get_bl_image_load_info(void)
37a8aa7fecSYatharth Kochar {
38a8aa7fecSYatharth Kochar 	return get_bl_load_info_from_mem_params_desc();
39a8aa7fecSYatharth Kochar }
40a8aa7fecSYatharth Kochar 
41a8aa7fecSYatharth Kochar /*******************************************************************************
42*5b8d50e4SSathees Balya  * ARM helper function to return the list of executable images.Since the default
43*5b8d50e4SSathees Balya  * descriptors are allocated within BL2 RW memory, this prevents BL31/BL32
44*5b8d50e4SSathees Balya  * overlay of BL2 memory. Hence this function also copies the descriptors to a
45*5b8d50e4SSathees Balya  * pre-allocated memory indicated by ARM_BL2_MEM_DESC_BASE.
46*5b8d50e4SSathees Balya  ******************************************************************************/
47*5b8d50e4SSathees Balya struct bl_params *arm_get_next_bl_params(void)
48*5b8d50e4SSathees Balya {
49*5b8d50e4SSathees Balya 	bl_mem_params_node_t *bl2_mem_params_descs_cpy
50*5b8d50e4SSathees Balya 			= (bl_mem_params_node_t *)ARM_BL2_MEM_DESC_BASE;
51*5b8d50e4SSathees Balya 	const bl_params_t *next_bl_params;
52*5b8d50e4SSathees Balya 
53*5b8d50e4SSathees Balya 	next_bl_params_cpy_ptr =
54*5b8d50e4SSathees Balya 		(bl_params_t *)(ARM_BL2_MEM_DESC_BASE +
55*5b8d50e4SSathees Balya 		(bl_mem_params_desc_num * sizeof(bl_mem_params_node_t)));
56*5b8d50e4SSathees Balya 
57*5b8d50e4SSathees Balya 	/*
58*5b8d50e4SSathees Balya 	 * Copy the memory descriptors to ARM_BL2_MEM_DESC_BASE area.
59*5b8d50e4SSathees Balya 	 */
60*5b8d50e4SSathees Balya 	(void) memcpy(bl2_mem_params_descs_cpy, bl_mem_params_desc_ptr,
61*5b8d50e4SSathees Balya 		(bl_mem_params_desc_num * sizeof(bl_mem_params_node_t)));
62*5b8d50e4SSathees Balya 
63*5b8d50e4SSathees Balya 	/*
64*5b8d50e4SSathees Balya 	 * Modify the global 'bl_mem_params_desc_ptr' to point to the
65*5b8d50e4SSathees Balya 	 * copied location.
66*5b8d50e4SSathees Balya 	 */
67*5b8d50e4SSathees Balya 	bl_mem_params_desc_ptr = bl2_mem_params_descs_cpy;
68*5b8d50e4SSathees Balya 
69*5b8d50e4SSathees Balya 	next_bl_params = get_next_bl_params_from_mem_params_desc();
70*5b8d50e4SSathees Balya 	assert(next_bl_params != NULL);
71*5b8d50e4SSathees Balya 
72*5b8d50e4SSathees Balya 	/*
73*5b8d50e4SSathees Balya 	 * Copy 'next_bl_params' to the reserved location after the copied
74*5b8d50e4SSathees Balya 	 * memory descriptors.
75*5b8d50e4SSathees Balya 	 */
76*5b8d50e4SSathees Balya 	(void) memcpy(next_bl_params_cpy_ptr, next_bl_params,
77*5b8d50e4SSathees Balya 						(sizeof(bl_params_t)));
78*5b8d50e4SSathees Balya 
79*5b8d50e4SSathees Balya 	populate_next_bl_params_config(next_bl_params_cpy_ptr);
80*5b8d50e4SSathees Balya 
81*5b8d50e4SSathees Balya 	return next_bl_params_cpy_ptr;
82*5b8d50e4SSathees Balya }
83*5b8d50e4SSathees Balya 
84*5b8d50e4SSathees Balya /*******************************************************************************
85*5b8d50e4SSathees Balya  * This function returns the list of executable images
86a8aa7fecSYatharth Kochar  ******************************************************************************/
876c77e749SSandrine Bailleux struct bl_params *plat_get_next_bl_params(void)
88a8aa7fecSYatharth Kochar {
89*5b8d50e4SSathees Balya 	return arm_get_next_bl_params();
90a8aa7fecSYatharth Kochar }
91*5b8d50e4SSathees Balya 
92