mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-15 01:08:19 +00:00
altos: Use FuDeviceLocker
This commit is contained in:
parent
5b4d7dce0a
commit
e3e7a7b7d1
@ -445,6 +445,7 @@ fu_device_altos_write_firmware (FuDeviceAltos *device,
|
||||
const gsize data_len;
|
||||
guint flash_len;
|
||||
g_autoptr(FuAltosFirmware) altos_firmware = NULL;
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
g_autoptr(GString) buf = g_string_new (NULL);
|
||||
|
||||
/* check kind */
|
||||
@ -505,7 +506,11 @@ fu_device_altos_write_firmware (FuDeviceAltos *device,
|
||||
}
|
||||
|
||||
/* open tty for download */
|
||||
if (!fu_device_altos_tty_open (device, error))
|
||||
locker = fu_device_locker_new_full (device,
|
||||
(FuDeviceLockerFunc) fu_device_altos_tty_open,
|
||||
(FuDeviceLockerFunc) fu_device_altos_tty_close,
|
||||
error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
for (guint i = 0; i < flash_len; i+= 0x100) {
|
||||
g_autoptr(GString) str = NULL;
|
||||
@ -574,10 +579,6 @@ fu_device_altos_write_firmware (FuDeviceAltos *device,
|
||||
progress_data);
|
||||
}
|
||||
|
||||
/* done */
|
||||
if (!fu_device_altos_tty_close (device, error))
|
||||
return FALSE;
|
||||
|
||||
/* success */
|
||||
return TRUE;
|
||||
}
|
||||
@ -590,6 +591,7 @@ fu_device_altos_read_firmware (FuDeviceAltos *device,
|
||||
{
|
||||
FuDeviceAltosPrivate *priv = GET_PRIVATE (device);
|
||||
guint flash_len;
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
g_autoptr(GString) buf = g_string_new (NULL);
|
||||
|
||||
/* check kind */
|
||||
@ -621,7 +623,11 @@ fu_device_altos_read_firmware (FuDeviceAltos *device,
|
||||
}
|
||||
|
||||
/* open tty for download */
|
||||
if (!fu_device_altos_tty_open (device, error))
|
||||
locker = fu_device_locker_new_full (device,
|
||||
(FuDeviceLockerFunc) fu_device_altos_tty_open,
|
||||
(FuDeviceLockerFunc) fu_device_altos_tty_close,
|
||||
error);
|
||||
if (locker == NULL)
|
||||
return NULL;
|
||||
for (guint i = priv->addr_base; i < priv->addr_bound; i+= 0x100) {
|
||||
g_autoptr(GString) str = NULL;
|
||||
@ -640,10 +646,6 @@ fu_device_altos_read_firmware (FuDeviceAltos *device,
|
||||
g_string_append_len (buf, str->str, str->len);
|
||||
}
|
||||
|
||||
/* done */
|
||||
if (!fu_device_altos_tty_close (device, error))
|
||||
return NULL;
|
||||
|
||||
/* success */
|
||||
return g_bytes_new (buf->str, buf->len);
|
||||
}
|
||||
@ -652,23 +654,26 @@ static gboolean
|
||||
fu_device_altos_probe_bootloader (FuDeviceAltos *device, GError **error)
|
||||
{
|
||||
FuDeviceAltosPrivate *priv = GET_PRIVATE (device);
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
g_auto(GStrv) lines = NULL;
|
||||
g_autoptr(GString) str = NULL;
|
||||
|
||||
/* get tty for upload */
|
||||
if (!fu_device_altos_find_tty (device, error))
|
||||
return FALSE;
|
||||
if (!fu_device_altos_tty_open (device, error))
|
||||
locker = fu_device_locker_new_full (device,
|
||||
(FuDeviceLockerFunc) fu_device_altos_tty_open,
|
||||
(FuDeviceLockerFunc) fu_device_altos_tty_close,
|
||||
error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* get the version information */
|
||||
if (!fu_device_altos_tty_write (device, "v\n", -1, error))
|
||||
return FALSE;
|
||||
str = fu_device_altos_tty_read (device, 100, -1, error);
|
||||
if (str == NULL) {
|
||||
fu_device_altos_tty_close (device, NULL);
|
||||
if (str == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* parse each line */
|
||||
lines = g_strsplit_set (str->str, "\n\r", -1);
|
||||
@ -710,10 +715,6 @@ fu_device_altos_probe_bootloader (FuDeviceAltos *device, GError **error)
|
||||
g_debug ("unknown data: '%s'", lines[i]);
|
||||
}
|
||||
|
||||
/* done */
|
||||
if (!fu_device_altos_tty_close (device, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -731,9 +732,11 @@ fu_device_altos_probe (FuDeviceAltos *device, GError **error)
|
||||
const gchar *version_prefix = "ChaosKey-hw-1.0-sw-";
|
||||
guint8 version_idx;
|
||||
g_autofree gchar *version = NULL;
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
|
||||
/* open */
|
||||
if (!g_usb_device_open (priv->usb_device, error))
|
||||
locker = fu_device_locker_new (priv->usb_device, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* get string */
|
||||
@ -741,22 +744,17 @@ fu_device_altos_probe (FuDeviceAltos *device, GError **error)
|
||||
version = g_usb_device_get_string_descriptor (priv->usb_device,
|
||||
version_idx,
|
||||
error);
|
||||
if (version == NULL) {
|
||||
g_usb_device_close (priv->usb_device, NULL);
|
||||
if (version == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
if (!g_str_has_prefix (version, version_prefix)) {
|
||||
g_set_error (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_NOT_SUPPORTED,
|
||||
"not a ChaosKey v1.0 device: %s",
|
||||
version);
|
||||
g_usb_device_close (priv->usb_device, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
fu_device_set_version (FU_DEVICE (device), version + 19);
|
||||
if (!g_usb_device_close (priv->usb_device, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* success */
|
||||
|
Loading…
Reference in New Issue
Block a user