Skip to content

Commit d92f31d

Browse files
committed
Fixes for the test-app and configuration.
1 parent 1977a3e commit d92f31d

7 files changed

Lines changed: 319 additions & 69 deletions

File tree

config/examples/nxp-s32k142.config

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,26 @@
88

99
ARCH?=ARM
1010
CORTEX_M4?=1
11+
NO_MPU=1
1112
TARGET?=s32k1xx
1213
SIGN?=ECC256
1314
HASH?=SHA256
14-
DEBUG?=0
1515
VTOR?=1
1616
NO_ASM?=0
1717
EXT_FLASH?=0
1818
SPI_FLASH?=0
1919
ALLOW_DOWNGRADE?=0
20-
NVM_FLASH_WRITEONCE?=0
20+
21+
# S32K1xx flash requires erase before write (cannot re-program same location)
22+
# This is required for sector swap trailer flag updates to work correctly
23+
NVM_FLASH_WRITEONCE?=1
24+
2125
WOLFBOOT_VERSION?=0
2226
V?=0
2327
SPMATH?=1
2428
RAM_CODE?=1
2529
DUALBANK_SWAP?=0
2630

27-
# Disable MPU (S32K1xx MPU configuration needs customization)
28-
WOLFBOOT_NO_MPU?=1
29-
30-
# Enable hardfault debugging
31-
DEBUG_HARDFAULT?=0
32-
33-
# Debug UART on LPUART1 (PTC6=RX, PTC7=TX)
34-
DEBUG_UART?=0
35-
3631
# 2KB sectors (S32K142 only - larger variants use 4KB sectors)
3732
WOLFBOOT_SECTOR_SIZE?=0x800
3833

@@ -51,4 +46,10 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x3E000
5146
#CFLAGS_EXTRA+=-DS32K1XX_CLOCK_HSRUN
5247

5348
# Optionally enable watchdog
54-
#CFLAGS_EXTRA+=-DWATCHDOG
49+
#CFLAGS_EXTRA+=-DWATCHDOG
50+
51+
# Debugging options (uncomment as needed)
52+
DEBUG?=0
53+
DEBUG_SYMBOLS?=0
54+
DEBUG_UART?=0
55+
#CFLAGS_EXTRA+=-DDEBUG_HARDFAULT

config/examples/nxp-s32k144.config

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
ARCH?=ARM
1010
CORTEX_M4?=1
11+
NO_MPU=1
1112
TARGET?=s32k1xx
1213
SIGN?=ECC256
1314
HASH?=SHA256
14-
DEBUG?=0
1515
VTOR?=1
1616
NO_ASM?=0
1717
EXT_FLASH?=0
1818
SPI_FLASH?=0
1919
ALLOW_DOWNGRADE?=0
20-
NVM_FLASH_WRITEONCE?=0
20+
21+
# S32K1xx flash requires erase before write (cannot re-program same location)
22+
# This is required for sector swap trailer flag updates to work correctly
23+
NVM_FLASH_WRITEONCE?=1
24+
2125
WOLFBOOT_VERSION?=0
2226
V?=0
2327
SPMATH?=1
@@ -27,15 +31,6 @@ DUALBANK_SWAP?=0
2731
# Select S32K144 variant for correct flash size and sector size
2832
CFLAGS_EXTRA+=-DS32K144
2933

30-
# Disable MPU (S32K1xx MPU configuration needs customization)
31-
WOLFBOOT_NO_MPU?=1
32-
33-
# Enable hardfault debugging
34-
#CFLAGS_EXTRA+=-DDEBUG_HARDFAULT
35-
36-
# Debug UART on LPUART1 (PTC6=RX, PTC7=TX)
37-
DEBUG_UART?=0
38-
3934
# 4KB sectors (S32K144/146/148 with 512KB+ flash)
4035
WOLFBOOT_SECTOR_SIZE?=0x1000
4136

@@ -55,3 +50,9 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x7C000
5550

