scripts: Create a common settings file for QEMU scripts
Move the settings into a common file so they can be used by all tools. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user