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 2017/02/06 22:57:00 UTC

[1/3] incubator-mynewt-core git commit: image_rsa: include missing string.h

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop e136d0896 -> 8092bf708


image_rsa: include missing string.h

Avoid warning when using memcmp.

Signed-off-by: Ricardo Salveti <ri...@linaro.org>


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/353857b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/353857b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/353857b5

Branch: refs/heads/develop
Commit: 353857b54d0e35ca63d17bc6b8fe19456da09ac5
Parents: e136d08
Author: Ricardo Salveti <ri...@linaro.org>
Authored: Wed Jan 18 11:41:39 2017 -0200
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Feb 6 14:53:00 2017 -0800

----------------------------------------------------------------------
 boot/bootutil/src/image_rsa.c | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/353857b5/boot/bootutil/src/image_rsa.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/src/image_rsa.c b/boot/bootutil/src/image_rsa.c
index 7b1f4d4..4890f46 100644
--- a/boot/bootutil/src/image_rsa.c
+++ b/boot/bootutil/src/image_rsa.c
@@ -17,6 +17,8 @@
  * under the License.
  */
 
+#include <string.h>
+
 #include "syscfg/syscfg.h"
 
 #if MYNEWT_VAL(BOOTUTIL_SIGN_RSA)


[3/3] incubator-mynewt-core git commit: Validate slot zero before booting

Posted by cc...@apache.org.
Validate slot zero before booting

Instead of just checking the upgrade image signature, check the
signature on each boot.  This helps to prevent rogue images being flash
by a means other than the upgrade process.

This feature is controlled by whether BOOTUTIL_VALIDATE_SLOT0 is
defined.


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/8092bf70
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8092bf70
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8092bf70

Branch: refs/heads/develop
Commit: 8092bf70896a8e55e4380e8e0277bed05a7fc61a
Parents: bf13e99
Author: David Brown <da...@linaro.org>
Authored: Wed Dec 14 07:59:48 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Feb 6 14:53:13 2017 -0800

----------------------------------------------------------------------
 boot/bootutil/src/loader.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8092bf70/boot/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index f2497af..cff5acd 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -551,13 +551,13 @@ split_image_check(struct image_header *app_hdr,
 }
 
 static int
