
From: Simon Glass <sjg@chromium.org> The two main QEMU scripts (build-efi and build-qemu) share some common arguments, so put them in the common file. Signed-off-by: Simon Glass <sjg@chromium.org> --- scripts/build-efi | 27 +++++---------------------- scripts/build-qemu | 24 +++--------------------- scripts/build_helper.py | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 43 deletions(-) diff --git a/scripts/build-efi b/scripts/build-efi index b1a6fc8755e..e4bd90f4376 100755 --- a/scripts/build-efi +++ b/scripts/build-efi @@ -20,7 +20,7 @@ import os from pathlib import Path import shutil -from build_helper import Helper +import build_helper # pylint: disable=C0413 from u_boot_pylib import command @@ -36,40 +36,23 @@ def parse_args(): """ parser = ArgumentParser( epilog='Script for running U-Boot as an EFI app/payload') + build_helper.add_common_args(parser) parser.add_argument('-a', '--app', action='store_true', help='Package up the app') parser.add_argument('-A', '--arm', action='store_true', help='Run on ARM architecture') - parser.add_argument('-B', '--no-build', action='store_true', - help="Don't build (an existing build must be present") - parser.add_argument('-d', '--disk', - help='Root disk image file to use with QEMU') parser.add_argument('-g', '--debug', action='store_true', help="Run QEMU with gdb") - parser.add_argument( - '-k', '--kvm', action='store_true', - help='Use KVM (Kernel-based Virtual Machine) for acceleration') parser.add_argument('-K', '--kernel', action='store_true', help='Add a kernel') parser.add_argument('-O', '--old', action='store_true', help='Use old EFI app build (before 32/64 split)') - parser.add_argument('-o', '--os', metavar='NAME', choices=['ubuntu'], - help='Run a specified Operating System') parser.add_argument('-p', '--payload', action='store_true', help='Package up the payload') parser.add_argument('-P', '--partition', action='store_true', help='Create a partition table') - parser.add_argument('-r', '--run', action='store_true', - help='Run QEMU with the image') - parser.add_argument( - '-R', '--release', default='24.04.1', - help='Select OS release version (e.g, 24.04) Default: 24.04.1') - parser.add_argument('-s', '--serial', action='store_true', - help='Run QEMU with serial only (no display)') parser.add_argument('-v', '--verbose', action='store_true', help='Show executed commands') - parser.add_argument('-w', '--word', action='store_true', - help='Use word version (32-bit) rather than 64-bit') args = parser.parse_args() @@ -81,7 +64,7 @@ def parse_args(): class BuildEfi: """Class to collect together the various bits of state while running""" def __init__(self, args): - self.helper = Helper() + self.helper = build_helper.Helper() self.helper.read_settings() self.img = self.helper.get_setting('efi_image_file', 'efi.img') self.build_dir = self.helper.get_setting("build_dir", '/tmp') @@ -204,7 +187,7 @@ class BuildEfi: def start(self): """This does all the work""" args = self.args - bitness = 32 if args.word else 64 + bitness = 32 if args.word_32bit else 64 arch = 'arm' if args.arm else 'x86' build_type = 'payload' if args.payload else 'app' build = f'efi-{arch}_{build_type}{bitness}' @@ -223,7 +206,7 @@ class BuildEfi: command.run('cp', bzimage, f'{dirpath}/vmlinuz') if args.run: - self.run_qemu(bitness, args.serial) + self.run_qemu(bitness, args.serial_only) if __name__ == "__main__": diff --git a/scripts/build-qemu b/scripts/build-qemu index 8a6078a43fc..6fcaa379ab6 100755 --- a/scripts/build-qemu +++ b/scripts/build-qemu @@ -20,7 +20,7 @@ import sys import shlex import time -from build_helper import Helper +import build_helper OUR_PATH = os.path.dirname(os.path.realpath(__file__)) OUR1_PATH = os.path.dirname(OUR_PATH) @@ -40,14 +40,11 @@ def parse_args(): parser = argparse.ArgumentParser( description='Build and/or run U-Boot with QEMU', formatter_class=argparse.RawTextHelpFormatter) + build_helper.add_common_args(parser) parser.add_argument('-a', '--arch', default='arm', choices=['arm', 'x86'], 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('-D', '--share-dir', metavar='DIR', help='Directory to share into the guest via virtiofs') parser.add_argument('-e', '--sct-run', action='store_true', @@ -56,25 +53,12 @@ def parse_args(): help='Run Tianocore (OVMF) instead of U-Boot') 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('-Q', '--use-qboot', action='store_true', help='Run qboot instead of U-Boot') - parser.add_argument('-r', '--run', action='store_true', - help='Run QEMU with the built/specified image') parser.add_argument('-x', '--xpl', action='store_true', help='Use xPL image rather than U-Boot proper') - parser.add_argument( - '-R', '--release', default='24.04.1', - help='Select OS release version (e.g, 24.04) Default: 24.04.1') - parser.add_argument( - '-s', '--serial-only', action='store_true', - help='Use serial console only (no graphical display for QEMU)') parser.add_argument( '-S', '--sct-seq', help='SCT sequence-file to be written into the SCT image if -e') @@ -86,8 +70,6 @@ def parse_args(): 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') - parser.add_argument('-w', '--word-32bit', action='store_true', - help='Use 32-bit version for the build/architecture') return parser.parse_args() @@ -99,7 +81,7 @@ class BuildQemu: """Set up arguments and configure paths""" self.args = args - self.helper = Helper() + self.helper = build_helper.Helper() self.helper.read_settings() self.imagedir = Path(self.helper.get_setting('image_dir', '~/dev')) self.ubdir = Path(self.helper.get_setting('build_dir', '/tmp/b')) diff --git a/scripts/build_helper.py b/scripts/build_helper.py index 210840a3250..ac7dbac9a30 100644 --- a/scripts/build_helper.py +++ b/scripts/build_helper.py @@ -107,3 +107,29 @@ sct_mnt = /mnt/sct input=f'type=c, size={size_mb-1}M, start=1M,bootable') else: shutil.copy2(tmp.name, fname) + + +def add_common_args(parser): + """Add some arguments which are common to build-efi/qemu scripts + + Args: + parser (argparse.ArgumentParser): Parser to modify + """ + parser.add_argument('-B', '--no-build', action='store_true', + help="Don't build; assume a build exists") + parser.add_argument('-d', '--disk', + help='Root disk image file to use with QEMU') + parser.add_argument( + '-k', '--kvm', action='store_true', + help='Use KVM (Kernel-based Virtual Machine) for acceleration') + parser.add_argument('-o', '--os', metavar='NAME', choices=['ubuntu'], + help='Run a specified Operating System') + parser.add_argument('-r', '--run', action='store_true', + help='Run QEMU with the image') + parser.add_argument( + '-R', '--release', default='24.04.1', + 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('-w', '--word-32bit', action='store_true', + help='Use 32-bit version for the build/architecture') -- 2.43.0