mirror of https://github.com/wolfSSL/wolfBoot.git
Add trustzone example, rework a few things for tz support.
parent
9078ede0fc
commit
27b89f011c
|
|
@ -0,0 +1,46 @@
|
|||
ARCH?=ARM
|
||||
TZEN?=1
|
||||
TARGET?=lpc55s69
|
||||
SIGN?=ECC384
|
||||
HASH?=SHA384
|
||||
MCUXSDK?=1
|
||||
MCUXPRESSO?=$(PWD)/../NXP/mcuxpresso-sdk/mcuxsdk
|
||||
MCUXPRESSO_CMSIS?=$(PWD)/../NXP/CMSIS_5/CMSIS
|
||||
MCUXPRESSO_CPU?=LPC55S69JBD100_cm33_core0
|
||||
MCUXPRESSO_DRIVERS?=$(MCUXPRESSO)/devices/LPC/LPC5500/LPC55S69
|
||||
MCUXPRESSO_PROJECT_TEMPLATE?=$(MCUXPRESSO)/examples/_boards/lpcxpresso55s69/project_template
|
||||
DEBUG?=0
|
||||
DEBUG_UART?=1
|
||||
VTOR?=1
|
||||
CORTEX_M0?=0
|
||||
CORTEX_M33?=1
|
||||
NO_ASM?=0
|
||||
NO_MPU=1
|
||||
EXT_FLASH?=0
|
||||
SPI_FLASH?=0
|
||||
ALLOW_DOWNGRADE?=0
|
||||
NVM_FLASH_WRITEONCE?=1
|
||||
NO_ARM_ASM=1
|
||||
WOLFBOOT_VERSION?=0
|
||||
V?=0
|
||||
SPMATH?=1
|
||||
RAM_CODE?=1
|
||||
DUALBANK_SWAP?=0
|
||||
PKA?=1
|
||||
FLASH_MULTI_SECTOR_ERASE?=1
|
||||
NO_DIRECT_READ_OF_ERASED_SECTOR?=1
|
||||
WOLFCRYPT_TZ?=1
|
||||
WOLFCRYPT_TZ_PKCS11?=1
|
||||
|
||||
# 512-byte pages erasable/writeable
|
||||
WOLFBOOT_SECTOR_SIZE?=0x200
|
||||
|
||||
# 200KB boot, 80KB keyvault, 8KB NSC, 56KB partitions, 512 swap
|
||||
WOLFBOOT_KEYVAULT_ADDRESS?=0x10032000
|
||||
WOLFBOOT_KEYVAULT_SIZE?=0x14000
|
||||
WOLFBOOT_NSC_ADDRESS?=0x10046000
|
||||
WOLFBOOT_NSC_SIZE?=0x2000
|
||||
WOLFBOOT_PARTITION_SIZE?=0xE000
|
||||
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x00048000
|
||||
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x00056000
|
||||
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x00064000
|
||||
|
|
@ -34,7 +34,7 @@ NO_DIRECT_READ_OF_ERASED_SECTOR?=1
|
|||
WOLFBOOT_SECTOR_SIZE?=0x200
|
||||
|
||||
# Default configuration
|
||||
# 32KB boot, 48KB partitions, 512 swap
|
||||
# 40KB boot, 44KB partitions, 512 swap
|
||||
WOLFBOOT_PARTITION_SIZE?=0xB000
|
||||
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xA000
|
||||
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x15000
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = @WOLFBOOT_PARTITION_BOOT_ADDRESS@
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256K
|
||||
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = @BOOTLOADER_PARTITION_SIZE@
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
|
|
|
|||
|
|
@ -48,18 +48,18 @@ static void hal_sau_init(void)
|
|||
sau_init_region(0, WOLFBOOT_NSC_ADDRESS,
|
||||
WOLFBOOT_NSC_ADDRESS + WOLFBOOT_NSC_SIZE - 1, 1);
|
||||
|
||||
/* Non-secure: application flash area (boot partition) */
|
||||
/* Non-secure: application flash area (boot+update partition) */
|
||||
sau_init_region(1, WOLFBOOT_PARTITION_BOOT_ADDRESS,
|
||||
WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE - 1,
|
||||
WOLFBOOT_PARTITION_BOOT_ADDRESS + (WOLFBOOT_PARTITION_SIZE * 2) - 1,
|
||||
0);
|
||||
|
||||
/* Non-secure RAM */
|
||||
sau_init_region(2, 0x20020000, 0x20025FFF, 0);
|
||||
sau_init_region(2, 0x20020000, 0x20027FFF, 0);
|
||||
|
||||
/* Peripherals */
|
||||
sau_init_region(3, 0x40000000, 0x4005FFFF, 0);
|
||||
sau_init_region(4, 0x40080000, 0x400DFFFF, 0);
|
||||
sau_init_region(5, 0x40100000, 0x4013FFFF, 0);
|
||||
sau_init_region(3, 0x40000000, 0x4003FFFF, 0);
|
||||
sau_init_region(4, 0x40080000, 0x400AFFFF, 0);
|
||||
sau_init_region(5, 0x40100000, 0x4010FFFF, 0);
|
||||
|
||||
/* Enable SAU */
|
||||
SAU_CTRL = SAU_INIT_CTRL_ENABLE;
|
||||
|
|
@ -70,13 +70,8 @@ static void hal_sau_init(void)
|
|||
|
||||
static void periph_unsecure(void)
|
||||
{
|
||||
// CLOCK_EnableClock(kCLOCK_Gpio0);
|
||||
// CLOCK_EnableClock(kCLOCK_Gpio1);
|
||||
// CLOCK_EnableClock(kCLOCK_Port0);
|
||||
// CLOCK_EnableClock(kCLOCK_Port1);
|
||||
|
||||
// GPIO_EnablePinControlNonSecure(GPIO0, (1UL << 10) | (1UL << 27));
|
||||
// GPIO_EnablePinControlNonSecure(GPIO1, (1UL << 2) | (1UL << 8) | (1UL << 9));
|
||||
CLOCK_EnableClock(kCLOCK_Iocon);
|
||||
CLOCK_EnableClock(kCLOCK_Gpio1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -96,8 +91,6 @@ void hal_init(void)
|
|||
#if defined(__WOLFBOOT) || !defined(TZEN)
|
||||
memset(&pflash, 0, sizeof(pflash));
|
||||
FLASH_Init(&pflash);
|
||||
// FLASH_GetProperty(&pflash, kFLASH_PropertyPflashSectorSize,
|
||||
// &pflash_sector_size);
|
||||
#endif
|
||||
|
||||
#if defined(TZEN) && !defined(NONSECURE_APP)
|
||||
|
|
@ -153,8 +146,7 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
|
|||
address % pflash_page_size == 0 &&
|
||||
len % pflash_page_size == 0 &&
|
||||
FLASH_Erase(&pflash, address, len, kFLASH_ApiEraseKey)
|
||||
== kStatus_FLASH_Success &&
|
||||
FLASH_VerifyErase(&pflash, address, len) == kStatus_FLASH_Success
|
||||
== kStatus_FLASH_Success
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x10000000, LENGTH = @WOLFBOOT_KEYVAULT_ADDRESS@ - @ARCH_FLASH_OFFSET@
|
||||
RAM (rwx) : ORIGIN = 0x30000000, LENGTH = 0x10000 /* 64K */
|
||||
RAM_HEAP (rwx) : ORIGIN = 0x30010000, LENGTH = 0xC000 /* 48K */
|
||||
RAM_KV (rwx) : ORIGIN = 0x3001C000, LENGTH = 0x2000 /* 8K */
|
||||
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))
|
||||
. = 0x200;
|
||||
*(.keystore*)
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
*(.init*)
|
||||
*(.fini*)
|
||||
. = ALIGN(4);
|
||||
_end_text = .;
|
||||
} > FLASH
|
||||
|
||||
.edidx :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.ARM.exidx*)
|
||||
} > FLASH
|
||||
|
||||
.gnu.sgstubs :
|
||||
{
|
||||
. += 0x400;
|
||||
. = ALIGN(4);
|
||||
*(.gnu.sgstubs*) /* Secure Gateway Stubs */
|
||||
. = ALIGN(4);
|
||||
} > FLASH_NSC
|
||||
|
||||
_stored_data = .;
|
||||
|
||||
.data : AT (_stored_data)
|
||||
{
|
||||
_start_data = .;
|
||||
KEEP(*(.data*))
|
||||
. = ALIGN(4);
|
||||
_end_data = .;
|
||||
} > RAM
|
||||
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
_start_bss = .;
|
||||
__bss_start__ = .;
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_end_bss = .;
|
||||
__bss_end__ = .;
|
||||
_end = .;
|
||||
} > RAM
|
||||
. = ALIGN(4);
|
||||
}
|
||||
|
||||
END_STACK = ORIGIN(RAM) + LENGTH(RAM);
|
||||
|
||||
_keyvault_origin = ORIGIN(RAM_KV);
|
||||
_keyvault_size = LENGTH(RAM_KV);
|
||||
|
||||
_flash_keyvault = ORIGIN(FLASH_KEYVAULT);
|
||||
_flash_keyvault_size = LENGTH(FLASH_KEYVAULT);
|
||||
|
||||
_start_heap = ORIGIN(RAM_HEAP);
|
||||
_heap_size = LENGTH(RAM_HEAP);
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = @WOLFBOOT_TEST_APP_ADDRESS@, LENGTH = @WOLFBOOT_TEST_APP_SIZE@
|
||||
RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 32K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
_start_text = .;
|
||||
KEEP(*(.isr_vector))
|
||||
*(.init)
|
||||
*(.fini)
|
||||
*(.text*)
|
||||
KEEP(*(.rodata*))
|
||||
. = ALIGN(4);
|
||||
_end_text = .;
|
||||
} > FLASH
|
||||
|
||||
.ARM :
|
||||
{
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} > FLASH
|
||||
|
||||
_stored_data = .;
|
||||
|
||||
.data : AT (_stored_data)
|
||||
{
|
||||
_start_data = .;
|
||||
KEEP(*(.data*))
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.ramcode))
|
||||
. = ALIGN(4);
|
||||
_end_data = .;
|
||||
} > RAM
|
||||
|
||||
.bss :
|
||||
{
|
||||
_start_bss = .;
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_end_bss = .;
|
||||
_end = .;
|
||||
} > RAM
|
||||
}
|
||||
|
||||
_wolfboot_partition_boot_address = @WOLFBOOT_PARTITION_BOOT_ADDRESS@;
|
||||
_wolfboot_partition_size = @WOLFBOOT_PARTITION_SIZE@;
|
||||
_wolfboot_partition_update_address = @WOLFBOOT_PARTITION_UPDATE_ADDRESS@;
|
||||
_wolfboot_partition_swap_address = @WOLFBOOT_PARTITION_SWAP_ADDRESS@;
|
||||
|
||||
PROVIDE(_start_heap = _end);
|
||||
PROVIDE(end = _end);
|
||||
PROVIDE(_end_stack = ORIGIN(RAM) + LENGTH(RAM));
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = @WOLFBOOT_TEST_APP_ADDRESS@, LENGTH = @WOLFBOOT_TEST_APP_SIZE@
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256K
|
||||
RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 32K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
|
|
|
|||
|
|
@ -43,16 +43,20 @@ extern void hal_init(void);
|
|||
|
||||
static void leds_init(void)
|
||||
{
|
||||
#ifndef TZEN
|
||||
CLOCK_EnableClock(kCLOCK_Iocon);
|
||||
CLOCK_EnableClock(kCLOCK_Gpio1);
|
||||
#endif
|
||||
|
||||
const gpio_pin_config_t LED_GPIOPIN_config = {
|
||||
.pinDirection = kGPIO_DigitalOutput,
|
||||
.outputLogic = 1U /* off */
|
||||
};
|
||||
GPIO_PinInit(GPIO, 1, 6, &LED_GPIOPIN_config); /* red off */
|
||||
GPIO_PinInit(GPIO, 1, 7, &LED_GPIOPIN_config); /* green off */
|
||||
GPIO_PinInit(GPIO, 1, 4, &LED_GPIOPIN_config); /* blue off */
|
||||
/* red output off */
|
||||
GPIO->SET[1] = 1UL << RED_LED;
|
||||
GPIO->DIR[1] |= 1UL << RED_LED;
|
||||
/* green output off */
|
||||
GPIO->SET[1] = 1UL << GREEN_LED;
|
||||
GPIO->DIR[1] |= 1UL << GREEN_LED;
|
||||
/* blue output off */
|
||||
GPIO->SET[1] = 1UL << BLUE_LED;
|
||||
GPIO->DIR[1] |= 1UL << BLUE_LED;
|
||||
|
||||
const uint32_t LED_PINMUX_CONFIG = (/* Pin is configured as PIO */
|
||||
IOCON_PIO_FUNC0 |
|
||||
|
|
@ -66,58 +70,82 @@ static void leds_init(void)
|
|||
IOCON_PIO_DIGITAL_EN |
|
||||
/* Open drain is disabled */
|
||||
IOCON_PIO_OPENDRAIN_DI);
|
||||
IOCON_PinMuxSet(IOCON, 1, 6, LED_PINMUX_CONFIG); /* red */
|
||||
IOCON_PinMuxSet(IOCON, 1, 7, LED_PINMUX_CONFIG); /* green */
|
||||
IOCON_PinMuxSet(IOCON, 1, 4, LED_PINMUX_CONFIG); /* blue */
|
||||
IOCON_PinMuxSet(IOCON, 1, RED_LED, LED_PINMUX_CONFIG);
|
||||
IOCON_PinMuxSet(IOCON, 1, GREEN_LED, LED_PINMUX_CONFIG);
|
||||
IOCON_PinMuxSet(IOCON, 1, BLUE_LED, LED_PINMUX_CONFIG);
|
||||
}
|
||||
|
||||
static void check_parts(
|
||||
uint32_t *pboot_ver, uint32_t *pupdate_ver,
|
||||
uint8_t *pboot_state, uint8_t *pupdate_state
|
||||
)
|
||||
{
|
||||
#ifdef WOLFCRYPT_SECURE_MODE
|
||||
*pboot_ver = wolfBoot_nsc_current_firmware_version();
|
||||
*pupdate_ver = wolfBoot_nsc_update_firmware_version();
|
||||
if (wolfBoot_nsc_get_partition_state(PART_BOOT, pboot_state) != 0)
|
||||
*pboot_state = IMG_STATE_NEW;
|
||||
if (wolfBoot_nsc_get_partition_state(PART_UPDATE, pupdate_state) != 0)
|
||||
*pupdate_state = IMG_STATE_NEW;
|
||||
#else
|
||||
*pboot_ver = wolfBoot_current_firmware_version();
|
||||
*pupdate_ver = wolfBoot_update_firmware_version();
|
||||
if (wolfBoot_get_partition_state(PART_BOOT, pboot_state) != 0)
|
||||
*pboot_state = IMG_STATE_NEW;
|
||||
if (wolfBoot_get_partition_state(PART_UPDATE, pupdate_state) != 0)
|
||||
*pupdate_state = IMG_STATE_NEW;
|
||||
#endif
|
||||
|
||||
wolfBoot_printf(" boot: ver=0x%lx state=0x%02x\n", *pboot_ver, *pboot_state);
|
||||
wolfBoot_printf(" update: ver=0x%lx state=0x%02x\n", *pupdate_ver, *pupdate_state);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
uint32_t boot_ver;
|
||||
uint32_t boot_ver, update_ver;
|
||||
uint8_t boot_state, update_state;
|
||||
|
||||
hal_init();
|
||||
leds_init();
|
||||
|
||||
#ifdef WOLFCRYPT_SECURE_MODE
|
||||
boot_ver = wolfBoot_nsc_current_firmware_version();
|
||||
#else
|
||||
boot_ver = wolfBoot_current_firmware_version();
|
||||
#endif
|
||||
check_parts(&boot_ver, &update_ver, &boot_state, &update_state);
|
||||
|
||||
wolfBoot_printf("Hello from firmware version %d\n", boot_ver);
|
||||
|
||||
if (boot_ver == 1) {
|
||||
uint32_t update_ver;
|
||||
if (
|
||||
boot_ver != 0 &&
|
||||
(boot_state == IMG_STATE_TESTING || boot_state == IMG_STATE_NEW)
|
||||
)
|
||||
{
|
||||
wolfBoot_printf("Calling wolfBoot_success()\n");
|
||||
#ifdef WOLFCRYPT_SECURE_MODE
|
||||
wolfBoot_nsc_success();
|
||||
#else
|
||||
wolfBoot_success();
|
||||
#endif
|
||||
check_parts(&boot_ver, &update_ver, &boot_state, &update_state);
|
||||
}
|
||||
|
||||
if (boot_ver == 1)
|
||||
{
|
||||
/* blue on */
|
||||
GPIO_PinWrite(GPIO, 1, BLUE_LED, 0);
|
||||
|
||||
#ifdef WOLFCRYPT_SECURE_MODE
|
||||
update_ver = wolfBoot_nsc_update_firmware_version();
|
||||
#else
|
||||
update_ver = wolfBoot_update_firmware_version();
|
||||
#endif
|
||||
|
||||
if (update_ver != 0) {
|
||||
wolfBoot_printf("Update firmware detected, version: 0x%lx\n", update_ver);
|
||||
wolfBoot_printf("Update detected, version: 0x%lx\n", update_ver);
|
||||
wolfBoot_printf("Triggering update...\n");
|
||||
#ifdef WOLFCRYPT_SECURE_MODE
|
||||
wolfBoot_nsc_update_trigger();
|
||||
#else
|
||||
wolfBoot_update_trigger();
|
||||
#endif
|
||||
check_parts(&boot_ver, &update_ver, &boot_state, &update_state);
|
||||
wolfBoot_printf("...done. Reboot to apply.\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* green on */
|
||||
GPIO_PinWrite(GPIO, 1, GREEN_LED, 0);
|
||||
|
||||
#ifdef WOLFCRYPT_SECURE_MODE
|
||||
wolfBoot_nsc_success();
|
||||
#else
|
||||
wolfBoot_success();
|
||||
#endif
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue