You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by pa...@apache.org on 2016/08/31 18:29:44 UTC

[2/2] incubator-mynewt-core git commit: MYNEWT-373

MYNEWT-373

Return better status when we fail to validate the split image. It can happen for two reasons.
1) we have an invalid image
2) we can't get RAM to validate (malloc)


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

Branch: refs/heads/develop
Commit: e803fa2b48c55c1dc5d37771ca739e78824d3e6d
Parents: 1149339
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Wed Aug 31 11:27:22 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Wed Aug 31 11:27:22 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/include/bootutil/loader.h |  4 ++++
 libs/bootutil/src/loader.c              | 30 ++++++++++++++++------------
 libs/split/include/split/split.h        |  4 +++-
 libs/split/src/split.c                  | 12 +++++------
 libs/split/src/split_config.c           |  2 --
 5 files changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e803fa2b/libs/bootutil/include/bootutil/loader.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/include/bootutil/loader.h b/libs/bootutil/include/bootutil/loader.h
index 76da0dd..75e0d01 100644
--- a/libs/bootutil/include/bootutil/loader.h
+++ b/libs/bootutil/include/bootutil/loader.h
@@ -74,6 +74,10 @@ boot_build_request(struct boot_req *preq, int area_descriptor_max);
 int
 boot_go(const struct boot_req *req, struct boot_rsp *rsp);
 
+
+#define SPLIT_GO_OK                 (0)
+#define SPLIT_GO_NON_MATCHING       (-1)
+#define SPLIT_GO_ERR                (-2)
 int
 split_go(int loader_slot, int split_slot, void **entry);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e803fa2b/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index 43635a0..e2d4cfa 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -607,40 +607,44 @@ split_go(int loader_slot, int split_slot, void **entry)
     /** Areas representing the beginning of image slots. */
     uint8_t img_starts[2];
     struct flash_area *descs;
+    uint32_t entry_val;
     struct boot_req req = {
         .br_slot_areas = img_starts,
     };
 
     descs = calloc(SPLIT_AREA_DESC_MAX, sizeof(struct flash_area));
     if (descs == NULL) {
-        return BOOT_ENOMEM;
+        return SPLIT_GO_ERR;
     }
 
     req.br_area_descs = descs;
 
     rc = boot_build_request(&req, SPLIT_AREA_DESC_MAX);
     if (rc != 0) {
-        return rc;
+        rc = SPLIT_GO_ERR;
+        goto split_app_go_end;
     }
 
     boot_req = &req;
 
     boot_image_info();
 
-    /* if this is not a bootable image and it validates, boot it
-     * TODO check flash config state */
-    if (!boot_image_bootable(&boot_img[split_slot].hdr) &&
-         split_image_check(&boot_img[split_slot].hdr,
+    /* Don't check the bootable image flag because we could really
+      * call a bootable or non-bootable image.  Just validate that
+      * the image check passes which is distinct from the normal check */
+    rc = split_image_check(&boot_img[split_slot].hdr,
                            &boot_img[split_slot].loc,
                            &boot_img[loader_slot].hdr,
-                           &boot_img[loader_slot].loc) == 0) {
-        uint32_t entry_val = (uint32_t) boot_img[split_slot].loc.bil_address +
-                             (uint32_t)  boot_img[split_slot].hdr.ih_hdr_size;
-            *entry = (void*) entry_val;
-            rc = 0;
-            goto split_app_go_end;
+                           &boot_img[loader_slot].loc);
+    if (rc != 0) {
+        rc = SPLIT_GO_NON_MATCHING;
+        goto split_app_go_end;
     }
-    rc =BOOT_EBADIMAGE;
+
+    entry_val = (uint32_t) boot_img[split_slot].loc.bil_address +
+                         (uint32_t)  boot_img[split_slot].hdr.ih_hdr_size;
+    *entry = (void*) entry_val;
+    rc = SPLIT_GO_OK;
 
 split_app_go_end:
     free(descs);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e803fa2b/libs/split/include/split/split.h
----------------------------------------------------------------------
diff --git a/libs/split/include/split/split.h b/libs/split/include/split/split.h
index 9396a9c..fa31369 100644
--- a/libs/split/include/split/split.h
+++ b/libs/split/include/split/split.h
@@ -50,7 +50,9 @@ split_app_init(void);
   * If toBoot is true, also performs the necessary steps
   * to prepare to boot.  An application may set toBoot to
   * false and call this function to check whether the split
-  * application is bootable */
+  * application is bootable.
+ * 
+ * @Returns zero on success, non-zero on failures */
 int
 split_app_go(void **entry, int toBoot);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e803fa2b/libs/split/src/split.c
----------------------------------------------------------------------
diff --git a/libs/split/src/split.c b/libs/split/src/split.c
index b868bf7..bcb7488 100644
--- a/libs/split/src/split.c
+++ b/libs/split/src/split.c
@@ -6,12 +6,11 @@
 #include <split/split.h>
 #include <split/split_priv.h>
 
+
 #define LOADER_IMAGE_SLOT    0
 #define SPLIT_IMAGE_SLOT    1
 #define SPLIT_TOTAL_IMAGES  2
 
-#define SPLIT_NO_BOOT  (1)
-
 void
 split_app_init(void) {
     int rc;
@@ -29,8 +28,9 @@ split_check_status(void) {
     void *entry;
     rc =split_go(LOADER_IMAGE_SLOT, SPLIT_IMAGE_SLOT, &entry);
 
-    if(rc) {
-        return SPLIT_NOT_MATCHING;
+    if(rc == SPLIT_GO_ERR) {
+        return SPLIT_INVALID;
+    } else if (rc) {
     }
     return SPLIT_MATCHING;
 }
@@ -54,12 +54,12 @@ split_app_go(void **entry, int toBoot) {
         /* if we can't read this, then we don't boot an app */
         rc = split_read_split(&split);
         if(rc) {
-            return SPLIT_NO_BOOT;
+            return -1;
         }
 
         /* if we are told not to, then we don't boot an app */
         if(split == SPLIT_NONE) {
-            return SPLIT_NO_BOOT;
+            return -1;
         }
 
         /* if this is a one-time test, reset the split mode */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e803fa2b/libs/split/src/split_config.c
----------------------------------------------------------------------
diff --git a/libs/split/src/split_config.c b/libs/split/src/split_config.c
index 5cce386..5f7cefa 100644
--- a/libs/split/src/split_config.c
+++ b/libs/split/src/split_config.c
@@ -9,8 +9,6 @@
 #define SPLIT_IMAGE_SLOT    1
 #define SPLIT_TOTAL_IMAGES  2
 
-#define SPLIT_NO_BOOT  (1)
-
 
 static char *split_conf_get(int argc, char **argv, char *buf, int max_len);
 static int split_conf_set(int argc, char **argv, char *val);