Skip to content

mcxe31b port with wolfip support - #1001

Open
twcook86 wants to merge 21 commits into
wolfSSL:masterfrom
twcook86:mcxe31b_emac
Open

twcook86 wants to merge 21 commits into
wolfSSL:masterfrom
twcook86:mcxe31b_emac

Conversation

@twcook86

@twcook86 twcook86 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Add NXP MCX E31B target (FRDM-MCXE31B), with optional wolfIP network test

Depends on #991 (MCXE247 wolfIP driver and speed test). This branch is
built on top of it, so the first 13 commits are #991's. Review only the
last 5 commits; they drop out of this PR once #991 merges.

Tested on FRDM-MCXE31B

Note: goes with wolfSSL/wolfip#201

Copilot AI balanced review requested due to automatic review settings November 24, 2026 06:21
@twcook86 twcook86 self-assigned this Nov 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unchecked XMODEM header sizes and packet bounds can allow flash writes beyond the update partition’s usable capacity, corrupting reserved trailer sectors, the swap sector, or later flash.

4 open issues
What changed in this PR

Adds bare-metal wolfBoot support for the FRDM-MCXE31B board, including firmware update testing and optional wolfIP networking. It builds on the MCXE247 networking and throughput work from #991.

Changes:

  • Adds the MCXE31B HAL, memory layouts, configuration, and console test application.
  • Integrates optional EMAC networking with shared throughput tests and memory-copy optimizations.
  • Adds target documentation, TRACE32 programming scripts, and a CI build job.
File Description
tools/​scripts/​wolfip_speed.py Adds host-side TCP/UDP throughput and statistics reporting.
tools/​scripts/​mcxe31b/​e31b_flash_update.cmm Programs update images with trailer-capacity checks.
tools/​scripts/​mcxe31b/​e31b_flash_factory_bin.cmm Programs factory images with IVT and size checks.
tools/​scripts/​mcxe31b/​e31b_debug.cmm Adds board connection and symbol-loading support.
tools/​scripts/​mcxe247/​e247_debug.cmm Removes obsolete SDK source-path setup.
test-app/​wolfip_tftp_test.h Shares application timebase and cancellation interfaces.
test-app/​wolfip_tftp_test.c Adds EMAC support and TCP/UDP throughput testing.
test-app/​startup_arm.c Adds interrupt routing, ECC initialization, and code relocation.
test-app/​Makefile Integrates MCXE31B and optional wolfIP build settings.
test-app/​ARM-s32k1xx-wolfip.ld Places network state and hot code in SRAM_L.
test-app/​ARM-mcxe31b.ld Defines the standard application memory layout.
test-app/​ARM-mcxe31b-wolfip.ld Separates network code, state, and DMA buffers across memory regions.
test-app/​app_s32k1xx.c Adds network cancellation and clock-mode handling.
test-app/​app_mcxe31b.c Adds the console, XMODEM updates, LEDs, and network command.
src/​string.c Optimizes ARM copies with unaligned source addresses.
hal/​s32k1xx.h Adds clock/cache interfaces and corrects SMC offsets.
hal/​s32k1xx.c Implements clock transitions and flash-cache maintenance.
hal/​mcxe31b.ld Defines bootloader IVT, flash, and DTCM placement.
hal/​mcxe31b.h Defines MCXE31B registers and board connections.
hal/​mcxe31b.c Implements clocks, caches, UART, and flash operations.
docs/​Targets.md Documents board setup, networking, programming, and update testing.
config/​examples/​mcxe31b.config Adds target defaults and optional network settings.
config/​examples/​mcxe247.config Updates clock, alignment, and network-test defaults.
arch.mk Selects Cortex-M7 and the MCXE31B flash origin.
.github/​workflows/​test-configs.yml Adds the MCXE31B configuration build job.

Review effort: Balanced

Comment thread test-app/app_mcxe31b.c Resolved
Comment thread test-app/app_mcxe31b.c Resolved
Comment thread test-app/app_mcxe31b.c Resolved
Comment thread test-app/app_mcxe31b.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #1001

Scan targets checked: wolfboot-src, wolfboot-bugs
Not reviewed (no scan target covers them): .github/workflows/test-configs.yml, arch.mk, config/examples/mcxe247.config, config/examples/mcxe31b.config, docs/Targets.md, hal/mcxe31b.h, hal/mcxe31b.ld, hal/s32k1xx.h, test-app/ARM-mcxe31b-wolfip.ld, test-app/ARM-mcxe31b.ld, test-app/ARM-s32k1xx-wolfip.ld, test-app/Makefile, test-app/wolfip_tftp_test.h, tools/scripts/mcxe247/e247_debug.cmm, tools/scripts/mcxe31b/e31b_debug.cmm, tools/scripts/mcxe31b/e31b_flash_factory_bin.cmm, tools/scripts/mcxe31b/e31b_flash_update.cmm, tools/scripts/wolfip_speed.py
Coverage: 7 of 7 in-scope changed file(s) opened by the reviewer

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Max

