Skip to content

Commit 7a28c9e

Browse files
committed
Resolved peer review items. Thanks Daniele. Documentation improvements. Added open() check for update server example.
1 parent 33e3607 commit 7a28c9e

6 files changed

Lines changed: 80 additions & 55 deletions

File tree

.gitignore

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
*.x86_64
3737
*.hex
3838
*.rom
39+
*.bin
3940

4041
# Debug files
4142
*.dSYM/
@@ -66,14 +67,11 @@ tools/ecc256/ecc256_keygen
6667
cscope.out
6768
tags
6869

69-
70-
image.bin
71-
image_v1_signed.bin
70+
# Generated files using target.h
7271
.wolfboot-arch-offset
7372
.wolfboot-offset
7473
.wolfboot-partition-size
75-
factory.bin
76-
wolfboot-align.bin
77-
wolfboot.bin
74+
75+
# Test tools
7876
tools/test-expect-version/test-expect-version
7977
tools/test-update-server/server

arch.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# check for FASTMATH or SP_MATH
44
ifeq ($(SPMATH),1)
5-
MATH_OBJS:=./lib/wolfssl/wolfcrypt/src/sp_int.o ./lib/wolfssl/wolfcrypt/src/sp_c32.o
5+
MATH_OBJS:=./lib/wolfssl/wolfcrypt/src/sp_int.o
66
else
77
MATH_OBJS:=./lib/wolfssl/wolfcrypt/src/integer.o
88
endif
@@ -47,13 +47,14 @@ ifeq ($(ARCH),RISCV)
4747
CROSS_COMPILE:=riscv32-unknown-elf-
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
50+
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
5051

5152
# Prune unused functions and data
5253
CFLAGS +=-ffunction-sections -fdata-sections
5354
LDFLAGS+=-Wl,--gc-sections
5455

5556
OBJS+=src/boot_riscv.o src/vector_riscv.o
56-
ARCH_FLASH_OFFSET=0x20000000
57+
ARCH_FLASH_OFFSET=0x20010000
5758
endif
5859

5960
CFLAGS+=-DARCH_FLASH_OFFSET=$(ARCH_FLASH_OFFSET)

docs/Targets.md

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
# Targets
22

3+
## STM32-F407
4+
5+
Example 512KB partitioning on STM32-F407
6+
7+
The example firmware provided in the `test-app` is configured to boot from the primary partition
8+
starting at address 0x20000. The flash layout is provided by the default example using the following
9+
configuration in `target.h`:
10+
11+
```C
12+
#define WOLFBOOT_SECTOR_SIZE 0x20000
13+
#define WOLFBOOT_PARTITION_SIZE 0x20000
14+
15+
#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x20000
16+
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x40000
17+
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x60000
18+
```
19+
20+
This results in the following partition configuration:
21+
22+
![example partitions](png/example_partitions.png)
23+
24+
This configuration demonstrates one of the possible layouts, with the slots
25+
aligned to the beginning of the physical sector on the flash.
26+
27+
The entry point for all the runnable firmware images on this target will be `0x20100`,
28+
256 Bytes after the beginning of the first flash partition. This is due to the presence
29+
of the firmware image header at the beginning of the partition, as explained more in details
30+
in [Firmware image](firmware_image.md)
31+
32+
In this particular case, due to the flash geometry, the swap space must be as big as 64KB, to account for proper sector swapping between the two images.
33+
34+
On other systems, the SWAP space can be as small as 512B, if multiple smaller flash blocks are used.
35+
36+
More information about the geometry of the flash and in-application programming (IAP) can be found in the manufacturer manual of each target device.
37+
38+
339
## SiFive HiFive1 RISC-V
440
541
### Features
@@ -19,7 +55,7 @@ Start Address: 0x20010000
1955
2056
### wolfBoot configuration
2157
22-
The default wolfBoot configuration will add a second stage bootloader, leaving the stock "double tap" bootloader for safety.
58+
The default wolfBoot configuration will add a second stage bootloader, leaving the stock "double tap" bootloader as a fallback for recovery. Your production implementation should replace this and partition addresses in `target.h` will need updated, so they are `0x10000` less.
2359
2460
For testing wolfBoot here are the changes required:
2561
@@ -45,14 +81,15 @@ For testing wolfBoot here are the changes required:
4581
4682
Bootloader Size: 0x10000 (64KB)
4783
Application Size 0x40000 (256KB)
84+
Swap Sector Size: 0x1000 (4KB)
4885
4986
```c
50-
#define WOLFBOOT_SECTOR_SIZE 0x10000
51-
#define WOLFBOOT_PARTITION_SIZE 0x40000
52-
87+
#define WOLFBOOT_SECTOR_SIZE 0x1000
5388
#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x20020000
89+
90+
#define WOLFBOOT_PARTITION_SIZE 0x40000
5491
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x20060000
55-
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x20070000
92+
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x200A0000
5693
```
5794

