blob: 990a36a88f3c0100c97979cbda5dda000942ad33 [file] [log] [blame]
Masahiro Yamada0fc50a82018-02-01 18:42:24 +09001/*
Yann Gautier2c303e32024-02-05 11:28:29 +01002 * Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved.
Masahiro Yamada0fc50a82018-02-01 18:42:24 +09003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Soby Mathew566034f2018-02-08 17:45:12 +00007#include <assert.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00008
9#include <arch_helpers.h>
10#include <common/bl_common.h>
11#include <common/debug.h>
Harrison Mutaib5d07402025-05-13 14:01:05 +000012#if TRANSFER_LIST
13#include <transfer_list.h>
14#endif
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000015#include <lib/xlat_tables/xlat_tables_compat.h>
16#include <plat/common/platform.h>
Manish V Badarkhe6f0a2f02020-07-23 20:23:01 +010017#include <services/arm_arch_svc.h>
Manish V Badarkhe0e753432020-02-22 08:43:00 +000018#include <smccc_helpers.h>
Sumit Garg2be57b82019-11-15 15:34:55 +053019#include <tools_share/firmware_encrypted.h>
Masahiro Yamada0fc50a82018-02-01 18:42:24 +090020
21/*
Soby Mathew566034f2018-02-08 17:45:12 +000022 * The following platform functions are weakly defined. The Platforms
23 * may redefine with strong definition.
Masahiro Yamada0fc50a82018-02-01 18:42:24 +090024 */
Soby Mathew566034f2018-02-08 17:45:12 +000025#pragma weak bl2_el3_plat_prepare_exit
Masahiro Yamada0fc50a82018-02-01 18:42:24 +090026#pragma weak plat_error_handler
27#pragma weak bl2_plat_preload_setup
Masahiro Yamadaba68ef52018-02-01 16:45:51 +090028#pragma weak bl2_plat_handle_pre_image_load
29#pragma weak bl2_plat_handle_post_image_load
Sumit Garg2be57b82019-11-15 15:34:55 +053030#pragma weak plat_get_enc_key_info
Manish V Badarkhe6f0a2f02020-07-23 20:23:01 +010031#pragma weak plat_is_smccc_feature_available
Manish V Badarkhe0e753432020-02-22 08:43:00 +000032#pragma weak plat_get_soc_version
33#pragma weak plat_get_soc_revision
Arvind Ram Prakashcb4ee3e2025-07-11 10:39:41 -050034#pragma weak plat_get_soc_name
Manish V Badarkhe0e753432020-02-22 08:43:00 +000035
36int32_t plat_get_soc_version(void)
37{
38 return SMC_ARCH_CALL_NOT_SUPPORTED;
39}
40
41int32_t plat_get_soc_revision(void)
42{
43 return SMC_ARCH_CALL_NOT_SUPPORTED;
44}
Masahiro Yamada0fc50a82018-02-01 18:42:24 +090045
Arvind Ram Prakashcb4ee3e2025-07-11 10:39:41 -050046int32_t plat_get_soc_name(char *soc_name __unused)
47{
48 return SMC_ARCH_CALL_NOT_SUPPORTED;
49}
50
Manish V Badarkhe6f0a2f02020-07-23 20:23:01 +010051int32_t plat_is_smccc_feature_available(u_register_t fid __unused)
52{
53 return SMC_ARCH_CALL_NOT_SUPPORTED;
54}
55
Soby Mathew566034f2018-02-08 17:45:12 +000056void bl2_el3_plat_prepare_exit(void)
57{
58}
59
Masahiro Yamada0fc50a82018-02-01 18:42:24 +090060void __dead2 plat_error_handler(int err)
61{
Maheedhar Bollapalli7e288d12024-04-25 10:34:02 +053062 while (1) {
Masahiro Yamada0fc50a82018-02-01 18:42:24 +090063 wfi();
Maheedhar Bollapalli7e288d12024-04-25 10:34:02 +053064 }
Masahiro Yamada0fc50a82018-02-01 18:42:24 +090065}
66
67void bl2_plat_preload_setup(void)
68{
69}
70
Masahiro Yamadaba68ef52018-02-01 16:45:51 +090071int bl2_plat_handle_pre_image_load(unsigned int image_id)
72{
73 return 0;
74}
75
76int bl2_plat_handle_post_image_load(unsigned int image_id)
77{
78 return 0;
79}
80
Roberto Vargas0916c382018-10-19 16:44:18 +010081/*
Sumit Garg2be57b82019-11-15 15:34:55 +053082 * Weak implementation to provide dummy decryption key only for test purposes,
83 * platforms must override this API for any real world firmware encryption
84 * use-case.
85 */
86int plat_get_enc_key_info(enum fw_enc_status_t fw_enc_status, uint8_t *key,
87 size_t *key_len, unsigned int *flags,
88 const uint8_t *img_id, size_t img_id_len)
89{
90#define DUMMY_FIP_ENC_KEY { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
91 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
92 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
93 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef }
94
95 const uint8_t dummy_key[] = DUMMY_FIP_ENC_KEY;
96
97 assert(*key_len >= sizeof(dummy_key));
98
99 *key_len = sizeof(dummy_key);
100 memcpy(key, dummy_key, *key_len);
101 *flags = 0;
102
103 return 0;
104}
105
106/*
Roberto Vargas0916c382018-10-19 16:44:18 +0100107 * Set up the page tables for the generic and platform-specific memory regions.
108 * The size of the Trusted SRAM seen by the BL image must be specified as well
109 * as an array specifying the generic memory regions which can be;
110 * - Code section;
111 * - Read-only data section;
112 * - Init code section, if applicable
113 * - Coherent memory region, if applicable.
114 */
115
116void __init setup_page_tables(const mmap_region_t *bl_regions,
117 const mmap_region_t *plat_regions)
118{
119#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
120 const mmap_region_t *regions = bl_regions;
121
122 while (regions->size != 0U) {
123 VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n",
124 regions->base_va,
125 regions->base_va + regions->size,
126 regions->attr);
127 regions++;
128 }
129#endif
130 /*
131 * Map the Trusted SRAM with appropriate memory attributes.
132 * Subsequent mappings will adjust the attributes for specific regions.
133 */
134 mmap_add(bl_regions);
135
136 /* Now (re-)map the platform-specific memory regions */
137 mmap_add(plat_regions);
138
139 /* Create the page tables to reflect the above mappings */
140 init_xlat_tables();
141}
Raymond Mao4d8b4ca2024-11-14 13:28:36 -0800142
143#if ((MEASURED_BOOT || DICE_PROTECTION_ENVIRONMENT) && TRANSFER_LIST)
144int plat_handoff_mboot(const void *data, uint32_t data_size, void *tl_base)
145{
146 if (!transfer_list_add(tl_base, TL_TAG_TPM_EVLOG, data_size, data))
147 return -1;
148
149 return 0;
150}
151#endif