Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
dfe3069
initial commit
twcook86 Nov 18, 2026
0a5ed18
add wolfip support
twcook86 Nov 18, 2026
4d279fe
wolfip perf improvements
twcook86 Nov 23, 2026
189821f
rename from e31b_emac to mcxe_emac for more general use
twcook86 Nov 23, 2026
6fbba9d
address copilot/fenrir issues
twcook86 Nov 25, 2026
9fff194
mcxe31b: opt in to the unaligned memcpy
twcook86 Dec 1, 2026
10abbe7
fix xmodem eot issue
twcook86 Dec 1, 2026
3fed3be
mcxe31b: stop the EMAC after the network test, use the stats macro
twcook86 Dec 4, 2026
4b20a3f
mcxe31b: check the test-app link, document header size and memcpy
twcook86 Dec 4, 2026
a382d02
mcxe31b: use the shared XMODEM receiver
twcook86 Dec 4, 2026
0c97c44
mcxe31b: fix review nits in startup, speed test and config
twcook86 Dec 4, 2026
d846f79
mcxe31b: range check flash writes and erases, bound clock waits
twcook86 Dec 5, 2026
aa7e641
mcxe31b: required build options in arch.mk, explicit build errors
twcook86 Dec 5, 2026
a72994f
test-app: clear the ITCM ECC with APP_ITCM_ECC_INIT
twcook86 Dec 5, 2026
2ff7fc1
mcxe31b: drain the XMODEM leftovers from the RX buffer, status names
twcook86 Dec 5, 2026
9474f8e
mcxe31b: unit test for the flash write and erase logic
twcook86 Dec 5, 2026
ba21829
test-app: select 64-bit SRAM ECC clears with APP_RAM_ECC_64BIT
twcook86 Dec 5, 2026
eaac394
s32k1xx: drain the XMODEM leftovers from the RX buffer
twcook86 Dec 5, 2026
5050424
mcxe31b: fix review findings in the flash, UART and build
twcook86 Dec 5, 2026
6a81d43
mcxe31b: confirm updates without a console, bound the heap
twcook86 Dec 5, 2026
f5d56d6
mcxe31b: unit test the flash lock mapping, rename abort
twcook86 Dec 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/test-configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,19 @@ jobs:
arch: arm
config-file: ./config/examples/mcxe247.config

nxp_mcxe31b_test:
uses: ./.github/workflows/test-build.yml
with:
arch: arm
config-file: ./config/examples/mcxe31b.config

nxp_mcxe31b_no_uart_test:
uses: ./.github/workflows/test-build.yml
with:
arch: arm
config-file: ./config/examples/mcxe31b.config
make-args: DEBUG_UART=0

max32666_test:
uses: ./.github/workflows/test-build.yml
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ tools/unit-tests/unit-elf-phentsize
tools/unit-tests/unit-fdt-memrsv-wrap
tools/unit-tests/unit-flash-erase-kinetis
tools/unit-tests/unit-flash-m2354
tools/unit-tests/unit-flash-mcxe31b
tools/unit-tests/unit-fwtpm-cmd-toctou
tools/unit-tests/unit-fwtpm-rsp-overrun
tools/unit-tests/unit-hifive1-flash-write
Expand Down
12 changes: 12 additions & 0 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,18 @@ ifeq ($(ARCH),ARM)
ifeq ($(TARGET),imx95_m7)
CORTEX_M7=1
endif
ifeq ($(TARGET),mcxe31b)
CORTEX_M7=1
ARCH_FLASH_OFFSET=0x00400000
# The CM7 DTCM is ECC protected and must be written before it is read
CFLAGS+=-DWOLFBOOT_RAM_ECC_INIT
# Each 64-bit ECC segment can be programmed once between erases: the
# HAL skips unchanged segments, and partition trailers need the
# write-once layout
ifneq ($(NVM_FLASH_WRITEONCE),1)
$(error TARGET=mcxe31b requires NVM_FLASH_WRITEONCE=1)
endif
endif
ifeq ($(TARGET),stm32l0)
CORTEX_M0=1
SPI_TARGET=stm32
Expand Down
82 changes: 82 additions & 0 deletions config/examples/mcxe31b.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# wolfBoot configuration for NXP MCX E31B (FRDM-MCXE31B)
#
# MCXE31B: Cortex-M7, 4 MB code flash (four 1 MB blocks) + 128 KB data flash,
# 8 KB sectors. wolfBoot switches the core from FIRC 48 MHz to the PLL
# (160 MHz) and enables the caches. It runs from flash, with data, bss and the
# RAM_CODE flash routines in the 64 KB CM7_0 DTCM.
#
# Build: cp config/examples/mcxe31b.config .config && make

