You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2023/03/04 03:35:28 UTC

[nuttx] 06/08: arch/nrf53: support for APPROTECT, and disable it at default for now

This is an automated email from the ASF dual-hosted git repository.

masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 49446c8e76c802ed4a77e3c52598ea53c346c1aa
Author: raiden00pl <ra...@railab.me>
AuthorDate: Fri Mar 3 17:47:32 2023 +0100

    arch/nrf53: support for APPROTECT, and disable it at default for now
---
 arch/arm/src/nrf53/Kconfig       |  4 ++++
 arch/arm/src/nrf53/nrf53_start.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/arch/arm/src/nrf53/Kconfig b/arch/arm/src/nrf53/Kconfig
index 1bdc33849b..9c6f2a759c 100644
--- a/arch/arm/src/nrf53/Kconfig
+++ b/arch/arm/src/nrf53/Kconfig
@@ -61,6 +61,10 @@ endif # NRF53_NET_BOOT
 
 endif # NRF53_APPCORE
 
+config NRF53_ENABLE_APPROTECT
+	bool "NRF53 enable APPROTECT"
+	default n
+
 # Peripheral Selection
 
 config NRF53_UART
diff --git a/arch/arm/src/nrf53/nrf53_start.c b/arch/arm/src/nrf53/nrf53_start.c
index dfc5f42375..58e6173dc7 100644
--- a/arch/arm/src/nrf53/nrf53_start.c
+++ b/arch/arm/src/nrf53/nrf53_start.c
@@ -37,6 +37,8 @@
 
 #include "nrf53_clockconfig.h"
 #include "hardware/nrf53_utils.h"
+#include "hardware/nrf53_uicr.h"
+#include "hardware/nrf53_ctrlap.h"
 #include "nrf53_lowputc.h"
 #include "nrf53_start.h"
 #include "nrf53_cpunet.h"
@@ -71,6 +73,33 @@
 void __start(void) noinstrument_function;
 #endif
 
+/****************************************************************************
+ * Name: nrf53_approtect
+ ****************************************************************************/
+
+void nrf53_approtect(void)
+{
+#ifdef CONFIG_NRF53_ENABLE_APPROTECT
+  /* Lock APPROTECT.DISABLE */
+
+  putreg32(CTRLAP_APPROTECTLOCK_LOCKED, NRF53_CTRLAP_APPROTECTLOCK);
+#else
+  uint32_t regval = 0;
+
+  /* Load APPROTECT from UICR */
+
+  regval = getreg32(NRF53_UICR_APPROTECT);
+  putreg32(regval, NRF53_CTRLAP_APPROTECTDISABLE);
+
+#  ifdef CONFIG_NRF53_APPCORE
+  /* Load SECUREAPPROTECT from UICR only for the App core */
+
+  regval = getreg32(NRF53_UICR_SECUREAPPROTECT);
+  putreg32(regval, NRF53_CTRLAP_SECUREREADPROTECTDISABLE);
+#  endif
+#endif
+}
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -99,6 +128,10 @@ void __start(void)
 
   __asm__ __volatile__ ("\tcpsid  i\n");
 
+  /* Handle APPROTECT configuration */
+
+  nrf53_approtect();
+
 #ifdef CONFIG_NRF53_NET_BOOT
   /* Boot CPU NET before console init */