From c48d0cfa0c2153bc99c268ec5494336f9d93f86a Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 14 May 2018 16:37:56 +0100 Subject: [PATCH] trivial: Add a read_firmware() vfunc to FuDevice --- plugins/altos/fu-altos-device.c | 12 +++++++----- plugins/altos/fu-altos-device.h | 2 -- plugins/altos/fu-plugin-altos.c | 3 +-- plugins/csr/fu-csr-device.c | 12 +++++++----- plugins/csr/fu-csr-device.h | 2 -- plugins/csr/fu-csr-tool.c | 2 +- plugins/csr/fu-plugin-csr.c | 2 +- src/fu-device.c | 32 ++++++++++++++++++++++++++++++++ src/fu-device.h | 6 +++++- 9 files changed, 54 insertions(+), 19 deletions(-) diff --git a/plugins/altos/fu-altos-device.c b/plugins/altos/fu-altos-device.c index da3c7959e..1c62a621d 100644 --- a/plugins/altos/fu-altos-device.c +++ b/plugins/altos/fu-altos-device.c @@ -558,10 +558,11 @@ fu_altos_device_write_firmware (FuDevice *device, GBytes *fw, GError **error) return TRUE; } -GBytes * -fu_altos_device_read_firmware (FuAltosDevice *device, GError **error) +static GBytes * +fu_altos_device_read_firmware (FuDevice *device, GError **error) { - FuAltosDevicePrivate *priv = GET_PRIVATE (device); + FuAltosDevice *self = FU_ALTOS_DEVICE (device); + FuAltosDevicePrivate *priv = GET_PRIVATE (self); guint flash_len; g_autoptr(FuDeviceLocker) locker = NULL; g_autoptr(GString) buf = g_string_new (NULL); @@ -605,12 +606,12 @@ fu_altos_device_read_firmware (FuAltosDevice *device, GError **error) g_autoptr(GString) str = NULL; /* request data from device */ - str = fu_altos_device_read_page (device, i, error); + str = fu_altos_device_read_page (self, i, error); if (str == NULL) return NULL; /* progress */ - fu_device_set_progress_full (FU_DEVICE (device), + fu_device_set_progress_full (device, i - priv->addr_base, priv->addr_bound - priv->addr_base); g_string_append_len (buf, str->str, str->len); @@ -779,6 +780,7 @@ fu_altos_device_class_init (FuAltosDeviceClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); FuDeviceClass *klass_device = FU_DEVICE_CLASS (klass); klass_device->write_firmware = fu_altos_device_write_firmware; + klass_device->read_firmware = fu_altos_device_read_firmware; object_class->finalize = fu_altos_device_finalize; } diff --git a/plugins/altos/fu-altos-device.h b/plugins/altos/fu-altos-device.h index ec10000cf..9adf2065b 100644 --- a/plugins/altos/fu-altos-device.h +++ b/plugins/altos/fu-altos-device.h @@ -58,8 +58,6 @@ const gchar *fu_altos_device_kind_to_string (FuAltosDeviceKind kind); FuAltosDeviceKind fu_altos_device_get_kind (FuAltosDevice *device); gboolean fu_altos_device_probe (FuAltosDevice *device, GError **error); -GBytes *fu_altos_device_read_firmware (FuAltosDevice *device, - GError **error); G_END_DECLS diff --git a/plugins/altos/fu-plugin-altos.c b/plugins/altos/fu-plugin-altos.c index 3bbd08dfc..478b8b7f5 100644 --- a/plugins/altos/fu-plugin-altos.c +++ b/plugins/altos/fu-plugin-altos.c @@ -78,8 +78,7 @@ fu_plugin_verify (FuPlugin *plugin, /* get data */ fu_device_set_status (dev, FWUPD_STATUS_DEVICE_VERIFY); - blob_fw = fu_altos_device_read_firmware (FU_ALTOS_DEVICE (dev), - error); + blob_fw = fu_device_read_firmware (dev, error); if (blob_fw == NULL) return FALSE; for (guint i = 0; checksum_types[i] != 0; i++) { diff --git a/plugins/csr/fu-csr-device.c b/plugins/csr/fu-csr-device.c index a0869b2a1..b5803a4f1 100644 --- a/plugins/csr/fu-csr-device.c +++ b/plugins/csr/fu-csr-device.c @@ -280,15 +280,16 @@ fu_csr_device_upload_chunk (FuCsrDevice *self, GError **error) sz - FU_CSR_COMMAND_HEADER_SIZE); } -GBytes * -fu_csr_device_upload (FuCsrDevice *self, GError **error) +static GBytes * +fu_csr_device_upload (FuDevice *device, GError **error) { + FuCsrDevice *self = FU_CSR_DEVICE (device); g_autoptr(GPtrArray) chunks = NULL; guint32 total_sz = 0; gsize done_sz = 0; /* notify UI */ - fu_device_set_status (FU_DEVICE (self), FWUPD_STATUS_DEVICE_READ); + fu_device_set_status (device, FWUPD_STATUS_DEVICE_READ); chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref); for (guint32 i = 0; i < 0x3ffffff; i++) { @@ -335,7 +336,7 @@ fu_csr_device_upload (FuCsrDevice *self, GError **error) /* add to chunk array */ done_sz += chunk_sz; g_ptr_array_add (chunks, g_steal_pointer (&chunk)); - fu_device_set_progress_full (FU_DEVICE (self), done_sz, (gsize) total_sz); + fu_device_set_progress_full (device, done_sz, (gsize) total_sz); /* we're done */ if (chunk_sz < 64 - FU_CSR_COMMAND_HEADER_SIZE) @@ -343,7 +344,7 @@ fu_csr_device_upload (FuCsrDevice *self, GError **error) } /* notify UI */ - fu_device_set_status (FU_DEVICE (self), FWUPD_STATUS_IDLE); + fu_device_set_status (device, FWUPD_STATUS_IDLE); return dfu_utils_bytes_join_array (chunks); } @@ -596,6 +597,7 @@ fu_csr_device_class_init (FuCsrDeviceClass *klass) FuUsbDeviceClass *klass_usb_device = FU_USB_DEVICE_CLASS (klass); klass_device->to_string = fu_csr_device_to_string; klass_device->write_firmware = fu_csr_device_download; + klass_device->read_firmware = fu_csr_device_upload; klass_usb_device->open = fu_csr_device_open; klass_usb_device->close = fu_csr_device_close; klass_usb_device->probe = fu_csr_device_probe; diff --git a/plugins/csr/fu-csr-device.h b/plugins/csr/fu-csr-device.h index 927009fe0..a6e08a10a 100644 --- a/plugins/csr/fu-csr-device.h +++ b/plugins/csr/fu-csr-device.h @@ -41,8 +41,6 @@ typedef enum { FuCsrDevice *fu_csr_device_new (GUsbDevice *usb_device); gboolean fu_csr_device_attach (FuCsrDevice *self, GError **error); -GBytes *fu_csr_device_upload (FuCsrDevice *self, - GError **error); void fu_csr_device_set_quirks (FuCsrDevice *self, FuCsrDeviceQuirks quirks); diff --git a/plugins/csr/fu-csr-tool.c b/plugins/csr/fu-csr-tool.c index da065461b..f2120123c 100644 --- a/plugins/csr/fu-csr-tool.c +++ b/plugins/csr/fu-csr-tool.c @@ -245,7 +245,7 @@ fu_csr_tool_dump (FuCsrToolPrivate *priv, gchar **values, GError **error) G_CALLBACK (fu_csr_tool_progress_cb), priv); g_signal_connect (device, "notify::progress", G_CALLBACK (fu_csr_tool_progress_cb), priv); - blob = fu_csr_device_upload (device, error); + blob = fu_device_read_firmware (FU_DEVICE (device), error); if (blob == NULL) return FALSE; diff --git a/plugins/csr/fu-plugin-csr.c b/plugins/csr/fu-plugin-csr.c index 55a29c889..08f914fb5 100644 --- a/plugins/csr/fu-plugin-csr.c +++ b/plugins/csr/fu-plugin-csr.c @@ -55,7 +55,7 @@ fu_plugin_verify (FuPlugin *plugin, FuDevice *device, locker = fu_device_locker_new (device, error); if (locker == NULL) return FALSE; - blob_fw = fu_csr_device_upload (FU_CSR_DEVICE (device), error); + blob_fw = fu_device_read_firmware (device, error); if (blob_fw == NULL) return FALSE; for (guint i = 0; checksum_types[i] != 0; i++) { diff --git a/src/fu-device.c b/src/fu-device.c index ddcd7a559..5487bc332 100644 --- a/src/fu-device.c +++ b/src/fu-device.c @@ -994,6 +994,38 @@ fu_device_write_firmware (FuDevice *device, GBytes *fw, GError **error) return klass->write_firmware (device, fw, error); } +/** + * fu_device_read_firmware: + * @device: A #FuDevice + * @error: A #GError + * + * Reads firmware from the device by calling a plugin-specific vfunc. + * + * Returns: (transfer full): A #GBytes, or %NULL for error + * + * Since: 1.0.8 + **/ +GBytes * +fu_device_read_firmware (FuDevice *device, GError **error) +{ + FuDeviceClass *klass = FU_DEVICE_GET_CLASS (device); + + g_return_val_if_fail (FU_IS_DEVICE (device), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + /* no plugin-specific method */ + if (klass->read_firmware == NULL) { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_SUPPORTED, + "not supported"); + return NULL; + } + + /* call vfunc */ + return klass->read_firmware (device, error); +} + static void fu_device_class_init (FuDeviceClass *klass) { diff --git a/src/fu-device.h b/src/fu-device.h index de415a231..25ddb9df7 100644 --- a/src/fu-device.h +++ b/src/fu-device.h @@ -40,8 +40,10 @@ struct _FuDeviceClass gboolean (*write_firmware) (FuDevice *device, GBytes *fw, GError **error); + GBytes *(*read_firmware) (FuDevice *device, + GError **error); /*< private >*/ - gpointer padding[29]; + gpointer padding[28]; }; /** @@ -167,6 +169,8 @@ FwupdRelease *fu_device_get_release_default (FuDevice *device); gboolean fu_device_write_firmware (FuDevice *device, GBytes *fw, GError **error); +GBytes *fu_device_read_firmware (FuDevice *device, + GError **error); G_END_DECLS