Skip to content

Commit 91145d5

Browse files
dgarskedanielinux
authored andcommitted
Add wolfBoot support for NXP LPC54S018M-EVK
1 parent 71b395d commit 91145d5

9 files changed

Lines changed: 777 additions & 0 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ wolfboot.efi: wolfboot.elf
334334
wolfboot.bin: wolfboot.elf
335335
@echo "\t[BIN] $@"
336336
$(Q)$(OBJCOPY) $(OBJCOPY_FLAGS) -O binary $^ $@
337+
ifeq ($(TARGET),nxp_lpc54s018m)
338+
@echo "\t[LPC] enhanced boot block"
339+
$(Q)python3 -c "import struct,os;f=open('$@','r+b');sz=os.path.getsize('$@');f.seek(0x24);f.write(struct.pack('<2I',0xEDDC94BD,0x160));f.seek(0x160);f.write(struct.pack('<25I',0xFEEDA5A5,3,0x10000000,sz-4,0,0,0,0,0,0xEDDC94BD,0,0,0,0x001640EF,0,0,0x1301001D,0,0,0,0x00000100,0,0,0x04030050,0x14110D09));f.seek(0);d=f.read(28);w=struct.unpack('<7I',d);s=sum(w)&0xFFFFFFFF;ck=(0x100000000-s)&0xFFFFFFFF;f.seek(0x1C);f.write(struct.pack('<I',ck));f.close();print('\tvector checksum: 0x%08X'%ck)"
340+
endif
337341
@echo
338342
@echo "\t[SIZE]"
339343
$(Q)$(SIZE) wolfboot.elf

arch.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,11 @@ ifeq ($(TARGET),lpc)
11891189
endif
11901190
endif
11911191

1192+
ifeq ($(TARGET),nxp_lpc54s018m)
1193+
ARCH_FLASH_OFFSET=0x10000000
1194+
# Bare-metal HAL — no NXP SDK dependencies
1195+
endif
1196+
11921197
ifeq ($(TARGET),lpc55s69)
11931198
ifneq ($(TZEN),1)
11941199
LSCRIPT_IN=hal/$(TARGET)-ns.ld
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ARCH?=ARM
2+
TARGET?=nxp_lpc54s018m
3+
SIGN?=ECC256
4+
HASH?=SHA256
5+
DEBUG?=0
6+
#DEBUG_UART?=1
7+
VTOR?=1
8+
NO_ASM?=0
9+
EXT_FLASH?=0
10+
SPI_FLASH?=0
11+
ALLOW_DOWNGRADE?=0
12+
NVM_FLASH_WRITEONCE?=0
13+
WOLFBOOT_VERSION?=0
14+
V?=0
15+
SPMATH?=1
16+
RAM_CODE?=1
17+
DUALBANK_SWAP?=0
18+
PKA?=1
19+
WOLFBOOT_PARTITION_SIZE?=0xF0000
20+
WOLFBOOT_SECTOR_SIZE?=0x1000
21+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x10010000
22+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x10100000
23+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x101F0000

