Skip to content

Commit 79277d6

Browse files
dgarskedanielinux
authored andcommitted
Progress on expanding STM32WB testing support. Including external SPI/TPM and RSA. Fixes to prevent STM32WB macro collisions with PKA. Makefile improvements for combinations of PKA, SIGN and WOLFTPM.
1 parent 2545574 commit 79277d6

8 files changed

Lines changed: 60 additions & 28 deletions

File tree

Makefile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ OBJS:= \
1818
./src/image.o \
1919
./src/libwolfboot.o
2020
WOLFCRYPT_OBJS:=
21+
PUBLIC_KEY_OBJS:=
2122

2223

2324
## Architecture/CPU configuration
@@ -29,17 +30,16 @@ ifeq ($(SIGN),ECC256)
2930
SIGN_OPTIONS=--ecc256
3031
PRIVATE_KEY=ecc256.der
3132
WOLFCRYPT_OBJS+= \
32-
$(ECC_EXTRA_OBJS) \
3333
$(MATH_OBJS) \
3434
./lib/wolfssl/wolfcrypt/src/ecc.o \
3535
./lib/wolfssl/wolfcrypt/src/memory.o \
3636
./lib/wolfssl/wolfcrypt/src/wc_port.o \
3737
./lib/wolfssl/wolfcrypt/src/sha256.o \
3838
./lib/wolfssl/wolfcrypt/src/hash.o \
39-
./src/ecc256_pub_key.o \
4039
./src/xmalloc_ecc.o
41-
CFLAGS+=-DWOLFBOOT_SIGN_ECC256 -DXMALLOC_USER $(ECC_EXTRA_CFLAGS) \
40+
CFLAGS+=-DWOLFBOOT_SIGN_ECC256 -DXMALLOC_USER \
4241
-Wstack-usage=1024
42+
PUBLIC_KEY_OBJS=./src/ecc256_pub_key.o
4343
endif
4444

4545
ifeq ($(SIGN),ED25519)
@@ -52,8 +52,8 @@ ifeq ($(SIGN),ED25519)
5252
./lib/wolfssl/wolfcrypt/src/sha256.o \
5353
./lib/wolfssl/wolfcrypt/src/hash.o \
5454
./lib/wolfssl/wolfcrypt/src/wolfmath.o \
55-
./lib/wolfssl/wolfcrypt/src/fe_low_mem.o \
56-
./src/ed25519_pub_key.o
55+
./lib/wolfssl/wolfcrypt/src/fe_low_mem.o
56+
PUBLIC_KEY_OBJS=./src/ed25519_pub_key.o
5757
CFLAGS+=-DWOLFBOOT_SIGN_ED25519 -nostdlib -DWOLFSSL_STATIC_MEMORY \
5858
-Wstack-usage=1024
5959
LDFLAGS+=-nostdlib
@@ -71,8 +71,8 @@ ifeq ($(SIGN),RSA2048)
7171
./lib/wolfssl/wolfcrypt/src/sha256.o \
7272
./lib/wolfssl/wolfcrypt/src/asn.o \
7373
./lib/wolfssl/wolfcrypt/src/hash.o \
74-
./src/rsa2048_pub_key.o \
7574
./src/xmalloc_rsa.o
75+
PUBLIC_KEY_OBJS=./src/rsa2048_pub_key.o
7676
CFLAGS+=-DWOLFBOOT_SIGN_RSA2048 -DXMALLOC_USER $(RSA_EXTRA_CFLAGS) \
7777
-Wstack-usage=12288 -DIMAGE_HEADER_SIZE=512
7878
endif
@@ -126,12 +126,18 @@ ifeq ($(VTOR),0)
126126
CFLAGS+=-DNO_VTOR
127127
endif
128128

