dfu: Fix uploading large firmware files

Fixes split into more than 0xff chunks were being truncated as uint8_t was the
wrong index type.
This commit is contained in:
Richard Hughes 2017-10-11 11:16:56 +01:00
parent 8e054956b2
commit a1c7716cdc
2 changed files with 11 additions and 15 deletions

View File

@ -33,11 +33,11 @@ DfuTarget *dfu_target_new (DfuDevice *device,
GUsbInterface *iface); GUsbInterface *iface);
GBytes *dfu_target_upload_chunk (DfuTarget *target, GBytes *dfu_target_upload_chunk (DfuTarget *target,
guint8 index, guint16 index,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
gboolean dfu_target_download_chunk (DfuTarget *target, gboolean dfu_target_download_chunk (DfuTarget *target,
guint8 index, guint16 index,
GBytes *bytes, GBytes *bytes,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);

View File

@ -638,7 +638,7 @@ dfu_target_setup (DfuTarget *target, GError **error)
} }
gboolean gboolean
dfu_target_download_chunk (DfuTarget *target, guint8 index, GBytes *bytes, dfu_target_download_chunk (DfuTarget *target, guint16 index, GBytes *bytes,
GCancellable *cancellable, GError **error) GCancellable *cancellable, GError **error)
{ {
DfuTargetPrivate *priv = GET_PRIVATE (target); DfuTargetPrivate *priv = GET_PRIVATE (target);
@ -864,7 +864,7 @@ dfu_target_read_unprotect (DfuTarget *target,
#endif #endif
GBytes * GBytes *
dfu_target_upload_chunk (DfuTarget *target, guint8 index, dfu_target_upload_chunk (DfuTarget *target, guint16 index,
GCancellable *cancellable, GError **error) GCancellable *cancellable, GError **error)
{ {
DfuTargetPrivate *priv = GET_PRIVATE (target); DfuTargetPrivate *priv = GET_PRIVATE (target);
@ -1033,13 +1033,13 @@ dfu_target_upload_element_dfuse (DfuTarget *target,
/* get all the chunks from the hardware */ /* get all the chunks from the hardware */
chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref); chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref);
for (guint idx = 0; idx < G_MAXUINT16; idx++) { for (guint16 idx = 0; idx < G_MAXUINT16; idx++) {
guint32 chunk_size; guint32 chunk_size;
/* read chunk of data -- ST uses wBlockNum=0 for DfuSe commands /* read chunk of data -- ST uses wBlockNum=0 for DfuSe commands
* and wBlockNum=1 is reserved */ * and wBlockNum=1 is reserved */
chunk_tmp = dfu_target_upload_chunk (target, chunk_tmp = dfu_target_upload_chunk (target,
(guint8) (idx + 2), idx + 2,
cancellable, cancellable,
error); error);
if (chunk_tmp == NULL) if (chunk_tmp == NULL)
@ -1124,12 +1124,12 @@ dfu_target_upload_element_dfu (DfuTarget *target,
/* get all the chunks from the hardware */ /* get all the chunks from the hardware */
chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref); chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref);
for (guint idx = 0; idx < G_MAXUINT16; idx++) { for (guint16 idx = 0; idx < G_MAXUINT16; idx++) {
guint32 chunk_size; guint32 chunk_size;
/* read chunk of data */ /* read chunk of data */
chunk_tmp = dfu_target_upload_chunk (target, chunk_tmp = dfu_target_upload_chunk (target,
(guint8) idx, idx,
cancellable, cancellable,
error); error);
if (chunk_tmp == NULL) if (chunk_tmp == NULL)
@ -1364,7 +1364,7 @@ dfu_target_download_element_dfu (DfuTarget *target,
{ {
DfuTargetPrivate *priv = GET_PRIVATE (target); DfuTargetPrivate *priv = GET_PRIVATE (target);
GBytes *bytes; GBytes *bytes;
guint nr_chunks; guint16 nr_chunks;
guint16 transfer_size = dfu_device_get_transfer_size (priv->device); guint16 transfer_size = dfu_device_get_transfer_size (priv->device);
/* round up as we have to transfer incomplete blocks */ /* round up as we have to transfer incomplete blocks */
@ -1379,7 +1379,7 @@ dfu_target_download_element_dfu (DfuTarget *target,
return FALSE; return FALSE;
} }
dfu_target_set_action (target, FWUPD_STATUS_DEVICE_WRITE); dfu_target_set_action (target, FWUPD_STATUS_DEVICE_WRITE);
for (guint i = 0; i < nr_chunks + 1; i++) { for (guint16 i = 0; i < nr_chunks + 1; i++) {
gsize length; gsize length;
guint32 offset; guint32 offset;
g_autoptr(GBytes) bytes_tmp = NULL; g_autoptr(GBytes) bytes_tmp = NULL;
@ -1398,11 +1398,7 @@ dfu_target_download_element_dfu (DfuTarget *target,
} }
g_debug ("writing #%04x chunk of size %" G_GSIZE_FORMAT, g_debug ("writing #%04x chunk of size %" G_GSIZE_FORMAT,
i, g_bytes_get_size (bytes_tmp)); i, g_bytes_get_size (bytes_tmp));
if (!dfu_target_download_chunk (target, if (!dfu_target_download_chunk (target, i, bytes_tmp, cancellable, error))
(guint8) i,
bytes_tmp,
cancellable,
error))
return FALSE; return FALSE;
/* update UI */ /* update UI */