Non-TZ nRF5340 fixes

pull/638/head
Mattia Moffa 2025-11-19 16:40:15 +01:00 committed by Daniele Lacamera
parent 60d953ea97
commit 076eabcc54
10 changed files with 108 additions and 23 deletions

View File

@ -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) \

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,7 @@
file wolfboot_app.elf
tar rem:3333
add-symbol-file image_app.elf
set pagination off
foc c

View File

@ -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

View File

@ -0,0 +1,7 @@
file wolfboot_net.elf
tar rem:3334
add-symbol-file image_net.elf
set pagination off
foc c