ARCH?=ARM
TARGET?=mcxe31b
SIGN?=ECC256
HASH?=SHA256
VTOR?=1
NO_ASM?=0
NO_MPU=1
EXT_FLASH?=0
SPI_FLASH?=0
ALLOW_DOWNGRADE?=0

# Each 64-bit ECC segment of the flash can be programmed only once between
# erases
NVM_FLASH_WRITEONCE?=1

WOLFBOOT_VERSION?=0
V?=0
SPMATH?=1
RAM_CODE?=1
DUALBANK_SWAP?=0

# 8KB sectors
WOLFBOOT_SECTOR_SIZE?=0x2000

# Word-at-a-time memcpy/memset in src/string.c (bootloader and test-app). The
# Cortex-M7 loads unaligned words from RAM and flash, so with
# FAST_MEMCPY_UNALIGNED memcpy copies words even when source and destination
# alignments differ. Nothing on this target copies from peripheral registers
# with memcpy.
CFLAGS_EXTRA+=-DFAST_MEMCPY -DFAST_MEMCPY_UNALIGNED

# The application's vector table follows the image header and is used in
# place (VTOR). The table must be 1 KB aligned, or the core fetches the vectors
# of some IRQs (e.g. EMAC, 105) from the wrong slots.
IMAGE_HEADER_SIZE?=1024

# Memory layout (code flash 0x00400000 - 0x007FFFFF):
# IVT + Bootloader: 0x00400000 - 0x0040FFFF (64 KB)
# Boot Partition: 0x00410000 - 0x005EFFFF (1920 KB)
# Update Partition: 0x005F0000 - 0x007CFFFF (1920 KB)
# Swap Sector: 0x007D0000 - 0x007D1FFF (8 KB)
# 0x007D4000 - 0x007FFFFF is left free: it holds the Secure BAF and, when the
# security firmware feature flag is set, the security firmware.
WOLFBOOT_PARTITION_SIZE?=0x1E0000
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x410000
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x5F0000
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x7D0000

# Console on the MCU-Link VCOM port: LPUART5, PTE14 (TX) and PTE3 (RX),
# 115200 8N1

# wolfIP network test in the test-app (optional)
# Adds the "network" console command. Needs a wolfIP checkout, which provides
# the nxp_mcxe_emac driver (EMAC, RMII to the LAN8741 PHY). The driver is
# interrupt driven; NXP_MCXE_EMAC_IRQ=0 makes it poll the EMAC instead.
ENABLE_WOLFIP?=0
WOLFBOOT_LIB_WOLFIP?=../lib/wolfip
NXP_MCXE_EMAC_IRQ?=1
# By default the command acquires a DHCP lease and runs a TCP and UDP
# throughput server on port 9, driven from the host by
# tools/scripts/wolfip_speed.py.
WOLFIP_SPEED_TEST?=1
# WOLFBOOT_TEST_TFTP=1 makes the command fetch a file over TFTP instead (it
# overrides WOLFIP_SPEED_TEST). The file must fit the 40 KB receive buffer
# (TFTP_RAM_MAX in test-app/Makefile).
# With both set to 0 the command only acquires a DHCP lease.
WOLFBOOT_TEST_TFTP?=0
CFLAGS_EXTRA+=-DHOST_IP_STR='"192.168.50.1"' -DTFTP_FILENAME='"wolfip_test.bin"'

