From 163f9ba0b9d6b15d045df1d133c90e492bf3591d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 17 Feb 2025 13:31:24 +0100 Subject: [PATCH] soc: nordic: nrf54l: Setup power and clock only on secure build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setup regulators and oscillators only on cpuapp secure target. Signed-off-by: Krzysztof Chruściński --- soc/nordic/nrf54l/soc.c | 58 +++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/soc/nordic/nrf54l/soc.c b/soc/nordic/nrf54l/soc.c index 5c24df49d54..b0f601448be 100644 --- a/soc/nordic/nrf54l/soc.c +++ b/soc/nordic/nrf54l/soc.c @@ -13,45 +13,38 @@ */ #include -#include #include #include #include #include #include -#include +#include +#include +#include +LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL); -#if defined(NRF_APPLICATION) -#include +#if (defined(NRF_APPLICATION) && !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE)) || \ + !defined(__ZEPHYR__) + +#include #include #include #include #include -#endif -#include +#include -#include -#include -#include - -LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL); - -#if defined(NRF_APPLICATION) #define LFXO_NODE DT_NODELABEL(lfxo) #define HFXO_NODE DT_NODELABEL(hfxo) -#endif -static int nordicsemi_nrf54l_init(void) +static inline void power_and_clock_configuration(void) { - /* Update the SystemCoreClock global variable with current core clock - * retrieved from the DT. - */ - SystemCoreClock = NRF_PERIPH_GET_FREQUENCY(DT_NODELABEL(cpu)); - -#if defined(NRF_APPLICATION) - /* Enable ICACHE */ - sys_cache_instr_enable(); - +/* NRF_REGULATORS and NRF_OSCILLATORS are configured to be secure + * as NRF_REGULATORS.POFCON is needed by the secure image to + * prevent glitches when the power supply is attacked. + * + * NRF_OSCILLATORS is also configured as secure because of a HW limitation + * that requires them to be configured with the same security property. + */ #if DT_ENUM_HAS_VALUE(LFXO_NODE, load_capacitors, internal) uint32_t xosc32ktrim = NRF_FICR->XOSC32KTRIM; @@ -165,7 +158,22 @@ static int nordicsemi_nrf54l_init(void) nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_MAIN, true); #endif -#endif /* NRF_APPLICATION */ +} +#endif /* NRF_APPLICATION && !CONFIG_TRUSTED_EXECUTION_NONSECURE */ + +int nordicsemi_nrf54l_init(void) +{ + /* Update the SystemCoreClock global variable with current core clock + * retrieved from the DT. + */ + SystemCoreClock = NRF_PERIPH_GET_FREQUENCY(DT_NODELABEL(cpu)); + + sys_cache_instr_enable(); + +#if (defined(NRF_APPLICATION) && !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE)) || \ + !defined(__ZEPHYR__) + power_and_clock_configuration(); +#endif return 0; }