From 40b6b3f5971d256e7d1c0af972eb9fe7157f595a Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 30 Jul 2015 18:41:30 +0100 Subject: [PATCH] Prefer the GUID from the firmware than the device The firmware may be more generic, and it also allows us to match the GUID then doing 'verify' on a device with a different device PID than the firmware actually declares. --- src/fu-provider-udev.c | 20 ++++++++++++++------ src/fu-rom.c | 19 +++++++++++++++++++ src/fu-rom.h | 1 + src/fu-util.c | 7 +------ 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/fu-provider-udev.c b/src/fu-provider-udev.c index c18250e4c..e90707320 100644 --- a/src/fu-provider-udev.c +++ b/src/fu-provider-udev.c @@ -169,18 +169,26 @@ fu_provider_udev_client_add (FuProviderUdev *provider_udev, GUdevDevice *device) rom_fn, error->message); } version = g_strdup (fu_rom_get_version (rom)); + + /* prefer the GUID from the firmware rather than the + * hardware as the firmware may be more generic, which + * also allows us to match the GUID when doing 'verify' + * on a device with a different PID to the firmware */ + guid_new = g_strdup (fu_rom_get_guid (rom)); } /* we failed */ if (version == NULL) return; - /* check the guid */ - if (!fu_guid_is_valid (guid)) { - guid_new = fu_guid_generate_from_string (guid); - g_debug ("Fixing GUID %s->%s", guid, guid_new); - } else { - guid_new = g_strdup (guid); + /* no GUID from the ROM, so fix up the VID:PID */ + if (guid_new == NULL) { + if (!fu_guid_is_valid (guid)) { + guid_new = fu_guid_generate_from_string (guid); + g_debug ("Fixing GUID %s->%s", guid, guid_new); + } else { + guid_new = g_strdup (guid); + } } /* did we get enough data */ diff --git a/src/fu-rom.c b/src/fu-rom.c index 409cc9c27..dda30ff7b 100644 --- a/src/fu-rom.c +++ b/src/fu-rom.c @@ -28,6 +28,7 @@ #include #include "fu-cleanup.h" +#include "fu-guid.h" #include "fu-rom.h" static void fu_rom_finalize (GObject *object); @@ -68,6 +69,7 @@ struct _FuRomPrivate GInputStream *stream; FuRomKind kind; gchar *version; + gchar *guid; guint16 vendor; guint16 model; GPtrArray *hdrs; /* of FuRomPciHeader */ @@ -631,6 +633,7 @@ fu_rom_load_file (FuRom *rom, GFile *file, FuRomLoadFlags flags, guint number_reads = 0; _cleanup_error_free_ GError *error_local = NULL; _cleanup_free_ gchar *fn = NULL; + _cleanup_free_ gchar *id = NULL; _cleanup_free_ guint8 *buffer = NULL; _cleanup_object_unref_ GFileOutputStream *output_stream = NULL; @@ -817,6 +820,11 @@ fu_rom_load_file (FuRom *rom, GFile *file, FuRomLoadFlags flags, g_checksum_update (priv->checksum_wip, hdr->rom_data, hdr->rom_len); } + /* update guid */ + id = g_strdup_printf ("0x%04x:0x%04x", priv->vendor, priv->model); + priv->guid = fu_guid_generate_from_string (id); + g_debug ("using %s for %s", priv->guid, id); + /* not known */ if (priv->version == NULL) { g_set_error_literal (error, @@ -849,6 +857,16 @@ fu_rom_get_version (FuRom *rom) return rom->priv->version; } +/** + * fu_rom_get_guid: + **/ +const gchar * +fu_rom_get_guid (FuRom *rom) +{ + g_return_val_if_fail (FU_IS_ROM (rom), NULL); + return rom->priv->guid; +} + /** * fu_rom_get_vendor: **/ @@ -914,6 +932,7 @@ fu_rom_finalize (GObject *object) g_checksum_free (priv->checksum_wip); g_free (priv->version); + g_free (priv->guid); g_ptr_array_unref (priv->hdrs); if (priv->stream != NULL) g_object_unref (priv->stream); diff --git a/src/fu-rom.h b/src/fu-rom.h index 4a1e22b08..db9346cb1 100644 --- a/src/fu-rom.h +++ b/src/fu-rom.h @@ -79,6 +79,7 @@ gboolean fu_rom_extract_all (FuRom *rom, FuRomKind fu_rom_get_kind (FuRom *rom); const gchar *fu_rom_get_version (FuRom *rom); const gchar *fu_rom_get_checksum (FuRom *rom); +const gchar *fu_rom_get_guid (FuRom *rom); guint16 fu_rom_get_vendor (FuRom *rom); guint16 fu_rom_get_model (FuRom *rom); const gchar *fu_rom_kind_to_string (FuRomKind kind); diff --git a/src/fu-util.c b/src/fu-util.c index d04c62811..aaff2df8b 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -876,7 +876,6 @@ fu_util_verify_update (FuUtilPrivate *priv, gchar **values, GError **error) as_store_set_api_version (store, 0.9); for (i = 1; values[i] != NULL; i++) { _cleanup_free_ gchar *guid = NULL; - _cleanup_free_ gchar *id = NULL; _cleanup_object_unref_ AsApp *app = NULL; _cleanup_object_unref_ AsRelease *rel = NULL; _cleanup_object_unref_ FuRom *rom = NULL; @@ -894,11 +893,7 @@ fu_util_verify_update (FuUtilPrivate *priv, gchar **values, GError **error) /* add app to store */ app = as_app_new (); - id = g_strdup_printf ("0x%04x:0x%04x", - fu_rom_get_vendor (rom), - fu_rom_get_model (rom)); - guid = fu_guid_generate_from_string (id); - as_app_set_id (app, guid, -1); + as_app_set_id (app, fu_rom_get_guid (rom), -1); as_app_set_id_kind (app, AS_ID_KIND_FIRMWARE); as_app_set_source_kind (app, AS_APP_SOURCE_KIND_INF); rel = as_release_new ();