Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 1 | /* |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 8 | #include <errno.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
| 10 | #include <arch_helpers.h> |
| 11 | #include <common/bl_common.h> |
| 12 | #include <common/debug.h> |
John Tsichritzis | 30f8964 | 2018-06-07 16:31:34 +0100 | [diff] [blame] | 13 | #if TRUSTED_BOARD_BOOT |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | #include <drivers/auth/mbedtls/mbedtls_config.h> |
John Tsichritzis | 30f8964 | 2018-06-07 16:31:34 +0100 | [diff] [blame] | 15 | #endif |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | #include <lib/xlat_tables/xlat_tables_compat.h> |
| 17 | #include <plat/common/platform.h> |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 18 | |
| 19 | /* |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 20 | * The following platform functions are weakly defined. The Platforms |
| 21 | * may redefine with strong definition. |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 22 | */ |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 23 | #pragma weak bl2_el3_plat_prepare_exit |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 24 | #pragma weak plat_error_handler |
| 25 | #pragma weak bl2_plat_preload_setup |
Masahiro Yamada | 02a0d3d | 2018-02-01 16:45:51 +0900 | [diff] [blame] | 26 | #pragma weak bl2_plat_handle_pre_image_load |
| 27 | #pragma weak bl2_plat_handle_post_image_load |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 28 | #pragma weak plat_try_next_boot_source |
John Tsichritzis | 30f8964 | 2018-06-07 16:31:34 +0100 | [diff] [blame] | 29 | #pragma weak plat_get_mbedtls_heap |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 30 | |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 31 | void bl2_el3_plat_prepare_exit(void) |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 32 | { |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 33 | } |
| 34 | |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 35 | void __dead2 plat_error_handler(int err) |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 36 | { |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 37 | while (1) |
| 38 | wfi(); |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 39 | } |
| 40 | |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 41 | void bl2_plat_preload_setup(void) |
| 42 | { |
| 43 | } |
| 44 | |
Masahiro Yamada | 02a0d3d | 2018-02-01 16:45:51 +0900 | [diff] [blame] | 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 | |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 55 | int plat_try_next_boot_source(void) |
| 56 | { |
| 57 | return 0; |
| 58 | } |
Soby Mathew | 73308d0 | 2018-01-09 14:36:14 +0000 | [diff] [blame] | 59 | |
John Tsichritzis | 30f8964 | 2018-06-07 16:31:34 +0100 | [diff] [blame] | 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 */ |
Roberto Vargas | 344ff02 | 2018-10-19 16:44:18 +0100 | [diff] [blame] | 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 | } |