129+
ifeq ($(PKA),1)
130+
OBJS += $(PKA_EXTRA_OBJS)
131+
CFLAGS+=$(PKA_EXTRA_CFLAGS)
132+
endif
133+
134+
OBJS+=$(PUBLIC_KEY_OBJS)
135+
129136
ifeq ($(WOLFTPM),1)
130137
OBJS += lib/wolfTPM/src/tpm2.o \
131138
lib/wolfTPM/src/tpm2_packet.o \
132139
lib/wolfTPM/src/tpm2_tis.o \
133140
lib/wolfTPM/src/tpm2_wrap.o \
134-
src/ecc256_pub_key.o \
135141
hal/spi/spi_drv_$(SPI_TARGET).o
136142
CFLAGS+=-DWOLFTPM_SLB9670 -DWOLFTPM2_NO_WOLFCRYPT -DSIZEOF_LONG=4 -Ilib/wolfTPM \
137143
-DMAX_COMMAND_SIZE=1024 -DMAX_RESPONSE_SIZE=1024 -DWOLFTPM2_MAX_BUFFER=1500 -DMAX_SESSION_NUM=1 -DMAX_DIGEST_BUFFER=973 \
@@ -141,6 +147,7 @@ else
141147
OBJS+=$(WOLFCRYPT_OBJS)
142148
endif
143149

150+
144151
ASFLAGS:=$(CFLAGS)
145152

146153
all: factory.bin

arch.mk

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ ifeq ($(ARCH),ARM)
2424
ifeq ($(TARGET),samr21)
2525
CORTEX_M0=1
2626
endif
27-
27+
2828
ifeq ($(TARGET),stm32l0)
2929
CORTEX_M0=1
3030
endif
31-
31+
3232
ifeq ($(TARGET),stm32g0)
3333
CORTEX_M0=1
3434
endif
@@ -73,25 +73,25 @@ ifeq ($(ARCH),RISCV)
7373
CROSS_COMPILE:=riscv32-unknown-elf-
7474
CFLAGS+=-fno-builtin-printf -DUSE_M_TIME -g -march=rv32imac -mabi=ilp32 -mcmodel=medany -nostartfiles -DARCH_RISCV
7575
LDFLAGS+=-march=rv32imac -mabi=ilp32 -mcmodel=medany
76-
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
77-
76+
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
77+
7878
# Prune unused functions and data
7979
CFLAGS +=-ffunction-sections -fdata-sections
8080
LDFLAGS+=-Wl,--gc-sections
8181

