You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2020/03/23 16:42:31 UTC

[mynewt-mcumgr] branch master updated: fs_mgmt: Fix file download for Zephyr

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

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


The following commit(s) were added to refs/heads/master by this push:
     new c4919da  fs_mgmt: Fix file download for Zephyr
c4919da is described below

commit c4919dab456ba383431b1936a6fd7524486f9718
Author: Dominik Ermel <do...@nordicsemi.no>
AuthorDate: Thu Feb 20 15:39:35 2020 +0000

    fs_mgmt: Fix file download for Zephyr
    
    File download worked only for files small enough to fit into small mcumgr
    buffer, dedicated for CBOR encoding. Because file read buffer size is
    independent from the size of CBOR encoding buffer and part of CBOR buffer
    is used outside of control of download backend, it could happen that the
    chunk read could not fit into actual free space left within CBOR buffer,
    automatically failing the download.
    
    Signed-off-by: Dominik Ermel <do...@nordicsemi.no>
---
 cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_config.h | 41 +++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_config.h b/cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_config.h
index deaec8a..2fd7ae0 100644
--- a/cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_config.h
+++ b/cmd/fs_mgmt/include/fs_mgmt/fs_mgmt_config.h
@@ -30,7 +30,46 @@
 
 #elif defined __ZEPHYR__
 
-#define FS_MGMT_DL_CHUNK_SIZE   CONFIG_FS_MGMT_DL_CHUNK_SIZE
+
+#define MCUMGR_BUF_SIZE         CONFIG_MCUMGR_BUF_SIZE
+/* File chunk needs to fit into MCUGMR_BUF_SZIE with all required headers
+ * and other data fields; following information takes space off the
+ * MCUMGR_BUF_SIZE, N is CONFIG_FS_MGMT_MAX_OFFSET_LEN
+ *  MGMT_HDR_SIZE - header that is placed in front of buffer and not
+ *    visible for cbod encoder (see smp_handle_single_req);
+ *  9 + 1 -- bytes taken by definition of CBOR undefined length map and map
+ *    terminator (break) character;
+ *  1 + strlen("off") + [1, N] -- CBOR encoded pair of "off" marker and
+ *    offset of the chunk within the file;
+ *  1 + strlen("data") + [1, N] -- CBOR encoded "data" marker; this marker
+ *    will be followed by file chunk of size FS_MGMT_DL_CHUNK_SIZE
+ *  1 + strlen("rc") + 1 -- status code of operation;
+ *  1 + strlen("len") + [1, N] -- CBOR encoded "len" marker and complete
+ *    length of a file; this is only sent once when "off" is 0;
+ *
+ * FS_MGMT_DL_CHUNK_SIZE is calculated with most pessimistic estimations,
+ * that is with headers fields taking most space, i.e. N bytes.
+ */
+//#define FS_MGMT_DL_CHUNK_SIZE   CONFIG_FS_MGMT_DL_CHUNK_SIZE
+#define CBOR_AND_OTHER_HDR \
+	((9 + 1) + \
+	 (1 + 3 + CONFIG_FS_MGMT_MAX_OFFSET_LEN) + \
+	 (1 + 4 + CONFIG_FS_MGMT_MAX_OFFSET_LEN) + \
+	 (1 + 2 + 1) + \
+	 (1 + 3 + CONFIG_FS_MGMT_MAX_OFFSET_LEN))
+
+#if defined(CONFIG_FS_MGMT_DL_CHUNK_SIZE_LIMIT)
+#if (CONFIG_FS_MGMT_DL_CHUNK_SIZE + CBOR_AND_OTHER_HDR) > MCUMGR_BUF_SIZE
+#warning FS_MGMT_DL_CHUNK_SIZE too big, rounding it down.
+#else
+#define FS_MGMT_DL_CHUNK_SIZE (CONFIG_FS_MGMT_DL_CHUNK_SIZE)
+#endif
+#endif
+
+#if !defined(FS_MGMT_DL_CHUNK_SIZE)
+#define FS_MGMT_DL_CHUNK_SIZE (MCUMGR_BUF_SIZE - CBOR_AND_OTHER_HDR)
+#endif
+
 #define FS_MGMT_PATH_SIZE       CONFIG_FS_MGMT_PATH_SIZE
 #define FS_MGMT_UL_CHUNK_SIZE   CONFIG_FS_MGMT_UL_CHUNK_SIZE