blob: 937322ec11f1e69c3c313fcd45884cf2f8c0d3a0 [file] [log] [blame]
Miklos Balint386b8b52017-11-29 13:12:32 +00001/*
Feder Liang55194382021-11-22 16:45:33 +08002 * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
Miklos Balint386b8b52017-11-29 13:12:32 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Ken Liu60fcf1c2022-05-18 14:58:48 +08008#include "build_config_check.h"
David Huf07e97d2021-02-15 22:05:40 +08009#include "fih.h"
Ken Liu55ba01f2021-01-20 17:34:50 +080010#include "ffm/tfm_boot_data.h"
TTornblom83d96372019-11-19 12:53:16 +010011#include "region.h"
Summer Qinf993cd42020-08-12 16:55:17 +080012#include "spm_ipc.h"
Kevin Peng54d47fb2021-06-15 16:40:08 +080013#include "tfm_hal_isolation.h"
Summer Qin0eb7c912020-08-19 16:08:50 +080014#include "tfm_hal_platform.h"
Kevin Pengb42ed862022-08-08 14:44:02 +080015#include "tfm_api.h"
Shawn Shanf5471ba2020-09-17 17:34:50 +080016#include "tfm_spm_log.h"
Summer Qin830c5542020-02-14 13:44:20 +080017#include "tfm_version.h"
Raef Colesaefbe082021-06-18 08:53:43 +010018#include "tfm_plat_otp.h"
19#include "tfm_plat_provisioning.h"
Miklos Balint386b8b52017-11-29 13:12:32 +000020
Kevin Peng300c68d2021-08-12 17:40:17 +080021REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Base);
Mate Toth-Pal6bb416a2019-05-07 16:23:55 +020022
David Huf07e97d2021-02-15 22:05:40 +080023static fih_int tfm_core_init(void)
Miklos Balint386b8b52017-11-29 13:12:32 +000024{
Mate Toth-Pal5d3ae082019-07-10 16:14:14 +020025 enum tfm_plat_err_t plat_err = TFM_PLAT_ERR_SYSTEM_ERR;
David Huf07e97d2021-02-15 22:05:40 +080026 fih_int fih_rc = FIH_FAILURE;
Mate Toth-Pal4341de02018-10-02 12:55:47 +020027
Jaykumar Pitambarbhai Patel98e6ce42020-01-06 12:42:42 +053028 /*
29 * Access to any peripheral should be performed after programming
30 * the necessary security components such as PPC/SAU.
31 */
David Huf07e97d2021-02-15 22:05:40 +080032 FIH_CALL(tfm_hal_set_up_static_boundaries, fih_rc);
33 if (fih_not_eq(fih_rc, fih_int_encode(TFM_HAL_SUCCESS))) {
34 FIH_RET(fih_int_encode(TFM_ERROR_GENERIC));
35 }
David Huf07e97d2021-02-15 22:05:40 +080036
37#ifdef TFM_FIH_PROFILE_ON
Kevin Peng38788a12021-09-08 16:23:50 +080038 FIH_CALL(tfm_hal_verify_static_boundaries, fih_rc);
39 if (fih_not_eq(fih_rc, fih_int_encode(TFM_HAL_SUCCESS))) {
David Huf07e97d2021-02-15 22:05:40 +080040 tfm_core_panic();
41 }
42#endif
Jaykumar Pitambarbhai Patel98e6ce42020-01-06 12:42:42 +053043
Kevin Pengc8555732021-09-24 15:15:21 +080044 FIH_CALL(tfm_hal_platform_init, fih_rc);
45 if (fih_not_eq(fih_rc, fih_int_encode(TFM_HAL_SUCCESS))) {
David Huf07e97d2021-02-15 22:05:40 +080046 FIH_RET(fih_int_encode(TFM_ERROR_GENERIC));
Andrei Narkevitch5bba54c2019-09-23 14:09:13 -070047 }
Miklos Balint386b8b52017-11-29 13:12:32 +000048
Raef Colesaefbe082021-06-18 08:53:43 +010049 plat_err = tfm_plat_otp_init();
50 if (plat_err != TFM_PLAT_ERR_SUCCESS) {
Xinyu Zhang6ad07032022-08-10 14:45:56 +080051 FIH_RET(fih_int_encode(TFM_ERROR_GENERIC));
Raef Colesaefbe082021-06-18 08:53:43 +010052 }
53
54 /* Perform provisioning. */
55 if (tfm_plat_provisioning_is_required()) {
56 plat_err = tfm_plat_provisioning_perform();
57 if (plat_err != TFM_PLAT_ERR_SUCCESS) {
58 FIH_RET(fih_int_encode(TFM_ERROR_GENERIC));
59 }
60 } else {
61 tfm_plat_provisioning_check_for_dummy_keys();
62 }
63
Summer Qindea1f2c2021-01-11 14:46:34 +080064 /* Configures architecture */
65 tfm_arch_config_extensions();
Jamie Fox45587672020-08-17 18:31:14 +010066
Shawn Shanf5471ba2020-09-17 17:34:50 +080067 SPMLOG_INFMSG("\033[1;34m[Sec Thread] Secure image initializing!\033[0m\r\n");
Miklos Balint6cbeba62018-04-12 17:31:34 +020068
Shawn Shanf5471ba2020-09-17 17:34:50 +080069 SPMLOG_DBGMSGVAL("TF-M isolation level is: ", TFM_LVL);
Miklos Balint386b8b52017-11-29 13:12:32 +000070
Gabor Toth4d414112021-11-10 17:44:50 +010071#if (CONFIG_TFM_FLOAT_ABI == 2)
72 SPMLOG_INFMSG("TF-M Float ABI: Hard\r\n");
Feder Liang55194382021-11-22 16:45:33 +080073#ifdef CONFIG_TFM_LAZY_STACKING
David Hu91ea6aa2021-11-17 14:34:48 +080074 SPMLOG_INFMSG("Lazy stacking enabled\r\n");
Feder Liangd4dbaa92021-09-07 15:34:46 +080075#else
David Hu91ea6aa2021-11-17 14:34:48 +080076 SPMLOG_INFMSG("Lazy stacking disabled\r\n");
Feder Liangd4dbaa92021-09-07 15:34:46 +080077#endif
78#endif
79
Tamas Ban9ff535b2018-09-18 08:15:18 +010080 tfm_core_validate_boot_data();
81
David Huf07e97d2021-02-15 22:05:40 +080082 FIH_RET(fih_int_encode(TFM_SUCCESS));
Miklos Balint386b8b52017-11-29 13:12:32 +000083}
84
85int main(void)
86{
David Huf07e97d2021-02-15 22:05:40 +080087 fih_int fih_rc = FIH_FAILURE;
88
Mate Toth-Pal6bb416a2019-05-07 16:23:55 +020089 /* set Main Stack Pointer limit */
Kevin Peng300c68d2021-08-12 17:40:17 +080090 tfm_arch_set_msplim((uint32_t)&REGION_NAME(Image$$, ARM_LIB_STACK,
91 $$ZI$$Base));
Mate Toth-Pal6bb416a2019-05-07 16:23:55 +020092
David Huf07e97d2021-02-15 22:05:40 +080093 fih_delay_init();
94
95 FIH_CALL(tfm_core_init, fih_rc);
96 if (fih_not_eq(fih_rc, fih_int_encode(TFM_SUCCESS))) {
Edison Ai9059ea02019-11-28 13:46:14 +080097 tfm_core_panic();
Hugues de Valon4bf875b2019-02-19 14:53:49 +000098 }
David Huf07e97d2021-02-15 22:05:40 +080099
Raef Coles0241dc62020-12-22 11:50:02 +0000100 /* All isolation should have been set up at this point */
101 FIH_LABEL_CRITICAL_POINT();
102
Soby Mathewc64adbc2020-03-11 12:33:44 +0000103 /* Print the TF-M version */
Anton Komlev2d2a6fc2022-02-20 15:47:53 +0000104 SPMLOG_INFMSG("\033[1;34mBooting TF-M "VERSION_FULLSTR"\033[0m\r\n");
Miklos Balint386b8b52017-11-29 13:12:32 +0000105
Edison Ai4d66dc32019-02-18 17:58:49 +0800106 /*
107 * Prioritise secure exceptions to avoid NS being able to pre-empt
108 * secure SVC or SecureFault. Do it before PSA API initialization.
109 */
Ken Liu50e21092020-10-14 16:42:15 +0800110 tfm_arch_set_secure_exception_priorities();
Ken Liu490281d2019-12-30 15:55:26 +0800111
112 /* Move to handler mode for further SPM initialization. */
113 tfm_core_handler_mode();
Kevin Peng300c68d2021-08-12 17:40:17 +0800114
115 return 0;
Miklos Balint386b8b52017-11-29 13:12:32 +0000116}