8282
OBJS+=src/boot_riscv.o src/vector_riscv.o
8383
ARCH_FLASH_OFFSET=0x20010000
8484
endif
85-
86-
85+
86+
8787
ifeq ($(TARGET),kinetis)
8888
CFLAGS+= -I$(KINETIS_DRIVERS)/drivers -I$(KINETIS_DRIVERS) -DCPU_$(KINETIS_CPU) -I$(KINETIS_CMSIS)/Include -DDEBUG_CONSOLE_ASSERT_DISABLE=1
8989
OBJS+= $(KINETIS_DRIVERS)/drivers/fsl_clock.o $(KINETIS_DRIVERS)/drivers/fsl_ftfx_flash.o $(KINETIS_DRIVERS)/drivers/fsl_ftfx_cache.o $(KINETIS_DRIVERS)/drivers/fsl_ftfx_controller.o
9090
## The following lines can be used to enable HW acceleration
9191
ifeq ($(KINETIS_CPU),MK82FN256VLL15)
9292
ifeq ($(PKA),1)
93-
ECC_EXTRA_CFLAGS+=-DFREESCALE_LTC_ECC -DFREESCALE_USE_LTC -DFREESCALE_LTC_TFM
94-
ECC_EXTRA_OBJS+=./lib/wolfssl/wolfcrypt/src/port/nxp/ksdk_port.o $(KINETIS_DRIVERS)/drivers/fsl_ltc.o
93+
PKA_EXTRA_CFLAGS+=-DFREESCALE_LTC_ECC -DFREESCALE_USE_LTC -DFREESCALE_LTC_TFM
94+
PKA_EXTRA_OBJS+=./lib/wolfssl/wolfcrypt/src/port/nxp/ksdk_port.o $(KINETIS_DRIVERS)/drivers/fsl_ltc.o
9595
endif
9696
endif
9797
endif
@@ -114,8 +114,8 @@ endif
114114
ifeq ($(TARGET),stm32wb)
115115
SPI_TARGET=stm32
116116
ifneq ($(PKA),0)
117-
ECC_EXTRA_OBJS+= $(STM32CUBE)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pka.o ./lib/wolfssl/wolfcrypt/src/port/st/stm32.o
118-
ECC_EXTRA_CFLAGS+=-DWOLFSSL_STM32_PKA -I$(STM32CUBE)/Drivers/STM32WBxx_HAL_Driver/Inc \
117+
PKA_EXTRA_OBJS+= $(STM32CUBE)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pka.o ./lib/wolfssl/wolfcrypt/src/port/st/stm32.o
118+
PKA_EXTRA_CFLAGS+=-DWOLFSSL_STM32_PKA -I$(STM32CUBE)/Drivers/STM32WBxx_HAL_Driver/Inc \
119119
-Isrc -I$(STM32CUBE)/Drivers/BSP/P-NUCLEO-WB55.Nucleo/ -I$(STM32CUBE)/Drivers/CMSIS/Device/ST/STM32WBxx/Include \
120120
-I$(STM32CUBE)/Drivers/STM32WBxx_HAL_Driver/Inc/ \
121121
-I$(STM32CUBE)/Drivers/CMSIS/Include \

config/openocd/openocd_stm32f4.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source [find interface/stlink.cfg]
2+
source [find target/stm32f4x.cfg]
3+
$_TARGETNAME configure -event reset-init {
4+
mmw 0xe0042004 0x7 0x0
5+
}
6+
init
7+
reset
8+
halt

config/openocd/openocd_stm32h7.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source [find interface/stlink.cfg]
2+
source [find target/stm32h7x.cfg]
3+
$_CHIPNAME.cpu0 configure -event reset-init {
4+
mmw 0xe0042004 0x7 0x0
5+
}
6+
init
7+
reset
8+
halt

hal/stm32wb.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,24 @@ PKA_HandleTypeDef hpka = { };
3232
#define DMB() __asm__ volatile ("dmb")
3333

3434
/*** RCC ***/
35-
35+
#ifndef RCC_BASE
3636
#define RCC_BASE (0x58000000)
37+
#endif
3738
#define RCC_CR (*(volatile uint32_t *)(RCC_BASE + 0x00))
3839
#define RCC_CFGR (*(volatile uint32_t *)(RCC_BASE + 0x08))
3940
#define RCC_PLLCFGR (*(volatile uint32_t *)(RCC_BASE + 0x0C))
4041

42+
#ifndef WOLFSSL_STM32_PKA
4143
#define RCC_CR_PLLRDY (1 << 25)
4244
#define RCC_CR_PLLON (1 << 24)
43-
#define RCC_CR_MSIRDY (1 << 1)
44-
#define RCC_CR_MSION (1 << 0)
45-
#define RCC_CR_HSIRDY (1 << 10)
46-
#define RCC_CR_HSION (1 << 8)
47-
#define RCC_CR_MSIRANGE_SHIFT 4
48-
#define RCC_CR_MSIRANGE_MASK (0x0F << 4)
49-
#define RCC_CR_MSIRANGE_6 (0x06 << 4)
45+
#define RCC_CR_MSIRDY (1 << 1)
46+
#define RCC_CR_MSION (1 << 0)
47+
#define RCC_CR_HSIRDY (1 << 10)
48+
#define RCC_CR_HSION (1 << 8)
49+
#define RCC_CR_MSIRANGE_SHIFT 4
50+
#define RCC_CR_MSIRANGE_6 (0x06 << 4)
51+
#define RCC_CR_MSIRANGE_Msk (0x0F << 4)
52+
#endif /* !WOLFSSL_STM32_PKA */
5053

