scripts: Move OS selection into the helper

Both scripts allow booting from an ISO containing an OS, so move this
handling into the common helper.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-06-12 06:29:58 -06:00
parent e2e338d4f1
commit fcc852c0f0
3 changed files with 14 additions and 23 deletions

View File

@@ -113,17 +113,6 @@ class BuildEfi:
if self.args.kvm:
extra.extend(['-enable-kvm', '-cpu', 'host'])
os_path = None
if self.args.os == 'ubuntu':
img_name = f'{self.args.os}-{self.args.release}-desktop-{self.helper.os_arch}.iso'
os_path = self.imagedir / self.args.os / img_name
if not os_path.exists():
tout.error(f'OS image {os_path} specified but not found')
else:
extra.extend([
'-drive',
f'if=virtio,file={os_path},format=raw,id=hd0,readonly=on'])
img_fname = Path(self.args.disk) if self.args.disk else None
if img_fname:
if img_fname.exists():

View File

@@ -69,7 +69,6 @@ class BuildQemu:
self.helper = build_helper.Helper(args)
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'))
self.sctdir = Path(self.helper.get_setting('sct_dir', '~/dev/efi/sct'))
self.tiano = Path(self.helper.get_setting('tianocore_dir',
@@ -159,11 +158,6 @@ class BuildQemu:
else:
raise ValueError(f"Invalid arch '{args.arch}'")
self.os_path = None
if args.os == 'ubuntu':
img_name = (f'{args.os}-{args.release}-desktop-{self.helper.os_arch}.iso')
self.os_path = self.imagedir / args.os / img_name
self.build_dir = self.ubdir / self.board
self.bios = (bios_override if bios_override
else self.build_dir / default_bios)
@@ -289,12 +283,6 @@ class BuildQemu:
# Add other parameters gathered from options
qemu_cmd.extend(self.qemu_extra)
if self.os_path:
if not self.os_path.exists():
tout.error(f'OS image {self.os_path} specified but not found')
qemu_cmd.extend([
'-drive',
f'if=virtio,file={self.os_path},format=raw,id=hd0,readonly=on'])
if self.img_fname:
if self.img_fname.exists():

View File

@@ -7,6 +7,7 @@
import configparser
import contextlib
import os
from pathlib import Path
import shutil
import subprocess
import sys
@@ -22,6 +23,7 @@ sys.path.insert(2, os.path.join(OUR1_PATH, 'test/py/tests'))
from u_boot_pylib import command
from u_boot_pylib import tools
from u_boot_pylib import tout
import fs_helper
@@ -75,6 +77,7 @@ sct_dir = ~/dev/efi/sct
sct_mnt = /mnt/sct
''', binary=False)
self.settings.read(fname)
self.imagedir = Path(self.get_setting('image_dir', '~/dev'))
def get_setting(self, name, fallback=None):
"""Get a setting by name
@@ -146,6 +149,17 @@ sct_mnt = /mnt/sct
if cmdline:
cmd.extend(['-append'] + [' '.join(cmdline)])
os_path = None
if args.os == 'ubuntu':
img_name = f'{args.os}-{args.release}-desktop-{self.os_arch}.iso'
os_path = self.imagedir / args.os / img_name
if not os_path.exists():
tout.error(f'OS image {os_path} specified but not found')
else:
cmd.extend([
'-drive',
f'if=virtio,file={os_path},format=raw,id=hd0,readonly=on'])
def add_common_args(parser):
"""Add some arguments which are common to build-efi/qemu scripts