Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit 53699cc

Browse files
committed
Move boot.py out of the filesystem and into the firmware. Then use badge.safe_mode()
to force the use of the default splash, disable services and disable sleeping. This should allow a user to uninstall any malicious applications without needing to plug the badge into a computer with USB.
1 parent af11948 commit 53699cc

File tree

7 files changed

+31
-34
lines changed

7 files changed

+31
-34
lines changed

esp32/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void mp_task(void *pvParameter) {
102102
// run boot-up scripts
103103
pyexec_frozen_module("_boot.py");
104104
if (pyexec_mode_kind != PYEXEC_MODE_RAW_REPL) {
105-
pyexec_file("boot.py");
105+
pyexec_frozen_module("boot.py");
106106
}
107107
// if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
108108
// pyexec_file("main.py");

esp32/modules/_boot.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import badge, gc, uos
22

3-
try:
4-
badge.mount_root()
5-
uos.mount(uos.VfsNative(None), '/')
6-
with open("/boot.py", "r") as f:
7-
f.close()
8-
9-
except OSError:
10-
import inisetup
11-
vfs = inisetup.setup()
3+
badge.mount_root()
4+
uos.mount(uos.VfsNative(None), '/')
125

136
gc.collect()

esp32/modules/create.py renamed to esp32/modules/boot.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import uos
2-
3-
def boot():
4-
print("Updating 'boot.py'...")
5-
with open("/boot.py", "w") as f:
6-
f.write("""\
71
# This file is executed on every boot (including wake-boot from deepsleep)
82
import badge, machine, esp, ugfx, sys
93
badge.init()
104
ugfx.init()
115
esp.rtcmem_write(0,0)
126
esp.rtcmem_write(1,0)
13-
splash = badge.nvs_get_str('boot','splash','splash')
7+
if badge.safe_mode():
8+
splash = 'splash'
9+
else:
10+
splash = badge.nvs_get_str('boot','splash','splash')
1411
if machine.reset_cause() != machine.DEEPSLEEP_RESET:
1512
print('[BOOT] Cold boot')
1613
else:
@@ -39,4 +36,3 @@ def boot():
3936
time.sleep(5)
4037
import appglue
4138
appglue.home()
42-
""")

esp32/modules/inisetup.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

esp32/modules/launcher.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,16 @@ def start():
166166
ugfx.clear(ugfx.WHITE)
167167
ugfx.flush()
168168

169-
ugfx.string_box(148,0,148,26, "STILL", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter)
169+
if badge.safe_mode():
170+
still = "SAFE"
171+
anyway = "Mode"
172+
else:
173+
still = "STILL"
174+
anyway = "Anyway"
175+
176+
ugfx.string_box(148,0,148,26, still, "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter)
170177
ugfx.string_box(148,23,148,23, "Hacking", "PermanentMarker22", ugfx.BLACK, ugfx.justifyCenter)
171-
ugfx.string_box(148,48,148,26, "Anyway", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter)
178+
ugfx.string_box(148,48,148,26, anyway, "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter)
172179

173180
#the line under the text
174181
str_len = ugfx.get_string_width("Hacking","PermanentMarker22")

esp32/modules/splash.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@ def draw(mode, goingToSleep=False):
3535
info2 = 'Press select to start OTA update'
3636
else:
3737
info2 = ''
38-
l = ugfx.get_string_width(info1,"Roboto_Regular12")
39-
ugfx.string(296-l, 0, info1, "Roboto_Regular12",ugfx.BLACK)
40-
l = ugfx.get_string_width(info2,"Roboto_Regular12")
41-
ugfx.string(296-l, 12, info2, "Roboto_Regular12",ugfx.BLACK)
38+
39+
def disp_string_right(y, s):
40+
l = ugfx.get_string_width(s,"Roboto_Regular12")
41+
ugfx.string(296-l, y, s, "Roboto_Regular12",ugfx.BLACK)
42+
43+
disp_string_right(0, info1)
44+
disp_string_right(12, info2)
45+
46+
if badge.safe_mode():
47+
disp_string_right(92, "Safe Mode - services disabled")
48+
disp_string_right(104, "Sleep disabled - will drain battery quickly")
49+
disp_string_right(116, "Press Reset button to exit")
4250

4351
easydraw.nickname()
4452

@@ -156,7 +164,8 @@ def onSleep(idleTime):
156164
if not easywifi.failure():
157165
spoc.show(False) # Check sponsors
158166

159-
services.setup(draw) # Start services
167+
if not badge.safe_mode():
168+
services.setup(draw) # Start services
160169

161170
draw(False)
162171
services.force_draw()

esp32/modules/tasks/powermanagement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def pm_task():
1818
idleTime = virtualtimers.idle_time()
1919
print("[Power management] Next task wants to run in "+str(idleTime)+" ms.")
2020

21-
if idleTime>30000:
21+
if idleTime>30000 and not badge.safe_mode():
2222
global onSleepCallback
2323
if not onSleepCallback==None:
2424
print("[Power management] Running onSleepCallback...")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy