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