5651
# Optionally enable watchdog
5752
#CFLAGS_EXTRA+=-DWATCHDOG
53+
54+
# Debugging options (uncomment as needed)
55+
DEBUG?=0
56+
DEBUG_SYMBOLS?=0
57+
DEBUG_UART?=0
58+
#CFLAGS_EXTRA+=-DDEBUG_HARDFAULT

config/examples/nxp-s32k146.config

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
ARCH?=ARM
1010
CORTEX_M4?=1
11+
NO_MPU=1
1112
TARGET?=s32k1xx
1213
SIGN?=ECC256
1314
HASH?=SHA256
14-
DEBUG?=0
1515
VTOR?=1
1616
NO_ASM?=0
1717
EXT_FLASH?=0
1818
SPI_FLASH?=0
1919
ALLOW_DOWNGRADE?=0
20-
NVM_FLASH_WRITEONCE?=0
20+
21+
# S32K1xx flash requires erase before write (cannot re-program same location)
22+
# This is required for sector swap trailer flag updates to work correctly
23+
NVM_FLASH_WRITEONCE?=1
24+
2125
WOLFBOOT_VERSION?=0
2226
V?=0
2327
SPMATH?=1
@@ -27,15 +31,6 @@ DUALBANK_SWAP?=0
2731
# Select S32K146 variant for correct flash size and sector size
2832
CFLAGS_EXTRA+=-DS32K146
2933

30-
# Disable MPU (S32K1xx MPU configuration needs customization)
31-
WOLFBOOT_NO_MPU?=1
32-
33-
# Enable hardfault debugging
34-
#CFLAGS_EXTRA+=-DDEBUG_HARDFAULT
35-
36-
# Debug UART on LPUART1 (PTC6=RX, PTC7=TX)
37-
DEBUG_UART?=0
38-
3934
# 4KB sectors (S32K144/146/148 with 512KB+ flash)
4035
WOLFBOOT_SECTOR_SIZE?=0x1000
4136

@@ -55,3 +50,9 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0xF4000
5550

5651
# Optionally enable watchdog
5752
#CFLAGS_EXTRA+=-DWATCHDOG
53+
54+
# Debugging options (uncomment as needed)
55+
DEBUG?=0
56+
DEBUG_SYMBOLS?=0
57+
DEBUG_UART?=0
58+
#CFLAGS_EXTRA+=-DDEBUG_HARDFAULT

config/examples/nxp-s32k148.config

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
ARCH?=ARM
1010
CORTEX_M4?=1
11+
NO_MPU=1
1112
TARGET?=s32k1xx
1213
SIGN?=ECC256
1314
HASH?=SHA256
14-
DEBUG?=0
1515
VTOR?=1
1616
NO_ASM?=0
1717
EXT_FLASH?=0
1818
SPI_FLASH?=0
1919
ALLOW_DOWNGRADE?=0
20-
NVM_FLASH_WRITEONCE?=0
20+
21+
# S32K1xx flash requires erase before write (cannot re-program same location)
22+
# This is required for sector swap trailer flag updates to work correctly
23+
NVM_FLASH_WRITEONCE?=1
24+
2125
WOLFBOOT_VERSION?=0
2226
V?=0
2327
SPMATH?=1
@@ -27,15 +31,6 @@ DUALBANK_SWAP?=0
2731
# Select S32K148 variant for correct flash size and sector size
2832
CFLAGS_EXTRA+=-DS32K148
2933

30-
# Disable MPU (S32K1xx MPU configuration needs customization)
31-
WOLFBOOT_NO_MPU?=1
32-
33-
# Enable hardfault debugging
34-
#CFLAGS_EXTRA+=-DDEBUG_HARDFAULT
35-
36-
# Debug UART on LPUART1 (PTC6=RX, PTC7=TX)
37-
DEBUG_UART?=0
38-
3934
# 4KB sectors (S32K144/146/148 with 512KB+ flash)
4035
WOLFBOOT_SECTOR_SIZE?=0x1000
4136

