diff --git a/.gitignore b/.gitignore index 47472c4f..d6a53d9c 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,5 @@ image_v1_signed.bin factory.bin wolfboot-align.bin wolfboot.bin +tools/test-expect-version/test-expect-version +tools/test-update-server/server diff --git a/arch.mk b/arch.mk index 682bca5d..a3145a3b 100644 --- a/arch.mk +++ b/arch.mk @@ -48,7 +48,7 @@ ifeq ($(ARCH),RISCV) CFLAGS+=-fno-builtin-printf -DUSE_PLIC -DUSE_M_TIME -g -march=rv32imac -mabi=ilp32 -mcmodel=medany -nostartfiles -DARCH_RISCV LDFLAGS+=-march=rv32imac -mabi=ilp32 -mcmodel=medany OBJS+=src/boot_riscv.o src/vector_riscv.o - ARCH_FLASH_OFFSET=0x20010000 + ARCH_FLASH_OFFSET=0x20000000 endif CFLAGS+=-DARCH_FLASH_OFFSET=$(ARCH_FLASH_OFFSET) diff --git a/docs/Targets.md b/docs/Targets.md index 16ea9837..ff899e22 100644 --- a/docs/Targets.md +++ b/docs/Targets.md @@ -24,21 +24,21 @@ The default wolfBoot configuration will add a second stage bootloader, leaving t For testing wolfBoot here are the changes required: 1. Makefile arguments: - * ARCH?=RISCV - * TARGET?=hifive1 + * ARCH=RISCV + * TARGET=hifive1 - ``` - make ARCH=RISCV TARGET=hifive1 clean - make ARCH=RISCV TARGET=hifive1 - ``` + ``` + make ARCH=RISCV TARGET=hifive1 clean + make ARCH=RISCV TARGET=hifive1 + ``` - If using the `riscv64-unknown-elf-` cross compiler you can add `CROSS_COMPILE=riscv64-unknown-elf-` to your `make` or modify `arch.mk` as follows: - - ``` - ifeq ($(ARCH),RISCV) - - CROSS_COMPILE:=riscv32-unknown-elf- - + CROSS_COMPILE:=riscv64-unknown-elf- - ``` + If using the `riscv64-unknown-elf-` cross compiler you can add `CROSS_COMPILE=riscv64-unknown-elf-` to your `make` or modify `arch.mk` as follows: + + ``` + ifeq ($(ARCH),RISCV) + - CROSS_COMPILE:=riscv32-unknown-elf- + + CROSS_COMPILE:=riscv64-unknown-elf- + ``` 2. `include/target.h` @@ -58,6 +58,32 @@ Application Size 0x40000 (256KB) #define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x20060000 ``` +### Build Options + +* To use ECC instead of ED25519 use make argument `SIGN=ECC256` +* To output wolfboot as hex for loading with JLink use make argument `wolfboot.hex` + +### Loading + +Loading with JLink: + +``` +JLinkExe -device FE310 -if JTAG -speed 4000 -jtagconf -1,-1 -autoconnect 1 +loadfile wolfboot.hex +reset +``` + +### Debugging + +Debugging with JLink: + +In one terminal: +`JLinkGDBServer -device FE310 -port 3333` + +In another terminal: +`riscv64-unknown-elf-gdb wolfboot.elf -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333"` + + ## STM32-F407 Example 512KB partitioning on STM32-F407 @@ -67,12 +93,12 @@ starting at address 0x20000. The flash layout is provided by the default example configuration in `target.h`: ```C -#define WOLFBOOT_SECTOR_SIZE 0x20000 -#define WOLFBOOT_PARTITION_SIZE 0x20000 +#define WOLFBOOT_SECTOR_SIZE 0x20000 +#define WOLFBOOT_PARTITION_SIZE 0x20000 -#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x20000 +#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x20000 #define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x40000 -#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x60000 +#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x60000 ``` This results in the following partition configuration: diff --git a/tools/test-expect-version/test-expect-version.c b/tools/test-expect-version/test-expect-version.c index 1d0ce90c..3ff37867 100644 --- a/tools/test-expect-version/test-expect-version.c +++ b/tools/test-expect-version/test-expect-version.c @@ -20,7 +20,7 @@ * *============================================================================= * - * OTA Upgrade mechanism implemented using DTLS 1.2 + * Update tool to verify update version * */ @@ -42,8 +42,10 @@ #include #define MSGLEN (4 + 4 + 8) -#define PORT "/dev/ttyS0" +#ifndef UART_DEV +#define UART_DEV "/dev/ttyS0" +#endif #ifndef B115200 #define B115200 115200 #endif @@ -55,7 +57,6 @@ void alarm_handler(int signo) } - int main(int argc, char** argv) { struct termios tty; @@ -71,7 +72,7 @@ int main(int argc, char** argv) exit(1); } - serialfd = open(PORT, O_RDWR | O_NOCTTY); + serialfd = open(UART_DEV, O_RDWR | O_NOCTTY); tcgetattr(serialfd, &tty); cfsetospeed(&tty, B115200); cfsetispeed(&tty, B115200); @@ -110,4 +111,3 @@ int main(int argc, char** argv) close(serialfd); return 0; } - diff --git a/tools/test-update-server/README.md b/tools/test-update-server/README.md new file mode 100644 index 00000000..e8c9777f --- /dev/null +++ b/tools/test-update-server/README.md @@ -0,0 +1,7 @@ +# Update Server Tool + +Tool to send binary image over UART to test application. + +Usage: + +`./server ../../factory.bin` diff --git a/tools/test-update-server/server.c b/tools/test-update-server/server.c index 25215c18..8574f042 100644 --- a/tools/test-update-server/server.c +++ b/tools/test-update-server/server.c @@ -20,7 +20,7 @@ * *============================================================================= * - * OTA Upgrade mechanism implemented using DTLS 1.2 + * OTA Upgrade mechanism implemented using UART * */ @@ -42,8 +42,16 @@ #include #define MSGLEN (4 + 4 + 8) -#define PORT "/dev/ttyACM0" - +#ifndef UART_DEV + #ifdef _MACH_ + #define UART_DEV "/dev/usbmodem144241" + #else + #define UART_DEV "/dev/ttyACM0" + #endif +#endif +#ifndef B115200 +#define B115200 115200 +#endif static volatile int cleanup; /* To handle shutdown */ union usb_ack { @@ -52,8 +60,8 @@ union usb_ack { }; -static uint8_t pktbuf[MSGLEN]; -static unsigned int pktbuf_size = 0; +static uint8_t pktbuf[MSGLEN]; +static unsigned int pktbuf_size = 0; static int serialfd = -1; static uint32_t high_ack; @@ -79,7 +87,7 @@ static int recv_ack(union usb_ack *ack) if (c == '#') { int i = 0; err = 0; - ack->offset = 0; + ack->offset = 0; while (i < 4) { res = read(serialfd, &c, 1); if (res < 1) { @@ -121,27 +129,27 @@ int main(int argc, char** argv) union usb_ack ack; struct termios tty; sigset(SIGALRM, alarm_handler); - - if (argc != 2) { printf("Usage: %s firmware_filename\n", argv[0]); exit(1); } + /* open file and get size */ ffd = open(argv[1], O_RDONLY); if (ffd < 0) { perror("opening file"); exit(2); } - res = fstat(ffd, &st); if (res != 0) { perror("fstat file"); exit(2); } tot_len = st.st_size; - serialfd = open(PORT, O_RDWR | O_NOCTTY); + + /* open UART */ + serialfd = open(UART_DEV, O_RDWR | O_NOCTTY); tcgetattr(serialfd, &tty); cfsetospeed(&tty, B115200); cfsetispeed(&tty, B115200); @@ -155,8 +163,8 @@ int main(int argc, char** argv) tty.c_cc[VMIN] = 0; tty.c_cc[VTIME] = 5; tcsetattr(serialfd, TCSANOW, &tty); - /* Await Start hash */ + /* Wait for start hash (asterisk) */ while (1) { char c; @@ -172,18 +180,17 @@ int main(int argc, char** argv) printf("%c",c); fflush(stdout); } - + } printf("Target connected.\n"); usleep(500000); printf("Starting update.\n"); - do { uint8_t hdr[2] = { 0xA5, 0x5A}; len = 0; - lseek(ffd, 0, SEEK_SET); - write(serialfd, &hdr, 2); + lseek(ffd, 0, SEEK_SET); + write(serialfd, &hdr, 2); write(serialfd, &tot_len, sizeof(uint32_t)); printf("Sent image file size (%d)\n", tot_len); while (len < tot_len) { @@ -201,7 +208,7 @@ int main(int argc, char** argv) pktbuf_size = 0; if (ack.offset != len) { printf("buf rewind %u\n", ack.offset); - lseek(ffd, ack.offset, SEEK_SET); + lseek(ffd, ack.offset, SEEK_SET); len = ack.offset; } memcpy(pktbuf + 4, &len, sizeof(len)); @@ -215,7 +222,9 @@ int main(int argc, char** argv) check(pktbuf); write(serialfd, pktbuf, pktbuf_size); len += res; - printf("Sent bytes: %d/%d %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x \r", len, tot_len, pktbuf[0], pktbuf[1], pktbuf[2], pktbuf[3], pktbuf[4], pktbuf[5], pktbuf[6], pktbuf[7]); + + printf("Sent bytes: %d/%d %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x \r", + len, tot_len, pktbuf[0], pktbuf[1], pktbuf[2], pktbuf[3], pktbuf[4], pktbuf[5], pktbuf[6], pktbuf[7]); fflush(stdout); alarm(2); @@ -223,17 +232,17 @@ int main(int argc, char** argv) } printf("\n\n"); } while (0); + printf("waiting for last ack...\n"); while(!cleanup) { res = recv_ack(&ack); if ((res == 0 ) && (ack.offset == tot_len)) { printf("Transfer complete.\n"); break; - } + } } printf("All done.\n"); close(serialfd); return 0; } -