shorten safe mode messages; improve message printing; fix CIRCUITPY_SAFEMODE_PY=0

This commit is contained in:
Dan Halbert 2023-02-13 21:29:57 -05:00
parent d8231f1588
commit d46d9d5c21
6 changed files with 88 additions and 89 deletions

View File

@ -31,14 +31,20 @@ msgstr ""
#: supervisor/shared/safe_mode.c #: supervisor/shared/safe_mode.c
msgid "" msgid ""
"\n" "\n"
"Please file an issue with the contents of your CIRCUITPY drive at \n" "Please file an issue with your program at https://github.com/adafruit/"
"https://github.com/adafruit/circuitpython/issues\n" "circuitpython/issues."
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c #: supervisor/shared/safe_mode.c
msgid "" msgid ""
"\n" "\n"
"To exit, reset the board without requesting safe mode." "Press reset to exit safe mode.\n"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"\n"
"You are in safe mode because:\n"
msgstr "" msgstr ""
#: py/obj.c #: py/obj.c
@ -536,10 +542,6 @@ msgstr ""
msgid "Attempt to allocate %d blocks" msgid "Attempt to allocate %d blocks"
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c
msgid "Attempted heap allocation when VM not running."
msgstr ""
#: ports/raspberrypi/audio_dma.c #: ports/raspberrypi/audio_dma.c
msgid "Audio conversion not implemented" msgid "Audio conversion not implemented"
msgstr "" msgstr ""
@ -588,7 +590,7 @@ msgid "Bitmap size and bits per value must match"
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c #: supervisor/shared/safe_mode.c
msgid "Boot device must be first device (interface #0)." msgid "Boot device must be first (interface #0)."
msgstr "" msgstr ""
#: ports/mimxrt10xx/common-hal/busio/UART.c #: ports/mimxrt10xx/common-hal/busio/UART.c
@ -790,10 +792,6 @@ msgstr ""
msgid "CircuitPython core code crashed hard. Whoops!\n" msgid "CircuitPython core code crashed hard. Whoops!\n"
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c
msgid "CircuitPython was unable to allocate the heap."
msgstr ""
#: shared-module/bitbangio/I2C.c #: shared-module/bitbangio/I2C.c
msgid "Clock stretch too long" msgid "Clock stretch too long"
msgstr "" msgstr ""
@ -832,10 +830,6 @@ msgstr ""
msgid "Couldn't allocate decoder" msgid "Couldn't allocate decoder"
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c
msgid "Crash into the HardFault_Handler."
msgstr ""
#: ports/stm/common-hal/analogio/AnalogOut.c #: ports/stm/common-hal/analogio/AnalogOut.c
msgid "DAC Channel Init Error" msgid "DAC Channel Init Error"
msgstr "" msgstr ""
@ -1003,6 +997,10 @@ msgstr ""
msgid "Failed to write internal flash." msgid "Failed to write internal flash."
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c
msgid "Fault detected by hardware."
msgstr ""
#: py/moduerrno.c #: py/moduerrno.c
msgid "File exists" msgid "File exists"
msgstr "" msgstr ""
@ -1088,6 +1086,15 @@ msgstr ""
msgid "Hardware in use, try alternative pins" msgid "Hardware in use, try alternative pins"
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c
msgid "Heap allocation when VM not running."
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"Heap was corrupted because the stack was too small. Increase stack size."
msgstr ""
#: extmod/vfs_posix_file.c py/objstringio.c #: extmod/vfs_posix_file.c py/objstringio.c
msgid "I/O operation on closed file" msgid "I/O operation on closed file"
msgstr "" msgstr ""
@ -1993,15 +2000,7 @@ msgid "Temperature read timed out"
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c #: supervisor/shared/safe_mode.c
msgid "" msgid "The `microcontroller` module was used to boot into safe mode."
"The CircuitPython heap was corrupted because the stack was too small.\n"
"Increase the stack size if you know how. If not:"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The `microcontroller` module was used to boot into safe mode. Press reset to "
"exit safe mode."
msgstr "" msgstr ""
#: py/obj.c #: py/obj.c
@ -2013,10 +2012,7 @@ msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30"
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c #: supervisor/shared/safe_mode.c
msgid "" msgid "The power dipped. Make sure you are providing enough power."
"The microcontroller's power dipped. Make sure your power supply provides\n"
"enough power for the whole circuit and press reset (after ejecting "
"CIRCUITPY)."
msgstr "" msgstr ""
#: shared-module/audiomixer/MixerVoice.c #: shared-module/audiomixer/MixerVoice.c
@ -2162,6 +2158,10 @@ msgstr ""
msgid "Unable to allocate buffers for signed conversion" msgid "Unable to allocate buffers for signed conversion"
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c
msgid "Unable to allocate the heap."
msgstr ""
#: ports/espressif/common-hal/busio/I2C.c #: ports/espressif/common-hal/busio/I2C.c
msgid "Unable to create lock" msgid "Unable to create lock"
msgstr "" msgstr ""
@ -2367,10 +2367,6 @@ msgstr ""
msgid "Writes not supported on Characteristic" msgid "Writes not supported on Characteristic"
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c
msgid "You are in safe mode because:\n"
msgstr ""
#: ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h #: ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
#: ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h #: ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h
#: ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h #: ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h
@ -2385,7 +2381,7 @@ msgid "You pressed button A at start up."
msgstr "" msgstr ""
#: supervisor/shared/safe_mode.c #: supervisor/shared/safe_mode.c
msgid "You pressed the BOOT button at start up." msgid "You pressed the BOOT button at start up"
msgstr "" msgstr ""
#: ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h #: ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h

