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 16:51:13 UTC

[01/18] incubator-mynewt-core git commit: imgmgr; add list2/boot2 which operate on image hashes instead of versions.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 48df9b088 -> 317a23bd6


imgmgr; add list2/boot2 which operate on image hashes instead of versions.


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

Branch: refs/heads/develop
Commit: ae5a46d5c17e7e16c3253aed74f758f8c22951bb
Parents: 48df9b0
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Apr 22 17:49:26 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:31:38 2016 -0700

----------------------------------------------------------------------
 libs/imgmgr/include/imgmgr/imgmgr.h |  18 +--
 libs/imgmgr/pkg.yml                 |   1 +
 libs/imgmgr/src/imgmgr.c            | 213 ++++++++++++++++++++++++++-----
 libs/imgmgr/src/imgmgr_boot.c       |  94 +++++++++++++-
 libs/imgmgr/src/imgmgr_priv.h       |  11 +-
 5 files changed, 292 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae5a46d5/libs/imgmgr/include/imgmgr/imgmgr.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/include/imgmgr/imgmgr.h b/libs/imgmgr/include/imgmgr/imgmgr.h
index e69dea6..511f1e0 100644
--- a/libs/imgmgr/include/imgmgr/imgmgr.h
+++ b/libs/imgmgr/include/imgmgr/imgmgr.h
@@ -20,14 +20,16 @@
 #ifndef _IMGMGR_H_
 #define _IMGMGR_H_
 
-#define IMGMGR_NMGR_OP_LIST	0
-#define IMGMGR_NMGR_OP_UPLOAD	1
-#define IMGMGR_NMGR_OP_BOOT	2
-#define IMGMGR_NMGR_OP_FILE	3
-
-#define IMGMGR_NMGR_MAX_MSG	120
-#define IMGMGR_NMGR_MAX_NAME	64
-#define IMGMGR_NMGR_MAX_VER	25	/* 255.255.65535.4294967295\0 */
+#define IMGMGR_NMGR_OP_LIST		0
+#define IMGMGR_NMGR_OP_UPLOAD		1
+#define IMGMGR_NMGR_OP_BOOT		2
+#define IMGMGR_NMGR_OP_FILE		3
+#define IMGMGR_NMGR_OP_LIST2		4
+#define IMGMGR_NMGR_OP_BOOT2		5
+
+#define IMGMGR_NMGR_MAX_MSG		120
+#define IMGMGR_NMGR_MAX_NAME		64
+#define IMGMGR_NMGR_MAX_VER		25	/* 255.255.65535.4294967295\0 */
 
 int imgmgr_module_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae5a46d5/libs/imgmgr/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/imgmgr/pkg.yml b/libs/imgmgr/pkg.yml
index 0c66744..93b8b00 100644
--- a/libs/imgmgr/pkg.yml
+++ b/libs/imgmgr/pkg.yml
@@ -26,6 +26,7 @@ pkg.keywords:
 pkg.deps:
     - libs/newtmgr
     - libs/bootutil
+    - libs/util
 pkg.deps.FS:
     - fs/fs
 pkg.cflags.FS: -DFS_PRESENT

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae5a46d5/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index eb192a0..e12fc73 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.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,
@@ -33,6 +33,7 @@
 #include "imgmgr_priv.h"
 
 static int imgr_list(struct nmgr_jbuf *);
+static int imgr_list2(struct nmgr_jbuf *);
 static int imgr_noop(struct nmgr_jbuf *);
 static int imgr_upload(struct nmgr_jbuf *);
 
@@ -48,61 +49,153 @@ static const struct nmgr_handler imgr_nmgr_handlers[] = {
     [IMGMGR_NMGR_OP_BOOT] = {
         .nh_read = imgr_boot_read,
         .nh_write = imgr_boot_write
-    }
-#ifdef FS_PRESENT
-    ,
+    },
     [IMGMGR_NMGR_OP_FILE] = {
+#ifdef FS_PRESENT
         .nh_read = imgr_file_download,
         .nh_write = imgr_file_upload
-    }
+#else
+        .nh_read = imgr_noop,
+        .nh_write = imgr_noop
 #endif
+    },
+    [IMGMGR_NMGR_OP_LIST2] = {
+        .nh_read = imgr_list2,
+        .nh_write = imgr_noop
+    },
+    [IMGMGR_NMGR_OP_BOOT2] = {
+        .nh_read = imgr_boot2_read,
+        .nh_write = imgr_boot2_write
+    }
+
 };
 
 static struct nmgr_group imgr_nmgr_group = {
     .ng_handlers = (struct nmgr_handler *)imgr_nmgr_handlers,
-#ifndef FS_PRESENT
-    .ng_handlers_count = 2,
-#else
-    .ng_handlers_count = 4,
-#endif
+    .ng_handlers_count =
+    sizeof(imgr_nmgr_handlers) / sizeof(imgr_nmgr_handlers[0]),
     .ng_group_id = NMGR_GROUP_ID_IMAGE,
 };
 
 struct imgr_state imgr_state;
 
 /*
- * Read version from image header from flash area 'area_id'.
+ * Read version and build hash from image located in flash area 'area_id'.
+ *
  * Returns -1 if area is not readable.
  * Returns 0 if image in slot is ok, and version string is valid.
  * Returns 1 if there is not a full image.
- * Returns 2 if slot is empty.
+ * Returns 2 if slot is empty. XXXX not there yet
  */
 int
-imgr_read_ver(int area_id, struct image_version *ver)
+imgr_read_info(int area_id, struct image_version *ver, uint8_t *hash)
 {
-    struct image_header hdr;
-    int rc;
+    struct image_header *hdr;
+    struct image_tlv *tlv;
+    int rc = -1;
+    int rc2;
     const struct flash_area *fa;
+    uint8_t data[sizeof(struct image_header)];
+    uint32_t data_off, data_end;
 
-    rc = flash_area_open(area_id, &fa);
-    if (rc) {
+    hdr = (struct image_header *)data;
+    rc2 = flash_area_open(area_id, &fa);
+    if (rc2) {
         return -1;
     }
-    rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
-    if (rc) {
-        return -1;
+    rc2 = flash_area_read(fa, 0, hdr, sizeof(*hdr));
+    if (rc2) {
+        goto end;
     }
     memset(ver, 0xff, sizeof(*ver));
-    if (hdr.ih_magic == 0x96f3b83c) {
-        memcpy(ver, &hdr.ih_ver, sizeof(*ver));
-        rc = 0;
+    if (hdr->ih_magic == IMAGE_MAGIC) {
+        memcpy(ver, &hdr->ih_ver, sizeof(*ver));
+    } else if (hdr->ih_magic == 0xffffffff) {
+        rc = 2;
+        goto end;
     } else {
         rc = 1;
+        goto end;
     }
+
+    /*
+     * Build ID is in a TLV after the image.
+     */
+    data_off = hdr->ih_hdr_size + hdr->ih_img_size;
+    data_end = data_off + hdr->ih_tlv_size;
+
+    tlv = (struct image_tlv *)data;
+    while (data_off + sizeof(*tlv) <= data_end) {
+        rc2 = flash_area_read(fa, data_off, tlv, sizeof(*tlv));
+        if (rc2) {
+            break;
+        }
+        if (tlv->it_type == 0xff && tlv->it_len == 0xffff) {
+            rc = 1;
+            break;
+        }
+        if (tlv->it_type != IMAGE_TLV_SHA256 ||
+          tlv->it_len != IMGMGR_HASH_LEN) {
+            data_off += sizeof(*tlv) + tlv->it_len;
+            continue;
+        }
+        data_off += sizeof(*tlv);
+        if (hash) {
+            rc2 = flash_area_read(fa, data_off, hash, IMGMGR_HASH_LEN);
+            if (rc2) {
+                break;
+            }
+        }
+        rc = 0;
+        break;
+    }
+end:
     flash_area_close(fa);
     return rc;
 }
 
+/*
+ * Finds image given version number. Returns the slot number image is in,
+ * or -1 if not found.
+ */
+int
+imgr_find_by_ver(struct image_version *find, uint8_t *hash)
+{
+    int i;
+    struct image_version ver;
+
+    for (i = FLASH_AREA_IMAGE_0; i <= FLASH_AREA_IMAGE_1; i++) {
+        if (imgr_read_info(i, &ver, hash) != 0) {
+            continue;
+        }
+        if (!memcmp(find, &ver, sizeof(ver))) {
+            return i;
+        }
+    }
+    return -1;
+}
+
+/*
+ * Finds image given hash of the image. Returns the slot number image is in,
+ * or -1 if not found.
+ */
+int
+imgr_find_by_hash(uint8_t *find, struct image_version *ver)
+{
+    int i;
+    uint8_t hash[IMGMGR_HASH_LEN];
+
+    for (i = FLASH_AREA_IMAGE_0; i <= FLASH_AREA_IMAGE_1; i++) {
+        if (imgr_read_info(i, ver, hash) != 0) {
+            continue;
+        }
+        if (!memcmp(hash, find, IMGMGR_HASH_LEN)) {
+            return i;
+        }
+    }
+    return -1;
+}
+
 static int
 imgr_list(struct nmgr_jbuf *njb)
 {
@@ -111,14 +204,14 @@ imgr_list(struct nmgr_jbuf *njb)
     int rc;
     struct json_encoder *enc;
     struct json_value array;
-    struct json_value versions[4];
-    struct json_value *version_ptrs[4];
-    char vers_str[4][IMGMGR_NMGR_MAX_VER];
+    struct json_value versions[IMGMGR_MAX_IMGS];
+    struct json_value *version_ptrs[IMGMGR_MAX_IMGS];
+    char vers_str[IMGMGR_MAX_IMGS][IMGMGR_NMGR_MAX_VER];
     int ver_len;
     int cnt = 0;
 
     for (i = FLASH_AREA_IMAGE_0; i <= FLASH_AREA_IMAGE_1; i++) {
-        rc = imgr_read_ver(i, &ver);
+        rc = imgr_read_info(i, &ver, NULL);
         if (rc != 0) {
             continue;
         }
@@ -141,6 +234,43 @@ imgr_list(struct nmgr_jbuf *njb)
 }
 
 static int
+imgr_list2(struct nmgr_jbuf *njb)
+{
+    struct json_encoder *enc;
+    int i;
+    int rc;
+    struct image_version ver;
+    uint8_t hash[IMGMGR_HASH_LEN]; /* SHA256 hash */
+    struct json_value jv_ver;
+    char vers_str[IMGMGR_NMGR_MAX_VER];
+    char hash_str[IMGMGR_HASH_STR + 1];
+    int ver_len;
+
+    enc = &njb->njb_enc;
+
+    json_encode_object_start(enc);
+    json_encode_array_name(enc, "images");
+    json_encode_array_start(enc);
+    for (i = FLASH_AREA_IMAGE_0; i <= FLASH_AREA_IMAGE_1; i++) {
+        rc = imgr_read_info(i, &ver, hash);
+        if (rc != 0) {
+            continue;
+        }
+        ver_len = imgr_ver_str(&ver, vers_str);
+        base64_encode(hash, IMGMGR_HASH_LEN, hash_str, 1);
+        JSON_VALUE_STRINGN(&jv_ver, vers_str, ver_len);
+
+        json_encode_object_start(enc);
+        json_encode_object_entry(enc, hash_str, &jv_ver);
+        json_encode_object_finish(enc);
+    }
+    json_encode_array_finish(enc);
+    json_encode_object_finish(enc);
+
+    return 0;
+}
+
+static int
 imgr_noop(struct nmgr_jbuf *njb)
 {
     return 0;
@@ -173,6 +303,7 @@ imgr_upload(struct nmgr_jbuf *njb)
         }
     };
     struct image_version ver;
+    struct image_header *hdr;
     struct json_encoder *enc;
     struct json_value jv;
     int active;
@@ -186,14 +317,23 @@ imgr_upload(struct nmgr_jbuf *njb)
         return OS_EINVAL;
     }
     len = strlen(img_data);
-    if (len) {
-        len = base64_decode(img_data, img_data);
-        if (len < 0) {
-            return OS_EINVAL;
-        }
+    if (!len) {
+        return OS_EINVAL;
+    }
+    len = base64_decode(img_data, img_data);
+    if (len < 0) {
+        return OS_EINVAL;
     }
 
     if (off == 0) {
+        if (len < sizeof(struct image_header)) {
+            /*
+             * Image header is the first thing in the image.
+             */
+            return OS_EINVAL;
+        }
+        hdr = (struct image_header *)img_data;
+
         /*
          * New upload.
          */
@@ -203,11 +343,15 @@ imgr_upload(struct nmgr_jbuf *njb)
         best = -1;
 
         for (i = FLASH_AREA_IMAGE_0; i <= FLASH_AREA_IMAGE_1; i++) {
-            rc = imgr_read_ver(i, &ver);
+            rc = imgr_read_info(i, &ver, NULL);
             if (rc < 0) {
                 continue;
             }
             if (rc == 0) {
+                if (!memcmp(&ver, &hdr->ih_ver, sizeof(ver))) {
+                    best = -1;
+                    break;
+                }
                 /*
                  * Image in slot is ok.
                  */
@@ -246,8 +390,7 @@ imgr_upload(struct nmgr_jbuf *njb)
             /*
              * No slot where to upload!
              */
-            assert(0);
-            goto out;
+            return OS_EINVAL;
         }
     } else if (off != imgr_state.upload.off) {
         /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae5a46d5/libs/imgmgr/src/imgmgr_boot.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_boot.c b/libs/imgmgr/src/imgmgr_boot.c
index 8084b0d..3e4f9cf 100644
--- a/libs/imgmgr/src/imgmgr_boot.c
+++ b/libs/imgmgr/src/imgmgr_boot.c
@@ -49,12 +49,24 @@ imgr_ver_jsonstr(struct json_encoder *enc, char *key,
     json_encode_object_entry(enc, key, &jv);
 }
 
+static void
+imgr_hash_jsonstr(struct json_encoder *enc, char *key, uint8_t *hash)
+{
+    struct json_value jv;
+    char hash_str[IMGMGR_HASH_STR + 1];
+
+    base64_encode(hash, IMGMGR_HASH_LEN, hash_str, 1);
+    JSON_VALUE_STRING(&jv, hash_str);
+    json_encode_object_entry(enc, key, &jv);
+}
+
 int
 imgr_boot_read(struct nmgr_jbuf *njb)
 {
     int rc;
     struct json_encoder *enc;
     struct image_version ver;
+    uint8_t hash[IMGMGR_HASH_LEN];
 
     enc = &njb->njb_enc;
 
@@ -70,7 +82,7 @@ imgr_boot_read(struct nmgr_jbuf *njb)
         imgr_ver_jsonstr(enc, "main", &ver);
     }
 
-    rc = imgr_read_ver(bsp_imgr_current_slot(), &ver);
+    rc = imgr_read_info(bsp_imgr_current_slot(), &ver, hash);
     if (!rc) {
         imgr_ver_jsonstr(enc, "active", &ver);
     }
@@ -84,6 +96,7 @@ int
 imgr_boot_write(struct nmgr_jbuf *njb)
 {
     char test_ver_str[28];
+    uint8_t hash[IMGMGR_HASH_LEN];
     const struct json_attr_t boot_write_attr[2] = {
         [0] = {
             .attribute = "test",
@@ -108,9 +121,88 @@ imgr_boot_write(struct nmgr_jbuf *njb)
         return OS_EINVAL;
     }
 
+    rc = imgr_find_by_ver(&ver, hash);
+    if (rc < 0) {
+        return OS_EINVAL;
+    }
     rc = boot_vect_write_test(&ver);
     if (rc) {
         return OS_EINVAL;
     }
     return rc;
 }
+
+int
+imgr_boot2_read(struct nmgr_jbuf *njb)
+{
+    int rc;
+    struct json_encoder *enc;
+    struct image_version ver;
+    uint8_t hash[IMGMGR_HASH_LEN];
+
+    enc = &njb->njb_enc;
+
+    json_encode_object_start(enc);
+
+    rc = boot_vect_read_test(&ver);
+    if (!rc) {
+        rc = imgr_find_by_ver(&ver, hash);
+        if (rc >= 0) {
+            imgr_hash_jsonstr(enc, "test", hash);
+        }
+    }
+
+    rc = boot_vect_read_main(&ver);
+    if (!rc) {
+        rc = imgr_find_by_ver(&ver, hash);
+        if (rc >= 0) {
+            imgr_hash_jsonstr(enc, "main", hash);
+        }
+    }
+
+    rc = imgr_read_info(bsp_imgr_current_slot(), &ver, hash);
+    if (!rc) {
+        imgr_hash_jsonstr(enc, "active", hash);
+    }
+
+    json_encode_object_finish(enc);
+
+    return 0;
+}
+
+int
+imgr_boot2_write(struct nmgr_jbuf *njb)
+{
+    char hash_str[IMGMGR_HASH_STR + 1];
+    uint8_t hash[IMGMGR_HASH_LEN];
+    const struct json_attr_t boot_write_attr[2] = {
+        [0] = {
+            .attribute = "test",
+            .type = t_string,
+            .addr.string = hash_str,
+            .len = sizeof(hash_str),
+        },
+        [1] = {
+            .attribute = NULL
+        }
+    };
+    int rc;
+    struct image_version ver;
+
+    rc = json_read_object(&njb->njb_buf, boot_write_attr);
+    if (rc) {
+        return OS_EINVAL;
+    }
+
+    base64_decode(hash_str, hash);
+    rc = imgr_find_by_hash(hash, &ver);
+    if (rc >= 0) {
+        rc = boot_vect_write_test(&ver);
+        if (rc) {
+            return OS_EINVAL;
+        }
+    } else {
+        rc = OS_EINVAL;
+    }
+    return rc;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae5a46d5/libs/imgmgr/src/imgmgr_priv.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_priv.h b/libs/imgmgr/src/imgmgr_priv.h
index e22845b..04323af 100644
--- a/libs/imgmgr/src/imgmgr_priv.h
+++ b/libs/imgmgr/src/imgmgr_priv.h
@@ -22,6 +22,11 @@
 
 #include <stdint.h>
 
+#define IMGMGR_MAX_IMGS		2
+
+#define IMGMGR_HASH_STR		48
+#define IMGMGR_HASH_LEN		32
+
 /*
  * When accompanied by image, it's this structure followed by data.
  * Response contains just the offset.
@@ -93,9 +98,13 @@ extern struct imgr_state imgr_state;
 
 int imgr_boot_read(struct nmgr_jbuf *);
 int imgr_boot_write(struct nmgr_jbuf *);
+int imgr_boot2_read(struct nmgr_jbuf *);
+int imgr_boot2_write(struct nmgr_jbuf *);
 int imgr_file_upload(struct nmgr_jbuf *);
 int imgr_file_download(struct nmgr_jbuf *);
 
-int imgr_read_ver(int area_id, struct image_version *ver);
+int imgr_read_info(int area_id, struct image_version *ver, uint8_t *hash);
+int imgr_find_by_ver(struct image_version *find, uint8_t *hash);
+int imgr_find_by_hash(uint8_t *find, struct image_version *ver);
 
 #endif /* __IMGMGR_PRIV_H */


[18/18] incubator-mynewt-core git commit: imgmgr; json decoder now wants to use 64-bit integers.

Posted by ma...@apache.org.
imgmgr; json decoder now wants to use 64-bit integers.


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

Branch: refs/heads/develop
Commit: 317a23bd6d7772a9b32d58dec89c0abeffe90ca7
Parents: e4aeaec
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu May 19 09:50:17 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:50:17 2016 -0700

----------------------------------------------------------------------
 libs/imgmgr/src/imgmgr_coredump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/317a23bd/libs/imgmgr/src/imgmgr_coredump.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_coredump.c b/libs/imgmgr/src/imgmgr_coredump.c
index 6a09a5a..6f3543b 100644
--- a/libs/imgmgr/src/imgmgr_coredump.c
+++ b/libs/imgmgr/src/imgmgr_coredump.c
@@ -64,7 +64,7 @@ imgr_core_list(struct nmgr_jbuf *njb)
 int
 imgr_core_load(struct nmgr_jbuf *njb)
 {
-    unsigned int off = UINT_MAX;
+    unsigned long long off = UINT_MAX;
     const struct json_attr_t dload_attr[2] = {
         [0] = {
             .attribute = "off",


[17/18] incubator-mynewt-core git commit: base64; fix define for computing the size of encoded data.

Posted by ma...@apache.org.
base64; fix define for computing the size of encoded data.


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

Branch: refs/heads/develop
Commit: 1bbd2da56c0e8a5e4b1a43ec0b5f060908e99a68
Parents: 4b726ce
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu May 19 09:19:46 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:35:45 2016 -0700

----------------------------------------------------------------------
 libs/util/include/util/base64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1bbd2da5/libs/util/include/util/base64.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/base64.h b/libs/util/include/util/base64.h
index c6b63a7..8e0c045 100644
--- a/libs/util/include/util/base64.h
+++ b/libs/util/include/util/base64.h
@@ -27,6 +27,6 @@ int base64_decode(const char *, void *buf);
 int base64_pad(char *, int);
 int base64_decode_len(const char *str);
 
-#define BASE64_ENCODE_SIZE(__size) (((__size) * (4 / 3)) + 4)
+#define BASE64_ENCODE_SIZE(__size) ((((__size) * 4) / 3) + 4)
 
 #endif /* __UTIL_BASE64_H__ */


[02/18] incubator-mynewt-core git commit: imgmgr; fix warning for uninitialized variable.

Posted by ma...@apache.org.
imgmgr; fix warning for uninitialized variable.


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

Branch: refs/heads/develop
Commit: 5fb05070d2b69c161bd0bb51740ddf4386ac1fe0
Parents: ae5a46d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 15:15:38 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:34:26 2016 -0700

----------------------------------------------------------------------
 libs/imgmgr/src/imgmgr_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5fb05070/libs/imgmgr/src/imgmgr_fs.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_fs.c b/libs/imgmgr/src/imgmgr_fs.c
index ab33c54..3ba5057 100644
--- a/libs/imgmgr/src/imgmgr_fs.c
+++ b/libs/imgmgr/src/imgmgr_fs.c
@@ -38,7 +38,7 @@
 int
 imgr_file_download(struct nmgr_jbuf *njb)
 {
-    long long unsigned int off;
+    long long unsigned int off = UINT_MAX;
     char tmp_str[IMGMGR_NMGR_MAX_NAME + 1];
     char img_data[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
     const struct json_attr_t dload_attr[3] = {


[12/18] incubator-mynewt-core git commit: hal/bsp; add hal_bsp.h, which exports common BSP APIs.

Posted by ma...@apache.org.
hal/bsp; add hal_bsp.h, which exports common BSP APIs.


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

Branch: refs/heads/develop
Commit: 0b3ca0075ba60e8f736740af1e702bb9a5ee5638
Parents: e157f02
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 20:34:26 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:35:45 2016 -0700

----------------------------------------------------------------------
 hw/bsp/bmd300eval/include/bsp/bsp.h             |  2 -
 hw/bsp/bmd300eval/src/libc_stubs.c              |  2 +-
 hw/bsp/bmd300eval/src/os_bsp.c                  |  2 +-
 hw/bsp/bmd300eval/src/sbrk.c                    |  1 +
 hw/bsp/native/include/bsp/bsp.h                 |  2 -
 hw/bsp/native/src/sbrk.c                        |  2 +
 hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h        |  2 -
 hw/bsp/nrf51dk-16kbram/src/hal_bsp.c            |  3 +-
 hw/bsp/nrf51dk-16kbram/src/libc_stubs.c         |  2 +-
 hw/bsp/nrf51dk-16kbram/src/os_bsp.c             |  2 +-
 hw/bsp/nrf51dk-16kbram/src/sbrk.c               |  1 +
 hw/bsp/nrf51dk/include/bsp/bsp.h                |  2 -
 hw/bsp/nrf51dk/src/libc_stubs.c                 |  2 +-
 hw/bsp/nrf51dk/src/os_bsp.c                     |  2 +-
 hw/bsp/nrf51dk/src/sbrk.c                       |  1 +
 hw/bsp/nrf52dk/include/bsp/bsp.h                |  2 -
 hw/bsp/nrf52dk/src/libc_stubs.c                 |  2 +-
 hw/bsp/nrf52dk/src/os_bsp.c                     |  2 +-
 hw/bsp/nrf52dk/src/sbrk.c                       |  1 +
 hw/bsp/nrf52pdk/include/bsp/bsp.h               |  2 -
 hw/bsp/nrf52pdk/src/hal_bsp.c                   |  4 +-
 hw/bsp/nrf52pdk/src/libc_stubs.c                |  2 +-
 hw/bsp/nrf52pdk/src/os_bsp.c                    |  2 +-
 hw/bsp/nrf52pdk/src/sbrk.c                      |  1 +
 .../include/bsp/bsp.h                           |  2 -
 hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c |  1 +
 .../olimex_stm32-e407_devboard/src/libc_stubs.c |  2 +-
 hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c  |  2 +-
 hw/hal/include/hal/hal_bsp.h                    | 43 ++++++++++++++++++++
 hw/hal/include/hal/hal_flash_int.h              |  3 --
 hw/hal/src/flash_map.c                          |  2 +
 hw/hal/src/test/flash_map_test.c                |  2 +-
 libs/flash_test/src/flash_test/flash_test.c     |  3 +-
 libs/imgmgr/src/imgmgr.c                        |  2 +-
 libs/imgmgr/src/imgmgr_boot.c                   |  2 +-
 libs/os/include/os/arch/cortex_m0/os/os_arch.h  |  1 -
 libs/os/include/os/arch/cortex_m4/os/os_arch.h  |  1 -
 libs/os/include/os/arch/sim/os/os_arch.h        |  2 -
 libs/os/src/arch/cortex_m0/os_arch_arm.c        |  1 +
 libs/os/src/arch/cortex_m4/os_arch_arm.c        |  1 +
 libs/os/src/arch/sim/os_arch_sim.c              |  2 +
 sys/coredump/src/coredump.c                     |  3 +-
 42 files changed, 80 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/bmd300eval/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/include/bsp/bsp.h b/hw/bsp/bmd300eval/include/bsp/bsp.h
index d2a32c5..7638ff5 100644
--- a/hw/bsp/bmd300eval/include/bsp/bsp.h
+++ b/hw/bsp/bmd300eval/include/bsp/bsp.h
@@ -38,8 +38,6 @@ extern "C" {
 /* UART info */
 #define CONSOLE_UART    0
 
-int bsp_imgr_current_slot(void);
-
 #define NFFS_AREA_MAX    (8)
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/bmd300eval/src/libc_stubs.c
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/src/libc_stubs.c b/hw/bsp/bmd300eval/src/libc_stubs.c
index 84f855e..b1b6b8b 100644
--- a/hw/bsp/bmd300eval/src/libc_stubs.c
+++ b/hw/bsp/bmd300eval/src/libc_stubs.c
@@ -17,8 +17,8 @@
  * under the License.
  */
 #include <hal/hal_system.h>
+#include <hal/hal_bsp.h>
 
-void * _sbrk(int c);
 int _close(int fd);
 int _fstat(int fd, void *s);
 void _exit(int s);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/bmd300eval/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/src/os_bsp.c b/hw/bsp/bmd300eval/src/os_bsp.c
index c05b208..66c1ceb 100644
--- a/hw/bsp/bmd300eval/src/os_bsp.c
+++ b/hw/bsp/bmd300eval/src/os_bsp.c
@@ -17,6 +17,7 @@
  * under the License.
  */
 #include <hal/flash_map.h>
+#include <hal/hal_bsp.h>
 
 static struct flash_area bsp_flash_areas[] = {
     [FLASH_AREA_BOOTLOADER] = {
@@ -47,7 +48,6 @@ static struct flash_area bsp_flash_areas[] = {
     }
 };
 
-void *_sbrk(int incr);
 void _close(int fd);
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/bmd300eval/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/src/sbrk.c b/hw/bsp/bmd300eval/src/sbrk.c
index 0fd7a41..8549266 100644
--- a/hw/bsp/bmd300eval/src/sbrk.c
+++ b/hw/bsp/bmd300eval/src/sbrk.c
@@ -18,6 +18,7 @@
  */
 
 #include <errno.h>
+#include <hal/hal_bsp.h>
 
 extern char __HeapBase;
 extern char __HeapLimit;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/native/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/native/include/bsp/bsp.h b/hw/bsp/native/include/bsp/bsp.h
index fb684c3..42a53f4 100644
--- a/hw/bsp/native/include/bsp/bsp.h
+++ b/hw/bsp/native/include/bsp/bsp.h
@@ -38,8 +38,6 @@ extern "C" {
 #define UART_CNT	2
 #define CONSOLE_UART	0
 
-int bsp_imgr_current_slot(void);
-
 #define NFFS_AREA_MAX    (8)
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/native/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/native/src/sbrk.c b/hw/bsp/native/src/sbrk.c
index 64000b7..3ec8a90 100644
--- a/hw/bsp/native/src/sbrk.c
+++ b/hw/bsp/native/src/sbrk.c
@@ -21,6 +21,8 @@
 #include <unistd.h>
 #include <errno.h>
 
+#include <hal/hal_bsp.h>
+
 extern int getpagesize(void);
 
 static void *cont;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h b/hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h
index 1392712..72370ff 100644
--- a/hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h
+++ b/hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h
@@ -37,8 +37,6 @@ extern "C" {
 /* UART info */
 #define CONSOLE_UART    0
 
-int bsp_imgr_current_slot(void);
-
 #define NFFS_AREA_MAX    (8)
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf51dk-16kbram/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/src/hal_bsp.c b/hw/bsp/nrf51dk-16kbram/src/hal_bsp.c
index bfca6f9..868ace8 100644
--- a/hw/bsp/nrf51dk-16kbram/src/hal_bsp.c
+++ b/hw/bsp/nrf51dk-16kbram/src/hal_bsp.c
@@ -19,7 +19,8 @@
 
 #include <stdint.h>
 #include <stddef.h>
-#include "mcu/nrf51_hal.h"
+#include <hal/hal_bsp.h>
+#include <mcu/nrf51_hal.h>
 
 static const struct nrf51_uart_cfg uart_cfg = {
     .suc_pin_tx = 9,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf51dk-16kbram/src/libc_stubs.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/src/libc_stubs.c b/hw/bsp/nrf51dk-16kbram/src/libc_stubs.c
index da54ed1..de047ea 100644
--- a/hw/bsp/nrf51dk-16kbram/src/libc_stubs.c
+++ b/hw/bsp/nrf51dk-16kbram/src/libc_stubs.c
@@ -18,8 +18,8 @@
  */
 
 #include <hal/hal_system.h>
+#include <hal/hal_bsp.h>
 
-void * _sbrk(int c);
 int _close(int fd);
 int _fstat(int fd, void *s);
 void _exit(int s);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/src/os_bsp.c b/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
index 2b88f27..07230b0 100644
--- a/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
+++ b/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
@@ -17,6 +17,7 @@
  * under the License.
  */
 #include <hal/flash_map.h>
+#include <hal/hal_bsp.h>
 
 static struct flash_area bsp_flash_areas[] = {
     [FLASH_AREA_BOOTLOADER] = {
@@ -46,7 +47,6 @@ static struct flash_area bsp_flash_areas[] = {
     }
 };
 
-void *_sbrk(int incr);
 void _close(int fd);
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf51dk-16kbram/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/src/sbrk.c b/hw/bsp/nrf51dk-16kbram/src/sbrk.c
index f06d124..7daef1a 100644
--- a/hw/bsp/nrf51dk-16kbram/src/sbrk.c
+++ b/hw/bsp/nrf51dk-16kbram/src/sbrk.c
@@ -18,6 +18,7 @@
  */
 
 #include <errno.h>
+#include <hal/hal_bsp.h>
 
 extern char __HeapBase;
 extern char __HeapLimit;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf51dk/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/include/bsp/bsp.h b/hw/bsp/nrf51dk/include/bsp/bsp.h
index 2bdfa56..6e2ab08 100644
--- a/hw/bsp/nrf51dk/include/bsp/bsp.h
+++ b/hw/bsp/nrf51dk/include/bsp/bsp.h
@@ -37,8 +37,6 @@ extern "C" {
 /* UART info */
 #define CONSOLE_UART    0
 
-int bsp_imgr_current_slot(void);
-
 #define NFFS_AREA_MAX    (8)
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf51dk/src/libc_stubs.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/libc_stubs.c b/hw/bsp/nrf51dk/src/libc_stubs.c
index da54ed1..de047ea 100644
--- a/hw/bsp/nrf51dk/src/libc_stubs.c
+++ b/hw/bsp/nrf51dk/src/libc_stubs.c
@@ -18,8 +18,8 @@
  */
 
 #include <hal/hal_system.h>
+#include <hal/hal_bsp.h>
 
-void * _sbrk(int c);
 int _close(int fd);
 int _fstat(int fd, void *s);
 void _exit(int s);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf51dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/os_bsp.c b/hw/bsp/nrf51dk/src/os_bsp.c
index 2b88f27..07230b0 100644
--- a/hw/bsp/nrf51dk/src/os_bsp.c
+++ b/hw/bsp/nrf51dk/src/os_bsp.c
@@ -17,6 +17,7 @@
  * under the License.
  */
 #include <hal/flash_map.h>
+#include <hal/hal_bsp.h>
 
 static struct flash_area bsp_flash_areas[] = {
     [FLASH_AREA_BOOTLOADER] = {
@@ -46,7 +47,6 @@ static struct flash_area bsp_flash_areas[] = {
     }
 };
 
-void *_sbrk(int incr);
 void _close(int fd);
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf51dk/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/sbrk.c b/hw/bsp/nrf51dk/src/sbrk.c
index f06d124..7daef1a 100644
--- a/hw/bsp/nrf51dk/src/sbrk.c
+++ b/hw/bsp/nrf51dk/src/sbrk.c
@@ -18,6 +18,7 @@
  */
 
 #include <errno.h>
+#include <hal/hal_bsp.h>
 
 extern char __HeapBase;
 extern char __HeapLimit;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf52dk/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/include/bsp/bsp.h b/hw/bsp/nrf52dk/include/bsp/bsp.h
index d2a32c5..7638ff5 100644
--- a/hw/bsp/nrf52dk/include/bsp/bsp.h
+++ b/hw/bsp/nrf52dk/include/bsp/bsp.h
@@ -38,8 +38,6 @@ extern "C" {
 /* UART info */
 #define CONSOLE_UART    0
 
-int bsp_imgr_current_slot(void);
-
 #define NFFS_AREA_MAX    (8)
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf52dk/src/libc_stubs.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/libc_stubs.c b/hw/bsp/nrf52dk/src/libc_stubs.c
index 84f855e..b1b6b8b 100644
--- a/hw/bsp/nrf52dk/src/libc_stubs.c
+++ b/hw/bsp/nrf52dk/src/libc_stubs.c
@@ -17,8 +17,8 @@
  * under the License.
  */
 #include <hal/hal_system.h>
+#include <hal/hal_bsp.h>
 
-void * _sbrk(int c);
 int _close(int fd);
 int _fstat(int fd, void *s);
 void _exit(int s);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf52dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/os_bsp.c b/hw/bsp/nrf52dk/src/os_bsp.c
index c05b208..66c1ceb 100644
--- a/hw/bsp/nrf52dk/src/os_bsp.c
+++ b/hw/bsp/nrf52dk/src/os_bsp.c
@@ -17,6 +17,7 @@
  * under the License.
  */
 #include <hal/flash_map.h>
+#include <hal/hal_bsp.h>
 
 static struct flash_area bsp_flash_areas[] = {
     [FLASH_AREA_BOOTLOADER] = {
@@ -47,7 +48,6 @@ static struct flash_area bsp_flash_areas[] = {
     }
 };
 
-void *_sbrk(int incr);
 void _close(int fd);
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf52dk/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/sbrk.c b/hw/bsp/nrf52dk/src/sbrk.c
index 0fd7a41..8549266 100644
--- a/hw/bsp/nrf52dk/src/sbrk.c
+++ b/hw/bsp/nrf52dk/src/sbrk.c
@@ -18,6 +18,7 @@
  */
 
 #include <errno.h>
+#include <hal/hal_bsp.h>
 
 extern char __HeapBase;
 extern char __HeapLimit;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf52pdk/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/include/bsp/bsp.h b/hw/bsp/nrf52pdk/include/bsp/bsp.h
index d2a32c5..7638ff5 100644
--- a/hw/bsp/nrf52pdk/include/bsp/bsp.h
+++ b/hw/bsp/nrf52pdk/include/bsp/bsp.h
@@ -38,8 +38,6 @@ extern "C" {
 /* UART info */
 #define CONSOLE_UART    0
 
-int bsp_imgr_current_slot(void);
-
 #define NFFS_AREA_MAX    (8)
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf52pdk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/hal_bsp.c b/hw/bsp/nrf52pdk/src/hal_bsp.c
index 0b04610..521aa61 100644
--- a/hw/bsp/nrf52pdk/src/hal_bsp.c
+++ b/hw/bsp/nrf52pdk/src/hal_bsp.c
@@ -18,7 +18,9 @@
  */
 #include <stdint.h>
 #include <stddef.h>
-#include "mcu/nrf52_hal.h"
+
+#include <hal/hal_bsp.h>
+#include <mcu/nrf52_hal.h>
 
 static const struct nrf52_uart_cfg uart_cfg = {
     .suc_pin_tx = 6,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf52pdk/src/libc_stubs.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/libc_stubs.c b/hw/bsp/nrf52pdk/src/libc_stubs.c
index 84f855e..b1b6b8b 100644
--- a/hw/bsp/nrf52pdk/src/libc_stubs.c
+++ b/hw/bsp/nrf52pdk/src/libc_stubs.c
@@ -17,8 +17,8 @@
  * under the License.
  */
 #include <hal/hal_system.h>
+#include <hal/hal_bsp.h>
 
-void * _sbrk(int c);
 int _close(int fd);
 int _fstat(int fd, void *s);
 void _exit(int s);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf52pdk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/os_bsp.c b/hw/bsp/nrf52pdk/src/os_bsp.c
index 1c5a7a9..9f2e337 100644
--- a/hw/bsp/nrf52pdk/src/os_bsp.c
+++ b/hw/bsp/nrf52pdk/src/os_bsp.c
@@ -17,6 +17,7 @@
  * under the License.
  */
 #include <hal/flash_map.h>
+#include <hal/hal_bsp.h>
 
 static struct flash_area bsp_flash_areas[] = {
     [FLASH_AREA_BOOTLOADER] = {
@@ -47,7 +48,6 @@ static struct flash_area bsp_flash_areas[] = {
     }
 };
 
-void *_sbrk(int incr);
 void _close(int fd);
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/nrf52pdk/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/sbrk.c b/hw/bsp/nrf52pdk/src/sbrk.c
index 0fd7a41..8549266 100644
--- a/hw/bsp/nrf52pdk/src/sbrk.c
+++ b/hw/bsp/nrf52pdk/src/sbrk.c
@@ -18,6 +18,7 @@
  */
 
 #include <errno.h>
+#include <hal/hal_bsp.h>
 
 extern char __HeapBase;
 extern char __HeapLimit;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h b/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
index 828b3d0..d39ddca 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
+++ b/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
@@ -38,8 +38,6 @@ extern "C" {
 #define UART_CNT 1
 #define CONSOLE_UART 0
 
-int bsp_imgr_current_slot(void);
-
 #define NFFS_AREA_MAX    (8)
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c b/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
index d469817..ec1d2a4 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
+++ b/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+#include "hal/hal_bsp.h"
 #include "hal/hal_gpio.h"
 #include "hal/hal_flash_int.h"
 #include "mcu/stm32f407xx.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/olimex_stm32-e407_devboard/src/libc_stubs.c
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/src/libc_stubs.c b/hw/bsp/olimex_stm32-e407_devboard/src/libc_stubs.c
index 84f855e..b1b6b8b 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/src/libc_stubs.c
+++ b/hw/bsp/olimex_stm32-e407_devboard/src/libc_stubs.c
@@ -17,8 +17,8 @@
  * under the License.
  */
 #include <hal/hal_system.h>
+#include <hal/hal_bsp.h>
 
-void * _sbrk(int c);
 int _close(int fd);
 int _fstat(int fd, void *s);
 void _exit(int s);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c b/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c
index ab622db..5cdc35a 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c
+++ b/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c
@@ -21,6 +21,7 @@
  * XXXX for now have this here.
  */
 #include <hal/flash_map.h>
+#include <hal/hal_bsp.h>
 
 static struct flash_area bsp_flash_areas[] = {
     [FLASH_AREA_BOOTLOADER] = {
@@ -51,7 +52,6 @@ static struct flash_area bsp_flash_areas[] = {
     }
 };
 
-void *_sbrk(int incr);
 void _close(int fd);
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/hal/include/hal/hal_bsp.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_bsp.h b/hw/hal/include/hal/hal_bsp.h
new file mode 100644
index 0000000..a491507
--- /dev/null
+++ b/hw/hal/include/hal/hal_bsp.h
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __HAL_BSP_H_
+#define __HAL_BSP_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <inttypes.h>
+
+/* External function prototypes supplied by BSP */
+struct hal_flash;
+const struct hal_flash *bsp_flash_dev(uint8_t flash_id);
+
+int bsp_imgr_current_slot(void);
+
+void os_bsp_init(void);
+
+void *_sbrk(int incr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/hal/include/hal/hal_flash_int.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_flash_int.h b/hw/hal/include/hal/hal_flash_int.h
index 3be4572..99bf329 100644
--- a/hw/hal/include/hal/hal_flash_int.h
+++ b/hw/hal/include/hal/hal_flash_int.h
@@ -50,9 +50,6 @@ struct hal_flash {
  */
 uint32_t hal_flash_sector_size(const struct hal_flash *hf, int sec_idx);
 
-/* External function prototype supplied by BSP */
-const struct hal_flash *bsp_flash_dev(uint8_t flash_id);
-
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/hal/src/flash_map.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/flash_map.c b/hw/hal/src/flash_map.c
index 8cae5cf..4b06c29 100644
--- a/hw/hal/src/flash_map.c
+++ b/hw/hal/src/flash_map.c
@@ -16,8 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+#include <inttypes.h>
 #include <string.h>
 
+#include "hal/hal_bsp.h"
 #include "hal/hal_flash.h"
 #include "hal/hal_flash_int.h"
 #ifdef NFFS_PRESENT

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/hw/hal/src/test/flash_map_test.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/test/flash_map_test.c b/hw/hal/src/test/flash_map_test.c
index c9df88c..06e065d 100644
--- a/hw/hal/src/test/flash_map_test.c
+++ b/hw/hal/src/test/flash_map_test.c
@@ -22,7 +22,7 @@
 #include <os/os.h>
 #include <testutil/testutil.h>
 #include "hal/flash_map.h"
-
+#include "hal/hal_bsp.h"
 #include "hal/hal_flash.h"
 #include "hal/hal_flash_int.h"
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/libs/flash_test/src/flash_test/flash_test.c
----------------------------------------------------------------------
diff --git a/libs/flash_test/src/flash_test/flash_test.c b/libs/flash_test/src/flash_test/flash_test.c
index 5a9bdad..980cbba 100644
--- a/libs/flash_test/src/flash_test/flash_test.c
+++ b/libs/flash_test/src/flash_test/flash_test.c
@@ -16,10 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
+#include <inttypes.h>
 #include <os/os.h>
 #include <console/console.h>
 #include <flash_test/flash_test.h>
+#include <hal/hal_bsp.h>
 #include <hal/hal_flash.h>
 #include <hal/hal_flash_int.h>
 #include <shell/shell.h>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index b730d66..21d0225 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@ -17,11 +17,11 @@
  * under the License.
  */
 #include <os/endian.h>
-#include <bsp/bsp.h>
 
 #include <limits.h>
 #include <assert.h>
 #include <string.h>
+#include <hal/hal_bsp.h>
 #include <hal/flash_map.h>
 #include <newtmgr/newtmgr.h>
 #include <json/json.h>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/libs/imgmgr/src/imgmgr_boot.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_boot.c b/libs/imgmgr/src/imgmgr_boot.c
index 3e4f9cf..2927f3e 100644
--- a/libs/imgmgr/src/imgmgr_boot.c
+++ b/libs/imgmgr/src/imgmgr_boot.c
@@ -31,7 +31,7 @@
 #include <fs/fsutil.h>
 #include <json/json.h>
 #include <util/base64.h>
-#include <bsp/bsp.h>
+#include <hal/hal_bsp.h>
 
 #include "imgmgr/imgmgr.h"
 #include "imgmgr_priv.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/libs/os/include/os/arch/cortex_m0/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m0/os/os_arch.h b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
index 7231cb7..e986702 100755
--- a/libs/os/include/os/arch/cortex_m0/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
@@ -69,7 +69,6 @@ void os_default_irq_asm(void);
 
 /* External function prototypes supplied by BSP */
 void os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio);
-void os_bsp_init(void);
 void os_bsp_ctx_sw(void);
 
 #endif /* _OS_ARCH_X86_H */ 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/libs/os/include/os/arch/cortex_m4/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m4/os/os_arch.h b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
index 590542a..8c67f09 100755
--- a/libs/os/include/os/arch/cortex_m4/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
@@ -69,7 +69,6 @@ void os_default_irq_asm(void);
 
 /* External function prototypes supplied by BSP */
 void os_bsp_systick_init(uint32_t os_tick_per_sec, int prio);
-void os_bsp_init(void);
 void os_bsp_idle(os_time_t ticks);
 void os_bsp_ctx_sw(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/libs/os/include/os/arch/sim/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/sim/os/os_arch.h b/libs/os/include/os/arch/sim/os/os_arch.h
index 6b98b8e..d9570c8 100644
--- a/libs/os/include/os/arch/sim/os/os_arch.h
+++ b/libs/os/include/os/arch/sim/os/os_arch.h
@@ -71,6 +71,4 @@ os_error_t os_arch_os_init(void);
 void os_arch_os_stop(void);
 os_error_t os_arch_os_start(void);
 
-void os_bsp_init(void);
-
 #endif /* _OS_ARCH_SIM_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/libs/os/src/arch/cortex_m0/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/os_arch_arm.c b/libs/os/src/arch/cortex_m0/os_arch_arm.c
index f5403f3..12df443 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -19,6 +19,7 @@
 
 #include "os/os.h"
 #include "os/os_arch.h"
+#include <hal/hal_bsp.h>
 #include <hal/hal_os_tick.h>
 #include <bsp/cmsis_nvic.h>
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/libs/os/src/arch/cortex_m4/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_arch_arm.c b/libs/os/src/arch/cortex_m4/os_arch_arm.c
index 6023eca..a02c217 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -19,6 +19,7 @@
 
 #include "os/os.h"
 #include "os/os_arch.h"
+#include <hal/hal_bsp.h>
 #include <hal/hal_os_tick.h>
 #include <bsp/cmsis_nvic.h>
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/libs/os/src/arch/sim/os_arch_sim.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/sim/os_arch_sim.c b/libs/os/src/arch/sim/os_arch_sim.c
index 14316c5..4fbf2bb 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -20,6 +20,8 @@
 #include "os/os.h"
 #include "os_priv.h"
 
+#include <hal/hal_bsp.h>
+
 #ifdef __APPLE__
 #define _XOPEN_SOURCE
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b3ca007/sys/coredump/src/coredump.c
----------------------------------------------------------------------
diff --git a/sys/coredump/src/coredump.c b/sys/coredump/src/coredump.c
index 97ef749..b9743d0 100644
--- a/sys/coredump/src/coredump.c
+++ b/sys/coredump/src/coredump.c
@@ -16,8 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#include <bsp/bsp.h>
-
+#include <hal/hal_bsp.h>
 #include <hal/flash_map.h>
 #include <bootutil/image.h>
 #include <imgmgr/imgmgr.h>


[08/18] incubator-mynewt-core git commit: newtmgr; add error code for 'not found'.

Posted by ma...@apache.org.
newtmgr; add error code for 'not found'.


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

Branch: refs/heads/develop
Commit: 52f847b1aaa5ec9dfd1fae2275bcb317611d4ad5
Parents: 5fb0507
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 15:16:12 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:34:27 2016 -0700

----------------------------------------------------------------------
 libs/newtmgr/include/newtmgr/newtmgr.h | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/52f847b1/libs/newtmgr/include/newtmgr/newtmgr.h
----------------------------------------------------------------------
diff --git a/libs/newtmgr/include/newtmgr/newtmgr.h b/libs/newtmgr/include/newtmgr/newtmgr.h
index 4a6c370..c2c327d 100644
--- a/libs/newtmgr/include/newtmgr/newtmgr.h
+++ b/libs/newtmgr/include/newtmgr/newtmgr.h
@@ -48,6 +48,7 @@
 #define NMGR_ERR_ENOMEM   (2)
 #define NMGR_ERR_EINVAL   (3)
 #define NMGR_ERR_ETIMEOUT (4)
+#define NMGR_ERR_ENOENT   (5)
 #define NMGR_ERR_EPERUSER (256)
 
 


[16/18] incubator-mynewt-core git commit: hal/bsp; add hal_bsp.h, which exports common BSP APIs.

Posted by ma...@apache.org.
hal/bsp; add hal_bsp.h, which exports common BSP APIs.


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

Branch: refs/heads/develop
Commit: e87c89db73be7864579c94a6f56f09b04bfd077e
Parents: 0b3ca00
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 20:35:43 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:35:45 2016 -0700

----------------------------------------------------------------------
 hw/hal/src/hal_flash.c | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e87c89db/hw/hal/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
index 8d360c5..b2aea19 100644
--- a/hw/hal/src/hal_flash.c
+++ b/hw/hal/src/hal_flash.c
@@ -20,6 +20,7 @@
 #include <assert.h>
 #include <bsp/bsp.h>
 
+#include "hal/hal_bsp.h"
 #include "hal/hal_flash.h"
 #include "hal/hal_flash_int.h"
 


[09/18] incubator-mynewt-core git commit: coredump; add C++ protection around the API.

Posted by ma...@apache.org.
coredump; add C++ protection around the API.


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

Branch: refs/heads/develop
Commit: 807955e691fbe10182582939f348d0a4888cc6f1
Parents: e87c89d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 20:36:00 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:35:45 2016 -0700

----------------------------------------------------------------------
 sys/coredump/include/coredump/coredump.h | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/807955e6/sys/coredump/include/coredump/coredump.h
----------------------------------------------------------------------
diff --git a/sys/coredump/include/coredump/coredump.h b/sys/coredump/include/coredump/coredump.h
index 1cf8b9b..e3eeadd 100644
--- a/sys/coredump/include/coredump/coredump.h
+++ b/sys/coredump/include/coredump/coredump.h
@@ -20,6 +20,10 @@
 #ifndef __COREDUMP_H__
 #define __COREDUMP_H__
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <inttypes.h>
 
 #define COREDUMP_MAGIC              0x690c47c3
@@ -48,4 +52,8 @@ struct coredump_header {
 
 void dump_core(void *regs, int regs_sz);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif


[15/18] incubator-mynewt-core git commit: coredump; use bsp_core_dump() to figure out memory areas to dump. If memory region is > 64k, split it into multiple areas.

Posted by ma...@apache.org.
coredump; use bsp_core_dump() to figure out memory areas to dump.
If memory region is > 64k, split it into multiple areas.


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

Branch: refs/heads/develop
Commit: c37da5d3d4c55a256b7209e27d4ee5bd1ebe544d
Parents: 1bbd2da
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu May 19 09:27:07 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:35:45 2016 -0700

----------------------------------------------------------------------
 sys/coredump/src/coredump.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c37da5d3/sys/coredump/src/coredump.c
----------------------------------------------------------------------
diff --git a/sys/coredump/src/coredump.c b/sys/coredump/src/coredump.c
index b9743d0..2161ef8 100644
--- a/sys/coredump/src/coredump.c
+++ b/sys/coredump/src/coredump.c
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+#include <limits.h>
 #include <hal/hal_bsp.h>
 #include <hal/flash_map.h>
 #include <bootutil/image.h>
@@ -33,8 +34,6 @@ dump_core_tlv(const struct flash_area *fa, uint32_t *off,
     *off += tlv->ct_len;
 }
 
-extern char *__vector_tbl_reloc__, *__StackTop;
-
 void
 dump_core(void *regs, int regs_sz)
 {
@@ -42,8 +41,11 @@ dump_core(void *regs, int regs_sz)
     struct coredump_tlv tlv;
     const struct flash_area *fa;
     struct image_version ver;
+    const struct bsp_mem_dump *mem, *cur;
+    int area_cnt, i;
     uint8_t hash[IMGMGR_HASH_LEN];
     uint32_t off;
+    uint32_t area_off, area_end;
 
     if (flash_area_open(FLASH_AREA_CORE, &fa)) {
         return;
@@ -81,11 +83,23 @@ dump_core(void *regs, int regs_sz)
         dump_core_tlv(fa, &off, &tlv, hash);
     }
 
-    tlv.ct_type = COREDUMP_TLV_MEM;
-    tlv.ct_len = (uint32_t)&__StackTop - (uint32_t)&__vector_tbl_reloc__;
-    tlv.ct_off = (uint32_t)&__vector_tbl_reloc__;
-    dump_core_tlv(fa, &off, &tlv, &__vector_tbl_reloc__);
-
+    mem = bsp_core_dump(&area_cnt);
+    for (i = 0; i < area_cnt; i++) {
+        cur = &mem[i];
+        area_off = (uint32_t)cur->bmd_start;
+        area_end = area_off + cur->bmd_size;
+        while (area_off < area_end) {
+            tlv.ct_type = COREDUMP_TLV_MEM;
+            if (cur->bmd_size > USHRT_MAX) {
+                tlv.ct_len = SHRT_MAX + 1;
+            } else {
+                tlv.ct_len = cur->bmd_size;
+            }
+            tlv.ct_off = area_off;
+            dump_core_tlv(fa, &off, &tlv, (void *)area_off);
+            area_off += tlv.ct_len;
+        }
+    }
     hdr.ch_magic = COREDUMP_MAGIC;
     hdr.ch_size = off;
 


[03/18] incubator-mynewt-core git commit: flash_map; insert placeholder for coredump. XXX will need it's own number.

Posted by ma...@apache.org.
flash_map; insert placeholder for coredump. XXX will need it's own
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/61ca3db7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/61ca3db7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/61ca3db7

Branch: refs/heads/develop
Commit: 61ca3db73f2b9b0974e500c5e07e3ff1aebc061d
Parents: dfbac67
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 15:24:19 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:34:27 2016 -0700

----------------------------------------------------------------------
 hw/hal/include/hal/flash_map.h | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/61ca3db7/hw/hal/include/hal/flash_map.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/flash_map.h b/hw/hal/include/hal/flash_map.h
index 078d0a3..979a069 100644
--- a/hw/hal/include/hal/flash_map.h
+++ b/hw/hal/include/hal/flash_map.h
@@ -58,6 +58,7 @@ struct flash_area {
 #define FLASH_AREA_IMAGE_1              2
 #define FLASH_AREA_IMAGE_SCRATCH        3
 #define FLASH_AREA_NFFS                 4
+#define FLASH_AREA_CORE                 2
 
 /*
  * Initializes flash map. Memory will be referenced by flash_map code


[13/18] incubator-mynewt-core git commit: os/cortex_m4; install default IRQ handler for NMI.

Posted by ma...@apache.org.
os/cortex_m4; install default IRQ handler for NMI.


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

Branch: refs/heads/develop
Commit: 9add53bdf0279e77a6f6cfb7511ce27994dd6671
Parents: c37da5d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu May 19 09:28:56 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:35:45 2016 -0700

----------------------------------------------------------------------
 libs/os/src/arch/cortex_m4/os_arch_arm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9add53bd/libs/os/src/arch/cortex_m4/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_arch_arm.c b/libs/os/src/arch/cortex_m4/os_arch_arm.c
index 837e941..2bd084a 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -199,7 +199,8 @@ os_arch_os_init(void)
          * state at the time of the interrupt, and few other regs which
          * should help in trying to figure out what went wrong.
          */
-        NVIC_SetVector(-13, (uint32_t)os_default_irq_asm); /* Hardfault */
+        NVIC_SetVector(NonMaskableInt_IRQn, (uint32_t)os_default_irq_asm);
+        NVIC_SetVector(-13, (uint32_t)os_default_irq_asm);
         NVIC_SetVector(MemoryManagement_IRQn, (uint32_t)os_default_irq_asm);
         NVIC_SetVector(BusFault_IRQn, (uint32_t)os_default_irq_asm);
         NVIC_SetVector(UsageFault_IRQn, (uint32_t)os_default_irq_asm);


[06/18] incubator-mynewt-core git commit: imgmgr; support downloading core files.

Posted by ma...@apache.org.
imgmgr; support downloading core files.


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

Branch: refs/heads/develop
Commit: dfbac6757f9158e4627eeeb0de6b43ab9afc87bf
Parents: a7d054c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 15:22:19 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:34:27 2016 -0700

----------------------------------------------------------------------
 libs/imgmgr/include/imgmgr/imgmgr.h |  11 +-
 libs/imgmgr/pkg.yml                 |   4 +
 libs/imgmgr/src/imgmgr.c            |  19 +++-
 libs/imgmgr/src/imgmgr_coredump.c   | 178 +++++++++++++++++++++++++++++++
 libs/imgmgr/src/imgmgr_priv.h       |   5 +-
 5 files changed, 213 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dfbac675/libs/imgmgr/include/imgmgr/imgmgr.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/include/imgmgr/imgmgr.h b/libs/imgmgr/include/imgmgr/imgmgr.h
index 511f1e0..e5e3596 100644
--- a/libs/imgmgr/include/imgmgr/imgmgr.h
+++ b/libs/imgmgr/include/imgmgr/imgmgr.h
@@ -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,
@@ -26,11 +26,15 @@
 #define IMGMGR_NMGR_OP_FILE		3
 #define IMGMGR_NMGR_OP_LIST2		4
 #define IMGMGR_NMGR_OP_BOOT2		5
+#define IMGMGR_NMGR_OP_CORELIST		6
+#define IMGMGR_NMGR_OP_CORELOAD		7
 
 #define IMGMGR_NMGR_MAX_MSG		120
 #define IMGMGR_NMGR_MAX_NAME		64
 #define IMGMGR_NMGR_MAX_VER		25	/* 255.255.65535.4294967295\0 */
 
+#define IMGMGR_HASH_LEN                 32
+
 int imgmgr_module_init(void);
 
 struct image_version;
@@ -45,4 +49,9 @@ int imgr_ver_parse(char *src, struct image_version *ver);
  */
 int imgr_ver_str(struct image_version *ver, char *dst);
 
+/*
+ * Given flash_map slot id, read in image_version and/or image hash.
+ */
+int imgr_read_info(int area_id, struct image_version *ver, uint8_t *hash);
+
 #endif /* _IMGMGR_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dfbac675/libs/imgmgr/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/imgmgr/pkg.yml b/libs/imgmgr/pkg.yml
index 93b8b00..ed02f32 100644
--- a/libs/imgmgr/pkg.yml
+++ b/libs/imgmgr/pkg.yml
@@ -30,3 +30,7 @@ pkg.deps:
 pkg.deps.FS:
     - fs/fs
 pkg.cflags.FS: -DFS_PRESENT
+
+pkg.deps.COREDUMP:
+    - sys/coredump
+pkg.cflags.COREDUMP: -DCOREDUMP_PRESENT

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dfbac675/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index e12fc73..b730d66 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@ -66,8 +66,25 @@ static const struct nmgr_handler imgr_nmgr_handlers[] = {
     [IMGMGR_NMGR_OP_BOOT2] = {
         .nh_read = imgr_boot2_read,
         .nh_write = imgr_boot2_write
+    },
+    [IMGMGR_NMGR_OP_CORELIST] = {
+#ifdef COREDUMP_PRESENT
+        .nh_read = imgr_core_list,
+        .nh_write = imgr_noop,
+#else
+        .nh_read = imgr_noop,
+        .nh_write = imgr_noop
+#endif
+    },
+    [IMGMGR_NMGR_OP_CORELOAD] = {
+#ifdef COREDUMP_PRESENT
+        .nh_read = imgr_core_load,
+        .nh_write = imgr_core_erase,
+#else
+        .nh_read = imgr_noop,
+        .nh_write = imgr_noop
+#endif
     }
-
 };
 
 static struct nmgr_group imgr_nmgr_group = {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dfbac675/libs/imgmgr/src/imgmgr_coredump.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_coredump.c b/libs/imgmgr/src/imgmgr_coredump.c
new file mode 100644
index 0000000..6a09a5a
--- /dev/null
+++ b/libs/imgmgr/src/imgmgr_coredump.c
@@ -0,0 +1,178 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifdef COREDUMP_PRESENT
+
+#include <limits.h>
+
+#include <hal/flash_map.h>
+#include <newtmgr/newtmgr.h>
+#include <coredump/coredump.h>
+#include <util/base64.h>
+
+#include "imgmgr/imgmgr.h"
+#include "imgmgr_priv.h"
+
+int
+imgr_core_list(struct nmgr_jbuf *njb)
+{
+    const struct flash_area *fa;
+    struct coredump_header hdr;
+    struct json_encoder *enc;
+    struct json_value jv;
+    int rc;
+
+    rc = flash_area_open(FLASH_AREA_CORE, &fa);
+    if (rc) {
+        rc = NMGR_ERR_EINVAL;
+    } else {
+        rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
+        if (rc != 0) {
+            rc = NMGR_ERR_EINVAL;
+        } else if (hdr.ch_magic != COREDUMP_MAGIC) {
+            rc = NMGR_ERR_ENOENT;
+        } else {
+            rc = 0;
+        }
+    }
+
+    enc = &njb->njb_enc;
+
+    json_encode_object_start(enc);
+    JSON_VALUE_INT(&jv, rc);
+    json_encode_object_entry(enc, "rc", &jv);
+    json_encode_object_finish(enc);
+
+    return 0;
+}
+
+int
+imgr_core_load(struct nmgr_jbuf *njb)
+{
+    unsigned int off = UINT_MAX;
+    const struct json_attr_t dload_attr[2] = {
+        [0] = {
+            .attribute = "off",
+            .type = t_uinteger,
+            .addr.uinteger = &off
+        }
+    };
+    int rc;
+    int sz;
+    const struct flash_area *fa;
+    char data[IMGMGR_NMGR_MAX_MSG];
+    char encoded[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
+    struct coredump_header *hdr;
+    struct json_encoder *enc;
+    struct json_value jv;
+
+    hdr = (struct coredump_header *)data;
+
+    rc = json_read_object(&njb->njb_buf, dload_attr);
+    if (rc || off == UINT_MAX) {
+        rc = NMGR_ERR_EINVAL;
+        goto err;
+    }
+
+    rc = flash_area_open(FLASH_AREA_CORE, &fa);
+    if (rc) {
+        rc = NMGR_ERR_EINVAL;
+        goto err;
+    }
+
+    rc = flash_area_read(fa, 0, hdr, sizeof(*hdr));
+    if (rc) {
+        rc = NMGR_ERR_EINVAL;
+        goto err_close;
+    }
+    if (hdr->ch_magic != COREDUMP_MAGIC) {
+        rc = NMGR_ERR_ENOENT;
+        goto err_close;
+    }
+    if (off > hdr->ch_size) {
+        off = hdr->ch_size;
+    }
+    sz = hdr->ch_size - off;
+    if (sz > sizeof(data)) {
+        sz = sizeof(data);
+    }
+
+    rc = flash_area_read(fa, off, data, sz);
+    if (rc) {
+        rc = NMGR_ERR_EINVAL;
+        goto err_close;
+    }
+
+    sz = base64_encode(data, sz, encoded, 1);
+
+    enc = &njb->njb_enc;
+
+    json_encode_object_start(enc);
+    JSON_VALUE_INT(&jv, 0);
+    json_encode_object_entry(enc, "rc", &jv);
+
+    JSON_VALUE_INT(&jv, off);
+    json_encode_object_entry(enc, "off", &jv);
+
+    JSON_VALUE_STRINGN(&jv, encoded, sz);
+    json_encode_object_entry(enc, "data", &jv);
+    json_encode_object_finish(enc);
+
+    flash_area_close(fa);
+    return 0;
+
+err_close:
+    flash_area_close(fa);
+err:
+    nmgr_jbuf_setoerr(njb, rc);
+    return 0;
+}
+
+/*
+ * Erase the area if it has a coredump, or the header is empty.
+ */
+int
+imgr_core_erase(struct nmgr_jbuf *njb)
+{
+    struct coredump_header hdr;
+    const struct flash_area *fa;
+    int rc;
+
+    rc = flash_area_open(FLASH_AREA_CORE, &fa);
+    if (rc) {
+        rc = NMGR_ERR_EINVAL;
+        goto err;
+    }
+
+    rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
+    if (rc == 0 &&
+      (hdr.ch_magic == COREDUMP_MAGIC || hdr.ch_magic == 0xffffffff)) {
+        rc = flash_area_erase(fa, 0, fa->fa_size);
+        if (rc) {
+            rc = NMGR_ERR_EINVAL;
+        }
+    }
+    rc = 0;
+
+    flash_area_close(fa);
+err:
+    nmgr_jbuf_setoerr(njb, rc);
+    return 0;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dfbac675/libs/imgmgr/src/imgmgr_priv.h
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_priv.h b/libs/imgmgr/src/imgmgr_priv.h
index 04323af..e8dcde3 100644
--- a/libs/imgmgr/src/imgmgr_priv.h
+++ b/libs/imgmgr/src/imgmgr_priv.h
@@ -25,7 +25,6 @@
 #define IMGMGR_MAX_IMGS		2
 
 #define IMGMGR_HASH_STR		48
-#define IMGMGR_HASH_LEN		32
 
 /*
  * When accompanied by image, it's this structure followed by data.
@@ -102,8 +101,10 @@ int imgr_boot2_read(struct nmgr_jbuf *);
 int imgr_boot2_write(struct nmgr_jbuf *);
 int imgr_file_upload(struct nmgr_jbuf *);
 int imgr_file_download(struct nmgr_jbuf *);
+int imgr_core_list(struct nmgr_jbuf *);
+int imgr_core_load(struct nmgr_jbuf *);
+int imgr_core_erase(struct nmgr_jbuf *);
 
-int imgr_read_info(int area_id, struct image_version *ver, uint8_t *hash);
 int imgr_find_by_ver(struct image_version *find, uint8_t *hash);
 int imgr_find_by_hash(uint8_t *find, struct image_version *ver);
 


[07/18] incubator-mynewt-core git commit: libs/os; coredumps for Cortex-M0.

Posted by ma...@apache.org.
libs/os; coredumps for Cortex-M0.


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

Branch: refs/heads/develop
Commit: e157f02130a7cea4f1467c68b9df4fa3a0640497
Parents: 61ca3db
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 15:25:35 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:34:27 2016 -0700

----------------------------------------------------------------------
 libs/os/pkg.yml                       |   4 ++
 libs/os/src/arch/cortex_m0/os_fault.c | 103 +++++++++++++++++++++++------
 2 files changed, 87 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e157f021/libs/os/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/os/pkg.yml b/libs/os/pkg.yml
index 98eeb3c..85133e1 100644
--- a/libs/os/pkg.yml
+++ b/libs/os/pkg.yml
@@ -33,5 +33,9 @@ pkg.deps.SHELL:
     - libs/shell 
 pkg.cflags.SHELL: -DSHELL_PRESENT 
 
+pkg.deps.COREDUMP:
+    - sys/coredump
+pkg.cflags.COREDUMP: -DCOREDUMP_PRESENT
+
 # Satisfy capability dependencies for the self-contained test executable.
 pkg.deps.SELFTEST: libs/console/stub

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e157f021/libs/os/src/arch/cortex_m0/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/os_fault.c b/libs/os/src/arch/cortex_m0/os_fault.c
index c46f8a8..f3d1ffb 100644
--- a/libs/os/src/arch/cortex_m0/os_fault.c
+++ b/libs/os/src/arch/cortex_m0/os_fault.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,
@@ -19,30 +19,14 @@
 
 #include <console/console.h>
 #include <hal/hal_system.h>
+#ifdef COREDUMP_PRESENT
+#include <coredump/coredump.h>
+#endif
 #include "os/os.h"
 
 #include <stdint.h>
 #include <unistd.h>
 
-int             os_die_line;
-const char     *os_die_module;
-
-void __assert_func(const char *file, int line, const char *func, const char *e);
-
-void
-__assert_func(const char *file, int line, const char *func, const char *e)
-{
-    int sr;
-
-    OS_ENTER_CRITICAL(sr);
-    (void)sr;
-    os_die_line = line;
-    os_die_module = file;
-    console_blocking_mode();
-    console_printf("Assert %s; failed in %s:%d\n", e ? e : "", file, line);
-    system_reset();
-}
-
 struct exception_frame {
     uint32_t r0;
     uint32_t r1;
@@ -67,9 +51,84 @@ struct trap_frame {
     uint32_t lr;    /* this LR holds EXC_RETURN */
 };
 
+struct coredump_regs {
+    uint32_t r0;
+    uint32_t r1;
+    uint32_t r2;
+    uint32_t r3;
+    uint32_t r4;
+    uint32_t r5;
+    uint32_t r6;
+    uint32_t r7;
+    uint32_t r8;
+    uint32_t r9;
+    uint32_t r10;
+    uint32_t r11;
+    uint32_t r12;
+    uint32_t sp;
+    uint32_t lr;
+    uint32_t pc;
+    uint32_t psr;
+};
+
+void __assert_func(const char *file, int line, const char *func, const char *e);
+
+#ifdef COREDUMP_PRESENT
+static void
+trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs)
+{
+    regs->r0 = tf->ef->r0;
+    regs->r1 = tf->ef->r1;
+    regs->r2 = tf->ef->r2;
+    regs->r3 = tf->ef->r3;
+    regs->r4 = tf->r4;
+    regs->r5 = tf->r5;
+    regs->r6 = tf->r6;
+    regs->r7 = tf->r7;
+    regs->r8 = tf->r8;
+    regs->r9 = tf->r9;
+    regs->r10 = tf->r10;
+    regs->r11 = tf->r11;
+    regs->r12 = tf->ef->r12;
+    /*
+     * SP just before exception for the coredump.
+     * See ARMv7-M Architecture Ref Manual, sections B1.5.6 - B1.5.8
+     * SP is adjusted by 0x20.
+     * If SCB->CCR.STKALIGN is set, SP is aligned to 8-byte boundary on
+     * exception entry.
+     * If this alignment adjustment happened, xPSR will have bit 9 set.
+     */
+    regs->sp = ((uint32_t)tf->ef) + 0x20;
+    if ((SCB->CCR & SCB_CCR_STKALIGN_Msk) & tf->ef->psr & (1 << 9)) {
+        regs->sp += 4;
+    }
+    regs->lr = tf->ef->lr;
+    regs->pc = tf->ef->pc;
+    regs->psr = tf->ef->psr;
+}
+#endif
+
+void
+__assert_func(const char *file, int line, const char *func, const char *e)
+{
+    int sr;
+
+    OS_ENTER_CRITICAL(sr);
+    (void)sr;
+    console_blocking_mode();
+    console_printf("Assert %s; failed in %s:%d\n", e ? e : "", file, line);
+    SCB->ICSR = SCB_ICSR_NMIPENDSET_Msk;
+    /* Exception happens right away. Next line not executed. */
+    system_reset();
+}
+
 void
 os_default_irq(struct trap_frame *tf)
 {
+#ifdef COREDUMP_PRESENT
+    struct coredump_regs regs;
+#endif
+
     console_blocking_mode();
     console_printf("Unhandled interrupt (%ld), exception sp 0x%08lx\n",
       SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk, (uint32_t)tf->ef);
@@ -82,6 +141,10 @@ os_default_irq(struct trap_frame *tf)
     console_printf("r12:0x%08lx  lr:0x%08lx  pc:0x%08lx psr:0x%08lx\n",
       tf->ef->r12, tf->ef->lr, tf->ef->pc, tf->ef->psr);
     console_printf("ICSR:0x%08lx\n", SCB->ICSR);
+#ifdef COREDUMP_PRESENT
+    trap_to_coredump(tf, &regs);
+    dump_core(&regs, sizeof(regs));
+#endif
     system_reset();
 }
 


[11/18] incubator-mynewt-core git commit: bsp; add bsp_core_dump() to report which areas to dump.

Posted by ma...@apache.org.
bsp; add bsp_core_dump() to report which areas to dump.


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

Branch: refs/heads/develop
Commit: 4b726ce9ff4904b69adf1b7bf31d9d2a826d3ef5
Parents: 7368608
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu May 19 09:14:43 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:35:45 2016 -0700

----------------------------------------------------------------------
 hw/bsp/bmd300eval/bmd300eval.ld                 |  2 ++
 hw/bsp/bmd300eval/include/bsp/bsp.h             |  6 +++++
 hw/bsp/bmd300eval/src/hal_bsp.c                 | 23 +++++++++++++++++-
 hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h        |  7 +++++-
 hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram.ld       |  2 ++
 hw/bsp/nrf51dk-16kbram/src/hal_bsp.c            | 18 ++++++++++++++
 hw/bsp/nrf51dk/include/bsp/bsp.h                |  5 ++++
 hw/bsp/nrf51dk/nrf51dk.ld                       |  2 ++
 hw/bsp/nrf51dk/src/hal_bsp.c                    | 21 +++++++++++++++-
 hw/bsp/nrf52dk/include/bsp/bsp.h                |  7 +++++-
 hw/bsp/nrf52dk/nrf52dk.ld                       |  2 ++
 hw/bsp/nrf52dk/src/hal_bsp.c                    | 20 ++++++++++++++++
 hw/bsp/nrf52pdk/include/bsp/bsp.h               |  8 +++++++
 hw/bsp/nrf52pdk/nrf52pdk.ld                     |  3 +++
 hw/bsp/nrf52pdk/src/hal_bsp.c                   | 20 ++++++++++++++++
 .../include/bsp/bsp.h                           |  8 +++++++
 .../olimex_stm32-e407_devboard.ld               |  3 +++
 hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c | 18 ++++++++++++++
 hw/hal/include/hal/hal_bsp.h                    | 25 +++++++++++++++++---
 19 files changed, 193 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/bmd300eval/bmd300eval.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/bmd300eval.ld b/hw/bsp/bmd300eval/bmd300eval.ld
index c019b63..d90df34 100755
--- a/hw/bsp/bmd300eval/bmd300eval.ld
+++ b/hw/bsp/bmd300eval/bmd300eval.ld
@@ -177,6 +177,8 @@ SECTIONS
     /* Heap starts after BSS */
     __HeapBase = .;
 
+    _ram_start = ORIGIN(RAM);
+
     /* .stack_dummy section doesn't contains any symbols. It is only
      * used for linker to calculate size of stack sections, and assign
      * values to stack symbols later */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/bmd300eval/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/include/bsp/bsp.h b/hw/bsp/bmd300eval/include/bsp/bsp.h
index 7638ff5..6edeeb4 100644
--- a/hw/bsp/bmd300eval/include/bsp/bsp.h
+++ b/hw/bsp/bmd300eval/include/bsp/bsp.h
@@ -20,6 +20,8 @@
 #ifndef H_BSP_H
 #define H_BSP_H
 
+#include <inttypes.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -32,6 +34,10 @@ extern "C" {
 /* More convenient section placement macros. */
 #define bssnz_t         sec_bss_nz_core
 
+extern uint8_t _ram_start;
+
+#define RAM_SIZE        0x10000
+
 /* LED pins */
 #define LED_BLINK_PIN   (17)
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/bmd300eval/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/src/hal_bsp.c b/hw/bsp/bmd300eval/src/hal_bsp.c
index 0b04610..0ac5ca8 100644
--- a/hw/bsp/bmd300eval/src/hal_bsp.c
+++ b/hw/bsp/bmd300eval/src/hal_bsp.c
@@ -18,7 +18,11 @@
  */
 #include <stdint.h>
 #include <stddef.h>
-#include "mcu/nrf52_hal.h"
+
+#include <hal/hal_bsp.h>
+#include <mcu/nrf52_hal.h>
+
+#include "bsp/bsp.h"
 
 static const struct nrf52_uart_cfg uart_cfg = {
     .suc_pin_tx = 6,
@@ -27,6 +31,16 @@ static const struct nrf52_uart_cfg uart_cfg = {
     .suc_pin_cts = 7
 };
 
+/*
+ * What memory to include in coredump.
+ */
+static const struct bsp_mem_dump dump_cfg[] = {
+    [0] = {
+        .bmd_start = &_ram_start,
+        .bmd_size = RAM_SIZE
+    }
+};
+
 const struct nrf52_uart_cfg *
 bsp_uart_config(void)
 {
@@ -44,3 +58,10 @@ bsp_flash_dev(uint8_t id)
     }
     return &nrf52k_flash_dev;
 }
+
+const struct bsp_mem_dump *
+bsp_core_dump(int *area_cnt)
+{
+    *area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
+    return dump_cfg;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h b/hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h
index 72370ff..c7eb661 100644
--- a/hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h
+++ b/hw/bsp/nrf51dk-16kbram/include/bsp/bsp.h
@@ -20,6 +20,8 @@
 #ifndef H_BSP_H
 #define H_BSP_H
 
+#include <inttypes.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -31,13 +33,16 @@ extern "C" {
 /* More convenient section placement macros. */
 #define bssnz_t
 
+extern uint8_t _ram_start;
+#define RAM_SIZE        0x4000
+
 /* LED pins */
 #define LED_BLINK_PIN   (21)
 
 /* UART info */
 #define CONSOLE_UART    0
 
-#define NFFS_AREA_MAX    (8)
+#define NFFS_AREA_MAX   (8)
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram.ld b/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram.ld
index 043af42..bae91f1 100755
--- a/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram.ld
+++ b/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram.ld
@@ -169,6 +169,8 @@ SECTIONS
         *(.stack*)
     } > RAM
 
+    _ram_start = ORIGIN(RAM);
+
     /* Set stack top to end of RAM, and stack limit move down by
      * size of stack_dummy section */
     __StackTop = ORIGIN(RAM) + LENGTH(RAM);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf51dk-16kbram/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/src/hal_bsp.c b/hw/bsp/nrf51dk-16kbram/src/hal_bsp.c
index 868ace8..3bc833e 100644
--- a/hw/bsp/nrf51dk-16kbram/src/hal_bsp.c
+++ b/hw/bsp/nrf51dk-16kbram/src/hal_bsp.c
@@ -21,6 +21,7 @@
 #include <stddef.h>
 #include <hal/hal_bsp.h>
 #include <mcu/nrf51_hal.h>
+#include "bsp/bsp.h"
 
 static const struct nrf51_uart_cfg uart_cfg = {
     .suc_pin_tx = 9,
@@ -29,6 +30,16 @@ static const struct nrf51_uart_cfg uart_cfg = {
     .suc_pin_cts = 10
 };
 
+/*
+ * What memory to include in coredump.
+ */
+static const struct bsp_mem_dump dump_cfg[] = {
+    [0] = {
+        .bmd_start = &_ram_start,
+        .bmd_size = RAM_SIZE
+    }
+};
+
 const struct nrf51_uart_cfg *bsp_uart_config(void)
 {
     return &uart_cfg;
@@ -45,3 +56,10 @@ bsp_flash_dev(uint8_t id)
     }
     return &nrf51_flash_dev;
 }
+
+const struct bsp_mem_dump *
+bsp_core_dump(int *area_cnt)
+{
+    *area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
+    return dump_cfg;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf51dk/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/include/bsp/bsp.h b/hw/bsp/nrf51dk/include/bsp/bsp.h
index 6e2ab08..87302ee 100644
--- a/hw/bsp/nrf51dk/include/bsp/bsp.h
+++ b/hw/bsp/nrf51dk/include/bsp/bsp.h
@@ -20,6 +20,8 @@
 #ifndef H_BSP_H
 #define H_BSP_H
 
+#include <inttypes.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -31,6 +33,9 @@ extern "C" {
 /* More convenient section placement macros. */
 #define bssnz_t
 
+extern uint8_t _ram_start;
+#define RAM_SIZE        0x8000
+
 /* LED pins */
 #define LED_BLINK_PIN   (21)
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf51dk/nrf51dk.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/nrf51dk.ld b/hw/bsp/nrf51dk/nrf51dk.ld
index 094f2c4..21f6aab 100755
--- a/hw/bsp/nrf51dk/nrf51dk.ld
+++ b/hw/bsp/nrf51dk/nrf51dk.ld
@@ -169,6 +169,8 @@ SECTIONS
         *(.stack*)
     } > RAM
 
+    _ram_start = ORIGIN(RAM);
+
     /* Set stack top to end of RAM, and stack limit move down by
      * size of stack_dummy section */
     __StackTop = ORIGIN(RAM) + LENGTH(RAM);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf51dk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/hal_bsp.c b/hw/bsp/nrf51dk/src/hal_bsp.c
index bfca6f9..3bc833e 100644
--- a/hw/bsp/nrf51dk/src/hal_bsp.c
+++ b/hw/bsp/nrf51dk/src/hal_bsp.c
@@ -19,7 +19,9 @@
 
 #include <stdint.h>
 #include <stddef.h>
-#include "mcu/nrf51_hal.h"
+#include <hal/hal_bsp.h>
+#include <mcu/nrf51_hal.h>
+#include "bsp/bsp.h"
 
 static const struct nrf51_uart_cfg uart_cfg = {
     .suc_pin_tx = 9,
@@ -28,6 +30,16 @@ static const struct nrf51_uart_cfg uart_cfg = {
     .suc_pin_cts = 10
 };
 
+/*
+ * What memory to include in coredump.
+ */
+static const struct bsp_mem_dump dump_cfg[] = {
+    [0] = {
+        .bmd_start = &_ram_start,
+        .bmd_size = RAM_SIZE
+    }
+};
+
 const struct nrf51_uart_cfg *bsp_uart_config(void)
 {
     return &uart_cfg;
@@ -44,3 +56,10 @@ bsp_flash_dev(uint8_t id)
     }
     return &nrf51_flash_dev;
 }
+
+const struct bsp_mem_dump *
+bsp_core_dump(int *area_cnt)
+{
+    *area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
+    return dump_cfg;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf52dk/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/include/bsp/bsp.h b/hw/bsp/nrf52dk/include/bsp/bsp.h
index 7638ff5..a9e2c01 100644
--- a/hw/bsp/nrf52dk/include/bsp/bsp.h
+++ b/hw/bsp/nrf52dk/include/bsp/bsp.h
@@ -20,6 +20,8 @@
 #ifndef H_BSP_H
 #define H_BSP_H
 
+#include <inttypes.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -32,13 +34,16 @@ extern "C" {
 /* More convenient section placement macros. */
 #define bssnz_t         sec_bss_nz_core
 
+extern uint8_t _ram_start;
+#define RAM_SIZE        0x10000
+
 /* LED pins */
 #define LED_BLINK_PIN   (17)
 
 /* UART info */
 #define CONSOLE_UART    0
 
-#define NFFS_AREA_MAX    (8)
+#define NFFS_AREA_MAX   (8)
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf52dk/nrf52dk.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/nrf52dk.ld b/hw/bsp/nrf52dk/nrf52dk.ld
index c019b63..e131176 100755
--- a/hw/bsp/nrf52dk/nrf52dk.ld
+++ b/hw/bsp/nrf52dk/nrf52dk.ld
@@ -185,6 +185,8 @@ SECTIONS
         *(.stack*)
     } > RAM
 
+    _ram_start = ORIGIN(RAM);
+
     /* Set stack top to end of RAM, and stack limit move down by
      * size of stack_dummy section */
     __StackTop = ORIGIN(RAM) + LENGTH(RAM);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf52dk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/hal_bsp.c b/hw/bsp/nrf52dk/src/hal_bsp.c
index 0b04610..2f0b4d9 100644
--- a/hw/bsp/nrf52dk/src/hal_bsp.c
+++ b/hw/bsp/nrf52dk/src/hal_bsp.c
@@ -18,6 +18,9 @@
  */
 #include <stdint.h>
 #include <stddef.h>
+
+#include "bsp/bsp.h"
+#include <hal/hal_bsp.h>
 #include "mcu/nrf52_hal.h"
 
 static const struct nrf52_uart_cfg uart_cfg = {
@@ -27,6 +30,16 @@ static const struct nrf52_uart_cfg uart_cfg = {
     .suc_pin_cts = 7
 };
 
+/*
+ * What memory to include in coredump.
+ */
+static const struct bsp_mem_dump dump_cfg[] = {
+    [0] = {
+	.bmd_start = &_ram_start,
+        .bmd_size = RAM_SIZE
+    }
+};
+
 const struct nrf52_uart_cfg *
 bsp_uart_config(void)
 {
@@ -44,3 +57,10 @@ bsp_flash_dev(uint8_t id)
     }
     return &nrf52k_flash_dev;
 }
+
+const struct bsp_mem_dump *
+bsp_core_dump(int *area_cnt)
+{
+    *area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
+    return dump_cfg;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf52pdk/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/include/bsp/bsp.h b/hw/bsp/nrf52pdk/include/bsp/bsp.h
index 7638ff5..4c94916 100644
--- a/hw/bsp/nrf52pdk/include/bsp/bsp.h
+++ b/hw/bsp/nrf52pdk/include/bsp/bsp.h
@@ -20,6 +20,8 @@
 #ifndef H_BSP_H
 #define H_BSP_H
 
+#include <inttypes.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -32,6 +34,12 @@ extern "C" {
 /* More convenient section placement macros. */
 #define bssnz_t         sec_bss_nz_core
 
+extern uint8_t _ram_start;
+extern uint8_t _code_ram_start;
+
+#define RAM_SIZE        0x8000
+#define CODE_RAM_SIZE   0x8000
+
 /* LED pins */
 #define LED_BLINK_PIN   (17)
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf52pdk/nrf52pdk.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/nrf52pdk.ld b/hw/bsp/nrf52pdk/nrf52pdk.ld
index 463f769..b612f5f 100755
--- a/hw/bsp/nrf52pdk/nrf52pdk.ld
+++ b/hw/bsp/nrf52pdk/nrf52pdk.ld
@@ -178,6 +178,9 @@ SECTIONS
     /* Heap starts after BSS */
     __HeapBase = .;
 
+    _ram_start = ORIGIN(RAM);
+    _code_ram_start = ORIGIN(CODE_RAM);
+
     /* .stack_dummy section doesn't contains any symbols. It is only
      * used for linker to calculate size of stack sections, and assign
      * values to stack symbols later */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/nrf52pdk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/hal_bsp.c b/hw/bsp/nrf52pdk/src/hal_bsp.c
index 521aa61..328c408 100644
--- a/hw/bsp/nrf52pdk/src/hal_bsp.c
+++ b/hw/bsp/nrf52pdk/src/hal_bsp.c
@@ -22,6 +22,8 @@
 #include <hal/hal_bsp.h>
 #include <mcu/nrf52_hal.h>
 
+#include "bsp/bsp.h"
+
 static const struct nrf52_uart_cfg uart_cfg = {
     .suc_pin_tx = 6,
     .suc_pin_rx = 8,
@@ -29,6 +31,17 @@ static const struct nrf52_uart_cfg uart_cfg = {
     .suc_pin_cts = 7
 };
 
+static const struct bsp_mem_dump dump_cfg[] = {
+    [0] = {
+        .bmd_start = &_ram_start,
+        .bmd_size = RAM_SIZE
+    },
+    [1] = {
+        .bmd_start = &_code_ram_start,
+        .bmd_size = CODE_RAM_SIZE
+    }
+};
+
 const struct nrf52_uart_cfg *
 bsp_uart_config(void)
 {
@@ -46,3 +59,10 @@ bsp_flash_dev(uint8_t id)
     }
     return &nrf52k_flash_dev;
 }
+
+const struct bsp_mem_dump *
+bsp_core_dump(int *area_cnt)
+{
+    *area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
+    return dump_cfg;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h b/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
index d39ddca..7751025 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
+++ b/hw/bsp/olimex_stm32-e407_devboard/include/bsp/bsp.h
@@ -19,6 +19,8 @@
 #ifndef H_BSP_H
 #define H_BSP_H
 
+#include <inttypes.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -31,6 +33,12 @@ extern "C" {
 /* More convenient section placement macros. */
 #define bssnz_t         sec_bss_nz_core
 
+extern uint8_t _ram_start;
+extern uint8_t _ccram_start;
+
+#define RAM_SIZE        (128 * 1024)
+#define CCRAM_SIZE      (64 * 1024)
+
 /* LED pins */
 #define LED_BLINK_PIN   (45)
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard.ld b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard.ld
index 50b8290..4c1541d 100755
--- a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard.ld
+++ b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard.ld
@@ -191,6 +191,9 @@ SECTIONS
     __HeapBase = .;
     __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
 
+    _ram_start = ORIGIN(RAM);
+    _ccram_start = ORIGIN(CCRAM);
+
     /* .stack_dummy section doesn't contains any symbols. It is only
      * used for linker to calculate size of stack sections, and assign
      * values to stack symbols later */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c b/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
index ec1d2a4..b68e370 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
+++ b/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
@@ -39,6 +39,17 @@ static const struct stm32f4_uart_cfg uart_cfg[UART_CNT] = {
     }
 };
 
+static const struct bsp_mem_dump dump_cfg[] = {
+    [0] = {
+        .bmd_start = &_ram_start,
+        .bmd_size = RAM_SIZE
+    },
+    [1] = {
+        .bmd_start = &_ccram_start,
+        .bmd_size = CCRAM_SIZE
+    }
+};
+
 const struct stm32f4_uart_cfg *
 bsp_uart_config(int port)
 {
@@ -57,3 +68,10 @@ bsp_flash_dev(uint8_t id)
     }
     return &stm32f4_flash_dev;
 }
+
+const struct bsp_mem_dump *
+bsp_core_dump(int *area_cnt)
+{
+    *area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
+    return dump_cfg;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b726ce9/hw/hal/include/hal/hal_bsp.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_bsp.h b/hw/hal/include/hal/hal_bsp.h
index d4c3104..848a7c5 100644
--- a/hw/hal/include/hal/hal_bsp.h
+++ b/hw/hal/include/hal/hal_bsp.h
@@ -26,16 +26,35 @@ extern "C" {
 
 #include <inttypes.h>
 
-/* External function prototypes supplied by BSP */
+/*
+ * Initializes BSP; registers flash_map with the system.
+ */
+void bsp_init(void);
+
+/*
+ * Return pointer to flash device structure, given BSP specific
+ * flash id.
+ */
 struct hal_flash;
 const struct hal_flash *bsp_flash_dev(uint8_t flash_id);
 
+/*
+ * Returns which flash map slot the currently running image is at.
+ */
 int bsp_imgr_current_slot(void);
 
-void bsp_init(void);
-
+/*
+ * Grows heap by given amount. XXX giving space back not implemented.
+ */
 void *_sbrk(int incr);
 
+struct bsp_mem_dump {
+    void *bmd_start;
+    uint32_t bmd_size;
+};
+
+const struct bsp_mem_dump *bsp_core_dump(int *area_cnt);
+
 #ifdef __cplusplus
 }
 #endif


[04/18] incubator-mynewt-core git commit: sys/coredump; initial coredumping. Intermediate commit.

Posted by ma...@apache.org.
sys/coredump; initial coredumping. Intermediate commit.


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

Branch: refs/heads/develop
Commit: a7d054c1c171785cbd925ebe12e35d3d9aad4843
Parents: cdfe810
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 15:20:18 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:34:27 2016 -0700

----------------------------------------------------------------------
 sys/coredump/include/coredump/coredump.h | 51 +++++++++++++++
 sys/coredump/pkg.yml                     | 30 +++++++++
 sys/coredump/src/coredump.c              | 94 +++++++++++++++++++++++++++
 3 files changed, 175 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d054c1/sys/coredump/include/coredump/coredump.h
----------------------------------------------------------------------
diff --git a/sys/coredump/include/coredump/coredump.h b/sys/coredump/include/coredump/coredump.h
new file mode 100644
index 0000000..1cf8b9b
--- /dev/null
+++ b/sys/coredump/include/coredump/coredump.h
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __COREDUMP_H__
+#define __COREDUMP_H__
+
+#include <inttypes.h>
+
+#define COREDUMP_MAGIC              0x690c47c3
+
+/*
+ * Coredump TLV types.
+ */
+#define COREDUMP_TLV_IMAGE          1   /* SHA256 of image creating this */
+#define COREDUMP_TLV_MEM            2   /* Memory dump */
+#define COREDUMP_TLV_REGS           3   /* CPU registers */
+
+struct coredump_tlv {
+    uint8_t ct_type;
+    uint8_t _pad;
+    uint16_t ct_len;
+    uint32_t ct_off;
+};
+
+/*
+ * Corefile header.  All fields are in little endian byte order.
+ */
+struct coredump_header {
+    uint32_t ch_magic;
+    uint32_t ch_size;                   /* Size of everything */
+};
+
+void dump_core(void *regs, int regs_sz);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d054c1/sys/coredump/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/coredump/pkg.yml b/sys/coredump/pkg.yml
new file mode 100644
index 0000000..cb8787d
--- /dev/null
+++ b/sys/coredump/pkg.yml
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# 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,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: sys/coredump
+pkg.description: Coredumps.
+pkg.keywords:
+    - flash
+    - core
+    - crash
+
+pkg.deps:
+    - hw/hal
+pkg.features:
+    - COREDUMP

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d054c1/sys/coredump/src/coredump.c
----------------------------------------------------------------------
diff --git a/sys/coredump/src/coredump.c b/sys/coredump/src/coredump.c
new file mode 100644
index 0000000..97ef749
--- /dev/null
+++ b/sys/coredump/src/coredump.c
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <bsp/bsp.h>
+
+#include <hal/flash_map.h>
+#include <bootutil/image.h>
+#include <imgmgr/imgmgr.h>
+#include <coredump/coredump.h>
+
+static void
+dump_core_tlv(const struct flash_area *fa, uint32_t *off,
+  struct coredump_tlv *tlv, void *data)
+{
+    flash_area_write(fa, *off, tlv, sizeof(*tlv));
+    *off += sizeof(*tlv);
+
+    flash_area_write(fa, *off, data, tlv->ct_len);
+    *off += tlv->ct_len;
+}
+
+extern char *__vector_tbl_reloc__, *__StackTop;
+
+void
+dump_core(void *regs, int regs_sz)
+{
+    struct coredump_header hdr;
+    struct coredump_tlv tlv;
+    const struct flash_area *fa;
+    struct image_version ver;
+    uint8_t hash[IMGMGR_HASH_LEN];
+    uint32_t off;
+
+    if (flash_area_open(FLASH_AREA_CORE, &fa)) {
+        return;
+    }
+
+    if (flash_area_read(fa, 0, &hdr, sizeof(hdr))) {
+        return;
+    }
+    if (hdr.ch_magic == COREDUMP_MAGIC) {
+        /*
+         * Don't override corefile.
+         */
+        return;
+    }
+
+    if (flash_area_erase(fa, 0, fa->fa_size)) {
+        return;
+    }
+
+    /*
+     * First put in data, followed by the header.
+     */
+    tlv.ct_type = COREDUMP_TLV_REGS;
+    tlv._pad = 0;
+    tlv.ct_len = regs_sz;
+    tlv.ct_off = 0;
+
+    off = sizeof(hdr);
+    dump_core_tlv(fa, &off, &tlv, regs);
+
+    if (imgr_read_info(bsp_imgr_current_slot(), &ver, hash) == 0) {
+        tlv.ct_type = COREDUMP_TLV_IMAGE;
+        tlv.ct_len = IMGMGR_HASH_LEN;
+
+        dump_core_tlv(fa, &off, &tlv, hash);
+    }
+
+    tlv.ct_type = COREDUMP_TLV_MEM;
+    tlv.ct_len = (uint32_t)&__StackTop - (uint32_t)&__vector_tbl_reloc__;
+    tlv.ct_off = (uint32_t)&__vector_tbl_reloc__;
+    dump_core_tlv(fa, &off, &tlv, &__vector_tbl_reloc__);
+
+    hdr.ch_magic = COREDUMP_MAGIC;
+    hdr.ch_size = off;
+
+    flash_area_write(fa, 0, &hdr, sizeof(hdr));
+}


[10/18] incubator-mynewt-core git commit: bsp; rename os_bsp_init() to bsp_init().

Posted by ma...@apache.org.
bsp; rename os_bsp_init() to bsp_init().


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

Branch: refs/heads/develop
Commit: 73686082bd2318d672c9a7993819d598a838c018
Parents: 807955e
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed May 18 10:57:16 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:35:45 2016 -0700

----------------------------------------------------------------------
 hw/bsp/bmd300eval/src/os_bsp.c                 | 2 +-
 hw/bsp/native/src/os_bsp.c                     | 3 +--
 hw/bsp/nrf51dk-16kbram/src/os_bsp.c            | 2 +-
 hw/bsp/nrf51dk/src/os_bsp.c                    | 2 +-
 hw/bsp/nrf52dk/src/os_bsp.c                    | 2 +-
 hw/bsp/nrf52pdk/src/os_bsp.c                   | 2 +-
 hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c | 2 +-
 hw/hal/include/hal/hal_bsp.h                   | 2 +-
 libs/os/src/arch/cortex_m0/os_arch_arm.c       | 2 +-
 libs/os/src/arch/cortex_m4/os_arch_arm.c       | 2 +-
 libs/os/src/arch/sim/os_arch_sim.c             | 2 +-
 11 files changed, 11 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/hw/bsp/bmd300eval/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/src/os_bsp.c b/hw/bsp/bmd300eval/src/os_bsp.c
index 66c1ceb..161d138 100644
--- a/hw/bsp/bmd300eval/src/os_bsp.c
+++ b/hw/bsp/bmd300eval/src/os_bsp.c
@@ -65,7 +65,7 @@ bsp_imgr_current_slot(void)
 }
 
 void
-os_bsp_init(void)
+bsp_init(void)
 {
     /*
      * XXX this reference is here to keep this function in.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/hw/bsp/native/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/native/src/os_bsp.c b/hw/bsp/native/src/os_bsp.c
index 0764ee5..a0782f3 100644
--- a/hw/bsp/native/src/os_bsp.c
+++ b/hw/bsp/native/src/os_bsp.c
@@ -64,9 +64,8 @@ bsp_imgr_current_slot(void)
 }
 
 void
-os_bsp_init(void)
+bsp_init(void)
 {
     flash_area_init(bsp_flash_areas,
       sizeof(bsp_flash_areas) / sizeof(bsp_flash_areas[0]));
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/src/os_bsp.c b/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
index 07230b0..98088a7 100644
--- a/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
+++ b/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
@@ -64,7 +64,7 @@ bsp_imgr_current_slot(void)
 }
 
 void
-os_bsp_init(void)
+bsp_init(void)
 {
     /*
      * XXX this reference is here to keep this function in.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/hw/bsp/nrf51dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/os_bsp.c b/hw/bsp/nrf51dk/src/os_bsp.c
index 07230b0..98088a7 100644
--- a/hw/bsp/nrf51dk/src/os_bsp.c
+++ b/hw/bsp/nrf51dk/src/os_bsp.c
@@ -64,7 +64,7 @@ bsp_imgr_current_slot(void)
 }
 
 void
-os_bsp_init(void)
+bsp_init(void)
 {
     /*
      * XXX this reference is here to keep this function in.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/hw/bsp/nrf52dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/os_bsp.c b/hw/bsp/nrf52dk/src/os_bsp.c
index 66c1ceb..161d138 100644
--- a/hw/bsp/nrf52dk/src/os_bsp.c
+++ b/hw/bsp/nrf52dk/src/os_bsp.c
@@ -65,7 +65,7 @@ bsp_imgr_current_slot(void)
 }
 
 void
-os_bsp_init(void)
+bsp_init(void)
 {
     /*
      * XXX this reference is here to keep this function in.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/hw/bsp/nrf52pdk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/os_bsp.c b/hw/bsp/nrf52pdk/src/os_bsp.c
index 9f2e337..c485dcf 100644
--- a/hw/bsp/nrf52pdk/src/os_bsp.c
+++ b/hw/bsp/nrf52pdk/src/os_bsp.c
@@ -65,7 +65,7 @@ bsp_imgr_current_slot(void)
 }
 
 void
-os_bsp_init(void)
+bsp_init(void)
 {
     /*
      * XXX this reference is here to keep this function in.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c b/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c
index 5cdc35a..f2fe9e1 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c
+++ b/hw/bsp/olimex_stm32-e407_devboard/src/os_bsp.c
@@ -69,7 +69,7 @@ bsp_imgr_current_slot(void)
 }
 
 void
-os_bsp_init(void)
+bsp_init(void)
 {
     /*
      * XXX this reference is here to keep this function in.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/hw/hal/include/hal/hal_bsp.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_bsp.h b/hw/hal/include/hal/hal_bsp.h
index a491507..d4c3104 100644
--- a/hw/hal/include/hal/hal_bsp.h
+++ b/hw/hal/include/hal/hal_bsp.h
@@ -32,7 +32,7 @@ const struct hal_flash *bsp_flash_dev(uint8_t flash_id);
 
 int bsp_imgr_current_slot(void);
 
-void os_bsp_init(void);
+void bsp_init(void);
 
 void *_sbrk(int incr);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/libs/os/src/arch/cortex_m0/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/os_arch_arm.c b/libs/os/src/arch/cortex_m0/os_arch_arm.c
index 12df443..40b9254 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -215,7 +215,7 @@ os_arch_os_init(void)
         }
 
         /* Call bsp related OS initializations */
-        os_bsp_init();
+        bsp_init();
 
         /* Set the PendSV interrupt exception priority to the lowest priority */
         NVIC_SetPriority(PendSV_IRQn, PEND_SV_PRIO);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/libs/os/src/arch/cortex_m4/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_arch_arm.c b/libs/os/src/arch/cortex_m4/os_arch_arm.c
index a02c217..837e941 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -208,7 +208,7 @@ os_arch_os_init(void)
         }
 
         /* Call bsp related OS initializations */
-        os_bsp_init();
+        bsp_init();
 
         /* Set the PendSV interrupt exception priority to the lowest priority */
         NVIC_SetPriority(PendSV_IRQn, PEND_SV_PRIO);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73686082/libs/os/src/arch/sim/os_arch_sim.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/sim/os_arch_sim.c b/libs/os/src/arch/sim/os_arch_sim.c
index 4fbf2bb..287b4fc 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -419,7 +419,7 @@ os_arch_os_init(void)
     os_init_idle_task();
     os_sanity_task_init(1);
 
-    os_bsp_init();
+    bsp_init();
 
     return OS_OK;
 }


[14/18] incubator-mynewt-core git commit: os/cortex_m4; support coredumps for Cortex-M4.

Posted by ma...@apache.org.
os/cortex_m4; support coredumps for Cortex-M4.


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

Branch: refs/heads/develop
Commit: e4aeaecb0babbf0cdbacd667767a46a3b4fdbc33
Parents: 9add53b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu May 19 09:29:36 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:35:45 2016 -0700

----------------------------------------------------------------------
 libs/os/src/arch/cortex_m4/os_fault.c | 104 +++++++++++++++++++++++------
 1 file changed, 85 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4aeaecb/libs/os/src/arch/cortex_m4/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_fault.c b/libs/os/src/arch/cortex_m4/os_fault.c
index 25ed5ca..d248e59 100644
--- a/libs/os/src/arch/cortex_m4/os_fault.c
+++ b/libs/os/src/arch/cortex_m4/os_fault.c
@@ -21,28 +21,13 @@
 #include <hal/hal_system.h>
 #include "os/os.h"
 
+#ifdef COREDUMP_PRESENT
+#include <coredump/coredump.h>
+#endif
+
 #include <stdint.h>
 #include <unistd.h>
 
-int             os_die_line;
-const char     *os_die_module;
-
-void __assert_func(const char *file, int line, const char *func, const char *e);
-
-void
-__assert_func(const char *file, int line, const char *func, const char *e)
-{
-    int sr;
-
-    OS_ENTER_CRITICAL(sr);
-    (void)sr;
-    os_die_line = line;
-    os_die_module = file;
-    console_blocking_mode();
-    console_printf("Assert %s; failed in %s:%d\n", e ? e : "", file, line);
-    system_reset();
-}
-
 struct exception_frame {
     uint32_t r0;
     uint32_t r1;
@@ -67,9 +52,84 @@ struct trap_frame {
     uint32_t lr;    /* this LR holds EXC_RETURN */
 };
 
+struct coredump_regs {
+    uint32_t r0;
+    uint32_t r1;
+    uint32_t r2;
+    uint32_t r3;
+    uint32_t r4;
+    uint32_t r5;
+    uint32_t r6;
+    uint32_t r7;
+    uint32_t r8;
+    uint32_t r9;
+    uint32_t r10;
+    uint32_t r11;
+    uint32_t r12;
+    uint32_t sp;
+    uint32_t lr;
+    uint32_t pc;
+    uint32_t psr;
+};
+
+void __assert_func(const char *file, int line, const char *func, const char *e);
+
+#ifdef COREDUMP_PRESENT
+static void
+trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs)
+{
+    regs->r0 = tf->ef->r0;
+    regs->r1 = tf->ef->r1;
+    regs->r2 = tf->ef->r2;
+    regs->r3 = tf->ef->r3;
+    regs->r4 = tf->r4;
+    regs->r5 = tf->r5;
+    regs->r6 = tf->r6;
+    regs->r7 = tf->r7;
+    regs->r8 = tf->r8;
+    regs->r9 = tf->r9;
+    regs->r10 = tf->r10;
+    regs->r11 = tf->r11;
+    regs->r12 = tf->ef->r12;
+    /*
+     * SP just before exception for the coredump.
+     * See ARMv7-M Architecture Ref Manual, sections B1.5.6 - B1.5.8
+     * SP is adjusted by 0x20.
+     * If SCB->CCR.STKALIGN is set, SP is aligned to 8-byte boundary on
+     * exception entry.
+     * If this alignment adjustment happened, xPSR will have bit 9 set.
+     */
+    regs->sp = ((uint32_t)tf->ef) + 0x20;
+    if ((SCB->CCR & SCB_CCR_STKALIGN_Msk) & tf->ef->psr & (1 << 9)) {
+        regs->sp += 4;
+    }
+    regs->lr = tf->ef->lr;
+    regs->pc = tf->ef->pc;
+    regs->psr = tf->ef->psr;
+}
+#endif
+
+void
+__assert_func(const char *file, int line, const char *func, const char *e)
+{
+    int sr;
+
+    OS_ENTER_CRITICAL(sr);
+    (void)sr;
+    console_blocking_mode();
+    console_printf("Assert %s; failed in %s:%d\n", e ? e : "", file, line);
+    SCB->ICSR = SCB_ICSR_NMIPENDSET_Msk;
+    asm("isb");
+    system_reset();
+}
+
 void
 os_default_irq(struct trap_frame *tf)
 {
+#ifdef COREDUMP_PRESENT
+    struct coredump_regs regs;
+#endif
+
     console_blocking_mode();
     console_printf("Unhandled interrupt (%ld), exception sp 0x%08lx\n",
       SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk, (uint32_t)tf->ef);
@@ -84,5 +144,11 @@ os_default_irq(struct trap_frame *tf)
     console_printf("ICSR:0x%08lx HFSR:0x%08lx CFSR:0x%08lx\n",
       SCB->ICSR, SCB->HFSR, SCB->CFSR);
     console_printf("BFAR:0x%08lx MMFAR:0x%08lx\n", SCB->BFAR, SCB->MMFAR);
+
+#ifdef COREDUMP_PRESENT
+    trap_to_coredump(tf, &regs);
+    dump_core(&regs, sizeof(regs));
+#endif
+
     system_reset();
 }


[05/18] incubator-mynewt-core git commit: newtmgr; send content in response to reset command.

Posted by ma...@apache.org.
newtmgr; send content in response to reset command.


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

Branch: refs/heads/develop
Commit: cdfe810437c7d1980381cb5f9298485fcaf1a6ca
Parents: 52f847b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 17 15:16:33 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu May 19 09:34:27 2016 -0700

----------------------------------------------------------------------
 libs/newtmgr/src/newtmgr_os.c | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdfe8104/libs/newtmgr/src/newtmgr_os.c
----------------------------------------------------------------------
diff --git a/libs/newtmgr/src/newtmgr_os.c b/libs/newtmgr/src/newtmgr_os.c
index fc147a9..8fb11fe 100644
--- a/libs/newtmgr/src/newtmgr_os.c
+++ b/libs/newtmgr/src/newtmgr_os.c
@@ -230,5 +230,7 @@ nmgr_reset(struct nmgr_jbuf *njb)
     json_encode_object_start(&njb->njb_enc);
     json_encode_object_finish(&njb->njb_enc);
 
+    nmgr_jbuf_setoerr(njb, 0);
+
     return OS_OK;
 }