1111# DiskAccess depends on CONFIG_DISK_ACCESS
1212DiskAccess = 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+
2047def 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
71101del 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