Skip to content

Commit 317bca1

Browse files
committed
Fix for ARCH_FLASH_OFFSET when make script is gathering .wolfboot-offset and .wolfboot-partition-size files. Updates to Target.md. Cleanups to test tools.
1 parent 0f00f8e commit 317bca1

6 files changed

Lines changed: 86 additions & 42 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ image_v1_signed.bin
7575
factory.bin
7676
wolfboot-align.bin
7777
wolfboot.bin
78+
tools/test-expect-version/test-expect-version
79+
tools/test-update-server/server

arch.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ifeq ($(ARCH),RISCV)
4848
CFLAGS+=-fno-builtin-printf -DUSE_PLIC -DUSE_M_TIME -g -march=rv32imac -mabi=ilp32 -mcmodel=medany -nostartfiles -DARCH_RISCV
4949
LDFLAGS+=-march=rv32imac -mabi=ilp32 -mcmodel=medany
5050
OBJS+=src/boot_riscv.o src/vector_riscv.o
51-
ARCH_FLASH_OFFSET=0x20010000
51+
ARCH_FLASH_OFFSET=0x20000000
5252
endif
5353

5454
CFLAGS+=-DARCH_FLASH_OFFSET=$(ARCH_FLASH_OFFSET)

docs/Targets.md

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ The default wolfBoot configuration will add a second stage bootloader, leaving t
2424
For testing wolfBoot here are the changes required:
2525

2626
1. Makefile arguments:
27-
* ARCH?=RISCV
28-
* TARGET?=hifive1
27+
* ARCH=RISCV
28+
* TARGET=hifive1
2929

30-
```
31-
make ARCH=RISCV TARGET=hifive1 clean
32-
make ARCH=RISCV TARGET=hifive1
33-
```
30+
```
31+
make ARCH=RISCV TARGET=hifive1 clean
32+
make ARCH=RISCV TARGET=hifive1
33+
```
3434
35-
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:
36-
37-
```
38-
ifeq ($(ARCH),RISCV)
39-
- CROSS_COMPILE:=riscv32-unknown-elf-
40-
+ CROSS_COMPILE:=riscv64-unknown-elf-
41-
```
35+
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:
36+
37+
```
38+
ifeq ($(ARCH),RISCV)
39+
- CROSS_COMPILE:=riscv32-unknown-elf-
40+
+ CROSS_COMPILE:=riscv64-unknown-elf-
41+
```
4242
4343
4444
2. `include/target.h`
@@ -58,6 +58,32 @@ Application Size 0x40000 (256KB)
5858
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x20060000
5959
```
6060

61+
### Build Options
62+
63+
* To use ECC instead of ED25519 use make argument `SIGN=ECC256`
64+
* To output wolfboot as hex for loading with JLink use make argument `wolfboot.hex`
65+
66+
### Loading
67+
68+
Loading with JLink:
69+
70+
```
71+
JLinkExe -device FE310 -if JTAG -speed 4000 -jtagconf -1,-1 -autoconnect 1
72+
loadfile wolfboot.hex
73+
reset
74+
```
75+
76+
### Debugging
77+
78+
Debugging with JLink:
79+
80+
In one terminal:
81+
`JLinkGDBServer -device FE310 -port 3333`
82+
83+
In another terminal:
84+
`riscv64-unknown-elf-gdb wolfboot.elf -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333"`
85+
86+
6187
## STM32-F407
6288

6389
Example 512KB partitioning on STM32-F407
@@ -67,12 +93,12 @@ starting at address 0x20000. The flash layout is provided by the default example
6793
configuration in `target.h`:
6894

6995
```C
70-
#define WOLFBOOT_SECTOR_SIZE 0x20000
71-
#define WOLFBOOT_PARTITION_SIZE 0x20000
96+
#define WOLFBOOT_SECTOR_SIZE 0x20000
97+
#define WOLFBOOT_PARTITION_SIZE 0x20000
7298

73-
#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x20000
99+
#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x20000
74100
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x40000
75-
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x60000
101+
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x60000
76102
```
77103
78104
This results in the following partition configuration:

tools/test-expect-version/test-expect-version.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*=============================================================================
2222
*
23-
* OTA Upgrade mechanism implemented using DTLS 1.2
23+
* Update tool to verify update version
2424
*
2525
*/
2626

@@ -42,8 +42,10 @@
4242
#include <errno.h>
4343

4444
#define MSGLEN (4 + 4 + 8)
45-
#define PORT "/dev/ttyS0"
4645

46+
#ifndef UART_DEV
47+
#define UART_DEV "/dev/ttyS0"
48+
#endif
4749
#ifndef B115200
4850
#define B115200 115200
4951
#endif
@@ -55,7 +57,6 @@ void alarm_handler(int signo)
5557
}
5658

5759

58-
5960
int main(int argc, char** argv)
6061
{
6162
struct termios tty;
@@ -71,7 +72,7 @@ int main(int argc, char** argv)
7172
exit(1);
7273
}
7374

74-
serialfd = open(PORT, O_RDWR | O_NOCTTY);
75+
serialfd = open(UART_DEV, O_RDWR | O_NOCTTY);
7576
tcgetattr(serialfd, &tty);
7677
cfsetospeed(&tty, B115200);
7778
cfsetispeed(&tty, B115200);
@@ -110,4 +111,3 @@ int main(int argc, char** argv)
110111
close(serialfd);
111112
return 0;
112113
}
113-

