DFU working on zephyr
diff --git a/cborattr/Kconfig b/cborattr/Kconfig
deleted file mode 100644
index ed54c7a..0000000
--- a/cborattr/Kconfig
+++ /dev/null
@@ -1,22 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE image
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this image
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this image 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.
-
-config CBORATTR_MAX_SIZE
-    int "Maximum chunk size for image uploads"
-    default 512
-    help
-      The maximum size of a CBOR attribute during decoding
diff --git a/cborattr/src/cborattr.c b/cborattr/src/cborattr.c
index 662836a..e94a490 100644
--- a/cborattr/src/cborattr.c
+++ b/cborattr/src/cborattr.c
@@ -17,24 +17,23 @@
  * under the License.
  */
 
-//#include <syscfg/syscfg.h>
 #include "cborattr/cborattr.h"
 #include "tinycbor/cbor.h"
 #include "tinycbor/cbor_buf_reader.h"
 
+#ifdef __ZEPHYR__
+#include <zephyr.h>
+#define CBORATTR_MAX_SIZE CONFIG_MGMT_CBORATTR_MAX_SIZE
+#endif
+
 #ifdef MYNEWT
+#include "syscfg/syscfg.h"
 #include "tinycbor/cbor_mbuf_reader.h"
 #include "tinycbor/cbor_mbuf_writer.h"
 #include "os/os_mbuf.h"
 #define CBORATTR_MAX_SIZE MYNEWT_VAL(CBORATTR_MAX_SIZE)
-#else
-#define CBORATTR_MAX_SIZE CONFIG_CBORATTR_MAX_SIZE
 #endif
 
-
-static int cbor_write_val(struct CborEncoder *enc,
-                          const struct cbor_out_val_t *val);
-
 /* this maps a CborType to a matching CborAtter Type. The mapping is not
  * one-to-one because of signedness of integers
  * and therefore we need a function to do this trickery */
@@ -409,6 +408,9 @@
 }
 
 #ifdef MYNEWT
+static int cbor_write_val(struct CborEncoder *enc,
+                          const struct cbor_out_val_t *val);
+
 /*
  * Read in cbor key/values from os_mbuf pointed by m, and fill them
  * into attrs.
diff --git a/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c b/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c
index 231a0f8..66af8c4 100644
--- a/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c
+++ b/cmd/fs_mgmt/port/zephyr/src/zephyr_fs_mgmt.c
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-#include <fs.h>
+#include <fs/fs.h>
 #include <mgmt/mgmt.h>
 #include <fs_mgmt/fs_mgmt_impl.h>
 
diff --git a/cmd/img_mgmt/CMakeLists.txt b/cmd/img_mgmt/CMakeLists.txt
index 1166d7d..3c54e05 100644
--- a/cmd/img_mgmt/CMakeLists.txt
+++ b/cmd/img_mgmt/CMakeLists.txt
@@ -4,8 +4,8 @@
 
 zephyr_library_sources(
     port/zephyr/src/zephyr_img_mgmt.c
+    port/zephyr/src/zephyr_img_mgmt_log.c
     src/img_mgmt.c
     src/img_mgmt_state.c
     src/img_mgmt_util.c
-    src/stubs.c
 )
diff --git a/cmd/img_mgmt/include/img_mgmt/img_mgmt_config.h b/cmd/img_mgmt/include/img_mgmt/img_mgmt_config.h
index 66fb218..250c29d 100644
--- a/cmd/img_mgmt/include/img_mgmt/img_mgmt_config.h
+++ b/cmd/img_mgmt/include/img_mgmt/img_mgmt_config.h
@@ -27,12 +27,16 @@
 #define IMG_MGMT_UL_CHUNK_SIZE  MYNEWT_VAL(IMG_MGMT_UL_CHUNK_SIZE)
 #define IMG_MGMT_VERBOSE_ERR    MYNEWT_VAL(IMG_MGMT_VERBOSE_ERR)
 #define IMG_MGMT_LAZY_ERASE     MYNEWT_VAL(IMG_MGMT_LAZY_ERASE)
+#define IMG_MGMT_DUMMY_HDR      MYNEWT_VAL(IMG_MGMT_DUMMY_HDR)
+#define IMG_MGMT_BOOT_CURR_SLOT boot_current_slot
 
 #elif defined __ZEPHYR__
 
 #define IMG_MGMT_UL_CHUNK_SIZE  CONFIG_IMG_MGMT_UL_CHUNK_SIZE
 #define IMG_MGMT_VERBOSE_ERR    CONFIG_IMG_MGMT_VERBOSE_ERR
-#define IMG_MGMT_LAZY_ERASE     CONFIG_IMG_MGMT_LAZY_ERASE
+#define IMG_MGMT_LAZY_ERASE     CONFIG_IMG_ERASE_PROGRESSIVELY
+#define IMG_MGMT_DUMMY_HDR      CONFIG_IMG_MGMT_DUMMY_HDR
+#define IMG_MGMT_BOOT_CURR_SLOT 0
 
 #else
 
diff --git a/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h b/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
index 0cb91a9..cff7dfa 100644
--- a/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
+++ b/cmd/img_mgmt/include/img_mgmt/img_mgmt_impl.h
@@ -131,7 +131,7 @@
  * @param off      Offset that is about to be written
  * @param len      Number of bytes to be written
  *
- * @return         0 if success 
+ * @return         0 if success
  *                 ERROR_CODE if could not erase sector
  */
 int img_mgmt_impl_erase_if_needed(uint32_t off, uint32_t len);
diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
index a21237d..bb96f6f 100644
--- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c
@@ -17,9 +17,14 @@
  * under the License.
  */
 
+#define LOG_MODULE_NAME mcumgr_flash_mgmt
+#define LOG_LEVEL CONFIG_IMG_MANAGER_LOG_LEVEL
+#include <logging/log.h>
+LOG_MODULE_REGISTER(LOG_MODULE_NAME);
+
 #include <assert.h>
 #include <flash.h>
-#include <flash_map.h>
+#include <storage/flash_map.h>
 #include <zephyr.h>
 #include <soc.h>
 #include <init.h>
@@ -28,6 +33,7 @@
 #include <mgmt/mgmt.h>
 #include <img_mgmt/img_mgmt_impl.h>
 #include <img_mgmt/img_mgmt.h>
+#include <img_mgmt/image.h>
 #include "../../../src/img_mgmt_priv.h"
 
 /**
@@ -105,6 +111,78 @@
     return fa_id;
 }
 
+static int
+img_mgmt_find_best_area_id(void)
+{
+    struct image_version ver;
+    int best = -1;
+    int i;
+    int rc;
+
+    for (i = 0; i < 2; i++) {
+        rc = img_mgmt_read_info(i, &ver, NULL, NULL);
+        if (rc < 0) {
+            continue;
+        }
+        if (rc == 0) {
+            /* Image in slot is ok. */
+            if (img_mgmt_slot_in_use(i)) {
+                /* Slot is in use; can't use this. */
+                continue;
+            } else {
+                /*
+                 * Not active slot, but image is ok. Use it if there are
+                 * no better candidates.
+                 */
+                best = i;
+            }
+            continue;
+        }
+        best = i;
+        break;
+    }
+    if (best >= 0) {
+        best = zephyr_img_mgmt_flash_area_id(best);
+    }
+    return best;
+}
+
+/**
+ * Compares two image version numbers in a semver-compatible way.
+ *
+ * @param a                     The first version to compare.
+ * @param b                     The second version to compare.
+ *
+ * @return                      -1 if a < b
+ * @return                       0 if a = b
+ * @return                       1 if a > b
+ */
+static int
+img_mgmt_vercmp(const struct image_version *a, const struct image_version *b)
+{
+    if (a->iv_major < b->iv_major) {
+        return -1;
+    } else if (a->iv_major > b->iv_major) {
+        return 1;
+    }
+
+    if (a->iv_minor < b->iv_minor) {
+        return -1;
+    } else if (a->iv_minor > b->iv_minor) {
+        return 1;
+    }
+
+    if (a->iv_revision < b->iv_revision) {
+        return -1;
+    } else if (a->iv_revision > b->iv_revision) {
+        return 1;
+    }
+
+    /* Note: For semver compatibility, don't compare the 32-bit build num. */
+
+    return 0;
+}
+
 int
 img_mgmt_impl_erase_slot(void)
 {
@@ -166,14 +244,14 @@
 
     rc = flash_area_open(zephyr_img_mgmt_flash_area_id(slot), &fa);
     if (rc != 0) {
-        return MGMT_ERR_EUNKNOWN;
+      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 MGMT_ERR_EUNKNOWN;
     }
 
     return 0;
@@ -235,6 +313,34 @@
 }
 
 int
