diff --git a/arch.mk b/arch.mk index 7c0335c5..61ffb9dd 100644 --- a/arch.mk +++ b/arch.mk @@ -687,6 +687,12 @@ ifeq ($(TARGET),mcxw) $(MCUXPRESSO_DRIVERS)/drivers/fsl_romapi.o endif +ifeq ($(TARGET),nrf5340_net) + # Net core doesn't support DSP and FP + CFLAGS+=-mcpu=cortex-m33+nodsp+nofp + LDFLAGS+=-mcpu=cortex-m33+nodsp+nofp +endif + ifeq ($(TARGET),imx_rt) CFLAGS+=\ -I$(MCUXPRESSO_DRIVERS) \ diff --git a/config/examples/nrf5340.config b/config/examples/nrf5340.config index 83be6bda..2b463d97 100644 --- a/config/examples/nrf5340.config +++ b/config/examples/nrf5340.config @@ -26,8 +26,8 @@ QSPI_FLASH?=1 # Flash is 4KB pages (app) WOLFBOOT_SECTOR_SIZE?=0x1000 -# Application offset (reserve 48KB for wolfBoot) -WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xC000 +# Application offset (reserve 64KB for wolfBoot) +WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x10000 # Application Partition Size (952KB) WOLFBOOT_PARTITION_SIZE?=0xEE000 diff --git a/config/examples/nrf5340_net.config b/config/examples/nrf5340_net.config index bc18a076..31964ed4 100644 --- a/config/examples/nrf5340_net.config +++ b/config/examples/nrf5340_net.config @@ -30,8 +30,8 @@ ARCH_FLASH_OFFSET=0x01000000 # Flash is 2KB pages WOLFBOOT_SECTOR_SIZE?=0x800 -# Application offset (reserve 48KB for wolfBoot) -WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x0100C000 +# Application offset (reserve 64KB for wolfBoot) +WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x01010000 # Application Partition Size (184KB) WOLFBOOT_PARTITION_SIZE?=0x2E000 diff --git a/docs/Targets.md b/docs/Targets.md index ba832580..12e4f7c5 100644 --- a/docs/Targets.md +++ b/docs/Targets.md @@ -2735,14 +2735,22 @@ Debugging with JLink: 1) Start GDB Server: ``` +# To debug the app core: JLinkGDBServer -device nRF5340_xxAA_APP -if SWD -port 3333 +# To debug the net core: +JLinkGDBServer -device nRF5340_xxAA_NET -if SWD -port 3334 ``` 2) Start GDB -This will use .gdbinit, but can supply `wolfboot.elf -ex "target remote localhost:3333"` if permissions not allowing. ``` -arm-none-eabi-gdb +cd tools/scripts/nrf5340 + +# To debug the app core: +arm-none-eabi-gdb -x app.gdbinit +# To debug the net core: +arm-none-eabi-gdb -x net.gdbinit + b main mon reset c diff --git a/hal/nrf5340.c b/hal/nrf5340.c index 60e231a6..4d42e2f6 100644 --- a/hal/nrf5340.c +++ b/hal/nrf5340.c @@ -340,6 +340,14 @@ void ext_flash_unlock(void) } #endif /* TARGET_nrf5340_net */ +static void hal_handle_approtect(void) { +#ifdef DEBUG_SYMBOLS + /* Needed to allow debugger access */ + CTRLAP_APPROTECT_DISABLE = 0x50FA50FA; + CTRLAP_SECUREAPPROTECT_DISABLE = 0x50FA50FA; +#endif +} + static void clock_init(void) { #ifdef TARGET_nrf5340_app @@ -692,6 +700,8 @@ void hal_init(void) clock_init(); + hal_handle_approtect(); + #ifdef DEBUG_UART uart_init(); #ifdef __WOLFBOOT diff --git a/hal/nrf5340.h b/hal/nrf5340.h index 0098e29c..397cd250 100644 --- a/hal/nrf5340.h +++ b/hal/nrf5340.h @@ -113,10 +113,27 @@ void sleep_us(uint32_t usec); #define SPU_FLASHREGION_PERM_LOCK (1 << 8) /* The content of this register can't be changed until the next reset */ #endif -/* OTP */ -#define UICR_BASE (0x00FF8000UL) +/* UICR */ +#ifdef TARGET_nrf5340_app + #define UICR_BASE (0x00FF8000UL) +#else + #define UICR_BASE (0x01FF8000UL) +#endif #define UICR_USER (UICR_BASE) -#define UICR_OTP (UICR_BASE + 0x100) +#define UICR_APPROTECT (*(volatile uint32_t *)(UICR_BASE + 0x000)) +#define UICR_SECUREAPPROTECT (*(volatile uint32_t *)(UICR_BASE + 0x01C)) +#define UICR_OTP (UICR_BASE + 0x100) + +/* CTRLAP */ +#ifdef TARGET_nrf5340_app + #define CTRLAP_BASE (0x50006000) +#else + #define CTRLAP_BASE (0x41006000) +#endif +#define CTRLAP_APPROTECT_LOCK (*(volatile uint32_t *)(CTRLAP_BASE 0x540)) +#define CTRLAP_APPROTECT_DISABLE (*(volatile uint32_t *)(CTRLAP_BASE 0x544)) +#define CTRLAP_SECUREAPPROTECT_LOCK (*(volatile uint32_t *)(CTRLAP_BASE 0x548)) +#define CTRLAP_SECUREAPPROTECT_DISABLE (*(volatile uint32_t *)(CTRLAP_BASE 0x54C)) /* Reset */ #ifdef TARGET_nrf5340_app diff --git a/test-app/Makefile b/test-app/Makefile index 4e167b4c..cbe3fb89 100644 --- a/test-app/Makefile +++ b/test-app/Makefile @@ -235,7 +235,8 @@ ifeq ($(TARGET),stm32u5) endif ifeq ($(TARGET),nrf5340_net) - APP_OBJS:=app_$(TARGET).o ../test-app/libwolfboot.o + CFLAGS+=-mcpu=cortex-m33+nodsp+nofp + LDFLAGS+=-mcpu=cortex-m33+nodsp+nofp LSCRIPT_TEMPLATE=ARM-nrf5340_net.ld endif diff --git a/tools/scripts/nrf5340/app.gdbinit b/tools/scripts/nrf5340/app.gdbinit new file mode 100644 index 00000000..e1052125 --- /dev/null +++ b/tools/scripts/nrf5340/app.gdbinit @@ -0,0 +1,7 @@ +file wolfboot_app.elf +tar rem:3333 +add-symbol-file image_app.elf +set pagination off +foc c + + diff --git a/tools/scripts/nrf5340/build_flash.sh b/tools/scripts/nrf5340/build_flash.sh index 26bc9857..b5731bed 100755 --- a/tools/scripts/nrf5340/build_flash.sh +++ b/tools/scripts/nrf5340/build_flash.sh @@ -15,8 +15,9 @@ # Build dela update version 3 and flash to external (also reprograms internal flash) # ./tools/scripts/nrf5340/build_flash.sh --delta -#import config for IMAGE_HEADER_SIZE and WOLFBOOT_SECTOR_SIZE -. config/examples/nrf5340.config +#import IMAGE_HEADER_SIZE and WOLFBOOT_SECTOR_SIZE +IMAGE_HEADER_SIZE="$(awk -F '?=|:=|=' '$1 == "IMAGE_HEADER_SIZE" { print $2 }' config/examples/nrf5340.config)" +WOLFBOOT_SECTOR_SIZE="$(awk -F '?=|:=|=' '$1 == "WOLFBOOT_SECTOR_SIZE" { print $2 }' config/examples/nrf5340.config)" # Defaults MAKE_ARGS=" DEBUG_SYMBOLS=1" @@ -47,22 +48,26 @@ fi while test $# -gt 0; do case "$1" in - -h|--help|-?) + -h|--help|-\?) echo "nRF5340 build / flash script" echo " " echo "default: build, erase and program" echo " " echo "options:" - echo "-h, --help show brief help" - echo "-c, --clean cleanup build artifacts" - echo "-b, --build build release with symbols" - echo "-d, --debug build debug" - echo "-v, --verbose build verbose" - echo "--version use custom version" - echo "-e, --erase do erase of internal/external flash" - echo "-p, --program program images built" - echo "-u, --update build update, sign and program external flash" - echo "-t, --delta build update, sign delta and program external flash" + echo "-h, --help show brief help" + echo "-c, --clean cleanup build artifacts" + echo "-b, --build build release with symbols" + echo "-d, --debug build debug" + echo "-v, --verbose build verbose" + echo "--version use custom version" + echo "-e, --erase do erase of internal/external flash" + echo "-ei, --erase-int do erase of internal flash" + echo "-ee, --erase-ext do erase of external flash" + echo "-p, --program program images built" + echo "-pi, --program-int program internal image (boot)" + echo "-pe, --program-ext program external image (update)" + echo "-u, --update build update, sign and program external flash" + echo "-t, --delta build update, sign delta and program external flash" exit 0 ;; -c|--clean) @@ -93,12 +98,32 @@ while test $# -gt 0; do echo "Do erase" shift ;; + -ei|--erase-int) + DO_ERASE_INT=1 + echo "Do erase internal" + shift + ;; + -ee|--erase-ext) + DO_ERASE_EXT=1 + echo "Do erase external" + shift + ;; -p|--program) DO_PROGRAM_INT=1 DO_PROGRAM_EXT=1 echo "Do program" shift ;; + -pi|--program-int) + DO_PROGRAM_INT=1 + echo "Do program internal" + shift + ;; + -pe|--program-ext) + DO_PROGRAM_EXT=1 + echo "Do program external" + shift + ;; --version) UPDATE_VERSION="$2" echo "Use version ${UPDATE_VERSION}" @@ -148,6 +173,8 @@ if [[ $DO_BUILD == 1 ]]; then make clean make $MAKE_ARGS cp test-app/image.bin tools/scripts/nrf5340/image_net.bin + cp wolfboot.elf tools/scripts/nrf5340/wolfboot_net.elf + cp test-app/image.elf tools/scripts/nrf5340/image_net.elf if [ ! -f tools/scripts/nrf5340/factory_net.bin ]; then cp test-app/image_v1_signed.bin tools/scripts/nrf5340/image_net_v1_signed.bin cp factory.bin tools/scripts/nrf5340/factory_net.bin @@ -158,6 +185,8 @@ if [[ $DO_BUILD == 1 ]]; then make clean make $MAKE_ARGS cp test-app/image.bin tools/scripts/nrf5340/image_app.bin + cp wolfboot.elf tools/scripts/nrf5340/wolfboot_app.elf + cp test-app/image.elf tools/scripts/nrf5340/image_app.elf if [ ! -f tools/scripts/nrf5340/factory_app.bin ]; then cp test-app/image_v1_signed.bin tools/scripts/nrf5340/image_app_v1_signed.bin cp factory.bin tools/scripts/nrf5340/factory_app.bin diff --git a/tools/scripts/nrf5340/net.gdbinit b/tools/scripts/nrf5340/net.gdbinit new file mode 100644 index 00000000..80d09624 --- /dev/null +++ b/tools/scripts/nrf5340/net.gdbinit @@ -0,0 +1,7 @@ +file wolfboot_net.elf +tar rem:3334 +add-symbol-file image_net.elf +set pagination off +foc c + +