mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 00:50:24 +08:00
ports: Use vfs module instead of os.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
b87bbaeb43
commit
7d28789544
@ -1,13 +1,13 @@
|
|||||||
import gc
|
import gc
|
||||||
import os
|
import vfs
|
||||||
from flashbdev import bdev
|
from flashbdev import bdev
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if bdev:
|
if bdev:
|
||||||
os.mount(bdev, "/")
|
vfs.mount(bdev, "/")
|
||||||
except OSError:
|
except OSError:
|
||||||
import inisetup
|
import inisetup
|
||||||
|
|
||||||
vfs = inisetup.setup()
|
inisetup.setup()
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import os
|
import vfs
|
||||||
from flashbdev import bdev
|
from flashbdev import bdev
|
||||||
|
|
||||||
|
|
||||||
@ -38,12 +38,12 @@ def setup():
|
|||||||
check_bootsec()
|
check_bootsec()
|
||||||
print("Performing initial setup")
|
print("Performing initial setup")
|
||||||
if bdev.info()[4] == "vfs":
|
if bdev.info()[4] == "vfs":
|
||||||
os.VfsLfs2.mkfs(bdev)
|
vfs.VfsLfs2.mkfs(bdev)
|
||||||
vfs = os.VfsLfs2(bdev)
|
fs = vfs.VfsLfs2(bdev)
|
||||||
elif bdev.info()[4] == "ffat":
|
elif bdev.info()[4] == "ffat":
|
||||||
os.VfsFat.mkfs(bdev)
|
vfs.VfsFat.mkfs(bdev)
|
||||||
vfs = os.VfsFat(bdev)
|
fs = vfs.VfsFat(bdev)
|
||||||
os.mount(vfs, "/")
|
vfs.mount(fs, "/")
|
||||||
with open("boot.py", "w") as f:
|
with open("boot.py", "w") as f:
|
||||||
f.write(
|
f.write(
|
||||||
"""\
|
"""\
|
||||||
@ -54,4 +54,4 @@ def setup():
|
|||||||
#webrepl.start()
|
#webrepl.start()
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
return vfs
|
return fs
|
||||||
|
@ -13,7 +13,7 @@ Note: v1.12-334 and newer (including v1.13) require an ESP8266 module with
|
|||||||
2MiB of flash or more, and use littlefs as the filesystem by default. When
|
2MiB of flash or more, and use littlefs as the filesystem by default. When
|
||||||
upgrading from older firmware please backup your files first, and either
|
upgrading from older firmware please backup your files first, and either
|
||||||
erase all flash before upgrading, or after upgrading execute
|
erase all flash before upgrading, or after upgrading execute
|
||||||
`os.VfsLfs2.mkfs(bdev)`.
|
`vfs.VfsLfs2.mkfs(bdev)`.
|
||||||
|
|
||||||
### OTA builds
|
### OTA builds
|
||||||
Over-The-Air (OTA) builds of the ESP8266 firmware are also provided.
|
Over-The-Air (OTA) builds of the ESP8266 firmware are also provided.
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import gc
|
import gc
|
||||||
|
|
||||||
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
|
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
|
||||||
import os
|
import vfs
|
||||||
from flashbdev import bdev
|
from flashbdev import bdev
|
||||||
|
|
||||||
if bdev:
|
if bdev:
|
||||||
try:
|
try:
|
||||||
os.mount(bdev, "/")
|
vfs.mount(bdev, "/")
|
||||||
except:
|
except:
|
||||||
import inisetup
|
import inisetup
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import os
|
import vfs
|
||||||
import network
|
import network
|
||||||
from flashbdev import bdev
|
from flashbdev import bdev
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ def fs_corrupted():
|
|||||||
"""\
|
"""\
|
||||||
The filesystem starting at sector %d with size %d sectors looks corrupt.
|
The filesystem starting at sector %d with size %d sectors looks corrupt.
|
||||||
You may want to make a flash snapshot and try to recover it. Otherwise,
|
You may want to make a flash snapshot and try to recover it. Otherwise,
|
||||||
format it with os.VfsLfs2.mkfs(bdev), or completely erase the flash and
|
format it with vfs.VfsLfs2.mkfs(bdev), or completely erase the flash and
|
||||||
reprogram MicroPython.
|
reprogram MicroPython.
|
||||||
"""
|
"""
|
||||||
% (bdev.start_sec, bdev.blocks)
|
% (bdev.start_sec, bdev.blocks)
|
||||||
@ -48,9 +48,9 @@ def setup():
|
|||||||
check_bootsec()
|
check_bootsec()
|
||||||
print("Performing initial setup")
|
print("Performing initial setup")
|
||||||
wifi()
|
wifi()
|
||||||
os.VfsLfs2.mkfs(bdev)
|
vfs.VfsLfs2.mkfs(bdev)
|
||||||
vfs = os.VfsLfs2(bdev)
|
fs = vfs.VfsLfs2(bdev)
|
||||||
os.mount(vfs, "/")
|
vfs.mount(fs, "/")
|
||||||
with open("boot.py", "w") as f:
|
with open("boot.py", "w") as f:
|
||||||
f.write(
|
f.write(
|
||||||
"""\
|
"""\
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
# format.py
|
# format.py
|
||||||
# Re-create the file system
|
# Re-create the file system
|
||||||
|
|
||||||
import os
|
import vfs
|
||||||
import mimxrt
|
import mimxrt
|
||||||
|
|
||||||
bdev = mimxrt.Flash()
|
bdev = mimxrt.Flash()
|
||||||
|
|
||||||
os.VfsLfs2.mkfs(bdev, progsize=256)
|
vfs.VfsLfs2.mkfs(bdev, progsize=256)
|
||||||
vfs = os.VfsLfs2(bdev, progsize=256)
|
fs = vfs.VfsLfs2(bdev, progsize=256)
|
||||||
os.mount(vfs, "/")
|
vfs.mount(fs, "/")
|
||||||
|
@ -3,17 +3,18 @@
|
|||||||
# Note: the flash requires the programming size to be aligned to 256 bytes.
|
# Note: the flash requires the programming size to be aligned to 256 bytes.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import vfs
|
||||||
import sys
|
import sys
|
||||||
import mimxrt
|
import mimxrt
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
|
|
||||||
bdev = mimxrt.Flash()
|
bdev = mimxrt.Flash()
|
||||||
try:
|
try:
|
||||||
vfs = os.VfsLfs2(bdev, progsize=256)
|
fs = vfs.VfsLfs2(bdev, progsize=256)
|
||||||
except:
|
except:
|
||||||
os.VfsLfs2.mkfs(bdev, progsize=256)
|
vfs.VfsLfs2.mkfs(bdev, progsize=256)
|
||||||
vfs = os.VfsLfs2(bdev, progsize=256)
|
fs = vfs.VfsLfs2(bdev, progsize=256)
|
||||||
os.mount(vfs, "/flash")
|
vfs.mount(fs, "/flash")
|
||||||
os.chdir("/flash")
|
os.chdir("/flash")
|
||||||
sys.path.append("/flash")
|
sys.path.append("/flash")
|
||||||
sys.path.append("/flash/lib")
|
sys.path.append("/flash/lib")
|
||||||
@ -27,8 +28,8 @@ except:
|
|||||||
|
|
||||||
sdcard = SDCard(1)
|
sdcard = SDCard(1)
|
||||||
|
|
||||||
fat = os.VfsFat(sdcard)
|
fat = vfs.VfsFat(sdcard)
|
||||||
os.mount(fat, "/sdcard")
|
vfs.mount(fat, "/sdcard")
|
||||||
os.chdir("/sdcard")
|
os.chdir("/sdcard")
|
||||||
sys.path.append("/sdcard")
|
sys.path.append("/sdcard")
|
||||||
except:
|
except:
|
||||||
|
@ -20,7 +20,7 @@ Direct wiring on SD card (SPI):
|
|||||||
---------------------------------
|
---------------------------------
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os, vfs
|
||||||
from machine import SPI, Pin
|
from machine import SPI, Pin
|
||||||
from sdcard import SDCard
|
from sdcard import SDCard
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ from sdcard import SDCard
|
|||||||
def mnt():
|
def mnt():
|
||||||
cs = Pin("P22", mode=Pin.OUT)
|
cs = Pin("P22", mode=Pin.OUT)
|
||||||
sd = SDCard(SPI(0), cs)
|
sd = SDCard(SPI(0), cs)
|
||||||
os.mount(sd, "/")
|
vfs.mount(sd, "/")
|
||||||
|
|
||||||
|
|
||||||
def list():
|
def list():
|
||||||
|
@ -44,7 +44,7 @@ Example usage of SD card reader:
|
|||||||
tf = mount_tf()
|
tf = mount_tf()
|
||||||
os.listdir()
|
os.listdir()
|
||||||
"""
|
"""
|
||||||
import os
|
import vfs
|
||||||
import time
|
import time
|
||||||
import framebuf
|
import framebuf
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ from sdcard import SDCard
|
|||||||
|
|
||||||
def mount_tf(self, mount_point="/"):
|
def mount_tf(self, mount_point="/"):
|
||||||
sd = SDCard(SPI(0), Pin("P15", mode=Pin.OUT))
|
sd = SDCard(SPI(0), Pin("P15", mode=Pin.OUT))
|
||||||
os.mount(sd, mount_point)
|
vfs.mount(sd, mount_point)
|
||||||
|
|
||||||
|
|
||||||
class ILI9341:
|
class ILI9341:
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
import os, nrf
|
import vfs, nrf
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from os import VfsLfs1
|
from vfs import VfsLfs1
|
||||||
|
|
||||||
os.VfsLfs1.mkfs(nrf.Flash())
|
vfs.VfsLfs1.mkfs(nrf.Flash())
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from os import VfsLfs2
|
from vfs import VfsLfs2
|
||||||
|
|
||||||
os.VfsLfs2.mkfs(nrf.Flash())
|
vfs.VfsLfs2.mkfs(nrf.Flash())
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from os import VfsFat
|
from vfs import VfsFat
|
||||||
|
|
||||||
os.VfsFat.mkfs(nrf.Flash())
|
vfs.VfsFat.mkfs(nrf.Flash())
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import os
|
import vfs
|
||||||
import machine, rp2
|
import machine, rp2
|
||||||
|
|
||||||
|
|
||||||
@ -6,10 +6,10 @@ import machine, rp2
|
|||||||
# Note: the flash requires the programming size to be aligned to 256 bytes.
|
# Note: the flash requires the programming size to be aligned to 256 bytes.
|
||||||
bdev = rp2.Flash()
|
bdev = rp2.Flash()
|
||||||
try:
|
try:
|
||||||
vfs = os.VfsLfs2(bdev, progsize=256)
|
fs = vfs.VfsLfs2(bdev, progsize=256)
|
||||||
except:
|
except:
|
||||||
os.VfsLfs2.mkfs(bdev, progsize=256)
|
vfs.VfsLfs2.mkfs(bdev, progsize=256)
|
||||||
vfs = os.VfsLfs2(bdev, progsize=256)
|
fs = vfs.VfsLfs2(bdev, progsize=256)
|
||||||
os.mount(vfs, "/")
|
vfs.mount(fs, "/")
|
||||||
|
|
||||||
del os, bdev, vfs
|
del vfs, bdev, fs
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import os
|
import vfs
|
||||||
import machine, rp2
|
import machine, rp2
|
||||||
|
|
||||||
|
|
||||||
# Try to mount the filesystem, and format the flash if it doesn't exist.
|
# Try to mount the filesystem, and format the flash if it doesn't exist.
|
||||||
bdev = rp2.Flash()
|
bdev = rp2.Flash()
|
||||||
try:
|
try:
|
||||||
vfs = os.VfsFat(bdev)
|
fs = vfs.VfsFat(bdev)
|
||||||
os.mount(vfs, "/")
|
|
||||||
except:
|
except:
|
||||||
os.VfsFat.mkfs(bdev)
|
vfs.VfsFat.mkfs(bdev)
|
||||||
vfs = os.VfsFat(bdev)
|
fs = vfs.VfsFat(bdev)
|
||||||
os.mount(vfs, "/")
|
vfs.mount(fs, "/")
|
||||||
|
|
||||||
del os, bdev, vfs
|
del vfs, bdev, fs
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
import gc
|
import gc
|
||||||
import os
|
import vfs
|
||||||
import samd
|
import samd
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
bdev = samd.Flash()
|
bdev = samd.Flash()
|
||||||
|
|
||||||
# Try to mount the filesystem, and format the flash if it doesn't exist.
|
# Try to mount the filesystem, and format the flash if it doesn't exist.
|
||||||
fs_type = os.VfsLfs2 if hasattr(os, "VfsLfs2") else os.VfsLfs1
|
fs_type = vfs.VfsLfs2 if hasattr(vfs, "VfsLfs2") else vfs.VfsLfs1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vfs = fs_type(bdev, progsize=256)
|
fs = fs_type(bdev, progsize=256)
|
||||||
except:
|
except:
|
||||||
fs_type.mkfs(bdev, progsize=256)
|
fs_type.mkfs(bdev, progsize=256)
|
||||||
vfs = fs_type(bdev, progsize=256)
|
fs = fs_type(bdev, progsize=256)
|
||||||
os.mount(vfs, "/")
|
vfs.mount(fs, "/")
|
||||||
sys.path.append("/lib")
|
sys.path.append("/lib")
|
||||||
|
|
||||||
del vfs, fs_type, bdev, os, samd, sys
|
del fs, fs_type, bdev, vfs, samd, sys
|
||||||
gc.collect()
|
gc.collect()
|
||||||
del gc
|
del gc
|
||||||
|
Loading…
Reference in New Issue
Block a user