diff --git a/hal/sim.c b/hal/sim.c index 2810af9e..b9640694 100644 --- a/hal/sim.c +++ b/hal/sim.c @@ -61,7 +61,7 @@ static int mmap_file(const char *path, uint8_t *address, uint8_t** ret_address) fd = open(path, O_RDWR); if (fd == -1) { - printf("can't open %s\n", path); + fprintf(stderr,"can't open %s\n", path); return -1; } @@ -110,9 +110,11 @@ int hal_flash_erase(uint32_t address, int len) uint8_t *ptr = 0; /* implicit cast abide compiler warning */ - printf("hal_flash_erase addr %p len %d\n", address, len); + fprintf(stderr,"hal_flash_erase addr %p len %d\n", address, len); if (address == erasefail_address) { - printf("POWER FAILURE\n"); + fprintf(stderr,"POWER FAILURE\n"); + /* Corrupt page */ + memset(ptr + address, 0xEE, len); exit(0); } memset(ptr + address, 0xff, len); @@ -127,14 +129,14 @@ void hal_init(void) ret = mmap_file(INTERNAL_FLASH_FILE, (uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS, &p); if (ret != 0) { - printf("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, NULL, &flash_base); if (ret != 0) { - printf("failed to load internal flash file\n"); + fprintf(stderr,"failed to load internal flash file\n"); exit(-1); } #endif /* EXT_FLASH */ @@ -142,7 +144,7 @@ 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); - printf("Set power fail to erase at address %p\n", erasefail_address); + fprintf(stderr,"Set power fail to erase at address %p\n", erasefail_address); break; } } @@ -184,18 +186,18 @@ void do_boot(const uint32_t *app_offset) fd = memfd_create("test_app", 0); if (fd == -1) { - printf("memfd error\n"); + fprintf(stderr,"memfd error\n"); exit(-1); } ret = write(fd, app_offset, WOLFBOOT_PARTITION_SIZE); if (ret != WOLFBOOT_PARTITION_SIZE) { - printf("can't write test-app to memfd\n"); + fprintf(stderr,"can't write test-app to memfd\n"); exit(-1); } ret = fexecve(fd, main_argv, envp); - printf("fexecve error\n"); + fprintf(stderr,"fexecve error\n"); exit(1); } diff --git a/test-app/app_sim.c b/test-app/app_sim.c index 9cfb82b3..a7de122a 100644 --- a/test-app/app_sim.c +++ b/test-app/app_sim.c @@ -76,4 +76,4 @@ int main(int argc, char *argv[]) { return 0; } -#endif /** PLATFROM_sim **/ +#endif /** PLATFORM_sim **/ diff --git a/tools/scripts/sim-sunnyday-update.sh b/tools/scripts/sim-sunnyday-update.sh new file mode 100755 index 00000000..3effcc28 --- /dev/null +++ b/tools/scripts/sim-sunnyday-update.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +V=`./wolfboot.elf update_trigger get_version 2>/dev/null` +if [ "x$V" != "x1" ]; then + echo "Failed first boot with update_trigger" + exit 1 +fi + + +V=`./wolfboot.elf success get_version 2>/dev/null` +if [ "x$V" != "x2" ]; then + echo "Failed update (V: $V)" + exit 1 +fi + +echo Test successful. +exit 0 + + diff --git a/tools/scripts/sim-update-fallback.sh b/tools/scripts/sim-update-fallback.sh new file mode 100755 index 00000000..087a8d22 --- /dev/null +++ b/tools/scripts/sim-update-fallback.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +V=`./wolfboot.elf update_trigger get_version 2>/dev/null` +if [ "x$V" != "x1" ]; then + echo "Failed first boot with update_trigger" + exit 1 +fi + + +V=`./wolfboot.elf get_version 2>/dev/null` +if [ "x$V" != "x2" ]; then + echo "Failed update (V: $V)" + exit 1 +fi + +V=`./wolfboot.elf get_version 2>/dev/null` +if [ "x$V" != "x1" ]; then + echo "Failed fallback (V: $V)" + exit 1 +fi + +echo Test successful. +exit 0 + + diff --git a/tools/scripts/sim-update-powerfail-resume.sh b/tools/scripts/sim-update-powerfail-resume.sh new file mode 100755 index 00000000..18983e4d --- /dev/null +++ b/tools/scripts/sim-update-powerfail-resume.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +V=`./wolfboot.elf update_trigger get_version 2>/dev/null` +if [ "x$V" != "x1" ]; then + echo "Failed first boot with update_trigger" + exit 1 +fi + + +./wolfboot.elf powerfail 15000 get_version 2>/dev/null +./wolfboot.elf powerfail 18000 get_version 2>/dev/null +./wolfboot.elf powerfail 1a000 get_version 2>/dev/null + +V=`./wolfboot.elf get_version 2>/dev/null` +if [ "x$V" != "x2" ]; then + echo "Failed update (V: $V)" + exit 1 +fi + +./wolfboot.elf powerfail 11000 get_version 2>/dev/null +./wolfboot.elf powerfail 14000 get_version 2>/dev/null +./wolfboot.elf powerfail 1e000 get_version 2>/dev/null + +V=`./wolfboot.elf get_version 2>/dev/null` +if [ "x$V" != "x1" ]; then + echo "Failed fallback (V: $V)" + exit 1 +fi + +echo Test successful. +exit 0 + +