1 /*
2 * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
3 * Copyright (c) 2019-2024 Cypress Semiconductor Corporation (an Infineon
4 * company) or an affiliate of Cypress Semiconductor Corporation. All rights
5 * reserved.
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 *
9 */
10
11 #include <string.h>
12 #include <stdint.h>
13
14 #include "tfm_hal_device_header.h"
15 #include "cy_pra.h"
16 #include "region_defs.h"
17 #include "target_cfg.h"
18 #include "tfm_hal_platform.h"
19 #include "tfm_plat_defs.h"
20 #include "uart_stdout.h"
21
22 extern const struct memory_region_limits memory_regions;
23
24 /* FIXME:
25 * Instead of TFM-customized mcuboot, at this moment psoc64 uses
26 * Cypress version of it - CypressBootloader (CYBL). CYBL doesn't
27 * populate SHARED_BOOT_MEASUREMENT.
28 * As a temp workaround, mock mcuboot shared data to pass
29 * initialization checks.
30 */
mock_tfm_shared_data(void)31 void mock_tfm_shared_data(void)
32 {
33 const uint32_t mock_data[] = {
34 0x00D92016, 0x00071103, 0x00455053, 0x30000911,
35 0x302E302E, 0x00081102, 0x00000000, 0x00241108,
36 0x6C170A97, 0x5645665E, 0xDB6E2BA6, 0xA4FF4D74,
37 0xFD34D7DB, 0x67449A82, 0x75FD0930, 0xAA15A9F9,
38 0x000A1109, 0x32414853, 0x11013635, 0xE6BF0024,
39 0x26886FD8, 0xFB97FFF4, 0xFBE6C496, 0x463E99C4,
40 0x5D56FC19, 0x34DF6AA2, 0x9A4829C3, 0x114338DC,
41 0x534E0008, 0x11404550, 0x2E300009, 0x42302E30,
42 0x00000811, 0x48000000, 0x7E002411, 0x5FD9229A,
43 0xE9672A5F, 0x31AAE1EA, 0x8514D772, 0x7F3B26BC,
44 0x2C7EF27A, 0x9C6047D2, 0x4937BB9F, 0x53000A11,
45 0x35324148, 0x24114136, 0xCA60B300, 0x6B8CC9F5,
46 0x82482A94, 0x23489DFA, 0xA966B1EF, 0x4A6E6AEF,
47 0x19197CA3, 0xC0CC1FED, 0x00000049, 0x00000000
48 };
49 uint32_t *boot_data = (uint32_t*)SHARED_BOOT_MEASUREMENT_BASE;
50 memcpy(boot_data, mock_data, sizeof(mock_data));
51 }
52
tfm_hal_platform_init(void)53 FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_platform_init(void)
54 {
55 enum tfm_plat_err_t plat_err = TFM_PLAT_ERR_SYSTEM_ERR;
56
57 platform_init();
58
59 #if defined(CY_DEVICE_SECURE)
60 /* Initialize Protected Register Access driver. */
61 Cy_PRA_Init();
62 #endif /* defined(CY_DEVICE_SECURE) */
63
64 /* FIXME: Use the actual data from mcuboot */
65 mock_tfm_shared_data();
66
67 __enable_irq();
68 stdio_init();
69
70 plat_err = nvic_interrupt_target_state_cfg();
71 if (plat_err != TFM_PLAT_ERR_SUCCESS) {
72 FIH_RET(fih_int_encode(TFM_HAL_ERROR_GENERIC));
73 }
74
75 plat_err = nvic_interrupt_enable();
76 if (plat_err != TFM_PLAT_ERR_SUCCESS) {
77 FIH_RET(fih_int_encode(TFM_HAL_ERROR_GENERIC));
78 }
79
80 FIH_RET(fih_int_encode(TFM_HAL_SUCCESS));
81 }
82
tfm_hal_get_ns_VTOR(void)83 uint32_t tfm_hal_get_ns_VTOR(void)
84 {
85 return memory_regions.non_secure_code_start;
86 }
87
tfm_hal_get_ns_entry_point(void)88 uint32_t tfm_hal_get_ns_entry_point(void)
89 {
90 return *((uint32_t *)(memory_regions.non_secure_code_start + 4));
91 }
92