trivial: Add a read_firmware() vfunc to FuDevice

This commit is contained in:
Richard Hughes 2018-05-14 16:37:56 +01:00
parent 0a0483b2ce
commit c48d0cfa0c
9 changed files with 54 additions and 19 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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++) {

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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++) {

View File

@ -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)
{

View File

@ -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