mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-20 17:52:35 +00:00
51
bin/mklittlefs.py
Executable file
51
bin/mklittlefs.py
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
import getopt
|
||||
import sys
|
||||
import os
|
||||
from littlefs import LittleFS
|
||||
from pathlib import Path
|
||||
|
||||
print( "Building LittleFS image..." )
|
||||
|
||||
argList = sys.argv[1:]
|
||||
arxx = { argList[i]: argList[i+1] for i in range(0, len(argList)-1, 2) }
|
||||
|
||||
dataPath = arxx["-c"]
|
||||
blockSize = int(arxx["-b"])
|
||||
blockCount = int(arxx["-s"]) / blockSize
|
||||
|
||||
cwd = os.getcwd()
|
||||
|
||||
os.chdir(dataPath)
|
||||
|
||||
fileList = []
|
||||
dirList = []
|
||||
|
||||
for (dirpath, dirnames, filenames) in os.walk('.'):
|
||||
for f in filenames:
|
||||
if (f[:1] != '.'):
|
||||
fileList.append( os.path.join(dirpath, f) )
|
||||
for d in dirnames:
|
||||
if (d[:1] != '.'):
|
||||
dirList.append( os.path.join(dirpath, d) )
|
||||
|
||||
fs = LittleFS(block_size=blockSize, block_count=blockCount) # create a 448kB partition
|
||||
|
||||
for curDir in dirList:
|
||||
print( "Creating dir " + curDir )
|
||||
fs.mkdir( curDir )
|
||||
|
||||
for curFile in fileList:
|
||||
print( "Adding file " + curFile )
|
||||
with open( curFile, 'rb' ) as f:
|
||||
data = f.read()
|
||||
|
||||
with fs.open( curFile, 'wb') as fh:
|
||||
fh.write( data )
|
||||
|
||||
outName = argList[-1]
|
||||
|
||||
os.chdir(cwd)
|
||||
|
||||
with open(outName, 'wb') as fh:
|
||||
fh.write(fs.context.buffer)
|
||||
Reference in New Issue
Block a user