Adds `factory_wstage1.bin` option to include first stage loader. Fix test-app verbose issue.

pull/301/head
David Garske 2023-04-20 09:46:04 -07:00 committed by Daniele Lacamera
parent 553ec760fd
commit 69ca95eb94
23 changed files with 203 additions and 134 deletions

3
.gitignore vendored
View File

@ -119,3 +119,6 @@ IDE/IAR/Release
build/ build/
CMakeFiles/ CMakeFiles/
CMakeCache.txt CMakeCache.txt
# Stage 1
stage1/loader_stage1.ld

View File

@ -46,6 +46,10 @@ include arch.mk
# Parse config options # Parse config options
include options.mk include options.mk
OBJS+=$(WOLFCRYPT_OBJS)
OBJS+=$(PUBLIC_KEY_OBJS)
OBJS+=$(UPDATE_OBJS)
CFLAGS+= \ CFLAGS+= \
-I"." -I"include/" -I"lib/wolfssl" \ -I"." -I"include/" -I"lib/wolfssl" \
-D"WOLFSSL_USER_SETTINGS" \ -D"WOLFSSL_USER_SETTINGS" \
@ -92,7 +96,7 @@ ifeq ($(TARGET),sim)
endif endif
ifeq ($(TARGET),nxp_p1021) ifeq ($(TARGET),nxp_p1021)
MAIN_TARGET:=loader_stage1.bin factory.bin MAIN_TARGET:=factory_wstage1.bin
endif endif
ASFLAGS:=$(CFLAGS) ASFLAGS:=$(CFLAGS)
@ -100,11 +104,10 @@ BOOTLOADER_PARTITION_SIZE?=$$(( $(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLAS
all: $(MAIN_TARGET) all: $(MAIN_TARGET)
stage1: loader_stage1.bin stage1: stage1/loader_stage1.bin
loader_stage1: loader_stage1.bin stage1/loader_stage1.bin:
loader_stage1.bin:
@echo "\t[BIN] $@" @echo "\t[BIN] $@"
$(Q)$(MAKE) -C stage1 $@ $(Q)$(MAKE) -C $(dir $@) $(notdir $@)
test-lib: $(OBJS) test-lib: $(OBJS)
$(Q)$(CC) $(CFLAGS) -o $@ $^ $(Q)$(CC) $(CFLAGS) -o $@ $^
@ -181,7 +184,15 @@ internal_flash.dd: test-app/image_v1_signed.bin wolfboot.elf $(BINASSEMBLE)
factory.bin: $(BOOT_IMG) wolfboot.bin $(PRIVATE_KEY) test-app/image_v1_signed.bin $(BINASSEMBLE) factory.bin: $(BOOT_IMG) wolfboot.bin $(PRIVATE_KEY) test-app/image_v1_signed.bin $(BINASSEMBLE)
@echo "\t[MERGE] $@" @echo "\t[MERGE] $@"
$(Q)$(BINASSEMBLE) $@ $(WOLFBOOT_ORIGIN) wolfboot.bin \ $(Q)$(BINASSEMBLE) $@ \
$(WOLFBOOT_ORIGIN) wolfboot.bin \
$(WOLFBOOT_PARTITION_BOOT_ADDRESS) test-app/image_v1_signed.bin
factory_wstage1.bin: $(BOOT_IMG) wolfboot.bin $(PRIVATE_KEY) test-app/image_v1_signed.bin $(BINASSEMBLE) stage1/loader_stage1.bin
@echo "\t[MERGE] $@"
$(Q)$(BINASSEMBLE) $@ \
$(WOLFBOOT_STAGE1_FLASH_ADDR) stage1/loader_stage1.bin \
$(WOLFBOOT_ORIGIN) wolfboot.bin \
$(WOLFBOOT_PARTITION_BOOT_ADDRESS) test-app/image_v1_signed.bin $(WOLFBOOT_PARTITION_BOOT_ADDRESS) test-app/image_v1_signed.bin
wolfboot.elf: include/target.h $(OBJS) $(LSCRIPT) FORCE wolfboot.elf: include/target.h $(OBJS) $(LSCRIPT) FORCE
@ -207,6 +218,7 @@ $(LSCRIPT): FORCE
sed -e "s/@WOLFBOOT_PARTITION_SIZE@/$(WOLFBOOT_PARTITION_SIZE)/g" | \ sed -e "s/@WOLFBOOT_PARTITION_SIZE@/$(WOLFBOOT_PARTITION_SIZE)/g" | \
sed -e "s/@WOLFBOOT_PARTITION_UPDATE_ADDRESS@/$(WOLFBOOT_PARTITION_UPDATE_ADDRESS)/g" | \ sed -e "s/@WOLFBOOT_PARTITION_UPDATE_ADDRESS@/$(WOLFBOOT_PARTITION_UPDATE_ADDRESS)/g" | \
sed -e "s/@WOLFBOOT_PARTITION_SWAP_ADDRESS@/$(WOLFBOOT_PARTITION_SWAP_ADDRESS)/g" | \ sed -e "s/@WOLFBOOT_PARTITION_SWAP_ADDRESS@/$(WOLFBOOT_PARTITION_SWAP_ADDRESS)/g" | \
sed -e "s/@WOLFBOOT_STAGE1_SIZE@/$(WOLFBOOT_STAGE1_SIZE)/g" | \
sed -e "s/@WOLFBOOT_STAGE1_LOAD_ADDR@/$(WOLFBOOT_STAGE1_LOAD_ADDR)/g" | \ sed -e "s/@WOLFBOOT_STAGE1_LOAD_ADDR@/$(WOLFBOOT_STAGE1_LOAD_ADDR)/g" | \
sed -e "s/@WOLFBOOT_STAGE1_FLASH_ADDR@/$(WOLFBOOT_STAGE1_FLASH_ADDR)/g" | \ sed -e "s/@WOLFBOOT_STAGE1_FLASH_ADDR@/$(WOLFBOOT_STAGE1_FLASH_ADDR)/g" | \
sed -e "s/@WOLFBOOT_STAGE1_BASE_ADDR@/$(WOLFBOOT_STAGE1_BASE_ADDR)/g" \ sed -e "s/@WOLFBOOT_STAGE1_BASE_ADDR@/$(WOLFBOOT_STAGE1_BASE_ADDR)/g" \

View File

@ -491,3 +491,5 @@ endif
ifeq ($(DEBUG_UART),1) ifeq ($(DEBUG_UART),1)
CFLAGS+=-DDEBUG_UART CFLAGS+=-DDEBUG_UART
endif endif
CFLAGS+=-DWOLFBOOT_ARCH=$(ARCH)

View File

@ -25,6 +25,9 @@ WOLFTPM?=0
# Flash Sector (Block) Size (16KB) # Flash Sector (Block) Size (16KB)
WOLFBOOT_SECTOR_SIZE=0x4000 WOLFBOOT_SECTOR_SIZE=0x4000
# Maximum size of wolfBoot stage 1 loader
WOLFBOOT_STAGE1_SIZE=0x1000
# wolfBoot partition size (128KB) # wolfBoot partition size (128KB)
BOOTLOADER_PARTITION_SIZE=0x20000 BOOTLOADER_PARTITION_SIZE=0x20000
@ -44,7 +47,6 @@ WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x1200000
# Location in Flash for temporary sector used during updates # Location in Flash for temporary sector used during updates
WOLFBOOT_PARTITION_SWAP_ADDRESS?= 0x2200000 WOLFBOOT_PARTITION_SWAP_ADDRESS?= 0x2200000
## Loader Destinations (DDR) ## ## Loader Destinations (DDR) ##
# Address in RAM to load stage 1 loader # Address in RAM to load stage 1 loader

View File

@ -1,8 +1,9 @@
ARCH=PPC ARCH=PPC
TARGET=nxp_t2080 TARGET=nxp_t2080
SIGN?=ED25519 SIGN?=ECC384
HASH?=SHA256 HASH?=SHA384
DEBUG?=1 DEBUG?=0
DEBUG_UART?=1
VTOR?=1 VTOR?=1
CORTEX_M0?=0 CORTEX_M0?=0
NO_ASM?=0 NO_ASM?=0

View File

@ -10,10 +10,13 @@ A first stage loader whose purpose is to load wolfBoot from flash to ram and jum
Example: `make WOLFBOOT_STAGE1_LOAD_ADDR=0x1000 stage1` Example: `make WOLFBOOT_STAGE1_LOAD_ADDR=0x1000 stage1`
* `WOLFBOOT_STAGE1_SIZE`: Maximum size of wolfBoot stage 1 loader
* `WOLFBOOT_STAGE1_FLASH_ADDR`: Location in Flash for stage 1 loader (XIP from boot ROM)
* `WOLFBOOT_STAGE1_BASE_ADDR`: Address in RAM to load stage 1 loader to * `WOLFBOOT_STAGE1_BASE_ADDR`: Address in RAM to load stage 1 loader to
* `WOLFBOOT_STAGE1_LOAD_ADDR`: Address in RAM to load wolfBoot to * `WOLFBOOT_STAGE1_LOAD_ADDR`: Address in RAM to load wolfBoot to
* `WOLFBOOT_LOAD_ADDRESS`: Address in RAM to load application partition * `WOLFBOOT_LOAD_ADDRESS`: Address in RAM to load application partition
## update_ram.c ## update_ram.c
Implementation for RAM based updater Implementation for RAM based updater

View File

@ -1081,22 +1081,27 @@ The NXP QorIQ P1021 is a PPC e500v2 based processor (two cores). This has been t
wolfBoot supports loading from external flash using the eLBC FMC (Flash Machine) with NAND. wolfBoot supports loading from external flash using the eLBC FMC (Flash Machine) with NAND.
When each e500 core comes out of reset, its MMU has one 4-Kbyte page defined at `0x0_FFFF_Fnnn`. For NAND boot the first 4KB is loaded to this region with the first offset jump instruction at `0x0_FFFF_FFFC`. The 4KB is mapped to the FCM buffers. When each e500 core comes out of reset, its MMU has one 4-Kbyte page defined at `0x0_FFFF_Fnnn`. For NAND boot the first 4KB is loaded to this region with the first offset jump instruction at `0x0_FFFF_FFFC`. The 4KB is mapped to the eLBC FCM buffers.
This device defines the default boot ROM address range to be 8 Mbytes at address `0x0_FF80_0000` to `0x0_FFFF_FFFF`. This device defines the default boot ROM address range to be 8 Mbytes at address `0x0_FF80_0000` to `0x0_FFFF_FFFF`.
cfg_rom_loc[0:3] = 1000 Local bus FCM-8-bit NAND flash small page These pin determine if the boot ROM will use small or large flash page:
cfg_rom_loc[0:3] = 1010 Local bus FCM-8-bit NAND flash large page * `cfg_rom_loc[0:3]` = 1000 Local bus FCM-8-bit NAND flash small page
* `cfg_rom_loc[0:3]` = 1010 Local bus FCM-8-bit NAND flash large page
If the boot sequencer is not enabled, the processor cores exit reset and fetches boot code in default configurations. If the boot sequencer is not enabled, the processor cores exit reset and fetches boot code in default configurations.
A loader must reside in the 4KB page to handle early startup including DDR and then load wolfBoot into DDR for execution. A loader must reside in the 4KB page to handle early startup including DDR and then load wolfBoot into DDR for execution.
### First Stage Loader (stage 1) for NXP P1021 PPC
A first stage loader is required to load the wolfBoot image into DDR for execution. This is because only 4KB of code space is available on boot. The stage 1 loader must also copy iteslf from the FCM buffer to DDR (or L2SRAM) to allow using of the eLBC to read NAND blocks.
### Building wolfBoot for NXP P1021 PPC ### Building wolfBoot for NXP P1021 PPC
By default wolfBoot will use `powerpc-linux-gnu-` cross-compiler prefix. These tools can be installed with the Debian package `gcc-powerpc-linux-gnu` (`sudo apt install gcc-powerpc-linux-gnu`). By default wolfBoot will use `powerpc-linux-gnu-` cross-compiler prefix. These tools can be installed with the Debian package `gcc-powerpc-linux-gnu` (`sudo apt install gcc-powerpc-linux-gnu`).
The `make` creates a `factory.bin` image that can be programmed at `0x00000000` The `make` creates a `factory_wstage1.bin` image that can be programmed at `0x00000000`
``` ```
cp ./config/examples/nxp-p1021.config .config cp ./config/examples/nxp-p1021.config .config
@ -1104,6 +1109,16 @@ make keytools
make clean && make make clean && make
``` ```
#### Flash Layout for NXP P1021 PPC (default)
| File | NAND offset |
| ---------------------------- | ----------- |
| stage1/loader_stage1.bin | 0x00000000 |
| wolfboot.bin | 0x00004000 |
| test-app/image_v1_signed.bin | 0x00200000 |
| update | 0x01200000 |
| swap block | 0x02200000 |
## NXP QorIQ T2080 PPC ## NXP QorIQ T2080 PPC

View File

@ -951,23 +951,6 @@ void hal_init(void)
(void)svr; (void)svr;
#endif #endif
#ifdef BUILD_LOADER_STAGE1
#ifdef WOLFBOOT_STAGE1_BASE_ADDR
/* if this is executing from boot 4KB region (FCM buffer) it must
* first be relocated to RAM before the eLBC NAND can be read */
if (((size_t)&hal_init & BOOT_ROM_ADDR) == BOOT_ROM_ADDR) {
__attribute__((noreturn)) void (*wolfboot_start)(void) =
(void*)BOOT_ROM_ADDR + BOOT_ROM_SIZE - 0x04;
/* relocate 4KB code to DST and jump */
memmove((void*)WOLFBOOT_STAGE1_BASE_ADDR, (void*)BOOT_ROM_ADDR,
BOOT_ROM_SIZE);
wolfboot_start(); /* never returns */
}
#endif
#endif
#ifdef ENABLE_PCIE #ifdef ENABLE_PCIE
hal_pcie_init(); hal_pcie_init();
#endif #endif

View File

@ -2,17 +2,17 @@ OUTPUT_ARCH( "powerpc" )
ENTRY( _reset ) ENTRY( _reset )
HEAP_SIZE = 4K; /* heap not used */
STACK_SIZE = 128K;
MEMORY MEMORY
{ {
/* L2 as SRAM (up to 256KB) */
RAM (rwx) : ORIGIN = 0xF8F80000, LENGTH = 64K
/* L1 as SRAM (up to 16KB) */
LRAM (rwx) : ORIGIN = 0xFFD00000, LENGTH = 16K
/* DDR3 - 512MB (offset by destination address and 4KB boot region) */ /* DDR3 - 512MB (offset by destination address and 4KB boot region) */
DRAM (rwx) : ORIGIN = @WOLFBOOT_STAGE1_LOAD_ADDR@, DRAM (rwx) : ORIGIN = @WOLFBOOT_STAGE1_LOAD_ADDR@,
LENGTH = 0x1FFFFFFF - @WOLFBOOT_STAGE1_LOAD_ADDR@ LENGTH = 0x1FFFFFFF - @WOLFBOOT_STAGE1_LOAD_ADDR@
/* L1 as SRAM (up to 16KB) */
RAM (rwx) : ORIGIN = 0xFFD00000, LENGTH = 16K
} }
SECTIONS SECTIONS
@ -77,5 +77,5 @@ SECTIONS
} > DRAM } > DRAM
} }
PROVIDE(_start_heap = ORIGIN(DRAM)); PROVIDE(_start_heap = _end);
PROVIDE(_end_stack = ORIGIN(LRAM) + (LENGTH(LRAM)) ); PROVIDE(_end_stack = _end + HEAP_SIZE + STACK_SIZE );

