Simulator fixes and support for using MacOS:

* Added simulator support for Mac.
* Fix for simulator to properly assemble wolfboot.bin + signedtestapp + update + swap.
* Fixes for handling 64-bit assigned mmap virtual addresses. Added hal_flash_write and hal_flash_erase support for 64-bit address using uintptr_t. Enabled if platform is 64-bit and `FORCE_32BIT` is not defined
* Fix simulator conflict with src/libwolfboot.o object in test-app.
* Cleanup test-app linker flags.
pull/339/head
David Garske 2023-08-03 14:34:55 -07:00 committed by Daniele Lacamera
parent 95d98645bd
commit 7190392245
33 changed files with 339 additions and 179 deletions

1
.gitignore vendored
View File

@ -93,6 +93,7 @@ include/target.h
.bootloader-partition-size
# Test tools
tools/check_config/check_config
tools/test-expect-version/test-expect-version
tools/test-update-server/server
tools/uart-flash-server/ufserver

View File

@ -175,12 +175,14 @@ test-app/image.elf: wolfboot.elf
$(Q)$(MAKE) -C test-app WOLFBOOT_ROOT="$(WOLFBOOT_ROOT)" image.elf
$(Q)$(SIZE) test-app/image.elf
internal_flash.dd: $(BINASSEMBLE) wolfboot.elf test-app/image_v1_signed.bin
internal_flash.dd: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin
@echo "\t[MERGE] internal_flash.dd"
$(Q)dd if=/dev/zero bs=1 count=$$(($(WOLFBOOT_SECTOR_SIZE))) > /tmp/swap
$(Q)$(BINASSEMBLE) $@ 0 test-app/image_v1_signed.bin \
$(WOLFBOOT_PARTITION_SIZE) /tmp/swap \
$$(($(WOLFBOOT_PARTITION_SIZE)*2)) /tmp/swap
$(Q)$(BINASSEMBLE) $@ \
0 wolfboot.bin \
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) test-app/image_v1_signed.bin \
$$(($(WOLFBOOT_PARTITION_UPDATE_ADDRESS)-$(ARCH_FLASH_OFFSET))) /tmp/swap \
$$(($(WOLFBOOT_PARTITION_SWAP_ADDRESS)-$(ARCH_FLASH_OFFSET))) /tmp/swap
factory.bin: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin
@echo "\t[MERGE] $@"

View File

@ -451,7 +451,7 @@ ifeq ($(USE_GCC),1)
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)gcc
AS=$(CROSS_COMPILE)gcc
OBJCOPY=$(CROSS_COMPILE)objcopy
OBJCOPY?=$(CROSS_COMPILE)objcopy
SIZE=$(CROSS_COMPILE)size
OUTPUT_FLAG=-o
endif
@ -569,7 +569,6 @@ ifeq ($(TARGET),x86_64_efi)
endif
ifeq ($(TARGET),sim)
ARCH_FLASH_OFFSET=0xC0000000
USE_GCC_HEADLESS=0
LD = gcc
UPDATE_OBJS:=src/update_flash.o

View File

@ -6,12 +6,14 @@ WOLFBOOT_SMALL_STACK=1
SPI_FLASH=0
DEBUG=1
DELTA_UPDATES=1
# it should be multiple of system page size
# sizes should be multiple of system page size
WOLFBOOT_PARTITION_SIZE=0x40000
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0xC0020000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
# if on external flash, it should be multiple of system page size
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0xC0060000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xC00A0000
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x60000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xA0000
# required for keytools
WOLFBOOT_FIXED_PARTITIONS=1

View File

@ -5,12 +5,14 @@ HASH?=SHA256
WOLFBOOT_SMALL_STACK=1
SPI_FLASH=0
DEBUG=1
# it should be multiple of system page size
# sizes should be multiple of system page size
WOLFBOOT_PARTITION_SIZE=0x40000
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0xC0020000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
# if on external flash, it should be multiple of system page size
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0xC0060000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xC00A0000
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x60000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xA0000
# required for keytools
WOLFBOOT_FIXED_PARTITIONS=1

View File

@ -9,12 +9,14 @@ ENCRYPT=1
ENCRYPT_WITH_AES128=1
DEBUG=1
DELTA_UPDATES=1
# it should be multiple of system page size
# sizes should be multiple of system page size
WOLFBOOT_PARTITION_SIZE=0x40000
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0xC0020000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
# if on external flash, it should be multiple of system page size
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x00000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x40000
# required for keytools
WOLFBOOT_FIXED_PARTITIONS=1

View File

@ -8,12 +8,14 @@ EXT_FLASH=1
ENCRYPT=1
ENCRYPT_WITH_AES128=1
DEBUG=1
# it should be multiple of system page size
# sizes should be multiple of system page size
WOLFBOOT_PARTITION_SIZE=0x40000
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0xC0020000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
# if on external flash, it should be multiple of system page size
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x00000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x40000
# required for keytools
WOLFBOOT_FIXED_PARTITIONS=1

View File

@ -5,13 +5,15 @@ HASH?=SHA256
WOLFBOOT_SMALL_STACK=1
SPI_FLASH=0
DEBUG=1
# it should be multiple of system page size
NVM_FLASH_WRITEONCE=1
# sizes should be multiple of system page size
WOLFBOOT_PARTITION_SIZE=0x40000
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0xC0020000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
# if on external flash, it should be multiple of system page size
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0xC0060000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xC00A0000
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x60000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xA0000
# required for keytools
WOLFBOOT_FIXED_PARTITIONS=1

View File

@ -6,12 +6,14 @@ WOLFBOOT_SMALL_STACK=1
SPI_FLASH=0
DEBUG=1
SPMATHALL=1
# it should be multiple of system page size
# sizes should be multiple of system page size
WOLFBOOT_PARTITION_SIZE=0x40000
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0xC0020000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
# if on external flash, it should be multiple of system page size
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0xC0060000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xC00A0000
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x60000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xA0000
# required for keytools
WOLFBOOT_FIXED_PARTITIONS=1

View File

@ -0,0 +1,23 @@
ARCH=sim
TARGET=sim
SIGN?=RSA2048
HASH?=SHA256
WOLFBOOT_SMALL_STACK=1
SPI_FLASH=0
DEBUG=1
SIM_TPM=1
WOLFTPM=1
# sizes should be multiple of system page size
WOLFBOOT_PARTITION_SIZE=0x40000
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x80000
# if on external flash, it should be multiple of system page size
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x100000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x180000
# required for keytools
WOLFBOOT_FIXED_PARTITIONS=1
# TPM Logging
# CFLAGS_EXTRA+=-DDEBUG_WOLFTPM -DWOLFTPM_DEBUG_VERBOSE