View File

@ -525,12 +525,16 @@ $(filter $(SRC_PATTERNS), \
qrio/PixelPolicy.c \ qrio/PixelPolicy.c \
qrio/QRInfo.c \ qrio/QRInfo.c \
supervisor/RunReason.c \ supervisor/RunReason.c \
supervisor/SafeModeReason.c \
supervisor/StatusBar.c \ supervisor/StatusBar.c \
wifi/AuthMode.c \ wifi/AuthMode.c \
wifi/Packet.c \ wifi/Packet.c \
) )
ifeq ($(CIRCUITPY_SAFEMODE_PY),1)
SRC_BINDINGS_ENUMS += \
supervisor/SafeModeReason.c
endif
SRC_BINDINGS_ENUMS += \ SRC_BINDINGS_ENUMS += \
util.c util.c

View File

@ -117,7 +117,10 @@ MP_PROPERTY_GETTER(supervisor_runtime_run_reason_obj,
(mp_obj_t)&supervisor_runtime_get_run_reason_obj); (mp_obj_t)&supervisor_runtime_get_run_reason_obj);
//| safe_mode_reason: SafeModeReason //| safe_mode_reason: SafeModeReason
//| """Why CircuitPython went into safe mode this particular time (read-only).""" //| """Why CircuitPython went into safe mode this particular time (read-only).
//|
//| **Limitations**: Raises ``NotImplementedError`` on builds that do not implement ``safemode.py``.
//| """
STATIC mp_obj_t supervisor_runtime_get_safe_mode_reason(mp_obj_t self) { STATIC mp_obj_t supervisor_runtime_get_safe_mode_reason(mp_obj_t self) {
#if CIRCUITPY_SAFEMODE_PY #if CIRCUITPY_SAFEMODE_PY
return cp_enum_find(&supervisor_safe_mode_reason_type, get_safe_mode()); return cp_enum_find(&supervisor_safe_mode_reason_type, get_safe_mode());

View File

@ -31,7 +31,6 @@
// Reuse the non-Python safe_mode_t enum // Reuse the non-Python safe_mode_t enum
#include "supervisor/shared/safe_mode.h" #include "supervisor/shared/safe_mode.h"
#if CIRCUITPY_SAFEMODE_PY
MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, NONE, SAFE_MODE_NONE); MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, NONE, SAFE_MODE_NONE);
MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, BROWNOUT, SAFE_MODE_BROWNOUT); MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, BROWNOUT, SAFE_MODE_BROWNOUT);
// alphabetical from here down // alphabetical from here down
@ -50,16 +49,16 @@ MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, USB_TOO_MANY
MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, USB_TOO_MANY_INTERFACE_NAMES, SAFE_MODE_USB_TOO_MANY_INTERFACE_NAMES); MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, USB_TOO_MANY_INTERFACE_NAMES, SAFE_MODE_USB_TOO_MANY_INTERFACE_NAMES);
MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, USER, SAFE_MODE_USER); MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, USER, SAFE_MODE_USER);
MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, WATCHDOG, SAFE_MODE_WATCHDOG); MAKE_ENUM_VALUE(supervisor_safe_mode_reason_type, safe_mode_reason, WATCHDOG, SAFE_MODE_WATCHDOG);
#endif
//| class SafeModeReason: //| class SafeModeReason:
//| """The reason that CircuitPython went into safe mode.""" //| """The reason that CircuitPython went into safe mode.
//|
//| **Limitations**: Class not available on builds that do not implement ``safemode.py``.
//| """
//| //|
MAKE_ENUM_MAP(supervisor_safe_mode_reason) { MAKE_ENUM_MAP(supervisor_safe_mode_reason) {
#if CIRCUITPY_SAFEMODE_PY
//| NONE: object //| NONE: object
//| """CircuitPython is not in safe mode.""" //| """CircuitPython is not in safe mode."""
//| //|
@ -146,7 +145,6 @@ MAKE_ENUM_MAP(supervisor_safe_mode_reason) {
//| """An internal watchdog timer expired.""" //| """An internal watchdog timer expired."""
//| //|
MAKE_ENUM_MAP_ENTRY(safe_mode_reason, WATCHDOG), MAKE_ENUM_MAP_ENTRY(safe_mode_reason, WATCHDOG),
#endif
}; };
STATIC MP_DEFINE_CONST_DICT(supervisor_safe_mode_reason_locals_dict, supervisor_safe_mode_reason_locals_table); STATIC MP_DEFINE_CONST_DICT(supervisor_safe_mode_reason_locals_dict, supervisor_safe_mode_reason_locals_table);

View File

@ -339,7 +339,7 @@ STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
#if CIRCUITPY_SAFEMODE_PY #if CIRCUITPY_SAFEMODE_PY
{ MP_ROM_QSTR(MP_QSTR_SafeModeReason), MP_ROM_PTR(&supervisor_safe_mode_reason_type) }, { MP_ROM_QSTR(MP_QSTR_SafeModeReason), MP_ROM_PTR(&supervisor_safe_mode_reason_type) },
#else #else
{ MP_ROM_QSTR(MP_QSTR_SafeModeReason), mp_const_none }, { MP_ROM_QSTR(MP_QSTR_SafeModeReason), MP_ROM_NONE },
#endif #endif
{ MP_ROM_QSTR(MP_QSTR_set_next_code_file), MP_ROM_PTR(&supervisor_set_next_code_file_obj) }, { MP_ROM_QSTR(MP_QSTR_set_next_code_file), MP_ROM_PTR(&supervisor_set_next_code_file_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&supervisor_ticks_ms_obj) }, { MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&supervisor_ticks_ms_obj) },

