From 764df76d34448211a8388024f5a0e4b876e130a8 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 5 Nov 2021 20:53:02 +0000 Subject: [PATCH] Allow overriding the firmware GType from a quirk file This also allows us to remove quite a lot of boilerplate from plugins. --- libfwupdplugin/fu-device.c | 48 ++++++++++++++++++++++ libfwupdplugin/fu-device.h | 4 ++ libfwupdplugin/fu-quirks.c | 1 + libfwupdplugin/fu-quirks.h | 8 ++++ libfwupdplugin/fwupdplugin.map | 2 + plugins/altos/fu-altos-device.c | 14 +------ plugins/analogix/fu-analogix-device.c | 14 +------ plugins/dfu-csr/fu-dfu-csr-device.c | 23 +---------- plugins/ebitdo/fu-ebitdo-device.c | 14 +------ plugins/elanfp/fu-elanfp-device.c | 14 +------ plugins/ep963x/fu-ep963x-device.c | 14 +------ plugins/hailuck/fu-hailuck-bl-device.c | 14 +------ plugins/pixart-rf/fu-pxi-receiver-device.c | 14 +------ plugins/pixart-rf/fu-pxi-wireless-device.c | 14 +------ plugins/solokey/fu-solokey-device.c | 14 +------ plugins/vli/fu-vli-usbhub-msp430-device.c | 14 +------ plugins/wacom-raw/fu-wacom-device.c | 14 +------ plugins/wacom-usb/fu-wac-device.c | 14 +------ plugins/wacom-usb/fu-wac-module-touch.c | 14 +------ 19 files changed, 77 insertions(+), 191 deletions(-) diff --git a/libfwupdplugin/fu-device.c b/libfwupdplugin/fu-device.c index 12835aa9e..eaa4640fa 100644 --- a/libfwupdplugin/fu-device.c +++ b/libfwupdplugin/fu-device.c @@ -67,6 +67,7 @@ typedef struct { guint64 size_max; gint open_refcount; /* atomic */ GType specialized_gtype; + GType firmware_gtype; GPtrArray *possible_plugins; GPtrArray *retry_recs; /* of FuDeviceRetryRecovery */ guint retry_delay; @@ -1611,6 +1612,16 @@ fu_device_set_quirk_kv(FuDevice *self, const gchar *key, const gchar *value, GEr priv->specialized_gtype = g_type_from_name(value); return TRUE; } + if (g_strcmp0(key, FU_QUIRKS_FIRMWARE_GTYPE) == 0) { + if (priv->firmware_gtype != G_TYPE_INVALID) { + g_debug("already set firmware GType to %s, ignoring %s", + g_type_name(priv->firmware_gtype), + value); + return TRUE; + } + priv->firmware_gtype = g_type_from_name(value); + return TRUE; + } if (g_strcmp0(key, FU_QUIRKS_CHILDREN) == 0) { g_auto(GStrv) sections = g_strsplit(value, ",", -1); for (guint i = 0; sections[i] != NULL; i++) { @@ -1646,6 +1657,39 @@ fu_device_get_specialized_gtype(FuDevice *self) return priv->specialized_gtype; } +/** + * fu_device_get_firmware_gtype: + * @self: a #FuDevice + * + * Gets the default firmware type for the device. + * + * Returns: #GType + * + * Since: 1.7.2 + **/ +GType +fu_device_get_firmware_gtype(FuDevice *self) +{ + FuDevicePrivate *priv = GET_PRIVATE(self); + return priv->firmware_gtype; +} + +/** + * fu_device_set_firmware_gtype: + * @self: a #FuDevice + * @firmware_gtype: a #GType + * + * Sets the default firmware type for the device. + * + * Since: 1.7.2 + **/ +void +fu_device_set_firmware_gtype(FuDevice *self, GType firmware_gtype) +{ + FuDevicePrivate *priv = GET_PRIVATE(self); + priv->firmware_gtype = firmware_gtype; +} + static void fu_device_quirks_iter_cb(FuContext *ctx, const gchar *key, const gchar *value, gpointer user_data) { @@ -3571,6 +3615,10 @@ fu_device_prepare_firmware(FuDevice *self, GBytes *fw, FwupdInstallFlags flags, firmware = klass->prepare_firmware(self, fw, flags, error); if (firmware == NULL) return NULL; + } else if (priv->firmware_gtype != G_TYPE_INVALID) { + firmware = g_object_new(priv->firmware_gtype, NULL); + if (!fu_firmware_parse(firmware, fw, flags, error)) + return NULL; } else { firmware = fu_firmware_new_from_bytes(fw); } diff --git a/libfwupdplugin/fu-device.h b/libfwupdplugin/fu-device.h index 0c275a0ff..03bdfd6b3 100644 --- a/libfwupdplugin/fu-device.h +++ b/libfwupdplugin/fu-device.h @@ -541,6 +541,10 @@ FwupdRelease * fu_device_get_release_default(FuDevice *self); GType fu_device_get_specialized_gtype(FuDevice *self); +GType +fu_device_get_firmware_gtype(FuDevice *self); +void +fu_device_set_firmware_gtype(FuDevice *self, GType firmware_gtype); void fu_device_add_internal_flag(FuDevice *self, FuDeviceInternalFlags flag); void diff --git a/libfwupdplugin/fu-quirks.c b/libfwupdplugin/fu-quirks.c index e1819c8c4..a33b7864f 100644 --- a/libfwupdplugin/fu-quirks.c +++ b/libfwupdplugin/fu-quirks.c @@ -516,6 +516,7 @@ fu_quirks_init(FuQuirks *self) fu_quirks_add_possible_key(self, FU_QUIRKS_FIRMWARE_SIZE_MIN); fu_quirks_add_possible_key(self, FU_QUIRKS_FLAGS); fu_quirks_add_possible_key(self, FU_QUIRKS_GTYPE); + fu_quirks_add_possible_key(self, FU_QUIRKS_FIRMWARE_GTYPE); fu_quirks_add_possible_key(self, FU_QUIRKS_GUID); fu_quirks_add_possible_key(self, FU_QUIRKS_ICON); fu_quirks_add_possible_key(self, FU_QUIRKS_INHIBIT); diff --git a/libfwupdplugin/fu-quirks.h b/libfwupdplugin/fu-quirks.h index b4dde715e..998949277 100644 --- a/libfwupdplugin/fu-quirks.h +++ b/libfwupdplugin/fu-quirks.h @@ -220,6 +220,14 @@ fu_quirks_add_possible_key(FuQuirks *self, const gchar *possible_key); * Since: 1.3.7 **/ #define FU_QUIRKS_GTYPE "GType" +/** + * FU_QUIRKS_FIRMWARE_GTYPE: + * + * The quirk key for the custom firmware GType. + * + * Since: 1.7.2 + **/ +#define FU_QUIRKS_FIRMWARE_GTYPE "FirmwareGType" /** * FU_QUIRKS_PROTOCOL: * diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index e9f9affaa..ccaf65745 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -949,6 +949,8 @@ LIBFWUPDPLUGIN_1.7.1 { LIBFWUPDPLUGIN_1.7.2 { global: fu_context_has_hwid_flag; + fu_device_get_firmware_gtype; + fu_device_set_firmware_gtype; fu_udev_device_get_bind_id; fu_udev_device_get_sysfs_attr_uint64; fu_udev_device_seek; diff --git a/plugins/altos/fu-altos-device.c b/plugins/altos/fu-altos-device.c index d6ba4a9e4..cdba530b1 100644 --- a/plugins/altos/fu-altos-device.c +++ b/plugins/altos/fu-altos-device.c @@ -223,18 +223,6 @@ fu_altos_device_write_page(FuAltosDevice *self, return TRUE; } -static FuFirmware * -fu_altos_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_altos_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_altos_device_write_firmware(FuDevice *device, FuFirmware *firmware, @@ -572,6 +560,7 @@ fu_altos_device_init(FuAltosDevice *self) fu_device_set_vendor(FU_DEVICE(self), "altusmetrum.org"); fu_device_set_summary(FU_DEVICE(self), "USB hardware random number generator"); fu_device_add_protocol(FU_DEVICE(self), "org.altusmetrum.altos"); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_ALTOS_FIRMWARE); /* requires manual step */ if (!fu_device_has_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_IS_BOOTLOADER)) @@ -585,7 +574,6 @@ fu_altos_device_class_init(FuAltosDeviceClass *klass) FuDeviceClass *klass_device = FU_DEVICE_CLASS(klass); klass_device->to_string = fu_altos_device_to_string; klass_device->probe = fu_altos_device_probe; - klass_device->prepare_firmware = fu_altos_device_prepare_firmware; klass_device->write_firmware = fu_altos_device_write_firmware; klass_device->dump_firmware = fu_altos_device_dump_firmware; klass_device->set_progress = fu_altos_device_set_progress; diff --git a/plugins/analogix/fu-analogix-device.c b/plugins/analogix/fu-analogix-device.c index d2fa56657..2603cb265 100644 --- a/plugins/analogix/fu-analogix-device.c +++ b/plugins/analogix/fu-analogix-device.c @@ -267,18 +267,6 @@ fu_analogix_device_probe(FuDevice *device, GError **error) return TRUE; } -static FuFirmware * -fu_analogix_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_analogix_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_analogix_device_write_image(FuAnalogixDevice *self, FuFirmware *image, @@ -465,6 +453,7 @@ fu_analogix_device_init(FuAnalogixDevice *self) fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_USABLE_DURING_UPDATE); fu_device_set_version_format(FU_DEVICE(self), FWUPD_VERSION_FORMAT_PAIR); fu_device_set_vendor(FU_DEVICE(self), "Analogix Semiconductor Inc."); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_ANALOGIX_FIRMWARE); } static void @@ -476,7 +465,6 @@ fu_analogix_device_class_init(FuAnalogixDeviceClass *klass) klass_device->setup = fu_analogix_device_setup; klass_device->open = fu_analogix_device_open; klass_device->probe = fu_analogix_device_probe; - klass_device->prepare_firmware = fu_analogix_device_prepare_firmware; klass_device->close = fu_analogix_device_close; klass_device->set_progress = fu_analogix_device_set_progress; } diff --git a/plugins/dfu-csr/fu-dfu-csr-device.c b/plugins/dfu-csr/fu-dfu-csr-device.c index ded200f89..6115c4e8d 100644 --- a/plugins/dfu-csr/fu-dfu-csr-device.c +++ b/plugins/dfu-csr/fu-dfu-csr-device.c @@ -342,27 +342,6 @@ fu_dfu_csr_device_download_chunk(FuDfuCsrDevice *self, guint16 idx, GBytes *chun return TRUE; } -static FuFirmware * -fu_dfu_csr_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_dfu_firmware_new(); - - /* parse the file */ - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - if (g_getenv("FWUPD_DFU_CSR_VERBOSE") != NULL) { - g_autofree gchar *fw_str = NULL; - fw_str = fu_firmware_to_string(firmware); - g_debug("%s", fw_str); - } - - /* success */ - return g_steal_pointer(&firmware); -} - static gboolean fu_dfu_csr_device_download(FuDevice *device, FuFirmware *firmware, @@ -455,6 +434,7 @@ fu_dfu_csr_device_init(FuDfuCsrDevice *self) { fu_device_add_protocol(FU_DEVICE(self), "com.qualcomm.dfu"); fu_device_add_internal_flag(FU_DEVICE(self), FU_DEVICE_INTERNAL_FLAG_REPLUG_MATCH_GUID); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_DFU_FIRMWARE); fu_device_register_private_flag(FU_DEVICE(self), FU_DFU_CSR_DEVICE_FLAG_REQUIRE_DELAY, "require-delay"); @@ -467,7 +447,6 @@ fu_dfu_csr_device_class_init(FuDfuCsrDeviceClass *klass) klass_device->to_string = fu_dfu_csr_device_to_string; klass_device->write_firmware = fu_dfu_csr_device_download; klass_device->dump_firmware = fu_dfu_csr_device_upload; - klass_device->prepare_firmware = fu_dfu_csr_device_prepare_firmware; klass_device->attach = fu_dfu_csr_device_attach; klass_device->setup = fu_dfu_csr_device_setup; klass_device->probe = fu_dfu_csr_device_probe; diff --git a/plugins/ebitdo/fu-ebitdo-device.c b/plugins/ebitdo/fu-ebitdo-device.c index 64a2e14a2..d43d61da4 100644 --- a/plugins/ebitdo/fu-ebitdo-device.c +++ b/plugins/ebitdo/fu-ebitdo-device.c @@ -656,18 +656,6 @@ fu_ebitdo_device_probe(FuDevice *device, GError **error) return TRUE; } -static FuFirmware * -fu_ebitdo_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_ebitdo_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static void fu_ebitdo_set_progress(FuDevice *self, FuProgress *progress) { @@ -685,6 +673,7 @@ fu_ebitdo_device_init(FuEbitdoDevice *self) fu_device_add_protocol(FU_DEVICE(self), "com.8bitdo"); fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_ADD_COUNTERPART_GUIDS); fu_device_add_internal_flag(FU_DEVICE(self), FU_DEVICE_INTERNAL_FLAG_REPLUG_MATCH_GUID); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_EBITDO_FIRMWARE); } static void @@ -697,6 +686,5 @@ fu_ebitdo_device_class_init(FuEbitdoDeviceClass *klass) klass_device->attach = fu_ebitdo_device_attach; klass_device->open = fu_ebitdo_device_open; klass_device->probe = fu_ebitdo_device_probe; - klass_device->prepare_firmware = fu_ebitdo_device_prepare_firmware; klass_device->set_progress = fu_ebitdo_set_progress; } diff --git a/plugins/elanfp/fu-elanfp-device.c b/plugins/elanfp/fu-elanfp-device.c index 781b91ebe..411e329b3 100644 --- a/plugins/elanfp/fu-elanfp-device.c +++ b/plugins/elanfp/fu-elanfp-device.c @@ -34,18 +34,6 @@ struct _FuElanfpDevice { G_DEFINE_TYPE(FuElanfpDevice, fu_elanfp_device, FU_TYPE_USB_DEVICE) -static FuFirmware * -fu_elanfp_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_elanfp_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_elanfp_device_open(FuDevice *device, GError **error) { @@ -439,6 +427,7 @@ fu_elanfp_device_init(FuElanfpDevice *device) fu_device_set_install_duration(FU_DEVICE(self), 10); fu_device_set_firmware_size_min(FU_DEVICE(self), 0x20000); fu_device_set_firmware_size_max(FU_DEVICE(self), 0x90000); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_ELANFP_FIRMWARE); } static void @@ -456,7 +445,6 @@ fu_elanfp_device_class_init(FuElanfpDeviceClass *klass) { FuDeviceClass *klass_device = FU_DEVICE_CLASS(klass); klass_device->setup = fu_elanfp_device_setup; - klass_device->prepare_firmware = fu_elanfp_device_prepare_firmware; klass_device->write_firmware = fu_elanfp_device_write_firmware; klass_device->open = fu_elanfp_device_open; klass_device->close = fu_elanfp_device_close; diff --git a/plugins/ep963x/fu-ep963x-device.c b/plugins/ep963x/fu-ep963x-device.c index b1d2c1a68..c2ac77bc3 100644 --- a/plugins/ep963x/fu-ep963x-device.c +++ b/plugins/ep963x/fu-ep963x-device.c @@ -202,18 +202,6 @@ fu_ep963x_device_setup(FuDevice *device, GError **error) return TRUE; } -static FuFirmware * -fu_ep963x_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_ep963x_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_ep963x_device_wait_cb(FuDevice *device, gpointer user_data, GError **error) { @@ -376,6 +364,7 @@ fu_ep963x_device_init(FuEp963xDevice *self) fu_device_set_version_format(FU_DEVICE(self), FWUPD_VERSION_FORMAT_NUMBER); fu_device_set_remove_delay(FU_DEVICE(self), FU_DEVICE_REMOVE_DELAY_RE_ENUMERATE); fu_device_set_firmware_size(FU_DEVICE(self), FU_EP963_FIRMWARE_SIZE); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_EP963X_FIRMWARE); fu_device_retry_set_delay(FU_DEVICE(self), 100); } @@ -383,7 +372,6 @@ static void fu_ep963x_device_class_init(FuEp963xDeviceClass *klass) { FuDeviceClass *klass_device = FU_DEVICE_CLASS(klass); - klass_device->prepare_firmware = fu_ep963x_device_prepare_firmware; klass_device->write_firmware = fu_ep963x_device_write_firmware; klass_device->attach = fu_ep963x_device_attach; klass_device->detach = fu_ep963x_device_detach; diff --git a/plugins/hailuck/fu-hailuck-bl-device.c b/plugins/hailuck/fu-hailuck-bl-device.c index 9effdf7c5..197a4f6cd 100644 --- a/plugins/hailuck/fu-hailuck-bl-device.c +++ b/plugins/hailuck/fu-hailuck-bl-device.c @@ -209,18 +209,6 @@ fu_hailuck_bl_device_write_block(FuHailuckBlDevice *self, return TRUE; } -static FuFirmware * -fu_hailuck_bl_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_hailuck_kbd_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_hailuck_bl_device_write_firmware(FuDevice *device, FuFirmware *firmware, @@ -303,6 +291,7 @@ static void fu_hailuck_bl_device_init(FuHailuckBlDevice *self) { fu_device_set_firmware_size(FU_DEVICE(self), 0x4000); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_HAILUCK_KBD_FIRMWARE); fu_device_add_protocol(FU_DEVICE(self), "com.hailuck.kbd"); fu_device_set_name(FU_DEVICE(self), "Keyboard [bootloader]"); fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_IS_BOOTLOADER); @@ -319,7 +308,6 @@ fu_hailuck_bl_device_class_init(FuHailuckBlDeviceClass *klass) { FuDeviceClass *klass_device = FU_DEVICE_CLASS(klass); klass_device->dump_firmware = fu_hailuck_bl_device_dump_firmware; - klass_device->prepare_firmware = fu_hailuck_bl_device_prepare_firmware; klass_device->write_firmware = fu_hailuck_bl_device_write_firmware; klass_device->attach = fu_hailuck_bl_device_attach; klass_device->probe = fu_hailuck_bl_device_probe; diff --git a/plugins/pixart-rf/fu-pxi-receiver-device.c b/plugins/pixart-rf/fu-pxi-receiver-device.c index 7b8060a55..f7609502c 100644 --- a/plugins/pixart-rf/fu-pxi-receiver-device.c +++ b/plugins/pixart-rf/fu-pxi-receiver-device.c @@ -536,18 +536,6 @@ fu_pxi_receiver_device_reset(FuDevice *device, GError **error) error); } -static FuFirmware * -fu_pxi_receiver_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_pxi_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_pxi_receiver_device_write_firmware(FuDevice *device, FuFirmware *firmware, @@ -880,6 +868,7 @@ fu_pxi_receiver_device_init(FuPxiReceiverDevice *self) fu_device_set_version_format(FU_DEVICE(self), FWUPD_VERSION_FORMAT_TRIPLET); fu_device_add_vendor_id(FU_DEVICE(self), "USB:0x093A"); fu_device_add_protocol(FU_DEVICE(self), "com.pixart.rf"); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_PXI_FIRMWARE); } static void @@ -890,6 +879,5 @@ fu_pxi_receiver_device_class_init(FuPxiReceiverDeviceClass *klass) klass_device->setup = fu_pxi_receiver_device_setup; klass_device->probe = fu_pxi_receiver_device_probe; klass_device->write_firmware = fu_pxi_receiver_device_write_firmware; - klass_device->prepare_firmware = fu_pxi_receiver_device_prepare_firmware; klass_device->set_progress = fu_pxi_receiver_device_set_progress; } diff --git a/plugins/pixart-rf/fu-pxi-wireless-device.c b/plugins/pixart-rf/fu-pxi-wireless-device.c index 66d5c179b..5d18dd657 100644 --- a/plugins/pixart-rf/fu-pxi-wireless-device.c +++ b/plugins/pixart-rf/fu-pxi-wireless-device.c @@ -570,18 +570,6 @@ fu_pxi_wireless_device_reset(FuDevice *device, GError **error) error); } -static FuFirmware * -fu_pxi_wireless_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_pxi_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_pxi_wireless_device_write_firmware(FuDevice *device, FuFirmware *firmware, @@ -665,6 +653,7 @@ fu_pxi_wireless_device_init(FuPxiWirelessDevice *self) fu_device_set_version_format(FU_DEVICE(self), FWUPD_VERSION_FORMAT_TRIPLET); fu_device_add_vendor_id(FU_DEVICE(self), "USB:0x093A"); fu_device_add_protocol(FU_DEVICE(self), "com.pixart.rf"); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_PXI_FIRMWARE); } static void @@ -672,7 +661,6 @@ fu_pxi_wireless_device_class_init(FuPxiWirelessDeviceClass *klass) { FuDeviceClass *klass_device = FU_DEVICE_CLASS(klass); klass_device->write_firmware = fu_pxi_wireless_device_write_firmware; - klass_device->prepare_firmware = fu_pxi_wireless_device_prepare_firmware; klass_device->to_string = fu_pxi_wireless_device_to_string; klass_device->set_progress = fu_pxi_wireless_device_set_progress; } diff --git a/plugins/solokey/fu-solokey-device.c b/plugins/solokey/fu-solokey-device.c index f51336634..8666afade 100644 --- a/plugins/solokey/fu-solokey-device.c +++ b/plugins/solokey/fu-solokey-device.c @@ -431,18 +431,6 @@ fu_solokey_device_verify(FuSolokeyDevice *self, GBytes *fw_sig, GError **error) return TRUE; } -static FuFirmware * -fu_solokey_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_solokey_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_solokey_device_write_firmware(FuDevice *device, FuFirmware *firmware, @@ -534,6 +522,7 @@ fu_solokey_device_init(FuSolokeyDevice *self) fu_device_add_protocol(FU_DEVICE(self), "com.solokeys"); fu_device_set_name(FU_DEVICE(self), "Solo Secure"); fu_device_set_summary(FU_DEVICE(self), "Open source FIDO2 security key"); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_SOLOKEY_FIRMWARE); fu_device_add_icon(FU_DEVICE(self), "applications-internet"); } @@ -542,7 +531,6 @@ fu_solokey_device_class_init(FuSolokeyDeviceClass *klass) { FuDeviceClass *klass_device = FU_DEVICE_CLASS(klass); klass_device->write_firmware = fu_solokey_device_write_firmware; - klass_device->prepare_firmware = fu_solokey_device_prepare_firmware; klass_device->setup = fu_solokey_device_setup; klass_device->open = fu_solokey_device_open; klass_device->close = fu_solokey_device_close; diff --git a/plugins/vli/fu-vli-usbhub-msp430-device.c b/plugins/vli/fu-vli-usbhub-msp430-device.c index b9827072e..92ec4df94 100644 --- a/plugins/vli/fu-vli-usbhub-msp430-device.c +++ b/plugins/vli/fu-vli-usbhub-msp430-device.c @@ -167,18 +167,6 @@ fu_vli_usbhub_msp430_device_detach(FuDevice *device, FuProgress *progress, GErro return fu_vli_usbhub_i2c_check_status(status, error); } -static FuFirmware * -fu_vli_usbhub_msp430_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_ihex_firmware_new(); - if (!fu_firmware_tokenize(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - typedef struct { guint8 command; guint8 buf[0x40]; @@ -339,6 +327,7 @@ fu_vli_usbhub_msp430_device_init(FuVliUsbhubMsp430Device *self) fu_device_set_version_format(FU_DEVICE(self), FWUPD_VERSION_FORMAT_PAIR); fu_device_set_logical_id(FU_DEVICE(self), "I2C"); fu_device_set_summary(FU_DEVICE(self), "I²C dock management device"); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_IHEX_FIRMWARE); /* the MSP device reboot takes down the entire hub for ~60 seconds */ fu_device_set_remove_delay(FU_DEVICE(self), 120 * 1000); @@ -352,7 +341,6 @@ fu_vli_usbhub_msp430_device_class_init(FuVliUsbhubMsp430DeviceClass *klass) klass_device->setup = fu_vli_usbhub_msp430_device_setup; klass_device->detach = fu_vli_usbhub_msp430_device_detach; klass_device->write_firmware = fu_vli_usbhub_msp430_device_write_firmware; - klass_device->prepare_firmware = fu_vli_usbhub_msp430_device_prepare_firmware; klass_device->set_progress = fu_vli_usbhub_msp430_device_set_progress; } diff --git a/plugins/wacom-raw/fu-wacom-device.c b/plugins/wacom-raw/fu-wacom-device.c index 0d1653d4f..8c438915b 100644 --- a/plugins/wacom-raw/fu-wacom-device.c +++ b/plugins/wacom-raw/fu-wacom-device.c @@ -197,18 +197,6 @@ fu_wacom_device_set_version_bootloader(FuWacomDevice *self, GError **error) return TRUE; } -static FuFirmware * -fu_wacom_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_ihex_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_wacom_device_write_firmware(FuDevice *device, FuFirmware *firmware, @@ -362,6 +350,7 @@ fu_wacom_device_init(FuWacomDevice *self) fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_INTERNAL); fu_device_add_internal_flag(FU_DEVICE(self), FU_DEVICE_INTERNAL_FLAG_REPLUG_MATCH_GUID); fu_device_set_version_format(FU_DEVICE(self), FWUPD_VERSION_FORMAT_PAIR); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_IHEX_FIRMWARE); } static void @@ -369,7 +358,6 @@ fu_wacom_device_class_init(FuWacomDeviceClass *klass) { FuDeviceClass *klass_device = FU_DEVICE_CLASS(klass); klass_device->to_string = fu_wacom_device_to_string; - klass_device->prepare_firmware = fu_wacom_device_prepare_firmware; klass_device->write_firmware = fu_wacom_device_write_firmware; klass_device->attach = fu_wacom_device_attach; klass_device->detach = fu_wacom_device_detach; diff --git a/plugins/wacom-usb/fu-wac-device.c b/plugins/wacom-usb/fu-wac-device.c index 9a26c909c..cd60d8f9d 100644 --- a/plugins/wacom-usb/fu-wac-device.c +++ b/plugins/wacom-usb/fu-wac-device.c @@ -457,18 +457,6 @@ fu_wac_device_switch_to_flash_loader(FuWacDevice *self, GError **error) error); } -static FuFirmware * -fu_wac_device_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_wac_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_wac_device_write_firmware(FuDevice *device, FuFirmware *firmware, @@ -923,6 +911,7 @@ fu_wac_device_init(FuWacDevice *self) fu_device_set_version_format(FU_DEVICE(self), FWUPD_VERSION_FORMAT_BCD); fu_device_set_install_duration(FU_DEVICE(self), 10); fu_device_set_remove_delay(FU_DEVICE(self), FU_DEVICE_REMOVE_DELAY_RE_ENUMERATE); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_WAC_FIRMWARE); } static void @@ -942,7 +931,6 @@ fu_wac_device_class_init(FuWacDeviceClass *klass) GObjectClass *object_class = G_OBJECT_CLASS(klass); FuDeviceClass *klass_device = FU_DEVICE_CLASS(klass); object_class->finalize = fu_wac_device_finalize; - klass_device->prepare_firmware = fu_wac_device_prepare_firmware; klass_device->write_firmware = fu_wac_device_write_firmware; klass_device->to_string = fu_wac_device_to_string; klass_device->setup = fu_wac_device_setup; diff --git a/plugins/wacom-usb/fu-wac-module-touch.c b/plugins/wacom-usb/fu-wac-module-touch.c index c39a7f9cc..4366c936d 100644 --- a/plugins/wacom-usb/fu-wac-module-touch.c +++ b/plugins/wacom-usb/fu-wac-module-touch.c @@ -19,18 +19,6 @@ struct _FuWacModuleTouch { G_DEFINE_TYPE(FuWacModuleTouch, fu_wac_module_touch, FU_TYPE_WAC_MODULE) -static FuFirmware * -fu_wac_module_touch_prepare_firmware(FuDevice *device, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - g_autoptr(FuFirmware) firmware = fu_ihex_firmware_new(); - if (!fu_firmware_parse(firmware, fw, flags, error)) - return NULL; - return g_steal_pointer(&firmware); -} - static gboolean fu_wac_module_touch_write_firmware(FuDevice *device, FuFirmware *firmware, @@ -128,13 +116,13 @@ fu_wac_module_touch_init(FuWacModuleTouch *self) { fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_UPDATABLE); fu_device_set_install_duration(FU_DEVICE(self), 30); + fu_device_set_firmware_gtype(FU_DEVICE(self), FU_TYPE_IHEX_FIRMWARE); } static void fu_wac_module_touch_class_init(FuWacModuleTouchClass *klass) { FuDeviceClass *klass_device = FU_DEVICE_CLASS(klass); - klass_device->prepare_firmware = fu_wac_module_touch_prepare_firmware; klass_device->write_firmware = fu_wac_module_touch_write_firmware; }