From 196d5be280080fd6086ad60f7bb06c163968bf70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Tue, 27 Oct 2020 00:00:01 +0000 Subject: [PATCH] Allow a custom disk image --- common.py | 16 ++++++++++------ run | 9 ++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/common.py b/common.py index 3042c55..6c52743 100644 --- a/common.py +++ b/common.py @@ -243,6 +243,9 @@ Enable or disable ccache: https://cirosantilli.com/linux-kernel-module-cheat#cca To have some fun when the kernel starts to beat you. ''' ) + self.add_argument( + '--disk-image', + ) self.add_argument( '--dry-run', default=False, @@ -1216,13 +1219,14 @@ Incompatible archs are skipped. env['image_elf'] = env['vmlinux'] if env['_args_given']['linux_exec']: env['image'] = env['linux_exec'] - if env['emulator'] == 'gem5': - if env['ramfs']: - env['disk_image'] = None + if not env['_args_given']['disk_image']: + if env['emulator'] == 'gem5': + if env['ramfs']: + env['disk_image'] = None + else: + env['disk_image'] = env['rootfs_raw_file'] else: - env['disk_image'] = env['rootfs_raw_file'] - else: - env['disk_image'] = env['qcow2_file'] + env['disk_image'] = env['qcow2_file'] # Android if not env['_args_given']['android_base_dir']: diff --git a/run b/run index 5bba8ff..4e34f5f 100755 --- a/run +++ b/run @@ -521,6 +521,8 @@ Extra options to append at the end of the emulator command line. use_disk_image = self.env['disk_image'] is not None and \ os.path.exists(self.env['disk_image']) or \ not self.env['baremetal'] + if self.env['_args_given']['disk_image'] and not os.path.exists(self.env['disk_image']) : + raise_rootfs_not_found() if self.env['emulator'] == 'gem5': if self.env['quiet']: show_stdout = False @@ -827,10 +829,15 @@ Extra options to append at the end of the emulator command line. '-device', 'ide-hd,drive=img-blkreplay', LF, ]) if use_disk_image: + if os.path.splitext(self.env['disk_image'])[1] == '.qcow2': + disk_format = 'qcow2' + else: + disk_format = 'raw' extra_emulator_args.extend([ '-drive', - 'file={},format=qcow2,if={}{}{}'.format( + 'file={},format={},if={}{}{}'.format( self.env['disk_image'], + disk_format, driveif, snapshot, rrid