5154
#define RCC_CFGR_SW_MSI 0x0
5255
#define RCC_CFGR_SW_PLL 0x3
@@ -78,9 +81,10 @@ PKA_HandleTypeDef hpka = { };
7881

7982
#define RCC_PRESCALER_DIV_NONE 0
8083

81-
8284
/*** FLASH ***/
85+
#ifndef FLASH_BASE
8386
#define FLASH_BASE (0x58004000)
87+
#endif
8488
#define FLASH_ACR (*(volatile uint32_t *)(FLASH_BASE + 0x00))
8589
#define FLASH_KEY (*(volatile uint32_t *)(FLASH_BASE + 0x08))
8690
#define FLASH_SR (*(volatile uint32_t *)(FLASH_BASE + 0x10))
@@ -92,6 +96,7 @@ PKA_HandleTypeDef hpka = { };
9296
/* Register values */
9397
#define FLASH_ACR_LATENCY_MASK (0x07)
9498

99+
#ifndef WOLFSSL_STM32_PKA
95100
#define FLASH_SR_BSY (1 << 16)
96101
#define FLASH_SR_SIZERR (1 << 6)
97102
#define FLASH_SR_PGAERR (1 << 5)
@@ -105,6 +110,8 @@ PKA_HandleTypeDef hpka = { };
105110
#define FLASH_CR_PER (1 << 1)
106111
#define FLASH_CR_PG (1 << 0)
107112

113+
#endif /* !WOLFSSL_STM32_PKA */
114+
108115
#define FLASH_CR_PNB_SHIFT 3
109116
#define FLASH_CR_PNB_MASK 0x3f
110117

@@ -238,7 +245,7 @@ static void clock_pll_on(void)
238245
flash_set_waitstates(flash_waitstates);
239246

240247
/* Configure + enable internal high-speed oscillator. */
241-
RCC_CR = (RCC_CR & (~RCC_CR_MSIRANGE_MASK)) | RCC_CR_MSIRANGE_6;
248+
RCC_CR = (RCC_CR & (~RCC_CR_MSIRANGE_Msk)) | RCC_CR_MSIRANGE_6;
242249
RCC_CR |= RCC_CR_MSION;
243250
DMB();
244251
while ((RCC_CR & RCC_CR_MSIRDY) == 0)

include/spi_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define SPI_DRV_H_INCLUDED
3131

3232
#include <stdint.h>
33+
3334
#if defined(PLATFORM_stm32f4) || defined(PLATFORM_stm32f7) || defined(PLATFORM_stm32wb)
3435
#include "hal/spi/spi_drv_stm32.h"
3536
#endif

include/user_settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
//#define WOLFSSL_SMALL_STACK
3333
#define WOLFCRYPT_ONLY
3434
//#define TFM_TIMING_RESISTANT
35+
#define SIZEOF_LONG_LONG 8
3536

3637
/* ED25519 and SHA512 */
3738
#ifdef WOLFBOOT_SIGN_ED25519

tools/config.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ifeq ($(ARCH),)
88
KINETIS_DRIVERS?=$(KINETIS)/devices/MK64F12
99
KINETIS_CMSIS?=$(KINETIS)/CMSIS
1010
FREEDOM_E_SDK?=$(HOME)/src/freedom-e-sdk
11-
STM32CUBE?=$(HOME)/src/STM32CubeWB/STM32Cube_FW_WB_V1.2.0
11+
STM32CUBE?=$(HOME)/STM32Cube/Repository/STM32Cube_FW_WB_V1.3.0
1212
DEBUG?=0
1313
VTOR?=1
1414
CORTEX_M0?=0

0 commit comments

Comments
 (0)