Added lfs generation tool
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 12s
This commit is contained in:
2
firmware/tools/littlefs_generator/.gitignore
vendored
Normal file
2
firmware/tools/littlefs_generator/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*hex
|
||||
source_folder/
|
||||
59
firmware/tools/littlefs_generator/generate_littlefs.py
Normal file
59
firmware/tools/littlefs_generator/generate_littlefs.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import os
|
||||
from littlefs import LittleFS
|
||||
from intelhex import IntelHex
|
||||
|
||||
# Konfiguration basierend auf Ihren neuen Log-Daten
|
||||
BLOCK_SIZE = 4096 # 0x1000
|
||||
BLOCK_COUNT = 2048 # 8 MB Gesamtgröße
|
||||
START_ADDR = 0x12000000
|
||||
|
||||
fs = LittleFS(
|
||||
block_size=BLOCK_SIZE,
|
||||
block_count=BLOCK_COUNT,
|
||||
read_size=16,
|
||||
prog_size=16,
|
||||
lookahead_size=32,
|
||||
cache_size=64
|
||||
)
|
||||
|
||||
def add_files_recursive(local_path, lfs_path='/'):
|
||||
if not os.path.exists(local_path):
|
||||
print(f"Warnung: {local_path} nicht gefunden.")
|
||||
return
|
||||
for item in os.listdir(local_path):
|
||||
full_path = os.path.join(local_path, item)
|
||||
target_path = os.path.join(lfs_path, item).replace("\\", "/")
|
||||
|
||||
if os.path.isfile(full_path):
|
||||
print(f"Adding {target_path}...")
|
||||
with open(full_path, 'rb') as f:
|
||||
with fs.open(target_path, 'wb') as lfs_file:
|
||||
lfs_file.write(f.read())
|
||||
elif os.path.isdir(full_path):
|
||||
fs.mkdir(target_path)
|
||||
add_files_recursive(full_path, target_path)
|
||||
|
||||
# 1. Image im RAM befüllen
|
||||
add_files_recursive('./source_folder')
|
||||
|
||||
# 2. "Löchriges" (Sparse) iHEX erstellen
|
||||
ih = IntelHex()
|
||||
lfs_buffer = fs.context.buffer
|
||||
|
||||
print("Analysiere Blöcke für Sparse-Export...")
|
||||
blocks_written = 0
|
||||
|
||||
for i in range(BLOCK_COUNT):
|
||||
offset = i * BLOCK_SIZE
|
||||
block_data = lfs_buffer[offset : offset + BLOCK_SIZE]
|
||||
|
||||
# Ein Block wird nur in das HEX-File aufgenommen, wenn er nicht leer (0xFF) ist
|
||||
# LittleFS markiert gelöschte/unbenutzte Blöcke mit 0xFF
|
||||
if any(b != 0xFF for b in block_data):
|
||||
ih.frombytes(block_data, offset=START_ADDR + offset)
|
||||
blocks_written += 1
|
||||
|
||||
ih.tofile('lfs_external_flash.hex', format='hex')
|
||||
|
||||
print(f"Fertig! {blocks_written}/{BLOCK_COUNT} Blöcke ins HEX geschrieben.")
|
||||
print(f"Effektive Größe im HEX: {blocks_written * BLOCK_SIZE / 1024:.1f} KB")
|
||||
2
firmware/tools/littlefs_generator/requirements.txt
Normal file
2
firmware/tools/littlefs_generator/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
littlefs-python
|
||||
intelhex
|
||||
Reference in New Issue
Block a user