[gnome-boxes/WIP/reinstate-gnome-nightly: 6/8] Enable UEFI only for the GNOME Nightly images




commit 1d176faf5d9599b1f688953116c1d388fd84d778
Author: Felipe Borges <felipeborges gnome org>
Date:   Thu Jul 23 16:46:18 2020 +0200

    Enable UEFI only for the GNOME Nightly images
    
    This reverts commit 8b4eaf4a7f240e89163c8581ec051b3938a89d4d.

 meson_options.txt        |  5 +++++
 src/installer-media.vala | 16 ++++++++++++++++
 src/meson.build          |  3 +++
 src/vm-configurator.vala | 34 +++++++++++++++++++++++++++++++---
 src/vm-creator.vala      |  3 ++-
 5 files changed, 57 insertions(+), 4 deletions(-)
---
diff --git a/meson_options.txt b/meson_options.txt
index c55a4712..a5f1be87 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -29,3 +29,8 @@ option ('profile',
   ],
   value: 'default'
 )
+
+option ('uefi',
+        type: 'boolean',
+        value: true,
+        description: 'Use UEFI whenever it is possible')
diff --git a/src/installer-media.vala b/src/installer-media.vala
index 87f5e7b1..bccaf1e5 100644
--- a/src/installer-media.vala
+++ b/src/installer-media.vala
@@ -55,6 +55,22 @@
         }
     }
 
+    public bool supports_efi {
+        get {
+            if (os == null)
+                return false;
+
+            return (os.get_id () == "http://gnome.org/gnome/nightly";);
+
+            /*foreach (var iter in os.get_firmware_list (null) .get_elements ()) {
+                var firmware = iter as Firmware;
+                if (firmware.get_firmware_type () == "efi")
+                    return true;
+            }
+            return false;*/
+        }
+    }
+
     public virtual bool prefers_q35 {
         get {
             if (os == null)
diff --git a/src/meson.build b/src/meson.build
index 3d4302af..2910ada6 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -191,6 +191,9 @@ else
   dependencies += libovf.get_variable('govf_vapi')
 endif
 
+if get_option('uefi')
+    vala_args += '--define=USE_UEFI'
+endif
 
 executable ('gnome-boxes', vala_sources + resources,
             include_directories: config_h_dir,
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index 7679cdc5..4a2fbd49 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -38,7 +38,7 @@
     private const string LIBOSINFO_XML = "<libosinfo>%s</libosinfo>";
     private const string LIBOSINFO_OS_ID_XML = "<os id=\"%s\"/>";
 
-    public static Domain create_domain_config (InstallerMedia install_media, string target_path, 
Capabilities caps)
+    public static Domain create_domain_config (InstallerMedia install_media, string target_path, 
Capabilities caps, DomainCapabilities domain_caps)
                                         throws VMConfiguratorError {
         var domain = new Domain ();
 
@@ -51,7 +51,7 @@ public static Domain create_domain_config (InstallerMedia install_media, string
         var virt_type = guest_kvm_enabled (best_caps) ? DomainVirtType.KVM : DomainVirtType.QEMU;
         domain.set_virt_type (virt_type);
 
-        set_os_config (domain, install_media, best_caps);
+        set_os_config (domain, install_media, best_caps, domain_caps);
 
         string[] features = {};
         if (guest_supports_feature (best_caps, "acpi"))
@@ -374,17 +374,45 @@ private static void set_post_install_os_config (Domain domain) {
 
         os.set_arch (old_os.get_arch ());
         os.set_machine (old_os.get_machine ());
+#if USE_UEFI
+        if (old_os.get_firmware () == GVirConfig.DomainOsFirmware.EFI)
+            os.set_firmware (GVirConfig.DomainOsFirmware.EFI);
+#endif
 
         domain.set_os (os);
     }
 
-    private static void set_os_config (Domain domain, InstallerMedia install_media, CapabilitiesGuest 
guest_caps) {
+    private static bool domain_caps_supports_efi (DomainCapabilities domain_caps) {
+        foreach (var firmware in domain_caps.get_os ().get_firmwares()) {
+            if (firmware == GVirConfig.DomainOsFirmware.EFI)
+                return true;
+        }
+
+        return false;
+    }
+
+    private static bool supports_efi (InstallerMedia install_media, DomainCapabilities domain_caps) {
+        if (install_media == null || !install_media.supports_efi)
+            return false;
+
+        if (domain_caps == null || !domain_caps_supports_efi (domain_caps))
+            return false;
+
+        return true;
+    }
+
+    private static void set_os_config (Domain domain, InstallerMedia install_media, CapabilitiesGuest 
guest_caps, DomainCapabilities domain_caps) {
         var os = new DomainOs ();
         os.set_os_type (DomainOsType.HVM);
         os.set_arch (guest_caps.get_arch ().get_name ());
         if (install_media.prefers_q35)
             os.set_machine ("q35");
 
+#if USE_UEFI
+        if (supports_efi (install_media, domain_caps))
+            os.set_firmware (GVirConfig.DomainOsFirmware.EFI);
+#endif
+
         var boot_devices = new GLib.List<DomainOsBootDevice> ();
         install_media.set_direct_boot_params (os);
         boot_devices.append (DomainOsBootDevice.CDROM);
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index 2c178ac1..c4b71aa5 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -211,7 +211,8 @@ protected void set_post_install_config (LibvirtMachine machine) {
                                                                     StorageVol   volume,
                                                                     Cancellable? cancellable) throws 
GLib.Error {
         var caps = yield connection.get_capabilities_async (cancellable);
-        var config = VMConfigurator.create_domain_config (install_media, volume.get_path (), caps);
+        var domcaps = yield connection.get_domain_capabilities_async (null, null, null, null, 0, 
cancellable);
+        var config = VMConfigurator.create_domain_config (install_media, volume.get_path (), caps, domcaps);
         config.name = name;
         config.title = title;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]