Skip to content

Commit 6ccdd68

Browse files
authored
Merge pull request #583 from danielinux/ramcode-bugfixes
Fixed missing long_call attribute, hal erase/write
2 parents b5a7e77 + a8012e8 commit 6ccdd68

File tree

9 files changed

+29
-22
lines changed

9 files changed

+29
-22
lines changed

arch.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ ifeq ($(ARCH),ARM)
243243
LSCRIPT_IN=hal/$(TARGET)-ns.ld
244244
endif
245245
SPI_TARGET=stm32
246+
ifneq ($(DEBUG),0)
247+
CFLAGS+=-DPKCS11_SMALL
248+
endif
249+
246250
endif
247251

248252
ifeq ($(TARGET),rp2350)

hal/stm32_tz.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void hal_tz_sau_init(void)
294294
sau_init_region(1, WOLFBOOT_PARTITION_BOOT_ADDRESS, FLASH_BANK2_BASE - 1, 0);
295295

296296
/* Secure: application flash area (second bank) */
297-
sau_init_region(2, WOLFBOOT_PARTITION_UPDATE_ADDRESS, FLASH_TOP -1, 0);
297+
sau_init_region(2, WOLFBOOT_PARTITION_UPDATE_ADDRESS, FLASH_TOP, 0);
298298

299299
/* Secure RAM regions in SRAM1/SRAM2 */
300300
sau_init_region(3, 0x30000000, 0x3004FFFF, 1);

hal/stm32h5.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,23 @@
2525

2626
#include "hal.h"
2727
#include "hal/stm32h5.h"
28+
#include "hal/armv8m_tz.h"
2829

2930
#define PLL_SRC_HSE 1
3031

3132
#if TZ_SECURE()
33+
34+
/* This function assumes that the boot and the update
35+
* partitions are at the same address in the two banks,
36+
* regardless wheather DUALBANK_SWAP is active or not.
37+
*/
3238
static int is_flash_nonsecure(uint32_t address)
3339
{
3440
uint32_t in_bank_offset = address & 0x000FFFFF;
35-
#ifdef DUALBANK_SWAP
3641
if (in_bank_offset >= (WOLFBOOT_PARTITION_BOOT_ADDRESS - FLASHMEM_ADDRESS_SPACE))
3742
return 1;
3843
else
3944
return 0;
40-
#else
41-
if (address >= WOLFBOOT_PARTITION_BOOT_ADDRESS)
42-
return 1;
43-
else
44-
return 0;
45-
#endif
4645
}
4746
#endif
4847

@@ -101,11 +100,9 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
101100
dst = (uint32_t *)address;
102101

103102
#if (TZ_SECURE())
103+
dst = (uint32_t *)(address | FLASH_SECURE_MMAP_BASE);
104104
if (is_flash_nonsecure(address)) {
105105
hal_tz_claim_nonsecure_area(address, len);
106-
} else if (((uint32_t)dst & 0x0F000000) == 0x08000000) {
107-
/* Convert into secure address space */
108-
dst = (uint32_t *)((address & (~FLASHMEM_ADDRESS_SPACE)) | FLASH_SECURE_MMAP_BASE);
109106
}
110107
#endif
111108
while (i < len) {
@@ -124,6 +121,7 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
124121
FLASH_SR |= FLASH_SR_EOP;
125122
FLASH_CR &= ~FLASH_CR_PG;
126123
i+=8;
124+
DSB();
127125
}
128126
#if (TZ_SECURE())
129127
if (is_flash_nonsecure(address)) {
@@ -201,7 +199,6 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
201199
base = FLASH_BANK2_BASE;
202200
bnksel = 1;
203201
}
204-
205202
#if TZ_SECURE()
206203
/* When in secure mode, skip erasing non-secure pages: will be erased upon claim */
207204
if (is_flash_nonsecure(address)) {

hal/stm32h5.ld

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
MEMORY
22
{
3-
FLASH (rx) : ORIGIN = @WOLFBOOT_ORIGIN@, LENGTH = @BOOTLOADER_PARTITION_SIZE@ - 0x20000
4-
RAM (rwx) : ORIGIN = 0x30000000, LENGTH = 0x30000
3+
FLASH (rx) : ORIGIN = @WOLFBOOT_ORIGIN@, LENGTH = @BOOTLOADER_PARTITION_SIZE@ - 0x1C000
4+
RAM (rwx) : ORIGIN = 0x30000000, LENGTH = 0x20000
55
RAM_KV (rw): ORIGIN = 0x30020000, LENGTH = 0x10000
66
RAM_HEAP (rw): ORIGIN = 0x30030000, LENGTH = 0x10000 /* 64KB Heap for wolfcrypt/PKCS11 */
7-
FLASH_KEYVAULT(rw): ORIGIN = @WOLFBOOT_ORIGIN@ + 0x20000, LENGTH = 0x18000
7+
FLASH_KEYVAULT(rw): ORIGIN = @WOLFBOOT_ORIGIN@ + 0x24000, LENGTH = 0x14000
88
FLASH_NSC(rx): ORIGIN = @WOLFBOOT_ORIGIN@ + 0x38000, LENGTH = 0x8000
99
}
1010

@@ -14,8 +14,8 @@ SECTIONS
1414
{
1515
_start_text = .;
1616
KEEP(*(.isr_vector))
17-
*(.text*)
18-
*(.rodata*)
17+
*(.text*)
18+
*(.rodata*)
1919
. = ALIGN(8);
2020
_end_text = .;
2121
} > FLASH

options.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ ifeq ($(RAM_CODE),1)
769769
LSCRIPT_IN=hal/$(TARGET)_chacha_ram.ld
770770
endif
771771
endif
772+
ifeq ($(ARCH),ARM)
773+
CFLAGS+=-mlong-calls
774+
endif
772775
endif
773776

774777
# Support external encryption cache

src/update_flash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static void RAMFUNCTION wolfBoot_self_update(struct wolfBoot_image *src)
102102
arch_reboot();
103103
}
104104

