Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "lib/wolfPSA"]
path = lib/wolfPSA
url = https://github.com/wolfSSL/wolfPSA.git
[submodule "lib/wolfHAL"]
path = lib/wolfHAL
url = https://github.com/wolfSSL/wolfHAL.git
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,23 @@ WOLFBOOT_LIB_WOLFTPM?=lib/wolfTPM
WOLFBOOT_LIB_WOLFPKCS11?=lib/wolfPKCS11
WOLFBOOT_LIB_WOLFPSA?=lib/wolfPSA
WOLFBOOT_LIB_WOLFHSM?=lib/wolfHSM
WOLFBOOT_LIB_WOLFHAL?=lib/wolfHAL

# Convert to absolute paths using abspath function
WOLFBOOT_LIB_WOLFSSL:=$(abspath $(WOLFBOOT_LIB_WOLFSSL))
WOLFBOOT_LIB_WOLFTPM:=$(abspath $(WOLFBOOT_LIB_WOLFTPM))
WOLFBOOT_LIB_WOLFPKCS11:=$(abspath $(WOLFBOOT_LIB_WOLFPKCS11))
WOLFBOOT_LIB_WOLFPSA:=$(abspath $(WOLFBOOT_LIB_WOLFPSA))
WOLFBOOT_LIB_WOLFHSM:=$(abspath $(WOLFBOOT_LIB_WOLFHSM))
WOLFBOOT_LIB_WOLFHAL:=$(abspath $(WOLFBOOT_LIB_WOLFHAL))

# Export variables so they are available to sub-makefiles
export WOLFBOOT_LIB_WOLFSSL
export WOLFBOOT_LIB_WOLFTPM
export WOLFBOOT_LIB_WOLFPKCS11
export WOLFBOOT_LIB_WOLFPSA
export WOLFBOOT_LIB_WOLFHSM
export WOLFBOOT_LIB_WOLFHAL

## Architecture/CPU configuration
include arch.mk
Expand Down Expand Up @@ -227,6 +230,13 @@ ifeq ($(TARGET),stm32h5)
endif
endif # TZEN=1

ifeq ($(TARGET),wolfhal)
LSCRIPT_IN:=hal/$(WOLFHAL_TARGET).ld
CFLAGS+= -I$(WOLFBOOT_LIB_WOLFHAL)
OBJS+=hal/wolfHAL/$(WOLFHAL_BOARD).o
include hal/wolfHAL/$(WOLFHAL_BOARD).mk
endif

ifeq ($(TARGET),x86_64_efi)
MAIN_TARGET:=wolfboot.efi
endif
Expand Down
6 changes: 6 additions & 0 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ ifeq ($(ARCH),ARM)
endif
endif

ifeq ($(TARGET),wolfhal)
ifeq ($(WOLFHAL_TARGET),stm32wb)
ARCH_FLASH_OFFSET=0x08000000
SPI_TARGET=stm32
endif
endif

ifeq ($(TARGET),stm32l5)
CORTEX_M33=1
Expand Down
14 changes: 14 additions & 0 deletions config/examples/stm32wb-wolfhal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
TARGET=wolfhal
SIGN=ECC256
HASH=SHA256
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_SIZE=0x20000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x08010000
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x08028000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x08048000
NVM_FLASH_WRITEONCE=1
PKA=0
WOLFHAL_TARGET=stm32wb
WOLFHAL_BOARD=stm32wb55_nucleo
WOLFHAL_FLASH_START=0x08000000
WOLFHAL_FLASH_SIZE=0x100000
2 changes: 1 addition & 1 deletion config/examples/stm32wb.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SIGN=ECC256
HASH=SHA256
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_SIZE=0x20000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x08008000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x08010000
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x08028000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x08048000
NVM_FLASH_WRITEONCE=1
Expand Down
2 changes: 2 additions & 0 deletions hal/stm32wb.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,5 @@ uint32_t HAL_GetTick(void)
}

#endif