Comment thread test-app/app_mcxe31b.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #1001

Scan targets checked: wolfboot-src, wolfboot-bugs
Not reviewed (no scan target covers them): .github/workflows/test-configs.yml, .gitignore, arch.mk, config/examples/mcxe247.config, config/examples/mcxe31b.config, config/examples/nxp-s32k142.config, config/examples/nxp-s32k144.config, config/examples/nxp-s32k146.config, config/examples/nxp-s32k148.config, docs/Targets.md, hal/mcxe31b.h, hal/mcxe31b.ld, hal/s32k1xx.h, test-app/ARM-mcxe31b-wolfip.ld, test-app/ARM-mcxe31b.ld, test-app/ARM-s32k1xx-wolfip.ld, test-app/Makefile, test-app/wolfip_tftp_test.h, tools/scripts/mcxe247/e247_debug.cmm, tools/scripts/mcxe31b/e31b_debug.cmm and 6 more
Coverage: 9 of 10 in-scope changed file(s) opened by the reviewer; not opened: test-app/app_mcxe31b.c

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread test-app/xmodem_rx.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

C40ASF flash/ECC, cache/DMA handling and power-loss recovery during trailer updates need hardware-informed review, while the optional wolfIP EMAC integration also needs validation beyond default CI.

No open issues 🎉

4 resolved since last review

Review effort: Balanced

FAST_MEMCPY's unaligned-source word path now also needs
FAST_MEMCPY_UNALIGNED (03718e4). Set it to keep the word copies this
port was tuned with; nothing here memcpy's from peripheral registers.
- Map WOLFIP_NETDEV_STOP to nxp_mcxe_emac_stop(), so the EMAC is stopped
  on every exit of the network test as on the MCXE247.
- speed_start() resets the driver stats through WOLFIP_NETDEV_STATS_RESET
  instead of the MCXE247 function.
- Linker scripts stop the build when the vector table is not 1 KB
  aligned (IMAGE_HEADER_SIZE=1024) and when the flash load images
  overflow FLASH.
- The wolfIP linker script also asserts that memcpy and wolfIP's
  csum_add are in .ramcode_itcm; string.o is built with __WOLFBOOT, so
  memcpy is in .ramcode also when the test-app builds it.
- Targets.md: fix the garbled ITCM sentence, document
  FAST_MEMCPY_UNALIGNED with the measured TCP rates without it, how to
  change the image header size, and the network console command.
app_mcxe31b.c carried a copy of the XMODEM-CRC receiver identical to
test-app/xmodem_rx.c. Include xmodem_rx.c instead, as app_s32k1xx.c
does, so receiver fixes land once, and rebuild app_mcxe31b.o when it
changes.

Tested on the FRDM-MCXE31B: an oversized header, blocks past the image,
EOT after 2 blocks are cancelled; a repeated block and a repeated last
block are ACKed again; a normal transfer completes and version 2 boots.
- The ITCM clear loop zeroes r3 itself instead of relying on the SRAM
  clear for TARGET_mcxe31b.
- Print the "Ctrl-C stops the server" hint whenever the test-app
  provides wolfip_test_abort(), not only for the MCXE247 ENET port.
- mcxe31b.config: the TFTP receive buffer is 40 KB (TFTP_RAM_MAX), not
  128 KB.
- hal_flash_write() and hal_flash_erase() refuse ranges outside the code
  and data flash: flash_lock_reg() indexes the lock registers by
  address, so an out of range address changed unrelated registers.
- mc_me_clock_enable() and the MUX_0 divider update wait time out, so
  clock_init() returns and the system stays on FIRC instead of hanging.
  uart_init() leaves LPUART5 alone when its clock does not start.

Tested on the FRDM-MCXE31B: XMODEM update to version 2, swap, and v2
marked SUCCESS.
- arch.mk sets WOLFBOOT_RAM_ECC_INIT for the target, as Targets.md says,
  instead of the example config, and stops the build without
  NVM_FLASH_WRITEONCE=1.
- test-app: ENABLE_WOLFIP=1 with DEBUG_UART=0 stops with a message
  instead of a linker assertion on memcpy.
