summaryrefslogtreecommitdiff
path: root/shared-module/storage/__init__.c
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-11-09 15:56:29 -0500
committerGitHub <noreply@github.com>2018-11-09 15:56:29 -0500
commit97bc95183d5114ce69c9387ebd2e2aa13feb65a7 (patch)
tree83853be3b0197c1c18bcea4f5d3403d48a63e15e /shared-module/storage/__init__.c
parentd08747d374057b24803b429bbf6474a2e4dcea5c (diff)
parent43f7ca7985768c974b6881957b21d687c34413ba (diff)
Merge pull request #1321 from tannewt/tinyusb_samd
Move atmel-samd to tinyusb and support nRF flash.
Diffstat (limited to 'shared-module/storage/__init__.c')
-rw-r--r--shared-module/storage/__init__.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c
index edce286b1..f09edd785 100644
--- a/shared-module/storage/__init__.c
+++ b/shared-module/storage/__init__.c
@@ -32,8 +32,12 @@
#include "py/mperrno.h"
#include "py/obj.h"
#include "py/runtime.h"
+#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/os/__init__.h"
#include "shared-bindings/storage/__init__.h"
+#include "supervisor/filesystem.h"
+#include "supervisor/flash.h"
+#include "supervisor/usb.h"
STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) {
if (vfs == MP_VFS_NONE) {
@@ -138,3 +142,25 @@ 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_remount(const char *mount_path, bool readonly) {
+ if (strcmp(mount_path, "/") != 0) {
+ mp_raise_OSError(MP_EINVAL);
+ }
+
+ #ifdef USB_AVAILABLE
+ // TODO(dhalbert): is this is a good enough check? It checks for
+ // CDC enabled. There is no "MSC enabled" check.
+ if (usb_enabled()) {
+ mp_raise_RuntimeError(translate("Cannot remount '/' when USB is active."));
+ }
+ #endif
+
+ supervisor_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.
+}