blob: d38fc6f75b20da5a3ccb7dc58883f4a8b1cce721 [file] [log] [blame]
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +09001/*
Zelalem87675d42020-02-03 14:56:42 -06002 * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +09003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Soby Mathew2f38ce32018-02-08 17:45:12 +00007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <arch_helpers.h>
10#include <common/bl_common.h>
11#include <common/debug.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <lib/xlat_tables/xlat_tables_compat.h>
13#include <plat/common/platform.h>
Manish V Badarkhef809c6e2020-02-22 08:43:00 +000014#include <smccc_helpers.h>
Sumit Garg617e2152019-11-15 15:34:55 +053015#include <tools_share/firmware_encrypted.h>
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090016
17/*
Soby Mathew2f38ce32018-02-08 17:45:12 +000018 * The following platform functions are weakly defined. The Platforms
19 * may redefine with strong definition.
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090020 */
Soby Mathew2f38ce32018-02-08 17:45:12 +000021#pragma weak bl2_el3_plat_prepare_exit
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090022#pragma weak plat_error_handler
23#pragma weak bl2_plat_preload_setup
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +090024#pragma weak bl2_plat_handle_pre_image_load
25#pragma weak bl2_plat_handle_post_image_load
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090026#pragma weak plat_try_next_boot_source
Sumit Garg617e2152019-11-15 15:34:55 +053027#pragma weak plat_get_enc_key_info
Manish V Badarkhef809c6e2020-02-22 08:43:00 +000028#pragma weak plat_get_soc_version
29#pragma weak plat_get_soc_revision
30
31int32_t plat_get_soc_version(void)
32{
33 return SMC_ARCH_CALL_NOT_SUPPORTED;
34}
35
36int32_t plat_get_soc_revision(void)
37{
38 return SMC_ARCH_CALL_NOT_SUPPORTED;
39}
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090040
Soby Mathew2f38ce32018-02-08 17:45:12 +000041void bl2_el3_plat_prepare_exit(void)
Masahiro Yamada43d20b32018-02-01 16:46:18 +090042{
Masahiro Yamada43d20b32018-02-01 16:46:18 +090043}
44
Soby Mathew2f38ce32018-02-08 17:45:12 +000045void __dead2 plat_error_handler(int err)
Masahiro Yamada43d20b32018-02-01 16:46:18 +090046{
Soby Mathew2f38ce32018-02-08 17:45:12 +000047 while (1)
48 wfi();
Masahiro Yamada43d20b32018-02-01 16:46:18 +090049}
50
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090051void bl2_plat_preload_setup(void)
52{
53}
54
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +090055int bl2_plat_handle_pre_image_load(unsigned int image_id)
56{
57 return 0;
58}
59
60int bl2_plat_handle_post_image_load(unsigned int image_id)
61{
62 return 0;
63}
64
Masahiro Yamada2a4fe4f2018-02-01 18:42:24 +090065int plat_try_next_boot_source(void)
66{
67 return 0;
68}
Soby Mathew73308d02018-01-09 14:36:14 +000069
Roberto Vargas344ff022018-10-19 16:44:18 +010070/*
Sumit Garg617e2152019-11-15 15:34:55 +053071 * Weak implementation to provide dummy decryption key only for test purposes,
72 * platforms must override this API for any real world firmware encryption
73 * use-case.
74 */
75int plat_get_enc_key_info(enum fw_enc_status_t fw_enc_status, uint8_t *key,
76 size_t *key_len, unsigned int *flags,
77 const uint8_t *img_id, size_t img_id_len)
78{
79#define DUMMY_FIP_ENC_KEY { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
80 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
84 const uint8_t dummy_key[] = DUMMY_FIP_ENC_KEY;
85
86 assert(*key_len >= sizeof(dummy_key));
87
88 *key_len = sizeof(dummy_key);
89 memcpy(key, dummy_key, *key_len);
90 *flags = 0;
91
92 return 0;
93}
94
95/*
Roberto Vargas344ff022018-10-19 16:44:18 +010096 * Set up the page tables for the generic and platform-specific memory regions.
97 * The size of the Trusted SRAM seen by the BL image must be specified as well
98 * as an array specifying the generic memory regions which can be;
99 * - Code section;
100 * - Read-only data section;
101 * - Init code section, if applicable
102 * - Coherent memory region, if applicable.
103 */
104
105void __init setup_page_tables(const mmap_region_t *bl_regions,
106 const mmap_region_t *plat_regions)
107{
108#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
109 const mmap_region_t *regions = bl_regions;
110
111 while (regions->size != 0U) {
112 VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n",
113 regions->base_va,
114 regions->base_va + regions->size,
115 regions->attr);
116 regions++;
117 }
118#endif
119 /*
120 * Map the Trusted SRAM with appropriate memory attributes.
121 * Subsequent mappings will adjust the attributes for specific regions.
122 */
123 mmap_add(bl_regions);
124
125 /* Now (re-)map the platform-specific memory regions */
126 mmap_add(plat_regions);
127
128 /* Create the page tables to reflect the above mappings */
129 init_xlat_tables();
130}