blob: 4cf1cc57355d83fc1f95d80f2ad1077da3346e08 [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
7#include <arch_helpers.h>
Soby Mathew2f38ce32018-02-08 17:45:12 +00008#include <assert.h>
9#include <bl_common.h>
10#include <debug.h>
11#include <errno.h>
John Tsichritzis30f89642018-06-07 16:31:34 +010012#if TRUSTED_BOARD_BOOT
13#include <mbedtls_config.h>
14#endif
Soby Mathew73308d02018-01-09 14:36:14 +000015#include <platform.h>
Antonio Nino Diaz61aff002018-10-19 16:52:22 +010016#include <xlat_tables_compat.h>
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090017
18/*
Soby Mathew2f38ce32018-02-08 17:45:12 +000019 * The following platform functions are weakly defined. The Platforms
20 * may redefine with strong definition.
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090021 */
Soby Mathew2f38ce32018-02-08 17:45:12 +000022#pragma weak bl2_el3_plat_prepare_exit
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090023#pragma weak plat_error_handler
24#pragma weak bl2_plat_preload_setup
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +090025#pragma weak bl2_plat_handle_pre_image_load
26#pragma weak bl2_plat_handle_post_image_load
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090027#pragma weak plat_try_next_boot_source
John Tsichritzis30f89642018-06-07 16:31:34 +010028#pragma weak plat_get_mbedtls_heap
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090029
Soby Mathew2f38ce32018-02-08 17:45:12 +000030void bl2_el3_plat_prepare_exit(void)
Masahiro Yamada43d20b32018-02-01 16:46:18 +090031{
Masahiro Yamada43d20b32018-02-01 16:46:18 +090032}
33
Soby Mathew2f38ce32018-02-08 17:45:12 +000034void __dead2 plat_error_handler(int err)
Masahiro Yamada43d20b32018-02-01 16:46:18 +090035{
Soby Mathew2f38ce32018-02-08 17:45:12 +000036 while (1)
37 wfi();
Masahiro Yamada43d20b32018-02-01 16:46:18 +090038}
39
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090040void bl2_plat_preload_setup(void)
41{
42}
43
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +090044int bl2_plat_handle_pre_image_load(unsigned int image_id)
45{
46 return 0;
47}
48
49int bl2_plat_handle_post_image_load(unsigned int image_id)
50{
51 return 0;
52}
53
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090054int plat_try_next_boot_source(void)
55{
56 return 0;
57}
Soby Mathew73308d02018-01-09 14:36:14 +000058
John Tsichritzis30f89642018-06-07 16:31:34 +010059#if TRUSTED_BOARD_BOOT
60/*
61 * The following default implementation of the function simply returns the
62 * by-default allocated heap.
63 */
64int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
65{
66 static unsigned char heap[TF_MBEDTLS_HEAP_SIZE];
67
68 assert(heap_addr != NULL);
69 assert(heap_size != NULL);
70
71 *heap_addr = heap;
72 *heap_size = sizeof(heap);
73 return 0;
74}
75#endif /* TRUSTED_BOARD_BOOT */
Roberto Vargas344ff022018-10-19 16:44:18 +010076
77/*
78 * Set up the page tables for the generic and platform-specific memory regions.
79 * The size of the Trusted SRAM seen by the BL image must be specified as well
80 * as an array specifying the generic memory regions which can be;
81 * - Code section;
82 * - Read-only data section;
83 * - Init code section, if applicable
84 * - Coherent memory region, if applicable.
85 */
86
87void __init setup_page_tables(const mmap_region_t *bl_regions,
88 const mmap_region_t *plat_regions)
89{
90#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
91 const mmap_region_t *regions = bl_regions;
92
93 while (regions->size != 0U) {
94 VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n",
95 regions->base_va,
96 regions->base_va + regions->size,
97 regions->attr);
98 regions++;
99 }
100#endif
101 /*
102 * Map the Trusted SRAM with appropriate memory attributes.
103 * Subsequent mappings will adjust the attributes for specific regions.
104 */
105 mmap_add(bl_regions);
106
107 /* Now (re-)map the platform-specific memory regions */
108 mmap_add(plat_regions);
109
110 /* Create the page tables to reflect the above mappings */
111 init_xlat_tables();
112}