5895
### Build Options
@@ -78,43 +115,7 @@ In one terminal:
78115
`JLinkGDBServer -device FE310 -port 3333`
79116
80117
In another terminal:
81-
`riscv64-unknown-elf-gdb test-app/image.elf -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333"`
82-
or
83-
`riscv64-unknown-elf-gdb wolfboot.elf -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333"`
84-
85-
86-
87-
## STM32-F407
88-
89-
Example 512KB partitioning on STM32-F407
90-
91-
The example firmware provided in the `test-app` is configured to boot from the primary partition
92-
starting at address 0x20000. The flash layout is provided by the default example using the following
93-
configuration in `target.h`:
94-
95-
```C
96-
#define WOLFBOOT_SECTOR_SIZE 0x20000
97-
#define WOLFBOOT_PARTITION_SIZE 0x20000
98-
99-
#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x20000
100-
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x40000
101-
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x60000
102118
```
103-
104-
This results in the following partition configuration:
105-
106-
![example partitions](png/example_partitions.png)
107-
108-
This configuration demonstrates one of the possible layouts, with the slots
109-
aligned to the beginning of the physical sector on the flash.
110-
111-
The entry point for all the runnable firmware images on this target will be `0x20100`,
112-
256 Bytes after the beginning of the first flash partition. This is due to the presence
113-
of the firmware image header at the beginning of the partition, as explained more in details
114-
in [Firmware image](firmware_image.md)
115-
116-
In this particular case, due to the flash geometry, the swap space must be as big as 64KB, to account for proper sector swapping between the two images.
117-
118-
On other systems, the SWAP space can be as small as 512B, if multiple smaller flash blocks are used.
119-
120-
More information about the geometry of the flash and in-application programming (IAP) can be found in the manufacturer manual of each target device.
119+
riscv64-unknown-elf-gdb wolfboot.elf -ex "set remotetimeout 240" -ex "target extended-remote localhost:3333"
120+
add-symbol-file test-app/image.elf 0x20020100
121+
```

docs/compile.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,23 @@ both `PART_UPDATE_EXT` and `PART_SWAP_EXT` are defined.
135135

136136
When external memory is used, the HAL API must be extended to define methods to access the custom memory.
137137
Refer to the [HAL](HAL.md) page for the description of the `ext_flash_*` API.
138+
139+
### Using Mac OS/X
140+
141+
If you see 0xC3 0xBF (C3BF) repeated in your factory.bin then your OS is using Unicode characters.
142+
143+
The "tr" command for assembling the 0xFF padding between `"bootloader" ... 0xFF ... "application" = factory.bin`, which requires the "C" locale.
144+
145+
Set this in your terminal
146+
```
147+
LANG=
148+
LC_COLLATE="C"
149+
LC_CTYPE="C"
150+
LC_MESSAGES="C"
151+
LC_MONETARY="C"
152+
LC_NUMERIC="C"
153+
LC_TIME="C"
154+
LC_ALL=
155+
```
156+
157+
Then run the normal `make` steps.

tools/test-update-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Tool to send binary image over UART to test application.
44

55
Usage:
66

7-
`./server ../../factory.bin`
7+
`./server ../../test-app/image_v1_signed.bin`

tools/test-update-server/server.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343

4444
#define MSGLEN (4 + 4 + 8)
4545
#ifndef UART_DEV
46-
#ifdef _MACH_
47-
#define UART_DEV "/dev/usbmodem144241"
46+
#ifdef __MACH__
47+
#define UART_DEV "/dev/cu.usbmodem1411"
4848
#else
4949
#define UART_DEV "/dev/ttyACM0"
5050
#endif
@@ -149,7 +149,12 @@ int main(int argc, char** argv)
149149
tot_len = st.st_size;
150150

151151
/* open UART */
152+
printf("Opening %s UART\n", UART_DEV);
152153
serialfd = open(UART_DEV, O_RDWR | O_NOCTTY);
154+
if (serialfd < 0) {
155+
fprintf(stderr, "failed opening serial %s\n", UART_DEV);
156+
exit(2);
157+
}
153158
tcgetattr(serialfd, &tty);
154159
cfsetospeed(&tty, B115200);
155160
cfsetispeed(&tty, B115200);

0 commit comments

Comments
 (0)