trivial: Add a write_firmware() vfunc to FuDevice

This commit is contained in:
Richard Hughes 2018-05-03 10:17:15 +01:00
parent 12040b51fe
commit 0a0483b2ce
21 changed files with 114 additions and 93 deletions

View File

@ -109,18 +109,6 @@ fu_altos_device_finalize (GObject *object)
G_OBJECT_CLASS (fu_altos_device_parent_class)->finalize (object); G_OBJECT_CLASS (fu_altos_device_parent_class)->finalize (object);
} }
static void
fu_altos_device_init (FuAltosDevice *device)
{
}
static void
fu_altos_device_class_init (FuAltosDeviceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = fu_altos_device_finalize;
}
FuAltosDeviceKind FuAltosDeviceKind
fu_altos_device_get_kind (FuAltosDevice *device) fu_altos_device_get_kind (FuAltosDevice *device)
{ {
@ -432,13 +420,11 @@ fu_altos_device_write_page (FuAltosDevice *device,
return TRUE; return TRUE;
} }
gboolean static gboolean
fu_altos_device_write_firmware (FuAltosDevice *device, fu_altos_device_write_firmware (FuDevice *device, GBytes *fw, GError **error)
GBytes *fw,
FuAltosDeviceWriteFirmwareFlag flags,
GError **error)
{ {
FuAltosDevicePrivate *priv = GET_PRIVATE (device); FuAltosDevice *self = FU_ALTOS_DEVICE (device);
FuAltosDevicePrivate *priv = GET_PRIVATE (self);
GBytes *fw_blob; GBytes *fw_blob;
const gchar *data; const gchar *data;
const gsize data_len; const gsize data_len;
@ -525,7 +511,7 @@ fu_altos_device_write_firmware (FuAltosDevice *device,
} }
/* verify data from device */ /* verify data from device */
if (!fu_altos_device_write_page (device, if (!fu_altos_device_write_page (self,
priv->addr_base + i, priv->addr_base + i,
buf_tmp, buf_tmp,
0x100, 0x100,
@ -533,7 +519,7 @@ fu_altos_device_write_firmware (FuAltosDevice *device,
return FALSE; return FALSE;
/* verify data written on device */ /* verify data written on device */
str = fu_altos_device_read_page (device, str = fu_altos_device_read_page (self,
priv->addr_base + i, priv->addr_base + i,
error); error);
if (str == NULL) if (str == NULL)
@ -557,18 +543,16 @@ fu_altos_device_write_firmware (FuAltosDevice *device,
} }
/* progress */ /* progress */
fu_device_set_progress_full (FU_DEVICE (device), i, flash_len); fu_device_set_progress_full (device, i, flash_len);
g_string_append_len (buf, str->str, str->len); g_string_append_len (buf, str->str, str->len);
} }
/* go to application mode */ /* go to application mode */
if (flags & FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_REBOOT) { if (!fu_altos_device_tty_write (self, "a\n", -1, error))
if (!fu_altos_device_tty_write (device, "a\n", -1, error)) return FALSE;
return FALSE;
}
/* progress complete */ /* progress complete */
fu_device_set_progress_full (FU_DEVICE (device), flash_len, flash_len); fu_device_set_progress_full (device, flash_len, flash_len);
/* success */ /* success */
return TRUE; return TRUE;
@ -784,6 +768,20 @@ fu_altos_device_init_real (FuAltosDevice *device)
} }
} }
static void
fu_altos_device_init (FuAltosDevice *device)
{
}
static void
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;
object_class->finalize = fu_altos_device_finalize;
}
typedef struct { typedef struct {
guint16 vid; guint16 vid;
guint16 pid; guint16 pid;

View File

@ -58,10 +58,6 @@ const gchar *fu_altos_device_kind_to_string (FuAltosDeviceKind kind);
FuAltosDeviceKind fu_altos_device_get_kind (FuAltosDevice *device); FuAltosDeviceKind fu_altos_device_get_kind (FuAltosDevice *device);
gboolean fu_altos_device_probe (FuAltosDevice *device, gboolean fu_altos_device_probe (FuAltosDevice *device,
GError **error); GError **error);
gboolean fu_altos_device_write_firmware (FuAltosDevice *device,
GBytes *fw,
FuAltosDeviceWriteFirmwareFlag flags,
GError **error);
GBytes *fu_altos_device_read_firmware (FuAltosDevice *device, GBytes *fu_altos_device_read_firmware (FuAltosDevice *device,
GError **error); GError **error);

View File

@ -92,9 +92,7 @@ main (int argc, char **argv)
fw = g_bytes_new (data, len); fw = g_bytes_new (data, len);
g_signal_connect (dev, "notify::progress", g_signal_connect (dev, "notify::progress",
G_CALLBACK (fu_altos_tool_progress_cb), NULL); G_CALLBACK (fu_altos_tool_progress_cb), NULL);
if (!fu_altos_device_write_firmware (dev, fw, if (!fu_device_write_firmware (FU_DEVICE (dev), fw, &error)) {
FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_NONE,
&error)) {
g_print ("Failed to write firmware: %s\n", error->message); g_print ("Failed to write firmware: %s\n", error->message);
return 1; return 1;
} }

View File

@ -98,11 +98,5 @@ fu_plugin_update (FuPlugin *plugin,
GError **error) GError **error)
{ {
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE); fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE);
if (!fu_altos_device_write_firmware (FU_ALTOS_DEVICE (dev), return fu_device_write_firmware (dev, blob_fw, error);
blob_fw,
FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_REBOOT,
error)) {
return FALSE;
}
return TRUE;
} }

