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/19 00:26:09 UTC
[1/3] incubator-mynewt-larva git commit: fs_root_ops symbol was
getting dropped with some projects.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master 35b6f852a -> ccc970cd7
fs_root_ops symbol was getting dropped with some projects.
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/344782a7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/344782a7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/344782a7
Branch: refs/heads/master
Commit: 344782a72e29814166c0e380fbe1da266e736597
Parents: 35b6f85
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Jan 18 15:18:42 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Jan 18 15:18:42 2016 -0800
----------------------------------------------------------------------
fs/fs/src/fs_mount.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/344782a7/fs/fs/src/fs_mount.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_mount.c b/fs/fs/src/fs_mount.c
index e452cf2..41d2688 100644
--- a/fs/fs/src/fs_mount.c
+++ b/fs/fs/src/fs_mount.c
@@ -17,7 +17,7 @@
#include <fs/fs_if.h>
#include "fs_priv.h"
-const struct fs_ops *fs_root_ops;
+const struct fs_ops *fs_root_ops = NULL;
int
fs_register(const struct fs_ops *fops)
[2/3] incubator-mynewt-larva git commit: Start encoding imgmgr newt
command payloads in json.
Posted by ma...@apache.org.
Start encoding imgmgr newt command payloads in json.
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/a519dacc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/a519dacc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/a519dacc
Branch: refs/heads/master
Commit: a519dacc55be535813be9cab96cc4942cdc492f5
Parents: 344782a
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Jan 18 15:23:34 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Jan 18 15:23:34 2016 -0800
----------------------------------------------------------------------
libs/imgmgr/include/imgmgr/imgmgr.h | 3 +
libs/imgmgr/src/imgmgr.c | 98 ++++++++++++++++++++++++++------
libs/imgmgr/src/imgmgr_fs.c | 82 +++++++++++++++++++-------
libs/imgmgr/src/imgmgr_priv.h | 26 ++++++---
4 files changed, 162 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a519dacc/libs/imgmgr/include/imgmgr/imgmgr.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/include/imgmgr/imgmgr.h b/libs/imgmgr/include/imgmgr/imgmgr.h
index 3e602ca..7fa580f 100644
--- a/libs/imgmgr/include/imgmgr/imgmgr.h
+++ b/libs/imgmgr/include/imgmgr/imgmgr.h
@@ -25,4 +25,7 @@
int imgmgr_module_init(void);
+struct image_version;
+int imgr_ver_parse(char *src, struct image_version *ver);
+
#endif /* _IMGMGR_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a519dacc/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index 8368216..1df0a36 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@ -19,6 +19,7 @@
#include <limits.h>
#include <assert.h>
#include <string.h>
+#include <stdio.h>
#include <hal/flash_map.h>
#include <newtmgr/newtmgr.h>
@@ -42,11 +43,16 @@ static const struct nmgr_handler imgr_nmgr_handlers[] = {
[IMGMGR_NMGR_OP_UPLOAD] = {
.nh_read = imgr_noop,
.nh_write = imgr_upload
- },
+ }
+#ifdef FS_PRESENT
+ ,
[IMGMGR_NMGR_OP_BOOT] = {
.nh_read = imgr_boot_read,
.nh_write = imgr_boot_write
}
+#else
+ goob
+#endif
};
static struct nmgr_group imgr_nmgr_group = {
@@ -95,23 +101,73 @@ imgr_read_ver(int area_id, struct image_version *ver)
return rc;
}
-void
-imgr_ver_hton(struct image_version *ver)
+int
+imgr_ver_parse(char *src, struct image_version *ver)
{
- ver->iv_revision = htons(ver->iv_revision);
- ver->iv_build_num = htonl(ver->iv_build_num);
+ unsigned long ul;
+ char *tok;
+ char *nxt;
+ char *ep;
+
+ memset(ver, 0, sizeof(*ver));
+
+ nxt = src;
+ tok = strsep(&nxt, ".");
+ ul = strtoul(tok, &ep, 10);
+ if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
+ return -1;
+ }
+ ver->iv_major = ul;
+ if (nxt == NULL) {
+ return 0;
+ }
+ tok = strsep(&nxt, ".");
+ ul = strtoul(tok, &ep, 10);
+ if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
+ return -1;
+ }
+ ver->iv_minor = ul;
+ if (nxt == NULL) {
+ return 0;
+ }
+
+ tok = strsep(&nxt, ".");
+ ul = strtoul(tok, &ep, 10);
+ if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT16_MAX) {
+ return -1;
+ }
+ ver->iv_revision = ul;
+ if (nxt == NULL) {
+ return 0;
+ }
+
+ tok = nxt;
+ ul = strtoul(tok, &ep, 10);
+ if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT32_MAX) {
+ return -1;
+ }
+ ver->iv_build_num = ul;
+
+ return 0;
}
-static int
-imgr_nmgr_append_ver(struct nmgr_hdr *rsp_hdr, struct os_mbuf *rsp,
- struct image_version *to_write)
+int
+imgr_ver_jsonstr(char *dst, int dstlen, char *key, struct image_version *ver)
{
- struct image_version ver;
-
- ver = *to_write;
- imgr_ver_hton(&ver);
+ int off = 0;
- return (nmgr_rsp_extend(rsp_hdr, rsp, &ver, sizeof(ver)));
+ if (key) {
+ off = snprintf(dst, dstlen, "\"%s\":", key);
+ }
+ if (ver->iv_build_num) {
+ off += snprintf(dst + off, dstlen - off, "\"%u.%u.%u.%lu\"",
+ ver->iv_major, ver->iv_minor, ver->iv_revision,
+ (unsigned long)ver->iv_build_num);
+ } else {
+ off += snprintf(dst + off, dstlen - off, "\"%u.%u.%u\"",
+ ver->iv_major, ver->iv_minor, ver->iv_revision);
+ }
+ return off;
}
static int
@@ -119,21 +175,27 @@ imgr_list(struct nmgr_hdr *nmr, struct os_mbuf *req, uint16_t srcoff,
struct nmgr_hdr *rsp_hdr, struct os_mbuf *rsp)
{
struct image_version ver;
+ char str[128];
+ int off;
int rc;
int i;
+ int put_comma = 0;
+ off = snprintf(str, sizeof(str), "{\"images\":[");
for (i = FLASH_AREA_IMAGE_0; i <= FLASH_AREA_IMAGE_1; i++) {
rc = imgr_read_ver(i, &ver);
if (rc < 0) {
continue;
}
- rc = imgr_nmgr_append_ver(rsp_hdr, rsp, &ver);
- if (rc) {
- goto err;
+ if (put_comma) {
+ off += snprintf(str + off, sizeof(str) - off, ",");
}
+ put_comma = 1;
+ off += imgr_ver_jsonstr(str + off, sizeof(str) - off, NULL, &ver);
}
- return 0;
-err:
+ off += snprintf(str + off, sizeof(str) - off, "]}");
+
+ rc = nmgr_rsp_extend(rsp_hdr, rsp, str, off);
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a519dacc/libs/imgmgr/src/imgmgr_fs.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_fs.c b/libs/imgmgr/src/imgmgr_fs.c
index ec3e6fa..06980fb 100644
--- a/libs/imgmgr/src/imgmgr_fs.c
+++ b/libs/imgmgr/src/imgmgr_fs.c
@@ -18,13 +18,16 @@
#include <assert.h>
#include <string.h>
+#include <stdio.h>
#include <newtmgr/newtmgr.h>
#include <bootutil/image.h>
#include <fs/fs.h>
#include <fs/fsutil.h>
+#include <json/json.h>
#include <bsp/bsp.h>
+#include "imgmgr/imgmgr.h"
#include "imgmgr_priv.h"
/* XXX share with bootutil */
@@ -32,6 +35,7 @@
#define BOOT_PATH_MAIN "/boot/main"
#define BOOT_PATH_TEST "/boot/test"
+#ifdef FS_PRESENT
static int
imgr_read_file(const char *path, struct image_version *ver)
{
@@ -67,29 +71,39 @@ int
imgr_boot_read(struct nmgr_hdr *nmr, struct os_mbuf *req,
uint16_t srcoff, struct nmgr_hdr *rsp_hdr, struct os_mbuf *rsp)
{
- struct imgmgr_bootrsp ibr;
int rc;
-
- rc = imgr_read_test(&ibr.ibr_test);
- if (rc) {
- memset(&ibr.ibr_test, 0xff, sizeof(ibr.ibr_test));
+ int prev_set = 0;
+ struct image_version ver;
+ char str[128];
+ int off;
+
+ off = snprintf(str, sizeof(str), "{");
+ rc = imgr_read_test(&ver);
+ if (!rc) {
+ off += imgr_ver_jsonstr(str + off, sizeof(str) - off, "test", &ver);
+ prev_set = 1;
}
- rc = imgr_read_main(&ibr.ibr_main);
- if (rc) {
- memset(&ibr.ibr_main, 0xff, sizeof(ibr.ibr_main));
+ rc = imgr_read_main(&ver);
+ if (!rc) {
+ if (prev_set) {
+ off += snprintf(str + off, sizeof(str) - off, ",");
+ }
+ off += imgr_ver_jsonstr(str + off, sizeof(str) - off, "main", &ver);
+ prev_set = 1;
}
- rc = imgr_read_ver(bsp_imgr_current_slot(), &ibr.ibr_active);
- if (rc) {
- memset(&ibr.ibr_active, 0xff, sizeof(ibr.ibr_active));
+ rc = imgr_read_ver(bsp_imgr_current_slot(), &ver);
+ if (!rc) {
+ if (prev_set) {
+ off += snprintf(str + off, sizeof(str) - off, ",");
+ }
+ off += imgr_ver_jsonstr(str + off, sizeof(str) - off, "active", &ver);
}
- imgr_ver_hton(&ibr.ibr_test);
- imgr_ver_hton(&ibr.ibr_main);
- imgr_ver_hton(&ibr.ibr_active);
+ off += snprintf(str + off, sizeof(str) - off, "}");
- rc = nmgr_rsp_extend(rsp_hdr, rsp, &ibr, sizeof(ibr));
+ rc = nmgr_rsp_extend(rsp_hdr, rsp, str, off);
if (rc) {
goto err;
}
@@ -103,19 +117,43 @@ int
imgr_boot_write(struct nmgr_hdr *nmr, struct os_mbuf *req,
uint16_t srcoff, struct nmgr_hdr *rsp_hdr, struct os_mbuf *rsp)
{
- struct image_version ver;
+ char incoming[64];
+ char test_ver_str[28];
+ const struct json_attr_t boot_write_attr[2] = {
+ [0] = {
+ .attribute = "test",
+ .type = JSON_VALUE_TYPE_STRING,
+ .addr.string = test_ver_str,
+ .len = sizeof(test_ver_str),
+ },
+ [1] = {
+ .attribute = NULL
+ }
+ };
int rc;
- int len;
+ const char *end;
+ struct image_version ver;
+
+ if (nmr->nh_len > sizeof(incoming)) {
+ return OS_EINVAL;
+ }
+ rc = os_mbuf_copydata(req, srcoff + sizeof(*nmr), nmr->nh_len, incoming);
+ if (rc) {
+ return OS_EINVAL;
+ }
- len = min(nmr->nh_len, sizeof(ver));
- rc = os_mbuf_copydata(req, srcoff + sizeof(*nmr), len, &ver);
- if (rc || len < sizeof(ver)) {
+ rc = json_read_object(incoming, boot_write_attr, &end);
+ if (rc) {
+ return OS_EINVAL;
+ }
+
+ rc = imgr_ver_parse(boot_write_attr[0].addr.string, &ver);
+ if (rc) {
return OS_EINVAL;
}
- ver.iv_revision = ntohs(ver.iv_revision);
- ver.iv_build_num = ntohl(ver.iv_build_num);
fs_mkdir(BOOT_PATH);
rc = imgr_write_file(BOOT_PATH_TEST, &ver);
return rc;
}
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a519dacc/libs/imgmgr/src/imgmgr_priv.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_priv.h b/libs/imgmgr/src/imgmgr_priv.h
index 7308aec..49b1716 100644
--- a/libs/imgmgr/src/imgmgr_priv.h
+++ b/libs/imgmgr/src/imgmgr_priv.h
@@ -28,13 +28,24 @@ struct imgmgr_upload_cmd {
};
/*
- * Response to boot read.
+ * Response to list:
+ * {
+ * "list":[ <version1>, <version2>]
+ * }
+ *
+ *
+ * Request to boot to version:
+ * {
+ * "test":<version>
+ * }
+ *
+ * Response to boot read:
+ * {
+ * "test":<version>,
+ * "main":<version>,
+ * "active":<version>
+ * }
*/
-struct imgmgr_bootrsp {
- struct image_version ibr_test; /* /boot/test */
- struct image_version ibr_main; /* /boot/main */
- struct image_version ibr_active; /* currently running image */
-};
struct nmgr_hdr;
struct os_mbuf;
@@ -45,6 +56,7 @@ int imgr_boot_write(struct nmgr_hdr *nmr, struct os_mbuf *req,
uint16_t srcoff, struct nmgr_hdr *rsp_hdr, struct os_mbuf *rsp);
int imgr_read_ver(int area_id, struct image_version *ver);
-void imgr_ver_hton(struct image_version *ver);
+int imgr_ver_jsonstr(char *dst, int dstlen, char *key,
+ struct image_version *ver);
#endif /* __IMGMGR_PRIV_H */
[3/3] incubator-mynewt-larva git commit: Use image version parsing
routine from libs/imgmgr in bin2img project.
Posted by ma...@apache.org.
Use image version parsing routine from libs/imgmgr in bin2img project.
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/ccc970cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/ccc970cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/ccc970cd
Branch: refs/heads/master
Commit: ccc970cd7d9d6d9823a8f528e92ea3a1d521eb65
Parents: a519dac
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Jan 18 15:25:15 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Jan 18 15:25:15 2016 -0800
----------------------------------------------------------------------
fs/fs/egg.yml | 5 +++-
libs/imgmgr/egg.yml | 4 ++-
libs/newtmgr/egg.yml | 1 -
libs/os/egg.yml | 4 +--
libs/shell/egg.yml | 3 +-
project/bin2img/bin2img.yml | 1 +
project/bin2img/src/bin2img.c | 56 ++------------------------------------
7 files changed, 14 insertions(+), 60 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ccc970cd/fs/fs/egg.yml
----------------------------------------------------------------------
diff --git a/fs/fs/egg.yml b/fs/fs/egg.yml
index 8f1d729..31a6a46 100644
--- a/fs/fs/egg.yml
+++ b/fs/fs/egg.yml
@@ -1,5 +1,8 @@
egg.name: fs/fs
egg.deps.SHELL:
- libs/shell
- - libs/console/full
+egg.reqs.SHELL:
+ - console
egg.cflags.SHELL: -DSHELL_PRESENT
+egg.identities:
+ - FS
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ccc970cd/libs/imgmgr/egg.yml
----------------------------------------------------------------------
diff --git a/libs/imgmgr/egg.yml b/libs/imgmgr/egg.yml
index 59f9b39..ca438ff 100644
--- a/libs/imgmgr/egg.yml
+++ b/libs/imgmgr/egg.yml
@@ -1,6 +1,8 @@
egg.name: libs/imgmgr
egg.vers: 0.1
egg.deps:
- - fs/fs
- libs/newtmgr
- libs/bootutil
+egg.deps.FS:
+ - fs/fs
+egg.cflags.FS: -DFS_PRESENT
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ccc970cd/libs/newtmgr/egg.yml
----------------------------------------------------------------------
diff --git a/libs/newtmgr/egg.yml b/libs/newtmgr/egg.yml
index 8f5e6b2..110a01f 100644
--- a/libs/newtmgr/egg.yml
+++ b/libs/newtmgr/egg.yml
@@ -5,5 +5,4 @@ egg.deps:
- libs/json
- libs/util
- libs/testutil
-egg.deps.SHELL:
- libs/shell
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ccc970cd/libs/os/egg.yml
----------------------------------------------------------------------
diff --git a/libs/os/egg.yml b/libs/os/egg.yml
index 08c4413..09a04a7 100644
--- a/libs/os/egg.yml
+++ b/libs/os/egg.yml
@@ -6,9 +6,9 @@ egg.req_caps:
- console
egg.deps.SHELL:
- - libs/console/full
- libs/shell
egg.cflags.SHELL: -DSHELL_PRESENT
-
+egg.reqs.SHELL:
+ - console
# Satisfy capability dependencies for the self-contained test executable.
egg.deps.selftest: libs/console/stub
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ccc970cd/libs/shell/egg.yml
----------------------------------------------------------------------
diff --git a/libs/shell/egg.yml b/libs/shell/egg.yml
index e064e6e..6d953bf 100644
--- a/libs/shell/egg.yml
+++ b/libs/shell/egg.yml
@@ -1,8 +1,9 @@
egg.name: libs/shell
egg.vers: 0.1
egg.deps:
- - libs/console/full
- libs/os
- libs/util
+egg.reqs:
+ - console
egg.identities:
- SHELL
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ccc970cd/project/bin2img/bin2img.yml
----------------------------------------------------------------------
diff --git a/project/bin2img/bin2img.yml b/project/bin2img/bin2img.yml
index 7a99887..acb4b3e 100644
--- a/project/bin2img/bin2img.yml
+++ b/project/bin2img/bin2img.yml
@@ -1,4 +1,5 @@
project.name: bin2img
project.eggs:
- libs/bootutil
+ - libs/imgmgr
- libs/console/stub
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ccc970cd/project/bin2img/src/bin2img.c
----------------------------------------------------------------------
diff --git a/project/bin2img/src/bin2img.c b/project/bin2img/src/bin2img.c
index ff8a139..d8bd021 100644
--- a/project/bin2img/src/bin2img.c
+++ b/project/bin2img/src/bin2img.c
@@ -22,6 +22,7 @@
#include <errno.h>
#include <sys/stat.h>
#include "bootutil/image.h"
+#include "imgmgr/imgmgr.h"
#include "crc32.h"
#if !defined(__BYTE_ORDER__) || (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
@@ -37,59 +38,6 @@ print_usage(FILE *stream)
}
static int
-parse_ver(struct image_version *out_ver, char *s)
-{
- unsigned long ul;
- char *tok;
- char *ep;
-
- tok = strtok(s, ".");
- if (tok == NULL) {
- return -1;
- }
-
- ul = strtoul(tok, &ep, 16);
- if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
- return -1;
- }
- out_ver->iv_major = ul;
-
- tok = strtok(NULL, ".");
- if (tok == NULL) {
- return -1;
- }
-
- ul = strtoul(tok, &ep, 16);
- if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
- return -1;
- }
- out_ver->iv_minor = ul;
-
- tok = strtok(NULL, ".");
- if (tok == NULL) {
- return -1;
- }
-
- ul = strtoul(tok, &ep, 16);
- if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT16_MAX) {
- return -1;
- }
- out_ver->iv_revision = ul;
-
- tok = strtok(NULL, ".");
- if (tok == NULL) {
- return -1;
- }
- ul = strtoul(tok, &ep, 16);
- if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT32_MAX) {
- return -1;
- }
- out_ver->iv_build_num = ul;
-
- return 0;
-}
-
-static int
is_image_file(const char *filename)
{
FILE *fp;
@@ -149,7 +97,7 @@ main(int argc, char **argv)
return 1;
}
- rc = parse_ver(&hdr.ih_ver, argv[3]);
+ rc = imgr_ver_parse(argv[3], &hdr.ih_ver);
if (rc != 0) {
print_usage(stderr);
return 1;