1212
1313#include <nrf.h>
1414
15+ #if defined(CONFIG_SOC_SERIES_NRF54LX )
1516#include <nrfx_rramc.h>
17+ #elif defined(CONFIG_SOC_SERIES_NRF71X )
18+ #include <nrfx_mramc.h>
19+
20+ #define REG_MRAMC_CONFIGNVR_PAGE_3 (uint32_t *)((uint32_t)NRF_MRAMC + 0x58C)
21+ #define MRAM_SICR_ENABLE_WRITE_ERASE 0xFFF00022
22+ #define MRAM_SICR_DISABLE_WRITE_ERASE 0x0
23+ #endif
1624
1725#include <cracen/lib_kmu.h>
1826
@@ -34,6 +42,35 @@ void lib_kmu_clear_all_events(void)
3442#endif
3543}
3644
45+ #if defined(CONFIG_SOC_SERIES_NRF71X )
46+ static void mram_enable_kmu_write_erase_to_sicr (bool permission )
47+ {
48+ /* CONFIGNVR.PAGE[3] contain the SICR info block
49+ * setting info block write and erase permission to
50+ * allow KMU to write to SICR in MRAM.
51+ *
52+ * Register not available on hal_nordic this version, need
53+ * to update this when it is available, WZN-5799.
54+ */
55+ static nrf_mramc_readynext_timeout_t prev_readynext_timeout ;
56+
57+ if (permission ) {
58+ /* Save previous readynext timeout value */
59+ nrf_mramc_readynext_timeout_get (NRF_MRAMC , & prev_readynext_timeout );
60+ nrf_mramc_readynext_timeout_t readynext_timeout = {
61+ .value = NRF_MRAMC_READYNEXTTIMEOUT_DEFAULT ,
62+ .direct_write = true,
63+ };
64+ nrf_mramc_readynext_timeout_set (NRF_MRAMC , & readynext_timeout );
65+ } else {
66+ nrf_mramc_readynext_timeout_set (NRF_MRAMC , & prev_readynext_timeout );
67+ }
68+
69+ * REG_MRAMC_CONFIGNVR_PAGE_3 = permission ?
70+ MRAM_SICR_ENABLE_WRITE_ERASE : MRAM_SICR_DISABLE_WRITE_ERASE ;
71+ }
72+ #endif
73+
3774static int trigger_task_and_wait_for_event_or_error (volatile uint32_t * task ,
3875 volatile uint32_t * event )
3976{
@@ -80,7 +117,7 @@ int lib_kmu_provision_slot(int slot_id, struct kmu_src *kmu_src)
80117 __ASSERT (IS_PTR_ALIGNED_BYTES (kmu_src -> dest , 16 ), "DEST misaligned" );
81118
82119 int result = 1 ;
83-
120+ #if defined( CONFIG_SOC_SERIES_NRF54LX )
84121#if defined(__NRF_TFM__ )
85122 nrf_rramc_config_t rramc_config ;
86123
@@ -92,19 +129,28 @@ int lib_kmu_provision_slot(int slot_id, struct kmu_src *kmu_src)
92129#else
93130 nrfx_rramc_write_enable_set (true, 0 );
94131#endif
132+ #elif defined(CONFIG_SOC_SERIES_NRF71X )
133+ /* Enable write and erase from KMU to SICR in MRAM */
134+ mram_enable_kmu_write_erase_to_sicr (true);
135+ #endif
95136
96137 NRF_KMU_S -> KEYSLOT = slot_id ;
97138 NRF_KMU_S -> SRC = (uint32_t )kmu_src ;
98139
99140 result = trigger_task_and_wait_for_event_or_error (& (NRF_KMU_S -> TASKS_PROVISION ),
100141 & (NRF_KMU_S -> EVENTS_PROVISIONED ));
101142
143+ #if defined(CONFIG_SOC_SERIES_NRF54LX )
102144#if defined(__NRF_TFM__ )
103145 rramc_config .write_buff_size = orig_write_buf_size ;
104146 nrf_rramc_config_set (NRF_RRAMC_S , & rramc_config );
105147#else
106148 nrfx_rramc_write_enable_set (false, 0 );
107149#endif
150+ #elif defined(CONFIG_SOC_SERIES_NRF71X )
151+ /* Disable write and erase from KMU to SICR in MRAM */
152+ mram_enable_kmu_write_erase_to_sicr (false);
153+ #endif
108154
109155 return result ;
110156}
@@ -145,17 +191,23 @@ int lib_kmu_block_slot_range(int slot_id, unsigned int slot_count)
145191
146192int lib_kmu_revoke_slot (int slot_id )
147193{
148- #if !defined(__NRF_TFM__ )
194+ #if !defined(__NRF_TFM__ ) && defined( CONFIG_SOC_SERIES_NRF54LX )
149195 nrfx_rramc_write_enable_set (true, 0 );
196+ #elif defined(CONFIG_SOC_SERIES_NRF71X )
197+ /* Enable write and erase from KMU to SICR in MRAM */
198+ mram_enable_kmu_write_erase_to_sicr (true);
150199#endif
151200
152201 NRF_KMU_S -> KEYSLOT = slot_id ;
153202
154203 int result = trigger_task_and_wait_for_event_or_error (& (NRF_KMU_S -> TASKS_REVOKE ),
155204 & (NRF_KMU_S -> EVENTS_REVOKED ));
156205
157- #if !defined(__NRF_TFM__ )
206+ #if !defined(__NRF_TFM__ ) && defined( CONFIG_SOC_SERIES_NRF54LX )
158207 nrfx_rramc_write_enable_set (false, 0 );
208+ #elif defined(CONFIG_SOC_SERIES_NRF71X )
209+ /* Disable write and erase from KMU to SICR in MRAM */
210+ mram_enable_kmu_write_erase_to_sicr (false);
159211#endif
160212
161213 return result ;
0 commit comments