Skip to content

Commit 4e3e55d

Browse files
dgarskedanielinux
authored andcommitted
Add NXP S32K1xx support with full update functionality
- HAL: Flash (FTFC), UART (LPUART1), Clock (FIRC 48MHz), Watchdog - Requires NVM_FLASH_WRITEONCE=1 and RAM_CODE=1 for proper operation - Test app with interactive console: status, trigger, success, reboot - LED indicators: Green (v1), Blue (v2+) - Flash automation script: tools/scripts/nxp-s32k142-flash.sh - Tested on S32K142EVB with sector swap update Supported variants: S32K142 (256KB), S32K144 (512KB), S32K146 (1MB), S32K148 (2MB)
1 parent 8a04871 commit 4e3e55d

18 files changed

Lines changed: 3501 additions & 18 deletions

.github/workflows/test-configs.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,30 @@ jobs:
216216
arch: arm
217217
config-file: ./config/examples/mcxw-tz.config
218218

219+
nxp_s32k142_test:
220+
uses: ./.github/workflows/test-build.yml
221+
with:
222+
arch: arm
223+
config-file: ./config/examples/nxp-s32k142.config
224+
225+
nxp_s32k144_test:
226+
uses: ./.github/workflows/test-build.yml
227+
with:
228+
arch: arm
229+
config-file: ./config/examples/nxp-s32k144.config
230+
231+
nxp_s32k146_test:
232+
uses: ./.github/workflows/test-build.yml
233+
with:
234+
arch: arm
235+
config-file: ./config/examples/nxp-s32k146.config
236+
237+
nxp_s32k148_test:
238+
uses: ./.github/workflows/test-build.yml
239+
with:
240+
arch: arm
241+
config-file: ./config/examples/nxp-s32k148.config
242+
219243
microchip_mpfs250_test:
220244
uses: ./.github/workflows/test-build-riscv.yml
221245
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*.rom
3939
*.bin
4040
*.efi
41+
*.srec
4142

4243
# Debug files
4344
*.dSYM/

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ endif
465465
$(WOLFBOOT_ORIGIN) wolfboot.bin \
466466
$(WOLFBOOT_PARTITION_BOOT_ADDRESS) test-app/image_v1_signed.bin
467467

468+
factory.srec: factory.bin
469+
@echo "\t[BIN2SREC] $@"
470+
$(Q)$(OBJCOPY) -I binary -O srec --change-addresses=$(WOLFBOOT_ORIGIN) $< $@
471+
468472
factory_wstage1.bin: $(BINASSEMBLE) stage1/loader_stage1.bin wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin
469473
@echo "\t[MERGE] $@"
470474
$(Q)$(BINASSEMBLE) $@ \
@@ -516,6 +520,7 @@ $(LSCRIPT): $(LSCRIPT_IN) FORCE
516520

517521
hex: wolfboot.hex
518522
srec: wolfboot.srec
523+
factory-srec: factory.srec
519524