View File

@ -5,12 +5,14 @@ HASH?=SHA256
WOLFBOOT_SMALL_STACK=1
SPI_FLASH=0
DEBUG=1
# it should be multiple of system page size
# sizes should be multiple of system page size
WOLFBOOT_PARTITION_SIZE=0x40000
WOLFBOOT_SECTOR_SIZE=0x1000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0xC0020000
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x20000
# if on external flash, it should be multiple of system page size
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0xC0060000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xC00A0000
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x60000
WOLFBOOT_PARTITION_SWAP_ADDRESS=0xA0000
# required for keytools
WOLFBOOT_FIXED_PARTITIONS=1

View File

@ -1516,6 +1516,8 @@ make test-sim-internal-flash-with-update
./wolfboot.elf success get_version
```
Note: This also works on Mac OS, but `objcopy` does not exist. Install with `brew install binutils` and make using `OBJCOPY=/usr/local/Cellar//binutils/2.41/bin/objcopy make`.
## Renesas RX72N

View File

@ -532,7 +532,7 @@ void hal_init(void)
#endif
}
int hal_flash_write(uint32_t address, const uint8_t *data, int len)
int hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
(void)address;
(void)data;
@ -541,7 +541,7 @@ int hal_flash_write(uint32_t address, const uint8_t *data, int len)
return 0;
}
int hal_flash_erase(uint32_t address, int len)
int hal_flash_erase(uintptr_t address, int len)
{
(void)address;
(void)len;

View File

@ -114,7 +114,7 @@ void hal_prepare_boot(void)
}
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
int RAMFUNCTION hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
return 0;
}
@ -128,7 +128,7 @@ void RAMFUNCTION hal_flash_lock(void)
}
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
int RAMFUNCTION hal_flash_erase(uintptr_t address, int len)
{
return 0;
}

144
hal/sim.c
View File

@ -19,6 +19,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
/* Note: All logging must use stderr to avoid issue with scripts
* printing version information */
#define _GNU_SOURCE
#include <stdint.h>
#include <string.h>
@ -29,10 +32,17 @@
#include <fcntl.h>
#include <unistd.h>
#ifdef __APPLE__
#include <mach-o/loader.h>
#include <mach-o/nlist.h>
#include <mach-o/dyld.h>
#endif
#include "wolfboot/wolfboot.h"
#include "target.h"
static uint8_t *ram_base;
/* Global pointer to the internal and external flash base */
uint8_t *sim_ram_base;
static uint8_t *flash_base;
uint32_t erasefail_address = 0xFFFFFFFF;
@ -61,7 +71,7 @@ static int mmap_file(const char *path, uint8_t *address, uint8_t** ret_address)
fd = open(path, O_RDWR);
if (fd == -1) {
fprintf(stderr,"can't open %s\n", path);
fprintf(stderr, "can't open %s\n", path);
return -1;
}
@ -70,10 +80,7 @@ static int mmap_file(const char *path, uint8_t *address, uint8_t** ret_address)
if (mmaped_addr == MAP_FAILED)
return -1;
if (address != NULL && mmaped_addr != address) {
munmap(address, st.st_size);
return -1;
}
fprintf(stderr, "Simulator assigned %s to base %p\n", path, mmaped_addr);
*ret_address = mmaped_addr;
@ -96,47 +103,44 @@ void hal_prepare_boot(void)
/* no op */
}
int hal_flash_write(uint32_t address, const uint8_t *data, int len)
int hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
uint8_t *ptr = 0;
/* implicit cast abide compiler warning */
memcpy(ptr + address, data, len);
memcpy((void*)address, data, len);
return 0;
}
int hal_flash_erase(uint32_t address, int len)
int hal_flash_erase(uintptr_t address, int len)
{
uint8_t *ptr = 0;
/* implicit cast abide compiler warning */
fprintf(stderr,"hal_flash_erase addr %x len %d\n", address, len);
fprintf(stderr, "hal_flash_erase addr %p len %d\n", (void*)address, len);
if (address == erasefail_address) {
fprintf(stderr,"POWER FAILURE\n");
fprintf(stderr, "POWER FAILURE\n");
/* Corrupt page */
memset(ptr + address, 0xEE, len);
memset((void*)address, 0xEE, len);
exit(0);
}
memset(ptr + address, 0xff, len);
memset((void*)address, 0xff, len);
return 0;
}
void hal_init(void)
{
int ret;
uint8_t *p;
int i;
ret = mmap_file(INTERNAL_FLASH_FILE,
(uint8_t*)ARCH_FLASH_OFFSET, &p);
(uint8_t*)ARCH_FLASH_OFFSET, &sim_ram_base);
if (ret != 0) {
fprintf(stderr,"failed to load internal flash file\n");
fprintf(stderr, "failed to load internal flash file\n");
exit(-1);
}
#ifdef EXT_FLASH
ret = mmap_file(EXTERNAL_FLASH_FILE, (uint8_t*)ARCH_FLASH_OFFSET + 0x10000000, &flash_base);
ret = mmap_file(EXTERNAL_FLASH_FILE,
(uint8_t*)ARCH_FLASH_OFFSET + 0x10000000, &flash_base);
if (ret != 0) {
fprintf(stderr,"failed to load internal flash file\n");
fprintf(stderr, "failed to load internal flash file\n");
exit(-1);
}
#endif /* EXT_FLASH */
@ -144,7 +148,8 @@ void hal_init(void)
for (i = 1; i < main_argc; i++) {
if (strcmp(main_argv[i], "powerfail") == 0) {
erasefail_address = strtol(main_argv[++i], NULL, 16);
fprintf(stderr,"Set power fail to erase at address %x\n", erasefail_address);
fprintf(stderr, "Set power fail to erase at address %x\n",
erasefail_address);
break;
}
}
@ -160,7 +165,7 @@ void ext_flash_unlock(void)
/* no op */
}
int ext_flash_write(uintptr_t address, const uint8_t *data, int len)
int ext_flash_write(uintptr_t address, const uint8_t *data, int len)
{
memcpy(flash_base + address, data, len);
return 0;
@ -172,35 +177,106 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len)
return len;
}
int ext_flash_erase(uintptr_t address, int len)
int ext_flash_erase(uintptr_t address, int len)
{
memset(flash_base + address, 0xff, len);
return 0;
}
#ifdef __APPLE__
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
/* Find the MachO entry point */
static int find_epc(void *base, struct entry_point_command **entry)
{
struct mach_header_64 *mh;
struct load_command *lc;
int i;
unsigned long text = 0;
*entry = NULL;
mh = (struct mach_header_64*)base;
lc = (struct load_command*)(base + sizeof(struct mach_header_64));
for (i=0; i<(int)mh->ncmds; i++) {
if (lc->cmd == LC_MAIN) { /* 0x80000028 */
*entry = (struct entry_point_command *)lc;
return 1;
}
lc = (struct load_command*)((unsigned long)lc + lc->cmdsize);
}
return 0;
}
#endif
void do_boot(const uint32_t *app_offset)
{
char *envp[1] = {NULL};
int ret;
int fd;
size_t app_size = WOLFBOOT_PARTITION_SIZE - IMAGE_HEADER_SIZE;
fd = memfd_create("test_app", 0);
if (fd == -1) {
fprintf(stderr,"memfd error\n");
#ifdef __APPLE__
typedef int (*main_entry)(int, char**, char**, char**);
NSObjectFileImage fileImage = NULL;
NSModule module = NULL;
NSSymbol symbol = NULL;
void *pSymbolAddress = NULL;
struct entry_point_command *epc;
main_entry main;
uint32_t *app_buf = (uint32_t*)app_offset;
uint32_t typeVal;
/* change to mh_bundle type - workaround to load object */
typeVal = app_buf[3];
if (typeVal != MH_BUNDLE)
app_buf[3] = MH_BUNDLE;
ret = NSCreateObjectFileImageFromMemory(app_buf, app_size, &fileImage);
if (ret != 1 || fileImage == NULL) {
fprintf(stderr, "Error loading object memory!\n");
exit(-1);
}
module = NSLinkModule(fileImage, "module",
(NSLINKMODULE_OPTION_PRIVATE | NSLINKMODULE_OPTION_BINDNOW));
symbol = NSLookupSymbolInModule(module, "__mh_execute_header");
pSymbolAddress = NSAddressOfSymbol(symbol);
if (!find_epc(pSymbolAddress, &epc)) {
fprintf(stderr, "Error finding entry point!\n");
exit(-1);
}
ret = write(fd, app_offset, WOLFBOOT_PARTITION_SIZE - IMAGE_HEADER_SIZE);
if (ret != WOLFBOOT_PARTITION_SIZE - IMAGE_HEADER_SIZE) {
fprintf(stderr,"can't write test-app to memfd\n");
/* restore mh_bundle type to allow hash to remain valid */
app_buf[3] = typeVal;
main = (main_entry)(void*)(pSymbolAddress + epc->entryoff);
main(main_argc, main_argv, NULL, NULL);
#else
char *envp[1] = {NULL};
int fd = memfd_create("test_app", 0);
if (fd == -1) {
fprintf(stderr, "memfd error\n");
exit(-1);
}
if ((size_t)write(fd, app_offset, app_size) != app_size) {
fprintf(stderr, "can't write test-app to memfd\n");
exit(-1);
}
ret = fexecve(fd, main_argv, envp);
fprintf(stderr,"fexecve error\n");
fprintf(stderr, "fexecve error\n");
#endif
exit(1);
}
#ifdef __APPLE__
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif
int wolfBoot_fallback_is_possible(void)
{
return 0;

View File

@ -52,7 +52,7 @@ static EFI_HANDLE *gImageHandle;
EFI_PHYSICAL_ADDRESS kernel_addr;
EFI_PHYSICAL_ADDRESS update_addr;
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
int RAMFUNCTION hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
return 0;
}
@ -65,7 +65,7 @@ void RAMFUNCTION hal_flash_lock(void)
{
}
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
int RAMFUNCTION hal_flash_erase(uintptr_t address, int len)
{
return 0;
}

View File

@ -63,7 +63,7 @@ void hal_prepare_boot(void)
}
#endif
int hal_flash_write(uint32_t address, const uint8_t *data, int len)
int hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
return 0;
}
@ -76,7 +76,7 @@ void hal_flash_lock(void)
{
}
int hal_flash_erase(uint32_t address, int len)
int hal_flash_erase(uintptr_t address, int len)
{
return 0;
}

