From aa8c262d141d78c148a89de63b54623ad2592e0e Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 9 Apr 2018 12:52:42 -0400 Subject: add storage.erase_filesystem() to erase and reformat CIRCUITPY --- shared-bindings/storage/__init__.c | 19 +++++++++++++++++++ shared-bindings/storage/__init__.h | 1 + 2 files changed, 20 insertions(+) (limited to 'shared-bindings/storage') diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 734cabcc1..2195d2242 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -131,6 +131,24 @@ mp_obj_t storage_getmount(const mp_obj_t mnt_in) { } MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount); +//| .. function:: erase_filesystem() +//| +//| Erase and re-create the ``CIRCUITPY`` filesystem. Then call +//| `microcontroller.reset()` to restart CircuitPython and have the +//| host computer remount CIRCUITPY. +//| +//| This function can be called from the REPL when ``CIRCUITPY`` +//| has become corrupted. +//| +//| .. warning:: All the data on ``CIRCUITPY`` will be lost, and +//| CircuitPython will restart. + +mp_obj_t storage_erase_filesystem(void) { + common_hal_storage_erase_filesystem(); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem); + STATIC const mp_rom_map_elem_t storage_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_storage) }, @@ -138,6 +156,7 @@ STATIC const mp_rom_map_elem_t storage_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&storage_umount_obj) }, { MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) }, { MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) }, + { MP_ROM_QSTR(MP_QSTR_erase_filesystem), MP_ROM_PTR(&storage_erase_filesystem_obj) }, //| .. class:: VfsFat(block_device) //| diff --git a/shared-bindings/storage/__init__.h b/shared-bindings/storage/__init__.h index 76b9ae854..6a0cb9fc7 100644 --- a/shared-bindings/storage/__init__.h +++ b/shared-bindings/storage/__init__.h @@ -35,5 +35,6 @@ void common_hal_storage_umount_path(const char* path); void common_hal_storage_umount_object(mp_obj_t vfs_obj); void common_hal_storage_remount(const char* path, bool readonly); mp_obj_t common_hal_storage_getmount(const char* path); +void common_hal_storage_erase_filesystem(void); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_STORAGE___INIT___H -- cgit v1.2.3 From 5f98953ed89f5e89b92f500788ae4ff0806886c8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 10 Apr 2018 12:08:41 -0400 Subject: esp8266 and nrf: raise NotImplementedError --- ports/atmel-samd/common-hal/storage/__init__.c | 8 ++++++++ ports/esp8266/common-hal/storage/__init__.c | 7 +++++++ ports/nrf/common-hal/storage/__init__.c | 4 ++++ shared-bindings/storage/__init__.c | 8 +++++--- shared-module/storage/__init__.c | 6 ------ supervisor/filesystem.h | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) (limited to 'shared-bindings/storage') diff --git a/ports/atmel-samd/common-hal/storage/__init__.c b/ports/atmel-samd/common-hal/storage/__init__.c index c4cb83142..383865558 100644 --- a/ports/atmel-samd/common-hal/storage/__init__.c +++ b/ports/atmel-samd/common-hal/storage/__init__.c @@ -29,7 +29,9 @@ #include "flash_api.h" #include "py/mperrno.h" #include "py/runtime.h" +#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/storage/__init__.h" +#include "supervisor/filesystem.h" #include "usb.h" extern volatile bool mp_msc_enabled; @@ -47,3 +49,9 @@ void common_hal_storage_remount(const char* mount_path, bool readonly) { flash_set_usb_writable(readonly); } + +void common_hal_storage_erase_filesystem(void) { + filesystem_init(false, true); // Force a re-format. + common_hal_mcu_reset(); + // We won't actually get here, since we're resetting. +} diff --git a/ports/esp8266/common-hal/storage/__init__.c b/ports/esp8266/common-hal/storage/__init__.c index a4c3a387a..dd732e3b7 100644 --- a/ports/esp8266/common-hal/storage/__init__.c +++ b/ports/esp8266/common-hal/storage/__init__.c @@ -26,9 +26,16 @@ #include +#include "lib/oofatfs/ff.h" +#include "lib/oofatfs/diskio.h" +#include "py/mperrno.h" #include "py/runtime.h" #include "shared-bindings/storage/__init__.h" void common_hal_storage_remount(const char* mount_path, bool readonly) { mp_raise_NotImplementedError(""); } + +void common_hal_storage_erase_filesystem() { + mp_raise_NotImplementedError("Use esptool to erase flash and re-upload Python instead"); +} diff --git a/ports/nrf/common-hal/storage/__init__.c b/ports/nrf/common-hal/storage/__init__.c index 9d94d3969..76ff81466 100644 --- a/ports/nrf/common-hal/storage/__init__.c +++ b/ports/nrf/common-hal/storage/__init__.c @@ -37,3 +37,7 @@ void common_hal_storage_remount(const char* mount_path, bool readonly) { mp_raise_OSError(MP_EINVAL); } } + +void common_hal_storage_erase_filesystem() { + mp_raise_NotImplementedError(""); +} diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 2195d2242..ca9281a18 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -133,15 +133,17 @@ MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount); //| .. function:: erase_filesystem() //| -//| Erase and re-create the ``CIRCUITPY`` filesystem. Then call -//| `microcontroller.reset()` to restart CircuitPython and have the +//| Erase and re-create the ``CIRCUITPY`` filesystem. +//| +//| On boards that present USB-visible ``CIRCUITPY`` drive (e.g., SAMD21 and SAMD51), +//| then call `microcontroller.reset()` to restart CircuitPython and have the //| host computer remount CIRCUITPY. //| //| This function can be called from the REPL when ``CIRCUITPY`` //| has become corrupted. //| //| .. warning:: All the data on ``CIRCUITPY`` will be lost, and -//| CircuitPython will restart. +//| CircuitPython will restart on certain boards. mp_obj_t storage_erase_filesystem(void) { common_hal_storage_erase_filesystem(); diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index f1fa74990..dc576ccda 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -127,9 +127,3 @@ void common_hal_storage_umount_path(const char* mount_path) { mp_obj_t common_hal_storage_getmount(const char *mount_path) { return storage_object_from_path(mount_path); } - -void common_hal_storage_erase_filesystem(void) { - filesystem_init(false, true); // Force a re-format. - common_hal_mcu_reset(); - // We won't actually get here, since we're resetting. -} diff --git a/supervisor/filesystem.h b/supervisor/filesystem.h index 63da0bcab..eb9e65c09 100644 --- a/supervisor/filesystem.h +++ b/supervisor/filesystem.h @@ -29,7 +29,7 @@ #include -void filesystem_init(bool create_allowed, bool create_force); +void filesystem_init(bool create_allowed, bool force_create); void filesystem_flush(void); void filesystem_writable_by_python(bool writable); bool filesystem_present(void); -- cgit v1.2.3