remove wolfhal TARGET. Add WOLFHAL option

pull/801/head
Alex Lanzano 2026-06-03 09:21:20 -04:00 committed by Daniele Lacamera
parent 125872c571
commit 01c52d87e8
9 changed files with 67 additions and 40 deletions

View File

@ -667,11 +667,11 @@ jobs:
arch: arm
config-file: ./config/examples/stm32wb.config
wolfhal_stm32wb_test:
stm32wb_wolfhal_test:
uses: ./.github/workflows/test-build.yml
with:
arch: arm
config-file: ./config/examples/wolfhal_stm32wb_nucleo.config
config-file: ./config/examples/stm32wb_wolfhal_nucleo.config
# TODO: ti-tms570lc435.config requires F021 Flash API (Windows installer only)
# ti_tms570lc435_test:

View File

@ -51,7 +51,11 @@ OBJS+=./src/dice/dice.o
endif
ifneq ($(TARGET),library)
OBJS+=./hal/$(TARGET).o
ifeq ($(WOLFHAL),1)
OBJS+=./hal/wolfhal.o
else
OBJS+=./hal/$(TARGET).o
endif
endif
# User-provided key configuration
@ -174,13 +178,16 @@ export WOLFBOOT_LIB_WOLFHSM
## Architecture/CPU configuration
include arch.mk
ifeq ($(TARGET),wolfhal)
ifeq ($(WOLFHAL),1)
ifeq ($(strip $(BOARD)),)
$(error TARGET=wolfhal requires BOARD to be set, e.g. BOARD=stm32wb_nucleo)
$(error WOLFHAL=1 requires BOARD to be set, e.g. BOARD=stm32wb_nucleo)
endif
# wolfHAL target: hal/wolfhal.o is added by the per-TARGET rule
# above. The board's board.c provides hal_init/hal_prepare_boot and
# the wolfHAL device handles; board.mk pulls in chip drivers.
ifeq ($(wildcard hal/boards/$(BOARD)/board.mk),)
$(error BOARD=$(BOARD) has no hal/boards/$(BOARD)/board.mk)
endif
# wolfHAL backend: hal/wolfhal.o replaces hal/$(TARGET).o above. The
# board's board.c provides hal_init/hal_prepare_boot and the wolfHAL
# device handles; board.mk pulls in chip drivers.
OBJS+=./hal/boards/$(BOARD)/board.o
include hal/boards/$(BOARD)/board.mk
endif

14
arch.mk
View File

@ -223,7 +223,7 @@ ifeq ($(ARCH),ARM)
SPI_TARGET=stm32
endif
# Defaults for linker script placeholders (overridden by wolfhal target)
# Defaults for linker script placeholders (overridden when WOLFHAL=1)
WOLFHAL_FLASH_EXCLUDE_TEXT?=*(.text*)
WOLFHAL_FLASH_EXCLUDE_RODATA?=*(.rodata*)
WOLFHAL_FLASH_RAM_SECTIONS?=
@ -574,7 +574,7 @@ endif
endif
endif
ifeq ($(TARGET),wolfhal)
ifeq ($(WOLFHAL),1)
WOLFHAL_ROOT?=$(WOLFBOOT_ROOT)/lib/wolfHAL
CFLAGS+=-I$(WOLFHAL_ROOT) -Ihal/boards/$(BOARD)
endif
@ -1953,9 +1953,13 @@ WOLFCRYPT_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/logging.o
ifeq ($(DEBUG_UART),1)
CFLAGS+=-DDEBUG_UART
# If this target has a UART driver, add it to the OBJS
ifneq (,$(wildcard hal/uart/uart_drv_$(TARGET).c))
OBJS+=hal/uart/uart_drv_$(TARGET).o
# If this target has a UART driver, add it to the OBJS. When WOLFHAL=1,
# the wolfHAL board.mk pulls in its own UART driver and hal/wolfhal.c
# provides uart_write; the legacy driver would collide on uart_write.
ifneq ($(WOLFHAL),1)
ifneq (,$(wildcard hal/uart/uart_drv_$(TARGET).c))
OBJS+=hal/uart/uart_drv_$(TARGET).o
endif
endif
endif

View File

