Skip to content

Commit cb44007

Browse files
Add Hijack Boot
1 parent d480776 commit cb44007

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

docs/os-development/hijack-boot.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Hijacking the Boot Sequence
2+
3+
You can intercept the boot sequence to drop into a raw REPL shell instead of starting MicroPythonOS — useful for debugging, running custom startup code, or recovering from a broken install.
4+
5+
## The one-liner
6+
7+
```python
8+
__import__("os").mkdir("/lib") or True; __import__("os").mkdir("/lib/mpos") or True; open("/lib/mpos/main.py","w").write('raise RuntimeError("/lib/mpos/main.py: dropping to REPL shell. To resume boot, do: import mpos.main")\n')
9+
```
10+
11+
Copy-paste this into your device's REPL (e.g. over serial) and hit enter. The `or True` handles the case where the directories already exist.
12+
13+
## What it does
14+
15+
`/lib/mpos/main.py` is MicroPythonOS's entry point. When the firmware boots, it looks for `main.py` on the filesystem — if found, it runs it first. This one-liner writes a stub that raises an error instead, which means:
16+
17+
1. The device boots into a clean MicroPython REPL.
18+
2. No MicroPythonOS code (LVGL, apps, frameworks) is loaded.
19+
3. You have full access to the filesystem and MicroPython stdlib.
20+
21+
## Resuming normal boot
22+
23+
From that REPL, you can start MicroPythonOS manually:
24+
25+
```python
26+
import mpos.main
27+
```
28+
29+
This runs the full boot sequence (LVGL init, app loading, launcher) as if nothing happened.
30+
31+
## Undoing the hijack
32+
33+
To restore normal boot on every power-on, delete the stub:
34+
35+
```python
36+
__import__("os").remove("/lib/mpos/main.py")
37+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ nav:
9191
- On MacOS: os-development/macos.md
9292
- On Windows: os-development/windows.md
9393
- Installing on ESP32: os-development/installing-on-esp32.md
94+
- Hijacking the Boot: os-development/hijack-boot.md
9495
- Automated Testing: os-development/automated-testing.md
9596
- Emulated ESP32: os-development/emulating-esp32-on-desktop.md
9697
- Porting Guide: os-development/porting-guide.md

0 commit comments

Comments
 (0)