@@ -863,6 +863,14 @@ static void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
863863        boot_output  =  & boot_text ;
864864        #endif 
865865
866+         // Get the base filesystem. 
867+         fs_user_mount_t  * vfs  =  filesystem_circuitpy ();
868+         FATFS  * fs  =  & vfs -> fatfs ;
869+ 
870+         // Allow boot.py access to CIRCUITPY, and allow writes to boot_out.txt. 
871+         // We can't use the regular flags for this, because they might get modified inside boot.py. 
872+         filesystem_set_ignore_write_protection (vfs , true);
873+ 
866874        // Write version info 
867875        mp_printf (& mp_plat_print , "%s\nBoard ID:%s\n" , MICROPY_FULL_VERSION_INFO , CIRCUITPY_BOARD_ID );
868876        #if  CIRCUITPY_MICROCONTROLLER  &&  COMMON_HAL_MCU_PROCESSOR_UID_LENGTH  >  0 
@@ -881,10 +889,6 @@ static void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
881889
882890
883891        #ifdef  CIRCUITPY_BOOT_OUTPUT_FILE 
884-         // Get the base filesystem. 
885-         fs_user_mount_t  * vfs  =  filesystem_circuitpy ();
886-         FATFS  * fs  =  & vfs -> fatfs ;
887- 
888892        boot_output  =  NULL ;
889893        #if  CIRCUITPY_STATUS_BAR 
890894        supervisor_status_bar_resume ();
@@ -906,16 +910,16 @@ static void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
906910            // in case power is momentary or will fail shortly due to, say a low, battery. 
907911            mp_hal_delay_ms (1000 );
908912
909-             // USB isn't up, so we can write the file. 
910-             // operating at the oofatfs (f_open) layer means the usb concurrent write permission 
911-             // is not even checked! 
912913            f_open (fs , & boot_output_file , CIRCUITPY_BOOT_OUTPUT_FILE , FA_WRITE  | FA_CREATE_ALWAYS );
913914            UINT  chars_written ;
914915            f_write (& boot_output_file , boot_text .buf , boot_text .len , & chars_written );
915916            f_close (& boot_output_file );
916917            filesystem_flush ();
917918        }
918919        #endif 
920+ 
921+         // Back to regular filesystem protections. 
922+         filesystem_set_ignore_write_protection (vfs , false);
919923    }
920924
921925    cleanup_after_vm (_exec_result .exception );
0 commit comments