#endif
76 changes: 76 additions & 0 deletions hal/uart/uart_drv_wolfhal.c
Copy link
Member

Choose a reason for hiding this comment

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

inclusion of this in the build should be conditional (default = off)

Copy link
Member Author

Choose a reason for hiding this comment

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

This file should only be compiled in when DEBUG_UART is defined as er arch.mk or if UART_FLASH is defined as per options.mk

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* uart_drv_wolfhal.c
*
* A generic UART driver using the wolfHAL API module.
*
* Copyright (C) 2025 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/

#ifdef TARGET_wolfhal

#include <stdint.h>
#include <wolfHAL/wolfHAL.h>

extern whal_Uart wbUart;

int uart_tx(const uint8_t c)
{
whal_Error err;
err = whal_Uart_Send(&wbUart, &c, 1);
if (err) {
return err;
}
return 1;
}

int uart_rx(uint8_t *c)
{
whal_Error err;
/* ALEX NOTE: this function also returns zero if no data is available... */
Copy link
Member

Choose a reason for hiding this comment

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

a better handling of whal_ return values is required

err = whal_Uart_Recv(&wbUart, c, 1);
if (err) {
return err;
}
return 1;
}

int uart_init(uint32_t bitrate, uint8_t data, char parity, uint8_t stop)
{
/* Handle these configure options in the wolfHAL UART config */
(void)bitrate;
(void)data;
(void)parity;
(void)stop;

whal_Error err;
err = whal_Uart_Init(&wbUart);
if (err) {
return err;
}

return 0;
}

#ifdef DEBUG_UART
void uart_write(const char *buf, unsigned int len)
{
whal_Uart_Send(&wbUart, (uint8_t *)buf, len);
}
#endif

#endif /* TARGET_wolfhal */
107 changes: 107 additions & 0 deletions hal/wolfHAL/stm32wb55_nucleo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <wolfHAL/platform/st/stm32wb55xx.h>

/*
* STM32WB55 Nucleo board configuration for wolfHAL.
*
* This file wires up the board-level clock, flash, GPIO, and optional UART
* instances used by wolfBoot. Most values are board defaults; override with
* build-time defines (e.g., DEBUG_UART/UART_FLASH) as needed.
*/

whal_Clock wbClockController;
whal_Flash wbFlash;

/* Core clock controller (MSI -> PLL -> SYSCLK at 64 MHz). */
whal_Clock wbClockController = {
WHAL_STM32WB55_RCC_PLL_DEVICE,

.cfg = &(whal_StRcc_Cfg) {
.flash = &wbFlash,
.flashLatency = WHAL_ST_FLASH_LATENCY_3,

.sysClkSrc = WHAL_ST_RCC_SYSCLK_SRC_PLL,
.sysClkCfg = &(whal_StRcc_PllClkCfg)
{
.clkSrc = WHAL_ST_RCC_PLLCLK_SRC_MSI,
/* 64 MHz */
.n = 32,
.m = 0,
.r = 1,
.q = 0,
.p = 0,
},
},
};

/* Internal flash mapping used by wolfBoot. */
whal_Flash wbFlash = {
WHAL_STM32WB55_FLASH_DEVICE,

.cfg = &(whal_StFlash_Cfg) {
.clkCtrl = &wbClockController,
.clk = &(whal_StRcc_Clk){WHAL_STM32WB55_FLASH_CLOCK},

.startAddr = 0x08000000,
.size = 0x100000,
},
};