- CI: build mcxe31b.config with DEBUG_UART=0.
The reset handler cleared the ITCM whenever APP_RAMCODE_ITCM was set,
which assumes an ECC protected ITCM, and only with APP_RAM_ECC_INIT.
Clear it with a separate APP_ITCM_ECC_INIT instead, and build the naked
reset handler when either option is set, each loop under its own
option. An ITCM without ECC needs only APP_RAMCODE_ITCM. The mcxe31b
wolfIP build sets APP_ITCM_ECC_INIT, and its linker script checks the
ITCM clear range is 8-byte aligned for the 64-bit stores.
- After a transfer, drain the bytes the LPUART interrupt buffered,
  instead of reading the LPUART, which the interrupt has already
  emptied.
- status names partition states with part_state_name(), so an unknown
  state shows as UNKNOWN instead of NEW.
- xmodem_rx.c: list the files that include it, the unit test included.
Add tools/unit-tests/unit-flash-mcxe31b.c. It compiles only the flash
logic of hal/mcxe31b.c (WOLFBOOT_UNIT_TEST_FLASH) and models the C40ASF
program and erase steps: one program per 64-bit ECC segment between
erases, programs that only clear bits. It covers the quad page split,
merging partial writes, skipping unchanged segments, the sector
rounding of the erase, the range checks of both, and failures.

The HAL reads the flash array through FLASH_PTR(), a plain pointer in
the target build, which the test maps onto its flash model.
The shared APP_RAM_ECC_INIT reset handler chose 64-bit stores by
TARGET_mcxe31b. Select them with APP_RAM_ECC_64BIT instead, set by the
mcxe31b wolfIP build, whose linker script now checks the SRAM clear
range is 8-byte aligned.

Tested on the FRDM-MCXE31B: boots, speed test unchanged.
After a transfer, drain the bytes the LPUART interrupt buffered,
instead of reading the LPUART, which the interrupt has already
emptied, as on the MCXE31B.
- hal_flash_write fails on a segment that must change but is already
  programmed, instead of programming it again and corrupting its ECC
- hal_flash_erase covers every sector of an unaligned range
- The console functions do nothing until uart_init() has clocked and
  configured LPUART5; uart_ready() tells the test-app
- Linker scripts place .keystore explicitly; the bootloader script checks
  the .data load image fits
- The test-app takes -DDEBUG_UART from DEBUG_UART=1 only, so the no-UART
  CI job builds a test-app without a console; the LPUART5 vector falls
  back to isr_empty
- Unit tests for both flash fixes; comment and Targets.md updates

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #1001

Scan targets checked: wolfboot-src, wolfboot-bugs
Not reviewed (no scan target covers them): .github/workflows/test-configs.yml, .gitignore, arch.mk, config/examples/mcxe31b.config, docs/Targets.md, hal/mcxe31b.h, hal/mcxe31b.ld, test-app/ARM-mcxe31b-wolfip.ld, test-app/ARM-mcxe31b.ld, test-app/Makefile, test-app/wolfip_tftp_test.h, tools/scripts/mcxe31b/e31b_debug.cmm, tools/scripts/mcxe31b/e31b_flash_factory_bin.cmm, tools/scripts/mcxe31b/e31b_flash_update.cmm, tools/unit-tests/Makefile
Coverage: 4 of 7 in-scope changed file(s) opened by the reviewer; not opened: hal/mcxe31b.c, test-app/app_mcxe31b.c, test-app/app_s32k1xx.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed stale reviews from themself December 5, 2026 05:46

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical issues allow heap growth to corrupt live stack frames and prevent update confirmation when DEBUG_UART=0, causing rollback on the next reset.

2 open issues

Review effort: Balanced

Comment thread test-app/app_mcxe31b.c Resolved
Comment thread test-app/app_mcxe31b.c Resolved
- The test-app marks a TESTING update successful also with DEBUG_UART=0;
  only the message needs the console. Without it the update was rolled
  back at the next reset.
- Both test-app linker scripts reserve a 16 KB stack region below the top
  of the DTCM; _sbrk() stops at its bottom (_end_heap) instead of at the
  initial stack pointer, and rejects negative increments.
- The lock register and bit calculation moves into flash_lock_bit(),
  which the unit test builds; flash_lock_reg() keeps its behaviour.
  test_lock_bit_mapping checks the super sector and sector boundaries
  of every code block, the last sector and the data flash.
- wolfip_test_abort(): rename the local abort, which shadowed abort(),
  to ctrl_c as in app_s32k1xx.c
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.

4 participants