Skip to content

Commit 9e9be83

Browse files
iabdalkaderdpgeorge
authored andcommitted
tools/mpremote: Allow .img for ROMFS file and validate ROMFS image.
Currently the tool allows writing an invalid ROMFS image, with a bad header or images smaller than minimum size, and only checks the image extension. This commit allows deploying a ROMFS with either a ".img" or ".romfs" extension (in the future support may be added for other extensions that have different semantics, eg a manifest), and validates the image header before writing. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent 74a5bf9 commit 9e9be83

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/mpremote/mpremote/commands.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .transport import TransportError, TransportExecError, stdout_write_bytes
1111
from .transport_serial import SerialTransport
12-
from .romfs import make_romfs
12+
from .romfs import make_romfs, VfsRomWriter
1313

1414

1515
class CommandError(Exception):
@@ -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) and romfs_filename.endswith((".img", ".romfs")):
559559
with open(romfs_filename, "rb") as f:
560560
romfs = f.read()
561561
else:
@@ -581,6 +581,11 @@ 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+
if not romfs.startswith(VfsRomWriter.ROMFS_HEADER):
586+
print("Invalid ROMFS image")
587+
sys.exit(1)
588+
584589
# Check if ROMFS filesystem image will fit in the target partition.
585590
if len(romfs) > rom_size:
586591
print("ROMFS image is too big for the target partition")

0 commit comments

Comments
 (0)