mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-14 16:11:22 +00:00
trivial: Refactor the UEFI resource coldplug into a new helper
No functional changes.
This commit is contained in:
parent
9b4a66c8f8
commit
2fac59f64a
@ -476,58 +476,11 @@ fu_plugin_uefi_uefi_type_to_string (guint32 uefi_type)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_coldplug (FuPlugin *plugin, GError **error)
|
||||
static void
|
||||
fu_plugin_uefi_coldplug_resource (FuPlugin *plugin, fwup_resource *re)
|
||||
{
|
||||
AsVersionParseFlag parse_flags;
|
||||
const gchar *product_name;
|
||||
fwup_resource *re;
|
||||
gint supported;
|
||||
g_autoptr(FuDevice) dev = NULL;
|
||||
g_autoptr(fwup_resource_iter) iter = NULL;
|
||||
|
||||
/* supported = 0 : ESRT unspported
|
||||
supported = 1 : unlocked, ESRT supported
|
||||
supported = 2 : it is locked but can be unlocked to support ESRT
|
||||
supported = 3 : it is locked, has been marked to be unlocked on next boot
|
||||
calling unlock again is OK.
|
||||
*/
|
||||
supported = fwup_supported ();
|
||||
if (supported == 0) {
|
||||
g_set_error_literal (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_NOT_SUPPORTED,
|
||||
"UEFI firmware updating not supported");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (supported == 2) {
|
||||
dev = fu_device_new ();
|
||||
fu_device_set_id (dev, "UEFI-dummy-dev0");
|
||||
fu_device_add_guid (dev, "2d47f29b-83a2-4f31-a2e8-63474f4d4c2e");
|
||||
fu_device_set_version (dev, "0");
|
||||
fu_device_add_icon (dev, "computer");
|
||||
fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE);
|
||||
fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_LOCKED);
|
||||
fu_plugin_device_add (plugin, dev);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* this can fail if we have no permissions */
|
||||
if (fwup_resource_iter_create (&iter) < 0) {
|
||||
g_set_error_literal (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_INTERNAL,
|
||||
"Cannot create fwup iter");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set Display Name to the system for all capsules */
|
||||
product_name = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_PRODUCT_NAME);
|
||||
|
||||
/* add each device */
|
||||
parse_flags = fu_plugin_uefi_get_version_format (plugin);
|
||||
while (fwup_resource_iter_next (iter, &re) > 0) {
|
||||
const gchar *uefi_type_str = NULL;
|
||||
efi_guid_t *guid_raw;
|
||||
guint32 uefi_type;
|
||||
@ -537,8 +490,14 @@ fu_plugin_coldplug (FuPlugin *plugin, GError **error)
|
||||
g_autofree gchar *id = NULL;
|
||||
g_autofree gchar *version = NULL;
|
||||
g_autofree gchar *version_lowest = NULL;
|
||||
g_autoptr(FuDevice) dev = NULL;
|
||||
g_autoptr(GString) display_name = g_string_new (NULL);
|
||||
|
||||
parse_flags = fu_plugin_uefi_get_version_format (plugin);
|
||||
|
||||
/* set Display Name to the system for all capsules */
|
||||
product_name = fu_plugin_get_dmi_value (plugin, FU_HWIDS_KEY_PRODUCT_NAME);
|
||||
|
||||
/* set up proper DisplayName */
|
||||
fwup_get_fw_type (re, &uefi_type);
|
||||
if (product_name != NULL)
|
||||
@ -554,14 +513,14 @@ fu_plugin_coldplug (FuPlugin *plugin, GError **error)
|
||||
fwup_get_guid (re, &guid_raw);
|
||||
if (efi_guid_cmp (guid_raw, &UX_CAPSULE_GUID) == 0) {
|
||||
g_debug ("skipping entry, detected fake BGRT");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
/* convert to strings */
|
||||
guid = fu_plugin_uefi_guid_to_string (guid_raw);
|
||||
if (guid == NULL) {
|
||||
g_warning ("failed to convert guid to string");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
fwup_get_fw_version(re, &version_raw);
|
||||
@ -599,6 +558,51 @@ fu_plugin_coldplug (FuPlugin *plugin, GError **error)
|
||||
}
|
||||
fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_REQUIRE_AC);
|
||||
fu_plugin_device_add (plugin, dev);
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_coldplug (FuPlugin *plugin, GError **error)
|
||||
{
|
||||
fwup_resource *re;
|
||||
gint supported;
|
||||
g_autoptr(fwup_resource_iter) iter = NULL;
|
||||
|
||||
/* supported = 0 : ESRT unspported
|
||||
supported = 1 : unlocked, ESRT supported
|
||||
supported = 2 : it is locked but can be unlocked to support ESRT
|
||||
supported = 3 : it is locked, has been marked to be unlocked on next boot
|
||||
calling unlock again is OK.
|
||||
*/
|
||||
supported = fwup_supported ();
|
||||
if (supported == 0) {
|
||||
g_set_error_literal (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_NOT_SUPPORTED,
|
||||
"UEFI firmware updating not supported");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (supported == 2) {
|
||||
g_autoptr(FuDevice) dev = fu_device_new ();
|
||||
fu_device_set_id (dev, "UEFI-dummy-dev0");
|
||||
fu_device_add_guid (dev, "2d47f29b-83a2-4f31-a2e8-63474f4d4c2e");
|
||||
fu_device_set_version (dev, "0");
|
||||
fu_device_add_icon (dev, "computer");
|
||||
fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE);
|
||||
fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_LOCKED);
|
||||
fu_plugin_device_add (plugin, dev);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* add each device */
|
||||
if (fwup_resource_iter_create (&iter) < 0) {
|
||||
g_set_error_literal (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_INTERNAL,
|
||||
"Cannot create fwup iter");
|
||||
return FALSE;
|
||||
}
|
||||
while (fwup_resource_iter_next (iter, &re) > 0)
|
||||
fu_plugin_uefi_coldplug_resource (plugin, re);
|
||||
return TRUE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user