Skip to content

Commit 076eabc

Browse files
mattia-moffadanielinux
authored andcommitted
Non-TZ nRF5340 fixes
1 parent 60d953e commit 076eabc

File tree

10 files changed

+108
-23
lines changed

10 files changed

+108
-23
lines changed

arch.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,12 @@ ifeq ($(TARGET),mcxw)
687687
$(MCUXPRESSO_DRIVERS)/drivers/fsl_romapi.o
688688
endif
689689

690+
ifeq ($(TARGET),nrf5340_net)
691+
# Net core doesn't support DSP and FP
692+
CFLAGS+=-mcpu=cortex-m33+nodsp+nofp
693+
LDFLAGS+=-mcpu=cortex-m33+nodsp+nofp
694+
endif
695+
690696
ifeq ($(TARGET),imx_rt)
691697
CFLAGS+=\
692698
-I$(MCUXPRESSO_DRIVERS) \

config/examples/nrf5340.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ QSPI_FLASH?=1
2626
# Flash is 4KB pages (app)
2727
WOLFBOOT_SECTOR_SIZE?=0x1000
2828

29-
# Application offset (reserve 48KB for wolfBoot)
30-
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xC000
29+
# Application offset (reserve 64KB for wolfBoot)
30+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x10000
3131

3232
# Application Partition Size (952KB)
3333
WOLFBOOT_PARTITION_SIZE?=0xEE000

config/examples/nrf5340_net.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ ARCH_FLASH_OFFSET=0x01000000
3030
# Flash is 2KB pages
3131
WOLFBOOT_SECTOR_SIZE?=0x800
3232

33-
# Application offset (reserve 48KB for wolfBoot)
34-
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x0100C000
33+
# Application offset (reserve 64KB for wolfBoot)
34+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x01010000
3535

3636
# Application Partition Size (184KB)
3737
WOLFBOOT_PARTITION_SIZE?=0x2E000

docs/Targets.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,14 +2735,22 @@ Debugging with JLink:
27352735

27362736
1) Start GDB Server:
27372737
```
2738+
# To debug the app core:
27382739
JLinkGDBServer -device nRF5340_xxAA_APP -if SWD -port 3333
2740+
# To debug the net core:
2741+
JLinkGDBServer -device nRF5340_xxAA_NET -if SWD -port 3334
27392742
```
27402743

27412744
2) Start GDB
2742-
This will use .gdbinit, but can supply `wolfboot.elf -ex "target remote localhost:3333"` if permissions not allowing.
27432745

