You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/08/24 00:53:15 UTC

[01/50] [abbrv] incubator-mynewt-core git commit: Fix incorrect handling of multiple connections and starting encrypted links with all of them

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/master 0d9c8f30e -> 70987f7d2


Fix incorrect handling of multiple connections and starting encrypted links with all of them


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

Branch: refs/heads/master
Commit: a955c2f9ec9b88293ccbffddc46dfa14e0b6d778
Parents: 22fe6f2
Author: William San Filippo <wi...@runtime.io>
Authored: Tue Aug 9 15:51:01 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Thu Aug 11 17:49:45 2016 -0700

----------------------------------------------------------------------
 apps/bletest/src/bletest_hci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a955c2f9/apps/bletest/src/bletest_hci.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/bletest_hci.c b/apps/bletest/src/bletest_hci.c
index 64d0270..354b568 100755
--- a/apps/bletest/src/bletest_hci.c
+++ b/apps/bletest/src/bletest_hci.c
@@ -63,7 +63,7 @@ bletest_send_conn_update(uint16_t handle)
 void
 bletest_ltk_req_reply(uint16_t handle)
 {
-    g_bletest_ltk_reply_handle = handle;
+    g_bletest_ltk_reply_handle |= (1 << (handle-1));
 }
 
 int


[44/50] [abbrv] incubator-mynewt-core git commit: Merge branch 'master' of https://github.com/SanjeewaUom/incubator-mynewt-core into develop

Posted by cc...@apache.org.
Merge branch 'master' of https://github.com/SanjeewaUom/incubator-mynewt-core into develop

This closes #97


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

Branch: refs/heads/master
Commit: d49726b3407ea46d061ccccb0071026930c75d2a
Parents: b02e613 a46aeec
Author: William San Filippo <wi...@runtime.io>
Authored: Mon Aug 22 09:57:06 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Mon Aug 22 09:57:06 2016 -0700

----------------------------------------------------------------------
 .../stm32f4discovery/boot-stm32f4discovery.ld   | 202 +++++++++
 hw/bsp/stm32f4discovery/f407.cfg                |  82 ++++
 hw/bsp/stm32f4discovery/include/bsp/bsp.h       |  55 +++
 hw/bsp/stm32f4discovery/include/bsp/bsp_sysid.h |  36 ++
 .../stm32f4discovery/include/bsp/cmsis_nvic.h   |  29 ++
 .../include/bsp/stm32f4xx_hal_conf.h            | 413 +++++++++++++++++++
 hw/bsp/stm32f4discovery/pkg.yml                 |  39 ++
 hw/bsp/stm32f4discovery/run_from_flash.ld       | 204 +++++++++
 hw/bsp/stm32f4discovery/run_from_loader.ld      | 210 ++++++++++
 hw/bsp/stm32f4discovery/run_from_sram.ld        | 202 +++++++++
 .../src/arch/cortex_m4/startup_STM32F40x.s      | 343 +++++++++++++++
 hw/bsp/stm32f4discovery/src/hal_bsp.c           |  77 ++++
 hw/bsp/stm32f4discovery/src/libc_stubs.c        |  84 ++++
 hw/bsp/stm32f4discovery/src/os_bsp.c            |  82 ++++
 hw/bsp/stm32f4discovery/src/sbrk.c              |  50 +++
 hw/bsp/stm32f4discovery/src/system_stm32f4xx.c  | 351 ++++++++++++++++
 hw/bsp/stm32f4discovery/stm32f4discovery.ld     | 213 ++++++++++
 .../stm32f4discovery/stm32f4discovery_debug.sh  |  47 +++
 .../stm32f4discovery_download.sh                |  56 +++
 19 files changed, 2775 insertions(+)
----------------------------------------------------------------------



[06/50] [abbrv] incubator-mynewt-core git commit: bletiny - parse_arg_uint32_dflt()

Posted by cc...@apache.org.
bletiny - parse_arg_uint32_dflt()


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

Branch: refs/heads/master
Commit: 1f5042055657b6f8d58661124200c100427fa920
Parents: 5e3595d
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 12 17:41:41 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Aug 12 18:16:34 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h |  1 +
 apps/bletiny/src/parse.c   | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1f504205/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index e24f0f0..df6e1ad 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -103,6 +103,7 @@ uint8_t parse_arg_uint8_dflt(char *name, uint8_t dflt, int *out_status);
 uint16_t parse_arg_uint16(char *name, int *status);
 uint16_t parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status);
 uint32_t parse_arg_uint32(char *name, int *out_status);
+uint32_t parse_arg_uint32_dflt(char *name, uint32_t dflt, int *out_status);
 uint64_t parse_arg_uint64(char *name, int *out_status);
 int parse_arg_kv(char *name, struct kv_pair *kvs, int *out_status);
 int parse_arg_kv_default(char *name, struct kv_pair *kvs, int def_val,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1f504205/apps/bletiny/src/parse.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/parse.c b/apps/bletiny/src/parse.c
index d951d3d..a2ae28a 100644
--- a/apps/bletiny/src/parse.c
+++ b/apps/bletiny/src/parse.c
@@ -260,6 +260,22 @@ parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status)
     return val;
 }
 
+uint32_t
+parse_arg_uint32_dflt(char *name, uint32_t dflt, int *out_status)
+{
+    uint32_t val;
+    int rc;
+
+    val = parse_arg_uint32(name, &rc);
+    if (rc == ENOENT) {
+        val = dflt;
+        rc = 0;
+    }
+
+    *out_status = rc;
+    return val;
+}
+
 int
 parse_arg_kv(char *name, struct kv_pair *kvs, int *out_status)
 {


[12/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Function to retrieve preferred ATT MTU.

Posted by cc...@apache.org.
BLE Host - Function to retrieve preferred ATT MTU.

uint16_t ble_att_preferred_mtu(void);


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

Branch: refs/heads/master
Commit: 567c9c1df35c0c7399fd060145f50072f8e7b6a9
Parents: 1f50420
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 12 17:43:28 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Aug 12 18:16:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_att.h |  1 +
 net/nimble/host/src/ble_att.c          | 19 +++++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/567c9c1d/net/nimble/host/include/host/ble_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_att.h b/net/nimble/host/include/host/ble_att.h
index 6afca97..24b4496 100644
--- a/net/nimble/host/include/host/ble_att.h
+++ b/net/nimble/host/include/host/ble_att.h
@@ -98,6 +98,7 @@ int ble_att_svr_read_local(uint16_t attr_handle, struct os_mbuf **out_om);
 int ble_att_svr_write_local(uint16_t attr_handle, struct os_mbuf *om);
 
 uint16_t ble_att_mtu(uint16_t conn_handle);
+uint16_t ble_att_preferred_mtu(void);
 int ble_att_set_preferred_mtu(uint16_t mtu);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/567c9c1d/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 29e359a..608904a 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -22,7 +22,7 @@
 #include "bsp/bsp.h"
 #include "ble_hs_priv.h"
 
-static uint16_t ble_att_preferred_mtu;
+static uint16_t ble_att_preferred_mtu_val;
 
 /** Dispatch table for incoming ATT requests.  Sorted by op code. */
 typedef int ble_att_rx_fn(uint16_t conn_handle, struct os_mbuf **om);
@@ -467,6 +467,17 @@ ble_att_rx(uint16_t conn_handle, struct os_mbuf **om)
 }
 
 /**
+ * Retrieves the preferred ATT MTU.
+ *
+ * @return                      The preferred ATT MTU.
+ */
+uint16_t
+ble_att_preferred_mtu(void)
+{
+    return ble_att_preferred_mtu_val;
+}
+
+/**
  * Sets the preferred ATT MTU; the device will indicate this value in all
  * subseqeunt ATT MTU exchanges.  The ATT MTU of a connection is equal to the
  * lower of the two peers' preferred MTU values.  The ATT MTU is what dictates
@@ -492,7 +503,7 @@ ble_att_set_preferred_mtu(uint16_t mtu)
         return BLE_HS_EINVAL;
     }
 
-    ble_att_preferred_mtu = mtu;
+    ble_att_preferred_mtu_val = mtu;
 
     /* XXX: Set my_mtu for established connections that haven't exchanged. */
 
@@ -510,7 +521,7 @@ ble_att_create_chan(void)
     }
 
     chan->blc_cid = BLE_L2CAP_CID_ATT;
-    chan->blc_my_mtu = ble_att_preferred_mtu;
+    chan->blc_my_mtu = ble_att_preferred_mtu_val;
     chan->blc_default_mtu = BLE_ATT_MTU_DFLT;
     chan->blc_rx_fn = ble_att_rx;
 
@@ -522,7 +533,7 @@ ble_att_init(void)
 {
     int rc;
 
-    ble_att_preferred_mtu = BLE_ATT_MTU_PREFERRED_DFLT;
+    ble_att_preferred_mtu_val = BLE_ATT_MTU_PREFERRED_DFLT;
 
     rc = stats_init_and_reg(
         STATS_HDR(ble_att_stats), STATS_SIZE_INIT_PARMS(ble_att_stats,


[48/50] [abbrv] incubator-mynewt-core git commit: Fix warnings reported by clang.

Posted by cc...@apache.org.
Fix warnings reported by clang.


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

Branch: refs/heads/master
Commit: 18c8837bdd7bca02771dcc9eaf783d9b2ce01764
Parents: 03c939a
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Aug 22 17:36:12 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Aug 22 17:36:12 2016 -0700

----------------------------------------------------------------------
 hw/mcu/native/src/hal_uart.c                |  2 +-
 libs/bootutil/src/test/boot_test.c          | 12 ++++------
 net/nimble/host/src/ble_sm.c                | 15 +++++--------
 net/nimble/host/src/ble_sm_alg.c            | 28 ------------------------
 net/nimble/host/src/test/ble_hs_test_util.c |  3 ---
 net/nimble/host/src/test/ble_sm_test_util.c |  3 +--
 6 files changed, 11 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18c8837b/hw/mcu/native/src/hal_uart.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_uart.c b/hw/mcu/native/src/hal_uart.c
index c30a414..41afcc6 100644
--- a/hw/mcu/native/src/hal_uart.c
+++ b/hw/mcu/native/src/hal_uart.c
@@ -148,9 +148,9 @@ uart_transmit_char(struct uart *uart)
         OS_EXIT_CRITICAL(sr);
         return 0;
     }
+    ch = rc;
     uart_log_data(uart, 1, ch);
     OS_EXIT_CRITICAL(sr);
-    ch = rc;
     rc = write(uart->u_fd, &ch, 1);
     if (rc <= 0) {
         /* XXX EOF/error, what now? */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18c8837b/libs/bootutil/src/test/boot_test.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/test/boot_test.c b/libs/bootutil/src/test/boot_test.c
index 459e424..c1dcb83 100644
--- a/libs/bootutil/src/test/boot_test.c
+++ b/libs/bootutil/src/test/boot_test.c
@@ -47,13 +47,7 @@ static struct flash_area boot_test_area_descs[] = {
     [4] = { .fa_off = 0x000a0000, .fa_size = 128 * 1024 },
     [5] = { .fa_off = 0x000c0000, .fa_size = 128 * 1024 },
     [6] = { .fa_off = 0x000e0000, .fa_size = 128 * 1024 },
-};
-
-static const struct flash_area boot_test_format_descs[] = {
-    [0] = { .fa_off = 0x00004000, .fa_size = 16 * 1024 },
-    [1] = { .fa_off = 0x00008000, .fa_size = 16 * 1024 },
-    [2] = { .fa_off = 0x0000c000, .fa_size = 16 * 1024 },
-    [3] = { .fa_off = 0, .fa_size = 0 },
+    [7] = { 0 },
 };
 
 /** Areas representing the beginning of image slots. */
@@ -1193,9 +1187,11 @@ boot_test_all(void)
 #ifdef MYNEWT_SELFTEST
 
 int
-main(void)
+main(int argc, char **argv)
 {
     tu_config.tc_print_results = 1;
+    tu_parse_args(argc, argv);
+
     tu_init();
 
     boot_test_all();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18c8837b/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 4991e2e..8e07cdb 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2260,17 +2260,12 @@ ble_sm_inject_io(uint16_t conn_handle, struct ble_sm_io *pkey)
 
         switch (pkey->action) {
         case BLE_SM_IOACT_OOB:
-            if (pkey->oob == NULL) {
-                res.app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_OOB);
-                res.sm_err = BLE_SM_ERR_OOB;
-            } else {
-                proc->flags |= BLE_SM_PROC_F_IO_INJECTED;
-                memcpy(proc->tk, pkey->oob, 16);
-                if ((proc->flags & BLE_SM_PROC_F_INITIATOR) ||
-                    (proc->flags & BLE_SM_PROC_F_ADVANCE_ON_IO)) {
+            proc->flags |= BLE_SM_PROC_F_IO_INJECTED;
+            memcpy(proc->tk, pkey->oob, 16);
+            if ((proc->flags & BLE_SM_PROC_F_INITIATOR) ||
+                (proc->flags & BLE_SM_PROC_F_ADVANCE_ON_IO)) {
 
-                    res.execute = 1;
-                }
+                res.execute = 1;
             }
             break;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18c8837b/net/nimble/host/src/ble_sm_alg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_alg.c b/net/nimble/host/src/ble_sm_alg.c
index a2b0fcf..66f86dc 100644
--- a/net/nimble/host/src/ble_sm_alg.c
+++ b/net/nimble/host/src/ble_sm_alg.c
@@ -40,34 +40,6 @@ static const uint32_t ble_sm_alg_dbg_priv_key[8] = {
     0xa3c55f38, 0x3f49f6d4
 };
 
-static const uint8_t ble_sm_alg_dbg_pub_key[64] = {
-    0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
-    0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
-    0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
-    0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20,
-    0x8b, 0xd2, 0x89, 0x15, 0xd0, 0x8e, 0x1c, 0x74,
-    0x24, 0x30, 0xed, 0x8f, 0xc2, 0x45, 0x63, 0x76,
-    0x5c, 0x15, 0x52, 0x5a, 0xbf, 0x9a, 0x32, 0x63,
-    0x6d, 0xeb, 0x2a, 0x65, 0x49, 0x9c, 0x80, 0xdc
-};
-
-static const uint8_t ble_sm_alg_dbg_f4[16] = {
-    0x2d, 0x87, 0x74, 0xa9, 0xbe, 0xa1, 0xed, 0xf1,
-    0x1c, 0xbd, 0xa9, 0x07, 0xf1, 0x16, 0xc9, 0xf2,
-};
-
-static const uint8_t ble_sm_alg_dbg_f5[32] = {
-    0x20, 0x6e, 0x63, 0xce, 0x20, 0x6a, 0x3f, 0xfd,
-    0x02, 0x4a, 0x08, 0xa1, 0x76, 0xf1, 0x65, 0x29,
-    0x38, 0x0a, 0x75, 0x94, 0xb5, 0x22, 0x05, 0x98,
-    0x23, 0xcd, 0xd7, 0x69, 0x11, 0x79, 0x86, 0x69,
-};
-
-static const uint8_t ble_sm_alg_dbg_f6[16] = {
-    0x61, 0x8f, 0x95, 0xda, 0x09, 0x0b, 0x6c, 0xd2,
-    0xc5, 0xe8, 0xd0, 0x9c, 0x98, 0x73, 0xc4, 0xe3,
-};
-
 static void
 ble_sm_alg_log_buf(const char *name, const uint8_t *buf, int len)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18c8837b/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index 0ced75a..e1acb81 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -34,9 +34,6 @@ uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
 
 #define BLE_HS_TEST_UTIL_PUB_ADDR_VAL { 0x0a, 0x54, 0xab, 0x49, 0x7f, 0x06 }
 
-static const uint8_t ble_hs_test_util_pub_addr[BLE_DEV_ADDR_LEN] =
-    BLE_HS_TEST_UTIL_PUB_ADDR_VAL;
-
 /** Use lots of small mbufs to ensure correct mbuf usage. */
 #define BLE_HS_TEST_UTIL_NUM_MBUFS      (100)
 #define BLE_HS_TEST_UTIL_BUF_SIZE       OS_ALIGN(100, 4)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18c8837b/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index ca9aadf..9edaa04 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -275,7 +275,6 @@ ble_sm_test_util_conn_cb(struct ble_gap_event *event, void *arg)
         rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc);
         TEST_ASSERT_FATAL(rc == 0);
         ble_sm_test_sec_state = desc.sec_state;
-        rc = 0;
         break;
 
     case BLE_GAP_EVENT_PASSKEY_ACTION:
@@ -288,7 +287,7 @@ ble_sm_test_util_conn_cb(struct ble_gap_event *event, void *arg)
 
     ble_sm_test_gap_event_type = event->type;
 
-    return rc;
+    return 0;
 }
 
 static void


[03/50] [abbrv] incubator-mynewt-core git commit: BLE apps - Update for latest HCI transport changes

Posted by cc...@apache.org.
BLE apps - Update for latest HCI transport changes


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

Branch: refs/heads/master
Commit: 50d00eb80ba1bc21986753480c282ecc17e08e38
Parents: 70f4ec7
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 16:31:33 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Thu Aug 11 17:49:45 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/main.c | 3 ---
 apps/bletest/src/main.c | 2 ++
 2 files changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/50d00eb8/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index d2ded46..b08b077 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -426,9 +426,6 @@ main(void)
     rc = ble_hs_init(&bleprph_evq, &cfg);
     assert(rc == 0);
 
-    rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
-    assert(rc == 0);
-
     nmgr_task_init(NEWTMGR_TASK_PRIO, newtmgr_stack, NEWTMGR_TASK_STACK_SIZE);
     imgmgr_module_init();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/50d00eb8/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index 94def1f..5dd0cde 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -44,6 +44,8 @@
 #include "controller/ble_ll_conn.h"
 #include "controller/ble_ll_scan.h"
 #include "controller/ble_ll_adv.h"
+
+/* RAM HCI transport. */
 #include "transport/ram/ble_hci_ram.h"
 
 /* RAM HCI transport. */


[40/50] [abbrv] incubator-mynewt-core git commit: boot; boot loader does not need to call os_init() anymore, as bsp_init() has been exported.

Posted by cc...@apache.org.
boot; boot loader does not need to call os_init() anymore, as bsp_init()
has been exported.


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

Branch: refs/heads/master
Commit: c3cd5b181b68d43b082ee1c50084513bf52a32b7
Parents: 2389573
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Aug 19 16:38:02 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 16:38:02 2016 -0700

----------------------------------------------------------------------
 apps/boot/src/boot.c | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c3cd5b18/apps/boot/src/boot.c
----------------------------------------------------------------------
diff --git a/apps/boot/src/boot.c b/apps/boot/src/boot.c
index 8ffcb1f..7323701 100755
--- a/apps/boot/src/boot.c
+++ b/apps/boot/src/boot.c
@@ -23,6 +23,7 @@
 #include <hal/flash_map.h>
 #include <os/os.h>
 #include <bsp/bsp.h>
+#include <hal/hal_bsp.h>
 #include <hal/hal_system.h>
 #include <hal/hal_flash.h>
 #include <config/config.h>
@@ -66,7 +67,11 @@ main(void)
         .br_slot_areas = img_starts,
     };
 
+#ifdef BOOT_SERIAL
     os_init();
+#else
+    bsp_init();
+#endif
 
     rc = hal_flash_init();
     assert(rc == 0);


[29/50] [abbrv] incubator-mynewt-core git commit: boot; don't use NFFS or FCB for keeping status. Interim commit.

Posted by cc...@apache.org.
boot; don't use NFFS or FCB for keeping status. Interim 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/b2009c9f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b2009c9f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b2009c9f

Branch: refs/heads/master
Commit: b2009c9fbce7d7ac8f6f039cda6866e81868b622
Parents: 5de9a72
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Aug 16 18:07:30 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:49 2016 -0700

----------------------------------------------------------------------
 apps/boot/pkg.yml                              |   3 +-
 apps/boot/src/boot.c                           |  91 +----
 apps/slinky/src/main.c                         |   1 -
 libs/bootutil/include/bootutil/bootutil_misc.h |   4 +-
 libs/bootutil/include/bootutil/loader.h        |   3 +
 libs/bootutil/src/bootutil_misc.c              | 264 ++-----------
 libs/bootutil/src/bootutil_priv.h              |  44 +--
 libs/bootutil/src/loader.c                     | 399 +++++++++++---------
 libs/imgmgr/src/imgmgr_boot.c                  |   6 +-
 9 files changed, 291 insertions(+), 524 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b2009c9f/apps/boot/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/boot/pkg.yml b/apps/boot/pkg.yml
index 10ec482..b877557 100644
--- a/apps/boot/pkg.yml
+++ b/apps/boot/pkg.yml
@@ -29,12 +29,11 @@ pkg.features: bootloader
 
 pkg.deps:
     - sys/config
-    - fs/nffs
     - libs/bootutil
     - libs/mbedtls
     - libs/os
     - libs/util
-    - libs/console/stub
+    - libs/console/full
 
 pkg.cflags: -DLOG_LEVEL=255
 pkg.cflags.NFFS:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b2009c9f/apps/boot/src/boot.c
----------------------------------------------------------------------
diff --git a/apps/boot/src/boot.c b/apps/boot/src/boot.c
index 97a9b32..37172ba 100755
--- a/apps/boot/src/boot.c
+++ b/apps/boot/src/boot.c
@@ -27,19 +27,11 @@
 #include <hal/hal_flash.h>
 #include <config/config.h>
 #include <config/config_file.h>
-#ifdef NFFS_PRESENT
-#include <fs/fs.h>
-#include <nffs/nffs.h>
-#elif FCB_PRESENT
-#include <fcb/fcb.h>
-#include <config/config_fcb.h>
-#else
-#error "Need NFFS or FCB for config storage"
-#endif
 #ifdef BOOT_SERIAL
 #include <hal/hal_gpio.h>
 #include <boot_serial/boot_serial.h>
 #endif
+#include <console/console.h>
 #include "bootutil/image.h"
 #include "bootutil/loader.h"
 #include "bootutil/bootutil_misc.h"
@@ -58,76 +50,11 @@ static struct os_task boot_ser_task;
 static os_stack_t boot_ser_stack[BOOT_SER_STACK_SZ];
 #endif
 
-#ifdef NFFS_PRESENT
-#define MY_CONFIG_FILE "/cfg/run"
-
-static struct conf_file my_conf = {
-    .cf_name = MY_CONFIG_FILE
-};
-
-static void
-setup_for_nffs(void)
-{
-    struct nffs_area_desc nffs_descs[NFFS_AREA_MAX + 1];
-    int cnt;
-    int rc;
-
-    /*
-     * Make sure we have enough left to initialize the NFFS with the
-     * right number of maximum areas otherwise the file-system will not
-     * be readable.
-     */
-    cnt = NFFS_AREA_MAX;
-    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, nffs_descs);
-    assert(rc == 0);
-
-    /*
-     * Initializes the flash driver and file system for use by the boot loader.
-     */
-    rc = nffs_init();
-    if (rc == 0) {
-        /* Look for an nffs file system in internal flash.  If no file
-         * system gets detected, all subsequent file operations will fail,
-         * but the boot loader should proceed anyway.
-         */
-        nffs_detect(nffs_descs);
-    }
-
-    rc = conf_file_src(&my_conf);
-    assert(rc == 0);
-    rc = conf_file_dst(&my_conf);
-    assert(rc == 0);
-}
-#else
-struct flash_area conf_fcb_area[NFFS_AREA_MAX + 1];
-
-static struct conf_fcb my_conf = {
-    .cf_fcb.f_magic = 0xc09f6e5e,
-    .cf_fcb.f_sectors = conf_fcb_area
-};
-
-static void
-setup_for_fcb(void)
-{
-    int cnt;
-    int rc;
-
-    rc = flash_area_to_sectors(FLASH_AREA_NFFS, &cnt, NULL);
-    assert(rc == 0);
-    assert(cnt <= sizeof(conf_fcb_area) / sizeof(conf_fcb_area[0]));
-    flash_area_to_sectors(FLASH_AREA_NFFS, &cnt, conf_fcb_area);
-
-    my_conf.cf_fcb.f_sector_cnt = cnt;
-
-    conf_fcb_src(&my_conf);
-    conf_fcb_dst(&my_conf);
-}
-#endif
-
 int
 main(void)
 {
     struct flash_area descs[AREA_DESC_MAX];
+    const struct flash_area *fap;
     /** Areas representing the beginning of image slots. */
     uint8_t img_starts[2];
     int cnt;
@@ -149,6 +76,9 @@ main(void)
     img_starts[0] = 0;
     total = cnt;
 
+    flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    req.br_img_sz = fap->fa_size;
+
     cnt = BOOT_AREA_DESC_MAX - total;
     assert(cnt >= 0);
     rc = flash_area_to_sectors(FLASH_AREA_IMAGE_1, &cnt, &descs[total]);
@@ -167,13 +97,8 @@ main(void)
 
     conf_init();
 
-#ifdef NFFS_PRESENT
-    setup_for_nffs();
-#elif FCB_PRESENT
-    setup_for_fcb();
-#endif
-    bootutil_cfg_register();
-
+    console_init(NULL);
+    console_printf("\nboot_loader\n");
 #ifdef BOOT_SERIAL
     /*
      * Configure a GPIO as input, and compare it against expected value.
@@ -189,6 +114,8 @@ main(void)
 #endif
     rc = boot_go(&req, &rsp);
     assert(rc == 0);
+    console_blocking_mode();
+    console_printf("\nboot_go = %d\n", rc);
 
     system_start((void *)(rsp.br_image_addr + rsp.br_hdr->ih_hdr_size));
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b2009c9f/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 7f724e6..fd68aa4 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -397,7 +397,6 @@ main(int argc, char **argv)
 
     nmgr_task_init(NEWTMGR_TASK_PRIO, newtmgr_stack, NEWTMGR_TASK_STACK_SIZE);
     imgmgr_module_init();
-    bootutil_cfg_register();
 
     stats_module_init();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b2009c9f/libs/bootutil/include/bootutil/bootutil_misc.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/include/bootutil/bootutil_misc.h b/libs/bootutil/include/bootutil/bootutil_misc.h
index ff42ac8..e8834db 100644
--- a/libs/bootutil/include/bootutil/bootutil_misc.h
+++ b/libs/bootutil/include/bootutil/bootutil_misc.h
@@ -23,9 +23,7 @@
 struct image_version;
 int boot_vect_read_test(struct image_version *out_ver);
 int boot_vect_read_main(struct image_version *out_ver);
-int boot_vect_write_test(struct image_version *ver);
+int boot_vect_write_test(int slot);
 int boot_vect_write_main(struct image_version *ver);
 
-void bootutil_cfg_register(void);
-
 #endif /*  __BOOTUTIL_MISC_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b2009c9f/libs/bootutil/include/bootutil/loader.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/include/bootutil/loader.h b/libs/bootutil/include/bootutil/loader.h
index 86f06ba..57a9eef 100644
--- a/libs/bootutil/include/bootutil/loader.h
+++ b/libs/bootutil/include/bootutil/loader.h
@@ -46,6 +46,9 @@ struct boot_req {
     /** The area to use as the image scratch area, index is
 	index to br_area_descs array, of the  */
     uint8_t br_scratch_area_idx;
+
+    /** Size of the image slot */
+    uint32_t br_img_sz;
 };
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b2009c9f/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c b/libs/bootutil/src/bootutil_misc.c
index 94536ef..8ae5599 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -20,89 +20,11 @@
 #include <string.h>
 #include <inttypes.h>
 #include <hal/hal_flash.h>
-#include <config/config.h>
+#include <hal/flash_map.h>
 #include <os/os.h>
 #include "bootutil/image.h"
 #include "bootutil_priv.h"
 
-#ifdef USE_STATUS_FILE
-#include <fs/fs.h>
-#include <fs/fsutil.h>
-#endif
-
-static int boot_conf_set(int argc, char **argv, char *val);
-
-static struct image_version boot_main;
-static struct image_version boot_test;
-#ifndef USE_STATUS_FILE
-static struct boot_status boot_saved;
-#endif
-
-static struct conf_handler boot_conf_handler = {
-    .ch_name = "boot",
-    .ch_get = NULL,
-    .ch_set = boot_conf_set,
-    .ch_commit = NULL,
-    .ch_export = NULL,
-};
-
-static int
-boot_conf_set(int argc, char **argv, char *val)
-{
-    int rc;
-    int len;
-
-    if (argc == 1) {
-        if (!strcmp(argv[0], "main")) {
-            len = sizeof(boot_main);
-            if (val) {
-                rc = conf_bytes_from_str(val, &boot_main, &len);
-            } else {
-                memset(&boot_main, 0, len);
-                rc = 0;
-            }
-        } else if (!strcmp(argv[0], "test")) {
-            len = sizeof(boot_test);
-            if (val) {
-                rc = conf_bytes_from_str(val, &boot_test, &len);
-            } else {
-                memset(&boot_test, 0, len);
-                rc = 0;
-            }
-#ifndef USE_STATUS_FILE
-        } else if (!strcmp(argv[0], "status")) {
-            if (!val) {
-                boot_saved.state = 0;
-                rc = 0;
-            } else {
-                rc = conf_value_from_str(val, CONF_INT32,
-                  &boot_saved.state, sizeof(boot_saved.state));
-            }
-        } else if (!strcmp(argv[0], "len")) {
-            conf_value_from_str(val, CONF_INT32, &boot_saved.length,
-              sizeof(boot_saved.length));
-            rc = 0;
-#endif
-        } else {
-            rc = OS_ENOENT;
-        }
-    } else {
-        rc = OS_ENOENT;
-    }
-    return rc;
-}
-
-static int
-boot_vect_read_one(struct image_version *dst, struct image_version *src)
-{
-    if (src->iv_major == 0 && src->iv_minor == 0 &&
-      src->iv_revision == 0 && src->iv_build_num == 0) {
-        return BOOT_EBADVECT;
-    }
-    memcpy(dst, src, sizeof(*dst));
-    return 0;
-}
-
 /**
  * Retrieves from the boot vector the version number of the test image (i.e.,
  * the image that has not been proven stable, and which will only run once).
@@ -114,7 +36,7 @@ boot_vect_read_one(struct image_version *dst, struct image_version *src)
 int
 boot_vect_read_test(struct image_version *out_ver)
 {
-    return boot_vect_read_one(out_ver, &boot_test);
+    return 0;
 }
 
 /**
@@ -127,24 +49,7 @@ boot_vect_read_test(struct image_version *out_ver)
 int
 boot_vect_read_main(struct image_version *out_ver)
 {
-    return boot_vect_read_one(out_ver, &boot_main);
-}
-
-static int
-boot_vect_write_one(const char *name, struct image_version *ver)
-{
-    char str[CONF_STR_FROM_BYTES_LEN(sizeof(struct image_version))];
-    char *to_store;
-
-    if (!ver) {
-        to_store = NULL;
-    } else {
-        if (!conf_str_from_bytes(ver, sizeof(*ver), str, sizeof(str))) {
-            return -1;
-        }
-        to_store = str;
-    }
-    return conf_save_one(name, to_store);
+    return 0;
 }
 
 /**
@@ -153,15 +58,22 @@ boot_vect_write_one(const char *name, struct image_version *ver)
  * @return                  0 on success; nonzero on failure.
  */
 int
-boot_vect_write_test(struct image_version *ver)
+boot_vect_write_test(int slot)
 {
-    if (!ver) {
-        memset(&boot_test, 0, sizeof(boot_test));
-        return boot_vect_write_one("boot/test", NULL);
-    } else {
-        memcpy(&boot_test, ver, sizeof(boot_test));
-        return boot_vect_write_one("boot/test", &boot_test);
+    const struct flash_area *fap;
+    uint32_t off;
+    uint32_t magic;
+    int rc;
+
+    rc = flash_area_open(slot, &fap);
+    if (rc) {
+        return rc;
     }
+
+    off = fap->fa_size - sizeof(struct boot_img_trailer);
+    magic = BOOT_IMG_MAGIC;
+
+    return flash_area_write(fap, off, &magic, sizeof(magic));
 }
 
 /**
@@ -172,37 +84,12 @@ boot_vect_write_test(struct image_version *ver)
 int
 boot_vect_write_main(struct image_version *ver)
 {
-    if (!ver) {
-        memset(&boot_main, 0, sizeof(boot_main));
-        return boot_vect_write_one("boot/main", NULL);
-    } else {
-        memcpy(&boot_main, ver, sizeof(boot_main));
-        return boot_vect_write_one("boot/main", &boot_main);
-    }
-}
-
-static int
-boot_read_image_header(struct image_header *out_hdr,
-                       const struct boot_image_location *loc)
-{
-    int rc;
-
-    rc = hal_flash_read(loc->bil_flash_id, loc->bil_address, out_hdr,
-                        sizeof *out_hdr);
-    if (rc != 0) {
-        return BOOT_EFLASH;
-    }
-
-    if (out_hdr->ih_magic != IMAGE_MAGIC) {
-        return BOOT_EBADIMAGE;
-    }
-
     return 0;
 }
 
 /**
- * Reads the header of each image present in flash.  Headers corresponding to
- * empty image slots are filled with 0xff bytes.
+ * Reads the header of image present in flash.  Header corresponding to
+ * empty image slot is filled with 0xff bytes.
  *
  * @param out_headers           Points to an array of image headers.  Each
  *                                  element is filled with the header of the
@@ -213,118 +100,23 @@ boot_read_image_header(struct image_header *out_hdr,
  *                                  also be equal to the lengths of the
  *                                  out_headers and addresses arrays.
  */
-void
-boot_read_image_headers(struct image_header *out_headers,
-                        const struct boot_image_location *addresses,
-                        int num_addresses)
-{
-    struct image_header *hdr;
-    int rc;
-    int i;
-
-    for (i = 0; i < num_addresses; i++) {
-        hdr = out_headers + i;
-        rc = boot_read_image_header(hdr, &addresses[i]);
-        if (rc != 0 || hdr->ih_magic != IMAGE_MAGIC) {
-            memset(hdr, 0xff, sizeof *hdr);
-        }
-    }
-}
-
-void
-bootutil_cfg_register(void)
-{
-    conf_register(&boot_conf_handler);
-}
-
-#ifndef USE_STATUS_FILE
-int
-boot_read_status(struct boot_status *bs)
-{
-    conf_load();
-
-    *bs = boot_saved;
-    return (boot_saved.state != 0);
-}
-
-/**
- * Writes the supplied boot status to the flash file system.  The boot status
- * contains the current state of an in-progress image copy operation.
- *
- * @param status                The boot status base to write.
- *
- * @return                      0 on success; nonzero on failure.
- */
-int
-boot_write_status(struct boot_status *bs)
-{
-    char str[12];
-    int rc;
-
-    rc = conf_save_one("boot/len",
-      conf_str_from_value(CONF_INT32, &bs->length, str, sizeof(str)));
-    if (rc) {
-        return rc;
-    }
-    return conf_save_one("boot/status",
-      conf_str_from_value(CONF_INT32, &bs->state, str, sizeof(str)));
-}
-
-/**
- * Erases the boot status from the flash file system.  The boot status
- * contains the current state of an in-progress image copy operation.  By
- * erasing the boot status, it is implied that there is no copy operation in
- * progress.
- */
-void
-boot_clear_status(void)
-{
-    conf_save_one("boot/status", NULL);
-}
-
-#else
-
-/**
- * Reads the boot status from the flash file system.  The boot status contains
- * the current state of an interrupted image copy operation.  If the boot
- * status is not present in the file system, the implication is that there is
- * no copy operation in progress.
- */
 int
-boot_read_status(struct boot_status *bs)
+boot_read_image_header(struct boot_image_location *loc,
+                       struct image_header *out_hdr)
 {
     int rc;
-    uint32_t bytes_read;
 
-    conf_load();
-
-    rc = fsutil_read_file(BOOT_PATH_STATUS, 0, sizeof(*bs),
-      bs, &bytes_read);
-    if (rc || bytes_read != sizeof(*bs)) {
-        memset(bs, 0, sizeof(*bs));
-        return 0;
+    rc = hal_flash_read(loc->bil_flash_id, loc->bil_address, out_hdr,
+                        sizeof *out_hdr);
+    if (rc != 0) {
+        rc = BOOT_EFLASH;
+    } else if (out_hdr->ih_magic != IMAGE_MAGIC) {
+        rc = BOOT_EBADIMAGE;
     }
-    return 1;
-}
 
-int
-boot_write_status(struct boot_status *bs)
-{
-    int rc;
-
-    /*
-     * XXX point of failure.
-     */
-    rc = fsutil_write_file(BOOT_PATH_STATUS, bs, sizeof(*bs));
     if (rc) {
-        rc = BOOT_EFILE;
+        memset(out_hdr, 0xff, sizeof(*out_hdr));
     }
     return rc;
 }
 
-void
-boot_clear_status(void)
-{
-    fs_unlink(BOOT_PATH_STATUS);
-}
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b2009c9f/libs/bootutil/src/bootutil_priv.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_priv.h b/libs/bootutil/src/bootutil_priv.h
index 98aa29f..3de5dd9 100644
--- a/libs/bootutil/src/bootutil_priv.h
+++ b/libs/bootutil/src/bootutil_priv.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,
@@ -21,7 +21,6 @@
 #define H_BOOTUTIL_PRIV_
 
 #include "bootutil/image.h"
-struct image_header;
 
 #define BOOT_EFLASH     1
 #define BOOT_EFILE      2
@@ -30,37 +29,38 @@ struct image_header;
 #define BOOT_EBADSTATUS 5
 #define BOOT_ENOMEM     6
 
-#define BOOT_IMAGE_NUM_NONE     0xff
-
-#define BOOT_PATH_STATUS    "/cfg/bst"
-
 #define BOOT_TMPBUF_SZ  256
 
+struct boot_image_location {
+    uint8_t bil_flash_id;
+    uint32_t bil_address;
+};
+
+/*
+ * Maintain state of copy progress.
+ */
 struct boot_status {
-    uint32_t length;
+    uint32_t idx;
     uint32_t state;
 };
 
-/**
- * The boot status header read from the file system, or generated if not
- * present on disk.  The boot status indicates the state of the image slots in
- * case the system was restarted while images were being moved in flash.
+/*
+ * End-of-image data structure.
  */
-
-struct boot_image_location {
-    uint8_t bil_flash_id;
-    uint32_t bil_address;
+#define BOOT_IMG_MAGIC  0x12344321
+struct boot_img_trailer {
+    uint32_t bit_start;
+    uint32_t bit_done;
 };
 
-void boot_read_image_headers(struct image_header *out_headers,
-                             const struct boot_image_location *addresses,
-                             int num_addresses);
-int boot_read_status(struct boot_status *);
-int boot_write_status(struct boot_status *);
-void boot_clear_status(void);
-
 int bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig, int slen,
     uint8_t key_id);
 
+int boot_read_image_header(struct boot_image_location *loc,
+  struct image_header *out_hdr);
+int boot_write_status(struct boot_status *bs);
+int boot_read_status(struct boot_status *bs);
+void boot_clear_status(void);
+
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b2009c9f/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index bd7fbd8..f8a0003 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -24,6 +24,7 @@
 #include <hal/flash_map.h>
 #include <hal/hal_flash.h>
 #include <os/os_malloc.h>
+#include <console/console.h>
 #include "bootutil/loader.h"
 #include "bootutil/image.h"
 #include "bootutil/bootutil_misc.h"
@@ -36,13 +37,16 @@
 static const struct boot_req *boot_req;
 
 /** Image headers read from flash. */
-struct image_header boot_img_hdrs[2];
+static struct boot_img {
+    struct image_header hdr;
+    struct boot_image_location loc;
+    uint32_t area;
+} boot_img[BOOT_NUM_SLOTS];
 
 static struct boot_status boot_state;
 
-#define BOOT_PERSIST(idx, st) (((idx) << 8) | (0xff & (st)))
-#define BOOT_PERSIST_IDX(st) (((st) >> 8) & 0xffffff)
-#define BOOT_PERSIST_ST(st) ((st) & 0xff)
+static int boot_erase_area(int area_idx, uint32_t sz);
+static uint32_t boot_copy_sz(int max_idx, int *cnt);
 
 /**
  * Calculates the flash offset of the specified image slot.
@@ -52,77 +56,73 @@ static struct boot_status boot_state;
  * @return                      The flash offset of the image slot.
  */
 static void
-boot_slot_addr(int slot_num, uint8_t *flash_id, uint32_t *address)
+boot_slot_addr(int slot_num, struct boot_image_location *loc)
 {
     const struct flash_area *area_desc;
     uint8_t area_idx;
 
-    assert(slot_num >= 0 && slot_num < BOOT_NUM_SLOTS);
-
     area_idx = boot_req->br_slot_areas[slot_num];
     area_desc = boot_req->br_area_descs + area_idx;
-    *flash_id = area_desc->fa_flash_id;
-    *address = area_desc->fa_off;
+    loc->bil_flash_id = area_desc->fa_flash_id;
+    loc->bil_address = area_desc->fa_off;
 }
 
-/**
- * Searches flash for an image with the specified version number.
- *
- * @param ver                   The version number to search for.
- *
- * @return                      The image slot containing the specified image
- *                              on success; -1 on failure.
- */
-static int
-boot_find_image_slot(const struct image_version *ver)
+static uint32_t
+boot_magic_off(int slot_num)
 {
-    int i;
+    return boot_img[slot_num].area + boot_img[slot_num].loc.bil_address -
+      sizeof(struct boot_img_trailer);
+}
 
-    for (i = 0; i < 2; i++) {
-        if (memcmp(&boot_img_hdrs[i].ih_ver, ver, sizeof *ver) == 0) {
-            return i;
-        }
-    }
+static uint32_t
+boot_scratch_off(void)
+{
+    struct flash_area *scratch;
+    uint32_t off;
+    int cnt;
 
-    return -1;
+    scratch = &boot_req->br_area_descs[boot_req->br_scratch_area_idx];
+    off = boot_copy_sz(boot_req->br_slot_areas[1], &cnt);
+    off += (scratch->fa_off - sizeof(struct boot_img_trailer));
+    return off;
 }
 
-/**
- * Selects a slot number to boot from, based on the contents of the boot
- * vector.
- *
- * @return                      The slot number to boot from on success;
- *                              -1 if an appropriate slot could not be
- *                              determined.
- */
-static int
-boot_select_image_slot(void)
+static void
+boot_slot_magic(int slot_num, struct boot_img_trailer *bit)
 {
-    struct image_version ver;
-    int slot;
-    int rc;
+    uint32_t off;
+    struct boot_img *b;
 
-    rc = boot_vect_read_test(&ver);
-    if (rc == 0) {
-        slot = boot_find_image_slot(&ver);
-        if (slot == -1) {
-            boot_vect_write_test(NULL);
-        } else {
-            return slot;
-        }
-    }
+    b = &boot_img[slot_num];
+    off = boot_magic_off(slot_num);
+    memset(bit, 0xff, sizeof(*bit));
+    hal_flash_read(b->loc.bil_flash_id, off, bit, sizeof(*bit));
+}
 
-    rc = boot_vect_read_main(&ver);
-    if (rc == 0) {
-        slot = boot_find_image_slot(&ver);
-        if (slot == -1) {
-            boot_vect_write_main(NULL);
-        } else {
-            return slot;
-        }
-    }
+static void
+boot_scratch_magic(struct boot_img_trailer *bit)
+{
+    uint32_t off;
+    struct flash_area *scratch;
+
+    scratch = &boot_req->br_area_descs[boot_req->br_scratch_area_idx];
+
+    off = boot_scratch_off();
+    hal_flash_read(scratch->fa_flash_id, off, bit, sizeof(*bit));
+}
 
-    return -1;
+void
+boot_image_info(void)
+{
+    int i;
+    struct boot_img *b;
+
+    for (i = 0; i < BOOT_NUM_SLOTS; i++) {
+        b = &boot_img[i];
+        boot_slot_addr(i, &b->loc);
+        boot_read_image_header(&b->loc, &b->hdr);
+        b->area = boot_req->br_img_sz;
+    }
 }
 
 /*
@@ -146,12 +146,54 @@ boot_image_check(struct image_header *hdr, struct boot_image_location *loc)
     return 0;
 }
 
+/**
+ * Selects a slot number to boot from.
+ *
+ * @return                      The slot number to boot from on success;
+ *                              -1 if an appropriate slot could not be
+ *                              determined.
+ */
+static int
+boot_select_image_slot(void)
+{
+    /*
+     * Check for swap magic. Check the integrity of the suggested image.
+     */
+    int rc;
+    int i;
+    struct boot_img *b;
+    struct boot_img_trailer bit;
+
+    for (i = 1; i < BOOT_NUM_SLOTS; i++) {
+        b = &boot_img[i];
+        boot_slot_magic(i, &bit);
+        if (bit.bit_start == BOOT_IMG_MAGIC) {
+            rc = boot_image_check(&b->hdr, &b->loc);
+            if (rc) {
+                /*
+                 * Image fails integrity check. Erase it.
+                 */
+                boot_erase_area(boot_req->br_slot_areas[i], b->area);
+            } else {
+                return i;
+            }
+        }
+    }
+    return 0;
+}
+
+static int
+boot_status_sz(void)
+{
+    return sizeof(struct boot_img_trailer) + 32 * sizeof(uint32_t);
+}
+
 /*
  * How many sectors starting from sector[idx] can fit inside scratch.
  *
  */
 static uint32_t
-boot_copy_sz(int idx, int max_idx, int *cnt)
+boot_copy_sz(int max_idx, int *cnt)
 {
     int i;
     uint32_t sz;
@@ -166,7 +208,7 @@ boot_copy_sz(int idx, int max_idx, int *cnt)
     }
     sz = 0;
     *cnt = 0;
-    for (i = idx; i < max_idx; i++) {
+    for (i = max_idx - 1; i >= 0; i--) {
         if (sz + boot_req->br_area_descs[i].fa_size > scratch_sz) {
             break;
         }
@@ -176,7 +218,6 @@ boot_copy_sz(int idx, int max_idx, int *cnt)
     return sz;
 }
 
-
 static int
 boot_erase_area(int area_idx, uint32_t sz)
 {
@@ -258,12 +299,11 @@ boot_copy_area(int from_area_idx, int to_area_idx, uint32_t sz)
  * @return                      0 on success; nonzero on failure.
  */
 static int
-boot_swap_areas(int idx, uint32_t sz)
+boot_swap_areas(int idx, uint32_t sz, int end_area)
 {
     int area_idx_1;
     int area_idx_2;
     int rc;
-    int state;
 
     area_idx_1 = boot_req->br_slot_areas[0] + idx;
     area_idx_2 = boot_req->br_slot_areas[1] + idx;
@@ -271,8 +311,7 @@ boot_swap_areas(int idx, uint32_t sz)
     assert(area_idx_1 != boot_req->br_scratch_area_idx);
     assert(area_idx_2 != boot_req->br_scratch_area_idx);
 
-    state = BOOT_PERSIST_ST(boot_state.state);
-    if (state == 0) {
+    if (boot_state.state == 0) {
         rc = boot_erase_area(boot_req->br_scratch_area_idx, sz);
         if (rc != 0) {
             return rc;
@@ -283,26 +322,25 @@ boot_swap_areas(int idx, uint32_t sz)
             return rc;
         }
 
-        boot_state.state = BOOT_PERSIST(idx, 1);
+        boot_state.state = 1;
         (void)boot_write_status(&boot_state);
-        state = 1;
     }
-    if (state == 1) {
+    if (boot_state.state == 1) {
         rc = boot_erase_area(area_idx_2, sz);
         if (rc != 0) {
             return rc;
         }
 
-        rc = boot_copy_area(area_idx_1, area_idx_2, sz);
+        rc = boot_copy_area(area_idx_1, area_idx_2,
+          end_area ? (sz - boot_status_sz()) : sz);
         if (rc != 0) {
             return rc;
         }
 
-        boot_state.state = BOOT_PERSIST(idx, 2);
+        boot_state.state = 2;
         (void)boot_write_status(&boot_state);
-        state = 2;
     }
-    if (state == 2) {
+    if (boot_state.state == 2) {
         rc = boot_erase_area(area_idx_1, sz);
         if (rc != 0) {
             return rc;
@@ -313,9 +351,9 @@ boot_swap_areas(int idx, uint32_t sz)
             return rc;
         }
 
-        boot_state.state = BOOT_PERSIST(idx + 1, 0);
+        boot_state.idx++;
+        boot_state.state = 0;
         (void)boot_write_status(&boot_state);
-        state = 3;
     }
     return 0;
 }
@@ -324,63 +362,129 @@ boot_swap_areas(int idx, uint32_t sz)
  * Swaps the two images in flash.  If a prior copy operation was interrupted
  * by a system reset, this function completes that operation.
  *
- * @param img1_length           The length, in bytes, of the slot 1 image.
- * @param img2_length           The length, in bytes, of the slot 2 image.
- *
  * @return                      0 on success; nonzero on failure.
  */
 static int
 boot_copy_image(void)
 {
-    uint32_t off;
     uint32_t sz;
     int i;
+    int end_area = 1;
     int cnt;
-    int rc;
-    int state_idx;
-
-    state_idx = BOOT_PERSIST_IDX(boot_state.state);
-    for (off = 0, i = 0; off < boot_state.length; off += sz, i += cnt) {
-        sz = boot_copy_sz(i, boot_req->br_slot_areas[1], &cnt);
-        if (i >= state_idx) {
-            rc = boot_swap_areas(i, sz);
-            assert(rc == 0);
+    int cur_idx;
+
+    for (i = boot_req->br_slot_areas[1], cur_idx = 0; i > 0; cur_idx++) {
+        sz = boot_copy_sz(i, &cnt);
+        i -= cnt;
+        if (cur_idx >= boot_state.idx) {
+            boot_swap_areas(i, sz, end_area);
         }
+        end_area = 0;
     }
+    boot_clear_status();
 
     return 0;
 }
 
-/**
- * Builds a default boot status corresponding to all images being fully present
- * in their slots.  This function is used when a boot status is not present in
- * flash (i.e., in the usual case when the previous boot operation ran to
- * completion).
+
+/*
+ * Is copy in progress?
  */
 static void
-boot_build_status(void)
+boot_read_status_bytes(struct boot_status *bs, uint8_t flash_id, uint32_t off)
 {
-    uint32_t len1;
-    uint32_t len2;
+    uint8_t status;
 
-    if (boot_img_hdrs[0].ih_magic == IMAGE_MAGIC) {
-        len1 = boot_img_hdrs[0].ih_hdr_size + boot_img_hdrs[0].ih_img_size +
-          boot_img_hdrs[0].ih_tlv_size;
-    } else {
-        len1 = 0;
+    off -= sizeof(status) * 2;
+    while (1) {
+        hal_flash_read(flash_id, off, &status, sizeof(status));
+        if (status == 0xff) {
+            break;
+        }
+        off--;
+        if (bs->state == 2) {
+            bs->idx++;
+            bs->state = 0;
+        } else {
+            bs->state++;
+        }
     }
+}
 
-    if (boot_img_hdrs[1].ih_magic == IMAGE_MAGIC) {
-        len2 = boot_img_hdrs[1].ih_hdr_size + boot_img_hdrs[1].ih_img_size +
-          boot_img_hdrs[0].ih_tlv_size;
-    } else {
-        len2 = 0;
+int
+boot_read_status(struct boot_status *bs)
+{
+    struct boot_img_trailer bit;
+    struct flash_area *scratch;
+
+    /*
+     * Check if boot_img_trailer is in scratch, or at the end of slot0.
+     */
+    boot_slot_magic(0, &bit);
+    if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
+        boot_read_status_bytes(bs, boot_img[0].loc.bil_flash_id,
+          boot_magic_off(0));
+        console_printf("status in slot0, %lu/%lu\n", bs->idx, bs->state);
+        return 1;
     }
-    boot_state.length = len1;
-    if (len1 < len2) {
-        boot_state.length = len2;
+    boot_scratch_magic(&bit);
+    if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
+        scratch = &boot_req->br_area_descs[boot_req->br_scratch_area_idx];
+        boot_read_status_bytes(bs, scratch->fa_flash_id, boot_scratch_off());
+        console_printf("status in scratch, %lu/%lu\n", bs->idx, bs->state);
+        return 1;
     }
-    boot_state.state = 0;
+    return 0;
+}
+
+#include <hal/hal_system.h>
+
+int
+boot_write_status(struct boot_status *bs)
+{
+    uint32_t off;
+    uint8_t flash_id;
+    uint8_t val;
+
+    if (bs->idx == 0) {
+        /*
+         * Write to scratch
+         */
+        off = boot_scratch_off();
+        flash_id =
+          boot_req->br_area_descs[boot_req->br_scratch_area_idx].fa_flash_id;
+    } else {
+        /*
+         * Write to slot 0;
+         */
+        off = boot_magic_off(0);
+        flash_id = boot_img[0].loc.bil_flash_id;
+    }
+    off -= ((3 * sizeof(uint8_t)) * bs->idx +
+      sizeof(uint8_t) * (bs->state + 1));
+
+    console_printf("status write, %lu/%lu -> %lx\n", bs->idx, bs->state, off);
+
+    val = bs->state;
+    hal_flash_write(flash_id, off, &val, sizeof(val));
+
+    return 0;
+}
+
+void
+boot_clear_status(void)
+{
+    uint32_t off;
+    uint32_t val = BOOT_IMG_MAGIC;
+    uint8_t flash_id;
+
+    /*
+     * Write to slot 0;
+     */
+    off = boot_magic_off(0);
+    flash_id = boot_img[0].loc.bil_flash_id;
+    off += sizeof(uint32_t);
+    hal_flash_write(flash_id, off, &val, sizeof(val));
 }
 
 /**
@@ -396,23 +500,23 @@ boot_build_status(void)
 int
 boot_go(const struct boot_req *req, struct boot_rsp *rsp)
 {
-    struct boot_image_location image_addrs[BOOT_NUM_SLOTS];
     int slot;
     int rc;
-    int i;
 
     /* Set the global boot request object.  The remainder of the boot process
      * will reference the global.
      */
     boot_req = req;
 
+    /* Attempt to read an image header from each slot. */
+    boot_image_info();
+
     /* Read the boot status to determine if an image copy operation was
      * interrupted (i.e., the system was reset before the boot loader could
      * finish its task last time).
      */
     if (boot_read_status(&boot_state)) {
         /* We are resuming an interrupted image copy. */
-        /* XXX if copy has not actually started yet, validate image */
         rc = boot_copy_image();
         if (rc != 0) {
             /* We failed to put the images back together; there is really no
@@ -422,80 +526,25 @@ boot_go(const struct boot_req *req, struct boot_rsp *rsp)
         }
     }
 
-    /* Cache the flash address of each image slot. */
-    for (i = 0; i < BOOT_NUM_SLOTS; i++) {
-        boot_slot_addr(i, &image_addrs[i].bil_flash_id,
-                       &image_addrs[i].bil_address);
-    }
-
-    /* Attempt to read an image header from each slot. */
-    boot_read_image_headers(boot_img_hdrs, image_addrs, BOOT_NUM_SLOTS);
-
-    /* Build a boot status structure indicating the flash location of each
-     * image part.  This structure will need to be used if an image copy
-     * operation is required.
+    /*
+     * Check if we should initiate copy.
      */
-    boot_build_status();
-
-    /* Determine which image the user wants to run, and where it is located. */
     slot = boot_select_image_slot();
     if (slot == -1) {
-        /* Either there is no image vector, or none of the requested images are
-         * present.  Just try booting from the first image slot.
-         */
-        if (boot_img_hdrs[0].ih_magic != IMAGE_MAGIC_NONE) {
-            slot = 0;
-        } else if (boot_img_hdrs[1].ih_magic != IMAGE_MAGIC_NONE) {
-            slot = 1;
-        } else {
-            /* No images present. */
-            return BOOT_EBADIMAGE;
-        }
+        return BOOT_EBADIMAGE;
     }
 
-    /*
-     * If the selected image fails integrity check, try the other one.
-     */
-    if (boot_image_check(&boot_img_hdrs[slot], &image_addrs[slot])) {
-        slot ^= 1;
-        if (boot_image_check(&boot_img_hdrs[slot], &image_addrs[slot])) {
-            return BOOT_EBADIMAGE;
-        }
-    }
-    switch (slot) {
-    case 0:
-        rsp->br_hdr = &boot_img_hdrs[0];
-        break;
-
-    case 1:
-        /* The user wants to run the image in the secondary slot.  The contents
-         * of this slot need to moved to the primary slot.
-         */
+    if (slot) {
         rc = boot_copy_image();
-        if (rc != 0) {
-            /* We failed to put the images back together; there is really no
-             * solution here.
-             */
+        if (rc) {
             return rc;
         }
-
-        rsp->br_hdr = &boot_img_hdrs[1];
-        break;
-
-    default:
-        assert(0);
-        break;
     }
 
     /* Always boot from the primary slot. */
-    rsp->br_flash_id = image_addrs[0].bil_flash_id;
-    rsp->br_image_addr = image_addrs[0].bil_address;
-
-    /* After successful boot, there should not be a status file. */
-    boot_clear_status();
-
-    /* If an image is being tested, it should only be booted into once. */
-    boot_vect_write_test(NULL);
+    rsp->br_flash_id = boot_img[0].loc.bil_flash_id;
+    rsp->br_image_addr = boot_img[0].loc.bil_address;
+    rsp->br_hdr = &boot_img[0].hdr;
 
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b2009c9f/libs/imgmgr/src/imgmgr_boot.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_boot.c b/libs/imgmgr/src/imgmgr_boot.c
index e678b74..c0277b1 100644
--- a/libs/imgmgr/src/imgmgr_boot.c
+++ b/libs/imgmgr/src/imgmgr_boot.c
@@ -132,12 +132,11 @@ imgr_boot_write(struct nmgr_jbuf *njb)
         rc = NMGR_ERR_EINVAL;
         goto err;
     }
-    rc = boot_vect_write_test(&ver);
+    rc = boot_vect_write_test(rc);
     if (rc) {
         rc = NMGR_ERR_EINVAL;
         goto err;
     }
-
     enc = &njb->njb_enc;
 
     json_encode_object_start(enc);
@@ -226,11 +225,12 @@ imgr_boot2_write(struct nmgr_jbuf *njb)
     base64_decode(hash_str, hash);
     rc = imgr_find_by_hash(hash, &ver);
     if (rc >= 0) {
-        rc = boot_vect_write_test(&ver);
+        rc = boot_vect_write_test(rc);
         if (rc) {
             rc = NMGR_ERR_EUNKNOWN;
             goto err;
         }
+        rc = 0;
     } else {
         rc = NMGR_ERR_EINVAL;
         goto err;



[05/50] [abbrv] incubator-mynewt-core git commit: MYNEWT-358: nrf51 cannot connect to directed advertisers w/privacy

Posted by cc...@apache.org.
MYNEWT-358: nrf51 cannot connect to directed advertisers w/privacy

In order to fix this issue I have added the local RPA to the resolving list and
modified the code so that the RPA timer is a true LL timer that will be used
to regenerate local RPAs at the specified timeout. This allows the local RPA
to be generated early and not during an IFS interval


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

Branch: refs/heads/master
Commit: 726a600cd594f7c6ae6092a3df58d469178806aa
Parents: a955c2f
Author: William San Filippo <wi...@runtime.io>
Authored: Thu Aug 11 14:19:56 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Thu Aug 11 17:49:46 2016 -0700

----------------------------------------------------------------------
 .../include/controller/ble_ll_resolv.h          |   7 +-
 net/nimble/controller/src/ble_ll_adv.c          |  17 +++
 net/nimble/controller/src/ble_ll_conn.c         |   1 +
 net/nimble/controller/src/ble_ll_resolv.c       | 150 +++++++++++++++----
 net/nimble/controller/src/ble_ll_scan.c         |   2 +-
 5 files changed, 142 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/726a600c/net/nimble/controller/include/controller/ble_ll_resolv.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_resolv.h b/net/nimble/controller/include/controller/ble_ll_resolv.h
index 251543b..6c63c79 100644
--- a/net/nimble/controller/include/controller/ble_ll_resolv.h
+++ b/net/nimble/controller/include/controller/ble_ll_resolv.h
@@ -23,15 +23,18 @@
 /*
  * An entry in the resolving list.
  *      The identity address is stored in little endian format.
+ *      The local rpa is stored in little endian format.
  *      The IRKs are stored in big endian format.
  */
 struct ble_ll_resolv_entry
 {
-    uint8_t rl_reserved;
     uint8_t rl_addr_type;
-    uint8_t rl_identity_addr[BLE_DEV_ADDR_LEN];
+    uint8_t rl_local_rpa_set;
+    uint16_t rl_reserved;
     uint8_t rl_local_irk[16];
     uint8_t rl_peer_irk[16];
+    uint8_t rl_identity_addr[BLE_DEV_ADDR_LEN];
+    uint8_t rl_local_rpa[BLE_DEV_ADDR_LEN];
 };
 
 extern struct ble_ll_resolv_entry g_ble_ll_resolv_list[];

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/726a600c/net/nimble/controller/src/ble_ll_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_adv.c b/net/nimble/controller/src/ble_ll_adv.c
index 1f43a5d..0c6df3b 100644
--- a/net/nimble/controller/src/ble_ll_adv.c
+++ b/net/nimble/controller/src/ble_ll_adv.c
@@ -121,6 +121,23 @@ struct ble_ll_adv_sm g_ble_ll_adv_sm;
 
 
 #if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
+/**
+ * Called to change advertisers ADVA and INITA (for directed advertisements)
+ * as an advertiser needs to adhere to the resolvable private address generation
+ * timer.
+ *
+ * NOTE: the resolvable private address code uses its own timer to regenerate
+ * local resolvable private addresses. The advertising code uses its own
+ * timer to reset the INITA (for directed advertisements). This code also sets
+ * the appropriate txadd and rxadd bits that will go into the advertisement.
+ *
+ * Another thing to note: it is possible that an IRK is all zeroes in the
+ * resolving list. That is why we need to check if the generated address is
+ * in fact a RPA as a resolving list entry with all zeroes will use the
+ * identity address (which may be a private address or public).
+ *
+ * @param advsm
+ */
 void
 ble_ll_adv_chk_rpa_timeout(struct ble_ll_adv_sm *advsm)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/726a600c/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c
index bfbdf99..fb95367 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -1904,6 +1904,7 @@ ble_ll_conn_event_end(void *arg)
      * The way this works is that whenever the timer expires it just gets reset
      * and we send the autheticated payload timeout event. Note that this timer
      * should run even when encryption is paused.
+     * XXX: what should be here? Was there code here that got deleted?
      */
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/726a600c/net/nimble/controller/src/ble_ll_resolv.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_resolv.c b/net/nimble/controller/src/ble_ll_resolv.c
index b4d58b0..903c95f 100644
--- a/net/nimble/controller/src/ble_ll_resolv.c
+++ b/net/nimble/controller/src/ble_ll_resolv.c
@@ -31,12 +31,15 @@
 #include "ble_ll_conn_priv.h"
 
 #if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
-
-/* Flag denoting whether or not address translation is enabled. */
-uint8_t g_ble_ll_addr_res_enabled;
-uint8_t g_ble_ll_resolv_list_size;
-uint8_t g_ble_ll_resolv_list_cnt;
-uint32_t g_ble_ll_resolv_rpa_tmo;
+struct ble_ll_resolv_data
+{
+    uint8_t addr_res_enabled;
+    uint8_t rl_size;
+    uint8_t rl_cnt;
+    uint32_t rpa_tmo;
+    struct os_callout_func rpa_timer;
+};
+struct ble_ll_resolv_data g_ble_ll_resolv_data;
 
 struct ble_ll_resolv_entry g_ble_ll_resolv_list[NIMBLE_OPT_LL_RESOLV_LIST_SIZE];
 
@@ -53,9 +56,9 @@ ble_ll_resolv_list_chg_allowed(void)
 {
     int rc;
 
-    if (g_ble_ll_addr_res_enabled && (ble_ll_adv_enabled()  ||
-                                      ble_ll_scan_enabled() ||
-                                      g_ble_ll_conn_create_sm)) {
+    if (g_ble_ll_resolv_data.addr_res_enabled &&
+            (ble_ll_adv_enabled() || ble_ll_scan_enabled() ||
+             g_ble_ll_conn_create_sm)) {
         rc = 0;
     } else {
         rc = 1;
@@ -64,6 +67,32 @@ ble_ll_resolv_list_chg_allowed(void)
 }
 
 /**
+ * Called when the Resolvable private address timer expires. This timer
+ * is used to regenerate local RPA's in the resolving list.
+ *
+ * @param arg
+ */
+void
+ble_ll_resolv_rpa_timer_cb(void *arg)
+{
+    int i;
+    os_sr_t sr;
+    struct ble_ll_resolv_entry *rl;
+
+    rl = &g_ble_ll_resolv_list[0];
+    for (i = 0; i < g_ble_ll_resolv_data.rl_cnt; ++i) {
+        OS_ENTER_CRITICAL(sr);
+        rl->rl_local_rpa_set = 0;
+        ble_ll_resolv_gen_priv_addr(rl, 1, rl->rl_local_rpa);
+        rl->rl_local_rpa_set = 1;
+        OS_EXIT_CRITICAL(sr);
+        ++rl;
+    }
+    os_callout_reset(&g_ble_ll_resolv_data.rpa_timer.cf_c,
+                     (int32_t)g_ble_ll_resolv_data.rpa_tmo);
+}
+
+/**
  * Called to determine if the IRK is all zero.
  *
  * @param irk
@@ -102,7 +131,7 @@ ble_ll_resolv_list_clr(void)
     }
 
     /* Sets total on list to 0. Clears HW resolve list */
-    g_ble_ll_resolv_list_cnt = 0;
+    g_ble_ll_resolv_data.rl_cnt = 0;
     ble_hw_resolv_list_clear();
 
     return BLE_ERR_SUCCESS;
@@ -119,7 +148,7 @@ ble_ll_resolv_list_clr(void)
 int
 ble_ll_resolv_list_read_size(uint8_t *rspbuf, uint8_t *rsplen)
 {
-    rspbuf[0] = g_ble_ll_resolv_list_size;
+    rspbuf[0] = g_ble_ll_resolv_data.rl_size;
     *rsplen = 1;
     return BLE_ERR_SUCCESS;
 }
@@ -141,7 +170,7 @@ ble_ll_is_on_resolv_list(uint8_t *addr, uint8_t addr_type)
     struct ble_ll_resolv_entry *rl;
 
     rl = &g_ble_ll_resolv_list[0];
-    for (i = 0; i < g_ble_ll_resolv_list_cnt; ++i) {
+    for (i = 0; i < g_ble_ll_resolv_data.rl_cnt; ++i) {
         if ((rl->rl_addr_type == addr_type) &&
             (!memcmp(&rl->rl_identity_addr[0], addr, BLE_DEV_ADDR_LEN))) {
             return i + 1;
@@ -167,7 +196,7 @@ ble_ll_resolv_list_find(uint8_t *addr, uint8_t addr_type)
     struct ble_ll_resolv_entry *rl;
 
     rl = &g_ble_ll_resolv_list[0];
-    for (i = 0; i < g_ble_ll_resolv_list_cnt; ++i) {
+    for (i = 0; i < g_ble_ll_resolv_data.rl_cnt; ++i) {
         if ((rl->rl_addr_type == addr_type) &&
             (!memcmp(&rl->rl_identity_addr[0], addr, BLE_DEV_ADDR_LEN))) {
             return rl;
@@ -197,7 +226,7 @@ ble_ll_resolv_list_add(uint8_t *cmdbuf)
     }
 
     /* Check if we have any open entries */
-    if (g_ble_ll_resolv_list_cnt >= g_ble_ll_resolv_list_size) {
+    if (g_ble_ll_resolv_data.rl_cnt >= g_ble_ll_resolv_data.rl_size) {
         return BLE_ERR_MEM_CAPACITY;
     }
 
@@ -206,14 +235,23 @@ ble_ll_resolv_list_add(uint8_t *cmdbuf)
 
     rc = BLE_ERR_SUCCESS;
     if (!ble_ll_is_on_resolv_list(ident_addr, addr_type)) {
-        rl = &g_ble_ll_resolv_list[g_ble_ll_resolv_list_cnt];
+        rl = &g_ble_ll_resolv_list[g_ble_ll_resolv_data.rl_cnt];
         rl->rl_addr_type = addr_type;
+        rl->rl_local_rpa_set = 0;
         memcpy(&rl->rl_identity_addr[0], ident_addr, BLE_DEV_ADDR_LEN);
         swap_buf(rl->rl_peer_irk, cmdbuf + 7, 16);
         swap_buf(rl->rl_local_irk, cmdbuf + 23, 16);
-        ++g_ble_ll_resolv_list_cnt;
 
+        /*
+         * Add peer IRK to HW resolving list. If we can add it, also
+         * generate a local RPA now to save time later.
+         */
         rc = ble_hw_resolv_list_add(rl->rl_peer_irk);
+        if (!rc) {
+            ble_ll_resolv_gen_priv_addr(rl, 1, rl->rl_local_rpa);
+            rl->rl_local_rpa_set = 1;
+        }
+        ++g_ble_ll_resolv_data.rl_cnt;
     }
 
     return rc;
@@ -243,11 +281,11 @@ ble_ll_resolv_list_rmv(uint8_t *cmdbuf)
 
     /* Remove from IRK records */
     position = ble_ll_is_on_resolv_list(ident_addr, addr_type);
-    if (position && (position < g_ble_ll_resolv_list_cnt)) {
+    if (position && (position < g_ble_ll_resolv_data.rl_cnt)) {
         memmove(&g_ble_ll_resolv_list[position - 1],
                 &g_ble_ll_resolv_list[position],
-                g_ble_ll_resolv_list_cnt - position);
-        --g_ble_ll_resolv_list_cnt;
+                g_ble_ll_resolv_data.rl_cnt - position);
+        --g_ble_ll_resolv_data.rl_cnt;
 
         /* Remove from HW list */
         ble_hw_resolv_list_rmv(position - 1);
@@ -267,13 +305,29 @@ int
 ble_ll_resolv_enable_cmd(uint8_t *cmdbuf)
 {
     int rc;
+    int32_t tmo;
+    uint8_t enabled;
 
     if (ble_ll_adv_enabled() || ble_ll_scan_enabled() ||
         g_ble_ll_conn_create_sm) {
         rc = BLE_ERR_CMD_DISALLOWED;
     } else {
-        g_ble_ll_addr_res_enabled = cmdbuf[0];
-        rc = BLE_ERR_SUCCESS;
+        enabled = cmdbuf[0];
+        if (enabled <= 1) {
+            /* If we change state, we need to disable/enable the RPA timer */
+            if ((enabled ^ g_ble_ll_resolv_data.addr_res_enabled) != 0) {
+                if (enabled) {
+                    tmo = (int32_t)g_ble_ll_resolv_data.rpa_tmo;
+                    os_callout_reset(&g_ble_ll_resolv_data.rpa_timer.cf_c, tmo);
+                } else {
+                    os_callout_stop(&g_ble_ll_resolv_data.rpa_timer.cf_c);
+                }
+                g_ble_ll_resolv_data.addr_res_enabled = enabled;
+            }
+            rc = BLE_ERR_SUCCESS;
+        } else {
+            rc = BLE_ERR_INV_HCI_CMD_PARMS;
+        }
     }
 
     return rc;
@@ -306,7 +360,11 @@ ble_ll_resolv_set_rpa_tmo(uint8_t *cmdbuf)
 
     tmo_secs = le16toh(cmdbuf);
     if ((tmo_secs > 0) && (tmo_secs <= 0xA1B8)) {
-        g_ble_ll_resolv_rpa_tmo = tmo_secs * OS_TICKS_PER_SEC;
+        g_ble_ll_resolv_data.rpa_tmo = tmo_secs * OS_TICKS_PER_SEC;
+        if (g_ble_ll_resolv_data.addr_res_enabled) {
+            os_callout_reset(&g_ble_ll_resolv_data.rpa_timer.cf_c,
+                             (int32_t)g_ble_ll_resolv_data.rpa_tmo);
+        }
     } else {
         rc = BLE_ERR_INV_HCI_CMD_PARMS;
     }
@@ -323,12 +381,11 @@ ble_ll_resolv_set_rpa_tmo(uint8_t *cmdbuf)
 uint32_t
 ble_ll_resolv_get_rpa_tmo(void)
 {
-    return g_ble_ll_resolv_rpa_tmo;
+    return g_ble_ll_resolv_data.rpa_tmo;
 }
 
 /**
- * Called the generate a resolvable private address
- *
+ * Called to generate a resolvable private address
  *
  * @param rl
  * @param local
@@ -348,6 +405,12 @@ ble_ll_resolv_gen_priv_addr(struct ble_ll_resolv_entry *rl, int local,
     assert(rl != NULL);
     assert(addr != NULL);
 
+    /* If the local rpa has already been generated, just copy it */
+    if (local && rl->rl_local_rpa_set) {
+        memcpy(addr, rl->rl_local_rpa, BLE_DEV_ADDR_LEN);
+        return;
+    }
+
     /* Get prand */
     prand = addr + 3;
     ble_ll_rand_prand_get(prand);
@@ -427,11 +490,29 @@ int
 ble_ll_resolv_rpa(uint8_t *rpa, uint8_t *irk)
 {
     int rc;
+    uint32_t *irk32;
+    uint32_t *key32;
+    uint32_t *pt32;
     struct ble_encryption_block ecb;
 
-    memcpy(ecb.key, irk, BLE_ENC_BLOCK_SIZE);
-    memset(ecb.plain_text, 0, BLE_ENC_BLOCK_SIZE);
-    swap_buf(&ecb.plain_text[13], rpa + 3, 3);
+    irk32 = (uint32_t *)irk;
+    key32 = (uint32_t *)&ecb.key[0];
+
+    key32[0] = irk32[0];
+    key32[1] = irk32[1];
+    key32[2] = irk32[2];
+    key32[3] = irk32[3];
+
+    pt32 = (uint32_t *)&ecb.plain_text[0];
+    pt32[0] = 0;
+    pt32[1] = 0;
+    pt32[2] = 0;
+    pt32[3] = 0;
+
+    ecb.plain_text[15] = rpa[3];
+    ecb.plain_text[14] = rpa[4];
+    ecb.plain_text[13] = rpa[5];
+
     ble_hw_encrypt_block(&ecb);
     if ((ecb.cipher_text[15] == rpa[0]) && (ecb.cipher_text[14] == rpa[1]) &&
         (ecb.cipher_text[13] == rpa[2])) {
@@ -451,7 +532,7 @@ ble_ll_resolv_rpa(uint8_t *rpa, uint8_t *irk)
 uint8_t
 ble_ll_resolv_enabled(void)
 {
-    return g_ble_ll_addr_res_enabled;
+    return g_ble_ll_resolv_data.addr_res_enabled;
 }
 
 /**
@@ -460,7 +541,8 @@ ble_ll_resolv_enabled(void)
 void
 ble_ll_resolv_list_reset(void)
 {
-    g_ble_ll_addr_res_enabled = 0;
+    g_ble_ll_resolv_data.addr_res_enabled = 0;
+    os_callout_stop(&g_ble_ll_resolv_data.rpa_timer.cf_c);
     ble_ll_resolv_list_clr();
     ble_ll_resolv_init();
 }
@@ -471,14 +553,18 @@ ble_ll_resolv_init(void)
     uint8_t hw_size;
 
     /* Default is 15 minutes */
-    g_ble_ll_resolv_rpa_tmo = 15 * 60 * OS_TICKS_PER_SEC;
+    g_ble_ll_resolv_data.rpa_tmo = 15 * 60 * OS_TICKS_PER_SEC;
 
     hw_size = ble_hw_resolv_list_size();
     if (hw_size > NIMBLE_OPT_LL_RESOLV_LIST_SIZE) {
         hw_size = NIMBLE_OPT_LL_RESOLV_LIST_SIZE;
     }
-    g_ble_ll_resolv_list_size = hw_size;
+    g_ble_ll_resolv_data.rl_size = hw_size;
 
+    os_callout_func_init(&g_ble_ll_resolv_data.rpa_timer,
+                         &g_ble_ll_data.ll_evq,
+                         ble_ll_resolv_rpa_timer_cb,
+                         NULL);
 }
 
 #endif  /* if BLE_LL_CFG_FEAT_LL_PRIVACY == 1 */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/726a600c/net/nimble/controller/src/ble_ll_scan.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c
index 0fc4e79..29193dc 100644
--- a/net/nimble/controller/src/ble_ll_scan.c
+++ b/net/nimble/controller/src/ble_ll_scan.c
@@ -448,7 +448,7 @@ ble_ll_hci_send_adv_report(uint8_t pdu_type, uint8_t txadd, uint8_t *rxbuf,
                  * are 2 greater than the unresolved ones in the spec, so
                  * we just add 2 here.
                  */
-                addr_type += 2;
+                addr_type = g_ble_ll_resolv_list[index].rl_addr_type + 2;
             } else{
                 adv_addr = rxbuf;
             }


[09/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Report updated MTU via GAP event cb.

Posted by cc...@apache.org.
BLE Host - Report updated MTU via GAP event cb.

Before this commit, MTU changes were only reported when we initiated the
exchange via a GATT procedure.  If the peer initiated the exchange, the
application never learned of an MTU update.

Now all MTU changes are reported through the GAP event callback.  The
callback passed to ble_gattc_exchange_mtu() is not very useful anymore.
Its only real purpose is to inform the user if the peer failed to
respond to the MTU request, which causes the connection to be terminated
anyway.

Relevant additions to the API:

 #define BLE_GAP_EVENT_MTU                   15

 struct ble_gap_event {
     /* [...] */

     /**
      * Represents a change in an L2CAP channel's MTU.
      *
      * Valid for the following event types:
      *     o BLE_GAP_EVENT_MTU
      */
     struct {
         /** The handle of the relevant connection. */
         uint16_t conn_handle;

         /**
          * Indicates the channel whose MTU has been updated; either
          * BLE_L2CAP_CID_ATT or the ID of a connection-oriented
          * channel.
          */
         uint16_t channel_id;

         /* The channel's new MTU. */
         uint16_t value;
     } mtu;
 };


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

Branch: refs/heads/master
Commit: e3750fe0d1e05829b97f6e635d23977369383dd6
Parents: 277edaf
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 12 17:48:00 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Aug 12 18:16:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h      |  21 +++++
 net/nimble/host/src/ble_att_clt.c           |   4 +-
 net/nimble/host/src/ble_att_cmd.c           |  31 +++----
 net/nimble/host/src/ble_att_cmd_priv.h      |   4 +-
 net/nimble/host/src/ble_att_svr.c           |   6 +-
 net/nimble/host/src/ble_gap.c               |  17 ++++
 net/nimble/host/src/ble_gap_priv.h          |   1 +
 net/nimble/host/src/test/ble_att_clt_test.c |  31 +++++++
 net/nimble/host/src/test/ble_att_svr_test.c |   2 +-
 net/nimble/host/src/test/ble_gap_test.c     | 111 +++++++++++++++++------
 net/nimble/host/src/test/ble_hs_test_util.c |  42 ++++++++-
 net/nimble/host/src/test/ble_hs_test_util.h |   5 +-
 12 files changed, 224 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 46854e0..960ad7b 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -107,6 +107,7 @@ struct hci_conn_update;
 #define BLE_GAP_EVENT_NOTIFY_RX             12
 #define BLE_GAP_EVENT_NOTIFY_TX             13
 #define BLE_GAP_EVENT_SUBSCRIBE             14
+#define BLE_GAP_EVENT_MTU                   15
 
 /*** Reason codes for the subscribe GAP event. */
 
@@ -489,6 +490,26 @@ struct ble_gap_event {
             /** Whether the peer is currently subscribed to indications. */
             uint8_t cur_indicate:1;
         } subscribe;
+
+        /**
+         * Represents a change in an L2CAP channel's MTU.
+         *
+         * Valid for the following event types:
+         *     o BLE_GAP_EVENT_MTU
+         */
+        struct {
+            /** The handle of the relevant connection. */
+            uint16_t conn_handle;
+
+            /**
+             * Indicates the channel whose MTU has been updated; either
+             * BLE_L2CAP_CID_ATT or the ID of a connection-oriented channel.
+             */
+            uint16_t channel_id;
+
+            /* The channel's new MTU. */
+            uint16_t value;
+        } mtu;
     };
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/ble_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c
index 8170c6c..735e819 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -173,7 +173,7 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
 
     rc = ble_hs_mbuf_pullup_base(rxom, BLE_ATT_MTU_CMD_SZ);
     if (rc == 0) {
-        ble_att_mtu_cmd_parse((*rxom)->om_data, (*rxom)->om_len, &cmd);
+        ble_att_mtu_rsp_parse((*rxom)->om_data, (*rxom)->om_len, &cmd);
         BLE_ATT_LOG_CMD(0, "mtu rsp", conn_handle, ble_att_mtu_cmd_log, &cmd);
 
         ble_hs_lock();
@@ -183,6 +183,8 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
         mtu = ble_l2cap_chan_mtu(chan);
 
         ble_hs_unlock();
+
+        ble_gap_mtu_event(conn_handle, BLE_L2CAP_CID_ATT, mtu);
     }
 
     ble_gattc_rx_mtu(conn_handle, rc, mtu);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/ble_att_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd.c b/net/nimble/host/src/ble_att_cmd.c
index b8ca094..05c6874 100644
--- a/net/nimble/host/src/ble_att_cmd.c
+++ b/net/nimble/host/src/ble_att_cmd.c
@@ -40,20 +40,6 @@ ble_att_init_parse(uint8_t op, const void *payload,
     return u8ptr + 1;
 }
 
-static const void *
-ble_att_init_parse_2op(uint8_t op1, uint8_t op2, const void *payload,
-                       int min_len, int actual_len)
-{
-    const uint8_t *u8ptr;
-
-    BLE_HS_DBG_ASSERT(actual_len >= min_len);
-
-    u8ptr = payload;
-    BLE_HS_DBG_ASSERT(u8ptr[0] == op1 || u8ptr[0] == op2);
-
-    return u8ptr + 1;
-}
-
 static void *
 ble_att_init_write(uint8_t op, void *payload, int min_len, int actual_len)
 {
@@ -113,13 +99,24 @@ ble_att_mtu_cmd_swap(struct ble_att_mtu_cmd *dst,
 }
 
 void
-ble_att_mtu_cmd_parse(const void *payload, int len,
+ble_att_mtu_req_parse(const void *payload, int len,
+                      struct ble_att_mtu_cmd *dst)
+{
+    const struct ble_att_mtu_cmd *src;
+
+    src = ble_att_init_parse(BLE_ATT_OP_MTU_REQ, payload, BLE_ATT_MTU_CMD_SZ,
+                             len);
+    ble_att_mtu_cmd_swap(dst, src);
+}
+
+void
+ble_att_mtu_rsp_parse(const void *payload, int len,
                       struct ble_att_mtu_cmd *dst)
 {
     const struct ble_att_mtu_cmd *src;
 
-    src = ble_att_init_parse_2op(BLE_ATT_OP_MTU_REQ, BLE_ATT_OP_MTU_RSP,
-                                 payload, BLE_ATT_MTU_CMD_SZ, len);
+    src = ble_att_init_parse(BLE_ATT_OP_MTU_RSP, payload, BLE_ATT_MTU_CMD_SZ,
+                             len);
     ble_att_mtu_cmd_swap(dst, src);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index 44989a1..bfeb28f 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -309,10 +309,12 @@ void ble_att_error_rsp_parse(const void *payload, int len,
 void ble_att_error_rsp_write(void *payload, int len,
                              const struct ble_att_error_rsp *rsp);
 void ble_att_error_rsp_log(const struct ble_att_error_rsp *cmd);
-void ble_att_mtu_cmd_parse(const void *payload, int len,
+void ble_att_mtu_req_parse(const void *payload, int len,
                            struct ble_att_mtu_cmd *cmd);
 void ble_att_mtu_req_write(void *payload, int len,
                            const struct ble_att_mtu_cmd *cmd);
+void ble_att_mtu_rsp_parse(const void *payload, int len,
+                           struct ble_att_mtu_cmd *cmd);
 void ble_att_mtu_rsp_write(void *payload, int len,
                            const struct ble_att_mtu_cmd *cmd);
 void ble_att_mtu_cmd_log(const struct ble_att_mtu_cmd *cmd);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index f224094..710db20 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -659,6 +659,7 @@ ble_att_svr_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
     struct os_mbuf *txom;
+    uint16_t mtu;
     uint8_t att_err;
     int rc;
 
@@ -669,7 +670,7 @@ ble_att_svr_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
         goto done;
     }
 
-    ble_att_mtu_cmd_parse((*rxom)->om_data, (*rxom)->om_len, &cmd);
+    ble_att_mtu_req_parse((*rxom)->om_data, (*rxom)->om_len, &cmd);
     BLE_ATT_LOG_CMD(0, "mtu req", conn_handle, ble_att_mtu_cmd_log, &cmd);
 
     rc = ble_att_svr_build_mtu_rsp(conn_handle, &txom, &att_err);
@@ -688,8 +689,11 @@ done:
         ble_att_conn_chan_find(conn_handle, &conn, &chan);
         ble_att_set_peer_mtu(chan, cmd.bamc_mtu);
         chan->blc_flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
+        mtu = ble_l2cap_chan_mtu(chan);
 
         ble_hs_unlock();
+
+        ble_gap_mtu_event(conn_handle, BLE_L2CAP_CID_ATT, mtu);
     }
     return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 9717125..f53a738 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2902,6 +2902,23 @@ ble_gap_subscribe_event(uint16_t conn_handle, uint16_t attr_handle,
 }
 
 /*****************************************************************************
+ * $mtu                                                                      *
+ *****************************************************************************/
+
+void
+ble_gap_mtu_event(uint16_t conn_handle, uint16_t cid, uint16_t mtu)
+{
+    struct ble_gap_event event;
+
+    memset(&event, 0, sizeof event);
+    event.type = BLE_GAP_EVENT_MTU;
+    event.mtu.conn_handle = conn_handle;
+    event.mtu.channel_id = cid;
+    event.mtu.value = mtu;
+    ble_gap_call_conn_event_cb(&event, conn_handle);
+}
+
+/*****************************************************************************
  * $init                                                                     *
  *****************************************************************************/
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index c2abbf3..eed5a18 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -89,6 +89,7 @@ void ble_gap_subscribe_event(uint16_t conn_handle, uint16_t attr_handle,
                              uint8_t reason,
                              uint8_t prev_notify, uint8_t cur_notify,
                              uint8_t prev_indicate, uint8_t cur_indicate);
+void ble_gap_mtu_event(uint16_t conn_handle, uint16_t cid, uint16_t mtu);
 int ble_gap_master_in_progress(void);
 
 void ble_gap_conn_broken(uint16_t conn_handle, int reason);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/test/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_clt_test.c b/net/nimble/host/src/test/ble_att_clt_test.c
index ab89e9d..14d66f6 100644
--- a/net/nimble/host/src/test/ble_att_clt_test.c
+++ b/net/nimble/host/src/test/ble_att_clt_test.c
@@ -275,6 +275,22 @@ ble_att_clt_test_misc_prep_bad(uint16_t handle, uint16_t offset,
     TEST_ASSERT(rc == status);
 }
 
+static void
+ble_att_clt_test_misc_tx_mtu(uint16_t conn_handle, uint16_t mtu, int status)
+{
+    struct ble_att_mtu_cmd req;
+    int rc;
+
+    req.bamc_mtu = mtu;
+    rc = ble_att_clt_tx_mtu(conn_handle, &req);
+    TEST_ASSERT(rc == status);
+
+    if (rc == 0) {
+        ble_hs_test_util_verify_tx_mtu_cmd(1, mtu);
+    }
+}
+
+
 TEST_CASE(ble_att_clt_test_tx_write)
 {
     ble_att_clt_test_case_tx_write_req_or_cmd(0);
@@ -509,6 +525,20 @@ TEST_CASE(ble_att_clt_test_tx_exec_write)
     TEST_ASSERT(rc == BLE_HS_EINVAL);
 }
 
+TEST_CASE(ble_att_clt_test_tx_mtu)
+{
+    uint16_t conn_handle;
+
+    conn_handle = ble_att_clt_test_misc_init();
+
+    /*** Success. */
+    ble_att_clt_test_misc_tx_mtu(conn_handle, 50, 0);
+
+    /*** Error: repeated sends. */
+    ble_att_clt_test_misc_tx_mtu(conn_handle, 50, BLE_HS_EALREADY);
+    ble_att_clt_test_misc_tx_mtu(conn_handle, 60, BLE_HS_EALREADY);
+}
+
 TEST_SUITE(ble_att_clt_suite)
 {
     tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
@@ -525,6 +555,7 @@ TEST_SUITE(ble_att_clt_suite)
     ble_att_clt_test_tx_prep_write();
     ble_att_clt_test_rx_prep_write();
     ble_att_clt_test_tx_exec_write();
+    ble_att_clt_test_tx_mtu();
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index d8dfb27..52a5669 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -475,7 +475,7 @@ ble_att_svr_test_misc_verify_tx_mtu_rsp(uint16_t conn_handle)
     rc = os_mbuf_copydata(om, 0, sizeof buf, buf);
     TEST_ASSERT(rc == 0);
 
-    ble_att_mtu_cmd_parse(buf, sizeof buf, &rsp);
+    ble_att_mtu_rsp_parse(buf, sizeof buf, &rsp);
 
     ble_hs_lock();
     rc = ble_hs_misc_conn_chan_find(conn_handle, BLE_L2CAP_CID_ATT,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index 1943d01..5dd6532 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -26,7 +26,7 @@
 #include "host/ble_hs_test.h"
 #include "ble_hs_test_util.h"
 
-static int ble_gap_test_conn_event_type;
+static struct ble_gap_event ble_gap_test_event;
 static int ble_gap_test_conn_status;
 static struct ble_gap_conn_desc ble_gap_test_conn_desc;
 static void *ble_gap_test_conn_arg;
@@ -54,7 +54,7 @@ ble_gap_test_util_update_in_progress(uint16_t conn_handle)
 static void
 ble_gap_test_util_reset_cb_info(void)
 {
-    ble_gap_test_conn_event_type = -1;
+    memset(&ble_gap_test_event, 0xff, sizeof ble_gap_test_event);
     ble_gap_test_conn_status = -1;
     memset(&ble_gap_test_conn_desc, 0xff, sizeof ble_gap_test_conn_desc);
     ble_gap_test_conn_arg = (void *)-1;
@@ -90,7 +90,7 @@ ble_gap_test_util_connect_cb(struct ble_gap_event *event, void *arg)
 {
     int *fail_reason;
 
-    ble_gap_test_conn_event_type = event->type;
+    ble_gap_test_event = *event;
     ble_gap_test_conn_arg = arg;
 
     switch (event->type) {
@@ -137,6 +137,9 @@ ble_gap_test_util_connect_cb(struct ble_gap_event *event, void *arg)
         }
         break;
 
+    case BLE_GAP_EVENT_MTU:
+        break;
+
     default:
         TEST_ASSERT_FATAL(0);
         break;
@@ -855,7 +858,7 @@ TEST_CASE(ble_gap_test_case_conn_gen_good)
 
     TEST_ASSERT(!ble_gap_master_in_progress());
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONNECT);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONNECT);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
                        peer_addr, 6) == 0);
@@ -989,7 +992,7 @@ ble_gap_test_util_conn_cancel(uint8_t hci_status)
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(!ble_gap_master_in_progress());
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_CANCEL);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_CANCEL);
 }
 
 static void
@@ -1029,7 +1032,7 @@ TEST_CASE(ble_gap_test_case_conn_cancel_good)
 
     ble_gap_test_util_conn_and_cancel(peer_addr, 0);
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_CANCEL);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_CANCEL);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == BLE_HS_CONN_HANDLE_NONE);
 }
 
@@ -1045,7 +1048,7 @@ TEST_CASE(ble_gap_test_case_conn_cancel_ctlr_fail)
     /* Make sure the host didn't invoke the application callback.  The cancel
      * failure was indicated via the return code from the gap call.
      */
-    TEST_ASSERT(ble_gap_test_conn_event_type == -1);
+    TEST_ASSERT(ble_gap_test_event.type == 0xff);
 
     /* Allow connection complete to succeed. */
     memset(&evt, 0, sizeof evt);
@@ -1059,7 +1062,7 @@ TEST_CASE(ble_gap_test_case_conn_cancel_ctlr_fail)
 
     TEST_ASSERT(!ble_gap_master_in_progress());
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONNECT);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONNECT);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
                        peer_addr, 6) == 0);
@@ -1095,7 +1098,7 @@ ble_gap_test_util_terminate(uint8_t *peer_addr, uint8_t hci_status)
     /* Reset the callback event code; we don't care about the successful
      * connection in this test.
      */
-    ble_gap_test_conn_event_type = -1;
+    ble_gap_test_event.type = -1;
 
     /* Terminate the connection. */
     rc = ble_hs_test_util_conn_terminate(2, hci_status);
@@ -1131,7 +1134,7 @@ TEST_CASE(ble_gap_test_case_conn_terminate_good)
 
     ble_gap_test_util_terminate(peer_addr, 0);
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_DISCONNECT);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_DISCONNECT);
     TEST_ASSERT(ble_gap_test_conn_status ==
                 BLE_HS_HCI_ERR(BLE_ERR_CONN_TERM_LOCAL));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
@@ -1172,7 +1175,7 @@ TEST_CASE(ble_gap_test_case_conn_terminate_ctlr_fail)
     evt.reason = 0;
     ble_gap_rx_disconn_complete(&evt);
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_TERM_FAILURE);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_TERM_FAILURE);
     TEST_ASSERT(ble_gap_test_conn_status ==
                 BLE_HS_HCI_ERR(BLE_ERR_UNSUPPORTED));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
@@ -1192,7 +1195,7 @@ TEST_CASE(ble_gap_test_case_conn_terminate_hci_fail)
 
     ble_gap_test_util_terminate(peer_addr, BLE_ERR_REPEATED_ATTEMPTS);
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == -1);
+    TEST_ASSERT(ble_gap_test_event.type == 0xff);
     TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0);
     TEST_ASSERT(!ble_gap_master_in_progress());
 }
@@ -1574,7 +1577,7 @@ TEST_CASE(ble_gap_test_case_adv_good)
 
             if (c != BLE_GAP_CONN_MODE_NON) {
                 TEST_ASSERT(!ble_gap_adv_active());
-                TEST_ASSERT(ble_gap_test_conn_event_type ==
+                TEST_ASSERT(ble_gap_test_event.type ==
                                 BLE_GAP_EVENT_CONNECT);
                 TEST_ASSERT(ble_gap_test_conn_status == 0);
                 TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
@@ -1598,7 +1601,7 @@ TEST_CASE(ble_gap_test_case_adv_ctlr_fail)
                                   peer_addr, c, d, BLE_ERR_DIR_ADV_TMO, -1, 0);
 
             TEST_ASSERT(!ble_gap_adv_active());
-            TEST_ASSERT(ble_gap_test_conn_event_type ==
+            TEST_ASSERT(ble_gap_test_event.type ==
                         BLE_GAP_EVENT_ADV_COMPLETE);
             TEST_ASSERT(ble_gap_test_conn_desc.conn_handle ==
                         BLE_HS_CONN_HANDLE_NONE);
@@ -1629,7 +1632,7 @@ TEST_CASE(ble_gap_test_case_adv_hci_fail)
                                       c, d, 0, fail_idx, BLE_ERR_UNSUPPORTED);
 
                 TEST_ASSERT(!ble_gap_adv_active());
-                TEST_ASSERT(ble_gap_test_conn_event_type == -1);
+                TEST_ASSERT(ble_gap_test_event.type == 0xff);
             }
         }
     }
@@ -1687,7 +1690,7 @@ TEST_CASE(ble_gap_test_case_stop_adv_good)
             ble_gap_test_util_stop_adv(BLE_ADDR_TYPE_PUBLIC, peer_addr, c, d,
                                        -1, 0);
             TEST_ASSERT(!ble_gap_adv_active());
-            TEST_ASSERT(ble_gap_test_conn_event_type == -1);
+            TEST_ASSERT(ble_gap_test_event.type == 0xff);
             TEST_ASSERT(ble_gap_test_conn_status == -1);
             TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == (uint16_t)-1);
             TEST_ASSERT(ble_gap_test_conn_arg == (void *)-1);
@@ -1706,7 +1709,7 @@ TEST_CASE(ble_gap_test_case_stop_adv_hci_fail)
             ble_gap_test_util_stop_adv(BLE_ADDR_TYPE_PUBLIC, peer_addr, c, d,
                                        0, BLE_ERR_UNSUPPORTED);
             TEST_ASSERT(ble_gap_adv_active());
-            TEST_ASSERT(ble_gap_test_conn_event_type == -1);
+            TEST_ASSERT(ble_gap_test_event.type == 0xff);
             TEST_ASSERT(ble_gap_test_conn_status == -1);
             TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == (uint16_t)-1);
             TEST_ASSERT(ble_gap_test_conn_arg == (void *)-1);
@@ -1767,7 +1770,7 @@ ble_gap_test_util_update(struct ble_gap_upd_params *params,
 
     TEST_ASSERT(!ble_gap_master_in_progress());
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -1782,7 +1785,7 @@ ble_gap_test_util_update(struct ble_gap_upd_params *params,
     return;
 
 fail:
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == status);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -1814,7 +1817,7 @@ ble_gap_test_util_update_peer(uint8_t status,
 
     TEST_ASSERT(!ble_gap_master_in_progress());
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -1869,7 +1872,7 @@ ble_gap_test_util_update_req_pos(struct ble_gap_upd_params *peer_params,
     TEST_ASSERT(!ble_gap_master_in_progress());
     TEST_ASSERT(!ble_gap_test_util_update_in_progress(2));
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -1882,7 +1885,7 @@ ble_gap_test_util_update_req_pos(struct ble_gap_upd_params *peer_params,
     return;
 
 hci_fail:
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -1932,7 +1935,7 @@ ble_gap_test_util_update_req_neg(struct ble_gap_upd_params *peer_params,
     return;
 
 hci_fail:
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -2008,7 +2011,7 @@ ble_gap_test_util_update_req_concurrent(
     TEST_ASSERT(!ble_gap_master_in_progress());
     TEST_ASSERT(!ble_gap_test_util_update_in_progress(2));
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -2021,7 +2024,7 @@ ble_gap_test_util_update_req_concurrent(
     return;
 
 hci_fail:
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(fail_status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
     TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -2325,7 +2328,7 @@ ble_gap_test_util_conn_forever(void)
     /* Advance 100 seconds; ensure no timeout reported. */
     os_time_advance(100 * OS_TICKS_PER_SEC);
     ble_gap_heartbeat();
-    TEST_ASSERT(ble_gap_test_conn_event_type == -1);
+    TEST_ASSERT(ble_gap_test_event.type == 0xff);
     TEST_ASSERT(ble_gap_conn_active());
 }
 
@@ -2362,7 +2365,7 @@ ble_gap_test_util_conn_timeout(int32_t duration_ms)
                                     BLE_HCI_OCF_LE_CREATE_CONN_CANCEL),
         0);
 
-    TEST_ASSERT(ble_gap_test_conn_event_type == -1);
+    TEST_ASSERT(ble_gap_test_event.type == 0xff);
 
     ticks_from_now = ble_gap_heartbeat();
     TEST_ASSERT(ticks_from_now == BLE_HS_FOREVER);
@@ -2382,7 +2385,7 @@ ble_gap_test_util_conn_timeout(int32_t duration_ms)
     TEST_ASSERT_FATAL(rc == 0);
 
     /* Ensure the GAP event was triggered. */
-    TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONNECT);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_CONNECT);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_ETIMEOUT);
 
     /* Clear GAP event for remainder of test. */
@@ -2556,6 +2559,57 @@ TEST_SUITE(ble_gap_test_suite_timeout)
     ble_gap_test_case_conn_timeout_disc_timeout();
 }
 
+TEST_CASE(ble_gap_test_case_mtu_us)
+{
+    const uint8_t peer_addr[6] = { 1,2,3,4,5,6 };
+    int rc;
+
+    ble_gap_test_util_init();
+
+    ble_hs_test_util_create_conn(2, peer_addr, ble_gap_test_util_connect_cb,
+                                 NULL);
+
+    ble_att_set_preferred_mtu(200);
+
+    rc = ble_gattc_exchange_mtu(2, NULL, NULL);
+    TEST_ASSERT_FATAL(rc == 0);
+    ble_hs_test_util_verify_tx_mtu_cmd(1, 200);
+
+    ble_hs_test_util_rx_att_mtu_cmd(2, 0, 123);
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_MTU);
+    TEST_ASSERT(ble_gap_test_event.mtu.conn_handle == 2);
+    TEST_ASSERT(ble_gap_test_event.mtu.channel_id == BLE_L2CAP_CID_ATT);
+    TEST_ASSERT(ble_gap_test_event.mtu.value == 123);
+}
+
+TEST_CASE(ble_gap_test_case_mtu_peer)
+{
+    const uint8_t peer_addr[6] = { 1,2,3,4,5,6 };
+
+    ble_gap_test_util_init();
+
+    ble_hs_test_util_create_conn(2, peer_addr, ble_gap_test_util_connect_cb,
+                                 NULL);
+
+    ble_att_set_preferred_mtu(200);
+
+    ble_hs_test_util_rx_att_mtu_cmd(2, 1, 123);
+    ble_hs_test_util_verify_tx_mtu_cmd(0, 200);
+
+    TEST_ASSERT(ble_gap_test_event.type == BLE_GAP_EVENT_MTU);
+    TEST_ASSERT(ble_gap_test_event.mtu.conn_handle == 2);
+    TEST_ASSERT(ble_gap_test_event.mtu.channel_id == BLE_L2CAP_CID_ATT);
+    TEST_ASSERT(ble_gap_test_event.mtu.value == 123);
+}
+
+TEST_SUITE(ble_gap_test_suite_mtu)
+{
+    tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
+
+    ble_gap_test_case_mtu_us();
+    ble_gap_test_case_mtu_peer();
+}
+
 /*****************************************************************************
  * $all                                                                      *
  *****************************************************************************/
@@ -2573,6 +2627,7 @@ ble_gap_test_all(void)
     ble_gap_test_suite_stop_adv();
     ble_gap_test_suite_update_conn();
     ble_gap_test_suite_timeout();
+    ble_gap_test_suite_mtu();
 
     return tu_any_failed;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index b5148e3..0ced75a 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -407,7 +407,7 @@ ble_hs_test_util_create_rpa_conn(uint16_t handle, uint8_t own_addr_type,
 }
 
 void
-ble_hs_test_util_create_conn(uint16_t handle, uint8_t *peer_id_addr,
+ble_hs_test_util_create_conn(uint16_t handle, const uint8_t *peer_id_addr,
                              ble_gap_event_fn *cb, void *cb_arg)
 {
     static uint8_t null_addr[6];
@@ -897,6 +897,26 @@ ble_hs_test_util_l2cap_rx_payload_flat(uint16_t conn_handle, uint16_t cid,
 }
 
 void
+ble_hs_test_util_rx_att_mtu_cmd(uint16_t conn_handle, int is_req, uint16_t mtu)
+{
+    struct ble_att_mtu_cmd cmd;
+    uint8_t buf[BLE_ATT_MTU_CMD_SZ];
+    int rc;
+
+    cmd.bamc_mtu = mtu;
+
+    if (is_req) {
+        ble_att_mtu_req_write(buf, sizeof buf, &cmd);
+    } else {
+        ble_att_mtu_rsp_write(buf, sizeof buf, &cmd);
+    }
+
+    rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+                                                buf, sizeof buf);
+    TEST_ASSERT(rc == 0);
+}
+
+void
 ble_hs_test_util_rx_att_err_rsp(uint16_t conn_handle, uint8_t req_op,
                                 uint8_t error_code, uint16_t err_handle)
 {
@@ -1149,6 +1169,26 @@ ble_hs_test_util_verify_tx_write_rsp(void)
 }
 
 void
+ble_hs_test_util_verify_tx_mtu_cmd(int is_req, uint16_t mtu)
+{
+    struct ble_att_mtu_cmd cmd;
+    struct os_mbuf *om;
+
+    ble_hs_test_util_tx_all();
+
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    if (is_req) {
+        ble_att_mtu_req_parse(om->om_data, om->om_len, &cmd);
+    } else {
+        ble_att_mtu_rsp_parse(om->om_data, om->om_len, &cmd);
+    }
+
+    TEST_ASSERT(cmd.bamc_mtu == mtu);
+}
+
+void
 ble_hs_test_util_verify_tx_err_rsp(uint8_t req_op, uint16_t handle,
                                    uint8_t error_code)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3750fe0/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index fa3b5e0..7780d4e 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -75,7 +75,7 @@ void ble_hs_test_util_create_rpa_conn(uint16_t handle, uint8_t own_addr_type,
                                       const uint8_t *peer_id_addr,
                                       const uint8_t *peer_rpa,
                                       ble_gap_event_fn *cb, void *cb_arg);
-void ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
+void ble_hs_test_util_create_conn(uint16_t handle, const uint8_t *addr,
                                   ble_gap_event_fn *cb, void *cb_arg);
 int ble_hs_test_util_connect(uint8_t own_addr_type,
                                    uint8_t peer_addr_type,
@@ -125,6 +125,8 @@ int ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
 int ble_hs_test_util_l2cap_rx_payload_flat(uint16_t conn_handle, uint16_t cid,
                                            const void *data, int len);
 void ble_hs_test_util_rx_hci_buf_size_ack(uint16_t buf_size);
+void ble_hs_test_util_rx_att_mtu_cmd(uint16_t conn_handle, int is_req,
+                                     uint16_t mtu);
 void ble_hs_test_util_rx_att_err_rsp(uint16_t conn_handle, uint8_t req_op,
                                      uint8_t error_code, uint16_t err_handle);
 void ble_hs_test_util_set_startup_acks(void);
@@ -143,6 +145,7 @@ void ble_hs_test_util_verify_tx_read_rsp(uint8_t *attr_data, int attr_len);
 void ble_hs_test_util_verify_tx_read_blob_rsp(uint8_t *attr_data,
                                               int attr_len);
 void ble_hs_test_util_verify_tx_write_rsp(void);
+void ble_hs_test_util_verify_tx_mtu_cmd(int is_req, uint16_t mtu);
 void ble_hs_test_util_verify_tx_err_rsp(uint8_t req_op, uint16_t handle,
                                         uint8_t error_code);
 void ble_hs_test_util_set_static_rnd_addr(void);


[07/50] [abbrv] incubator-mynewt-core git commit: BLE apps - Handle GAP MTU event.

Posted by cc...@apache.org.
BLE apps - Handle GAP MTU event.


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

Branch: refs/heads/master
Commit: 63911e836ea1b3251e72f49e578d2921fc3baa84
Parents: 032d0a7
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 12 18:15:01 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Aug 12 18:16:35 2016 -0700

----------------------------------------------------------------------
 apps/blecent/src/main.c | 7 +++++++
 apps/bleprph/src/main.c | 7 +++++++
 apps/bletiny/src/main.c | 7 +++++++
 apps/bleuart/src/main.c | 1 -
 4 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63911e83/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index 384338a..7056cc6 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -446,6 +446,13 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
         /* Attribute data is contained in event->notify_rx.attr_data. */
         return 0;
 
+    case BLE_GAP_EVENT_MTU:
+        BLECENT_LOG(INFO, "mtu update event; conn_handle=%d cid=%d mtu=%d\n",
+                    event->mtu.conn_handle,
+                    event->mtu.channel_id,
+                    event->mtu.value);
+        return 0;
+
     default:
         return 0;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63911e83/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index b08b077..0233bc1 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -265,6 +265,13 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
                     event->subscribe.prev_indicate,
                     event->subscribe.cur_indicate);
         return 0;
+
+    case BLE_GAP_EVENT_MTU:
+        BLEPRPH_LOG(INFO, "mtu update event; conn_handle=%d cid=%d mtu=%d\n",
+                    event->mtu.conn_handle,
+                    event->mtu.channel_id,
+                    event->mtu.value);
+        return 0;
     }
 
     return 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63911e83/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 469944c..d06fa0a 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1031,6 +1031,13 @@ bletiny_gap_event(struct ble_gap_event *event, void *arg)
                        event->subscribe.cur_indicate);
         return 0;
 
+    case BLE_GAP_EVENT_MTU:
+        console_printf("mtu update event; conn_handle=%d cid=%d mtu=%d\n",
+                       event->mtu.conn_handle,
+                       event->mtu.channel_id,
+                       event->mtu.value);
+        return 0;
+
     default:
         return 0;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/63911e83/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index 264be92..8ff7d82 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -193,7 +193,6 @@ bleuart_gap_event(struct ble_gap_event *event, void *arg)
         /* Connection terminated; resume advertising. */
         bleuart_advertise();
         return 0;
-
     }
 
     return 0;


[08/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Only log ATT cmd after tx succeeds.

Posted by cc...@apache.org.
BLE Host - Only log ATT cmd after tx succeeds.

Before, we were logging each ATT transmission as soon as a higher layer
requested the send.

Now:

* For client requests, don't log until after transmit succeeds.

* For server responses, don't log until we are sure we will attempt a
transmission.  Unfortunately, due to the way the server code is
structures, we don't have the necessary information for logging after
the transmit occurs.  This is still an improvement, as it prevents
spurious logging when there are invalid arguments or insufficient
resources.


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

Branch: refs/heads/master
Commit: 032d0a791af19899312dd9fe8a1053a81b69cf92
Parents: e3750fe
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 12 18:10:39 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Aug 12 18:16:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 76 +++++++++++++++++++---------------
 net/nimble/host/src/ble_att_svr.c | 10 +++--
 2 files changed, 48 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/032d0a79/net/nimble/host/src/ble_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c
index 735e819..2e7352b 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -118,8 +118,6 @@ ble_att_clt_tx_mtu(uint16_t conn_handle, const struct ble_att_mtu_cmd *req)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_ATT_LOG_CMD(1, "mtu req", conn_handle, ble_att_mtu_cmd_log, req);
-
     if (req->bamc_mtu < BLE_ATT_MTU_DFLT) {
         return BLE_HS_EINVAL;
     }
@@ -151,6 +149,8 @@ ble_att_clt_tx_mtu(uint16_t conn_handle, const struct ble_att_mtu_cmd *req)
         return rc;
     }
 
+    BLE_ATT_LOG_CMD(1, "mtu req", conn_handle, ble_att_mtu_cmd_log, req);
+
     ble_hs_lock();
 
     ble_att_conn_chan_find(conn_handle, &conn, &chan);
@@ -206,9 +206,6 @@ ble_att_clt_tx_find_info(uint16_t conn_handle,
     struct os_mbuf *txom;
     int rc;
 
-    BLE_ATT_LOG_CMD(1, "find info req", conn_handle,
-                    ble_att_find_info_req_log, req);
-
     if (req->bafq_start_handle == 0 ||
         req->bafq_start_handle > req->bafq_end_handle) {
 
@@ -226,6 +223,9 @@ ble_att_clt_tx_find_info(uint16_t conn_handle,
         return rc;
     }
 
+    BLE_ATT_LOG_CMD(1, "find info req", conn_handle,
+                    ble_att_find_info_req_log, req);
+
     return 0;
 }
 
@@ -336,9 +336,6 @@ ble_att_clt_tx_find_type_value(uint16_t conn_handle,
     return BLE_HS_ENOTSUP;
 #endif
 
-    BLE_ATT_LOG_CMD(1, "find type value req", conn_handle,
-                    ble_att_find_type_value_req_log, req);
-
     struct os_mbuf *txom;
     int rc;
 
@@ -369,6 +366,9 @@ ble_att_clt_tx_find_type_value(uint16_t conn_handle,
         goto err;
     }
 
+    BLE_ATT_LOG_CMD(1, "find type value req", conn_handle,
+                    ble_att_find_type_value_req_log, req);
+
     return 0;
 
 err:
@@ -447,9 +447,6 @@ ble_att_clt_tx_read_type(uint16_t conn_handle,
 
     txom = NULL;
 
-    BLE_ATT_LOG_CMD(1, "read type req", conn_handle,
-                    ble_att_read_type_req_log, req);
-
     if (req->batq_start_handle == 0 ||
         req->batq_start_handle > req->batq_end_handle) {
 
@@ -475,6 +472,9 @@ ble_att_clt_tx_read_type(uint16_t conn_handle,
         goto err;
     }
 
+    BLE_ATT_LOG_CMD(1, "read type req", conn_handle,
+                    ble_att_read_type_req_log, req);
+
     return 0;
 
 err:
@@ -555,8 +555,6 @@ ble_att_clt_tx_read(uint16_t conn_handle, const struct ble_att_read_req *req)
     struct os_mbuf *txom;
     int rc;
 
-    BLE_ATT_LOG_CMD(1, "read req", conn_handle, ble_att_read_req_log, req);
-
     if (req->barq_handle == 0) {
         return BLE_HS_EINVAL;
     }
@@ -572,6 +570,8 @@ ble_att_clt_tx_read(uint16_t conn_handle, const struct ble_att_read_req *req)
         return rc;
     }
 
+    BLE_ATT_LOG_CMD(1, "read req", conn_handle, ble_att_read_req_log, req);
+
     return 0;
 }
 
@@ -609,9 +609,6 @@ ble_att_clt_tx_read_blob(uint16_t conn_handle,
     struct os_mbuf *txom;
     int rc;
 
-    BLE_ATT_LOG_CMD(1, "read blob req", conn_handle,
-                    ble_att_read_blob_req_log, req);
-
     if (req->babq_handle == 0) {
         return BLE_HS_EINVAL;
     }
@@ -627,6 +624,9 @@ ble_att_clt_tx_read_blob(uint16_t conn_handle,
         return rc;
     }
 
+    BLE_ATT_LOG_CMD(1, "read blob req", conn_handle,
+                    ble_att_read_blob_req_log, req);
+
     return 0;
 }
 
@@ -756,9 +756,6 @@ ble_att_clt_tx_read_group_type(uint16_t conn_handle,
 
     txom = NULL;
 
-    BLE_ATT_LOG_CMD(1, "read group type req", conn_handle,
-                    ble_att_read_group_type_req_log, req);
-
     if (req->bagq_start_handle == 0 ||
         req->bagq_start_handle > req->bagq_end_handle) {
 
@@ -783,6 +780,9 @@ ble_att_clt_tx_read_group_type(uint16_t conn_handle,
         goto err;
     }
 
+    BLE_ATT_LOG_CMD(1, "read group type req", conn_handle,
+                    ble_att_read_group_type_req_log, req);
+
     return 0;
 
 err:
@@ -896,10 +896,14 @@ ble_att_clt_tx_write_req(uint16_t conn_handle,
 
     int rc;
 
+    rc = ble_att_clt_tx_write_req_or_cmd(conn_handle, req, txom, 1);
+    if (rc != 0) {
+        return rc;
+    }
+
     BLE_ATT_LOG_CMD(1, "write req", conn_handle, ble_att_write_cmd_log, req);
 
-    rc = ble_att_clt_tx_write_req_or_cmd(conn_handle, req, txom, 1);
-    return rc;
+    return 0;
 }
 
 int
@@ -913,10 +917,14 @@ ble_att_clt_tx_write_cmd(uint16_t conn_handle,
 
     int rc;
 
+    rc = ble_att_clt_tx_write_req_or_cmd(conn_handle, req, txom, 0);
+    if (rc != 0) {
+        return rc;
+    }
+
     BLE_ATT_LOG_CMD(1, "write cmd", conn_handle, ble_att_write_cmd_log, req);
 
-    rc = ble_att_clt_tx_write_req_or_cmd(conn_handle, req, txom, 0);
-    return rc;
+    return 0;
 }
 
 int
@@ -948,9 +956,6 @@ ble_att_clt_tx_prep_write(uint16_t conn_handle,
 
     int rc;
 
-    BLE_ATT_LOG_CMD(1, "prep write req", conn_handle,
-                    ble_att_prep_write_cmd_log, req);
-
     if (req->bapc_handle == 0) {
         rc = BLE_HS_EINVAL;
         goto err;
@@ -983,6 +988,9 @@ ble_att_clt_tx_prep_write(uint16_t conn_handle,
         goto err;
     }
 
+    BLE_ATT_LOG_CMD(1, "prep write req", conn_handle,
+                    ble_att_prep_write_cmd_log, req);
+
     return 0;
 
 err:
@@ -1036,9 +1044,6 @@ ble_att_clt_tx_exec_write(uint16_t conn_handle,
     struct os_mbuf *txom;
     int rc;
 
-    BLE_ATT_LOG_CMD(1, "exec write req", conn_handle,
-                    ble_att_exec_write_req_log, req);
-
     if ((req->baeq_flags & BLE_ATT_EXEC_WRITE_F_RESERVED) != 0) {
         return BLE_HS_EINVAL;
     }
@@ -1054,6 +1059,9 @@ ble_att_clt_tx_exec_write(uint16_t conn_handle,
         return rc;
     }
 
+    BLE_ATT_LOG_CMD(1, "exec write req", conn_handle,
+                    ble_att_exec_write_req_log, req);
+
     return 0;
 }
 
@@ -1092,8 +1100,6 @@ ble_att_clt_tx_notify(uint16_t conn_handle,
 
     int rc;
 
-    BLE_ATT_LOG_CMD(1, "notify req", conn_handle, ble_att_notify_req_log, req);
-
     if (req->banq_handle == 0) {
         rc = BLE_HS_EINVAL;
         goto err;
@@ -1112,6 +1118,8 @@ ble_att_clt_tx_notify(uint16_t conn_handle,
         goto err;
     }
 
+    BLE_ATT_LOG_CMD(1, "notify req", conn_handle, ble_att_notify_req_log, req);
+
     return 0;
 
 err:
@@ -1134,9 +1142,6 @@ ble_att_clt_tx_indicate(uint16_t conn_handle,
 
     int rc;
 
-    BLE_ATT_LOG_CMD(1, "indicate req", conn_handle, ble_att_indicate_req_log,
-                    req);
-
     if (req->baiq_handle == 0) {
         rc = BLE_HS_EINVAL;
         goto err;
@@ -1157,6 +1162,9 @@ ble_att_clt_tx_indicate(uint16_t conn_handle,
         goto err;
     }
 
+    BLE_ATT_LOG_CMD(1, "indicate req", conn_handle, ble_att_indicate_req_log,
+                    req);
+
     return 0;
 
 err:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/032d0a79/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 710db20..5d64c25 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -510,8 +510,6 @@ ble_att_svr_tx_error_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
     rsp.baep_error_code = error_code;
 
     ble_att_error_rsp_write(dst, BLE_ATT_ERROR_RSP_SZ, &rsp);
-    BLE_ATT_LOG_CMD(1, "error rsp", conn->bhc_handle,
-                    ble_att_error_rsp_log, &rsp);
 
     rc = ble_l2cap_tx(conn, chan, txom);
     txom = NULL;
@@ -519,6 +517,9 @@ ble_att_svr_tx_error_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
         goto err;
     }
 
+    BLE_ATT_LOG_CMD(1, "error rsp", conn->bhc_handle,
+                    ble_att_error_rsp_log, &rsp);
+
     return 0;
 
 err:
@@ -829,8 +830,6 @@ ble_att_svr_build_find_info_rsp(uint16_t conn_handle,
     }
 
     ble_att_find_info_rsp_write(buf, BLE_ATT_FIND_INFO_RSP_BASE_SZ, &rsp);
-    BLE_ATT_LOG_CMD(1, "find info rsp", conn_handle, ble_att_find_info_rsp_log,
-                    &rsp);
 
     /* Write the variable length Information Data field, populating the format
      * field as appropriate.
@@ -842,6 +841,9 @@ ble_att_svr_build_find_info_rsp(uint16_t conn_handle,
         goto done;
     }
 
+    BLE_ATT_LOG_CMD(1, "find info rsp", conn_handle, ble_att_find_info_rsp_log,
+                    &rsp);
+
     rc = 0;
 
 done:


[25/50] [abbrv] incubator-mynewt-core git commit: This closes #86.

Posted by cc...@apache.org.
This closes #86.

Merge branch 'fix/nmgr-config' of https://github.com/simonratner/incubator-mynewt-core into develop


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

Branch: refs/heads/master
Commit: 5de9a7263153f357dcf65378ebf93ab4f55683a9
Parents: c0f685b 785dd5d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Aug 18 10:39:44 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 10:39:44 2016 -0700

----------------------------------------------------------------------
 sys/config/src/config_nmgr.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
----------------------------------------------------------------------



[45/50] [abbrv] incubator-mynewt-core git commit: This closes #96.

Posted by cc...@apache.org.
This closes #96.

Merge remote-tracking branch 'bgiori/newtmgr-id-bug' into develop

* bgiori/newtmgr-id-bug:
  Fixed bug where ID was always wrong in response


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

Branch: refs/heads/master
Commit: 4751ae0d8f5aefa2a2ae9e8d41652c08a7538ca0
Parents: d49726b fcda6e7
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Aug 22 12:52:37 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Aug 22 12:52:37 2016 -0700

----------------------------------------------------------------------
 libs/newtmgr/src/newtmgr.c | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------



[10/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Don't allow >1 tx MTU request per conn.

Posted by cc...@apache.org.
BLE Host - Don't allow >1 tx MTU request per conn.


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

Branch: refs/heads/master
Commit: 277edafa0cdf40067cfffc4596a5bb65d4645986
Parents: 30d5d15
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 12 17:46:39 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Aug 12 18:16:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/277edafa/net/nimble/host/src/ble_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c
index ed36b7f..8170c6c 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -124,6 +124,22 @@ ble_att_clt_tx_mtu(uint16_t conn_handle, const struct ble_att_mtu_cmd *req)
         return BLE_HS_EINVAL;
     }
 
+    ble_hs_lock();
+
+    ble_att_conn_chan_find(conn_handle, &conn, &chan);
+    if (chan == NULL) {
+        rc = BLE_HS_ENOTCONN;
+    } else if (chan->blc_flags & BLE_L2CAP_CHAN_F_TXED_MTU) {
+        rc = BLE_HS_EALREADY;
+    } else {
+        rc = 0;
+    }
+    ble_hs_unlock();
+
+    if (rc != 0) {
+        return rc;
+    }
+
     rc = ble_att_clt_init_req(BLE_ATT_MTU_CMD_SZ, &txom);
     if (rc != 0) {
         return rc;


[33/50] [abbrv] incubator-mynewt-core git commit: bootutil; adjust unit tests to work with status upkeep outside sys/config.

Posted by cc...@apache.org.
bootutil; adjust unit tests to work with status upkeep outside sys/config.


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

Branch: refs/heads/master
Commit: 41814394c87063955be04d33e5f0308c03d7dfd6
Parents: ce4f190
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Aug 19 14:53:14 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:50 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/src/test/boot_test.c | 203 +++++++++++++++++++-------------
 1 file changed, 120 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/41814394/libs/bootutil/src/test/boot_test.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/test/boot_test.c b/libs/bootutil/src/test/boot_test.c
index e78d2e4..459e424 100644
--- a/libs/bootutil/src/test/boot_test.c
+++ b/libs/bootutil/src/test/boot_test.c
@@ -342,7 +342,9 @@ boot_test_util_verify_area(const struct flash_area *area_desc,
                 TEST_ASSERT(buf[i] == boot_test_util_byte_at(img_msb,
                                                         img_off + i));
             } else if (past_image) {
+#if 0
                 TEST_ASSERT(buf[i] == 0xff);
+#endif
             }
         }
 
@@ -353,45 +355,18 @@ boot_test_util_verify_area(const struct flash_area *area_desc,
 static void
 boot_test_util_verify_status_clear(void)
 {
-    struct fs_file *file;
+    struct boot_img_trailer bit;
+    const struct flash_area *fap;
     int rc;
-    int empty = 1;
-    char *needle = "boot/status=";
-    int nlen = strlen(needle);
-    uint32_t len, hlen;
-    char *haystack, *ptr;
-
-    rc = fs_open(MY_CONF_PATH, FS_ACCESS_READ, &file);
-    if (rc != 0) {
-        return;
-    }
-    rc = fs_filelen(file, &len);
-    TEST_ASSERT(rc == 0);
 
-    haystack = malloc(len + 1);
-    TEST_ASSERT(haystack);
-
-    rc = fs_read(file, len, haystack, &hlen);
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
     TEST_ASSERT(rc == 0);
-    TEST_ASSERT(hlen == len);
-    haystack[len] = '\0';
-
-    fs_close(file);
 
-    ptr = haystack;
-    while ((ptr = strstr(ptr, needle))) {
-        if (ptr[nlen] == '\n') {
-            empty = 1;
-        } else {
-            empty = 0;
-        }
-        ptr += nlen;
-    }
-    TEST_ASSERT(empty == 1);
-    free(haystack);
+    rc = flash_area_read(fap, fap->fa_size - sizeof(bit), &bit, sizeof(bit));
+    TEST_ASSERT(rc == 0);
 
-    rc = fs_open(BOOT_PATH_STATUS, FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == FS_ENOENT);
+    TEST_ASSERT(bit.bit_copy_start != BOOT_IMG_MAGIC ||
+      bit.bit_copy_done != 0xff);
 }
 
 static void
@@ -436,7 +411,6 @@ TEST_CASE(boot_test_setup)
     rc = conf_file_dst(&my_conf);
     assert(rc == 0);
 
-    bootutil_cfg_register();
 }
 
 TEST_CASE(boot_test_nv_ns_10)
@@ -458,6 +432,7 @@ TEST_CASE(boot_test_nv_ns_10)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
@@ -495,12 +470,14 @@ TEST_CASE(boot_test_nv_ns_01)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
     boot_test_util_write_image(&hdr, 1);
     boot_test_util_write_hash(&hdr, 1);
 
+    boot_vect_write_test(FLASH_AREA_IMAGE_1);
     rc = boot_go(&req, &rsp);
     TEST_ASSERT(rc == 0);
 
@@ -540,6 +517,7 @@ TEST_CASE(boot_test_nv_ns_11)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
@@ -579,15 +557,13 @@ TEST_CASE(boot_test_vm_ns_10)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
     boot_test_util_write_image(&hdr, 0);
     boot_test_util_write_hash(&hdr, 0);
 
-    rc = boot_vect_write_main(&hdr.ih_ver);
-    TEST_ASSERT(rc == 0);
-
     rc = boot_go(&req, &rsp);
     TEST_ASSERT(rc == 0);
 
@@ -618,13 +594,14 @@ TEST_CASE(boot_test_vm_ns_01)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
     boot_test_util_write_image(&hdr, 1);
     boot_test_util_write_hash(&hdr, 1);
 
-    rc = boot_vect_write_main(&hdr.ih_ver);
+    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
     TEST_ASSERT(rc == 0);
 
     rc = boot_go(&req, &rsp);
@@ -666,6 +643,7 @@ TEST_CASE(boot_test_vm_ns_11_a)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
@@ -674,9 +652,6 @@ TEST_CASE(boot_test_vm_ns_11_a)
     boot_test_util_write_image(&hdr1, 1);
     boot_test_util_write_hash(&hdr1, 1);
 
-    rc = boot_vect_write_main(&hdr0.ih_ver);
-    TEST_ASSERT(rc == 0);
-
     rc = boot_go(&req, &rsp);
     TEST_ASSERT(rc == 0);
 
@@ -716,6 +691,7 @@ TEST_CASE(boot_test_vm_ns_11_b)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
@@ -724,7 +700,7 @@ TEST_CASE(boot_test_vm_ns_11_b)
     boot_test_util_write_image(&hdr1, 1);
     boot_test_util_write_hash(&hdr1, 1);
 
-    rc = boot_vect_write_main(&hdr1.ih_ver);
+    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
     TEST_ASSERT(rc == 0);
 
     rc = boot_go(&req, &rsp);
@@ -766,6 +742,7 @@ TEST_CASE(boot_test_vm_ns_11_2areas)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
@@ -774,7 +751,7 @@ TEST_CASE(boot_test_vm_ns_11_2areas)
     boot_test_util_write_image(&hdr1, 1);
     boot_test_util_write_hash(&hdr1, 1);
 
-    rc = boot_vect_write_main(&hdr1.ih_ver);
+    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
     TEST_ASSERT(rc == 0);
 
     rc = boot_go(&req, &rsp);
@@ -808,6 +785,7 @@ TEST_CASE(boot_test_nv_bs_10)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
@@ -815,14 +793,16 @@ TEST_CASE(boot_test_nv_bs_10)
     boot_test_util_write_hash(&hdr, 0);
     boot_test_util_swap_areas(boot_test_slot_areas[1],
       BOOT_TEST_AREA_IDX_SCRATCH);
-
+#if 0
     status.length = hdr.ih_hdr_size + hdr.ih_img_size + hdr.ih_tlv_size;
     status.state = 1;
 
     rc = boot_write_status(&status);
     TEST_ASSERT(rc == 0);
     conf_load();
-
+#else
+    (void)status;
+#endif
     rc = boot_go(&req, &rsp);
     TEST_ASSERT(rc == 0);
 
@@ -838,7 +818,6 @@ TEST_CASE(boot_test_nv_bs_11)
 {
     struct boot_status status;
     struct boot_rsp rsp;
-    int len;
     int rc;
 
     struct image_header hdr0 = {
@@ -864,6 +843,7 @@ TEST_CASE(boot_test_nv_bs_11)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
@@ -871,14 +851,13 @@ TEST_CASE(boot_test_nv_bs_11)
     boot_test_util_write_hash(&hdr0, 0);
     boot_test_util_write_image(&hdr1, 1);
     boot_test_util_write_hash(&hdr1, 1);
-    boot_test_util_copy_area(boot_test_slot_areas[1],
+    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
+    boot_test_util_copy_area(5,
       BOOT_TEST_AREA_IDX_SCRATCH);
 
-    status.length = hdr0.ih_hdr_size + hdr0.ih_img_size + hdr0.ih_tlv_size;
-    len = hdr1.ih_hdr_size + hdr1.ih_img_size + hdr1.ih_tlv_size;
-    if (len > status.length) {
-        status.length = len;
-    }
+    boot_req_set(&req);
+    status.idx = 0;
+    status.elem_sz = 1;
     status.state = 1;
 
     rc = boot_write_status(&status);
@@ -900,7 +879,6 @@ TEST_CASE(boot_test_nv_bs_11_2areas)
     struct boot_status status;
     struct boot_rsp rsp;
     int rc;
-    int len;
 
     struct image_header hdr0 = {
         .ih_magic = IMAGE_MAGIC,
@@ -925,6 +903,7 @@ TEST_CASE(boot_test_nv_bs_11_2areas)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
@@ -932,15 +911,13 @@ TEST_CASE(boot_test_nv_bs_11_2areas)
     boot_test_util_write_hash(&hdr0, 0);
     boot_test_util_write_image(&hdr1, 1);
     boot_test_util_write_hash(&hdr1, 1);
-    boot_test_util_swap_areas(boot_test_slot_areas[0],
-      boot_test_slot_areas[1]);
+    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
 
-    status.length = hdr0.ih_hdr_size + hdr0.ih_img_size + hdr0.ih_tlv_size;
-    len = hdr1.ih_hdr_size + hdr1.ih_img_size + hdr1.ih_tlv_size;
-    if (len > status.length) {
-        status.length = len;
-    }
-    status.state = 1 << 8;
+    boot_test_util_swap_areas(2, 5);
+
+    status.idx = 1;
+    status.elem_sz = 1;
+    status.state = 0;
 
     rc = boot_write_status(&status);
     TEST_ASSERT(rc == 0);
@@ -958,6 +935,8 @@ TEST_CASE(boot_test_nv_bs_11_2areas)
 
 TEST_CASE(boot_test_vb_ns_11)
 {
+    const struct flash_area *fap;
+    struct boot_img_trailer bit;
     struct boot_rsp rsp;
     int rc;
     int i;
@@ -985,18 +964,27 @@ TEST_CASE(boot_test_vb_ns_11)
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
     boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
     boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
     boot_test_util_write_hash(&hdr1, 1);
 
-    rc = boot_vect_write_main(&hdr0.ih_ver);
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    TEST_ASSERT(rc == 0);
+
+    memset(&bit, 0xff, sizeof(bit));
+    bit.bit_copy_start = BOOT_IMG_MAGIC;
+    bit.bit_copy_done = 0;
+    bit.bit_img_ok = 1;
+
+    rc = flash_area_write(fap, fap->fa_size - sizeof(bit), &bit, sizeof(bit));
     TEST_ASSERT(rc == 0);
 
-    rc = boot_vect_write_test(&hdr1.ih_ver);
+    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
     TEST_ASSERT(rc == 0);
 
     /* First boot should use the test image. */
@@ -1021,6 +1009,7 @@ TEST_CASE(boot_test_vb_ns_11)
 
         boot_test_util_verify_flash(&hdr0, 0, &hdr1, 1);
         boot_test_util_verify_status_clear();
+        boot_vect_write_main();
     }
 }
 
@@ -1029,29 +1018,45 @@ TEST_CASE(boot_test_no_hash)
     struct boot_rsp rsp;
     int rc;
 
-    struct image_header hdr = {
+    struct image_header hdr0 = {
         .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 0,
+        .ih_tlv_size = 4 + 32,
         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
         .ih_img_size = 12 * 1024,
-        .ih_flags = 0,
+        .ih_flags = IMAGE_F_SHA256,
         .ih_ver = { 0, 2, 3, 4 },
     };
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 0,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = 0,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
 
     struct boot_req req = {
         .br_area_descs = boot_test_area_descs,
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr, 0);
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+
+    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
+    TEST_ASSERT(rc == 0);
 
     rc = boot_go(&req, &rsp);
-    TEST_ASSERT(rc != 0);
+    TEST_ASSERT(rc == 0);
 
-    boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr0, sizeof hdr0) == 0);
+
+    boot_test_util_verify_flash(&hdr0, 0, NULL, 0xff);
     boot_test_util_verify_status_clear();
 }
 
@@ -1060,30 +1065,46 @@ TEST_CASE(boot_test_no_flag_has_hash)
     struct boot_rsp rsp;
     int rc;
 
-    struct image_header hdr = {
+    struct image_header hdr0 = {
         .ih_magic = IMAGE_MAGIC,
         .ih_tlv_size = 4 + 32,
         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
         .ih_img_size = 12 * 1024,
-        .ih_flags = 0,
+        .ih_flags = IMAGE_F_SHA256,
         .ih_ver = { 0, 2, 3, 4 },
     };
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = 0,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
 
     struct boot_req req = {
         .br_area_descs = boot_test_area_descs,
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr, 0);
-    boot_test_util_write_hash(&hdr, 0);
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
+    TEST_ASSERT(rc == 0);
 
     rc = boot_go(&req, &rsp);
-    TEST_ASSERT(rc != 0);
+    TEST_ASSERT(rc == 0);
 
-    boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr0, sizeof hdr0) == 0);
+
+    boot_test_util_verify_flash(&hdr0, 0, NULL, 0xff);
     boot_test_util_verify_status_clear();
 }
 
@@ -1092,7 +1113,7 @@ TEST_CASE(boot_test_invalid_hash)
     struct boot_rsp rsp;
     int rc;
 
-    struct image_header hdr = {
+    struct image_header hdr0 = {
         .ih_magic = IMAGE_MAGIC,
         .ih_tlv_size = 4 + 32,
         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
@@ -1100,12 +1121,21 @@ TEST_CASE(boot_test_invalid_hash)
         .ih_flags = IMAGE_F_SHA256,
         .ih_ver = { 0, 2, 3, 4 },
     };
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = 0,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
 
     struct boot_req req = {
         .br_area_descs = boot_test_area_descs,
         .br_slot_areas = boot_test_slot_areas,
         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
     };
 
     struct image_tlv tlv = {
@@ -1113,16 +1143,23 @@ TEST_CASE(boot_test_invalid_hash)
         .it_len = 32
     };
     boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr, 0);
-    rc = hal_flash_write(boot_test_img_addrs[0].flash_id,
-      boot_test_img_addrs[0].address + hdr.ih_hdr_size + hdr.ih_img_size,
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    rc = hal_flash_write(boot_test_img_addrs[1].flash_id,
+      boot_test_img_addrs[1].address + hdr1.ih_hdr_size + hdr1.ih_img_size,
       &tlv, sizeof(tlv));
     TEST_ASSERT(rc == 0);
 
+    rc = boot_vect_write_test(FLASH_AREA_IMAGE_1);
+    TEST_ASSERT(rc == 0);
+
     rc = boot_go(&req, &rsp);
-    TEST_ASSERT(rc != 0);
+    TEST_ASSERT(rc == 0);
 
-    boot_test_util_verify_flash(&hdr, 0, NULL, 0xff);
+    TEST_ASSERT(memcmp(rsp.br_hdr, &hdr0, sizeof hdr0) == 0);
+
+    boot_test_util_verify_flash(&hdr0, 0, NULL, 0xff);
     boot_test_util_verify_status_clear();
 }
 


[23/50] [abbrv] incubator-mynewt-core git commit: basic os_callout

Posted by cc...@apache.org.
basic os_callout


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

Branch: refs/heads/master
Commit: bc4c0a83f752e0b2113f8fb1ed001ec45ddc7c5c
Parents: 40c072e
Author: NgesBrian <ng...@gmail.com>
Authored: Wed Jul 20 01:17:41 2016 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 09:20:59 2016 -0700

----------------------------------------------------------------------
 libs/os/src/test/callout_test.c | 82 ++++++++++++++++++++++++++++++++++++
 libs/os/src/test/os_test.c      |  2 +-
 libs/os/src/test/os_test_priv.h |  2 +-
 3 files changed, 84 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc4c0a83/libs/os/src/test/callout_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/callout_test.c b/libs/os/src/test/callout_test.c
new file mode 100644
index 0000000..034c2f4
--- /dev/null
+++ b/libs/os/src/test/callout_test.c
@@ -0,0 +1,82 @@
+/**
+ * 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 "testutil/testutil.h"
+#include "os/os.h"
+#include "os_test_priv.h"
+#include "os/os_eventq.h"
+#include "os/os_callout.h"
+
+/* Task 1 for sending */
+#define CALLOUT_STACK_SIZE        (5120)
+#define SEND_CALLOUT_TASK_PRIO        (1)
+struct os_task callout_task_struct_send;
+os_stack_t callout_task_stack_send[CALLOUT_STACK_SIZE];
+
+/* Initializing the callout 
+struct os_event callout_event;
+struct os_eventq callout_eventq;
+struct os_eventq callout_eventq_delivered;
+struct os_callout struct_callout;
+*/
+
+/* Delearing variables for callout_func */
+struct os_callout_func callout_func;
+struct os_eventq callout_eventq;
+void native_cputimer_cb(void *arg);
+
+/* This is a callout task to send data */
+void
+callout_task_send()
+{
+    int i;
+    /*
+    struct_callout.c_ev = callout_event;
+    struct_callout.c_evq = &callout_eventq;
+    struct_callout.c_ticks = OS_TICKS_PER_SEC / 20;
+    */
+    /* Initialize the callout
+    os_callout_init(&struct_callout, &callout_eventq_delivered, NULL);
+    */
+
+    /* Initialize the callout function */
+    os_callout_func_init(&callout_func, &callout_eventq,
+        native_cputimer_cb, NULL);
+    i = os_callout_queued((struct os_callout )callout_func);
+    TEST_ASSERT(i == 0);
+}
+
+TEST_CASE(callout_test){
+
+    /* Initializing the OS */
+    os_init();
+    
+    /* Initialize the sending task */
+    os_task_init(&callout_task_struct_send, "callout_task_send",
+        callout_task_send, NULL, SEND_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_send, CALLOUT_STACK_SIZE);
+
+    /* Does not return until OS_restart is called */
+    os_start();
+
+}
+
+TEST_SUITE(os_callout_test_suite){   
+    callout_test();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc4c0a83/libs/os/src/test/os_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/os_test.c b/libs/os/src/test/os_test.c
index 1b3af1a..48f0720 100644
--- a/libs/os/src/test/os_test.c
+++ b/libs/os/src/test/os_test.c
@@ -31,7 +31,7 @@ os_test_all(void)
     os_sem_test_suite();
     os_mbuf_test_suite();
     os_eventq_test_suite();
-    
+    os_callout_test_suite();
 
     return tu_case_failed;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc4c0a83/libs/os/src/test/os_test_priv.h
----------------------------------------------------------------------
diff --git a/libs/os/src/test/os_test_priv.h b/libs/os/src/test/os_test_priv.h
index 5193c33..e923a6f 100644
--- a/libs/os/src/test/os_test_priv.h
+++ b/libs/os/src/test/os_test_priv.h
@@ -27,6 +27,6 @@ int os_mbuf_test_suite(void);
 int os_mutex_test_suite(void);
 int os_sem_test_suite(void);
 int os_eventq_test_suite(void);
-
+int os_callout_test_suite(void);
 
 #endif


[30/50] [abbrv] incubator-mynewt-core git commit: boot; return full flash location of status bytes, instead of just offset.

Posted by cc...@apache.org.
boot; return full flash location of status bytes, instead of just offset.


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

Branch: refs/heads/master
Commit: 52a8e9f9876078a64b76657d19754f34835f6036
Parents: b2009c9
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Aug 17 09:53:24 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:49 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/src/loader.c | 87 +++++++++++++++++++++++------------------
 1 file changed, 49 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/52a8e9f9/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index f8a0003..65d0fc8 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -36,7 +36,7 @@
 /** The request object provided by the client. */
 static const struct boot_req *boot_req;
 
-/** Image headers read from flash. */
+/** Info about image slots. */
 static struct boot_img {
     struct image_header hdr;
     struct boot_image_location loc;
@@ -52,8 +52,8 @@ static uint32_t boot_copy_sz(int max_idx, int *cnt);
  * Calculates the flash offset of the specified image slot.
  *
  * @param slot_num              The number of the slot to calculate.
+ * @param loc                   The flash location of the slot.
  *
- * @return                      The flash offset of the image slot.
  */
 static void
 boot_slot_addr(int slot_num, struct boot_image_location *loc)
@@ -67,50 +67,53 @@ boot_slot_addr(int slot_num, struct boot_image_location *loc)
     loc->bil_address = area_desc->fa_off;
 }
 
-static uint32_t
-boot_magic_off(int slot_num)
+static void
+boot_magic_loc(int slot_num, uint8_t *flash_id, uint32_t *off)
 {
-    return boot_img[slot_num].area + boot_img[slot_num].loc.bil_address -
-      sizeof(struct boot_img_trailer);
+    struct boot_img *b;
+
+    b = &boot_img[slot_num];
+    *flash_id = b->loc.bil_flash_id;
+    *off = b->area + b->loc.bil_address - sizeof(struct boot_img_trailer);
 }
 
-static uint32_t
-boot_scratch_off(void)
+static void
+boot_scratch_loc(uint8_t *flash_id, uint32_t *off)
 {
     struct flash_area *scratch;
-    uint32_t off;
     int cnt;
 
     scratch = &boot_req->br_area_descs[boot_req->br_scratch_area_idx];
-    off = boot_copy_sz(boot_req->br_slot_areas[1], &cnt);
-    off += (scratch->fa_off - sizeof(struct boot_img_trailer));
-    return off;
+    *flash_id = scratch->fa_flash_id;
+    *off = boot_copy_sz(boot_req->br_slot_areas[1], &cnt);
+    *off += (scratch->fa_off - sizeof(struct boot_img_trailer));
 }
 
 static void
 boot_slot_magic(int slot_num, struct boot_img_trailer *bit)
 {
     uint32_t off;
-    struct boot_img *b;
+    uint8_t flash_id;
 
-    b = &boot_img[slot_num];
-    off = boot_magic_off(slot_num);
+    boot_magic_loc(slot_num, &flash_id, &off);
     memset(bit, 0xff, sizeof(*bit));
-    hal_flash_read(b->loc.bil_flash_id, off, bit, sizeof(*bit));
+    hal_flash_read(flash_id, off, bit, sizeof(*bit));
 }
 
 static void
 boot_scratch_magic(struct boot_img_trailer *bit)
 {
     uint32_t off;
-    struct flash_area *scratch;
-
-    scratch = &boot_req->br_area_descs[boot_req->br_scratch_area_idx];
+    uint8_t flash_id;
 
-    off = boot_scratch_off();
-    hal_flash_read(scratch->fa_flash_id, off, bit, sizeof(*bit));
+    boot_scratch_loc(&flash_id, &off);
+    memset(bit, 0xff, sizeof(*bit));
+    hal_flash_read(flash_id, off, bit, sizeof(*bit));
 }
 
+/*
+ * Gather info about image in a given slot.
+ */
 void
 boot_image_info(void)
 {
@@ -218,6 +221,15 @@ boot_copy_sz(int max_idx, int *cnt)
     return sz;
 }
 
+/**
+ * Erase one area.  The destination area must
+ * be erased prior to this function being called.
+ *
+ * @param area_idx            The index of the area.
+ * @param sz                  The number of bytes to erase.
+ *
+ * @return                      0 on success; nonzero on failure.
+ */
 static int
 boot_erase_area(int area_idx, uint32_t sz)
 {
@@ -289,13 +301,15 @@ boot_copy_area(int from_area_idx, int to_area_idx, uint32_t sz)
 }
 
 /**
- * Swaps the contents of two flash areas.
+ * Swaps the contents of two flash areas belonging to images.
  *
- * @param area_idx_1          The index of one area to swap.  This area
+ * @param area_idx            The index of first slot to exchange. This area
  *                                  must be part of the first image slot.
- * @param area_idx_2          The index of the other area to swap.  This
- *                                  area must be part of the second image
- *                                  slot.
+ * @param sz                  The number of bytes swap.
+ *
+ * @param end_area            Boolean telling whether this includes this
+ *                                  area has last slots.
+ *
  * @return                      0 on success; nonzero on failure.
  */
 static int
@@ -415,22 +429,23 @@ int
 boot_read_status(struct boot_status *bs)
 {
     struct boot_img_trailer bit;
-    struct flash_area *scratch;
+    uint8_t flash_id;
+    uint32_t off;
 
     /*
      * Check if boot_img_trailer is in scratch, or at the end of slot0.
      */
     boot_slot_magic(0, &bit);
     if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
-        boot_read_status_bytes(bs, boot_img[0].loc.bil_flash_id,
-          boot_magic_off(0));
+        boot_magic_loc(0, &flash_id, &off);
+        boot_read_status_bytes(bs, flash_id, off);
         console_printf("status in slot0, %lu/%lu\n", bs->idx, bs->state);
         return 1;
     }
     boot_scratch_magic(&bit);
     if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
-        scratch = &boot_req->br_area_descs[boot_req->br_scratch_area_idx];
-        boot_read_status_bytes(bs, scratch->fa_flash_id, boot_scratch_off());
+        boot_scratch_loc(&flash_id, &off);
+        boot_read_status_bytes(bs, flash_id, off);
         console_printf("status in scratch, %lu/%lu\n", bs->idx, bs->state);
         return 1;
     }
@@ -450,15 +465,12 @@ boot_write_status(struct boot_status *bs)
         /*
          * Write to scratch
          */
-        off = boot_scratch_off();
-        flash_id =
-          boot_req->br_area_descs[boot_req->br_scratch_area_idx].fa_flash_id;
+        boot_scratch_loc(&flash_id, &off);
     } else {
         /*
          * Write to slot 0;
          */
-        off = boot_magic_off(0);
-        flash_id = boot_img[0].loc.bil_flash_id;
+        boot_magic_loc(0, &flash_id, &off);
     }
     off -= ((3 * sizeof(uint8_t)) * bs->idx +
       sizeof(uint8_t) * (bs->state + 1));
@@ -481,8 +493,7 @@ boot_clear_status(void)
     /*
      * Write to slot 0;
      */
-    off = boot_magic_off(0);
-    flash_id = boot_img[0].loc.bil_flash_id;
+    boot_magic_loc(0, &flash_id, &off);
     off += sizeof(uint32_t);
     hal_flash_write(flash_id, off, &val, sizeof(val));
 }


[47/50] [abbrv] incubator-mynewt-core git commit: MYNEWT-329

Posted by cc...@apache.org.
MYNEWT-329

By default, we will assume that cputime counts at a 1 MHz rate.
If a different frequency is desired the user should define
HAL_CPUTIME in their target, project or bsp. See the jira ticket
for more information.


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

Branch: refs/heads/master
Commit: 03c939a22d76b045f55228ad61c1fc4b88cd5fc6
Parents: 6f3d956
Author: William San Filippo <wi...@runtime.io>
Authored: Mon Aug 22 15:20:30 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Mon Aug 22 15:20:30 2016 -0700

----------------------------------------------------------------------
 hw/hal/include/hal/hal_cputime.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/03c939a2/hw/hal/include/hal/hal_cputime.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_cputime.h b/hw/hal/include/hal/hal_cputime.h
index 7932de6..08cf2de 100644
--- a/hw/hal/include/hal/hal_cputime.h
+++ b/hw/hal/include/hal/hal_cputime.h
@@ -26,6 +26,22 @@ extern "C" {
 
 #include "os/queue.h"
 
+/*
+ * NOTE: these definitions allow one to override the cputime frequency used.
+ * The reason these definitions exist is to make the code more efficient/smaller
+ * when CPUTIME counts at 1 MHz.
+ *
+ * For those who want a different cputime frequency, you can set the macro
+ * HAL_CPUTIME to the desired frequency in your project, target or bsp.
+ */
+#ifndef HAL_CPUTIME
+#define HAL_CPUTIME 1000000
+#endif
+
+#if (HAL_CPUTIME == 1000000)
+#define HAL_CPUTIME_1MHZ
+#endif
+
 /* CPU timer callback function */
 struct cpu_timer;
 typedef void (*cputimer_func)(void *arg);


[18/50] [abbrv] incubator-mynewt-core git commit: updating the code as from last comment

Posted by cc...@apache.org.
updating the code as from last comment


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

Branch: refs/heads/master
Commit: 618151456d514f5501cd0f8c79153d6a283dc2c1
Parents: f8af60d
Author: NgesBrian <ng...@gmail.com>
Authored: Wed Aug 10 12:26:52 2016 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 09:20:59 2016 -0700

----------------------------------------------------------------------
 libs/os/src/test/callout_test.c | 44 +++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/61815145/libs/os/src/test/callout_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/callout_test.c b/libs/os/src/test/callout_test.c
index 937b170..a56efd5 100644
--- a/libs/os/src/test/callout_test.c
+++ b/libs/os/src/test/callout_test.c
@@ -41,9 +41,6 @@ struct os_callout_func callout_func_test;
 struct os_eventq callout_evq;
 struct os_event callout_ev;
 
-int i; 
-int j;
- 
 /* The callout_stop task */
 #define SEND_STOP_CALLOUT_TASK_PRIO        (3)
 struct os_task callout_task_struct_stop_send;
@@ -73,37 +70,35 @@ os_stack_t callout_task_stack_listen[CALLOUT_STACK_SIZE];
 
 struct os_callout_func callout_func_speak;
 
+/* Global variables to be used by the callout functions */
+int p;
+int q;
+int t;
 /* This is the function for callout_init*/
 void
 my_callout_func(void *arg)
 {
-    int p;
     p = 4;
-    TEST_ASSERT(p == 4);
 }
 
 /* This is the function for callout_init of stop test_case*/
 void
 my_callout_stop_func(void *arg)
 {
-    int q;
     q = 1;
-    TEST_ASSERT(q == 1);
 }
 /* This is the function for callout_init for speak test_case*/
 void
 my_callout_speak_func(void *arg)
 {
-    int p;
-    p = 4;
-    TEST_ASSERT(p == 4);
+    t = 2;
 }
 
 /* This is a callout task to send data */
 void
 callout_task_send(void *arg )
 {
-   
+   int i;
     /* Should say whether callout is armed or not */
     i= os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 0);
@@ -124,6 +119,7 @@ callout_task_send(void *arg )
 void
 callout_task_receive( void *arg)
 {
+    int i;
     struct os_event *event;
     os_time_t now;
     os_time_t tm;
@@ -133,7 +129,6 @@ callout_task_receive( void *arg)
     TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
     TEST_ASSERT(event->ev_arg == NULL);
 
-    TEST_ASSERT(i == 1);
     /* Should say whether callout is armed or not */
     i = os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 0);
@@ -153,27 +148,25 @@ callout_task_receive( void *arg)
 void
 callout_task_stop_send( void *arg)
 {
-     int k;
-
+    int k;
+    int j;    
      /* Should say whether callout is armed or not */
     for(k = 0; k<MULTI_SIZE; k++){
         j = os_callout_queued(&callout_func_stop_test[k].cf_c);
         TEST_ASSERT(j == 0);
     }
 
+
     /* Show that  callout is not armed after calling callout_stop */
     for(k = 0; k<MULTI_SIZE; k++){
         os_callout_stop(&callout_func_stop_test[k].cf_c);
         j = os_callout_queued(&callout_func_stop_test[k].cf_c);
         TEST_ASSERT(j == 0);
     }
-    /* Assigning data to send */
+    /* Arm the callout */
     for(k = 0; k<MULTI_SIZE; k++){
-        callout_func_stop_test[k].cf_c.c_ev.ev_type = 10+ k;
-        callout_func_stop_test[k].cf_c.c_ev.ev_arg = NULL;
-
-         os_eventq_put(callout_func_stop_test[k].cf_c.c_evq,
-             &callout_func_stop_test[k].cf_c.c_ev);
+        j = os_callout_reset(&callout_func_stop_test[k].cf_c, OS_TICKS_PER_SEC/ 50);
+        TEST_ASSERT_FATAL(j == 0);
     }
     os_time_delay( OS_TICKS_PER_SEC );
 }
@@ -188,8 +181,9 @@ callout_task_stop_receive( void *arg )
     for(k=0; k<MULTI_SIZE; k++){
         event = os_eventq_poll(&callout_func_stop_test[k].cf_c.c_evq, 1,
            OS_WAIT_FOREVER);
-        TEST_ASSERT(event->ev_type == 10+k);
+        TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
         TEST_ASSERT(event->ev_arg == NULL);
+
      }
      
     /* Show that event is removed from the queued after calling callout_stop */
@@ -207,6 +201,7 @@ callout_task_stop_receive( void *arg )
 void
 callout_task_stop_speak( void *arg )
 {
+    int i;
     /* Arm the callout */
     i = os_callout_reset(&callout_func_speak.cf_c, OS_TICKS_PER_SEC/ 50);
     TEST_ASSERT_FATAL(i == 0);
@@ -216,7 +211,6 @@ callout_task_stop_speak( void *arg )
     TEST_ASSERT(i == 1);
 
     os_callout_stop(&callout_func_speak.cf_c);
-    TEST_ASSERT(i == 1);
     
     /* Send the callout */ 
     os_time_delay(OS_TICKS_PER_SEC/ 100 );
@@ -253,6 +247,7 @@ TEST_CASE(callout_test)
     /* Initialize the callout function */
     os_callout_func_init(&callout_func_test, &callout_evq,
         my_callout_func, NULL);
+    TEST_ASSERT(p == 4);
 
     /* Does not return until OS_restart is called */
     os_start();
@@ -284,6 +279,8 @@ TEST_CASE(callout_test_stop)
     for(k = 0; k<MULTI_SIZE; k++){
         os_callout_func_init(&callout_func_stop_test[k], &callout_stop_evq[k],
            my_callout_stop_func, NULL);
+         TEST_ASSERT(q == 1);
+
     }
 
     /* Does not return until OS_restart is called */
@@ -312,7 +309,8 @@ TEST_CASE(callout_test_speak)
     /* Initialize the callout function */
     os_callout_func_init(&callout_func_speak, &callout_evq,
         my_callout_speak_func, NULL);
-
+    TEST_ASSERT(t == 2);
+    
     /* Does not return until OS_restart is called */
     os_start();
 


[50/50] [abbrv] incubator-mynewt-core git commit: Merge branch 'develop' - in preparation for backwards-compatibility-breaking changes to develop.

Posted by cc...@apache.org.
Merge branch 'develop' - in preparation for
backwards-compatibility-breaking changes to develop.

* develop: (290 commits)
  sim compiler - replace objsize with size
  Fix warnings reported by clang.
  MYNEWT-329
  MYNEWT-354
  STM32f407 discovery board BSP
  mbedtls; use smaller version of SHA256.
  boot; boot loader does not need to call os_init() anymore, as bsp_init() has been exported.
  boot; app does not need the dependency to mbedtls
  slinky; time-based waits must use OS_TICKS_PER_SEC.
  bootutil; adjust unit tests to work with status upkeep outside sys/config.
  bootutil; was returning wrong image header in response when swithing images. Add boot_set_req() routine for unit test use.
  boot/bootutil; remove debug console use from bootloader.
  bootutil/imgmgr; output of boot now shows the fallback image.
  imgmgr; automatically confirm image as good for now.
  bootutil; add 'confirm' step, telling that image was confirmed as good. Otherwise next restart we'll go back to old image.
  bootutil; make status element size depend on flash alignment restrictions.
  boot, imgmgr; return the slot number for test image.
  bootutil; move routines reading boot-copy-status from loader.c to bootutil_misc.c.
  boot; return full flash location of status bytes, instead of just offset.
  boot; don't use NFFS or FCB for keeping status. Interim 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/70987f7d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/70987f7d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/70987f7d

Branch: refs/heads/master
Commit: 70987f7d2e3c791132509f08566fe77de34142ac
Parents: 0d9c8f3 665e22f
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 23 17:35:28 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Aug 23 17:35:28 2016 -0700

----------------------------------------------------------------------
 CODING_STANDARDS.md                             |    2 +
 apps/blecent/pkg.yml                            |   39 +
 apps/blecent/src/blecent.h                      |  117 +
 apps/blecent/src/main.c                         |  620 +++++
 apps/blecent/src/misc.c                         |  237 ++
 apps/blecent/src/peer.c                         |  807 +++++++
 apps/blehci/pkg.yml                             |    5 +-
 apps/blehci/src/main.c                          |  314 +--
 apps/bleprph/pkg.yml                            |   17 +
 apps/bleprph/src/bleprph.h                      |   26 +-
 apps/bleprph/src/gatt_svr.c                     |  337 +--
 apps/bleprph/src/main.c                         |  203 +-
 apps/bleprph/src/misc.c                         |    6 +-
 apps/bleprph/src/store.c                        |  374 ---
 apps/bletest/pkg.yml                            |    1 +
 apps/bletest/src/bletest_hci.c                  |  133 +-
 apps/bletest/src/main.c                         |   48 +-
 apps/bletiny/pkg.yml                            |   14 +
 apps/bletiny/src/bletiny.h                      |   83 +-
 apps/bletiny/src/cmd.c                          |  393 ++--
 apps/bletiny/src/gatt_svr.c                     |  343 +--
 apps/bletiny/src/main.c                         |  515 +++--
 apps/bletiny/src/misc.c                         |   37 +-
 apps/bletiny/src/parse.c                        |  108 +-
 apps/bletiny/src/store.c                        |  399 ----
 apps/bleuart/pkg.yml                            |   43 +
 apps/bleuart/src/main.c                         |  362 +++
 apps/blinky/src/main.c                          |    2 -
 apps/boot/pkg.yml                               |    2 -
 apps/boot/src/boot.c                            |   96 +-
 apps/ffs2native/src/main.c                      |   77 +-
 apps/luatest/src/main.c                         |    1 -
 apps/slinky/src/main.c                          |   37 +-
 compiler/arm-none-eabi-m4/compiler.yml          |    7 +-
 compiler/sim/compiler.yml                       |    2 +-
 .../include/uart_bitbang/uart_bitbang.h         |   25 +
 .../include/uart_bitbang/uart_bitbang_api.h     |   33 +
 drivers/uart_bitbang/pkg.yml                    |   27 +
 drivers/uart_bitbang/src/uart_bitbang.c         |  325 +++
 fs/fs/src/fsutil.c                              |    2 +-
 fs/nffs/src/nffs.c                              |   10 +
 fs/nffs/src/nffs_block.c                        |    3 +
 fs/nffs/src/nffs_cache.c                        |    8 +-
 fs/nffs/src/nffs_hash.c                         |    2 +
 fs/nffs/src/nffs_inode.c                        |    4 +
 fs/nffs/src/nffs_priv.h                         |    4 +
 fs/nffs/src/nffs_restore.c                      |   60 +-
 hw/bsp/arduino_primo_nrf52/primo_debug.sh       |    5 +-
 hw/bsp/nrf51-blenano/src/os_bsp.c               |    2 +-
 .../olimex_stm32-e407_devboard_debug.sh         |    1 -
 hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c |    4 +-
 .../stm32f4discovery/boot-stm32f4discovery.ld   |  202 ++
 hw/bsp/stm32f4discovery/f407.cfg                |   82 +
 hw/bsp/stm32f4discovery/include/bsp/bsp.h       |   55 +
 hw/bsp/stm32f4discovery/include/bsp/bsp_sysid.h |   36 +
 .../stm32f4discovery/include/bsp/cmsis_nvic.h   |   29 +
 .../include/bsp/stm32f4xx_hal_conf.h            |  413 ++++
 hw/bsp/stm32f4discovery/pkg.yml                 |   39 +
 hw/bsp/stm32f4discovery/run_from_flash.ld       |  204 ++
 hw/bsp/stm32f4discovery/run_from_loader.ld      |  210 ++
 hw/bsp/stm32f4discovery/run_from_sram.ld        |  202 ++
 .../src/arch/cortex_m4/startup_STM32F40x.s      |  343 +++
 hw/bsp/stm32f4discovery/src/hal_bsp.c           |   77 +
 hw/bsp/stm32f4discovery/src/libc_stubs.c        |   84 +
 hw/bsp/stm32f4discovery/src/os_bsp.c            |   82 +
 hw/bsp/stm32f4discovery/src/sbrk.c              |   50 +
 hw/bsp/stm32f4discovery/src/system_stm32f4xx.c  |  351 +++
 hw/bsp/stm32f4discovery/stm32f4discovery.ld     |  213 ++
 .../stm32f4discovery/stm32f4discovery_debug.sh  |   47 +
 .../stm32f4discovery_download.sh                |   56 +
 hw/hal/include/hal/hal_cputime.h                |   16 +
 hw/hal/include/hal/hal_uart.h                   |    6 +
 hw/mcu/native/src/hal_uart.c                    |    2 +-
 hw/mcu/nordic/nrf52xxx/src/hal_gpio.c           |  503 ++---
 hw/mcu/nordic/nrf52xxx/src/hal_uart.c           |   33 +-
 hw/mcu/stm/stm32f4xx/src/hal_gpio.c             |    2 +-
 hw/mcu/stm/stm32f4xx/src/hal_uart.c             |   16 +
 libs/bleuart/include/bleuart/bleuart.h          |   34 +
 libs/bleuart/pkg.yml                            |   34 +
 libs/bleuart/src/bleuart.c                      |  204 ++
 libs/boot_serial/src/test/boot_test.c           |    1 +
 libs/bootutil/include/bootutil/bootutil_misc.h  |   11 +-
 libs/bootutil/include/bootutil/loader.h         |    3 +
 libs/bootutil/src/bootutil_misc.c               |  382 ++--
 libs/bootutil/src/bootutil_priv.h               |   57 +-
 libs/bootutil/src/loader.c                      |  387 ++--
 libs/bootutil/src/test/boot_test.c              |  215 +-
 libs/console/full/src/cons_tty.c                |   17 +-
 libs/imgmgr/include/imgmgr/imgmgr.h             |    2 +-
 libs/imgmgr/src/imgmgr.c                        |    4 +
 libs/imgmgr/src/imgmgr_boot.c                   |   30 +-
 .../include/inet_def_service/inet_def_service.h |   25 +
 libs/inet_def_service/pkg.yml                   |   38 +
 libs/inet_def_service/src/inet_def_service.c    |  333 +++
 libs/mbedtls/include/mbedtls/config_mynewt.h    |    2 +
 libs/newtmgr/pkg.yml                            |    5 +-
 libs/newtmgr/src/newtmgr.c                      |    1 -
 .../transport/ble/include/nmgrble/newtmgr_ble.h |   28 +
 libs/newtmgr/transport/ble/pkg.yml              |   30 +
 libs/newtmgr/transport/ble/src/newtmgr_ble.c    |  237 ++
 libs/os/include/os/arch/cortex_m0/os/os_arch.h  |   12 +-
 libs/os/include/os/arch/cortex_m4/os/os_arch.h  |   12 +-
 libs/os/include/os/os_mbuf.h                    |   12 +-
 libs/os/include/os/os_mempool.h                 |    3 +
 libs/os/src/arch/cortex_m0/m0/HAL_CM0.s         |    1 -
 libs/os/src/arch/cortex_m0/os_arch_arm.c        |   34 +-
 libs/os/src/arch/cortex_m4/m4/HAL_CM4.s         |    2 +-
 libs/os/src/arch/cortex_m4/os_arch_arm.c        |   35 +-
 libs/os/src/arch/sim/os_arch_sim.c              |    2 +-
 libs/os/src/os.c                                |    4 +
 libs/os/src/os_callout.c                        |    4 +-
 libs/os/src/os_eventq.c                         |   33 +-
 libs/os/src/os_mbuf.c                           |  181 +-
 libs/os/src/os_mempool.c                        |   74 +-
 libs/os/src/os_priv.h                           |   10 +-
 libs/os/src/os_task.c                           |    3 +-
 libs/os/src/os_time.c                           |   12 +-
 libs/os/src/test/callout_test.c                 |  330 +++
 libs/os/src/test/eventq_test.c                  |  297 ++-
 libs/os/src/test/os_test.c                      |    2 +-
 libs/os/src/test/os_test_priv.h                 |    2 +-
 libs/shell/src/shell.c                          |    2 +
 libs/testutil/include/testutil/testutil.h       |    8 +-
 libs/testutil/src/case.c                        |   10 +
 libs/testutil/src/suite.c                       |   24 +
 libs/testutil/src/testutil_priv.h               |    5 +
 libs/util/include/util/mem.h                    |   38 +
 libs/util/src/mem.c                             |  146 ++
 libs/wifi_mgmt/include/wifi_mgmt/wifi_mgmt.h    |   82 +
 libs/wifi_mgmt/include/wifi_mgmt/wifi_mgmt_if.h |   47 +
 libs/wifi_mgmt/pkg.yml                          |   35 +
 libs/wifi_mgmt/src/wifi.c                       |  348 +++
 libs/wifi_mgmt/src/wifi_cli.c                   |   89 +
 libs/wifi_mgmt/src/wifi_priv.h                  |   27 +
 .../controller/include/controller/ble_ll.h      |   23 +-
 .../controller/include/controller/ble_ll_hci.h  |    3 +
 .../include/controller/ble_ll_resolv.h          |    7 +-
 .../controller/include/controller/ble_ll_scan.h |    2 +-
 .../controller/include/controller/ble_phy.h     |    3 +
 net/nimble/controller/pkg.yml                   |    6 +-
 net/nimble/controller/src/ble_ll.c              |  154 +-
 net/nimble/controller/src/ble_ll_adv.c          |   17 +
 net/nimble/controller/src/ble_ll_conn.c         |  143 +-
 net/nimble/controller/src/ble_ll_conn_hci.c     |   41 +-
 net/nimble/controller/src/ble_ll_conn_priv.h    |   12 +-
 net/nimble/controller/src/ble_ll_hci.c          |   16 +-
 net/nimble/controller/src/ble_ll_hci_ev.c       |   15 +-
 net/nimble/controller/src/ble_ll_rand.c         |    3 +-
 net/nimble/controller/src/ble_ll_resolv.c       |  175 +-
 net/nimble/controller/src/ble_ll_scan.c         |   15 +-
 net/nimble/controller/src/ble_ll_sched.c        |   14 +-
 net/nimble/drivers/native/src/ble_phy.c         |  161 +-
 net/nimble/drivers/nrf51/src/ble_phy.c          |  201 +-
 net/nimble/drivers/nrf52/src/ble_phy.c          |  203 +-
 net/nimble/host/include/host/ble_att.h          |   49 +-
 net/nimble/host/include/host/ble_gap.h          |  448 +++-
 net/nimble/host/include/host/ble_gatt.h         |  428 +++-
 net/nimble/host/include/host/ble_hs.h           |   93 +-
 net/nimble/host/include/host/ble_hs_adv.h       |   21 +-
 net/nimble/host/include/host/ble_hs_id.h        |   30 +
 net/nimble/host/include/host/ble_hs_log.h       |   39 +
 net/nimble/host/include/host/ble_hs_mbuf.h      |   31 +
 net/nimble/host/include/host/ble_hs_test.h      |   11 +-
 net/nimble/host/include/host/ble_ibeacon.h      |   25 +
 net/nimble/host/include/host/ble_store.h        |   72 +
 net/nimble/host/include/host/ble_uuid.h         |    4 +-
 net/nimble/host/include/host/host_hci.h         |  133 --
 net/nimble/host/pkg.yml                         |   18 +-
 .../gap/include/services/gap/ble_svc_gap.h      |   39 +
 net/nimble/host/services/gap/pkg.yml            |   31 +
 net/nimble/host/services/gap/src/ble_svc_gap.c  |  167 ++
 .../gatt/include/services/gatt/ble_svc_gatt.h   |   29 +
 net/nimble/host/services/gatt/pkg.yml           |   31 +
 .../host/services/gatt/src/ble_svc_gatt.c       |   90 +
 .../lls/include/services/lls/ble_svc_lls.h      |   44 +
 net/nimble/host/services/lls/pkg.yml            |   31 +
 net/nimble/host/services/lls/src/ble_svc_lls.c  |  201 ++
 net/nimble/host/src/ble_att.c                   |  109 +-
 net/nimble/host/src/ble_att_clt.c               |  868 +++----
 net/nimble/host/src/ble_att_cmd.c               |  236 +-
 net/nimble/host/src/ble_att_cmd_priv.h          |  127 +-
 net/nimble/host/src/ble_att_priv.h              |   97 +-
 net/nimble/host/src/ble_att_svr.c               |  899 ++++----
 net/nimble/host/src/ble_eddystone.c             |   15 +-
 net/nimble/host/src/ble_gap.c                   | 2120 +++++++++++-------
 net/nimble/host/src/ble_gap_priv.h              |   25 +-
 net/nimble/host/src/ble_gatt_priv.h             |   24 +-
 net/nimble/host/src/ble_gattc.c                 | 1131 ++++++----
 net/nimble/host/src/ble_gatts.c                 | 1077 +++++++--
 net/nimble/host/src/ble_hci_cmd.c               |  298 ---
 net/nimble/host/src/ble_hci_util.c              |  159 --
 net/nimble/host/src/ble_hci_util_priv.h         |   30 -
 net/nimble/host/src/ble_hs.c                    |  369 ++-
 net/nimble/host/src/ble_hs_adv.c                |  134 +-
 net/nimble/host/src/ble_hs_adv_priv.h           |   19 +-
 net/nimble/host/src/ble_hs_atomic.c             |   20 +
 net/nimble/host/src/ble_hs_atomic_priv.h        |    1 +
 net/nimble/host/src/ble_hs_cfg.c                |   34 +-
 net/nimble/host/src/ble_hs_conn.c               |   64 +-
 net/nimble/host/src/ble_hs_conn_priv.h          |   22 +-
 net/nimble/host/src/ble_hs_dbg.c                |  509 +++++
 net/nimble/host/src/ble_hs_dbg_priv.h           |   26 +
 net/nimble/host/src/ble_hs_hci.c                |  518 +++++
 net/nimble/host/src/ble_hs_hci_cmd.c            | 1375 ++++++++++++
 net/nimble/host/src/ble_hs_hci_evt.c            |  677 ++++++
 net/nimble/host/src/ble_hs_hci_priv.h           |  158 ++
 net/nimble/host/src/ble_hs_hci_util.c           |  196 ++
 net/nimble/host/src/ble_hs_id.c                 |  248 ++
 net/nimble/host/src/ble_hs_id_priv.h            |   30 +
 net/nimble/host/src/ble_hs_log.c                |   47 +
 net/nimble/host/src/ble_hs_mbuf.c               |  198 ++
 net/nimble/host/src/ble_hs_mbuf_priv.h          |   11 +
 net/nimble/host/src/ble_hs_misc.c               |   73 +-
 net/nimble/host/src/ble_hs_priv.h               |   84 +-
 net/nimble/host/src/ble_hs_pvcy.c               |  146 +-
 net/nimble/host/src/ble_hs_pvcy_priv.h          |   31 +
 net/nimble/host/src/ble_hs_startup.c            |   66 +-
 net/nimble/host/src/ble_ibeacon.c               |   16 +-
 net/nimble/host/src/ble_l2cap.c                 |   25 +-
 net/nimble/host/src/ble_l2cap_priv.h            |    7 +-
 net/nimble/host/src/ble_l2cap_sig.c             |   59 +-
 net/nimble/host/src/ble_l2cap_sig_cmd.c         |   22 +-
 net/nimble/host/src/ble_l2cap_sig_priv.h        |    2 +-
 net/nimble/host/src/ble_sm.c                    |  162 +-
 net/nimble/host/src/ble_sm_alg.c                |   78 +-
 net/nimble/host/src/ble_sm_cmd.c                |  162 +-
 net/nimble/host/src/ble_sm_lgcy.c               |    7 +-
 net/nimble/host/src/ble_sm_priv.h               |   28 +-
 net/nimble/host/src/ble_sm_sc.c                 |   91 +-
 net/nimble/host/src/ble_uuid.c                  |   29 +-
 net/nimble/host/src/ble_uuid_priv.h             |   28 +
 net/nimble/host/src/host_dbg.c                  |  503 -----
 net/nimble/host/src/host_dbg_priv.h             |   25 -
 net/nimble/host/src/host_hci.c                  |  745 ------
 net/nimble/host/src/host_hci_cmd.c              | 1326 -----------
 net/nimble/host/src/test/ble_att_clt_test.c     |   58 +-
 net/nimble/host/src/test/ble_att_svr_test.c     |  460 ++--
 net/nimble/host/src/test/ble_gap_test.c         | 1327 ++++++++---
 net/nimble/host/src/test/ble_gatt_conn_test.c   |  126 +-
 net/nimble/host/src/test/ble_gatt_disc_c_test.c |   22 +-
 net/nimble/host/src/test/ble_gatt_disc_d_test.c |   93 +-
 net/nimble/host/src/test/ble_gatt_disc_s_test.c |   24 +-
 net/nimble/host/src/test/ble_gatt_find_s_test.c |   22 +-
 net/nimble/host/src/test/ble_gatt_read_test.c   |  248 +-
 net/nimble/host/src/test/ble_gatt_write_test.c  |  163 +-
 .../host/src/test/ble_gatts_notify_test.c       |  589 ++++-
 net/nimble/host/src/test/ble_gatts_read_test.c  |  261 +++
 net/nimble/host/src/test/ble_gatts_reg_test.c   |  292 ++-
 net/nimble/host/src/test/ble_host_hci_test.c    |   94 -
 net/nimble/host/src/test/ble_hs_adv_test.c      |  468 ++--
 net/nimble/host/src/test/ble_hs_conn_test.c     |   92 +-
 net/nimble/host/src/test/ble_hs_hci_test.c      |   99 +
 net/nimble/host/src/test/ble_hs_test.c          |   21 +-
 net/nimble/host/src/test/ble_hs_test_util.c     |  844 ++++++-
 net/nimble/host/src/test/ble_hs_test_util.h     |  103 +-
 net/nimble/host/src/test/ble_l2cap_test.c       |   17 +-
 net/nimble/host/src/test/ble_os_test.c          |   92 +-
 net/nimble/host/src/test/ble_sm_lgcy_test.c     |    3 +-
 net/nimble/host/src/test/ble_sm_sc_test.c       |    3 +-
 net/nimble/host/src/test/ble_sm_test.c          |    3 +-
 net/nimble/host/src/test/ble_sm_test_util.c     |  158 +-
 net/nimble/host/src/test/ble_sm_test_util.h     |    3 +-
 net/nimble/host/src/test/ble_uuid_test.c        |    5 +-
 .../store/ram/include/store/ram/ble_store_ram.h |   30 +
 net/nimble/host/store/ram/pkg.yml               |   31 +
 net/nimble/host/store/ram/src/ble_store_ram.c   |  373 +++
 net/nimble/include/nimble/ble.h                 |   21 +-
 net/nimble/include/nimble/ble_hci_trans.h       |  169 ++
 net/nimble/include/nimble/hci_common.h          |    9 +
 net/nimble/include/nimble/hci_transport.h       |   32 -
 net/nimble/include/nimble/nimble_opt.h          |   53 +-
 net/nimble/src/ble_util.c                       |   43 +
 net/nimble/src/util.c                           |   26 +-
 .../ram/include/transport/ram/ble_hci_ram.h     |   30 +
 net/nimble/transport/ram/pkg.yml                |   33 +
 net/nimble/transport/ram/src/ble_hci_ram.c      |  229 ++
 .../uart/include/transport/uart/ble_hci_uart.h  |   19 +
 net/nimble/transport/uart/pkg.yml               |   34 +
 net/nimble/transport/uart/src/ble_hci_uart.c    |  743 ++++++
 sys/config/src/config_nmgr.c                    |   18 +-
 sys/fcb/src/fcb.c                               |    6 +-
 sys/fcb/src/fcb_rotate.c                        |   10 +-
 sys/log/include/log/log.h                       |    8 +
 sys/log/src/log.c                               |    5 +
 sys/log/src/log_fcb.c                           |    6 +-
 sys/log/src/log_nmgr.c                          |    8 -
 sys/mn_socket/include/mn_socket/mn_socket.h     |  146 ++
 sys/mn_socket/include/mn_socket/mn_socket_ops.h |   82 +
 sys/mn_socket/pkg.yml                           |   31 +
 sys/mn_socket/src/mn_socket.c                   |  123 +
 sys/mn_socket/src/mn_socket_aconv.c             |   57 +
 sys/mn_socket/src/test/mn_sock_test.c           |   82 +
 292 files changed, 28344 insertions(+), 12349 deletions(-)
----------------------------------------------------------------------



[21/50] [abbrv] incubator-mynewt-core git commit: advancement in the callout

Posted by cc...@apache.org.
advancement in the callout


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

Branch: refs/heads/master
Commit: 0b7cd2f1f01554fd795b0b9a1116939f5c3cca4e
Parents: 3359c33
Author: NgesBrian <ng...@gmail.com>
Authored: Mon Jul 25 00:14:41 2016 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 09:20:59 2016 -0700

----------------------------------------------------------------------
 libs/os/src/test/callout_test.c | 44 +++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b7cd2f1/libs/os/src/test/callout_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/callout_test.c b/libs/os/src/test/callout_test.c
index 350e94d..960a7fd 100644
--- a/libs/os/src/test/callout_test.c
+++ b/libs/os/src/test/callout_test.c
@@ -35,35 +35,44 @@ os_stack_t callout_task_stack_receive[CALLOUT_STACK_SIZE];
 
 /* Delearing variables for callout_func */
 struct os_callout_func callout_func_test;
-struct os_eventq *callout_eventq;
-void native_cputimer_cb(void *arg);
 
 /* The event to be sent*/
 struct os_eventq callout_evq;
 struct os_event callout_ev;
 
+/* This is the function for callout_init*/
+void my_callout_func(void *arg)
+{
+    int i;
+    i = 4;
+    TEST_ASSERT(i==4);
+}
+
 /* This is a callout task to send data */
 void
 callout_task_send()
 {
-   int i;
-    /* assigning the *callout_eventq */
-    callout_eventq = &callout_evq;
-
-    /* Initialize the callout function */
-    os_callout_func_init(&callout_func_test, callout_eventq,
-        native_cputimer_cb, NULL);
-
+    int i; 
     /* should say whether os is armed or not */
     i = os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 0);
-    
+
     /* Arm the OS */
-    os_callout_reset(&callout_func_test.cf_c, OS_TICKS_PER_SEC/ 50);
-    
+    i = os_callout_reset(&callout_func_test.cf_c, OS_TICKS_PER_SEC/ 50);
+    TEST_ASSERT_FATAL(i == 0);
+
+    /* should say whether os is armed or not */
+    i = os_callout_queued(&callout_func_test.cf_c);
+    TEST_ASSERT(i == 1);
+
     /* Send the callout */ 
-    os_time_delay(OS_TICKS_PER_SEC / 50);
+    os_time_delay(OS_TICKS_PER_SEC );
+    TEST_ASSERT(i == 0);
+
+     /* should say whether os is armed or not */
+    i = os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 0);
+
 }
 
 void
@@ -76,7 +85,6 @@ callout_task_receive(void *arg)
         TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
         TEST_ASSERT(event->ev_arg == NULL);
 
-
     /* Finishes the test when OS has been started */
     os_test_restart();
 
@@ -98,8 +106,12 @@ TEST_CASE(callout_test)
         callout_task_receive, NULL, RECEIVE_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
         callout_task_stack_receive, CALLOUT_STACK_SIZE);
 
-    os_eventq_init(callout_eventq);
+    os_eventq_init(&callout_evq);
     
+    /* Initialize the callout function */
+    os_callout_func_init(&callout_func_test, &callout_evq,
+        my_callout_func, NULL);
+
     /* Does not return until OS_restart is called */
     os_start();
 


[38/50] [abbrv] incubator-mynewt-core git commit: imgmgr; automatically confirm image as good for now.

Posted by cc...@apache.org.
imgmgr; automatically confirm image as good for now.


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

Branch: refs/heads/master
Commit: 183be3aaa662216f17519861e49f9b8d9758b834
Parents: a54ebc5
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Aug 18 16:53:25 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:50 2016 -0700

----------------------------------------------------------------------
 libs/imgmgr/src/imgmgr.c | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/183be3aa/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index 5e8539a..aac8574 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@ -28,6 +28,7 @@
 #include <util/base64.h>
 
 #include <bootutil/image.h>
+#include <bootutil/bootutil_misc.h>
 
 #include "imgmgr/imgmgr.h"
 #include "imgmgr_priv.h"
@@ -494,5 +495,8 @@ imgmgr_module_init(void)
 
     rc = nmgr_group_register(&imgr_nmgr_group);
     assert(rc == 0);
+
+    boot_confirm_ok();
+
     return rc;
 }


[11/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Update conns' pref. MTU

Posted by cc...@apache.org.
BLE Host - Update conns' pref. MTU

Prior to this commit, setting the preferred MTU only affected future
connections.

Now, an existing connection is updated if we haven't transmitted our
preferred MTU over it yet.


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

Branch: refs/heads/master
Commit: 30d5d15550c0c464a7a185a554794730d498dd7e
Parents: 567c9c1
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 12 17:44:19 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Aug 12 18:16:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_att.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/30d5d155/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 608904a..a6d39b8 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -496,6 +496,10 @@ ble_att_preferred_mtu(void)
 int
 ble_att_set_preferred_mtu(uint16_t mtu)
 {
+    struct ble_l2cap_chan *chan;
+    struct ble_hs_conn *conn;
+    int i;
+
     if (mtu < BLE_ATT_MTU_DFLT) {
         return BLE_HS_EINVAL;
     }
@@ -505,7 +509,22 @@ ble_att_set_preferred_mtu(uint16_t mtu)
 
     ble_att_preferred_mtu_val = mtu;
 
-    /* XXX: Set my_mtu for established connections that haven't exchanged. */
+    /* Set my_mtu for established connections that haven't exchanged. */
+    ble_hs_lock();
+
+    i = 0;
+    while ((conn = ble_hs_conn_find_by_idx(i)) != NULL) {
+        chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+        BLE_HS_DBG_ASSERT(chan != NULL);
+
+        if (!(chan->blc_flags & BLE_L2CAP_CHAN_F_TXED_MTU)) {
+            chan->blc_my_mtu = mtu;
+        }
+
+        i++;
+    }
+
+    ble_hs_unlock();
 
     return 0;
 }


[19/50] [abbrv] incubator-mynewt-core git commit: fixing

Posted by cc...@apache.org.
fixing


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

Branch: refs/heads/master
Commit: 6e96e26732cdda69e613553c7d1d5f093f26dc42
Parents: 6181514
Author: NgesBrian <ng...@gmail.com>
Authored: Mon Aug 15 23:34:51 2016 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 09:20:59 2016 -0700

----------------------------------------------------------------------
 libs/os/src/test/callout_test.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e96e267/libs/os/src/test/callout_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/callout_test.c b/libs/os/src/test/callout_test.c
index a56efd5..4e3811d 100644
--- a/libs/os/src/test/callout_test.c
+++ b/libs/os/src/test/callout_test.c
@@ -121,6 +121,7 @@ callout_task_receive( void *arg)
 {
     int i;
     struct os_event *event;
+    struct os_callout_func *callout;
     os_time_t now;
     os_time_t tm;
     os_sr_t sr; 
@@ -128,6 +129,8 @@ callout_task_receive( void *arg)
     event = os_eventq_poll(&callout_func_test.cf_c.c_evq, 1, OS_WAIT_FOREVER);
     TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
     TEST_ASSERT(event->ev_arg == NULL);
+    callout = (struct os_callout_func *)event;
+    TEST_ASSERT(callout->cf_func == my_callout_func);
 
     /* Should say whether callout is armed or not */
     i = os_callout_queued(&callout_func_test.cf_c);
@@ -177,12 +180,16 @@ callout_task_stop_receive( void *arg )
 {
     int k;
     struct os_event *event;
+    struct os_callout_func *callout;
     /* Recieving using the os_eventq_poll */
     for(k=0; k<MULTI_SIZE; k++){
         event = os_eventq_poll(&callout_func_stop_test[k].cf_c.c_evq, 1,
            OS_WAIT_FOREVER);
         TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
         TEST_ASSERT(event->ev_arg == NULL);
+        callout = (struct os_callout_func *)event;
+        TEST_ASSERT(callout->cf_func == my_callout_stop_func);
+
 
      }
      
@@ -221,8 +228,13 @@ callout_task_stop_speak( void *arg )
 void
 callout_task_stop_listen( void *arg )
 {
-    os_eventq_get(callout_func_speak.cf_c.c_evq);
+    struct os_event *event;
+    struct os_callout_func *callout;
+    event = os_eventq_get(callout_func_speak.cf_c.c_evq);
     TEST_ASSERT_FATAL(0);
+    callout = (struct os_callout_func *)event;
+    TEST_ASSERT(callout->cf_func == my_callout_speak_func);
+
 }
 
 /* Test case to test the basics of the callout */
@@ -247,11 +259,9 @@ TEST_CASE(callout_test)
     /* Initialize the callout function */
     os_callout_func_init(&callout_func_test, &callout_evq,
         my_callout_func, NULL);
-    TEST_ASSERT(p == 4);
 
     /* Does not return until OS_restart is called */
     os_start();
-
 }
 
 /* Test case of the callout_task_stop */
@@ -279,8 +289,6 @@ TEST_CASE(callout_test_stop)
     for(k = 0; k<MULTI_SIZE; k++){
         os_callout_func_init(&callout_func_stop_test[k], &callout_stop_evq[k],
            my_callout_stop_func, NULL);
-         TEST_ASSERT(q == 1);
-
     }
 
     /* Does not return until OS_restart is called */
@@ -308,9 +316,7 @@ TEST_CASE(callout_test_speak)
     
     /* Initialize the callout function */
     os_callout_func_init(&callout_func_speak, &callout_evq,
-        my_callout_speak_func, NULL);
-    TEST_ASSERT(t == 2);
-    
+        my_callout_speak_func, NULL);    
     /* Does not return until OS_restart is called */
     os_start();
 


[02/50] [abbrv] incubator-mynewt-core git commit: Fix incorrect handling of multiple connections and starting encrypted links with all of them

Posted by cc...@apache.org.
Fix incorrect handling of multiple connections and starting encrypted links with all of them


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

Branch: refs/heads/master
Commit: 22fe6f2ed1eef48e6e18779c220e5ab7e5279a7c
Parents: 50d00eb
Author: William San Filippo <wi...@runtime.io>
Authored: Tue Aug 9 15:49:07 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Thu Aug 11 17:49:45 2016 -0700

----------------------------------------------------------------------
 apps/bletest/src/main.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/22fe6f2e/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index 5dd0cde..bfe8d50 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -659,6 +659,8 @@ bletest_execute_advertiser(void)
     int i;
 #if (BLETEST_CONCURRENT_CONN_TEST == 1)
     int j;
+    uint16_t mask;
+    uint16_t reply_handle;
 #endif
     int rc;
     uint16_t handle;
@@ -730,10 +732,16 @@ bletest_execute_advertiser(void)
     if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
 #if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
         /* Do we need to send a LTK reply? */
-        if (g_bletest_ltk_reply_handle) {
-            //bletest_send_ltk_req_neg_reply(g_bletest_ltk_reply_handle);
-            bletest_send_ltk_req_reply(g_bletest_ltk_reply_handle);
-            g_bletest_ltk_reply_handle = 0;
+        mask = 1;
+        reply_handle = 1;
+        while (g_bletest_ltk_reply_handle && mask) {
+            if (g_bletest_ltk_reply_handle & mask) {
+                bletest_send_ltk_req_reply(reply_handle);
+                //bletest_send_ltk_req_neg_reply(reply_handle);
+                g_bletest_ltk_reply_handle &= ~mask;
+            }
+            ++reply_handle;
+            mask <<= 1;
         }
 #endif
         if (g_bletest_current_conns) {


[28/50] [abbrv] incubator-mynewt-core git commit: boot, imgmgr; return the slot number for test image.

Posted by cc...@apache.org.
boot, imgmgr; return the slot number for test image.


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

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

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


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc0317c4/libs/bootutil/include/bootutil/bootutil_misc.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/include/bootutil/bootutil_misc.h b/libs/bootutil/include/bootutil/bootutil_misc.h
index e8834db..389366b 100644
--- a/libs/bootutil/include/bootutil/bootutil_misc.h
+++ b/libs/bootutil/include/bootutil/bootutil_misc.h
@@ -21,7 +21,7 @@
 #define __BOOTUTIL_MISC_H_
 
 struct image_version;
-int boot_vect_read_test(struct image_version *out_ver);
+int boot_vect_read_test(int *slot);
 int boot_vect_read_main(struct image_version *out_ver);
 int boot_vect_write_test(int slot);
 int boot_vect_write_main(struct image_version *ver);

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

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


[35/50] [abbrv] incubator-mynewt-core git commit: bootutil/imgmgr; output of boot now shows the fallback image.

Posted by cc...@apache.org.
bootutil/imgmgr; output of boot now shows the fallback image.


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

Branch: refs/heads/master
Commit: 1869d9b8c7ab4200e151a598bd9a12fd4acb69cf
Parents: 183be3a
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Aug 18 21:59:14 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:50 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/include/bootutil/bootutil_misc.h |   6 +-
 libs/bootutil/src/bootutil_misc.c              | 117 ++++++++++++--------
 libs/imgmgr/src/imgmgr.c                       |   2 +-
 libs/imgmgr/src/imgmgr_boot.c                  |  11 +-
 4 files changed, 83 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1869d9b8/libs/bootutil/include/bootutil/bootutil_misc.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/include/bootutil/bootutil_misc.h b/libs/bootutil/include/bootutil/bootutil_misc.h
index c018bb8..2e3049d 100644
--- a/libs/bootutil/include/bootutil/bootutil_misc.h
+++ b/libs/bootutil/include/bootutil/bootutil_misc.h
@@ -20,11 +20,9 @@
 #ifndef __BOOTUTIL_MISC_H_
 #define __BOOTUTIL_MISC_H_
 
-struct image_version;
 int boot_vect_read_test(int *slot);
-int boot_vect_read_main(struct image_version *out_ver);
+int boot_vect_read_main(int *slot);
 int boot_vect_write_test(int slot);
-int boot_vect_write_main(struct image_version *ver);
-void boot_confirm_ok(void);
+int boot_vect_write_main(void);
 
 #endif /*  __BOOTUTIL_MISC_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1869d9b8/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c b/libs/bootutil/src/bootutil_misc.c
index 595bb52..22ac921 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -26,10 +26,32 @@
 #include <os/os.h>
 #include <console/console.h>
 #include "bootutil/image.h"
+#include "bootutil/bootutil_misc.h"
 #include "bootutil_priv.h"
 
+/*
+ * Read the image trailer from a given slot.
+ */
+static int
+boot_vect_read_img_trailer(int slot, struct boot_img_trailer *bit)
+{
+    int rc;
+    const struct flash_area *fap;
+    uint32_t off;
+
+    rc = flash_area_open(slot, &fap);
+    if (rc) {
+        return rc;
+    }
+    off = fap->fa_size - sizeof(struct boot_img_trailer);
+    rc = flash_area_read(fap, off, bit, sizeof(*bit));
+    flash_area_close(fap);
+
+    return rc;
+}
+
 /**
- * Retrieves from the boot vector the version number of the test image (i.e.,
+ * Retrieves from the slot number of the test image (i.e.,
  * the image that has not been proven stable, and which will only run once).
  *
  * @param slot              On success, the slot number of image to boot.
@@ -39,19 +61,15 @@
 int
 boot_vect_read_test(int *slot)
 {
-    const struct flash_area *fap;
     struct boot_img_trailer bit;
     int i;
     int rc;
-    uint32_t off;
 
-    for (i = FLASH_AREA_IMAGE_1; i <= FLASH_AREA_IMAGE_1; i++) {
-        rc = flash_area_open(i, &fap);
-        if (rc) {
+    for (i = FLASH_AREA_IMAGE_0; i <= FLASH_AREA_IMAGE_1; i++) {
+        if (i == bsp_imgr_current_slot()) {
             continue;
         }
-        off = fap->fa_size - sizeof(struct boot_img_trailer);
-        rc = flash_area_read(fap, off, &bit, sizeof(bit));
+        rc = boot_vect_read_img_trailer(i, &bit);
         if (rc) {
             continue;
         }
@@ -64,16 +82,32 @@ boot_vect_read_test(int *slot)
 }
 
 /**
- * Retrieves from the boot vector the version number of the main image.
+ * Retrieves from the slot number of the main image. If this is
+ * different from test image slot, next restart will revert to main.
  *
  * @param out_ver           On success, the main version gets written here.
  *
  * @return                  0 on success; nonzero on failure.
  */
 int
-boot_vect_read_main(struct image_version *out_ver)
+boot_vect_read_main(int *slot)
 {
-    return -1;
+    int rc;
+    struct boot_img_trailer bit;
+
+    rc = boot_vect_read_img_trailer(FLASH_AREA_IMAGE_0, &bit);
+    assert(rc == 0);
+
+    if (bit.bit_copy_start != BOOT_IMG_MAGIC || bit.bit_img_ok != 0xff) {
+        /*
+         * If there never was copy that took place, or if the current
+         * image has been marked good, we'll keep booting it.
+         */
+        *slot = FLASH_AREA_IMAGE_0;
+    } else {
+        *slot = FLASH_AREA_IMAGE_1;
+    }
+    return 0;
 }
 
 /**
@@ -97,18 +131,43 @@ boot_vect_write_test(int slot)
     off = fap->fa_size - sizeof(struct boot_img_trailer);
     magic = BOOT_IMG_MAGIC;
 
-    return flash_area_write(fap, off, &magic, sizeof(magic));
+    rc = flash_area_write(fap, off, &magic, sizeof(magic));
+    flash_area_close(fap);
+
+    return rc;
 }
 
 /**
  * Deletes the main image version number from the boot vector.
+ * This must be called by the app to confirm that it is ok to keep booting
+ * to this image.
  *
  * @return                  0 on success; nonzero on failure.
  */
 int
-boot_vect_write_main(struct image_version *ver)
+boot_vect_write_main(void)
 {
-    return -1;
+    const struct flash_area *fap;
+    uint32_t off;
+    int rc;
+    uint8_t val;
+
+    /*
+     * Write to slot 0.
+     */
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    if (rc) {
+        return rc;
+    }
+
+    off = fap->fa_size - sizeof(struct boot_img_trailer);
+    off += (sizeof(uint32_t) + sizeof(uint8_t));
+    rc = flash_area_read(fap, off, &val, sizeof(val));
+    if (!rc && val == 0xff) {
+        val = 0;
+        rc = flash_area_write(fap, off, &val, sizeof(val));
+    }
+    return rc;
 }
 
 /**
@@ -261,33 +320,3 @@ boot_clear_status(void)
     off += sizeof(uint32_t);
     hal_flash_write(flash_id, off, &val, sizeof(val));
 }
-
-/*
- * This must be called by the app to confirm that it is ok to keep booting
- * to this image.
- *
- */
-void
-boot_confirm_ok(void)
-{
-    const struct flash_area *fap;
-    uint32_t off;
-    int rc;
-    uint8_t val;
-
-    /*
-     * Write to slot 0.
-     */
-    rc = flash_area_open(bsp_imgr_current_slot(), &fap);
-    if (rc) {
-        return;
-    }
-
-    off = fap->fa_size - sizeof(struct boot_img_trailer);
-    off += (sizeof(uint32_t) + sizeof(uint8_t));
-    rc = flash_area_read(fap, off, &val, sizeof(val));
-    if (!rc && val == 0xff) {
-        val = 0;
-        flash_area_write(fap, off, &val, sizeof(val));
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1869d9b8/libs/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr.c b/libs/imgmgr/src/imgmgr.c
index aac8574..ebdf1a8 100644
--- a/libs/imgmgr/src/imgmgr.c
+++ b/libs/imgmgr/src/imgmgr.c
@@ -496,7 +496,7 @@ imgmgr_module_init(void)
     rc = nmgr_group_register(&imgr_nmgr_group);
     assert(rc == 0);
 
-    boot_confirm_ok();
+    boot_vect_write_main();
 
     return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1869d9b8/libs/imgmgr/src/imgmgr_boot.c
----------------------------------------------------------------------
diff --git a/libs/imgmgr/src/imgmgr_boot.c b/libs/imgmgr/src/imgmgr_boot.c
index c252b9c..f636a5e 100644
--- a/libs/imgmgr/src/imgmgr_boot.c
+++ b/libs/imgmgr/src/imgmgr_boot.c
@@ -80,9 +80,12 @@ imgr_boot_read(struct nmgr_jbuf *njb)
         }
     }
 
-    rc = boot_vect_read_main(&ver);
+    rc = boot_vect_read_main(&slot);
     if (!rc) {
-        imgr_ver_jsonstr(enc, "main", &ver);
+        rc = imgr_read_info(slot, &ver, hash);
+        if (!rc) {
+            imgr_ver_jsonstr(enc, "main", &ver);
+        }
     }
 
     rc = imgr_read_info(bsp_imgr_current_slot(), &ver, hash);
@@ -179,9 +182,9 @@ imgr_boot2_read(struct nmgr_jbuf *njb)
         }
     }
 
-    rc = boot_vect_read_main(&ver);
+    rc = boot_vect_read_main(&slot);
     if (!rc) {
-        rc = imgr_find_by_ver(&ver, hash);
+        rc = imgr_read_info(slot, &ver, hash);
         if (rc >= 0) {
             imgr_hash_jsonstr(enc, "main", hash);
         }


[49/50] [abbrv] incubator-mynewt-core git commit: sim compiler - replace objsize with size

Posted by cc...@apache.org.
sim compiler - replace objsize with size

This appears to be a typo.  There is no tool called objsize.  size works
fine.

This only affects OS X.  It hasn't been a problem in the past when gcc-5
was used because the invocation of gobjdump was crashing with a message
like the following:

    2016/08/22 17:50:54 [DEBUG] o=gobjdump(68189,0x7fff71813000) malloc:
    *** error for object 0x1016002a0: pointer being freed was not
    allocated *** set a breakpoint in malloc_error_break to debug

When gobjdump crashed, newt ignored the error, but did not invoke the
size tool.

When clang is used instead of gcc, gobjdump doesn't crash, so the
incorrect size path is reported as a build failure.


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

Branch: refs/heads/master
Commit: 665e22f5722d6348c1b260192e27f69d855b58fd
Parents: 18c8837
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Aug 22 17:51:41 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Aug 22 17:51:41 2016 -0700

----------------------------------------------------------------------
 compiler/sim/compiler.yml | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/665e22f5/compiler/sim/compiler.yml
----------------------------------------------------------------------
diff --git a/compiler/sim/compiler.yml b/compiler/sim/compiler.yml
index 0eba296..225a4e9 100644
--- a/compiler/sim/compiler.yml
+++ b/compiler/sim/compiler.yml
@@ -42,7 +42,6 @@ compiler.ld.flags.LINUX: -lutil
 compiler.path.cc.DARWIN.OVERWRITE: "/usr/local/bin/gcc-5"
 compiler.path.as.DARWIN.OVERWRITE: "/usr/local/bin/gcc-5 -x assembler-with-cpp"
 compiler.path.objdump.DARWIN.OVERWRITE: "gobjdump"
-compiler.path.objsize.DARWIN.OVERWRITE: "objsize"
 compiler.path.objcopy.DARWIN.OVERWRITE: "gobjcopy"
 compiler.flags.base.DARWIN: >
     -DMN_OSX


[15/50] [abbrv] incubator-mynewt-core git commit: adding the test for os_callout

Posted by cc...@apache.org.
adding the test for os_callout


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

Branch: refs/heads/master
Commit: f8af60da488f0bad0887d6834deebd254e9dd9cd
Parents: 5f85bac
Author: NgesBrian <ng...@gmail.com>
Authored: Sat Aug 6 11:45:08 2016 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 09:20:59 2016 -0700

----------------------------------------------------------------------
 libs/os/src/test/callout_test.c | 130 +++++++++++++++++++++++++++++------
 1 file changed, 108 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f8af60da/libs/os/src/test/callout_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/callout_test.c b/libs/os/src/test/callout_test.c
index bb1644d..937b170 100644
--- a/libs/os/src/test/callout_test.c
+++ b/libs/os/src/test/callout_test.c
@@ -22,6 +22,7 @@
 #include "os_test_priv.h"
 #include "os/os_eventq.h"
 #include "os/os_callout.h"
+#include "os/os_time.h"
 
 /* Task 1 for sending */
 #define CALLOUT_STACK_SIZE        (5120)
@@ -60,6 +61,18 @@ struct os_callout_func callout_func_stop_test[MULTI_SIZE];
 struct os_eventq callout_stop_evq[MULTI_SIZE];
 struct os_event callout_stop_ev;
 
+/* Declearing varables for callout_speak */
+#define SPEAK_CALLOUT_TASK_PRIO        (5)
+struct os_task callout_task_struct_speak;
+os_stack_t callout_task_stack_speak[CALLOUT_STACK_SIZE];
+
+/* Declearing varaibles for listen */
+#define LISTEN_CALLOUT_TASK_PRIO        (6)
+struct os_task callout_task_struct_listen;
+os_stack_t callout_task_stack_listen[CALLOUT_STACK_SIZE];
+
+struct os_callout_func callout_func_speak;
+
 /* This is the function for callout_init*/
 void
 my_callout_func(void *arg)
@@ -69,7 +82,7 @@ my_callout_func(void *arg)
     TEST_ASSERT(p == 4);
 }
 
-/* This is the function for callout_init*/
+/* This is the function for callout_init of stop test_case*/
 void
 my_callout_stop_func(void *arg)
 {
@@ -77,13 +90,21 @@ my_callout_stop_func(void *arg)
     q = 1;
     TEST_ASSERT(q == 1);
 }
+/* This is the function for callout_init for speak test_case*/
+void
+my_callout_speak_func(void *arg)
+{
+    int p;
+    p = 4;
+    TEST_ASSERT(p == 4);
+}
 
 /* This is a callout task to send data */
 void
-callout_task_send()
+callout_task_send(void *arg )
 {
    
-    /* should say whether callout is armed or not */
+    /* Should say whether callout is armed or not */
     i= os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 0);
 
@@ -91,7 +112,7 @@ callout_task_send()
     i = os_callout_reset(&callout_func_test.cf_c, OS_TICKS_PER_SEC/ 50);
     TEST_ASSERT_FATAL(i == 0);
 
-    /* should say whether callout is armed or not */
+    /* Should say whether callout is armed or not */
     i = os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 1);
 
@@ -101,59 +122,69 @@ callout_task_send()
 
 /* This is the callout to receive data */
 void
-callout_task_receive(void *arg)
+callout_task_receive( void *arg)
 {
     struct os_event *event;
-    /* Recieving using the os_eventq_poll*/
+    os_time_t now;
+    os_time_t tm;
+    os_sr_t sr; 
+    /* Recieve using the os_eventq_poll */
     event = os_eventq_poll(&callout_func_test.cf_c.c_evq, 1, OS_WAIT_FOREVER);
     TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
     TEST_ASSERT(event->ev_arg == NULL);
 
     TEST_ASSERT(i == 1);
-    /* should say whether callout is armed or not */
+    /* Should say whether callout is armed or not */
     i = os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 0);
 
+    OS_ENTER_CRITICAL(sr);
+    now = os_time_get();
+    tm = os_callout_wakeup_ticks(now);
+    TEST_ASSERT(tm == OS_TIMEOUT_NEVER);
+    OS_EXIT_CRITICAL(sr);
+    
     /* Finishes the test when OS has been started */
     os_test_restart();
 
 }
 
-
 /* This is callout to send the stop_callout */
 void
-callout_task_stop_send()
+callout_task_stop_send( void *arg)
 {
      int k;
-     //os_time_t tim;
 
-     /* should say whether callout is armed or not */
+     /* Should say whether callout is armed or not */
     for(k = 0; k<MULTI_SIZE; k++){
         j = os_callout_queued(&callout_func_stop_test[k].cf_c);
         TEST_ASSERT(j == 0);
     }
 
-    /* show that  callout is not armed after calling callout_stop */
+    /* Show that  callout is not armed after calling callout_stop */
     for(k = 0; k<MULTI_SIZE; k++){
         os_callout_stop(&callout_func_stop_test[k].cf_c);
         j = os_callout_queued(&callout_func_stop_test[k].cf_c);
         TEST_ASSERT(j == 0);
     }
-    /* Assigning data to send*/
+    /* Assigning data to send */
     for(k = 0; k<MULTI_SIZE; k++){
         callout_func_stop_test[k].cf_c.c_ev.ev_type = 10+ k;
         callout_func_stop_test[k].cf_c.c_ev.ev_arg = NULL;
+
+         os_eventq_put(callout_func_stop_test[k].cf_c.c_evq,
+             &callout_func_stop_test[k].cf_c.c_ev);
     }
-    os_time_delay(OS_TICKS_PER_SEC );
+    os_time_delay( OS_TICKS_PER_SEC );
 }
 
 /* This is the callout to receive stop_callout data */
 void
-callout_task_stop_receive()
+callout_task_stop_receive( void *arg )
 {
     int k;
     struct os_event *event;
-    /* Recieving using the os_eventq_poll*/
+    /* Recieving using the os_eventq_poll */
     for(k=0; k<MULTI_SIZE; k++){
         event = os_eventq_poll(&callout_func_stop_test[k].cf_c.c_evq, 1,
            OS_WAIT_FOREVER);
@@ -161,19 +192,46 @@ callout_task_stop_receive()
         TEST_ASSERT(event->ev_arg == NULL);
      }
      
-    /* Showing that event is removed from the queued after calling callout_stop */    
+    /* Show that event is removed from the queued after calling callout_stop */
     for(k=0; k<MULTI_SIZE; k++){
         os_callout_stop(&callout_func_stop_test[k].cf_c);
-        event = os_eventq_poll(&callout_func_stop_test[k].cf_c.c_evq, MULTI_SIZE,
-            OS_WAIT_FOREVER);
-        TEST_ASSERT(event->ev_type != 10+k);
+        /* Testing that the event has been removed from queue */
+        TEST_ASSERT_FATAL(1); 
      }
+    /* Finishes the test when OS has been started */
+    os_test_restart();
+
+}
+
+/* This is a callout task to send data */
+void
+callout_task_stop_speak( void *arg )
+{
+    /* Arm the callout */
+    i = os_callout_reset(&callout_func_speak.cf_c, OS_TICKS_PER_SEC/ 50);
+    TEST_ASSERT_FATAL(i == 0);
 
+    /* should say whether callout is armed or not */
+    i = os_callout_queued(&callout_func_speak.cf_c);
+    TEST_ASSERT(i == 1);
+
+    os_callout_stop(&callout_func_speak.cf_c);
+    TEST_ASSERT(i == 1);
+    
+    /* Send the callout */ 
+    os_time_delay(OS_TICKS_PER_SEC/ 100 );
     /* Finishes the test when OS has been started */
     os_test_restart();
+}
 
+void
+callout_task_stop_listen( void *arg )
+{
+    os_eventq_get(callout_func_speak.cf_c.c_evq);
+    TEST_ASSERT_FATAL(0);
 }
 
+/* Test case to test the basics of the callout */
 TEST_CASE(callout_test)
 {
 
@@ -216,7 +274,7 @@ TEST_CASE(callout_test_stop)
     /* Initialize the receiving task */
     os_task_init(&callout_task_struct_stop_receive, "callout_task_stop_receive",
         callout_task_stop_receive, NULL, RECEIVE_STOP_CALLOUT_TASK_PRIO,
-            OS_WAIT_FOREVER, callout_task_stack_stop_receive, CALLOUT_STACK_SIZE);
+        OS_WAIT_FOREVER, callout_task_stack_stop_receive, CALLOUT_STACK_SIZE);
 
     for(k = 0; k< MULTI_SIZE; k++){
         os_eventq_init(&callout_stop_evq[k]);
@@ -233,8 +291,36 @@ TEST_CASE(callout_test_stop)
 
 }
 
+/* Test case to test case for speak and listen */
+TEST_CASE(callout_test_speak)
+{
+    /* Initializing the OS */
+    os_init();
+    
+    /* Initialize the sending task */
+    os_task_init(&callout_task_struct_speak, "callout_task_speak",
+        callout_task_stop_speak, NULL, SPEAK_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_speak, CALLOUT_STACK_SIZE);
+
+    /* Initialize the receive task */
+    os_task_init(&callout_task_struct_listen, "callout_task_listen",
+        callout_task_stop_listen, NULL, LISTEN_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_listen, CALLOUT_STACK_SIZE);
+
+    os_eventq_init(&callout_evq);
+    
+    /* Initialize the callout function */
+    os_callout_func_init(&callout_func_speak, &callout_evq,
+        my_callout_speak_func, NULL);
+
+    /* Does not return until OS_restart is called */
+    os_start();
+
+}
+
 TEST_SUITE(os_callout_test_suite)
 {   
-    //callout_test();
+    callout_test();
     callout_test_stop();
+    callout_test_speak();
 }


[27/50] [abbrv] incubator-mynewt-core git commit: bootutil; move routines reading boot-copy-status from loader.c to bootutil_misc.c.

Posted by cc...@apache.org.
bootutil; move routines reading boot-copy-status from loader.c to
bootutil_misc.c.


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

Branch: refs/heads/master
Commit: c29be5acf72dfebe61e5ac80b7c1daa53174dfef
Parents: 52a8e9f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Aug 17 10:48:42 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:49 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/src/bootutil_misc.c | 118 ++++++++++++++++++++++++++++++
 libs/bootutil/src/bootutil_priv.h |   5 ++
 libs/bootutil/src/loader.c        | 126 ++++++---------------------------
 3 files changed, 146 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c29be5ac/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c b/libs/bootutil/src/bootutil_misc.c
index 8ae5599..3885af9 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -22,6 +22,7 @@
 #include <hal/hal_flash.h>
 #include <hal/flash_map.h>
 #include <os/os.h>
+#include <console/console.h>
 #include "bootutil/image.h"
 #include "bootutil_priv.h"
 
@@ -120,3 +121,120 @@ boot_read_image_header(struct boot_image_location *loc,
     return rc;
 }
 
+/*
+ * How far has the copy progressed?
+ */
+static void
+boot_read_status_bytes(struct boot_status *bs, uint8_t flash_id, uint32_t off)
+{
+    uint8_t status;
+
+    off -= sizeof(status) * 2;
+    while (1) {
+        hal_flash_read(flash_id, off, &status, sizeof(status));
+        if (status == 0xff) {
+            break;
+        }
+        off--;
+        if (bs->state == 2) {
+            bs->idx++;
+            bs->state = 0;
+        } else {
+            bs->state++;
+        }
+    }
+}
+
+/**
+ * Reads the boot status from the flash.  The boot status contains
+ * the current state of an interrupted image copy operation.  If the boot
+ * status is not present, or it indicates that previous copy finished,
+ * there is no operation in progress.
+ */
+int
+boot_read_status(struct boot_status *bs)
+{
+    struct boot_img_trailer bit;
+    uint8_t flash_id;
+    uint32_t off;
+
+    /*
+     * Check if boot_img_trailer is in scratch, or at the end of slot0.
+     */
+    boot_slot_magic(0, &bit);
+    if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
+        boot_magic_loc(0, &flash_id, &off);
+        boot_read_status_bytes(bs, flash_id, off);
+        console_printf("status in slot0, %lu/%lu\n", bs->idx, bs->state);
+        return 1;
+    }
+    boot_scratch_magic(&bit);
+    if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
+        boot_scratch_loc(&flash_id, &off);
+        boot_read_status_bytes(bs, flash_id, off);
+        console_printf("status in scratch, %lu/%lu\n", bs->idx, bs->state);
+        return 1;
+    }
+    return 0;
+}
+
+#include <hal/hal_system.h>
+
+/**
+ * Writes the supplied boot status to the flash file system.  The boot status
+ * contains the current state of an in-progress image copy operation.
+ *
+ * @param bs                    The boot status to write.
+ *
+ * @return                      0 on success; nonzero on failure.
+ */
+int
+boot_write_status(struct boot_status *bs)
+{
+    uint32_t off;
+    uint8_t flash_id;
+    uint8_t val;
+
+    if (bs->idx == 0) {
+        /*
+         * Write to scratch
+         */
+        boot_scratch_loc(&flash_id, &off);
+    } else {
+        /*
+         * Write to slot 0;
+         */
+        boot_magic_loc(0, &flash_id, &off);
+    }
+    off -= ((3 * sizeof(uint8_t)) * bs->idx +
+      sizeof(uint8_t) * (bs->state + 1));
+
+    console_printf("status write, %lu/%lu -> %lx\n", bs->idx, bs->state, off);
+
+    val = bs->state;
+    hal_flash_write(flash_id, off, &val, sizeof(val));
+
+    return 0;
+}
+
+/**
+ * Finalizes the copy-in-progress status on the flash.  The boot status
+ * contains the current state of an in-progress image copy operation.  By
+ * clearing this, it is implied that there is no copy operation in
+ * progress.
+ */
+void
+boot_clear_status(void)
+{
+    uint32_t off;
+    uint32_t val = BOOT_IMG_MAGIC;
+    uint8_t flash_id;
+
+    /*
+     * Write to slot 0;
+     */
+    boot_magic_loc(0, &flash_id, &off);
+    off += sizeof(uint32_t);
+    hal_flash_write(flash_id, off, &val, sizeof(val));
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c29be5ac/libs/bootutil/src/bootutil_priv.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_priv.h b/libs/bootutil/src/bootutil_priv.h
index 3de5dd9..ffdfcb2 100644
--- a/libs/bootutil/src/bootutil_priv.h
+++ b/libs/bootutil/src/bootutil_priv.h
@@ -62,5 +62,10 @@ int boot_write_status(struct boot_status *bs);
 int boot_read_status(struct boot_status *bs);
 void boot_clear_status(void);
 
+void boot_magic_loc(int slot_num, uint8_t *flash_id, uint32_t *off);
+void boot_scratch_loc(uint8_t *flash_id, uint32_t *off);
+void boot_slot_magic(int slot_num, struct boot_img_trailer *bit);
+void boot_scratch_magic(struct boot_img_trailer *bit);
+
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c29be5ac/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index 65d0fc8..22187a7 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -24,7 +24,6 @@
 #include <hal/flash_map.h>
 #include <hal/hal_flash.h>
 #include <os/os_malloc.h>
-#include <console/console.h>
 #include "bootutil/loader.h"
 #include "bootutil/image.h"
 #include "bootutil/bootutil_misc.h"
@@ -67,7 +66,22 @@ boot_slot_addr(int slot_num, struct boot_image_location *loc)
     loc->bil_address = area_desc->fa_off;
 }
 
-static void
+/*
+ * Status about copy-in-progress is either in slot0 (target slot) or
+ * in scratch area. It is in scratch area if the process is currently
+ * moving the last sector within image.
+ *
+ * If the copy-in-progress status is within the image slot, it will
+ * be at the end of the area.
+ * If the sector containing the boot copy status is in scratch, it's
+ * offset from beginning of scratch depends on how much of the image
+ * fits inside the scratch area.
+ *
+ * We start copy from the end of image, so boot-copy-status is in
+ * scratch when the first area is being moved. Otherwise it will be
+ * in slot 0.
+ */
+void
 boot_magic_loc(int slot_num, uint8_t *flash_id, uint32_t *off)
 {
     struct boot_img *b;
@@ -77,7 +91,7 @@ boot_magic_loc(int slot_num, uint8_t *flash_id, uint32_t *off)
     *off = b->area + b->loc.bil_address - sizeof(struct boot_img_trailer);
 }
 
-static void
+void
 boot_scratch_loc(uint8_t *flash_id, uint32_t *off)
 {
     struct flash_area *scratch;
@@ -85,11 +99,15 @@ boot_scratch_loc(uint8_t *flash_id, uint32_t *off)
 
     scratch = &boot_req->br_area_descs[boot_req->br_scratch_area_idx];
     *flash_id = scratch->fa_flash_id;
+
+    /*
+     * Calculate where the boot status would be, if it was copied to scratch.
+     */
     *off = boot_copy_sz(boot_req->br_slot_areas[1], &cnt);
     *off += (scratch->fa_off - sizeof(struct boot_img_trailer));
 }
 
-static void
+void
 boot_slot_magic(int slot_num, struct boot_img_trailer *bit)
 {
     uint32_t off;
@@ -100,7 +118,7 @@ boot_slot_magic(int slot_num, struct boot_img_trailer *bit)
     hal_flash_read(flash_id, off, bit, sizeof(*bit));
 }
 
-static void
+void
 boot_scratch_magic(struct boot_img_trailer *bit)
 {
     uint32_t off;
@@ -400,104 +418,6 @@ boot_copy_image(void)
     return 0;
 }
 
-
-/*
- * Is copy in progress?
- */
-static void
-boot_read_status_bytes(struct boot_status *bs, uint8_t flash_id, uint32_t off)
-{
-    uint8_t status;
-
-    off -= sizeof(status) * 2;
-    while (1) {
-        hal_flash_read(flash_id, off, &status, sizeof(status));
-        if (status == 0xff) {
-            break;
-        }
-        off--;
-        if (bs->state == 2) {
-            bs->idx++;
-            bs->state = 0;
-        } else {
-            bs->state++;
-        }
-    }
-}
-
-int
-boot_read_status(struct boot_status *bs)
-{
-    struct boot_img_trailer bit;
-    uint8_t flash_id;
-    uint32_t off;
-
-    /*
-     * Check if boot_img_trailer is in scratch, or at the end of slot0.
-     */
-    boot_slot_magic(0, &bit);
-    if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
-        boot_magic_loc(0, &flash_id, &off);
-        boot_read_status_bytes(bs, flash_id, off);
-        console_printf("status in slot0, %lu/%lu\n", bs->idx, bs->state);
-        return 1;
-    }
-    boot_scratch_magic(&bit);
-    if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
-        boot_scratch_loc(&flash_id, &off);
-        boot_read_status_bytes(bs, flash_id, off);
-        console_printf("status in scratch, %lu/%lu\n", bs->idx, bs->state);
-        return 1;
-    }
-    return 0;
-}
-
-#include <hal/hal_system.h>
-
-int
-boot_write_status(struct boot_status *bs)
-{
-    uint32_t off;
-    uint8_t flash_id;
-    uint8_t val;
-
-    if (bs->idx == 0) {
-        /*
-         * Write to scratch
-         */
-        boot_scratch_loc(&flash_id, &off);
-    } else {
-        /*
-         * Write to slot 0;
-         */
-        boot_magic_loc(0, &flash_id, &off);
-    }
-    off -= ((3 * sizeof(uint8_t)) * bs->idx +
-      sizeof(uint8_t) * (bs->state + 1));
-
-    console_printf("status write, %lu/%lu -> %lx\n", bs->idx, bs->state, off);
-
-    val = bs->state;
-    hal_flash_write(flash_id, off, &val, sizeof(val));
-
-    return 0;
-}
-
-void
-boot_clear_status(void)
-{
-    uint32_t off;
-    uint32_t val = BOOT_IMG_MAGIC;
-    uint8_t flash_id;
-
-    /*
-     * Write to slot 0;
-     */
-    boot_magic_loc(0, &flash_id, &off);
-    off += sizeof(uint32_t);
-    hal_flash_write(flash_id, off, &val, sizeof(val));
-}
-
 /**
  * Prepares the booting process.  Based on the information provided in the
  * request object, this function moves images around in flash as appropriate,


[04/50] [abbrv] incubator-mynewt-core git commit: Use new acl data tx routine

Posted by cc...@apache.org.
Use new acl data tx routine


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

Branch: refs/heads/master
Commit: 5e3595d7b597bce180edeb96355379384eec3aeb
Parents: 726a600
Author: William San Filippo <wi...@runtime.io>
Authored: Thu Aug 11 15:49:05 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Thu Aug 11 17:49:46 2016 -0700

----------------------------------------------------------------------
 apps/bletest/src/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5e3595d7/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index bfe8d50..b6468a8 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -781,7 +781,7 @@ bletest_execute_advertiser(void)
 
                         /* Add length */
                         OS_MBUF_PKTHDR(om)->omp_len = om->om_len;
-                        ble_hci_trans_hs_acl_data_send(om);
+                        ble_hci_trans_hs_acl_tx(om);
 
                         /* Increment last handle used */
                         ++g_last_handle_used;


[31/50] [abbrv] incubator-mynewt-core git commit: boot/bootutil; remove debug console use from bootloader.

Posted by cc...@apache.org.
boot/bootutil; remove debug console use from bootloader.


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

Branch: refs/heads/master
Commit: 2331b503e4421e82aa67033752e66b4c8ab3dd72
Parents: 1869d9b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Aug 19 10:45:44 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:50 2016 -0700

----------------------------------------------------------------------
 apps/boot/pkg.yml                 | 2 +-
 apps/boot/src/boot.c              | 2 --
 libs/bootutil/src/bootutil_misc.c | 6 ------
 3 files changed, 1 insertion(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2331b503/apps/boot/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/boot/pkg.yml b/apps/boot/pkg.yml
index b877557..2cd19f5 100644
--- a/apps/boot/pkg.yml
+++ b/apps/boot/pkg.yml
@@ -33,7 +33,7 @@ pkg.deps:
     - libs/mbedtls
     - libs/os
     - libs/util
-    - libs/console/full
+    - libs/console/stub
 
 pkg.cflags: -DLOG_LEVEL=255
 pkg.cflags.NFFS:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2331b503/apps/boot/src/boot.c
----------------------------------------------------------------------
diff --git a/apps/boot/src/boot.c b/apps/boot/src/boot.c
index 37172ba..8ffcb1f 100755
--- a/apps/boot/src/boot.c
+++ b/apps/boot/src/boot.c
@@ -97,8 +97,6 @@ main(void)
 
     conf_init();
 
-    console_init(NULL);
-    console_printf("\nboot_loader\n");
 #ifdef BOOT_SERIAL
     /*
      * Configure a GPIO as input, and compare it against expected value.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2331b503/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c b/libs/bootutil/src/bootutil_misc.c
index 22ac921..6539bdd 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -24,7 +24,6 @@
 #include <hal/flash_map.h>
 #include <hal/hal_bsp.h>
 #include <os/os.h>
-#include <console/console.h>
 #include "bootutil/image.h"
 #include "bootutil/bootutil_misc.h"
 #include "bootutil_priv.h"
@@ -248,20 +247,17 @@ boot_read_status(struct boot_status *bs)
     if (bit.bit_copy_start == BOOT_IMG_MAGIC && bit.bit_copy_done == 0xff) {
         boot_magic_loc(0, &flash_id, &off);
         boot_read_status_bytes(bs, flash_id, off);
-        console_printf("status in slot0, %lu/%u\n", bs->idx, bs->state);
         return 1;
     }
     boot_scratch_magic(&bit);
     if (bit.bit_copy_start == BOOT_IMG_MAGIC && bit.bit_copy_done == 0xff) {
         boot_scratch_loc(&flash_id, &off);
         boot_read_status_bytes(bs, flash_id, off);
-        console_printf("status in scratch, %lu/%u\n", bs->idx, bs->state);
         return 1;
     }
     return 0;
 }
 
-#include <hal/hal_system.h>
 
 /**
  * Writes the supplied boot status to the flash file system.  The boot status
@@ -291,8 +287,6 @@ boot_write_status(struct boot_status *bs)
     }
     off -= ((3 * bs->elem_sz) * bs->idx + bs->elem_sz * (bs->state + 1));
 
-    console_printf("status write, %lu/%u -> %lx\n", bs->idx, bs->state, off);
-
     val = bs->state;
     hal_flash_write(flash_id, off, &val, sizeof(val));
 


[41/50] [abbrv] incubator-mynewt-core git commit: mbedtls; use smaller version of SHA256.

Posted by cc...@apache.org.
mbedtls; use smaller version of SHA256.


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

Branch: refs/heads/master
Commit: b02e6138d29c719180389fe4b66e90b1afac1071
Parents: c3cd5b1
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Aug 19 16:38:46 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 16:38:46 2016 -0700

----------------------------------------------------------------------
 libs/mbedtls/include/mbedtls/config_mynewt.h | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b02e6138/libs/mbedtls/include/mbedtls/config_mynewt.h
----------------------------------------------------------------------
diff --git a/libs/mbedtls/include/mbedtls/config_mynewt.h b/libs/mbedtls/include/mbedtls/config_mynewt.h
index d200879..a18ac6f 100644
--- a/libs/mbedtls/include/mbedtls/config_mynewt.h
+++ b/libs/mbedtls/include/mbedtls/config_mynewt.h
@@ -40,6 +40,8 @@
 #undef MBEDTLS_SELF_TEST
 #endif
 
+#define MBEDTLS_SHA256_SMALLER		/* comes with performance hit */
+
 /**
  * \name SECTION: Module configuration options
  *


[46/50] [abbrv] incubator-mynewt-core git commit: MYNEWT-354

Posted by cc...@apache.org.
MYNEWT-354

This fixes the compilation error when BLE_LL_CFG_FEAT_LE_ENCRYPTION
was set to 0. The issue here was that BLE_LL_CFG_FEAT_LE_PING cannot
be set to 1 if encryption is not defined (set to 0). Note that
LE_PING can be either defined or undefined (1 or 0) if encryption
is defined.


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

Branch: refs/heads/master
Commit: 6f3d956f863e03f52ef22513c4b8501a58d6843d
Parents: 4751ae0
Author: William San Filippo <wi...@runtime.io>
Authored: Mon Aug 22 15:00:45 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Mon Aug 22 15:05:12 2016 -0700

----------------------------------------------------------------------
 net/nimble/include/nimble/nimble_opt.h | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6f3d956f/net/nimble/include/nimble/nimble_opt.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/nimble_opt.h b/net/nimble/include/nimble/nimble_opt.h
index 2fd8228..c82bcb5 100644
--- a/net/nimble/include/nimble/nimble_opt.h
+++ b/net/nimble/include/nimble/nimble_opt.h
@@ -357,9 +357,14 @@
 /*
  * This option allows a controller to send/receive LE pings.
  */
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 0)
+#undef BLE_LL_CFG_FEAT_LE_PING
+#define BLE_LL_CFG_FEAT_LE_PING                 (0)
+#else
 #ifndef BLE_LL_CFG_FEAT_LE_PING
 #define  BLE_LL_CFG_FEAT_LE_PING                (1)
 #endif
+#endif
 
 /*
  * This option enables/disables the data length update procedure in the


[42/50] [abbrv] incubator-mynewt-core git commit: STM32f407 discovery board BSP

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/stm32f4discovery.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/stm32f4discovery.ld b/hw/bsp/stm32f4discovery/stm32f4discovery.ld
new file mode 100644
index 0000000..4c1541d
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/stm32f4discovery.ld
@@ -0,0 +1,213 @@
+/**
+ * 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.
+ */
+
+/* Linker script for STM32F407 when running from flash and using the bootloader */
+
+/* Linker script to configure memory regions. */
+MEMORY
+{ 
+  FLASH (rx) :  ORIGIN = 0x08020000, LENGTH = 384K /* First image slot. */
+  CCM (rwx) :   ORIGIN = 0x10000000, LENGTH = 64K
+  RAM (rwx) :   ORIGIN = 0x20000000, LENGTH = 128K
+}
+
+/* Linker script to place sections and symbol values. Should be used together
+ * with other linker script that defines memory regions FLASH and RAM.
+ * It references following symbols, which must be defined in code:
+ *   Reset_Handler : Entry of reset handler
+ * 
+ * It defines following symbols, which code can use without definition:
+ *   __exidx_start
+ *   __exidx_end
+ *   __etext
+ *   __data_start__
+ *   __preinit_array_start
+ *   __preinit_array_end
+ *   __init_array_start
+ *   __init_array_end
+ *   __fini_array_start
+ *   __fini_array_end
+ *   __data_end__
+ *   __bss_start__
+ *   __bss_end__
+ *   __end__
+ *   end
+ *   __HeapBase
+ *   __HeapLimit
+ *   __StackLimit
+ *   __StackTop
+ *   __stack
+ *   __coredata_start__
+ *   __coredata_end__
+ *   __corebss_start__
+ *   __corebss_end__
+ *   __ecoredata
+ *   __ecorebss
+ */
+ENTRY(Reset_Handler)
+
+SECTIONS
+{
+    /* Reserve space at the start of the image for the header. */
+    .imghdr (NOLOAD):
+    {
+        . = . + 0x20;
+    } > FLASH
+
+    .text :
+    {
+        __isr_vector_start = .;
+        KEEP(*(.isr_vector))
+        __isr_vector_end = .;
+        *(.text*)
+
+        KEEP(*(.init))
+        KEEP(*(.fini))
+
+        /* .ctors */
+        *crtbegin.o(.ctors)
+        *crtbegin?.o(.ctors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
+        *(SORT(.ctors.*))
+        *(.ctors)
+
+        /* .dtors */
+        *crtbegin.o(.dtors)
+        *crtbegin?.o(.dtors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
+        *(SORT(.dtors.*))
+        *(.dtors)
+
+        *(.rodata*)
+
+        KEEP(*(.eh_frame*))
+    } > FLASH
+
+    .ARM.extab : 
+    {
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
+    } > FLASH
+
+    __exidx_start = .;
+    .ARM.exidx :
+    {
+        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+    } > FLASH
+
+    __exidx_end = .;
+
+    __etext = .;
+
+    .vector_relocation :
+    {
+        . = ALIGN(4);
+        __vector_tbl_reloc__ = .;
+        . = . + (__isr_vector_end - __isr_vector_start);
+        . = ALIGN(4);
+    } > RAM
+
+    .coredata : AT (__etext)
+    {
+        __coredata_start__ = .;
+        *(.data.core)
+        . = ALIGN(4);
+        __coredata_end__ = .;
+    } > CCM
+
+    __ecoredata = __etext + SIZEOF(.coredata);
+        
+    .data : AT (__ecoredata)
+    {
+        __data_start__ = .;
+        *(vtable)
+        *(.data*)
+
+        /* preinit data */
+        PROVIDE_HIDDEN (__preinit_array_start = .);
+        KEEP(*(.preinit_array))
+        PROVIDE_HIDDEN (__preinit_array_end = .);
+
+        . = ALIGN(4);
+        /* init data */
+        PROVIDE_HIDDEN (__init_array_start = .);
+        KEEP(*(SORT(.init_array.*)))
+        KEEP(*(.init_array))
+        PROVIDE_HIDDEN (__init_array_end = .);
+
+
+        . = ALIGN(4);
+        /* finit data */
+        PROVIDE_HIDDEN (__fini_array_start = .);
+        KEEP(*(SORT(.fini_array.*)))
+        KEEP(*(.fini_array))
+        PROVIDE_HIDDEN (__fini_array_end = .);
+
+        KEEP(*(.jcr*))
+        . = ALIGN(4);
+        /* All data end */
+        __data_end__ = .;
+
+    } > RAM
+
+    .corebss (NOLOAD):
+    {
+        . = ALIGN(4);
+        __corebss_start__ = .;
+        *(.bss.core)
+        . = ALIGN(4);
+        __corebss_end__ = .;
+        *(.corebss*)
+        *(.bss.core.nz)
+        . = ALIGN(4);
+        __ecorebss = .;
+    } > CCM
+
+    .bss :
+    {
+        . = ALIGN(4);
+        __bss_start__ = .;
+        *(.bss*)
+        *(COMMON)
+        . = ALIGN(4);
+        __bss_end__ = .;
+    } > RAM
+
+    __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 */
+    .stack_dummy (COPY):
+    {
+        *(.stack*)
+    } > CCM
+
+    /* Set stack top to end of CCM; stack limit is bottom of stack */
+    __StackTop = ORIGIN(CCM) + LENGTH(CCM);
+    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
+    PROVIDE(__stack = __StackTop);
+    
+    /* Check for CCM overflow */
+    ASSERT(__StackLimit >= __ecorebss, "CCM overflow!")
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh b/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
new file mode 100644
index 0000000..c1a889b
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# 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.
+#
+# Called: $0 <bsp_path> <binary> [identities...]
+#  - bsp_directory_path is absolute path to hw/bsp/bsp_name
+#  - binary is the path to prefix to target binary, .elf appended to name is
+#    the ELF file
+#  - identities is the project identities string.
+# 
+#
+if [ $# -lt 2 ]; then
+    echo "Need binary to debug"
+    exit 1
+fi
+
+MY_PATH=$1
+FILE_NAME=$2.elf
+GDB_CMD_FILE=.gdb_cmds
+
+echo "Debugging" $FILE_NAME
+
+#
+# Block Ctrl-C from getting passed to openocd.
+# Exit openocd when gdb detaches.
+#
+set -m
+openocd -f board/stm32f4discovery.cfg -s $MY_PATH -c "gdb_port 3333; telnet_port 4444; stm32f4x.cpu configure -event gdb-detach {shutdown}" -c init -c "reset halt" &
+set +m
+
+echo "target remote localhost:3333" > $GDB_CMD_FILE
+arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME
+rm $GDB_CMD_FILE

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh b/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh
new file mode 100644
index 0000000..87013c6
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/stm32f4discovery_download.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+# 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.
+#
+# Called: $0 <bsp_directory_path> <binary> [features...]
+#  - bsp_directory_path is absolute path to hw/bsp/bsp_name
+#  - binary is the path to prefix to target binary, .elf.bin appended to this
+#    name is the raw binary format of the binary.
+#  - features are the target features. So you can have e.g. different
+#    flash offset for bootloader 'feature'
+# 
+#
+if [ $# -lt 2 ]; then
+    echo "Need binary to download"
+    exit 1
+fi
+
+MYPATH=$1
+BASENAME=$2
+IS_BOOTLOADER=0
+
+# Look for 'bootloader' from 3rd arg onwards
+shift
+shift
+while [ $# -gt 0 ]; do
+    if [ $1 = "bootloader" ]; then
+	IS_BOOTLOADER=1
+    fi
+    shift
+done
+
+if [ $IS_BOOTLOADER -eq 1 ]; then
+    FLASH_OFFSET=0x08000000
+    FILE_NAME=$BASENAME.elf.bin
+else
+    FLASH_OFFSET=0x08020000
+    FILE_NAME=$BASENAME.img
+fi
+echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
+
+openocd -f board/stm32f4discovery.cfg -s $MYPATH -c init -c "reset halt" -c "flash write_image erase $FILE_NAME $FLASH_OFFSET" -c "reset run" -c shutdown
+


[13/50] [abbrv] incubator-mynewt-core git commit: boot_serial; regression test on linux was failing to build.

Posted by cc...@apache.org.
boot_serial; regression test on linux was failing to build.

Reported by Nges.


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

Branch: refs/heads/master
Commit: 02f9f5277ff733512ce9d700d69034caa074e6a6
Parents: 63911e8
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Aug 15 13:21:58 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Aug 15 13:21:58 2016 -0700

----------------------------------------------------------------------
 libs/boot_serial/src/test/boot_test.c | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/02f9f527/libs/boot_serial/src/test/boot_test.c
----------------------------------------------------------------------
diff --git a/libs/boot_serial/src/test/boot_test.c b/libs/boot_serial/src/test/boot_test.c
index e11a649..8fe3425 100644
--- a/libs/boot_serial/src/test/boot_test.c
+++ b/libs/boot_serial/src/test/boot_test.c
@@ -25,6 +25,7 @@
 #include <inttypes.h>
 #include <util/base64.h>
 #include <util/crc16.h>
+#include <os/endian.h>
 #include <testutil/testutil.h>
 #include <hal/hal_flash.h>
 #include <hal/flash_map.h>


[34/50] [abbrv] incubator-mynewt-core git commit: slinky; time-based waits must use OS_TICKS_PER_SEC.

Posted by cc...@apache.org.
slinky; time-based waits must use OS_TICKS_PER_SEC.


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

Branch: refs/heads/master
Commit: 5213aca4e57b02223f65cc6e2fa4d9a14ea752b3
Parents: 4181439
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Aug 19 15:02:19 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:50 2016 -0700

----------------------------------------------------------------------
 apps/slinky/src/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5213aca4/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index fd68aa4..1ee66ac 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -220,7 +220,7 @@ task1_handler(void *arg)
         ++g_task1_loops;
 
         /* Wait one second */
-        os_time_delay(1000);
+        os_time_delay(OS_TICKS_PER_SEC);
 
         /* Toggle the LED */
         prev_pin_state = hal_gpio_read(g_led_pin);


[22/50] [abbrv] incubator-mynewt-core git commit: adding the test for os_callout

Posted by cc...@apache.org.
adding the test for os_callout


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

Branch: refs/heads/master
Commit: 3359c33c0c7ad49f0c8c4d1d3b4254c86cafee26
Parents: bc4c0a8
Author: NgesBrian <ng...@gmail.com>
Authored: Sun Jul 24 11:19:49 2016 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 09:20:59 2016 -0700

----------------------------------------------------------------------
 libs/os/src/test/callout_test.c | 71 +++++++++++++++++++++++++-----------
 1 file changed, 50 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3359c33c/libs/os/src/test/callout_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/callout_test.c b/libs/os/src/test/callout_test.c
index 034c2f4..350e94d 100644
--- a/libs/os/src/test/callout_test.c
+++ b/libs/os/src/test/callout_test.c
@@ -29,40 +29,61 @@
 struct os_task callout_task_struct_send;
 os_stack_t callout_task_stack_send[CALLOUT_STACK_SIZE];
 
-/* Initializing the callout 
-struct os_event callout_event;
-struct os_eventq callout_eventq;
-struct os_eventq callout_eventq_delivered;
-struct os_callout struct_callout;
-*/
+#define RECEIVE_CALLOUT_TASK_PRIO        (2)
+struct os_task callout_task_struct_receive;
+os_stack_t callout_task_stack_receive[CALLOUT_STACK_SIZE];
 
 /* Delearing variables for callout_func */
-struct os_callout_func callout_func;
-struct os_eventq callout_eventq;
+struct os_callout_func callout_func_test;
+struct os_eventq *callout_eventq;
 void native_cputimer_cb(void *arg);
 
+/* The event to be sent*/
+struct os_eventq callout_evq;
+struct os_event callout_ev;
+
 /* This is a callout task to send data */
 void
 callout_task_send()
 {
-    int i;
-    /*
-    struct_callout.c_ev = callout_event;
-    struct_callout.c_evq = &callout_eventq;
-    struct_callout.c_ticks = OS_TICKS_PER_SEC / 20;
-    */
-    /* Initialize the callout
-    os_callout_init(&struct_callout, &callout_eventq_delivered, NULL);
-    */
+   int i;
+    /* assigning the *callout_eventq */
+    callout_eventq = &callout_evq;
 
     /* Initialize the callout function */
-    os_callout_func_init(&callout_func, &callout_eventq,
+    os_callout_func_init(&callout_func_test, callout_eventq,
         native_cputimer_cb, NULL);
-    i = os_callout_queued((struct os_callout )callout_func);
+
+    /* should say whether os is armed or not */
+    i = os_callout_queued(&callout_func_test.cf_c);
+    TEST_ASSERT(i == 0);
+    
+    /* Arm the OS */
+    os_callout_reset(&callout_func_test.cf_c, OS_TICKS_PER_SEC/ 50);
+    
+    /* Send the callout */ 
+    os_time_delay(OS_TICKS_PER_SEC / 50);
     TEST_ASSERT(i == 0);
 }
 
-TEST_CASE(callout_test){
+void
+callout_task_receive(void *arg)
+{
+    struct os_event *event;
+    os_time_delay(OS_TICKS_PER_SEC / 20);
+    /* Recieving using the os_eventq_poll*/
+        event = os_eventq_poll(&callout_func_test.cf_c.c_evq, 1, OS_WAIT_FOREVER);
+        TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
+        TEST_ASSERT(event->ev_arg == NULL);
+
+
+    /* Finishes the test when OS has been started */
+    os_test_restart();
+
+}
+
+TEST_CASE(callout_test)
+{
 
     /* Initializing the OS */
     os_init();
@@ -72,11 +93,19 @@ TEST_CASE(callout_test){
         callout_task_send, NULL, SEND_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
         callout_task_stack_send, CALLOUT_STACK_SIZE);
 
+    /* Initialize the sending task */
+    os_task_init(&callout_task_struct_receive, "callout_task_receive",
+        callout_task_receive, NULL, RECEIVE_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_receive, CALLOUT_STACK_SIZE);
+
+    os_eventq_init(callout_eventq);
+    
     /* Does not return until OS_restart is called */
     os_start();
 
 }
 
-TEST_SUITE(os_callout_test_suite){   
+TEST_SUITE(os_callout_test_suite)
+{   
     callout_test();
 }


[20/50] [abbrv] incubator-mynewt-core git commit: corrections in the test callout

Posted by cc...@apache.org.
corrections in the test callout


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

Branch: refs/heads/master
Commit: 3946efd7979a370e7ad016aad9067ff71c6a8d9d
Parents: 0b7cd2f
Author: NgesBrian <ng...@gmail.com>
Authored: Wed Jul 27 21:34:10 2016 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 09:20:59 2016 -0700

----------------------------------------------------------------------
 libs/os/src/test/callout_test.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3946efd7/libs/os/src/test/callout_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/callout_test.c b/libs/os/src/test/callout_test.c
index 960a7fd..27241dd 100644
--- a/libs/os/src/test/callout_test.c
+++ b/libs/os/src/test/callout_test.c
@@ -40,19 +40,21 @@ struct os_callout_func callout_func_test;
 struct os_eventq callout_evq;
 struct os_event callout_ev;
 
+ int i; 
+ 
 /* This is the function for callout_init*/
 void my_callout_func(void *arg)
 {
-    int i;
-    i = 4;
-    TEST_ASSERT(i==4);
+    int p;
+    p = 4;
+    TEST_ASSERT(p==4);
 }
 
 /* This is a callout task to send data */
 void
 callout_task_send()
 {
-    int i; 
+   
     /* should say whether os is armed or not */
     i = os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 0);
@@ -67,24 +69,22 @@ callout_task_send()
 
     /* Send the callout */ 
     os_time_delay(OS_TICKS_PER_SEC );
-    TEST_ASSERT(i == 0);
-
-     /* should say whether os is armed or not */
-    i = os_callout_queued(&callout_func_test.cf_c);
-    TEST_ASSERT(i == 0);
-
 }
 
 void
 callout_task_receive(void *arg)
 {
     struct os_event *event;
-    os_time_delay(OS_TICKS_PER_SEC / 20);
     /* Recieving using the os_eventq_poll*/
         event = os_eventq_poll(&callout_func_test.cf_c.c_evq, 1, OS_WAIT_FOREVER);
         TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
         TEST_ASSERT(event->ev_arg == NULL);
 
+    TEST_ASSERT(i == 1);
+    /* should say whether os is armed or not */
+    i = os_callout_queued(&callout_func_test.cf_c);
+    TEST_ASSERT(i == 0);
+
     /* Finishes the test when OS has been started */
     os_test_restart();
 


[37/50] [abbrv] incubator-mynewt-core git commit: bootutil; add 'confirm' step, telling that image was confirmed as good. Otherwise next restart we'll go back to old image.

Posted by cc...@apache.org.
bootutil; add 'confirm' step, telling that image was confirmed as good.
Otherwise next restart we'll go back to old image.


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

Branch: refs/heads/master
Commit: a54ebc54c968870a23d016d38bcba962bee1c477
Parents: 857e611
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Aug 18 16:52:23 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:50 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/include/bootutil/bootutil_misc.h |  1 +
 libs/bootutil/src/bootutil_misc.c              | 41 ++++++++++++++++++---
 libs/bootutil/src/bootutil_priv.h              |  8 ++--
 libs/bootutil/src/loader.c                     | 14 ++++++-
 4 files changed, 54 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a54ebc54/libs/bootutil/include/bootutil/bootutil_misc.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/include/bootutil/bootutil_misc.h b/libs/bootutil/include/bootutil/bootutil_misc.h
index 389366b..c018bb8 100644
--- a/libs/bootutil/include/bootutil/bootutil_misc.h
+++ b/libs/bootutil/include/bootutil/bootutil_misc.h
@@ -25,5 +25,6 @@ int boot_vect_read_test(int *slot);
 int boot_vect_read_main(struct image_version *out_ver);
 int boot_vect_write_test(int slot);
 int boot_vect_write_main(struct image_version *ver);
+void boot_confirm_ok(void);
 
 #endif /*  __BOOTUTIL_MISC_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a54ebc54/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c b/libs/bootutil/src/bootutil_misc.c
index cf48f84..595bb52 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -22,6 +22,7 @@
 #include <assert.h>
 #include <hal/hal_flash.h>
 #include <hal/flash_map.h>
+#include <hal/hal_bsp.h>
 #include <os/os.h>
 #include <console/console.h>
 #include "bootutil/image.h"
@@ -54,7 +55,7 @@ boot_vect_read_test(int *slot)
         if (rc) {
             continue;
         }
-        if (bit.bit_start == BOOT_IMG_MAGIC) {
+        if (bit.bit_copy_start == BOOT_IMG_MAGIC) {
             *slot = i;
             return 0;
         }
@@ -185,14 +186,14 @@ boot_read_status(struct boot_status *bs)
      * Check if boot_img_trailer is in scratch, or at the end of slot0.
      */
     boot_slot_magic(0, &bit);
-    if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
+    if (bit.bit_copy_start == BOOT_IMG_MAGIC && bit.bit_copy_done == 0xff) {
         boot_magic_loc(0, &flash_id, &off);
         boot_read_status_bytes(bs, flash_id, off);
         console_printf("status in slot0, %lu/%u\n", bs->idx, bs->state);
         return 1;
     }
     boot_scratch_magic(&bit);
-    if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
+    if (bit.bit_copy_start == BOOT_IMG_MAGIC && bit.bit_copy_done == 0xff) {
         boot_scratch_loc(&flash_id, &off);
         boot_read_status_bytes(bs, flash_id, off);
         console_printf("status in scratch, %lu/%u\n", bs->idx, bs->state);
@@ -249,14 +250,44 @@ void
 boot_clear_status(void)
 {
     uint32_t off;
-    uint32_t val = BOOT_IMG_MAGIC;
+    uint8_t val = 0;
     uint8_t flash_id;
 
     /*
-     * Write to slot 0;
+     * Write to slot 0; boot_img_trailer is the 8 bytes within image slot.
+     * Here we say that copy operation was finished.
      */
     boot_magic_loc(0, &flash_id, &off);
     off += sizeof(uint32_t);
     hal_flash_write(flash_id, off, &val, sizeof(val));
 }
 
+/*
+ * This must be called by the app to confirm that it is ok to keep booting
+ * to this image.
+ *
+ */
+void
+boot_confirm_ok(void)
+{
+    const struct flash_area *fap;
+    uint32_t off;
+    int rc;
+    uint8_t val;
+
+    /*
+     * Write to slot 0.
+     */
+    rc = flash_area_open(bsp_imgr_current_slot(), &fap);
+    if (rc) {
+        return;
+    }
+
+    off = fap->fa_size - sizeof(struct boot_img_trailer);
+    off += (sizeof(uint32_t) + sizeof(uint8_t));
+    rc = flash_area_read(fap, off, &val, sizeof(val));
+    if (!rc && val == 0xff) {
+        val = 0;
+        flash_area_write(fap, off, &val, sizeof(val));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a54ebc54/libs/bootutil/src/bootutil_priv.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_priv.h b/libs/bootutil/src/bootutil_priv.h
index 697145d..585f75c 100644
--- a/libs/bootutil/src/bootutil_priv.h
+++ b/libs/bootutil/src/bootutil_priv.h
@@ -46,12 +46,14 @@ struct boot_status {
 };
 
 /*
- * End-of-image data structure.
+ * End-of-image slot data structure.
  */
 #define BOOT_IMG_MAGIC  0x12344321
 struct boot_img_trailer {
-    uint32_t bit_start;
-    uint32_t bit_done;
+    uint32_t bit_copy_start;
+    uint8_t  bit_copy_done;
+    uint8_t  bit_img_ok;
+    uint16_t _pad;
 };
 
 int bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig, int slen,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a54ebc54/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index 3171c05..b144c83 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -200,10 +200,19 @@ boot_select_image_slot(void)
     struct boot_img *b;
     struct boot_img_trailer bit;
 
+    boot_slot_magic(0, &bit);
+    if (bit.bit_copy_start == BOOT_IMG_MAGIC && bit.bit_copy_done != 0xff &&
+      bit.bit_img_ok == 0xff) {
+        /*
+         * Copied the image successfully, but image was not confirmed as good.
+         * We need to go back to another image.
+         */
+        boot_vect_write_test(FLASH_AREA_IMAGE_1);
+    }
     for (i = 1; i < BOOT_NUM_SLOTS; i++) {
         b = &boot_img[i];
         boot_slot_magic(i, &bit);
-        if (bit.bit_start == BOOT_IMG_MAGIC) {
+        if (bit.bit_copy_start == BOOT_IMG_MAGIC) {
             rc = boot_image_check(&b->hdr, &b->loc);
             if (rc) {
                 /*
@@ -473,7 +482,8 @@ boot_go(const struct boot_req *req, struct boot_rsp *rsp)
     }
 
     /*
-     * Check if we should initiate copy.
+     * Check if we should initiate copy, or revert back to earlier image.
+     *
      */
     slot = boot_select_image_slot();
     if (slot == -1) {


[14/50] [abbrv] incubator-mynewt-core git commit: MYNEWT-83: use a fixed buffer for reception.

Posted by cc...@apache.org.
MYNEWT-83: use a fixed buffer for reception.

The changes for this ticket caused the code to ack a packet at
the link layer even though it was not handed to the host. This
is an error; the link layer should only ack data packets that
were handed to the host.


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

Branch: refs/heads/master
Commit: 40c072ebdde316339581823525b5237d4c5565f4
Parents: 02f9f52
Author: William San Filippo <wi...@runtime.io>
Authored: Mon Aug 15 19:44:27 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Mon Aug 15 19:45:54 2016 -0700

----------------------------------------------------------------------
 .../controller/include/controller/ble_ll.h      | 11 +++
 .../controller/include/controller/ble_phy.h     |  8 +--
 net/nimble/controller/src/ble_ll.c              | 73 +++++++++++++++++++-
 net/nimble/controller/src/ble_ll_conn.c         | 24 +++++--
 net/nimble/drivers/native/src/ble_phy.c         | 55 +++++----------
 net/nimble/drivers/nrf51/src/ble_phy.c          | 62 +++++------------
 net/nimble/drivers/nrf52/src/ble_phy.c          | 62 +++++------------
 7 files changed, 149 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40c072eb/net/nimble/controller/include/controller/ble_ll.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h
index 51d725c..7865cf8 100644
--- a/net/nimble/controller/include/controller/ble_ll.h
+++ b/net/nimble/controller/include/controller/ble_ll.h
@@ -86,6 +86,7 @@ STATS_SECT_START(ble_ll_stats)
     STATS_SECT_ENTRY(hci_events_sent)
     STATS_SECT_ENTRY(bad_ll_state)
     STATS_SECT_ENTRY(bad_acl_hdr)
+    STATS_SECT_ENTRY(no_bufs)
     STATS_SECT_ENTRY(rx_adv_pdu_crc_ok)
     STATS_SECT_ENTRY(rx_adv_pdu_crc_err)
     STATS_SECT_ENTRY(rx_adv_bytes_crc_ok)
@@ -312,6 +313,16 @@ int ble_ll_is_our_devaddr(uint8_t *addr, int addr_type);
  */
 void ble_ll_acl_data_in(struct os_mbuf *txpkt);
 
+/**
+ * Allocate a pdu (chain) for reception.
+ *
+ * @param len Length of PDU. This includes the PDU header as well as payload.
+ * Does not include MIC if encrypted.
+ *
+ * @return struct os_mbuf* Pointer to mbuf chain to hold received packet
+ */
+struct os_mbuf *ble_ll_rxpdu_alloc(uint16_t len);
+
 /*--- PHY interfaces ---*/
 struct ble_mbuf_hdr;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40c072eb/net/nimble/controller/include/controller/ble_phy.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_phy.h b/net/nimble/controller/include/controller/ble_phy.h
index 74f349a..585c2dc 100644
--- a/net/nimble/controller/include/controller/ble_phy.h
+++ b/net/nimble/controller/include/controller/ble_phy.h
@@ -97,12 +97,8 @@ int ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans);
 /* Place the PHY into receive mode */
 int ble_phy_rx(void);
 
-/*
- * Retrieve the received PDU from the PHY. This returns an mbuf with
- * the most recently received PDU in it. It also contains the ble_hdr
- * as well
- */
-struct os_mbuf *ble_phy_rxpdu_get(uint8_t *dptr, uint16_t mblen);
+/* Copies the received PHY buffer into the allocated pdu */
+void ble_phy_rxpdu_copy(uint8_t *dptr, struct os_mbuf *rxpdu);
 
 /* Get an RSSI reading */
 int ble_phy_rssi_get(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40c072eb/net/nimble/controller/src/ble_ll.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c
index b8fcca5..3beb28e 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -151,6 +151,7 @@ STATS_NAME_START(ble_ll_stats)
     STATS_NAME(ble_ll_stats, hci_events_sent)
     STATS_NAME(ble_ll_stats, bad_ll_state)
     STATS_NAME(ble_ll_stats, bad_acl_hdr)
+    STATS_NAME(ble_ll_stats, no_bufs)
     STATS_NAME(ble_ll_stats, rx_adv_pdu_crc_ok)
     STATS_NAME(ble_ll_stats, rx_adv_pdu_crc_err)
     STATS_NAME(ble_ll_stats, rx_adv_bytes_crc_ok)
@@ -262,6 +263,68 @@ ble_ll_count_rx_adv_pdus(uint8_t pdu_type)
     }
 }
 
+/**
+ * Allocate a pdu (chain) for reception.
+ *
+ * @param len
+ *
+ * @return struct os_mbuf*
+ */
+struct os_mbuf *
+ble_ll_rxpdu_alloc(uint16_t len)
+{
+    uint16_t mb_bytes;
+    struct os_mbuf *m;
+    struct os_mbuf *n;
+    struct os_mbuf *p;
+    struct os_mbuf_pkthdr *pkthdr;
+
+    p = os_msys_get_pkthdr(len, sizeof(struct ble_mbuf_hdr));
+    if (!p) {
+        goto rxpdu_alloc_exit;
+    }
+
+    /* Set packet length */
+    pkthdr = OS_MBUF_PKTHDR(p);
+    pkthdr->omp_len = len;
+
+    /*
+     * NOTE: first mbuf in chain will have data pre-pended to it so we adjust
+     * m_data by a word.
+     */
+    p->om_data += 4;
+    mb_bytes = (p->om_omp->omp_databuf_len - p->om_pkthdr_len - 4);
+
+    if (mb_bytes < len) {
+        n = p;
+        len -= mb_bytes;
+        while (len) {
+            m = os_msys_get(len, 0);
+            if (!m) {
+                os_mbuf_free_chain(p);
+                p = NULL;
+                goto rxpdu_alloc_exit;
+            }
+            /* Chain new mbuf to existing chain */
+            SLIST_NEXT(n, om_next) = m;
+            n = m;
+            mb_bytes = m->om_omp->omp_databuf_len;
+            if (mb_bytes >= len) {
+                len = 0;
+            } else {
+                len -= mb_bytes;
+            }
+        }
+    }
+
+
+rxpdu_alloc_exit:
+    if (!p) {
+        STATS_INC(ble_ll_stats, no_bufs);
+    }
+    return p;
+}
+
 int
 ble_ll_chk_txrx_octets(uint16_t octets)
 {
@@ -806,13 +869,19 @@ ble_ll_rx_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
     switch (BLE_MBUF_HDR_RX_STATE(rxhdr)) {
     case BLE_LL_STATE_ADV:
         if (!badpkt) {
-            rxpdu = ble_phy_rxpdu_get(rxbuf, len + BLE_LL_PDU_HDR_LEN);
+            rxpdu = ble_ll_rxpdu_alloc(len + BLE_LL_PDU_HDR_LEN);
+            if (rxpdu) {
+                ble_phy_rxpdu_copy(rxbuf, rxpdu);
+            }
         }
         rc = ble_ll_adv_rx_isr_end(pdu_type, rxpdu, crcok);
         break;
     case BLE_LL_STATE_SCANNING:
         if (!badpkt) {
-            rxpdu = ble_phy_rxpdu_get(rxbuf, len + BLE_LL_PDU_HDR_LEN);
+            rxpdu = ble_ll_rxpdu_alloc(len + BLE_LL_PDU_HDR_LEN);
+            if (rxpdu) {
+                ble_phy_rxpdu_copy(rxbuf, rxpdu);
+            }
         }
         rc = ble_ll_scan_rx_isr_end(rxpdu, crcok);
         break;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40c072eb/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c
index fb95367..e3c40e2 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -2350,12 +2350,13 @@ init_rx_isr_exit:
      * We have to restart receive if we cant hand up pdu. We return 0 so that
      * the phy does not get disabled.
      */
-    rxpdu = ble_phy_rxpdu_get(rxbuf, pyld_len + BLE_LL_PDU_HDR_LEN);
+    rxpdu = ble_ll_rxpdu_alloc(pyld_len + BLE_LL_PDU_HDR_LEN);
     if (rxpdu == NULL) {
         ble_phy_disable();
         ble_phy_rx();
         rc = 0;
     } else {
+        ble_phy_rxpdu_copy(rxbuf, rxpdu);
         ble_ll_rx_pdu_in(rxpdu);
     }
 
@@ -2627,6 +2628,19 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
     struct os_mbuf *rxpdu;
     struct ble_mbuf_hdr *txhdr;
 
+    /* Retrieve the header and payload length */
+    hdr_byte = rxbuf[0];
+    rx_pyld_len = rxbuf[1];
+
+    /*
+     * We need to attempt to allocate a buffer here. The reason we do this
+     * now is that we should not ack the packet if we have no receive
+     * buffers available. We want to free up our transmit PDU if it was
+     * acked, but we should not ack the received frame if we cant hand it up.
+     * NOTE: we hand up empty pdu's to the LL task!
+     */
+    rxpdu = ble_ll_rxpdu_alloc(rx_pyld_len + BLE_LL_PDU_HDR_LEN);
+
     /*
      * We should have a current connection state machine. If we dont, we just
      * hand the packet to the higher layer to count it.
@@ -2638,10 +2652,6 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
         goto conn_exit;
     }
 
-    /* Set the handle in the ble mbuf header */
-    hdr_byte = rxbuf[0];
-    rx_pyld_len = rxbuf[1];
-
     /*
      * Check the packet CRC. A connection event can continue even if the
      * received PDU does not pass the CRC check. If we receive two consecutive
@@ -2686,7 +2696,7 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
          */
         hdr_sn = hdr_byte & BLE_LL_DATA_HDR_SN_MASK;
         conn_nesn = connsm->next_exp_seqnum;
-        if ((hdr_sn && conn_nesn) || (!hdr_sn && !conn_nesn)) {
+        if (rxpdu && ((hdr_sn && conn_nesn) || (!hdr_sn && !conn_nesn))) {
             connsm->next_exp_seqnum ^= 1;
 #if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
             if (CONN_F_ENCRYPTED(connsm) && !ble_ll_conn_is_empty_pdu(rxbuf)) {
@@ -2815,8 +2825,8 @@ chk_rx_terminate_ind:
 
 conn_exit:
     /* Copy the received pdu and hand it up */
-    rxpdu = ble_phy_rxpdu_get(rxbuf, rxbuf[1] + BLE_LL_PDU_HDR_LEN);
     if (rxpdu) {
+        ble_phy_rxpdu_copy(rxbuf, rxpdu);
         ble_ll_rx_pdu_in(rxpdu);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40c072eb/net/nimble/drivers/native/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/net/nimble/drivers/native/src/ble_phy.c b/net/nimble/drivers/native/src/ble_phy.c
index 4eb5d97..ff195fc 100644
--- a/net/nimble/drivers/native/src/ble_phy.c
+++ b/net/nimble/drivers/native/src/ble_phy.c
@@ -141,14 +141,15 @@ ble_xcvr_clear_irq(uint32_t mask)
 /**
  * Copies the data from the phy receive buffer into a mbuf chain.
  *
- *
  * @param dptr Pointer to receive buffer
- * @param len Length of receive buffer to copy.
+ * @param rxpdu Pointer to already allocated mbuf chain
+ *
+ * NOTE: the packet header already has the total mbuf length in it. The
+ * lengths of the individual mbufs are not set prior to calling.
  *
- * @return struct os_mbuf* Pointer to mbuf. NULL if no mbuf available.
  */
-struct os_mbuf *
-ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
+void
+ble_phy_rxpdu_copy(uint8_t *dptr, struct os_mbuf *rxpdu)
 {
     uint16_t rem_bytes;
     uint16_t mb_bytes;
@@ -156,35 +157,25 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
     uint32_t *dst;
     uint32_t *src;
     struct os_mbuf *m;
-    struct os_mbuf *n;
-    struct os_mbuf *p;
     struct ble_mbuf_hdr *ble_hdr;
     struct os_mbuf_pkthdr *pkthdr;
 
     /* Better be aligned */
     assert(((uint32_t)dptr & 3) == 0);
 
-    p = os_msys_get_pkthdr(len, sizeof(struct ble_mbuf_hdr));
-    if (!p) {
-        STATS_INC(ble_phy_stats, no_bufs);
-        return NULL;
-    }
+    pkthdr = OS_MBUF_PKTHDR(rxpdu);
+    rem_bytes = pkthdr->omp_len;
 
-    /*
-     * Fill in the mbuf pkthdr first. NOTE: first mbuf in chain will have data
-     * pre-pended to it so we adjust m_data by a word.
-     */
-    p->om_data += 4;
-    dst = (uint32_t *)(p->om_data);
+    /* Fill in the mbuf pkthdr first. */
+    dst = (uint32_t *)(rxpdu->om_data);
     src = (uint32_t *)dptr;
 
-    rem_bytes = len;
-    mb_bytes = (p->om_omp->omp_databuf_len - p->om_pkthdr_len - 4);
+    mb_bytes = (rxpdu->om_omp->omp_databuf_len - rxpdu->om_pkthdr_len - 4);
     copylen = min(mb_bytes, rem_bytes);
     copylen &= 0xFFFC;
     rem_bytes -= copylen;
     mb_bytes -= copylen;
-    p->om_len = copylen;
+    rxpdu->om_len = copylen;
     while (copylen > 0) {
         *dst = *src;
         ++dst;
@@ -193,7 +184,7 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
     }
 
     /* Copy remaining bytes */
-    m = p;
+    m = rxpdu;
     while (rem_bytes > 0) {
         /* If there are enough bytes in the mbuf, copy them and leave */
         if (rem_bytes <= mb_bytes) {
@@ -202,16 +193,8 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
             break;
         }
 
-        n = os_msys_get(rem_bytes, 0);
-        if (!n) {
-            os_mbuf_free_chain(p);
-            STATS_INC(ble_phy_stats, no_bufs);
-            return NULL;
-        }
-
-        /* Chain new mbuf to existing chain */
-        SLIST_NEXT(m, om_next) = n;
-        m = n;
+        m = SLIST_NEXT(m, om_next);
+        assert(m != NULL);
 
         mb_bytes = m->om_omp->omp_databuf_len;
         copylen = min(mb_bytes, rem_bytes);
@@ -228,15 +211,9 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
         }
     }
 
-    /* Set packet length */
-    pkthdr = OS_MBUF_PKTHDR(p);
-    pkthdr->omp_len = len;
-
     /* Copy ble header */
-    ble_hdr = BLE_MBUF_HDR_PTR(p);
+    ble_hdr = BLE_MBUF_HDR_PTR(rxpdu);
     memcpy(ble_hdr, &g_ble_phy_data.rxhdr, sizeof(struct ble_mbuf_hdr));
-
-    return p;
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40c072eb/net/nimble/drivers/nrf51/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/net/nimble/drivers/nrf51/src/ble_phy.c b/net/nimble/drivers/nrf51/src/ble_phy.c
index 15a2da7..a24a434 100644
--- a/net/nimble/drivers/nrf51/src/ble_phy.c
+++ b/net/nimble/drivers/nrf51/src/ble_phy.c
@@ -28,11 +28,6 @@
 #include "controller/ble_ll.h"
 #include "mcu/nrf51_bitfields.h"
 
-/*
- * XXX: need to make the copy from mbuf into the PHY data structures 32-bit
- * copies or we are screwed.
- */
-
 /* XXX: 4) Make sure RF is higher priority interrupt than schedule */
 
 /*
@@ -113,7 +108,6 @@ STATS_SECT_START(ble_phy_stats)
     STATS_SECT_ENTRY(rx_valid)
     STATS_SECT_ENTRY(rx_crc_err)
     STATS_SECT_ENTRY(rx_late)
-    STATS_SECT_ENTRY(no_bufs)
     STATS_SECT_ENTRY(radio_state_errs)
     STATS_SECT_ENTRY(rx_hw_err)
     STATS_SECT_ENTRY(tx_hw_err)
@@ -131,7 +125,6 @@ STATS_NAME_START(ble_phy_stats)
     STATS_NAME(ble_phy_stats, rx_valid)
     STATS_NAME(ble_phy_stats, rx_crc_err)
     STATS_NAME(ble_phy_stats, rx_late)
-    STATS_NAME(ble_phy_stats, no_bufs)
     STATS_NAME(ble_phy_stats, radio_state_errs)
     STATS_NAME(ble_phy_stats, rx_hw_err)
     STATS_NAME(ble_phy_stats, tx_hw_err)
@@ -187,14 +180,15 @@ struct nrf_ccm_data g_nrf_ccm_data;
 /**
  * Copies the data from the phy receive buffer into a mbuf chain.
  *
- *
  * @param dptr Pointer to receive buffer
- * @param len Length of receive buffer to copy.
+ * @param rxpdu Pointer to already allocated mbuf chain
+ *
+ * NOTE: the packet header already has the total mbuf length in it. The
+ * lengths of the individual mbufs are not set prior to calling.
  *
- * @return struct os_mbuf* Pointer to mbuf. NULL if no mbuf available.
  */
-struct os_mbuf *
-ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
+void
+ble_phy_rxpdu_copy(uint8_t *dptr, struct os_mbuf *rxpdu)
 {
     uint16_t rem_bytes;
     uint16_t mb_bytes;
@@ -202,35 +196,25 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
     uint32_t *dst;
     uint32_t *src;
     struct os_mbuf *m;
-    struct os_mbuf *n;
-    struct os_mbuf *p;
     struct ble_mbuf_hdr *ble_hdr;
     struct os_mbuf_pkthdr *pkthdr;
 
     /* Better be aligned */
     assert(((uint32_t)dptr & 3) == 0);
 
-    p = os_msys_get_pkthdr(len, sizeof(struct ble_mbuf_hdr));
-    if (!p) {
-        STATS_INC(ble_phy_stats, no_bufs);
-        return NULL;
-    }
+    pkthdr = OS_MBUF_PKTHDR(rxpdu);
+    rem_bytes = pkthdr->omp_len;
 
-    /*
-     * Fill in the mbuf pkthdr first. NOTE: first mbuf in chain will have data
-     * pre-pended to it so we adjust m_data by a word.
-     */
-    p->om_data += 4;
-    dst = (uint32_t *)(p->om_data);
+    /* Fill in the mbuf pkthdr first. */
+    dst = (uint32_t *)(rxpdu->om_data);
     src = (uint32_t *)dptr;
 
-    rem_bytes = len;
-    mb_bytes = (p->om_omp->omp_databuf_len - p->om_pkthdr_len - 4);
+    mb_bytes = (rxpdu->om_omp->omp_databuf_len - rxpdu->om_pkthdr_len - 4);
     copylen = min(mb_bytes, rem_bytes);
     copylen &= 0xFFFC;
     rem_bytes -= copylen;
     mb_bytes -= copylen;
-    p->om_len = copylen;
+    rxpdu->om_len = copylen;
     while (copylen > 0) {
         *dst = *src;
         ++dst;
@@ -239,7 +223,7 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
     }
 
     /* Copy remaining bytes */
-    m = p;
+    m = rxpdu;
     while (rem_bytes > 0) {
         /* If there are enough bytes in the mbuf, copy them and leave */
         if (rem_bytes <= mb_bytes) {
@@ -248,16 +232,8 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
             break;
         }
 
-        n = os_msys_get(rem_bytes, 0);
-        if (!n) {
-            os_mbuf_free_chain(p);
-            STATS_INC(ble_phy_stats, no_bufs);
-            return NULL;
-        }
-
-        /* Chain new mbuf to existing chain */
-        SLIST_NEXT(m, om_next) = n;
-        m = n;
+        m = SLIST_NEXT(m, om_next);
+        assert(m != NULL);
 
         mb_bytes = m->om_omp->omp_databuf_len;
         copylen = min(mb_bytes, rem_bytes);
@@ -274,15 +250,9 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
         }
     }
 
-    /* Set packet length */
-    pkthdr = OS_MBUF_PKTHDR(p);
-    pkthdr->omp_len = len;
-
     /* Copy ble header */
-    ble_hdr = BLE_MBUF_HDR_PTR(p);
+    ble_hdr = BLE_MBUF_HDR_PTR(rxpdu);
     memcpy(ble_hdr, &g_ble_phy_data.rxhdr, sizeof(struct ble_mbuf_hdr));
-
-    return p;
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40c072eb/net/nimble/drivers/nrf52/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/net/nimble/drivers/nrf52/src/ble_phy.c b/net/nimble/drivers/nrf52/src/ble_phy.c
index 8ffab96..2e34669 100644
--- a/net/nimble/drivers/nrf52/src/ble_phy.c
+++ b/net/nimble/drivers/nrf52/src/ble_phy.c
@@ -29,11 +29,6 @@
 #include "controller/ble_ll.h"
 #include "mcu/nrf52_bitfields.h"
 
-/*
- * XXX: need to make the copy from mbuf into the PHY data structures 32-bit
- * copies or we are screwed.
- */
-
 /* XXX: 4) Make sure RF is higher priority interrupt than schedule */
 
 /*
@@ -107,7 +102,6 @@ STATS_SECT_START(ble_phy_stats)
     STATS_SECT_ENTRY(rx_valid)
     STATS_SECT_ENTRY(rx_crc_err)
     STATS_SECT_ENTRY(rx_late)
-    STATS_SECT_ENTRY(no_bufs)
     STATS_SECT_ENTRY(radio_state_errs)
     STATS_SECT_ENTRY(rx_hw_err)
     STATS_SECT_ENTRY(tx_hw_err)
@@ -125,7 +119,6 @@ STATS_NAME_START(ble_phy_stats)
     STATS_NAME(ble_phy_stats, rx_valid)
     STATS_NAME(ble_phy_stats, rx_crc_err)
     STATS_NAME(ble_phy_stats, rx_late)
-    STATS_NAME(ble_phy_stats, no_bufs)
     STATS_NAME(ble_phy_stats, radio_state_errs)
     STATS_NAME(ble_phy_stats, rx_hw_err)
     STATS_NAME(ble_phy_stats, tx_hw_err)
@@ -188,14 +181,15 @@ struct nrf_ccm_data g_nrf_ccm_data;
 /**
  * Copies the data from the phy receive buffer into a mbuf chain.
  *
- *
  * @param dptr Pointer to receive buffer
- * @param len Length of receive buffer to copy.
+ * @param rxpdu Pointer to already allocated mbuf chain
+ *
+ * NOTE: the packet header already has the total mbuf length in it. The
+ * lengths of the individual mbufs are not set prior to calling.
  *
- * @return struct os_mbuf* Pointer to mbuf. NULL if no mbuf available.
  */
-struct os_mbuf *
-ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
+void
+ble_phy_rxpdu_copy(uint8_t *dptr, struct os_mbuf *rxpdu)
 {
     uint16_t rem_bytes;
     uint16_t mb_bytes;
@@ -203,35 +197,25 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
     uint32_t *dst;
     uint32_t *src;
     struct os_mbuf *m;
-    struct os_mbuf *n;
-    struct os_mbuf *p;
     struct ble_mbuf_hdr *ble_hdr;
     struct os_mbuf_pkthdr *pkthdr;
 
     /* Better be aligned */
     assert(((uint32_t)dptr & 3) == 0);
 
-    p = os_msys_get_pkthdr(len, sizeof(struct ble_mbuf_hdr));
-    if (!p) {
-        STATS_INC(ble_phy_stats, no_bufs);
-        return NULL;
-    }
+    pkthdr = OS_MBUF_PKTHDR(rxpdu);
+    rem_bytes = pkthdr->omp_len;
 
-    /*
-     * Fill in the mbuf pkthdr first. NOTE: first mbuf in chain will have data
-     * pre-pended to it so we adjust m_data by a word.
-     */
-    p->om_data += 4;
-    dst = (uint32_t *)(p->om_data);
+    /* Fill in the mbuf pkthdr first. */
+    dst = (uint32_t *)(rxpdu->om_data);
     src = (uint32_t *)dptr;
 
-    rem_bytes = len;
-    mb_bytes = (p->om_omp->omp_databuf_len - p->om_pkthdr_len - 4);
+    mb_bytes = (rxpdu->om_omp->omp_databuf_len - rxpdu->om_pkthdr_len - 4);
     copylen = min(mb_bytes, rem_bytes);
     copylen &= 0xFFFC;
     rem_bytes -= copylen;
     mb_bytes -= copylen;
-    p->om_len = copylen;
+    rxpdu->om_len = copylen;
     while (copylen > 0) {
         *dst = *src;
         ++dst;
@@ -240,7 +224,7 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
     }
 
     /* Copy remaining bytes */
-    m = p;
+    m = rxpdu;
     while (rem_bytes > 0) {
         /* If there are enough bytes in the mbuf, copy them and leave */
         if (rem_bytes <= mb_bytes) {
@@ -249,16 +233,8 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
             break;
         }
 
-        n = os_msys_get(rem_bytes, 0);
-        if (!n) {
-            os_mbuf_free_chain(p);
-            STATS_INC(ble_phy_stats, no_bufs);
-            return NULL;
-        }
-
-        /* Chain new mbuf to existing chain */
-        SLIST_NEXT(m, om_next) = n;
-        m = n;
+        m = SLIST_NEXT(m, om_next);
+        assert(m != NULL);
 
         mb_bytes = m->om_omp->omp_databuf_len;
         copylen = min(mb_bytes, rem_bytes);
@@ -275,15 +251,9 @@ ble_phy_rxpdu_get(uint8_t *dptr, uint16_t len)
         }
     }
 
-    /* Set packet length */
-    pkthdr = OS_MBUF_PKTHDR(p);
-    pkthdr->omp_len = len;
-
     /* Copy ble header */
-    ble_hdr = BLE_MBUF_HDR_PTR(p);
+    ble_hdr = BLE_MBUF_HDR_PTR(rxpdu);
     memcpy(ble_hdr, &g_ble_phy_data.rxhdr, sizeof(struct ble_mbuf_hdr));
-
-    return p;
 }
 
 /**


[32/50] [abbrv] incubator-mynewt-core git commit: bootutil; was returning wrong image header in response when swithing images. Add boot_set_req() routine for unit test use.

Posted by cc...@apache.org.
bootutil; was returning wrong image header in response when
swithing images. Add boot_set_req() routine for unit test use.


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

Branch: refs/heads/master
Commit: ce4f1902cc4873937793fd527bd253f105f0d47b
Parents: 2331b50
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Aug 19 14:51:49 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:50 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/src/bootutil_priv.h |  3 +++
 libs/bootutil/src/loader.c        | 10 +++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ce4f1902/libs/bootutil/src/bootutil_priv.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_priv.h b/libs/bootutil/src/bootutil_priv.h
index 585f75c..7fe6eac 100644
--- a/libs/bootutil/src/bootutil_priv.h
+++ b/libs/bootutil/src/bootutil_priv.h
@@ -70,5 +70,8 @@ void boot_scratch_loc(uint8_t *flash_id, uint32_t *off);
 void boot_slot_magic(int slot_num, struct boot_img_trailer *bit);
 void boot_scratch_magic(struct boot_img_trailer *bit);
 
+struct boot_req;
+void boot_req_set(struct boot_req *req);
+
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ce4f1902/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index b144c83..8037c98 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -47,6 +47,12 @@ static struct boot_status boot_state;
 static int boot_erase_area(int area_idx, uint32_t sz);
 static uint32_t boot_copy_sz(int max_idx, int *cnt);
 
+void
+boot_req_set(struct boot_req *req)
+{
+    boot_req = req;
+}
+
 /**
  * Calculates the flash offset of the specified image slot.
  *
@@ -491,6 +497,8 @@ boot_go(const struct boot_req *req, struct boot_rsp *rsp)
     }
 
     if (slot) {
+        boot_state.idx = 0;
+        boot_state.state = 0;
         rc = boot_copy_image();
         if (rc) {
             return rc;
@@ -500,7 +508,7 @@ boot_go(const struct boot_req *req, struct boot_rsp *rsp)
     /* Always boot from the primary slot. */
     rsp->br_flash_id = boot_img[0].loc.bil_flash_id;
     rsp->br_image_addr = boot_img[0].loc.bil_address;
-    rsp->br_hdr = &boot_img[0].hdr;
+    rsp->br_hdr = &boot_img[slot].hdr;
 
     return 0;
 }


[16/50] [abbrv] incubator-mynewt-core git commit: just adding more code

Posted by cc...@apache.org.
just adding more code


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

Branch: refs/heads/master
Commit: 5f85bacc6125cbf92ba524fcb8124c2a76a731c4
Parents: eacd968
Author: NgesBrian <ng...@gmail.com>
Authored: Sat Jul 30 09:16:27 2016 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 09:20:59 2016 -0700

----------------------------------------------------------------------
 libs/os/src/test/callout_test.c | 135 ++++++++++++++++++++++++++++++++---
 1 file changed, 126 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f85bacc/libs/os/src/test/callout_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/callout_test.c b/libs/os/src/test/callout_test.c
index f239db7..bb1644d 100644
--- a/libs/os/src/test/callout_test.c
+++ b/libs/os/src/test/callout_test.c
@@ -40,14 +40,42 @@ struct os_callout_func callout_func_test;
 struct os_eventq callout_evq;
 struct os_event callout_ev;
 
- int i; 
+int i; 
+int j;
  
+/* The callout_stop task */
+#define SEND_STOP_CALLOUT_TASK_PRIO        (3)
+struct os_task callout_task_struct_stop_send;
+os_stack_t callout_task_stack_stop_send[CALLOUT_STACK_SIZE];
+
+#define RECEIVE_STOP_CALLOUT_TASK_PRIO        (4)
+struct os_task callout_task_struct_stop_receive;
+os_stack_t callout_task_stack_stop_receive[CALLOUT_STACK_SIZE];
+
+/* Delearing variables for callout_stop_func */
+#define MULTI_SIZE    (2)
+struct os_callout_func callout_func_stop_test[MULTI_SIZE];
+
+/* The event to be sent*/
+struct os_eventq callout_stop_evq[MULTI_SIZE];
+struct os_event callout_stop_ev;
+
 /* This is the function for callout_init*/
-void my_callout_func(void *arg)
+void
+my_callout_func(void *arg)
 {
     int p;
     p = 4;
-    TEST_ASSERT(p==4);
+    TEST_ASSERT(p == 4);
+}
+
+/* This is the function for callout_init*/
+void
+my_callout_stop_func(void *arg)
+{
+    int q;
+    q = 1;
+    TEST_ASSERT(q == 1);
 }
 
 /* This is a callout task to send data */
@@ -56,7 +84,7 @@ callout_task_send()
 {
    
     /* should say whether callout is armed or not */
-    i = os_callout_queued(&callout_func_test.cf_c);
+    i= os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 0);
 
     /* Arm the callout */
@@ -71,14 +99,15 @@ callout_task_send()
     os_time_delay(OS_TICKS_PER_SEC );
 }
 
+/* This is the callout to receive data */
 void
 callout_task_receive(void *arg)
 {
     struct os_event *event;
     /* Recieving using the os_eventq_poll*/
-        event = os_eventq_poll(&callout_func_test.cf_c.c_evq, 1, OS_WAIT_FOREVER);
-        TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
-        TEST_ASSERT(event->ev_arg == NULL);
+    event = os_eventq_poll(&callout_func_test.cf_c.c_evq, 1, OS_WAIT_FOREVER);
+    TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
+    TEST_ASSERT(event->ev_arg == NULL);
 
     TEST_ASSERT(i == 1);
     /* should say whether callout is armed or not */
@@ -90,6 +119,61 @@ callout_task_receive(void *arg)
 
 }
 
+
+/* This is callout to send the stop_callout */
+void
+callout_task_stop_send()
+{
+     int k;
+     //os_time_t tim;
+
+     /* should say whether callout is armed or not */
+    for(k = 0; k<MULTI_SIZE; k++){
+        j = os_callout_queued(&callout_func_stop_test[k].cf_c);
+        TEST_ASSERT(j == 0);
+    }
+
+    /* show that  callout is not armed after calling callout_stop */
+    for(k = 0; k<MULTI_SIZE; k++){
+        os_callout_stop(&callout_func_stop_test[k].cf_c);
+        j = os_callout_queued(&callout_func_stop_test[k].cf_c);
+        TEST_ASSERT(j == 0);
+    }
+    /* Assigning data to send*/
+    for(k = 0; k<MULTI_SIZE; k++){
+        callout_func_stop_test[k].cf_c.c_ev.ev_type = 10+ k;
+        callout_func_stop_test[k].cf_c.c_ev.ev_arg = NULL;
+    }
+    os_time_delay(OS_TICKS_PER_SEC );
+}
+
+/* This is the callout to receive stop_callout data */
+void
+callout_task_stop_receive()
+{
+    int k;
+    struct os_event *event;
+    /* Recieving using the os_eventq_poll*/
+    for(k=0; k<MULTI_SIZE; k++){
+        event = os_eventq_poll(&callout_func_stop_test[k].cf_c.c_evq, 1,
+           OS_WAIT_FOREVER);
+        TEST_ASSERT(event->ev_type == 10+k);
+        TEST_ASSERT(event->ev_arg == NULL);
+     }
+     
+    /* Showing that event is removed from the queued after calling callout_stop */    
+    for(k=0; k<MULTI_SIZE; k++){
+        os_callout_stop(&callout_func_stop_test[k].cf_c);
+        event = os_eventq_poll(&callout_func_stop_test[k].cf_c.c_evq, MULTI_SIZE,
+            OS_WAIT_FOREVER);
+        TEST_ASSERT(event->ev_type != 10+k);
+     }
+
+    /* Finishes the test when OS has been started */
+    os_test_restart();
+
+}
+
 TEST_CASE(callout_test)
 {
 
@@ -101,7 +185,7 @@ TEST_CASE(callout_test)
         callout_task_send, NULL, SEND_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
         callout_task_stack_send, CALLOUT_STACK_SIZE);
 
-    /* Initialize the sending task */
+    /* Initialize the receive task */
     os_task_init(&callout_task_struct_receive, "callout_task_receive",
         callout_task_receive, NULL, RECEIVE_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
         callout_task_stack_receive, CALLOUT_STACK_SIZE);
@@ -117,7 +201,40 @@ TEST_CASE(callout_test)
 
 }
 
+/* Test case of the callout_task_stop */
+TEST_CASE(callout_test_stop)
+{
+    int k;
+    /* Initializing the OS */
+    os_init();
+
+    /* Initialize the sending task */
+    os_task_init(&callout_task_struct_stop_send, "callout_task_stop_send",
+        callout_task_stop_send, NULL, SEND_STOP_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_stop_send, CALLOUT_STACK_SIZE);
+
+    /* Initialize the receiving task */
+    os_task_init(&callout_task_struct_stop_receive, "callout_task_stop_receive",
+        callout_task_stop_receive, NULL, RECEIVE_STOP_CALLOUT_TASK_PRIO,
+            OS_WAIT_FOREVER, callout_task_stack_stop_receive, CALLOUT_STACK_SIZE);
+
+    for(k = 0; k< MULTI_SIZE; k++){
+        os_eventq_init(&callout_stop_evq[k]);
+    }
+    
+    /* Initialize the callout function */
+    for(k = 0; k<MULTI_SIZE; k++){
+        os_callout_func_init(&callout_func_stop_test[k], &callout_stop_evq[k],
+           my_callout_stop_func, NULL);
+    }
+
+    /* Does not return until OS_restart is called */
+    os_start();
+
+}
+
 TEST_SUITE(os_callout_test_suite)
 {   
-    callout_test();
+    //callout_test();
+    callout_test_stop();
 }


[24/50] [abbrv] incubator-mynewt-core git commit: This closes #81.

Posted by cc...@apache.org.
This closes #81.

Merge branch 'nffs-update' of https://github.com/peterfs/incubator-mynewt-core into develop


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

Branch: refs/heads/master
Commit: c0f685b406bcf9f54a374b6ce122bca76d1c51c2
Parents: 6e96e26 fd74367
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Aug 18 09:56:32 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 09:56:32 2016 -0700

----------------------------------------------------------------------
 apps/ffs2native/src/main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------



[17/50] [abbrv] incubator-mynewt-core git commit: correction of comments

Posted by cc...@apache.org.
correction of comments


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

Branch: refs/heads/master
Commit: eacd9681ba0d577fac2c30a9a68fd73436c937d5
Parents: 3946efd
Author: NgesBrian <ng...@gmail.com>
Authored: Thu Jul 28 03:49:42 2016 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 18 09:20:59 2016 -0700

----------------------------------------------------------------------
 libs/os/src/test/callout_test.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eacd9681/libs/os/src/test/callout_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/callout_test.c b/libs/os/src/test/callout_test.c
index 27241dd..f239db7 100644
--- a/libs/os/src/test/callout_test.c
+++ b/libs/os/src/test/callout_test.c
@@ -55,15 +55,15 @@ void
 callout_task_send()
 {
    
-    /* should say whether os is armed or not */
+    /* should say whether callout is armed or not */
     i = os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 0);
 
-    /* Arm the OS */
+    /* Arm the callout */
     i = os_callout_reset(&callout_func_test.cf_c, OS_TICKS_PER_SEC/ 50);
     TEST_ASSERT_FATAL(i == 0);
 
-    /* should say whether os is armed or not */
+    /* should say whether callout is armed or not */
     i = os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 1);
 
@@ -81,7 +81,7 @@ callout_task_receive(void *arg)
         TEST_ASSERT(event->ev_arg == NULL);
 
     TEST_ASSERT(i == 1);
-    /* should say whether os is armed or not */
+    /* should say whether callout is armed or not */
     i = os_callout_queued(&callout_func_test.cf_c);
     TEST_ASSERT(i == 0);
 


[26/50] [abbrv] incubator-mynewt-core git commit: Fixed bug where ID was always wrong in response

Posted by cc...@apache.org.
Fixed bug where ID was always wrong in response


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

Branch: refs/heads/master
Commit: fcda6e7c7b621de808f9796025f0d7d094e77f37
Parents: 5de9a72
Author: Brian Giori <br...@gmail.com>
Authored: Fri Aug 19 12:21:10 2016 -0700
Committer: Brian Giori <br...@gmail.com>
Committed: Fri Aug 19 12:21:10 2016 -0700

----------------------------------------------------------------------
 libs/newtmgr/src/newtmgr.c | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fcda6e7c/libs/newtmgr/src/newtmgr.c
----------------------------------------------------------------------
diff --git a/libs/newtmgr/src/newtmgr.c b/libs/newtmgr/src/newtmgr.c
index c3bc614..d15b4b9 100644
--- a/libs/newtmgr/src/newtmgr.c
+++ b/libs/newtmgr/src/newtmgr.c
@@ -472,7 +472,6 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
 
         rsp_hdr->nh_len = htons(rsp_hdr->nh_len);
         rsp_hdr->nh_group = htons(rsp_hdr->nh_group);
-        rsp_hdr->nh_id = htons(rsp_hdr->nh_id);
 
         off += sizeof(hdr) + OS_ALIGN(hdr.nh_len, 4);
     }


[43/50] [abbrv] incubator-mynewt-core git commit: STM32f407 discovery board BSP

Posted by cc...@apache.org.
STM32f407 discovery board BSP

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

Branch: refs/heads/master
Commit: a46aeec5cf7c651ab89c82e5af64666b36601a95
Parents: 8101830
Author: Pradeep Sanjeewa <gp...@gmail.com>
Authored: Mon Aug 22 19:32:39 2016 +0530
Committer: GitHub <no...@github.com>
Committed: Mon Aug 22 19:32:39 2016 +0530

----------------------------------------------------------------------
 .../stm32f4discovery/boot-stm32f4discovery.ld   | 202 +++++++++
 hw/bsp/stm32f4discovery/f407.cfg                |  82 ++++
 hw/bsp/stm32f4discovery/include/bsp/bsp.h       |  55 +++
 hw/bsp/stm32f4discovery/include/bsp/bsp_sysid.h |  36 ++
 .../stm32f4discovery/include/bsp/cmsis_nvic.h   |  29 ++
 .../include/bsp/stm32f4xx_hal_conf.h            | 413 +++++++++++++++++++
 hw/bsp/stm32f4discovery/pkg.yml                 |  39 ++
 hw/bsp/stm32f4discovery/run_from_flash.ld       | 204 +++++++++
 hw/bsp/stm32f4discovery/run_from_loader.ld      | 210 ++++++++++
 hw/bsp/stm32f4discovery/run_from_sram.ld        | 202 +++++++++
 .../src/arch/cortex_m4/startup_STM32F40x.s      | 343 +++++++++++++++
 hw/bsp/stm32f4discovery/src/hal_bsp.c           |  77 ++++
 hw/bsp/stm32f4discovery/src/libc_stubs.c        |  84 ++++
 hw/bsp/stm32f4discovery/src/os_bsp.c            |  82 ++++
 hw/bsp/stm32f4discovery/src/sbrk.c              |  50 +++
 hw/bsp/stm32f4discovery/src/system_stm32f4xx.c  | 351 ++++++++++++++++
 hw/bsp/stm32f4discovery/stm32f4discovery.ld     | 213 ++++++++++
 .../stm32f4discovery/stm32f4discovery_debug.sh  |  47 +++
 .../stm32f4discovery_download.sh                |  56 +++
 19 files changed, 2775 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/boot-stm32f4discovery.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/boot-stm32f4discovery.ld b/hw/bsp/stm32f4discovery/boot-stm32f4discovery.ld
new file mode 100644
index 0000000..5f41879
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/boot-stm32f4discovery.ld
@@ -0,0 +1,202 @@
+/**
+ * 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.
+ */
+ 
+/* Linker script for STM32F407 when running code from SRAM */
+
+/* Linker script to configure memory regions. */
+MEMORY
+{ 
+  FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
+  CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K
+  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
+}
+
+/* Linker script to place sections and symbol values. Should be used together
+ * with other linker script that defines memory regions FLASH and RAM.
+ * It references following symbols, which must be defined in code:
+ *   Reset_Handler : Entry of reset handler
+ * 
+ * It defines following symbols, which code can use without definition:
+ *   __exidx_start
+ *   __exidx_end
+ *   __etext
+ *   __data_start__
+ *   __preinit_array_start
+ *   __preinit_array_end
+ *   __init_array_start
+ *   __init_array_end
+ *   __fini_array_start
+ *   __fini_array_end
+ *   __data_end__
+ *   __bss_start__
+ *   __bss_end__
+ *   __end__
+ *   end
+ *   __HeapBase
+ *   __HeapLimit
+ *   __StackLimit
+ *   __StackTop
+ *   __stack
+ *   __coredata_start__
+ *   __coredata_end__
+ *   __corebss_start__
+ *   __corebss_end__
+ *   __ecoredata
+ *   __ecorebss
+ */
+ENTRY(Reset_Handler)
+
+SECTIONS
+{
+    .text :
+    {
+        __vector_tbl_reloc__ = .;
+        KEEP(*(.isr_vector))
+        *(.text*)
+
+        KEEP(*(.init))
+        KEEP(*(.fini))
+
+        /* .ctors */
+        *crtbegin.o(.ctors)
+        *crtbegin?.o(.ctors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
+        *(SORT(.ctors.*))
+        *(.ctors)
+
+        /* .dtors */
+        *crtbegin.o(.dtors)
+        *crtbegin?.o(.dtors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
+        *(SORT(.dtors.*))
+        *(.dtors)
+
+        *(.rodata*)
+
+        KEEP(*(.eh_frame*))
+    } > FLASH
+
+    .ARM.extab : 
+    {
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
+    } > FLASH
+
+    __exidx_start = .;
+    .ARM.exidx :
+    {
+        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+    } > FLASH
+
+    __exidx_end = .;
+
+    . = ALIGN(8);
+    __etext = .;
+
+    .coredata : AT (__etext)
+    {
+        __coredata_start__ = .;
+        *(.data.core)
+        . = ALIGN(8);
+        __coredata_end__ = .;
+    } > CCM
+
+    __ecoredata = __etext + SIZEOF(.coredata);
+
+    /* This section is here so that the start of .data has the same VMA and LMA */
+    .ram_coredata (NOLOAD):
+    {
+        . = . + SIZEOF(.coredata);
+    } > RAM
+
+    .data : AT (__ecoredata)
+    {
+        __data_start__ = .;
+        *(vtable)
+        *(.data*)
+
+        /* preinit data */
+        PROVIDE_HIDDEN (__preinit_array_start = .);
+        KEEP(*(.preinit_array))
+        PROVIDE_HIDDEN (__preinit_array_end = .);
+
+        . = ALIGN(4);
+        /* init data */
+        PROVIDE_HIDDEN (__init_array_start = .);
+        KEEP(*(SORT(.init_array.*)))
+        KEEP(*(.init_array))
+        PROVIDE_HIDDEN (__init_array_end = .);
+
+
+        . = ALIGN(4);
+        /* finit data */
+        PROVIDE_HIDDEN (__fini_array_start = .);
+        KEEP(*(SORT(.fini_array.*)))
+        KEEP(*(.fini_array))
+        PROVIDE_HIDDEN (__fini_array_end = .);
+
+        KEEP(*(.jcr*))
+        . = ALIGN(4);
+        /* All data end */
+        __data_end__ = .;
+
+    } > RAM
+
+    .corebss (NOLOAD):
+    {
+        . = ALIGN(4);
+        __corebss_start__ = .;
+        *(.bss.core)
+        . = ALIGN(4);
+        __corebss_end__ = .;
+        *(.corebss*)
+        *(.bss.core.nz)
+        . = ALIGN(4);
+        __ecorebss = .;
+    } > CCM
+
+    .bss :
+    {
+        . = ALIGN(4);
+        __bss_start__ = .;
+        *(.bss*)
+        *(COMMON)
+        . = ALIGN(4);
+        __bss_end__ = .;
+    } > RAM
+    
+    __HeapBase = .;
+    __HeapLimit = ORIGIN(RAM) + LENGTH(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 */
+    .stack_dummy (COPY):
+    {
+        *(.stack*)
+    } > CCM
+
+    /* Set stack top to end of CCM; stack limit is bottom of stack */
+    __StackTop = ORIGIN(CCM) + LENGTH(CCM);
+    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
+    PROVIDE(__stack = __StackTop);
+    
+    /* Check for CCM overflow */
+    ASSERT(__StackLimit >= __ecorebss, "CCM overflow!")
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/f407.cfg
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/f407.cfg b/hw/bsp/stm32f4discovery/f407.cfg
new file mode 100644
index 0000000..7c46d8b
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/f407.cfg
@@ -0,0 +1,82 @@
+#
+# 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.
+#
+
+# script for stm32f4x family
+
+if { [info exists CHIPNAME] } {
+   set _CHIPNAME $CHIPNAME
+} else {
+   set _CHIPNAME stm32f4x
+}
+
+if { [info exists ENDIAN] } {
+   set _ENDIAN $ENDIAN
+} else {
+   set _ENDIAN little
+}
+
+# Work-area is a space in RAM used for flash programming
+# By default use 64kB
+if { [info exists WORKAREASIZE] } {
+   set _WORKAREASIZE $WORKAREASIZE
+} else {
+   set _WORKAREASIZE 0x10000
+}
+
+# JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz
+#
+# Since we may be running of an RC oscilator, we crank down the speed a
+# bit more to be on the safe side. Perhaps superstition, but if are
+# running off a crystal, we can run closer to the limit. Note
+# that there can be a pretty wide band where things are more or less stable.
+adapter_khz 1000
+
+adapter_nsrst_delay 100
+jtag_ntrst_delay 100
+
+#jtag scan chain
+if { [info exists CPUTAPID] } {
+   set _CPUTAPID $CPUTAPID
+} else {
+  # See STM Document RM0090
+  # Section 32.6.2 - corresponds to Cortex-M4 r0p1
+   set _CPUTAPID 0x4ba00477
+}
+jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
+
+if { [info exists BSTAPID] } {
+   set _BSTAPID $BSTAPID
+} else {
+  # See STM Document RM0090
+  # Section 32.6.3
+  set _BSTAPID 0x06413041
+}
+jtag newtap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID
+
+set _TARGETNAME $_CHIPNAME.cpu
+target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNAME
+
+$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
+
+set _FLASHNAME $_CHIPNAME.flash
+flash bank $_FLASHNAME stm32f2x 0 0 0 0 $_TARGETNAME
+
+# if srst is not fitted use SYSRESETREQ to
+# perform a soft reset
+cortex_m3 reset_config sysresetreq

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/include/bsp/bsp.h b/hw/bsp/stm32f4discovery/include/bsp/bsp.h
new file mode 100644
index 0000000..7ab3e6e
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/include/bsp/bsp.h
@@ -0,0 +1,55 @@
+/**
+ * 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 H_BSP_H
+#define H_BSP_H
+
+#include <inttypes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Define special stackos sections */
+#define sec_data_core   __attribute__((section(".data.core")))
+#define sec_bss_core    __attribute__((section(".bss.core")))
+#define sec_bss_nz_core __attribute__((section(".bss.core.nz")))
+
+/* 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   (60)
+
+/* UART */
+#define UART_CNT 1
+#define CONSOLE_UART 0
+
+#define NFFS_AREA_MAX    (8)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* H_BSP_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/include/bsp/bsp_sysid.h
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/include/bsp/bsp_sysid.h b/hw/bsp/stm32f4discovery/include/bsp/bsp_sysid.h
new file mode 100644
index 0000000..7b0a24b
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/include/bsp/bsp_sysid.h
@@ -0,0 +1,36 @@
+/**
+ * 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 BSP_SYSID_H
+#define BSP_SYSID_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* stub until this BSP gets new HAL */
+enum system_device_id  
+{
+    RESERVED,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BSP_SYSID_H */
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/include/bsp/cmsis_nvic.h
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/include/bsp/cmsis_nvic.h b/hw/bsp/stm32f4discovery/include/bsp/cmsis_nvic.h
new file mode 100644
index 0000000..008b247
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/include/bsp/cmsis_nvic.h
@@ -0,0 +1,29 @@
+/* mbed Microcontroller Library - cmsis_nvic
+ * Copyright (c) 2009-2011 ARM Limited. All rights reserved.
+ *
+ * CMSIS-style functionality to support dynamic vectors
+ */
+
+#ifndef MBED_CMSIS_NVIC_H
+#define MBED_CMSIS_NVIC_H
+
+#include <stdint.h>
+
+#define NVIC_NUM_VECTORS      (16 + 81)   // CORE + MCU Peripherals
+#define NVIC_USER_IRQ_OFFSET  16
+
+#include "mcu/stm32f4xx.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void NVIC_Relocate(void);
+void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
+uint32_t NVIC_GetVector(IRQn_Type IRQn);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/include/bsp/stm32f4xx_hal_conf.h
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/include/bsp/stm32f4xx_hal_conf.h b/hw/bsp/stm32f4discovery/include/bsp/stm32f4xx_hal_conf.h
new file mode 100644
index 0000000..8e4216c
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/include/bsp/stm32f4xx_hal_conf.h
@@ -0,0 +1,413 @@
+/**
+  ******************************************************************************
+  * @file    stm32f4xx_hal_conf.h
+  * @author  MCD Application Team
+  * @version V1.2.1
+  * @date    13-March-2015
+  * @brief   HAL configuration file
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */ 
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+/* ########################## Module Selection ############################## */
+/**
+  * @brief This is the list of modules to be used in the HAL driver 
+  */
+#define HAL_MODULE_ENABLED
+#if 0
+#define HAL_ADC_MODULE_ENABLED
+#define HAL_CAN_MODULE_ENABLED
+#define HAL_CRC_MODULE_ENABLED
+#define HAL_CRYP_MODULE_ENABLED
+#define HAL_DAC_MODULE_ENABLED
+#define HAL_DCMI_MODULE_ENABLED
+#define HAL_DMA_MODULE_ENABLED
+/* #define HAL_DMA2D_MODULE_ENABLED */
+#define HAL_ETH_MODULE_ENABLED
+#define HAL_FLASH_MODULE_ENABLED
+#define HAL_NAND_MODULE_ENABLED
+#define HAL_NOR_MODULE_ENABLED
+#define HAL_PCCARD_MODULE_ENABLED
+#define HAL_SRAM_MODULE_ENABLED
+/* #define HAL_SDRAM_MODULE_ENABLED */
+#define HAL_HASH_MODULE_ENABLED
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+#define HAL_I2S_MODULE_ENABLED
+#define HAL_IWDG_MODULE_ENABLED
+#define HAL_LTDC_MODULE_ENABLED
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_RNG_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
+/* #define HAL_SAI_MODULE_ENABLED */
+#define HAL_SD_MODULE_ENABLED
+#define HAL_SPI_MODULE_ENABLED
+#define HAL_TIM_MODULE_ENABLED
+#define HAL_UART_MODULE_ENABLED
+#define HAL_USART_MODULE_ENABLED
+#define HAL_IRDA_MODULE_ENABLED
+#define HAL_SMARTCARD_MODULE_ENABLED
+#define HAL_WWDG_MODULE_ENABLED
+#define HAL_CORTEX_MODULE_ENABLED
+#define HAL_PCD_MODULE_ENABLED
+#define HAL_HCD_MODULE_ENABLED
+#else
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_FLASH_MODULE_ENABLED
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#endif
+
+/* ########################## HSE/HSI Values adaptation ##################### */
+/**
+  * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+  *        This value is used by the RCC HAL module to compute the system frequency
+  *        (when HSE is used as system clock source, directly or through the PLL).  
+  */
+#if !defined  (HSE_VALUE) 
+  #define HSE_VALUE    ((uint32_t)12000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined  (HSE_STARTUP_TIMEOUT)
+  #define HSE_STARTUP_TIMEOUT    ((uint32_t)5000)   /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+  * @brief Internal High Speed oscillator (HSI) value.
+  *        This value is used by the RCC HAL module to compute the system frequency
+  *        (when HSI is used as system clock source, directly or through the PLL). 
+  */
+#if !defined  (HSI_VALUE)
+  #define HSI_VALUE    ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+  * @brief Internal Low Speed oscillator (LSI) value.
+  */
+#if !defined  (LSI_VALUE) 
+ #define LSI_VALUE  ((uint32_t)32000)    
+#endif /* LSI_VALUE */                      /*!< Value of the Internal Low Speed oscillator in Hz
+                                             The real value may vary depending on the variations
+                                             in voltage and temperature.  */
+/**
+  * @brief External Low Speed oscillator (LSE) value.
+  */
+#if !defined  (LSE_VALUE)
+ #define LSE_VALUE  ((uint32_t)32768)    /*!< Value of the External Low Speed oscillator in Hz */
+#endif /* LSE_VALUE */
+
+/**
+  * @brief External clock source for I2S peripheral
+  *        This value is used by the I2S HAL module to compute the I2S clock source 
+  *        frequency, this source is inserted directly through I2S_CKIN pad. 
+  */
+#if !defined  (EXTERNAL_CLOCK_VALUE)
+  #define EXTERNAL_CLOCK_VALUE    ((uint32_t)12288000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+   ===  you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+  * @brief This is the HAL system configuration section
+  */     
+#define  VDD_VALUE                    ((uint32_t)3300) /*!< Value of VDD in mv */
+#define  TICK_INT_PRIORITY            ((uint32_t)0x0F) /*!< tick interrupt priority */
+#define  USE_RTOS                     0
+#define  PREFETCH_ENABLE              0 /* The prefetch will be enabled in SystemClock_Config(), depending on the used 
+                                           STM32F405/415/07/417 device: RevA (prefetch must be off) or RevZ (prefetch can be on/off) */
+#define  INSTRUCTION_CACHE_ENABLE     1
+#define  DATA_CACHE_ENABLE            1
+
+/* ########################## Assert Selection ############################## */
+/**
+  * @brief Uncomment the line below to expanse the "assert_param" macro in the 
+  *        HAL drivers code
+  */
+/* #define USE_FULL_ASSERT    1 */
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0   2
+#define MAC_ADDR1   0
+#define MAC_ADDR2   0
+#define MAC_ADDR3   0
+#define MAC_ADDR4   0
+#define MAC_ADDR5   0
+
+/* Definition of the Ethernet driver buffers size and count */   
+#define ETH_RX_BUF_SIZE                ETH_MAX_PACKET_SIZE /* buffer size for receive               */
+#define ETH_TX_BUF_SIZE                ETH_MAX_PACKET_SIZE /* buffer size for transmit              */
+#define ETH_RXBUFNB                    ((uint32_t)4)       /* 4 Rx buffers of size ETH_RX_BUF_SIZE  */
+#define ETH_TXBUFNB                    ((uint32_t)4)       /* 4 Tx buffers of size ETH_TX_BUF_SIZE  */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/ 
+#define DP83848_PHY_ADDRESS             0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ 
+#define PHY_RESET_DELAY                 ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY                ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO                     ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO                    ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR                         ((uint16_t)0x00)    /*!< Transceiver Basic Control Register   */
+#define PHY_BSR                         ((uint16_t)0x01)    /*!< Transceiver Basic Status Register    */
+ 
+#define PHY_RESET                       ((uint16_t)0x8000)  /*!< PHY Reset */
+#define PHY_LOOPBACK                    ((uint16_t)0x4000)  /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M             ((uint16_t)0x2100)  /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M             ((uint16_t)0x2000)  /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M              ((uint16_t)0x0100)  /*!< Set the full-duplex mode at 10 Mb/s  */
+#define PHY_HALFDUPLEX_10M              ((uint16_t)0x0000)  /*!< Set the half-duplex mode at 10 Mb/s  */
+#define PHY_AUTONEGOTIATION             ((uint16_t)0x1000)  /*!< Enable auto-negotiation function     */
+#define PHY_RESTART_AUTONEGOTIATION     ((uint16_t)0x0200)  /*!< Restart auto-negotiation function    */
+#define PHY_POWERDOWN                   ((uint16_t)0x0800)  /*!< Select the power down mode           */
+#define PHY_ISOLATE                     ((uint16_t)0x0400)  /*!< Isolate PHY from MII                 */
+
+#define PHY_AUTONEGO_COMPLETE           ((uint16_t)0x0020)  /*!< Auto-Negotiation process completed   */
+#define PHY_LINKED_STATUS               ((uint16_t)0x0004)  /*!< Valid link established               */
+#define PHY_JABBER_DETECTION            ((uint16_t)0x0002)  /*!< Jabber condition detected            */
+  
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR                          ((uint16_t)0x10)    /*!< PHY status register Offset                      */
+#define PHY_MICR                        ((uint16_t)0x11)    /*!< MII Interrupt Control Register                  */
+#define PHY_MISR                        ((uint16_t)0x12)    /*!< MII Interrupt Status and Misc. Control Register */
+ 
+#define PHY_LINK_STATUS                 ((uint16_t)0x0001)  /*!< PHY Link mask                                   */
+#define PHY_SPEED_STATUS                ((uint16_t)0x0002)  /*!< PHY Speed mask                                  */
+#define PHY_DUPLEX_STATUS               ((uint16_t)0x0004)  /*!< PHY Duplex mask                                 */
+
+#define PHY_MICR_INT_EN                 ((uint16_t)0x0002)  /*!< PHY Enable interrupts                           */
+#define PHY_MICR_INT_OE                 ((uint16_t)0x0001)  /*!< PHY Enable output interrupt events              */
+
+#define PHY_MISR_LINK_INT_EN            ((uint16_t)0x0020)  /*!< Enable Interrupt on change of link status       */
+#define PHY_LINK_INTERRUPT              ((uint16_t)0x2000)  /*!< PHY link status interrupt mask                  */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+  * @brief Include module's header file 
+  */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+   
+#ifdef HAL_CORTEX_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_cryp.h" 
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+ 
+#ifdef HAL_SRAM_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */ 
+  
+#ifdef HAL_SDRAM_MODULE_ENABLED
+  #include "mcu/stm32f4xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */      
+
+#ifdef HAL_HASH_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "mcu/stm32f4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+   
+/* Exported macro ------------------------------------------------------------*/
+#ifdef  USE_FULL_ASSERT
+/**
+  * @brief  The assert_param macro is used for function's parameters check.
+  * @param  expr: If expr is false, it calls assert_failed function
+  *         which reports the name of the source file and the source
+  *         line number of the call that failed. 
+  *         If expr is true, it returns no value.
+  * @retval None
+  */
+  #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+  void assert_failed(uint8_t* file, uint32_t line);
+#else
+  #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */    
+    
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_HAL_CONF_H */
+ 
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/pkg.yml b/hw/bsp/stm32f4discovery/pkg.yml
new file mode 100644
index 0000000..04e74d3
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/pkg.yml
@@ -0,0 +1,39 @@
+#
+# 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: hw/bsp/stm32f4discovery
+pkg.type: bsp
+pkg.description: BSP definition for the stm32f4 discovery board.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - stm32
+    - stm32f4
+    - discovery
+
+pkg.arch: cortex_m4
+pkg.compiler: compiler/arm-none-eabi-m4
+pkg.linkerscript: "stm32f4discovery.ld"
+pkg.linkerscript.bootloader.OVERWRITE: "boot-stm32f4discovery.ld"
+pkg.downloadscript: "stm32f4discovery_download.sh"
+pkg.debugscript: "stm32f4discovery_debug.sh"
+pkg.cflags: -DSTM32F407xx
+pkg.deps:
+    - hw/mcu/stm/stm32f4xx
+    - libs/baselibc

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/run_from_flash.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/run_from_flash.ld b/hw/bsp/stm32f4discovery/run_from_flash.ld
new file mode 100644
index 0000000..658d923
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/run_from_flash.ld
@@ -0,0 +1,204 @@
+/**
+ * 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.
+ */
+ 
+/* Linker script for STM32F407 when running from flash and not using the bootloader */
+
+/* Linker script to configure memory regions. */
+MEMORY
+{ 
+  FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
+  CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K
+  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x20000 
+}
+
+/* Linker script to place sections and symbol values. Should be used together
+ * with other linker script that defines memory regions FLASH and RAM.
+ * It references following symbols, which must be defined in code:
+ *   Reset_Handler : Entry of reset handler
+ * 
+ * It defines following symbols, which code can use without definition:
+ *   __exidx_start
+ *   __exidx_end
+ *   __etext
+ *   __data_start__
+ *   __preinit_array_start
+ *   __preinit_array_end
+ *   __init_array_start
+ *   __init_array_end
+ *   __fini_array_start
+ *   __fini_array_end
+ *   __data_end__
+ *   __bss_start__
+ *   __bss_end__
+ *   __end__
+ *   end
+ *   __HeapBase
+ *   __HeapLimit
+ *   __StackLimit
+ *   __StackTop
+ *   __stack
+ *   __coredata_start__
+ *   __coredata_end__
+ *   __corebss_start__
+ *   __corebss_end__
+ *   __ecoredata
+ *   __ecorebs
+ */
+ENTRY(Reset_Handler)
+
+SECTIONS
+{
+    .text :
+    {
+        __isr_vector_start = .;
+        KEEP(*(.isr_vector))
+        __isr_vector_end = .;
+        *(.text*)
+
+        KEEP(*(.init))
+        KEEP(*(.fini))
+
+        /* .ctors */
+        *crtbegin.o(.ctors)
+        *crtbegin?.o(.ctors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
+        *(SORT(.ctors.*))
+        *(.ctors)
+
+        /* .dtors */
+        *crtbegin.o(.dtors)
+        *crtbegin?.o(.dtors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
+        *(SORT(.dtors.*))
+        *(.dtors)
+
+        *(.rodata*)
+
+        KEEP(*(.eh_frame*))
+    } > FLASH
+
+    .ARM.extab : 
+    {
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
+    } > FLASH
+
+    __exidx_start = .;
+    .ARM.exidx :
+    {
+        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+    } > FLASH
+
+    __exidx_end = .;
+
+    __etext = .;
+
+    .vector_relocation :
+    {
+        . = ALIGN(4);
+        __vector_tbl_reloc__ = .;
+        . = . + (__isr_vector_end - __isr_vector_start);
+        . = ALIGN(4);
+    } > RAM
+
+    .coredata : AT (__etext)
+    {
+        __coredata_start__ = .;
+        *(.data.core)
+        . = ALIGN(4);
+        __coredata_end__ = .;
+    } > CCM
+
+    __ecoredata = __etext + SIZEOF(.coredata);
+        
+    .data : AT (__ecoredata)
+    {
+        __data_start__ = .;
+        *(vtable)
+        *(.data*)
+
+        /* preinit data */
+        PROVIDE_HIDDEN (__preinit_array_start = .);
+        KEEP(*(.preinit_array))
+        PROVIDE_HIDDEN (__preinit_array_end = .);
+
+        . = ALIGN(4);
+        /* init data */
+        PROVIDE_HIDDEN (__init_array_start = .);
+        KEEP(*(SORT(.init_array.*)))
+        KEEP(*(.init_array))
+        PROVIDE_HIDDEN (__init_array_end = .);
+
+
+        . = ALIGN(4);
+        /* finit data */
+        PROVIDE_HIDDEN (__fini_array_start = .);
+        KEEP(*(SORT(.fini_array.*)))
+        KEEP(*(.fini_array))
+        PROVIDE_HIDDEN (__fini_array_end = .);
+
+        KEEP(*(.jcr*))
+        . = ALIGN(4);
+        /* All data end */
+        __data_end__ = .;
+
+    } > RAM
+
+    .corebss (NOLOAD):
+    {
+        . = ALIGN(4);
+        __corebss_start__ = .;
+        *(.bss.core)
+        . = ALIGN(4);
+        __corebss_end__ = .;
+        *(.corebss*)
+        *(.bss.core.nz)
+        . = ALIGN(4);
+        __ecorebss = .;
+    } > CCM
+
+    .bss :
+    {
+        . = ALIGN(4);
+        __bss_start__ = .;
+        *(.bss*)
+        *(COMMON)
+        . = ALIGN(4);
+        __bss_end__ = .;
+    } > RAM
+
+    __HeapBase = .;
+    __HeapLimit = ORIGIN(RAM) + LENGTH(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 */
+    .stack_dummy (COPY):
+    {
+        *(.stack*)
+    } > CCM
+
+    /* Set stack top to end of CCM; stack limit is bottom of stack */
+    __StackTop = ORIGIN(CCM) + LENGTH(CCM);
+    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
+    PROVIDE(__stack = __StackTop);
+    
+    /* Check for CCM overflow */
+    ASSERT(__StackLimit >= __ecorebss, "CCM overflow!")
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/run_from_loader.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/run_from_loader.ld b/hw/bsp/stm32f4discovery/run_from_loader.ld
new file mode 100644
index 0000000..50b8290
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/run_from_loader.ld
@@ -0,0 +1,210 @@
+/**
+ * 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.
+ */
+
+/* Linker script for STM32F407 when running from flash and using the bootloader */
+
+/* Linker script to configure memory regions. */
+MEMORY
+{ 
+  FLASH (rx) :  ORIGIN = 0x08020000, LENGTH = 384K /* First image slot. */
+  CCM (rwx) :   ORIGIN = 0x10000000, LENGTH = 64K
+  RAM (rwx) :   ORIGIN = 0x20000000, LENGTH = 128K
+}
+
+/* Linker script to place sections and symbol values. Should be used together
+ * with other linker script that defines memory regions FLASH and RAM.
+ * It references following symbols, which must be defined in code:
+ *   Reset_Handler : Entry of reset handler
+ * 
+ * It defines following symbols, which code can use without definition:
+ *   __exidx_start
+ *   __exidx_end
+ *   __etext
+ *   __data_start__
+ *   __preinit_array_start
+ *   __preinit_array_end
+ *   __init_array_start
+ *   __init_array_end
+ *   __fini_array_start
+ *   __fini_array_end
+ *   __data_end__
+ *   __bss_start__
+ *   __bss_end__
+ *   __end__
+ *   end
+ *   __HeapBase
+ *   __HeapLimit
+ *   __StackLimit
+ *   __StackTop
+ *   __stack
+ *   __coredata_start__
+ *   __coredata_end__
+ *   __corebss_start__
+ *   __corebss_end__
+ *   __ecoredata
+ *   __ecorebss
+ */
+ENTRY(Reset_Handler)
+
+SECTIONS
+{
+    /* Reserve space at the start of the image for the header. */
+    .imghdr (NOLOAD):
+    {
+        . = . + 0x20;
+    } > FLASH
+
+    .text :
+    {
+        __isr_vector_start = .;
+        KEEP(*(.isr_vector))
+        __isr_vector_end = .;
+        *(.text*)
+
+        KEEP(*(.init))
+        KEEP(*(.fini))
+
+        /* .ctors */
+        *crtbegin.o(.ctors)
+        *crtbegin?.o(.ctors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
+        *(SORT(.ctors.*))
+        *(.ctors)
+
+        /* .dtors */
+        *crtbegin.o(.dtors)
+        *crtbegin?.o(.dtors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
+        *(SORT(.dtors.*))
+        *(.dtors)
+
+        *(.rodata*)
+
+        KEEP(*(.eh_frame*))
+    } > FLASH
+
+    .ARM.extab : 
+    {
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
+    } > FLASH
+
+    __exidx_start = .;
+    .ARM.exidx :
+    {
+        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+    } > FLASH
+
+    __exidx_end = .;
+
+    __etext = .;
+
+    .vector_relocation :
+    {
+        . = ALIGN(4);
+        __vector_tbl_reloc__ = .;
+        . = . + (__isr_vector_end - __isr_vector_start);
+        . = ALIGN(4);
+    } > RAM
+
+    .coredata : AT (__etext)
+    {
+        __coredata_start__ = .;
+        *(.data.core)
+        . = ALIGN(4);
+        __coredata_end__ = .;
+    } > CCM
+
+    __ecoredata = __etext + SIZEOF(.coredata);
+        
+    .data : AT (__ecoredata)
+    {
+        __data_start__ = .;
+        *(vtable)
+        *(.data*)
+
+        /* preinit data */
+        PROVIDE_HIDDEN (__preinit_array_start = .);
+        KEEP(*(.preinit_array))
+        PROVIDE_HIDDEN (__preinit_array_end = .);
+
+        . = ALIGN(4);
+        /* init data */
+        PROVIDE_HIDDEN (__init_array_start = .);
+        KEEP(*(SORT(.init_array.*)))
+        KEEP(*(.init_array))
+        PROVIDE_HIDDEN (__init_array_end = .);
+
+
+        . = ALIGN(4);
+        /* finit data */
+        PROVIDE_HIDDEN (__fini_array_start = .);
+        KEEP(*(SORT(.fini_array.*)))
+        KEEP(*(.fini_array))
+        PROVIDE_HIDDEN (__fini_array_end = .);
+
+        KEEP(*(.jcr*))
+        . = ALIGN(4);
+        /* All data end */
+        __data_end__ = .;
+
+    } > RAM
+
+    .corebss (NOLOAD):
+    {
+        . = ALIGN(4);
+        __corebss_start__ = .;
+        *(.bss.core)
+        . = ALIGN(4);
+        __corebss_end__ = .;
+        *(.corebss*)
+        *(.bss.core.nz)
+        . = ALIGN(4);
+        __ecorebss = .;
+    } > CCM
+
+    .bss :
+    {
+        . = ALIGN(4);
+        __bss_start__ = .;
+        *(.bss*)
+        *(COMMON)
+        . = ALIGN(4);
+        __bss_end__ = .;
+    } > RAM
+
+    __HeapBase = .;
+    __HeapLimit = ORIGIN(RAM) + LENGTH(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 */
+    .stack_dummy (COPY):
+    {
+        *(.stack*)
+    } > CCM
+
+    /* Set stack top to end of CCM; stack limit is bottom of stack */
+    __StackTop = ORIGIN(CCM) + LENGTH(CCM);
+    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
+    PROVIDE(__stack = __StackTop);
+    
+    /* Check for CCM overflow */
+    ASSERT(__StackLimit >= __ecorebss, "CCM overflow!")
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/run_from_sram.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/run_from_sram.ld b/hw/bsp/stm32f4discovery/run_from_sram.ld
new file mode 100644
index 0000000..cdf5efe
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/run_from_sram.ld
@@ -0,0 +1,202 @@
+/**
+ * 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.
+ */
+
+/* Linker script for STM32F407 when running code from SRAM */
+
+/* Linker script to configure memory regions. */
+MEMORY
+{ 
+  FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
+  CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K
+  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x20000
+}
+
+/* Linker script to place sections and symbol values. Should be used together
+ * with other linker script that defines memory regions FLASH and RAM.
+ * It references following symbols, which must be defined in code:
+ *   Reset_Handler : Entry of reset handler
+ * 
+ * It defines following symbols, which code can use without definition:
+ *   __exidx_start
+ *   __exidx_end
+ *   __etext
+ *   __data_start__
+ *   __preinit_array_start
+ *   __preinit_array_end
+ *   __init_array_start
+ *   __init_array_end
+ *   __fini_array_start
+ *   __fini_array_end
+ *   __data_end__
+ *   __bss_start__
+ *   __bss_end__
+ *   __end__
+ *   end
+ *   __HeapBase
+ *   __HeapLimit
+ *   __StackLimit
+ *   __StackTop
+ *   __stack
+ *   __coredata_start__
+ *   __coredata_end__
+ *   __corebss_start__
+ *   __corebss_end__
+ *   __ecoredata
+ *   __ecorebss
+ */
+ENTRY(Reset_Handler)
+
+SECTIONS
+{
+    .text :
+    {
+        __vector_tbl_reloc__ = .;
+        KEEP(*(.isr_vector))
+        *(.text*)
+
+        KEEP(*(.init))
+        KEEP(*(.fini))
+
+        /* .ctors */
+        *crtbegin.o(.ctors)
+        *crtbegin?.o(.ctors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
+        *(SORT(.ctors.*))
+        *(.ctors)
+
+        /* .dtors */
+        *crtbegin.o(.dtors)
+        *crtbegin?.o(.dtors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
+        *(SORT(.dtors.*))
+        *(.dtors)
+
+        *(.rodata*)
+
+        KEEP(*(.eh_frame*))
+    } > RAM
+
+    .ARM.extab : 
+    {
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
+    } > RAM
+
+    __exidx_start = .;
+    .ARM.exidx :
+    {
+        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+    } > RAM
+
+    __exidx_end = .;
+
+    . = ALIGN(8);
+    __etext = .;
+
+    .coredata : AT (__etext)
+    {
+        __coredata_start__ = .;
+        *(.data.core)
+        . = ALIGN(8);
+        __coredata_end__ = .;
+    } > CCM
+
+    __ecoredata = __etext + SIZEOF(.coredata);
+
+    /* This section is here so that the start of .data has the same VMA and LMA */
+    .ram_coredata (NOLOAD):
+    {
+        . = . + SIZEOF(.coredata);
+    } > RAM
+
+    .data : AT (__ecoredata)
+    {
+        __data_start__ = .;
+        *(vtable)
+        *(.data*)
+
+        /* preinit data */
+        PROVIDE_HIDDEN (__preinit_array_start = .);
+        KEEP(*(.preinit_array))
+        PROVIDE_HIDDEN (__preinit_array_end = .);
+
+        . = ALIGN(4);
+        /* init data */
+        PROVIDE_HIDDEN (__init_array_start = .);
+        KEEP(*(SORT(.init_array.*)))
+        KEEP(*(.init_array))
+        PROVIDE_HIDDEN (__init_array_end = .);
+
+
+        . = ALIGN(4);
+        /* finit data */
+        PROVIDE_HIDDEN (__fini_array_start = .);
+        KEEP(*(SORT(.fini_array.*)))
+        KEEP(*(.fini_array))
+        PROVIDE_HIDDEN (__fini_array_end = .);
+
+        KEEP(*(.jcr*))
+        . = ALIGN(4);
+        /* All data end */
+        __data_end__ = .;
+
+    } > RAM
+
+    .corebss (NOLOAD):
+    {
+        . = ALIGN(4);
+        __corebss_start__ = .;
+        *(.bss.core)
+        . = ALIGN(4);
+        __corebss_end__ = .;
+        *(.corebss*)
+        *(.bss.core.nz)
+        . = ALIGN(4);
+        __ecorebss = .;
+    } > CCM
+
+    .bss :
+    {
+        . = ALIGN(4);
+        __bss_start__ = .;
+        *(.bss*)
+        *(COMMON)
+        . = ALIGN(4);
+        __bss_end__ = .;
+    } > RAM
+
+    __HeapBase = .;
+    __HeapLimit = ORIGIN(RAM) + LENGTH(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 */
+    .stack_dummy (COPY):
+    {
+        *(.stack*)
+    } > CCM
+
+    /* Set stack top to end of CCM; stack limit is bottom of stack */
+    __StackTop = ORIGIN(CCM) + LENGTH(CCM);
+    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
+    PROVIDE(__stack = __StackTop);
+    
+    /* Check for CCM overflow */
+    ASSERT(__StackLimit >= __ecorebss, "CCM overflow!")
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/src/arch/cortex_m4/startup_STM32F40x.s
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/src/arch/cortex_m4/startup_STM32F40x.s b/hw/bsp/stm32f4discovery/src/arch/cortex_m4/startup_STM32F40x.s
new file mode 100644
index 0000000..646b4bf
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/src/arch/cortex_m4/startup_STM32F40x.s
@@ -0,0 +1,343 @@
+/* File: startup_STM32F40x.S
+ * Purpose: startup file for Cortex-M4 devices. Should use with
+ *   GCC for ARM Embedded Processors
+ * Version: V1.4
+ * Date: 09 July 2012
+ *
+ * Copyright (c) 2011, 2012, ARM Limited
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+    * Neither the name of the ARM Limited nor the
+      names of its contributors may be used to endorse or promote products
+      derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL ARM LIMITED BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+    .syntax unified
+    .arch armv7-m
+
+    .section .stack
+    .align 3
+#ifdef __STACK_SIZE
+    .equ    Stack_Size, __STACK_SIZE
+#else
+    .equ    Stack_Size, 0xc00
+#endif
+    .globl    __StackTop
+    .globl    __StackLimit
+__StackLimit:
+    .space    Stack_Size
+    .size __StackLimit, . - __StackLimit
+__StackTop:
+    .size __StackTop, . - __StackTop
+
+    .section .heap
+    .align 3
+#ifdef __HEAP_SIZE
+    .equ    Heap_Size, __HEAP_SIZE
+#else
+    .equ    Heap_Size, 0
+#endif
+    .globl    __HeapBase
+    .globl    __HeapLimit
+__HeapBase:
+    .if    Heap_Size
+    .space    Heap_Size
+    .endif
+    .size __HeapBase, . - __HeapBase
+__HeapLimit:
+    .size __HeapLimit, . - __HeapLimit
+
+    .section .isr_vector
+    .align 2
+    .globl __isr_vector
+__isr_vector:
+    .long    __StackTop            /* Top of Stack */
+    .long    Reset_Handler         /* Reset Handler */
+    .long    NMI_Handler           /* NMI Handler */
+    .long    HardFault_Handler     /* Hard Fault Handler */
+    .long    MemManage_Handler     /* MPU Fault Handler */
+    .long    BusFault_Handler      /* Bus Fault Handler */
+    .long    UsageFault_Handler    /* Usage Fault Handler */
+    .long    0                     /* Reserved */
+    .long    0                     /* Reserved */
+    .long    0                     /* Reserved */
+    .long    0                     /* Reserved */
+    .long    SVC_Handler           /* SVCall Handler */
+    .long    DebugMon_Handler      /* Debug Monitor Handler */
+    .long    0                     /* Reserved */
+    .long    PendSV_Handler        /* PendSV Handler */
+    .long    SysTick_Handler       /* SysTick Handler */
+
+    /* External interrupts */
+    .long     WWDG_IRQHandler               /* Window WatchDog */
+    .long     PVD_IRQHandler                /* PVD through EXTI Line detection */
+    .long     TAMP_STAMP_IRQHandler         /* Tamper and TimeStamps through the EXTI line */
+    .long     RTC_WKUP_IRQHandler           /* RTC Wakeup through the EXTI line */
+    .long     FLASH_IRQHandler              /* FLASH */
+    .long     RCC_IRQHandler                /* RCC */
+    .long     EXTI0_IRQHandler              /* EXTI Line0 */
+    .long     EXTI1_IRQHandler              /* EXTI Line1 */
+    .long     EXTI2_IRQHandler              /* EXTI Line2 */
+    .long     EXTI3_IRQHandler              /* EXTI Line3 */
+    .long     EXTI4_IRQHandler              /* EXTI Line4 */
+    .long     DMA1_Stream0_IRQHandler       /* DMA1 Stream 0 */
+    .long     DMA1_Stream1_IRQHandler       /* DMA1 Stream 1 */
+    .long     DMA1_Stream2_IRQHandler       /* DMA1 Stream 2 */
+    .long     DMA1_Stream3_IRQHandler       /* DMA1 Stream 3 */
+    .long     DMA1_Stream4_IRQHandler       /* DMA1 Stream 4 */
+    .long     DMA1_Stream5_IRQHandler       /* DMA1 Stream 5 */
+    .long     DMA1_Stream6_IRQHandler       /* DMA1 Stream 6 */
+    .long     ADC_IRQHandler                /* ADC1, ADC2 and ADC3s */
+    .long     CAN1_TX_IRQHandler            /* CAN1 TX */
+    .long     CAN1_RX0_IRQHandler           /* CAN1 RX0 */
+    .long     CAN1_RX1_IRQHandler           /* CAN1 RX1 */
+    .long     CAN1_SCE_IRQHandler           /* CAN1 SCE */
+    .long     EXTI9_5_IRQHandler            /* External Line[9:5]s */
+    .long     TIM1_BRK_TIM9_IRQHandler      /* TIM1 Break and TIM9 */
+    .long     TIM1_UP_TIM10_IRQHandler      /* TIM1 Update and TIM10 */
+    .long     TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */
+    .long     TIM1_CC_IRQHandler            /* TIM1 Capture Compare */
+    .long     TIM2_IRQHandler               /* TIM2 */
+    .long     TIM3_IRQHandler               /* TIM3 */
+    .long     TIM4_IRQHandler               /* TIM4 */
+    .long     I2C1_EV_IRQHandler            /* I2C1 Event */
+    .long     I2C1_ER_IRQHandler            /* I2C1 Error */
+    .long     I2C2_EV_IRQHandler            /* I2C2 Event */
+    .long     I2C2_ER_IRQHandler            /* I2C2 Error */
+    .long     SPI1_IRQHandler               /* SPI1 */
+    .long     SPI2_IRQHandler               /* SPI2 */
+    .long     USART1_IRQHandler             /* USART1 */
+    .long     USART2_IRQHandler             /* USART2 */
+    .long     USART3_IRQHandler             /* USART3 */
+    .long     EXTI15_10_IRQHandler          /* External Line[15:10]s */
+    .long     RTC_Alarm_IRQHandler          /* RTC Alarm (A and B) through EXTI Line */
+    .long     OTG_FS_WKUP_IRQHandler        /* USB OTG FS Wakeup through EXTI line */
+    .long     TIM8_BRK_TIM12_IRQHandler     /* TIM8 Break and TIM12 */
+    .long     TIM8_UP_TIM13_IRQHandler      /* TIM8 Update and TIM13 */
+    .long     TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */
+    .long     TIM8_CC_IRQHandler            /* TIM8 Capture Compare */
+    .long     DMA1_Stream7_IRQHandler       /* DMA1 Stream7 */
+    .long     FSMC_IRQHandler               /* FSMC */
+    .long     SDIO_IRQHandler               /* SDIO */
+    .long     TIM5_IRQHandler               /* TIM5 */
+    .long     SPI3_IRQHandler               /* SPI3 */
+    .long     UART4_IRQHandler              /* UART4 */
+    .long     UART5_IRQHandler              /* UART5 */
+    .long     TIM6_DAC_IRQHandler           /* TIM6 and DAC1&2 underrun errors */
+    .long     TIM7_IRQHandler               /* TIM7 */
+    .long     DMA2_Stream0_IRQHandler       /* DMA2 Stream 0 */
+    .long     DMA2_Stream1_IRQHandler       /* DMA2 Stream 1 */
+    .long     DMA2_Stream2_IRQHandler       /* DMA2 Stream 2 */
+    .long     DMA2_Stream3_IRQHandler       /* DMA2 Stream 3 */
+    .long     DMA2_Stream4_IRQHandler       /* DMA2 Stream 4 */
+    .long     ETH_IRQHandler                /* Ethernet */
+    .long     ETH_WKUP_IRQHandler           /* Ethernet Wakeup through EXTI line */
+    .long     CAN2_TX_IRQHandler            /* CAN2 TX */
+    .long     CAN2_RX0_IRQHandler           /* CAN2 RX0 */
+    .long     CAN2_RX1_IRQHandler           /* CAN2 RX1 */
+    .long     CAN2_SCE_IRQHandler           /* CAN2 SCE */
+    .long     OTG_FS_IRQHandler             /* USB OTG FS */
+    .long     DMA2_Stream5_IRQHandler       /* DMA2 Stream 5 */
+    .long     DMA2_Stream6_IRQHandler       /* DMA2 Stream 6 */
+    .long     DMA2_Stream7_IRQHandler       /* DMA2 Stream 7 */
+    .long     USART6_IRQHandler             /* USART6 */
+    .long     I2C3_EV_IRQHandler            /* I2C3 event */
+    .long     I2C3_ER_IRQHandler            /* I2C3 error */
+    .long     OTG_HS_EP1_OUT_IRQHandler     /* USB OTG HS End Point 1 Out */
+    .long     OTG_HS_EP1_IN_IRQHandler      /* USB OTG HS End Point 1 In */
+    .long     OTG_HS_WKUP_IRQHandler        /* USB OTG HS Wakeup through EXTI */
+    .long     OTG_HS_IRQHandler             /* USB OTG HS */
+    .long     DCMI_IRQHandler               /* DCMI */
+    .long     CRYP_IRQHandler               /* CRYP crypto */
+    .long     HASH_RNG_IRQHandler           /* Hash and Rng */
+    .long     FPU_IRQHandler                /* FPU */
+
+    .size    __isr_vector, . - __isr_vector
+
+    .text
+    .thumb
+    .thumb_func
+    .align 2
+    .globl    Reset_Handler
+    .type    Reset_Handler, %function
+Reset_Handler:
+/* Copy data core section from flash to RAM */
+    ldr    r1, =__etext
+    ldr    r2, =__coredata_start__
+    ldr    r3, =__coredata_end__
+
+.LC0:
+    cmp     r2, r3
+    ittt    lt
+    ldrlt   r0, [r1], #4
+    strlt   r0, [r2], #4
+    blt    .LC0
+
+/*     Loop to copy data from read only memory to RAM. The ranges
+ *      of copy from/to are specified by following symbols evaluated in
+ *      linker script.
+ *      __etext: End of code section, i.e., begin of data sections to copy from.
+ *      __data_start__/__data_end__: RAM address range that data should be
+ *      copied to. Both must be aligned to 4 bytes boundary.  */
+    ldr    r1, =__ecoredata
+    ldr    r2, =__data_start__
+    ldr    r3, =__data_end__
+
+.LC1:
+    cmp     r2, r3
+    ittt    lt
+    ldrlt   r0, [r1], #4
+    strlt   r0, [r2], #4
+    blt    .LC1
+
+/* Set the bss core section to zero */
+    mov     r0, #0
+    ldr     r1, =__corebss_start__
+    ldr     r2, =__corebss_end__
+
+.LC2:
+    cmp     r1, r2
+    itt     lt
+    strlt   r0, [r1], #4
+    blt    .LC2
+
+/* Call system initialization and startup routines */
+    ldr    r0, =SystemInit
+    blx    r0
+    ldr    r0, =_start
+    bx     r0
+    .pool
+    .size Reset_Handler, . - Reset_Handler
+
+    .text
+/*    Macro to define default handlers. Default handler
+ *    will be weak symbol and just dead loops. They can be
+ *    overwritten by other handlers */
+    .macro    def_default_handler    handler_name
+    .align 1
+    .thumb_func
+    .weak    \handler_name
+    .type    \handler_name, %function
+\handler_name :
+    b    .
+    .size    \handler_name, . - \handler_name
+    .endm
+
+    def_default_handler    NMI_Handler
+    def_default_handler    HardFault_Handler
+    def_default_handler    MemManage_Handler
+    def_default_handler    BusFault_Handler
+    def_default_handler    UsageFault_Handler
+    def_default_handler    SVC_Handler
+    def_default_handler    DebugMon_Handler
+    def_default_handler    PendSV_Handler
+    def_default_handler    SysTick_Handler
+    def_default_handler    Default_Handler
+
+    .macro    def_irq_default_handler    handler_name
+    .weak     \handler_name
+    .set      \handler_name, Default_Handler
+    .endm
+
+    def_irq_default_handler     WWDG_IRQHandler
+    def_irq_default_handler     PVD_IRQHandler
+    def_irq_default_handler     TAMP_STAMP_IRQHandler
+    def_irq_default_handler     RTC_WKUP_IRQHandler
+    def_irq_default_handler     FLASH_IRQHandler
+    def_irq_default_handler     RCC_IRQHandler
+    def_irq_default_handler     EXTI0_IRQHandler
+    def_irq_default_handler     EXTI1_IRQHandler
+    def_irq_default_handler     EXTI2_IRQHandler
+    def_irq_default_handler     EXTI3_IRQHandler
+    def_irq_default_handler     EXTI4_IRQHandler
+    def_irq_default_handler     DMA1_Stream0_IRQHandler
+    def_irq_default_handler     DMA1_Stream1_IRQHandler
+    def_irq_default_handler     DMA1_Stream2_IRQHandler
+    def_irq_default_handler     DMA1_Stream3_IRQHandler
+    def_irq_default_handler     DMA1_Stream4_IRQHandler
+    def_irq_default_handler     DMA1_Stream5_IRQHandler
+    def_irq_default_handler     DMA1_Stream6_IRQHandler
+    def_irq_default_handler     ADC_IRQHandler
+    def_irq_default_handler     CAN1_TX_IRQHandler
+    def_irq_default_handler     CAN1_RX0_IRQHandler
+    def_irq_default_handler     CAN1_RX1_IRQHandler
+    def_irq_default_handler     CAN1_SCE_IRQHandler
+    def_irq_default_handler     EXTI9_5_IRQHandler
+    def_irq_default_handler     TIM1_BRK_TIM9_IRQHandler
+    def_irq_default_handler     TIM1_UP_TIM10_IRQHandler
+    def_irq_default_handler     TIM1_TRG_COM_TIM11_IRQHandler
+    def_irq_default_handler     TIM1_CC_IRQHandler
+    def_irq_default_handler     TIM2_IRQHandler
+    def_irq_default_handler     TIM3_IRQHandler
+    def_irq_default_handler     TIM4_IRQHandler
+    def_irq_default_handler     I2C1_EV_IRQHandler
+    def_irq_default_handler     I2C1_ER_IRQHandler
+    def_irq_default_handler     I2C2_EV_IRQHandler
+    def_irq_default_handler     I2C2_ER_IRQHandler
+    def_irq_default_handler     SPI1_IRQHandler
+    def_irq_default_handler     SPI2_IRQHandler
+    def_irq_default_handler     USART1_IRQHandler
+    def_irq_default_handler     USART2_IRQHandler
+    def_irq_default_handler     USART3_IRQHandler
+    def_irq_default_handler     EXTI15_10_IRQHandler
+    def_irq_default_handler     RTC_Alarm_IRQHandler
+    def_irq_default_handler     OTG_FS_WKUP_IRQHandler
+    def_irq_default_handler     TIM8_BRK_TIM12_IRQHandler
+    def_irq_default_handler     TIM8_UP_TIM13_IRQHandler
+    def_irq_default_handler     TIM8_TRG_COM_TIM14_IRQHandler
+    def_irq_default_handler     TIM8_CC_IRQHandler
+    def_irq_default_handler     DMA1_Stream7_IRQHandler
+    def_irq_default_handler     FSMC_IRQHandler
+    def_irq_default_handler     SDIO_IRQHandler
+    def_irq_default_handler     TIM5_IRQHandler
+    def_irq_default_handler     SPI3_IRQHandler
+    def_irq_default_handler     UART4_IRQHandler
+    def_irq_default_handler     UART5_IRQHandler
+    def_irq_default_handler     TIM6_DAC_IRQHandler
+    def_irq_default_handler     TIM7_IRQHandler
+    def_irq_default_handler     DMA2_Stream0_IRQHandler
+    def_irq_default_handler     DMA2_Stream1_IRQHandler
+    def_irq_default_handler     DMA2_Stream2_IRQHandler
+    def_irq_default_handler     DMA2_Stream3_IRQHandler
+    def_irq_default_handler     DMA2_Stream4_IRQHandler
+    def_irq_default_handler     ETH_IRQHandler
+    def_irq_default_handler     ETH_WKUP_IRQHandler
+    def_irq_default_handler     CAN2_TX_IRQHandler
+    def_irq_default_handler     CAN2_RX0_IRQHandler
+    def_irq_default_handler     CAN2_RX1_IRQHandler
+    def_irq_default_handler     CAN2_SCE_IRQHandler
+    def_irq_default_handler     OTG_FS_IRQHandler
+    def_irq_default_handler     DMA2_Stream5_IRQHandler
+    def_irq_default_handler     DMA2_Stream6_IRQHandler
+    def_irq_default_handler     DMA2_Stream7_IRQHandler
+    def_irq_default_handler     USART6_IRQHandler
+    def_irq_default_handler     I2C3_EV_IRQHandler
+    def_irq_default_handler     I2C3_ER_IRQHandler
+    def_irq_default_handler     OTG_HS_EP1_OUT_IRQHandler
+    def_irq_default_handler     OTG_HS_EP1_IN_IRQHandler
+    def_irq_default_handler     OTG_HS_WKUP_IRQHandler
+    def_irq_default_handler     OTG_HS_IRQHandler
+    def_irq_default_handler     DCMI_IRQHandler
+    def_irq_default_handler     CRYP_IRQHandler
+    def_irq_default_handler     HASH_RNG_IRQHandler
+    def_irq_default_handler     FPU_IRQHandler
+    def_irq_default_handler     DEF_IRQHandler
+
+    .end

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/src/hal_bsp.c b/hw/bsp/stm32f4discovery/src/hal_bsp.c
new file mode 100644
index 0000000..763002f
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/src/hal_bsp.c
@@ -0,0 +1,77 @@
+/**
+ * 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 "hal/hal_bsp.h"
+#include "hal/hal_gpio.h"
+#include "hal/hal_flash_int.h"
+#include "mcu/stm32f407xx.h"
+#include "mcu/stm32f4xx_hal_gpio_ex.h"
+#include "mcu/stm32f4_bsp.h"
+#include "bsp/bsp.h"
+#include <assert.h>
+
+static const struct stm32f4_uart_cfg uart_cfg[UART_CNT] = {
+    [0] = {
+        .suc_uart = USART6,
+        .suc_rcc_reg = &RCC->APB2ENR,
+        .suc_rcc_dev = RCC_APB2ENR_USART6EN,
+        .suc_pin_tx = 38,
+        .suc_pin_rx = 39,
+        .suc_pin_rts = 34,
+        .suc_pin_cts = 35,
+        .suc_pin_af = GPIO_AF8_USART6,
+        .suc_irqn = USART6_IRQn
+    }
+};
+
+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)
+{
+    assert(port < UART_CNT);
+    return &uart_cfg[port];
+}
+
+const struct hal_flash *
+bsp_flash_dev(uint8_t id)
+{
+    /*
+     * Internal flash mapped to id 0.
+     */
+    if (id != 0) {
+        return NULL;
+    }
+    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/a46aeec5/hw/bsp/stm32f4discovery/src/libc_stubs.c
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/src/libc_stubs.c b/hw/bsp/stm32f4discovery/src/libc_stubs.c
new file mode 100644
index 0000000..b1b6b8b
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/src/libc_stubs.c
@@ -0,0 +1,84 @@
+/**
+ * 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 <hal/hal_system.h>
+#include <hal/hal_bsp.h>
+
+int _close(int fd);
+int _fstat(int fd, void *s);
+void _exit(int s);
+int _kill(int pid, int sig);
+int _write(int fd, void *b, int nb);
+int _isatty(int c);
+int _lseek(int fd, int off, int w);
+int _read(int fd, void *b, int nb);
+int _getpid(void);
+
+int
+_close(int fd)
+{
+    return -1;
+}
+
+int
+_fstat(int fd, void *s)
+{
+    return -1;
+}
+
+
+void
+_exit(int s)
+{
+    system_reset();
+}
+
+int
+_kill(int pid, int sig)
+{
+    return -1;
+}
+
+int
+_write(int fd, void *b, int nb)
+{
+    return -1;
+}
+
+int
+_isatty(int c)
+{
+    return -1;
+}
+
+int
+_lseek(int fd, int off, int w)
+{
+    return -1;
+}
+
+int
+_read(int fd, void *b, int nb)
+{
+    return -1;
+}
+
+int
+_getpid(void) {
+    return -1;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/src/os_bsp.c b/hw/bsp/stm32f4discovery/src/os_bsp.c
new file mode 100644
index 0000000..f2fe9e1
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/src/os_bsp.c
@@ -0,0 +1,82 @@
+/**
+ * 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.
+ */
+
+/*
+ * 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] = {
+        .fa_flash_id = 0,	/* internal flash */
+        .fa_off = 0x08000000,	/* beginning */
+        .fa_size = (32 * 1024)
+    },
+    /* 2 * 16K and 1*64K sectors here */
+    [FLASH_AREA_IMAGE_0] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x08020000,
+        .fa_size = (384 * 1024)
+    },
+    [FLASH_AREA_IMAGE_1] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x08080000,
+        .fa_size = (384 * 1024)
+    },
+    [FLASH_AREA_IMAGE_SCRATCH] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x080e0000,
+        .fa_size = (128 * 1024)
+    },
+    [FLASH_AREA_NFFS] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x08008000,
+        .fa_size = (32 * 1024)
+    }
+};
+
+void _close(int fd);
+
+/*
+ * Returns the flash map slot where the currently active image is located.
+ * If executing from internal flash from fixed location, that slot would
+ * be easy to find.
+ * If images are in external flash, and copied to RAM for execution, then
+ * this routine would have to figure out which one of those slots is being
+ * used.
+ */
+int
+bsp_imgr_current_slot(void)
+{
+    return FLASH_AREA_IMAGE_0;
+}
+
+void
+bsp_init(void)
+{
+    /*
+     * XXX this reference is here to keep this function in.
+     */
+    _sbrk(0);
+    _close(0);
+    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/a46aeec5/hw/bsp/stm32f4discovery/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/src/sbrk.c b/hw/bsp/stm32f4discovery/src/sbrk.c
new file mode 100644
index 0000000..e95a5d7
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/src/sbrk.c
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+
+extern char __HeapBase;
+extern char __HeapLimit;
+
+void *
+_sbrk(int incr)
+{
+    static char *brk = &__HeapBase;
+
+    void *prev_brk;
+
+    if (incr < 0) {
+        /* Returning memory to the heap. */
+        incr = -incr;
+        if (brk - incr < &__HeapBase) {
+            prev_brk = (void *)-1;
+        } else {
+            prev_brk = brk;
+            brk -= incr;
+        }
+    } else {
+        /* Allocating memory from the heap. */
+        if (&__HeapLimit - brk >= incr) {
+            prev_brk = brk;
+            brk += incr;
+        } else {
+            prev_brk = (void *)-1;
+        }
+    }
+
+    return prev_brk;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a46aeec5/hw/bsp/stm32f4discovery/src/system_stm32f4xx.c
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/src/system_stm32f4xx.c b/hw/bsp/stm32f4discovery/src/system_stm32f4xx.c
new file mode 100644
index 0000000..34036ca
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/src/system_stm32f4xx.c
@@ -0,0 +1,351 @@
+/**
+  ******************************************************************************
+  * @file    system_stm32f4xx.c
+  * @author  MCD Application Team
+  * @version V1.3.0
+  * @date    01-July-2015
+  * @brief   CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.
+  *
+  *   This file provides two functions and one global variable to be called from 
+  *   user application:
+  *      - SystemInit(): This function is called at startup just after reset and 
+  *                      before branch to main program. This call is made inside
+  *                      the "startup_stm32f4xx.s" file.
+  *
+  *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
+  *                                  by the user application to setup the SysTick 
+  *                                  timer or configure other parameters.
+  *                                     
+  *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
+  *                                 be called whenever the core clock is changed
+  *                                 during program execution.
+  *
+  *
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+
+/** @addtogroup CMSIS
+  * @{
+  */
+
+/** @addtogroup stm32f4xx_system
+  * @{
+  */  
+  
+/** @addtogroup STM32F4xx_System_Private_Includes
+  * @{
+  */
+
+#include "mcu/stm32f4xx.h"
+#include "bsp/cmsis_nvic.h"
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F4xx_System_Private_TypesDefinitions
+  * @{
+  */
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F4xx_System_Private_Defines
+  * @{
+  */
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F4xx_System_Private_Macros
+  * @{
+  */
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F4xx_System_Private_Variables
+  * @{
+  */
+  /* This variable is updated in three ways:
+      1) by calling CMSIS function SystemCoreClockUpdate()
+      2) by calling HAL API function HAL_RCC_GetHCLKFreq()
+      3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 
+         Note: If you use this function to configure the system clock; then there
+               is no need to call the 2 first functions listed above, since SystemCoreClock
+               variable is updated automatically.
+  */
+uint32_t SystemCoreClock = 168000000;
+
+const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes
+  * @{
+  */
+
+static void SystemClock_Config(void);
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F4xx_System_Private_Functions
+  * @{
+  */
+
+/**
+  * @brief  Setup the microcontroller system
+  *         Initialize the FPU setting, vector table location and External memory 
+  *         configuration.
+  * @param  None
+  * @retval None
+  */
+void SystemInit(void)
+{
+  /* FPU settings ------------------------------------------------------------*/
+  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
+    SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */
+  #endif
+  /* Reset the RCC clock configuration to the default reset state ------------*/
+  /* Set HSION bit */
+  RCC->CR |= (uint32_t)0x00000001;
+
+  /* Reset CFGR register */
+  RCC->CFGR = 0x00000000;
+
+  /* Reset HSEON, CSSON and PLLON bits */
+  RCC->CR &= (uint32_t)0xFEF6FFFF;
+
+  /* Reset PLLCFGR register */
+  RCC->PLLCFGR = 0x24003010;
+
+  /* Reset HSEBYP bit */
+  RCC->CR &= (uint32_t)0xFFFBFFFF;
+
+  /* Disable all interrupts */
+  RCC->CIR = 0x00000000;
+
+  /* Configure System Clock */
+  SystemClock_Config();
+
+  /* Relocate the vector table */
+  NVIC_Relocate();
+}
+
+/**
+   * @brief  Update SystemCoreClock variable according to Clock Register Values.
+  *         The SystemCoreClock variable contains the core clock (HCLK), it can
+  *         be used by the user application to setup the SysTick timer or configure
+  *         other parameters.
+  *           
+  * @note   Each time the core clock (HCLK) changes, this function must be called
+  *         to update SystemCoreClock variable value. Otherwise, any configuration
+  *         based on this variable will be incorrect.         
+  *     
+  * @note   - The system frequency computed by this function is not the real 
+  *           frequency in the chip. It is calculated based on the predefined 
+  *           constant and the selected clock source:
+  *             
+  *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
+  *                                              
+  *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
+  *                          
+  *           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) 
+  *             or HSI_VALUE(*) multiplied/divided by the PLL factors.
+  *         
+  *         (*) HSI_VALUE is a constant defined in stm32f4xx_hal_conf.h file (default value
+  *             16 MHz) but the real value may vary depending on the variations
+  *             in voltage and temperature.   
+  *    
+  *         (**) HSE_VALUE is a constant defined in stm32f4xx_hal_conf.h file (its value
+  *              depends on the application requirements), user has to ensure that HSE_VALUE
+  *              is same as the real frequency of the crystal used. Otherwise, this function
+  *              may have wrong result.
+  *                
+  *         - The result of this function could be not correct when using fractional
+  *           value for HSE crystal.
+  *     
+  * @param  None
+  * @retval None
+  */
+void SystemCoreClockUpdate(void)
+{
+  uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
+  
+  /* Get SYSCLK source -------------------------------------------------------*/
+  tmp = RCC->CFGR & RCC_CFGR_SWS;
+
+  switch (tmp)
+  {
+    case 0x00:  /* HSI used as system clock source */
+      SystemCoreClock = HSI_VALUE;
+      break;
+    case 0x04:  /* HSE used as system clock source */
+      SystemCoreClock = HSE_VALUE;
+      break;
+    case 0x08:  /* PLL used as system clock source */
+
+      /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
+         SYSCLK = PLL_VCO / PLL_P
+         */    
+      pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
+      pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
+      
+      if (pllsource != 0)
+      {
+        /* HSE used as PLL clock source */
+        pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+      }
+      else
+      {
+        /* HSI used as PLL clock source */
+        pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+      }
+
+      pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
+      SystemCoreClock = pllvco/pllp;
+      break;
+    default:
+      SystemCoreClock = HSI_VALUE;
+      break;
+  }
+  /* Compute HCLK frequency --------------------------------------------------*/
+  /* Get HCLK prescaler */
+  tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
+  /* HCLK frequency */
+  SystemCoreClock >>= tmp;
+}
+
+/**
+  * @brief  System Clock Configuration
+  *         The system Clock is configured as follow : 
+  *            System Clock source            = PLL (HSE)
+  *            SYSCLK(Hz)                     = 168000000
+  *            HCLK(Hz)                       = 168000000
+  *            AHB Prescaler                  = 1
+  *            APB1 Prescaler                 = 4
+  *            APB2 Prescaler                 = 2
+  *            HSE Frequency(Hz)              = 12000000
+  *            PLL_M                          = 12
+  *            PLL_N                          = 336
+  *            PLL_P                          = 2
+  *            PLL_Q                          = 7
+  *            VDD(V)                         = 3.3
+  *            Main regulator output voltage  = Scale1 mode
+  *            Flash Latency(WS)              = 5
+  * @param  None
+  * @retval None
+  */
+static void SystemClock_Config(void)
+{
+  /* Configure Flash prefetch, Instruction cache, Data cache */ 
+#if (INSTRUCTION_CACHE_ENABLE != 0)
+    __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
+#endif /* INSTRUCTION_CACHE_ENABLE */
+
+#if (DATA_CACHE_ENABLE != 0)
+    __HAL_FLASH_DATA_CACHE_ENABLE();
+#endif /* DATA_CACHE_ENABLE */
+
+#if (PREFETCH_ENABLE != 0)
+    __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
+#endif /* PREFETCH_ENABLE */
+
+    /* Enable Power Control clock */
+    __HAL_RCC_PWR_CLK_ENABLE();
+  
+    /* The voltage scaling allows optimizing the power consumption when the device is 
+     clocked below the maximum system frequency, to update the voltage scaling value 
+     regarding system frequency refer to product datasheet.  */
+    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
+
+    /* Enable HSE and wait till HSE is ready */  
+    RCC->CR |= ((uint32_t)RCC_CR_HSEON);
+    while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) {
+        /* XXX: some error should occur here */
+    }
+
+    /* HCLK Configuration */
+    MODIFY_REG(RCC->CFGR, RCC_CFGR_HPRE, RCC_SYSCLK_DIV1);
+
+    /* PCLK1 Configuration */ 
+    MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_HCLK_DIV4);
+
+    /* PCLK2 Configuration */ 
+    MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, (RCC_HCLK_DIV2 << 3));
+
+    /* Configure the main PLL clock source, multiplication and division factors. */
+    WRITE_REG(RCC->PLLCFGR, (RCC_PLLSOURCE_HSE  | \
+                             12                 | \
+                             (336 << POSITION_VAL(RCC_PLLCFGR_PLLN))  | \
+                             (((RCC_PLLP_DIV2 >> 1) -1) << POSITION_VAL(RCC_PLLCFGR_PLLP)) | \
+                             (7 << POSITION_VAL(RCC_PLLCFGR_PLLQ))));
+
+    /* Enable the main PLL. */
+    __HAL_RCC_PLL_ENABLE();
+
+    /* Wait till PLL is ready */  
+    while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) {
+        /* XXX: handle this */
+    }
+
+    /* Enable the Flash prefetch */
+    __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
+
+    /* Set flash wait states */
+    __HAL_FLASH_SET_LATENCY(FLASH_LATENCY_5);
+  
+    /* Start PLL */  
+    __HAL_RCC_SYSCLK_CONFIG(RCC_SYSCLKSOURCE_PLLCLK);
+
+    while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK) {
+        /* XXX: deal with this*/
+    }
+}
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+  
+/**
+  * @}
+  */    
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/



[39/50] [abbrv] incubator-mynewt-core git commit: boot; app does not need the dependency to mbedtls

Posted by cc...@apache.org.
boot; app does not need the dependency to mbedtls


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

Branch: refs/heads/master
Commit: 23895738da0820aca3965bbb8e85bf65f3c6ce5c
Parents: 5213aca
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Aug 19 16:36:06 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 16:36:06 2016 -0700

----------------------------------------------------------------------
 apps/boot/pkg.yml | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/23895738/apps/boot/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/boot/pkg.yml b/apps/boot/pkg.yml
index 2cd19f5..0ceb3d1 100644
--- a/apps/boot/pkg.yml
+++ b/apps/boot/pkg.yml
@@ -30,7 +30,6 @@ pkg.features: bootloader
 pkg.deps:
     - sys/config
     - libs/bootutil
-    - libs/mbedtls
     - libs/os
     - libs/util
     - libs/console/stub


[36/50] [abbrv] incubator-mynewt-core git commit: bootutil; make status element size depend on flash alignment restrictions.

Posted by cc...@apache.org.
bootutil; make status element size depend on flash alignment restrictions.


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

Branch: refs/heads/master
Commit: 857e611ee3c070e76f51ffd47240af982a069414
Parents: cc0317c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Aug 17 16:07:37 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Aug 19 15:11:50 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/src/bootutil_misc.c | 15 ++++++++-------
 libs/bootutil/src/bootutil_priv.h |  5 +++--
 libs/bootutil/src/loader.c        | 15 +++++++++++++++
 3 files changed, 26 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/857e611e/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c b/libs/bootutil/src/bootutil_misc.c
index e353b62..cf48f84 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -19,6 +19,7 @@
 
 #include <string.h>
 #include <inttypes.h>
+#include <assert.h>
 #include <hal/hal_flash.h>
 #include <hal/flash_map.h>
 #include <os/os.h>
@@ -150,13 +151,14 @@ boot_read_status_bytes(struct boot_status *bs, uint8_t flash_id, uint32_t off)
 {
     uint8_t status;
 
-    off -= sizeof(status) * 2;
+    assert(bs->elem_sz);
+    off -= bs->elem_sz * 2;
     while (1) {
         hal_flash_read(flash_id, off, &status, sizeof(status));
         if (status == 0xff) {
             break;
         }
-        off--;
+        off -= bs->elem_sz;
         if (bs->state == 2) {
             bs->idx++;
             bs->state = 0;
@@ -186,14 +188,14 @@ boot_read_status(struct boot_status *bs)
     if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
         boot_magic_loc(0, &flash_id, &off);
         boot_read_status_bytes(bs, flash_id, off);
-        console_printf("status in slot0, %lu/%lu\n", bs->idx, bs->state);
+        console_printf("status in slot0, %lu/%u\n", bs->idx, bs->state);
         return 1;
     }
     boot_scratch_magic(&bit);
     if (bit.bit_start == BOOT_IMG_MAGIC && bit.bit_done == 0xffffffff) {
         boot_scratch_loc(&flash_id, &off);
         boot_read_status_bytes(bs, flash_id, off);
-        console_printf("status in scratch, %lu/%lu\n", bs->idx, bs->state);
+        console_printf("status in scratch, %lu/%u\n", bs->idx, bs->state);
         return 1;
     }
     return 0;
@@ -227,10 +229,9 @@ boot_write_status(struct boot_status *bs)
          */
         boot_magic_loc(0, &flash_id, &off);
     }
-    off -= ((3 * sizeof(uint8_t)) * bs->idx +
-      sizeof(uint8_t) * (bs->state + 1));
+    off -= ((3 * bs->elem_sz) * bs->idx + bs->elem_sz * (bs->state + 1));
 
-    console_printf("status write, %lu/%lu -> %lx\n", bs->idx, bs->state, off);
+    console_printf("status write, %lu/%u -> %lx\n", bs->idx, bs->state, off);
 
     val = bs->state;
     hal_flash_write(flash_id, off, &val, sizeof(val));

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/857e611e/libs/bootutil/src/bootutil_priv.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_priv.h b/libs/bootutil/src/bootutil_priv.h
index ffdfcb2..697145d 100644
--- a/libs/bootutil/src/bootutil_priv.h
+++ b/libs/bootutil/src/bootutil_priv.h
@@ -40,8 +40,9 @@ struct boot_image_location {
  * Maintain state of copy progress.
  */
 struct boot_status {
-    uint32_t idx;
-    uint32_t state;
+    uint32_t idx;       /* Which area we're operating on */
+    uint8_t elem_sz;    /* Size of the status element to write in bytes */
+    uint8_t state;      /* Which part of the swapping process are we at */
 };
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/857e611e/libs/bootutil/src/loader.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/loader.c b/libs/bootutil/src/loader.c
index 22187a7..3171c05 100644
--- a/libs/bootutil/src/loader.c
+++ b/libs/bootutil/src/loader.c
@@ -137,6 +137,7 @@ boot_image_info(void)
 {
     int i;
     struct boot_img *b;
+    struct flash_area *scratch;
 
     for (i = 0; i < BOOT_NUM_SLOTS; i++) {
         b = &boot_img[i];
@@ -144,6 +145,20 @@ boot_image_info(void)
         boot_read_image_header(&b->loc, &b->hdr);
         b->area = boot_req->br_img_sz;
     }
+
+    /*
+     * Figure out what size to write update status update as.
+     * The size depends on what the minimum write size is for scratch
+     * area, active image slot. We need to use the bigger of those 2
+     * values.
+     */
+    boot_state.elem_sz = hal_flash_align(boot_img[0].loc.bil_flash_id);
+
+    scratch = &boot_req->br_area_descs[boot_req->br_scratch_area_idx];
+    i = hal_flash_align(scratch->fa_flash_id);
+    if (i > boot_state.elem_sz) {
+        boot_state.elem_sz = i;
+    }
 }
 
 /*