@ -1,5 +1,6 @@
TARGET=wolfhal
TARGET=stm32wb
BOARD=stm32wb_nucleo
WOLFHAL=1
PKA=0
SIGN=ECC256
HASH=SHA256

View File

@ -7,11 +7,11 @@ platforms.
## Overview
The wolfHAL integration uses a single generic `TARGET=wolfhal` with a per-board
abstraction layer. All board-specific details — device instances, driver bindings,
build flags, and linker scripts — live in a self-contained board directory. Adding
support for a new board or MCU family requires no changes to the core build system or
HAL shim.
The wolfHAL integration is enabled by setting `WOLFHAL=1` alongside the existing
`TARGET=<chip>` and a new `BOARD=<board>` variable. All board-specific details —
device instances, driver bindings, build flags, and linker scripts — live in a
self-contained board directory. Adding support for a new board or MCU family
requires no changes to the core build system or HAL shim.
The integration uses wolfHAL's **direct API mapping** feature. Each platform
driver source provides an optional `#ifdef` block that renames its driver
@ -48,13 +48,14 @@ The integration consists of four parts:
### How It Fits Together
```
config/examples/wolfhal_<board>.config
└─ TARGET=wolfhal BOARD=<board>
config/examples/<chip>_wolfhal_<board>.config
└─ TARGET=<chip> BOARD=<board> WOLFHAL=1
arch.mk
└─ Sets WOLFHAL_ROOT, CFLAGS += -Ihal/boards/$(BOARD)
Makefile
└─ OBJS += hal/wolfhal.o (replaces hal/$(TARGET).o)
└─ OBJS += hal/boards/$(BOARD)/board.o
└─ include hal/boards/$(BOARD)/board.mk
@ -78,14 +79,17 @@ linker can garbage-collect any unused symbols with `-Wl,--gc-sections`.
A wolfHAL-based config requires two variables beyond the standard wolfBoot settings:
```
TARGET=wolfhal
TARGET=stm32wb
BOARD=stm32wb_nucleo
WOLFHAL=1
```
- `TARGET=wolfhal` selects the generic wolfHAL HAL shim and build path.
- `TARGET` keeps its usual meaning (the chip family).
- `WOLFHAL=1` swaps the legacy `hal/$(TARGET).c` for the generic wolfHAL shim
(`hal/wolfhal.c`) and includes the per-board build pieces.
- `BOARD` selects the board directory under `hal/boards/`.
See `config/examples/wolfhal_*.config` for complete examples.
See `config/examples/*_wolfhal_*.config` for complete examples.
## Adding a New Board
@ -210,11 +214,12 @@ Only one API mapping flag may be active per device type per build.
### 4. Config File
Create `config/examples/wolfhal_<board_name>.config`:
Create `config/examples/<chip>_wolfhal_<board_name>.config`:
```
TARGET=wolfhal
TARGET=<chip>
BOARD=<board_name>
WOLFHAL=1
SIGN=ECC256
HASH=SHA256
WOLFBOOT_SECTOR_SIZE=0x1000

View File

@ -5,7 +5,7 @@ CFLAGS+=-DWHAL_CFG_NO_TIMEOUT
# Upstream wolfHAL drivers from lib/wolfHAL/src/. wolfBoot's hal_flash_*
# contract is satisfied by hal/wolfhal.c (added automatically because
# TARGET=wolfhal) calling whal_Flash_*.
# WOLFHAL=1) calling whal_Flash_*.
CFLAGS+=-DWHAL_CFG_STM32WB_FLASH_DIRECT_API_MAPPING
CFLAGS+=-DWHAL_CFG_STM32WB_GPIO_DIRECT_API_MAPPING

View File

@ -780,7 +780,12 @@ ifeq ($(NO_XIP),1)
endif
ifeq ($(DEBUG_UART),1)
ifeq ($(strip $(UART_TARGET)),)
ifeq ($(WOLFHAL),1)
# wolfHAL provides uart_write via hal/wolfhal.c; the wolfHAL board.mk
# pulls in the wolfHAL uart driver. Don't auto-add the legacy
# hal/uart/uart_drv_$(TARGET).o or its symbols would collide.
CFLAGS+=-DDEBUG_UART
else ifeq ($(strip $(UART_TARGET)),)
else
UART_DRV_OBJ:=hal/uart/uart_drv_$(UART_TARGET).o
ifneq ($(wildcard $(UART_DRV_OBJ)),)
@ -1215,7 +1220,7 @@ OBJS+=$(SECURE_OBJS)
ifeq ($(RAM_CODE),1)
ifeq ($(ENCRYPT),1)
ifeq ($(ENCRYPT_WITH_CHACHA),1)
ifneq ($(TARGET),wolfhal)
ifneq ($(WOLFHAL),1)
LSCRIPT_IN=hal/$(TARGET)_chacha_ram.ld
endif
endif

View File

@ -90,7 +90,7 @@ else
APP_OBJS:=app_renesas_rx.o ../test-app/libwolfboot.o ../src/boot_renesas.o ../src/boot_renesas_start.o ../hal/renesas-rx.o
LDFLAGS+=-ffreestanding -nostartfiles
CFLAGS+=-DWOLFBOOT_RENESAS_APP
else ifeq ($(TARGET),wolfhal)
else ifeq ($(WOLFHAL),1)
APP_OBJS:=app_wolfhal.o led.o system.o timer.o ../test-app/libwolfboot.o
else
APP_OBJS:=app_$(TARGET).o led.o system.o timer.o ../test-app/libwolfboot.o
@ -378,7 +378,11 @@ ifeq ($(TZEN),1)
APP_OBJS+=$(sort $(WOLFCRYPT_APP_OBJS))
endif
else
APP_OBJS+=../hal/$(TARGET).o
ifeq ($(WOLFHAL),1)
APP_OBJS+=../hal/wolfhal.o
else
APP_OBJS+=../hal/$(TARGET).o
endif
endif
ifeq ($(ARCH),RISCV)
@ -685,16 +689,17 @@ ifeq ($(QSPI_FLASH),1)
endif
endif
ifeq ($(TARGET),wolfhal)
ifeq ($(WOLFHAL),1)
ifeq ($(strip $(BOARD)),)
$(error TARGET=wolfhal requires BOARD to be set, e.g. BOARD=stm32wb_nucleo)
$(error WOLFHAL=1 requires BOARD to be set, e.g. BOARD=stm32wb_nucleo)
endif
ifeq ($(wildcard $(WOLFBOOT_ROOT)/hal/boards/$(BOARD)/board.mk),)
$(error BOARD=$(BOARD) has no hal/boards/$(BOARD)/board.mk)
endif
WOLFHAL_ROOT?=$(WOLFBOOT_ROOT)/lib/wolfHAL
CFLAGS+=-I$(WOLFHAL_ROOT) -DWHAL_CFG_NO_TIMEOUT -I$(WOLFBOOT_ROOT)/hal/boards/$(BOARD)
DEBUG_UART=1
APP_OBJS+=board_$(BOARD).o
# hal/wolfhal.o is added by the generic ../hal/$(TARGET).o rule below
# when TARGET=wolfhal, so we don't add it explicitly here.
include $(WOLFBOOT_ROOT)/hal/boards/$(BOARD)/board.mk
endif
@ -702,7 +707,11 @@ ifeq ($(UART_FLASH),1)
CFLAGS+=-D"UART_FLASH=1"
APP_OBJS+= ../src/uart_flash.o ../hal/uart/uart_drv_$(UART_TARGET).o
else ifeq ($(TARGET),stm32wb)
APP_OBJS+=../hal/uart/uart_drv_$(UART_TARGET).o
# With WOLFHAL=1, hal/wolfhal.c + the wolfHAL UART driver provide
# uart_write; the legacy driver would collide.
ifneq ($(WOLFHAL),1)
APP_OBJS+=../hal/uart/uart_drv_$(UART_TARGET).o
endif
endif
ifeq ($(TARGET),kinetis)

View File

@ -30,8 +30,6 @@
#include "board.h"
#ifdef TARGET_wolfhal
/* Chip drivers behind the wolfHAL API are singletons (configured via
* board.h). Use the BOARD_*_DEV handles defined there. */
@ -85,5 +83,3 @@ void main(void)
while (1)
__asm__ volatile("wfi");
}
#endif /* TARGET_wolfhal */