@@ -150,9 +150,12 @@ K_SEM_DEFINE(boot_log_sem, 1, 1);
150150 * !defined(CONFIG_LOG_MODE_MINIMAL)
151151 */
152152
153+ #if USE_PARTITION_MANAGER
154+ #include <pm_config.h>
155+ #endif
156+
153157#if USE_PARTITION_MANAGER && CONFIG_FPROTECT
154158#include <fprotect.h>
155- #include <pm_config.h>
156159#endif
157160
158161#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL
@@ -173,9 +176,48 @@ K_SEM_DEFINE(boot_log_sem, 1, 1);
173176
174177#define RRAMC_REGION_RWX_LSB 0
175178#define RRAMC_REGION_RWX_WIDTH 3
176- #define RRAMC_REGION_TO_LOCK_ADDR NRF_RRAMC->REGION[4].CONFIG
177- #define RRAMC_REGION_TO_LOCK_ADDR_H (((uint32_t)(&(RRAMC_REGION_TO_LOCK_ADDR))) >> 16)
178- #define RRAMC_REGION_TO_LOCK_ADDR_L (((uint32_t)(&(RRAMC_REGION_TO_LOCK_ADDR))) & 0x0000fffful)
179+
180+ #define RRAMC_REGION_NUMBER 4
181+ #define NRF_RRAM_REGION_SIZE_UNIT 0x400
182+ #define NRF_RRAM_REGION_ADDRESS_RESOLUTION 0x400
183+
184+ #if defined(CONFIG_SOC_NRF54L15_CPUAPP ) || defined(CONFIG_SOC_NRF54L05_CPUAPP ) || \
185+ defined(CONFIG_SOC_NRF54L10_CPUAPP )
186+ #define MAX_PROTECTED_REGION_SIZE (31 * 1024)
187+ #elif defined(CONFIG_SOC_NRF54LV10A_ENGA_CPUAPP ) || defined(CONFIG_SOC_NRF54LM20A_ENGA_CPUAPP )
188+ #define MAX_PROTECTED_REGION_SIZE (127 * 1024)
189+ #elif defined(CONFIG_SOC_NRF54LS05B_ENGA_CPUAPP )
190+ #define MAX_PROTECTED_REGION_SIZE (1023 * 1024)
191+ #endif
192+
193+ #define RRAMC_REGION_CONFIG NRF_RRAMC->REGION[RRAMC_REGION_NUMBER].CONFIG
194+ #define RRAMC_REGION_CONFIG_H (((uint32_t)(&(RRAMC_REGION_CONFIG))) >> 16)
195+ #define RRAMC_REGION_CONFIG_L (((uint32_t)(&(RRAMC_REGION_CONFIG))) & 0x0000fffful)
196+
197+ #define RRAMC_REGION_ADDRESS NRF_RRAMC->REGION[RRAMC_REGION_NUMBER].ADDRESS
198+ #define RRAMC_REGION_ADDRESS_H (((uint32_t)(&(RRAMC_REGION_ADDRESS))) >> 16)
199+ #define RRAMC_REGION_ADDRESS_L (((uint32_t)(&(RRAMC_REGION_ADDRESS))) & 0x0000fffful)
200+
201+ #if (CONFIG_NCS_IS_VARIANT_IMAGE )
202+ #define PROTECTED_REGION_START PM_S1_IMAGE_ADDRESS
203+ #define PROTECTED_REGION_SIZE PM_S1_IMAGE_SIZE
204+ #else
205+ #define PROTECTED_REGION_START PM_MCUBOOT_ADDRESS
206+ #define PROTECTED_REGION_SIZE PM_MCUBOOT_SIZE
207+ #endif
208+
209+ BUILD_ASSERT ((PROTECTED_REGION_START % NRF_RRAM_REGION_ADDRESS_RESOLUTION ) == 0 ,
210+ "Start of protected region is not aligned - not possible to protect" );
211+
212+ BUILD_ASSERT ((PROTECTED_REGION_SIZE % NRF_RRAM_REGION_SIZE_UNIT ) == 0 ,
213+ "Size of protected region is not aligned - not possible to protect" );
214+
215+ BUILD_ASSERT (PROTECTED_REGION_SIZE <= MAX_PROTECTED_REGION_SIZE ,
216+ "Size of protected region is too big for protection" );
217+
218+ #define PROTECTED_REGION_START_H ((PROTECTED_REGION_START) >> 16)
219+ #define PROTECTED_REGION_START_L ((PROTECTED_REGION_START) & 0x0000fffful)
220+
179221#endif /* CONFIG_NCS_MCUBOOT_DISABLE_SELF_RWX */
180222
181223BOOT_LOG_MODULE_REGISTER (mcuboot );
@@ -245,11 +287,21 @@ static void __ramfunc jump_in(uint32_t reset)
245287 " ldr r2 , [r1 ]\n "
246288 /* Size of the region should be set at this point
247289 * by NSIB's DISABLE_NEXT_W.
248- * If not, set it according partition size.
290+ * If not, the region has not been configured yet.
291+ * Set the size and address to the partition size and address.
249292 */
250293 " ands r4 , r2 , %12 \n "
251294 " cbnz r4 , clear_rwx \n "
295+ /* Set the size of the protected region */
252296 " movt r2 , %8 \n "
297+ /* Set the address of the protected region */
298+ " isb \n "
299+ " movw r5 , %13 \n "
300+ " movt r5 , %14 \n "
301+ " movw r6 , %15 \n "
302+ " movt r6 , %16 \n "
303+ " str r6 , [r5 ]\n "
304+ " dsb \n "
253305 " clear_rwx :\n "
254306 " bfc r2 , %9 , %10 \n "
255307 /* Disallow further modifications */
@@ -270,13 +322,17 @@ static void __ramfunc jump_in(uint32_t reset)
270322 " r " (CLEANUP_RAM_GAP_SIZE),
271323 " i " (0)
272324#ifdef CONFIG_NCS_MCUBOOT_DISABLE_SELF_RWX
273- , " i " (RRAMC_REGION_TO_LOCK_ADDR_L ),
274- " i " (RRAMC_REGION_TO_LOCK_ADDR_H ),
275- " i " (CONFIG_PM_PARTITION_SIZE_B0_IMAGE / 1024 ),
325+ , " i " (RRAMC_REGION_CONFIG_L ),
326+ " i " (RRAMC_REGION_CONFIG_H ),
327+ " i " ((PROTECTED_REGION_SIZE) / (NRF_RRAM_REGION_SIZE_UNIT) ),
276328 " i " (RRAMC_REGION_RWX_LSB),
277329 " i " (RRAMC_REGION_RWX_WIDTH),
278330 " i " (RRAMC_REGION_CONFIG_LOCK_Msk),
279- " i " (RRAMC_REGION_CONFIG_SIZE_Msk)
331+ " i " (RRAMC_REGION_CONFIG_SIZE_Msk),
332+ " i " (RRAMC_REGION_ADDRESS_L),
333+ " i " (RRAMC_REGION_ADDRESS_H),
334+ " i " (PROTECTED_REGION_START_L),
335+ " i " (PROTECTED_REGION_START_H)
280336#endif /* CONFIG_NCS_MCUBOOT_DISABLE_SELF_RWX */
281337 : " r0 ", " r1 ", " r2 ", " r3 ", " r4 ", " r5 ", " r6 ", " memory "
282338 );
0 commit comments