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/05 20:43:37 UTC

[mynewt-mcumgr] branch master updated (f3bebef -> 79f78f0)

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 f3bebef  Mynewt - minor renames.
     new d03e76c  zephyr - fragmentation of overly long responses.
     new cd82935  Make znp extra buffer larger (4B --> 8B).
     new 9f52c32  Move `img` command handlers to `cmd` TLD.
     new a7c3565  Change `img` prefix to `img_mgmt`
     new 79f78f0  OS command group

The 5 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 => cmd/img_mgmt/include/img_mgmt}/image.h  |   3 +
 cmd/img_mgmt/include/img_mgmt/img_mgmt.h           |  69 +++++
 .../img_mgmt/include/img_mgmt/img_mgmt_impl.h      |  22 +-
 {img => cmd/img_mgmt}/pkg.yml                      |   2 +-
 {img => cmd/img_mgmt}/port/mynewt/pkg.yml          |   4 +-
 .../img_mgmt/port/mynewt/src/mynewt_img_mgmt.c     |  30 +-
 .../img_mgmt/port/zephyr/src/zephyr_img_mgmt.c     |  46 +--
 img/src/img.c => cmd/img_mgmt/src/img_mgmt.c       | 142 ++++-----
 .../img_priv.h => cmd/img_mgmt/src/img_mgmt_priv.h |  32 +--
 .../img_mgmt/src/img_mgmt_state.c                  | 102 +++----
 .../img_util.c => cmd/img_mgmt/src/img_mgmt_util.c |  59 +---
 {img => cmd/img_mgmt}/syscfg.yml                   |   0
 cmd/os_mgmt/Makefile                               |  17 ++
 .../os_mgmt/include/os_mgmt/os_mgmt.h              |  24 +-
 cmd/os_mgmt/include/os_mgmt/os_mgmt_impl.h         |   6 +
 cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c       |  37 +++
 cmd/os_mgmt/port/zephyr/src/zephyr_os_mgmt.c       |  23 ++
 cmd/os_mgmt/src/os_mgmt.c                          | 320 +++++++++++++++++++++
 img/include/img/img.h                              |  77 -----
 smp/port/zephyr/include/zephyr_smp/zephyr_smp.h    |  13 +-
 smp/port/zephyr/src/zephyr_smp.c                   |  74 +++--
 21 files changed, 731 insertions(+), 371 deletions(-)
 rename {img/include/img => cmd/img_mgmt/include/img_mgmt}/image.h (96%)
 create mode 100644 cmd/img_mgmt/include/img_mgmt/img_mgmt.h
 rename img/include/img/img_impl.h => cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h (81%)
 rename {img => cmd/img_mgmt}/pkg.yml (98%)
 rename {img => cmd/img_mgmt}/port/mynewt/pkg.yml (94%)
 rename img/port/mynewt/src/mynewt_img.c => cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c (84%)
 rename img/port/zephyr/src/zephyr_img.c => cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c (72%)
 rename img/src/img.c => cmd/img_mgmt/src/img_mgmt.c (64%)
 rename img/src/img_priv.h => cmd/img_mgmt/src/img_mgmt_priv.h (72%)
 rename img/src/img_state.c => cmd/img_mgmt/src/img_mgmt_state.c (68%)
 rename img/src/img_util.c => cmd/img_mgmt/src/img_mgmt_util.c (50%)
 rename {img => cmd/img_mgmt}/syscfg.yml (100%)
 create mode 100644 cmd/os_mgmt/Makefile
 copy mgmt/port/mynewt/include/mynewt_mgmt/mynewt_mgmt.h => cmd/os_mgmt/include/os_mgmt/os_mgmt.h (69%)
 create mode 100644 cmd/os_mgmt/include/os_mgmt/os_mgmt_impl.h
 create mode 100644 cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c
 create mode 100644 cmd/os_mgmt/port/zephyr/src/zephyr_os_mgmt.c
 create mode 100644 cmd/os_mgmt/src/os_mgmt.c
 delete mode 100644 img/include/img/img.h

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

[mynewt-mcumgr] 04/05: Change `img` prefix to `img_mgmt`

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 a7c35650621dc51635acd159ed057c270af24243
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Jan 4 17:32:03 2018 -0800

    Change `img` prefix to `img_mgmt`
---
 cmd/img/include/img/img.h                          |  77 -----------
 .../img => img_mgmt/include/img_mgmt}/image.h      |   3 +
 cmd/img_mgmt/include/img_mgmt/img_mgmt.h           |  69 ++++++++++
 .../include/img_mgmt/img_mgmt_impl.h}              |  22 ++--
 cmd/{img => img_mgmt}/pkg.yml                      |   0
 cmd/{img => img_mgmt}/port/mynewt/pkg.yml          |   2 +-
 .../port/mynewt/src/mynewt_img_mgmt.c}             |  30 ++---
 .../port/zephyr/src/zephyr_img_mgmt.c}             |  46 +++----
 cmd/{img/src/img.c => img_mgmt/src/img_mgmt.c}     | 142 ++++++++++-----------
 .../img_priv.h => img_mgmt/src/img_mgmt_priv.h}    |  32 +----
 .../img_state.c => img_mgmt/src/img_mgmt_state.c}  | 102 +++++++--------
 .../img_util.c => img_mgmt/src/img_mgmt_util.c}    |  59 +--------
 cmd/{img => img_mgmt}/syscfg.yml                   |   0
 13 files changed, 254 insertions(+), 330 deletions(-)

