summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/wic/engine.py63
-rwxr-xr-xscripts/runqemu27
2 files changed, 18 insertions, 72 deletions
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index 9d596be3a7..b9e60cbe4e 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -345,64 +345,29 @@ class Disk:
345 path)) 345 path))
346 346
347 def copy(self, src, dest): 347 def copy(self, src, dest):
348 """Copy files or directories to/from the vfat or ext* partition.""" 348 """Copy partition image into wic image."""
349 pnum = dest.part if isinstance(src, str) else src.part 349 pnum = dest.part if isinstance(src, str) else src.part
350 partimg = self._get_part_image(pnum)
351 350
352 if self.partitions[pnum].fstype.startswith('ext'): 351 if self.partitions[pnum].fstype.startswith('ext'):
353 if isinstance(src, str): # host to image case 352 if isinstance(src, str):
354 if os.path.isdir(src): 353 cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
355 base = os.path.abspath(src) 354 format(os.path.dirname(dest.path), src, os.path.basename(src),
356 base_parent = os.path.dirname(base) 355 self.debugfs, self._get_part_image(pnum))
357 cmds = [] 356 else: # copy from wic
358 made = set() 357 # run both dump and rdump to support both files and directory
359
360 for root, dirs, files in os.walk(base):
361 for fname in files:
362 host_file = os.path.join(root, fname)
363 rel = os.path.relpath(host_file, base_parent)
364 dest_file = os.path.join(dest.path, rel)
365 dest_dir = os.path.dirname(dest_file)
366
367 # create dir structure (mkdir -p)
368 parts = dest_dir.strip('/').split('/')
369 cur = ''
370 for p in parts:
371 cur = cur + '/' + p
372 if cur not in made:
373 cmds.append(f'mkdir "{cur}"')
374 made.add(cur)
375
376 cmds.append(f'write "{host_file}" "{dest_file}"')
377
378 # write script to a temp file
379 with tempfile.NamedTemporaryFile(mode='w', delete=False,
380 prefix='wic-debugfs-') as tf:
381 for line in cmds:
382 tf.write(line + '\n')
383 scriptname = tf.name
384
385 cmd = f"{self.debugfs} -w -f {scriptname} {partimg}"
386
387 else: # single file
388 cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
389 format(os.path.dirname(dest.path), src,
390 os.path.basename(src), self.debugfs, partimg)
391
392 else: # image to host case
393 cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\ 358 cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
394 format(os.path.dirname(src.path), src.path, 359 format(os.path.dirname(src.path), src.path,
395 dest, src.path, dest, self.debugfs, partimg) 360 dest, src.path, dest, self.debugfs,
396 361 self._get_part_image(pnum))
397 else: # fat 362 else: # fat
398 if isinstance(src, str): 363 if isinstance(src, str):
399 cmd = "{} -i {} -snop {} ::{}".format(self.mcopy, 364 cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
400 partimg, 365 self._get_part_image(pnum),
401 src, dest.path) 366 src, dest.path)
402 else: 367 else:
403 cmd = "{} -i {} -snop ::{} {}".format(self.mcopy, 368 cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
404 partimg, 369 self._get_part_image(pnum),
405 src.path, dest) 370 src.path, dest)
406 371
407 exec_cmd(cmd, as_shell=True) 372 exec_cmd(cmd, as_shell=True)
408 self._put_part_image(pnum) 373 self._put_part_image(pnum)
diff --git a/scripts/runqemu b/scripts/runqemu
index 4bac151ccf..c28980e616 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -421,27 +421,8 @@ class BaseConfig(object):
421 else: 421 else:
422 raise RunQemuError("Unknown path arg %s" % p) 422 raise RunQemuError("Unknown path arg %s" % p)
423 423
424 def rootfs_fixups(self): 424 def uncompress_rootfs(self):
425 425 """Decompress ZST rootfs image if needed"""
426 """Decompress and/or resize the rootfs image, if needed"""
427 qb_rootfs_opt = self.get('QB_ROOTFS_OPT')
428
429 # Check if sdcard size is a power of 2, as that is currently a requirement for qemu
430 # See https://gitlab.com/qemu-project/qemu/-/issues/1754
431 rootfs_size = os.path.getsize(self.rootfs)
432 rootfs_size_pwr2 = 1 << (rootfs_size - 1).bit_length()
433 if ("if=sd" in qb_rootfs_opt or "if=pflash" in qb_rootfs_opt) and rootfs_size != rootfs_size_pwr2:
434 logger.info("Using sd-card or pflash and is not power of 2. File size %d, power of 2 size %d" %(rootfs_size, rootfs_size_pwr2))
435 logger.info("Attempting to use truncate to correct this.")
436
437 # Ensure the 'truncate' tool is installed before attempting to make a power of 2.
438 if not shutil.which('truncate'):
439 raise RunQemuError(f"'truncate' is required to make {self.rootfs} a power of 2 in size but was not found in PATH")
440 try:
441 subprocess.check_call(['truncate', '-s', str(rootfs_size_pwr2), self.rootfs])
442 except subprocess.CalledProcessError as e:
443 raise RunQemuError(f"Failed to make {self.rootfs} power of 2 in size: {e}")
444
445 if not self.rootfs or not self.fstype.endswith('.zst'): 426 if not self.rootfs or not self.fstype.endswith('.zst'):
446 return 427 return
447 428
@@ -903,7 +884,7 @@ to your build configuration.
903 self.set('QB_MEM', qb_mem) 884 self.set('QB_MEM', qb_mem)
904 885
905 mach = self.get('MACHINE') 886 mach = self.get('MACHINE')
906 if not mach.startswith(('qemumips', 'qemux86', 'qemuloongarch64')) and self.get('QB_DTB') == "": 887 if not mach.startswith(('qemumips', 'qemux86', 'qemuloongarch64')):
907 self.kernel_cmdline_script += ' mem=%s' % self.get('QB_MEM').replace('-m','').strip() + 'M' 888 self.kernel_cmdline_script += ' mem=%s' % self.get('QB_MEM').replace('-m','').strip() + 'M'
908 889
909 self.qemu_opt_script += ' %s' % self.get('QB_MEM') 890 self.qemu_opt_script += ' %s' % self.get('QB_MEM')
@@ -1828,7 +1809,7 @@ def main():
1828 config.check_args() 1809 config.check_args()
1829 config.read_qemuboot() 1810 config.read_qemuboot()
1830 config.check_and_set() 1811 config.check_and_set()
1831 config.rootfs_fixups() 1812 config.uncompress_rootfs()
1832 # Check whether the combos is valid or not 1813 # Check whether the combos is valid or not
1833 config.validate_combos() 1814 config.validate_combos()
1834 config.print_config() 1815 config.print_config()