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