Skip to content

Commit bb2ae16

Browse files
hijack-boot: document overriding board detection via pre-set hardware_id
1 parent 18ba724 commit bb2ae16

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

docs/os-development/hijack-boot.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,37 @@ To restore normal boot on every power-on, delete the override and its containing
5050
```python
5151
import shutil ; shutil.rmtree("/lib/mpos")
5252
```
53+
54+
## Overriding Board Detection
55+
56+
If `DeviceInfo.hardware_id` is already set before `import mpos.main`, the normal board detection is skipped entirely. This lets you force a specific board file or do custom initialization without modifying the firmware.
57+
58+
### Force a known board
59+
60+
```python
61+
from mpos import DeviceInfo
62+
DeviceInfo.set_hardware_id("linux")
63+
import mpos.main
64+
```
65+
66+
The matching `mpos/board/linux.py` will be imported as usual.
67+
68+
### Custom/new device (no board file)
69+
70+
Set a hardware ID that has no corresponding `mpos/board/*.py` file. Put any init code (display, touch, etc.) directly in `/lib/mpos/main.py` before the import:
71+
72+
```python
73+
from mpos import DeviceInfo
74+
from mpos import DisplayMetrics
75+
import lvgl as lv
76+
77+
# Custom init for a new board
78+
DisplayMetrics.set_resolution(480, 320)
79+
DisplayMetrics.set_dpi(160)
80+
# ... more init as needed ...
81+
82+
DeviceInfo.set_hardware_id("my_new_board")
83+
import mpos.main
84+
```
85+
86+
`mpos.main` will log a warning about the missing board file and continue booting. This is useful when adding support for a new device using a prebuilt image — you can prototype the board init in `/lib/mpos/main.py` without rebuilding the firmware. Once stable, create `mpos/board/my_new_board.py` and include it in the next firmware build.

0 commit comments

Comments
 (0)