View File

@ -5,25 +5,21 @@ ENTRY( _reset )
BASE_ADDR = @WOLFBOOT_STAGE1_BASE_ADDR@; BASE_ADDR = @WOLFBOOT_STAGE1_BASE_ADDR@;
/* for flashing to NAND it must be 4KB */ /* for flashing to NAND it must be 4KB */
/* if debugging and running from RAM this can be increased */ LOADER_STAGE1_SIZE = @WOLFBOOT_STAGE1_SIZE@;
MAX_LOADER_SIZE = 0x1000; /* 4KB */
/* Boot initialization code */ /* Boot initialization code */
BOOTSTRAP_TLB = BASE_ADDR; BOOTSTRAP_TLB = BASE_ADDR;
/* Entry point where boot executes from (end of region) */ /* Entry point where boot executes from (end of region) */
BOOTSTRAP_ENTRY = BASE_ADDR + MAX_LOADER_SIZE - 4; BOOTSTRAP_ENTRY = BASE_ADDR + LOADER_STAGE1_SIZE - 4;
MEMORY MEMORY
{ {
/* Boot Location */ /* Boot Location */
FLASH (rx) : ORIGIN = BOOTSTRAP_TLB, LENGTH = MAX_LOADER_SIZE FLASH (rx) : ORIGIN = BOOTSTRAP_TLB, LENGTH = LOADER_STAGE1_SIZE
/* L2 as SRAM (up to 256KB) */
RAM (rwx) : ORIGIN = BASE_ADDR + MAX_LOADER_SIZE, LENGTH = 128K - MAX_LOADER_SIZE
/* L1 as SRAM (up to 16KB) */ /* L1 as SRAM (up to 16KB) */
L1RAM (rwx) : ORIGIN = 0xffd00000, LENGTH = 16K RAM (rwx) : ORIGIN = 0xffd00000, LENGTH = 16K
} }
SECTIONS SECTIONS
@ -84,4 +80,4 @@ SECTIONS
} }
PROVIDE(_start_heap = _end); PROVIDE(_start_heap = _end);
PROVIDE(_end_stack = ORIGIN(L1RAM) + (LENGTH(L1RAM)) ); PROVIDE(_end_stack = ORIGIN(RAM) + (LENGTH(RAM)) );

