mirror of https://github.com/wolfSSL/wolfBoot.git
Keep STM32L5 flash, SRAM and peripherals Secure for a secure application handoff
parent
709faedd94
commit
8ab44fab80
6
Makefile
6
Makefile
|
|
@ -402,7 +402,11 @@ TARGET_H_TEMPLATE:=include/target.h.in
|
|||
ifeq ($(TZEN),1)
|
||||
ifeq ($(TARGET),stm32l5)
|
||||
# Don't build a contiguous image
|
||||
MAIN_TARGET:=wolfboot.bin test-app/image_v1_signed.bin
|
||||
ifeq ($(WOLFBOOT_SECURE_APP),1)
|
||||
MAIN_TARGET:=wolfboot.bin
|
||||
else
|
||||
MAIN_TARGET:=wolfboot.bin test-app/image_v1_signed.bin
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET),stm32u5)
|
||||
|
|
|
|||
3
arch.mk
3
arch.mk
|
|
@ -680,6 +680,9 @@ ifeq ($(ARCH),ARM)
|
|||
ARCH_FLASH_OFFSET=0x08000000
|
||||
ifeq ($(TZEN),1)
|
||||
WOLFBOOT_ORIGIN=0x0C000000
|
||||
ifeq ($(WOLFBOOT_SECURE_APP),1)
|
||||
$(call LSCRIPT_IN_DEFAULT,hal/$(TARGET)-secure-app.ld)
|
||||
endif
|
||||
else
|
||||
WOLFBOOT_ORIGIN=0x08000000
|
||||
$(call LSCRIPT_IN_DEFAULT,hal/$(TARGET)-ns.ld)
|
||||
|
|
|
|||
|
|
@ -317,6 +317,16 @@ void hal_gtzc_init(void)
|
|||
int i;
|
||||
/* One bit in the bitmask: 256B */
|
||||
|
||||
#if defined(WOLFBOOT_SECURE_APP)
|
||||
/* SRAM1 (192 KB) and SRAM2 (64 KB) stay Secure until the secure
|
||||
* application installs its own split. */
|
||||
for (i = 0; i < 24; i++) {
|
||||
SET_GTZC_MPCBBx_S_VCTR(1, i, 0xFFFFFFFF);
|
||||
}
|
||||
for (i = 0; i < 8; i++) {
|
||||
SET_GTZC_MPCBBx_S_VCTR(2, i, 0xFFFFFFFF);
|
||||
}
|
||||
#else
|
||||
/* Configure lower half of total RAM as secure
|
||||
* 0x3000 0000 : 0x3001 FFFF - 128KB
|
||||
*/
|
||||
|
|
@ -337,6 +347,7 @@ void hal_gtzc_init(void)
|
|||
for (i = 0; i < 8; i++) {
|
||||
SET_GTZC_MPCBBx_S_VCTR(2, i, 0x0);
|
||||
}
|
||||
#endif /* WOLFBOOT_SECURE_APP */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -383,6 +394,9 @@ void hal_tz_sau_init(void)
|
|||
sau_init_region(0, WOLFBOOT_NSC_ADDRESS,
|
||||
WOLFBOOT_NSC_ADDRESS + WOLFBOOT_NSC_SIZE - 1, 1);
|
||||
|
||||
/* A secure application is entered Secure and programs its own
|
||||
* Non-secure flash and RAM windows. */
|
||||
#if !defined(WOLFBOOT_SECURE_APP)
|
||||
/* Non-secure: application flash area (boot partition only) */
|
||||
sau_init_region(1, WOLFBOOT_PARTITION_BOOT_ADDRESS,
|
||||
WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - 1,
|
||||
|
|
@ -390,6 +404,7 @@ void hal_tz_sau_init(void)
|
|||
|
||||
/* Non-secure RAM region in SRAM1/SRAM2 */
|
||||
sau_init_region(2, 0x20020000, 0x2003FFFF, 0);
|
||||
#endif
|
||||
|
||||
/* Non-secure: internal peripherals */
|
||||
sau_init_region(3, 0x40000000, 0x4FFFFFFF, 0);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
/* SRAM below 0x30030000 holds the handoff record and the secure app's RAM. */
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = @WOLFBOOT_ORIGIN@, LENGTH = @WOLFBOOT_KEYVAULT_ADDRESS@ - @WOLFBOOT_ORIGIN@
|
||||
RAM (rwx) : ORIGIN = 0x30030000, LENGTH = 0x0000C000
|
||||
RAM_HEAP (rw): ORIGIN = 0x3003C000, LENGTH = 0x4000
|
||||
FLASH_KEYVAULT(rw): ORIGIN = @WOLFBOOT_KEYVAULT_ADDRESS@, LENGTH = @WOLFBOOT_KEYVAULT_SIZE@
|
||||
FLASH_NSC(rx): ORIGIN = @WOLFBOOT_NSC_ADDRESS@, LENGTH = @WOLFBOOT_NSC_SIZE@
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
_start_text = .;
|
||||
KEEP(*(.isr_vector))
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
. = ALIGN(8);
|
||||
_end_text = .;
|
||||
} > FLASH
|
||||
|
||||
.edidx :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.ARM.exidx*)
|
||||
} > FLASH
|
||||
|
||||
/* Data is stored in FLASH, not after the NSC: the boot partition
|
||||
* follows the NSC directly. */
|
||||
.data :
|
||||
{
|
||||
_start_data = .;
|
||||
KEEP(*(.data*))
|
||||
. = ALIGN(8);
|
||||
KEEP(*(.ramcode))
|
||||
. = ALIGN(8);
|
||||
_end_data = .;
|
||||
} > RAM AT > FLASH
|
||||
_stored_data = LOADADDR(.data);
|
||||
|
||||
.gnu.sgstubs ORIGIN(FLASH_NSC) :
|
||||
{
|
||||
. += 0x400;
|
||||
. = ALIGN(4);
|
||||
*(.gnu.sgstubs*) /* Secure Gateway stubs */
|
||||
. = ALIGN(4);
|
||||
} >FLASH_NSC
|
||||
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
_start_bss = .;
|
||||
__bss_start__ = .;
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
. = ALIGN(8);
|
||||
_end_bss = .;
|
||||
__bss_end__ = .;
|
||||
_end = .;
|
||||
} > RAM
|
||||
. = ALIGN(8);
|
||||
}
|
||||
|
||||
END_STACK = ORIGIN(RAM) + LENGTH(RAM);
|
||||
|
||||
_flash_keyvault = ORIGIN(FLASH_KEYVAULT);
|
||||
_flash_keyvault_size = LENGTH(FLASH_KEYVAULT);
|
||||
|
||||
_start_heap = ORIGIN(RAM_HEAP);
|
||||
_heap_size = LENGTH(RAM_HEAP);
|
||||
|
|
@ -276,6 +276,15 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
|
|||
if (len == 0)
|
||||
return -1;
|
||||
|
||||
#if TZ_SECURE() && defined(WOLFBOOT_SECURE_APP)
|
||||
/* Secure-app partitions are linked at the Secure flash alias */
|
||||
if ((address >= FLASH_SECURE_MMAP_BASE) &&
|
||||
(address <= (FLASH_SECURE_MMAP_BASE +
|
||||
(FLASH_TOP - FLASHMEM_ADDRESS_SPACE)))) {
|
||||
address -= (FLASH_SECURE_MMAP_BASE - FLASHMEM_ADDRESS_SPACE);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (address < ARCH_FLASH_OFFSET)
|
||||
return -1;
|
||||
|
||||
|
|
@ -421,7 +430,8 @@ static void clock_pll_on(int powersave)
|
|||
DMB();
|
||||
}
|
||||
|
||||
#if TZ_SECURE()
|
||||
/* A secure application keeps every peripheral Secure across the jump */
|
||||
#if TZ_SECURE() && !defined(WOLFBOOT_SECURE_APP)
|
||||
static void periph_unsecure()
|
||||
{
|
||||
volatile uint32_t reg;
|
||||
|
|
@ -540,7 +550,7 @@ void hal_prepare_boot(void)
|
|||
#ifdef WOLFBOOT_RESTORE_CLOCK
|
||||
clock_pll_off();
|
||||
#endif
|
||||
#if TZ_SECURE()
|
||||
#if TZ_SECURE() && !defined(WOLFBOOT_SECURE_APP)
|
||||
periph_unsecure();
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue