Skip to content

Commit 9397988

Browse files
dgarskedanielinux
authored andcommitted
Support for custom flash option byte on NXP S32K14xx
1 parent 38e2a1f commit 9397988

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
lines changed

config/examples/nxp-s32k142.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x3E000
4848
# Optionally enable watchdog
4949
#CFLAGS_EXTRA+=-DWATCHDOG
5050

51+
# Flash Option Byte (FOPT) override (default 0xFF)
52+
# Example: disable RESET_PIN_CFG (use PTA5 as GPIO instead of RESET)
53+
#CFLAGS_EXTRA+=-DWOLFBOOT_FOPT=0xF7
54+
5155
# Debugging options (uncomment as needed)
5256
DEBUG?=0
5357
DEBUG_SYMBOLS?=0

config/examples/nxp-s32k144.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x7C000
5151
# Optionally enable watchdog
5252
#CFLAGS_EXTRA+=-DWATCHDOG
5353

54+
# Flash Option Byte (FOPT) override (default 0xFF)
55+
# Example: disable RESET_PIN_CFG (use PTA5 as GPIO instead of RESET)
56+
#CFLAGS_EXTRA+=-DWOLFBOOT_FOPT=0xF7
57+
5458
# Debugging options (uncomment as needed)
5559
DEBUG?=0
5660
DEBUG_SYMBOLS?=0

config/examples/nxp-s32k146.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0xF4000
5151
# Optionally enable watchdog
5252
#CFLAGS_EXTRA+=-DWATCHDOG
5353

54+
# Flash Option Byte (FOPT) override (default 0xFF)
55+
# Example: disable RESET_PIN_CFG (use PTA5 as GPIO instead of RESET)
56+
#CFLAGS_EXTRA+=-DWOLFBOOT_FOPT=0xF7
57+
5458
# Debugging options (uncomment as needed)
5559
DEBUG?=0
5660
DEBUG_SYMBOLS?=0

config/examples/nxp-s32k148.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x1EC000
5151
# Optionally enable watchdog
5252
#CFLAGS_EXTRA+=-DWATCHDOG
5353

54+
# Flash Option Byte (FOPT) override (default 0xFF)
55+
# Example: disable RESET_PIN_CFG (use PTA5 as GPIO instead of RESET)
56+
#CFLAGS_EXTRA+=-DWOLFBOOT_FOPT=0xF7
57+
5458
# Debugging options (uncomment as needed)
5559
DEBUG?=0
5660
DEBUG_SYMBOLS?=0

docs/Targets.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3650,6 +3650,21 @@ The following build options are available for the S32K1xx HAL:
36503650
| `DEBUG_UART` | Enable LPUART1 debug output. |
36513651
| `DEBUG_HARDFAULT` | Enable detailed hard fault debugging output. |
36523652
| `S32K144`, `S32K146`, `S32K148` | Select variant (default is S32K142). Affects flash/SRAM size definitions. |
3653+
| `WOLFBOOT_FOPT` | Override the Flash Option Byte (FOPT) in the Flash Configuration Field (FCF at 0x40D). Default is `0xFF`. Set via `CFLAGS_EXTRA+=-DWOLFBOOT_FOPT=0xF7` in your `.config` file. See FOPT bit field table below. |
3654+
3655+
**FOPT Bit Fields** (from S32K1xx Reference Manual Table 25-2):
3656+
3657+
| Bit(s) | Field | Default | Description |
3658+
|--------|-------|---------|-------------|
3659+
| 7-6 | Reserved | 1 | Reserved for future expansion. |
3660+
| 5 | Reserved | 1 | Reserved. |
3661+
| 4 | Reserved | 1 | Reserved for future expansion. |
3662+
| 3 | RESET_PIN_CFG | 1 | `1`: RESET pin enabled (pullup, passive filter). `0`: RESET pin disabled after POR (use PTA5 as GPIO). |
3663+
| 2 | NMI_PIN_CFG | 1 | `1`: NMI pin/interrupts enabled. `0`: NMI interrupts always blocked (pin defaults to NMI_b with pullup). |
3664+
| 1 | Reserved | 1 | Reserved for future expansion. |
3665+
| 0 | LPBOOT | 1 | `1`: Core/system clock divider (OUTDIV1) = divide by 1. `0`: OUTDIV1 = divide by 2. Not available on S32K14xW. |
3666+
3667+
Example: To disable the RESET pin (use PTA5 as GPIO), set bit 3 to 0: `WOLFBOOT_FOPT=0xF7`.
36533668

36543669
**IMPORTANT:** Flash sector size depends on the S32K variant:
36553670
- **S32K142** (256KB Flash): 2KB sectors (`WOLFBOOT_SECTOR_SIZE=0x800`)

hal/s32k1xx.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
/* Located at 0x400-0x40F in flash */
6363

6464
#ifdef __WOLFBOOT
65+
66+
/* Flash Option Byte - override with CFLAGS_EXTRA+=-DWOLFBOOT_FOPT=0xF7 */
67+
#ifndef WOLFBOOT_FOPT
68+
#define WOLFBOOT_FOPT 0xFF
69+
#endif
70+
6571
#define FCF_LEN (16)
6672
const uint8_t __attribute__((section(".flash_config"))) flash_config[FCF_LEN] = {
6773
/* Backdoor comparison key (8 bytes) */
@@ -71,7 +77,7 @@ const uint8_t __attribute__((section(".flash_config"))) flash_config[FCF_LEN] =
7177
/* Flash Security Byte */
7278
0xFE, /* SEC=10 (unsecured), FSLACC=11, MEEN=11, KEYEN=11 */
7379
/* Flash Option Byte */
74-
0xFF,
80+
WOLFBOOT_FOPT,
7581
/* EEPROM Protection Byte */
7682
0xFF,
7783
/* Data Flash Protection Byte */

0 commit comments

Comments
 (0)