Skip to content

Commit f732d3a

Browse files
committed
Support for the Nordic nRF5340 (application and network cores):
* Added nRF5340 driver support for Clock, Internal Flash (NVMC), GPIO, SPU, OTP, UART, SPI, QSPI and IPC. * Added support for updating the network core (Sign using "--id 2")/ * Cleanup the nRF52 port * Improved external QSPI and internal Flash tests and logging. * Improved internal printf support for formatter length.
1 parent 0367597 commit f732d3a

34 files changed

+2224
-181
lines changed

.gdbinit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
tar rem:3333
22
file wolfboot.elf
33
add-symbol-file test-app/image.elf
4+
set pagination off
45
foc c
56

67

.github/workflows/test-configs.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ jobs:
116116
arch: arm
117117
config-file: ./config/examples/nrf52840.config
118118

119+
nrf5340_app_test:
120+
uses: ./.github/workflows/test-build.yml
121+
with:
122+
arch: arm
123+
config-file: ./config/examples/nrf5340.config
124+
125+
nrf5340_net_test:
126+
uses: ./.github/workflows/test-build.yml
127+
with:
128+
arch: arm
129+
config-file: ./config/examples/nrf5340_net.config
130+
119131
nxp_p1021_test:
120132
uses: ./.github/workflows/test-build.yml
121133
with:

arch.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ ifeq ($(CORTEX_M33),1)
181181
CFLAGS+=-mcpu=cortex-m33 -DCORTEX_M33
182182
LDFLAGS+=-mcpu=cortex-m33
183183
ifeq ($(TZEN),1)
184-
OBJS+=hal/stm32_tz.o
184+
ifneq (,$(findstring stm32,$(TARGET)))
185+
OBJS+=hal/stm32_tz.o
186+
endif
185187
CFLAGS+=-mcmse
186188
ifeq ($(WOLFCRYPT_TZ),1)
187189
SECURE_OBJS+=./src/wc_callable.o

config/examples/nrf52840.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ TARGET?=nrf52
33
SIGN?=ECC256
44
HASH?=SHA256
55
DEBUG?=0
6+
DEBUG_UART?=1
67
VTOR?=1
78
CORTEX_M0?=0
89
NO_ASM?=0

config/examples/nrf5340.config

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
ARCH?=ARM
2+
TZEN?=0
3+
TARGET?=nrf5340
4+
SIGN?=ECC256
5+
HASH?=SHA256
6+
WOLFBOOT_VERSION?=1
7+
VTOR?=1
8+
CORTEX_M0?=0
9+
CORTEX_M33?=1
10+
NO_ASM?=0
11+
NO_MPU=1
12+
ALLOW_DOWNGRADE?=0
13+
NVM_FLASH_WRITEONCE?=0
14+
15+
SPMATH?=1
16+
RAM_CODE?=1
17+
18+
DUALBANK_SWAP?=0
19+
FLAGS_HOME=0
20+
DISABLE_BACKUP=0
21+
EXT_FLASH?=1
22+
SPI_FLASH?=0
23+
QSPI_FLASH?=1
24+
25+
# Flash is 4KB pages (app)
26+
WOLFBOOT_SECTOR_SIZE?=0x1000
27+
28+
# Application offset (reserve 48KB for wolfBoot)
29+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xC000
30+
31+
# Application Partition Size (952KB)
32+
WOLFBOOT_PARTITION_SIZE?=0xEE000
33+
34+
# External Flash offset for application update (1MB)
35+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x0
36+
37+
# External Flash offset for network update at 0x100000 (size=256KB)
38+
39+
# External Flash offset for swap (4KB)
40+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x140000
41+
42+
V?=0
43+
DEBUG?=0
44+
DEBUG_UART?=1
45+
USE_GCC=1
46+
47+
CFLAGS_EXTRA+=-DDEBUG_FLASH

config/examples/nrf5340_net.config

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ARCH?=ARM
2+
TZEN?=0
3+
TARGET?=nrf5340_net
4+
SIGN?=ECC256
5+
HASH?=SHA256
6+
WOLFBOOT_VERSION?=1
7+
VTOR?=1
8+
CORTEX_M0?=0
9+
CORTEX_M33?=1
10+
NO_ASM?=1
11+
NO_MPU=1
12+
ALLOW_DOWNGRADE?=0
13+
NVM_FLASH_WRITEONCE?=0
14+
15+
SPMATH?=1
16+
RAM_CODE?=1
17+
18+
DUALBANK_SWAP?=0
19+
FLAGS_HOME=0
20+
DISABLE_BACKUP=0
21+
EXT_FLASH?=0
22+
SPI_FLASH?=0
23+
QSPI_FLASH?=0
24+
25+
# Flash base for network core
26+
ARCH_FLASH_OFFSET=0x01000000
27+
28+
# Flash is 2KB pages
29+
WOLFBOOT_SECTOR_SIZE?=0x800
30+
31+
# Application offset (reserve 48KB for wolfBoot)
32+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x0100C000
33+
34+
# Application Partition Size (184KB)
35+
WOLFBOOT_PARTITION_SIZE?=0x2E000
36+
37+
# Flash offset for update (not used - handled by application core)
38+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x0100C000
39+
40+
# Flash offset for swap (not used - handled by application core)
41+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x103A800
42+
43+
V?=0
44+
DEBUG?=0
45+
DEBUG_UART?=1
46+
USE_GCC=1
47+
48+
CFLAGS_EXTRA+=-DDEBUG_FLASH

docs/Targets.md

Lines changed: 137 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@ This README describes configuration of supported targets.
44

55
## Supported Targets
66

