mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-05 19:28:12 +00:00
uefi: Set the quirks on created devices
Ensure the quirk object is set, and then add the GUIDs first so that the version format can be set from a quirk file. Additionally, only overwrite the fallback name if the name has not already been set manually from a quirk.
This commit is contained in:
parent
89ab873f72
commit
ce712426f8
@ -477,36 +477,22 @@ fu_plugin_uefi_coldplug_device (FuPlugin *plugin, FuUefiDevice *dev, GError **er
|
||||
{
|
||||
FuUefiDeviceKind device_kind;
|
||||
FuVersionFormat version_format;
|
||||
guint32 version_raw;
|
||||
g_autofree gchar *name = NULL;
|
||||
g_autofree gchar *version_lowest = NULL;
|
||||
g_autofree gchar *version = NULL;
|
||||
|
||||
/* add details to the device */
|
||||
/* set default version format */
|
||||
device_kind = fu_uefi_device_get_kind (dev);
|
||||
version_format = fu_plugin_uefi_get_version_format_for_type (plugin, device_kind);
|
||||
version_raw = fu_uefi_device_get_version (dev);
|
||||
version = fu_common_version_from_uint32 (version_raw, version_format);
|
||||
fu_device_set_version (dev, version);
|
||||
name = fu_plugin_uefi_get_name_for_type (plugin, fu_uefi_device_get_kind (dev));
|
||||
if (name != NULL)
|
||||
fu_device_set_name (FU_DEVICE (dev), name);
|
||||
version_raw = fu_uefi_device_get_version_lowest (dev);
|
||||
if (version_raw != 0) {
|
||||
version_lowest = fu_common_version_from_uint32 (version_raw,
|
||||
version_format);
|
||||
fu_device_set_version_lowest (FU_DEVICE (dev), version_lowest);
|
||||
}
|
||||
fu_device_add_flag (FU_DEVICE (dev), FWUPD_DEVICE_FLAG_INTERNAL);
|
||||
fu_device_add_flag (FU_DEVICE (dev), FWUPD_DEVICE_FLAG_NEEDS_REBOOT);
|
||||
fu_device_add_flag (FU_DEVICE (dev), FWUPD_DEVICE_FLAG_REQUIRE_AC);
|
||||
if (device_kind == FU_UEFI_DEVICE_KIND_DEVICE_FIRMWARE) {
|
||||
/* nothing better in the icon naming spec */
|
||||
fu_device_add_icon (FU_DEVICE (dev), "audio-card");
|
||||
} else {
|
||||
/* this is probably system firmware */
|
||||
fu_device_add_icon (FU_DEVICE (dev), "computer");
|
||||
fu_device_add_guid (FU_DEVICE (dev), "main-system-firmware");
|
||||
fu_device_set_version_format (FU_DEVICE (dev), version_format);
|
||||
|
||||
/* probe to get add GUIDs (and hence any quirk fixups) */
|
||||
if (!fu_device_probe (FU_DEVICE (dev), error))
|
||||
return FALSE;
|
||||
|
||||
/* set fallback name if nothing else is set */
|
||||
if (fu_device_get_name (FU_DEVICE (dev)) == 0) {
|
||||
g_autofree gchar *name = NULL;
|
||||
name = fu_plugin_uefi_get_name_for_type (plugin, fu_uefi_device_get_kind (dev));
|
||||
if (name != NULL)
|
||||
fu_device_set_name (FU_DEVICE (dev), name);
|
||||
}
|
||||
|
||||
/* success */
|
||||
@ -741,6 +727,7 @@ fu_plugin_coldplug (FuPlugin *plugin, GError **error)
|
||||
for (guint i = 0; i < entries->len; i++) {
|
||||
const gchar *path = g_ptr_array_index (entries, i);
|
||||
g_autoptr(FuUefiDevice) dev = fu_uefi_device_new_from_entry (path);
|
||||
fu_device_set_quirks (FU_DEVICE (dev), fu_plugin_get_quirks (plugin));
|
||||
if (!fu_plugin_uefi_coldplug_device (plugin, dev, error))
|
||||
return FALSE;
|
||||
if (error_esp != NULL) {
|
||||
|
@ -367,6 +367,61 @@ fu_uefi_device_write_firmware (FuDevice *device, GBytes *fw, GError **error)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
fu_uefi_device_probe (FuDevice *device, GError **error)
|
||||
{
|
||||
FuUefiDevice *self = FU_UEFI_DEVICE (device);
|
||||
FuVersionFormat version_format;
|
||||
g_autofree gchar *guid_devid = NULL;
|
||||
g_autofree gchar *guid_strup = NULL;
|
||||
g_autofree gchar *version_lowest = NULL;
|
||||
g_autofree gchar *version = NULL;
|
||||
|
||||
/* broken sysfs? */
|
||||
if (self->fw_class == NULL) {
|
||||
g_set_error_literal (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_NOT_SUPPORTED,
|
||||
"failed to read fw_class");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* add GUID first, as quirks may set the version format */
|
||||
fu_device_add_guid (device, self->fw_class);
|
||||
|
||||
/* set versions */
|
||||
version_format = fu_device_get_version_format (device);
|
||||
version = fu_common_version_from_uint32 (self->fw_version, version_format);
|
||||
fu_device_set_version (device, version);
|
||||
if (self->fw_version_lowest != 0) {
|
||||
version_lowest = fu_common_version_from_uint32 (self->fw_version_lowest,
|
||||
version_format);
|
||||
fu_device_set_version_lowest (device, version_lowest);
|
||||
}
|
||||
|
||||
/* set flags */
|
||||
fu_device_add_flag (device, FWUPD_DEVICE_FLAG_INTERNAL);
|
||||
fu_device_add_flag (device, FWUPD_DEVICE_FLAG_NEEDS_REBOOT);
|
||||
fu_device_add_flag (device, FWUPD_DEVICE_FLAG_REQUIRE_AC);
|
||||
|
||||
/* add icons */
|
||||
if (self->kind == FU_UEFI_DEVICE_KIND_DEVICE_FIRMWARE) {
|
||||
/* nothing better in the icon naming spec */
|
||||
fu_device_add_icon (device, "audio-card");
|
||||
} else {
|
||||
/* this is probably system firmware */
|
||||
fu_device_add_icon (device, "computer");
|
||||
fu_device_add_guid (device, "main-system-firmware");
|
||||
}
|
||||
|
||||
/* Windows seems to be case insensitive, but for convenience we'll
|
||||
* match the upper case values typically specified in the .inf file */
|
||||
guid_strup = g_ascii_strup (self->fw_class, -1);
|
||||
guid_devid = g_strdup_printf ("UEFI\\RES_{%s}", guid_strup);
|
||||
fu_device_add_guid (device, guid_devid);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
fu_uefi_device_init (FuUefiDevice *self)
|
||||
{
|
||||
@ -389,26 +444,10 @@ fu_uefi_device_class_init (FuUefiDeviceClass *klass)
|
||||
FuDeviceClass *klass_device = FU_DEVICE_CLASS (klass);
|
||||
object_class->finalize = fu_uefi_device_finalize;
|
||||
klass_device->to_string = fu_uefi_device_to_string;
|
||||
klass_device->probe = fu_uefi_device_probe;
|
||||
klass_device->write_firmware = fu_uefi_device_write_firmware;
|
||||
}
|
||||
|
||||
static void
|
||||
fu_uefi_device_add_win10_guid (FuUefiDevice *self)
|
||||
{
|
||||
g_autofree gchar *guid_devid = NULL;
|
||||
g_autofree gchar *guid_strup = NULL;
|
||||
|
||||
/* broken sysfs? */
|
||||
if (self->fw_class == NULL)
|
||||
return;
|
||||
|
||||
/* windows seems to be case insensitive, but for convenience we'll
|
||||
* match the upper case values typically specified in the .inf file */
|
||||
guid_strup = g_ascii_strup (self->fw_class, -1);
|
||||
guid_devid = g_strdup_printf ("UEFI\\RES_{%s}", guid_strup);
|
||||
fu_device_add_guid (FU_DEVICE (self), guid_devid);
|
||||
}
|
||||
|
||||
FuUefiDevice *
|
||||
fu_uefi_device_new_from_entry (const gchar *entry_path)
|
||||
{
|
||||
@ -423,10 +462,8 @@ fu_uefi_device_new_from_entry (const gchar *entry_path)
|
||||
|
||||
/* read values from sysfs */
|
||||
fw_class_fn = g_build_filename (entry_path, "fw_class", NULL);
|
||||
if (g_file_get_contents (fw_class_fn, &self->fw_class, NULL, NULL)) {
|
||||
if (g_file_get_contents (fw_class_fn, &self->fw_class, NULL, NULL))
|
||||
g_strdelimit (self->fw_class, "\n", '\0');
|
||||
fu_device_add_guid (FU_DEVICE (self), self->fw_class);
|
||||
}
|
||||
self->capsule_flags = fu_uefi_read_file_as_uint64 (entry_path, "capsule_flags");
|
||||
self->kind = fu_uefi_read_file_as_uint64 (entry_path, "fw_type");
|
||||
self->fw_version = fu_uefi_read_file_as_uint64 (entry_path, "fw_version");
|
||||
@ -444,9 +481,6 @@ fu_uefi_device_new_from_entry (const gchar *entry_path)
|
||||
self->fw_class, self->fmp_hardware_instance);
|
||||
fu_device_set_id (FU_DEVICE (self), id);
|
||||
|
||||
/* this is the DeviceID used in Windows 10 */
|
||||
fu_uefi_device_add_win10_guid (self);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -467,9 +501,6 @@ fu_uefi_device_new_from_dev (FuDevice *dev)
|
||||
self->capsule_flags = 0; /* FIXME? */
|
||||
self->fw_version = 0; /* FIXME? */
|
||||
g_assert (self->fw_class != NULL);
|
||||
|
||||
/* this is the DeviceID used in Windows 10 */
|
||||
fu_uefi_device_add_win10_guid (self);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user