blob: 2357edfa93a6414fd4e4017f0791ba2a616c8f02 [file] [log] [blame]
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +09001/*
Soby Mathew2f38ce32018-02-08 17:45:12 +00002 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +09003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Soby Mathew2f38ce32018-02-08 17:45:12 +00007#include <assert.h>
Soby Mathew2f38ce32018-02-08 17:45:12 +00008#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
10#include <arch_helpers.h>
11#include <common/bl_common.h>
12#include <common/debug.h>
John Tsichritzis30f89642018-06-07 16:31:34 +010013#if TRUSTED_BOARD_BOOT
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <drivers/auth/mbedtls/mbedtls_config.h>
John Tsichritzis30f89642018-06-07 16:31:34 +010015#endif
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <lib/xlat_tables/xlat_tables_compat.h>
17#include <plat/common/platform.h>
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090018
19/*
Soby Mathew2f38ce32018-02-08 17:45:12 +000020 * The following platform functions are weakly defined. The Platforms
21 * may redefine with strong definition.
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090022 */
Soby Mathew2f38ce32018-02-08 17:45:12 +000023#pragma weak bl2_el3_plat_prepare_exit
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090024#pragma weak plat_error_handler
25#pragma weak bl2_plat_preload_setup
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +090026#pragma weak bl2_plat_handle_pre_image_load
27#pragma weak bl2_plat_handle_post_image_load
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090028#pragma weak plat_try_next_boot_source
John Tsichritzis30f89642018-06-07 16:31:34 +010029#pragma weak plat_get_mbedtls_heap
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090030
Soby Mathew2f38ce32018-02-08 17:45:12 +000031void bl2_el3_plat_prepare_exit(void)
Masahiro Yamada43d20b32018-02-01 16:46:18 +090032{
Masahiro Yamada43d20b32018-02-01 16:46:18 +090033}
34
Soby Mathew2f38ce32018-02-08 17:45:12 +000035void __dead2 plat_error_handler(int err)
Masahiro Yamada43d20b32018-02-01 16:46:18 +090036{
Soby Mathew2f38ce32018-02-08 17:45:12 +000037 while (1)
38 wfi();
Masahiro Yamada43d20b32018-02-01 16:46:18 +090039}
40
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090041void bl2_plat_preload_setup(void)
42{
43}
44
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +090045int bl2_plat_handle_pre_image_load(unsigned int image_id)
46{
47 return 0;
48}
49
50int bl2_plat_handle_post_image_load(unsigned int image_id)
51{
52 return 0;
53}
54
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090055int plat_try_next_boot_source(void)
56{
57 return 0;
58}
Soby Mathew73308d02018-01-09 14:36:14 +000059
John Tsichritzis30f89642018-06-07 16:31:34 +010060#if TRUSTED_BOARD_BOOT
61/*
62 * The following default implementation of the function simply returns the
63 * by-default allocated heap.
64 */
65int 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 */
Roberto Vargas344ff022018-10-19 16:44:18 +010077
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
88void __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}