Skip to content

Commit 7d28789

Browse files
committed
ports: Use vfs module instead of os.
Signed-off-by: Damien George <[email protected]>
1 parent b87bbae commit 7d28789

File tree

13 files changed

+58
-58
lines changed

13 files changed

+58
-58
lines changed

ports/esp32/modules/_boot.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import gc
2-
import os
2+
import vfs
33
from flashbdev import bdev
44

55
try:
66
if bdev:
7-
os.mount(bdev, "/")
7+
vfs.mount(bdev, "/")
88
except OSError:
99
import inisetup
1010

11-
vfs = inisetup.setup()
11+
inisetup.setup()
1212

1313
gc.collect()

ports/esp32/modules/inisetup.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
import vfs
22
from flashbdev import bdev
33

44

@@ -38,12 +38,12 @@ def setup():
3838
check_bootsec()
3939
print("Performing initial setup")
4040
if bdev.info()[4] == "vfs":
41-
os.VfsLfs2.mkfs(bdev)
42-
vfs = os.VfsLfs2(bdev)
41+
vfs.VfsLfs2.mkfs(bdev)
42+
fs = vfs.VfsLfs2(bdev)
4343
elif bdev.info()[4] == "ffat":
44-
os.VfsFat.mkfs(bdev)
45-
vfs = os.VfsFat(bdev)
46-
os.mount(vfs, "/")
44+
vfs.VfsFat.mkfs(bdev)
45+
fs = vfs.VfsFat(bdev)
46+
vfs.mount(fs, "/")
4747
with open("boot.py", "w") as f:
4848
f.write(
4949
"""\
@@ -54,4 +54,4 @@ def setup():
5454
#webrepl.start()
5555
"""
5656
)
57-
return vfs
57+
return fs

ports/esp8266/boards/ESP8266_GENERIC/board.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Note: v1.12-334 and newer (including v1.13) require an ESP8266 module with
1313
2MiB of flash or more, and use littlefs as the filesystem by default. When
1414
upgrading from older firmware please backup your files first, and either
1515
erase all flash before upgrading, or after upgrading execute
16-
`os.VfsLfs2.mkfs(bdev)`.
16+
`vfs.VfsLfs2.mkfs(bdev)`.
1717

1818
### OTA builds
1919
Over-The-Air (OTA) builds of the ESP8266 firmware are also provided.

ports/esp8266/modules/_boot.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import gc
22

33
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
4-
import os
4+
import vfs
55
from flashbdev import bdev
66

77
if bdev:
88
try:
9-
os.mount(bdev, "/")
9+
vfs.mount(bdev, "/")
1010
except:
1111
import inisetup
1212

ports/esp8266/modules/inisetup.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
import vfs
22
import network
33
from flashbdev import bdev
44

