File tree Expand file tree Collapse file tree 4 files changed +89
-0
lines changed Expand file tree Collapse file tree 4 files changed +89
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,13 @@ void mp_task(void *pvParameter) {
66
66
mp_obj_list_init (mp_sys_argv , 0 );
67
67
readline_init0 ();
68
68
69
+ // run boot-up scripts
70
+ pyexec_frozen_module ("_boot.py" );
71
+ pyexec_file ("boot.py" );
72
+ if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL ) {
73
+ pyexec_file ("main.py" );
74
+ }
75
+
69
76
for (;;) {
70
77
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL ) {
71
78
if (pyexec_raw_repl () != 0 ) {
Original file line number Diff line number Diff line change
1
+ import gc
2
+ import uos
3
+ from flashbdev import bdev
4
+
5
+ try :
6
+ if bdev :
7
+ vfs = uos .VfsFat (bdev , "" )
8
+ except OSError :
9
+ import inisetup
10
+ vfs = inisetup .setup ()
11
+
12
+ gc .collect ()
Original file line number Diff line number Diff line change
1
+ import esp
2
+
3
+ class FlashBdev :
4
+
5
+ SEC_SIZE = 4096
6
+ START_SEC = esp .flash_user_start () // SEC_SIZE
7
+
8
+ def __init__ (self , blocks ):
9
+ self .blocks = blocks
10
+
11
+ def readblocks (self , n , buf ):
12
+ #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
13
+ esp .flash_read ((n + self .START_SEC ) * self .SEC_SIZE , buf )
14
+
15
+ def writeblocks (self , n , buf ):
16
+ #print("writeblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
17
+ #assert len(buf) <= self.SEC_SIZE, len(buf)
18
+ esp .flash_erase (n + self .START_SEC )
19
+ esp .flash_write ((n + self .START_SEC ) * self .SEC_SIZE , buf )
20
+
21
+ def ioctl (self , op , arg ):
22
+ #print("ioctl(%d, %r)" % (op, arg))
23
+ if op == 4 : # BP_IOCTL_SEC_COUNT
24
+ return self .blocks
25
+ if op == 5 : # BP_IOCTL_SEC_SIZE
26
+ return self .SEC_SIZE
27
+
28
+ size = esp .flash_size ()
29
+ if size < 1024 * 1024 :
30
+ # flash too small for a filesystem
31
+ bdev = None
32
+ else :
33
+ # for now we use a fixed size for the filesystem
34
+ bdev = FlashBdev (256 * 1024 // FlashBdev .SEC_SIZE )
Original file line number Diff line number Diff line change
1
+ import uos
2
+ from flashbdev import bdev
3
+
4
+ def check_bootsec ():
5
+ buf = bytearray (bdev .SEC_SIZE )
6
+ bdev .readblocks (0 , buf )
7
+ empty = True
8
+ for b in buf :
9
+ if b != 0xff :
10
+ empty = False
11
+ break
12
+ if empty :
13
+ return True
14
+ fs_corrupted ()
15
+
16
+ def fs_corrupted ():
17
+ import time
18
+ while 1 :
19
+ print ("""\
20
+ FAT filesystem appears to be corrupted. If you had important data there, you
21
+ may want to make a flash snapshot to try to recover it. Otherwise, perform
22
+ factory reprogramming of MicroPython firmware (completely erase flash, followed
23
+ by firmware programming).
24
+ """ )
25
+ time .sleep (3 )
26
+
27
+ def setup ():
28
+ check_bootsec ()
29
+ print ("Performing initial setup" )
30
+ uos .VfsFat .mkfs (bdev )
31
+ vfs = uos .VfsFat (bdev , "" )
32
+ with open ("/boot.py" , "w" ) as f :
33
+ f .write ("""\
34
+ # This file is executed on every boot (including wake-boot from deepsleep)
35
+ """ )
36
+ return vfs
You can’t perform that action at this time.
0 commit comments