8000 Don't create a new filesystem if we restart in safe mode. (#319) · adafruit/circuitpython@922006d · GitHub
[go: up one dir, main page]

Skip to content

Commit 922006d

Browse files
authored
Don't create a new filesystem if we restart in safe mode. (#319)
1 parent ef65ee7 commit 922006d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

atmel-samd/main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) {
107107

108108
// we don't make this function static because it needs a lot of stack and we
109109
// want it to be executed without using stack within main() function
110-
void init_flash_fs(void) {
110+
void init_flash_fs(bool create_allowed) {
111111
// init the vfs object
112112
fs_user_mount_t *vfs_fat = &fs_user_mount_flash;
113113
vfs_fat->flags = 0;
@@ -116,7 +116,7 @@ void init_flash_fs(void) {
116116
// try to mount the flash
117117
FRESULT res = f_mount(&vfs_fat->fatfs);
118118

119-
if (res == FR_NO_FILESYSTEM) {
119+
if (res == FR_NO_FILESYSTEM && create_allowed) {
120120
// no filesystem so create a fresh one
121121

122122
uint8_t working_buf[_MAX_SS];
@@ -653,7 +653,10 @@ int main(void) {
653653
mp_stack_fill_with_sentinel();
654654
#endif
655655

656-
init_flash_fs();
656+
// Create a new filesystem only if we're not in a safe mode.
657+
// A power brownout here could make it appear as if there's
658+
// no SPI flash filesystem, and we might erase the existing one.
659+
init_flash_fs(safe_mode == NO_SAFE_MODE);
657660

658661
// Reset everything and prep MicroPython to run boot.py.
659662
reset_samd21();

0 commit comments

Comments
 (0)
0