View File

@ -271,15 +271,16 @@ fu_colorhug_device_verify_firmware (FuColorhugDevice *device, GError **error)
return TRUE; return TRUE;
} }
gboolean static gboolean
fu_colorhug_device_write_firmware (FuColorhugDevice *device, GBytes *fw, GError **error) fu_colorhug_device_write_firmware (FuDevice *device, GBytes *fw, GError **error)
{ {
FuColorhugDevicePrivate *priv = GET_PRIVATE (device); FuColorhugDevice *self = FU_COLORHUG_DEVICE (device);
FuColorhugDevicePrivate *priv = GET_PRIVATE (self);
GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device)); GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device));
g_autoptr(GError) error_local = NULL; g_autoptr(GError) error_local = NULL;
/* write firmware */ /* write firmware */
fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_WRITE); fu_device_set_status (device, FWUPD_STATUS_DEVICE_WRITE);
ch_device_queue_set_flash_success (priv->device_queue, ch_device_queue_set_flash_success (priv->device_queue,
usb_device, usb_device,
0x00); 0x00);
@ -298,7 +299,7 @@ fu_colorhug_device_write_firmware (FuColorhugDevice *device, GBytes *fw, GError
} }
/* verify firmware */ /* verify firmware */
fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_VERIFY); fu_device_set_status (device, FWUPD_STATUS_DEVICE_VERIFY);
ch_device_queue_verify_firmware (priv->device_queue, usb_device, ch_device_queue_verify_firmware (priv->device_queue, usb_device,
g_bytes_get_data (fw, NULL), g_bytes_get_data (fw, NULL),
g_bytes_get_size (fw)); g_bytes_get_size (fw));
@ -330,7 +331,9 @@ static void
fu_colorhug_device_class_init (FuColorhugDeviceClass *klass) fu_colorhug_device_class_init (FuColorhugDeviceClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
FuDeviceClass *klass_device = FU_DEVICE_CLASS (klass);
FuUsbDeviceClass *klass_usb_device = FU_USB_DEVICE_CLASS (klass); FuUsbDeviceClass *klass_usb_device = FU_USB_DEVICE_CLASS (klass);
klass_device->write_firmware = fu_colorhug_device_write_firmware;
object_class->finalize = fu_colorhug_device_finalize; object_class->finalize = fu_colorhug_device_finalize;
klass_usb_device->open = fu_colorhug_device_open; klass_usb_device->open = fu_colorhug_device_open;
klass_usb_device->probe = fu_colorhug_device_probe; klass_usb_device->probe = fu_colorhug_device_probe;

View File

@ -47,9 +47,6 @@ gboolean fu_colorhug_device_attach (FuColorhugDevice *device,
GError **error); GError **error);
gboolean fu_colorhug_device_set_flash_success (FuColorhugDevice *device, gboolean fu_colorhug_device_set_flash_success (FuColorhugDevice *device,
GError **error); GError **error);
gboolean fu_colorhug_device_write_firmware (FuColorhugDevice *device,
GBytes *fw,
GError **error);
gboolean fu_colorhug_device_verify_firmware (FuColorhugDevice *device, gboolean fu_colorhug_device_verify_firmware (FuColorhugDevice *device,
GError **error); GError **error);