27442746
```
2745-
arm-none-eabi-gdb
2747+
cd tools/scripts/nrf5340
2748+
2749+
# To debug the app core:
2750+
arm-none-eabi-gdb -x app.gdbinit
2751+
# To debug the net core:
2752+
arm-none-eabi-gdb -x net.gdbinit
2753+
27462754
b main
27472755
mon reset
27482756
c

hal/nrf5340.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ void ext_flash_unlock(void)
340340
}
341341
#endif /* TARGET_nrf5340_net */
342342

343+
static void hal_handle_approtect(void) {
344+
#ifdef DEBUG_SYMBOLS
345+
/* Needed to allow debugger access */
346+
CTRLAP_APPROTECT_DISABLE = 0x50FA50FA;
347+
CTRLAP_SECUREAPPROTECT_DISABLE = 0x50FA50FA;
348+
#endif
349+
}
350+
343351
static void clock_init(void)
344352
{
345353
#ifdef TARGET_nrf5340_app
@@ -692,6 +700,8 @@ void hal_init(void)
692700

693701
clock_init();
694702

703+
hal_handle_approtect();
704+
695705
#ifdef DEBUG_UART
696706
uart_init();
697707
#ifdef __WOLFBOOT

hal/nrf5340.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,27 @@ void sleep_us(uint32_t usec);
113113
#define SPU_FLASHREGION_PERM_LOCK (1 << 8) /* The content of this register can't be changed until the next reset */
114114
#endif
115115

116-
/* OTP */
117-
#define UICR_BASE (0x00FF8000UL)
116+
/* UICR */
117+
#ifdef TARGET_nrf5340_app
118+
#define UICR_BASE (0x00FF8000UL)
119+
#else
120+
#define UICR_BASE (0x01FF8000UL)
121+
#endif
118122
#define UICR_USER (UICR_BASE)
119-
#define UICR_OTP (UICR_BASE + 0x100)
123+
#define UICR_APPROTECT (*(volatile uint32_t *)(UICR_BASE + 0x000))
124+
#define UICR_SECUREAPPROTECT (*(volatile uint32_t *)(UICR_BASE + 0x01C))
125+
#define UICR_OTP (UICR_BASE + 0x100)
126+
127+
/* CTRLAP */
128+
#ifdef TARGET_nrf5340_app
129+
#define CTRLAP_BASE (0x50006000)
130+
#else
131+
#define CTRLAP_BASE (0x41006000)
132+
#endif
133+
#define CTRLAP_APPROTECT_LOCK (*(volatile uint32_t *)(CTRLAP_BASE 0x540))
134+
#define CTRLAP_APPROTECT_DISABLE (*(volatile uint32_t *)(CTRLAP_BASE 0x544))
135+
#define CTRLAP_SECUREAPPROTECT_LOCK (*(volatile uint32_t *)(CTRLAP_BASE 0x548))
136+
#define CTRLAP_SECUREAPPROTECT_DISABLE (*(volatile uint32_t *)(CTRLAP_BASE 0x54C))
120137

121138
/* Reset */
122139
#ifdef TARGET_nrf5340_app

test-app/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ ifeq ($(TARGET),stm32u5)
235235
endif
236236

237237
ifeq ($(TARGET),nrf5340_net)
238-
APP_OBJS:=app_$(TARGET).o ../test-app/libwolfboot.o
238+
CFLAGS+=-mcpu=cortex-m33+nodsp+nofp
239+
LDFLAGS+=-mcpu=cortex-m33+nodsp+nofp
239240
LSCRIPT_TEMPLATE=ARM-nrf5340_net.ld
240241
endif
241242

tools/scripts/nrf5340/app.gdbinit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
file wolfboot_app.elf
2+
tar rem:3333
3+
add-symbol-file image_app.elf
4+
set pagination off
5+
foc c
6+
7+

tools/scripts/nrf5340/build_flash.sh

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
# Build dela update version 3 and flash to external (also reprograms internal flash)
1616
# ./tools/scripts/nrf5340/build_flash.sh --delta
1717

18-
#import config for IMAGE_HEADER_SIZE and WOLFBOOT_SECTOR_SIZE
19-
. config/examples/nrf5340.config
18+
#import IMAGE_HEADER_SIZE and WOLFBOOT_SECTOR_SIZE
19+
IMAGE_HEADER_SIZE="$(awk -F '?=|:=|=' '$1 == "IMAGE_HEADER_SIZE" { print $2 }' config/examples/nrf5340.config)"
20+
WOLFBOOT_SECTOR_SIZE="$(awk -F '?=|:=|=' '$1 == "WOLFBOOT_SECTOR_SIZE" { print $2 }' config/examples/nrf5340.config)"
2021

2122
# Defaults
2223
MAKE_ARGS=" DEBUG_SYMBOLS=1"
@@ -47,22 +48,26 @@ fi
4748

4849
while test $# -gt 0; do
4950
case "$1" in
50-
-h|--help|-?)
51+
-h|--help|-\?)
5152
echo "nRF5340 build / flash script"
5253
echo " "
5354
echo "default: build, erase and program"
5455
echo " "
5556
echo "options:"
56-
echo "-h, --help show brief help"
57-
echo "-c, --clean cleanup build artifacts"
58-
echo "-b, --build build release with symbols"
59-
echo "-d, --debug build debug"
60-
echo "-v, --verbose build verbose"
61-
echo "--version use custom version"
62-
echo "-e, --erase do erase of internal/external flash"
63-
echo "-p, --program program images built"
64-
echo "-u, --update build update, sign and program external flash"
65-
echo "-t, --delta build update, sign delta and program external flash"
57+
echo "-h, --help show brief help"
58+
echo "-c, --clean cleanup build artifacts"
59+
echo "-b, --build build release with symbols"
60+
echo "-d, --debug build debug"
61+
echo "-v, --verbose build verbose"
62+
echo "--version use custom version"
63+
echo "-e, --erase do erase of internal/external flash"
64+
echo "-ei, --erase-int do erase of internal flash"
65+
echo "-ee, --erase-ext do erase of external flash"
66+
echo "-p, --program program images built"
67+
echo "-pi, --program-int program internal image (boot)"
68+
echo "-pe, --program-ext program external image (update)"
69+
echo "-u, --update build update, sign and program external flash"
70+
echo "-t, --delta build update, sign delta and program external flash"
6671
exit 0
6772
;;
6873
-c|--clean)
@@ -93,12 +98,32 @@ while test $# -gt 0; do
9398
echo "Do erase"
9499
shift
95100
;;
101+
-ei|--erase-int)
102+
DO_ERASE_INT=1
103+
echo "Do erase internal"
104+
shift
105+
;;
106+
-ee|--erase-ext)
107+
DO_ERASE_EXT=1
108+
echo "Do erase external"
109+
shift
110+
;;
96111
-p|--program)
97112
DO_PROGRAM_INT=1
98113
DO_PROGRAM_EXT=1
99114
echo "Do program"
100115
shift
101116
;;
117+
-pi|--program-int)
118+
DO_PROGRAM_INT=1
119+
echo "Do program internal"
120+
shift
121+
;;
122+
-pe|--program-ext)
123+
DO_PROGRAM_EXT=1
124+
echo "Do program external"
125+
shift
126+
;;
102127
--version)
103128
UPDATE_VERSION="$2"
104129
echo "Use version ${UPDATE_VERSION}"
@@ -148,6 +173,8 @@ if [[ $DO_BUILD == 1 ]]; then
148173
make clean
149174
make $MAKE_ARGS
150175
cp test-app/image.bin tools/scripts/nrf5340/image_net.bin
176+
cp wolfboot.elf tools/scripts/nrf5340/wolfboot_net.elf
177+
cp test-app/image.elf tools/scripts/nrf5340/image_net.elf
151178
if [ ! -f tools/scripts/nrf5340/factory_net.bin ]; then
152179
cp test-app/image_v1_signed.bin tools/scripts/nrf5340/image_net_v1_signed.bin
153180
cp factory.bin tools/scripts/nrf5340/factory_net.bin
@@ -158,6 +185,8 @@ if [[ $DO_BUILD == 1 ]]; then
158185
make clean
159186
make $MAKE_ARGS
160187
cp test-app/image.bin tools/scripts/nrf5340/image_app.bin
188+
cp wolfboot.elf tools/scripts/nrf5340/wolfboot_app.elf
189+
cp test-app/image.elf tools/scripts/nrf5340/image_app.elf
161190
if [ ! -f tools/scripts/nrf5340/factory_app.bin ]; then
162191
cp test-app/image_v1_signed.bin tools/scripts/nrf5340/image_app_v1_signed.bin
163192
cp factory.bin tools/scripts/nrf5340/factory_app.bin

tools/scripts/nrf5340/net.gdbinit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
file wolfboot_net.elf
2+
tar rem:3334
3+
add-symbol-file image_net.elf
4+
set pagination off
5+
foc c
6+
7+

0 commit comments

Comments
 (0)