Blob Blame History Raw
From 3cd6171c44ef217acef059c871efc726eb9df062 Mon Sep 17 00:00:00 2001
From: Gary Lin <glin@suse.com>
Date: Thu, 28 Mar 2019 16:20:22 +0800
Subject: [PATCH] uefi: add a new option to specify the os name

fu_uefi_get_esp_path_for_os() generates the path to the OS directory
based on "ID" in /etc/os-release, and it may not work for some distros.

Take openSUSE as an example, the "ID" for openSUSE Leap is
"opensuse-leap" and that for openSUSE Tumbleweed is "opensuse-tumbleweed".
However, both of them use the same OS directory in the ESP, i.e.
"/EFI/opensuse".

This commit adds a new build option, efi_os_dir, to allow the packager to
specify the name of OS directory at build time instead of the runtime
detection.

Signed-off-by: Gary Lin <glin@suse.com>
---
 meson_options.txt             | 1 +
 plugins/uefi/fu-uefi-common.c | 4 ++++
 plugins/uefi/meson.build      | 5 +++++
 3 files changed, 10 insertions(+)

diff --git a/meson_options.txt b/meson_options.txt
index 23ef8cdb..c1767205 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -24,3 +24,4 @@ option('efi-ld', type : 'string', value : 'ld', description : 'the linker to use
 option('efi-libdir', type : 'string', description : 'path to the EFI lib directory')
 option('efi-ldsdir', type : 'string', description : 'path to the EFI lds directory')
 option('efi-includedir', type : 'string', value : '/usr/include/efi', description : 'path to the EFI header directory')
+option('efi_os_dir', type: 'string', description : 'the name of OS directory in ESP')
diff --git a/plugins/uefi/fu-uefi-common.c b/plugins/uefi/fu-uefi-common.c
index 2e3268aa..4d9d03d7 100644
--- a/plugins/uefi/fu-uefi-common.c
+++ b/plugins/uefi/fu-uefi-common.c
@@ -246,6 +246,7 @@ gchar *
 fu_uefi_get_esp_path_for_os (const gchar *esp_path)
 {
 	const gchar *os_release_id = NULL;
+#ifndef EFI_OS_DIR
 	g_autoptr(GError) error_local = NULL;
 	g_autoptr(GHashTable) os_release = fwupd_get_os_release (&error_local);
 	if (os_release != NULL) {
@@ -255,6 +256,9 @@ fu_uefi_get_esp_path_for_os (const gchar *esp_path)
 	}
 	if (os_release_id == NULL)
 		os_release_id = "unknown";
+#else
+	os_release_id = EFI_OS_DIR;
+#endif
 	return g_build_filename (esp_path, "EFI", os_release_id, NULL);
 }
 
diff --git a/plugins/uefi/meson.build b/plugins/uefi/meson.build
index 140418a8..21d4b6c8 100644
--- a/plugins/uefi/meson.build
+++ b/plugins/uefi/meson.build
@@ -3,6 +3,11 @@ subdir('efi')
 cargs = ['-DG_LOG_DOMAIN="FuPluginUefi"']
 cargs += '-DEFI_APP_LOCATION_BUILD="' + app.full_path() + '"'
 
+efi_os_dir = get_option('efi_os_dir')
+if efi_os_dir != ''
+  cargs += '-DEFI_OS_DIR="' + efi_os_dir + '"'
+endif
+
 shared_module('fu_plugin_uefi',
   sources : [
     'fu-plugin-uefi.c',
-- 
2.24.1