@@ -237,7 +237,48 @@ Where:
237237 ` image-slot-size ` is the size of the image slot.
238238 ` image-trailer-size ` is the size of the image trailer.
239239
240- ### [ Swap without using scratch] ( #image-swap-no-scratch )
240+ ### [ Swap using offset (without using scratch)] ( #image-swap-offset-no-scratch )
241+
242+ This algorithm is an alternative to the swap-using-scratch algorithm and an
243+ enhancement of the swap using move algorithm.
244+ It uses an additional sector in the secondary slot to make swap possible.
245+ The algorithm works as follows:
246+
247+ 1. Update image must be placed starting at the second sector in the secondary slot
248+ 2. Copies the N-th sector from the primary slot to the N-th sector of the
249+ secondary slot.
250+ 3. Copies the (N+1)-th sector from the secondary slot to the N-th sector of the
251+ primary slot.
252+ 4. Repeats steps 2. and 3. until all the slots' sectors are swapped.
253+
254+ This algorithm is designed so that the lower sector of the secondary slot is
255+ used only for allowing sectors to move down during a swap. Therefore the most
256+ memory-size-effective slot layout is when the secondary slot is larger than
257+ the primary slot by exactly one sector, although same-sized slots are allowed
258+ as well. The algorithm is limited to support sectors of the same sector layout.
259+ All slot's sectors should be of the same size. This algorithm uses 2 flags per
260+ sector update rather than the 3 flags used by swap using move, which requires
261+ a smaller swap status area size.
262+
263+ When using this algorithm the maximum image size available for the application
264+ will be:
265+ ```
266+ maximum-image-size1 = N * slot-sector-size - image-trailer-sectors-size
267+ ```
268+
269+ Where:
270+ ` N ` is the number of sectors in the primary slot.
271+ ` image-trailer-sectors-size ` is the size of the image trailer rounded up to
272+ the total size of sectors its occupied. For instance if the image-trailer-size
273+ is equal to 1056 B and the sector size is equal to 1024 B, then
274+ ` image-trailer-sectors-size ` will be equal to 2048 B.
275+
276+ The algorithm does one erase cycle on both the primary and secondary slots
277+ during each swap.
278+
279+ The algorithm is enabled using the ` MCUBOOT_SWAP_USING_OFFSET ` option.
280+
281+ ### [ Swap using move (without using scratch)] ( #image-swap-no-scratch )
241282
242283This algorithm is an alternative to the swap-using-scratch algorithm.
243284It uses an additional sector in the primary slot to make swap possible.
@@ -635,7 +676,17 @@ types described above via a set of tables. These tables are reproduced below.
635676---
636677
637678```
638- State I
679+ State I (swap using offset only)
680+ | primary slot | secondary slot |
681+ -----------------+--------------+----------------|
682+ magic | Any | Good |
683+ image-ok | Any | Unset |
684+ copy-done | Any | Set |
685+ -----------------+--------------+----------------'
686+ result: BOOT_SWAP_TYPE_REVERT |
687+ -------------------------------------------------'
688+
689+ State II
639690 | primary slot | secondary slot |
640691 -----------------+--------------+----------------|
641692 magic | Any | Good |
@@ -646,7 +697,7 @@ types described above via a set of tables. These tables are reproduced below.
646697 -------------------------------------------------'
647698
648699
649- State II
700+ State III
650701 | primary slot | secondary slot |
651702 -----------------+--------------+----------------|
652703 magic | Any | Good |
@@ -657,7 +708,7 @@ types described above via a set of tables. These tables are reproduced below.
657708 -------------------------------------------------'
658709
659710
660- State III
711+ State IV
661712 | primary slot | secondary slot |
662713 -----------------+--------------+----------------|
663714 magic | Good | Any |
@@ -674,7 +725,7 @@ Otherwise, MCUboot does not attempt to swap images, resulting in one of the
674725other three swap types, as illustrated by State IV.
675726
676727```
677- State IV
728+ State V
678729 | primary slot | secondary slot |
679730 -----------------+--------------+----------------|
680731 magic | Any | Any |
@@ -687,7 +738,7 @@ other three swap types, as illustrated by State IV.
687738 -------------------------------------------------'
688739```
689740
690- In State IV , when no errors occur, MCUboot will attempt to boot the contents of
741+ In State V , when no errors occur, MCUboot will attempt to boot the contents of
691742the primary slot directly, and the result is ` BOOT_SWAP_TYPE_NONE ` . If the image
692743in the primary slot is not valid, the result is ` BOOT_SWAP_TYPE_FAIL ` . If a
693744fatal error occurs during boot, the result is ` BOOT_SWAP_TYPE_PANIC ` . If the
@@ -979,7 +1030,10 @@ the middle of an image swap operation. The swap status region consists of a
9791030series of single-byte records. These records are written independently, and
9801031therefore must be padded according to the minimum write size imposed by the
9811032flash hardware. The structure of the swap status region is illustrated below.
982- In this figure, a min-write-size of 1 is assumed for simplicity.
1033+ In this figure, a min-write-size of 1 is assumed for simplicity, this diagram
1034+ shows 3 states per sector which is applicable to swap using scratch and swap
1035+ using move, however in swap using offset mode there are only 2 states per
1036+ sector and the overall state size required is less.
9831037
9841038```
9851039 0 1 2 3
@@ -1040,14 +1094,15 @@ values map to the above four states as follows
10401094
10411095The swap status region can accommodate ` BOOT_MAX_IMG_SECTORS ` sector indices.
10421096Hence, the size of the region, in bytes, is
1043- ` BOOT_MAX_IMG_SECTORS * min-write-size * 3 ` . The only requirement for the index
1044- count is that it is great enough to account for a maximum-sized image
1045- (i.e., at least as great as the total sector count in an image slot). If a
1046- device's image slots have been configured with ` BOOT_MAX_IMG_SECTORS: 128 ` and
1047- use less than 128 sectors, the first record that gets written will be somewhere
1048- in the middle of the region. For example, if a slot uses 64 sectors, the first
1049- sector index that gets swapped is 63, which corresponds to the exact halfway
1050- point within the region.
1097+ ` BOOT_MAX_IMG_SECTORS * min-write-size * s ` where ` s ` is 3 for swap using
1098+ scratch and swap using move modes, and is 2 for swap using offset mode. The
1099+ only requirement for the index count is that it is great enough to account
1100+ for a maximum-sized image (i.e., at least as great as the total sector count in
1101+ an image slot). If a device's image slots have been configured with
1102+ ` BOOT_MAX_IMG_SECTORS: 128 ` and use less than 128 sectors, the first record
1103+ that gets written will be somewhere in the middle of the region. For example,
1104+ if a slot uses 64 sectors, the first sector index that gets swapped is 63,
1105+ which corresponds to the exact halfway point within the region.
10511106
10521107---
10531108*** Note***
0 commit comments