@@ -36,7 +36,7 @@ def fs_corrupted():
3636
"""\
3737
The filesystem starting at sector %d with size %d sectors looks corrupt.
3838
You may want to make a flash snapshot and try to recover it. Otherwise,
39-
format it with os.VfsLfs2.mkfs(bdev), or completely erase the flash and
39+
format it with vfs.VfsLfs2.mkfs(bdev), or completely erase the flash and
4040
reprogram MicroPython.
4141
"""
4242
% (bdev.start_sec, bdev.blocks)
@@ -48,9 +48,9 @@ def setup():
4848
check_bootsec()
4949
print("Performing initial setup")
5050
wifi()
51-
os.VfsLfs2.mkfs(bdev)
52-
vfs = os.VfsLfs2(bdev)
53-
os.mount(vfs, "/")
51+
vfs.VfsLfs2.mkfs(bdev)
52+
fs = vfs.VfsLfs2(bdev)
53+
vfs.mount(fs, "/")
5454
with open("boot.py", "w") as f:
5555
f.write(
5656
"""\
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# format.py
22
# Re-create the file system
33

4-
import os
4+
import vfs
55
import mimxrt
66

77
bdev = mimxrt.Flash()
88

9-
os.VfsLfs2.mkfs(bdev, progsize=256)
10-
vfs = os.VfsLfs2(bdev, progsize=256)
11-
os.mount(vfs, "/")
9+
vfs.VfsLfs2.mkfs(bdev, progsize=256)
10+
fs = vfs.VfsLfs2(bdev, progsize=256)
11+
vfs.mount(fs, "/")

ports/mimxrt/modules/_boot.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
# Note: the flash requires the programming size to be aligned to 256 bytes.
44

55
import os
6+
import vfs
67
import sys
78
import mimxrt
89
from machine import Pin
910

1011
bdev = mimxrt.Flash()
1112
try:
12-
vfs = os.VfsLfs2(bdev, progsize=256)
13+
fs = vfs.VfsLfs2(bdev, progsize=256)
1314
except:
14-
os.VfsLfs2.mkfs(bdev, progsize=256)
15-
vfs = os.VfsLfs2(bdev, progsize=256)
16-
os.mount(vfs, "/flash")
15+
vfs.VfsLfs2.mkfs(bdev, progsize=256)
16+
fs = vfs.VfsLfs2(bdev, progsize=256)
17+
vfs.mount(fs, "/flash")
1718
os.chdir("/flash")
1819
sys.path.append("/flash")
1920
sys.path.append("/flash/lib")
@@ -27,8 +28,8 @@
2728

2829
sdcard = SDCard(1)
2930

30-
fat = os.VfsFat(sdcard)
31-
os.mount(fat, "/sdcard")
31+
fat = vfs.VfsFat(sdcard)
32+
vfs.mount(fat, "/sdcard")
3233
os.chdir("/sdcard")
3334
sys.path.append("/sdcard")
3435
except:

ports/nrf/examples/mountsd.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
---------------------------------
2121
"""
2222

23-
import os
23+
import os, vfs
2424
from machine import SPI, Pin
2525
from sdcard import SDCard
2626

2727

2828
def mnt():
2929
cs = Pin("P22", mode=Pin.OUT)
3030
sd = SDCard(SPI(0), cs)
31-
os.mount(sd, "/")
31+
vfs.mount(sd, "/")
3232

3333

3434
def list():

ports/nrf/examples/seeed_tft.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
tf = mount_tf()
4545
os.listdir()
4646
"""
47-
import os
47+
import vfs
4848
import time
4949
import framebuf
5050

@@ -54,7 +54,7 @@
5454

5555
def mount_tf(self, mount_point="/"):
5656
sd = SDCard(SPI(0), Pin("P15", mode=Pin.OUT))
57-
os.mount(sd, mount_point)
57+
vfs.mount(sd, mount_point)
5858

5959

6060
class ILI9341:

ports/nrf/modules/scripts/_mkfs.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import os, nrf
1+
import vfs, nrf
22

33
try:
4-
from os import VfsLfs1
4+
from vfs import VfsLfs1
55

6-
os.VfsLfs1.mkfs(nrf.Flash())
6+
vfs.VfsLfs1.mkfs(nrf.Flash())
77
except ImportError:
88
try:
9-
from os import VfsLfs2
9+
from vfs import VfsLfs2
1010

11-
os.VfsLfs2.mkfs(nrf.Flash())
11+
vfs.VfsLfs2.mkfs(nrf.Flash())
1212
except ImportError:
1313
try:
14-
from os import VfsFat
14+
from vfs import VfsFat
1515

16-
os.VfsFat.mkfs(nrf.Flash())
16+
vfs.VfsFat.mkfs(nrf.Flash())
1717
except ImportError:
1818
pass
1919
except OSError as e:

ports/rp2/modules/_boot.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import os
1+
import vfs
22
import machine, rp2
33

44

55
# Try to mount the filesystem, and format the flash if it doesn't exist.
66
# Note: the flash requires the programming size to be aligned to 256 bytes.
77
bdev = rp2.Flash()
88
try:
9-
vfs = os.VfsLfs2(bdev, progsize=256)
9+
fs = vfs.VfsLfs2(bdev, progsize=256)
1010
except:
11-
os.VfsLfs2.mkfs(bdev, progsize=256)
12-
vfs = os.VfsLfs2(bdev, progsize=256)
13-
os.mount(vfs, "/")
11+
vfs.VfsLfs2.mkfs(bdev, progsize=256)
12+
fs = vfs.VfsLfs2(bdev, progsize=256)
13+
vfs.mount(fs, "/")
1414

15-
del os, bdev, vfs
15+
del vfs, bdev, fs

ports/rp2/modules/_boot_fat.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import os
1+
import vfs
22
import machine, rp2
33

44

55
# Try to mount the filesystem, and format the flash if it doesn't exist.
66
bdev = rp2.Flash()
77
try:
8-
vfs = os.VfsFat(bdev)
9-
os.mount(vfs, "/")
8+
fs = vfs.VfsFat(bdev)
109
except:
11-
os.VfsFat.mkfs(bdev)
12-
vfs = os.VfsFat(bdev)
13-
os.mount(vfs, "/")
10+
vfs.VfsFat.mkfs(bdev)
11+
fs = vfs.VfsFat(bdev)
12+
vfs.mount(fs, "/")
1413

15-
del os, bdev, vfs
14+
del vfs, bdev, fs

ports/samd/modules/_boot.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import gc
2-
import os
2+
import vfs
33
import samd
44
import sys
55

66
bdev = samd.Flash()
77

88
# Try to mount the filesystem, and format the flash if it doesn't exist.
9-
fs_type = os.VfsLfs2 if hasattr(os, "VfsLfs2") else os.VfsLfs1
9+
fs_type = vfs.VfsLfs2 if hasattr(vfs, "VfsLfs2") else vfs.VfsLfs1
1010

1111
try:
12-
vfs = fs_type(bdev, progsize=256)
12+
fs = fs_type(bdev, progsize=256)
1313
except:
1414
fs_type.mkfs(bdev, progsize=256)
15-
vfs = fs_type(bdev, progsize=256)
16-
os.mount(vfs, "/")
15+
fs = fs_type(bdev, progsize=256)
16+
vfs.mount(fs, "/")
1717
sys.path.append("/lib")
1818

19-
del vfs, fs_type, bdev, os, samd, sys
19+
del fs, fs_type, bdev, vfs, samd, sys
2020
gc.collect()
2121
del gc

0 commit comments

Comments
 (0)