Skip to content

Commit 0ebaad2

Browse files
VynDragondpgeorge
authored andcommitted
zephyr/modules: Add Zephyr FileSystem support to _boot.py.
Signed-off-by: Vdragon <mail@massdriver.space>
1 parent a40aba3 commit 0ebaad2

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

ports/zephyr/modules/_boot.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,39 @@
1111
# DiskAccess depends on CONFIG_DISK_ACCESS
1212
DiskAccess = getattr(zephyr, "DiskAccess", None)
1313

14+
# zephyr.FileSystem depends on CONFIG_FILE_SYSTEM and CONFIG_FLASH_MAP
15+
FileSystem = getattr(zephyr, "FileSystem", None)
16+
1417
_FLASH = const("/flash")
1518
_FLASH_LIB = const("/flash/lib")
1619
_STORAGE_KEY = const("storage")
1720
_FLASH_EXISTS = False
1821

1922

23+
def mount_filesystem_flash():
24+
"""Create a filesystem if needed on the FS partition "/flash"
25+
and mount it on /flash.
26+
Return True if successful, False otherwise.
27+
"""
28+
if _FLASH in FileSystem.fstab():
29+
fs = FileSystem(_FLASH)
30+
retval = True
31+
try:
32+
vfs.mount(fs, _FLASH)
33+
except OSError:
34+
if getattr(fs, "mkfs", None):
35+
try:
36+
fs.mkfs()
37+
vfs.mount(fs, _FLASH)
38+
except OSError:
39+
print("Error formatting flash partition")
40+
retval = False
41+
else:
42+
retval = False
43+
return retval
44+
return False
45+
46+
2047
def create_flash_partition():
2148
"""Create an LFS2 filesystem on the partition labeled storage
2249
and mount it on /flash.
@@ -54,7 +81,10 @@ def mount_all_disks():
5481
return retval
5582

5683

57-
if FlashArea and create_flash_partition():
84+
# Prefer FileSystem over FlashArea Access
85+
if FileSystem and mount_filesystem_flash():
86+
_FLASH_EXISTS = True
87+
elif FlashArea and create_flash_partition():
5888
_FLASH_EXISTS = True
5989

6090
# Prefer disks to /flash
@@ -67,6 +97,6 @@ def mount_all_disks():
6797
sys.path.append(_FLASH_LIB)
6898

6999
# Cleanup globals for boot.py/main.py
70-
del FlashArea, DiskAccess, zephyr
100+
del FlashArea, DiskAccess, FileSystem, zephyr
71101
del sys, vfs, os, const
72-
del create_flash_partition, mount_all_disks, _FLASH_EXISTS
102+
del mount_filesystem_flash, create_flash_partition, mount_all_disks, _FLASH_EXISTS

0 commit comments

Comments
 (0)