@@ -55,3 +50,9 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x1EC000
5550

5651
# Optionally enable watchdog
5752
#CFLAGS_EXTRA+=-DWATCHDOG
53+
54+
# Debugging options (uncomment as needed)
55+
DEBUG?=0
56+
DEBUG_SYMBOLS?=0
57+
DEBUG_UART?=0
58+
#CFLAGS_EXTRA+=-DDEBUG_HARDFAULT

docs/Targets.md

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,12 +2880,15 @@ The following build options are available for the S32K1xx HAL:
28802880

28812881
| Option | Description |
28822882
|--------|-------------|
2883+
| `NVM_FLASH_WRITEONCE` | **Required for S32K1xx.** Flash can only be written once between erases. Enables proper sector swap trailer management. |
2884+
| `RAM_CODE` | **Required for S32K1xx.** Run flash operations from RAM (no read-while-write on same block). |
28832885
| `WOLFBOOT_RESTORE_CLOCK` | Restore clock to SIRC (8 MHz) before booting application. Recommended for applications that configure their own clocks. |
28842886
| `WOLFBOOT_DISABLE_WATCHDOG_ON_BOOT` | Keep watchdog disabled when jumping to application. By default, the watchdog is re-enabled before boot since it is enabled out of reset. |
28852887
| `WATCHDOG` | Enable watchdog during wolfBoot operation. Recommended for production. |
28862888
| `WATCHDOG_TIMEOUT_MS` | Watchdog timeout in milliseconds when `WATCHDOG` is enabled (default: 1000ms). |
28872889
| `S32K1XX_CLOCK_HSRUN` | Enable HSRUN mode (112 MHz). Requires external crystal and SPLL (not fully implemented). |
28882890
| `DEBUG_UART` | Enable LPUART1 debug output. |
2891+
| `DEBUG_HARDFAULT` | Enable detailed hard fault debugging output. |
28892892
| `S32K144`, `S32K146`, `S32K148` | Select variant (default is S32K142). Affects flash/SRAM size definitions. |
28902893

28912894
**IMPORTANT:** Flash sector size depends on the S32K variant:
@@ -2948,6 +2951,41 @@ cp factory.srec /media/<user>/S32K142EVB/
29482951

29492952
The board will automatically program the flash and reset.
29502953

2954+
### NXP S32K1XX: Flash Script
2955+
2956+
A convenience script is provided for building and flashing S32K142:
2957+
2958+
```sh
2959+
./tools/scripts/nxp-s32k142-flash.sh [OPTIONS]
2960+
```
2961+
2962+
**Options:**
2963+
2964+
| Option | Description |
2965+
|--------|-------------|
2966+
| (none) | Build and flash `factory.srec` (v1 only) |
2967+
| `--test-update` | Build with v2 in update partition (use `trigger` command to start update) |
2968+
| `--update` | Build with v2 and auto-trigger (starts update on boot) |
2969+
| `--skip-build` | Skip build, use existing `.srec` file |
2970+
| `--skip-flash` | Skip flashing (just build) |
2971+
| `--skip-uart` | Skip UART monitoring |
2972+
| `--uart-only` | Only monitor UART (no build/flash) |
2973+
| `--interactive` | Keep UART open until Ctrl+C |
2974+
| `--timeout SECS` | UART capture duration (default: 5s) |
2975+
2976+
**Examples:**
2977+
2978+
```sh
2979+
# Build and flash factory image, monitor UART for 5 seconds
2980+
./tools/scripts/nxp-s32k142-flash.sh
2981+
2982+
# Build with v2 update, flash, and stay on UART
2983+
./tools/scripts/nxp-s32k142-flash.sh --test-update --interactive
2984+
2985+
# Just monitor UART
2986+
./tools/scripts/nxp-s32k142-flash.sh --uart-only --interactive
2987+
```
2988+
29512989
### NXP S32K1XX: Test Application
29522990

