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+=config/wolfHAL/$(WOLFHAL_BOARD).o
include config/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_SIZE=0x100000
WOLFHAL_INIT_HOOKS=1
101 changes: 101 additions & 0 deletions config/wolfHAL/stm32wb55_nucleo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include <wolfHAL/platform/st/stm32wb55xx.h>

whal_StRcc_PeriphClk periphClkEn[] =
Copy link
Member

Choose a reason for hiding this comment

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

static

{
WHAL_ST_RCC_PERIPH_GPIOA,
WHAL_ST_RCC_PERIPH_GPIOB,
WHAL_ST_RCC_PERIPH_LPUART1,
WHAL_ST_RCC_PERIPH_FLASH,
};

whal_Clock wbClock = {
Copy link
Member

Choose a reason for hiding this comment

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

static

WHAL_STM32WB55_RCC_DEVICE,

.cfg = &(whal_StRcc_Cfg){
.sysClkSrc = WHAL_ST_RCC_SYSCLK_SRC_PLL,
.sysClkCfg.pll =
{
.clkSrc = WHAL_ST_RCC_PLLCLK_SRC_MSI,
/* 64 MHz */
.n = 32,
.m = 0,
.r = 1,
.q = 0,
.p = 0,
},
.periphClkEn = periphClkEn,
.periphClkEnCount = sizeof(periphClkEn) / sizeof(whal_StRcc_PeriphClk),
},
};

whal_Gpio wbGpio = {
Copy link
Member

Choose a reason for hiding this comment

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

static

WHAL_STM32WB55_GPIO_DEVICE,

.pinCfg = &(whal_StGpio_Cfg[3]){
{ /* 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,
},
{ /* LPUART1 TX */
.port = WHAL_STGPIO_PORT_A,
.pin = 2,
.mode = WHAL_STGPIO_MODE_ALTFN,
.outType = WHAL_STGPIO_OUTTYPE_PUSHPULL,
.speed = WHAL_STGPIO_SPEED_FAST,
.pull = WHAL_STGPIO_PULL_UP,
.altFn = 8,
},
{ /* LPUART1 RX */
.port = WHAL_STGPIO_PORT_A,
.pin = 3,
.mode = WHAL_STGPIO_MODE_ALTFN,
.outType = WHAL_STGPIO_OUTTYPE_PUSHPULL,
.speed = WHAL_STGPIO_SPEED_FAST,
.pull = WHAL_STGPIO_PULL_UP,
.altFn = 8,
},
},
.pinCount = 3,
};

whal_Uart wbUart = {
Copy link
Member

Choose a reason for hiding this comment

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

static

WHAL_STM32WB55_LPUART1_DEVICE,

.cfg = &(whal_StUart_Cfg){
.baud = 115200,
.sysClk = &wbClock,
},
};

whal_Flash wbFlash = {
Copy link
Member

Choose a reason for hiding this comment

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

static

WHAL_STM32WB55_FLASH_DEVICE,

.cfg = &(whal_StFlash_Cfg) {
.startAddr = 0x08000000,
.size = 0x100000,
},
};

void hal_pre_init()
{
/* The flash read latency needs to be set prior to
* calling whal_Clock_Enable in hal_init() */

whal_StFlash_SetLatencyArgs wbFlashLatency = {
.latency = WHAL_ST_FLASH_LATENCY_3
};
whal_Flash_Cmd(&wbFlash, WHAL_ST_FLASH_CMD_SET_LATENCY, &wbFlashLatency);
}

void hal_post_prepare_boot()
{
whal_StFlash_SetLatencyArgs wbFlashLatency = {
.latency = WHAL_ST_FLASH_LATENCY_0
};
whal_Flash_Cmd(&wbFlash, WHAL_ST_FLASH_CMD_SET_LATENCY, &wbFlashLatency);
}
25 changes: 25 additions & 0 deletions config/wolfHAL/stm32wb55_nucleo.mk
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 st_uart.o should be conditional to config (default is no uart enabled in bootloader)

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/reg.o

OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/clock/clock.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/uart/uart.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/gpio/gpio.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/flash/flash.o


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

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

APP_OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/clock/clock.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/uart/uart.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/gpio/gpio.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/flash/flash.o


APP_OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/clock/st_rcc.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/uart/st_uart.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/gpio/st_gpio.o \
$(WOLFBOOT_LIB_WOLFHAL)/src/flash/st_flash.o
72 changes: 72 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)

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* uart_drv_stm32wb.c
*
* Driver for the back-end of the UART_FLASH module.
*
* Example implementation for stm32WB, using UART1.
*
* Pinout: RX=PB7, TX=PB6 (VCOM port UART1 -> STLINK USB)
*
* 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_Uart_Send(&wbUart, &c, 1);
return 1;
}

int uart_rx(uint8_t *c)
{
whal_Uart_Recv(&wbUart, c, 1);
/* 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

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 1;
}

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 */
89 changes: 89 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,89 @@
/* 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 wbClock;
extern whal_Gpio wbGpio;
extern whal_Uart wbUart;
extern whal_Flash wbFlash;

#ifdef WOLFHAL_INIT_HOOKS
extern void hal_pre_init();
extern void hal_post_prepare_boot();
#endif /* WOLFHAL_INIT_HOOKS */

void RAMFUNCTION hal_flash_unlock(void)
{
whal_Flash_Unlock(&wbFlash,
0, WOLFHAL_FLASH_SIZE);
}

void RAMFUNCTION hal_flash_lock(void)
{
whal_Flash_Lock(&wbFlash,
0, WOLFHAL_FLASH_SIZE);
}

int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
{
whal_Flash_Write(&wbFlash, address, data, len);
return 0;
}

int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
{
if (len == 0)
return -1;

whal_Flash_Erase(&wbFlash, address, len);
return 0;
}

void hal_init(void)
{
#ifdef WOLFHAL_INIT_HOOKS
hal_pre_init();
#endif /* WOLFHAL_INIT_HOOKS */

whal_Clock_Init(&wbClock);
whal_Clock_Enable(&wbClock);

whal_Gpio_Init(&wbGpio);
whal_Uart_Init(&wbUart);
whal_Flash_Init(&wbFlash);
}

void hal_prepare_boot(void)
{
whal_Flash_Deinit(&wbFlash);
whal_Uart_Deinit(&wbUart);
whal_Gpio_Deinit(&wbGpio);

whal_Clock_Disable(&wbClock);
whal_Clock_Deinit(&wbClock);

#ifdef WOLFHAL_INIT_HOOKS
hal_post_prepare_boot();
#endif /* WOLFHAL_INIT_HOOKS */
}
1 change: 1 addition & 0 deletions lib/wolfHAL
Submodule wolfHAL added at 6a463b
8 changes: 8 additions & 0 deletions options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1145,3 +1145,11 @@ endif
ifeq ($(TZEN),1)
CFLAGS+=-DTZEN
endif

ifneq ($(WOLFHAL_FLASH_SIZE),)
CFLAGS+=-DWOLFHAL_FLASH_SIZE=$(WOLFHAL_FLASH_SIZE)
endif

ifeq ($(WOLFHAL_INIT_HOOKS),1)
CFLAGS+=-DWOLFHAL_INIT_HOOKS=$(WOLFHAL_INIT_HOOKS)
endif
7 changes: 7 additions & 0 deletions test-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ else
endif
endif

ifeq ($(TARGET),wolfhal)
WOLFBOOT_LIB_WOLFHAL?=../lib/wolfHAL
CFLAGS += -I$(WOLFBOOT_LIB_WOLFHAL)
APP_OBJS += ../config/wolfHAL/$(WOLFHAL_BOARD).o
include ../config/wolfHAL/$(WOLFHAL_BOARD).mk
endif

include ../arch.mk

# Setup default linker flags
Expand Down
Loading
Loading