You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/08/19 22:12:04 UTC
[05/12] incubator-mynewt-core git commit: bootutil;
add 'confirm' step, telling that image was confirmed as good.
Otherwise next restart we'll go back to old image.
bootutil; add 'confirm' step, telling that image was confirmed as good.
Otherwise next restart we'll go back to old image.
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/a54ebc54
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a54ebc54
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a54ebc54
Branch: refs/heads/develop
Commit: a54ebc54c968870a23d016d38bcba962bee1c477
Parents: 857e611
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Aug 18 16:52:23 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:50 2016 -0700
----------------------------------------------------------------------
libs/bootutil/include/bootutil/bootutil_misc.h | 1 +
libs/bootutil/src/bootutil_misc.c | 41 ++++++++++++++++++---
libs/bootutil/src/bootutil_priv.h | 8 ++--
libs/bootutil/src/loader.c | 14 ++++++-
4 files changed, 54 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a54ebc54/libs/bootutil/include/bootutil/bootutil_misc.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/include/bootutil/bootutil_misc.h b/libs/bootutil/include/bootutil/bootutil_misc.h
index 389366b..c018bb8 100644
--- a/libs/bootutil/include/bootutil/bootutil_misc.h
+++ b/libs/bootutil/include/bootutil/bootutil_misc.h
@@ -25,5 +25,6 @@ int boot_vect_read_test(int *slot);
int boot_vect_read_main(struct image_version *out_ver);
int boot_vect_write_test(int slot);
int boot_vect_write_main(struct image_version *ver);
+void boot_confirm_ok(void);
#endif /* __BOOTUTIL_MISC_H_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a54ebc54/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c b/libs/bootutil/src/bootutil_misc.c
index cf48f84..595bb52 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -22,6 +22,7 @@
#include <assert.h>
#include <hal/hal_flash.h>
#include <hal/flash_map.h>
+#include <hal/hal_bsp.h>
#include <os/os.h>
#include <console/console.h>
#include "bootutil/image.h"
@@ -54,7 +55,7 @@ boot_vect_read_test(int *slot)
if (rc) {
continue;
}
- if (bit.bit_start == BOOT_IMG_MAGIC) {
+ if (bit.bit_copy_start == BOOT_IMG_MAGIC) {
*slot = i;
return 0;
}
@@ -185,14 +186,14 @@ boot_read_status(struct boot_status *bs)
* Check if boot_img_trailer is in scratch, or at the end of slot0.
*/
boot_slot_magic(0, &bit);
- if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
+ if (bit.bit_copy_start == BOOT_IMG_MAGIC && bit.bit_copy_done == 0xff) {
boot_magic_loc(0, &flash_id, &off);
boot_read_status_bytes(bs, flash_id, off);
console_printf("status in slot0, %lu/%u\n", bs->idx, bs->state);
return 1;
}
boot_scratch_magic(&bit);
- if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
+ if (bit.bit_copy_start == BOOT_IMG_MAGIC && bit.bit_copy_done == 0xff) {
boot_scratch_loc(&flash_id, &off);
boot_read_status_bytes(bs, flash_id, off);
console_printf("status in scratch, %lu/%u\n", bs->idx, bs->state);
@@ -249,14 +250,44 @@ void
boot_clear_status(void)
{
uint32_t off;
- uint32_t val = BOOT_IMG_MAGIC;
+ uint8_t val = 0;
uint8_t flash_id;
/*
- * Write to slot 0;
+ * Write to slot 0; boot_img_trailer is the 8 bytes within image slot.
+ * Here we say that copy operation was finished.
*/
boot_magic_loc(0, &flash_id, &off);
off += sizeof(uint32_t);
hal_flash_write(flash_id, off, &val, sizeof(val));
}
+/*
+ * This must be called by the app to confirm that it is ok to keep booting
+ * to this image.
+ *
+ */
+void
+boot_confirm_ok(void)
+{
+ const struct flash_area *fap;
+ uint32_t off;
+ int rc;
+ uint8_t val;
+
+ /*
+ * Write to slot 0.
+ */
+ rc = flash_area_open(bsp_imgr_current_slot(), &fap);
+ if (rc) {
+ return;
+ }
+
+ off = fap->fa_size - sizeof(struct boot_img_trailer);
+ off += (sizeof(uint32_t) + sizeof(uint8_t));
+ rc = flash_area_read(fap, off, &val, sizeof(val));
+ if (!rc && val == 0xff) {
+ val = 0;
+ flash_area_write(fap, off, &val, sizeof(val));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a54ebc54/libs/bootutil/src/bootutil_priv.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_priv.h b/libs/bootutil/src/bootutil_priv.h
index 697145d..585f75c 100644
--- a/libs/bootutil/src/bootutil_priv.h
+++ b/libs/bootutil/src/bootutil_priv.h
@@ -46,12 +46,14 @@ struct boot_status {
};
/*
- * End-of-image data structure.
+ * End-of-image slot data structure.
*/
#define BOOT_IMG_MAGIC 0x12344321
struct boot_img_trailer {
- uint32_t bit_start;
- uint32_t bit_done;
+ uint32_t bit_copy_start;
+ uint8_t bit_copy_done;
+ uint8_t bit_img_ok;
+ uint16_t _pad;
};
int bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig, int slen,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a54ebc54/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index 3171c05..b144c83 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -200,10 +200,19 @@ boot_select_image_slot(void)
struct boot_img *b;
struct boot_img_trailer bit;
+ boot_slot_magic(0, &bit);
+ if (bit.bit_copy_start == BOOT_IMG_MAGIC && bit.bit_copy_done != 0xff &&
+ bit.bit_img_ok == 0xff) {
+ /*
+ * Copied the image successfully, but image was not confirmed as good.
+ * We need to go back to another image.
+ */
+ boot_vect_write_test(FLASH_AREA_IMAGE_1);
+ }
for (i = 1; i < BOOT_NUM_SLOTS; i++) {
b = &boot_img[i];
boot_slot_magic(i, &bit);
- if (bit.bit_start == BOOT_IMG_MAGIC) {
+ if (bit.bit_copy_start == BOOT_IMG_MAGIC) {
rc = boot_image_check(&b->hdr, &b->loc);
if (rc) {
/*
@@ -473,7 +482,8 @@ boot_go(const struct boot_req *req, struct boot_rsp *rsp)
}
/*
- * Check if we should initiate copy.
+ * Check if we should initiate copy, or revert back to earlier image.
+ *
*/
slot = boot_select_image_slot();
if (slot == -1) {