29532991
The S32K1xx test application (`test-app/app_s32k1xx.c`) provides a feature-rich demo application for testing wolfBoot functionality.
@@ -2963,12 +3001,14 @@ The S32K1xx test application (`test-app/app_s32k1xx.c`) provides a feature-rich
29633001

29643002
| Command | Description |
29653003
|---------|-------------|
2966-
| `help` or `?` | Show available commands |
2967-
| `info` | Display system and partition information |
3004+
| `help` | Show available commands |
3005+
| `info` | Display partition and keystore information |
3006+
| `status` | Show partition versions and states |
29683007
| `success` | Mark current firmware as successful (wolfBoot_success) |
2969-
| `update` | Trigger firmware update (wolfBoot_update_trigger) |
2970-
| `reset` | Perform software reset |
2971-
| `xmodem` | Receive firmware image via XMODEM protocol |
3008+
| `trigger` | Set update flag if update image is in flash |
3009+
| `update` | Receive firmware via XMODEM and trigger update |
3010+
| `timestamp` | Show current system time (ms) |
3011+
| `reboot` | Perform software reset |
29723012

29733013
**UART Configuration:**
29743014
- LPUART1: PTC7 (TX), PTC6 (RX)
@@ -2984,23 +3024,32 @@ Copyright 2025 wolfSSL Inc.
29843024
Firmware Version: 1
29853025
29863026
=== Partition Information ===
2987-
Boot Partition:
2988-
Address: 0x0000C000
3027+
Boot Partition @ 0xC000:
29893028
Version: 1
2990-
State: SUCCESS
2991-
Update Partition:
2992-
Address: 0x00025000
2993-
Version: 0
2994-
State: SUCCESS
2995-
Swap Partition:
2996-
Address: 0x0003E000
2997-
Size: 2048 bytes
3029+
State: SUCCESS (0x00)
3030+
Update Partition @ 0x25000:
3031+
Version: 0 (empty)
3032+
State: (no trailer)
3033+
3034+
=== Keystore Information ===
3035+
Number of keys: 1
3036+
Key 0: ECDSA P-256 (secp256r1), SHA-256
29983037
29993038
Type 'help' for available commands.
30003039
30013040
cmd>
30023041
```
30033042

3043+
**Testing Firmware Update:**
3044+
3045+
1. Flash with v2 image: `./tools/scripts/nxp-s32k142-flash.sh --test-update`
3046+
2. Connect to UART: `picocom -b 115200 /dev/ttyACM1`
3047+
3. Run `status` to verify v1 in boot, v2 in update
3048+
4. Run `trigger` to set update flag
3049+
5. Run `reboot` to start update
3050+
6. After reboot, LED changes from Green (v1) to Blue (v2)
3051+
7. Run `success` to mark v2 as good
3052+
30043053
### NXP S32K1XX: Flash Configuration Field (FCF)
30053054

30063055
The bootloader includes the Flash Configuration Field (FCF) at address 0x400-0x40F with the following settings:
@@ -3043,6 +3092,10 @@ Then power cycle the board.
30433092

30443093
The following features are planned or available for contribution:
30453094

3095+
- [x] **Sector swap update**: Full firmware update with sector swapping (completed)
3096+
- [x] **Interactive test application**: Console with status, trigger, success commands (completed)
3097+
- [x] **Flash automation script**: `tools/scripts/nxp-s32k142-flash.sh` (completed)
3098+
- [ ] **XMODEM improvements**: ISR-based UART RX for reliable high-speed transfers
30463099
- [ ] **SPLL + SOSC support**: Add external crystal oscillator and SPLL configuration for true 112 MHz operation in HSRUN mode
30473100
- [ ] **Hardware crypto acceleration**: Integrate CSEc (Cryptographic Services Engine) for hardware-accelerated crypto operations
30483101
- [ ] **FlexNVM/EEPROM support**: Add support for FlexNVM partitioning and EEPROM emulation

0 commit comments

Comments
 (0)