Skip to content

Commit 0b7b7ae

Browse files
nordicjmd3zd3z
authored andcommitted
docs: zephyr: Add note on swap-using-scratch
Adds details on how to use the swap-using-scratch algorithm and associated risks. Signed-off-by: Jamie McCrae <[email protected]>
1 parent 94360d5 commit 0b7b7ae

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/readme-zephyr.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ partitions defined in its device tree. These partitions are:
1515
- `boot_partition`: for MCUboot itself
1616
- `slot0_partition`: the primary slot of Image 0
1717
- `slot1_partition`: the secondary slot of Image 0
18+
19+
It is not recommended to use the swap-using-scratch algorithm of MCUboot, but
20+
if this operating mode is desired then the following flash partition is also
21+
needed (see end of this help file for details on creating a scratch partition
22+
and how to use the swap-using-scratch algorithm):
23+
1824
- `scratch_partition`: the scratch slot
1925

2026
Currently, the two image slots must be contiguous. If you are running
@@ -156,3 +162,50 @@ although MCUboot's key management infrastructure supports multiple keypairs.
156162

157163
Once MCUboot is built, this new keypair file (`mykey.pem` in this
158164
example) can be used to sign images.
165+
166+
## Using swap-using-scratch flash algorithm
167+
168+
To use the swap-using-scratch flash algorithm, a scratch partition needs to be
169+
present for the target board which is used for holding the data being swapped
170+
from both slots, this section must be at least as big as the largest sector
171+
size of the 2 partitions (e.g. if a device has a primary slot in main flash
172+
with a sector size of 512 bytes and secondar slot in external off-chip flash
173+
with a sector size of 4KB then the scratch area must be at least 4KB in size).
174+
The number of sectors must also be evenly divisable by this sector size, e.g.
175+
4KB, 8KB, 12KB, 16KB are allowed, 7KB, 7.5KB are not. This scratch partition
176+
needs adding to the .dts file for the board, e.g. for the nrf52dk_nrf52832
177+
board thus would involve updating
178+
`<zephyr>/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts` with:
179+
180+
```
181+
boot_partition: partition@0 {
182+
label = "mcuboot";
183+
reg = <0x00000000 0xc000>;
184+
};
185+
slot0_partition: partition@c000 {
186+
label = "image-0";
187+
reg = <0x0000C000 0x37000>;
188+
};
189+
slot1_partition: partition@43000 {
190+
label = "image-1";
191+
reg = <0x00043000 0x37000>;
192+
};
193+
storage_partition: partition@7a000 {
194+
label = "storage";
195+
reg = <0x0007a000 0x00006000>;
196+
};
197+
```
198+
199+
Which would make the application size 220KB and scratch size 24KB (the nRF52832
200+
has a 4KB sector size so the size of the scratch partition can be reduced at
201+
the cost of vastly reducing flash lifespan, e.g. for a 32KB firmware update
202+
with an 8KB scratch area, the scratch area would be erased and programmed 8
203+
times per image upgrade/revert). To configure MCUboot to work in
204+
swap-using-scratch mode, the Kconfig value must be set when building it:
205+
`CONFIG_BOOT_SWAP_USING_SCRATCH=y`.
206+
207+
Note that it is possible for an application to get into a stuck state when
208+
swap-using-scratch is used whereby an application has loaded a firmware update
209+
and marked it as test/confirmed but MCUboot will not swap the images and
210+
erasing the secondary slot from the zephyr application returns an error
211+
because the slot is marked for upgrade.

0 commit comments

Comments
 (0)