-boot_validate_slot1(void)
+boot_validate_slot(int slot)
 {
     const struct flash_area *fap;
     int rc;
     
-    if (boot_data.imgs[1].hdr.ih_magic == 0xffffffff ||
-        boot_data.imgs[1].hdr.ih_flags & IMAGE_F_NON_BOOTABLE) {
+    if (boot_data.imgs[slot].hdr.ih_magic == 0xffffffff ||
+        boot_data.imgs[slot].hdr.ih_flags & IMAGE_F_NON_BOOTABLE) {
 
         /* No bootable image in slot 1; continue booting from slot 0. */
         return -1;
@@ -566,13 +566,14 @@ boot_validate_slot1(void)
     /* Image in slot 1 is invalid.  Erase the image and continue booting
      * from slot 0.
      */
-    rc = flash_area_open(FLASH_AREA_IMAGE_1, &fap);
+    rc = flash_area_open(flash_area_id_from_image_slot(slot), &fap);
     if (rc != 0) {
         return BOOT_EFLASH;
     }
 
-    if (boot_data.imgs[1].hdr.ih_magic != IMAGE_MAGIC ||
-        boot_image_check(&boot_data.imgs[1].hdr, fap) != 0) {
+    if ((boot_data.imgs[slot].hdr.ih_magic != IMAGE_MAGIC ||
+	 boot_image_check(&boot_data.imgs[slot].hdr, fap) != 0) &&
+	slot == 1) {
 
         /* Image in slot 1 is invalid.  Erase the image and continue booting
          * from slot 0.
@@ -608,7 +609,7 @@ boot_validated_swap_type(void)
     }
 
     /* Boot loader wants to switch to slot 1.  Ensure image is valid. */
-    rc = boot_validate_slot1();
+    rc = boot_validate_slot(1);
     if (rc != 0) {
         return BOOT_SWAP_TYPE_FAIL;
     }
@@ -1045,6 +1046,12 @@ boot_go(struct boot_rsp *rsp)
 
     switch (swap_type) {
     case BOOT_SWAP_TYPE_NONE:
+#ifdef BOOTUTIL_VALIDATE_SLOT0
+        rc = boot_validate_slot(0);
+        if (rc != 0) {
+            return BOOT_EBADIMAGE;
+        }
+#endif
         slot = 0;
         break;
 


[2/3] incubator-mynewt-core git commit: bootutil: Fix issue with align > 1

Posted by cc...@apache.org.
bootutil: Fix issue with align > 1

Some flash devices not only require writes to occur on an `align` byte
boundary, but also require that the writes be done in chunks of this
size as well.  Enhance the sections that write status bytes to write
more than a single status byte.


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/bf13e99e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/bf13e99e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/bf13e99e

Branch: refs/heads/develop
Commit: bf13e99ed1897317dc11032db03df22ae7cb92d4
Parents: 353857b
Author: David Brown <da...@linaro.org>
Authored: Mon Jan 23 15:50:58 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Feb 6 14:53:06 2017 -0800

----------------------------------------------------------------------
 boot/bootutil/src/bootutil_misc.c | 19 +++++++++++++------
 boot/bootutil/src/loader.c        |  9 ++++++++-
 2 files changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf13e99e/boot/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c
index 87895ba..2fe08e3 100644
--- a/boot/bootutil/src/bootutil_misc.c
+++ b/boot/bootutil/src/bootutil_misc.c
@@ -309,13 +309,17 @@ int
 boot_write_copy_done(const struct flash_area *fap)
 {
     uint32_t off;
-    uint8_t val;
     int rc;
+    uint8_t buf[8];
+    uint8_t align;
 
     off = boot_copy_done_off(fap);
 
-    val = 1;
-    rc = flash_area_write(fap, off, &val, 1);
+    align = hal_flash_align(fap->fa_device_id);
+    memset(buf, 0xFF, 8);
+    buf[0] = 1;
+
+    rc = flash_area_write(fap, off, buf, align);
     if (rc != 0) {
         return BOOT_EFLASH;
     }
@@ -327,13 +331,16 @@ int
 boot_write_image_ok(const struct flash_area *fap)
 {
     uint32_t off;
-    uint8_t val;
     int rc;
+    uint8_t buf[8];
+    uint8_t align;
 
     off = boot_image_ok_off(fap);
 
-    val = 1;
-    rc = flash_area_write(fap, off, &val, 1);
+    align = hal_flash_align(fap->fa_device_id);
+    memset(buf, 0xFF, 8);
+    buf[0] = 1;
+    rc = flash_area_write(fap, off, buf, align);
     if (rc != 0) {
         return BOOT_EFLASH;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf13e99e/boot/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index 1d9f71b..f2497af 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -462,6 +462,8 @@ boot_write_status(struct boot_status *bs)
     uint32_t off;
     int area_id;
     int rc;
+    uint8_t buf[8];
+    uint8_t align;
 
     if (bs->idx == 0) {
         /* Write to scratch. */
@@ -480,7 +482,12 @@ boot_write_status(struct boot_status *bs)
     off = boot_status_off(fap) +
           boot_status_internal_off(bs->idx, bs->state, boot_data.write_sz);
 
-    rc = flash_area_write(fap, off, &bs->state, 1);
+    align = hal_flash_align(fap->fa_device_id);
+    // ASSERT(align <= 8);
+    memset(buf, 0xFF, 8);
+    buf[0] = bs->state;
+
+    rc = flash_area_write(fap, off, buf, align);
     if (rc != 0) {
         rc = BOOT_EFLASH;
         goto done;