MYNEWT-518 - Clean up previous commit.
The previous commit for this ticket left the code in a working state.
However, it was not possible for image management to distinguish between
the test and permanent states.
Now, these two states are indicated by the addition of a new swap type:
BOOT_SWAP_TYPE_PERMANENT.
diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c
index c85f454..87895ba 100644
--- a/boot/bootutil/src/bootutil_misc.c
+++ b/boot/bootutil/src/bootutil_misc.c
@@ -45,6 +45,7 @@
uint8_t bsw_magic_slot0;
uint8_t bsw_magic_slot1;
uint8_t bsw_image_ok_slot0;
+ uint8_t bsw_image_ok_slot1;
uint8_t bsw_swap_type;
};
@@ -58,7 +59,7 @@
/* | slot-0 | slot-1 |
*----------+------------+------------|
* magic | Unset | Unset |
- * image-ok | Any | N/A |
+ * image-ok | Any | Any |
* ---------+------------+------------'
* swap: none |
* -----------------------------------'
@@ -66,6 +67,7 @@
.bsw_magic_slot0 = BOOT_MAGIC_UNSET,
.bsw_magic_slot1 = BOOT_MAGIC_UNSET,
.bsw_image_ok_slot0 = 0,
+ .bsw_image_ok_slot1 = 0,
.bsw_swap_type = BOOT_SWAP_TYPE_NONE,
},
@@ -73,24 +75,39 @@
/* | slot-0 | slot-1 |
*----------+------------+------------|
* magic | Any | Good |
- * image-ok | Any | [*] |
- * ---------+------------+------------+---------------------------'
- * swap: test |
- * note: slot-1 image-ok val indicates whether swap is permanent; |
- * (0xff=temporary; 0x01=permanent) |
- * ---------------------------------------------------------------'
+ * image-ok | Any | Unset |
+ * ---------+------------+------------`
+ * swap: test |
+ * -----------------------------------'
*/
.bsw_magic_slot0 = 0,
.bsw_magic_slot1 = BOOT_MAGIC_GOOD,
.bsw_image_ok_slot0 = 0,
+ .bsw_image_ok_slot1 = 0xff,
.bsw_swap_type = BOOT_SWAP_TYPE_TEST,
},
{
/* | slot-0 | slot-1 |
*----------+------------+------------|
+ * magic | Any | Good |
+ * image-ok | Any | 0x01 |
+ * ---------+------------+------------`
+ * swap: permanent |
+ * -----------------------------------'
+ */
+ .bsw_magic_slot0 = 0,
+ .bsw_magic_slot1 = BOOT_MAGIC_GOOD,
+ .bsw_image_ok_slot0 = 0,
+ .bsw_image_ok_slot1 = 0x01,
+ .bsw_swap_type = BOOT_SWAP_TYPE_PERM,
+ },
+
+ {
+ /* | slot-0 | slot-1 |
+ *----------+------------+------------|
* magic | Good | Unset |
- * image-ok | 0xff | N/A |
+ * image-ok | 0xff | Any |
* ---------+------------+------------'
* swap: revert (test image running) |
* -----------------------------------'
@@ -98,6 +115,7 @@
.bsw_magic_slot0 = BOOT_MAGIC_GOOD,
.bsw_magic_slot1 = BOOT_MAGIC_UNSET,
.bsw_image_ok_slot0 = 0xff,
+ .bsw_image_ok_slot1 = 0,
.bsw_swap_type = BOOT_SWAP_TYPE_REVERT,
},
@@ -105,7 +123,7 @@
/* | slot-0 | slot-1 |
*----------+------------+------------|
* magic | Good | Unset |
- * image-ok | 0x01 | N/A |
+ * image-ok | 0x01 | Any |
* ---------+------------+------------'
* swap: none (confirmed test image) |
* -----------------------------------'
@@ -113,6 +131,7 @@
.bsw_magic_slot0 = BOOT_MAGIC_GOOD,
.bsw_magic_slot1 = BOOT_MAGIC_UNSET,
.bsw_image_ok_slot0 = 0x01,
+ .bsw_image_ok_slot1 = 0,
.bsw_swap_type = BOOT_SWAP_TYPE_NONE,
},
};
@@ -345,7 +364,9 @@
(table->bsw_magic_slot1 == 0 ||
table->bsw_magic_slot1 == state_slot1.magic) &&
(table->bsw_image_ok_slot0 == 0 ||
- table->bsw_image_ok_slot0 == state_slot0.image_ok)) {
+ table->bsw_image_ok_slot0 == state_slot0.image_ok) &&
+ (table->bsw_image_ok_slot1 == 0 ||
+ table->bsw_image_ok_slot1 == state_slot1.image_ok)) {
return table->bsw_swap_type;
}
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index e4dfc61..fc20fdb 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -143,6 +143,7 @@
static const uint8_t boot_swap_trans_table[][2] = {
/* From To */
{ BOOT_SWAP_TYPE_REVERT, BOOT_SWAP_TYPE_NONE },
+ { BOOT_SWAP_TYPE_PERM, BOOT_SWAP_TYPE_NONE },
{ BOOT_SWAP_TYPE_TEST, BOOT_SWAP_TYPE_REVERT },
};
@@ -974,6 +975,7 @@
swap_type = boot_validated_swap_type();
switch (swap_type) {
case BOOT_SWAP_TYPE_TEST:
+ case BOOT_SWAP_TYPE_PERM:
case BOOT_SWAP_TYPE_REVERT:
rc = boot_copy_image(&bs);
assert(rc == 0);
@@ -1040,6 +1042,7 @@
break;
case BOOT_SWAP_TYPE_TEST:
+ case BOOT_SWAP_TYPE_PERM:
slot = 1;
boot_finalize_test_swap();
break;