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/05/19 23:53:12 UTC
[1/3] incubator-mynewt-core git commit: slinky;
print out banner to console at bootup.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop f54eda03b -> 52e7b2fe3
slinky; print out banner to console at bootup.
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/ac2c20a3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ac2c20a3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ac2c20a3
Branch: refs/heads/develop
Commit: ac2c20a3062bc4f482c1763b457c3d24d14234df
Parents: f54eda0
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 25 14:45:03 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 16:49:59 2016 -0700
----------------------------------------------------------------------
apps/slinky/src/main.c | 11 +++++++++++
libs/imgmgr/include/imgmgr/imgmgr.h | 5 +++++
libs/imgmgr/src/imgmgr.c | 6 ++++++
3 files changed, 22 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2c20a3/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 5265417..f505cf2 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -30,6 +30,7 @@
#include <fs/fs.h>
#include <nffs/nffs.h>
#include <newtmgr/newtmgr.h>
+#include <bootutil/image.h>
#include <bootutil/bootutil_misc.h>
#include <imgmgr/imgmgr.h>
#include <assert.h>
@@ -260,6 +261,7 @@ main(int argc, char **argv)
{
int rc;
int cnt;
+ struct image_version ver;
/* NFFS_AREA_MAX is defined in the BSP-specified bsp.h header file. */
struct nffs_area_desc descs[NFFS_AREA_MAX + 1];
@@ -340,6 +342,15 @@ main(int argc, char **argv)
conf_load();
rc = init_tasks();
+
+ rc = imgr_my_version(&ver);
+ if (rc == 0) {
+ console_printf("\nSlinky %u.%u.%u.%u\n",
+ ver.iv_major, ver.iv_minor, ver.iv_revision,
+ (unsigned int)ver.iv_build_num);
+ } else {
+ console_printf("\nSlinky\n");
+ }
os_start();
/* os start should never return. If it does, this should be an error */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2c20a3/libs/imgmgr/include/imgmgr/imgmgr.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/include/imgmgr/imgmgr.h b/libs/imgmgr/include/imgmgr/imgmgr.h
index e5e3596..d007e7f 100644
--- a/libs/imgmgr/include/imgmgr/imgmgr.h
+++ b/libs/imgmgr/include/imgmgr/imgmgr.h
@@ -54,4 +54,9 @@ int imgr_ver_str(struct image_version *ver, char *dst);
*/
int imgr_read_info(int area_id, struct image_version *ver, uint8_t *hash);
+/*
+ * Returns version number of current image (if available).
+ */
+int imgr_my_version(struct image_version *ver);
+
#endif /* _IMGMGR_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2c20a3/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index 21d0225..b0a2f32 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@ -171,6 +171,12 @@ end:
return rc;
}
+int
+imgr_my_version(struct image_version *ver)
+{
+ return imgr_read_info(bsp_imgr_current_slot(), ver, NULL);
+}
+
/*
* Finds image given version number. Returns the slot number image is in,
* or -1 if not found.
[2/3] incubator-mynewt-core git commit: imgmgr;
send response via newtmgr on failures. Add rc to all responses
(except to image list). Reject image uploads if image is missing magic
number.
Posted by ma...@apache.org.
imgmgr; send response via newtmgr on failures.
Add rc to all responses (except to image list).
Reject image uploads if image is missing magic number.
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/910a7c69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/910a7c69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/910a7c69
Branch: refs/heads/develop
Commit: 910a7c692bb97c647f33490ea17fa4cc38fe246f
Parents: ac2c20a
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Apr 29 16:36:01 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 16:50:29 2016 -0700
----------------------------------------------------------------------
libs/imgmgr/src/imgmgr.c | 57 ++++++++++++++++++++++++--------
libs/imgmgr/src/imgmgr_boot.c | 66 ++++++++++++++++++++++++++++++++------
libs/imgmgr/src/imgmgr_fs.c | 65 ++++++++++++++++++++++++++-----------
3 files changed, 148 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/910a7c69/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index b0a2f32..f583d51 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@ -337,15 +337,16 @@ imgr_upload(struct nmgr_jbuf *njb)
rc = json_read_object(&njb->njb_buf, off_attr);
if (rc || off == UINT_MAX) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
len = strlen(img_data);
- if (!len) {
- return OS_EINVAL;
- }
- len = base64_decode(img_data, img_data);
- if (len < 0) {
- return OS_EINVAL;
+ if (len) {
+ len = base64_decode(img_data, img_data);
+ if (len < 0) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
}
if (off == 0) {
@@ -353,9 +354,14 @@ imgr_upload(struct nmgr_jbuf *njb)
/*
* Image header is the first thing in the image.
*/
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
hdr = (struct image_header *)img_data;
+ if (hdr->ih_magic != IMAGE_MAGIC) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
/*
* New upload.
@@ -402,8 +408,15 @@ imgr_upload(struct nmgr_jbuf *njb)
best = i;
}
if (best >= 0) {
+ if (imgr_state.upload.fa) {
+ flash_area_close(imgr_state.upload.fa);
+ imgr_state.upload.fa = NULL;
+ }
rc = flash_area_open(best, &imgr_state.upload.fa);
- assert(rc == 0);
+ if (rc) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
/*
* XXXX only erase if needed.
*/
@@ -413,24 +426,32 @@ imgr_upload(struct nmgr_jbuf *njb)
/*
* No slot where to upload!
*/
- return OS_EINVAL;
+ rc = NMGR_ERR_ENOMEM;
+ goto err;
}
} else if (off != imgr_state.upload.off) {
/*
* Invalid offset. Drop the data, and respond with the offset we're
* expecting data for.
*/
- rc = 0;
goto out;
}
- if (len && imgr_state.upload.fa) {
+ if (!imgr_state.upload.fa) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
+ if (len) {
rc = flash_area_write(imgr_state.upload.fa, imgr_state.upload.off,
img_data, len);
- assert(rc == 0);
+ if (rc) {
+ rc = NMGR_ERR_EINVAL;
+ goto err_close;
+ }
imgr_state.upload.off += len;
if (imgr_state.upload.size == imgr_state.upload.off) {
/* Done */
+ flash_area_close(imgr_state.upload.fa);
imgr_state.upload.fa = NULL;
}
}
@@ -439,11 +460,21 @@ out:
json_encode_object_start(enc);
+ JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
+ json_encode_object_entry(enc, "rc", &jv);
+
JSON_VALUE_UINT(&jv, imgr_state.upload.off);
json_encode_object_entry(enc, "off", &jv);
+
json_encode_object_finish(enc);
return 0;
+err_close:
+ flash_area_close(imgr_state.upload.fa);
+ imgr_state.upload.fa = NULL;
+err:
+ nmgr_jbuf_setoerr(njb, rc);
+ return 0;
}
int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/910a7c69/libs/imgmgr/src/imgmgr_boot.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_boot.c b/libs/imgmgr/src/imgmgr_boot.c
index 2927f3e..05cfa59 100644
--- a/libs/imgmgr/src/imgmgr_boot.c
+++ b/libs/imgmgr/src/imgmgr_boot.c
@@ -66,6 +66,7 @@ imgr_boot_read(struct nmgr_jbuf *njb)
int rc;
struct json_encoder *enc;
struct image_version ver;
+ struct json_value jv;
uint8_t hash[IMGMGR_HASH_LEN];
enc = &njb->njb_enc;
@@ -87,6 +88,9 @@ imgr_boot_read(struct nmgr_jbuf *njb)
imgr_ver_jsonstr(enc, "active", &ver);
}
+ JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
+ json_encode_object_entry(enc, "rc", &jv);
+
json_encode_object_finish(enc);
return 0;
@@ -108,28 +112,48 @@ imgr_boot_write(struct nmgr_jbuf *njb)
.attribute = NULL
}
};
+ struct json_encoder *enc;
+ struct json_value jv;
int rc;
struct image_version ver;
rc = json_read_object(&njb->njb_buf, boot_write_attr);
if (rc) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
rc = imgr_ver_parse(boot_write_attr[0].addr.string, &ver);
if (rc) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
rc = imgr_find_by_ver(&ver, hash);
if (rc < 0) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
rc = boot_vect_write_test(&ver);
if (rc) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
- return rc;
+
+ enc = &njb->njb_enc;
+
+ json_encode_object_start(enc);
+
+ JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
+ json_encode_object_entry(enc, "rc", &jv);
+
+ json_encode_object_finish(enc);
+
+ return 0;
+
+err:
+ nmgr_jbuf_setoerr(njb, rc);
+ return 0;
}
int
@@ -138,6 +162,7 @@ imgr_boot2_read(struct nmgr_jbuf *njb)
int rc;
struct json_encoder *enc;
struct image_version ver;
+ struct json_value jv;
uint8_t hash[IMGMGR_HASH_LEN];
enc = &njb->njb_enc;
@@ -165,6 +190,9 @@ imgr_boot2_read(struct nmgr_jbuf *njb)
imgr_hash_jsonstr(enc, "active", hash);
}
+ JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
+ json_encode_object_entry(enc, "rc", &jv);
+
json_encode_object_finish(enc);
return 0;
@@ -186,12 +214,15 @@ imgr_boot2_write(struct nmgr_jbuf *njb)
.attribute = NULL
}
};
+ struct json_encoder *enc;
+ struct json_value jv;
int rc;
struct image_version ver;
rc = json_read_object(&njb->njb_buf, boot_write_attr);
if (rc) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
base64_decode(hash_str, hash);
@@ -199,10 +230,27 @@ imgr_boot2_write(struct nmgr_jbuf *njb)
if (rc >= 0) {
rc = boot_vect_write_test(&ver);
if (rc) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EUNKNOWN;
+ goto err;
}
} else {
- rc = OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
- return rc;
+
+ enc = &njb->njb_enc;
+
+ json_encode_object_start(enc);
+
+ JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
+ json_encode_object_entry(&njb->njb_enc, "rc", &jv);
+
+ json_encode_object_finish(enc);
+
+ return 0;
+
+err:
+ nmgr_jbuf_setoerr(njb, rc);
+
+ return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/910a7c69/libs/imgmgr/src/imgmgr_fs.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_fs.c b/libs/imgmgr/src/imgmgr_fs.c
index 3ba5057..9ca3c7b 100644
--- a/libs/imgmgr/src/imgmgr_fs.c
+++ b/libs/imgmgr/src/imgmgr_fs.c
@@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
@@ -62,21 +62,25 @@ imgr_file_download(struct nmgr_jbuf *njb)
rc = json_read_object(&njb->njb_buf, dload_attr);
if (rc || off == UINT_MAX) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
rc = fs_open(tmp_str, FS_ACCESS_READ, &file);
if (rc || !file) {
- return OS_EINVAL;
+ rc = NMGR_ERR_ENOMEM;
+ goto err;
}
rc = fs_seek(file, off);
if (rc) {
- goto err;
+ rc = NMGR_ERR_EUNKNOWN;
+ goto err_close;
}
rc = fs_read(file, 32, tmp_str, &out_len);
if (rc) {
- goto err;
+ rc = NMGR_ERR_EUNKNOWN;
+ goto err_close;
}
out_len = base64_encode(tmp_str, out_len, img_data, 1);
@@ -96,12 +100,18 @@ imgr_file_download(struct nmgr_jbuf *njb)
}
fs_close(file);
+ JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
+ json_encode_object_entry(&njb->njb_enc, "rc", &jv);
+
json_encode_object_finish(enc);
return 0;
-err:
+
+err_close:
fs_close(file);
- return OS_EINVAL;
+err:
+ nmgr_jbuf_setoerr(njb, rc);
+ return 0;
}
int
@@ -144,13 +154,15 @@ imgr_file_upload(struct nmgr_jbuf *njb)
rc = json_read_object(&njb->njb_buf, off_attr);
if (rc || off == UINT_MAX) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
len = strlen(img_data);
if (len) {
len = base64_decode(img_data, img_data);
if (len < 0) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
}
@@ -162,30 +174,36 @@ imgr_file_upload(struct nmgr_jbuf *njb)
imgr_state.upload.size = size;
if (!strlen(file_name)) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
+ if (imgr_state.upload.file) {
+ fs_close(imgr_state.upload.file);
+ imgr_state.upload.file = NULL;
}
rc = fs_open(file_name, FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE,
&imgr_state.upload.file);
if (rc) {
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err;
}
} else if (off != imgr_state.upload.off) {
/*
* Invalid offset. Drop the data, and respond with the offset we're
* expecting data for.
*/
- rc = 0;
goto out;
}
- if (len && imgr_state.upload.file) {
+ if (!imgr_state.upload.file) {
+ rc = NMGR_ERR_EINVAL;
+ goto err;
+ }
+ if (len) {
rc = fs_write(imgr_state.upload.file, img_data, len);
if (rc) {
- /*
- fs_close(imgr_state.upload.file);
- */
- imgr_state.upload.file = NULL;
- return OS_EINVAL;
+ rc = NMGR_ERR_EINVAL;
+ goto err_close;
}
imgr_state.upload.off += len;
if (imgr_state.upload.size == imgr_state.upload.off) {
@@ -199,11 +217,22 @@ out:
json_encode_object_start(enc);
+ JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
+ json_encode_object_entry(&njb->njb_enc, "rc", &jv);
+
JSON_VALUE_UINT(&jv, imgr_state.upload.off);
json_encode_object_entry(enc, "off", &jv);
+
json_encode_object_finish(enc);
return 0;
+
+err_close:
+ fs_close(imgr_state.upload.file);
+ imgr_state.upload.file = NULL;
+err:
+ nmgr_jbuf_setoerr(njb, rc);
+ return 0;
}
#endif
[3/3] incubator-mynewt-core git commit: imgmgr;
fix return codes of image_get_info() when it sees corrupt image.
Posted by ma...@apache.org.
imgmgr; fix return codes of image_get_info() when it sees corrupt 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/52e7b2fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/52e7b2fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/52e7b2fe
Branch: refs/heads/develop
Commit: 52e7b2fe33f1682e0baf6a6919a0584be3ed202d
Parents: 910a7c6
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu May 5 15:02:41 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 16:50:52 2016 -0700
----------------------------------------------------------------------
libs/imgmgr/src/imgmgr.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/52e7b2fe/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index f583d51..cce4711 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@ -145,10 +145,9 @@ imgr_read_info(int area_id, struct image_version *ver, uint8_t *hash)
while (data_off + sizeof(*tlv) <= data_end) {
rc2 = flash_area_read(fa, data_off, tlv, sizeof(*tlv));
if (rc2) {
- break;
+ goto end;
}
if (tlv->it_type == 0xff && tlv->it_len == 0xffff) {
- rc = 1;
break;
}
if (tlv->it_type != IMAGE_TLV_SHA256 ||
@@ -158,14 +157,18 @@ imgr_read_info(int area_id, struct image_version *ver, uint8_t *hash)
}
data_off += sizeof(*tlv);
if (hash) {
+ if (data_off + IMGMGR_HASH_LEN > data_end) {
+ goto end;
+ }
rc2 = flash_area_read(fa, data_off, hash, IMGMGR_HASH_LEN);
if (rc2) {
- break;
+ goto end;
}
}
rc = 0;
- break;
+ goto end;
}
+ rc = 1;
end:
flash_area_close(fa);
return rc;