You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2017/03/24 23:15:38 UTC

[16/50] [abbrv] incubator-mynewt-core git commit: MYNEWT-669 NMP: Make max chunk size configurable.

MYNEWT-669 NMP: Make max chunk size configurable.

Currently, the largest image or file chunk that a Mynewt device can
receive is hardcoded at 400 bytes. Furthermore, the largets CBOR
attribute that we can decode is 300 bytes long.This is not great because
this number is independent of the transport MTU, so the client has no
way of knowing the limit.

The fix is to create three new compile-time settings:

    * CBORATTR_MAX_SIZE
    * FS_UPLOAD_MAX_CHUNK_SIZE
    * IMGMGR_MAX_CHUNK_SIZE

and set them to 512 by default. This value is large enough to
accommodate full-size BLE packets.

This is still not a perfect solution because these values are not tied
to the MTU in any way. One way to truly solve this would be to have an
"NMP MTU" that the client can discover. That would be a pretty big
change.


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

Branch: refs/heads/nrf_cputime
Commit: 78946572ddbf9489b47206ab42bb9bc348b7f008
Parents: fd20bc9
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Mar 14 18:18:07 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Mar 14 19:13:48 2017 -0700

----------------------------------------------------------------------
 encoding/cborattr/include/cborattr/cborattr.h |  3 ---
 encoding/cborattr/src/cborattr.c              |  5 +++--
 encoding/cborattr/syscfg.yml                  | 24 ++++++++++++++++++++++
 fs/fs/include/fs/fs.h                         |  1 -
 fs/fs/src/fs_nmgr.c                           |  4 ++--
 fs/fs/syscfg.yml                              |  6 ++++++
 mgmt/imgmgr/include/imgmgr/imgmgr.h           |  1 -
 mgmt/imgmgr/src/imgmgr.c                      |  2 +-
 mgmt/imgmgr/src/imgmgr_coredump.c             |  2 +-
 mgmt/imgmgr/syscfg.yml                        |  5 +++++
 10 files changed, 42 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78946572/encoding/cborattr/include/cborattr/cborattr.h
