Repository navigation
Conversation
- Build the wolfIP nxp_mcxe_enet port without the MCUXpresso SDK, in interrupt mode, with ENET IRQs 73-75 routed to the driver handler. - IMAGE_HEADER_SIZE=1024 in mcxe247.config: the 179-entry vector table needs 1 KB alignment for VTOR, otherwise the ENET IRQs vector to the wrong handler. - Place the wolfIP state in SRAM_L and use 9 KB TCP buffers per socket. - Speed test: TCP and UDP server on port 9 with rx, tx and bidirectional modes, and a per-test CPU breakdown from the driver cycle counters. Host side: tools/scripts/wolfip_speed.py. - Drop the SDK paths from the TRACE32 debug script and the docs.
- Ctrl-C on the console stops the throughput server - UDP datagrams carry a session id chosen by the host for each test. The board ignores data of a finished test, so datagrams still queued on the way cannot start a new test, and the host ignores board datagrams of an earlier test. - wolfip_speed.py sends UDP at 100 Mbit/s on the wire by default instead of as fast as the host can, and warns when --rate 0 is used.
-ffreestanding disables the compiler builtins, so every small fixed-size memcpy in wolfIP (one per 16-bit word in the transport checksum, header field accessors) became a call to the byte-wise memcpy in src/string.c. That was most of the stack's CPU time. Building the wolfIP sources hosted lets the compiler inline them. Measured with tools/scripts/wolfip_speed.py at 48 MHz, Mbit/s: TCP rx 4.3 -> 6.9, TCP tx 4.1 -> 6.3, UDP rx 5.5 -> 9.1, UDP tx 5.4 -> 9.0.
wolfIP is CPU bound on the MCXE247. -O2 on the wolfIP objects is 10-18% faster than -Os for 12KB more flash (80 MHz, code cache on): tcp-rx 24.1 -> 27.0, tcp-tx 22.0 -> 25.9, udp-tx 38.2 -> 41.8 Mbit/s. With the faster stack the driver keeps up with a line-rate UDP flood, and wolfIP_poll() took up to 128 frames per call into a socket that holds six datagrams, so udp-rx fell to 7.6 Mbit/s. Limiting the budget to 8 frames lets the speed server drain the socket between batches: udp-rx 36.9 -> 45.1 Mbit/s. WOLFIP_POLL_BUDGET needs the wolfIP change that makes it overridable.
The receiver thread gave up the GIL on every recvfrom() and then waited for the pacer's busy-wait loop to release it, so the host dropped most of what the board sent (55-92% loss). Bidir now drains the socket between sends in one thread and collects the board's last datagrams afterwards. UDP bidir board tx as received by the host: 8.4 -> 21.5 Mbit/s, 0% loss.
With ENABLE_WOLFIP=1 the network command now runs the TCP and UDP throughput server (WOLFIP_SPEED_TEST=1); the TFTP fetch is opt-in with WOLFBOOT_TEST_TFTP=1. Update the config comments and docs/Targets.md.
memcpy (already in SRAM_U as RAM code) and wolfIP's csum_add() were the hottest code. In SRAM_U the core fetches code over the system bus, which the copies' own data accesses also use; SRAM_L is fetched over the code bus in parallel. A .ramcode_l section in ARM-s32k1xx-wolfip.ld takes string.o's .ramcode and wolfip.o's .text.csum_add ahead of the .text rule, loads after .edidx in flash, and is copied at reset (APP_RAMCODE_L in startup_arm.c). .keystore is now placed in flash explicitly; the new layout had made it an orphan in SRAM_L. 332 bytes of SRAM_L. 80 MHz, code cache on: tcp-rx 29.2 -> 33.8, tcp-tx 28.7 -> 33.1, udp-rx 56.0 -> 66.6, udp-tx 49.6 -> 60.4, udp-bidir 23.6+26.5 -> 28.9+32.5 Mbit/s. TFTP test and a flash write from the test-app pass.
s32k1xx_clock_hsrun() enters HSRUN on the FIRC, then runs the core from the SPLL at 112 MHz (bus 56 MHz, flash 28 MHz), as the SDK's BOARD_BootClockHSRUN does. s32k1xx_clock_run() returns to RUN at 80 MHz. The SOSC and SPLL setup is split into helpers that the 80 MHz path now shares. With S32K1XX_HSRUN_SPEED_TEST the test-app's network command runs the speed server in HSRUN and switches back when it stops, so flash writes from the console still work. mcxe247.config sets it. The SMC register offsets were the Kinetis layout. On the S32K1xx and MCXE247 VERID and PARAM come first: PMPROT is at 0x08, PMCTRL at 0x0C and PMSTAT at 0x14. Before, the HSRUN enable went to a read-only register, so S32K1XX_CLOCK_HSRUN could never enter HSRUN either. 112 MHz vs 80 MHz: tcp-rx 33.8 -> 45.7, tcp-tx 33.1 -> 43.7, udp-rx 66.6 -> 95.6 (line rate), udp-tx 60.4 -> 75.8, udp-bidir 28.9+32.5 -> 38.0+42.8 Mbit/s. After the server stops, a flash write (success) works and HSRUN can be entered again.
At -Os GCC compiled the unaligned-source word loop with both pointers recomputed from the byte count on every pass: 15 instructions per 16 bytes. Step word pointers instead and store through an aligned type, since the destination is aligned by then: 11 instructions per 16 bytes. Results match a byte copy for every length up to 300 and all source/destination offsets 0-7 (host test, ASan/UBSan). MCXE247 wolfIP speed test at 112 MHz: udp-tx 75.8 -> 77.5 Mbit/s, wolfIP cycles per frame down 2-4% for tcp-rx, udp-tx and udp-bidir.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved bugs can hide TCP transfer failures, skew UDP measurements, let incoming TCP connections invalidate active UDP tests, and break the documented netcat workflow.
4 open issues
What changed in this PR
Optimizes MCXE247 Ethernet processing in the wolfBoot test application and adds host-driven throughput benchmarks. This integrates with the standalone, interrupt-driven ENET driver in wolfIP #196.
Changes:
- Adds TCP/UDP receive, transmit, and bidirectional benchmarks with throughput, loss, and CPU reporting.
- Optimizes buffering, memory placement, copying, and interrupt handling.
- Adds clock and cache controls, benchmark cancellation, and updated configuration and documentation.
| File | Description |
|---|---|
tools/scripts/wolfip_speed.py |
Adds the host benchmark runner and results reporting. |
tools/scripts/mcxe247/e247_debug.cmm |
Removes SDK arguments and source paths. |
test-app/wolfip_tftp_test.h |
Declares the console-abort callback. |
test-app/wolfip_tftp_test.c |
Adds TCP/UDP benchmark modes, statistics, and shutdown handling. |
test-app/startup_arm.c |
Routes ENET interrupts and copies hot code into RAM. |
test-app/Makefile |
Removes SDK dependencies and tunes network compilation and buffers. |
test-app/ARM-s32k1xx-wolfip.ld |
Places hot code and wolfIP state in SRAM_L. |
test-app/app_s32k1xx.c |
Integrates clock switching and cancellation; corrects partition-state reporting. |
src/string.c |
Optimizes ARM copies with unaligned word loads. |
hal/s32k1xx.h |
Adds clock/cache interfaces and corrects power-register offsets. |
hal/s32k1xx.c |
Implements clock transitions and flash-cache management. |
docs/Targets.md |
Documents performance options, memory layout, and benchmark usage. |
config/examples/mcxe247.config |
Updates performance defaults, image-header alignment, and network-test settings. |
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #991
Scan targets checked: wolfboot-src, wolfboot-bugs
Not reviewed (no scan target covers them): config/examples/mcxe247.config, docs/Targets.md, hal/s32k1xx.h, test-app/ARM-s32k1xx-wolfip.ld, test-app/Makefile, test-app/wolfip_tftp_test.h, tools/scripts/mcxe247/e247_debug.cmm, tools/scripts/wolfip_speed.py
Coverage: 5 of 5 in-scope changed file(s) opened by the reviewer
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: Max
Board server: - Refuse a TCP client while a UDP test runs. Its speed_start() cleared the shared state and silently ended the UDP test. - A TCP client that sends no direction byte within 500 ms gets a bidir test. A plain "nc <ip> 9" that only reads never got any data. - End a UDP bidir test when the board's stream ends, as tx already did. It stayed open until the host's 'q', about 1 s later, so the window held an idle tail: an 8 s test was timed as 9 s and the board rx rate read about 11% low (udp-bidir rx 38.9 -> 43.8 Mbit/s at 112 MHz, same loss). wolfip_speed.py: - An error in a TCP worker thread (reset, sendall() timeout) now fails the test instead of reporting partial counts. The socket is closed in a finally block, and the receiver waits with select() so it no longer changes the timeout the sender's sendall() uses. - Send 'q' before every test, TCP too, so a UDP test left running cannot make the board refuse the TCP client.
aidangarske
left a comment
There was a problem hiding this comment.
Skoll Multi-Scan Review
Modes: review + review-security
Overall recommendation: REQUEST_CHANGES
Findings: 6 total — 6 posted, 0 skipped
6 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [High] [review] Finished UDP sessions can be restarted by delayed data —
test-app/wolfip_tftp_test.c:649 - [High] [review+review-security] New clock, power-mode and cache waits have no timeout —
hal/s32k1xx.c:244 - [Medium] [review-security] Unauthenticated UDP command can trigger a transmit flood of up to 49.7 days —
test-app/wolfip_tftp_test.c:804 - [Medium] [review] The new throughput protocol state machine has no automated coverage —
test-app/wolfip_tftp_test.c:630 - [Medium] [review] New unaligned memcpy path lacks targeted tests —
src/string.c:328 - [Medium] [review] New XMODEM bounds and duplicate-block handling lacks regression tests —
test-app/app_s32k1xx.c:612
Review generated by Skoll
| speed.active = 0U; | ||
| speed.streaming = 0U; | ||
| speed.end_ms = now; | ||
| speed_ended_session = speed.session; |
There was a problem hiding this comment.
Finished UDP sessions can be restarted by delayed data · bug
The stale-packet defense remembers only one ended session, and speed_stop() overwrites it for every protocol. TCP tests have speed.session == 0, so ending any TCP test erases the last UDP session ID. A delayed datagram from that UDP test then passes the check at line 791 and starts a new test.
The same happens without TCP: after UDP session B ends, session A is no longer remembered. Delayed A data can restart it. If B is still running, delayed A data also passes, and lines 793-794 stop B in favor of A.
This breaks the contract in the file's protocol comment that data from a finished test is ignored. A restarted 'r' test has no end time, so it blocks TCP clients until a 'q', a new UDP session or a server stop. It also replaces the previous test's statistics. The affected code is the optional benchmark server in the test application.
Suggested fix: At minimum, update speed_ended_session only when speed.proto == SPEED_PROTO_UDP. That fixes the TCP case but not older UDP sessions. For a complete fix, create sessions only from a distinct start command and accept data only for the active session, or track enough ended sessions to reject late packets.
Basis: The protocol comment in wolfip_tftp_test.c states that data of a test that has ended is ignored.
|
|
||
| static void sysclk_wait(uint32_t scs) | ||
| { | ||
| while ((SCG_CSR & SCG_CSR_SCS_MASK) != scs) {} |
There was a problem hiding this comment.
New clock, power-mode and cache waits have no timeout · Logic
The new paths spin without a bound while waiting for SOSC valid, SPLL lock, system-clock selection and HSRUN/RUN status. The cache helpers do the same on LMEM_PCCCR_GO. config/examples/mcxe247.config now enables the crystal/SPLL path and code cache by default.
A crystal that does not start, a PLL that does not lock, or a failed power-mode transition therefore hangs wolfBoot in hal_init() before image verification or recovery. It can also hang the network console command.
Severity differs between modes: review rated this High/BLOCK, while review-security rated it Low (exceptional trigger, narrow reach, no security boundary). The stricter rating is kept. For context, the surrounding HAL already uses unbounded polling for FIRC valid, clock switching and flash command completion, so maintainers may reasonably weigh this lower.
Suggested fix: Use bounded polling for the new hardware transitions. Return an error from failed runtime transitions. At boot, either stay on or return to the known-good FIRC configuration, or enter an explicit failure path.
Basis: The wolfBoot project convention supplied to the reviewers requires deterministic execution with no unbounded loops in critical code.
| if (len < (uint32_t)SPEED_HDR_LEN || len > SPEED_UDP_MAX) | ||
| len = SPEED_UDP_MAX; | ||
| speed.stream_len = len; | ||
| speed.stream_end_ms = now + speed_get32(speed_rxbuf + 8); |
There was a problem hiding this comment.
Unauthenticated UDP command can trigger a transmit flood of up to 49.7 days · Security
The UDP control path accepts any datagram of at least 16 bytes with the magic byte, a valid command and a nonzero session. A 't' or 'b' command supplies an unchecked 32-bit duration in milliseconds, and speed_udp_send() then sends bursts to the packet's source address until that deadline. One packet can request about 49.7 days.
There is no authentication, return-routability check or server-side duration limit. A reachable peer can consume the board's CPU and link capacity, and a spoofed source address can redirect the traffic to a third party. The same open path lets 'q' packets or new session IDs stop or replace another client's test.
This applies while the speed server is running (WOLFIP_SPEED_TEST builds, which the mcxe247 example config enables by default). Ctrl-C on the console, a 'q' packet or a new session ends the stream.
Suggested fix: Clamp the requested duration to a small server-side maximum. If the server may run on untrusted networks, also require a return-routability or authenticated session handshake before streaming.
| #endif | ||
| } | ||
|
|
||
| static void speed_start(uint8_t proto, uint8_t mode, uint64_t now) |
There was a problem hiding this comment.
The new throughput protocol state machine has no automated coverage · test
No repository test exercises the new TCP/UDP lifecycle, session replacement, delayed datagrams or TCP-to-UDP transitions. The host script is a manual benchmark driver, not a regression test, so it would not catch the stale-session bug above.
Suggested fix: Add mocked socket/state-machine tests for: delayed data after UDP A completes; UDP A, then B, then delayed A; UDP, then TCP, then delayed UDP; active-session replacement; 'q' handling; and TCP refusal during an active UDP test.
| * align the destination, then copy words. Network stacks copy payloads | ||
| * at 2 mod 4 offsets, which the aligned-only path below never speeds | ||
| * up. Normal memory only, as for any word access. */ | ||
| if (n >= 2 * sizeof(uint32_t)) { |
There was a problem hiding this comment.
New unaligned memcpy path lacks targeted tests · test
tools/unit-tests/unit-string.c defines FAST_MEMCPY, but the new branch also requires __ARM_FEATURE_UNALIGNED. An x86 host build therefore does not compile it; an ARM host that defines the macro would. The existing memcpy cases use fixed lengths of 16 and 32 bytes and do not vary source or destination offsets. The new alignment prologue, 16-byte loop, word remainder and byte tail have no targeted regression coverage in a widely used primitive.
Suggested fix: Add a test variant that enables the unaligned branch. Check every source and destination offset from 0 to 3, with lengths around 0, 4, 8, 16 and 32 bytes and guard bytes around both buffers.
Basis: ISO C17 section 7.24.2.1 requires memcpy to copy exactly n characters from the source object into the destination object.
| calc_crc = crc16_ccitt(xpkt + 3, XMODEM_PAYLOAD_SIZE); | ||
|
|
||
| if (recv_crc == calc_crc) { | ||
| if (recv_crc == calc_crc && dup) { |
There was a problem hiding this comment.
New XMODEM bounds and duplicate-block handling lacks regression tests · test
The change substantially alters updater validation, maximum-image calculations, final-block behavior, duplicate ACK handling and cancellation, but no automated test targets xmodem_receive_ram(). These paths control which bytes are written to the update partition and whether the sender can finish after a lost ACK.
Suggested fix: Add mocked UART/flash tests for: an image exactly at the maximum size; an oversized header; a block crossing into the trailer sectors; a duplicate ordinary block; a duplicate final block after eot_expected; a bad-CRC duplicate; and a flash write failure.
| | Script | Purpose | | ||
| |--------|---------| | ||
| | `e247_debug.cmm` | Reset and halt the CPU, then load the `wolfboot.elf` and `test-app/image.elf` symbols. Takes the MCUXpresso SDK path as an optional argument, used to find the ENET driver sources (default: `../NXP/mcuxpresso-sdk/mcuxsdk` next to the checkout) | | ||
| | `e247_debug.cmm` | Reset and halt the CPU, then load the `wolfboot.elf` and `test-app/image.elf` symbols | |
There was a problem hiding this comment.
The onboard MCU-Link works for this too: pyocd pack install mcxe247vlq then pyocd flash -t mcxe247vlq --base-address 0 factory.bin is what I tested with. Can you document that next to the TRACE32 steps like the other FRDM targets, and warn that pyocd erase --chip leaves the FCF erased so the part comes back secured after reset?
| # Adds the "network" console command. Needs a wolfIP checkout and an MCUXpresso | ||
| # SDK (for the fsl_enet driver). | ||
| # Adds the "network" console command. Needs a wolfIP checkout, which provides | ||
| # the interrupt-driven nxp_mcxe_enet driver. |
There was a problem hiding this comment.
Against current wolfIP master this fails on a missing fsl_enet.h, since it needs wolfip#196, and nothing records which wolfIP it expects. Now that the port is SDK-free, can lib/wolfip be a pinned submodule like the other lib/ deps, with an ENABLE_WOLFIP=1 mcxe247 build in test-configs.yml?

Optimizes the mcxe247 for ethernet processing.
Adds tcp/udp throughput tests.
Goes with wolfSSL/wolfip#196