Skip to content

Commit

Permalink
Simulator fixes and support for using MacOS:
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dgarske committed Aug 3, 2023
1 parent 7638bfb commit 215bbcd
Show file tree
Hide file tree
Showing 33 changed files with 335 additions and 179 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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] $@"
Expand Down
3 changes: 1 addition & 2 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions config/examples/sim-delta-update.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions config/examples/sim-ecc.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions config/examples/sim-encrypt-delta-update.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions config/examples/sim-encrypt-update.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions config/examples/sim-nvm-writeonce.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions config/examples/sim-rsa.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions config/examples/sim-tpm.config
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions config/examples/sim.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions docs/Targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,10 @@ make test-sim-internal-flash-with-update
# it should print 2
./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

This example for `Renesas RX72N` demonstrates simple secure firmware update by wolfBoot. A sample application v1 is
Expand Down
4 changes: 2 additions & 2 deletions hal/nxp_t2080.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions hal/raspi3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Loading

0 comments on commit 215bbcd

Please sign in to comment.