You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/05/09 15:14:46 UTC

[03/13] incubator-mynewt-core git commit: bootutil; with nffs use separate tmp file for status storage.

bootutil; with nffs use separate tmp file for status storage.


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

Branch: refs/heads/develop
Commit: de0b034a6822b62c84da8e52441a91170b58e622
Parents: c1bdd9c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Apr 28 20:46:25 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon May 9 08:03:11 2016 -0700

----------------------------------------------------------------------
 libs/bootutil/pkg.yml             |  5 ++-
 libs/bootutil/src/bootutil_misc.c | 60 +++++++++++++++++++++++++++++++---
 libs/bootutil/src/bootutil_priv.h |  4 +--
 3 files changed, 61 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/de0b034a/libs/bootutil/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/bootutil/pkg.yml b/libs/bootutil/pkg.yml
index 01b8c43..53c741c 100644
--- a/libs/bootutil/pkg.yml
+++ b/libs/bootutil/pkg.yml
@@ -26,12 +26,15 @@ pkg.keywords:
     - bootloader
 
 pkg.deps: 
-    - fs/nffs
     - libs/os 
     - libs/testutil
     - libs/mbedtls
     - hw/hal
     - sys/config
 
+pkg.deps.FS:
+    - fs/fs
+pkg.cflags.NFFS: -DUSE_STATUS_FILE
+
 pkg.cflags.IMAGE_KEYS_RSA: -DIMAGE_SIGNATURES_RSA
 pkg.cflags.IMAGE_KEYS_EC: -DIMAGE_SIGNATURES_EC

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/de0b034a/libs/bootutil/src/bootutil_misc.c
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_misc.c b/libs/bootutil/src/bootutil_misc.c
index eaaeaf7..94afb53 100644
--- a/libs/bootutil/src/bootutil_misc.c
+++ b/libs/bootutil/src/bootutil_misc.c
@@ -25,11 +25,18 @@
 #include "bootutil/image.h"
 #include "bootutil_priv.h"
 
+#ifdef USE_STATUS_FILE
+#include <fs/fs.h>
+#include <fs/fsutil.h>
+#endif
+
 static int boot_conf_set(int argc, char **argv, char *val);
 
 static struct image_version boot_main;
 static struct image_version boot_test;
+#ifndef USE_STATUS_FILE
 static struct boot_status boot_saved;
+#endif
 
 static struct conf_handler boot_conf_handler = {
     .ch_name = "boot",
@@ -62,6 +69,7 @@ boot_conf_set(int argc, char **argv, char *val)
                 memset(&boot_test, 0, len);
                 rc = 0;
             }
+#ifndef USE_STATUS_FILE
         } else if (!strcmp(argv[0], "status")) {
             if (!val) {
                 boot_saved.state = 0;
@@ -74,6 +82,7 @@ boot_conf_set(int argc, char **argv, char *val)
             conf_value_from_str(val, CONF_INT32, &boot_saved.length,
               sizeof(boot_saved.length));
             rc = 0;
+#endif
         } else {
             rc = OS_ENOENT;
         }
@@ -228,6 +237,7 @@ bootutil_cfg_register(void)
     conf_register(&boot_conf_handler);
 }
 
+#ifndef USE_STATUS_FILE
 int
 boot_read_status(struct boot_status *bs)
 {
@@ -242,10 +252,6 @@ boot_read_status(struct boot_status *bs)
  * contains the current state of an in-progress image copy operation.
  *
  * @param status                The boot status base to write.
- * @param entries               The array of boot status entries to write.
- * @param num_areas             The number of flash areas capable of storing
- *                                  image data.  This is equal to the length of
- *                                  the entries array.
  *
  * @return                      0 on success; nonzero on failure.
  */
@@ -275,3 +281,49 @@ boot_clear_status(void)
 {
     conf_save_one(&boot_conf_handler, "status", NULL);
 }
+
+#else
+
+/**
+ * Reads the boot status from the flash file system.  The boot status contains
+ * the current state of an interrupted image copy operation.  If the boot
+ * status is not present in the file system, the implication is that there is
+ * no copy operation in progress.
+ */
+int
+boot_read_status(struct boot_status *bs)
+{
+    int rc;
+    uint32_t bytes_read;
+
+    conf_load();
+
+    rc = fsutil_read_file(BOOT_PATH_STATUS, 0, sizeof(*bs),
+      bs, &bytes_read);
+    if (rc || bytes_read != sizeof(*bs)) {
+        return BOOT_EBADSTATUS;
+    }
+    return rc;
+}
+
+int
+boot_write_status(struct boot_status *bs)
+{
+    int rc;
+
+    /*
+     * XXX point of failure.
+     */
+    rc = fsutil_write_file(BOOT_PATH_STATUS, bs, sizeof(*bs));
+    if (rc) {
+        rc = BOOT_EFILE;
+    }
+    return rc;
+}
+
+void
+boot_clear_status(void)
+{
+    fs_unlink(BOOT_PATH_STATUS);
+}
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/de0b034a/libs/bootutil/src/bootutil_priv.h
----------------------------------------------------------------------
diff --git a/libs/bootutil/src/bootutil_priv.h b/libs/bootutil/src/bootutil_priv.h
index ddbbd5c..98aa29f 100644
--- a/libs/bootutil/src/bootutil_priv.h
+++ b/libs/bootutil/src/bootutil_priv.h
@@ -32,9 +32,7 @@ struct image_header;
 
 #define BOOT_IMAGE_NUM_NONE     0xff
 
-#define BOOT_PATH_MAIN      "/boot/main"
-#define BOOT_PATH_TEST      "/boot/test"
-#define BOOT_PATH_STATUS    "/boot/status"
+#define BOOT_PATH_STATUS    "/cfg/bst"
 
 #define BOOT_TMPBUF_SZ  256