Skip to content

Commit 34def41

Browse files
danielinuxdgarske
authored andcommitted
Added support for STM32F7 + DUALBANK_SWAP hw-assisted support
1 parent d0719f3 commit 34def41

13 files changed

Lines changed: 1184 additions & 13 deletions

File tree

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ WOLFBOOT_VERSION?=0
2424
V?=0
2525
SPMATH?=1
2626
RAM_CODE?=0
27+
DUALBANK_SWAP=0
2728

2829

2930

@@ -85,6 +86,10 @@ ifeq ($(RAM_CODE),1)
8586
CFLAGS+= -DRAM_CODE
8687
endif
8788

89+
ifeq ($(DUALBANK_SWAP),1)
90+
CFLAGS+= -DDUALBANK_SWAP
91+
endif
92+
8893
ifeq ($(SPI_FLASH),1)
8994
EXT_FLASH=1
9095
CFLAGS+= -DSPI_FLASH=1

arch.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ ifeq ($(ARCH),ARM)
3030
CORTEX_M0=1
3131
endif
3232

33+
ifeq ($(TARGET),stm32f7)
34+
ARCH_FLASH_OFFSET=0x08000000
35+
else
36+
ARCH_FLASH_OFFSET=0x0
37+
endif
38+
3339
## Cortex-M CPU
3440
ifeq ($(CORTEX_M0),1)
3541
CFLAGS+=-mcpu=cortex-m0

docs/Targets.md

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This results in the following partition configuration:
2626
This configuration demonstrates one of the possible layouts, with the slots
2727
aligned to the beginning of the physical sector on the flash.
2828
29-
The entry point for all the runnable firmware images on this target will be `0x20100`,
29+
The entry point for all the runnable firmware images on this target will be `0x20100`,
3030
256 Bytes after the beginning of the first flash partition. This is due to the presence
3131
of the firmware image header at the beginning of the partition, as explained more in details
3232
in [Firmware image](firmware_image.md)
@@ -114,14 +114,14 @@ For testing wolfBoot here are the changes required:
114114
1. Makefile arguments:
115115
* ARCH=RISCV
116116
* TARGET=hifive1
117-
117+
118118
```
119119
make ARCH=RISCV TARGET=hifive1 RAM_CODE=1 clean
120120
make ARCH=RISCV TARGET=hifive1 RAM_CODE=1
121121
```
122122
123123
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:
124-
124+
125125
```
126126
ifeq ($(ARCH),RISCV)
127127
- CROSS_COMPILE:=riscv32-unknown-elf-
@@ -172,3 +172,115 @@ riscv64-unknown-elf-gdb wolfboot.elf -ex "set remotetimeout 240" -ex "target ext
172172
add-symbol-file test-app/image.elf 0x20020100
173173
```
174174

