Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop dd68ace87 -> 566a80030


imgmgr - image state

Some additional changes:
    * Remove obsolete split status newtmgr command
    * Always clear split/status config setting on "confirm" if only slot
      0 is active.
    * When checking split-matching state, if non-matching, clear
      split/status config setting.


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/566a8003
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/566a8003
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/566a8003

Branch: refs/heads/develop
Commit: 566a8003027077bceccbb5789ada8b6f659af1d6
Parents: dd68ace
Author: Christopher Collins <ccoll...@apache.org>
Authored: Thu Oct 13 15:09:08 2016 -0700
Committer: Christopher Collins <ccoll...@apache.org>
Committed: Thu Oct 13 15:09:08 2016 -0700

----------------------------------------------------------------------
 boot/split/src/split.c         |   8 ++-
 boot/split/src/split_netmgr.c  | 131 ------------------------------------
 mgmt/imgmgr/src/imgmgr_state.c |  13 ++--
 mgmt/mgmt/include/mgmt/mgmt.h  |  15 +++--
 4 files changed, 20 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/566a8003/boot/split/src/split.c
----------------------------------------------------------------------
diff --git a/boot/split/src/split.c b/boot/split/src/split.c
index 7194874..62cca29 100644
--- a/boot/split/src/split.c
+++ b/boot/split/src/split.c
@@ -39,9 +39,6 @@ split_app_init(void)
 
     rc = split_conf_init();
     assert(rc == 0);
-
-    rc = split_nmgr_register();
-    assert(rc == 0);
 }
 
 split_status_t
@@ -135,5 +132,10 @@ split_app_go(void **entry, int toboot)
     }
 
     rc = split_go(LOADER_IMAGE_SLOT, SPLIT_IMAGE_SLOT, entry);
+    if (rc != 0) {
+        /* Images don't match; clear split status. */
+        split_write_split(SPLIT_MODE_LOADER);
+    }
+
     return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/566a8003/boot/split/src/split_netmgr.c
----------------------------------------------------------------------
diff --git a/boot/split/src/split_netmgr.c b/boot/split/src/split_netmgr.c
deleted file mode 100644
index ae22554..0000000
--- a/boot/split/src/split_netmgr.c
+++ /dev/null
@@ -1,131 +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.
- */
-
-#include <tinycbor/cbor.h>
-#include <cborattr/cborattr.h>
-#include <mgmt/mgmt.h>
-#include <bootutil/bootutil_misc.h>
-#include <bootutil/image.h>
-#include <split/split.h>
-#include <split_priv.h>
-
-
-static int imgr_splitapp_read(struct mgmt_cbuf *cb);
-static int imgr_splitapp_write(struct mgmt_cbuf *cb);
-
-static const struct mgmt_handler split_nmgr_handlers[] = {
-    [SPLIT_NMGR_OP_SPLIT] = {
-        .mh_read = imgr_splitapp_read,
-        .mh_write = imgr_splitapp_write
-    },
-};
-
-static struct mgmt_group split_nmgr_group = {
-    .mg_handlers = (struct mgmt_handler *)split_nmgr_handlers,
-    .mg_handlers_count =
-        sizeof(split_nmgr_handlers) / sizeof(split_nmgr_handlers[0]),
-    .mg_group_id = MGMT_GROUP_ID_SPLIT,
-};
-
-int
-split_nmgr_register(void)
-{
-    int rc;
-    rc = mgmt_group_register(&split_nmgr_group);
-    return (rc);
-}
-
-int
-imgr_splitapp_read(struct mgmt_cbuf *cb)
-{
-    int x;
-    CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
-
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-
-    x = split_mode_get();
-    g_err |= cbor_encode_text_stringz(&rsp, "splitMode");
-    g_err |= cbor_encode_int(&rsp, x);
-
-    x = split_check_status();
-    g_err |= cbor_encode_text_stringz(&rsp, "splitStatus");
-    g_err |= cbor_encode_int(&rsp, x);
-
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-
-    g_err |= cbor_encoder_close_container(penc, &rsp);
-
-    return 0;
-}
-
-int
-imgr_splitapp_write(struct mgmt_cbuf *cb)
-{
-    long long int split_mode;
-    long long int send_split_status;  /* ignored */
-    long long int sent_rc; /* ignored */
-    const struct cbor_attr_t split_write_attr[4] = {
-        [0] =
-        {
-            .attribute = "splitMode",
-            .type = CborAttrIntegerType,
-            .addr.integer = &split_mode,
-            .nodefault = true,
-        },
-        [1] =
-        {
-            .attribute = "splitStatus",
-            .type = CborAttrIntegerType,
-            .addr.integer = &send_split_status,
-            .nodefault = true,
-        },
-        [2] =
-        {
-            .attribute = "rc",
-            .type = CborAttrIntegerType,
-            .addr.integer = &sent_rc,
-            .nodefault = true,
-        },
-        [3] =
-        {
-            .attribute = NULL
-        }
-    };
-    int rc;
-
-    rc = cbor_read_object(&cb->it, split_write_attr);
-    if (rc) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
-    }
-
-    rc = split_write_split(split_mode);
-    if (rc) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
-    }
-
-    rc = MGMT_ERR_EOK;
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-    return 0;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/566a8003/mgmt/imgmgr/src/imgmgr_state.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_state.c b/mgmt/imgmgr/src/imgmgr_state.c
index 67551d7..3a6efdd 100644
--- a/mgmt/imgmgr/src/imgmgr_state.c
+++ b/mgmt/imgmgr/src/imgmgr_state.c
@@ -95,10 +95,6 @@ imgmgr_state_flags(int query_slot)
         break;
     }
 