# Debugging options
DEBUG?=0
DEBUG_SYMBOLS?=0
DEBUG_UART?=1
188 changes: 188 additions & 0 deletions docs/Targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ This README describes configuration of supported targets.
* [NXP RW612](#nxp-rw612)
* [NXP S32K1XX](#nxp-s32k1xx)
* [NXP MCXE247](#nxp-mcxe247)
* [NXP MCXE31B](#nxp-mcxe31b)
* [NXP P1021 PPC](#nxp-qoriq-p1021-ppc)
* [NXP T10xx PPC (T1024 / T1040)](#nxp-qoriq-t10xx-ppc-t1024--t1040)
* [NXP T2080 PPC](#nxp-qoriq-t2080-ppc)
Expand Down Expand Up @@ -8067,6 +8068,193 @@ Detach with `SYStem.Down` before testing an update, which relies on a software
reset.


## NXP MCXE31B

The NXP MCX E31B is a Cortex-M7 microcontroller with 4 MB of code flash (four
1 MB blocks), 128 KB of data flash and 512 KB of SRAM. It has its own
bare-metal `mcxe31b` HAL. No SDK is needed. The port targets the FRDM-MCXE31B
board.

- The boot ROM (Secure BAF) starts wolfBoot through the Image Vector Table
(IVT) that the HAL places at `0x00400000`.
- Flash (C40ASF): 8 KB sectors. Each 64-bit ECC segment can be programmed once
between erases, and a program operation writes up to 128 bytes.
- wolfBoot and the test application use the 64 KB CM7_0 DTCM for data, stack
and the `RAM_CODE` flash routines. The DTCM is ECC protected; the reset
handler clears it before use (`WOLFBOOT_RAM_ECC_INIT`, set by `arch.mk`).
- `hal_init()` switches from the boot ROM's FIRC 48 MHz to the PLL (16 MHz
crystal, reference manual clock "Option A"): core 160 MHz, AIPS_PLAT 80 MHz,
AIPS_SLOW 40 MHz. It first enables the last mile regulator, which the
FRDM-MCXE31B feeds through the Q1 ballast on VRC_CTRL. If a step fails,
wolfBoot stays on FIRC and prints a warning.
- The I-cache and D-cache are on while wolfBoot runs; flash program and erase
invalidate the D-cache over the modified range. Both caches are cleaned and
turned off before the jump to the application. The clocks stay at 160 MHz:
`WOLFBOOT_RESTORE_CLOCK` has no effect on this target.
- `mcxe31b.config` sets `IMAGE_HEADER_SIZE=1024`, so the application starts
1 KB into the boot partition. The application's vector table is used in
place, and with up to 163 entries it must be 1 KB aligned: with the default
256-byte header the core fetches the vectors of some interrupts (the EMAC,
IRQ 105, among them) from the wrong slots. The test application's linker
scripts stop the build when the vector table is not 1 KB aligned.
A bootloader finds the application at its own header size, so wolfBoot
built with one header size cannot boot an image signed with another. To
change the size, rebuild with the new `IMAGE_HEADER_SIZE`, program
`factory.bin` with `e31b_flash_factory_bin.cmm` (which also erases the
update partition and swap sector), and sign every update image again with
the new size (see [Testing an update](#nxp-mcxe31b-testing-an-update)).
- `mcxe31b.config` sets `FAST_MEMCPY` and `FAST_MEMCPY_UNALIGNED`, the
word-at-a-time `memcpy` and `memset` of `src/string.c`, for wolfBoot and the
test application. The Cortex-M7 loads unaligned words from RAM and flash, so
`memcpy` copies words even when the source and destination alignments
differ. Without `FAST_MEMCPY_UNALIGNED` it copies those bytes one at a time.

### NXP MCXE31B: Memory Layout

| Region | Address Range | Size |
|--------|---------------|------|
| IVT + Bootloader | 0x00400000 - 0x0040FFFF | 64 KB |
| Boot Partition | 0x00410000 - 0x005EFFFF | 1920 KB |
| Update Partition | 0x005F0000 - 0x007CFFFF | 1920 KB |
| Swap Sector | 0x007D0000 - 0x007D1FFF | 8 KB |

`0x007D4000 - 0x007FFFFF` is not used: the Secure BAF occupies the last 48 KB,
and the security firmware uses the 128 KB below it when its feature flag is
set. The boot ROM uses the lowest valid IVT, so the IVT of wolfBoot at
`0x00400000` always wins.

### NXP MCXE31B: Building

```sh
cp config/examples/mcxe31b.config .config
make
```

`factory.bin` (wolfBoot plus the signed version 1 test application) must be
programmed at `0x00400000`.

The console is on the MCU-Link VCOM port (LPUART5, PTE14 TX, PTE3 RX, 115200
8N1). The test application shows green on the RGB LED for version 1 and blue
for later versions, and has the same console as the
[S32K1xx test application](#nxp-s32k1xx-test-application), including
`network` (see [Network test](#nxp-mcxe31b-network-test)).

### NXP MCXE31B: Configuration Options

| Option | Description |
|--------|-------------|
| `NVM_FLASH_WRITEONCE` | **Required.** A 64-bit ECC segment can be programmed once between erases, so trailer updates erase and rewrite the sector. |
| `RAM_CODE` | **Required.** The flash program and erase routines run from DTCM, so the block being written is not read. The linker script checks this. |
| `DEBUG_UART` | Console output on LPUART5 (MCU-Link VCOM). |

### NXP MCXE31B: Network test

The test application can run a wolfIP throughput test or a DHCP and TFTP test
over the board's Ethernet port (RMII to a LAN8741A PHY, 50 MHz reference clock
from the board oscillator). This is optional and needs a wolfIP checkout, whose
`nxp_mcxe_emac` port is a standalone driver for the EMAC (Synopsys Ethernet
QoS), its clocks and pins, and the PHY (no vendor SDK). The test app builds it
interrupt driven (`NXP_MCXE_EMAC_IRQ=1`, EMAC IRQ 105 routed in
`test-app/startup_arm.c`); `NXP_MCXE_EMAC_IRQ=0` makes it poll the EMAC
instead. `test-app/ARM-mcxe31b-wolfip.ld` keeps the driver's descriptor rings
and frame buffers in the DTCM, which the core does not cache and the EMAC DMA
reaches through its backdoor port, and places the wolfIP stack state, with
9 KB TCP receive and transmit buffers per socket, the TFTP receive buffer and
libwolfboot's 8 KB flash sector buffer (`NVM_CACHE`) in SRAM. SRAM is ECC
protected: the reset handler clears all 320 KB of it with 64-bit stores
(`APP_RAM_ECC_INIT`, `APP_RAM_ECC_64BIT`) before it is used. The hottest network code
(`memcpy`, `memset` and `memcmp`, wolfIP's checksum, poll loop, FIFO and TCP
send path, and the driver's poll, send and interrupt handler) runs from the
ITCM: the reset handler clears the ITCM, which is also ECC protected
(`APP_ITCM_ECC_INIT`), and copies the code there (`APP_RAMCODE_ITCM`).
The linker script stops the build when `memcpy` or the
wolfIP checksum is missing from the ITCM. wolfIP takes at most 16 frames per
`wolfIP_poll()` (`WOLFIP_POLL_BUDGET=16`). The driver uses 8 transmit and 4 receive
descriptors (19 KB of DTCM).
Set `ENABLE_WOLFIP=1` in `mcxe31b.config` and check the wolfIP path:

```sh
ENABLE_WOLFIP?=1
WOLFBOOT_LIB_WOLFIP?=../lib/wolfip
NXP_MCXE_EMAC_IRQ?=1
WOLFIP_SPEED_TEST?=1
WOLFBOOT_TEST_TFTP?=0
```

Type `network` on the console to run the test. It works the same way as the
[MCXE247 network test](#nxp-mcxe247-network-test): by default it acquires a
DHCP lease and runs a TCP and UDP throughput server on port 9, driven from a
PC on the same network with `python3 tools/scripts/wolfip_speed.py <ip>`.
Ctrl-C on the console stops the server. Measured on the FRDM-MCXE31B at
160 MHz, 100 Mbit/s full duplex, interrupt driven, 10 s per test, with the
script run by Windows Python on a Windows PC on an otherwise idle network:

| Test | Board receives | Board sends |
|------|----------------|-------------|
| TCP, one direction | 88-90 Mbit/s | 86 Mbit/s |
| TCP, both directions | 52.4-53.0 Mbit/s | 39.5 Mbit/s |
| UDP, one direction | 95.7 Mbit/s (no loss) | 95.7 Mbit/s |
| UDP, both directions | 93.5-95.3 Mbit/s | 95.7 Mbit/s |

UDP in one direction runs at the line rate, and both directions at once come
close to it: the board drops 0.4-2.4% of what it receives. TCP is limited by the
CPU.

With `WOLFBOOT_TEST_TFTP=1` the command fetches `TFTP_FILENAME` from
`HOST_IP_STR` instead (40 KB at most) and prints its size and checksum
followed by `WOLFIP_TEST: PASS` or `WOLFIP_TEST: FAIL`. Both the interrupt
driven and the polled build pass this test.

### NXP MCXE31B: Programming with Lauterbach TRACE32

Connect the 10-pin debug cable to J14 and short JP5 to disable the onboard
MCU-Link SWD. TRACE32 R2024.09 has no MCXE31B entry. The S32K314 has the same
debug architecture (AHB-AP 4 = CM7_0, MDM-AP 6, SDA-AP 7) and flash
controller, so use `SYStem.CPU S32K314-M7` with SWD (JTAG on J14 does not
work). Program `factory.bin` at `0x00400000`.

Scripts for this are in `tools/scripts/mcxe31b`. They find the build output
relative to their own location, so run them from the wolfBoot checkout, for
example `DO <wolfBoot>/tools/scripts/mcxe31b/e31b_flash_factory_bin.cmm`:

| Script | Purpose |
|--------|---------|
| `e31b_debug.cmm` | Reset and halt the CPU, then load the `wolfboot.elf` and `test-app/image.elf` symbols |
| `e31b_flash_factory_bin.cmm` | Program `factory.bin`, erase the update partition and swap sector, then reset and detach |
| `e31b_flash_update.cmm` | Program `test-app/image_v2_signed.bin` into the update partition, then reset and detach |

Each script writes a log to the TRACE32 system directory (`~~`).

The flash scripts run the TRACE32 S32K3 flash algorithm (`s32k3x4.bin`) from
the DTCM, which they clear first so its ECC is valid. They leave the data
flash and the Secure BAF area untouched. The factory script refuses a file
without the IVT marker at offset 0.

`SYStem.Up` sometimes reports a debug port time-out while the boot ROM runs.
`e31b_debug.cmm` then attaches, and finds the core halted at the reset vector.

While TRACE32 is attached, it halts the CPU at the reset vector on every reset.
Detach with `SYStem.Down` before testing an update, which relies on a software
reset.

### NXP MCXE31B: Testing an update

Tested on the FRDM-MCXE31B:

1. Program `factory.bin` with `e31b_flash_factory_bin.cmm`. wolfBoot boots
version 1 and the RGB LED is green.
2. Sign version 2 with the configured 1 KB header and program it with
`e31b_flash_update.cmm`:
```sh
IMAGE_HEADER_SIZE=1024 tools/keytools/sign --ecc256 --sha256 test-app/image.bin wolfboot_signing_private_key.der 2
```
3. On the console, `status` shows the update. `trigger` then `reboot` swaps
the partitions. Version 2 boots, finds the TESTING state and marks itself
successful. The RGB LED is blue.

The console `update` command receives a signed image over XMODEM-CRC into the
update partition instead, and triggers it.

## TI Hercules TMS570LC435

See [/config/examples/ti-tms570lc435.config](/config/examples/ti-tms570lc435.config) for example configuration.
Expand Down
Loading
Loading