520525
%.hex:%.elf
521526
@echo "\t[ELF2HEX] $@"
@@ -548,7 +553,7 @@ clean:
548553
$(Q)rm -f src/wc_secure_calls.o
549554
$(Q)rm -f $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/*.o $(WOLFBOOT_LIB_WOLFTPM)/src/*.o $(WOLFBOOT_LIB_WOLFTPM)/hal/*.o $(WOLFBOOT_LIB_WOLFTPM)/examples/pcr/*.o
550555
$(Q)rm -f $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/port/Renesas/*.o
551-
$(Q)rm -f wolfboot.bin wolfboot.elf wolfboot.map test-update.rom wolfboot.hex
556+
$(Q)rm -f wolfboot.bin wolfboot.elf wolfboot.map test-update.rom wolfboot.hex wolfboot.srec factory.srec
552557
$(Q)rm -f $(MACHINE_OBJ) $(MAIN_TARGET) $(LSCRIPT)
553558
$(Q)rm -f $(OBJS)
554559
$(Q)rm -f tools/keytools/otp/otp-keystore-gen

config/examples/nxp-s32k142.config

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# wolfBoot configuration for NXP S32K142
2+
#
3+
# S32K142: Cortex-M4F, 256KB Flash, 32KB SRAM
4+
# Flash sector size: 2KB
5+
# Default: RUN mode at 48 MHz (FIRC - internal RC oscillator)
6+
#
7+
# Build: cp config/examples/nxp-s32k142.config .config && make
8+
9+
ARCH?=ARM
10+
CORTEX_M4?=1
11+
NO_MPU=1
12+
TARGET?=s32k1xx
13+
SIGN?=ECC256
14+
HASH?=SHA256
15+
VTOR?=1
16+
NO_ASM?=0
17+
EXT_FLASH?=0
18+
SPI_FLASH?=0
19+
ALLOW_DOWNGRADE?=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+
25+
WOLFBOOT_VERSION?=0
26+
V?=0
27+
SPMATH?=1
28+
RAM_CODE?=1
29+
DUALBANK_SWAP?=0
30+
31+
# 2KB sectors (S32K142 only - larger variants use 4KB sectors)
32+
WOLFBOOT_SECTOR_SIZE?=0x800
33+
34+
# Memory layout for S32K142 (256KB Flash):
35+
# Bootloader: 0x00000000 - 0x0000BFFF (48 KB)
36+
# Boot Partition: 0x0000C000 - 0x00024FFF (100 KB)
37+
# Update Partition: 0x00025000 - 0x0003DFFF (100 KB)
38+
# Swap Sector: 0x0003E000 - 0x0003E7FF (2 KB)
39+
WOLFBOOT_PARTITION_SIZE?=0x19000
40+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xC000
41+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x25000
42+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x3E000
43+
44+
# Clock mode: Default is RUN mode with FIRC (48 MHz internal RC)
45+
# To enable HSRUN mode (112 MHz), uncomment below (requires SOSC + SPLL, not fully implemented):
46+
#CFLAGS_EXTRA+=-DS32K1XX_CLOCK_HSRUN
47+
48+
# Optionally enable watchdog
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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# wolfBoot configuration for NXP S32K144
2+
#
3+
# S32K144: Cortex-M4F, 512KB Flash, 64KB SRAM
4+
# Flash sector size: 4KB (larger flash variants use 4KB sectors)
5+
# Default: RUN mode at 48 MHz (FIRC - internal RC oscillator)
6+
#
7+
# Build: cp config/examples/nxp-s32k144.config .config && make
8+
9+
ARCH?=ARM
10+
CORTEX_M4?=1
11+
NO_MPU=1
12+
TARGET?=s32k1xx
13+
SIGN?=ECC256
14+
HASH?=SHA256
15+
VTOR?=1
16+
NO_ASM?=0
17+
EXT_FLASH?=0
18+
SPI_FLASH?=0
19+
ALLOW_DOWNGRADE?=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+
25+
WOLFBOOT_VERSION?=0
26+
V?=0
27+
SPMATH?=1
28+
RAM_CODE?=1
29+
DUALBANK_SWAP?=0
30+
31+
# Select S32K144 variant for correct flash size and sector size
32+
CFLAGS_EXTRA+=-DS32K144
33+
34+
# 4KB sectors (S32K144/146/148 with 512KB+ flash)
35+
WOLFBOOT_SECTOR_SIZE?=0x1000
36+
37+
# Memory layout for S32K144 (512KB Flash):
38+
# Bootloader: 0x00000000 - 0x0000BFFF (48 KB)
39+
# Boot Partition: 0x0000C000 - 0x00043FFF (224 KB)
40+
# Update Partition: 0x00044000 - 0x0007BFFF (224 KB)
41+
# Swap Sector: 0x0007C000 - 0x0007CFFF (4 KB)
42+
WOLFBOOT_PARTITION_SIZE?=0x38000
43+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xC000
44+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x44000
45+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x7C000
46+
47+
# Clock mode: Default is RUN mode with FIRC (48 MHz internal RC)
48+
# To enable HSRUN mode (112 MHz), uncomment below (requires SOSC + SPLL, not fully implemented):
49+
#CFLAGS_EXTRA+=-DS32K1XX_CLOCK_HSRUN
50+
51+
# Optionally enable watchdog
52+
#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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# wolfBoot configuration for NXP S32K146
2+
#
3+
# S32K146: Cortex-M4F, 1MB Flash, 128KB SRAM
4+
# Flash sector size: 4KB (larger flash variants use 4KB sectors)
5+
# Default: RUN mode at 48 MHz (FIRC - internal RC oscillator)
6+
#
7+
# Build: cp config/examples/nxp-s32k146.config .config && make
8+
9+
ARCH?=ARM
10+
CORTEX_M4?=1
11+
NO_MPU=1
12+
TARGET?=s32k1xx
13+
SIGN?=ECC256
14+
HASH?=SHA256
15+
VTOR?=1
16+
NO_ASM?=0
17+
EXT_FLASH?=0
18+
SPI_FLASH?=0
19+
ALLOW_DOWNGRADE?=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+
25+
WOLFBOOT_VERSION?=0
26+
V?=0
27+
SPMATH?=1
28+
RAM_CODE?=1
29+
DUALBANK_SWAP?=0
30+
31+
# Select S32K146 variant for correct flash size and sector size
32+
CFLAGS_EXTRA+=-DS32K146
33+
34+
# 4KB sectors (S32K144/146/148 with 512KB+ flash)
35+
WOLFBOOT_SECTOR_SIZE?=0x1000
36+
37+
# Memory layout for S32K146 (1MB Flash):
38+
# Bootloader: 0x00000000 - 0x0000BFFF (48 KB)
39+
# Boot Partition: 0x0000C000 - 0x0007FFFF (464 KB)
40+
# Update Partition: 0x00080000 - 0x000F3FFF (464 KB)
41+
# Swap Sector: 0x000F4000 - 0x000F4FFF (4 KB)
42+
WOLFBOOT_PARTITION_SIZE?=0x74000
43+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xC000
44+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x80000
45+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0xF4000
46+
47+
# Clock mode: Default is RUN mode with FIRC (48 MHz internal RC)
48+
# To enable HSRUN mode (112 MHz), uncomment below (requires SOSC + SPLL, not fully implemented):
49+
#CFLAGS_EXTRA+=-DS32K1XX_CLOCK_HSRUN
50+
51+
# Optionally enable watchdog
52+
#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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# wolfBoot configuration for NXP S32K148
2+
#
3+
# S32K148: Cortex-M4F, 2MB Flash, 256KB SRAM
4+
# Flash sector size: 4KB (larger flash variants use 4KB sectors)
5+
# Default: RUN mode at 48 MHz (FIRC - internal RC oscillator)
6+
#
7+
# Build: cp config/examples/nxp-s32k148.config .config && make
8+
9+
ARCH?=ARM
10+
CORTEX_M4?=1
11+
NO_MPU=1
12+
TARGET?=s32k1xx
13+
SIGN?=ECC256
14+
HASH?=SHA256
15+
VTOR?=1
16+
NO_ASM?=0
17+
EXT_FLASH?=0
18+
SPI_FLASH?=0
19+
ALLOW_DOWNGRADE?=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+
25+
WOLFBOOT_VERSION?=0
26+
V?=0
27+
SPMATH?=1
28+
RAM_CODE?=1
29+
DUALBANK_SWAP?=0
30+
31+
# Select S32K148 variant for correct flash size and sector size
32+
CFLAGS_EXTRA+=-DS32K148
33+
34+
# 4KB sectors (S32K144/146/148 with 512KB+ flash)
35+
WOLFBOOT_SECTOR_SIZE?=0x1000
36+
37+
# Memory layout for S32K148 (2MB Flash):
38+
# Bootloader: 0x00000000 - 0x0000BFFF (48 KB)
39+
# Boot Partition: 0x0000C000 - 0x000FBFFF (960 KB)
40+
# Update Partition: 0x000FC000 - 0x001EBFFF (960 KB)
41+
# Swap Sector: 0x001EC000 - 0x001ECFFF (4 KB)
42+
WOLFBOOT_PARTITION_SIZE?=0xF0000
43+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xC000
44+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0xFC000
45+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x1EC000
46+
47+
# Clock mode: Default is RUN mode with FIRC (48 MHz internal RC)
48+
# To enable HSRUN mode (112 MHz), uncomment below (requires SOSC + SPLL, not fully implemented):
49+
#CFLAGS_EXTRA+=-DS32K1XX_CLOCK_HSRUN
50+
51+
# Optionally enable watchdog
52+
#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

0 commit comments

Comments
 (0)