diff --git a/plugins/mtd/README.md b/plugins/mtd/README.md index 8a55617b8..6eefb8849 100644 --- a/plugins/mtd/README.md +++ b/plugins/mtd/README.md @@ -19,6 +19,10 @@ These devices use custom DeviceInstanceId values built from the device `NAME` an * `MTD\VENDOR_foo&NAME_baz` * `MTD\VENDOR_foo&PRODUCT_bar&NAME_baz` +If the `FirmwareGType` quirk is set for the device then the firmware is read back from the device at +daemon startup and parsed for the version number. +In the event the firmware has multiple child images then the device GUIDs are used as firmware IDs. + ## Update Behavior The MTD device is erased in chunks, written and then read back to verify. diff --git a/plugins/mtd/fu-mtd-device.c b/plugins/mtd/fu-mtd-device.c index 77057c567..50cf2814c 100644 --- a/plugins/mtd/fu-mtd-device.c +++ b/plugins/mtd/fu-mtd-device.c @@ -30,6 +30,8 @@ fu_mtd_device_to_string(FuDevice *device, guint idt, GString *str) static gboolean fu_mtd_device_setup(FuDevice *device, GError **error) { + FuFirmware *firmware_child = NULL; + GPtrArray *instance_ids; GType firmware_gtype = fu_device_get_firmware_gtype(device); const gchar *fn; g_autoptr(FuFirmware) firmware = NULL; @@ -53,11 +55,24 @@ fu_mtd_device_setup(FuDevice *device, GError **error) if (!fu_firmware_parse_file(firmware, file, FWUPD_INSTALL_FLAG_NONE, error)) return FALSE; + /* find the firmware child that matches any of the device GUID, + * and use the main firmware version if no match */ + instance_ids = fu_device_get_instance_ids(device); + for (guint i = 0; i < instance_ids->len; i++) { + const gchar *instance_id = g_ptr_array_index(instance_ids, i); + g_autofree gchar *guid = fwupd_guid_hash_string(instance_id); + firmware_child = fu_firmware_get_image_by_id(firmware, guid, NULL); + if (firmware_child != NULL) + break; + } + if (firmware_child == NULL) + firmware_child = firmware; + /* copy over the version */ - if (fu_firmware_get_version(firmware) != NULL) - fu_device_set_version(device, fu_firmware_get_version(firmware)); - if (fu_firmware_get_version_raw(firmware) != G_MAXUINT64) - fu_device_set_version_raw(device, fu_firmware_get_version_raw(firmware)); + if (fu_firmware_get_version(firmware_child) != NULL) + fu_device_set_version(device, fu_firmware_get_version(firmware_child)); + if (fu_firmware_get_version_raw(firmware_child) != G_MAXUINT64) + fu_device_set_version_raw(device, fu_firmware_get_version_raw(firmware_child)); /* success */ return TRUE;