View File

@ -145,8 +145,7 @@ void print_safe_mode_message(safe_mode_t reason) {
return; return;
} }
serial_write("\r\n"); serial_write_compressed(translate("\nYou are in safe mode because:\n"));
serial_write_compressed(translate("You are in safe mode because:\n"));
const compressed_string_t *message = NULL; const compressed_string_t *message = NULL;
@ -154,29 +153,31 @@ void print_safe_mode_message(safe_mode_t reason) {
switch (reason) { switch (reason) {
case SAFE_MODE_BROWNOUT: case SAFE_MODE_BROWNOUT:
message = translate("The microcontroller's power dipped. Make sure your power supply provides\nenough power for the whole circuit and press reset (after ejecting CIRCUITPY)."); message = translate("The power dipped. Make sure you are providing enough power.");
break; break;
case SAFE_MODE_USER: case SAFE_MODE_USER:
#if defined(BOARD_USER_SAFE_MODE_ACTION) #if defined(BOARD_USER_SAFE_MODE_ACTION)
message = BOARD_USER_SAFE_MODE_ACTION; message = BOARD_USER_SAFE_MODE_ACTION;
#elif defined(CIRCUITPY_BOOT_BUTTON) #elif defined(CIRCUITPY_BOOT_BUTTON)
message = translate("You pressed the BOOT button at start up."); message = translate("You pressed the BOOT button at start up");
#else #else
message = translate("You pressed the reset button during boot."); message = translate("You pressed the reset button during boot.");
#endif #endif
serial_write_compressed(message);
message = translate("\nTo exit, reset the board without requesting safe mode.");
// The final piece is printed below.
break; break;
case SAFE_MODE_NO_CIRCUITPY: case SAFE_MODE_NO_CIRCUITPY:
message = translate("CIRCUITPY drive could not be found or created."); message = translate("CIRCUITPY drive could not be found or created.");
break; break;
case SAFE_MODE_PROGRAMMATIC: case SAFE_MODE_PROGRAMMATIC:
message = translate("The `microcontroller` module was used to boot into safe mode. Press reset to exit safe mode."); message = translate("The `microcontroller` module was used to boot into safe mode.");
break; break;
#if CIRCUITPY_SAFEMODE_PY
case SAFE_MODE_SAFEMODE_PY_ERROR: case SAFE_MODE_SAFEMODE_PY_ERROR:
message = translate("Error in safemode.py."); message = translate("Error in safemode.py.");
break; break;
#endif
case SAFE_MODE_STACK_OVERFLOW:
message = translate("Heap was corrupted because the stack was too small. Increase stack size.");
break;
case SAFE_MODE_USB_TOO_MANY_ENDPOINTS: case SAFE_MODE_USB_TOO_MANY_ENDPOINTS:
message = translate("USB devices need more endpoints than are available."); message = translate("USB devices need more endpoints than are available.");
break; break;
@ -184,7 +185,7 @@ void print_safe_mode_message(safe_mode_t reason) {
message = translate("USB devices specify too many interface names."); message = translate("USB devices specify too many interface names.");
break; break;
case SAFE_MODE_USB_BOOT_DEVICE_NOT_INTERFACE_ZERO: case SAFE_MODE_USB_BOOT_DEVICE_NOT_INTERFACE_ZERO:
message = translate("Boot device must be first device (interface #0)."); message = translate("Boot device must be first (interface #0).");
break; break;
case SAFE_MODE_WATCHDOG: case SAFE_MODE_WATCHDOG:
message = translate("Internal watchdog timer expired."); message = translate("Internal watchdog timer expired.");
@ -194,44 +195,41 @@ void print_safe_mode_message(safe_mode_t reason) {
} }
if (message) { if (message) {
// Non-crash safe mode.
serial_write_compressed(message); serial_write_compressed(message);
serial_write("\r\n"); } else {
return; // Something worse happened.
serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
switch (reason) {
case SAFE_MODE_GC_ALLOC_OUTSIDE_VM:
message = translate("Heap allocation when VM not running.");
break;
case SAFE_MODE_FLASH_WRITE_FAIL:
message = translate("Failed to write internal flash.");
break;
case SAFE_MODE_HARD_FAULT:
message = translate("Fault detected by hardware.");
break;
case SAFE_MODE_INTERRUPT_ERROR:
message = translate("Interrupt error.");
break;
case SAFE_MODE_NLR_JUMP_FAIL:
message = translate("NLR jump failed. Likely memory corruption.");
break;
case SAFE_MODE_NO_HEAP:
message = translate("Unable to allocate the heap.");
break;
case SAFE_MODE_SDK_FATAL_ERROR:
message = translate("Third-party firmware fatal error.");
break;
default:
message = translate("Unknown reason.");
break;
}
serial_write_compressed(message);
serial_write_compressed(translate("\nPlease file an issue with your program at https://github.com/adafruit/circuitpython/issues."));
} }
// Something worse happened. // Always tell user how to get out of safe mode.
serial_write_compressed(translate("\nPress reset to exit safe mode.\n"));
serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n"));
switch (reason) {
case SAFE_MODE_GC_ALLOC_OUTSIDE_VM:
message = translate("Attempted heap allocation when VM not running.");
break;
case SAFE_MODE_FLASH_WRITE_FAIL:
message = translate("Failed to write internal flash.");
break;
case SAFE_MODE_HARD_FAULT:
message = translate("Crash into the HardFault_Handler.");
break;
case SAFE_MODE_INTERRUPT_ERROR:
message = translate("Interrupt error.");
break;
case SAFE_MODE_NLR_JUMP_FAIL:
message = translate("NLR jump failed. Likely memory corruption.");
break;
case SAFE_MODE_NO_HEAP:
message = translate("CircuitPython was unable to allocate the heap.");
break;
case SAFE_MODE_SDK_FATAL_ERROR:
message = translate("Third-party firmware fatal error.");
break;
case SAFE_MODE_STACK_OVERFLOW:
message = translate("The CircuitPython heap was corrupted because the stack was too small.\nIncrease the stack size if you know how. If not:");
break;
default:
message = translate("Unknown reason.");
break;
}
serial_write_compressed(message);
serial_write_compressed(translate("\nPlease file an issue with the contents of your CIRCUITPY drive at \nhttps://github.com/adafruit/circuitpython/issues\n"));
} }