analogix: Be more accurate when reporting percentage progress

This commit is contained in:
Richard Hughes 2022-10-27 10:10:56 +01:00
parent 912a578411
commit 22928ac52a

View File

@ -242,6 +242,40 @@ fu_analogix_device_probe(FuDevice *device, GError **error)
return TRUE;
}
static gboolean
fu_analogix_device_write_chunks(FuAnalogixDevice *self,
GPtrArray *chunks,
guint16 req_val,
FuProgress *progress,
GError **error)
{
/* progress */
fu_progress_set_id(progress, G_STRLOC);
fu_progress_set_steps(progress, chunks->len);
for (guint i = 0; i < chunks->len; i++) {
AnxUpdateStatus status = UPDATE_STATUS_INVALID;
FuChunk *chk = g_ptr_array_index(chunks, i);
if (!fu_analogix_device_send(self,
ANX_BB_RQT_SEND_UPDATE_DATA,
req_val,
i + 1,
fu_chunk_get_data(chk),
fu_chunk_get_data_sz(chk),
error)) {
g_prefix_error(error, "failed send on chk %u: ", i);
return FALSE;
}
if (!fu_analogix_device_get_update_status(self, &status, error)) {
g_prefix_error(error, "failed status on chk %u: ", i);
return FALSE;
}
fu_progress_step_done(progress);
}
/* success */
return TRUE;
}
static gboolean
fu_analogix_device_write_image(FuAnalogixDevice *self,
FuFirmware *image,
@ -256,9 +290,8 @@ fu_analogix_device_write_image(FuAnalogixDevice *self,
/* progress */
fu_progress_set_id(progress, G_STRLOC);
fu_progress_add_flag(progress, FU_PROGRESS_FLAG_GUESSED);
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_BUSY, 10, "initialization");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 90, NULL);
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_BUSY, 2, "initialization");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 98, NULL);
/* offset into firmware */
block_bytes = fu_firmware_get_bytes(image, error);
@ -283,26 +316,12 @@ fu_analogix_device_write_image(FuAnalogixDevice *self,
/* write data */
chunks = fu_chunk_array_new_from_bytes(block_bytes, 0x00, 0x00, BILLBOARD_MAX_PACKET_SIZE);
for (guint i = 0; i < chunks->len; i++) {
FuChunk *chk = g_ptr_array_index(chunks, i);
if (!fu_analogix_device_send(self,
ANX_BB_RQT_SEND_UPDATE_DATA,
if (!fu_analogix_device_write_chunks(self,
chunks,
req_val,
i + 1,
fu_chunk_get_data(chk),
fu_chunk_get_data_sz(chk),
error)) {
g_prefix_error(error, "failed send on chk %u: ", i);
fu_progress_get_child(progress),
error))
return FALSE;
}
if (!fu_analogix_device_get_update_status(self, &status, error)) {
g_prefix_error(error, "failed status on chk %u: ", i);
return FALSE;
}
fu_progress_set_percentage_full(fu_progress_get_child(progress),
i + 1,
chunks->len);
}
fu_progress_step_done(progress);
/* success */
@ -317,21 +336,54 @@ fu_analogix_device_write_firmware(FuDevice *device,
GError **error)
{
FuAnalogixDevice *self = FU_ANALOGIX_DEVICE(device);
gsize totalsz = 0;
g_autoptr(FuFirmware) fw_cus = NULL;
g_autoptr(FuFirmware) fw_ocm = NULL;
g_autoptr(FuFirmware) fw_srx = NULL;
g_autoptr(FuFirmware) fw_stx = NULL;
/* these are all optional */
fw_cus = fu_firmware_get_image_by_id(firmware, "custom", NULL);
fw_stx = fu_firmware_get_image_by_id(firmware, "stx", NULL);
fw_srx = fu_firmware_get_image_by_id(firmware, "srx", NULL);
fw_ocm = fu_firmware_get_image_by_id(firmware, "ocm", NULL);
/* progress */
fu_progress_set_id(progress, G_STRLOC);
fu_progress_add_flag(progress, FU_PROGRESS_FLAG_GUESSED);
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 25, "cus");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 25, "stx");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 25, "srx");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 25, "ocm");
if (fw_cus != NULL)
totalsz += fu_firmware_get_size(fw_cus);
if (fw_stx != NULL)
totalsz += fu_firmware_get_size(fw_stx);
if (fw_srx != NULL)
totalsz += fu_firmware_get_size(fw_srx);
if (fw_ocm != NULL)
totalsz += fu_firmware_get_size(fw_ocm);
if (fw_cus != NULL) {
fu_progress_add_step(progress,
FWUPD_STATUS_DEVICE_WRITE,
(100 * fu_firmware_get_size(fw_cus) / totalsz),
"cus");
}
if (fw_stx != NULL) {
fu_progress_add_step(progress,
FWUPD_STATUS_DEVICE_WRITE,
(100 * fu_firmware_get_size(fw_stx) / totalsz),
"stx");
}
if (fw_srx != NULL) {
fu_progress_add_step(progress,
FWUPD_STATUS_DEVICE_WRITE,
(100 * fu_firmware_get_size(fw_srx) / totalsz),
"srx");
}
if (fw_ocm != NULL) {
fu_progress_add_step(progress,
FWUPD_STATUS_DEVICE_WRITE,
(100 * fu_firmware_get_size(fw_ocm) / totalsz),
"ocm");
}
/* CUSTOM_DEF */
fw_cus = fu_firmware_get_image_by_id(firmware, "custom", NULL);
if (fw_cus != NULL) {
if (!fu_analogix_device_write_image(self,
fw_cus,
@ -341,11 +393,10 @@ fu_analogix_device_write_firmware(FuDevice *device,
g_prefix_error(error, "program custom define failed: ");
return FALSE;
}
}
fu_progress_step_done(progress);
}
/* SECURE_TX */
fw_stx = fu_firmware_get_image_by_id(firmware, "stx", NULL);
if (fw_stx != NULL) {
if (!fu_analogix_device_write_image(self,
fw_stx,
@ -355,11 +406,10 @@ fu_analogix_device_write_firmware(FuDevice *device,
g_prefix_error(error, "program secure TX failed: ");
return FALSE;
}
}
fu_progress_step_done(progress);
}
/* SECURE_RX */
fw_srx = fu_firmware_get_image_by_id(firmware, "srx", NULL);
if (fw_srx != NULL) {
if (!fu_analogix_device_write_image(self,
fw_srx,
@ -369,11 +419,10 @@ fu_analogix_device_write_firmware(FuDevice *device,
g_prefix_error(error, "program secure RX failed: ");
return FALSE;
}
}
fu_progress_step_done(progress);
}
/* OCM */
fw_ocm = fu_firmware_get_image_by_id(firmware, "ocm", NULL);
if (fw_ocm != NULL) {
if (!fu_analogix_device_write_image(self,
fw_ocm,
@ -383,8 +432,8 @@ fu_analogix_device_write_firmware(FuDevice *device,
g_prefix_error(error, "program OCM failed: ");
return FALSE;
}
}
fu_progress_step_done(progress);
}
/* success */
return TRUE;
@ -394,11 +443,10 @@ static void
fu_analogix_device_set_progress(FuDevice *self, FuProgress *progress)
{
fu_progress_set_id(progress, G_STRLOC);
fu_progress_add_flag(progress, FU_PROGRESS_FLAG_GUESSED);
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_RESTART, 0, "detach");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 98, "write");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_WRITE, 99, "write");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_RESTART, 0, "attach");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_BUSY, 2, "reload");
fu_progress_add_step(progress, FWUPD_STATUS_DEVICE_BUSY, 1, "reload");
}
static void