diff --git a/cmd/img/include/img/img.h b/cmd/img/include/img/img.h
deleted file mode 100644
index fa5a3cb..0000000
--- a/cmd/img/include/img/img.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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_IMG_
-#define H_IMG_
-
-#include <inttypes.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define IMG_NMGR_ID_STATE       0
-#define IMG_NMGR_ID_UPLOAD      1
-#define IMG_NMGR_ID_FILE        2
-#define IMG_NMGR_ID_CORELIST    3
-#define IMG_NMGR_ID_CORELOAD    4
-#define IMG_NMGR_ID_ERASE	    5
-
-#define IMG_NMGR_MAX_NAME	    64
-#define IMG_NMGR_MAX_VER        25  /* 255.255.65535.4294967295\0 */
-
-#define IMG_HASH_LEN            32
-
-#define IMG_STATE_F_PENDING     0x01
-#define IMG_STATE_F_CONFIRMED   0x02
-#define IMG_STATE_F_ACTIVE      0x04
-#define IMG_STATE_F_PERMANENT   0x08
-
-#define IMG_SWAP_TYPE_NONE      0
-#define IMG_SWAP_TYPE_TEST      1
-#define IMG_SWAP_TYPE_PERM      2
-#define IMG_SWAP_TYPE_REVERT    3
-
-struct image_version;
-
-/*
- * Take version and convert it to string in dst.
- */
-int img_ver_str(const struct image_version *ver, char *dst);
-
-/*
- * Given flash_map slot id, read in image_version and/or image hash.
- */
-int img_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
-                  uint32_t *flags);
-
-/*
- * Returns version number of current image (if available).
- */
-int img_my_version(struct image_version *ver);
-
-uint8_t img_state_flags(int query_slot);
-int img_state_slot_in_use(int slot);
-int img_group_register(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_IMG_ */
diff --git a/cmd/img/include/img/image.h b/cmd/img_mgmt/include/img_mgmt/image.h
similarity index 96%
rename from cmd/img/include/img/image.h
rename to cmd/img_mgmt/include/img_mgmt/image.h
index 53c6215..63bb7fe 100644
--- a/cmd/img/include/img/image.h
+++ b/cmd/img_mgmt/include/img_mgmt/image.h
@@ -41,6 +41,9 @@ extern "C" {
  */
 #define IMAGE_TLV_SHA256            0x10   /* SHA256 of image hdr and body */
 
+/** Image TLV-specific definitions. */
+#define IMAGE_HASH_LEN              32
+
 struct image_version {
     uint8_t iv_major;
     uint8_t iv_minor;
diff --git a/cmd/img_mgmt/include/img_mgmt/img_mgmt.h b/cmd/img_mgmt/include/img_mgmt/img_mgmt.h
new file mode 100644
index 0000000..1a7da19
--- /dev/null
+++ b/cmd/img_mgmt/include/img_mgmt/img_mgmt.h
@@ -0,0 +1,69 @@
+/*
+ * 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_IMG_MGMT_
+#define H_IMG_MGMT_
+
+#include <inttypes.h>
+struct image_version;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define IMG_MGMT_ID_STATE           0
+#define IMG_MGMT_ID_UPLOAD          1
+#define IMG_MGMT_ID_FILE            2
+#define IMG_MGMT_ID_CORELIST        3
+#define IMG_MGMT_ID_CORELOAD        4
+#define IMG_MGMT_ID_ERASE           5
+
+#define IMG_MGMT_MAX_NAME           64
+#define IMG_MGMT_MAX_VER            25  /* 255.255.65535.4294967295\0 */
+
+#define IMG_MGMT_STATE_F_PENDING    0x01
+#define IMG_MGMT_STATE_F_CONFIRMED  0x02
+#define IMG_MGMT_STATE_F_ACTIVE     0x04
+#define IMG_MGMT_STATE_F_PERMANENT  0x08
+
+#define IMG_MGMT_SWAP_TYPE_NONE     0
+#define IMG_MGMT_SWAP_TYPE_TEST     1
+#define IMG_MGMT_SWAP_TYPE_PERM     2
+#define IMG_MGMT_SWAP_TYPE_REVERT   3
+
+/**
+ * Take version and convert it to string in dst.
+ */
+int img_mgmt_ver_str(const struct image_version *ver, char *dst);
+
+/**
+ * Given flash_map slot id, read in image_version and/or image hash.
+ */
+int img_mgmt_read_info(int image_slot, struct image_version *ver,
+                       uint8_t *hash, uint32_t *flags);
+
+uint8_t img_mgmt_state_flags(int query_slot);
+int img_mgmt_slot_in_use(int slot);
+int img_mgmt_group_register(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_IMG_MGMT_ */
diff --git a/cmd/img/include/img/img_impl.h b/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
similarity index 81%
rename from cmd/img/include/img/img_impl.h
rename to cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
index ce19838..b6b81b0 100644
--- a/cmd/img/include/img/img_impl.h
+++ b/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
@@ -1,5 +1,5 @@
-#ifndef H_IMG_IMPL_
-#define H_IMG_IMPL_
+#ifndef H_IMG_MGMT_IMPL_
+#define H_IMG_MGMT_IMPL_
 
 /* This file declares implementation-specific functions required by image
  * management.  Each function must be defined in a way that is compatible with
@@ -11,7 +11,7 @@
  *
  * @return                      0 on success, MGMT_ERR_[...] code on failure.
  */
-int img_impl_erase_slot(void);
+int img_mgmt_impl_erase_slot(void);
 
 /**
  * @brief Marks the image in the specified slot as pending. On the next reboot,
@@ -27,7 +27,7 @@ int img_impl_erase_slot(void);
  *
  * @return                      0 on success, MGMT_ERR_[...] code on failure.
  */
-int img_impl_write_pending(int slot, bool permanent);
+int img_mgmt_impl_write_pending(int slot, bool permanent);
 
 /**
  * @brief Marks the image in slot 0 as confirmed. The system will continue
@@ -35,7 +35,7 @@ int img_impl_write_pending(int slot, bool permanent);
  *
  * @return                      0 on success, MGMT_ERR_[...] code on failure.
  */
-int img_impl_write_confirmed(void);
+int img_mgmt_impl_write_confirmed(void);
 
 /**
  * @brief Reads the specified chunk of data from an image slot.
@@ -47,8 +47,8 @@ int img_impl_write_confirmed(void);
  *
  * @return                      0 on success, MGMT_ERR_[...] code on failure.
  */
-int img_impl_read(int slot, unsigned int offset, void *dst,
-                  unsigned int num_bytes);
+int img_mgmt_impl_read(int slot, unsigned int offset, void *dst,
+                       unsigned int num_bytes);
 
 /**
  * @brief Writes the specified chunk of image data to slot 1.
@@ -64,15 +64,15 @@ int img_impl_read(int slot, unsigned int offset, void *dst,
  *
  * @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);
+int img_mgmt_impl_write_image_data(unsigned int offset, const void *data,
+                                   unsigned int num_bytes, bool last);
 
 /**
  * @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_MGMT_SWAP_TYPE_[...] code.
  */
-int img_impl_swap_type(void);
+int img_mgmt_impl_swap_type(void);
 
 #endif
diff --git a/cmd/img/pkg.yml b/cmd/img_mgmt/pkg.yml
similarity index 100%
rename from cmd/img/pkg.yml
rename to cmd/img_mgmt/pkg.yml
diff --git a/cmd/img/port/mynewt/pkg.yml b/cmd/img_mgmt/port/mynewt/pkg.yml
similarity index 96%
rename from cmd/img/port/mynewt/pkg.yml
rename to cmd/img_mgmt/port/mynewt/pkg.yml
index 0e5ec11..f2a358e 100644
--- a/cmd/img/port/mynewt/pkg.yml
+++ b/cmd/img_mgmt/port/mynewt/pkg.yml
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-pkg.name: cmd/img/port/mynewt
+pkg.name: cmd/img_mgmt/port/mynewt
 pkg.description: XXX
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
diff --git a/cmd/img/port/mynewt/src/mynewt_img.c b/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c
similarity index 84%
rename from cmd/img/port/mynewt/src/mynewt_img.c
rename to cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c
index 28d39f3..1ae7950 100644
--- a/cmd/img/port/mynewt/src/mynewt_img.c
+++ b/cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c
@@ -1,7 +1,7 @@
 #include "sysinit/sysinit.h"
 
 int
-img_impl_erase_slot(void)
+img_mgmt_impl_erase_slot(void)
 {
     const struct flash_area *fa;
     bool empty;
@@ -28,7 +28,7 @@ img_impl_erase_slot(void)
 }
 
 int
-img_impl_write_pending(int slot, bool permanent)
+img_mgmt_impl_write_pending(int slot, bool permanent)
 {
     uint32_t image_flags;
     uint8_t state_flags;
@@ -87,7 +87,7 @@ img_impl_write_pending(int slot, bool permanent)
 }
 
 int
-img_impl_write_confirmed(void)
+img_mgmt_impl_write_confirmed(void)
 {
     /* Confirm the unified image or loader in slot 0. */
     rc = boot_set_confirmed();
@@ -112,8 +112,8 @@ img_impl_write_confirmed(void)
 }
 
 int
-img_impl_read(int slot, unsigned int offset, void *dst,
-              unsigned int num_bytes)
+img_mgmt_impl_read(int slot, unsigned int offset, void *dst,
+                   unsigned int num_bytes)
 {
     const struct flash_area *fa;
     int area_id;
@@ -135,8 +135,8 @@ img_impl_read(int slot, unsigned int offset, void *dst,
 }
 
 int
-img_impl_write_image_data(unsigned int offset, const void *data,
-                          unsigned int num_bytes, bool last)
+img_mgmt_impl_write_image_data(unsigned int offset, const void *data,
+                               unsigned int num_bytes, bool last)
 {
     const struct flash_area *fa;
     int rc;
@@ -156,32 +156,32 @@ img_impl_write_image_data(unsigned int offset, const void *data,
 }
 
 int
-img_impl_swap_type(void)
+img_mgmt_impl_swap_type(void)
 {
     switch (boot_swap_type()) {
     case BOOT_SWAP_TYPE_NONE:
-        return IMG_SWAP_TYPE_NONE;
+        return IMG_MGMT_SWAP_TYPE_NONE;
     case BOOT_SWAP_TYPE_TEST:
-        return IMG_SWAP_TYPE_TEST;
+        return IMG_MGMT_SWAP_TYPE_TEST;
     case BOOT_SWAP_TYPE_PERM:
-        return IMG_SWAP_TYPE_PERM;
+        return IMG_MGMT_SWAP_TYPE_PERM;
     case BOOT_SWAP_TYPE_REVERT:
-        return IMG_SWAP_TYPE_REVERT;
+        return IMG_MGMT_SWAP_TYPE_REVERT;
     default:
         assert(0);
-        return IMG_SWAP_TYPE_NONE;
+        return IMG_MGMT_SWAP_TYPE_NONE;
     }
 }
 
 void
-img_module_init(void)
+img_mgmt_module_init(void)
 {
     int rc;
 
     /* Ensure this function only gets called by sysinit. */
     SYSINIT_ASSERT_ACTIVE();
 
-    rc = img_group_register();
+    rc = img_mgmt_group_register();
     SYSINIT_PANIC_ASSERT(rc == 0);
 
 #if MYNEWT_VAL(IMGMGR_CLI)
diff --git a/cmd/img/port/zephyr/src/zephyr_img.c b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
similarity index 72%
rename from cmd/img/port/zephyr/src/zephyr_img.c
rename to cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index 2bee3e1..0a3ed5a 100644
--- a/cmd/img/port/zephyr/src/zephyr_img.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -6,14 +6,14 @@
 #include <dfu/mcuboot.h>
 #include <dfu/flash_img.h>
 #include "mgmt/mgmt.h"
-#include "img/img_impl.h"
-#include "img/img.h"
+#include "img_mgmt/img_mgmt_impl.h"
+#include "img_mgmt/img_mgmt.h"
 
 static struct device *zephyr_img_flash_dev;
 static struct flash_img_context zephyr_img_flash_ctxt;
 
 static int
-img_impl_flash_check_empty(off_t offset, size_t size, bool *out_empty)
+img_mgmt_impl_flash_check_empty(off_t offset, size_t size, bool *out_empty)
 {
     uint32_t data[16];
     off_t addr;
@@ -50,7 +50,7 @@ img_impl_flash_check_empty(off_t offset, size_t size, bool *out_empty)
 }
 
 static off_t
-img_impl_abs_offset(int slot, off_t sub_offset)
+img_mgmt_impl_abs_offset(int slot, off_t sub_offset)
 {
     off_t slot_start;
 
@@ -73,14 +73,14 @@ img_impl_abs_offset(int slot, off_t sub_offset)
 }
 
 int
-img_impl_erase_slot(void)
+img_mgmt_impl_erase_slot(void)
 {
     bool empty;
     int rc;
 
-    rc = img_impl_flash_check_empty(FLASH_AREA_IMAGE_1_OFFSET,
-                                    FLASH_AREA_IMAGE_1_SIZE,
-                                    &empty);
+    rc = img_mgmt_impl_flash_check_empty(FLASH_AREA_IMAGE_1_OFFSET,
+                                         FLASH_AREA_IMAGE_1_SIZE,
+                                         &empty);
     if (rc != 0) {
         return MGMT_ERR_EUNKNOWN;
     }
@@ -96,7 +96,7 @@ img_impl_erase_slot(void)
 }
 
 int
-img_impl_write_pending(int slot, bool permanent)
+img_mgmt_impl_write_pending(int slot, bool permanent)
 {
     int rc;
 
@@ -113,7 +113,7 @@ img_impl_write_pending(int slot, bool permanent)
 }
 
 int
-img_impl_write_confirmed(void)
+img_mgmt_impl_write_confirmed(void)
 {
     int rc;
 
@@ -126,13 +126,13 @@ img_impl_write_confirmed(void)
 }
 
 int
-img_impl_read(int slot, unsigned int offset, void *dst,
-              unsigned int num_bytes)
+img_mgmt_impl_read(int slot, unsigned int offset, void *dst,
+                   unsigned int num_bytes)
 {
     off_t abs_offset;
     int rc;
 
-    abs_offset = img_impl_abs_offset(slot, offset);
+    abs_offset = img_mgmt_impl_abs_offset(slot, offset);
     rc = flash_read(zephyr_img_flash_dev, abs_offset, dst, num_bytes);
     if (rc != 0) {
         return MGMT_ERR_EUNKNOWN;
@@ -142,8 +142,8 @@ img_impl_read(int slot, unsigned int offset, void *dst,
 }
 
 int
-img_impl_write_image_data(unsigned int offset, const void *data,
-                          unsigned int num_bytes, bool last)
+img_mgmt_impl_write_image_data(unsigned int offset, const void *data,
+                               unsigned int num_bytes, bool last)
 {
     int rc;
 
@@ -169,25 +169,25 @@ img_impl_write_image_data(unsigned int offset, const void *data,
 }
 
 int
-img_impl_swap_type(void)
+img_mgmt_impl_swap_type(void)
 {
     switch (boot_swap_type()) {
     case BOOT_SWAP_TYPE_NONE:
-        return IMG_SWAP_TYPE_NONE;
+        return IMG_MGMT_SWAP_TYPE_NONE;
     case BOOT_SWAP_TYPE_TEST:
-        return IMG_SWAP_TYPE_TEST;
+        return IMG_MGMT_SWAP_TYPE_TEST;
     case BOOT_SWAP_TYPE_PERM:
-        return IMG_SWAP_TYPE_PERM;
+        return IMG_MGMT_SWAP_TYPE_PERM;
     case BOOT_SWAP_TYPE_REVERT:
-        return IMG_SWAP_TYPE_REVERT;
+        return IMG_MGMT_SWAP_TYPE_REVERT;
     default:
         assert(0);
-        return IMG_SWAP_TYPE_NONE;
+        return IMG_MGMT_SWAP_TYPE_NONE;
     }
 }
 
 static int
-img_impl_init(struct device *dev)
+img_mgmt_impl_init(struct device *dev)
 {
     ARG_UNUSED(dev);
 
@@ -198,4 +198,4 @@ img_impl_init(struct device *dev)
     return 0;
 }
 
-SYS_INIT(img_impl_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
+SYS_INIT(img_mgmt_impl_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
diff --git a/cmd/img/src/img.c b/cmd/img_mgmt/src/img_mgmt.c
similarity index 64%
rename from cmd/img/src/img.c
rename to cmd/img_mgmt/src/img_mgmt.c
index 9a2019c..970030e 100644
--- a/cmd/img/src/img.c
+++ b/cmd/img_mgmt/src/img_mgmt.c
@@ -24,43 +24,43 @@
 #include "cborattr/cborattr.h"
 #include "mgmt/mgmt.h"
 
-#include "img/img.h"
-#include "img/image.h"
-#include "img/img_impl.h"
-#include "img_priv.h"
+#include "img_mgmt/image.h"
+#include "img_mgmt/img_mgmt.h"
+#include "img_mgmt/img_mgmt_impl.h"
+#include "img_mgmt_priv.h"
 
-#define IMG_MAX_CHUNK_SIZE 512
+#define IMG_MGMT_MAX_CHUNK_SIZE 512
 
-static int img_upload(struct mgmt_cbuf *);
-static int img_erase(struct mgmt_cbuf *);
+static mgmt_handler_fn img_mgmt_upload;
+static mgmt_handler_fn img_mgmt_erase;
 
-static const struct mgmt_handler img_nmgr_handlers[] = {
-    [IMG_NMGR_ID_STATE] = {
-        .mh_read = img_state_read,
-        .mh_write = img_state_write,
+static const struct mgmt_handler img_mgmt_handlers[] = {
+    [IMG_MGMT_ID_STATE] = {
+        .mh_read = img_mgmt_state_read,
+        .mh_write = img_mgmt_state_write,
     },
-    [IMG_NMGR_ID_UPLOAD] = {
+    [IMG_MGMT_ID_UPLOAD] = {
         .mh_read = NULL,
-        .mh_write = img_upload
+        .mh_write = img_mgmt_upload
     },
-    [IMG_NMGR_ID_ERASE] = {
+    [IMG_MGMT_ID_ERASE] = {
         .mh_read = NULL,
-        .mh_write = img_erase
+        .mh_write = img_mgmt_erase
     },
 #if 0
-    [IMG_NMGR_ID_CORELIST] = {
-#if MYNEWT_VAL(IMG_COREDUMP)
-        .mh_read = img_core_list,
+    [IMG_MGMT_ID_CORELIST] = {
+#if MYNEWT_VAL(IMG_MGMT_COREDUMP)
+        .mh_read = img_mgmt_core_list,
         .mh_write = NULL
 #else
         .mh_read = NULL,
         .mh_write = NULL
 #endif
     },
-    [IMG_NMGR_ID_CORELOAD] = {
-#if MYNEWT_VAL(IMG_COREDUMP)
-        .mh_read = img_core_load,
-        .mh_write = img_core_erase,
+    [IMG_MGMT_ID_CORELOAD] = {
+#if MYNEWT_VAL(IMG_MGMT_COREDUMP)
+        .mh_read = img_mgmt_core_load,
+        .mh_write = img_mgmt_core_erase,
 #else
         .mh_read = NULL,
         .mh_write = NULL
@@ -69,12 +69,12 @@ static const struct mgmt_handler img_nmgr_handlers[] = {
 #endif
 };
 
-#define IMG_HANDLER_CNT                                                \
-    sizeof(img_nmgr_handlers) / sizeof(img_nmgr_handlers[0])
+#define IMG_MGMT_HANDLER_CNT                                    \
+    sizeof(img_mgmt_handlers) / sizeof(img_mgmt_handlers[0])
 
-static struct mgmt_group img_nmgr_group = {
-    .mg_handlers = (struct mgmt_handler *)img_nmgr_handlers,
-    .mg_handlers_count = IMG_HANDLER_CNT,
+static struct mgmt_group img_mgmt_group = {
+    .mg_handlers = (struct mgmt_handler *)img_mgmt_handlers,
+    .mg_handlers_count = IMG_MGMT_HANDLER_CNT,
     .mg_group_id = MGMT_GROUP_ID_IMAGE,
 };
 
@@ -82,16 +82,16 @@ static struct {
     off_t off;
     size_t image_len;
     bool uploading;
-} img_ctxt;
+} img_mgmt_ctxt;
 
 static int
-img_img_tlvs(const struct image_header *hdr,
-             int slot, off_t *start_off, off_t *end_off)
+img_mgmt_tlvs(const struct image_header *hdr,
+              int slot, off_t *start_off, off_t *end_off)
 {
     struct image_tlv_info tlv_info;
     int rc;
 
-    rc = img_impl_read(slot, *start_off, &tlv_info, sizeof tlv_info);
+    rc = img_mgmt_impl_read(slot, *start_off, &tlv_info, sizeof tlv_info);
     if (rc != 0) {
         return -1;
     }
@@ -122,8 +122,8 @@ img_img_tlvs(const struct image_header *hdr,
  * XXX Define return code macros.
  */
 int
-img_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
-              uint32_t *flags)
+img_mgmt_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
+                   uint32_t *flags)
 {
     struct image_header hdr;
     struct image_tlv tlv;
@@ -131,7 +131,7 @@ img_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
     uint32_t data_end;
     int rc;
 
-    rc = img_impl_read(image_slot, 0, &hdr, sizeof hdr);
+    rc = img_mgmt_impl_read(image_slot, 0, &hdr, sizeof hdr);
     if (rc != 0) {
         return -1;
     }
@@ -155,29 +155,29 @@ img_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
 
     /* The hash is contained in a TLV after the image. */
     data_off = hdr.ih_hdr_size + hdr.ih_img_size;
-    rc = img_img_tlvs(&hdr, image_slot, &data_off, &data_end);
+    rc = img_mgmt_tlvs(&hdr, image_slot, &data_off, &data_end);
     if (rc != 0) {
         return rc;
     }
 
     while (data_off + sizeof tlv <= data_end) {
-        rc = img_impl_read(image_slot, data_off, &tlv, sizeof tlv);
+        rc = img_mgmt_impl_read(image_slot, data_off, &tlv, sizeof tlv);
         if (rc != 0) {
             return 0;
         }
         if (tlv.it_type == 0xff && tlv.it_len == 0xffff) {
             return 1;
         }
-        if (tlv.it_type != IMAGE_TLV_SHA256 || tlv.it_len != IMG_HASH_LEN) {
+        if (tlv.it_type != IMAGE_TLV_SHA256 || tlv.it_len != IMAGE_HASH_LEN) {
             data_off += sizeof tlv + tlv.it_len;
             continue;
         }
         data_off += sizeof tlv;
         if (hash != NULL) {
-            if (data_off + IMG_HASH_LEN > data_end) {
+            if (data_off + IMAGE_HASH_LEN > data_end) {
                 return 0;
             }
-            rc = img_impl_read(image_slot, data_off, hash, IMG_HASH_LEN);
+            rc = img_mgmt_impl_read(image_slot, data_off, hash, IMAGE_HASH_LEN);
             if (rc != 0) {
                 return 0;
             }
@@ -193,13 +193,13 @@ img_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
  * or -1 if not found.
  */
 int
-img_find_by_ver(struct image_version *find, uint8_t *hash)
+img_mgmt_find_by_ver(struct image_version *find, uint8_t *hash)
 {
     int i;
     struct image_version ver;
 
     for (i = 0; i < 2; i++) {
-        if (img_read_info(i, &ver, hash, NULL) != 0) {
+        if (img_mgmt_read_info(i, &ver, hash, NULL) != 0) {
             continue;
         }
         if (!memcmp(find, &ver, sizeof(ver))) {
@@ -214,16 +214,16 @@ img_find_by_ver(struct image_version *find, uint8_t *hash)
  * or -1 if not found.
  */
 int
-img_find_by_hash(uint8_t *find, struct image_version *ver)
+img_mgmt_find_by_hash(uint8_t *find, struct image_version *ver)
 {
     int i;
-    uint8_t hash[IMG_HASH_LEN];
+    uint8_t hash[IMAGE_HASH_LEN];
 
     for (i = 0; i < 2; i++) {
-        if (img_read_info(i, ver, hash, NULL) != 0) {
+        if (img_mgmt_read_info(i, ver, hash, NULL) != 0) {
             continue;
         }
-        if (!memcmp(hash, find, IMG_HASH_LEN)) {
+        if (!memcmp(hash, find, IMAGE_HASH_LEN)) {
             return i;
         }
     }
@@ -231,12 +231,12 @@ img_find_by_hash(uint8_t *find, struct image_version *ver)
 }
 
 static int
-img_erase(struct mgmt_cbuf *cb)
+img_mgmt_erase(struct mgmt_cbuf *cb)
 {
     CborError err;
     int rc;
 
-    rc = img_impl_erase_slot();
+    rc = img_mgmt_impl_erase_slot();
 
     err = 0;
     err |= cbor_encode_text_stringz(&cb->encoder, "rc");
@@ -250,7 +250,7 @@ img_erase(struct mgmt_cbuf *cb)
 }
 
 static int
-img_write_upload_rsp(struct mgmt_cbuf *cb, int status)
+img_mgmt_write_upload_rsp(struct mgmt_cbuf *cb, int status)
 {
     CborError err;
 
@@ -258,7 +258,7 @@ img_write_upload_rsp(struct mgmt_cbuf *cb, int status)
     err |= cbor_encode_text_stringz(&cb->encoder, "rc");
     err |= cbor_encode_int(&cb->encoder, status);
     err |= cbor_encode_text_stringz(&cb->encoder, "off");
-    err |= cbor_encode_int(&cb->encoder, img_ctxt.off);
+    err |= cbor_encode_int(&cb->encoder, img_mgmt_ctxt.off);
 
     if (err != 0) {
         return MGMT_ERR_ENOMEM;
@@ -268,7 +268,7 @@ img_write_upload_rsp(struct mgmt_cbuf *cb, int status)
 
 /* XXX: Rename */
 static int
-img_upload_first(struct mgmt_cbuf *cb, const uint8_t *req_data, size_t len)
+img_mgmt_upload_first(struct mgmt_cbuf *cb, const uint8_t *req_data, size_t len)
 {
     struct image_header hdr;
     int rc;
@@ -282,29 +282,29 @@ img_upload_first(struct mgmt_cbuf *cb, const uint8_t *req_data, size_t len)
         return MGMT_ERR_EINVAL;
     }
 
-    if (img_state_slot_in_use(1)) {
+    if (img_mgmt_slot_in_use(1)) {
         /* No free slot. */
         return MGMT_ERR_ENOMEM;
     }
 
-    rc = img_impl_erase_slot();
+    rc = img_mgmt_impl_erase_slot();
     if (rc != 0) {
         return rc;
     }
 
-    img_ctxt.uploading = true;
-    img_ctxt.off = 0;
-    img_ctxt.image_len = 0;
+    img_mgmt_ctxt.uploading = true;
+    img_mgmt_ctxt.off = 0;
+    img_mgmt_ctxt.image_len = 0;
 
     return 0;
 }
 
 static int
-img_upload(struct mgmt_cbuf *cb)
+img_mgmt_upload(struct mgmt_cbuf *cb)
 {
     long long unsigned int off = UINT_MAX;
     long long unsigned int size = UINT_MAX;
-    uint8_t img_data[IMG_MAX_CHUNK_SIZE];
+    uint8_t img_mgmt_data[IMG_MGMT_MAX_CHUNK_SIZE];
     size_t data_len = 0;
     bool last;
     int rc;
@@ -313,9 +313,9 @@ img_upload(struct mgmt_cbuf *cb)
         [0] = {
             .attribute = "data",
             .type = CborAttrByteStringType,
-            .addr.bytestring.data = img_data,
+            .addr.bytestring.data = img_mgmt_data,
             .addr.bytestring.len = &data_len,
-            .len = sizeof(img_data)
+            .len = sizeof(img_mgmt_data)
         },
         [1] = {
             .attribute = "len",
@@ -338,42 +338,42 @@ img_upload(struct mgmt_cbuf *cb)
     }
 
     if (off == 0) {
-        rc = img_upload_first(cb, img_data, data_len);
+        rc = img_mgmt_upload_first(cb, img_mgmt_data, data_len);
         if (rc != 0) {
             return rc;
         }
-        img_ctxt.image_len = size;
+        img_mgmt_ctxt.image_len = size;
     } else {
-        if (!img_ctxt.uploading) {
+        if (!img_mgmt_ctxt.uploading) {
             return MGMT_ERR_EINVAL;
         }
 
-        if (off != img_ctxt.off) {
+        if (off != img_mgmt_ctxt.off) {
             /* Invalid offset. Drop the data, and respond with the offset we're
              * expecting data for.
              */
-            return img_write_upload_rsp(cb, 0);
+            return img_mgmt_write_upload_rsp(cb, 0);
         }
     }
 
     if (data_len > 0) {
-        last = img_ctxt.off + data_len == img_ctxt.image_len;
-        rc = img_impl_write_image_data(off, img_data, data_len, last);
+        last = img_mgmt_ctxt.off + data_len == img_mgmt_ctxt.image_len;
+        rc = img_mgmt_impl_write_image_data(off, img_mgmt_data, data_len, last);
         if (rc != 0) {
             return rc;
         }
 
-        img_ctxt.off += data_len;
+        img_mgmt_ctxt.off += data_len;
         if (last) {
-            img_ctxt.uploading = false;
+            img_mgmt_ctxt.uploading = false;
         }
     }
 
-    return img_write_upload_rsp(cb, 0);
+    return img_mgmt_write_upload_rsp(cb, 0);
 }
 
 int
-img_group_register(void)
+img_mgmt_group_register(void)
 {
-    return mgmt_group_register(&img_nmgr_group);
+    return mgmt_group_register(&img_mgmt_group);
 }
diff --git a/cmd/img/src/img_priv.h b/cmd/img_mgmt/src/img_mgmt_priv.h
similarity index 72%
rename from cmd/img/src/img_priv.h
rename to cmd/img_mgmt/src/img_mgmt_priv.h
index 8140856..f763b56 100644
--- a/cmd/img/src/img_priv.h
+++ b/cmd/img_mgmt/src/img_mgmt_priv.h
@@ -26,18 +26,6 @@
 extern "C" {
 #endif
 
-#define IMG_MAX_IMGS		2
-
-#define IMG_HASH_STR		48
-
-/*
- * When accompanied by image, it's this structure followed by data.
- * Response contains just the offset.
- */
-struct img_upload_cmd {
-    uint32_t iuc_off;
-};
-
 /*
  * Response to list:
  * {
@@ -82,21 +70,15 @@ struct img_upload_cmd {
  * }
  */
 
-struct nmgr_hdr;
-struct os_mbuf;
-struct fs_file;
 struct mgmt_cbuf;
 
-struct nmgr_jbuf;
-
-int img_core_list(struct mgmt_cbuf *);
-int img_core_load(struct mgmt_cbuf *);
-int img_core_erase(struct mgmt_cbuf *);
-int img_state_read(struct mgmt_cbuf *cb);
-int img_state_write(struct mgmt_cbuf *njb);
-int img_find_by_ver(struct image_version *find, uint8_t *hash);
-int img_find_by_hash(uint8_t *find, struct image_version *ver);
-int img_cli_register(void);
+int img_mgmt_core_list(struct mgmt_cbuf *);
+int img_mgmt_core_load(struct mgmt_cbuf *);
+int img_mgmt_core_erase(struct mgmt_cbuf *);
+int img_mgmt_state_read(struct mgmt_cbuf *cb);
+int img_mgmt_state_write(struct mgmt_cbuf *njb);
+int img_mgmt_find_by_ver(struct image_version *find, uint8_t *hash);
+int img_mgmt_find_by_hash(uint8_t *find, struct image_version *ver);
 
 #ifdef __cplusplus
 }
diff --git a/cmd/img/src/img_state.c b/cmd/img_mgmt/src/img_mgmt_state.c
similarity index 68%
rename from cmd/img/src/img_state.c
rename to cmd/img_mgmt/src/img_mgmt_state.c
index 84b797f..91be314 100644
--- a/cmd/img/src/img_state.c
+++ b/cmd/img_mgmt/src/img_mgmt_state.c
@@ -24,13 +24,13 @@
 #include "cborattr/cborattr.h"
 #include "cbor.h"
 #include "mgmt/mgmt.h"
-#include "img/img.h"
-#include "img/image.h"
-#include "img_priv.h"
-#include "img/img_impl.h"
+#include "img_mgmt/img_mgmt.h"
+#include "img_mgmt/image.h"
+#include "img_mgmt_priv.h"
+#include "img_mgmt/img_mgmt_impl.h"
 
 uint8_t
-img_state_flags(int query_slot)
+img_mgmt_state_flags(int query_slot)
 {
     uint8_t flags;
     int swap_type;
@@ -42,36 +42,36 @@ img_state_flags(int query_slot)
     /* Determine if this is is pending or confirmed (only applicable for
      * unified images and loaders.
      */
-    swap_type = img_impl_swap_type();
+    swap_type = img_mgmt_impl_swap_type();
     switch (swap_type) {
-    case IMG_SWAP_TYPE_NONE:
+    case IMG_MGMT_SWAP_TYPE_NONE:
         if (query_slot == 0) {
-            flags |= IMG_STATE_F_CONFIRMED;
-            flags |= IMG_STATE_F_ACTIVE;
+            flags |= IMG_MGMT_STATE_F_CONFIRMED;
+            flags |= IMG_MGMT_STATE_F_ACTIVE;
         }
         break;
 
-    case IMG_SWAP_TYPE_TEST:
+    case IMG_MGMT_SWAP_TYPE_TEST:
         if (query_slot == 0) {
-            flags |= IMG_STATE_F_CONFIRMED;
+            flags |= IMG_MGMT_STATE_F_CONFIRMED;
         } else if (query_slot == 1) {
-            flags |= IMG_STATE_F_PENDING;
+            flags |= IMG_MGMT_STATE_F_PENDING;
         }
         break;
 
-    case IMG_SWAP_TYPE_PERM:
+    case IMG_MGMT_SWAP_TYPE_PERM:
         if (query_slot == 0) {
-            flags |= IMG_STATE_F_CONFIRMED;
+            flags |= IMG_MGMT_STATE_F_CONFIRMED;
         } else if (query_slot == 1) {
-            flags |= IMG_STATE_F_PENDING | IMG_STATE_F_PERMANENT;
+            flags |= IMG_MGMT_STATE_F_PENDING | IMG_MGMT_STATE_F_PERMANENT;
         }
         break;
 
-    case IMG_SWAP_TYPE_REVERT:
+    case IMG_MGMT_SWAP_TYPE_REVERT:
         if (query_slot == 0) {
-            flags |= IMG_STATE_F_ACTIVE;
+            flags |= IMG_MGMT_STATE_F_ACTIVE;
         } else if (query_slot == 1) {
-            flags |= IMG_STATE_F_CONFIRMED;
+            flags |= IMG_MGMT_STATE_F_CONFIRMED;
         }
         break;
     }
@@ -79,46 +79,46 @@ img_state_flags(int query_slot)
     /* Slot 0 is always active. */
     /* XXX: The slot 0 assumption only holds when running from flash. */
     if (query_slot == 0) {
-        flags |= IMG_STATE_F_ACTIVE;
+        flags |= IMG_MGMT_STATE_F_ACTIVE;
     }
 
     return flags;
 }
 
 static int
-img_state_any_pending(void)
+img_mgmt_state_any_pending(void)
 {
-    return img_state_flags(0) & IMG_STATE_F_PENDING ||
-           img_state_flags(1) & IMG_STATE_F_PENDING;
+    return img_mgmt_state_flags(0) & IMG_MGMT_STATE_F_PENDING ||
+           img_mgmt_state_flags(1) & IMG_MGMT_STATE_F_PENDING;
 }
 
 int
-img_state_slot_in_use(int slot)
+img_mgmt_slot_in_use(int slot)
 {
     uint8_t state_flags;
 
-    state_flags = img_state_flags(slot);
-    return state_flags & IMG_STATE_F_ACTIVE       ||
-           state_flags & IMG_STATE_F_CONFIRMED    ||
-           state_flags & IMG_STATE_F_PENDING;
+    state_flags = img_mgmt_state_flags(slot);
+    return state_flags & IMG_MGMT_STATE_F_ACTIVE       ||
+           state_flags & IMG_MGMT_STATE_F_CONFIRMED    ||
+           state_flags & IMG_MGMT_STATE_F_PENDING;
 }
 
 int
-img_state_set_pending(int slot, int permanent)
+img_mgmt_state_set_pending(int slot, int permanent)
 {
     uint8_t state_flags;
     int rc;
 
-    state_flags = img_state_flags(slot);
+    state_flags = img_mgmt_state_flags(slot);
 
     /* 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 & IMG_STATE_F_CONFIRMED && slot != 0) {
+    if (state_flags & IMG_MGMT_STATE_F_CONFIRMED && slot != 0) {
         return MGMT_ERR_EBADSTATE;
     }
 
-    rc = img_impl_write_pending(slot, permanent);
+    rc = img_mgmt_impl_write_pending(slot, permanent);
     if (rc != 0) {
         return MGMT_ERR_EUNKNOWN;
     }
@@ -127,16 +127,16 @@ img_state_set_pending(int slot, int permanent)
 }
 
 int
-img_state_confirm(void)
+img_mgmt_state_confirm(void)
 {
     int rc;
 
     /* Confirm disallowed if a test is pending. */
-    if (img_state_any_pending()) {
+    if (img_mgmt_state_any_pending()) {
         return MGMT_ERR_EBADSTATE;
     }
 
-    rc = img_impl_write_confirmed();
+    rc = img_mgmt_impl_write_confirmed();
     if (rc != 0) {
         return MGMT_ERR_EUNKNOWN;
     }
@@ -145,14 +145,14 @@ img_state_confirm(void)
 }
 
 int
-img_state_read(struct mgmt_cbuf *cb)
+img_mgmt_state_read(struct mgmt_cbuf *cb)
 {
     int i;
     int rc;
     uint32_t flags;
     struct image_version ver;
-    uint8_t hash[IMG_HASH_LEN]; /* SHA256 hash */
-    char vers_str[IMG_NMGR_MAX_VER];
+    uint8_t hash[IMAGE_HASH_LEN]; /* SHA256 hash */
+    char vers_str[IMG_MGMT_MAX_VER];
     int any_non_bootable;
     uint8_t state_flags;
     CborError g_err = CborNoError;
@@ -166,7 +166,7 @@ img_state_read(struct mgmt_cbuf *cb)
     g_err |= cbor_encoder_create_array(&cb->encoder, &images,
                                        CborIndefiniteLength);
     for (i = 0; i < 2; i++) {
-        rc = img_read_info(i, &ver, hash, &flags);
+        rc = img_mgmt_read_info(i, &ver, hash, &flags);
         if (rc != 0) {
             continue;
         }
@@ -175,7 +175,7 @@ img_state_read(struct mgmt_cbuf *cb)
             any_non_bootable = 1;
         }
 
-        state_flags = img_state_flags(i);
+        state_flags = img_mgmt_state_flags(i);
 
         g_err |= cbor_encoder_create_map(&images, &image,
                                          CborIndefiniteLength);
@@ -183,30 +183,30 @@ img_state_read(struct mgmt_cbuf *cb)
         g_err |= cbor_encode_int(&image, i);
 
         g_err |= cbor_encode_text_stringz(&image, "version");
-        img_ver_str(&ver, vers_str);
+        img_mgmt_ver_str(&ver, vers_str);
         g_err |= cbor_encode_text_stringz(&image, vers_str);
 
         g_err |= cbor_encode_text_stringz(&image, "hash");
-        g_err |= cbor_encode_byte_string(&image, hash, IMG_HASH_LEN);
+        g_err |= cbor_encode_byte_string(&image, hash, IMAGE_HASH_LEN);
 
         g_err |= cbor_encode_text_stringz(&image, "bootable");
         g_err |= cbor_encode_boolean(&image, !(flags & IMAGE_F_NON_BOOTABLE));
 
         g_err |= cbor_encode_text_stringz(&image, "pending");
         g_err |= cbor_encode_boolean(&image,
-                                     state_flags & IMG_STATE_F_PENDING);
+                                     state_flags & IMG_MGMT_STATE_F_PENDING);
 
         g_err |= cbor_encode_text_stringz(&image, "confirmed");
         g_err |= cbor_encode_boolean(&image,
-                                     state_flags & IMG_STATE_F_CONFIRMED);
+                                     state_flags & IMG_MGMT_STATE_F_CONFIRMED);
 
         g_err |= cbor_encode_text_stringz(&image, "active");
         g_err |= cbor_encode_boolean(&image,
-                                     state_flags & IMG_STATE_F_ACTIVE);
+                                     state_flags & IMG_MGMT_STATE_F_ACTIVE);
 
         g_err |= cbor_encode_text_stringz(&image, "permanent");
         g_err |= cbor_encode_boolean(&image,
-                                     state_flags & IMG_STATE_F_PERMANENT);
+                                     state_flags & IMG_MGMT_STATE_F_PERMANENT);
 
         g_err |= cbor_encoder_close_container(&images, &image);
     }
@@ -223,9 +223,9 @@ img_state_read(struct mgmt_cbuf *cb)
 }
 
 int
-img_state_write(struct mgmt_cbuf *cb)
+img_mgmt_state_write(struct mgmt_cbuf *cb)
 {
-    uint8_t hash[IMG_HASH_LEN];
+    uint8_t hash[IMAGE_HASH_LEN];
     size_t hash_len = 0;
     bool confirm;
     int slot;
@@ -262,7 +262,7 @@ img_state_write(struct mgmt_cbuf *cb)
             return MGMT_ERR_EINVAL;
         }
     } else {
-        slot = img_find_by_hash(hash, NULL);
+        slot = img_mgmt_find_by_hash(hash, NULL);
         if (slot < 0) {
             return MGMT_ERR_EINVAL;
         }
@@ -270,16 +270,16 @@ img_state_write(struct mgmt_cbuf *cb)
 
     if (slot == 0 && confirm) {
         /* Confirm current setup. */
-        rc = img_state_confirm();
+        rc = img_mgmt_state_confirm();
     } else {
-        rc = img_state_set_pending(slot, confirm);
+        rc = img_mgmt_state_set_pending(slot, confirm);
     }
     if (rc != 0) {
         return rc;
     }
 
     /* Send the current image state in the response. */
-    rc = img_state_read(cb);
+    rc = img_mgmt_state_read(cb);
     if (rc != 0) {
         return rc;
     }
diff --git a/cmd/img/src/img_util.c b/cmd/img_mgmt/src/img_mgmt_util.c
similarity index 50%
rename from cmd/img/src/img_util.c
rename to cmd/img_mgmt/src/img_mgmt_util.c
index ae9ca1e..7b4124b 100644
--- a/cmd/img/src/img_util.c
+++ b/cmd/img_mgmt/src/img_mgmt_util.c
@@ -22,64 +22,11 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "img/image.h"
-#include "img/img.h"
+#include "img_mgmt/image.h"
+#include "img_mgmt/img_mgmt.h"
 
-// Removed due to missing strsep().
-#if 0
 int
-img_ver_parse(char *src, struct image_version *ver)
-{
-    unsigned long ul;
-    char *tok;
-    char *nxt;
-    char *ep;
-
-    memset(ver, 0, sizeof(*ver));
-
-    nxt = src;
-    tok = strsep(&nxt, ".");
-    ul = strtoul(tok, &ep, 10);
-    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
-        return -1;
-    }
-    ver->iv_major = ul;
-    if (nxt == NULL) {
-        return 0;
-    }
-    tok = strsep(&nxt, ".");
-    ul = strtoul(tok, &ep, 10);
-    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT8_MAX) {
-        return -1;
-    }
-    ver->iv_minor = ul;
-    if (nxt == NULL) {
-        return 0;
-    }
-
-    tok = strsep(&nxt, ".");
-    ul = strtoul(tok, &ep, 10);
-    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT16_MAX) {
-        return -1;
-    }
-    ver->iv_revision = ul;
-    if (nxt == NULL) {
-        return 0;
-    }
-
-    tok = nxt;
-    ul = strtoul(tok, &ep, 10);
-    if (tok[0] == '\0' || ep[0] != '\0' || ul > UINT32_MAX) {
-        return -1;
-    }
-    ver->iv_build_num = ul;
-
-    return 0;
-}
-#endif
-
-int
-img_ver_str(const struct image_version *ver, char *dst)
+img_mgmt_ver_str(const struct image_version *ver, char *dst)
 {
     if (ver->iv_build_num) {
         return sprintf(dst, "%u.%u.%u.%lu",
diff --git a/cmd/img/syscfg.yml b/cmd/img_mgmt/syscfg.yml
similarity index 100%
rename from cmd/img/syscfg.yml
rename to cmd/img_mgmt/syscfg.yml

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

[mynewt-mcumgr] 03/05: Move `img` command handlers to `cmd` TLD.

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 9f52c32e9b17b4df758ffab8ce885885cca49496
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Jan 4 16:54:03 2018 -0800

    Move `img` command handlers to `cmd` TLD.
---
 {img => cmd/img}/include/img/image.h          | 0
 {img => cmd/img}/include/img/img.h            | 0
 {img => cmd/img}/include/img/img_impl.h       | 0
 {img => cmd/img}/pkg.yml                      | 2 +-
 {img => cmd/img}/port/mynewt/pkg.yml          | 4 ++--
 {img => cmd/img}/port/mynewt/src/mynewt_img.c | 0
 {img => cmd/img}/port/zephyr/src/zephyr_img.c | 0
 {img => cmd/img}/src/img.c                    | 0
 {img => cmd/img}/src/img_priv.h               | 0
 {img => cmd/img}/src/img_state.c              | 0
 {img => cmd/img}/src/img_util.c               | 0
 {img => cmd/img}/syscfg.yml                   | 0
 12 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/img/include/img/image.h b/cmd/img/include/img/image.h
similarity index 100%
rename from img/include/img/image.h
rename to cmd/img/include/img/image.h
diff --git a/img/include/img/img.h b/cmd/img/include/img/img.h
similarity index 100%
rename from img/include/img/img.h
rename to cmd/img/include/img/img.h
diff --git a/img/include/img/img_impl.h b/cmd/img/include/img/img_impl.h
similarity index 100%
rename from img/include/img/img_impl.h
rename to cmd/img/include/img/img_impl.h
diff --git a/img/pkg.yml b/cmd/img/pkg.yml
similarity index 98%
rename from img/pkg.yml
rename to cmd/img/pkg.yml
index 351e3cf..6904563 100644
--- a/img/pkg.yml
+++ b/cmd/img/pkg.yml
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-pkg.name: img
+pkg.name: cmd/img
 pkg.description: Library for image uploading.
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
diff --git a/img/port/mynewt/pkg.yml b/cmd/img/port/mynewt/pkg.yml
similarity index 94%
rename from img/port/mynewt/pkg.yml
rename to cmd/img/port/mynewt/pkg.yml
index ecbc68f..0e5ec11 100644
--- a/img/port/mynewt/pkg.yml
+++ b/cmd/img/port/mynewt/pkg.yml
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-pkg.name: img/port/mynewt
+pkg.name: cmd/img/port/mynewt
 pkg.description: XXX
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
@@ -27,5 +27,5 @@ pkg.deps:
     - '@apache-mynewt-core/boot/split'
     - '@apache-mynewt-core/encoding/base64'
     - '@apache-mynewt-core/sys/flash_map'
-    - '@mynewt-mcumgr/img'
+    - '@mynewt-mcumgr/cmd/img'
     - '@mynewt-mcumgr/mgmt'
diff --git a/img/port/mynewt/src/mynewt_img.c b/cmd/img/port/mynewt/src/mynewt_img.c
similarity index 100%
rename from img/port/mynewt/src/mynewt_img.c
rename to cmd/img/port/mynewt/src/mynewt_img.c
diff --git a/img/port/zephyr/src/zephyr_img.c b/cmd/img/port/zephyr/src/zephyr_img.c
similarity index 100%
rename from img/port/zephyr/src/zephyr_img.c
rename to cmd/img/port/zephyr/src/zephyr_img.c
diff --git a/img/src/img.c b/cmd/img/src/img.c
similarity index 100%
rename from img/src/img.c
rename to cmd/img/src/img.c
diff --git a/img/src/img_priv.h b/cmd/img/src/img_priv.h
similarity index 100%
rename from img/src/img_priv.h
rename to cmd/img/src/img_priv.h
diff --git a/img/src/img_state.c b/cmd/img/src/img_state.c
similarity index 100%
rename from img/src/img_state.c
rename to cmd/img/src/img_state.c
diff --git a/img/src/img_util.c b/cmd/img/src/img_util.c
similarity index 100%
rename from img/src/img_util.c
rename to cmd/img/src/img_util.c
diff --git a/img/syscfg.yml b/cmd/img/syscfg.yml
similarity index 100%
rename from img/syscfg.yml
rename to cmd/img/syscfg.yml

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

[mynewt-mcumgr] 05/05: OS command group

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 79f78f0e932e8dee55e8afe7dc09c4caf22e31fa
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Jan 5 10:39:32 2018 -0800

    OS command group
---
 cmd/os_mgmt/Makefile                         |  17 ++
 cmd/os_mgmt/include/os_mgmt/os_mgmt.h        |  45 ++++
 cmd/os_mgmt/include/os_mgmt/os_mgmt_impl.h   |   6 +
 cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c |  37 ++++
 cmd/os_mgmt/port/zephyr/src/zephyr_os_mgmt.c |  23 ++
 cmd/os_mgmt/src/os_mgmt.c                    | 320 +++++++++++++++++++++++++++
 6 files changed, 448 insertions(+)

diff --git a/cmd/os_mgmt/Makefile b/cmd/os_mgmt/Makefile
new file mode 100644
index 0000000..8b6287f
--- /dev/null
+++ b/cmd/os_mgmt/Makefile
@@ -0,0 +1,17 @@
+#
+# Copyright (c) 2017 Intel Corporation
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+PREFIX ?= .
+OBJ_DIR ?= $(PREFIX)/obj
+LIB_DIR ?= $(PREFIX)/lib
+
+all:
+	mkdir -p $(OBJ_DIR) $(LIB_DIR)
+	$(CC) -c $(CFLAGS) -Iinclude -I$(CURDIR)/../tinycbor/src -I$(CURDIR)/../cborattr/include -I$(CURDIR)/../mcumgr/mgmt/include src/mgmt_os.c -o $(OBJ_DIR)/mgmt_os.o
+	$(AR) -rcs $(LIB_DIR)/libmgmt_os.a $(OBJ_DIR)/mgmt_os.o
+
+clean:
+	rm -rf $(OBJ_DIR) $(LIB_DIR)
diff --git a/cmd/os_mgmt/include/os_mgmt/os_mgmt.h b/cmd/os_mgmt/include/os_mgmt/os_mgmt.h
new file mode 100644
index 0000000..6037946
--- /dev/null
+++ b/cmd/os_mgmt/include/os_mgmt/os_mgmt.h
@@ -0,0 +1,45 @@
+/*
+ * 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_OS_MGMT_
+#define H_OS_MGMT_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct mgmt_cbuf;
+
+/*
+ * Command IDs for OS management group.
+ */
+#define OS_MGMT_ID_ECHO             0
+#define OS_MGMT_ID_CONS_ECHO_CTRL   1
+#define OS_MGMT_ID_TASKSTATS        2
+#define OS_MGMT_ID_MPSTATS          3
+#define OS_MGMT_ID_DATETIME_STR     4
+#define OS_MGMT_ID_RESET            5
+
+int os_mgmt_group_register(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_OS_MGMT_ */
diff --git a/cmd/os_mgmt/include/os_mgmt/os_mgmt_impl.h b/cmd/os_mgmt/include/os_mgmt/os_mgmt_impl.h
new file mode 100644
index 0000000..e3b3308
--- /dev/null
+++ b/cmd/os_mgmt/include/os_mgmt/os_mgmt_impl.h
@@ -0,0 +1,6 @@
+#ifndef H_OS_MGMT_IMPL_
+#define H_OS_MGMT_IMPL_
+
+int os_mgmt_impl_reset(void);
+
+#endif
diff --git a/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c b/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c
new file mode 100644
index 0000000..9763ce9
--- /dev/null
+++ b/cmd/os_mgmt/port/mynewt/src/mynewt_os_mgmt.c
@@ -0,0 +1,37 @@
+#include "hal/hal_system.h"
+#include "hal/hal_watchdog.h"
+#include "os/os.h"
+#if MYNEWT_VAL(LOG_SOFT_RESET)
+#include "reboot/log_reboot.h"
+#endif
+#include "os_mgmt/os_mgmt_impl.h"
+
+static struct os_callout mynewt_os_mgmt_reset_callout;
+
+static void
+mynewt_os_mgmt_reset_tmo(struct os_event *ev)
+{
+    /*
+     * Tickle watchdog just before re-entering bootloader.
+     * Depending on what system has been doing lately, watchdog
+     * timer might be close to firing.
+     */
+    hal_watchdog_tickle();
+    hal_system_reset();
+}
+
+int
+os_mgmt_impl_reset(void)
+{
+    int rc;
+
+    os_callout_init(&mynewt_os_mgmt_reset_callout, mgmt_evq_get(),
+                    nmgr_reset_tmo, NULL);
+
+#if MYNEWT_VAL(LOG_SOFT_RESET)
+    log_reboot(HAL_RESET_REQUESTED);
+#endif
+    os_callout_reset(&nmgr_reset_callout, OS_TICKS_PER_SEC / 4);
+
+    return 0;
+}
diff --git a/cmd/os_mgmt/port/zephyr/src/zephyr_os_mgmt.c b/cmd/os_mgmt/port/zephyr/src/zephyr_os_mgmt.c
new file mode 100644
index 0000000..95e9b8f
--- /dev/null
+++ b/cmd/os_mgmt/port/zephyr/src/zephyr_os_mgmt.c
@@ -0,0 +1,23 @@
+#include <zephyr.h>
+#include <misc/reboot.h>
+#include "os_mgmt/os_mgmt_impl.h"
+
+static void zephyr_os_mgmt_reset_cb(struct k_timer *timer);
+
+static K_TIMER_DEFINE(zephyr_os_mgmt_reset_timer,
+                      zephyr_os_mgmt_reset_cb, NULL);
+
+
+static void
+zephyr_os_mgmt_reset_cb(struct k_timer *timer)
+{
+    sys_reboot(SYS_REBOOT_WARM);
+}
+
+int
+os_mgmt_impl_reset(void)
+{
+    k_timer_start(&zephyr_os_mgmt_reset_timer, K_MSEC(250), 0);
+
+    return 0;
+}
diff --git a/cmd/os_mgmt/src/os_mgmt.c b/cmd/os_mgmt/src/os_mgmt.c
new file mode 100644
index 0000000..5429d74
--- /dev/null
+++ b/cmd/os_mgmt/src/os_mgmt.c
@@ -0,0 +1,320 @@
+/*
+ * 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 <assert.h>
+#include <string.h>
+#include "mgmt/mgmt.h"
+#include "os_mgmt/os_mgmt.h"
+#include "os_mgmt/os_mgmt_impl.h"
+#include "cbor.h"
+#include "cborattr/cborattr.h"
+
+static mgmt_handler_fn os_mgmt_echo;
+static mgmt_handler_fn os_mgmt_reset;
+
+#if 0
+static int os_mgmt_console_echo(struct mgmt_cbuf *);
+static int os_mgmt_taskstat_read(struct mgmt_cbuf *njb);
+static int os_mgmt_mpstat_read(struct mgmt_cbuf *njb);
+static int os_mgmt_datetime_get(struct mgmt_cbuf *njb);
+static int os_mgmt_datetime_set(struct mgmt_cbuf *njb);
+#endif
+
+static const struct mgmt_handler os_mgmt_group_handlers[] = {
+    [OS_MGMT_ID_ECHO] = {
+        os_mgmt_echo, os_mgmt_echo
+    },
+#if 0
+    [OS_MGMT_ID_CONS_ECHO_CTRL] = {
+        os_mgmt_console_echo, os_mgmt_console_echo
+    },
+    [OS_MGMT_ID_TASKSTATS] = {
+        os_mgmt_taskstat_read, NULL
+    },
+    [OS_MGMT_ID_MPSTATS] = {
+        os_mgmt_mpstat_read, NULL
+    },
+    [OS_MGMT_ID_DATETIME_STR] = {
+        os_mgmt_datetime_get, os_mgmt_datetime_set
+    },
+#endif
+    [OS_MGMT_ID_RESET] = {
+        NULL, os_mgmt_reset
+    },
+};
+
+#define OS_MGMT_GROUP_SZ    \
+    (sizeof os_mgmt_group_handlers / sizeof os_mgmt_group_handlers[0])
+
+static struct mgmt_group os_mgmt_group = {
+    .mg_handlers = os_mgmt_group_handlers,
+    .mg_handlers_count = OS_MGMT_GROUP_SZ,
+    .mg_group_id = MGMT_GROUP_ID_OS,
+};
+
+static int
+os_mgmt_echo(struct mgmt_cbuf *cb)
+{
+    char echo_buf[128] = {'\0'};
+    CborError g_err = CborNoError;
+
+    const struct cbor_attr_t attrs[2] = {
+        [0] = {
+            .attribute = "d",
+            .type = CborAttrTextStringType,
+            .addr.string = echo_buf,
+            .nodefault = 1,
+            .len = sizeof(echo_buf),
+        },
+        [1] = {
+            .attribute = NULL
+        }
+    };
+
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "r");
+    g_err |= cbor_read_object(&cb->it, attrs);
+    g_err |= cbor_encode_text_string(&cb->encoder, echo_buf, strlen(echo_buf));
+
+    if (g_err) {
+        return MGMT_ERR_ENOMEM;
+    }
+    return (0);
+}
+
+#if 0
+static int
+os_mgmt_console_echo(struct mgmt_cbuf *cb)
+{
+    long long int echo_on = 1;
+    int rc;
+    const struct cbor_attr_t attrs[2] = {
+        [0] = {
+            .attribute = "echo",
+            .type = CborAttrIntegerType,
+            .addr.integer = &echo_on,
+            .nodefault = 1
+        },
+        [1] = { 0 },
+    };
+
+    rc = cbor_read_object(&cb->it, attrs);
+    if (rc) {
+        return MGMT_ERR_EINVAL;
+    }
+
+    if (echo_on) {
+        console_echo(1);
+    } else {
+        console_echo(0);
+    }
+    return (0);
+}
+
+static int
+os_mgmt_taskstat_read(struct mgmt_cbuf *cb)
+{
+    struct os_task *prev_task;
+    struct os_task_info oti;
+    CborError g_err = CborNoError;
+    CborEncoder tasks;
+    CborEncoder task;
+
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "tasks");
+    g_err |= cbor_encoder_create_map(&cb->encoder, &tasks,
+                                     CborIndefiniteLength);
+
+    prev_task = NULL;
+    while (1) {
+        prev_task = os_task_info_get_next(prev_task, &oti);
+        if (prev_task == NULL) {
+            break;
+        }
+
+        g_err |= cbor_encode_text_stringz(&tasks, oti.oti_name);
+        g_err |= cbor_encoder_create_map(&tasks, &task, CborIndefiniteLength);
+        g_err |= cbor_encode_text_stringz(&task, "prio");
+        g_err |= cbor_encode_uint(&task, oti.oti_prio);
+        g_err |= cbor_encode_text_stringz(&task, "tid");
+        g_err |= cbor_encode_uint(&task, oti.oti_taskid);
+        g_err |= cbor_encode_text_stringz(&task, "state");
+        g_err |= cbor_encode_uint(&task, oti.oti_state);
+        g_err |= cbor_encode_text_stringz(&task, "stkuse");
+        g_err |= cbor_encode_uint(&task, oti.oti_stkusage);
+        g_err |= cbor_encode_text_stringz(&task, "stksiz");
+        g_err |= cbor_encode_uint(&task, oti.oti_stksize);
+        g_err |= cbor_encode_text_stringz(&task, "cswcnt");
+        g_err |= cbor_encode_uint(&task, oti.oti_cswcnt);
+        g_err |= cbor_encode_text_stringz(&task, "runtime");
+        g_err |= cbor_encode_uint(&task, oti.oti_runtime);
+        g_err |= cbor_encode_text_stringz(&task, "last_checkin");
+        g_err |= cbor_encode_uint(&task, oti.oti_last_checkin);
+        g_err |= cbor_encode_text_stringz(&task, "next_checkin");
+        g_err |= cbor_encode_uint(&task, oti.oti_next_checkin);
+        g_err |= cbor_encoder_close_container(&tasks, &task);
+    }
+    g_err |= cbor_encoder_close_container(&cb->encoder, &tasks);
+
+    if (g_err) {
+        return MGMT_ERR_ENOMEM;
+    }
+    return (0);
+}
+
+static int
+os_mgmt_mpstat_read(struct mgmt_cbuf *cb)
+{
+    struct os_mempool *prev_mp;
+    struct os_mempool_info omi;
+    CborError g_err = CborNoError;
+    CborEncoder pools;
+    CborEncoder pool;
+
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "mpools");
+    g_err |= cbor_encoder_create_map(&cb->encoder, &pools,
+                                     CborIndefiniteLength);
+
+    prev_mp = NULL;
+    while (1) {
+        prev_mp = os_mempool_info_get_next(prev_mp, &omi);
+        if (prev_mp == NULL) {
+            break;
+        }
+
+        g_err |= cbor_encode_text_stringz(&pools, omi.omi_name);
+        g_err |= cbor_encoder_create_map(&pools, &pool, CborIndefiniteLength);
+        g_err |= cbor_encode_text_stringz(&pool, "blksiz");
+        g_err |= cbor_encode_uint(&pool, omi.omi_block_size);
+        g_err |= cbor_encode_text_stringz(&pool, "nblks");
+        g_err |= cbor_encode_uint(&pool, omi.omi_num_blocks);
+        g_err |= cbor_encode_text_stringz(&pool, "nfree");
+        g_err |= cbor_encode_uint(&pool, omi.omi_num_free);
+        g_err |= cbor_encode_text_stringz(&pool, "min");
+        g_err |= cbor_encode_uint(&pool, omi.omi_min_free);
+        g_err |= cbor_encoder_close_container(&pools, &pool);
+    }
+
+    g_err |= cbor_encoder_close_container(&cb->encoder, &pools);
+
+    if (g_err) {
+        return MGMT_ERR_ENOMEM;
+    }
+    return (0);
+}
+
+static int
+os_mgmt_datetime_get(struct mgmt_cbuf *cb)
+{
+    struct os_timeval tv;
+    struct os_timezone tz;
+    char buf[DATETIME_BUFSIZE];
+    int rc;
+    CborError g_err = CborNoError;
+
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+
+    /* Display the current datetime */
+    rc = os_gettimeofday(&tv, &tz);
+    assert(rc == 0);
+    rc = datetime_format(&tv, &tz, buf, DATETIME_BUFSIZE);
+    if (rc) {
+        rc = MGMT_ERR_EINVAL;
+        goto err;
+    }
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "datetime");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, buf);
+
+    if (g_err) {
+        return MGMT_ERR_ENOMEM;
+    }
+    return 0;
+
+err:
+    return (rc);
+}
+
+static int
+os_mgmt_datetime_set(struct mgmt_cbuf *cb)
+{
+    struct os_timeval tv;
+    struct os_timezone tz;
+    char buf[DATETIME_BUFSIZE];
+    int rc = 0;
+    const struct cbor_attr_t datetime_write_attr[] = {
+        [0] = {
+            .attribute = "datetime",
+            .type = CborAttrTextStringType,
+            .addr.string = buf,
+            .len = sizeof(buf),
+        },
+        { 0 },
+    };
+
+    rc = cbor_read_object(&cb->it, datetime_write_attr);
+    if (rc) {
+        return MGMT_ERR_EINVAL;
+    }
+
+    /* Set the current datetime */
+    rc = datetime_parse(buf, &tv, &tz);
+    if (!rc) {
+        rc = os_settimeofday(&tv, &tz);
+        if (rc) {
+          return MGMT_ERR_EINVAL;
+        }
+    } else {
+        return MGMT_ERR_EINVAL;
+    }
+
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
+}
+
+static void
+os_mgmt_reset_tmo(struct os_event *ev)
+{
+    /*
+     * Tickle watchdog just before re-entering bootloader.
+     * Depending on what system has been doing lately, watchdog
+     * timer might be close to firing.
+     */
+    hal_watchdog_tickle();
+    hal_system_reset();
+}
+#endif
+
+static int
+os_mgmt_reset(struct mgmt_cbuf *cb)
+{
+    return os_mgmt_impl_reset();
+}
+
+int
+os_mgmt_group_register(void)
+{
+    return mgmt_group_register(&os_mgmt_group);
+}

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

[mynewt-mcumgr] 01/05: zephyr - fragmentation of overly long responses.

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 d03e76c77eb1c4bb0b3da54d2b099c3435868cfa
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Jan 4 13:24:35 2018 -0800

    zephyr - fragmentation of overly long responses.
---
 smp/port/zephyr/include/zephyr_smp/zephyr_smp.h | 13 ++++-
 smp/port/zephyr/src/zephyr_smp.c                | 72 +++++++++++++++----------
 2 files changed, 55 insertions(+), 30 deletions(-)

diff --git a/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h b/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h
index d74e8c4..c05ef01 100644
--- a/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h
+++ b/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h
@@ -14,7 +14,18 @@ struct zephyr_nmgr_pkt;
  */
 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);
+
+/**
+ * MTU query function.  The supplied packet should contain a request received
+ * from the peer whose MTU is being queried.  This function takes a packet
+ * parameter because some transports store connection-specific information in
+ * the packet (e.g., the BLE transport stores the connection pointer).
+ *
+ * @return                      The transport's MTU;
+ *                              0 if transmission is currently not possible.
+ */
+typedef uint16_t
+zephyr_smp_transport_get_mtu_fn(const struct zephyr_nmgr_pkt *pkt);
 
 struct zephyr_smp_transport {
     /* Must be the first member. */
diff --git a/smp/port/zephyr/src/zephyr_smp.c b/smp/port/zephyr/src/zephyr_smp.c
index 2262397..759006d 100644
--- a/smp/port/zephyr/src/zephyr_smp.c
+++ b/smp/port/zephyr/src/zephyr_smp.c
@@ -23,32 +23,6 @@ static const struct mgmt_streamer_cfg zephyr_smp_cbor_cfg = {
     .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)
 {
@@ -68,6 +42,29 @@ zephyr_smp_alloc_rsp(const void *req, void *arg)
     return rsp_pkt;
 }
 
+static struct zephyr_nmgr_pkt *
+zephyr_smp_split_frag(struct zephyr_nmgr_pkt **pkt, uint16_t mtu)
+{
+    struct zephyr_nmgr_pkt *frag;
+    struct zephyr_nmgr_pkt *src;
+
+    src = *pkt;
+
+    if (src->len <= mtu) {
+        *pkt = NULL;
+        frag = src;
+    } else {
+        frag = zephyr_smp_alloc_rsp(src, NULL);
+        frag->len = mtu;
+        memcpy(frag->data, src->data, mtu);
+
+        src->len -= mtu;
+        memmove(src->data, src->data + mtu, src->len);
+    }
+
+    return frag;
+}
+
 static int
 zephyr_smp_trim_front(void *buf, int len, void *arg)
 {
@@ -126,18 +123,35 @@ static int
 zephyr_smp_tx_rsp(struct smp_streamer *ns, void *rsp, void *arg)
 {
     struct zephyr_smp_transport *zst;
+    struct zephyr_nmgr_pkt *frag;
     struct zephyr_nmgr_pkt *pkt;
+    uint16_t mtu;
     int rc;
+    int i;
 
     zst = arg;
     pkt = rsp;
 
-    rc = zst->zst_output(zst, pkt);
-    if (rc != 0) {
+    mtu = zst->zst_get_mtu(rsp);
+    if (mtu == 0) {
+        /* The transport cannot support a transmission right now. */
         return MGMT_ERR_EUNKNOWN;
     }
 
-    return MGMT_ERR_EOK;
+    i = 0;
+    while (pkt != NULL) {
+        frag = zephyr_smp_split_frag(&pkt, mtu);
+        if (frag == NULL) {
+            return MGMT_ERR_ENOMEM;
+        }
+
+        rc = zst->zst_output(zst, frag);
+        if (rc != 0) {
+            return MGMT_ERR_EUNKNOWN;
+        }
+    }
+
+    return 0;
 }
 
 static void

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

[mynewt-mcumgr] 02/05: Make znp extra buffer larger (4B --> 8B).

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 cd8293558655fe5b127707bfaf9c868947d8ea95
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Jan 4 15:19:10 2018 -0800

    Make znp extra buffer larger (4B --> 8B).
    
    The znp type (struct zephyr_nmgr_pkt) is an intermediate construct used
    only during development.  Therefore, this change will have no effect
    once znp is removed from the codebase.
    
    This change was necessary for BLE.  We need to store the peer's address
    in the packet rather than just the connection pointer.  Using just the
    pointer is not a good solution because it is impossible to perform all
    the necessary reference counting.
---
 smp/port/zephyr/include/zephyr_smp/zephyr_smp.h | 2 +-
 smp/port/zephyr/src/zephyr_smp.c                | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h b/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h
index c05ef01..c84ce91 100644
--- a/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h
+++ b/smp/port/zephyr/include/zephyr_smp/zephyr_smp.h
@@ -19,7 +19,7 @@ typedef int zephyr_smp_transport_out_fn(struct zephyr_smp_transport *zst,
  * MTU query function.  The supplied packet should contain a request received
  * from the peer whose MTU is being queried.  This function takes a packet
  * parameter because some transports store connection-specific information in
- * the packet (e.g., the BLE transport stores the connection pointer).
+ * the packet (e.g., the BLE transport stores the peer address).
  *
  * @return                      The transport's MTU;
  *                              0 if transmission is currently not possible.
diff --git a/smp/port/zephyr/src/zephyr_smp.c b/smp/port/zephyr/src/zephyr_smp.c
index 759006d..823a67c 100644
--- a/smp/port/zephyr/src/zephyr_smp.c
+++ b/smp/port/zephyr/src/zephyr_smp.c
@@ -37,7 +37,7 @@ zephyr_smp_alloc_rsp(const void *req, void *arg)
         return NULL;
     }
     rsp_pkt->len = 0;
-    rsp_pkt->extra = req_pkt->extra;
+    memcpy(rsp_pkt->extra, req_pkt->extra, sizeof rsp_pkt->extra);
 
     return rsp_pkt;
 }

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