/* GPIO pin configuration: LED on PB5 and optional UART1 pins. */
whal_StGpio_PinCfg pinCfg[] = {
{ /* LED */
.port = WHAL_STGPIO_PORT_B,
.pin = 5,
.mode = WHAL_STGPIO_MODE_OUT,
.outType = WHAL_STGPIO_OUTTYPE_PUSHPULL,
.speed = WHAL_STGPIO_SPEED_LOW,
.pull = WHAL_STGPIO_PULL_UP,
.altFn = 0,
},
#if defined(DEBUG_UART) || defined(UART_FLASH)
{ /* UART1 TX */
.port = WHAL_STGPIO_PORT_B,
.pin = 6,
.mode = WHAL_STGPIO_MODE_ALTFN,
.outType = WHAL_STGPIO_OUTTYPE_PUSHPULL,
.speed = WHAL_STGPIO_SPEED_FAST,
.pull = WHAL_STGPIO_PULL_UP,
.altFn = 7,
},
{ /* UART1 RX */
.port = WHAL_STGPIO_PORT_B,
.pin = 7,
.mode = WHAL_STGPIO_MODE_ALTFN,
.outType = WHAL_STGPIO_OUTTYPE_PUSHPULL,
.speed = WHAL_STGPIO_SPEED_FAST,
.pull = WHAL_STGPIO_PULL_UP,
.altFn = 7,
},
#endif /* DEBUG_UART || UART_FLASH */
};

/* GPIO controller for configured pins. */
whal_Gpio wbGpio = {
WHAL_STM32WB55_GPIO_DEVICE,

.cfg = &(whal_StGpio_Cfg) {
.clkCtrl = &wbClockController,
.clk = &(whal_StRcc_Clk) {WHAL_STM32WB55_GPIOB_CLOCK},

.pinCfg = pinCfg,
.pinCount = sizeof(pinCfg) / sizeof(whal_StGpio_PinCfg),
},
};

#if defined(DEBUG_UART) || defined(UART_FLASH)
/* UART1 configuration for debug/flash operations. */
whal_Uart wbUart = {
WHAL_STM32WB55_UART1_DEVICE,

.cfg = &(whal_StUart_Cfg){
.clkCtrl = &wbClockController,
.clk = &(whal_StRcc_Clk) {WHAL_STM32WB55_UART1_CLOCK},

.baud = 115200,
},
};
#endif /* DEBUG_UART || UART_FLASH */
21 changes: 21 additions & 0 deletions hal/wolfHAL/stm32wb55_nucleo.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CFLAGS += -DWHAL_CFG_NO_CALLBACKS=1

OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/reg.o

OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/clock/st_rcc.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/gpio/st_gpio.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/flash/st_flash.o

ifeq ($(DEBUG_UART),1)
OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/uart/st_uart.o
endif

APP_OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/reg.o

APP_OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/clock/st_rcc.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/gpio/st_gpio.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/flash/st_flash.o

ifeq ($(DEBUG_UART),1)
APP_OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/uart/st_uart.o
endif
72 changes: 72 additions & 0 deletions hal/wolfhal.c
Copy link
Member

Choose a reason for hiding this comment

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

All return values from the underlying whal_ interfaces are discarded. Please propagate failures/errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* stm32wb.c
*
* Copyright (C) 2025 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/

#include <stdint.h>
#include <wolfHAL/wolfHAL.h>
#include "image.h"

extern whal_Clock wbClockController;
extern whal_Gpio wbGpio;
extern whal_Flash wbFlash;
#if defined(DEBUG_UART) || defined(UART_FLASH)
extern whal_Uart wbUart;
#endif /* DEBUG_UART || UART_FLASH */

void hal_init(void)
{
whal_Error err;

err = whal_Clock_Init(&wbClockController);
if (err) {
return;
}

err = whal_Gpio_Init(&wbGpio);
if (err) {
return;
}

err = whal_Flash_Init(&wbFlash);
if (err) {
return;
}

#if defined(DEBUG_UART) || defined(UART_FLASH)
err = whal_Uart_Init(&wbUart);
if (err) {
return;
}
#endif /* DEBUG_UART || UART_FLASH */

}

void hal_prepare_boot(void)
{
#if defined(DEBUG_UART) || defined(UART_FLASH)
whal_Uart_Deinit(&wbUart);
#endif /* DEBUG_UART || UART_FLASH */

whal_Flash_Deinit(&wbFlash);

whal_Gpio_Deinit(&wbGpio);

whal_Clock_Deinit(&wbClockController);
}
Loading
Loading