View File

@ -35,10 +35,6 @@
/* Relocate CCSRBAR */ /* Relocate CCSRBAR */
#define CCSRBAR 0xFFE00000 #define CCSRBAR 0xFFE00000
/* boot address */
#define BOOT_ROM_ADDR 0xFFFFF000UL
#define BOOT_ROM_SIZE (4*1024)
/* Memory used for transferring blocks to/from NAND. /* Memory used for transferring blocks to/from NAND.
* Maps to eLBC FCM internal 8KB region (by hardware) */ * Maps to eLBC FCM internal 8KB region (by hardware) */
#define FLASH_BASE_ADDR 0xFC000000 #define FLASH_BASE_ADDR 0xFC000000
@ -65,6 +61,10 @@
#error Please define MMU version and CCSRBAR for platform #error Please define MMU version and CCSRBAR for platform
#endif #endif
/* boot address */
#define BOOT_ROM_ADDR 0xFFFFF000UL
#define BOOT_ROM_SIZE (4*1024)
#define RESET_VECTOR (BOOT_ROM_ADDR + (BOOT_ROM_SIZE - 4)) #define RESET_VECTOR (BOOT_ROM_ADDR + (BOOT_ROM_SIZE - 4))
#ifndef CCSRBAR_DEF #ifndef CCSRBAR_DEF

