Skip to content

Commit e6766ee

Browse files
committed
tools/mpremote/romfs: Validate romfs image.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent 8f973d3 commit e6766ee

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tools/mpremote/mpremote/commands.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ def _do_romfs_deploy(state, args):
555555
romfs_filename = args.path
556556

557557
# Read in or create the ROMFS filesystem image.
558-
if romfs_filename.endswith(".romfs"):
558+
if os.path.isfile(romfs_filename):
559559
with open(romfs_filename, "rb") as f:
560560
romfs = f.read()
561561
else:
@@ -581,6 +581,12 @@ def _do_romfs_deploy(state, args):
581581
rom_size = transport.eval("len(dev)")
582582
print(f"ROMFS{rom_id} partition has size {rom_size} bytes")
583583

584+
# Check if ROMFS image is valid
585+
ROMFS_HEADER = b"\xd2\xcd\x31"
586+
if len(romfs) < 4 or not romfs.startswith(ROMFS_HEADER):
587+
print("Invalid ROMFS image")
588+
sys.exit(1)
589+
584590
# Check if ROMFS filesystem image will fit in the target partition.
585591
if len(romfs) > rom_size:
586592
print("ROMFS image is too big for the target partition")

0 commit comments

Comments
 (0)