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 2018/01/04 03:01:14 UTC

[mynewt-mcumgr] branch master updated (36a8312 -> f3bebef)

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git.


    from 36a8312  image management
     new 7ada577  img - Add `slot` param to `img_impl_write_pending`
     new 4047ddd  img - Format doxygen comments for reading in src.
     new aeb2e28  img (zephyr) - initialize flash dev at init time.
     new b9326f0  Some metadata corrections for Mynewt port.
     new a889f74  img - Mynewt port.
     new 916a93c  SMP transport for zephyr
     new 46ad88a  Use latest tinycbor.
     new f3bebef  Mynewt - minor renames.

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 img/include/img/img_impl.h                      |  51 +++---
 {smp => img}/pkg.yml                            |  31 ++--
 {mgmt => img}/port/mynewt/pkg.yml               |   8 +-
 img/port/mynewt/src/mynewt_img.c                | 191 +++++++++++++++++++
 img/port/zephyr/src/zephyr_img.c                |  39 ++--
 img/src/img_state.c                             |   9 +-
 smp/pkg.yml => img/syscfg.yml                   |  39 ++--
 mgmt/include/mgmt/endian.h                      |  31 ++++
 mgmt/pkg.yml                                    |   8 +-
 mgmt/port/mynewt/pkg.yml                        |   4 +-
 mgmt/src/mgmt.c                                 |   7 +-
 smp/include/smp/smp.h                           |   1 -
 smp/pkg.yml                                     |  12 +-
 smp/port/mynewt/include/mynewt_smp/mynewt_smp.h |  16 +-
 smp/port/mynewt/pkg.yml                         |   6 +-
 smp/port/mynewt/src/mynewt_smp.c                |  28 +--
 smp/port/zephyr/include/zephyr_smp/zephyr_smp.h |  37 ++++
 smp/port/zephyr/src/zephyr_smp.c                | 234 ++++++++++++++++++++++++
 smp/src/smp.c                                   |  34 +---
 19 files changed, 626 insertions(+), 160 deletions(-)
 copy {smp => img}/pkg.yml (66%)
 copy {mgmt => img}/port/mynewt/pkg.yml (81%)
 create mode 100644 img/port/mynewt/src/mynewt_img.c
 copy smp/pkg.yml => img/syscfg.yml (62%)
 create mode 100644 mgmt/include/mgmt/endian.h
 create mode 100644 smp/port/zephyr/include/zephyr_smp/zephyr_smp.h
 create mode 100644 smp/port/zephyr/src/zephyr_smp.c

-- 
To stop receiving notification emails like this one, please contact
['"commits@mynewt.apache.org" <co...@mynewt.apache.org>'].

[mynewt-mcumgr] 05/08: img - Mynewt port.

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit a889f74ce4a8876fd1cf2bea7c50bfa7672e0371
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Jan 3 12:12:40 2018 -0800

    img - Mynewt port.
---
 img/pkg.yml                      |  46 ++++++++++
 img/port/mynewt/pkg.yml          |  31 +++++++
 img/port/mynewt/src/mynewt_img.c | 191 +++++++++++++++++++++++++++++++++++++++
 img/syscfg.yml                   |  34 +++++++
 4 files changed, 302 insertions(+)