7+
* [Simulated](#simulated)
78
* [Cortex-A53 / Raspberry PI 3](#cortex-a53--raspberry-pi-3-experimental)
89
* [Cypress PSoC-6](#cypress-psoc-6)
910
* [Infineon AURIX TC3xx](#infineon-aurix-tc3xx)
1011
* [Intel x86-64 Intel FSP](#intel-x86_64-with-intel-fsp-support)
1112
* [Microchip SAME51](#microchip-same51)
13+
* [Nordic nRF52840](#nordic-nrf52840)
14+
* [Nordic nRF5340](#nordic-nrf5340)
15+
* [NXP iMX-RT](#nxp-imx-rt)
1216
* [NXP Kinetis](#nxp-kinetis)
1317
* [NXP LPC54xxx](#nxp-lpc54xxx)
1418
* [NXP MCXA153](#nxp-mcxa153)
1519
* [NXP P1021 PPC](#nxp-qoriq-p1021-ppc)
1620
* [NXP T1024 PPC](#nxp-qoriq-t1024-ppc)
1721
* [NXP T2080 PPC](#nxp-qoriq-t2080-ppc)
18-
* [NXP iMX-RT](#nxp-imx-rt)
19-
* [Nordic nRF52840](#nordic-nrf52840)
2022
* [Qemu x86-64 UEFI](#qemu-x86-64-uefi)
2123
* [Renesas RA6M4](#renesas-ra6m4)
2224
* [Renesas RX65N](#renesas-rx65n)
2325
* [Renesas RX72N](#renesas-rx72n)
2426
* [Renesas RZN2L](#renesas-rzn2l)
27+
* [SiFive HiFive1 RISC-V](#sifive-hifive1-risc-v)
2528
* [STM32C0](#stm32c0)
2629
* [STM32F4](#stm32f4)
2730
* [STM32F7](#stm32f7)
@@ -33,7 +36,6 @@ This README describes configuration of supported targets.
3336
* [STM32L5](#stm32l5)
3437
* [STM32U5](#stm32u5)
3538
* [STM32WB55](#stm32wb55)
36-
* [SiFive HiFive1 RISC-V](#sifive-hifive1-risc-v)
3739
* [TI Hercules TMS570LC435](#ti-hercules-tms570lc435)
3840
* [Xilinx Zynq UltraScale](#xilinx-zynq-ultrascale)
3941

@@ -2122,6 +2124,135 @@ Example of flash memory layout and configuration on the nRF52:
21222124
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x58000
21232125
```
21242126
2127+
2128+
## Nordic nRF5340
2129+
2130+
Tested with the Nordic nRF5340-DK. This device has two cores:
2131+
1) Application core: Cortex-M33 at 128MHz, w/TrustZone, 1MB flash, 512KB RAM
2132+
2) Network core: Cortex-M33 at 64MHz, 256KB Flash and 64KB RAM
2133+
2134+
The cores communicate using the IPC peripheral.
2135+
2136+
The network core can access application core resources (flash, RAM, and peripherals) when granted permission through the application's DCNF and SPU settings. A small portion of the application core RAM is dedicated to the exchange of messages between the application and network cores.
2137+
2138+
The DK board has two virtual COM ports. Application core and Network core will each output to different VCOM ports.
2139+
2140+
Example Boot Output:
2141+
2142+
Application Core:
2143+
2144+
```
2145+
wolfBoot HAL Init (app core)
2146+
QSPI Freq=24MHz (Div Clk=3/Sck=1), Addr=24-bits, PageSz=256
2147+
QSPI Activate
2148+
QSPI Flash ID (ret 0): 0xC2 0x28 0x17
2149+
Status Reg: Ret 0, 0x40 (Quad Enabled: Yes)
2150+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x2000022C
2151+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x2000022C
2152+
Boot partition: 0xC000 (size 7428, version 0x1)
2153+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x0 -> 0x20000128
2154+
Update partition: 0x0 (size 7428, version 0x2)
2155+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x2000022C
2156+
Boot partition: 0xC000 (size 7428, version 0x1)
2157+
Booting version: 0x1
2158+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x100000 -> 0x20000128
2159+
Update partition: 0x100000 (size 5492, version 0x2)
2160+
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x0 -> 0x20000230
2161+
Network version: 0x2
2162+
========================
2163+
nRF5340 wolfBoot (app core)
2164+
Copyright 2024 wolfSSL Inc
2165+
GPL v3
2166+
Version : 0x1
2167+
========================
2168+
Internal Flash Write: addr 0xF9FFC, len 4
2169+
Internal Flash Write: addr 0xF9FFB, len 1
2170+
```
2171+
2172+
Network Core:
2173+
2174+
```
2175+
wolfBoot HAL Init (net core)
2176+
Boot partition: 0x100C000 (size 5492, version 0x1)
2177+
Update partition: 0x100C000 (size 5492, version 0x1)
2178+
Boot partition: 0x100C000 (size 5492, version 0x1)
2179+
Booting version: 0x1
2180+
========================
2181+
nRF5340 wolfBoot (net core)
2182+
Copyright 2024 wolfSSL Inc
2183+
GPL v3
2184+
Version : 0x1
2185+
========================
2186+
Internal Flash Write: addr 0x1039FFC, len 4
2187+
Internal Flash Write: addr 0x1039FFB, len 1
2188+
```
2189+
2190+
### Building / Flashing Nordic nRF5340
2191+
2192+
You may optionally use `./tools/scripts/nrf5340/build_flash.sh` for building and flashing both cores.
2193+
2194+
The `nrfjprog` can be used to program external QSPI flash for testing. Example: `nrfjprog --program <qspi_content.hex> --verify -f nrf53`
2195+
2196+
#### Application Core
2197+
2198+
Flash base: 0x00000000, SRAM base: 0x20000000
2199+
2200+
Building Application core:
2201+
2202+
```sh
2203+
cp config/examples/nrf5340.config .config
2204+
make clean
2205+
make
2206+
```
2207+
2208+
Flashing Application core with JLink:
2209+
2210+
```
2211+
JLinkExe -device nRF5340_xxAA_APP -if SWD -speed 4000 -jtagconf -1,-1 -autoconnect 1
2212+
loadbin factory.bin 0x0
2213+
rnh
2214+
```
2215+
2216+
#### Network Core
2217+
2218+
Flash base: 0x01000000, SRAM base: 0x21000000
2219+
2220+
Building Network core:
2221+
2222+
```sh
2223+
cp config/examples/nrf5340_net.config .config
2224+
make clean
2225+
make
2226+
```
2227+
2228+
Flashing Network core with JLink:
2229+
2230+
```
2231+
JLinkExe -device nRF5340_xxAA_NET -if SWD -speed 4000 -jtagconf -1,-1 -autoconnect 1
2232+
loadbin factory.bin 0x01000000
2233+
rnh
2234+
```
2235+
2236+
### Debugging Nordic nRF5340
2237+
2238+
Debugging with JLink:
2239+
2240+
1) Start GDB Server:
2241+
```
2242+
JLinkGDBServer -device nRF5340_xxAA_APP -if SWD -port 3333
2243+
```
2244+
2245+
2) Start GDB
2246+
This will use .gdbinit, but can supply `wolfboot.elf -ex "target remote localhost:3333"` if permissions not allowing.
2247+
2248+
```
2249+
arm-none-eabi-gdb
2250+
b main
2251+
mon reset
2252+
c
2253+
```
2254+
2255+
21252256
## Simulated
21262257

21272258
You can create a simulated target that uses files to mimic an internal and
@@ -2864,8 +2995,8 @@ repository that can be directly flashed into the BIOS flash of the board.
28642995

28652996
## Infineon AURIX TC3xx
28662997

2867-
wolfBoot supports the AURIX TC3xx family of devices, and provides a demo application targeting the TC375 AURIX LiteKit-V2.
2998+
wolfBoot supports the AURIX TC3xx family of devices, and provides a demo application targeting the TC375 AURIX LiteKit-V2.
28682999

2869-
For detailed instructions on using wolfBoot with the AURIX TC3xx, please refer to [IDE/AURIX/README.md](../IDE/AURIX/README.md)
3000+
For detailed instructions on using wolfBoot with the AURIX TC3xx, please refer to [IDE/AURIX/README.md](../IDE/AURIX/README.md)
28703001

2871-
wolfBoot can also integrate with [wolfHSM](https://www.wolfssl.com/products/wolfhsm/) on AURIX TC3xx devices, offloading cryptographic operations and key storage to the AURIX HSM core. For more information on using wolfBoot with wolfHSM on AURIX devices, please contact us at [email protected].
3002+
wolfBoot can also integrate with [wolfHSM](https://www.wolfssl.com/products/wolfhsm/) on AURIX TC3xx devices, offloading cryptographic operations and key storage to the AURIX HSM core. For more information on using wolfBoot with wolfHSM on AURIX devices, please contact us at [email protected].

hal/nrf52.c

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,42 @@
1919
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
2020
*/
2121

22+
#ifdef TARGET_nrf52
23+
2224
#include <stdint.h>
2325
#include "image.h"
26+
#include "nrf52.h"
2427

25-
/* Assembly helpers */
26-
#define DMB() __asm__ volatile ("dmb")
27-
28-
29-
/* Instantiation */
30-
#define CLOCK_CONTROL_BASE (0x40000000)
31-
#define NVMC_BASE (0x4001E000)
32-
28+
#ifdef DEBUG_UART
29+
void uart_init(void)
30+
{
31+
UART0_BAUDRATE = BAUD_115200;
32+
UART0_ENABLE = 1;
33+
}
3334

34-
/* Flash write/erase control */
35-
#define NVMC_CONFIG *((volatile uint32_t *)(NVMC_BASE + 0x504))
36-
#define NVMC_ERASEPAGE *((volatile uint32_t *)(NVMC_BASE + 0x508))
37-
#define NVMC_READY *((volatile uint32_t *)(NVMC_BASE + 0x400))
38-
#define NVMC_CONFIG_REN 0
39-
#define NVMC_CONFIG_WEN 1
40-
#define NVMC_CONFIG_EEN 2
35+
static void uart_write_char(char c)
36+
{
37+
UART0_EVENT_ENDTX = 0;
4138

42-
#define FLASH_PAGE_SIZE (4096)
39+
UART0_TXD_PTR = (uint32_t)(&c);
40+
UART0_TXD_MAXCOUNT = 1;
41+
UART0_TASK_STARTTX = 1;
42+
while(UART0_EVENT_ENDTX == 0)
43+
;
44+
}
4345

44-
/* Clock control */
45-
#define TASKS_HFCLKSTART *((volatile uint32_t *)(CLOCK_CONTROL_BASE + 0x000))
46-
#define TASKS_HFCLKSTOP *((volatile uint32_t *)(CLOCK_CONTROL_BASE + 0x004))
47-
#define TASKS_HFCLKSTARTED *((volatile uint32_t *)(CLOCK_CONTROL_BASE + 0x100))
46+
void uart_write(const char* buf, unsigned int sz)
47+
{
48+
uint32_t pos = 0;
49+
while (sz-- > 0) {
50+
char c = buf[pos++];
51+
if (c == '\n') { /* handle CRLF */
52+
uart_write_char('\r');
53+
}
54+
uart_write_char(c);
55+
}
56+
}
57+
#endif /* DEBUG_UART */
4858

4959
static void RAMFUNCTION flash_wait_complete(void)
5060
{
@@ -117,3 +127,4 @@ void hal_prepare_boot(void)
117127
TASKS_HFCLKSTOP = 1;
118128
}
119129

130+
#endif /* TARGET_nrf52 */

0 commit comments

Comments
 (0)