Skip to content

Commit 29206b1

Browse files
committed
boot-qemu.py: Pull large sections of ARM64QEMURunner.run() into new methods
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent 09a59ca commit 29206b1

1 file changed

Lines changed: 49 additions & 42 deletions

File tree

boot-qemu.py

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -402,29 +402,59 @@ def __init__(self):
402402
def _can_use_kvm(self):
403403
return platform.machine() == 'aarch64' and self._have_dev_kvm_access()
404404

405-
def run(self):
406-
machine = ['virt', 'gic-version=max']
405+
def _get_cpu_val(self):
406+
cpu = ['max']
407407

408-
if not self.use_kvm:
409-
cpu = ['max']
408+
self._set_qemu_path()
409+
if (qemu_ver := self._get_qemu_ver_tuple()) >= (6, 2, 50):
410+
self._set_kernel_vars()
411+
kernel_ver = self._get_kernel_ver_tuple('gzip')
412+
413+
# https://gitlab.com/qemu-project/qemu/-/issues/964
414+
if kernel_ver < (4, 16, 0):
415+
cpu = ['cortex-a72']
416+
# https://gitlab.com/qemu-project/qemu/-/commit/69b2265d5fe8e0f401d75e175e0a243a7d505e53
417+
elif kernel_ver < (5, 12, 0):
418+
cpu.append('lpa2=off')
419+
420+
# https://lore.kernel.org/YlgVa+AP0g4IYvzN@lakrids/
421+
if 'max' in cpu and qemu_ver >= (6, 0, 0):
422+
cpu.append('pauth-impdef=true')
423+
424+
return cpu
425+
426+
def _setup_efi(self):
427+
# Sizing the images to 64M is recommended by "Prepare the firmware" section at
428+
# https://mirrors.edge.kernel.org/pub/linux/kernel/people/will/docs/qemu/qemu-arm64-howto.html
429+
efi_img_size = 64 * 1024 * 1024 # 64M
430+
431+
usr_share = Path('/usr/share')
432+
433+
aavmf_locations = [
434+
Path('edk2/aarch64/QEMU_EFI.silent.fd'), # Fedora
435+
Path('edk2/aarch64/QEMU_EFI.fd'), # Arch Linux (current)
436+
Path('edk2-armvirt/aarch64/QEMU_EFI.fd'), # Arch Linux (old)
437+
Path('qemu-efi-aarch64/QEMU_EFI.fd'), # Debian and Ubuntu
438+
]
439+
aavmf = utils.find_first_file(usr_share, aavmf_locations)
410440

411-
self._set_qemu_path()
412-
if (qemu_ver := self._get_qemu_ver_tuple()) >= (6, 2, 50):
413-
self._set_kernel_vars()
414-
kernel_ver = self._get_kernel_ver_tuple('gzip')
441+
self._efi_img = Path(BOOT_UTILS, 'images', self._initrd_arch,
442+
'efi.img')
443+
shutil.copyfile(aavmf, self._efi_img)
444+
with self._efi_img.open(mode='r+b') as file:
445+
file.truncate(efi_img_size)
415446

416-
# https://gitlab.com/qemu-project/qemu/-/issues/964
417-
if kernel_ver < (4, 16, 0):
418-
cpu = ['cortex-a72']
419-
# https://gitlab.com/qemu-project/qemu/-/commit/69b2265d5fe8e0f401d75e175e0a243a7d505e53
420-
elif kernel_ver < (5, 12, 0):
421-
cpu.append('lpa2=off')
447+
self._efi_vars = self._efi_img.with_stem('efivars')
448+
self._efi_vars.unlink(missing_ok=True)
449+
with self._efi_vars.open(mode='xb') as file:
450+
file.truncate(efi_img_size)
422451

423-
# https://lore.kernel.org/YlgVa+AP0g4IYvzN@lakrids/
424-
if 'max' in cpu and qemu_ver >= (6, 0, 0):
425-
cpu.append('pauth-impdef=true')
452+
def run(self):
453+
machine = ['virt', 'gic-version=max']
426454

427-
self._qemu_args += ['-cpu', ','.join(cpu)]
455+
if not self.use_kvm:
456+
cpu_val = self._get_cpu_val()
457+
self._qemu_args += ['-cpu', ','.join(cpu_val)]
428458

429459
# Boot with VHE emulation, which allows the kernel to run at EL2.
430460
# KVM does not emulate VHE, so this cannot be unconditional.
@@ -433,30 +463,7 @@ def run(self):
433463
self._qemu_args += ['-machine', ','.join(machine)]
434464

435465
if self.efi:
436-
# Sizing the images to 64M is recommended by "Prepare the firmware" section at
437-
# https://mirrors.edge.kernel.org/pub/linux/kernel/people/will/docs/qemu/qemu-arm64-howto.html
438-
efi_img_size = 64 * 1024 * 1024 # 64M
439-
440-
usr_share = Path('/usr/share')
441-
442-
aavmf_locations = [
443-
Path('edk2/aarch64/QEMU_EFI.silent.fd'), # Fedora
444-
Path('edk2/aarch64/QEMU_EFI.fd'), # Arch Linux (current)
445-
Path('edk2-armvirt/aarch64/QEMU_EFI.fd'), # Arch Linux (old)
446-
Path('qemu-efi-aarch64/QEMU_EFI.fd'), # Debian and Ubuntu
447-
]
448-
aavmf = utils.find_first_file(usr_share, aavmf_locations)
449-
450-
self._efi_img = Path(BOOT_UTILS, 'images', self._initrd_arch,
451-
'efi.img')
452-
shutil.copyfile(aavmf, self._efi_img)
453-
with self._efi_img.open(mode='r+b') as file:
454-
file.truncate(efi_img_size)
455-
456-
self._efi_vars = self._efi_img.with_stem('efivars')
457-
self._efi_vars.unlink(missing_ok=True)
458-
with self._efi_vars.open(mode='xb') as file:
459-
file.truncate(efi_img_size)
466+
self._setup_efi()
460467

461468
super().run()
462469

0 commit comments

Comments
 (0)