Do USB init even in safe mode

This commit is contained in:
Dan Halbert 2021-05-08 11:03:05 -04:00
parent f761292c72
commit 4b45c37516
1 changed files with 43 additions and 35 deletions

24
main.c
View File

@ -447,11 +447,17 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
FIL* boot_output_file; FIL* boot_output_file;
STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
// If not in safe mode, run boot before initing USB and capture output in a // If not in safe mode, run boot before initing USB and capture output in a file.
// file.
if (filesystem_present() && safe_mode == NO_SAFE_MODE && MP_STATE_VM(vfs_mount_table) != NULL) {
static const char * const boot_py_filenames[] = STRING_LIST("settings.txt", "settings.py", "boot.py", "boot.txt");
// There is USB setup to do even if boot.py is not actually run.
const bool ok_to_run = filesystem_present()
&& safe_mode == NO_SAFE_MODE
&& MP_STATE_VM(vfs_mount_table) != NULL;
static const char * const boot_py_filenames[] = STRING_LIST("settings.txt", "settings.py", "boot.py", "boot.txt");
bool skip_boot_output = false;
if (ok_to_run) {
new_status_color(BOOT_RUNNING); new_status_color(BOOT_RUNNING);
#ifdef CIRCUITPY_BOOT_OUTPUT_FILE #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
@ -463,8 +469,6 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
bool have_boot_py = first_existing_file_in_list(boot_py_filenames) != NULL; bool have_boot_py = first_existing_file_in_list(boot_py_filenames) != NULL;
bool skip_boot_output = false;
// If there's no boot.py file that might write some changing output, // If there's no boot.py file that might write some changing output,
// read the existing copy of CIRCUITPY_BOOT_OUTPUT_FILE and see if its contents // read the existing copy of CIRCUITPY_BOOT_OUTPUT_FILE and see if its contents
// match the version info we would print anyway. If so, skip writing CIRCUITPY_BOOT_OUTPUT_FILE. // match the version info we would print anyway. If so, skip writing CIRCUITPY_BOOT_OUTPUT_FILE.
@ -505,6 +509,10 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
#endif #endif
filesystem_flush(); filesystem_flush();
}
// Do USB setup even if boot.py is not run.
supervisor_allocation* heap = allocate_remaining_memory(); supervisor_allocation* heap = allocate_remaining_memory();
start_mp(heap); start_mp(heap);
@ -514,6 +522,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
#endif #endif
// TODO(tannewt): Re-add support for flashing boot error output. // TODO(tannewt): Re-add support for flashing boot error output.
if (ok_to_run) {
bool found_boot = maybe_run_list(boot_py_filenames, NULL); bool found_boot = maybe_run_list(boot_py_filenames, NULL);
(void) found_boot; (void) found_boot;
@ -524,6 +533,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
} }
boot_output_file = NULL; boot_output_file = NULL;
#endif #endif
}
#if CIRCUITPY_USB #if CIRCUITPY_USB
@ -545,8 +555,6 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
// Now give back the data we saved from the heap going away. // Now give back the data we saved from the heap going away.
usb_return_boot_py_data(usb_boot_py_data, size); usb_return_boot_py_data(usb_boot_py_data, size);
#endif #endif
}
} }
STATIC int run_repl(void) { STATIC int run_repl(void) {