diff --git a/img/pkg.yml b/img/pkg.yml
new file mode 100644
index 0000000..351e3cf
--- /dev/null
+++ b/img/pkg.yml
@@ -0,0 +1,46 @@
+#
+# 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: img
+pkg.description: Library for image uploading.
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+    - '@apache-mynewt-core/boot/split'
+    - '@apache-mynewt-core/encoding/base64'
+    - '@apache-mynewt-core/sys/flash_map'
+    - '@mynewt-mcumgr/mgmt'
+
+pkg.req_apis:
+    - newtmgr
+    - bootloader
+
+pkg.deps.IMG_FS:
+    - '@apache-mynewt-core/fs/fs'
+
+pkg.deps.IMG_COREDUMP:
+    - '@apache-mynewt-core/sys/coredump'
+
+pkg.deps.IMG_SHELL:
+    - '@apache-mynewt-core/sys/shell'
+
+pkg.init:
+    img_module_init: 500
diff --git a/img/port/mynewt/pkg.yml b/img/port/mynewt/pkg.yml
new file mode 100644
index 0000000..ecbc68f
--- /dev/null
+++ b/img/port/mynewt/pkg.yml
@@ -0,0 +1,31 @@
+#
+# 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: img/port/mynewt
+pkg.description: XXX
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+    - '@apache-mynewt-core/boot/split'
+    - '@apache-mynewt-core/encoding/base64'
+    - '@apache-mynewt-core/sys/flash_map'
+    - '@mynewt-mcumgr/img'
+    - '@mynewt-mcumgr/mgmt'
diff --git a/img/port/mynewt/src/mynewt_img.c b/img/port/mynewt/src/mynewt_img.c
new file mode 100644
index 0000000..28d39f3
--- /dev/null
+++ b/img/port/mynewt/src/mynewt_img.c
@@ -0,0 +1,191 @@
+#include "sysinit/sysinit.h"
+
+int
+img_impl_erase_slot(void)
+{
+    const struct flash_area *fa;
+    bool empty;
+    int rc;
+
+    rc = flash_area_open(FLASH_AREA_IMAGE_1, &fa);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    rc = flash_area_is_empty(fa, &empty);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    if (!empty) {
+        rc = flash_area_erase(fa, 0, fa->fa_size);
+        if (rc != 0) {
+            return MGMT_ERR_EUNKNOWN;
+        }
+    }
+
+    return 0;
+}
+
+int
+img_impl_write_pending(int slot, bool permanent)
+{
+    uint32_t image_flags;
+    uint8_t state_flags;
+    int split_app_active;
+    int rc;
+
+    state_flags = imgmgr_state_flags(slot);
+    split_app_active = split_app_active_get();
+
+    /* Unconfirmed slots are always runable.  A confirmed slot can only be
+     * run if it is a loader in a split image setup.
+     */
+    if (state_flags & IMGMGR_STATE_F_CONFIRMED &&
+        (slot != 0 || !split_app_active)) {
+
+        return MGMT_ERR_EBADSTATE;
+    }
+
+    rc = imgr_read_info(slot, NULL, NULL, &image_flags);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    if (!(image_flags & IMAGE_F_NON_BOOTABLE)) {
+        /* Unified image or loader. */
+        if (!split_app_active) {
+            /* No change in split status. */
+            rc = boot_set_pending(permanent);
+            if (rc != 0) {
+                return MGMT_ERR_EUNKNOWN;
+            }
+        } else {
+            /* Currently loader + app; testing loader-only. */
+            if (permanent) {
+                rc = split_write_split(SPLIT_MODE_LOADER);
+            } else {
+                rc = split_write_split(SPLIT_MODE_TEST_LOADER);
+            }
+            if (rc != 0) {
+                return MGMT_ERR_EUNKNOWN;
+            }
+        }
+    } else {
+        /* Testing split app. */
+        if (permanent) {
+            rc = split_write_split(SPLIT_MODE_APP);
+        } else {
+            rc = split_write_split(SPLIT_MODE_TEST_APP);
+        }
+        if (rc != 0) {
+            return MGMT_ERR_EUNKNOWN;
+        }
+    }
+
+    return 0;
+}
+
+int
+img_impl_write_confirmed(void)
+{
+    /* Confirm the unified image or loader in slot 0. */
+    rc = boot_set_confirmed();
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    /* If a split app in slot 1 is active, confirm it as well. */
+    if (split_app_active_get()) {
+        rc = split_write_split(SPLIT_MODE_APP);
+        if (rc != 0) {
+            return MGMT_ERR_EUNKNOWN;
+        }
+    } else {
+        rc = split_write_split(SPLIT_MODE_LOADER);
+        if (rc != 0) {
+            return MGMT_ERR_EUNKNOWN;
+        }
+    }
+
+    return 0;
+}
+
+int
+img_impl_read(int slot, unsigned int offset, void *dst,
+              unsigned int num_bytes)
+{
+    const struct flash_area *fa;
+    int area_id;
+    int rc;
+
+    area_id = flash_area_id_from_image_slot(image_slot);
+    rc = flash_area_open(area_id, &fa);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    rc = flash_area_read(fa, offset, dst, num_bytes);
+    flash_area_close(fa);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    return 0;
+}
+
+int
+img_impl_write_image_data(unsigned int offset, const void *data,
+                          unsigned int num_bytes, bool last)
+{
+    const struct flash_area *fa;
+    int rc;
+
+    rc = flash_area_open(FLASH_AREA_IMAGE_1, &fa);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    rc = flash_area_write(fa, offset, data, num_bytes);
+    flash_area_close(fa);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    return 0;
+}
+
+int
+img_impl_swap_type(void)
+{
+    switch (boot_swap_type()) {
+    case BOOT_SWAP_TYPE_NONE:
+        return IMG_SWAP_TYPE_NONE;
+    case BOOT_SWAP_TYPE_TEST:
+        return IMG_SWAP_TYPE_TEST;
+    case BOOT_SWAP_TYPE_PERM:
+        return IMG_SWAP_TYPE_PERM;
+    case BOOT_SWAP_TYPE_REVERT:
+        return IMG_SWAP_TYPE_REVERT;
+    default:
+        assert(0);
+        return IMG_SWAP_TYPE_NONE;
+    }
+}
+
+void
+img_module_init(void)
+{
+    int rc;
+
+    /* Ensure this function only gets called by sysinit. */
+    SYSINIT_ASSERT_ACTIVE();
+
+    rc = img_group_register();
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+#if MYNEWT_VAL(IMGMGR_CLI)
+    rc = imgr_cli_register();
+    SYSINIT_PANIC_ASSERT(rc == 0);
+#endif
+}
diff --git a/img/syscfg.yml b/img/syscfg.yml
new file mode 100644
index 0000000..4f3c95d
--- /dev/null
+++ b/img/syscfg.yml
@@ -0,0 +1,34 @@
+# 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.
+#
+
+# Package: mgmt/imgmgr
+
+syscfg.defs:
+    IMGMGR_COREDUMP:
+        description: 'Newtmgr commands for fetching/erasing coredump'
+        value: 0
+    IMGMGR_CLI:
+        description: 'CLI commands to interact with image management'
+        value: 0
+        restrictions:
+            - SHELL_TASK
+    IMGMGR_MAX_CHUNK_SIZE:
+        description: >
+            The maximum amount of image or core data that can fit in a
+            single NMP message
+        value: 512

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.

[mynewt-mcumgr] 01/08: img - Add `slot` param to `img_impl_write_pending`

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit 7ada577e39714ce19743bb215b1f7c33f945f52b
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Jan 3 12:06:44 2018 -0800

    img - Add `slot` param to `img_impl_write_pending`
    
    The old interface precluded the use of split images in Mynewt.  For
    non-split-images, the `slot` argument is always 1.
---
 img/include/img/img_impl.h       | 8 +++++---
 img/port/zephyr/src/zephyr_img.c | 5 ++++-
 img/src/img_state.c              | 9 +--------
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/img/include/img/img_impl.h b/img/include/img/img_impl.h
index f634110..7c3248d 100644
--- a/img/include/img/img_impl.h
+++ b/img/include/img/img_impl.h
@@ -14,9 +14,11 @@
 int img_impl_erase_slot(void);
 
 /**
- * @brief Marks the image in slot 1 as pending. On the next reboot, the system
- * will perform a boot of the slot 1 image.
+ * @brief Marks the image in the specified slot as pending. On the next reboot,
+ * the system will perform a boot of the specified image.
  *
+ * @param slot The slot to mark as pending.  In the typical use case, this is
+ * 1.
  * @param permanent Whether the image should be used permanently or
  * only tested once:
  *   0=run image once, then confirm or revert.
@@ -24,7 +26,7 @@ int img_impl_erase_slot(void);
  *
  * @return 0 on success, MGMT_ERR_[...] code on failure.
  */
