mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject [28/50] [abbrv] incubator-mynewt-core git commit: boot, imgmgr; return the slot number for test image.
Date Wed, 24 Aug 2016 00:53:42 GMT
boot, imgmgr; return the slot number for test 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/cc0317c4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/cc0317c4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/cc0317c4

Branch: refs/heads/master
Commit: cc0317c4b122f318064f3be8f11288ae08f74488
Parents: c29be5a
Author: Marko Kiiskila <marko@runtime.io>
Authored: Wed Aug 17 12:56:16 2016 -0700
Committer: Marko Kiiskila <marko@runtime.io>
Committed: Fri Aug 19 15:11:49 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/include/bootutil/bootutil_misc.h |  2 +-
 libs/bootutil/src/bootutil_misc.c              | 31 +++++++++++++++++----
 libs/imgmgr/src/imgmgr_boot.c                  | 13 ++++++---
 3 files changed, 36 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc0317c4/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 e8834db..389366b 100644
--- a/libs/bootutil/include/bootutil/bootutil_misc.h
+++ b/libs/bootutil/include/bootutil/bootutil_misc.h
@@ -21,7 +21,7 @@
 #define __BOOTUTIL_MISC_H_
 
 struct image_version;
-int boot_vect_read_test(struct image_version *out_ver);
+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);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc0317c4/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c b/libs/bootutil/src/bootutil_misc.c
index 3885af9..e353b62 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -30,14 +30,35 @@
  * Retrieves from the boot vector the version number of the test image (i.e.,
  * the image that has not been proven stable, and which will only run once).
  *
- * @param out_ver           On success, the test version gets written here.
+ * @param slot              On success, the slot number of image to boot.
  *
  * @return                  0 on success; nonzero on failure.
  */
 int
-boot_vect_read_test(struct image_version *out_ver)
+boot_vect_read_test(int *slot)
 {
-    return 0;
+    const struct flash_area *fap;
+    struct boot_img_trailer bit;
+    int i;
+    int rc;
+    uint32_t off;
+
+    for (i = FLASH_AREA_IMAGE_1; i <= FLASH_AREA_IMAGE_1; i++) {
+        rc = flash_area_open(i, &fap);
+        if (rc) {
+            continue;
+        }
+        off = fap->fa_size - sizeof(struct boot_img_trailer);
+        rc = flash_area_read(fap, off, &bit, sizeof(bit));
+        if (rc) {
+            continue;
+        }
+        if (bit.bit_start == BOOT_IMG_MAGIC) {
+            *slot = i;
+            return 0;
+        }
+    }
+    return -1;
 }
 
 /**
@@ -50,7 +71,7 @@ boot_vect_read_test(struct image_version *out_ver)
 int
 boot_vect_read_main(struct image_version *out_ver)
 {
-    return 0;
+    return -1;
 }
 
 /**
@@ -85,7 +106,7 @@ boot_vect_write_test(int slot)
 int
 boot_vect_write_main(struct image_version *ver)
 {
-    return 0;
+    return -1;
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc0317c4/libs/imgmgr/src/imgmgr_boot.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_boot.c b/libs/imgmgr/src/imgmgr_boot.c
index c0277b1..c252b9c 100644
--- a/libs/imgmgr/src/imgmgr_boot.c
+++ b/libs/imgmgr/src/imgmgr_boot.c
@@ -63,6 +63,7 @@ imgr_boot_read(struct nmgr_jbuf *njb)
 {
     int rc;
     struct json_encoder *enc;
+    int slot;
     struct image_version ver;
     struct json_value jv;
     uint8_t hash[IMGMGR_HASH_LEN];
@@ -71,9 +72,12 @@ imgr_boot_read(struct nmgr_jbuf *njb)
 
     json_encode_object_start(enc);
 
-    rc = boot_vect_read_test(&ver);
+    rc = boot_vect_read_test(&slot);
     if (!rc) {
-        imgr_ver_jsonstr(enc, "test", &ver);
+        rc = imgr_read_info(slot, &ver, hash);
+        if (!rc) {
+            imgr_ver_jsonstr(enc, "test", &ver);
+        }
     }
 
     rc = boot_vect_read_main(&ver);
@@ -161,14 +165,15 @@ imgr_boot2_read(struct nmgr_jbuf *njb)
     struct image_version ver;
     struct json_value jv;
     uint8_t hash[IMGMGR_HASH_LEN];
+    int slot;
 
     enc = &njb->njb_enc;
 
     json_encode_object_start(enc);
 
-    rc = boot_vect_read_test(&ver);
+    rc = boot_vect_read_test(&slot);
     if (!rc) {
-        rc = imgr_find_by_ver(&ver, hash);
+        rc = imgr_read_info(slot, &ver, hash);
         if (rc >= 0) {
             imgr_hash_jsonstr(enc, "test", hash);
         }


Mime
View raw message