From cf571aec9236dd0fbe62a081919dd1ad0ba4b8cc Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 29 Mar 2025 19:33:57 +0100 Subject: [PATCH] scripts/libraries: Add romfs util. Signed-off-by: iabdalkader --- scripts/libraries/romfs.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 scripts/libraries/romfs.py diff --git a/scripts/libraries/romfs.py b/scripts/libraries/romfs.py new file mode 100644 index 000000000..5c775f70d --- /dev/null +++ b/scripts/libraries/romfs.py @@ -0,0 +1,26 @@ +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}" + )