xref: /rk3399_ARM-atf/plat/common/plat_bl_common.c (revision 0a0a7a9ac82cb79af91f098cedc69cc67bca3978)
1 /*
2  * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 
9 #include <arch_helpers.h>
10 #include <common/bl_common.h>
11 #include <common/debug.h>
12 #include <lib/xlat_tables/xlat_tables_compat.h>
13 #include <plat/common/platform.h>
14 #include <smccc_helpers.h>
15 #include <tools_share/firmware_encrypted.h>
16 
17 /*
18  * The following platform functions are weakly defined. The Platforms
19  * may redefine with strong definition.
20  */
21 #pragma weak bl2_el3_plat_prepare_exit
22 #pragma weak plat_error_handler
23 #pragma weak bl2_plat_preload_setup
24 #pragma weak bl2_plat_handle_pre_image_load
25 #pragma weak bl2_plat_handle_post_image_load
26 #pragma weak plat_try_next_boot_source
27 #pragma weak plat_get_enc_key_info
28 #pragma weak plat_get_soc_version
29 #pragma weak plat_get_soc_revision
30 
31 int32_t plat_get_soc_version(void)
32 {
33 	return SMC_ARCH_CALL_NOT_SUPPORTED;
34 }
35 
36 int32_t plat_get_soc_revision(void)
37 {
38 	return SMC_ARCH_CALL_NOT_SUPPORTED;
39 }
40 
41 void bl2_el3_plat_prepare_exit(void)
42 {
43 }
44 
45 void __dead2 plat_error_handler(int err)
46 {
47 	while (1)
48 		wfi();
49 }
50 
51 void bl2_plat_preload_setup(void)
52 {
53 }
54 
55 int bl2_plat_handle_pre_image_load(unsigned int image_id)
56 {
57 	return 0;
58 }
59 
60 int bl2_plat_handle_post_image_load(unsigned int image_id)
61 {
62 	return 0;
63 }
64 
65 int plat_try_next_boot_source(void)
66 {
67 	return 0;
68 }
69 
70 /*
71  * Weak implementation to provide dummy decryption key only for test purposes,
72  * platforms must override this API for any real world firmware encryption
73  * use-case.
74  */
75 int plat_get_enc_key_info(enum fw_enc_status_t fw_enc_status, uint8_t *key,
76 			  size_t *key_len, unsigned int *flags,
77 			  const uint8_t *img_id, size_t img_id_len)
78 {
79 #define DUMMY_FIP_ENC_KEY { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
80 			    0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
81 			    0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
82 			    0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef }
83 
84 	const uint8_t dummy_key[] = DUMMY_FIP_ENC_KEY;
85 
86 	assert(*key_len >= sizeof(dummy_key));
87 
88 	*key_len = sizeof(dummy_key);
89 	memcpy(key, dummy_key, *key_len);
90 	*flags = 0;
91 
92 	return 0;
93 }
94 
95 /*
96  * Set up the page tables for the generic and platform-specific memory regions.
97  * The size of the Trusted SRAM seen by the BL image must be specified as well
98  * as an array specifying the generic memory regions which can be;
99  * - Code section;
100  * - Read-only data section;
101  * - Init code section, if applicable
102  * - Coherent memory region, if applicable.
103  */
104 
105 void __init setup_page_tables(const mmap_region_t *bl_regions,
106 			      const mmap_region_t *plat_regions)
107 {
108 #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
109 	const mmap_region_t *regions = bl_regions;
110 
111 	while (regions->size != 0U) {
112 		VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n",
113 				regions->base_va,
114 				regions->base_va + regions->size,
115 				regions->attr);
116 		regions++;
117 	}
118 #endif
119 	/*
120 	 * Map the Trusted SRAM with appropriate memory attributes.
121 	 * Subsequent mappings will adjust the attributes for specific regions.
122 	 */
123 	mmap_add(bl_regions);
124 
125 	/* Now (re-)map the platform-specific memory regions */
126 	mmap_add(plat_regions);
127 
128 	/* Create the page tables to reflect the above mappings */
129 	init_xlat_tables();
130 }
131