New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement safemode.py #7577
Implement safemode.py #7577
Conversation
|
Will the Will Will Will This is a great feature - it will save me so much downtime and manual resets. Thanks, Dan! |
You can't enter boot.py or code.py if you are in safe mode, so that is moot. But if you get into the REPL, then
If The point of In many cases, |
|
Thanks, Dan. I currently track reset and reload reasons and stats, using |
You might able to use SleepMemory for this, even without alarms. Or |
|
I don't think edit: ah, but yes |
|
While trying to undo One solution to this is to not run |
|
If I'm trigging a user safe mode I assume it's because I can't get to the REPL any other way. Could a casually written safemode.py block that? |
Yes, if it did a |
|
There's also |
|
I've been testing edit: found out unintentionally that the "special safemode which is entered if there are errors in |
|
If safemode.py can write a new boot.py file... being able to modify storage.remount options by using the "safe mode" button sounds like it could be useful. Perhaps a case for a supervisor.set_next_boot_file feature |
|
I'm using edit: I'm not sure it's even necessary to use |
I implemented this on the latest commit, because I believe the expectation would be that user-initiated safemode should prevent anything from running, so you can do code repair. Also documented this. The README.rst could use more work in long run to make it more comprehensive. It sometimes takes a "this is different than MicroPython" viewpoint, and should probably stand on its own. (That's true of other places in the doc as well.) Things like documenting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good. Thank you! Just a couple comments on getting it enabled everywhere.
|
@tannewt ok it fits on all the enabled builds now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks like only M0 without external flash won't have it.
|
This is the type of creature comfort that might not be as appreciated later because it solves a problem too effectively. So I just wanted to say thanks while it's still fresh, @dhalbert. |
Fixes #5956.
Fixes #2694.
safemode.py, which is executed first, instead ofboot.pyand/orcode.py, but only if the board has been reset due to going into safe mode.safemode.pyhas no access to USB. Its output is not written toboot_out.txt, unlikeboot.py, to minimize possible problems. There is a special safemode which is entered if there are errors insafemode.py.safemode.pyexits normally, the safe mode will remain in effect, andboot.pyandcode.pywill not be executed. The safe mode reason will be reported in the console as usual.safemode.pycan also do amicrocontroller.reset(), which will clear the safe mode and restart normally, as if the reset button was pressed. It can also do a deep sleep.supervisor.SafeModeReasonenum class, andsupervisor.runtime.safe_mode_reason, which returns one of those enums.Internal changes in support of the above:
SAFE_MODE_....NO_SAFE_MODEis nowSAFE_MODE_NONE(I always did a double-take onNO_SAFE_MODE).MANUALandUSERare now both justUSER. The Nordic-specific safemode is now renamed to be for third-party SDK fatal errors in general. Etc. All hardware faults are nowHARD_FAULT.HEAP_OVERWRITTENis nowSTACK_OVERFLOWbecause that describes what happened.USERsafe mode messages were all changed to second person instead of passive voice for clarity.supervisor/message/default.hwas obsolete and unused; removed.CIRCUITPY_SAFEMODE_PYis now a compiler flag, though it's default on. But maybe some tiny ports can't use it. I think it will fit, though.