175+
176+
## STM32-F769
177+
178+
The STM32-F76x and F77x offer dual-bank hardware-assisted swapping.
179+
The flash geometry must be defined beforehand, and wolfBoot can be compiled to use hardware
180+
assisted bank-swapping to perform updates.
181+
182+
183+
Example 2MB partitioning on STM32-F769:
184+
185+
- Dual-bank configuration
186+
187+
BANK A: 0x08000000 to 0x080FFFFFF (1MB)
188+
BANK B: 0x08100000 to 0x081FFFFFF (1MB)
189+
190+
- WolfBoot executes from BANK A after reboot (address: 0x08000000)
191+
- Boot partition @ BANK A + 0x20000 = 0x08020000
192+
- Update partition @ BANK B + 0x20000 = 0x08120000
193+
- Application entry point: 0x08020100
194+
195+
```C
196+
#define WOLFBOOT_SECTOR_SIZE 0x20000
197+
#define WOLFBOOT_PARTITION_SIZE 0x40000
198+
199+
#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x08020000
200+
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x08120000
201+
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x0 /* Unused, swap is hw-assisted */
202+
```
203+
204+
### Build Options
205+
206+
To activate the dual-bank hardware-assisted swap feature on STM32F76x/77x, use the
207+
`DUALBANK_SWAP=1` compile time option. Some code requires to run in RAM during the swapping
208+
of the images, so the compile-time option `RAMCODE=1` is also required in this case.
209+
210+
Dual-bank STM32F7 build can be built using:
211+
212+
```
213+
make TARGET=stm32f7 DUALBANK_SWAP=1 RAM_CODE=1
214+
```
215+
216+
217+
### Loading the firmware
218+
219+
To switch between single-bank (1x2MB) and dual-bank (2 x 1MB) mode mapping, this [stm32f7-dualbank-tool](https://github.com/danielinux/stm32f7-dualbank-tool)
220+
can be used.
221+
Before starting openocd, switch the flash mode to dualbank (e.g. via `make dualbank` using the dualbank tool).
222+
223+
OpenOCD configuration for flashing/debugging, can be copied into `openocd.cfg` in your working directory:
224+
225+
```
226+
source [find interface/stlink.cfg]
227+
source [find board/stm32f7discovery.cfg]
228+
$_TARGETNAME configure -event reset-init {
229+
mmw 0xe0042004 0x7 0x0
230+
}
231+
init
232+
reset
233+
halt
234+
```
235+
236+
OpenOCD can be either run in background (to allow remote GDB and monitor terminal connections), or
237+
directly from command line, to execute terminal scripts.
238+
239+
If OpenOCD is running, local TCP port 4444 can be used to access an interactive terminal prompt.
240+
241+
Using the following openocd commands, the initial images for wolfBoot and the test application
242+
are loaded to flash in bank 0:
243+
244+
```
245+
flash write_image unlock erase wolfboot.bin 0x08000000
246+
flash verify_bank 0 wolfboot.bin
247+
flash write_image unlock erase test-app/image_v1_signed.bin 0x08020000
248+
flash verify_bank 0 test-app/image_v1_signed.bin 0x20000
249+
reset
250+
resume 0x0000001
251+
```
252+
253+
To sign the same application image as new version (2), use the python script `sign.py` provided:
254+
255+
```
256+
tools/keytools/sign.py test-app/image.bin ed25519.der 2
257+
```
258+
259+
From OpenOCD, the updated image (version 2) can be flashed to the second bank:
260+
```
261+
flash write_image unlock erase test-app/image_v2_signed.bin 0x08120000
262+
flash verify_bank 0 test-app/image_v1_signed.bin 0x20000
263+
```
264+
265+
Upon reboot, wolfboot will elect the best candidate (version 2 in this case) and authenticate the image.
266+
If the accepted candidate image resides on BANK B (like in this case), wolfBoot will perform one bank swap before
267+
booting.
268+
269+
The bank-swap operation is immediate and a SWAP image is not required in this case. Fallback mechanism can rely on
270+
a second choice (older firmware) in the other bank.
271+
272+
273+
### Debugging
274+
275+
Debugging with OpenOCD:
276+
277+
Use the OpenOCD configuration from the previous section to run OpenOCD.
278+
279+
From another console, connect using gdb, e.g.:
280+
281+
```
282+
arm-none-eabi-gdb
283+
(gdb) target remote:3333
284+
```
285+
286+

docs/compile.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ both `PART_UPDATE_EXT` and `PART_SWAP_EXT` are defined.
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.
138138

139+
### Executing flash access code from RAM
140+
141+
On some platform, flash access code requires to be executed from RAM, to avoid conflict e.g. when writing
142+
to the same device where wolfBoot is executing, or when changing the configuration of the flash itself.
143+
144+
To move all the code accessing the internal flash for writing, into a section in RAM, use the compile time option
145+
`RAM_CODE=1` (on some hardware configurations this is required for the bootloader to access the flash for writing).
146+
147+
### Enable Dual-bank hardware-assisted swapping
148+
149+
When supported by the target platform, hardware-assisted dual-bank swapping can be used to perform updates.
150+
To enable this functionality, use `DUALBANK_SWAP=1`. Currently, only STM32F76x and F77x support this feature.
151+
139152
### Using Mac OS/X
140153

141154
If you see 0xC3 0xBF (C3BF) repeated in your factory.bin then your OS is using Unicode characters.
@@ -155,3 +168,4 @@ LC_ALL=
155168
```
156169

157170
Then run the normal `make` steps.
171+

0 commit comments

Comments
 (0)