Skip to content

Commit d12de2d

Browse files
asmellbycarlescufi
authored andcommitted
soc: silabs: Add soc_prep_hook() for Series 2
CMSIS SystemInit is not used in Zephyr. Implement the functionality that isn't already done by Zephyr startup using soc_prep_hook(). The reason the lack of TrustZone init did not create immediately obvious issues previously is that SMU faults can only happen if the SMU clock is enabled. Signed-off-by: Aksel Skauge Mellbye <[email protected]>
1 parent 4dc2f6f commit d12de2d

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

modules/hal_silabs/simplicity_sdk/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ zephyr_compile_definitions_ifdef(CONFIG_SOC_GECKO_DEV_INIT
119119
SL_CATALOG_HFXO_MANAGER_PRESENT
120120
)
121121

122-
zephyr_compile_options(
123-
-mcmse # Cortex-M Security Extensions are needed for startup code
124-
)
125-
126122
zephyr_library_sources(
127123
${DEVICE_DIR}/SiliconLabs/${SILABS_DEVICE_FAMILY}/Source/system_${CONFIG_SOC_SERIES}.c
128124
${EMLIB_DIR}/src/em_system.c

soc/silabs/silabs_s2/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ if SOC_FAMILY_SILABS_S2
66
config SOC_FAMILY_SILABS_S2
77
select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE
88
select BUILD_OUTPUT_HEX
9+
select SOC_PREP_HOOK
910
select SOC_EARLY_INIT_HOOK
1011

1112
rsource "*/Kconfig"
1213

14+
config ARM_SECURE_FIRMWARE
15+
default y
16+
1317
endif

soc/silabs/silabs_s2/efr32mg21/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ config SOC_SERIES_EFR32MG21
66
select CPU_CORTEX_M33
77
select CPU_CORTEX_M_HAS_DWT
88
select ARMV8_M_DSP
9+
select ARM_TRUSTZONE_M
910
select CPU_HAS_FPU
1011
select CPU_HAS_ARM_MPU
1112
select CPU_HAS_ARM_SAU

soc/silabs/silabs_s2/soc.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
#include <sl_hfxo_manager.h>
1919
#include <sl_power_manager.h>
2020

21+
#if defined(CONFIG_PRINTK) || defined(CONFIG_LOG)
22+
#define PR_EXC(...) LOG_ERR(__VA_ARGS__)
23+
#else
24+
#define PR_EXC(...)
25+
#endif /* CONFIG_PRINTK || CONFIG_LOG */
26+
27+
#if (CONFIG_FAULT_DUMP == 2)
28+
#define PR_FAULT_INFO(...) PR_EXC(__VA_ARGS__)
29+
#else
30+
#define PR_FAULT_INFO(...)
31+
#endif
32+
2133
LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL);
2234

2335
void soc_early_init_hook(void)
@@ -35,3 +47,54 @@ void soc_early_init_hook(void)
3547
sl_hfxo_manager_init();
3648
}
3749
}
50+
51+
#if defined(CONFIG_ARM_SECURE_FIRMWARE) && !defined(CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS)
52+
static void smu_fault(void)
53+
{
54+
PR_FAULT_INFO("***** SMU FAULT *****");
55+
56+
if (SMU->IF & SMU_IF_BMPUSEC) {
57+
PR_FAULT_INFO("Bus Manager Fault");
58+
PR_EXC("SMU.BMPUFS=%d", SMU->BMPUFS);
59+
}
60+
if (SMU->IF & SMU_IF_PPUSEC) {
61+
PR_FAULT_INFO("Peripheral Access Fault");
62+
PR_EXC("SMU.PPUFS=%d", SMU->PPUFS);
63+
}
64+
65+
z_fatal_error(K_ERR_CPU_EXCEPTION, NULL);
66+
}
67+
#endif
68+
69+
void soc_prep_hook(void)
70+
{
71+
/* Initialize TrustZone state of the device.
72+
* If this is a secure app with no non-secure callable functions, it is a secure-only app.
73+
* Configure all peripherals except the SMU and SEMAILBOX to non-secure aliases, and make
74+
* all bus transactions from the CPU have non-secure attribution.
75+
* This makes the secure-only app behave more like a non-secure app, allowing the use of
76+
* libraries that only expect to use non-secure peripherals, such as the radio subsystem.
77+
*/
78+
#if defined(CONFIG_ARM_SECURE_FIRMWARE) && !defined(CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS)
79+
#if defined(CMU_CLKEN1_SMU)
80+
CMU_S->CLKEN1_SET = CMU_CLKEN1_SMU;
81+
#endif
82+
SMU->PPUSATD0_CLR = _SMU_PPUSATD0_MASK;
83+
#if defined(SEMAILBOX_PRESENT)
84+
SMU->PPUSATD1_CLR = (_SMU_PPUSATD1_MASK & (~SMU_PPUSATD1_SMU & ~SMU_PPUSATD1_SEMAILBOX));
85+
#else
86+
SMU->PPUSATD1_CLR = (_SMU_PPUSATD1_MASK & ~SMU_PPUSATD1_SMU);
87+
#endif
88+
89+
SAU->CTRL = SAU_CTRL_ALLNS_Msk;
90+
__DSB();
91+
__ISB();
92+
93+
NVIC_ClearPendingIRQ(SMU_SECURE_IRQn);
94+
SMU->IF_CLR = SMU_IF_PPUSEC | SMU_IF_BMPUSEC;
95+
SMU->IEN = SMU_IEN_PPUSEC | SMU_IEN_BMPUSEC;
96+
97+
IRQ_DIRECT_CONNECT(SMU_SECURE_IRQn, 0, smu_fault, 0);
98+
irq_enable(SMU_SECURE_IRQn);
99+
#endif
100+
}

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ manifest:
223223
groups:
224224
- hal
225225
- name: hal_silabs
226-
revision: 5c7a7834a6df7882518a2da127f950d80987dfcb
226+
revision: 69a5fad41aced94dc59d3103edd6ef370851e623
227227
path: modules/hal/silabs
228228
groups:
229229
- hal

0 commit comments

Comments
 (0)