don't enter safemode.py on USER safe mode

This commit is contained in:
Dan Halbert 2023-02-14 11:20:29 -05:00
parent 0f099cdb31
commit 328585f160
3 changed files with 12 additions and 4 deletions

View File

@ -139,8 +139,10 @@ Behavior
possible to fix code that causes nasty crashes by making it available through mass storage after possible to fix code that causes nasty crashes by making it available through mass storage after
the crash. A reset (the button) is needed after it's fixed to get back into normal mode. the crash. A reset (the button) is needed after it's fixed to get back into normal mode.
- Safe mode may be handled programmatically by providing a ``safemode.py``. - Safe mode may be handled programmatically by providing a ``safemode.py``.
``safemode.py`` is run if the board has reset due to entering safe mode. USB is not ``safemode.py`` is run if the board has reset due to entering safe mode, unless the safe mode
available so nothing can be printed. ``safemode.py`` can determine why the safe mode occurred initiated by the user by pressing button(s).
USB is not available so nothing can be printed.
``safemode.py`` can determine why the safe mode occurred
using ``supervisor.runtime.safe_mode_reason``, and take appropriate action. For instance, using ``supervisor.runtime.safe_mode_reason``, and take appropriate action. For instance,
if a hard crash occurred, ``safemode.py`` may do a ``microcontroller.reset()`` if a hard crash occurred, ``safemode.py`` may do a ``microcontroller.reset()``
to automatically restart despite the crash. to automatically restart despite the crash.

4
main.c
View File

@ -733,7 +733,9 @@ vstr_t *boot_output;
#if CIRCUITPY_SAFEMODE_PY #if CIRCUITPY_SAFEMODE_PY
STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) { STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) {
// Don't run if we aren't in safe mode or we won't be able to find safemode.py. // Don't run if we aren't in safe mode or we won't be able to find safemode.py.
if (safe_mode == SAFE_MODE_NONE || !filesystem_present()) { // Also don't run if it's a user-initiated safemode (pressing button(s) during boot),
// since that's deliberate.
if (safe_mode == SAFE_MODE_NONE || safe_mode == SAFE_MODE_USER || !filesystem_present()) {
return; return;
} }

View File

@ -137,7 +137,11 @@ MAKE_ENUM_MAP(supervisor_safe_mode_reason) {
MAKE_ENUM_MAP_ENTRY(safe_mode_reason, USB_TOO_MANY_INTERFACE_NAMES), MAKE_ENUM_MAP_ENTRY(safe_mode_reason, USB_TOO_MANY_INTERFACE_NAMES),
//| USER: object //| USER: object
//| """The user pressed one or more buttons to enter safe mode.""" //| """The user pressed one or more buttons to enter safe mode.
//| This safe mode does **not** cause ``safemode.py`` to be run, since its purpose
//| is to prevent all user code from running.
//| This allows errors in ``safemode.py`` to be corrected easily.
//| """
//| //|
MAKE_ENUM_MAP_ENTRY(safe_mode_reason, USER), MAKE_ENUM_MAP_ENTRY(safe_mode_reason, USER),