Skip to content

Commit

Permalink
Fixes for handling 64-bit assign mmap virtual addresses.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Aug 3, 2023
1 parent 8726df2 commit 0aa41b8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
18 changes: 8 additions & 10 deletions hal/sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ static int mmap_file(const char *path, uint8_t *address, uint8_t** ret_address)
if (mmaped_addr == MAP_FAILED)
return -1;

printf("Simulator assigned %s to base %p\n", path, mmaped_addr);

*ret_address = mmaped_addr;

close(fd);
Expand All @@ -98,28 +100,24 @@ 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");
/* 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;
}

Expand Down
4 changes: 2 additions & 2 deletions include/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void hal_deinit();
#endif

void hal_init(void);
int hal_flash_write(uint32_t address, const uint8_t *data, int len);
int hal_flash_erase(uint32_t address, int len);
int hal_flash_write(uintptr_t address, const uint8_t *data, int len);
int hal_flash_erase(uintptr_t address, int len);
void hal_flash_unlock(void);
void hal_flash_lock(void);
void hal_prepare_boot(void);
Expand Down
12 changes: 6 additions & 6 deletions src/libwolfboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,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);
Expand Down Expand Up @@ -384,10 +384,10 @@ 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, (uint32_t)(PART_UPDATE_ENDFLAGS - sizeof(uint32_t)));
partition_magic_write(part, PART_UPDATE_ENDFLAGS - sizeof(uint32_t));
}
}
#endif /* EXT_FLASH */
Expand Down
4 changes: 2 additions & 2 deletions tools/scripts/qemu64/sign_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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



8 changes: 4 additions & 4 deletions tools/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -141,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)
Expand All @@ -167,10 +167,10 @@ 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) \
Expand Down

0 comments on commit 0aa41b8

Please sign in to comment.