From 58bed5200e11bbda43e32ec6bd3e7dcd8f20061a Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 10 Oct 2019 16:32:57 +0100 Subject: [PATCH] dfu: Remove functionality you can do now with fwupdtool --- plugins/dfu/dfu-tool.c | 259 ----------------------------------------- 1 file changed, 259 deletions(-) diff --git a/plugins/dfu/dfu-tool.c b/plugins/dfu/dfu-tool.c index 203bac1d7..367ac5cd7 100644 --- a/plugins/dfu/dfu-tool.c +++ b/plugins/dfu/dfu-tool.c @@ -868,40 +868,6 @@ dfu_tool_convert (DfuToolPrivate *priv, gchar **values, GError **error) return dfu_firmware_write_file (firmware, file_out, error); } -static gboolean -dfu_tool_attach (DfuToolPrivate *priv, gchar **values, GError **error) -{ - g_autoptr(DfuDevice) device = NULL; - g_autoptr(FuDeviceLocker) locker = NULL; - - device = dfu_tool_get_default_device (priv, error); - if (device == NULL) - return FALSE; - locker = fu_device_locker_new (device, error); - if (locker == NULL) - return FALSE; - if (!dfu_device_refresh_and_clear (device, error)) - return FALSE; - return fu_device_attach (FU_DEVICE (device), error); -} - -static gboolean -dfu_tool_reset (DfuToolPrivate *priv, gchar **values, GError **error) -{ - g_autoptr(DfuDevice) device = NULL; - g_autoptr(FuDeviceLocker) locker = NULL; - - device = dfu_tool_get_default_device (priv, error); - if (device == NULL) - return FALSE; - locker = fu_device_locker_new (device, error); - if (locker == NULL) - return FALSE; - if (!dfu_device_refresh (device, error)) - return FALSE; - return dfu_device_reset (device, error); -} - static void fu_tool_action_changed_cb (FuDevice *device, GParamSpec *pspec, DfuToolPrivate *priv) { @@ -1469,207 +1435,6 @@ dfu_tool_write (DfuToolPrivate *priv, gchar **values, GError **error) return TRUE; } -static void -dfu_tool_list_target (DfuTarget *target) -{ - GPtrArray *sectors; - const gchar *tmp; - g_autofree gchar *alt_id = NULL; - g_autoptr(GError) error_local = NULL; - - /* TRANSLATORS: the identifier name please */ - alt_id = g_strdup_printf ("%i", dfu_target_get_alt_setting (target)); - dfu_tool_print_indent (_("ID"), alt_id, 1); - - /* this is optional */ - tmp = dfu_target_get_alt_name_for_display (target, &error_local); - if (tmp != NULL) { - /* TRANSLATORS: interface name, e.g. "Flash" */ - dfu_tool_print_indent (_("Name"), tmp, 2); - } else if (!g_error_matches (error_local, - FWUPD_ERROR, - FWUPD_ERROR_NOT_FOUND)) { - g_autofree gchar *str = NULL; - str = g_strdup_printf ("Error: %s", error_local->message); - dfu_tool_print_indent (_("Name"), str, 2); - } - - /* print sector information */ - sectors = dfu_target_get_sectors (target); - for (guint i = 0; i < sectors->len; i++) { - DfuSector *sector; - g_autofree gchar *msg = NULL; - g_autofree gchar *title = NULL; - sector = g_ptr_array_index (sectors, i); - msg = dfu_sector_to_string (sector); - /* TRANSLATORS: these are areas of memory on the chip */ - title = g_strdup_printf ("%s 0x%02x", _("Region"), i); - dfu_tool_print_indent (title, msg, 2); - } -} - -static gboolean -dfu_tool_list (DfuToolPrivate *priv, gchar **values, GError **error) -{ - g_autoptr(GUsbContext) usb_context = NULL; - g_autoptr(GPtrArray) devices = NULL; - - /* get all the connected USB devices */ - usb_context = g_usb_context_new (error); - if (usb_context == NULL) - return FALSE; - g_usb_context_enumerate (usb_context); - devices = g_usb_context_get_devices (usb_context); - for (guint i = 0; i < devices->len; i++) { - DfuTarget *target; - GUsbDevice *usb_device; - GPtrArray *dfu_targets; - const gchar *tmp; - gboolean is_runtime; - guint16 transfer_size; - g_autofree gchar *attrs = NULL; - const gchar *quirks = NULL; - g_autofree gchar *version = NULL; - g_autoptr(DfuDevice) device = NULL; - g_autoptr(FuDeviceLocker) locker = NULL; - g_autoptr(GError) error_local = NULL; - - /* device specific */ - usb_device = g_ptr_array_index (devices, i); - device = dfu_device_new (usb_device); - fu_device_set_quirks (FU_DEVICE (device), priv->quirks); - dfu_device_set_usb_context (device, usb_context); - if (!fu_device_probe (FU_DEVICE (device), NULL)) - continue; - version = fu_common_version_from_uint16 (g_usb_device_get_release (usb_device), - FWUPD_VERSION_FORMAT_BCD); - g_print ("%s %04x:%04x [v%s]:\n", - /* TRANSLATORS: detected a DFU device */ - _("Found"), - g_usb_device_get_vid (usb_device), - g_usb_device_get_pid (usb_device), - version); - - tmp = dfu_version_to_string (dfu_device_get_version (device)); - if (tmp != NULL) { - /* TRANSLATORS: DFU protocol version, e.g. 1.1 */ - dfu_tool_print_indent (_("Protocol"), tmp, 1); - } - - /* open */ - locker = fu_device_locker_new (device, &error_local); - if (locker == NULL) { - if (g_error_matches (error_local, - FWUPD_ERROR, - FWUPD_ERROR_PERMISSION_DENIED)) { - /* TRANSLATORS: probably not run as root... */ - dfu_tool_print_indent (_("Status"), _("Permission denied"), 1); - continue; - } - if (g_error_matches (error_local, - FWUPD_ERROR, - FWUPD_ERROR_NOT_SUPPORTED)) { - g_debug ("ignoring warning, continuing..."); - } else { - /* TRANSLATORS: device has failed to report status */ - dfu_tool_print_indent (_("Status"), error_local->message, 1); - } - continue; - } - if (!dfu_device_refresh_and_clear (device, &error_local)) { - /* TRANSLATORS: device has failed to report status */ - dfu_tool_print_indent (_("Status"), error_local->message, 1); - continue; - } - - tmp = fu_device_get_name (FU_DEVICE (device)); - if (tmp != NULL) { - /* TRANSLATORS: device name, e.g. 'ColorHug2' */ - dfu_tool_print_indent (_("Name"), tmp, 1); - } - - tmp = fu_device_get_serial (FU_DEVICE (device)); - if (tmp != NULL) { - /* TRANSLATORS: serial number, e.g. '00012345' */ - dfu_tool_print_indent (_("Serial"), tmp, 1); - } - - /* TRANSLATORS: device mode, e.g. application runtime or DFU */ - is_runtime = !fu_device_has_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_IS_BOOTLOADER); - dfu_tool_print_indent (_("Mode"), is_runtime ? _("Runtime") : _("DFU"), 1); - - tmp = dfu_status_to_string (dfu_device_get_status (device)); - /* TRANSLATORS: device status, e.g. "OK" */ - dfu_tool_print_indent (_("Status"), tmp, 1); - - tmp = dfu_state_to_string (dfu_device_get_state (device)); - /* TRANSLATORS: device state, i.e. appIDLE */ - dfu_tool_print_indent (_("State"), tmp, 1); - - transfer_size = dfu_device_get_transfer_size (device); - if (transfer_size > 0) { - g_autofree gchar *str = NULL; - str = g_format_size_full (transfer_size, - G_FORMAT_SIZE_LONG_FORMAT); - /* TRANSLATORS: transfer size in bytes */ - dfu_tool_print_indent (_("Transfer Size"), str, 1); - } - - /* attributes can be an empty string */ - attrs = dfu_device_get_attributes_as_string (device); - if (attrs != NULL && attrs[0] != '\0') { - /* TRANSLATORS: device attributes, i.e. things that - * the device can do */ - dfu_tool_print_indent (_("Attributes"), attrs, 1); - } - - /* quirks are NULL if none are set */ - quirks = fu_device_get_custom_flags (FU_DEVICE (device)); - if (quirks != NULL) { - /* TRANSLATORS: device quirks, i.e. things that - * it does that we have to work around */ - dfu_tool_print_indent (_("Quirks"), quirks, 1); - } - - /* this is optional */ - tmp = dfu_device_get_chip_id (device); - if (tmp != NULL) { - /* TRANSLATORS: chip ID, e.g. "0x58200204" */ - dfu_tool_print_indent (_("Chip ID"), tmp, 1); - } - - /* list targets */ - dfu_targets = dfu_device_get_targets (device); - for (guint j = 0; j < dfu_targets->len; j++) { - target = g_ptr_array_index (dfu_targets, j); - dfu_tool_list_target (target); - } - } - return TRUE; -} - -static gboolean -dfu_tool_detach (DfuToolPrivate *priv, gchar **values, GError **error) -{ - g_autoptr(DfuDevice) device = NULL; - g_autoptr(FuDeviceLocker) locker = NULL; - - /* open correct device */ - device = dfu_tool_get_default_device (priv, error); - if (device == NULL) - return FALSE; - if (priv->transfer_size > 0) - dfu_device_set_transfer_size (device, priv->transfer_size); - - /* detach */ - locker = fu_device_locker_new (device, error); - if (locker == NULL) - return FALSE; - if (!dfu_device_refresh_and_clear (device, error)) - return FALSE; - return fu_device_detach (FU_DEVICE (device), error); -} - static gboolean dfu_tool_sigint_cb (gpointer user_data) { @@ -1759,18 +1524,6 @@ main (int argc, char *argv[]) /* TRANSLATORS: command description */ _("Set alternative name on firmware file"), dfu_tool_set_alt_setting_name); - dfu_tool_add (priv->cmd_array, - "attach", - NULL, - /* TRANSLATORS: command description */ - _("Attach DFU capable device back to runtime"), - dfu_tool_attach); - dfu_tool_add (priv->cmd_array, - "reset", - NULL, - /* TRANSLATORS: command description */ - _("Reset a DFU device"), - dfu_tool_reset); dfu_tool_add (priv->cmd_array, "read", "FILENAME", @@ -1795,18 +1548,6 @@ main (int argc, char *argv[]) /* TRANSLATORS: command description */ _("Write firmware from file into one partition"), dfu_tool_write_alt); - dfu_tool_add (priv->cmd_array, - "list", - NULL, - /* TRANSLATORS: command description */ - _("List currently attached DFU capable devices"), - dfu_tool_list); - dfu_tool_add (priv->cmd_array, - "detach", - NULL, - /* TRANSLATORS: command description */ - _("Detach currently attached DFU capable device"), - dfu_tool_detach); dfu_tool_add (priv->cmd_array, "dump", "FILENAME",