@@ -319,6 +319,31 @@ def run(self):
319319 self ._run_fg ()
320320
321321
322+ class ARMEFIQEMURunner (QEMURunner ):
323+
324+ def _setup_efi (self , possible_locations ):
325+ # Sizing the images to 64M is recommended by "Prepare the firmware" section at
326+ # https://mirrors.edge.kernel.org/pub/linux/kernel/people/will/docs/qemu/qemu-arm64-howto.html
327+ efi_img_size = 64 * 1024 * 1024 # 64M
328+
329+ usr_share = Path ('/usr/share' )
330+
331+ aavmf = utils .find_first_file (usr_share , possible_locations )
332+
333+ self ._efi_img = Path (utils .BOOT_UTILS , 'images' , self ._initrd_arch ,
334+ 'efi.img' )
335+ # This file is in /usr/share, so it must be copied in order to be
336+ # modified.
337+ shutil .copyfile (aavmf , self ._efi_img )
338+ with self ._efi_img .open (mode = 'r+b' ) as file :
339+ file .truncate (efi_img_size )
340+
341+ self ._efi_vars = self ._efi_img .with_name ('efivars.img' )
342+ self ._efi_vars .unlink (missing_ok = True )
343+ with self ._efi_vars .open (mode = 'xb' ) as file :
344+ file .truncate (efi_img_size )
345+
346+
322347class ARMQEMURunner (QEMURunner ):
323348
324349 def __init__ (self ):
@@ -359,11 +384,12 @@ def __init__(self):
359384 self ._machine = 'romulus-bmc'
360385
361386
362- class ARMV7QEMURunner (ARMQEMURunner ):
387+ class ARMV7QEMURunner (ARMQEMURunner , ARMEFIQEMURunner ):
363388
364389 def __init__ (self ):
365390 super ().__init__ ()
366391
392+ self .supports_efi = True
367393 self .use_kvm = self ._can_use_kvm ()
368394
369395 self .cmdline += ['console=ttyAMA0' , 'earlycon' ]
@@ -386,14 +412,20 @@ def _can_use_kvm(self):
386412 return self ._have_dev_kvm_access ()
387413
388414 def run (self ):
415+ if self .efi :
416+ aavmf_locations = [
417+ Path ('edk2/arm/QEMU_EFI.fd' ), # Arch Linux, Fedora
418+ ]
419+ self ._setup_efi (aavmf_locations )
420+
389421 if self .use_kvm :
390422 self ._kvm_cpu .append ('aarch64=off' )
391423 self ._qemu_arch = 'aarch64'
392424
393425 super ().run ()
394426
395427
396- class ARM64QEMURunner (QEMURunner ):
428+ class ARM64QEMURunner (ARMEFIQEMURunner ):
397429
398430 def __init__ (self ):
399431 super ().__init__ ()
@@ -429,34 +461,6 @@ def _get_cpu_val(self):
429461
430462 return cpu
431463
432- def _setup_efi (self ):
433- # Sizing the images to 64M is recommended by "Prepare the firmware" section at
434- # https://mirrors.edge.kernel.org/pub/linux/kernel/people/will/docs/qemu/qemu-arm64-howto.html
435- efi_img_size = 64 * 1024 * 1024 # 64M
436-
437- usr_share = Path ('/usr/share' )
438-
439- aavmf_locations = [
440- Path ('edk2/aarch64/QEMU_EFI.silent.fd' ), # Fedora
441- Path ('edk2/aarch64/QEMU_EFI.fd' ), # Arch Linux (current)
442- Path ('edk2-armvirt/aarch64/QEMU_EFI.fd' ), # Arch Linux (old)
443- Path ('qemu-efi-aarch64/QEMU_EFI.fd' ), # Debian and Ubuntu
444- ]
445- aavmf = utils .find_first_file (usr_share , aavmf_locations )
446-
447- self ._efi_img = Path (utils .BOOT_UTILS , 'images' , self ._initrd_arch ,
448- 'efi.img' )
449- # This file is in /usr/share, so it must be copied in order to be
450- # modified.
451- shutil .copyfile (aavmf , self ._efi_img )
452- with self ._efi_img .open (mode = 'r+b' ) as file :
453- file .truncate (efi_img_size )
454-
455- self ._efi_vars = self ._efi_img .with_name ('efivars.img' )
456- self ._efi_vars .unlink (missing_ok = True )
457- with self ._efi_vars .open (mode = 'xb' ) as file :
458- file .truncate (efi_img_size )
459-
460464 def run (self ):
461465 machine = ['virt' , 'gic-version=max' ]
462466
@@ -471,7 +475,13 @@ def run(self):
471475 self ._qemu_args += ['-machine' , ',' .join (machine )]
472476
473477 if self .efi :
474- self ._setup_efi ()
478+ aavmf_locations = [
479+ Path ('edk2/aarch64/QEMU_EFI.silent.fd' ), # Fedora
480+ Path ('edk2/aarch64/QEMU_EFI.fd' ), # Arch Linux (current)
481+ Path ('edk2-armvirt/aarch64/QEMU_EFI.fd' ), # Arch Linux (old)
482+ Path ('qemu-efi-aarch64/QEMU_EFI.fd' ), # Debian and Ubuntu
483+ ]
484+ self ._setup_efi (aavmf_locations )
475485
476486 super ().run ()
477487
0 commit comments