scripts: Move some QEMU-arg building into build_helper
Providing a kernel, initrd and related options are useful in the EFI app too, so move them into the common code. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -152,6 +152,7 @@ class BuildEfi:
|
||||
cmd = [qemu]
|
||||
cmd += '-m', mem
|
||||
cmd += '-nic', 'none'
|
||||
self.helper.add_qemu_args(self.args, cmd)
|
||||
cmd += extra
|
||||
tout.info(' '.join(cmd))
|
||||
command.run(*cmd)
|
||||
|
||||
@@ -41,18 +41,12 @@ def parse_args():
|
||||
description='Build and/or run U-Boot with QEMU',
|
||||
formatter_class=argparse.RawTextHelpFormatter)
|
||||
build_helper.add_common_args(parser)
|
||||
parser.add_argument('-C', '--enable-console', action='store_true',
|
||||
help="Enable linux console (x86 only)")
|
||||
parser.add_argument('-D', '--share-dir', metavar='DIR',
|
||||
help='Directory to share into the guest via virtiofs')
|
||||
parser.add_argument('-e', '--sct-run', action='store_true',
|
||||
help='Run UEFI Self-Certification Test (SCT)')
|
||||
parser.add_argument('-E', '--use-tianocore', action='store_true',
|
||||
help='Run Tianocore (OVMF) instead of U-Boot')
|
||||
parser.add_argument('-I', '--initrd',
|
||||
help='Initial ramdisk to run using -initrd')
|
||||
parser.add_argument('-K', '--kernel',
|
||||
help='Kernel to run using -kernel')
|
||||
parser.add_argument('-Q', '--use-qboot', action='store_true',
|
||||
help='Run qboot instead of U-Boot')
|
||||
parser.add_argument('-x', '--xpl', action='store_true',
|
||||
@@ -60,12 +54,6 @@ def parse_args():
|
||||
parser.add_argument(
|
||||
'-S', '--sct-seq',
|
||||
help='SCT sequence-file to be written into the SCT image if -e')
|
||||
parser.add_argument(
|
||||
'-t', '--root',
|
||||
help='Pass the given root device to linux via root=xxx')
|
||||
parser.add_argument(
|
||||
'-U', '--uuid',
|
||||
help='Pass the given root device to linux via root=/dev/disk/by-uuid/')
|
||||
parser.add_argument('-v', '--verbose', action='store_true',
|
||||
help='Show executed commands')
|
||||
|
||||
@@ -282,8 +270,6 @@ class BuildQemu:
|
||||
if not self.bios.exists():
|
||||
tout.fatal(f"Error: BIOS file '{self.bios}' not found")
|
||||
|
||||
cmdline = []
|
||||
|
||||
qemu_cmd = [str(self.qemu)]
|
||||
if self.bios:
|
||||
qemu_cmd.extend(['-bios', str(self.bios)])
|
||||
@@ -304,20 +290,7 @@ class BuildQemu:
|
||||
if not any(item.startswith('-serial') for item in self.qemu_extra):
|
||||
qemu_cmd.extend(['-serial', 'mon:stdio'])
|
||||
|
||||
if self.args.kernel:
|
||||
qemu_cmd.extend(['-kernel', self.args.kernel])
|
||||
if self.args.initrd:
|
||||
qemu_cmd.extend(['-initrd', self.args.initrd])
|
||||
|
||||
if self.args.enable_console:
|
||||
cmdline.append('console=ttyS0,115200,8n1')
|
||||
if self.args.root:
|
||||
cmdline.append(f'root={self.args.root}')
|
||||
if self.args.uuid:
|
||||
cmdline.append(f'root=/dev/disk/by-uuid/{self.args.uuid}')
|
||||
|
||||
if cmdline:
|
||||
qemu_cmd.extend(['-append'] + [' '.join(cmdline)])
|
||||
self.helper.add_qemu_args(self.args, qemu_cmd)
|
||||
|
||||
# Add other parameters gathered from options
|
||||
qemu_cmd.extend(self.qemu_extra)
|
||||
|
||||
@@ -108,6 +108,31 @@ sct_mnt = /mnt/sct
|
||||
else:
|
||||
shutil.copy2(tmp.name, fname)
|
||||
|
||||
def add_qemu_args(self, args, cmd):
|
||||
"""Add QEMU arguments according to the selected options
|
||||
|
||||
This helps in creating the command-line used to run QEMU.
|
||||
|
||||
Args:
|
||||
args (list of str): Existing arguments to add to
|
||||
cmd (argparse.Namespace): Program arguments
|
||||
"""
|
||||
cmdline = []
|
||||
if args.kernel:
|
||||
cmd.extend(['-kernel', args.kernel])
|
||||
if args.initrd:
|
||||
cmd.extend(['-initrd', args.initrd])
|
||||
|
||||
if args.enable_console:
|
||||
cmdline.append('console=ttyS0,115200,8n1')
|
||||
if args.root:
|
||||
cmdline.append(f'root={args.root}')
|
||||
if args.uuid:
|
||||
cmdline.append(f'root=/dev/disk/by-uuid/{args.uuid}')
|
||||
|
||||
if cmdline:
|
||||
cmd.extend(['-append'] + [' '.join(cmdline)])
|
||||
|
||||
|
||||
def add_common_args(parser):
|
||||
"""Add some arguments which are common to build-efi/qemu scripts
|
||||
@@ -119,11 +144,17 @@ def add_common_args(parser):
|
||||
help='Select architecture (arm, x86) Default: arm')
|
||||
parser.add_argument('-B', '--no-build', action='store_true',
|
||||
help="Don't build; assume a build exists")
|
||||
parser.add_argument('-C', '--enable-console', action='store_true',
|
||||
help="Enable linux console (x86 only)")
|
||||
parser.add_argument('-d', '--disk',
|
||||
help='Root disk image file to use with QEMU')
|
||||
parser.add_argument('-I', '--initrd',
|
||||
help='Initial ramdisk to run using -initrd')
|
||||
parser.add_argument(
|
||||
'-k', '--kvm', action='store_true',
|
||||
help='Use KVM (Kernel-based Virtual Machine) for acceleration')
|
||||
parser.add_argument('-K', '--kernel',
|
||||
help='Kernel to run using -kernel')
|
||||
parser.add_argument('-o', '--os', metavar='NAME', choices=['ubuntu'],
|
||||
help='Run a specified Operating System')
|
||||
parser.add_argument('-r', '--run', action='store_true',
|
||||
@@ -133,5 +164,11 @@ def add_common_args(parser):
|
||||
help='Select OS release version (e.g, 24.04) Default: 24.04.1')
|
||||
parser.add_argument('-s', '--serial-only', action='store_true',
|
||||
help='Run QEMU with serial only (no display)')
|
||||
parser.add_argument(
|
||||
'-t', '--root',
|
||||
help='Pass the given root device to linux via root=xxx')
|
||||
parser.add_argument(
|
||||
'-U', '--uuid',
|
||||
help='Pass the given root device to linux via root=/dev/disk/by-uuid/')
|
||||
parser.add_argument('-w', '--word-32bit', action='store_true',
|
||||
help='Use 32-bit version for the build/architecture')
|
||||
|
||||
Reference in New Issue
Block a user