You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/12/21 18:20:41 UTC
incubator-mynewt-core git commit: MYNEWT-518 boot - Allow
test+confirm as single act
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 20304feca -> 19f534b80
MYNEWT-518 boot - Allow test+confirm as single act
Currently, to permanently run the alternate image, the boot loader
requires the following sequence:
1. image test <slot-01-hash>
2. reboot
3. image confirm
The new feature is to remove the need for the third step. The user
should be able to permanently switch images with this sequence:
1. image confirm <slot-01-hash>
2. reboot
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/19f534b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/19f534b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/19f534b8
Branch: refs/heads/develop
Commit: 19f534b801454ab8a5e1fb2f585a522eba07e3d9
Parents: 20304fe
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Dec 21 10:10:51 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Dec 21 10:20:33 2016 -0800
----------------------------------------------------------------------
boot/bootutil/include/bootutil/bootutil.h | 2 +-
boot/bootutil/src/bootutil_misc.c | 19 ++++--
boot/bootutil/test/src/boot_test.c | 4 ++
boot/bootutil/test/src/boot_test.h | 1 +
boot/bootutil/test/src/boot_test_utils.c | 12 ++++
.../test/src/testcases/boot_test_invalid_hash.c | 2 +-
.../src/testcases/boot_test_no_flag_has_hash.c | 2 +-
.../test/src/testcases/boot_test_no_hash.c | 2 +-
.../test/src/testcases/boot_test_nv_bs_11.c | 2 +-
.../src/testcases/boot_test_nv_bs_11_2areas.c | 2 +-
.../test/src/testcases/boot_test_nv_ns_01.c | 2 +-
.../test/src/testcases/boot_test_permanent.c | 54 +++++++++++++++++
.../testcases/boot_test_permanent_continue.c | 63 ++++++++++++++++++++
.../test/src/testcases/boot_test_vb_ns_11.c | 2 +-
.../test/src/testcases/boot_test_vm_ns_01.c | 2 +-
.../src/testcases/boot_test_vm_ns_11_2areas.c | 2 +-
.../test/src/testcases/boot_test_vm_ns_11_b.c | 2 +-
17 files changed, 160 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/include/bootutil/bootutil.h
----------------------------------------------------------------------
diff --git a/boot/bootutil/include/bootutil/bootutil.h b/boot/bootutil/include/bootutil/bootutil.h
index 4473da9..6d62aaa 100644
--- a/boot/bootutil/include/bootutil/bootutil.h
+++ b/boot/bootutil/include/bootutil/bootutil.h
@@ -53,7 +53,7 @@ int boot_go(struct boot_rsp *rsp);
int boot_swap_type(void);
-int boot_set_pending(void);
+int boot_set_pending(int permanent);
int boot_set_confirmed(void);
#define SPLIT_GO_OK (0)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c
index f3ab9d5..1119bc2 100644
--- a/boot/bootutil/src/bootutil_misc.c
+++ b/boot/bootutil/src/bootutil_misc.c
@@ -74,9 +74,11 @@ static const struct boot_swap_table boot_swap_tables[] = {
*----------+------------+------------|
* magic | Any | Good |
* image-ok | Any | N/A |
- * ---------+------------+------------'
- * swap: test |
- * -----------------------------------'
+ * ---------+------------+------------+---------------------------'
+ * swap: test |
+ * note: slot-1 image-ok val indicates whether swap is permanent; |
+ * (0xff=temporary; 0x01=permanent) |
+ * ---------------------------------------------------------------'
*/
.bsw_magic_slot0 = 0,
.bsw_magic_slot1 = BOOT_MAGIC_GOOD,
@@ -357,10 +359,15 @@ boot_swap_type(void)
* Marks the image in slot 1 as pending. On the next reboot, the system will
* perform a one-time boot of the slot 1 image.
*
+ * @param permanent Whether the image should be used permanently or
+ * only tested once:
+ * 0=run image once, then confirm or revert.
+ * 1=run image forever.
+ *
* @return 0 on success; nonzero on failure.
*/
int
-boot_set_pending(void)
+boot_set_pending(int permanent)
{
const struct flash_area *fap;
struct boot_swap_state state_slot1;
@@ -386,6 +393,10 @@ boot_set_pending(void)
rc = boot_write_magic(fap);
}
+ if (rc == 0 && permanent) {
+ rc = boot_write_image_ok(fap);
+ }
+
flash_area_close(fap);
return rc;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/boot_test.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test.c b/boot/bootutil/test/src/boot_test.c
index a0e8069..98972f3 100644
--- a/boot/bootutil/test/src/boot_test.c
+++ b/boot/bootutil/test/src/boot_test.c
@@ -51,6 +51,8 @@ TEST_CASE_DECL(boot_test_no_flag_has_hash)
TEST_CASE_DECL(boot_test_invalid_hash)
TEST_CASE_DECL(boot_test_revert)
TEST_CASE_DECL(boot_test_revert_continue)
+TEST_CASE_DECL(boot_test_permanent)
+TEST_CASE_DECL(boot_test_permanent_continue)
TEST_SUITE(boot_test_main)
{
@@ -71,6 +73,8 @@ TEST_SUITE(boot_test_main)
boot_test_invalid_hash();
boot_test_revert();
boot_test_revert_continue();
+ boot_test_permanent();
+ boot_test_permanent_continue();
}
int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/boot_test.h
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test.h b/boot/bootutil/test/src/boot_test.h
index 072dfbb..d0c1319 100644
--- a/boot/bootutil/test/src/boot_test.h
+++ b/boot/bootutil/test/src/boot_test.h
@@ -67,6 +67,7 @@ void boot_test_util_write_image(const struct image_header *hdr,
int slot);
void boot_test_util_write_hash(const struct image_header *hdr, int slot);
void boot_test_util_mark_revert(void);
+void boot_test_util_mark_swap_perm(void);
void boot_test_util_verify_area(const struct flash_area *area_desc,
const struct image_header *hdr,
uint32_t image_addr, int img_msb);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/boot_test_utils.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test_utils.c b/boot/bootutil/test/src/boot_test_utils.c
index dc6fbb0..355a5d9 100644
--- a/boot/bootutil/test/src/boot_test_utils.c
+++ b/boot/bootutil/test/src/boot_test_utils.c
@@ -323,6 +323,18 @@ boot_test_util_mark_revert(void)
}
void
+boot_test_util_mark_swap_perm(void)
+{
+ struct boot_swap_state state_slot0 = {
+ .magic = BOOT_MAGIC_GOOD,
+ .copy_done = 0x01,
+ .image_ok = 0x01,
+ };
+
+ boot_test_util_write_swap_state(FLASH_AREA_IMAGE_0, &state_slot0);
+}
+
+void
boot_test_util_verify_area(const struct flash_area *area_desc,
const struct image_header *hdr,
uint32_t image_addr, int img_msb)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c b/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c
index 515ab45..bac3f7e 100644
--- a/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c
+++ b/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c
@@ -52,7 +52,7 @@ TEST_CASE(boot_test_invalid_hash)
&tlv, sizeof(tlv));
TEST_ASSERT(rc == 0);
- rc = boot_set_pending();
+ rc = boot_set_pending(0);
TEST_ASSERT(rc == 0);
boot_test_util_verify_all(BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c b/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c
index 61c8f40..b6a8ec5 100644
--- a/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c
+++ b/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c
@@ -45,7 +45,7 @@ TEST_CASE(boot_test_no_flag_has_hash)
boot_test_util_write_image(&hdr1, 1);
boot_test_util_write_hash(&hdr1, 1);
- rc = boot_set_pending();
+ rc = boot_set_pending(0);
TEST_ASSERT(rc == 0);
boot_test_util_verify_all(BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_no_hash.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_no_hash.c b/boot/bootutil/test/src/testcases/boot_test_no_hash.c
index 639a1fb..13fe7e1 100644
--- a/boot/bootutil/test/src/testcases/boot_test_no_hash.c
+++ b/boot/bootutil/test/src/testcases/boot_test_no_hash.c
@@ -44,7 +44,7 @@ TEST_CASE(boot_test_no_hash)
boot_test_util_write_hash(&hdr0, 0);
boot_test_util_write_image(&hdr1, 1);
- rc = boot_set_pending();
+ rc = boot_set_pending(0);
TEST_ASSERT(rc == 0);
boot_test_util_verify_all(BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
index efa967e..eae13bd 100644
--- a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
@@ -46,7 +46,7 @@ TEST_CASE(boot_test_nv_bs_11)
boot_test_util_write_hash(&hdr0, 0);
boot_test_util_write_image(&hdr1, 1);
boot_test_util_write_hash(&hdr1, 1);
- rc = boot_set_pending();
+ rc = boot_set_pending(0);
boot_test_util_copy_area(5, BOOT_TEST_AREA_IDX_SCRATCH);
status.idx = 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
index eec22f8..ba09ea1 100644
--- a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
@@ -46,7 +46,7 @@ TEST_CASE(boot_test_nv_bs_11_2areas)
boot_test_util_write_hash(&hdr0, 0);
boot_test_util_write_image(&hdr1, 1);
boot_test_util_write_hash(&hdr1, 1);
- rc = boot_set_pending();
+ rc = boot_set_pending(0);
TEST_ASSERT_FATAL(rc == 0);
boot_test_util_swap_areas(2, 5);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c b/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
index 0481ef0..8abd90e 100644
--- a/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
@@ -33,7 +33,7 @@ TEST_CASE(boot_test_nv_ns_01)
boot_test_util_write_image(&hdr, 1);
boot_test_util_write_hash(&hdr, 1);
- boot_set_pending();
+ boot_set_pending(0);
boot_test_util_verify_all(BOOT_SWAP_TYPE_REVERT, NULL, &hdr);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_permanent.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_permanent.c b/boot/bootutil/test/src/testcases/boot_test_permanent.c
new file mode 100644
index 0000000..cb156af
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_permanent.c
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "boot_test.h"
+
+TEST_CASE(boot_test_permanent)
+{
+ int rc;
+
+ struct image_header hdr0 = {
+ .ih_magic = IMAGE_MAGIC,
+ .ih_tlv_size = 4 + 32,
+ .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+ .ih_img_size = 5 * 1024,
+ .ih_flags = IMAGE_F_SHA256,
+ .ih_ver = { 0, 5, 21, 432 },
+ };
+
+ struct image_header hdr1 = {
+ .ih_magic = IMAGE_MAGIC,
+ .ih_tlv_size = 4 + 32,
+ .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+ .ih_img_size = 32 * 1024,
+ .ih_flags = IMAGE_F_SHA256,
+ .ih_ver = { 1, 2, 3, 432 },
+ };
+
+ boot_test_util_init_flash();
+ boot_test_util_write_image(&hdr0, 0);
+ boot_test_util_write_hash(&hdr0, 0);
+ boot_test_util_write_image(&hdr1, 1);
+ boot_test_util_write_hash(&hdr1, 1);
+
+ rc = boot_set_pending(1);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ /* A permanent swap exhibits the same behavior as a revert. */
+ boot_test_util_verify_all(BOOT_SWAP_TYPE_REVERT, &hdr0, &hdr1);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_permanent_continue.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_permanent_continue.c b/boot/bootutil/test/src/testcases/boot_test_permanent_continue.c
new file mode 100644
index 0000000..83ad692
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_permanent_continue.c
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "boot_test.h"
+
+TEST_CASE(boot_test_permanent_continue)
+{
+ struct boot_status status;
+ int rc;
+
+ struct image_header hdr0 = {
+ .ih_magic = IMAGE_MAGIC,
+ .ih_tlv_size = 4 + 32,
+ .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+ .ih_img_size = 5 * 1024,
+ .ih_flags = IMAGE_F_SHA256,
+ .ih_ver = { 0, 5, 21, 432 },
+ };
+
+ struct image_header hdr1 = {
+ .ih_magic = IMAGE_MAGIC,
+ .ih_tlv_size = 4 + 32,
+ .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+ .ih_img_size = 32 * 1024,
+ .ih_flags = IMAGE_F_SHA256,
+ .ih_ver = { 1, 2, 3, 432 },
+ };
+
+ boot_test_util_init_flash();
+ boot_test_util_write_image(&hdr0, 0);
+ boot_test_util_write_hash(&hdr0, 0);
+ boot_test_util_write_image(&hdr1, 1);
+ boot_test_util_write_hash(&hdr1, 1);
+
+ /* Indicate that the image in slot 0 is being permanently used. */
+ boot_test_util_mark_swap_perm();
+
+ boot_test_util_swap_areas(2, 5);
+
+ status.idx = 1;
+ status.state = 0;
+
+ rc = boot_write_status(&status);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ /* A permanent swap exhibits the same behavior as a revert. */
+ boot_test_util_verify_all(BOOT_SWAP_TYPE_REVERT, &hdr0, &hdr1);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c b/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
index c6f7b93..e9b961d 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
@@ -46,7 +46,7 @@ TEST_CASE(boot_test_vb_ns_11)
boot_test_util_write_image(&hdr1, 1);
boot_test_util_write_hash(&hdr1, 1);
- rc = boot_set_pending();
+ rc = boot_set_pending(0);
TEST_ASSERT(rc == 0);
boot_test_util_verify_all(BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
index 3c89033..a539fa2 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
@@ -35,7 +35,7 @@ TEST_CASE(boot_test_vm_ns_01)
boot_test_util_write_image(&hdr, 1);
boot_test_util_write_hash(&hdr, 1);
- rc = boot_set_pending();
+ rc = boot_set_pending(0);
TEST_ASSERT(rc == 0);
boot_test_util_verify_all(BOOT_SWAP_TYPE_REVERT, NULL, &hdr);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
index 490a634..24b5da2 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
@@ -46,7 +46,7 @@ TEST_CASE(boot_test_vm_ns_11_2areas)
boot_test_util_write_image(&hdr1, 1);
boot_test_util_write_hash(&hdr1, 1);
- rc = boot_set_pending();
+ rc = boot_set_pending(0);
TEST_ASSERT(rc == 0);
boot_test_util_verify_all(BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/19f534b8/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
index 914242b..e1a87c7 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
@@ -46,7 +46,7 @@ TEST_CASE(boot_test_vm_ns_11_b)
boot_test_util_write_image(&hdr1, 1);
boot_test_util_write_hash(&hdr1, 1);
- rc = boot_set_pending();
+ rc = boot_set_pending(0);
TEST_ASSERT(rc == 0);
boot_test_util_verify_all(BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);