-int img_impl_write_pending(bool permanent);
+int img_impl_write_pending(int slot, bool permanent);
 
 /**
  * @brief Marks the image in slot 0 as confirmed. The system will continue
diff --git a/img/port/zephyr/src/zephyr_img.c b/img/port/zephyr/src/zephyr_img.c
index f99d5fe..4d298eb 100644
--- a/img/port/zephyr/src/zephyr_img.c
+++ b/img/port/zephyr/src/zephyr_img.c
@@ -105,11 +105,14 @@ img_impl_erase_slot(void)
 }
 
 int
-img_impl_write_pending(bool permanent)
+img_impl_write_pending(int slot, bool permanent)
 {
     int rc;
 
     img_impl_init_flash();
+    if (slot != 1) {
+        return MGMT_ERR_EINVAL;
+    }
 
     rc = boot_request_upgrade(permanent);
     if (rc != 0) {
diff --git a/img/src/img_state.c b/img/src/img_state.c
index b8ae6fa..84b797f 100644
--- a/img/src/img_state.c
+++ b/img/src/img_state.c
@@ -106,7 +106,6 @@ img_state_slot_in_use(int slot)
 int
 img_state_set_pending(int slot, int permanent)
 {
-    uint32_t image_flags;
     uint8_t state_flags;
     int rc;
 
@@ -119,12 +118,7 @@ img_state_set_pending(int slot, int permanent)
         return MGMT_ERR_EBADSTATE;
     }
 
-    rc = img_read_info(slot, NULL, NULL, &image_flags);
-    if (rc != 0) {
-        return MGMT_ERR_EUNKNOWN;
-    }
-
-    rc = img_impl_write_pending(permanent);
+    rc = img_impl_write_pending(slot, permanent);
     if (rc != 0) {
         return MGMT_ERR_EUNKNOWN;
     }
@@ -142,7 +136,6 @@ img_state_confirm(void)
         return MGMT_ERR_EBADSTATE;
     }
 
-    /* Confirm the unified image or loader in slot 0. */
     rc = img_impl_write_confirmed();
     if (rc != 0) {
         return MGMT_ERR_EUNKNOWN;

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.

[mynewt-mcumgr] 04/08: Some metadata corrections for Mynewt port.

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit b9326f0a6d54907afaf13654e330c5bb1634dda9
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Jan 3 12:12:24 2018 -0800

    Some metadata corrections for Mynewt port.
---
 mgmt/pkg.yml             |  8 ++++----
 mgmt/port/mynewt/pkg.yml |  4 ++--
 smp/pkg.yml              | 12 ++++++------
 smp/port/mynewt/pkg.yml  |  6 +++---
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/mgmt/pkg.yml b/mgmt/pkg.yml
index 7059910..58cad0c 100644
--- a/mgmt/pkg.yml
+++ b/mgmt/pkg.yml
@@ -17,13 +17,13 @@
 # under the License.
 #
 
-pkg.name: mgmt/mgmt
+pkg.name: mgmt
 pkg.description: System-wide management interfaces.
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
 
 pkg.deps:
-    - encoding/tinycbor
-    - kernel/os
-    - mgmt/mgmt/port/mynewt
+    - '@apache-mynewt-core/encoding/tinycbor'
+    - '@apache-mynewt-core/kernel/os'
+    - '@mynewt-mcumgr/mgmt/port/mynewt'
diff --git a/mgmt/port/mynewt/pkg.yml b/mgmt/port/mynewt/pkg.yml
index 048acfc..ed4a680 100644
--- a/mgmt/port/mynewt/pkg.yml
+++ b/mgmt/port/mynewt/pkg.yml
@@ -17,11 +17,11 @@
 # under the License.
 #
 
-pkg.name: mgmt/mgmt/port/mynewt
+pkg.name: mgmt/port/mynewt
 pkg.description: XXX
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
 
 pkg.deps:
-    - kernel/os
+    - '@apache-mynewt-core/kernel/os'
diff --git a/smp/pkg.yml b/smp/pkg.yml
index bf165cb..b615c60 100644
--- a/smp/pkg.yml
+++ b/smp/pkg.yml
@@ -24,11 +24,11 @@ pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
 
 pkg.deps:
-    - encoding/cborattr
-    - kernel/os
-    - mgmt
-    - smp/port/mynewt
-    - util/mem
+    - '@apache-mynewt-core/encoding/cborattr'
+    - '@apache-mynewt-core/kernel/os'
+    - '@apache-mynewt-core/util/mem'
+    - '@mynewt-mcumgr/mgmt'
+    - '@mynewt-mcumgr/smp/port/mynewt'
 
 pkg.deps.NEWTMGR_BLE_HOST:
     # XXX: Inaccurate path.
@@ -38,4 +38,4 @@ pkg.apis:
     - smp
 
 pkg.init:
-    nmgr_pkg_init: 500
+    smp_pkg_init: 500
diff --git a/smp/port/mynewt/pkg.yml b/smp/port/mynewt/pkg.yml
index ae71ebf..9ccc2fd 100644
--- a/smp/port/mynewt/pkg.yml
+++ b/smp/port/mynewt/pkg.yml
@@ -24,6 +24,6 @@ pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
 
 pkg.deps:
-    - kernel/os
-    - mgmt
-    - util/mem
+    - '@apache-mynewt-core/kernel/os'
+    - '@apache-mynewt-core/util/mem'
+    - '@mynewt-mcumgr/mgmt'

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.

[mynewt-mcumgr] 02/08: img - Format doxygen comments for reading in src.

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit 4047ddd339f0d5e48e7f0a0d05aa26469922b101
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Jan 3 12:11:07 2018 -0800

    img - Format doxygen comments for reading in src.
---
 img/include/img/img_impl.h | 47 ++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/img/include/img/img_impl.h b/img/include/img/img_impl.h
index 7c3248d..ce19838 100644
--- a/img/include/img/img_impl.h
+++ b/img/include/img/img_impl.h
@@ -9,7 +9,7 @@
 /**
  * @brief Ensures the spare slot (slot 1) is fully erased.
  *
- * @return 0 on success, MGMT_ERR_[...] code on failure.
+ * @return                      0 on success, MGMT_ERR_[...] code on failure.
  */
 int img_impl_erase_slot(void);
 
@@ -17,14 +17,15 @@ int img_impl_erase_slot(void);
  * @brief Marks the image in the specified slot as pending. On the next reboot,
  * the system will perform a boot of the specified image.
  *
- * @param slot The slot to mark as pending.  In the typical use case, this is
- * 1.
- * @param permanent Whether the image should be used permanently or
- * only tested once:
- *   0=run image once, then confirm or revert.
- *   1=run image forever.
+ * @param slot                  The slot to mark as pending.  In the typical
+ *                                  use case, this is 1.
+ * @param permanent             Whether the image should be used permanently or
+ *                                  only tested once:
+ *                                      0=run image once, then confirm or
+ *                                        revert.
+ *                                      1=run image forever.
  *
- * @return 0 on success, MGMT_ERR_[...] code on failure.
+ * @return                      0 on success, MGMT_ERR_[...] code on failure.
  */
 int img_impl_write_pending(int slot, bool permanent);
 
@@ -32,19 +33,19 @@ int img_impl_write_pending(int slot, bool permanent);
  * @brief Marks the image in slot 0 as confirmed. The system will continue
  * booting into the image in slot 0 until told to boot from a different slot.
  *
- * @return 0 on success, MGMT_ERR_[...] code on failure.
+ * @return                      0 on success, MGMT_ERR_[...] code on failure.
  */
 int img_impl_write_confirmed(void);
 
 /**
  * @brief Reads the specified chunk of data from an image slot.
  *
- * @param slot The index of the slot to read from.
- * @param offset The offset within the slot to read from.
- * @param dst On success, the read data gets written here.
- * @param num_bytes The number of byets to read.
+ * @param slot                  The index of the slot to read from.
+ * @param offset                The offset within the slot to read from.
+ * @param dst                   On success, the read data gets written here.
+ * @param num_bytes             The number of byets to read.
  *
- * @return 0 on success, MGMT_ERR_[...] code on failure.
+ * @return                      0 on success, MGMT_ERR_[...] code on failure.
  */
 int img_impl_read(int slot, unsigned int offset, void *dst,
                   unsigned int num_bytes);
@@ -52,14 +53,16 @@ int img_impl_read(int slot, unsigned int offset, void *dst,
 /**
  * @brief Writes the specified chunk of image data to slot 1.
  *
- * @param offset The offset within slot 1 to write to.
- * @param data The image data to write.
- * @param num_bytes The number of bytes to read.
- * @param last Whether this chunk is the end of the image:
- *   false=additional image chunks are forthcoming
- *   true=last image chunk; flush unwritten data to disk
+ * @param offset                The offset within slot 1 to write to.
+ * @param data                  The image data to write.
+ * @param num_bytes             The number of bytes to read.
+ * @param last                  Whether this chunk is the end of the image:
+ *                                  false=additional image chunks are
+ *                                        forthcoming.
+ *                                  true=last image chunk; flush unwritten data
+ *                                       to disk.
  *
- * @return 0 on success, MGMT_ERR_[...] code on failure.
+ * @return                      0 on success, MGMT_ERR_[...] code on failure.
  */
 int img_impl_write_image_data(unsigned int offset, const void *data,
                               unsigned int num_bytes, bool last);
@@ -68,7 +71,7 @@ int img_impl_write_image_data(unsigned int offset, const void *data,
  * @brief Indicates the type of swap operation that will occur on the next
  * reboot, if any.
  *
- * @return an IMG_SWAP_TYPE_[...] code.
+ * @return                      An IMG_SWAP_TYPE_[...] code.
  */
 int img_impl_swap_type(void);
 

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.

[mynewt-mcumgr] 07/08: Use latest tinycbor.

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit 46ad88ab79f90a9a5674a22e641172770e7af3c9
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Jan 3 17:24:38 2018 -0800

    Use latest tinycbor.
---
 mgmt/include/mgmt/endian.h | 31 +++++++++++++++++++++++++++++++
 mgmt/src/mgmt.c            |  7 ++++---
 smp/src/smp.c              | 34 ++++------------------------------
 3 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/mgmt/include/mgmt/endian.h b/mgmt/include/mgmt/endian.h
new file mode 100644
index 0000000..704213e
--- /dev/null
+++ b/mgmt/include/mgmt/endian.h
@@ -0,0 +1,31 @@
+#ifndef H_MGMT_ENDIAN_
+#define H_MGMT_ENDIAN_
+
+#include <inttypes.h>
+
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+
+#ifndef ntohs
+#define ntohs(x) (x)
+#endif
+
+#ifndef htons
+#define htons(x) (x)
+#endif
+
+#else
+/* Little endian. */
+
+#ifndef ntohs
+#define ntohs(x)   ((uint16_t)  \
+    ((((x) & 0xff00) >> 8) |    \
+     (((x) & 0x00ff) << 8)))
+#endif
+
+#ifndef htons
+#define htons(x) (ntohs(x))
+#endif
+
+#endif
+
+#endif
diff --git a/mgmt/src/mgmt.c b/mgmt/src/mgmt.c
index f12fc98..f906e5d 100644
--- a/mgmt/src/mgmt.c
+++ b/mgmt/src/mgmt.c
@@ -18,7 +18,8 @@
  */
 
 #include <string.h>
-#include "tinycbor/cbor.h"
+#include "cbor.h"
+#include "mgmt/endian.h"
 #include "mgmt/mgmt.h"
 
 static struct mgmt_group *mgmt_group_list;
@@ -145,12 +146,12 @@ mgmt_cbuf_init(struct mgmt_cbuf *cbuf, struct mgmt_streamer *streamer)
 {
     int rc;
 
-    rc = cbor_parser_init(streamer->reader, 0, &cbuf->parser, &cbuf->it);
+    rc = cbor_parser_cust_reader_init(streamer->reader, 0, &cbuf->parser, &cbuf->it);
     if (rc != CborNoError) {
         return mgmt_err_from_cbor(rc);
     }
 
-    cbor_encoder_init(&cbuf->encoder, streamer->writer, 0);
+    cbor_encoder_cust_writer_init(&cbuf->encoder, streamer->writer, 0);
 
     return 0;
 }
diff --git a/smp/src/smp.c b/smp/src/smp.c
index 6caf653..f88e17f 100644
--- a/smp/src/smp.c
+++ b/smp/src/smp.c
@@ -22,36 +22,10 @@
 #include <assert.h>
 #include <string.h>
 
+#include "mgmt/endian.h"
 #include "mgmt/mgmt.h"
 #include "smp/smp.h"
-#include "tinycbor/cbor.h"
-#include "tinycbor/cbor_mbuf_writer.h"
-#include "tinycbor/cbor_mbuf_reader.h"
-
-#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-
-#ifndef ntohs
-#define ntohs(x) (x)
-#endif
-
-#ifndef htons
-#define htons(x) (x)
-#endif
-
-#else
-/* Little endian. */
-
-#ifndef ntohs
-#define ntohs(x)   ((uint16_t)  \
-    ((((x) & 0xff00) >> 8) |    \
-     (((x) & 0x00ff) << 8)))
-#endif
-
-#ifndef htons
-#define htons(x) (ntohs(x))
-#endif
-
-#endif
+#include "cbor.h"
 
 static int
 smp_align4(int x)
@@ -96,11 +70,11 @@ smp_read_hdr(struct smp_streamer *streamer, struct mgmt_hdr *dst_hdr)
 
     reader = streamer->ss_base.reader;
 
-    if (reader->message_size < sizeof *hdr) {
+    if (reader->message_size < sizeof *dst_hdr) {
         return MGMT_ERR_EINVAL;
     }
 
-    reader->cpy(reader, (char *)hdr, 0, sizeof *hdr);
+    reader->cpy(reader, (char *)dst_hdr, 0, sizeof *dst_hdr);
     return 0;
 }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.

[mynewt-mcumgr] 08/08: Mynewt - minor renames.

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit f3bebefe340ddbb6d9d1f5e492a2a930895b34cb
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Jan 3 17:25:12 2018 -0800

    Mynewt - minor renames.
---
 smp/port/mynewt/include/mynewt_smp/mynewt_smp.h | 16 +++++++-------
 smp/port/mynewt/src/mynewt_smp.c                | 28 ++++++++++++-------------
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/smp/port/mynewt/include/mynewt_smp/mynewt_smp.h b/smp/port/mynewt/include/mynewt_smp/mynewt_smp.h
index 02883c5..294d44d 100644
--- a/smp/port/mynewt/include/mynewt_smp/mynewt_smp.h
+++ b/smp/port/mynewt/include/mynewt_smp/mynewt_smp.h
@@ -33,7 +33,7 @@ extern "C" {
  * Transmit function.  The supplied mbuf is always consumed, regardless of
  * return code.
  */
-typedef int mynewt_smp_transport_out_fn(struct mynewt_smp_transport *mnt,
+typedef int mynewt_smp_transport_out_fn(struct mynewt_smp_transport *mst,
                                         struct os_mbuf *m);
 
 /**
@@ -48,16 +48,16 @@ typedef int mynewt_smp_transport_out_fn(struct mynewt_smp_transport *mnt,
 typedef uint16_t mynewt_smp_transport_get_mtu_fn(struct os_mbuf *m);
 
 struct mynewt_smp_transport {
-    struct os_mqueue msp_imq;
-    mynewt_smp_transport_out_fn *msp_output;
-    mynewt_smp_transport_get_mtu_fn *msp_get_mtu;
+    struct os_mqueue mst_imq;
+    mynewt_smp_transport_out_fn *mst_output;
+    mynewt_smp_transport_get_mtu_fn *mst_get_mtu;
 };
 
-int mynewt_smp_transport_init(struct mynewt_smp_transport *mnt,
-                               mynewt_smp_transport_out_fn *output_func,
-                               mynewt_smp_transport_get_mtu_fn *get_mtu_func);
+int mynewt_smp_transport_init(struct mynewt_smp_transport *mst,
+                              mynewt_smp_transport_out_fn *output_func,
+                              mynewt_smp_transport_get_mtu_fn *get_mtu_func);
 
-int mynewt_smp_rx_req(struct mynewt_smp_transport *mnt, struct os_mbuf *req);
+int mynewt_smp_rx_req(struct mynewt_smp_transport *mst, struct os_mbuf *req);
 
 #ifdef __cplusplus
 }
diff --git a/smp/port/mynewt/src/mynewt_smp.c b/smp/port/mynewt/src/mynewt_smp.c
index f5f2950..bf6eace 100644
--- a/smp/port/mynewt/src/mynewt_smp.c
+++ b/smp/port/mynewt/src/mynewt_smp.c
@@ -139,16 +139,16 @@ mynewt_smp_init_writer(struct cbor_encoder_writer *writer, void *buf,
 static int
 mynewt_smp_tx_rsp(struct smp_streamer *ss, void *rsp, void *arg)
 {
-    struct mynewt_smp_transport *msp;
+    struct mynewt_smp_transport *mst;
     struct os_mbuf *om_rsp;
     struct os_mbuf *frag;
     uint16_t mtu;
     int rc;
 
-    msp = arg;
+    mst = arg;
     om_rsp = rsp;
 
-    mtu = msp->msp_get_mtu(rsp);
+    mtu = mst->mst_get_mtu(rsp);
     if (mtu == 0) {
         /* The transport cannot support a transmission right now. */
         return MGMT_ERR_EUNKNOWN;
@@ -161,7 +161,7 @@ mynewt_smp_tx_rsp(struct smp_streamer *ss, void *rsp, void *arg)
             return MGMT_ERR_ENOMEM;
         }
 
-        rc = msp->msp_output(msp, frag);
+        rc = mst->mst_output(mst, frag);
         if (rc != 0) {
             /* Output function already freed mbuf. */
             return MGMT_ERR_EUNKNOWN;
@@ -178,7 +178,7 @@ mynewt_smp_free_buf(void *buf, void *arg)
 }
 
 static void
-mynewt_smp_process(struct mynewt_smp_transport *msp)
+mynewt_smp_process(struct mynewt_smp_transport *mst)
 {
     struct cbor_mbuf_reader reader;
     struct cbor_mbuf_writer writer;
@@ -191,13 +191,13 @@ mynewt_smp_process(struct mynewt_smp_transport *msp)
             .cfg = &mynewt_smp_cbor_cfg,
             .reader = &reader.r,
             .writer = &writer.enc,
-            .cb_arg = msp,
+            .cb_arg = mst,
         },
         .ss_tx_rsp = mynewt_smp_tx_rsp,
     };
 
     while (1) {
-        req = os_mqueue_get(&msp->msp_imq);
+        req = os_mqueue_get(&mst->mst_imq);
         if (req == NULL) {
             break;
         }
@@ -216,18 +216,18 @@ mynewt_smp_event_data_in(struct os_event *ev)
 }
 
 int
-mynewt_smp_transport_init(struct mynewt_smp_transport *msp,
+mynewt_smp_transport_init(struct mynewt_smp_transport *mst,
                           mynewt_smp_transport_out_fn *output_func,
                           mynewt_smp_transport_get_mtu_fn *get_mtu_func)
 {
     int rc;
 
-    *msp = (struct mynewt_smp_transport) {
-        .msp_output = output_func,
-        .msp_get_mtu = get_mtu_func,
+    *mst = (struct mynewt_smp_transport) {
+        .mst_output = output_func,
+        .mst_get_mtu = get_mtu_func,
     };
 
-    rc = os_mqueue_init(&msp->msp_imq, mynewt_smp_event_data_in, msp);
+    rc = os_mqueue_init(&mst->mst_imq, mynewt_smp_event_data_in, mst);
     if (rc != 0) {
         return rc;
     }
@@ -236,11 +236,11 @@ mynewt_smp_transport_init(struct mynewt_smp_transport *msp,
 }
 
 int
-mynewt_smp_rx_req(struct mynewt_smp_transport *msp, struct os_mbuf *req)
+mynewt_smp_rx_req(struct mynewt_smp_transport *mst, struct os_mbuf *req)
 {
     int rc;
 
-    rc = os_mqueue_put(&msp->msp_imq, mgmt_evq_get(), req);
+    rc = os_mqueue_put(&mst->mst_imq, mgmt_evq_get(), req);
     if (rc != 0) {
         os_mbuf_free_chain(req);
     }

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.

[mynewt-mcumgr] 06/08: SMP transport for zephyr

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit 916a93cfcd3683244e826073abe9640284fb0f28
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Jan 3 17:23:43 2018 -0800

    SMP transport for zephyr
---
 smp/include/smp/smp.h                           |   1 -
 smp/port/zephyr/include/zephyr_smp/zephyr_smp.h |  37 ++++
 smp/port/zephyr/src/zephyr_smp.c                | 234 ++++++++++++++++++++++++
 3 files changed, 271 insertions(+), 1 deletion(-)

diff --git a/smp/include/smp/smp.h b/smp/include/smp/smp.h
index 2feaa47..15e0b40 100644
--- a/smp/include/smp/smp.h
+++ b/smp/include/smp/smp.h
@@ -28,7 +28,6 @@
 extern "C" {
 #endif
 
-struct mynewt_smp_transport;
 struct smp_streamer;
 struct mgmt_hdr;
 
diff --git a/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h b/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h
new file mode 100644
index 0000000..d74e8c4
--- /dev/null
+++ b/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h
@@ -0,0 +1,37 @@
+#ifndef H_ZEPHYR_SMP_
+#define H_ZEPHYR_SMP_
+
+struct zephyr_smp_transport;
+
+/* XXX: Note: `zephyr_nmgr_pkt` is only used here during development.  Most
+ * likely, a net_buf will be used instead.
+ */
+struct zephyr_nmgr_pkt;
+
+/**
+ * Transmit function.  The supplied mbuf is always consumed, regardless of
+ * return code.
+ */
+typedef int zephyr_smp_transport_out_fn(struct zephyr_smp_transport *zst,
+                                        struct zephyr_nmgr_pkt *pkt);
+typedef uint16_t zephyr_smp_transport_get_mtu_fn(void);
+
+struct zephyr_smp_transport {
+    /* Must be the first member. */
+    struct k_work zst_work;
+
+    /* FIFO containing incoming requests to be processed. */
+    struct k_fifo zst_fifo;
+
+    zephyr_smp_transport_out_fn *zst_output;
+    zephyr_smp_transport_get_mtu_fn *zst_get_mtu;
+};
+
+void zephyr_smp_transport_init(struct zephyr_smp_transport *zst,
+                               zephyr_smp_transport_out_fn *output_func,
+                               zephyr_smp_transport_get_mtu_fn *get_mtu_func);
+
+int zephyr_smp_rx_req(struct zephyr_smp_transport *zst,
+                      struct zephyr_nmgr_pkt *pkt);
+
+#endif
diff --git a/smp/port/zephyr/src/zephyr_smp.c b/smp/port/zephyr/src/zephyr_smp.c
new file mode 100644
index 0000000..2262397
--- /dev/null
+++ b/smp/port/zephyr/src/zephyr_smp.c
@@ -0,0 +1,234 @@
+#include <zephyr.h>
+#include "mgmt/mgmt.h"
+#include "smp/smp.h"
+#include "znp/znp.h"
+#include "zephyr_smp/zephyr_smp.h"
+
+static mgmt_alloc_rsp_fn zephyr_smp_alloc_rsp;
+static mgmt_trim_front_fn zephyr_smp_trim_front;
+static mgmt_reset_buf_fn zephyr_smp_reset_buf;
+static mgmt_write_at_fn zephyr_smp_write_at;
+static mgmt_init_reader_fn zephyr_smp_init_reader;
+static mgmt_init_writer_fn zephyr_smp_init_writer;
+static mgmt_free_buf_fn zephyr_smp_free_buf;
+static smp_tx_rsp_fn zephyr_smp_tx_rsp;
+
+static const struct mgmt_streamer_cfg zephyr_smp_cbor_cfg = {
+    .alloc_rsp = zephyr_smp_alloc_rsp,
+    .trim_front = zephyr_smp_trim_front,
+    .reset_buf = zephyr_smp_reset_buf,
+    .write_at = zephyr_smp_write_at,
+    .init_reader = zephyr_smp_init_reader,
+    .init_writer = zephyr_smp_init_writer,
+    .free_buf = zephyr_smp_free_buf,
+};
+
+#if 0
+/**
+ * Allocates an mbuf to contain an outgoing response fragment.
+ */
+static struct os_mbuf *
+zephyr_smp_rsp_frag_alloc(uint16_t frag_size, void *arg)
+{
+    struct os_mbuf *src_rsp;
+    struct os_mbuf *frag;
+
+    /* We need to duplicate the user header from the source response, as that
+     * is where transport-specific information is stored.
+     */
+    src_rsp = arg;
+
+    frag = os_msys_get_pkthdr(frag_size, OS_MBUF_USRHDR_LEN(src_rsp));
+    if (frag != NULL) {
+        /* Copy the user header from the response into the fragment mbuf. */
+        memcpy(OS_MBUF_USRHDR(frag), OS_MBUF_USRHDR(src_rsp),
+               OS_MBUF_USRHDR_LEN(src_rsp));
+    }
+
+    return frag;
+}
+#endif
+
+static void *
+zephyr_smp_alloc_rsp(const void *req, void *arg)
+{
+    const struct zephyr_nmgr_pkt *req_pkt;
+    struct zephyr_nmgr_pkt *rsp_pkt;
+
+    req_pkt = req;
+
+    rsp_pkt = k_malloc(sizeof *rsp_pkt);
+    if (rsp_pkt == NULL) {
+        assert(0);
+        return NULL;
+    }
+    rsp_pkt->len = 0;
+    rsp_pkt->extra = req_pkt->extra;
+
+    return rsp_pkt;
+}
+
+static int
+zephyr_smp_trim_front(void *buf, int len, void *arg)
+{
+    struct zephyr_nmgr_pkt *pkt;
+
+    if (len > 0) {
+        pkt = buf;
+        if (len >= pkt->len) {
+            pkt->len = 0;
+        } else {
+            memmove(pkt->data, pkt->data + len, pkt->len - len);
+            pkt->len -= len;
+        }
+    }
+
+    return 0;
+}
+
+static void
+zephyr_smp_reset_buf(void *buf, void *arg)
+{
+    struct zephyr_nmgr_pkt *pkt;
+
+    pkt = buf;
+    pkt->len = 0;
+}
+
+static int
+zephyr_smp_write_at(struct cbor_encoder_writer *writer, int offset,
+                     const void *data, int len, void *arg)
+{
+    struct cbor_znp_writer *czw;
+    struct zephyr_nmgr_pkt *pkt;
+
+    czw = (struct cbor_znp_writer *)writer;
+    pkt = czw->pkt;
+
+    if (offset < 0 || offset > pkt->len) {
+        return MGMT_ERR_EINVAL;
+    }
+
+    if (offset + len > sizeof pkt->data) {
+        return MGMT_ERR_EINVAL;
+    }
+
+    memcpy(pkt->data + offset, data, len);
+    if (pkt->len < offset + len) {
+        pkt->len = offset + len;
+        writer->bytes_written = pkt->len;
+    }
+
+    return 0;
+}
+
+static int
+zephyr_smp_tx_rsp(struct smp_streamer *ns, void *rsp, void *arg)
+{
+    struct zephyr_smp_transport *zst;
+    struct zephyr_nmgr_pkt *pkt;
+    int rc;
+
+    zst = arg;
+    pkt = rsp;
+
+    rc = zst->zst_output(zst, pkt);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    return MGMT_ERR_EOK;
+}
+
+static void
+zephyr_smp_free_buf(void *buf, void *arg)
+{
+    k_free(buf);
+}
+
+static int
+zephyr_smp_init_reader(struct cbor_decoder_reader *reader, void *buf,
+                        void *arg)
+{
+    struct cbor_znp_reader *czr;
+
+    czr = (struct cbor_znp_reader *)reader;
+    cbor_znp_reader_init(czr, buf, 0);
+
+    return 0;
+}
+
+static int
+zephyr_smp_init_writer(struct cbor_encoder_writer *writer, void *buf,
+                        void *arg)
+{
+    struct cbor_znp_writer *czw;
+
+    czw = (struct cbor_znp_writer *)writer;
+    cbor_znp_writer_init(czw, buf);
+
+    return 0;
+}
+
+static int
+zephyr_smp_process_packet(struct zephyr_smp_transport *zst,
+                          struct zephyr_nmgr_pkt *pkt)
+{
+    struct cbor_znp_reader reader;
+    struct cbor_znp_writer writer;
+    struct smp_streamer streamer;
+    int rc;
+
+    streamer = (struct smp_streamer) {
+        .ss_base = {
+            .cfg = &zephyr_smp_cbor_cfg,
+            .reader = &reader.r,
+            .writer = &writer.enc,
+            .cb_arg = zst,
+        },
+        .ss_tx_rsp = zephyr_smp_tx_rsp,
+    };
+
+    rc = smp_process_single_packet(&streamer, pkt);
+    return rc;
+}
+
+static void
+zephyr_smp_handle_reqs(struct k_work *work)
+{
+    struct zephyr_smp_transport *zst;
+    struct zephyr_nmgr_pkt *pkt;
+
+    zst = (void *)work;
+
+    while ((pkt = k_fifo_get(&zst->zst_fifo, K_NO_WAIT)) != NULL) {
+        zephyr_smp_process_packet(zst, pkt);
+    }
+}
+
+void
+zephyr_smp_transport_init(struct zephyr_smp_transport *zst,
+                          zephyr_smp_transport_out_fn *output_func,
+                          zephyr_smp_transport_get_mtu_fn *get_mtu_func)
+{
+    *zst = (struct zephyr_smp_transport) {
+        .zst_output = output_func,
+        .zst_get_mtu = get_mtu_func,
+    };
+
+    k_work_init(&zst->zst_work, zephyr_smp_handle_reqs);
+    k_fifo_init(&zst->zst_fifo);
+}
+
+/* XXX: Note: `zephyr_nmgr_pkt` is only used here during development.  Most
+ * likely, a net_buf will be used instead.
+ */
+int
+zephyr_smp_rx_req(struct zephyr_smp_transport *zst,
+                  struct zephyr_nmgr_pkt *pkt)
+{
+    k_fifo_put(&zst->zst_fifo, pkt);
+    k_work_submit(&zst->zst_work);
+
+    return 0;
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.

[mynewt-mcumgr] 03/08: img (zephyr) - initialize flash dev at init time.

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit aeb2e28cac70da834e2f72df838051c401a513af
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Jan 3 12:11:40 2018 -0800

    img (zephyr) - initialize flash dev at init time.
---
 img/port/zephyr/src/zephyr_img.c | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/img/port/zephyr/src/zephyr_img.c b/img/port/zephyr/src/zephyr_img.c
index 4d298eb..2bee3e1 100644
--- a/img/port/zephyr/src/zephyr_img.c
+++ b/img/port/zephyr/src/zephyr_img.c
@@ -2,6 +2,7 @@
 #include <flash.h>
 #include <zephyr.h>
 #include <soc.h>
+#include <init.h>
 #include <dfu/mcuboot.h>
 #include <dfu/flash_img.h>
 #include "mgmt/mgmt.h"
@@ -11,14 +12,6 @@
 static struct device *zephyr_img_flash_dev;
 static struct flash_img_context zephyr_img_flash_ctxt;
 
-static void
-img_impl_init_flash(void)
-{
-    if (zephyr_img_flash_dev == NULL) {
-        zephyr_img_flash_dev = device_get_binding(FLASH_DRIVER_NAME);
-    }
-}
-
 static int
 img_impl_flash_check_empty(off_t offset, size_t size, bool *out_empty)
 {
@@ -85,8 +78,6 @@ img_impl_erase_slot(void)
     bool empty;
     int rc;
 
-    img_impl_init_flash();
-
     rc = img_impl_flash_check_empty(FLASH_AREA_IMAGE_1_OFFSET,
                                     FLASH_AREA_IMAGE_1_SIZE,
                                     &empty);
@@ -109,7 +100,6 @@ img_impl_write_pending(int slot, bool permanent)
 {
     int rc;
 
-    img_impl_init_flash();
     if (slot != 1) {
         return MGMT_ERR_EINVAL;
     }
@@ -127,8 +117,6 @@ img_impl_write_confirmed(void)
 {
     int rc;
 
-    img_impl_init_flash();
-
     rc = boot_write_img_confirmed();
     if (rc != 0) {
         return MGMT_ERR_EUNKNOWN;
@@ -144,8 +132,6 @@ img_impl_read(int slot, unsigned int offset, void *dst,
     off_t abs_offset;
     int rc;
 
-    img_impl_init_flash();
-
     abs_offset = img_impl_abs_offset(slot, offset);
     rc = flash_read(zephyr_img_flash_dev, abs_offset, dst, num_bytes);
     if (rc != 0) {
@@ -161,8 +147,6 @@ img_impl_write_image_data(unsigned int offset, const void *data,
 {
     int rc;
 
-    img_impl_init_flash();
-
     if (offset == 0) {
         flash_img_init(&zephyr_img_flash_ctxt, zephyr_img_flash_dev);
     }
@@ -187,8 +171,6 @@ img_impl_write_image_data(unsigned int offset, const void *data,
 int
 img_impl_swap_type(void)
 {
-    img_impl_init_flash();
-
     switch (boot_swap_type()) {
     case BOOT_SWAP_TYPE_NONE:
         return IMG_SWAP_TYPE_NONE;
@@ -203,3 +185,17 @@ img_impl_swap_type(void)
         return IMG_SWAP_TYPE_NONE;
     }
 }
+
+static int
+img_impl_init(struct device *dev)
+{
+    ARG_UNUSED(dev);
+
+    zephyr_img_flash_dev = device_get_binding(FLASH_DRIVER_NAME);
+    if (!zephyr_img_flash_dev) {
+        return -ENODEV;
+    }
+    return 0;
+}
+
+SYS_INIT(img_impl_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.