From 4713f23f7f0dbb9fe060413194ab36d746b24477 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 23 Nov 2017 17:28:23 +0000 Subject: [PATCH] dfu: Fix attaching AVR32 devices like the XMEGA Also, add a self test that uses the XMEGA A3BU XPLAINED board, see https://github.com/hughsie/fwupd-test-firmware/tree/master/AVR/XMEGA-A3BU-XPLAINED-1.23 for more details about how to build the bootloader and firmware. --- data/installed-tests/hardware.py | 6 ++++++ plugins/dfu/dfu-target-avr.c | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/data/installed-tests/hardware.py b/data/installed-tests/hardware.py index a0736cb4b..57fb35d32 100755 --- a/data/installed-tests/hardware.py +++ b/data/installed-tests/hardware.py @@ -85,6 +85,12 @@ if __name__ == '__main__': tests = [] + # DFU A3BU XPLAINED Mouse + test = Test('DfuXmegaA3BU-Xplained', '80478b9a-3643-5e47-ab0f-ed28abe1019d') + test.add_file('90c381f1c5932a7f9505372305a615ca000e68df-a3bu-xplained123.cab', '1.23') + test.add_file('24d838541efe0340bf67e1cc5a9b95526e4d3702-a3bu-xplained124.cab', '1.24') + tests.append(test) + # DFU AT90USBKEY Mouse test = Test('DfuAT90USBKEY', 'c1874c52-5f6a-5864-926d-ea84bcdc82ea') test.add_file('b6bef375597e848971f230cf992c9740f7bf5b92-at90usbkey123.cab', '1.23') diff --git a/plugins/dfu/dfu-target-avr.c b/plugins/dfu/dfu-target-avr.c index db8177435..90ee5e77e 100644 --- a/plugins/dfu/dfu-target-avr.c +++ b/plugins/dfu/dfu-target-avr.c @@ -110,23 +110,37 @@ dfu_target_avr_mass_erase (DfuTarget *target, static gboolean dfu_target_avr_attach (DfuTarget *target, GCancellable *cancellable, GError **error) { - g_autoptr(GBytes) data_in = NULL; guint8 buf[3]; + g_autoptr(GBytes) data_empty = NULL; + g_autoptr(GBytes) data_in = NULL; g_autoptr(GError) error_local = NULL; /* format buffer */ buf[0] = DFU_AVR32_GROUP_EXEC; buf[1] = DFU_AVR32_CMD_START_APPLI; - buf[2] = 0x00; + buf[2] = DFU_AVR32_START_APPLI_RESET; data_in = g_bytes_new_static (buf, sizeof(buf)); if (!dfu_target_download_chunk (target, 0, data_in, cancellable, &error_local)) { if (g_error_matches (error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) { g_debug ("ignoring as device rebooting: %s", error_local->message); return TRUE; } - g_prefix_error (error, "cannot attach: "); + g_prefix_error (error, "cannot start application reset attach: "); return FALSE; } + + /* do zero-sized download to initiate the reset */ + data_empty = g_bytes_new (NULL, 0); + if (!dfu_target_download_chunk (target, 0, data_empty, cancellable, &error_local)) { + if (g_error_matches (error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) { + g_debug ("ignoring as device rebooting: %s", error_local->message); + return TRUE; + } + g_prefix_error (error, "cannot initiate reset for attach: "); + return FALSE; + } + + /* success */ return TRUE; }