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/04 03:01:19 UTC

[mynewt-mcumgr] 05/08: img - Mynewt port.

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 a889f74ce4a8876fd1cf2bea7c50bfa7672e0371
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Jan 3 12:12:40 2018 -0800

    img - Mynewt port.
---
 img/pkg.yml                      |  46 ++++++++++
 img/port/mynewt/pkg.yml          |  31 +++++++
 img/port/mynewt/src/mynewt_img.c | 191 +++++++++++++++++++++++++++++++++++++++
 img/syscfg.yml                   |  34 +++++++
 4 files changed, 302 insertions(+)

diff --git a/img/pkg.yml b/img/pkg.yml
new file mode 100644
index 0000000..351e3cf
--- /dev/null
+++ b/img/pkg.yml
@@ -0,0 +1,46 @@
+#
+# 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.
+#
+
+pkg.name: img
+pkg.description: Library for image uploading.
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+    - '@apache-mynewt-core/boot/split'
+    - '@apache-mynewt-core/encoding/base64'
+    - '@apache-mynewt-core/sys/flash_map'
+    - '@mynewt-mcumgr/mgmt'
+
+pkg.req_apis:
+    - newtmgr
+    - bootloader
+
+pkg.deps.IMG_FS:
+    - '@apache-mynewt-core/fs/fs'
+
+pkg.deps.IMG_COREDUMP:
+    - '@apache-mynewt-core/sys/coredump'
+
+pkg.deps.IMG_SHELL:
+    - '@apache-mynewt-core/sys/shell'
+
+pkg.init:
+    img_module_init: 500
diff --git a/img/port/mynewt/pkg.yml b/img/port/mynewt/pkg.yml
new file mode 100644
index 0000000..ecbc68f
--- /dev/null
+++ b/img/port/mynewt/pkg.yml
@@ -0,0 +1,31 @@
+#
+# 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.
+#
+
+pkg.name: img/port/mynewt
+pkg.description: XXX
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+    - '@apache-mynewt-core/boot/split'
+    - '@apache-mynewt-core/encoding/base64'
+    - '@apache-mynewt-core/sys/flash_map'
+    - '@mynewt-mcumgr/img'
+    - '@mynewt-mcumgr/mgmt'
diff --git a/img/port/mynewt/src/mynewt_img.c b/img/port/mynewt/src/mynewt_img.c
new file mode 100644
index 0000000..28d39f3
--- /dev/null
+++ b/img/port/mynewt/src/mynewt_img.c
@@ -0,0 +1,191 @@
+#include "sysinit/sysinit.h"
+
+int
+img_impl_erase_slot(void)
+{
+    const struct flash_area *fa;
+    bool empty;
+    int rc;
+
+    rc = flash_area_open(FLASH_AREA_IMAGE_1, &fa);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    rc = flash_area_is_empty(fa, &empty);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    if (!empty) {
+        rc = flash_area_erase(fa, 0, fa->fa_size);
+        if (rc != 0) {
+            return MGMT_ERR_EUNKNOWN;
+        }
+    }
+
+    return 0;
+}
+
+int
+img_impl_write_pending(int slot, bool permanent)
+{
+    uint32_t image_flags;
+    uint8_t state_flags;
+    int split_app_active;
+    int rc;
+
+    state_flags = imgmgr_state_flags(slot);
+    split_app_active = split_app_active_get();
+
+    /* 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 & IMGMGR_STATE_F_CONFIRMED &&
+        (slot != 0 || !split_app_active)) {
+
+        return MGMT_ERR_EBADSTATE;
+    }
+
+    rc = imgr_read_info(slot, NULL, NULL, &image_flags);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    if (!(image_flags & IMAGE_F_NON_BOOTABLE)) {
+        /* Unified image or loader. */
+        if (!split_app_active) {
+            /* No change in split status. */
+            rc = boot_set_pending(permanent);
+            if (rc != 0) {
+                return MGMT_ERR_EUNKNOWN;
+            }
+        } else {
+            /* Currently loader + app; testing loader-only. */
+            if (permanent) {
+                rc = split_write_split(SPLIT_MODE_LOADER);
+            } else {
+                rc = split_write_split(SPLIT_MODE_TEST_LOADER);
+            }
+            if (rc != 0) {
+                return MGMT_ERR_EUNKNOWN;
+            }
+        }
+    } else {
+        /* Testing split app. */
+        if (permanent) {
+            rc = split_write_split(SPLIT_MODE_APP);
+        } else {
+            rc = split_write_split(SPLIT_MODE_TEST_APP);
+        }
+        if (rc != 0) {
+            return MGMT_ERR_EUNKNOWN;
+        }
+    }
+
+    return 0;
+}
+
+int
+img_impl_write_confirmed(void)
+{
+    /* Confirm the unified image or loader in slot 0. */
+    rc = boot_set_confirmed();
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    /* If a split app in slot 1 is active, confirm it as well. */
+    if (split_app_active_get()) {
+        rc = split_write_split(SPLIT_MODE_APP);
+        if (rc != 0) {
+            return MGMT_ERR_EUNKNOWN;
+        }
+    } else {
+        rc = split_write_split(SPLIT_MODE_LOADER);
+        if (rc != 0) {
+            return MGMT_ERR_EUNKNOWN;
+        }
+    }
+
+    return 0;
+}
+
+int
+img_impl_read(int slot, unsigned int offset, void *dst,
+              unsigned int num_bytes)
+{
+    const struct flash_area *fa;
+    int area_id;
+    int rc;
+
+    area_id = flash_area_id_from_image_slot(image_slot);
+    rc = flash_area_open(area_id, &fa);
+    if (rc != 0) {
+        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 0;
+}
+
+int
+img_impl_write_image_data(unsigned int offset, const void *data,
+                          unsigned int num_bytes, bool last)
+{
+    const struct flash_area *fa;
+    int rc;
+
+    rc = flash_area_open(FLASH_AREA_IMAGE_1, &fa);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    rc = flash_area_write(fa, offset, data, num_bytes);
+    flash_area_close(fa);
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    return 0;
+}
+
+int
+img_impl_swap_type(void)
+{
+    switch (boot_swap_type()) {
+    case BOOT_SWAP_TYPE_NONE:
+        return IMG_SWAP_TYPE_NONE;
+    case BOOT_SWAP_TYPE_TEST:
+        return IMG_SWAP_TYPE_TEST;
+    case BOOT_SWAP_TYPE_PERM:
+        return IMG_SWAP_TYPE_PERM;
+    case BOOT_SWAP_TYPE_REVERT:
+        return IMG_SWAP_TYPE_REVERT;
+    default:
+        assert(0);
+        return IMG_SWAP_TYPE_NONE;
+    }
+}
+
+void
+img_module_init(void)
+{
+    int rc;
+
+    /* Ensure this function only gets called by sysinit. */
+    SYSINIT_ASSERT_ACTIVE();
+
+    rc = img_group_register();
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+#if MYNEWT_VAL(IMGMGR_CLI)
+    rc = imgr_cli_register();
+    SYSINIT_PANIC_ASSERT(rc == 0);
+#endif
+}
diff --git a/img/syscfg.yml b/img/syscfg.yml
new file mode 100644
index 0000000..4f3c95d
--- /dev/null
+++ b/img/syscfg.yml
@@ -0,0 +1,34 @@
+# 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:
+    IMGMGR_COREDUMP:
+        description: 'Newtmgr commands for fetching/erasing coredump'
+        value: 0
+    IMGMGR_CLI:
+        description: 'CLI commands to interact with image management'
+        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

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