View File

@ -40,7 +40,7 @@ void hal_prepare_boot(void)
}
#endif
int hal_flash_write(uint32_t address, const uint8_t *data, int len)
int hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
return 0;
}
@ -53,7 +53,7 @@ void hal_flash_lock(void)
{
}
int hal_flash_erase(uint32_t address, int len)
int hal_flash_erase(uintptr_t address, int len)
{
return 0;
}

View File

@ -1168,7 +1168,7 @@ void hal_prepare_boot(void)
}
/* Flash functions must be relocated to RAM for execution */
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
int RAMFUNCTION hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
return 0;
}
@ -1182,7 +1182,7 @@ void RAMFUNCTION hal_flash_lock(void)
}
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
int RAMFUNCTION hal_flash_erase(uintptr_t address, int len)
{
return 0;
}

View File

@ -46,8 +46,13 @@ void hal_deinit();
#endif
void hal_init(void);
#if !defined(FORCE_32BIT) && INTPTR_MAX == INT64_MAX /* 64-bit platform */
int hal_flash_write(uintptr_t address, const uint8_t *data, int len);
int hal_flash_erase(uintptr_t address, int len);
#else
int hal_flash_write(uint32_t address, const uint8_t *data, int len);
int hal_flash_erase(uint32_t address, int len);
#endif
void hal_flash_unlock(void);
void hal_flash_lock(void);
void hal_prepare_boot(void);

View File

@ -27,10 +27,12 @@
#if defined(DEBUG_ZYNQ) && !defined(PRINTF_ENABLED)
# define PRINTF_ENABLED
#endif
#if defined(WOLFBOOT_DEBUG_EFI) && !defined(PRINTF_ENABLED)
# define PRINTF_ENABLED
#endif
#if defined(ARCH_SIM) && !defined(PRINTF_ENABLED)
# define PRINTF_ENABLED
#endif
#if defined(DEBUG_UART)
void uart_write(const char* buf, unsigned int sz);

View File

