Skip to content

Conversation

@dgarske
Copy link
Contributor

@dgarske dgarske commented Dec 31, 2025

Add NXP S32K1xx Support

This PR adds full wolfBoot support for the NXP S32K1xx automotive microcontroller family (S32K142, S32K144, S32K146, S32K148).

Summary

Adds a complete bare-metal HAL implementation for the S32K1xx Cortex-M4F family with sector-swap firmware update capability. Tested on S32K142EVB with successful firmware updates.

Features

HAL Implementation (hal/s32k1xx.c, hal/s32k1xx.h):

  • Flash programming using FTFC controller (phrase-level 8-byte writes)
  • LPUART1 debug output at 115200 baud
  • Clock configuration using FIRC (48 MHz internal RC oscillator)
  • Watchdog management (disable during boot, optional enable for production)
  • Flash Configuration Field (FCF) for security settings

Test Application (test-app/app_s32k1xx.c):

  • Interactive console with commands: status, trigger, success, reboot, help
  • LED indicators: Green LED for v1, Blue LED for v2+
  • XMODEM firmware update support
  • Partition and keystore information display

Configuration Files:

  • config/examples/nxp-s32k142.config - 256KB Flash, 32KB SRAM, 2KB sectors
  • config/examples/nxp-s32k144.config - 512KB Flash, 64KB SRAM, 4KB sectors
  • config/examples/nxp-s32k146.config - 1MB Flash, 128KB SRAM, 4KB sectors
  • config/examples/nxp-s32k148.config - 2MB Flash, 256KB SRAM, 4KB sectors

Tooling:

  • tools/scripts/nxp-s32k142-flash.sh - Automated build, sign, and flash script using J-Link

Memory Layout (S32K142)

Region Address Range Size
Bootloader 0x00000000 - 0x0000BFFF 48 KB
Boot Partition 0x0000C000 - 0x00024FFF 100 KB
Update Partition 0x00025000 - 0x0003DFFF 100 KB
Swap Sector 0x0003E000 - 0x0003E7FF 2 KB

Important Configuration Requirements

  • NVM_FLASH_WRITEONCE=1 - Required because S32K1xx flash cannot be reprogrammed without erase
  • RAM_CODE=1 - Required because flash cannot be read while being programmed

Build & Test

# Build wolfBoot
cp config/examples/nxp-s32k142.config .config
make clean && make

# Build test app
make test-app/image.bin

# Sign images
./tools/keytools/sign --ecc256 --sha256 test-app/image.bin wolfboot_signing_private_key.der 1
./tools/keytools/sign --ecc256 --sha256 test-app/image.bin wolfboot_signing_private_key.der 2

Files Changed

  • New files: hal/s32k1xx.c, hal/s32k1xx.h, hal/s32k1xx.ld, test-app/app_s32k1xx.c, test-app/ARM-s32k1xx.ld
  • Config files: 4 new example configurations for S32K142/144/146/148
  • CI: Added build tests for all S32K1xx variants
  • Documentation: Added comprehensive S32K1xx section to docs/Targets.md

Testing

Verified on S32K142EVB:

  • wolfBoot boots successfully and validates firmware signature
  • Firmware update via sector swap completes successfully
  • Test application marks update as successful
  • Version rollback works correctly

@dgarske dgarske self-assigned this Dec 31, 2025
@dgarske dgarske closed this Jan 5, 2026
@dgarske dgarske reopened this Jan 5, 2026
- 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)
danielinux
danielinux previously approved these changes Jan 14, 2026
Copy link
Member

@danielinux danielinux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Port is complete (docs, tests). Builds fine. Just one thought/consideration on skipping FCF writes.

Comment on lines +516 to +524
/* CRITICAL: Protect the Flash Configuration Field (FCF) region.
* Writing incorrect values to 0x400-0x40F can permanently lock the device!
* The FCF is programmed once in the flash_config section and should never
* be modified at runtime.
*/
if ((address < FCF_END_ADDR) && ((address + len) > FCF_START_ADDR)) {
/* Requested write overlaps with FCF region - this is dangerous!
* Skip the FCF portion to prevent device locking.
*/
Copy link
Member

@danielinux danielinux Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I wonder if this would affect self-update in any way? It looks like it should not, as the writing is silently discarded and 0 is returned. The new (signed) wolfboot should contain a valid FCF, and self-update will try to overwrite this area, but as long as FCF remains constant across self-updates this should be OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will run some self-update tests and find out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants