Skip to content

Commit 74ecb3b

Browse files
committed
Further port improvements (not tested)
1 parent d72fd46 commit 74ecb3b

File tree

5 files changed

+386
-12
lines changed

5 files changed

+386
-12
lines changed

.vscode/launch.json

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
],
2323
"postLaunchCommands": [
2424
"monitor reset halt",
25-
"load",
26-
"monitor programbin test-app/image_v1_signed.bin 0xc000"
25+
"load factory.elf",
26+
"add-symbol-file test-app/image.elf",
27+
"monitor reset halt"
2728
]
2829
},
2930
{
@@ -47,8 +48,59 @@
4748
],
4849
"postLaunchCommands": [
4950
"monitor reset halt",
50-
"load",
51-
"monitor programbin test-app/image_v1_signed.bin 0xc000"
51+
"load factory.elf",
52+
"add-symbol-file test-app/image.elf",
53+
"monitor reset halt"
54+
]
55+
},
56+
{
57+
"name": "Recovery: Flash and Debug wolfBoot",
58+
"type": "cortex-debug",
59+
"request": "launch",
60+
"cwd": "${workspaceFolder}",
61+
"executable": "${workspaceFolder}/wolfboot.elf",
62+
"servertype": "external",
63+
"gdbTarget": "127.0.0.1:7224",
64+
"device": "S32K142",
65+
"runToEntryPoint": "main",
66+
"showDevDebugOutput": "raw",
67+
"svdFile": "",
68+
"gdbPath": "${workspaceFolder}/.vscode/arm-gdb-wrapper.sh",
69+
"toolchainPath": "/opt/arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi/bin",
70+
"toolchainPrefix": "arm-none-eabi",
71+
"preLaunchTask": "Start GDB Server Recovery",
72+
"preLaunchCommands": [
73+
"set mem inaccessible-by-default off"
74+
],
75+
"postLaunchCommands": [
76+
"load factory.elf",
77+
"add-symbol-file test-app/image.elf",
78+
"monitor reset halt"
79+
]
80+
},
81+
{
82+
"name": "Recovery: Flash and Debug wolfBoot (with UART)",
83+
"type": "cortex-debug",
84+
"request": "launch",
85+
"cwd": "${workspaceFolder}",
86+
"executable": "${workspaceFolder}/wolfboot.elf",
87+
"servertype": "external",
88+
"gdbTarget": "127.0.0.1:7224",
89+
"device": "S32K142",
90+
"runToEntryPoint": "main",
91+
"showDevDebugOutput": "raw",
92+
"svdFile": "",
93+
"gdbPath": "${workspaceFolder}/.vscode/arm-gdb-wrapper.sh",
94+
"toolchainPath": "/opt/arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi/bin",
95+
"toolchainPrefix": "arm-none-eabi",
96+
"preLaunchTask": "Start GDB Server Recovery and UART",
97+
"preLaunchCommands": [
98+
"set mem inaccessible-by-default off"
99+
],
100+
"postLaunchCommands": [
101+
"load factory.elf",
102+
"add-symbol-file test-app/image.elf",
103+
"monitor reset halt"
52104
]
53105
},
54106
{
@@ -71,7 +123,7 @@
71123
],
72124
"postLaunchCommands": [
73125
"monitor reset halt",
74-
"load",
126+
"load factory.elf",
75127
"monitor reset run",
76128
"quit"
77129
]

.vscode/tasks.json

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "2.0.0",
33
"tasks": [
44
{
5-
"label": "Start PEMicro GDB Server",
5+
"label": "Start PEMicro GDB Server Only",
66
"type": "shell",
77
"command": "${env:HOME}/.local/pemicro/pegdbserver_console",
88
"args": [
@@ -40,6 +40,76 @@
4040
"clear": true
4141
}
4242
},
43+
{
44+
"label": "Mass Erase Only",
45+
"type": "shell",
46+
"command": "${env:HOME}/.local/pemicro/pegdbserver_console",
47+
"args": [
48+
"-startserver",
49+
"-device=NXP_S32K1xx_S32K142F256M15",
50+
"-interface=OPENSDA",
51+
"-port=USB1",
52+
"-speed=1000",
53+
"-forcemasserase",
54+
"-attachonly",
55+
"-singlesession"
56+
],
57+
"options": {
58+
"env": {
59+
"LD_LIBRARY_PATH": "${env:HOME}/.local/pemicro/gdi:${env:HOME}/.local/pemicro/gdi/P&E:${env:LD_LIBRARY_PATH}"
60+
},
61+
"cwd": "${env:HOME}/.local/pemicro"
62+
},
63+
"problemMatcher": [],
64+
"presentation": {
65+
"echo": true,
66+
"reveal": "always",
67+
"focus": true,
68+
"panel": "dedicated",
69+
"showReuseMessage": false,
70+
"clear": true
71+
}
72+
},
73+
{
74+
"label": "Start PEMicro GDB Server (Recovery Mode)",
75+
"type": "shell",
76+
"command": "${env:HOME}/.local/pemicro/pegdbserver_console",
77+
"args": [
78+
"-startserver",
79+
"-device=NXP_S32K1xx_S32K142F256M15",
80+
"-interface=OPENSDA",
81+
"-port=USB1",
82+
"-serverport=7224",
83+
"-speed=1000",
84+
"-attachonly"
85+
],
86+
"options": {
87+
"env": {
88+
"LD_LIBRARY_PATH": "${env:HOME}/.local/pemicro/gdi:${env:HOME}/.local/pemicro/gdi/P&E:${env:LD_LIBRARY_PATH}"
89+
},
90+
"cwd": "${env:HOME}/.local/pemicro"
91+
},
92+
"isBackground": true,
93+
"problemMatcher": {
94+
"pattern": {
95+
"regexp": "^ERROR:(.*)$",
96+
"message": 1
97+
},
98+
"background": {
99+
"activeOnStart": true,
100+
"beginsPattern": "^P&E GDB Server",
101+
"endsPattern": "^All Servers Running"
102+
}
103+
},
104+
"presentation": {
105+
"echo": true,
106+
"reveal": "always",
107+
"focus": false,
108+
"panel": "dedicated",
109+
"showReuseMessage": false,
110+
"clear": true
111+
}
112+
},
43113
{
44114
"label": "Start UART Monitor",
45115
"type": "shell",
@@ -65,13 +135,58 @@
65135
"clear": true
66136
}
67137
},
138+
{
139+
"label": "Create Factory ELF",
140+
"type": "shell",
141+
"command": "/opt/arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-objcopy",
142+
"args": [
143+
"-I", "binary",
144+
"-O", "elf32-littlearm",
145+
"-B", "arm",
146+
"factory.bin",
147+
"factory.elf"
148+
],
149+
"options": {
150+
"cwd": "${workspaceFolder}"
151+
},
152+
"problemMatcher": []
153+
},
154+
{
155+
"label": "Start PEMicro GDB Server",
156+
"dependsOn": [
157+
"Create Factory ELF",
158+
"Start PEMicro GDB Server Only"
159+
],
160+
"dependsOrder": "sequence",
161+
"problemMatcher": []
162+
},
68163
{
69164
"label": "Start GDB Server and UART",
70165
"dependsOn": [
71-
"Start PEMicro GDB Server",
166+
"Create Factory ELF",
167+
"Start PEMicro GDB Server Only",
72168
"Start UART Monitor"
73169
],
74-
"dependsOrder": "parallel",
170+
"dependsOrder": "sequence",
171+
"problemMatcher": []
172+
},
173+
{
174+
"label": "Start GDB Server Recovery",
175+
"dependsOn": [
176+
"Create Factory ELF",
177+
"Start PEMicro GDB Server (Recovery Mode)"
178+
],
179+
"dependsOrder": "sequence",
180+
"problemMatcher": []
181+
},
182+
{
183+
"label": "Start GDB Server Recovery and UART",
184+
"dependsOn": [
185+
"Create Factory ELF",
186+
"Start PEMicro GDB Server (Recovery Mode)",
187+
"Start UART Monitor"
188+
],
189+
"dependsOrder": "sequence",
75190
"problemMatcher": []
76191
},
77192
{
@@ -121,4 +236,3 @@
121236
}
122237
]
123238
}
124-

docs/Targets.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2997,15 +2997,81 @@ The bootloader includes the Flash Configuration Field (FCF) at address 0x400-0x4
29972997
- Flash protection: All regions unprotected
29982998
- Backdoor key access: Enabled
29992999

3000+
**CRITICAL WARNING:** The FCF region at 0x400-0x40F controls device security settings. Writing incorrect values can **permanently lock the device**, making it irrecoverable. The wolfBoot HAL includes protection to prevent accidental writes to this region.
3001+
3002+
### NXP S32K1XX: Recovering a Locked/Unresponsive Device
3003+
3004+
If your S32K device becomes locked or unresponsive (e.g., stuck in reset with D1 LED illuminated on S32K-EVB boards), try these recovery procedures:
3005+
3006+
**Symptoms of a locked device:**
3007+
- Debugger cannot connect ("Soft reset failed", "Failed to enter debug mode")
3008+
- Device stuck in reset (D1 LED constantly on for S32K-EVB)
3009+
- J-Link reports "Readout protection is set" at address 0x400-0x40F
3010+
3011+
**Recovery Option 1: PEMicro Force Mass Erase**
3012+
3013+
```sh
3014+
pegdbserver_console -device=NXP_S32K1xx_S32K142 -interface=OPENSDA -port=USB1 -forcemasserase -singlesession
3015+
```
3016+
3017+
After mass erase completes, power cycle the board before attempting to reconnect.
3018+
3019+
**Recovery Option 2: J-Link Unlock**
3020+
3021+
```sh
3022+
JLinkExe -if swd -Device S32K142
3023+
unlock Kinetis
3024+
erase
3025+
r
3026+
q
3027+
```
3028+
3029+
Then power cycle the board.
3030+
3031+
**Recovery Option 3: NXP S32 Design Studio**
3032+
3033+
1. Install NXP S32 Design Studio (free from NXP)
3034+
2. Create a debug configuration for S32K142
3035+
3. Use the "Device Security" or "Flash Programmer" utility
3036+
4. Perform a mass erase to recover the device
3037+
3038+
**Recovery Option 4: Hardware Recovery (Last Resort)**
3039+
3040+
If software recovery fails, some devices support hardware-based recovery:
3041+
1. Hold the device in reset while connecting debugger
3042+
2. Use SWD low-level commands to issue mass erase
3043+
3. Some debuggers have "recovery mode" options that hold reset during connection
3044+
3045+
**Prevention:**
3046+
3047+
The wolfBoot HAL includes FCF write protection that prevents `hal_flash_write()` from modifying the 0x400-0x40F region. This protection is always enabled to prevent accidental device locking.
3048+
3049+
### NXP S32K1XX: Configuration Options
3050+
3051+
The following build options are available for the S32K1xx HAL:
3052+
3053+
| Option | Description |
3054+
|--------|-------------|
3055+
| `WOLFBOOT_RESTORE_CLOCK` | Restore clock to SIRC (8 MHz) before booting application. Recommended for applications that configure their own clocks. |
3056+
| `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. |
3057+
| `WATCHDOG` | Enable watchdog during wolfBoot operation. Recommended for production. |
3058+
| `WATCHDOG_TIMEOUT_MS` | Watchdog timeout in milliseconds when `WATCHDOG` is enabled (default: 1000ms). |
3059+
| `S32K1XX_CLOCK_HSRUN` | Enable HSRUN mode (112 MHz). Requires external crystal and SPLL (not fully implemented). |
3060+
| `DEBUG_UART` | Enable LPUART1 debug output. |
3061+
| `S32K144`, `S32K146`, `S32K148` | Select variant (default is S32K142). Affects flash/SRAM size definitions. |
3062+
30003063
### NXP S32K1XX: TODO / Future Enhancements
30013064

30023065
The following features are planned or available for contribution:
30033066

30043067
- [ ] **SPLL + SOSC support**: Add external crystal oscillator and SPLL configuration for true 112 MHz operation in HSRUN mode
30053068
- [ ] **Hardware crypto acceleration**: Integrate CSEc (Cryptographic Services Engine) for hardware-accelerated crypto operations
30063069
- [ ] **FlexNVM/EEPROM support**: Add support for FlexNVM partitioning and EEPROM emulation
3007-
- [ ] **S32K144/146/148 support**: Test and validate on larger S32K1xx variants with more flash/RAM
3070+
- [x] **S32K144/146/148 support**: Header defines for variant-specific flash/SRAM sizes (hardware testing pending)
30083071
- [ ] **CAN/LIN bootloader**: Add firmware update over CAN or LIN bus for automotive applications
3072+
- [x] **FCF Protection**: Prevent accidental writes to Flash Configuration Field to avoid device locking
3073+
- [x] **WOLFBOOT_RESTORE_CLOCK**: Support for restoring clock to safe state before booting application
3074+
- [x] **Watchdog re-enable on boot**: Re-enable watchdog before jumping to application (matches reset default)
30093075

30103076

30113077
## TI Hercules TMS570LC435

0 commit comments

Comments
 (0)