----------------------------------------------------------------------
diff --git a/encoding/cborattr/include/cborattr/cborattr.h b/encoding/cborattr/include/cborattr/cborattr.h
index 7142df6..9e69ca9 100644
--- a/encoding/cborattr/include/cborattr/cborattr.h
+++ b/encoding/cborattr/include/cborattr/cborattr.h
@@ -38,9 +38,6 @@ extern "C" {
  * is a key/value pair.  keys are always text strings, but values can be
  * many different things (enumerated below) */
 
-    /* maximum size of the string attribute name for this decoder */
-#define CBOR_ATTR_MAX (128)
-
 typedef enum CborAttrType {
     CborAttrIntegerType = 1,
     CborAttrUnsignedIntegerType,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78946572/encoding/cborattr/src/cborattr.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/src/cborattr.c b/encoding/cborattr/src/cborattr.c
index e78c8f9..d2e731a 100644
--- a/encoding/cborattr/src/cborattr.c
+++ b/encoding/cborattr/src/cborattr.c
@@ -17,6 +17,7 @@
  * under the License.
  */
 
+#include <syscfg/syscfg.h>
 #include <cborattr/cborattr.h>
 #include <tinycbor/cbor.h>
 #include <tinycbor/cbor_buf_reader.h>
@@ -139,7 +140,7 @@ cbor_internal_read_object(CborValue *root_value,
                           int offset)
 {
     const struct cbor_attr_t *cursor, *best_match;
-    char attrbuf[CBOR_ATTR_MAX + 1];
+    char attrbuf[MYNEWT_VAL(CBORATTR_MAX_SIZE) + 1];
     void *lptr;
     CborValue cur_value;
     CborError err = 0;
@@ -189,7 +190,7 @@ cbor_internal_read_object(CborValue *root_value,
         /* get the attribute */
         if (cbor_value_is_text_string(&cur_value)) {
             if (cbor_value_calculate_string_length(&cur_value, &len) == 0) {
-                if (len > CBOR_ATTR_MAX) {
+                if (len > MYNEWT_VAL(CBORATTR_MAX_SIZE)) {
                     err |= CborErrorDataTooLarge;
                     goto err_return;
                 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78946572/encoding/cborattr/syscfg.yml
----------------------------------------------------------------------
diff --git a/encoding/cborattr/syscfg.yml b/encoding/cborattr/syscfg.yml
new file mode 100644
index 0000000..cc93c26
--- /dev/null
+++ b/encoding/cborattr/syscfg.yml
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Package: mgmt/imgmgr
+
+syscfg.defs:
+    CBORATTR_MAX_SIZE:
+        description: 'The maximum size of a CBOR attribute during decoding'
+        value: 512

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78946572/fs/fs/include/fs/fs.h
----------------------------------------------------------------------
diff --git a/fs/fs/include/fs/fs.h b/fs/fs/include/fs/fs.h
index ce5da94..7fb85ec 100644
--- a/fs/fs/include/fs/fs.h
+++ b/fs/fs/include/fs/fs.h
@@ -81,7 +81,6 @@ int fs_dirent_is_dir(const struct fs_dirent *);
 
 #define FS_NMGR_ID_FILE     0
 
-#define FS_NMGR_MAX_MSG     400
 #define FS_NMGR_MAX_NAME    64
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78946572/fs/fs/src/fs_nmgr.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_nmgr.c b/fs/fs/src/fs_nmgr.c
index bd87697..15dd8bd 100644
--- a/fs/fs/src/fs_nmgr.c
+++ b/fs/fs/src/fs_nmgr.c
@@ -71,7 +71,7 @@ fs_nmgr_file_download(struct mgmt_cbuf *cb)
 {
     long long unsigned int off = UINT_MAX;
     char tmp_str[FS_NMGR_MAX_NAME + 1];
-    uint8_t img_data[FS_NMGR_MAX_MSG];
+    uint8_t img_data[MYNEWT_VAL(FS_UPLOAD_MAX_CHUNK_SIZE)];
     const struct cbor_attr_t dload_attr[3] = {
         [0] = {
             .attribute = "off",
@@ -141,7 +141,7 @@ err_close:
 static int
 fs_nmgr_file_upload(struct mgmt_cbuf *cb)
 {
-    uint8_t img_data[FS_NMGR_MAX_MSG];
+    uint8_t img_data[MYNEWT_VAL(FS_UPLOAD_MAX_CHUNK_SIZE)];
     char file_name[FS_NMGR_MAX_NAME + 1];
     size_t img_len;
     long long unsigned int off = UINT_MAX;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78946572/fs/fs/syscfg.yml
----------------------------------------------------------------------
diff --git a/fs/fs/syscfg.yml b/fs/fs/syscfg.yml
index 3cf5a35..af9e4c3 100644
--- a/fs/fs/syscfg.yml
+++ b/fs/fs/syscfg.yml
@@ -28,3 +28,9 @@ syscfg.defs:
     FS_NMGR:
         description: 'Enables file system newtmgr commands.'
         value: 0
+
+    FS_UPLOAD_MAX_CHUNK_SIZE:
+        description: >
+            The maximum amount of file data that can fit in a
+            single NMP upload request
+        value: 512

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78946572/mgmt/imgmgr/include/imgmgr/imgmgr.h
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/include/imgmgr/imgmgr.h b/mgmt/imgmgr/include/imgmgr/imgmgr.h
index bae9a94..3fb3fb1 100644
--- a/mgmt/imgmgr/include/imgmgr/imgmgr.h
+++ b/mgmt/imgmgr/include/imgmgr/imgmgr.h
@@ -32,7 +32,6 @@ extern "C" {
 #define IMGMGR_NMGR_ID_CORELIST     3
 #define IMGMGR_NMGR_ID_CORELOAD     4
 
-#define IMGMGR_NMGR_MAX_MSG         400
 #define IMGMGR_NMGR_MAX_NAME		64
 #define IMGMGR_NMGR_MAX_VER         25  /* 255.255.65535.4294967295\0 */
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78946572/mgmt/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr.c b/mgmt/imgmgr/src/imgmgr.c
index 7b4431e..b6f0a4c 100644
--- a/mgmt/imgmgr/src/imgmgr.c
+++ b/mgmt/imgmgr/src/imgmgr.c
@@ -225,7 +225,7 @@ imgr_find_by_hash(uint8_t *find, struct image_version *ver)
 static int
 imgr_upload(struct mgmt_cbuf *cb)
 {
-    uint8_t img_data[IMGMGR_NMGR_MAX_MSG];
+    uint8_t img_data[MYNEWT_VAL(IMGMGR_MAX_CHUNK_SIZE)];
     long long unsigned int off = UINT_MAX;
     long long unsigned int size = UINT_MAX;
     size_t data_len = 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78946572/mgmt/imgmgr/src/imgmgr_coredump.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_coredump.c b/mgmt/imgmgr/src/imgmgr_coredump.c
index 48058c9..26b9ea0 100644
--- a/mgmt/imgmgr/src/imgmgr_coredump.c
+++ b/mgmt/imgmgr/src/imgmgr_coredump.c
@@ -76,7 +76,7 @@ imgr_core_load(struct mgmt_cbuf *cb)
     int rc;
     int sz;
     const struct flash_area *fa;
-    uint8_t data[IMGMGR_NMGR_MAX_MSG];
+    uint8_t data[MYNEWT_VAL(IMGMGR_MAX_CHUNK_SIZE)];
     struct coredump_header *hdr;
     CborError g_err = CborNoError;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78946572/mgmt/imgmgr/syscfg.yml
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/syscfg.yml b/mgmt/imgmgr/syscfg.yml
index da42801..4f3c95d 100644
--- a/mgmt/imgmgr/syscfg.yml
+++ b/mgmt/imgmgr/syscfg.yml
@@ -27,3 +27,8 @@ syscfg.defs:
         value: 0
         restrictions:
             - SHELL_TASK
+    IMGMGR_MAX_CHUNK_SIZE:
+        description: >
+            The maximum amount of image or core data that can fit in a
+            single NMP message
+        value: 512