openmv/scripts/libraries/romfs.py
iabdalkader cf571aec92 scripts/libraries: Add romfs util.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-03-30 08:26:41 +02:00

27 lines
970 B
Python

import os
import uctypes
def ls_romfs():
# Define possible alignment sizes in descending order
alignments = [128, 64, 32, 16, 8, 4]
for fname in os.listdir("/rom"):
with open("/rom/" + fname, "rb") as file:
address = uctypes.addressof(file) & 0xFFFFFFF
size = len(memoryview(file))
aligned = False
# Check alignment for each size, starting from the highest alignment
for alignment in alignments:
if address % alignment == 0:
print(
f"addr: 0x{address:08X} size: {size:<8} alignment: {alignment:<4} name: {fname}"
)
aligned = True
break
# If not aligned to any of the specified sizes
if not aligned:
print(
f"addr: 0x{address:08X} size: {size:<8} alignment: NOT aligned name: {fname}"
)