From 07708f15185d96930621493c3e2886cc2e948622 Mon Sep 17 00:00:00 2001 From: Gadi Rotenberg Date: Sun, 9 Feb 2020 13:25:16 +0200 Subject: [PATCH] Added fix to allow remount when usb enabled but msc is ejected --- shared-module/storage/__init__.c | 4 +--- supervisor/shared/usb/usb_msc_flash.c | 10 +++++++++- supervisor/usb.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 215e1356a3..c3d4b50c8e 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -149,9 +149,7 @@ void common_hal_storage_remount(const char *mount_path, bool readonly, bool disa } #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()) { + if (!usb_msc_ejected()) { mp_raise_RuntimeError(translate("Cannot remount '/' when USB is active.")); } #endif diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c index 0376cfc1df..c0279f9e5f 100644 --- a/supervisor/shared/usb/usb_msc_flash.c +++ b/supervisor/shared/usb/usb_msc_flash.c @@ -39,7 +39,7 @@ #define MSC_FLASH_BLOCK_SIZE 512 -static bool ejected[1]; +static bool ejected[1] = {true}; void usb_msc_mount(void) { // Reset the ejection tracking every time we're plugged into USB. This allows for us to battery @@ -53,6 +53,14 @@ void usb_msc_umount(void) { } +bool usb_msc_ejected(void) { + bool all_ejected = true; + for (uint8_t i = 0; i < sizeof(ejected); i++) { + all_ejected &= ejected[i]; + } + return all_ejected; +} + // The root FS is always at the end of the list. static fs_user_mount_t* get_vfs(int lun) { // TODO(tannewt): Return the mount which matches the lun where 0 is the end diff --git a/supervisor/usb.h b/supervisor/usb.h index 0cc361619d..29280c725b 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -44,5 +44,6 @@ void usb_init(void); // Propagate plug/unplug events to the MSC logic. void usb_msc_mount(void); void usb_msc_umount(void); +bool usb_msc_ejected(void); #endif // MICROPY_INCLUDED_SUPERVISOR_USB_H