Skip to content

Commit 42ffd06

Browse files
JPEWdevEmantor
authored andcommitted
driver/usbstoragedriver: Copy bitmap when using bmaptool
bmaptool requires that a bitmap be provided or it will fail (unless --nobmap is passed). Therefore, discover the bmap file that lives along side the image file and pass it to bmaptool. The bitmap file is explicitly passed to bmaptool so that it is not dependent on being along side the image file when copied remotely. Signed-off-by: Joshua Watt <[email protected]>
1 parent 20d6c60 commit 42ffd06

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

labgrid/driver/usbstoragedriver.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,35 @@ def write_image(self, filename=None, mode=Mode.DD, partition=None, skip=0, seek=
104104
elif mode == Mode.BMAPTOOL:
105105
if skip or seek:
106106
raise ExecutionError("bmaptool does not support skip or seek")
107+
108+
# Try to find a block map file using the same logic that bmaptool
109+
# uses. Handles cases where the image is named like: <image>.bz2
110+
# and the block map file is <image>.bmap
111+
mf_bmap = None
112+
image_path = filename
113+
while True:
114+
bmap_path = "{}.bmap".format(image_path)
115+
if os.path.exists(bmap_path):
116+
mf_bmap = ManagedFile(bmap_path, self.storage)
117+
mf_bmap.sync_to_resource()
118+
break
119+
120+
image_path, ext = os.path.splitext(image_path)
121+
if not ext:
122+
break
123+
107124
self.logger.info('Writing %s to %s using bmaptool.', remote_path, target)
108125
args = [
109126
"bmaptool",
110127
"copy",
111128
"{}".format(remote_path),
112129
"{}".format(target),
113130
]
131+
132+
if mf_bmap is None:
133+
args.append("--nobmap")
134+
else:
135+
args.append("--bmap={}".format(mf_bmap.get_remote_path()))
114136
else:
115137
raise ValueError
116138

0 commit comments

Comments
 (0)