Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 1 | /* |
Zelalem | 87675d4 | 2020-02-03 14:56:42 -0600 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, 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> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <arch_helpers.h> |
| 10 | #include <common/bl_common.h> |
| 11 | #include <common/debug.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <lib/xlat_tables/xlat_tables_compat.h> |
| 13 | #include <plat/common/platform.h> |
Sumit Garg | 617e215 | 2019-11-15 15:34:55 +0530 | [diff] [blame] | 14 | #include <tools_share/firmware_encrypted.h> |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 15 | |
| 16 | /* |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 17 | * The following platform functions are weakly defined. The Platforms |
| 18 | * may redefine with strong definition. |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 19 | */ |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 20 | #pragma weak bl2_el3_plat_prepare_exit |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 21 | #pragma weak plat_error_handler |
| 22 | #pragma weak bl2_plat_preload_setup |
Masahiro Yamada | 02a0d3d | 2018-02-01 16:45:51 +0900 | [diff] [blame] | 23 | #pragma weak bl2_plat_handle_pre_image_load |
| 24 | #pragma weak bl2_plat_handle_post_image_load |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 25 | #pragma weak plat_try_next_boot_source |
Sumit Garg | 617e215 | 2019-11-15 15:34:55 +0530 | [diff] [blame] | 26 | #pragma weak plat_get_enc_key_info |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 27 | |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 28 | void bl2_el3_plat_prepare_exit(void) |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 29 | { |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 30 | } |
| 31 | |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 32 | void __dead2 plat_error_handler(int err) |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 33 | { |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 34 | while (1) |
| 35 | wfi(); |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 36 | } |
| 37 | |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 38 | void bl2_plat_preload_setup(void) |
| 39 | { |
| 40 | } |
| 41 | |
Masahiro Yamada | 02a0d3d | 2018-02-01 16:45:51 +0900 | [diff] [blame] | 42 | int bl2_plat_handle_pre_image_load(unsigned int image_id) |
| 43 | { |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
| 48 | { |
| 49 | return 0; |
| 50 | } |
| 51 | |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 52 | int plat_try_next_boot_source(void) |
| 53 | { |
| 54 | return 0; |
| 55 | } |
Soby Mathew | 73308d0 | 2018-01-09 14:36:14 +0000 | [diff] [blame] | 56 | |
Roberto Vargas | 344ff02 | 2018-10-19 16:44:18 +0100 | [diff] [blame] | 57 | /* |
Sumit Garg | 617e215 | 2019-11-15 15:34:55 +0530 | [diff] [blame] | 58 | * Weak implementation to provide dummy decryption key only for test purposes, |
| 59 | * platforms must override this API for any real world firmware encryption |
| 60 | * use-case. |
| 61 | */ |
| 62 | int plat_get_enc_key_info(enum fw_enc_status_t fw_enc_status, uint8_t *key, |
| 63 | size_t *key_len, unsigned int *flags, |
| 64 | const uint8_t *img_id, size_t img_id_len) |
| 65 | { |
| 66 | #define DUMMY_FIP_ENC_KEY { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \ |
| 67 | 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \ |
| 68 | 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \ |
| 69 | 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef } |
| 70 | |
| 71 | const uint8_t dummy_key[] = DUMMY_FIP_ENC_KEY; |
| 72 | |
| 73 | assert(*key_len >= sizeof(dummy_key)); |
| 74 | |
| 75 | *key_len = sizeof(dummy_key); |
| 76 | memcpy(key, dummy_key, *key_len); |
| 77 | *flags = 0; |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | /* |
Roberto Vargas | 344ff02 | 2018-10-19 16:44:18 +0100 | [diff] [blame] | 83 | * Set up the page tables for the generic and platform-specific memory regions. |
| 84 | * The size of the Trusted SRAM seen by the BL image must be specified as well |
| 85 | * as an array specifying the generic memory regions which can be; |
| 86 | * - Code section; |
| 87 | * - Read-only data section; |
| 88 | * - Init code section, if applicable |
| 89 | * - Coherent memory region, if applicable. |
| 90 | */ |
| 91 | |
| 92 | void __init setup_page_tables(const mmap_region_t *bl_regions, |
| 93 | const mmap_region_t *plat_regions) |
| 94 | { |
| 95 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
| 96 | const mmap_region_t *regions = bl_regions; |
| 97 | |
| 98 | while (regions->size != 0U) { |
| 99 | VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n", |
| 100 | regions->base_va, |
| 101 | regions->base_va + regions->size, |
| 102 | regions->attr); |
| 103 | regions++; |
| 104 | } |
| 105 | #endif |
| 106 | /* |
| 107 | * Map the Trusted SRAM with appropriate memory attributes. |
| 108 | * Subsequent mappings will adjust the attributes for specific regions. |
| 109 | */ |
| 110 | mmap_add(bl_regions); |
| 111 | |
| 112 | /* Now (re-)map the platform-specific memory regions */ |
| 113 | mmap_add(plat_regions); |
| 114 | |
| 115 | /* Create the page tables to reflect the above mappings */ |
| 116 | init_xlat_tables(); |
| 117 | } |