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