From c90acbd2bf36509baff237e40fa7082bc2c0e8e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kope=C4=87?= Date: Tue, 22 Jun 2021 15:28:26 +0200 Subject: [PATCH 1/6] Fixes for freebsd efivar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Kopeć --- libfwupdplugin/fu-efivar-freebsd.c | 29 +++++++++++++++++-- meson.build | 2 +- plugins/uefi-capsule/fu-plugin-uefi-capsule.c | 4 +-- plugins/uefi-capsule/fu-uefi-common.c | 5 ++++ plugins/uefi-dbx/meson.build | 2 ++ plugins/uefi-pk/meson.build | 2 ++ 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/libfwupdplugin/fu-efivar-freebsd.c b/libfwupdplugin/fu-efivar-freebsd.c index c4fe3da5ec00..b39a0fe3ce04 100644 --- a/libfwupdplugin/fu-efivar-freebsd.c +++ b/libfwupdplugin/fu-efivar-freebsd.c @@ -11,9 +11,9 @@ #include -#include "fu-common.h" #include "fu-efivar-impl.h" +#include "fu-common.h" #include "fwupd-error.h" gboolean @@ -35,6 +35,8 @@ fu_efivar_delete_impl (const gchar *guid, const gchar *name, GError **error) efi_guid_t guidt; efi_str_to_guid (guid, &guidt); + if (!fu_efivar_exists_impl(guid, name)) + return TRUE; if (efi_del_variable (guidt, name) == 0) return TRUE; @@ -50,7 +52,7 @@ fu_efivar_delete_with_glob_impl (const gchar *guid, const gchar *name_glob, GErr { efi_guid_t *guidt = NULL; gchar *name = NULL; - gboolean rv = FALSE; + gboolean rv = TRUE; efi_guid_t guid_to_delete; efi_str_to_guid (guid, &guid_to_delete); @@ -98,8 +100,29 @@ fu_efivar_get_data_impl (const gchar *guid, const gchar *name, guint8 **data, gsize *data_sz, guint32 *attr, GError **error) { efi_guid_t guidt; + gboolean success; + guint8 *buf; + gssize sz = 0; + efi_str_to_guid (guid, &guidt); - return (efi_get_variable (guidt, name, data, data_sz, attr) != 0); + success = efi_get_variable (guidt, name, &buf, data_sz, attr) == 1; + if (data_sz != NULL) + sz = *data_sz; + if (success && sz) { + g_autofree guint8 *ret_buf = g_malloc0(sz); + memcpy(ret_buf, buf, sz); + *data = g_steal_pointer(&ret_buf); + } + + if (!success) { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_FAILED, + "failed to read efivar: %s", + name); + } + + return success; } diff --git a/meson.build b/meson.build index 34bcb1443920..2e0fb493eb01 100644 --- a/meson.build +++ b/meson.build @@ -285,7 +285,7 @@ if get_option('default_library') != 'static' platform_deps += cc.find_library('shlwapi') endif if host_machine.system() == 'freebsd' - platform_deps += dependency('efivar') + platform_deps += cc.find_library('efivar') endif endif diff --git a/plugins/uefi-capsule/fu-plugin-uefi-capsule.c b/plugins/uefi-capsule/fu-plugin-uefi-capsule.c index d8d6e62b85bf..48b3cda72459 100644 --- a/plugins/uefi-capsule/fu-plugin-uefi-capsule.c +++ b/plugins/uefi-capsule/fu-plugin-uefi-capsule.c @@ -118,7 +118,6 @@ fu_plugin_add_security_attrs (FuPlugin *plugin, FuSecurityAttrs *attrs) attr = fwupd_security_attr_new (FWUPD_SECURITY_ATTR_ID_UEFI_SECUREBOOT); fwupd_security_attr_set_plugin (attr, fu_plugin_get_name (plugin)); fu_security_attrs_append (attrs, attr); - /* SB not available or disabled */ if (!fu_efivar_secure_boot_enabled_full (&error)) { if (g_error_matches (error, @@ -131,7 +130,6 @@ fu_plugin_add_security_attrs (FuPlugin *plugin, FuSecurityAttrs *attrs) fwupd_security_attr_set_result (attr, FWUPD_SECURITY_ATTR_RESULT_NOT_ENABLED); return; } - /* success */ fwupd_security_attr_add_flag (attr, FWUPD_SECURITY_ATTR_FLAG_SUCCESS); fwupd_security_attr_set_result (attr, FWUPD_SECURITY_ATTR_RESULT_ENABLED); @@ -537,7 +535,7 @@ fu_plugin_uefi_capsule_coldplug_device (FuPlugin *plugin, FuUefiDevice *dev, GEr /* set vendor ID as the BIOS vendor */ if (device_kind != FU_UEFI_DEVICE_KIND_FMP) { const gchar *dmi_vendor; - dmi_vendor = fu_context_get_hwid_value (ctx, FU_HWIDS_KEY_BIOS_VENDOR); + dmi_vendor = fu_context_get_hwid_value (ctx, FU_HWIDS_KEY_BASEBOARD_MANUFACTURER); if (dmi_vendor != NULL) { g_autofree gchar *vendor_id = g_strdup_printf ("DMI:%s", dmi_vendor); fu_device_add_vendor_id (FU_DEVICE (dev), vendor_id); diff --git a/plugins/uefi-capsule/fu-uefi-common.c b/plugins/uefi-capsule/fu-uefi-common.c index a8bfb2058511..fb9f4fea64b7 100644 --- a/plugins/uefi-capsule/fu-uefi-common.c +++ b/plugins/uefi-capsule/fu-uefi-common.c @@ -32,7 +32,12 @@ fu_uefi_bootmgr_get_suffix (GError **error) }; g_autofree gchar *sysfsfwdir = fu_common_get_path (FU_PATH_KIND_SYSFSDIR_FW); g_autofree gchar *sysfsefidir = g_build_filename (sysfsfwdir, "efi", NULL); +#ifdef __linux__ firmware_bits = fu_uefi_read_file_as_uint64 (sysfsefidir, "fw_platform_size"); +#else + firmware_bits = 64; +#endif + if (firmware_bits == 0) { g_set_error (error, G_IO_ERROR, diff --git a/plugins/uefi-dbx/meson.build b/plugins/uefi-dbx/meson.build index 25c9fe7ea774..a191db0c1cc9 100644 --- a/plugins/uefi-dbx/meson.build +++ b/plugins/uefi-dbx/meson.build @@ -1,3 +1,4 @@ +if host_machine.system() != 'freebsd' if get_option('plugin_uefi_capsule') cargs = ['-DG_LOG_DOMAIN="FuPluginUefiDbx"'] @@ -92,3 +93,4 @@ if get_option('man') ) endif endif +endif diff --git a/plugins/uefi-pk/meson.build b/plugins/uefi-pk/meson.build index 2f8c261366d4..6f45abaec26f 100644 --- a/plugins/uefi-pk/meson.build +++ b/plugins/uefi-pk/meson.build @@ -1,3 +1,4 @@ +if host_machine.system() != 'freebsd' if get_option('plugin_uefi_pk') cargs = ['-DG_LOG_DOMAIN="FuPluginUefiPk"'] @@ -24,3 +25,4 @@ shared_module('fu_plugin_uefi_pk', ], ) endif +endif From 0c9e1cebc74bce1086dd8bbddefa54c2471f703a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kope=C4=87?= Date: Wed, 7 Jul 2021 15:03:51 +0200 Subject: [PATCH 2/6] Fix compilation on FreeBSD provided efivar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Kopeć --- meson.build | 1 + plugins/uefi-capsule/fu-uefi-backend-freebsd.c | 1 + 2 files changed, 2 insertions(+) diff --git a/meson.build b/meson.build index 2e0fb493eb01..d087ef15b7b6 100644 --- a/meson.build +++ b/meson.build @@ -286,6 +286,7 @@ if get_option('default_library') != 'static' endif if host_machine.system() == 'freebsd' platform_deps += cc.find_library('efivar') + platform_deps += cc.find_library('geom') endif endif diff --git a/plugins/uefi-capsule/fu-uefi-backend-freebsd.c b/plugins/uefi-capsule/fu-uefi-backend-freebsd.c index f0dde4ae8da9..6da26a8c5929 100644 --- a/plugins/uefi-capsule/fu-uefi-backend-freebsd.c +++ b/plugins/uefi-capsule/fu-uefi-backend-freebsd.c @@ -20,6 +20,7 @@ #include +#include "fu-kenv.h" #include "fu-uefi-common.h" #include "fu-uefi-device.h" #include "fu-uefi-backend.h" From 32b56a815c5d3e742711756214844a71819d2417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kope=C4=87?= Date: Wed, 7 Jul 2021 15:29:43 +0200 Subject: [PATCH 3/6] Undo more workarounds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Kopeć --- libfwupdplugin/fu-efivar-freebsd.c | 2 +- plugins/uefi-capsule/fu-plugin-uefi-capsule.c | 4 +++- plugins/uefi-dbx/meson.build | 2 -- plugins/uefi-pk/meson.build | 2 -- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libfwupdplugin/fu-efivar-freebsd.c b/libfwupdplugin/fu-efivar-freebsd.c index b39a0fe3ce04..c971fc14be3b 100644 --- a/libfwupdplugin/fu-efivar-freebsd.c +++ b/libfwupdplugin/fu-efivar-freebsd.c @@ -11,9 +11,9 @@ #include +#include "fu-common.h" #include "fu-efivar-impl.h" -#include "fu-common.h" #include "fwupd-error.h" gboolean diff --git a/plugins/uefi-capsule/fu-plugin-uefi-capsule.c b/plugins/uefi-capsule/fu-plugin-uefi-capsule.c index 48b3cda72459..d8d6e62b85bf 100644 --- a/plugins/uefi-capsule/fu-plugin-uefi-capsule.c +++ b/plugins/uefi-capsule/fu-plugin-uefi-capsule.c @@ -118,6 +118,7 @@ fu_plugin_add_security_attrs (FuPlugin *plugin, FuSecurityAttrs *attrs) attr = fwupd_security_attr_new (FWUPD_SECURITY_ATTR_ID_UEFI_SECUREBOOT); fwupd_security_attr_set_plugin (attr, fu_plugin_get_name (plugin)); fu_security_attrs_append (attrs, attr); + /* SB not available or disabled */ if (!fu_efivar_secure_boot_enabled_full (&error)) { if (g_error_matches (error, @@ -130,6 +131,7 @@ fu_plugin_add_security_attrs (FuPlugin *plugin, FuSecurityAttrs *attrs) fwupd_security_attr_set_result (attr, FWUPD_SECURITY_ATTR_RESULT_NOT_ENABLED); return; } + /* success */ fwupd_security_attr_add_flag (attr, FWUPD_SECURITY_ATTR_FLAG_SUCCESS); fwupd_security_attr_set_result (attr, FWUPD_SECURITY_ATTR_RESULT_ENABLED); @@ -535,7 +537,7 @@ fu_plugin_uefi_capsule_coldplug_device (FuPlugin *plugin, FuUefiDevice *dev, GEr /* set vendor ID as the BIOS vendor */ if (device_kind != FU_UEFI_DEVICE_KIND_FMP) { const gchar *dmi_vendor; - dmi_vendor = fu_context_get_hwid_value (ctx, FU_HWIDS_KEY_BASEBOARD_MANUFACTURER); + dmi_vendor = fu_context_get_hwid_value (ctx, FU_HWIDS_KEY_BIOS_VENDOR); if (dmi_vendor != NULL) { g_autofree gchar *vendor_id = g_strdup_printf ("DMI:%s", dmi_vendor); fu_device_add_vendor_id (FU_DEVICE (dev), vendor_id); diff --git a/plugins/uefi-dbx/meson.build b/plugins/uefi-dbx/meson.build index a191db0c1cc9..25c9fe7ea774 100644 --- a/plugins/uefi-dbx/meson.build +++ b/plugins/uefi-dbx/meson.build @@ -1,4 +1,3 @@ -if host_machine.system() != 'freebsd' if get_option('plugin_uefi_capsule') cargs = ['-DG_LOG_DOMAIN="FuPluginUefiDbx"'] @@ -93,4 +92,3 @@ if get_option('man') ) endif endif -endif diff --git a/plugins/uefi-pk/meson.build b/plugins/uefi-pk/meson.build index 6f45abaec26f..2f8c261366d4 100644 --- a/plugins/uefi-pk/meson.build +++ b/plugins/uefi-pk/meson.build @@ -1,4 +1,3 @@ -if host_machine.system() != 'freebsd' if get_option('plugin_uefi_pk') cargs = ['-DG_LOG_DOMAIN="FuPluginUefiPk"'] @@ -25,4 +24,3 @@ shared_module('fu_plugin_uefi_pk', ], ) endif -endif From 9c6fe347edebdcba55cee1d06ce89e35d0936cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kope=C4=87?= Date: Wed, 7 Jul 2021 15:35:30 +0200 Subject: [PATCH 4/6] Enable polkit on FreeBSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Kopeć --- contrib/freebsd/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/freebsd/Makefile b/contrib/freebsd/Makefile index a485e79ab5e5..1e094768c3b7 100644 --- a/contrib/freebsd/Makefile +++ b/contrib/freebsd/Makefile @@ -27,7 +27,8 @@ LIB_DEPENDS= libcurl.so:ftp/curl \ libjcat.so:textproc/libjcat \ libjson-glib-1.0.so:devel/json-glib \ libxmlb.so:textproc/libxmlb \ - libefiboot.so:devel/gnu-efi + libefiboot.so:devel/gnu-efi \ + libpolkit-gobject-1.so:sysutils/polkit RUN_DEPENDS= ${LOCALBASE}/libexec/fwupd/efi/fwupdx64.efi:sysutils/fwupd-efi @@ -52,7 +53,7 @@ MESON_ARGS= -Dgudev=false \ -Dplugin_realtek_mst=false \ -Dplugin_thunderbolt=false \ -Dplugin_tpm=false \ - -Dpolkit=false \ + -Dpolkit=true \ -Dsystemd=false \ -Dtests=false \ -Ddocs=gtkdoc \ From 0a8021a2e0ef9002613fe0abae373607af2ebffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kope=C4=87?= Date: Wed, 7 Jul 2021 15:37:03 +0200 Subject: [PATCH 5/6] ci: Use FreeBSD built-in libefivar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rhboot/efivar doesn't actually work on FreeBSD, while libefivar included in FreeBSD is actually fully functional despite the "not implemented" warnings in manpages. Signed-off-by: Michał Kopeć --- contrib/ci/build_freebsd_package.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/contrib/ci/build_freebsd_package.sh b/contrib/ci/build_freebsd_package.sh index 60f56614ce04..01c5ef4ac7c5 100755 --- a/contrib/ci/build_freebsd_package.sh +++ b/contrib/ci/build_freebsd_package.sh @@ -32,16 +32,13 @@ if [ -z "$GITHUB_SHA" ] || [ -z "$GITHUB_REPOSITORY" ] || \ exit 1 fi -# Include-file of libefivar port uses GCC-specific builtin function -export CC=gcc - set -xe mkdir -p /usr/local/etc/pkg/repos/ # Fix meson flag problem https://www.mail-archive.com/freebsd-ports@freebsd.org/msg86617.html cp /etc/pkg/FreeBSD.conf /usr/local/etc/pkg/repos/FreeBSD.conf sed -i .old 's|url: "pkg+http://pkg.FreeBSD.org/${ABI}/quarterly"|url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest"|' \ /usr/local/etc/pkg/repos/FreeBSD.conf -pkg install -y meson efivar +pkg install -y meson pkg upgrade -y meson cd /usr git clone https://github.com/3mdeb/freebsd-ports.git --depth 1 -b fwupd ports From 74d051ee954ccff48439912a896a9f4c1b2d3e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kope=C4=87?= Date: Wed, 7 Jul 2021 15:48:57 +0200 Subject: [PATCH 6/6] uefi-capsule: Use BASEBOARD_MANUFACTURER as BIOS vendor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Kopeć --- plugins/uefi-capsule/fu-plugin-uefi-capsule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/uefi-capsule/fu-plugin-uefi-capsule.c b/plugins/uefi-capsule/fu-plugin-uefi-capsule.c index d8d6e62b85bf..0158b67a19a5 100644 --- a/plugins/uefi-capsule/fu-plugin-uefi-capsule.c +++ b/plugins/uefi-capsule/fu-plugin-uefi-capsule.c @@ -537,7 +537,7 @@ fu_plugin_uefi_capsule_coldplug_device (FuPlugin *plugin, FuUefiDevice *dev, GEr /* set vendor ID as the BIOS vendor */ if (device_kind != FU_UEFI_DEVICE_KIND_FMP) { const gchar *dmi_vendor; - dmi_vendor = fu_context_get_hwid_value (ctx, FU_HWIDS_KEY_BIOS_VENDOR); + dmi_vendor = fu_context_get_hwid_value (ctx, FU_HWIDS_KEY_BASEBOARD_MANUFACTURER); if (dmi_vendor != NULL) { g_autofree gchar *vendor_id = g_strdup_printf ("DMI:%s", dmi_vendor); fu_device_add_vendor_id (FU_DEVICE (dev), vendor_id);