tools/test-update-server/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Update Server Tool
2+
3+
Tool to send binary image over UART to test application.
4+
5+
Usage:
6+
7+
`./server ../../factory.bin`

tools/test-update-server/server.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*=============================================================================
2222
*
23-
* OTA Upgrade mechanism implemented using DTLS 1.2
23+
* OTA Upgrade mechanism implemented using UART
2424
*
2525
*/
2626

@@ -42,8 +42,16 @@
4242
#include <errno.h>
4343

4444
#define MSGLEN (4 + 4 + 8)
45-
#define PORT "/dev/ttyACM0"
46-
45+
#ifndef UART_DEV
46+
#ifdef _MACH_
47+
#define UART_DEV "/dev/usbmodem144241"
48+
#else
49+
#define UART_DEV "/dev/ttyACM0"
50+
#endif
51+
#endif
52+
#ifndef B115200
53+
#define B115200 115200
54+
#endif
4755

4856
static volatile int cleanup; /* To handle shutdown */
4957
union usb_ack {
@@ -52,8 +60,8 @@ union usb_ack {
5260
};
5361

5462

55-
static uint8_t pktbuf[MSGLEN];
56-
static unsigned int pktbuf_size = 0;
63+
static uint8_t pktbuf[MSGLEN];
64+
static unsigned int pktbuf_size = 0;
5765
static int serialfd = -1;
5866
static uint32_t high_ack;
5967

@@ -79,7 +87,7 @@ static int recv_ack(union usb_ack *ack)
7987
if (c == '#') {
8088
int i = 0;
8189
err = 0;
82-
ack->offset = 0;
90+
ack->offset = 0;
8391
while (i < 4) {
8492
res = read(serialfd, &c, 1);
8593
if (res < 1) {
@@ -121,27 +129,27 @@ int main(int argc, char** argv)
121129
union usb_ack ack;
122130
struct termios tty;
123131
sigset(SIGALRM, alarm_handler);
124-
125-
126132

127133
if (argc != 2) {
128134
printf("Usage: %s firmware_filename\n", argv[0]);
129135
exit(1);
130136
}
131137

138+
/* open file and get size */
132139
ffd = open(argv[1], O_RDONLY);
133140
if (ffd < 0) {
134141
perror("opening file");
135142
exit(2);
136143
}
137-
138144
res = fstat(ffd, &st);
139145
if (res != 0) {
140146
perror("fstat file");
141147
exit(2);
142148
}
143149
tot_len = st.st_size;
144-
serialfd = open(PORT, O_RDWR | O_NOCTTY);
150+
151+
/* open UART */
152+
serialfd = open(UART_DEV, O_RDWR | O_NOCTTY);
145153
tcgetattr(serialfd, &tty);
146154
cfsetospeed(&tty, B115200);
147155
cfsetispeed(&tty, B115200);
@@ -155,8 +163,8 @@ int main(int argc, char** argv)
155163
tty.c_cc[VMIN] = 0;
156164
tty.c_cc[VTIME] = 5;
157165
tcsetattr(serialfd, TCSANOW, &tty);
158-
/* Await Start hash */
159166

167+
/* Wait for start hash (asterisk) */
160168
while (1) {
161169
char c;
162170

@@ -172,18 +180,17 @@ int main(int argc, char** argv)
172180
printf("%c",c);
173181
fflush(stdout);
174182
}
175-
183+
176184
}
177185
printf("Target connected.\n");
178186
usleep(500000);
179187
printf("Starting update.\n");
180188

181-
182189
do {
183190
uint8_t hdr[2] = { 0xA5, 0x5A};
184191
len = 0;
185-
lseek(ffd, 0, SEEK_SET);
186-
write(serialfd, &hdr, 2);
192+
lseek(ffd, 0, SEEK_SET);
193+
write(serialfd, &hdr, 2);
187194
write(serialfd, &tot_len, sizeof(uint32_t));
188195
printf("Sent image file size (%d)\n", tot_len);
189196
while (len < tot_len) {
@@ -201,7 +208,7 @@ int main(int argc, char** argv)
201208
pktbuf_size = 0;
202209
if (ack.offset != len) {
203210
printf("buf rewind %u\n", ack.offset);
204-
lseek(ffd, ack.offset, SEEK_SET);
211+
lseek(ffd, ack.offset, SEEK_SET);
205212
len = ack.offset;
206213
}
207214
memcpy(pktbuf + 4, &len, sizeof(len));
@@ -215,25 +222,27 @@ int main(int argc, char** argv)
215222
check(pktbuf);
216223
write(serialfd, pktbuf, pktbuf_size);
217224
len += res;
218-
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]);
225+
226+
printf("Sent bytes: %d/%d %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x \r",
227+
len, tot_len, pktbuf[0], pktbuf[1], pktbuf[2], pktbuf[3], pktbuf[4], pktbuf[5], pktbuf[6], pktbuf[7]);
219228

220229
fflush(stdout);
221230
alarm(2);
222231
}
223232
}
224233
printf("\n\n");
225234
} while (0);
235+
226236
printf("waiting for last ack...\n");
227237
while(!cleanup) {
228238
res = recv_ack(&ack);
229239
if ((res == 0 ) && (ack.offset == tot_len)) {
230240
printf("Transfer complete.\n");
231241
break;
232-
}
242+
}
233243
}
234244
printf("All done.\n");
235245
close(serialfd);
236246

237247
return 0;
238248
}
239-

0 commit comments

Comments
 (0)