diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-04-09 12:52:42 -0400 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2018-04-09 12:52:42 -0400 |
| commit | aa8c262d141d78c148a89de63b54623ad2592e0e (patch) | |
| tree | 3c79429cc76896f7070f968e631bab81fbb8dbdf /shared-bindings | |
| parent | 4e053cea0df0105e05052087077b2431cad26718 (diff) | |
add storage.erase_filesystem() to erase and reformat CIRCUITPY
Diffstat (limited to 'shared-bindings')
| -rw-r--r-- | shared-bindings/storage/__init__.c | 19 | ||||
| -rw-r--r-- | shared-bindings/storage/__init__.h | 1 |
2 files changed, 20 insertions, 0 deletions
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 |