View File

@ -163,7 +163,7 @@ fu_plugin_update (FuPlugin *plugin,
locker = fu_device_locker_new (device, error); locker = fu_device_locker_new (device, error);
if (locker == NULL) if (locker == NULL)
return FALSE; return FALSE;
return fu_colorhug_device_write_firmware (colorhug_dev, blob_fw, error); return fu_device_write_firmware (FU_DEVICE (colorhug_dev), blob_fw, error);
} }
gboolean gboolean

View File

@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
* *
* Copyright (C) 2017 Richard Hughes <richard@hughsie.com> * Copyright (C) 2017-2018 Richard Hughes <richard@hughsie.com>
* *
* Licensed under the GNU Lesser General Public License Version 2.1 * Licensed under the GNU Lesser General Public License Version 2.1
* *
@ -449,9 +449,10 @@ _dfu_firmware_get_default_element_data (DfuFirmware *firmware)
return dfu_element_get_contents (element); return dfu_element_get_contents (element);
} }
gboolean static gboolean
fu_csr_device_download (FuCsrDevice *self, GBytes *blob, GError **error) fu_csr_device_download (FuDevice *device, GBytes *blob, GError **error)
{ {
FuCsrDevice *self = FU_CSR_DEVICE (device);
GBytes *blob_noftr; GBytes *blob_noftr;
const guint8 *data; const guint8 *data;
gsize sz = 0; gsize sz = 0;
@ -461,7 +462,7 @@ fu_csr_device_download (FuCsrDevice *self, GBytes *blob, GError **error)
g_autoptr(GPtrArray) packets = NULL; g_autoptr(GPtrArray) packets = NULL;
/* notify UI */ /* notify UI */
fu_device_set_status (FU_DEVICE (self), FWUPD_STATUS_DEVICE_WRITE); fu_device_set_status (device, FWUPD_STATUS_DEVICE_WRITE);
/* parse the file */ /* parse the file */
if (!dfu_firmware_parse_data (dfu_firmware, blob, if (!dfu_firmware_parse_data (dfu_firmware, blob,
@ -505,7 +506,7 @@ fu_csr_device_download (FuCsrDevice *self, GBytes *blob, GError **error)
return FALSE; return FALSE;
/* update progress */ /* update progress */
fu_device_set_progress_full (FU_DEVICE (self), fu_device_set_progress_full (device,
(gsize) idx, (gsize) packets->len); (gsize) idx, (gsize) packets->len);
} }
@ -515,7 +516,7 @@ fu_csr_device_download (FuCsrDevice *self, GBytes *blob, GError **error)
return FALSE; return FALSE;
/* notify UI */ /* notify UI */
fu_device_set_status (FU_DEVICE (self), FWUPD_STATUS_IDLE); fu_device_set_status (device, FWUPD_STATUS_IDLE);
return TRUE; return TRUE;
} }
@ -594,6 +595,7 @@ fu_csr_device_class_init (FuCsrDeviceClass *klass)
FuDeviceClass *klass_device = FU_DEVICE_CLASS (klass); FuDeviceClass *klass_device = FU_DEVICE_CLASS (klass);
FuUsbDeviceClass *klass_usb_device = FU_USB_DEVICE_CLASS (klass); FuUsbDeviceClass *klass_usb_device = FU_USB_DEVICE_CLASS (klass);
klass_device->to_string = fu_csr_device_to_string; klass_device->to_string = fu_csr_device_to_string;
klass_device->write_firmware = fu_csr_device_download;
klass_usb_device->open = fu_csr_device_open; klass_usb_device->open = fu_csr_device_open;
klass_usb_device->close = fu_csr_device_close; klass_usb_device->close = fu_csr_device_close;
klass_usb_device->probe = fu_csr_device_probe; klass_usb_device->probe = fu_csr_device_probe;

View File

@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
* *
* Copyright (C) 2017 Richard Hughes <richard@hughsie.com> * Copyright (C) 2017-2018 Richard Hughes <richard@hughsie.com>
* *
* Licensed under the GNU Lesser General Public License Version 2.1 * Licensed under the GNU Lesser General Public License Version 2.1
* *
@ -41,9 +41,6 @@ typedef enum {
FuCsrDevice *fu_csr_device_new (GUsbDevice *usb_device); FuCsrDevice *fu_csr_device_new (GUsbDevice *usb_device);
gboolean fu_csr_device_attach (FuCsrDevice *self, gboolean fu_csr_device_attach (FuCsrDevice *self,
GError **error); GError **error);
gboolean fu_csr_device_download (FuCsrDevice *self,
GBytes *blob,
GError **error);
GBytes *fu_csr_device_upload (FuCsrDevice *self, GBytes *fu_csr_device_upload (FuCsrDevice *self,
GError **error); GError **error);
void fu_csr_device_set_quirks (FuCsrDevice *self, void fu_csr_device_set_quirks (FuCsrDevice *self,

View File

@ -296,7 +296,7 @@ fu_csr_tool_write (FuCsrToolPrivate *priv, gchar **values, GError **error)
G_CALLBACK (fu_csr_tool_progress_cb), priv); G_CALLBACK (fu_csr_tool_progress_cb), priv);
g_signal_connect (device, "notify::progress", g_signal_connect (device, "notify::progress",
G_CALLBACK (fu_csr_tool_progress_cb), priv); G_CALLBACK (fu_csr_tool_progress_cb), priv);
return fu_csr_device_download (device, blob, error); return fu_device_write_firmware (FU_DEVICE (device), blob, error);
} }
static gboolean static gboolean

View File

@ -74,7 +74,7 @@ fu_plugin_update (FuPlugin *plugin, FuDevice *device, GBytes *blob_fw,
locker = fu_device_locker_new (device, error); locker = fu_device_locker_new (device, error);
if (locker == NULL) if (locker == NULL)
return FALSE; return FALSE;
if (!fu_csr_device_download (FU_CSR_DEVICE (device), blob_fw, error)) if (!fu_device_write_firmware (device, blob_fw, error))
return FALSE; return FALSE;
return fu_csr_device_attach (FU_CSR_DEVICE (device), error); return fu_csr_device_attach (FU_CSR_DEVICE (device), error);
} }