@ -36,6 +36,15 @@
#ifdef WOLFBOOT_FIXED_PARTITIONS
#ifdef ARCH_SIM
#include <stdint.h>
/* use runtime ram base for simulator */
extern uint8_t *sim_ram_base;
#undef ARCH_FLASH_OFFSET
#define ARCH_FLASH_OFFSET ((size_t)sim_ram_base)
#define WOLFBOOT_PART_USE_ARCH_OFFSET
#endif
#ifdef PULL_LINKER_DEFINES
#include <stdint.h>
@ -51,21 +60,41 @@
static const uint32_t WOLFBOOT_PARTITION_UPDATE_ADDRESS = (uint32_t)_wolfboot_partition_update_address;
static const uint32_t WOLFBOOT_PARTITION_SWAP_ADDRESS = (uint32_t)_wolfboot_partition_swap_address;
#else
#if defined(WOLFBOOT_PART_USE_ARCH_OFFSET)
#if !defined(EXT_FLASH) || (defined(EXT_FLASH) && !defined(PART_BOOT_EXT))
#define WOLFBOOT_PARTITION_BOOT_ADDRESS (ARCH_FLASH_OFFSET + @WOLFBOOT_PARTITION_BOOT_ADDRESS@)
#endif
#if !defined(EXT_FLASH) || (defined(EXT_FLASH) && !defined(PART_UPDATE_EXT))
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS (ARCH_FLASH_OFFSET + @WOLFBOOT_PARTITION_UPDATE_ADDRESS@)
#endif
#if !defined(EXT_FLASH) || (defined(EXT_FLASH) && !defined(PART_SWAP_EXT))
#define WOLFBOOT_PARTITION_SWAP_ADDRESS (ARCH_FLASH_OFFSET + @WOLFBOOT_PARTITION_SWAP_ADDRESS@)
#endif
#endif
/* use values provided on input template parsing */
#define WOLFBOOT_PARTITION_BOOT_ADDRESS @WOLFBOOT_PARTITION_BOOT_ADDRESS@
#define WOLFBOOT_PARTITION_SIZE @WOLFBOOT_PARTITION_SIZE@
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS @WOLFBOOT_PARTITION_UPDATE_ADDRESS@
#define WOLFBOOT_PARTITION_SWAP_ADDRESS @WOLFBOOT_PARTITION_SWAP_ADDRESS@
#ifndef WOLFBOOT_PARTITION_BOOT_ADDRESS
#define WOLFBOOT_PARTITION_BOOT_ADDRESS @WOLFBOOT_PARTITION_BOOT_ADDRESS@
#endif
#ifndef WOLFBOOT_PARTITION_UPDATE_ADDRESS
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS @WOLFBOOT_PARTITION_UPDATE_ADDRESS@
#endif
#ifndef WOLFBOOT_PARTITION_SWAP_ADDRESS
#define WOLFBOOT_PARTITION_SWAP_ADDRESS @WOLFBOOT_PARTITION_SWAP_ADDRESS@
#endif
#ifndef WOLFBOOT_PARTITION_SIZE
#define WOLFBOOT_PARTITION_SIZE @WOLFBOOT_PARTITION_SIZE@
#endif
#endif
#define WOLFBOOT_DTS_BOOT_ADDRESS @WOLFBOOT_DTS_BOOT_ADDRESS@
#define WOLFBOOT_DTS_UPDATE_ADDRESS @WOLFBOOT_DTS_UPDATE_ADDRESS@
#define WOLFBOOT_DTS_BOOT_ADDRESS @WOLFBOOT_DTS_BOOT_ADDRESS@
#define WOLFBOOT_DTS_UPDATE_ADDRESS @WOLFBOOT_DTS_UPDATE_ADDRESS@
#endif /* WOLFBOOT_FIXED_PARTITIONS */
/* Load address in RAM for staged OS (update_ram only) */
#define WOLFBOOT_LOAD_ADDRESS @WOLFBOOT_LOAD_ADDRESS@
#define WOLFBOOT_LOAD_DTS_ADDRESS @WOLFBOOT_LOAD_DTS_ADDRESS@
#define WOLFBOOT_LOAD_ADDRESS @WOLFBOOT_LOAD_ADDRESS@
#define WOLFBOOT_LOAD_DTS_ADDRESS @WOLFBOOT_LOAD_DTS_ADDRESS@
#endif /* !H_TARGETS_TARGET_ */

View File

@ -177,6 +177,7 @@ ifeq ($(SIGN),RSA2048)
./lib/wolfssl/wolfcrypt/src/rsa.o \
./lib/wolfssl/wolfcrypt/src/asn.o \
./lib/wolfssl/wolfcrypt/src/hash.o \
./lib/wolfssl/wolfcrypt/src/wolfmath.o \
./lib/wolfssl/wolfcrypt/src/wc_port.o
CFLAGS+=-D"WOLFBOOT_SIGN_RSA2048" $(RSA_EXTRA_CFLAGS)
ifeq ($(WOLFBOOT_SMALL_STACK),1)
@ -210,6 +211,7 @@ ifeq ($(SIGN),RSA3072)
./lib/wolfssl/wolfcrypt/src/rsa.o \
./lib/wolfssl/wolfcrypt/src/asn.o \
./lib/wolfssl/wolfcrypt/src/hash.o \
./lib/wolfssl/wolfcrypt/src/wolfmath.o \
./lib/wolfssl/wolfcrypt/src/wc_port.o
CFLAGS+=-D"WOLFBOOT_SIGN_RSA3072" $(RSA_EXTRA_CFLAGS)
ifeq ($(WOLFBOOT_SMALL_STACK),1)
@ -246,6 +248,7 @@ ifeq ($(SIGN),RSA4096)
./lib/wolfssl/wolfcrypt/src/rsa.o \
./lib/wolfssl/wolfcrypt/src/asn.o \
./lib/wolfssl/wolfcrypt/src/hash.o \
./lib/wolfssl/wolfcrypt/src/wolfmath.o \
./lib/wolfssl/wolfcrypt/src/wc_port.o
CFLAGS+=-D"WOLFBOOT_SIGN_RSA4096" $(RSA_EXTRA_CFLAGS)
ifeq ($(WOLFBOOT_SMALL_STACK),1)

View File

