1566034fcSSoby Mathew /* 2566034fcSSoby Mathew * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. 3566034fcSSoby Mathew * 4566034fcSSoby Mathew * SPDX-License-Identifier: BSD-3-Clause 5566034fcSSoby Mathew */ 6566034fcSSoby Mathew 7566034fcSSoby Mathew #include <assert.h> 8566034fcSSoby Mathew #include <errno.h> 9*09d40e0eSAntonio Nino Diaz 10*09d40e0eSAntonio Nino Diaz #include <arch_helpers.h> 11*09d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 12*09d40e0eSAntonio Nino Diaz #include <common/debug.h> 136d01a463SJohn Tsichritzis #if TRUSTED_BOARD_BOOT 14*09d40e0eSAntonio Nino Diaz #include <drivers/auth/mbedtls/mbedtls_config.h> 156d01a463SJohn Tsichritzis #endif 16*09d40e0eSAntonio Nino Diaz #include <lib/xlat_tables/xlat_tables_compat.h> 17*09d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 18566034fcSSoby Mathew 19566034fcSSoby Mathew /* 20566034fcSSoby Mathew * The following platform functions are weakly defined. The Platforms 21566034fcSSoby Mathew * may redefine with strong definition. 22566034fcSSoby Mathew */ 23566034fcSSoby Mathew #pragma weak bl2_el3_plat_prepare_exit 24566034fcSSoby Mathew #pragma weak plat_error_handler 25566034fcSSoby Mathew #pragma weak bl2_plat_preload_setup 26566034fcSSoby Mathew #pragma weak bl2_plat_handle_pre_image_load 27566034fcSSoby Mathew #pragma weak bl2_plat_handle_post_image_load 28566034fcSSoby Mathew #pragma weak plat_try_next_boot_source 296d01a463SJohn Tsichritzis #pragma weak plat_get_mbedtls_heap 30566034fcSSoby Mathew 31566034fcSSoby Mathew void bl2_el3_plat_prepare_exit(void) 32566034fcSSoby Mathew { 33566034fcSSoby Mathew } 34566034fcSSoby Mathew 35566034fcSSoby Mathew void __dead2 plat_error_handler(int err) 36566034fcSSoby Mathew { 37566034fcSSoby Mathew while (1) 38566034fcSSoby Mathew wfi(); 39566034fcSSoby Mathew } 40566034fcSSoby Mathew 41566034fcSSoby Mathew void bl2_plat_preload_setup(void) 42566034fcSSoby Mathew { 43566034fcSSoby Mathew } 44566034fcSSoby Mathew 45566034fcSSoby Mathew int bl2_plat_handle_pre_image_load(unsigned int image_id) 46566034fcSSoby Mathew { 47566034fcSSoby Mathew return 0; 48566034fcSSoby Mathew } 49566034fcSSoby Mathew 50566034fcSSoby Mathew int bl2_plat_handle_post_image_load(unsigned int image_id) 51566034fcSSoby Mathew { 52566034fcSSoby Mathew return 0; 53566034fcSSoby Mathew } 54566034fcSSoby Mathew 55566034fcSSoby Mathew int plat_try_next_boot_source(void) 56566034fcSSoby Mathew { 57566034fcSSoby Mathew return 0; 58566034fcSSoby Mathew } 59a6f340feSSoby Mathew 606d01a463SJohn Tsichritzis #if TRUSTED_BOARD_BOOT 616d01a463SJohn Tsichritzis /* 626d01a463SJohn Tsichritzis * The following default implementation of the function simply returns the 636d01a463SJohn Tsichritzis * by-default allocated heap. 646d01a463SJohn Tsichritzis */ 656d01a463SJohn Tsichritzis int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size) 666d01a463SJohn Tsichritzis { 676d01a463SJohn Tsichritzis static unsigned char heap[TF_MBEDTLS_HEAP_SIZE]; 686d01a463SJohn Tsichritzis 696d01a463SJohn Tsichritzis assert(heap_addr != NULL); 706d01a463SJohn Tsichritzis assert(heap_size != NULL); 716d01a463SJohn Tsichritzis 726d01a463SJohn Tsichritzis *heap_addr = heap; 736d01a463SJohn Tsichritzis *heap_size = sizeof(heap); 746d01a463SJohn Tsichritzis return 0; 756d01a463SJohn Tsichritzis } 766d01a463SJohn Tsichritzis #endif /* TRUSTED_BOARD_BOOT */ 770916c38dSRoberto Vargas 780916c38dSRoberto Vargas /* 790916c38dSRoberto Vargas * Set up the page tables for the generic and platform-specific memory regions. 800916c38dSRoberto Vargas * The size of the Trusted SRAM seen by the BL image must be specified as well 810916c38dSRoberto Vargas * as an array specifying the generic memory regions which can be; 820916c38dSRoberto Vargas * - Code section; 830916c38dSRoberto Vargas * - Read-only data section; 840916c38dSRoberto Vargas * - Init code section, if applicable 850916c38dSRoberto Vargas * - Coherent memory region, if applicable. 860916c38dSRoberto Vargas */ 870916c38dSRoberto Vargas 880916c38dSRoberto Vargas void __init setup_page_tables(const mmap_region_t *bl_regions, 890916c38dSRoberto Vargas const mmap_region_t *plat_regions) 900916c38dSRoberto Vargas { 910916c38dSRoberto Vargas #if LOG_LEVEL >= LOG_LEVEL_VERBOSE 920916c38dSRoberto Vargas const mmap_region_t *regions = bl_regions; 930916c38dSRoberto Vargas 940916c38dSRoberto Vargas while (regions->size != 0U) { 950916c38dSRoberto Vargas VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n", 960916c38dSRoberto Vargas regions->base_va, 970916c38dSRoberto Vargas regions->base_va + regions->size, 980916c38dSRoberto Vargas regions->attr); 990916c38dSRoberto Vargas regions++; 1000916c38dSRoberto Vargas } 1010916c38dSRoberto Vargas #endif 1020916c38dSRoberto Vargas /* 1030916c38dSRoberto Vargas * Map the Trusted SRAM with appropriate memory attributes. 1040916c38dSRoberto Vargas * Subsequent mappings will adjust the attributes for specific regions. 1050916c38dSRoberto Vargas */ 1060916c38dSRoberto Vargas mmap_add(bl_regions); 1070916c38dSRoberto Vargas 1080916c38dSRoberto Vargas /* Now (re-)map the platform-specific memory regions */ 1090916c38dSRoberto Vargas mmap_add(plat_regions); 1100916c38dSRoberto Vargas 1110916c38dSRoberto Vargas /* Create the page tables to reflect the above mappings */ 1120916c38dSRoberto Vargas init_xlat_tables(); 1130916c38dSRoberto Vargas } 114