Skip to content

Wolfhal uart flash - #998

Merged
dgarske merged 3 commits into
wolfSSL:masterfrom
AlexLanzano:wolfhal-uart-flash
Dec 4, 2026
Merged

dgarske merged 3 commits into
wolfSSL:masterfrom
AlexLanzano:wolfhal-uart-flash

Conversation

@AlexLanzano

@AlexLanzano AlexLanzano commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds UART flash (UART_FLASH=1) support for wolfHAL boards, so the update and swap partitions can live on a remote host served by tools/uart-flash-server. Also adds BOARD_DIR so wolfHAL boards can be kept outside the wolfBoot tree.

UART flash on wolfHAL

  • hal/wolfhal.c implements uart_init, uart_tx and uart_rx on top of the wolfHAL UART API, using the board's BOARD_UART_FLASH_DEV. With WOLFHAL=1, the legacy hal/uart/uart_drv_<target>.c driver is no longer linked (options.mk, test-app/Makefile).
  • src/uart_flash.c: with WOLFHAL defined, uart_rx blocks until the board's wolfHAL UART timeout instead of returning immediately, so the ACK, read and erase waits call it once rather than spinning in a loop of uart_rx calls.
  • stm32wb_nucleo:
    • links the GPIO and UART drivers when either DEBUG_UART or UART_FLASH is set
    • keeps wolfHAL timeouts enabled for UART_FLASH=1
    • defines BOARD_UART_FLASH_DEV as the debug UART
    • provides a poll-count whal_Timeout (500000 polls, matching the legacy loop count)
  • docs/wolfHAL.md gains a UART Flash section: how it works, board requirements, a timeout example, and build/test steps.
  • CI: new stm32wb_wolfhal_uart_flash_encryption_test job building stm32wb-uart-flash-encryption.config with WOLFHAL=1 BOARD=stm32wb_nucleo.

BOARD_DIR

wolfHAL builds read board.mk, wolfHAL_board.c and wolfHAL_board.h from BOARD_DIR, which defaults to hal/boards/$(BOARD). Relative paths resolve against the wolfBoot root, so an out-of-tree board can be built with:

make WOLFHAL=1 BOARD=myboard BOARD_DIR=/path/to/myboard

Testing

  • Builds: stm32wb.config with WOLFHAL=1 BOARD=stm32wb_nucleo UART_FLASH=1, and stm32wb-uart-flash-encryption.config with WOLFHAL=1 BOARD=stm32wb_nucleo.
  • Hardware (NUCLEO-WB55): encrypted update over UART flash with ufserver, following the test-enc-update steps. v1 boots and triggers the update, wolfBoot fetches and swaps in the encrypted v2 image, and the app reports version 2. Same result as the legacy UART driver baseline.

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

The board-path default in arch.mk duplicates WOLFBOOT_ROOT during normalization, causing standalone test-app builds to fail the board.mk existence check for an in-tree board.

1 open issue
What changed in this PR

This PR adds UART-backed remote flash support to wolfBoot’s wolfHAL integration and allows board files to live outside the repository.

Changes:

  • Add wolfHAL UART adapters and STM32WB timeout configuration for remote flash operations.
  • Use configurable BOARD_DIR paths in bootloader and test-application builds.
  • Document the setup and add build coverage for encrypted UART flash.
File Description
test-app/​Makefile Use BOARD_DIR and omit the legacy UART driver with wolfHAL.
src/​uart_flash.c Use wolfHAL’s receive timeout for protocol waits.
options.mk Exclude the legacy UART driver from wolfHAL builds.
Makefile Load and compile board files from BOARD_DIR.
hal/​wolfhal.c Provide UART flash functions through wolfHAL APIs.
hal/​boards/​stm32wb_nucleo/​wolfHAL_board.h Define the UART flash device and timeout configuration.
hal/​boards/​stm32wb_nucleo/​wolfHAL_board.c Add poll-based timeouts and UART flash initialization.
hal/​boards/​stm32wb_nucleo/​board.mk Enable timeouts and required drivers for UART flash.
docs/​wolfHAL.md Document external boards and UART flash setup.
arch.mk Define WOLFHAL and resolve board-directory paths.
.github/​workflows/​test-configs.yml Add an encrypted UART flash build configuration for wolfHAL.

Review effort: Balanced

Comment thread arch.mk 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 #998

Scan targets checked: wolfboot-src, wolfboot-bugs
Not reviewed (no scan target covers them): .github/workflows/test-configs.yml, Makefile, arch.mk, docs/wolfHAL.md, hal/boards/stm32wb_nucleo/board.mk, hal/boards/stm32wb_nucleo/wolfHAL_board.h, options.mk, test-app/Makefile
Coverage: 3 of 3 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

Comment thread test-app/Makefile Resolved
Implement uart_init/tx/rx in hal/wolfhal.c and rely on the board's
wolfHAL UART timeout in uart_flash.c. Enable it on stm32wb_nucleo,
with docs and a CI build.
Let wolfHAL builds read board files from BOARD_DIR, defaulting to
hal/boards/$(BOARD). Relative paths resolve against the wolfBoot root.
@dgarske dgarske self-assigned this Dec 4, 2026
@dgarske
dgarske self-requested a review December 4, 2026 16:13

@dgarske dgarske left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes look good. Built and compared against master (arm-none-eabi-gcc 13.2.1):

  • stm32wb UART_FLASH (both configs), out-of-tree BOARD_DIR (absolute and relative), standalone test-app: all build.
  • stm32wb/stm32wba wolfHAL builds without UART_FLASH, and the legacy UART flash build, are byte-identical to master.
    No WB55 here, so not hardware tested on my side.

The Copilot test-app BOARD_DIR comment does not reproduce at 5743b7f. Please reply/resolve it if it was fixed by the second commit.

Comment thread src/uart_flash.c Resolved
Comment thread src/uart_flash.c Resolved
Comment thread hal/wolfhal.c Resolved
Skip non-ACK bytes, give the erase ACK ERASE_TIMEOUT board timeouts,
and document that UART_FLASH_BITRATE is ignored.

@dgarske dgarske left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Latest push resolves all three. Rebuilt at e1a1e20 (stm32wb UART_FLASH with and without wolfHAL, uart-flash-encryption): all build, legacy build unchanged. Thanks!

@dgarske
dgarske merged commit 444636a into wolfSSL:master Dec 4, 2026
585 checks passed
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.

6 participants