@ -152,7 +152,7 @@ static int nvm_cached_sector = 0;
static int nvm_select_fresh_sector(int part)
{
int sel;
uint32_t off;
uintptr_t off;
uint8_t *base;
uint8_t *addr_align;
@ -201,10 +201,11 @@ static int nvm_select_fresh_sector(int part)
return sel;
}
static int RAMFUNCTION trailer_write(uint8_t part, uint32_t addr, uint8_t val) {
size_t addr_align = (size_t)(addr & (~(NVM_CACHE_SIZE - 1)));
size_t addr_read, addr_write;
uint32_t addr_off = addr & (NVM_CACHE_SIZE - 1);
static int RAMFUNCTION trailer_write(uint8_t part, uintptr_t addr, uint8_t val)
{
uintptr_t addr_align = (size_t)(addr & (~(NVM_CACHE_SIZE - 1)));
uintptr_t addr_read, addr_write;
uintptr_t addr_off = addr & (NVM_CACHE_SIZE - 1);
int ret = 0;
nvm_cached_sector = nvm_select_fresh_sector(part);
@ -238,11 +239,11 @@ static int RAMFUNCTION trailer_write(uint8_t part, uint32_t addr, uint8_t val) {
return ret;
}
static int RAMFUNCTION partition_magic_write(uint8_t part, uint32_t addr)
static int RAMFUNCTION partition_magic_write(uint8_t part, uintptr_t addr)
{
uint32_t off = addr % NVM_CACHE_SIZE;
size_t base = (size_t)addr - off;
size_t addr_read, addr_write;
uintptr_t off = addr % NVM_CACHE_SIZE;
uintptr_t base = (uintptr_t)addr - off;
uintptr_t addr_read, addr_write;
int ret;
nvm_cached_sector = nvm_select_fresh_sector(part);
addr_read = base - (nvm_cached_sector * NVM_CACHE_SIZE);
@ -265,6 +266,7 @@ static int RAMFUNCTION partition_magic_write(uint8_t part, uint32_t addr)
static uint8_t* RAMFUNCTION get_trailer_at(uint8_t part, uint32_t at)
{
uint8_t *ret = NULL;
uint32_t sel_sec = 0;
#ifdef NVM_FLASH_WRITEONCE
sel_sec = nvm_select_fresh_sector(part);
@ -273,9 +275,9 @@ static uint8_t* RAMFUNCTION get_trailer_at(uint8_t part, uint32_t at)
if (FLAGS_BOOT_EXT()){
ext_flash_check_read(PART_BOOT_ENDFLAGS - (sizeof(uint32_t) + at),
(void *)&ext_cache, sizeof(uint32_t));
return (uint8_t *)&ext_cache;
ret = (uint8_t *)&ext_cache;
} else {
return (void *)(PART_BOOT_ENDFLAGS -
ret = (void *)(PART_BOOT_ENDFLAGS -
(WOLFBOOT_SECTOR_SIZE * sel_sec + (sizeof(uint32_t) + at)));
}
}
@ -283,13 +285,13 @@ static uint8_t* RAMFUNCTION get_trailer_at(uint8_t part, uint32_t at)
if (FLAGS_UPDATE_EXT()) {
ext_flash_check_read(PART_UPDATE_ENDFLAGS - (sizeof(uint32_t) + at),
(void *)&ext_cache, sizeof(uint32_t));
return (uint8_t *)&ext_cache;
ret = (uint8_t *)&ext_cache;
} else {
return (void *)(PART_UPDATE_ENDFLAGS -
ret = (void *)(PART_UPDATE_ENDFLAGS -
(WOLFBOOT_SECTOR_SIZE * sel_sec + (sizeof(uint32_t) + at)));
}
} else
return NULL;
}
return ret;
}
static void RAMFUNCTION set_trailer_at(uint8_t part, uint32_t at, uint8_t val)
@ -354,20 +356,20 @@ static void RAMFUNCTION set_partition_magic(uint8_t part)
#else
static uint8_t* RAMFUNCTION get_trailer_at(uint8_t part, uint32_t at)
{
uint8_t *ret = NULL;
uint32_t sel_sec = 0;
#ifdef NVM_FLASH_WRITEONCE
sel_sec = nvm_select_fresh_sector(part);
#endif
if (part == PART_BOOT) {
return (void *)(PART_BOOT_ENDFLAGS -
ret = (void *)(PART_BOOT_ENDFLAGS -
(WOLFBOOT_SECTOR_SIZE * sel_sec + (sizeof(uint32_t) + at)));
}
else if (part == PART_UPDATE) {
return (void *)(PART_UPDATE_ENDFLAGS -
ret = (void *)(PART_UPDATE_ENDFLAGS -
(WOLFBOOT_SECTOR_SIZE * sel_sec + (sizeof(uint32_t) + at)));
}
return NULL;
return ret;
}
static void RAMFUNCTION set_trailer_at(uint8_t part, uint32_t at, uint8_t val)
@ -383,7 +385,7 @@ static void RAMFUNCTION set_trailer_at(uint8_t part, uint32_t at, uint8_t val)
static void RAMFUNCTION set_partition_magic(uint8_t part)
{
if (part == PART_BOOT) {
partition_magic_write(part, (uint32_t)(PART_BOOT_ENDFLAGS - sizeof(uint32_t)));
partition_magic_write(part, PART_BOOT_ENDFLAGS - sizeof(uint32_t));
}
else if (part == PART_UPDATE) {
partition_magic_write(part, PART_UPDATE_ENDFLAGS - sizeof(uint32_t));
@ -489,15 +491,15 @@ void RAMFUNCTION wolfBoot_erase_partition(uint8_t part)
int size = 0;
if (part == PART_BOOT) {
address = WOLFBOOT_PARTITION_BOOT_ADDRESS;
address = (uint32_t)WOLFBOOT_PARTITION_BOOT_ADDRESS;
size = WOLFBOOT_PARTITION_SIZE;
}
if (part == PART_UPDATE) {
address = WOLFBOOT_PARTITION_UPDATE_ADDRESS;
address = (uint32_t)WOLFBOOT_PARTITION_UPDATE_ADDRESS;
size = WOLFBOOT_PARTITION_SIZE;
}
if (part == PART_SWAP) {
address = WOLFBOOT_PARTITION_SWAP_ADDRESS;
address = (uint32_t)WOLFBOOT_PARTITION_SWAP_ADDRESS;
size = WOLFBOOT_SECTOR_SIZE;
}
@ -939,7 +941,7 @@ static uint8_t ENCRYPT_KEY[ENCRYPT_KEY_SIZE + ENCRYPT_NONCE_SIZE];
static int RAMFUNCTION hal_set_key(const uint8_t *k, const uint8_t *nonce)
{
uint32_t addr, addr_align, addr_off;
uintptr_t addr, addr_align, addr_off;
int ret = 0;
int sel_sec = 0;
#ifdef MMU
@ -950,10 +952,10 @@ static int RAMFUNCTION hal_set_key(const uint8_t *k, const uint8_t *nonce)
addr = ENCRYPT_TMP_SECRET_OFFSET + WOLFBOOT_PARTITION_BOOT_ADDRESS;
addr_align = addr & (~(WOLFBOOT_SECTOR_SIZE - 1));
addr_off = addr & (WOLFBOOT_SECTOR_SIZE - 1);
#ifdef NVM_FLASH_WRITEONCE
sel_sec = nvm_select_fresh_sector(PART_BOOT);
addr_align -= (sel_sec * WOLFBOOT_SECTOR_SIZE);
#endif
#ifdef NVM_FLASH_WRITEONCE
sel_sec = nvm_select_fresh_sector(PART_BOOT);
addr_align -= (sel_sec * WOLFBOOT_SECTOR_SIZE);
#endif
hal_flash_unlock();
/* casting to unsigned long to abide compilers on 64bit architectures */
XMEMCPY(ENCRYPT_CACHE,
@ -1131,14 +1133,18 @@ static uint8_t RAMFUNCTION part_address(uintptr_t a)
{
#ifdef WOLFBOOT_FIXED_PARTITIONS
if ( 1 &&
#if WOLFBOOT_PARTITION_UPDATE_ADDRESS != 0
#if !defined(WOLFBOOT_PART_USE_ARCH_OFFSET) && !defined(PULL_LINKER_DEFINES)
#if WOLFBOOT_PARTITION_UPDATE_ADDRESS != 0
(a >= WOLFBOOT_PARTITION_UPDATE_ADDRESS) &&
#endif
#endif
(a < WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE))
return PART_UPDATE;
if ( 1 &&
#if WOLFBOOT_PARTITION_SWAP_ADDRESS != 0
#if !defined(WOLFBOOT_PART_USE_ARCH_OFFSET) && !defined(PULL_LINKER_DEFINES)
#if WOLFBOOT_PARTITION_SWAP_ADDRESS != 0
(a >= WOLFBOOT_PARTITION_SWAP_ADDRESS) &&
#endif
#endif
(a < WOLFBOOT_PARTITION_SWAP_ADDRESS + WOLFBOOT_SECTOR_SIZE))
return PART_SWAP;

View File

@ -22,6 +22,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifdef __APPLE__
#define _FORTIFY_SOURCE 0
#endif
#include <stddef.h>
#ifndef PLATFORM_library

View File

@ -57,8 +57,8 @@ static void RAMFUNCTION wolfBoot_erase_bootloader(void)
static void RAMFUNCTION wolfBoot_self_update(struct wolfBoot_image *src)
{
uint32_t pos = 0;
uint32_t src_offset = IMAGE_HEADER_SIZE;
uintptr_t pos = 0;
uintptr_t src_offset = IMAGE_HEADER_SIZE;
hal_flash_unlock();
wolfBoot_erase_bootloader();
@ -67,8 +67,8 @@ static void RAMFUNCTION wolfBoot_self_update(struct wolfBoot_image *src)
while (pos < src->fw_size) {
uint8_t buffer[FLASHBUFFER_SIZE];
if (src_offset + pos < (src->fw_size + IMAGE_HEADER_SIZE + FLASHBUFFER_SIZE)) {
uint32_t opos = pos + ((uint32_t)&_start_text);
ext_flash_check_read((uintptr_t)(src->hdr) + src_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
uintptr_t opos = pos + ((uintptr_t)&_start_text);
ext_flash_check_read((uintptr_t)(src->hdr) + src_offset + pos, (void*)buffer, FLASHBUFFER_SIZE);
hal_flash_write(opos, buffer, FLASHBUFFER_SIZE);
}
pos += FLASHBUFFER_SIZE;
@ -79,7 +79,7 @@ static void RAMFUNCTION wolfBoot_self_update(struct wolfBoot_image *src)
while (pos < src->fw_size) {
if (src_offset + pos < (src->fw_size + IMAGE_HEADER_SIZE + FLASHBUFFER_SIZE)) {
uint8_t *orig = (uint8_t*)(src->hdr + src_offset + pos);
hal_flash_write(pos + (uint32_t)&_start_text, orig, FLASHBUFFER_SIZE);
hal_flash_write(pos + (uintptr_t)&_start_text, orig, FLASHBUFFER_SIZE);
}
pos += FLASHBUFFER_SIZE;
}
@ -414,7 +414,7 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed)
}
PART_SANITY_CHECK(&update);
#ifndef ALLOW_DOWNGRADE
if ( ((fallback_allowed==1) &&
if ( ((fallback_allowed==1) &&
(~(uint32_t)fallback_allowed == 0xFFFFFFFE)) ||
(wolfBoot_current_firmware_version() <
wolfBoot_update_firmware_version()) ) {

View File

@ -6,11 +6,6 @@ TARGET?=none
ARCH?=ARM
MCUXPRESSO_CMSIS?=$(MCUXPRESSO)/CMSIS
ifeq ($(TARGET),sim)
LDFLAGS=-Wl,-gc-sections -Wl,-Map=image.map
endif
ifeq ($(SIGN),RSA2048)
IMAGE_HEADER_SIZE:=512
endif
@ -35,16 +30,19 @@ endif
ifeq ($(TARGET),ti_hercules)
APP_OBJS:=app_$(TARGET).o ../src/libwolfboot.o
APP_OBJS:=app_$(TARGET).o ../test-app/libwolfboot.o
CFLAGS+=-I"../include"
else
CFLAGS+=-g -ggdb -Wall -Wstack-usage=1024 -ffreestanding -Wno-unused -DPLATFORM_$(TARGET) -I../include -nostartfiles
APP_OBJS:=app_$(TARGET).o led.o system.o timer.o ../src/libwolfboot.o
APP_OBJS:=app_$(TARGET).o led.o system.o timer.o ../test-app/libwolfboot.o
endif
include ../arch.mk
# Setup default linker flags
LDFLAGS=-T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=image.map
ifeq ($(DEBUG_UART),1)
APP_OBJS+=../src/string.o
endif
@ -114,17 +112,16 @@ ifeq ($(TARGET),stm32u5)
LDFLAGS+=-mcpu=cortex-m33
endif
ifeq ($(TARGET),ti_hercules)
LSCRIPT_TEMPLATE=ARM-r5be.ld
LDFLAGS+=$(LSCRIPT) --map_file=image.map
else
LDFLAGS+=-T $(LSCRIPT) -Wl,-gc-sections -Wl,-Map=image.map
# Override linker flags
LDFLAGS=$(LSCRIPT) --map_file=image.map
endif
ifeq ($(TARGET),sim)
LDFLAGS=-Wl,-gc-sections -Wl,-Map=image.map
APP_OBJS=app_$(TARGET).o ../src/libwolfboot.o ../hal/$(TARGET).o
APP_OBJS=app_$(TARGET).o ../test-app/libwolfboot.o ../hal/$(TARGET).o
# Override linker flags
LDFLAGS=
endif
ifeq ($(EXT_FLASH),1)
@ -270,7 +267,7 @@ image.elf: $(APP_OBJS) $(LSCRIPT)
standalone: image.bin
../src/libwolfboot.o: ../src/libwolfboot.c FORCE
../test-app/libwolfboot.o: ../src/libwolfboot.c FORCE
@echo "\t[CC-$(ARCH)] $@"
$(Q)$(CC) $(CFLAGS) -c $(OUTPUT_FLAG) $@ ../src/libwolfboot.c

View File

@ -1,6 +1,6 @@
/* unit-parser.c
/* check_config.c
*
* Unit test for parser functions in libwolfboot.c
* Show configuration
*
*
* Copyright (C) 2021 wolfSSL Inc.
@ -32,11 +32,11 @@ static int locked = 0;
void hal_init(void)
{
}
int hal_flash_write(uint32_t address, const uint8_t *data, int len)
int hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
return 0;
}
int hal_flash_erase(uint32_t address, int len)
int hal_flash_erase(uintptr_t address, int len)
{
return 0;
}
@ -102,5 +102,4 @@ int main(void)
);
#endif
return 0;
}

View File

@ -4,8 +4,8 @@ tools/keytools/sign --ecc256 --sha256 bzImage wolfboot_signing_private_key.der 8
tools/keytools/sign --ecc256 --sha256 bzImage wolfboot_signing_private_key.der 2
cp base-part-image app.bin
dd if=bzImage_v8_signed.bin of=app.bin bs=1K seek=1024 conv=notrunc
dd if=bzImage_v2_signed.bin of=app.bin bs=1K seek=17408 conv=notrunc
dd if=bzImage_v8_signed.bin of=app.bin bs=1k seek=1024 conv=notrunc
dd if=bzImage_v2_signed.bin of=app.bin bs=1k seek=17408 conv=notrunc

View File

@ -28,42 +28,38 @@ else
endif
endif
# Make sign algorithm argument
ifeq ($(SIGN),NONE)
SIGN_ARGS+=--no-sign
SIGN_ARGS+=--no-sign
endif
ifeq ($(SIGN),ED25519)
SIGN_ARGS+= --ed25519
SIGN_ARGS+= --ed25519
endif
ifeq ($(SIGN),ED448)
SIGN_ARGS+= --ed448
SIGN_ARGS+= --ed448
endif
ifeq ($(SIGN),ECC256)
SIGN_ARGS+= --ecc256
SIGN_ARGS+= --ecc256
endif
ifeq ($(SIGN),RSA2048)
SIGN_ARGS+= --rsa2048
SIGN_ARGS+= --rsa2048
endif
ifeq ($(SIGN),RSA3072)
SIGN_ARGS+= --rsa3072
SIGN_ARGS+= --rsa3072
endif
ifeq ($(SIGN),RSA4096)
SIGN_ARGS+= --rsa4096
SIGN_ARGS+= --rsa4096
endif
# Make sign hash argument
ifeq ($(HASH),SHA256)
SIGN_ARGS+= --sha256
SIGN_ARGS+= --sha256
endif
ifeq ($(HASH),SHA384)
SIGN_ARGS+= --sha384
SIGN_ARGS+= --sha384
endif
ifeq ($(HASH),SHA3)
SIGN_ARGS+= --sha3
SIGN_ARGS+= --sha3
endif
$(EXPVER):
@ -145,11 +141,11 @@ test-update: test-app/image.bin FORCE
test-sim-external-flash-with-enc-update:SIGN_ENC_ARGS=--encrypt /tmp/enc_key.der --aes128
test-sim-external-flash-with-enc-update: wolfboot.bin test-app/image.elf FORCE
$(Q)cp test-app/image.elf test-app/image.bak.elf
$(Q)dd if=/dev/urandom of=test-app/image.elf bs=1K count=16 oflag=append conv=notrunc
$(Q)dd if=/dev/urandom of=test-app/image.elf bs=1k count=16 oflag=append conv=notrunc
@printf "0123456789abcdef0123456789abcdef0123456789abcdef" > /tmp/enc_key.der
$(Q)$(SIGN_TOOL) $(SIGN_OPTIONS) $(SIGN_ENC_ARGS) test-app/image.elf $(PRIVATE_KEY) 1
$(Q)cp test-app/image.bak.elf test-app/image.elf
$(Q)dd if=/dev/urandom of=test-app/image.elf bs=1K count=16 oflag=append conv=notrunc
$(Q)dd if=/dev/urandom of=test-app/image.elf bs=1k count=16 oflag=append conv=notrunc
$(Q)$(SIGN_TOOL) $(SIGN_OPTIONS) $(SIGN_ENC_ARGS) test-app/image.elf $(PRIVATE_KEY) $(TEST_UPDATE_VERSION)
$(Q)$(SIGN_TOOL) $(SIGN_ARGS) $(DELTA_UPDATE_OPTIONS) $(SIGN_ENC_ARGS) \
test-app/image.elf $(PRIVATE_KEY) $(TEST_UPDATE_VERSION)
@ -157,7 +153,8 @@ test-sim-external-flash-with-enc-update: wolfboot.bin test-app/image.elf FORCE
#
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_PARTITION_SIZE))) count=1 2>/dev/null | tr "\000" "\377" > v1_part.dd
$(Q)dd if=test-app/image_v1_signed.bin bs=256 of=v1_part.dd conv=notrunc
$(Q)$(BINASSEMBLE) internal_flash.dd 0 wolfboot.bin \
$(Q)$(BINASSEMBLE) internal_flash.dd \
0 wolfboot.bin \
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) v1_part.dd
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_SECTOR_SIZE))) count=1 2>/dev/null | tr "\000" "\377" > erased_sec.dd
$(Q)$(BINASSEMBLE) external_flash.dd 0 test-app/image_v$(TEST_UPDATE_VERSION)_signed_and_encrypted.bin \
@ -170,23 +167,25 @@ test-sim-external-flash-with-enc-delta-update:
test-sim-internal-flash-with-update: wolfboot.bin test-app/image.elf FORCE
$(Q)cp test-app/image.elf test-app/image.bak.elf
$(Q)dd if=/dev/urandom of=test-app/image.elf bs=1K count=16 oflag=append conv=notrunc
$(Q)dd if=/dev/urandom of=test-app/image.elf bs=1k count=16 oflag=append conv=notrunc
$(Q)$(SIGN_TOOL) $(SIGN_OPTIONS) test-app/image.elf $(PRIVATE_KEY) 1
$(Q)cp test-app/image.bak.elf test-app/image.elf
$(Q)dd if=/dev/urandom of=test-app/image.elf bs=1K count=16 oflag=append conv=notrunc
$(Q)dd if=/dev/urandom of=test-app/image.elf bs=1k count=16 oflag=append conv=notrunc
$(Q)$(SIGN_TOOL) $(SIGN_OPTIONS) test-app/image.elf $(PRIVATE_KEY) $(TEST_UPDATE_VERSION)
$(Q)dd if=/dev/zero bs=$$(($(WOLFBOOT_SECTOR_SIZE))) count=1 2>/dev/null | tr "\000" "\377" > erased_sec.dd
$(Q)$(SIGN_TOOL) $(SIGN_ARGS) $(DELTA_UPDATE_OPTIONS) \
test-app/image.elf $(PRIVATE_KEY) $(TEST_UPDATE_VERSION)
$(Q)$(BINASSEMBLE) internal_flash.dd 0 wolfboot.bin \
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) test-app/image_v1_signed.bin \
$(Q)$(BINASSEMBLE) internal_flash.dd \
0 wolfboot.bin \
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) test-app/image_v1_signed.bin \
$$(($(WOLFBOOT_PARTITION_UPDATE_ADDRESS)-$(ARCH_FLASH_OFFSET))) test-app/image_v$(TEST_UPDATE_VERSION)_signed.bin \
$$(($(WOLFBOOT_PARTITION_SWAP_ADDRESS)-$(ARCH_FLASH_OFFSET))) erased_sec.dd
test-sim-internal-flash-with-delta-update:
make test-sim-internal-flash-with-update DELTA_UPDATE_OPTIONS="--delta test-app/image_v1_signed.bin"
$(Q)$(BINASSEMBLE) internal_flash.dd 0 wolfboot.bin \
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) test-app/image_v1_signed.bin \
$(Q)$(BINASSEMBLE) internal_flash.dd \
0 wolfboot.bin \
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) test-app/image_v1_signed.bin \
$$(($(WOLFBOOT_PARTITION_UPDATE_ADDRESS)-$(ARCH_FLASH_OFFSET))) test-app/image_v$(TEST_UPDATE_VERSION)_signed_diff.bin \
$$(($(WOLFBOOT_PARTITION_SWAP_ADDRESS)-$(ARCH_FLASH_OFFSET))) erased_sec.dd

View File

@ -88,7 +88,7 @@ void printmsg(const char *msg)
}
int hal_flash_write(uint32_t address, const uint8_t *data, int len)
int hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
(void)address;
(void)data;
@ -96,7 +96,7 @@ int hal_flash_write(uint32_t address, const uint8_t *data, int len)
return -1;
}
int hal_flash_erase(uint32_t address, int len)
int hal_flash_erase(uintptr_t address, int len)
{
(void)address;
(void)len;

View File

@ -30,7 +30,7 @@
#define EXT_FLASH
#if defined(ENCRYPT_WITH_AES256) || defined(ENCRYPT_WITH_AES128)
#define WOLFSSL_AES_COUNTER
#define WOLFSSL_AES_COUNTER
#define WOLFSSL_AES_DIRECT
#endif
#if defined(ENCRYPT_WITH_AES256)
@ -68,11 +68,11 @@ static int locked = 0;
void hal_init(void)
{
}
int hal_flash_write(uint32_t address, const uint8_t *data, int len)
int hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
return 0;
}
int hal_flash_erase(uint32_t address, int len)
int hal_flash_erase(uintptr_t address, int len)
{
return 0;
}
@ -211,7 +211,7 @@ START_TEST(test_ext_flash_operations) {
/* Erase the first sector */
eres = ext_flash_erase(address, WOLFBOOT_SECTOR_SIZE);
ck_assert_int_eq(eres, 0);
/* Read first sector from the flash memory */
rres = ext_flash_read(address, data, WOLFBOOT_SECTOR_SIZE);
ck_assert_int_eq(rres, WOLFBOOT_SECTOR_SIZE);
@ -255,7 +255,7 @@ START_TEST(test_ext_enc_flash_operations) {
/* Read data from the flash memory */
rres = ext_flash_check_read(address, data, size);
ck_assert_int_eq(rres, size);
/* Check that the data read from the flash memory matches the data that was written */
ck_assert_mem_eq(&flash[address], test_buffer, size);

View File

@ -37,11 +37,11 @@ static int locked = 0;
void hal_init(void)
{
}
int hal_flash_write(uint32_t address, const uint8_t *data, int len)
int hal_flash_write(uintptr_t address, const uint8_t *data, int len)
{
return 0;
}
int hal_flash_erase(uint32_t address, int len)
int hal_flash_erase(uintptr_t address, int len)
{
return 0;
}
@ -108,7 +108,7 @@ START_TEST (test_parser_sunny)
/* Check version */
fail_if(wolfBoot_find_header(test_buffer + 8, HDR_VERSION, &p) != 4, "Parser error: cannot locate version");
fail_if((p[0] != 0x0d) || (p[1] != 0x0c) || (p[2] != 0x0b) || (p[3] != 0x0a), "Parser error: version doesn't match");
/* Check timestamp */
fail_if(wolfBoot_find_header(test_buffer + 8, HDR_TIMESTAMP, &p) != 8, "Parser error: cannot locate timestamp");
fail_if((p[0] != 0x07) || (p[1] != 0x06) || (p[2] != 0x05) || (p[3] != 0x04), "Parser error: timestamp doesn't match");
@ -116,7 +116,7 @@ START_TEST (test_parser_sunny)
/* Check sha256 field */
fail_if(wolfBoot_find_header(test_buffer + 8, HDR_SHA256, &p) != 32, "Parser error: cannot locate hash");
for (i = 0; i < 32; i++)
for (i = 0; i < 32; i++)
fail_unless(p[i] == i, "Parser error: hash does not match");
/* Check non-existing field */
@ -144,7 +144,7 @@ START_TEST (test_parser_borders)
bad_buff[10] = 0xF8;
bad_buff[11] = 0x00;
fail_if(wolfBoot_find_header(bad_buff + 8, HDR_VERSION, &p) != 0, "Parser error: accessing version field out of bounds");
/* Second field too large */
bad_buff[8] = 0x01;
bad_buff[9] = 0x00;