Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 1 | /* |
Yann Gautier | 8b61d88 | 2024-02-05 11:28:29 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2024, 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> |
Harrison Mutai | a120496 | 2025-05-13 14:01:05 +0000 | [diff] [blame] | 12 | #if TRANSFER_LIST |
| 13 | #include <transfer_list.h> |
| 14 | #endif |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <lib/xlat_tables/xlat_tables_compat.h> |
| 16 | #include <plat/common/platform.h> |
Manish V Badarkhe | 80f13ee | 2020-07-23 20:23:01 +0100 | [diff] [blame] | 17 | #include <services/arm_arch_svc.h> |
Manish V Badarkhe | f809c6e | 2020-02-22 08:43:00 +0000 | [diff] [blame] | 18 | #include <smccc_helpers.h> |
Sumit Garg | 617e215 | 2019-11-15 15:34:55 +0530 | [diff] [blame] | 19 | #include <tools_share/firmware_encrypted.h> |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 20 | |
| 21 | /* |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 22 | * The following platform functions are weakly defined. The Platforms |
| 23 | * may redefine with strong definition. |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 24 | */ |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 25 | #pragma weak bl2_el3_plat_prepare_exit |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 26 | #pragma weak plat_error_handler |
| 27 | #pragma weak bl2_plat_preload_setup |
Masahiro Yamada | 02a0d3d | 2018-02-01 16:45:51 +0900 | [diff] [blame] | 28 | #pragma weak bl2_plat_handle_pre_image_load |
| 29 | #pragma weak bl2_plat_handle_post_image_load |
Sumit Garg | 617e215 | 2019-11-15 15:34:55 +0530 | [diff] [blame] | 30 | #pragma weak plat_get_enc_key_info |
Manish V Badarkhe | 80f13ee | 2020-07-23 20:23:01 +0100 | [diff] [blame] | 31 | #pragma weak plat_is_smccc_feature_available |
Manish V Badarkhe | f809c6e | 2020-02-22 08:43:00 +0000 | [diff] [blame] | 32 | #pragma weak plat_get_soc_version |
| 33 | #pragma weak plat_get_soc_revision |
| 34 | |
| 35 | int32_t plat_get_soc_version(void) |
| 36 | { |
| 37 | return SMC_ARCH_CALL_NOT_SUPPORTED; |
| 38 | } |
| 39 | |
| 40 | int32_t plat_get_soc_revision(void) |
| 41 | { |
| 42 | return SMC_ARCH_CALL_NOT_SUPPORTED; |
| 43 | } |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 44 | |
Manish V Badarkhe | 80f13ee | 2020-07-23 20:23:01 +0100 | [diff] [blame] | 45 | int32_t plat_is_smccc_feature_available(u_register_t fid __unused) |
| 46 | { |
| 47 | return SMC_ARCH_CALL_NOT_SUPPORTED; |
| 48 | } |
| 49 | |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 50 | void bl2_el3_plat_prepare_exit(void) |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 51 | { |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 52 | } |
| 53 | |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 54 | void __dead2 plat_error_handler(int err) |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 55 | { |
Maheedhar Bollapalli | 9bf4184 | 2024-04-25 10:34:02 +0530 | [diff] [blame] | 56 | while (1) { |
Soby Mathew | 2f38ce3 | 2018-02-08 17:45:12 +0000 | [diff] [blame] | 57 | wfi(); |
Maheedhar Bollapalli | 9bf4184 | 2024-04-25 10:34:02 +0530 | [diff] [blame] | 58 | } |
Masahiro Yamada | 43d20b3 | 2018-02-01 16:46:18 +0900 | [diff] [blame] | 59 | } |
| 60 | |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 61 | void bl2_plat_preload_setup(void) |
| 62 | { |
| 63 | } |
| 64 | |
Masahiro Yamada | 02a0d3d | 2018-02-01 16:45:51 +0900 | [diff] [blame] | 65 | int bl2_plat_handle_pre_image_load(unsigned int image_id) |
| 66 | { |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
| 71 | { |
| 72 | return 0; |
| 73 | } |
| 74 | |
Roberto Vargas | 344ff02 | 2018-10-19 16:44:18 +0100 | [diff] [blame] | 75 | /* |
Sumit Garg | 617e215 | 2019-11-15 15:34:55 +0530 | [diff] [blame] | 76 | * Weak implementation to provide dummy decryption key only for test purposes, |
| 77 | * platforms must override this API for any real world firmware encryption |
| 78 | * use-case. |
| 79 | */ |
| 80 | int plat_get_enc_key_info(enum fw_enc_status_t fw_enc_status, uint8_t *key, |
| 81 | size_t *key_len, unsigned int *flags, |
| 82 | const uint8_t *img_id, size_t img_id_len) |
| 83 | { |
| 84 | #define DUMMY_FIP_ENC_KEY { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \ |
| 85 | 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \ |
| 86 | 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \ |
| 87 | 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef } |
| 88 | |
| 89 | const uint8_t dummy_key[] = DUMMY_FIP_ENC_KEY; |
| 90 | |
| 91 | assert(*key_len >= sizeof(dummy_key)); |
| 92 | |
| 93 | *key_len = sizeof(dummy_key); |
| 94 | memcpy(key, dummy_key, *key_len); |
| 95 | *flags = 0; |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | /* |
Roberto Vargas | 344ff02 | 2018-10-19 16:44:18 +0100 | [diff] [blame] | 101 | * Set up the page tables for the generic and platform-specific memory regions. |
| 102 | * The size of the Trusted SRAM seen by the BL image must be specified as well |
| 103 | * as an array specifying the generic memory regions which can be; |
| 104 | * - Code section; |
| 105 | * - Read-only data section; |
| 106 | * - Init code section, if applicable |
| 107 | * - Coherent memory region, if applicable. |
| 108 | */ |
| 109 | |
| 110 | void __init setup_page_tables(const mmap_region_t *bl_regions, |
| 111 | const mmap_region_t *plat_regions) |
| 112 | { |
| 113 | #if LOG_LEVEL >= LOG_LEVEL_VERBOSE |
| 114 | const mmap_region_t *regions = bl_regions; |
| 115 | |
| 116 | while (regions->size != 0U) { |
| 117 | VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n", |
| 118 | regions->base_va, |
| 119 | regions->base_va + regions->size, |
| 120 | regions->attr); |
| 121 | regions++; |
| 122 | } |
| 123 | #endif |
| 124 | /* |
| 125 | * Map the Trusted SRAM with appropriate memory attributes. |
| 126 | * Subsequent mappings will adjust the attributes for specific regions. |
| 127 | */ |
| 128 | mmap_add(bl_regions); |
| 129 | |
| 130 | /* Now (re-)map the platform-specific memory regions */ |
| 131 | mmap_add(plat_regions); |
| 132 | |
| 133 | /* Create the page tables to reflect the above mappings */ |
| 134 | init_xlat_tables(); |
| 135 | } |
Raymond Mao | ab98f15 | 2024-11-14 13:28:36 -0800 | [diff] [blame] | 136 | |
| 137 | #if ((MEASURED_BOOT || DICE_PROTECTION_ENVIRONMENT) && TRANSFER_LIST) |
| 138 | int plat_handoff_mboot(const void *data, uint32_t data_size, void *tl_base) |
| 139 | { |
| 140 | if (!transfer_list_add(tl_base, TL_TAG_TPM_EVLOG, data_size, data)) |
| 141 | return -1; |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | #endif |