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/01/22 22:10:03 UTC

incubator-mynewt-larva git commit: Add len field to first upload request.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 9bbdfc582 -> df59850fe


Add len field to first upload request.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/df59850f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/df59850f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/df59850f

Branch: refs/heads/master
Commit: df59850fe214f13aaae9045aa18035d00a04ccb3
Parents: 9bbdfc5
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Jan 22 13:09:01 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Jan 22 13:09:01 2016 -0800

----------------------------------------------------------------------
 libs/imgmgr/src/imgmgr.c      | 17 +++++++++++++++--
 libs/imgmgr/src/imgmgr_priv.h |  6 ++++--
 2 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/df59850f/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index 5b76b61..9818071 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@ -64,6 +64,7 @@ static struct nmgr_group imgr_nmgr_group = {
 static struct {
     struct {
         uint32_t off;
+        uint32_t size;
         const struct flash_area *fa;
     } upload;
 } img_state;
@@ -149,7 +150,8 @@ imgr_upload(struct nmgr_jbuf *njb)
 {
     char img_data[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
     unsigned int off = UINT_MAX;
-    const struct json_attr_t off_attr[3] = {
+    unsigned int size = UINT_MAX;
+    const struct json_attr_t off_attr[4] = {
         [0] = {
             .attribute = "off",
             .type = t_uinteger,
@@ -161,6 +163,12 @@ imgr_upload(struct nmgr_jbuf *njb)
             .type = t_string,
             .addr.string = img_data,
             .len = sizeof(img_data)
+        },
+        [2] = {
+            .attribute = "len",
+            .type = t_uinteger,
+            .addr.uinteger = &size,
+            .nodefault = true
         }
     };
     struct image_version ver;
@@ -189,6 +197,7 @@ imgr_upload(struct nmgr_jbuf *njb)
          * New upload.
          */
         img_state.upload.off = 0;
+        img_state.upload.size = size;
         active = bsp_imgr_current_slot();
         best = -1;
 
@@ -248,11 +257,15 @@ imgr_upload(struct nmgr_jbuf *njb)
         goto out;
     }
 
-    if (len) {
+    if (len && img_state.upload.fa) {
         rc = flash_area_write(img_state.upload.fa, img_state.upload.off,
           img_data, len);
         assert(rc == 0);
         img_state.upload.off += len;
+        if (img_state.upload.size == img_state.upload.off) {
+            /* Done */
+            img_state.upload.fa = NULL;
+        }
     }
 out:
     enc = &njb->njb_enc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/df59850f/libs/imgmgr/src/imgmgr_priv.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_priv.h b/libs/imgmgr/src/imgmgr_priv.h
index 99193b4..ff13a0c 100644
--- a/libs/imgmgr/src/imgmgr_priv.h
+++ b/libs/imgmgr/src/imgmgr_priv.h
@@ -46,16 +46,18 @@ struct imgmgr_upload_cmd {
  *      "active":<version>
  * }
  *
- * Request to upload:
+ * Request to image upload:
  * {
  *      "off":<offset>,
+ *      "len":<img_size>		inspected when off = 0
  *      "data":<base64encoded binary>
  * }
  *
  * Response to upload:
  * {
- *      "off":<offset
+ *      "off":<offset>
  * }
+ *
  */
 
 struct nmgr_hdr;