diff --git a/libdfu/dfu-firmware.c b/libdfu/dfu-firmware.c index 593221510..133c73881 100644 --- a/libdfu/dfu-firmware.c +++ b/libdfu/dfu-firmware.c @@ -54,6 +54,7 @@ typedef struct { guint16 vid; guint16 pid; guint16 release; + guint32 crc; DfuFirmwareFormat format; } DfuFirmwarePrivate; @@ -820,9 +821,10 @@ dfu_firmware_parse_data (DfuFirmware *firmware, GBytes *bytes, } /* verify the checksum */ + priv->crc = GUINT32_FROM_LE (ftr->crc); if ((flags & DFU_FIRMWARE_PARSE_FLAG_NO_CRC_TEST) == 0) { crc_new = dfu_firmware_generate_crc32 (data, len - 4); - if (GUINT32_FROM_LE (ftr->crc) != crc_new) { + if (priv->crc != crc_new) { g_set_error (error, DFU_ERROR, DFU_ERROR_INTERNAL, @@ -1072,6 +1074,7 @@ dfu_firmware_to_string (DfuFirmware *firmware) g_string_append_printf (str, "vid: 0x%04x\n", priv->vid); g_string_append_printf (str, "pid: 0x%04x\n", priv->pid); g_string_append_printf (str, "release: 0x%04x\n", priv->release); + g_string_append_printf (str, "crc: 0x%08x\n", priv->crc); g_string_append_printf (str, "format: %s [0x%04x]\n", dfu_firmware_format_to_string (priv->format), priv->format); diff --git a/libdfu/dfu-tool.c b/libdfu/dfu-tool.c index e9a563331..503eb9704 100644 --- a/libdfu/dfu-tool.c +++ b/libdfu/dfu-tool.c @@ -1197,8 +1197,8 @@ dfu_tool_watch (DfuToolPrivate *priv, gchar **values, GError **error) static gboolean dfu_tool_dump (DfuToolPrivate *priv, gchar **values, GError **error) { - g_autoptr(DfuFirmware) firmware = NULL; - g_autoptr(GFile) file = NULL; + DfuFirmwareParseFlags flags = DFU_FIRMWARE_PARSE_FLAG_NONE; + guint i; /* check args */ if (g_strv_length (values) < 1) { @@ -1209,16 +1209,31 @@ dfu_tool_dump (DfuToolPrivate *priv, gchar **values, GError **error) return FALSE; } - /* open file */ - firmware = dfu_firmware_new (); - file = g_file_new_for_path (values[0]); - if (!dfu_firmware_parse_file (firmware, file, - DFU_FIRMWARE_PARSE_FLAG_NONE, - priv->cancellable, error)) - return FALSE; + /* dump corrupt files */ + if (priv->force) { + flags |= DFU_FIRMWARE_PARSE_FLAG_NO_CRC_TEST; + flags |= DFU_FIRMWARE_PARSE_FLAG_NO_VERSION_TEST; + } - /* dump to screen */ - g_print ("%s\n", dfu_firmware_to_string (firmware)); + /* open files */ + for (i = 0; values[i] != NULL; i++) { + g_autoptr(DfuFirmware) firmware = NULL; + g_autoptr(GFile) file = NULL; + g_autoptr(GError) error_local = NULL; + + /* dump to screen */ + g_print ("Loading %s:\n", values[i]); + firmware = dfu_firmware_new (); + file = g_file_new_for_path (values[i]); + if (!dfu_firmware_parse_file (firmware, file, flags, + priv->cancellable, + &error_local)) { + g_print ("Failed to load firmware: %s\n", + error_local->message); + continue; + } + g_print ("%s\n", dfu_firmware_to_string (firmware)); + } return TRUE; }