View File

@ -34,6 +34,15 @@ extern "C" {
#include "target.h" #include "target.h"
#include "wolfboot/wolfboot.h" #include "wolfboot/wolfboot.h"
#ifdef EXT_FLASH
#include "hal.h"
#endif
#if defined(EXT_ENCRYPTED) && (defined(__WOLFBOOT) || defined(UNIT_TEST))
#include "encrypt.h"
#endif
int wolfBot_get_dts_size(void *dts_addr); int wolfBot_get_dts_size(void *dts_addr);
@ -576,11 +585,9 @@ uint16_t wolfBoot_find_header(uint8_t *haystack, uint16_t type, uint8_t **ptr);
((pn == PART_UPDATE || pn == PART_DTS_UPDATE)?UPDATE_EXT: \ ((pn == PART_UPDATE || pn == PART_DTS_UPDATE)?UPDATE_EXT: \
((pn == PART_SWAP)?SWAP_EXT:0))) ((pn == PART_SWAP)?SWAP_EXT:0)))
# define PART_IS_EXT(x) PARTN_IS_EXT(((x)->part)) # define PART_IS_EXT(x) PARTN_IS_EXT(((x)->part))
#include "hal.h"
#if defined(EXT_ENCRYPTED) && (defined(__WOLFBOOT) || defined(UNIT_TEST)) #if defined(EXT_ENCRYPTED) && (defined(__WOLFBOOT) || defined(UNIT_TEST))
#include "encrypt.h"
#define ext_flash_check_write ext_flash_encrypt_write #define ext_flash_check_write ext_flash_encrypt_write
#define ext_flash_check_read ext_flash_decrypt_read #define ext_flash_check_read ext_flash_decrypt_read
#else #else
@ -588,7 +595,8 @@ uint16_t wolfBoot_find_header(uint8_t *haystack, uint16_t type, uint8_t **ptr);
#define ext_flash_check_read ext_flash_read #define ext_flash_check_read ext_flash_read
#endif #endif
static inline int wb_flash_erase(struct wolfBoot_image *img, uint32_t off, uint32_t size) static inline int wb_flash_erase(struct wolfBoot_image *img, uint32_t off,
uint32_t size)
{ {
if (PART_IS_EXT(img)) if (PART_IS_EXT(img))
return ext_flash_erase((uintptr_t)(img->hdr) + off, size); return ext_flash_erase((uintptr_t)(img->hdr) + off, size);
@ -596,7 +604,8 @@ static inline int wb_flash_erase(struct wolfBoot_image *img, uint32_t off, uint3
return hal_flash_erase((uintptr_t)(img->hdr) + off, size); return hal_flash_erase((uintptr_t)(img->hdr) + off, size);
} }
static inline int wb_flash_write(struct wolfBoot_image *img, uint32_t off, const void *data, uint32_t size) static inline int wb_flash_write(struct wolfBoot_image *img, uint32_t off,
const void *data, uint32_t size)
{ {
if (PART_IS_EXT(img)) if (PART_IS_EXT(img))
return ext_flash_check_write((uintptr_t)(img->hdr) + off, data, size); return ext_flash_check_write((uintptr_t)(img->hdr) + off, data, size);
@ -604,18 +613,22 @@ static inline int wb_flash_write(struct wolfBoot_image *img, uint32_t off, const
return hal_flash_write((uintptr_t)(img->hdr) + off, data, size); return hal_flash_write((uintptr_t)(img->hdr) + off, data, size);
} }
static inline int wb_flash_write_verify_word(struct wolfBoot_image *img, uint32_t off, uint32_t word) static inline int wb_flash_write_verify_word(struct wolfBoot_image *img,
uint32_t off, uint32_t word)
{ {
int ret; int ret;
volatile uint32_t copy; volatile uint32_t copy;
if (PART_IS_EXT(img)) if (PART_IS_EXT(img))
{ {
ext_flash_check_read((uintptr_t)(img->hdr) + off, (void *)&copy, sizeof(uint32_t)); ext_flash_check_read((uintptr_t)(img->hdr) + off, (void *)&copy,
sizeof(uint32_t));
while (copy != word) { while (copy != word) {
ret = ext_flash_check_write((uintptr_t)(img->hdr) + off, (void *)&word, sizeof(uint32_t)); ret = ext_flash_check_write((uintptr_t)(img->hdr) + off,
(void *)&word, sizeof(uint32_t));
if (ret < 0) if (ret < 0)
return ret; return ret;
ext_flash_check_read((uintptr_t)(img->hdr) + off, (void *)&copy, sizeof(uint32_t)); ext_flash_check_read((uintptr_t)(img->hdr) + off, (void *)&copy,
sizeof(uint32_t));
} }
} else { } else {
volatile uint32_t *pcopy = (volatile uint32_t*)(img->hdr + off); volatile uint32_t *pcopy = (volatile uint32_t*)(img->hdr + off);
@ -631,8 +644,10 @@ static inline int wb_flash_write_verify_word(struct wolfBoot_image *img, uint32_
# define PART_IS_EXT(x) (0) # define PART_IS_EXT(x) (0)
# define PARTN_IS_EXT(x) (0) # define PARTN_IS_EXT(x) (0)
# define wb_flash_erase(im, of, siz) hal_flash_erase(((uintptr_t)(((im)->hdr)) + of), siz) # define wb_flash_erase(im, of, siz) \
# define wb_flash_write(im, of, dat, siz) hal_flash_write(((uintptr_t)((im)->hdr)) + of, dat, siz) hal_flash_erase(((uintptr_t)(((im)->hdr)) + of), siz)
# define wb_flash_write(im, of, dat, siz) \
hal_flash_write(((uintptr_t)((im)->hdr)) + of, dat, siz)
#endif /* EXT_FLASH */ #endif /* EXT_FLASH */
@ -645,9 +660,10 @@ static inline int wb_flash_write_verify_word(struct wolfBoot_image *img, uint32_
#define UBOOT_FDT_MAGIC 0xEDFE0DD0UL #define UBOOT_FDT_MAGIC 0xEDFE0DD0UL
#ifndef EXT_ENCRYPTED #ifndef EXT_ENCRYPTED
#define WOLFBOOT_MAX_SPACE (WOLFBOOT_PARTITION_SIZE - (TRAILER_SKIP + sizeof(uint32_t) + (WOLFBOOT_PARTITION_SIZE + 1 / (WOLFBOOT_SECTOR_SIZE * 8)))) #define WOLFBOOT_MAX_SPACE (WOLFBOOT_PARTITION_SIZE - \
(TRAILER_SKIP + sizeof(uint32_t) + \
(WOLFBOOT_PARTITION_SIZE + 1 / (WOLFBOOT_SECTOR_SIZE * 8))))
#else #else
#include "encrypt.h"
#define WOLFBOOT_MAX_SPACE (WOLFBOOT_PARTITION_SIZE - ENCRYPT_TMP_SECRET_OFFSET) #define WOLFBOOT_MAX_SPACE (WOLFBOOT_PARTITION_SIZE - ENCRYPT_TMP_SECRET_OFFSET)
#endif #endif

View File

@ -34,6 +34,12 @@
#define WOLFCRYPT_ONLY #define WOLFCRYPT_ONLY
#define SIZEOF_LONG_LONG 8 #define SIZEOF_LONG_LONG 8
#define CTYPE_USER /* don't let wolfCrypt types.h include ctype.h */
extern int toupper(int c);
extern int tolower(int c);
#define XTOUPPER(c) toupper((c))
#define XTOLOWER(c) tolower((c))
#ifdef USE_FAST_MATH #ifdef USE_FAST_MATH
# define WC_NO_HARDEN # define WC_NO_HARDEN
#endif #endif

View File

@ -376,8 +376,9 @@ else
endif endif
endif endif
ifeq ($(V),0) Q?=@
Q=@ ifeq ($(V),1)
Q=
endif endif
ifeq ($(NO_MPU),1) ifeq ($(NO_MPU),1)
@ -415,9 +416,6 @@ ifeq ($(WOLFBOOT_HUGE_STACK),1)
CFLAGS+=-DWOLFBOOT_HUGE_STACK CFLAGS+=-DWOLFBOOT_HUGE_STACK
endif endif
OBJS+=$(PUBLIC_KEY_OBJS)
OBJS+=$(UPDATE_OBJS)
ifeq ($(WOLFTPM),1) ifeq ($(WOLFTPM),1)
OBJS += lib/wolfTPM/src/tpm2.o \ OBJS += lib/wolfTPM/src/tpm2.o \
lib/wolfTPM/src/tpm2_packet.o \ lib/wolfTPM/src/tpm2_packet.o \
@ -466,7 +464,6 @@ ifeq ($(HASH),SHA3)
endif endif
CFLAGS+=-DIMAGE_HEADER_SIZE=$(IMAGE_HEADER_SIZE) CFLAGS+=-DIMAGE_HEADER_SIZE=$(IMAGE_HEADER_SIZE)
OBJS+=$(WOLFCRYPT_OBJS)
# check if both encryption and self update are on # check if both encryption and self update are on
# #

View File

@ -412,7 +412,7 @@ setup_l2:
stw r4, 0(r6) /* write L2SC0 MMR to flash invalidate L2 cache and locks */ stw r4, 0(r6) /* write L2SC0 MMR to flash invalidate L2 cache and locks */
l2loop: l2loop:
sync sync
lwz r5, 0(6r) /* get current L2SC0 MMR value */ lwz r5, 0(r6) /* get current L2SC0 MMR value */
and. r5, r5, r4 /* compare to mask to see if complete */ and. r5, r5, r4 /* compare to mask to see if complete */
bne l2loop bne l2loop
isync isync

0
src/boot_renesas.c 100755 → 100644
View File

0
src/loader.c 100755 → 100644
View File

View File

@ -37,6 +37,14 @@ size_t strlen(const char *s); /* forward declaration */
#endif #endif
#endif #endif
#if !defined(__IAR_SYSTEMS_ICC__) && !defined(PLATFORM_X86_64_EFI)
/* for RAMFUNCTION */
#include "image.h"
#endif
#if !defined(BUILD_LOADER_STAGE1) || \
(defined(PRINTF_ENABLED) && defined(DEBUG_UART))
int islower(int c) int islower(int c)
{ {
return (c >= 'a' && c <= 'z'); return (c >= 'a' && c <= 'z');
@ -137,16 +145,6 @@ int strncasecmp(const char *s1, const char *s2, size_t n)
return diff; return diff;
} }
size_t strlen(const char *s)
{
size_t i = 0;
while (s[i] != 0)
i++;
return i;
}
char *strncat(char *dest, const char *src, size_t n) char *strncat(char *dest, const char *src, size_t n)
{ {
size_t i = 0; size_t i = 0;
@ -179,22 +177,6 @@ int strncmp(const char *s1, const char *s2, size_t n)
return diff; return diff;
} }
#if !defined(__IAR_SYSTEMS_ICC__) && !defined(PLATFORM_X86_64_EFI)
#include "image.h"
void RAMFUNCTION *memcpy(void *dst, const void *src, size_t n)
{
size_t i;
const char *s = (const char *)src;
char *d = (char *)dst;
for (i = 0; i < n; i++) {
d[i] = s[i];
}
return dst;
}
#endif /* IAR */
char *strncpy(char *dst, const char *src, size_t n) char *strncpy(char *dst, const char *src, size_t n)
{ {
size_t i; size_t i;
@ -222,7 +204,6 @@ char *strcpy(char *dst, const char *src)
return dst; return dst;
} }
int memcmp(const void *_s1, const void *_s2, size_t n) int memcmp(const void *_s1, const void *_s2, size_t n)
{ {
int diff = 0; int diff = 0;
@ -239,6 +220,35 @@ int memcmp(const void *_s1, const void *_s2, size_t n)
return diff; return diff;
} }
#endif /* !BUILD_LOADER_STAGE1 || (PRINTF_ENABLED && DEBUG_UART) */
#if !defined(BUILD_LOADER_STAGE1) || defined(DEBUG_UART)
size_t strlen(const char *s)
{
size_t i = 0;
while (s[i] != 0)
i++;
return i;
}
#endif
#if !defined(__IAR_SYSTEMS_ICC__) && !defined(PLATFORM_X86_64_EFI)
void RAMFUNCTION *memcpy(void *dst, const void *src, size_t n)
{
size_t i;
const char *s = (const char *)src;
char *d = (char *)dst;
for (i = 0; i < n; i++) {
d[i] = s[i];
}
return dst;
}
#endif /* IAR */
#ifndef __IAR_SYSTEMS_ICC__ #ifndef __IAR_SYSTEMS_ICC__
void *memmove(void *dst, const void *src, size_t n) void *memmove(void *dst, const void *src, size_t n)
{ {
@ -258,6 +268,7 @@ void *memmove(void *dst, const void *src, size_t n)
} }
#endif #endif
#if defined(PRINTF_ENABLED) && defined(DEBUG_UART) #if defined(PRINTF_ENABLED) && defined(DEBUG_UART)
void uart_writenum(int num, int base) void uart_writenum(int num, int base)
{ {

20
stage1/Makefile 100755 → 100644
View File

@ -12,7 +12,7 @@ WOLFBOOT_ROOT?=$(PWD)
CFLAGS:=-D"__WOLFBOOT" CFLAGS:=-D"__WOLFBOOT"
CFLAGS+=-Werror -Wextra CFLAGS+=-Werror -Wextra
LDFLAGS:= LDFLAGS:=
LSCRIPT:=../config/loader_stage1.ld LSCRIPT:=loader_stage1.ld
LSCRIPT_IN:=../hal/$(TARGET)_stage1.ld LSCRIPT_IN:=../hal/$(TARGET)_stage1.ld
LSCRIPT_FLAGS:= LSCRIPT_FLAGS:=
LD_START_GROUP:=-Wl,--start-group LD_START_GROUP:=-Wl,--start-group
@ -24,7 +24,7 @@ DEBUG_UART?=0
OBJS:= \ OBJS:= \
./hal/$(TARGET).o \ ./hal/$(TARGET).o \
./src/string.o \ ./src/string.o \
./src/loader_stage1.o loader_stage1.o
WOLFCRYPT_OBJS:= WOLFCRYPT_OBJS:=
PUBLIC_KEY_OBJS:= PUBLIC_KEY_OBJS:=
@ -55,12 +55,21 @@ TARGET_H_TEMPLATE:=../include/target.h.in
ASFLAGS:=$(CFLAGS) ASFLAGS:=$(CFLAGS)
BOOTLOADER_PARTITION_SIZE?=$$(( $(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) BOOTLOADER_PARTITION_SIZE?=$$(( $(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET)))
ifeq ($(WOLFBOOT_STAGE1_SIZE),)
# default is end of 4KB region (0x0FFC)
WOLFBOOT_STAGE1_SIZE=0x1000
endif
CFLAGS+=\ CFLAGS+=\
-DBUILD_LOADER_STAGE1 -DNO_PRINTF_UART \ -DBUILD_LOADER_STAGE1 \
-DWOLFBOOT_STAGE1_SIZE=$(WOLFBOOT_STAGE1_SIZE) \
-DWOLFBOOT_STAGE1_LOAD_ADDR=$(WOLFBOOT_STAGE1_LOAD_ADDR) \ -DWOLFBOOT_STAGE1_LOAD_ADDR=$(WOLFBOOT_STAGE1_LOAD_ADDR) \
-DWOLFBOOT_STAGE1_FLASH_ADDR=$(WOLFBOOT_STAGE1_FLASH_ADDR) \ -DWOLFBOOT_STAGE1_FLASH_ADDR=$(WOLFBOOT_STAGE1_FLASH_ADDR) \
-DWOLFBOOT_STAGE1_BASE_ADDR=$(WOLFBOOT_STAGE1_BASE_ADDR) -DWOLFBOOT_STAGE1_BASE_ADDR=$(WOLFBOOT_STAGE1_BASE_ADDR)
# For printf support (disable NO_PRINTF_UART) and increase WOLFBOOT_STAGE1_SIZE
CFLAGS+=-DNO_PRINTF_UART
BUILD_DIR=. BUILD_DIR=.
LS1_OBJS=$(addprefix $(BUILD_DIR)/, $(notdir $(OBJS))) LS1_OBJS=$(addprefix $(BUILD_DIR)/, $(notdir $(OBJS)))
vpath %.c $(dir ../src) vpath %.c $(dir ../src)
@ -103,6 +112,7 @@ $(LSCRIPT): FORCE
sed -e "s/@WOLFBOOT_PARTITION_SIZE@/$(WOLFBOOT_PARTITION_SIZE)/g" | \ sed -e "s/@WOLFBOOT_PARTITION_SIZE@/$(WOLFBOOT_PARTITION_SIZE)/g" | \
sed -e "s/@WOLFBOOT_PARTITION_UPDATE_ADDRESS@/$(WOLFBOOT_PARTITION_UPDATE_ADDRESS)/g" | \ sed -e "s/@WOLFBOOT_PARTITION_UPDATE_ADDRESS@/$(WOLFBOOT_PARTITION_UPDATE_ADDRESS)/g" | \
sed -e "s/@WOLFBOOT_PARTITION_SWAP_ADDRESS@/$(WOLFBOOT_PARTITION_SWAP_ADDRESS)/g" | \ sed -e "s/@WOLFBOOT_PARTITION_SWAP_ADDRESS@/$(WOLFBOOT_PARTITION_SWAP_ADDRESS)/g" | \
sed -e "s/@WOLFBOOT_STAGE1_SIZE@/$(WOLFBOOT_STAGE1_SIZE)/g" | \
sed -e "s/@WOLFBOOT_STAGE1_LOAD_ADDR@/$(WOLFBOOT_STAGE1_LOAD_ADDR)/g" | \ sed -e "s/@WOLFBOOT_STAGE1_LOAD_ADDR@/$(WOLFBOOT_STAGE1_LOAD_ADDR)/g" | \
sed -e "s/@WOLFBOOT_STAGE1_FLASH_ADDR@/$(WOLFBOOT_STAGE1_FLASH_ADDR)/g" | \ sed -e "s/@WOLFBOOT_STAGE1_FLASH_ADDR@/$(WOLFBOOT_STAGE1_FLASH_ADDR)/g" | \
sed -e "s/@WOLFBOOT_STAGE1_BASE_ADDR@/$(WOLFBOOT_STAGE1_BASE_ADDR)/g" \ sed -e "s/@WOLFBOOT_STAGE1_BASE_ADDR@/$(WOLFBOOT_STAGE1_BASE_ADDR)/g" \
@ -110,7 +120,7 @@ $(LSCRIPT): FORCE
%.hex:%.elf %.hex:%.elf
@echo "\t[ELF2HEX] $@" @echo "\t[ELF2HEX] $@"
@$(OBJCOPY) -O ihex $^ $@ $(Q)@$(OBJCOPY) -O ihex $^ $@
../include/target.h: $(TARGET_H_TEMPLATE) FORCE ../include/target.h: $(TARGET_H_TEMPLATE) FORCE
@cat $(TARGET_H_TEMPLATE) | \ @cat $(TARGET_H_TEMPLATE) | \
@ -150,7 +160,7 @@ $(BUILD_DIR)/%.o: ../hal/%.S
clean: clean:
$(Q)rm -f *.o $(Q)rm -f *.o
$(Q)rm -f loader_stage1.bin loader_stage1.elf loader_stage1.map ../config/loader_stage1.ld $(Q)rm -f loader_stage1.bin loader_stage1.elf loader_stage1.map loader_stage1.ld
FORCE: FORCE:

View File

@ -28,20 +28,29 @@
#include "spi_flash.h" #include "spi_flash.h"
#include "printf.h" #include "printf.h"
#include "wolfboot/wolfboot.h" #include "wolfboot/wolfboot.h"
#include "string.h"
#include <stdint.h>
#ifndef EXT_FLASH #ifndef EXT_FLASH
#error The stage1 loader only supports use with external flash #error The stage1 loader only supports use with external flash
#endif #endif
#ifndef LOADER_STAGE1_SIZE #ifndef WOLFBOOT_STAGE1_SIZE
#define LOADER_STAGE1_SIZE (4*1024) #define WOLFBOOT_STAGE1_SIZE (4*1024)
#endif
#ifndef LOADER_STAGE1_START_ADDR
/* default is end of 4KB region (0x0FFC) */
#define LOADER_STAGE1_START_ADDR \
(WOLFBOOT_STAGE1_LOAD_ADDR + LOADER_STAGE1_SIZE - 0x4)
#endif #endif
#ifndef WOLFBOOT_STAGE1_START_ADDR
/* default is end of 4KB region (0x0FFC) */
#define WOLFBOOT_STAGE1_START_ADDR \
(WOLFBOOT_STAGE1_LOAD_ADDR + WOLFBOOT_STAGE1_SIZE - 0x4)
#endif
#ifdef BUILD_LOADER_STAGE1
#if defined(WOLFBOOT_ARCH) && WOLFBOOT_ARCH == PPC
#include "hal/nxp_ppc.h"
#endif
int main(void) int main(void)
{ {
@ -58,15 +67,31 @@ int main(void)
uart_write("Loader Stage 1\r\n", 16); uart_write("Loader Stage 1\r\n", 16);
#endif #endif
#ifdef BOOT_ROM_ADDR
/* if this is executing from boot 4KB region (FCM buffer) it must
* first be relocated to RAM before the eLBC NAND can be read */
if (((uintptr_t)&hal_init & BOOT_ROM_ADDR) == BOOT_ROM_ADDR) {
wolfboot_start = (void*)WOLFBOOT_STAGE1_BASE_ADDR + BOOT_ROM_SIZE - 0x04;
/* relocate 4KB code to DST and jump */
memmove((void*)WOLFBOOT_STAGE1_BASE_ADDR, (void*)BOOT_ROM_ADDR,
BOOT_ROM_SIZE);
wolfboot_start(); /* never returns */
}
#endif
ret = ext_flash_read( ret = ext_flash_read(
(uintptr_t)WOLFBOOT_ORIGIN, /* flash offset */ (uintptr_t)WOLFBOOT_ORIGIN, /* flash offset */
(uint8_t*)WOLFBOOT_STAGE1_LOAD_ADDR,/* ram destination */ (uint8_t*)WOLFBOOT_STAGE1_LOAD_ADDR,/* ram destination */
BOOTLOADER_PARTITION_SIZE /* boot-loader partition (entire) */ BOOTLOADER_PARTITION_SIZE /* boot-loader partition (entire) */
); );
if (ret >= 0) { if (ret >= 0) {
wolfboot_start = (void*)LOADER_STAGE1_START_ADDR; wolfboot_start = (void*)WOLFBOOT_STAGE1_START_ADDR;
wolfboot_start(); /* never returns */ wolfboot_start(); /* never returns */
} }
return 0; return 0;
} }
#endif /* BUILD_LOADER_STAGE1 */

View File

@ -68,10 +68,6 @@ ifeq ($(ARCH),ARM_BE)
CFLAGS+=-DSTACK_PAINTING=0 CFLAGS+=-DSTACK_PAINTING=0
endif endif
ifeq ($(V),0)
Q=@
endif
ifeq ($(ENCRYPT),1) ifeq ($(ENCRYPT),1)
CFLAGS+=-D"EXT_ENCRYPTED=1" CFLAGS+=-D"EXT_ENCRYPTED=1"
endif endif
@ -264,26 +260,26 @@ standalone:CFLAGS+=-D"TEST_APP_STANDALONE"
standalone:LDFLAGS:=-T standalone.ld -Wl,-gc-sections -Wl,-Map=image.map standalone:LDFLAGS:=-T standalone.ld -Wl,-gc-sections -Wl,-Map=image.map
image.bin: image.elf image.bin: image.elf
$(Q)echo "\t[BIN] $@" @echo "\t[BIN] $@"
$(Q)$(OBJCOPY) --gap-fill $(FILL_BYTE) -O binary $^ $@ $(Q)$(OBJCOPY) --gap-fill $(FILL_BYTE) -O binary $^ $@
image.elf: $(APP_OBJS) $(LSCRIPT) image.elf: $(APP_OBJS) $(LSCRIPT)
$(Q)echo "\t[LD] $@" @echo "\t[LD] $@"
$(Q)$(LD) $(LDFLAGS) $(APP_OBJS) $(OUTPUT_FLAG) $@ $(Q)$(LD) $(LDFLAGS) $(APP_OBJS) $(OUTPUT_FLAG) $@
standalone: image.bin standalone: image.bin
../src/libwolfboot.o: ../src/libwolfboot.c FORCE ../src/libwolfboot.o: ../src/libwolfboot.c FORCE
$(Q)echo "\t[CC-$(ARCH)] $@" @echo "\t[CC-$(ARCH)] $@"
$(Q)$(CC) $(CFLAGS) -c $(OUTPUT_FLAG) $@ ../src/libwolfboot.c $(Q)$(CC) $(CFLAGS) -c $(OUTPUT_FLAG) $@ ../src/libwolfboot.c
%.o:%.c %.o:%.c
$(Q)echo "\t[CC-$(ARCH)] $@" @echo "\t[CC-$(ARCH)] $@"
$(Q)$(CC) $(CFLAGS) -c $(OUTPUT_FLAG) $@ $^ $(Q)$(CC) $(CFLAGS) -c $(OUTPUT_FLAG) $@ $^
%.o:%.S %.o:%.S
$(Q)echo "\t[AS-$(ARCH)] $@" @echo "\t[AS-$(ARCH)] $@"
$(Q)$(CC) $(CFLAGS) -c $(OUTPUT_FLAG) $@ $^ $(Q)$(CC) $(CFLAGS) -c $(OUTPUT_FLAG) $@ $^
clean: clean:

View File

@ -8,11 +8,6 @@ EXE=bin-assemble
LIBS= LIBS=
Q?=@
ifeq ($(V),1)
Q=
endif
$(EXE): $(EXE).o $(EXE): $(EXE).o
$(Q)$(CC) -o $@ $^ $(CFLAGS) $(LIBS) $(Q)$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

View File

@ -4,10 +4,6 @@
CC=gcc CC=gcc
CFLAGS+=-DBUILD_TOOL -Wall -g -ggdb -I../../include -I../../hal -Wextra CFLAGS+=-DBUILD_TOOL -Wall -g -ggdb -I../../include -I../../hal -Wextra
Q?=@
ifeq ($(V),1)
Q=
endif
EXE=ufserver EXE=ufserver