View File

@ -367,10 +367,11 @@ fu_ebitdo_device_get_serial (FuEbitdoDevice *device)
return priv->serial; return priv->serial;
} }
gboolean static gboolean
fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **error) fu_ebitdo_device_write_firmware (FuDevice *device, GBytes *fw, GError **error)
{ {
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device); FuEbitdoDevice *self = FU_EBITDO_DEVICE (device);
FuEbitdoDevicePrivate *priv = GET_PRIVATE (self);
FuEbitdoFirmwareHeader *hdr; FuEbitdoFirmwareHeader *hdr;
const guint8 *payload_data; const guint8 *payload_data;
const guint chunk_sz = 32; const guint chunk_sz = 32;
@ -422,8 +423,8 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er
} }
/* set up the firmware header */ /* set up the firmware header */
fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_WRITE); fu_device_set_status (device, FWUPD_STATUS_DEVICE_WRITE);
if (!fu_ebitdo_device_send (device, if (!fu_ebitdo_device_send (self,
FU_EBITDO_PKT_TYPE_USER_CMD, FU_EBITDO_PKT_TYPE_USER_CMD,
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA, FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
FU_EBITDO_PKT_CMD_FW_UPDATE_HEADER, FU_EBITDO_PKT_CMD_FW_UPDATE_HEADER,
@ -436,7 +437,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er
error_local->message); error_local->message);
return FALSE; return FALSE;
} }
if (!fu_ebitdo_device_receive (device, NULL, 0, &error_local)) { if (!fu_ebitdo_device_receive (self, NULL, 0, &error_local)) {
g_set_error (error, g_set_error (error,
G_IO_ERROR, G_IO_ERROR,
G_IO_ERROR_INVALID_DATA, G_IO_ERROR_INVALID_DATA,
@ -453,8 +454,8 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er
g_debug ("writing %u bytes to 0x%04x of 0x%04x", g_debug ("writing %u bytes to 0x%04x of 0x%04x",
chunk_sz, offset, payload_len); chunk_sz, offset, payload_len);
} }
fu_device_set_progress_full (FU_DEVICE (device), offset, payload_len); fu_device_set_progress_full (device, offset, payload_len);
if (!fu_ebitdo_device_send (device, if (!fu_ebitdo_device_send (self,
FU_EBITDO_PKT_TYPE_USER_CMD, FU_EBITDO_PKT_TYPE_USER_CMD,
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA, FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
FU_EBITDO_PKT_CMD_FW_UPDATE_DATA, FU_EBITDO_PKT_CMD_FW_UPDATE_DATA,
@ -467,7 +468,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er
offset, error_local->message); offset, error_local->message);
return FALSE; return FALSE;
} }
if (!fu_ebitdo_device_receive (device, NULL, 0, &error_local)) { if (!fu_ebitdo_device_receive (self, NULL, 0, &error_local)) {
g_set_error (error, g_set_error (error,
G_IO_ERROR, G_IO_ERROR,
G_IO_ERROR_INVALID_DATA, G_IO_ERROR_INVALID_DATA,
@ -478,7 +479,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er
} }
/* mark as complete */ /* mark as complete */
fu_device_set_progress_full (FU_DEVICE (device), payload_len, payload_len); fu_device_set_progress_full (device, payload_len, payload_len);
/* set the "encode id" which is likely a checksum, bluetooth pairing /* set the "encode id" which is likely a checksum, bluetooth pairing
* or maybe just security-through-obscurity -- also note: * or maybe just security-through-obscurity -- also note:
@ -486,7 +487,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er
serial_new[0] = priv->serial[0] ^ app_key_index[priv->serial[0] & 0x0f]; serial_new[0] = priv->serial[0] ^ app_key_index[priv->serial[0] & 0x0f];
serial_new[1] = priv->serial[1] ^ app_key_index[priv->serial[1] & 0x0f]; serial_new[1] = priv->serial[1] ^ app_key_index[priv->serial[1] & 0x0f];
serial_new[2] = priv->serial[2] ^ app_key_index[priv->serial[2] & 0x0f]; serial_new[2] = priv->serial[2] ^ app_key_index[priv->serial[2] & 0x0f];
if (!fu_ebitdo_device_send (device, if (!fu_ebitdo_device_send (self,
FU_EBITDO_PKT_TYPE_USER_CMD, FU_EBITDO_PKT_TYPE_USER_CMD,
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA, FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
FU_EBITDO_PKT_CMD_FW_SET_ENCODE_ID, FU_EBITDO_PKT_CMD_FW_SET_ENCODE_ID,
@ -502,7 +503,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er
} }
/* mark flash as successful */ /* mark flash as successful */
if (!fu_ebitdo_device_send (device, if (!fu_ebitdo_device_send (self,
FU_EBITDO_PKT_TYPE_USER_CMD, FU_EBITDO_PKT_TYPE_USER_CMD,
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA, FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
FU_EBITDO_PKT_CMD_FW_UPDATE_OK, FU_EBITDO_PKT_CMD_FW_UPDATE_OK,
@ -515,7 +516,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er
error_local->message); error_local->message);
return FALSE; return FALSE;
} }
if (!fu_ebitdo_device_receive (device, NULL, 0, &error_local)) { if (!fu_ebitdo_device_receive (self, NULL, 0, &error_local)) {
g_set_error (error, g_set_error (error,
G_IO_ERROR, G_IO_ERROR,
G_IO_ERROR_INVALID_DATA, G_IO_ERROR_INVALID_DATA,
@ -525,7 +526,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **er
} }
/* success! */ /* success! */
fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_IDLE); fu_device_set_status (device, FWUPD_STATUS_IDLE);
return TRUE; return TRUE;
} }
@ -582,7 +583,9 @@ fu_ebitdo_device_init (FuEbitdoDevice *device)
static void static void
fu_ebitdo_device_class_init (FuEbitdoDeviceClass *klass) fu_ebitdo_device_class_init (FuEbitdoDeviceClass *klass)
{ {
FuDeviceClass *klass_device = FU_DEVICE_CLASS (klass);
FuUsbDeviceClass *klass_usb_device = FU_USB_DEVICE_CLASS (klass); FuUsbDeviceClass *klass_usb_device = FU_USB_DEVICE_CLASS (klass);
klass_device->write_firmware = fu_ebitdo_device_write_firmware;
klass_usb_device->open = fu_ebitdo_device_open; klass_usb_device->open = fu_ebitdo_device_open;
klass_usb_device->probe = fu_ebitdo_device_probe; klass_usb_device->probe = fu_ebitdo_device_probe;
} }

View File

@ -43,11 +43,6 @@ FuEbitdoDevice *fu_ebitdo_device_new (GUsbDevice *usb_device);
gboolean fu_ebitdo_device_is_bootloader (FuEbitdoDevice *device); gboolean fu_ebitdo_device_is_bootloader (FuEbitdoDevice *device);
const guint32 *fu_ebitdo_device_get_serial (FuEbitdoDevice *device); const guint32 *fu_ebitdo_device_get_serial (FuEbitdoDevice *device);
/* object methods */
gboolean fu_ebitdo_device_write_firmware (FuEbitdoDevice *device,
GBytes *fw,
GError **error);
G_END_DECLS G_END_DECLS
#endif /* __FU_EBITDO_DEVICE_H */ #endif /* __FU_EBITDO_DEVICE_H */

View File

@ -142,7 +142,7 @@ main (int argc, char **argv)
fw = g_bytes_new (data, len); fw = g_bytes_new (data, len);
g_signal_connect (dev, "notify::progress", g_signal_connect (dev, "notify::progress",
G_CALLBACK (fu_ebitdo_tool_progress_cb), NULL); G_CALLBACK (fu_ebitdo_tool_progress_cb), NULL);
if (!fu_ebitdo_device_write_firmware (dev, fw, &error)) { if (!fu_device_write_firmware (FU_DEVICE (dev), fw, &error)) {
g_print ("Failed to write firmware: %s\n", error->message); g_print ("Failed to write firmware: %s\n", error->message);
return 1; return 1;
} }

View File

@ -69,7 +69,7 @@ fu_plugin_update (FuPlugin *plugin,
locker = fu_device_locker_new (ebitdo_dev, error); locker = fu_device_locker_new (ebitdo_dev, error);
if (locker == NULL) if (locker == NULL)
return FALSE; return FALSE;
if (!fu_ebitdo_device_write_firmware (ebitdo_dev, blob_fw, error)) if (!fu_device_write_firmware (FU_DEVICE (ebitdo_dev), blob_fw, error))
return FALSE; return FALSE;
/* when doing a soft-reboot the device does not re-enumerate properly /* when doing a soft-reboot the device does not re-enumerate properly

View File

@ -186,7 +186,7 @@ fu_plugin_update (FuPlugin *plugin,
/* write the firmware */ /* write the firmware */
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE); fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE);
if (!lu_device_write_firmware (device, blob_fw, error)) if (!fu_device_write_firmware (dev, blob_fw, error))
return FALSE; return FALSE;
/* success */ /* success */

View File

@ -903,10 +903,11 @@ lu_device_attach (LuDevice *device, GError **error)
return TRUE; return TRUE;
} }
gboolean static gboolean
lu_device_write_firmware (LuDevice *device, GBytes *fw, GError **error) lu_device_write_firmware (FuDevice *device, GBytes *fw, GError **error)
{ {
LuDeviceClass *klass = LU_DEVICE_GET_CLASS (device); LuDevice *self = LU_DEVICE (device);
LuDeviceClass *klass = LU_DEVICE_GET_CLASS (self);
g_return_val_if_fail (LU_IS_DEVICE (device), FALSE); g_return_val_if_fail (LU_IS_DEVICE (device), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@ -926,12 +927,12 @@ lu_device_write_firmware (LuDevice *device, GBytes *fw, GError **error)
G_IO_ERROR, G_IO_ERROR,
G_IO_ERROR_FAILED, G_IO_ERROR_FAILED,
"not supported in %s", "not supported in %s",
lu_device_kind_to_string (lu_device_get_kind (device))); lu_device_kind_to_string (lu_device_get_kind (self)));
return FALSE; return FALSE;
} }
/* call either nordic or texas vfunc */ /* call either nordic or texas vfunc */
return klass->write_firmware (device, fw, error); return klass->write_firmware (self, fw, error);
} }
#ifndef HAVE_GUDEV_232 #ifndef HAVE_GUDEV_232
@ -1076,6 +1077,7 @@ lu_device_class_init (LuDeviceClass *klass)
object_class->get_property = lu_device_get_property; object_class->get_property = lu_device_get_property;
object_class->set_property = lu_device_set_property; object_class->set_property = lu_device_set_property;
klass_device->to_string = lu_device_to_string; klass_device->to_string = lu_device_to_string;
klass_device->write_firmware = lu_device_write_firmware;
pspec = g_param_spec_uint ("kind", NULL, NULL, pspec = g_param_spec_uint ("kind", NULL, NULL,
LU_DEVICE_KIND_UNKNOWN, LU_DEVICE_KIND_UNKNOWN,

View File

@ -130,9 +130,6 @@ gboolean lu_device_probe (LuDevice *device,
GError **error); GError **error);
gboolean lu_device_poll (LuDevice *device, gboolean lu_device_poll (LuDevice *device,
GError **error); GError **error);
gboolean lu_device_write_firmware (LuDevice *device,
GBytes *fw,
GError **error);
gboolean lu_device_hidpp_send (LuDevice *device, gboolean lu_device_hidpp_send (LuDevice *device,
LuHidppMsg *msg, LuHidppMsg *msg,
guint timeout, guint timeout,

View File

@ -351,7 +351,7 @@ lu_tool_write (FuLuToolPrivate *priv, gchar **values, GError **error)
fw = g_bytes_new (data, len); fw = g_bytes_new (data, len);
g_signal_connect (device, "notify::progress", g_signal_connect (device, "notify::progress",
G_CALLBACK (lu_write_progress_cb), NULL); G_CALLBACK (lu_write_progress_cb), NULL);
if (!lu_device_write_firmware (device, fw, error)) if (!fu_device_write_firmware (FU_DEVICE (device), fw, error))
return FALSE; return FALSE;
/* detach back into runtime */ /* detach back into runtime */

View File

@ -961,6 +961,39 @@ fu_device_get_release_default (FuDevice *device)
return rel; return rel;
} }
/**
* fu_device_write_firmware:
* @device: A #FuDevice
* @fw: A #GBytes
* @error: A #GError
*
* Writes firmware to the device by calling a plugin-specific vfunc.
*
* Returns: %TRUE on success
*
* Since: 1.0.8
**/
gboolean
fu_device_write_firmware (FuDevice *device, GBytes *fw, GError **error)
{
FuDeviceClass *klass = FU_DEVICE_GET_CLASS (device);
g_return_val_if_fail (FU_IS_DEVICE (device), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
/* no plugin-specific method */
if (klass->write_firmware == NULL) {
g_set_error_literal (error,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
"not supported");
return FALSE;
}
/* call vfunc */
return klass->write_firmware (device, fw, error);
}
static void static void
fu_device_class_init (FuDeviceClass *klass) fu_device_class_init (FuDeviceClass *klass)
{ {

View File

@ -37,8 +37,11 @@ struct _FuDeviceClass
FwupdDeviceClass parent_class; FwupdDeviceClass parent_class;
void (*to_string) (FuDevice *device, void (*to_string) (FuDevice *device,
GString *str); GString *str);
gboolean (*write_firmware) (FuDevice *device,
GBytes *fw,
GError **error);
/*< private >*/ /*< private >*/
gpointer padding[30]; gpointer padding[29];
}; };
/** /**
@ -161,6 +164,9 @@ void fu_device_set_quirks (FuDevice *device,
FuQuirks *quirks); FuQuirks *quirks);
FuQuirks *fu_device_get_quirks (FuDevice *device); FuQuirks *fu_device_get_quirks (FuDevice *device);
FwupdRelease *fu_device_get_release_default (FuDevice *device); FwupdRelease *fu_device_get_release_default (FuDevice *device);
gboolean fu_device_write_firmware (FuDevice *device,
GBytes *fw,
GError **error);
G_END_DECLS G_END_DECLS