1 /* 2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <assert.h> 8 #include <errno.h> 9 10 #include <arch_helpers.h> 11 #include <common/bl_common.h> 12 #include <common/debug.h> 13 #if TRUSTED_BOARD_BOOT 14 #include <drivers/auth/mbedtls/mbedtls_config.h> 15 #endif 16 #include <lib/xlat_tables/xlat_tables_compat.h> 17 #include <plat/common/platform.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_try_next_boot_source 29 #pragma weak plat_get_mbedtls_heap 30 31 void bl2_el3_plat_prepare_exit(void) 32 { 33 } 34 35 void __dead2 plat_error_handler(int err) 36 { 37 while (1) 38 wfi(); 39 } 40 41 void bl2_plat_preload_setup(void) 42 { 43 } 44 45 int bl2_plat_handle_pre_image_load(unsigned int image_id) 46 { 47 return 0; 48 } 49 50 int bl2_plat_handle_post_image_load(unsigned int image_id) 51 { 52 return 0; 53 } 54 55 int plat_try_next_boot_source(void) 56 { 57 return 0; 58 } 59 60 #if TRUSTED_BOARD_BOOT 61 /* 62 * The following default implementation of the function simply returns the 63 * by-default allocated heap. 64 */ 65 int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size) 66 { 67 static unsigned char heap[TF_MBEDTLS_HEAP_SIZE]; 68 69 assert(heap_addr != NULL); 70 assert(heap_size != NULL); 71 72 *heap_addr = heap; 73 *heap_size = sizeof(heap); 74 return 0; 75 } 76 #endif /* TRUSTED_BOARD_BOOT */ 77 78 /* 79 * Set up the page tables for the generic and platform-specific memory regions. 80 * The size of the Trusted SRAM seen by the BL image must be specified as well 81 * as an array specifying the generic memory regions which can be; 82 * - Code section; 83 * - Read-only data section; 84 * - Init code section, if applicable 85 * - Coherent memory region, if applicable. 86 */ 87 88 void __init setup_page_tables(const mmap_region_t *bl_regions, 89 const mmap_region_t *plat_regions) 90 { 91 #if LOG_LEVEL >= LOG_LEVEL_VERBOSE 92 const mmap_region_t *regions = bl_regions; 93 94 while (regions->size != 0U) { 95 VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n", 96 regions->base_va, 97 regions->base_va + regions->size, 98 regions->attr); 99 regions++; 100 } 101 #endif 102 /* 103 * Map the Trusted SRAM with appropriate memory attributes. 104 * Subsequent mappings will adjust the attributes for specific regions. 105 */ 106 mmap_add(bl_regions); 107 108 /* Now (re-)map the platform-specific memory regions */ 109 mmap_add(plat_regions); 110 111 /* Create the page tables to reflect the above mappings */ 112 init_xlat_tables(); 113 } 114