You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/12/20 13:21:58 UTC

[GitHub] mkiiskila closed pull request #1571: imgmgr; add 'erase' command to CLI.

mkiiskila closed pull request #1571: imgmgr; add 'erase' command to CLI.
URL: https://github.com/apache/mynewt-core/pull/1571
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/mgmt/imgmgr/src/imgmgr_cli.c b/mgmt/imgmgr/src/imgmgr_cli.c
index b583a842b3..06aa5ea56b 100644
--- a/mgmt/imgmgr/src/imgmgr_cli.c
+++ b/mgmt/imgmgr/src/imgmgr_cli.c
@@ -158,6 +158,43 @@ imgr_cli_confirm(void)
     }
 }
 
+static void
+imgr_cli_erase(void)
+{
+    const struct flash_area *fa;
+    int area_id;
+    int rc;
+
+    area_id = imgmgr_find_best_area_id();
+    if (area_id >= 0) {
+#if MYNEWT_VAL(LOG_FCB_SLOT1)
+        /*
+         * If logging to slot1 is enabled, make sure it's locked before erasing
+         * so log handler does not corrupt our data.
+         */
+        if (area_id == FLASH_AREA_IMAGE_1) {
+            log_fcb_slot1_lock();
+        }
+#endif
+
+        rc = flash_area_open(area_id, &fa);
+        if (rc) {
+            console_printf("Error opening area %d\n", area_id);
+            return;
+        }
+        rc = flash_area_erase(fa, 0, fa->fa_size);
+        flash_area_close(fa);
+        if (rc) {
+            console_printf("Error erasing area rc=%d\n", rc);
+        }
+    } else {
+        /*
+         * No slot where to erase!
+         */
+        console_printf("No suitable area to erase\n");
+    }
+}
+
 static int
 imgr_cli_cmd(int argc, char **argv)
 {
@@ -184,6 +221,8 @@ imgr_cli_cmd(int argc, char **argv)
         } else {
             imgr_cli_set_pending(argv[2], 1);
         }
+    } else if (!strcmp(argv[1], "erase")) {
+        imgr_cli_erase();
     } else {
         console_printf("Unknown cmd\n");
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services