From 6101067f03b3bf4e811a01357b52e17c4b6ef2bb Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 14 Jan 2021 21:00:37 +0000 Subject: [PATCH] coreboot: Remove plugin and instead add metadata to flashrom devices The coreboot plugin never actually gained the ability to write. As it stands a coreboot system now adds *two* system-firmware devices (from both flashrom and coreboot) which isn't ideal. Just allow flashrom to enumerate quirked devices and add coreboot-specific metadata as required. If we require some kind of cbfs parsing then we can do that in FuFlashromDevice->prepare_firmware(). --- contrib/ci/build_windows.sh | 1 - contrib/fwupd.spec.in | 1 - meson_options.txt | 1 - plugins/coreboot/README.md | 63 ----------- plugins/coreboot/coreboot.quirk | 2 - plugins/coreboot/fu-coreboot-common.c | 115 -------------------- plugins/coreboot/fu-plugin-coreboot.c | 147 -------------------------- plugins/coreboot/fu-plugin-coreboot.h | 16 --- plugins/coreboot/meson.build | 30 ------ plugins/flashrom/README.md | 27 +++++ plugins/flashrom/flashrom.quirk | 5 +- plugins/flashrom/fu-flashrom-device.c | 40 +++++++ plugins/flashrom/fu-flashrom-device.h | 14 +++ plugins/flashrom/fu-plugin-flashrom.c | 123 ++++++++++++++++++--- plugins/flashrom/meson.build | 1 + plugins/meson.build | 4 - 16 files changed, 193 insertions(+), 397 deletions(-) delete mode 100644 plugins/coreboot/README.md delete mode 100644 plugins/coreboot/coreboot.quirk delete mode 100644 plugins/coreboot/fu-coreboot-common.c delete mode 100644 plugins/coreboot/fu-plugin-coreboot.c delete mode 100644 plugins/coreboot/fu-plugin-coreboot.h delete mode 100644 plugins/coreboot/meson.build create mode 100644 plugins/flashrom/fu-flashrom-device.c create mode 100644 plugins/flashrom/fu-flashrom-device.h diff --git a/contrib/ci/build_windows.sh b/contrib/ci/build_windows.sh index 736244744..eb216741a 100755 --- a/contrib/ci/build_windows.sh +++ b/contrib/ci/build_windows.sh @@ -16,7 +16,6 @@ meson .. \ --bindir=$target \ -Dbuild=standalone \ -Dpolkit=false \ - -Dplugin_coreboot=false \ -Dplugin_flashrom=false \ -Dplugin_uefi_capsule=false \ -Dplugin_redfish=false \ diff --git a/contrib/fwupd.spec.in b/contrib/fwupd.spec.in index 795e4e253..780c65629 100644 --- a/contrib/fwupd.spec.in +++ b/contrib/fwupd.spec.in @@ -385,7 +385,6 @@ done %{_libdir}/fwupd-plugins-3/libfu_plugin_bcm57xx.so %{_libdir}/fwupd-plugins-3/libfu_plugin_ccgx.so %{_libdir}/fwupd-plugins-3/libfu_plugin_colorhug.so -%{_libdir}/fwupd-plugins-3/libfu_plugin_coreboot.so %{_libdir}/fwupd-plugins-3/libfu_plugin_cros_ec.so %{_libdir}/fwupd-plugins-3/libfu_plugin_csr.so %{_libdir}/fwupd-plugins-3/libfu_plugin_cpu.so diff --git a/meson_options.txt b/meson_options.txt index d38840056..87e76870d 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -26,7 +26,6 @@ option('plugin_nvme', type : 'boolean', value : true, description : 'enable NVMe option('plugin_modem_manager', type : 'boolean', value : false, description : 'enable ModemManager support') option('plugin_msr', type : 'boolean', value : true, description : 'enable MSR support') option('plugin_flashrom', type : 'boolean', value : false, description : 'enable libflashrom support') -option('plugin_coreboot', type : 'boolean', value : true, description : 'enable coreboot support') option('plugin_platform_integrity', type : 'boolean', value : false, description : 'enable platform integrity support') option('supported_build', type : 'boolean', value : false, description: 'distribution package with upstream support') option('systemd', type : 'boolean', value : true, description : 'enable systemd support') diff --git a/plugins/coreboot/README.md b/plugins/coreboot/README.md deleted file mode 100644 index c55ca55a3..000000000 --- a/plugins/coreboot/README.md +++ /dev/null @@ -1,63 +0,0 @@ -coreboot -======== - -Introduction ------------- - -Until now only the version detection has been implemented. - -System identification ---------------------- - -coreboot can be detected the following ways: -1. by parsing SMBIOS type 0 vendor string. On coreboot enabled platforms - it's always `coreboot`. -2. by parsing ACPI tables. An ACPI device with the _HID `BOOT0000` exists. - (This HID has been reserved for coreboot enabled platforms) -3. by parsing the devicetree. A node under *firmware/coreboot* with the - compatible id `coreboot` exists. - -coreboot version string ------------------------ - -The coreboot version string can have an optional prefix (see below). -After the optional prefix the *major*, *minor* string follows and finally -the *build string*, containing the exact commit and repository state, follows. - -For example: -> 4.10-989-gc8a4e4b9c5-dirty - -**Exception on Lenovo devices:** - -The thinkpad_acpi kernel module requires a specific pattern in the DMI version -string. To satisfy those requirements coreboot adds the CBETxxxx prefix to the -DMI version string on all Lenovo devices. - -For example: -> CBET4000 4.10-989-gc8a4e4b9c5-dirty - -The coreboot DMI version string always starts with `CBET`. - -GUID Generation ---------------- - -These device uses hardware ID values which are derived from SMBIOS. -The following HWIDs are added on coreboot enabled platforms: - -* HardwareID-3 -* HardwareID-4 -* HardwareID-5 -* HardwareID-6 -* HardwareID-10 - -They do match the values provided by `fwupdtool hwids` or -the `ComputerHardwareIds.exe` Windows utility. - -Vendor ID Security ------------------- - -The vendor ID is set from the BIOS vendor, in this instance `DMI:coreboot` - -External interface access -------------------------- -This plugin does not currently use any external access. diff --git a/plugins/coreboot/coreboot.quirk b/plugins/coreboot/coreboot.quirk deleted file mode 100644 index 2884572b2..000000000 --- a/plugins/coreboot/coreboot.quirk +++ /dev/null @@ -1,2 +0,0 @@ -[SmbiosManufacturer=LENOVO] -CorebootVersionQuirks = lenovo-cbet-prefix diff --git a/plugins/coreboot/fu-coreboot-common.c b/plugins/coreboot/fu-coreboot-common.c deleted file mode 100644 index cfc55150d..000000000 --- a/plugins/coreboot/fu-coreboot-common.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2019 9elements Agency GmbH - * - * SPDX-License-Identifier: LGPL-2.1+ - */ - -#include "config.h" - -#include -#include - -#include "fu-plugin-coreboot.h" - -/** - * FU_QUIRKS_COREBOOT_VERSION: - * @key: The SMBIOS manufacturer name - * @value: One of the following: "lenovo-cbet-prefix" - * - * "lenovo-cbet-prefix" quirk: - * The thinkpad_acpi kernel module requires a specific pattern - * in the DMI version string. To satisfy those requirements - * coreboot adds the CBETxxxx prefix to the DMI version string - * on all Lenovo devices. The prefix isn't present in the - * version string found in coreboot tables, or on other - * coreboot enabled devices. - * - * Since: 1.3.5 - */ -#define FU_QUIRKS_COREBOOT_VERSION "CorebootVersionQuirks" -#define FU_QUIRK_CBET_PREFIX "lenovo-cbet-prefix" - -/* Tries to convert the coreboot version string to a triplet string. - * Returns NULL on error. */ -gchar * -fu_plugin_coreboot_version_string_to_triplet (const gchar *coreboot_version, - GError **error) -{ - guint cb_major = 0; - guint cb_minor = 0; - guint cb_build = 0; - gint rc; - - rc = sscanf (coreboot_version, "%u.%u-%u", &cb_major, &cb_minor, &cb_build); - - if (rc < 0) { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_INVALID_DATA, - "Failed to parse firmware version"); - return NULL; - } - - /* Sanity check */ - if (cb_major == 0) { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_INVALID_DATA, - "Invalid firmware version"); - return NULL; - } - - return g_strdup_printf ("%u.%u.%u", cb_major, cb_minor, cb_build); -} - -/* convert firmware type to user friendly string representation */ -gchar * -fu_plugin_coreboot_get_name_for_type (FuPlugin *plugin, - const gchar *vboot_partition) -{ - GString *display_name; - - if (vboot_partition != NULL) { - display_name = g_string_new (vboot_partition); - g_string_prepend (display_name, ", VBOOT partition "); - } else { - display_name = g_string_new (""); - } - - g_string_prepend (display_name, "coreboot System Firmware"); - return g_string_free (display_name, FALSE); -} - -/* Returns the version string with possible quirks applied */ -const gchar * -fu_plugin_coreboot_get_version_string (FuPlugin *plugin) -{ - const gchar *version; - const gchar *manufacturer; - const gchar *quirk = NULL; - - version = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_BIOS_VERSION); - if (version == NULL) - return NULL; - - manufacturer = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_MANUFACTURER); - if (manufacturer != NULL) { - g_autofree gchar *group = NULL; - - /* any quirks match */ - group = g_strdup_printf ("SmbiosManufacturer=%s", manufacturer); - quirk = fu_plugin_lookup_quirk_by_id (plugin, group, - FU_QUIRKS_COREBOOT_VERSION); - } - - if (quirk == NULL) - return version; - - if (g_strcmp0(quirk, FU_QUIRK_CBET_PREFIX) == 0) { - if (strlen (version) > 9 && g_str_has_prefix (version, "CBET")) - version += 9; - return version; - } - - return version; -} diff --git a/plugins/coreboot/fu-plugin-coreboot.c b/plugins/coreboot/fu-plugin-coreboot.c deleted file mode 100644 index af030fec3..000000000 --- a/plugins/coreboot/fu-plugin-coreboot.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2019 9elements Agency GmbH - * - * SPDX-License-Identifier: LGPL-2.1+ - */ - -#include "config.h" - -#include -#include -#include -#include - -#include "fu-plugin-vfuncs.h" -#include "fu-hash.h" -#include "fu-device-metadata.h" -#include "fu-device-private.h" -#include "fu-plugin-coreboot.h" - -void -fu_plugin_init (FuPlugin *plugin) -{ - fu_plugin_set_build_hash (plugin, FU_BUILD_HASH); -} - -gboolean -fu_plugin_coldplug (FuPlugin *plugin, GError **error) -{ - const gchar *major; - const gchar *minor; - const gchar *version; - GBytes *bios_table; - gboolean updatable = FALSE; /* TODO: Implement update support */ - g_autofree gchar *name = NULL; - g_autofree gchar *triplet = NULL; - g_autoptr(FuDevice) dev = NULL; - - /* don't include FU_HWIDS_KEY_BIOS_VERSION */ - static const gchar *hwids[] = { - "HardwareID-3", - "HardwareID-4", - "HardwareID-5", - "HardwareID-6", - "HardwareID-10", - }; - - version = fu_plugin_coreboot_get_version_string (plugin); - if (version != NULL) - triplet = fu_plugin_coreboot_version_string_to_triplet (version, error); - - if (version == NULL || triplet == NULL) { - major = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_BIOS_MAJOR_RELEASE); - if (major == NULL) { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_NOT_FOUND, - "Missing BIOS major release"); - return FALSE; - } - minor = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_BIOS_MINOR_RELEASE); - if (minor == NULL) { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_NOT_FOUND, - "Missing BIOS minor release"); - return FALSE; - } - triplet = g_strdup_printf ("%s.%s.0", major, minor); - } - - if (triplet == NULL) { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_INVALID_DATA, - "No version string found"); - - return FALSE; - } - dev = fu_device_new (); - fu_device_set_version_format (dev, FWUPD_VERSION_FORMAT_TRIPLET); - fu_device_set_version (dev, triplet); - fu_device_set_summary (dev, "Open Source system boot firmware"); - fu_device_set_id (dev, "coreboot"); - fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_INTERNAL); - fu_device_add_icon (dev, "computer"); - name = fu_plugin_coreboot_get_name_for_type (plugin, NULL); - if (name != NULL) { - fu_device_set_name (dev, name); - } else { - fu_device_set_name (dev, fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_PRODUCT_NAME)); - } - fu_device_set_vendor (dev, fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_MANUFACTURER)); - fu_device_add_instance_id (dev, "main-system-firmware"); - fu_device_add_vendor_id (dev, "DMI:coreboot"); - - for (guint i = 0; i < G_N_ELEMENTS (hwids); i++) { - char *str; - str = fu_plugin_get_hwid_replace_value (plugin, hwids[i], NULL); - if (str != NULL) - fu_device_add_instance_id (dev, str); - } - - bios_table = fu_plugin_get_smbios_data (plugin, FU_SMBIOS_STRUCTURE_TYPE_BIOS); - if (bios_table != NULL) { - guint32 bios_characteristics; - gsize len; - const guint8 *value = g_bytes_get_data (bios_table, &len); - if (len >= 0x9) { - gint firmware_size = (value[0x9] + 1) * 64 * 1024; - fu_device_set_firmware_size_max (dev, firmware_size); - } - if (len >= (0xa + sizeof(guint32))) { - memcpy (&bios_characteristics, &value[0xa], sizeof (guint32)); - /* Read the "BIOS is upgradeable (Flash)" flag */ - if (!(bios_characteristics & (1 << 11))) - updatable = FALSE; - } - } - - if (updatable) - fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE); - - /* convert instances to GUID */ - fu_device_convert_instance_ids (dev); - - fu_plugin_device_add (plugin, dev); - - return TRUE; -} - -gboolean -fu_plugin_startup (FuPlugin *plugin, GError **error) -{ - const gchar *vendor; - - vendor = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_BIOS_VENDOR); - if (g_strcmp0 (vendor, "coreboot") != 0) { - g_set_error (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_FOUND, - "No coreboot detected on this machine."); - return FALSE; - } - - return TRUE; -} - diff --git a/plugins/coreboot/fu-plugin-coreboot.h b/plugins/coreboot/fu-plugin-coreboot.h deleted file mode 100644 index 442399d24..000000000 --- a/plugins/coreboot/fu-plugin-coreboot.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2019 9elements Agency GmbH - * - * SPDX-License-Identifier: LGPL-2.1+ - */ - -#pragma once - -#include "fu-plugin.h" -#include "fu-device.h" - -gchar *fu_plugin_coreboot_version_string_to_triplet (const gchar *coreboot_version, - GError **error); -gchar *fu_plugin_coreboot_get_name_for_type (FuPlugin *plugin, - const gchar *vboot_partition); -const gchar *fu_plugin_coreboot_get_version_string (FuPlugin *plugin); diff --git a/plugins/coreboot/meson.build b/plugins/coreboot/meson.build deleted file mode 100644 index 80480f8c7..000000000 --- a/plugins/coreboot/meson.build +++ /dev/null @@ -1,30 +0,0 @@ -cargs = ['-DG_LOG_DOMAIN="FuPluginCoreboot"'] - -install_data(['coreboot.quirk'], - install_dir: join_paths(datadir, 'fwupd', 'quirks.d') -) - -shared_module('fu_plugin_coreboot', - fu_hash, - sources : [ - 'fu-plugin-coreboot.c', - 'fu-coreboot-common.c', - ], - include_directories : [ - root_incdir, - fwupd_incdir, - fwupdplugin_incdir, - ], - install : true, - install_dir: plugin_dir, - link_with : [ - fwupd, - fwupdplugin, - ], - c_args : [ - cargs, - ], - dependencies : [ - plugin_deps, - ], -) diff --git a/plugins/flashrom/README.md b/plugins/flashrom/README.md index b3fb1a257..5818ac9e3 100644 --- a/plugins/flashrom/README.md +++ b/plugins/flashrom/README.md @@ -17,9 +17,36 @@ This plugin supports the following protocol ID: * org.flashrom +Coreboot Version String +----------------------- + +The coreboot version string can have an optional prefix (see below). +After the optional prefix the *major*, *minor* string follows and finally +the *build string*, containing the exact commit and repository state, follows. + +For example `4.10-989-gc8a4e4b9c5-dirty` + +**Exception on Lenovo devices:** + +The thinkpad_acpi kernel module requires a specific pattern in the DMI version +string. To satisfy those requirements coreboot adds the CBETxxxx prefix to the +DMI version string on all Lenovo devices. + +For example `CBET4000 4.10-989-gc8a4e4b9c5-dirty` + +The coreboot DMI version string always starts with `CBET`. + GUID Generation --------------- +These device uses hardware ID values which are derived from SMBIOS. + + * HardwareID-3 + * HardwareID-4 + * HardwareID-5 + * HardwareID-6 + * HardwareID-10 + These device uses hardware ID values which are derived from SMBIOS. They should match the values provided by `fwupdtool hwids` or the `ComputerHardwareIds.exe` Windows utility. diff --git a/plugins/flashrom/flashrom.quirk b/plugins/flashrom/flashrom.quirk index f790d22de..d092582ad 100644 --- a/plugins/flashrom/flashrom.quirk +++ b/plugins/flashrom/flashrom.quirk @@ -10,4 +10,7 @@ VersionFormat=quad # Starlabs LabTop L4 [HwId=baf1d04e-fd16-5e6a-93cc-1c23d171f879] DeviceId=StarlabsLabTopL4 -VersionFormat=triplet + +# Starlabs LabTop L4 (in coreboot) +[Guid=0ee5867c-93f0-5fb4-adf1-9d686ea1183a] +Branch=coreboot diff --git a/plugins/flashrom/fu-flashrom-device.c b/plugins/flashrom/fu-flashrom-device.c new file mode 100644 index 000000000..8927a3d4d --- /dev/null +++ b/plugins/flashrom/fu-flashrom-device.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2017 Richard Hughes + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#include "config.h" + +#include "fu-flashrom-device.h" + +struct _FuFlashromDevice { + FuDevice parent_instance; +}; + +G_DEFINE_TYPE (FuFlashromDevice, fu_flashrom_device, FU_TYPE_DEVICE) + +static void +fu_flashrom_device_init (FuFlashromDevice *self) +{ + fu_device_set_protocol (FU_DEVICE (self), "org.flashrom"); + fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_INTERNAL); + fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_UPDATABLE); + fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_NEEDS_REBOOT); + fu_device_add_flag (FU_DEVICE (self), FWUPD_DEVICE_FLAG_REQUIRE_AC); + fu_device_add_instance_id (FU_DEVICE (self), "main-system-firmware"); + fu_device_add_internal_flag (FU_DEVICE (self), FU_DEVICE_INTERNAL_FLAG_ENSURE_SEMVER); + fu_device_set_version_format (FU_DEVICE (self), FWUPD_VERSION_FORMAT_TRIPLET); + fu_device_add_icon (FU_DEVICE (self), "computer"); +} + +static void +fu_flashrom_device_class_init (FuFlashromDeviceClass *klass) +{ +} + +FuDevice * +fu_flashrom_device_new (void) +{ + return FU_DEVICE (g_object_new (FU_TYPE_FLASHROM_DEVICE, NULL)); +} diff --git a/plugins/flashrom/fu-flashrom-device.h b/plugins/flashrom/fu-flashrom-device.h new file mode 100644 index 000000000..7da298763 --- /dev/null +++ b/plugins/flashrom/fu-flashrom-device.h @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2017 Richard Hughes + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#pragma once + +#include "fu-plugin.h" + +#define FU_TYPE_FLASHROM_DEVICE (fu_flashrom_device_get_type ()) +G_DECLARE_FINAL_TYPE (FuFlashromDevice, fu_flashrom_device, FU, FLASHROM_DEVICE, FuDevice) + +FuDevice *fu_flashrom_device_new (void); diff --git a/plugins/flashrom/fu-plugin-flashrom.c b/plugins/flashrom/fu-plugin-flashrom.c index b58493edd..fbedf8c55 100644 --- a/plugins/flashrom/fu-plugin-flashrom.c +++ b/plugins/flashrom/fu-plugin-flashrom.c @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2017 Richard Hughes + * Copyright (C) 2019 9elements Agency GmbH * * Licensed under the GNU General Public License Version 2 * @@ -24,8 +25,10 @@ #include #include "fu-plugin-vfuncs.h" +#include "fu-flashrom-device.h" #include "fu-hash.h" -#include "libflashrom.h" + +#include #define SELFCHECK_TRUE 1 @@ -42,6 +45,7 @@ fu_plugin_init (FuPlugin *plugin) fu_plugin_set_build_hash (plugin, FU_BUILD_HASH); fu_plugin_alloc_data (plugin, sizeof (FuPluginData)); fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_METADATA_SOURCE, "linux_lockdown"); + fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_CONFLICTS, "coreboot"); /* obsoleted */ } void @@ -84,6 +88,91 @@ fu_plugin_flashrom_debug_cb (enum flashrom_log_level lvl, const char *fmt, va_li return 0; } +static void +fu_plugin_flashrom_device_set_version (FuPlugin *plugin, FuDevice *device) +{ + const gchar *version; + const gchar *version_major; + const gchar *version_minor; + + /* as-is */ + version = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_BIOS_VERSION); + if (version != NULL) { + /* some Lenovo hardware requires a specific prefix for the EC, + * so strip it before we use ensure-semver */ + if (strlen (version) > 9 && g_str_has_prefix (version, "CBET")) + version += 9; + + /* this may not "stick" if there are no numeric chars */ + fu_device_set_version (device, version); + if (fu_device_get_version (device) != NULL) + return; + } + + /* component parts only */ + version_major = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_BIOS_MAJOR_RELEASE); + version_minor = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_BIOS_MINOR_RELEASE); + if (version_major != NULL && version_minor != NULL) { + g_autofree gchar *tmp = g_strdup_printf ("%s.%s.0", + version_major, + version_minor); + fu_device_set_version (device, tmp); + return; + } +} +static void +fu_plugin_flashrom_device_set_bios_info (FuPlugin *plugin, FuDevice *device) +{ + const guint8 *buf; + gsize bufsz; + guint32 bios_char = 0x0; + guint8 bios_sz = 0x0; + g_autoptr(GBytes) bios_table = NULL; + + /* get SMBIOS info */ + bios_table = fu_plugin_get_smbios_data (plugin, FU_SMBIOS_STRUCTURE_TYPE_BIOS); + if (bios_table == NULL) + return; + + /* ROM size */ + buf = g_bytes_get_data (bios_table, &bufsz); + if (fu_common_read_uint8_safe (buf, bufsz, 0x9, &bios_sz, NULL)) { + guint64 firmware_size = (bios_sz + 1) * 64 * 1024; + fu_device_set_firmware_size_max (device, firmware_size); + } + + /* BIOS characteristics */ + if (fu_common_read_uint32_safe (buf, bufsz, 0xa, &bios_char, G_LITTLE_ENDIAN, NULL)) { + if ((bios_char & (1 << 11)) == 0) + fu_device_remove_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE); + } +} + +static void +fu_plugin_flashrom_device_set_hwids (FuPlugin *plugin, FuDevice *device) +{ + static const gchar *hwids[] = { + "HardwareID-3", + "HardwareID-4", + "HardwareID-5", + "HardwareID-6", + "HardwareID-10", + /* a more useful one for coreboot branch detection */ + FU_HWIDS_KEY_MANUFACTURER "&" + FU_HWIDS_KEY_FAMILY "&" + FU_HWIDS_KEY_PRODUCT_NAME "&" + FU_HWIDS_KEY_PRODUCT_SKU "&" + FU_HWIDS_KEY_BIOS_VENDOR, + }; + /* don't include FU_HWIDS_KEY_BIOS_VERSION */ + for (guint i = 0; i < G_N_ELEMENTS (hwids); i++) { + g_autofree gchar *str = NULL; + str = fu_plugin_get_hwid_replace_value (plugin, hwids[i], NULL); + if (str != NULL) + fu_device_add_instance_id (device, str); + } +} + gboolean fu_plugin_coldplug (FuPlugin *plugin, GError **error) { @@ -93,7 +182,6 @@ fu_plugin_coldplug (FuPlugin *plugin, GError **error) gint rc; g_autoptr(GPtrArray) devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); - dmi_vendor = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_BIOS_VENDOR); for (guint i = 0; i < hwids->len; i++) { const gchar *guid = g_ptr_array_index (hwids, i); const gchar *quirk_str; @@ -104,23 +192,26 @@ fu_plugin_coldplug (FuPlugin *plugin, GError **error) "DeviceId"); if (quirk_str != NULL) { g_autofree gchar *device_id = g_strdup_printf ("flashrom-%s", quirk_str); - g_autoptr(FuDevice) dev = fu_device_new (); - fu_device_set_id (dev, device_id); - fu_device_set_quirks (dev, fu_plugin_get_quirks (plugin)); - fu_device_set_protocol (dev, "org.flashrom"); - fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_INTERNAL); - fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE); - fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_NEEDS_REBOOT); - fu_device_set_name (dev, fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_PRODUCT_NAME)); - fu_device_set_vendor (dev, fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_MANUFACTURER)); - fu_device_add_internal_flag (dev, FU_DEVICE_INTERNAL_FLAG_ENSURE_SEMVER); - fu_device_set_version (dev, fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_BIOS_VERSION)); - fu_device_add_guid (dev, guid); + g_autoptr(FuDevice) device = fu_flashrom_device_new (); + fu_device_set_quirks (device, fu_plugin_get_quirks (plugin)); + fu_device_set_name (device, fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_PRODUCT_NAME)); + fu_device_set_vendor (device, fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_MANUFACTURER)); + + /* use same VendorID logic as with UEFI */ + dmi_vendor = fu_plugin_get_dmi_value (plugin, 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); + fu_device_add_vendor_id (FU_DEVICE (device), vendor_id); } - g_ptr_array_add (devices, g_steal_pointer (&dev)); + + fu_device_set_id (device, device_id); + fu_device_add_guid (device, guid); + fu_plugin_flashrom_device_set_version (plugin, device); + fu_plugin_flashrom_device_set_hwids (plugin, device); + fu_plugin_flashrom_device_set_bios_info (plugin, device); + if (!fu_device_setup (device, error)) + return FALSE; + g_ptr_array_add (devices, g_steal_pointer (&device)); break; } } diff --git a/plugins/flashrom/meson.build b/plugins/flashrom/meson.build index 18060d9dc..43949a462 100644 --- a/plugins/flashrom/meson.build +++ b/plugins/flashrom/meson.build @@ -7,6 +7,7 @@ install_data(['flashrom.quirk'], shared_module('fu_plugin_flashrom', fu_hash, sources : [ + 'fu-flashrom-device.c', 'fu-plugin-flashrom.c', ], include_directories : [ diff --git a/plugins/meson.build b/plugins/meson.build index 8f9dae448..9d340fdb1 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -143,10 +143,6 @@ if get_option('plugin_flashrom') subdir('flashrom') endif -if get_option('plugin_coreboot') -subdir('coreboot') -endif - if get_option('plugin_platform_integrity') subdir('platform-integrity') endif