+img_mgmt_impl_erase_image_data(unsigned int off, unsigned int num_bytes)
+{
+    const struct flash_area *fa;
+    int rc;
+
+    rc = flash_area_open(DT_FLASH_AREA_IMAGE_1_ID, &fa);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    rc = flash_area_erase(fa, off, num_bytes);
+    flash_area_close(fa);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    return 0;
+}
+
+#if IMG_MGMT_LAZY_ERASE
+int img_mgmt_impl_erase_if_needed(uint32_t off, uint32_t len)
+{
+    /* This is done internally to the flash_img API. */
+    return 0;
+}
+#endif
+
+int
 img_mgmt_impl_swap_type(void)
 {
     switch (mcuboot_swap_type()) {
@@ -251,3 +357,148 @@
         return IMG_MGMT_SWAP_TYPE_NONE;
     }
 }
+
+/**
+ * Verifies an upload request and indicates the actions that should be taken
+ * during processing of the request.  This is a "read only" function in the
+ * sense that it doesn't write anything to flash and doesn't modify any global
+ * variables.
+ *
+ * @param req                   The upload request to inspect.
+ * @param action                On success, gets populated with information
+ *                                  about how to process the request.
+ *
+ * @return                      0 if processing should occur;
+ *                              A MGMT_ERR code if an error response should be
+ *                                  sent instead.
+ */
+int
+img_mgmt_impl_upload_inspect(const struct img_mgmt_upload_req *req,
+                             struct img_mgmt_upload_action *action,
+                             const char **errstr)
+{
+    const struct image_header *hdr;
+    const struct flash_area *fa;
+    struct image_version cur_ver;
+    uint8_t rem_bytes;
+    bool empty;
+    int rc;
+
+    memset(action, 0, sizeof *action);
+
+    if (req->off == -1) {
+        /* Request did not include an `off` field. */
+        *errstr = img_mgmt_err_str_hdr_malformed;
+        return MGMT_ERR_EINVAL;
+    }
+
+    if (req->off == 0) {
+        /* First upload chunk. */
+        if (req->data_len < sizeof(struct image_header)) {
+            /*
+             * Image header is the first thing in the image.
+             */
+            *errstr = img_mgmt_err_str_hdr_malformed;
+            return MGMT_ERR_EINVAL;
+        }
+
+        if (req->size == -1) {
+            /* Request did not include a `len` field. */
+            *errstr = img_mgmt_err_str_hdr_malformed;
+            return MGMT_ERR_EINVAL;
+        }
+        action->size = req->size;
+
+        hdr = (struct image_header *)req->img_data;
+        if (hdr->ih_magic != IMAGE_MAGIC) {
+            *errstr = img_mgmt_err_str_magic_mismatch;
+            return MGMT_ERR_EINVAL;
+        }
+
+        if (req->data_sha_len > IMG_MGMT_DATA_SHA_LEN) {
+            return MGMT_ERR_EINVAL;
+        }
+
+        /*
+         * If request includes proper data hash we can check whether there is
+         * upload in progress (interrupted due to e.g. link disconnection) with
+         * the same data hash so we can just resume it by simply including
+         * current upload offset in response.
+         */
+        if ((req->data_sha_len > 0) && (g_img_mgmt_state.area_id != -1)) {
+            if ((g_img_mgmt_state.data_sha_len == req->data_sha_len) &&
+                            !memcmp(g_img_mgmt_state.data_sha, req->data_sha,
+                                                        req->data_sha_len)) {
+                return 0;
+            }
+        }
+
+        action->area_id = img_mgmt_find_best_area_id();
+        if (action->area_id < 0) {
+            /* No slot where to upload! */
+            *errstr = img_mgmt_err_str_no_slot;
+            return MGMT_ERR_ENOMEM;
+        }
+
+        if (req->upgrade) {
+            /* User specified upgrade-only.  Make sure new image version is
+             * greater than that of the currently running image.
+             */
+            rc = img_mgmt_my_version(&cur_ver);
+            if (rc != 0) {
+                return MGMT_ERR_EUNKNOWN;
+            }
+
+            if (img_mgmt_vercmp(&cur_ver, &hdr->ih_ver) >= 0) {
+                *errstr = img_mgmt_err_str_downgrade;
+                return MGMT_ERR_EBADSTATE;
+            }
+        }
+
+#if IMG_MGMT_LAZY_ERASE
+        (void) empty;
+#else
+        rc = zephyr_img_mgmt_flash_check_empty(action->area_id, &empty);
+        if (rc) {
+            return MGMT_ERR_EUNKNOWN;
+        }
+
+        action->erase = !empty;
+#endif
+    } else {
+        /* Continuation of upload. */
+        action->area_id = g_img_mgmt_state.area_id;
+        action->size = g_img_mgmt_state.size;
+
+        if (req->off != g_img_mgmt_state.off) {
+            /*
+             * Invalid offset. Drop the data, and respond with the offset we're
+             * expecting data for.
+             */
+            return 0;
+        }
+    }
+
+    /* Calculate size of flash write. */
+    action->write_bytes = req->data_len;
+    if (req->off + req->data_len < action->size) {
+        /*
+         * Respect flash write alignment if not in the last block
+         */
+        rc = flash_area_open(action->area_id, &fa);
+        if (rc) {
+            *errstr = img_mgmt_err_str_flash_open_failed;
+            return MGMT_ERR_EUNKNOWN;
+        }
+
+        rem_bytes = req->data_len % flash_area_align(fa);
+        flash_area_close(fa);
+
+        if (rem_bytes) {
+            action->write_bytes -= rem_bytes;
+        }
+    }
+
+    action->proceed = true;
+    return 0;
+}
diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt_log.c b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt_log.c
new file mode 100644
index 0000000..2155e66
--- /dev/null
+++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt_log.c
@@ -0,0 +1,90 @@
+/*
+ * 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 <zephyr.h>
+#include <img_mgmt/img_mgmt.h>
+/**
+ * Log event types (all events are CBOR-encoded):
+ *
+ * upstart:
+ *     When: upon receiving an upload request with an offset of 0.
+ *     Structure:
+ *     {
+ *         "ev": "upstart",
+ *         "rc": <mgmt-error-code (int)>
+ *     }
+ *
+ * updone:
+ *     When: upon receiving an upload request containing the final chunk of an
+ *           image OR a failed upload request with a non-zero offset.
+ *     Structure:
+ *     {
+ *         "ev": "updone",
+ *         "rc": <mgmt-error-code (int)>
+ *         "hs": <image-hash (byte-string)> (only present on success)
+ *     }
+ *
+ * pend:
+ *     When: upon receiving a non-permanent `set-pending` request.
+ *     Structure:
+ *     {
+ *         "ev": "pend",
+ *         "rc": <mgmt-error-code (int)>,
+ *         "hs": <image-hash (byte-string)>
+ *     }
+ *
+ * conf:
+ *     When: upon receiving a `confirm` request OR a permanent `set-pending`
+ *           request.
+ *     Structure:
+ *     {
+ *         "ev": "conf",
+ *         "rc": <mgmt-error-code (int)>,
+ *         "hs": <image-hash (byte-string)> (only present for `set-pending`)
+ *     }
+ */
+
+#define IMG_MGMT_LOG_EV_UPSTART   "upstart"
+#define IMG_MGMT_LOG_EV_UPDONE    "updone"
+#define IMG_MGMT_LOG_EV_PEND      "pend"
+#define IMG_MGMT_LOG_EV_CONF      "conf"
+
+int
+img_mgmt_impl_log_upload_start(int status)
+{
+    return 0;
+}
+
+int
+img_mgmt_impl_log_upload_done(int status, const uint8_t *hash)
+{
+    return 0;
+}
+
+int
+img_mgmt_impl_log_pending(int status, const uint8_t *hash)
+{
+    return 0;
+}
+
+int
+img_mgmt_impl_log_confirm(int status, const uint8_t *hash)
+{
+    return 0;
+}
diff --git a/cmd/img_mgmt/src/img_mgmt.c b/cmd/img_mgmt/src/img_mgmt.c
index b994cae..a8cfd56 100644
--- a/cmd/img_mgmt/src/img_mgmt.c
+++ b/cmd/img_mgmt/src/img_mgmt.c
@@ -109,10 +109,10 @@
                    uint32_t *flags)
 {
 
-#if MYNEWT_VAL(IMG_MGMT_DUMMY_HDR)
+#if IMG_MGMT_DUMMY_HDR
     uint8_t dummy_hash[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
                             0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77};
- 
+
     if (!hash && !ver && !flags) {
         return 0;
     }
@@ -581,7 +581,7 @@
 int
 img_mgmt_my_version(struct image_version *ver)
 {
-    return img_mgmt_read_info(boot_current_slot, ver, NULL, NULL);
+    return img_mgmt_read_info(IMG_MGMT_BOOT_CURR_SLOT, ver, NULL, NULL);
 }
 
 void
diff --git a/cmd/img_mgmt/src/img_mgmt_state.c b/cmd/img_mgmt/src/img_mgmt_state.c
index 5998ada..ffbdd8e 100644
--- a/cmd/img_mgmt/src/img_mgmt_state.c
+++ b/cmd/img_mgmt/src/img_mgmt_state.c
@@ -18,6 +18,7 @@
  */
 
 #include <assert.h>
+
 #include "tinycbor/cbor.h"
 #include "cborattr/cborattr.h"
 #include "mgmt/mgmt.h"
diff --git a/cmd/log_mgmt/CMakeLists.txt b/cmd/log_mgmt/CMakeLists.txt
index 7d72dcd..eeb4e40 100644
--- a/cmd/log_mgmt/CMakeLists.txt
+++ b/cmd/log_mgmt/CMakeLists.txt
@@ -1,4 +1,5 @@
-target_include_directories(MCUMGR INTERFACE 
+if(CONFIG_MCUMGR)
+target_include_directories(MCUMGR INTERFACE
     include
 )
 
@@ -7,3 +8,4 @@
     cmd/log_mgmt/src/log_mgmt.c
     cmd/log_mgmt/src/stubs.c
 )
+endif
diff --git a/cmd/log_mgmt/Kconfig b/cmd/log_mgmt/Kconfig
deleted file mode 100644
index bb59dfd..0000000
--- a/cmd/log_mgmt/Kconfig
+++ /dev/null
@@ -1,59 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE log
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this log
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this log 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.
-
-menuconfig MCUMGR_CMD_LOG_MGMT
-    bool "Enable mcumgr handlers for log management"
-    help
-      Enables mcumgr handlers for log management
-
-if MCUMGR_CMD_LOG_MGMT
-config LOG_MGMT_MAX_RSP_LEN
-    int "Maximum MCUmgr response len for log downloads"
-    default 512
-    help
-      Limits the maximum response len for log downloads, in bytes.
-
-config LOG_MGMT_NAME_LEN
-    int "Maximum log name length"
-    default 64
-    help
-      Limits the maximum length of log names, in bytes.  If a log's name length
-      exceeds this number, it gets truncated in management responses. A buffer
-      of this size gets allocated on the stack during handling of all log
-      management commands.
-
-config LOG_MGMT_CHUNK_LEN
-    int "Maximum log chunk length"
-    default 128
-    help
-      Limits the maximum length of log entry bodies chunks, so, every log entry gets
-      read in chunks upto a point where the entire entry is read. Also, a buffer gets
-      allocated on the stack with this size.
-
-config LOG_MGMT_READ_WATERMARK_UPDATE
-    bool "Enable reading of log watermark update"
-    help
-      Enables reading of log watermark update 
-
-config LOG_GLOBAL_IDX
-    bool "Enable global index over all logs"
-    default false
-    help
-      Log entries indices are coming from same number space. Otherwise
-      every log has their own indexing.
-
-endif
diff --git a/cmd/os_mgmt/port/zephyr/src/zephyr_os_mgmt.c b/cmd/os_mgmt/port/zephyr/src/zephyr_os_mgmt.c
index eae1afb..37f3d17 100644
--- a/cmd/os_mgmt/port/zephyr/src/zephyr_os_mgmt.c
+++ b/cmd/os_mgmt/port/zephyr/src/zephyr_os_mgmt.c
@@ -18,7 +18,7 @@
  */
 
 #include <zephyr.h>
-#include <misc/reboot.h>
+#include <power/reboot.h>
 #include <debug/object_tracing.h>
 #include <kernel_structs.h>
 #include <mgmt/mgmt.h>
diff --git a/cmd/os_mgmt/src/os_mgmt.c b/cmd/os_mgmt/src/os_mgmt.c
index 9b17e0b..5a10887 100644
--- a/cmd/os_mgmt/src/os_mgmt.c
+++ b/cmd/os_mgmt/src/os_mgmt.c
@@ -19,6 +19,7 @@
 
 #include <assert.h>
 #include <string.h>
+
 #include "tinycbor/cbor.h"
 #include "cborattr/cborattr.h"
 #include "mgmt/mgmt.h"
diff --git a/cmd/stat_mgmt/port/zephyr/src/zephyr_stat_mgmt.c b/cmd/stat_mgmt/port/zephyr/src/zephyr_stat_mgmt.c
index 22654f8..7681d0b 100644
--- a/cmd/stat_mgmt/port/zephyr/src/zephyr_stat_mgmt.c
+++ b/cmd/stat_mgmt/port/zephyr/src/zephyr_stat_mgmt.c
@@ -17,8 +17,8 @@
  * under the License.
  */
 
-#include <misc/util.h>
-#include <stats.h>
+#include <sys/util.h>
+#include <stats/stats.h>
 #include <mgmt/mgmt.h>
 #include <stat_mgmt/stat_mgmt.h>
 #include <stat_mgmt/stat_mgmt_impl.h>
diff --git a/mgmt/src/mgmt.c b/mgmt/src/mgmt.c
index 351f353..ba366a7 100644
--- a/mgmt/src/mgmt.c
+++ b/mgmt/src/mgmt.c
@@ -18,6 +18,7 @@
  */
 
 #include <string.h>
+
 #include "tinycbor/cbor.h"
 #include "mgmt/endian.h"
 #include "mgmt/mgmt.h"
diff --git a/samples/smp_svr/zephyr/CMakeLists.txt b/samples/smp_svr/zephyr/CMakeLists.txt
index 80f09f0..723108d 100644
--- a/samples/smp_svr/zephyr/CMakeLists.txt
+++ b/samples/smp_svr/zephyr/CMakeLists.txt
@@ -7,6 +7,8 @@
 # This provides a basic application structure suitable for communication using
 # mcumgr.  It can be used as a starting point for new applications.
 
+cmake_minimum_required(VERSION 3.14)
+
 # Zephyr uses Device Tree (DT) to describe some board hardware configuration.
 #
 # See the Zephyr documentation for more information on DT:
diff --git a/samples/smp_svr/zephyr/prj.conf b/samples/smp_svr/zephyr/prj.conf
index bdca171..dfa64c1 100644
--- a/samples/smp_svr/zephyr/prj.conf
+++ b/samples/smp_svr/zephyr/prj.conf
@@ -17,7 +17,7 @@
 #CONFIG_MCUMGR_SMP_UART=y
 
 # Bluetooth support requires a net_buf user_data size >= 7.
-CONFIG_NET_BUF_USER_DATA_SIZE=7
+CONFIG_NET_BUF_USER_DATA_SIZE=8
 
 # Enable flash operations.
 CONFIG_FLASH=y
diff --git a/samples/smp_svr/zephyr/src/main.c b/samples/smp_svr/zephyr/src/main.c
index bfb325a..4a21974 100644
--- a/samples/smp_svr/zephyr/src/main.c
+++ b/samples/smp_svr/zephyr/src/main.c
@@ -11,13 +11,14 @@
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/conn.h>
 #include <bluetooth/gatt.h>
-#include <stats.h>
+#include <stats/stats.h>
 #include <mgmt/smp_bt.h>
 #include <mgmt/buf.h>
 
 #ifdef CONFIG_MCUMGR_CMD_FS_MGMT
 #include <device.h>
-#include <fs.h>
+#include <fs/fs.h>
+#include <nffs/nffs.h>
 #include "fs_mgmt/fs_mgmt.h"
 #endif
 #ifdef CONFIG_MCUMGR_CMD_OS_MGMT
diff --git a/smp/src/smp.c b/smp/src/smp.c
index fae40aa..5ae0fc4 100644
--- a/smp/src/smp.c
+++ b/smp/src/smp.c
@@ -22,10 +22,10 @@
 #include <assert.h>
 #include <string.h>
 
+#include "tinycbor/cbor.h"
 #include "mgmt/endian.h"
 #include "mgmt/mgmt.h"
 #include "smp/smp.h"
-#include "tinycbor/cbor.h"
 
 static int
 smp_align4(int x)