-    /* An image cannot be both pending and confirmed. */
-    assert(!(flags & IMGMGR_STATE_F_PENDING) ||
-           !(flags & IMGMGR_STATE_F_CONFIRMED));
-
     return flags;
 }
 
@@ -137,7 +133,7 @@ imgmgr_state_test_slot(int slot)
     if (state_flags & IMGMGR_STATE_F_CONFIRMED &&
         (slot != 0 || !split_app_active)) {
 
-        return MGMT_ERR_EINVAL;
+        return MGMT_ERR_EBADSTATE;
     }
 
     rc = imgr_read_info(slot, NULL, NULL, &image_flags);
@@ -175,7 +171,7 @@ imgmgr_state_confirm(void)
 
     /* Confirm disallowed if a test is pending. */
     if (imgmgr_state_any_pending()) {
-        return MGMT_ERR_EINVAL;
+        return MGMT_ERR_EBADSTATE;
     }
 
     /* Confirm the unified image or loader in slot 0. */
@@ -190,6 +186,11 @@ imgmgr_state_confirm(void)
         if (rc != 0) {
             return MGMT_ERR_EUNKNOWN;
         }
+    } else {
+        rc = split_write_split(SPLIT_MODE_LOADER);
+        if (rc != 0) {
+            return MGMT_ERR_EUNKNOWN;
+        }
     }
 
     return 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/566a8003/mgmt/mgmt/include/mgmt/mgmt.h
----------------------------------------------------------------------
diff --git a/mgmt/mgmt/include/mgmt/mgmt.h b/mgmt/mgmt/include/mgmt/mgmt.h
index cd5c4f5..7d74d1b 100644
--- a/mgmt/mgmt/include/mgmt/mgmt.h
+++ b/mgmt/mgmt/include/mgmt/mgmt.h
@@ -52,13 +52,14 @@ extern "C" {
 /**
  * Newtmgr error codes
  */
-#define MGMT_ERR_EOK      (0)
-#define MGMT_ERR_EUNKNOWN (1)
-#define MGMT_ERR_ENOMEM   (2)
-#define MGMT_ERR_EINVAL   (3)
-#define MGMT_ERR_ETIMEOUT (4)
-#define MGMT_ERR_ENOENT   (5)
-#define MGMT_ERR_EPERUSER (256)
+#define MGMT_ERR_EOK        (0)
+#define MGMT_ERR_EUNKNOWN   (1)
+#define MGMT_ERR_ENOMEM     (2)
+#define MGMT_ERR_EINVAL     (3)
+#define MGMT_ERR_ETIMEOUT   (4)
+#define MGMT_ERR_ENOENT     (5)
+#define MGMT_ERR_EBADSTATE  (6)     /* Current state disallows command. */
+#define MGMT_ERR_EPERUSER   (256)
 
 struct mgmt_cbuf;
 

Reply via email to