docs/Targets.md

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This README describes configuration of supported targets.
2121
* [NXP iMX-RT](#nxp-imx-rt)
2222
* [NXP Kinetis](#nxp-kinetis)
2323
* [NXP LPC54xxx](#nxp-lpc54xxx)
24+
* [NXP LPC54S018M](#nxp-lpc54s018m)
2425
* [NXP LPC55S69](#nxp-lpc55s69)
2526
* [NXP LS1028A](#nxp-ls1028a)
2627
* [NXP MCXA153](#nxp-mcxa153)
@@ -1937,6 +1938,202 @@ arm-none-eabi-gdb wolfboot.elf -ex "target remote localhost:3333"
19371938
```
19381939

19391940

1941+
## NXP LPC54S018M
1942+
1943+
The NXP LPC54S018M is a Cortex-M4 microcontroller running at 180MHz. Unlike the
1944+
LPC54606 which has internal flash, the LPC54S018M has **no internal NOR flash**
1945+
all code executes from on-package SPIFI-mapped QSPI flash (Winbond W25Q32JV, 4MB)
1946+
at address `0x10000000`.
1947+
1948+
This has been tested on the LPC54S018M-EVK board, which includes an on-board
1949+
Link2 debug probe (CMSIS-DAP / J-Link compatible) and a VCOM UART via Flexcomm0.
1950+
1951+
Because flash erase/write operations disable XIP (execute-in-place), all flash
1952+
programming functions must run from RAM. The configuration uses `RAM_CODE=1` to
1953+
ensure this.
1954+
1955+
### LPC54S018M: Link2 debug probe setup
1956+
1957+
The LPC54S018M-EVK has an on-board LPC-Link2 debug probe (LPC4322). The probe
1958+
firmware determines the debug protocol: CMSIS-DAP or J-Link. J-Link firmware is
1959+
recommended for use with wolfBoot.
1960+
1961+
**Jumper JP5** controls the Link2 boot mode:
1962+
- **Installed (normal):** Link2 runs from its internal flash (debug probe mode)
1963+
- **Removed (DFU):** Link2 enters DFU mode for firmware programming
1964+
1965+
To program J-Link firmware onto the Link2:
1966+
1967+
1. Remove JP5 and power cycle the board. The Link2 enters DFU mode
1968+
(USB `1fc9:000c`).
1969+
1970+
2. Install [NXP LinkServer](https://www.nxp.com/design/design-center/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER)
1971+
which includes LPCScrypt.
1972+
1973+
3. Boot LPCScrypt onto the Link2 (requires sudo or udev rules):
1974+
1975+
```sh
1976+
sudo /usr/local/LinkServer/lpcscrypt/scripts/boot_lpcscrypt
1977+
```
1978+
1979+
4. Identify the LPCScrypt serial port and program J-Link firmware:
1980+
1981+
```sh
1982+
# Find the new ttyACM device created after boot_lpcscrypt
1983+
ls -lt /dev/ttyACM*
1984+
1985+
# Program J-Link firmware (replace /dev/ttyACMx with the correct port)
1986+
sudo /usr/local/LinkServer/lpcscrypt/bin/lpcscrypt -d /dev/ttyACMx \
1987+
program /usr/local/LinkServer/lpcscrypt/probe_firmware/LPCLink2/Firmware_JLink_LPC-Link2_20230502.bin BankA
1988+
```
1989+
1990+
5. Re-install JP5 and power cycle the board. The Link2 should now enumerate
1991+
as a Segger J-Link USB device.
1992+
1993+
**Note:** If `uart-monitor` or another tool has the serial port open, you must
1994+
release it first (e.g., `uart-monitor yield /dev/ttyACMx`) before running
1995+
lpcscrypt.
1996+
1997+
To program CMSIS-DAP firmware instead (for use with pyocd/OpenOCD):
1998+
1999+
```sh
2000+
sudo /usr/local/LinkServer/lpcscrypt/bin/lpcscrypt -d /dev/ttyACMx \
2001+
program /usr/local/LinkServer/lpcscrypt/probe_firmware/LPCLink2/LPC432x_CMSIS_DAP_V5_460.bin.hdr BankA
2002+
```
2003+
2004+
### LPC54S018M: MCUXpresso SDK setup
2005+
2006+
This requires the NXP MCUXpresso SDK. We tested using
2007+
[mcuxsdk-manifests](https://github.com/nxp-mcuxpresso/mcuxsdk-manifests) and
2008+
[CMSIS_5](https://github.com/nxp-mcuxpresso/CMSIS_5) placed under "../NXP".
2009+
2010+
```sh
2011+
cd ../NXP
2012+
2013+
# Install west
2014+
python -m venv west-venv
2015+
source west-venv/bin/activate
2016+
pip install west
2017+
2018+
# Set up the repository
2019+
west init -m https://github.com/nxp-mcuxpresso/mcuxsdk-manifests.git mcuxpresso-sdk
2020+
cd mcuxpresso-sdk
2021+
west update
2022+
2023+
deactivate
2024+
```
2025+
2026+
The CMSIS headers are also needed:
2027+
2028+
```sh
2029+
cd ../NXP
2030+
git clone https://github.com/nxp-mcuxpresso/CMSIS_5.git
2031+
```
2032+
2033+
### LPC54S018M: Flash partition layout
2034+
2035+
The 4MB SPIFI flash is partitioned as follows:
2036+
2037+
| Region | Address | Size |
2038+
|--------------|-------------|--------|
2039+
| wolfBoot | 0x10000000 | 64KB |
2040+
| Boot (app) | 0x10010000 | 960KB |
2041+
| Update | 0x10100000 | 960KB |
2042+
| Swap sector | 0x101F0000 | 4KB |
2043+
2044+
The sector size is 4KB, matching the W25Q32JV minimum erase size.
2045+
2046+
### LPC54S018M: Configuring and compiling
2047+
2048+
Copy the example configuration file and build with make:
2049+
2050+
```sh
2051+
cp config/examples/nxp_lpc54s018m.config .config
2052+
make
2053+
```
2054+
2055+
This produces `factory.bin` containing wolfBoot + the signed test application.
2056+
2057+
### LPC54S018M: Loading the firmware
2058+
2059+
The on-board Link2 debugger supports both CMSIS-DAP and J-Link protocols.
2060+
See [Link2 debug probe setup](#lpc54s018m-link2-debug-probe-setup) for
2061+
programming the probe firmware.
2062+
2063+
**Using JLink** (Link2 with J-Link firmware):
2064+
2065+
```
2066+
JLinkExe -device LPC54S018M -if SWD -speed 4000
2067+
loadbin factory.bin 0x10000000
2068+
r
2069+
g
2070+
```
2071+
2072+
**Using pyocd** (Link2 with CMSIS-DAP firmware):
2073+
2074+
```sh
2075+
pyocd pack install LPC54S018J4MET180
2076+
pyocd flash -t LPC54S018J4MET180 factory.bin --base-address 0x10000000
2077+
pyocd reset -t LPC54S018J4MET180
2078+
```
2079+
2080+
**Note:** The LPC54S018M boot ROM validates a vector table checksum at offset
2081+
0x1C. The build system automatically computes and patches this checksum into
2082+
`wolfboot.bin`. If the checksum is invalid, the boot ROM will enter ISP mode
2083+
instead of booting from SPIFI flash.
2084+
2085+
### LPC54S018M: Testing firmware update
2086+
2087+
1. Build and flash factory.bin (version 1). USR_LED1 (P3.14) lights up.
2088+
2089+
2. Sign a version 2 update image and load it to the update partition:
2090+
2091+
```sh
2092+
# Build update image (version 2)
2093+
make test-app/image_v2_signed.bin
2094+
```
2095+
2096+
```
2097+
JLinkExe -device LPC54S018M -if SWD -speed 4000
2098+
loadbin test-app/image_v2_signed.bin 0x10100000
2099+
r
2100+
g
2101+
```
2102+
2103+
3. The test application detects the update, triggers a swap via
2104+
`wolfBoot_update_trigger()`, and resets. After the swap, USR_LED2 (P3.3)
2105+
lights up indicating version 2 is running.
2106+
2107+
4. The application calls `wolfBoot_success()` to confirm the update and
2108+
prevent rollback.
2109+
2110+
### LPC54S018M: LED indicators
2111+
2112+
The test application uses three user LEDs (accent LEDs accent active low):
2113+
2114+
| LED | GPIO | Meaning |
2115+
|-----------|--------|----------------------------|
2116+
| USR_LED1 | P3.14 | Version 1 running |
2117+
| USR_LED2 | P3.3 | Version 2+ running |
2118+
| USR_LED3 | P2.2 | Update activity in progress |
2119+
2120+
### LPC54S018M: Debugging with JLink
2121+
2122+
```
2123+
JLinkGDBServer -device LPC54S018M -if SWD -speed 4000 -port 3333
2124+
```
2125+
2126+
Then, from another console:
2127+
2128+
```
2129+
arm-none-eabi-gdb wolfboot.elf -ex "target remote localhost:3333"
2130+
(gdb) add-symbol-file test-app/image.elf 0x10010100
2131+
```
2132+
2133+
Note: The image.elf symbol offset is the boot partition address (0x10010000) plus
2134+
the wolfBoot image header size (0x100).
2135+
2136+
19402137
## NXP LPC55S69
19412138

19422139
The NXP LPC55S69 is a dual-core Cortex-M33 microcontroller. The support has been

0 commit comments

Comments
 (0)