Move the settings into a common file so they can be used by all tools. Signed-off-by: Simon Glass <s...@chromium.org> ---
scripts/build-efi | 53 ++++----------------------------- scripts/build_helper.py | 65 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 47 deletions(-) diff --git a/scripts/build-efi b/scripts/build-efi index a2b5540ad29..2f4b916c49b 100755 --- a/scripts/build-efi +++ b/scripts/build-efi @@ -16,7 +16,6 @@ Use ~/.build-efi to configure the various paths used by this script. """ from argparse import ArgumentParser -import configparser import os import shutil @@ -63,55 +62,15 @@ def parse_args(): return args -def get_settings(): - """Get settings from the settings file - - Return: - ConfigParser containing settings - """ - settings = configparser.ConfigParser() - fname = f'{os.getenv("HOME")}/.build-efi' - if not os.path.exists(fname): - print('No config file found ~/.build-efi\nCreating one...\n') - tools.write_file(fname, '''[build-efi] -# Mount path for the temporary image -mount_point = /mnt/test-efi - -# Image-output filename -image_file = try.img - -# Set ubdir to the build directory where you build U-Boot out-of-tree -# We avoid in-tree build because it gets confusing trying different builds -build_dir = /tmp/b - -# Build the kernel with: make O=/tmp/kernel -bzimage = /tmp/kernel/arch/x86/boot/bzImage - -# Place where OVMF-pure-efi.i386.fd etc. are kept -efi_dir = . -''', binary=False) - settings.read(fname) - return settings - - class BuildEfi: """Class to collect together the various bits of state while running""" - def __init__(self, settings, args): + def __init__(self, args): self.helper = Helper() - self.settings = settings - self.img = self.get_setting('image_file', 'try.img') - self.build_dir = self.get_setting("build_dir", '/tmp') + 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') self.args = args - def get_setting(self, name, fallback=None): - """Get a setting by name - - Args: - name (str): Name of setting to retrieve - fallback (str or None): Value to return if the setting is missing - """ - return self.settings.get('build-efi', name, fallback=fallback) - def run_qemu(self, bitness, serial_only): """Run QEMU @@ -120,7 +79,7 @@ class BuildEfi: serial_only (bool): True to run without a display """ extra = [] - efi_dir = self.get_setting("efi_dir") + efi_dir = self.helper.get_setting('efi_dir') if self.args.arm: qemu_arch = 'aarch64' extra += ['--machine', 'virt', '-cpu', 'max'] @@ -210,5 +169,5 @@ class BuildEfi: if __name__ == "__main__": - efi = BuildEfi(get_settings(), parse_args()) + efi = BuildEfi(parse_args()) efi.start() diff --git a/scripts/build_helper.py b/scripts/build_helper.py index 15177a48e80..923270c95c7 100644 --- a/scripts/build_helper.py +++ b/scripts/build_helper.py @@ -4,6 +4,7 @@ """ +import configparser import contextlib import os import shutil @@ -28,6 +29,70 @@ class Helper: def __init__(self): self.settings = None + def read_settings(self): + """Get settings from the settings file""" + self.settings = configparser.ConfigParser() + fname = f'{os.getenv("HOME")}/.u_boot_qemu' + if not os.path.exists(fname): + print('No config file found: {fname}\nCreating one...\n') + tools.write_file(fname, '''# U-Boot QEMU-scripts config + +[DEFAULT] +# Image-output filename +image_file = try.img + +# Image directory (for prebuilt UEFI-images) +image_dir = ~/dev/uefi + +# Set ubdir to the build directory where you build U-Boot out-of-tree +# We avoid in-tree build because it gets confusing trying different builds +build_dir = /tmp/b + +# Build the kernel with: make O=/tmp/kernel +bzimage = /tmp/kernel/arch/x86/boot/bzImage + +# Directory where OVMF-pure-efi.i386.fd etc. are kept +efi_dir = ~/dev/efi + +# Directory where SCT image (sct.img) is kept +sct_dir = ~/dev/efi/sct + +# Directory where the SCT image is temporarily mounted for modification +sct_mnt = /mnt/sct + +# Directory containing Tianocore builds (e.g. OVMF-pure-efi.x64.fd) +tianocore_dir = ~/dev/efi/tianocore + +''', binary=False) + self.settings.read(fname) + + def get_setting(self, name, fallback=None): + """Get a setting by name + + Args: + name (str): Name of setting to retrieve + fallback (str or None): Value to return if the setting is missing + """ + raw = self.settings.get('DEFAULT', name, fallback=fallback) + return os.path.expandvars(os.path.expanduser(raw)) + + def stage(self, name): + """Context manager to count requests across a range of patchwork calls + + Args: + name (str): Stage name + + Return: + _Stage: contect object + + Usage: + with self.stage('name'): + ...do things + + Note that the output only appears if the -N flag is used + """ + return self._Stage(name) + @contextlib.contextmanager def make_disk(self, fname, size_mb=20, fs_type='ext4', use_part=False): """Create a raw disk image with files on it -- 2.43.0