105-
void wolfBoot_check_self_update(void)
105+
void RAMFUNCTION wolfBoot_check_self_update(void)
106106
{
107107
uint8_t st;
108108
struct wolfBoot_image update;
@@ -237,7 +237,7 @@ static int RAMFUNCTION wolfBoot_copy_sector(struct wolfBoot_image *src,
237237
* new swap
238238
* @return 0 on success, negative value if no swap needed or on error
239239
*/
240-
static int wolfBoot_swap_and_final_erase(int resume)
240+
static int RAMFUNCTION wolfBoot_swap_and_final_erase(int resume)
241241
{
242242
struct wolfBoot_image boot[1];
243243
struct wolfBoot_image update[1];

test-app/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,16 @@ ifeq ($(TARGET),stm32h5)
184184
APP_OBJS+=wcs/wolfcrypt_secure.o
185185
ifeq ($(WOLFCRYPT_TZ),1)
186186
APP_OBJS+=../lib/wolfssl/wolfcrypt/src/logging.o
187-
APP_OBJS+=../lib/wolfssl/wolfcrypt/benchmark/benchmark.o
188187
APP_OBJS+=../lib/wolfssl/wolfcrypt/test/test.o
188+
APP_OBJS+=../lib/wolfssl/wolfcrypt/benchmark/benchmark.o
189189
endif
190190
else
191191
LSCRIPT_TEMPLATE=ARM-stm32h5.ld
192192
endif
193193
CFLAGS+=-DAPP_HAS_SYSTICK
194-
CFLAGS+=-DRAMFUNCTION='__attribute__((used,section(".ramcode")))'
194+
CFLAGS+=-DRAMFUNCTION='__attribute__((used,section(".ramcode"),long_call))'
195195
CFLAGS+=-mcpu=cortex-m33 -ffunction-sections -fdata-sections -fno-common
196+
CFLAGS+=-mlong-calls
196197
LDFLAGS+=-mcpu=cortex-m33
197198
LDFLAGS+=-Wl,-gc-sections -Wl,-Map=image.map
198199
CFLAGS+=-I..

test-app/wcs/user_settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,7 @@ extern int tolower(int c);
143143
#define WOLFSSL_SP_NO_DYN_STACK
144144

145145

146+
struct timespec;
147+
int clock_gettime (unsigned long clock_id, struct timespec *tp);
146148

147149
#endif /* !H_USER_SETTINGS_ */

tools/bin-assemble/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-include ../../options.mk
44

55
CC=gcc
6-
CFLAGS+=-Wall -g -ggdb
6+
CFLAGS=-Wall -g -ggdb
77
EXE=bin-assemble
88

99
LIBS=

0 commit comments

Comments
 (0)