mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-09 06:12:15 +00:00
Add fu_common_sum8() common functionality
We now have 9 different plugins all using this functionality, and we're about to add one more. Move this into common code so that all the plugins are using the same endian and bufsz-safe versions.
This commit is contained in:
parent
5f88043c4f
commit
3ffc3fa774
@ -3425,6 +3425,206 @@ fu_common_crc32(const guint8 *buf, gsize bufsz)
|
|||||||
return fu_common_crc32_full(buf, bufsz, 0xFFFFFFFF, 0xEDB88320);
|
return fu_common_crc32_full(buf, bufsz, 0xFFFFFFFF, 0xEDB88320);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_sum8:
|
||||||
|
* @buf: memory buffer
|
||||||
|
* @bufsz: size of @buf
|
||||||
|
*
|
||||||
|
* Returns the arithmetic sum of all bytes in @buf.
|
||||||
|
*
|
||||||
|
* Returns: sum value
|
||||||
|
*
|
||||||
|
* Since: 1.7.3
|
||||||
|
**/
|
||||||
|
guint8
|
||||||
|
fu_common_sum8(const guint8 *buf, gsize bufsz)
|
||||||
|
{
|
||||||
|
guint8 checksum = 0;
|
||||||
|
g_return_val_if_fail(buf != NULL, G_MAXUINT8);
|
||||||
|
for (gsize i = 0; i < bufsz; i++)
|
||||||
|
checksum += buf[i];
|
||||||
|
return checksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_sum8_bytes:
|
||||||
|
* @blob: a #GBytes
|
||||||
|
*
|
||||||
|
* Returns the arithmetic sum of all bytes in @blob.
|
||||||
|
*
|
||||||
|
* Returns: sum value
|
||||||
|
*
|
||||||
|
* Since: 1.7.3
|
||||||
|
**/
|
||||||
|
guint8
|
||||||
|
fu_common_sum8_bytes(GBytes *blob)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(blob != NULL, G_MAXUINT8);
|
||||||
|
return fu_common_sum8(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_sum16:
|
||||||
|
* @buf: memory buffer
|
||||||
|
* @bufsz: size of @buf
|
||||||
|
*
|
||||||
|
* Returns the arithmetic sum of all bytes in @buf, adding them one byte at a time.
|
||||||
|
*
|
||||||
|
* Returns: sum value
|
||||||
|
*
|
||||||
|
* Since: 1.7.3
|
||||||
|
**/
|
||||||
|
guint16
|
||||||
|
fu_common_sum16(const guint8 *buf, gsize bufsz)
|
||||||
|
{
|
||||||
|
guint16 checksum = 0;
|
||||||
|
g_return_val_if_fail(buf != NULL, G_MAXUINT16);
|
||||||
|
for (gsize i = 0; i < bufsz; i++)
|
||||||
|
checksum += buf[i];
|
||||||
|
return checksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_sum16_bytes:
|
||||||
|
* @blob: a #GBytes
|
||||||
|
*
|
||||||
|
* Returns the arithmetic sum of all bytes in @blob, adding them one byte at a time.
|
||||||
|
*
|
||||||
|
* Returns: sum value
|
||||||
|
*
|
||||||
|
* Since: 1.7.3
|
||||||
|
**/
|
||||||
|
guint16
|
||||||
|
fu_common_sum16_bytes(GBytes *blob)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(blob != NULL, G_MAXUINT16);
|
||||||
|
return fu_common_sum16(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_sum16w:
|
||||||
|
* @buf: memory buffer
|
||||||
|
* @bufsz: size of @buf
|
||||||
|
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
|
||||||
|
*
|
||||||
|
* Returns the arithmetic sum of all bytes in @buf, adding them one word at a time.
|
||||||
|
* The caller must ensure that @bufsz is a multiple of 2.
|
||||||
|
*
|
||||||
|
* Returns: sum value
|
||||||
|
*
|
||||||
|
* Since: 1.7.3
|
||||||
|
**/
|
||||||
|
guint16
|
||||||
|
fu_common_sum16w(const guint8 *buf, gsize bufsz, FuEndianType endian)
|
||||||
|
{
|
||||||
|
guint16 checksum = 0;
|
||||||
|
g_return_val_if_fail(buf != NULL, G_MAXUINT16);
|
||||||
|
g_return_val_if_fail(bufsz % 2 == 0, G_MAXUINT16);
|
||||||
|
for (gsize i = 0; i < bufsz; i += 2)
|
||||||
|
checksum += fu_common_read_uint16(&buf[i], endian);
|
||||||
|
return checksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_sum16w_bytes:
|
||||||
|
* @blob: a #GBytes
|
||||||
|
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
|
||||||
|
*
|
||||||
|
* Returns the arithmetic sum of all bytes in @blob, adding them one word at a time.
|
||||||
|
* The caller must ensure that the size of @blob is a multiple of 2.
|
||||||
|
*
|
||||||
|
* Returns: sum value
|
||||||
|
*
|
||||||
|
* Since: 1.7.3
|
||||||
|
**/
|
||||||
|
guint16
|
||||||
|
fu_common_sum16w_bytes(GBytes *blob, FuEndianType endian)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(blob != NULL, G_MAXUINT16);
|
||||||
|
return fu_common_sum16w(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob), endian);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_sum32:
|
||||||
|
* @buf: memory buffer
|
||||||
|
* @bufsz: size of @buf
|
||||||
|
*
|
||||||
|
* Returns the arithmetic sum of all bytes in @buf, adding them one byte at a time.
|
||||||
|
*
|
||||||
|
* Returns: sum value
|
||||||
|
*
|
||||||
|
* Since: 1.7.3
|
||||||
|
**/
|
||||||
|
guint32
|
||||||
|
fu_common_sum32(const guint8 *buf, gsize bufsz)
|
||||||
|
{
|
||||||
|
guint32 checksum = 0;
|
||||||
|
g_return_val_if_fail(buf != NULL, G_MAXUINT32);
|
||||||
|
for (gsize i = 0; i < bufsz; i++)
|
||||||
|
checksum += buf[i];
|
||||||
|
return checksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_sum32_bytes:
|
||||||
|
* @blob: a #GBytes
|
||||||
|
*
|
||||||
|
* Returns the arithmetic sum of all bytes in @blob, adding them one byte at a time.
|
||||||
|
*
|
||||||
|
* Returns: sum value
|
||||||
|
*
|
||||||
|
* Since: 1.7.3
|
||||||
|
**/
|
||||||
|
guint32
|
||||||
|
fu_common_sum32_bytes(GBytes *blob)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(blob != NULL, G_MAXUINT32);
|
||||||
|
return fu_common_sum32(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_sum32w:
|
||||||
|
* @buf: memory buffer
|
||||||
|
* @bufsz: size of @buf
|
||||||
|
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
|
||||||
|
*
|
||||||
|
* Returns the arithmetic sum of all bytes in @buf, adding them one dword at a time.
|
||||||
|
* The caller must ensure that @bufsz is a multiple of 4.
|
||||||
|
*
|
||||||
|
* Returns: sum value
|
||||||
|
*
|
||||||
|
* Since: 1.7.3
|
||||||
|
**/
|
||||||
|
guint32
|
||||||
|
fu_common_sum32w(const guint8 *buf, gsize bufsz, FuEndianType endian)
|
||||||
|
{
|
||||||
|
guint32 checksum = 0;
|
||||||
|
g_return_val_if_fail(buf != NULL, G_MAXUINT32);
|
||||||
|
g_return_val_if_fail(bufsz % 4 == 0, G_MAXUINT32);
|
||||||
|
for (gsize i = 0; i < bufsz; i += 4)
|
||||||
|
checksum += fu_common_read_uint32(&buf[i], endian);
|
||||||
|
return checksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_sum32w_bytes:
|
||||||
|
* @blob: a #GBytes
|
||||||
|
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
|
||||||
|
*
|
||||||
|
* Returns the arithmetic sum of all bytes in @blob, adding them one dword at a time.
|
||||||
|
* The caller must ensure that the size of @blob is a multiple of 4.
|
||||||
|
*
|
||||||
|
* Returns: sum value
|
||||||
|
*
|
||||||
|
* Since: 1.7.3
|
||||||
|
**/
|
||||||
|
guint32
|
||||||
|
fu_common_sum32w_bytes(GBytes *blob, FuEndianType endian)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(blob != NULL, G_MAXUINT32);
|
||||||
|
return fu_common_sum32w(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob), endian);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fu_common_uri_get_scheme:
|
* fu_common_uri_get_scheme:
|
||||||
* @uri: valid URI, e.g. `https://foo.bar/baz`
|
* @uri: valid URI, e.g. `https://foo.bar/baz`
|
||||||
|
@ -420,6 +420,28 @@ guint32
|
|||||||
fu_common_crc32(const guint8 *buf, gsize bufsz);
|
fu_common_crc32(const guint8 *buf, gsize bufsz);
|
||||||
guint32
|
guint32
|
||||||
fu_common_crc32_full(const guint8 *buf, gsize bufsz, guint32 crc, guint32 polynomial);
|
fu_common_crc32_full(const guint8 *buf, gsize bufsz, guint32 crc, guint32 polynomial);
|
||||||
|
|
||||||
|
guint8
|
||||||
|
fu_common_sum8(const guint8 *buf, gsize bufsz);
|
||||||
|
guint8
|
||||||
|
fu_common_sum8_bytes(GBytes *blob);
|
||||||
|
guint16
|
||||||
|
fu_common_sum16(const guint8 *buf, gsize bufsz);
|
||||||
|
guint16
|
||||||
|
fu_common_sum16_bytes(GBytes *blob);
|
||||||
|
guint16
|
||||||
|
fu_common_sum16w(const guint8 *buf, gsize bufsz, FuEndianType endian);
|
||||||
|
guint16
|
||||||
|
fu_common_sum16w_bytes(GBytes *blob, FuEndianType endian);
|
||||||
|
guint32
|
||||||
|
fu_common_sum32(const guint8 *buf, gsize bufsz);
|
||||||
|
guint32
|
||||||
|
fu_common_sum32_bytes(GBytes *blob);
|
||||||
|
guint32
|
||||||
|
fu_common_sum32w(const guint8 *buf, gsize bufsz, FuEndianType endian);
|
||||||
|
guint32
|
||||||
|
fu_common_sum32w_bytes(GBytes *blob, FuEndianType endian);
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
fu_common_uri_get_scheme(const gchar *uri);
|
fu_common_uri_get_scheme(const gchar *uri);
|
||||||
gsize
|
gsize
|
||||||
|
@ -113,17 +113,6 @@ fu_efi_firmware_file_export(FuFirmware *firmware, FuFirmwareExportFlags flags, X
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint8
|
|
||||||
fu_efi_firmware_file_data_checksum8(GBytes *blob)
|
|
||||||
{
|
|
||||||
gsize bufsz = 0;
|
|
||||||
guint8 checksum = 0;
|
|
||||||
const guint8 *buf = g_bytes_get_data(blob, &bufsz);
|
|
||||||
for (gsize i = 0; i < bufsz; i++)
|
|
||||||
checksum += buf[i];
|
|
||||||
return 0x100 - checksum;
|
|
||||||
}
|
|
||||||
|
|
||||||
static guint8
|
static guint8
|
||||||
fu_efi_firmware_file_hdr_checksum8(GBytes *blob)
|
fu_efi_firmware_file_hdr_checksum8(GBytes *blob)
|
||||||
{
|
{
|
||||||
@ -265,7 +254,7 @@ fu_efi_firmware_file_parse(FuFirmware *firmware,
|
|||||||
/* verify data checksum */
|
/* verify data checksum */
|
||||||
if ((priv->attrib & FU_EFI_FIRMWARE_FILE_ATTRIB_CHECKSUM) > 0 &&
|
if ((priv->attrib & FU_EFI_FIRMWARE_FILE_ATTRIB_CHECKSUM) > 0 &&
|
||||||
(flags & FWUPD_INSTALL_FLAG_IGNORE_CHECKSUM) == 0) {
|
(flags & FWUPD_INSTALL_FLAG_IGNORE_CHECKSUM) == 0) {
|
||||||
guint8 data_checksum_verify = fu_efi_firmware_file_data_checksum8(blob);
|
guint8 data_checksum_verify = 0x100 - fu_common_sum8_bytes(blob);
|
||||||
if (data_checksum_verify != data_checksum) {
|
if (data_checksum_verify != data_checksum) {
|
||||||
g_set_error(error,
|
g_set_error(error,
|
||||||
FWUPD_ERROR,
|
FWUPD_ERROR,
|
||||||
@ -344,7 +333,7 @@ fu_efi_firmware_file_write(FuFirmware *firmware, GError **error)
|
|||||||
return NULL;
|
return NULL;
|
||||||
g_byte_array_append(buf, (guint8 *)&guid, sizeof(guid));
|
g_byte_array_append(buf, (guint8 *)&guid, sizeof(guid));
|
||||||
fu_byte_array_append_uint8(buf, 0x0); /* hdr_checksum */
|
fu_byte_array_append_uint8(buf, 0x0); /* hdr_checksum */
|
||||||
fu_byte_array_append_uint8(buf, fu_efi_firmware_file_data_checksum8(blob));
|
fu_byte_array_append_uint8(buf, 0x100 - fu_common_sum8_bytes(blob));
|
||||||
fu_byte_array_append_uint8(buf, priv->type); /* data_checksum */
|
fu_byte_array_append_uint8(buf, priv->type); /* data_checksum */
|
||||||
fu_byte_array_append_uint8(buf, priv->attrib); /* data_checksum */
|
fu_byte_array_append_uint8(buf, priv->attrib); /* data_checksum */
|
||||||
fu_byte_array_append_uint32(buf,
|
fu_byte_array_append_uint32(buf,
|
||||||
|
@ -960,5 +960,15 @@ LIBFWUPDPLUGIN_1.7.3 {
|
|||||||
global:
|
global:
|
||||||
fu_archive_firmware_get_type;
|
fu_archive_firmware_get_type;
|
||||||
fu_archive_firmware_new;
|
fu_archive_firmware_new;
|
||||||
|
fu_common_sum16;
|
||||||
|
fu_common_sum16_bytes;
|
||||||
|
fu_common_sum16w;
|
||||||
|
fu_common_sum16w_bytes;
|
||||||
|
fu_common_sum32;
|
||||||
|
fu_common_sum32_bytes;
|
||||||
|
fu_common_sum32w;
|
||||||
|
fu_common_sum32w_bytes;
|
||||||
|
fu_common_sum8;
|
||||||
|
fu_common_sum8_bytes;
|
||||||
local: *;
|
local: *;
|
||||||
} LIBFWUPDPLUGIN_1.7.2;
|
} LIBFWUPDPLUGIN_1.7.2;
|
||||||
|
@ -163,9 +163,7 @@ fu_acpi_phat_parse(FuFirmware *firmware,
|
|||||||
|
|
||||||
/* verify checksum */
|
/* verify checksum */
|
||||||
if ((flags & FWUPD_INSTALL_FLAG_IGNORE_CHECKSUM) == 0) {
|
if ((flags & FWUPD_INSTALL_FLAG_IGNORE_CHECKSUM) == 0) {
|
||||||
guint8 checksum = 0;
|
guint8 checksum = fu_common_sum8(buf, length);
|
||||||
for (gsize i = 0; i < length; i++)
|
|
||||||
checksum += buf[i];
|
|
||||||
if (checksum != 0x00) {
|
if (checksum != 0x00) {
|
||||||
g_set_error(error,
|
g_set_error(error,
|
||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
@ -220,7 +218,6 @@ fu_acpi_phat_write(FuFirmware *firmware, GError **error)
|
|||||||
{
|
{
|
||||||
FuAcpiPhat *self = FU_ACPI_PHAT(firmware);
|
FuAcpiPhat *self = FU_ACPI_PHAT(firmware);
|
||||||
const gchar *oem_table_id_str = fu_firmware_get_id(firmware);
|
const gchar *oem_table_id_str = fu_firmware_get_id(firmware);
|
||||||
guint8 checksum = 0;
|
|
||||||
guint8 creator_id[] = {'F', 'W', 'U', 'P'};
|
guint8 creator_id[] = {'F', 'W', 'U', 'P'};
|
||||||
guint8 creator_rev[] = {'0', '0', '0', '0'};
|
guint8 creator_rev[] = {'0', '0', '0', '0'};
|
||||||
guint8 oem_id[6] = {'\0'};
|
guint8 oem_id[6] = {'\0'};
|
||||||
@ -276,9 +273,7 @@ fu_acpi_phat_write(FuFirmware *firmware, GError **error)
|
|||||||
g_byte_array_append(buf, buf2->data, buf2->len);
|
g_byte_array_append(buf, buf2->data, buf2->len);
|
||||||
|
|
||||||
/* fixup checksum */
|
/* fixup checksum */
|
||||||
for (gsize i = 0; i < buf->len; i++)
|
buf->data[9] = 0xFF - fu_common_sum8(buf->data, buf->len);
|
||||||
checksum += buf->data[i];
|
|
||||||
buf->data[9] = 0xFF - checksum;
|
|
||||||
|
|
||||||
/* success */
|
/* success */
|
||||||
return g_byte_array_free_to_bytes(g_steal_pointer(&buf));
|
return g_byte_array_free_to_bytes(g_steal_pointer(&buf));
|
||||||
|
@ -162,17 +162,6 @@ fu_ccgx_firmware_add_record(FuCcgxFirmware *self,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint8
|
|
||||||
fu_ccgx_firmware_record_calc_checksum(FuCcgxFirmwareRecord *rcd)
|
|
||||||
{
|
|
||||||
guint8 csum = 0x0;
|
|
||||||
gsize bufsz = 0;
|
|
||||||
const guint8 *buf = g_bytes_get_data(rcd->data, &bufsz);
|
|
||||||
for (gsize j = 0; j < bufsz; j++)
|
|
||||||
csum += buf[j];
|
|
||||||
return csum;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
fu_ccgx_firmware_parse_md_block(FuCcgxFirmware *self, FwupdInstallFlags flags, GError **error)
|
fu_ccgx_firmware_parse_md_block(FuCcgxFirmware *self, FwupdInstallFlags flags, GError **error)
|
||||||
{
|
{
|
||||||
@ -238,7 +227,7 @@ fu_ccgx_firmware_parse_md_block(FuCcgxFirmware *self, FwupdInstallFlags flags, G
|
|||||||
}
|
}
|
||||||
for (guint i = 0; i < self->records->len - 1; i++) {
|
for (guint i = 0; i < self->records->len - 1; i++) {
|
||||||
rcd = g_ptr_array_index(self->records, i);
|
rcd = g_ptr_array_index(self->records, i);
|
||||||
checksum_calc += fu_ccgx_firmware_record_calc_checksum(rcd);
|
checksum_calc += fu_common_sum8_bytes(rcd->data);
|
||||||
fw_size += g_bytes_get_size(rcd->data);
|
fw_size += g_bytes_get_size(rcd->data);
|
||||||
}
|
}
|
||||||
if (fw_size != metadata.fw_size) {
|
if (fw_size != metadata.fw_size) {
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 Richard Hughes <richard@hughsie.com>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: LGPL-2.1+
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include "fu-elantp-common.h"
|
|
||||||
|
|
||||||
guint16
|
|
||||||
fu_elantp_calc_checksum(const guint8 *data, gsize length)
|
|
||||||
{
|
|
||||||
guint16 checksum = 0;
|
|
||||||
for (gsize i = 0; i < length; i += 2)
|
|
||||||
checksum += ((guint16)(data[i + 1]) << 8) | (data[i]);
|
|
||||||
return checksum;
|
|
||||||
}
|
|
@ -44,6 +44,3 @@
|
|||||||
#define ELANTP_DELAY_UNLOCK 100 /* ms */
|
#define ELANTP_DELAY_UNLOCK 100 /* ms */
|
||||||
#define ELANTP_DELAY_WRITE_BLOCK 35 /* ms */
|
#define ELANTP_DELAY_WRITE_BLOCK 35 /* ms */
|
||||||
#define ELANTP_DELAY_WRITE_BLOCK_512 50 /* ms */
|
#define ELANTP_DELAY_WRITE_BLOCK_512 50 /* ms */
|
||||||
|
|
||||||
guint16
|
|
||||||
fu_elantp_calc_checksum(const guint8 *data, gsize length);
|
|
||||||
|
@ -339,8 +339,9 @@ fu_elantp_hid_device_write_firmware(FuDevice *device,
|
|||||||
chunks = fu_chunk_array_new(buf + iap_addr, bufsz - iap_addr, 0x0, 0x0, self->fw_page_size);
|
chunks = fu_chunk_array_new(buf + iap_addr, bufsz - iap_addr, 0x0, 0x0, self->fw_page_size);
|
||||||
for (guint i = 0; i < chunks->len; i++) {
|
for (guint i = 0; i < chunks->len; i++) {
|
||||||
FuChunk *chk = g_ptr_array_index(chunks, i);
|
FuChunk *chk = g_ptr_array_index(chunks, i);
|
||||||
guint16 csum_tmp =
|
guint16 csum_tmp = fu_common_sum16w(fu_chunk_get_data(chk),
|
||||||
fu_elantp_calc_checksum(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
|
fu_chunk_get_data_sz(chk),
|
||||||
|
G_LITTLE_ENDIAN);
|
||||||
gsize blksz = self->fw_page_size + 3;
|
gsize blksz = self->fw_page_size + 3;
|
||||||
g_autofree guint8 *blk = g_malloc0(blksz);
|
g_autofree guint8 *blk = g_malloc0(blksz);
|
||||||
|
|
||||||
|
@ -411,8 +411,9 @@ fu_elantp_i2c_device_write_firmware(FuDevice *device,
|
|||||||
chunks = fu_chunk_array_new(buf + iap_addr, bufsz - iap_addr, 0x0, 0x0, self->fw_page_size);
|
chunks = fu_chunk_array_new(buf + iap_addr, bufsz - iap_addr, 0x0, 0x0, self->fw_page_size);
|
||||||
for (guint i = 0; i < chunks->len; i++) {
|
for (guint i = 0; i < chunks->len; i++) {
|
||||||
FuChunk *chk = g_ptr_array_index(chunks, i);
|
FuChunk *chk = g_ptr_array_index(chunks, i);
|
||||||
guint16 csum_tmp =
|
guint16 csum_tmp = fu_common_sum16w(fu_chunk_get_data(chk),
|
||||||
fu_elantp_calc_checksum(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
|
fu_chunk_get_data_sz(chk),
|
||||||
|
G_LITTLE_ENDIAN);
|
||||||
gsize blksz = self->fw_page_size + 4;
|
gsize blksz = self->fw_page_size + 4;
|
||||||
g_autofree guint8 *blk = g_malloc0(blksz);
|
g_autofree guint8 *blk = g_malloc0(blksz);
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ shared_module('fu_plugin_elantp',
|
|||||||
fu_hash,
|
fu_hash,
|
||||||
sources : [
|
sources : [
|
||||||
'fu-plugin-elantp.c',
|
'fu-plugin-elantp.c',
|
||||||
'fu-elantp-common.c',
|
|
||||||
'fu-elantp-firmware.c', # fuzzing
|
'fu-elantp-firmware.c', # fuzzing
|
||||||
'fu-elantp-hid-device.c',
|
'fu-elantp-hid-device.c',
|
||||||
'fu-elantp-i2c-device.c',
|
'fu-elantp-i2c-device.c',
|
||||||
|
@ -315,8 +315,7 @@ fu_pxi_ble_device_check_support_resume(FuPxiBleDevice *self,
|
|||||||
/* calculate device current checksum */
|
/* calculate device current checksum */
|
||||||
for (guint i = 0; i < self->fwstate.offset; i++) {
|
for (guint i = 0; i < self->fwstate.offset; i++) {
|
||||||
FuChunk *chk = g_ptr_array_index(chunks, i);
|
FuChunk *chk = g_ptr_array_index(chunks, i);
|
||||||
checksum_tmp +=
|
checksum_tmp += fu_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
|
||||||
fu_pxi_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check current file is different with previous fw bin or not */
|
/* check current file is different with previous fw bin or not */
|
||||||
@ -488,7 +487,7 @@ fu_pxi_ble_device_write_chunk(FuPxiBleDevice *self, FuChunk *chk, GError **error
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* the last chunk */
|
/* the last chunk */
|
||||||
checksum = fu_pxi_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
|
checksum = fu_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
|
||||||
self->fwstate.checksum += checksum;
|
self->fwstate.checksum += checksum;
|
||||||
if (checksum_device != self->fwstate.checksum) {
|
if (checksum_device != self->fwstate.checksum) {
|
||||||
g_set_error(error,
|
g_set_error(error,
|
||||||
@ -581,8 +580,6 @@ fu_pxi_ble_device_fw_upgrade(FuPxiBleDevice *self,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
const gchar *version;
|
const gchar *version;
|
||||||
const guint8 *buf;
|
|
||||||
gsize bufsz = 0;
|
|
||||||
guint8 fw_version[5] = {0x0};
|
guint8 fw_version[5] = {0x0};
|
||||||
guint8 opcode = 0;
|
guint8 opcode = 0;
|
||||||
guint16 checksum;
|
guint16 checksum;
|
||||||
@ -592,11 +589,10 @@ fu_pxi_ble_device_fw_upgrade(FuPxiBleDevice *self,
|
|||||||
fw = fu_firmware_get_bytes(firmware, error);
|
fw = fu_firmware_get_bytes(firmware, error);
|
||||||
if (fw == NULL)
|
if (fw == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
buf = g_bytes_get_data(fw, &bufsz);
|
checksum = fu_common_sum16_bytes(fw);
|
||||||
checksum = fu_pxi_common_sum16(buf, bufsz);
|
|
||||||
fu_byte_array_append_uint8(req, PXI_HID_DEV_OTA_FEATURE_REPORT_ID);
|
fu_byte_array_append_uint8(req, PXI_HID_DEV_OTA_FEATURE_REPORT_ID);
|
||||||
fu_byte_array_append_uint8(req, FU_PXI_DEVICE_CMD_FW_UPGRADE);
|
fu_byte_array_append_uint8(req, FU_PXI_DEVICE_CMD_FW_UPGRADE);
|
||||||
fu_byte_array_append_uint32(req, bufsz, G_LITTLE_ENDIAN);
|
fu_byte_array_append_uint32(req, g_bytes_get_size(fw), G_LITTLE_ENDIAN);
|
||||||
fu_byte_array_append_uint16(req, checksum, G_LITTLE_ENDIAN);
|
fu_byte_array_append_uint16(req, checksum, G_LITTLE_ENDIAN);
|
||||||
version = fu_firmware_get_version(firmware);
|
version = fu_firmware_get_version(firmware);
|
||||||
if (!fu_memcpy_safe(fw_version,
|
if (!fu_memcpy_safe(fw_version,
|
||||||
@ -623,7 +619,7 @@ fu_pxi_ble_device_fw_upgrade(FuPxiBleDevice *self,
|
|||||||
"FwUpgrade command fail, "
|
"FwUpgrade command fail, "
|
||||||
"fw-checksum: 0x%04x fw-size: %" G_GSIZE_FORMAT ": ",
|
"fw-checksum: 0x%04x fw-size: %" G_GSIZE_FORMAT ": ",
|
||||||
checksum,
|
checksum,
|
||||||
bufsz);
|
g_bytes_get_size(fw));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (opcode != FU_PXI_DEVICE_CMD_FW_UPGRADE) {
|
if (opcode != FU_PXI_DEVICE_CMD_FW_UPGRADE) {
|
||||||
|
@ -9,24 +9,6 @@
|
|||||||
|
|
||||||
#include "fu-pxi-common.h"
|
#include "fu-pxi-common.h"
|
||||||
|
|
||||||
guint8
|
|
||||||
fu_pxi_common_sum8(const guint8 *buf, gsize bufsz)
|
|
||||||
{
|
|
||||||
guint8 checksum = 0;
|
|
||||||
for (gsize idx = 0; idx < bufsz; idx++)
|
|
||||||
checksum += (guint8)buf[idx];
|
|
||||||
return checksum;
|
|
||||||
}
|
|
||||||
|
|
||||||
guint16
|
|
||||||
fu_pxi_common_sum16(const guint8 *buf, gsize bufsz)
|
|
||||||
{
|
|
||||||
guint16 checksum = 0;
|
|
||||||
for (gsize idx = 0; idx < bufsz; idx++)
|
|
||||||
checksum += (guint8)buf[idx];
|
|
||||||
return checksum;
|
|
||||||
}
|
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
fu_pxi_spec_check_result_to_string(guint8 spec_check_result)
|
fu_pxi_spec_check_result_to_string(guint8 spec_check_result)
|
||||||
{
|
{
|
||||||
@ -172,7 +154,7 @@ fu_pxi_composite_receiver_cmd(guint8 opcode,
|
|||||||
g_byte_array_prepend(wireless_mod_cmd, &rf_cmd_code, 0x01); /* command code */
|
g_byte_array_prepend(wireless_mod_cmd, &rf_cmd_code, 0x01); /* command code */
|
||||||
|
|
||||||
/* prepend checksum */
|
/* prepend checksum */
|
||||||
checksum = fu_pxi_common_sum8(wireless_mod_cmd->data, wireless_mod_cmd->len);
|
checksum = fu_common_sum8(wireless_mod_cmd->data, wireless_mod_cmd->len);
|
||||||
g_byte_array_prepend(wireless_mod_cmd, &checksum, 0x01);
|
g_byte_array_prepend(wireless_mod_cmd, &checksum, 0x01);
|
||||||
|
|
||||||
/* prepend feature report id */
|
/* prepend feature report id */
|
||||||
|
@ -103,10 +103,6 @@ struct ota_fw_state {
|
|||||||
guint8 spec_check_result;
|
guint8 spec_check_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
guint8
|
|
||||||
fu_pxi_common_sum8(const guint8 *buf, gsize bufsz);
|
|
||||||
guint16
|
|
||||||
fu_pxi_common_sum16(const guint8 *buf, gsize bufsz);
|
|
||||||
gboolean
|
gboolean
|
||||||
fu_pxi_composite_receiver_cmd(guint8 opcode,
|
fu_pxi_composite_receiver_cmd(guint8 opcode,
|
||||||
guint8 sn,
|
guint8 sn,
|
||||||
|
@ -385,7 +385,7 @@ fu_pxi_receiver_device_write_chunk(FuDevice *device, FuChunk *chk, GError **erro
|
|||||||
self->fwstate.mtu_size);
|
self->fwstate.mtu_size);
|
||||||
|
|
||||||
/* the checksum of chunk */
|
/* the checksum of chunk */
|
||||||
checksum = fu_pxi_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
|
checksum = fu_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
|
||||||
self->fwstate.checksum += checksum;
|
self->fwstate.checksum += checksum;
|
||||||
for (guint i = 0; i < chunks->len; i++) {
|
for (guint i = 0; i < chunks->len; i++) {
|
||||||
FuChunk *chk2 = g_ptr_array_index(chunks, i);
|
FuChunk *chk2 = g_ptr_array_index(chunks, i);
|
||||||
@ -414,9 +414,6 @@ fu_pxi_receiver_device_fw_upgrade(FuDevice *device,
|
|||||||
{
|
{
|
||||||
FuPxiReceiverDevice *self = FU_PXI_RECEIVER_DEVICE(device);
|
FuPxiReceiverDevice *self = FU_PXI_RECEIVER_DEVICE(device);
|
||||||
const gchar *version;
|
const gchar *version;
|
||||||
const guint8 *buf;
|
|
||||||
gsize bufsz = 0;
|
|
||||||
guint16 checksum = 0x0;
|
|
||||||
guint8 fw_version[5] = {0x0};
|
guint8 fw_version[5] = {0x0};
|
||||||
guint8 res[FU_PXI_RECEIVER_DEVICE_OTA_BUF_SZ] = {0x0};
|
guint8 res[FU_PXI_RECEIVER_DEVICE_OTA_BUF_SZ] = {0x0};
|
||||||
guint8 result = 0x0;
|
guint8 result = 0x0;
|
||||||
@ -434,19 +431,16 @@ fu_pxi_receiver_device_fw_upgrade(FuDevice *device,
|
|||||||
if (fw == NULL)
|
if (fw == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
buf = g_bytes_get_data(fw, &bufsz);
|
|
||||||
checksum = fu_pxi_common_sum16(buf, bufsz);
|
|
||||||
|
|
||||||
/* ota fw upgrade command */
|
/* ota fw upgrade command */
|
||||||
fu_byte_array_append_uint8(ota_cmd, 0x0c); /* ota fw upgrade command length */
|
fu_byte_array_append_uint8(ota_cmd, 0x0c); /* ota fw upgrade command length */
|
||||||
fu_byte_array_append_uint8(
|
fu_byte_array_append_uint8(
|
||||||
ota_cmd,
|
ota_cmd,
|
||||||
FU_PXI_DEVICE_CMD_FW_UPGRADE); /* ota fw upgrade command opccode */
|
FU_PXI_DEVICE_CMD_FW_UPGRADE); /* ota fw upgrade command opccode */
|
||||||
fu_byte_array_append_uint32(ota_cmd,
|
fu_byte_array_append_uint32(ota_cmd,
|
||||||
bufsz,
|
g_bytes_get_size(fw),
|
||||||
G_LITTLE_ENDIAN); /* ota fw upgrade command fw size */
|
G_LITTLE_ENDIAN); /* ota fw upgrade command fw size */
|
||||||
fu_byte_array_append_uint16(ota_cmd,
|
fu_byte_array_append_uint16(ota_cmd,
|
||||||
checksum,
|
fu_common_sum16_bytes(fw),
|
||||||
G_LITTLE_ENDIAN); /* ota fw upgrade command checksum */
|
G_LITTLE_ENDIAN); /* ota fw upgrade command checksum */
|
||||||
|
|
||||||
version = fu_firmware_get_version(firmware);
|
version = fu_firmware_get_version(firmware);
|
||||||
|
@ -334,7 +334,7 @@ fu_pxi_wireless_device_write_chunk(FuDevice *device, FuChunk *chk, GError **erro
|
|||||||
self->fwstate.mtu_size);
|
self->fwstate.mtu_size);
|
||||||
|
|
||||||
/* calculate checksum of chunk */
|
/* calculate checksum of chunk */
|
||||||
checksum = fu_pxi_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
|
checksum = fu_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
|
||||||
self->fwstate.checksum += checksum;
|
self->fwstate.checksum += checksum;
|
||||||
|
|
||||||
for (guint i = 0; i < chunks->len; i++) {
|
for (guint i = 0; i < chunks->len; i++) {
|
||||||
@ -461,9 +461,6 @@ fu_pxi_wireless_device_fw_upgrade(FuDevice *device,
|
|||||||
FuPxiReceiverDevice *parent;
|
FuPxiReceiverDevice *parent;
|
||||||
FuPxiWirelessDevice *self = FU_PXI_WIRELESS_DEVICE(device);
|
FuPxiWirelessDevice *self = FU_PXI_WIRELESS_DEVICE(device);
|
||||||
const gchar *version;
|
const gchar *version;
|
||||||
const guint8 *buf;
|
|
||||||
gsize bufsz = 0;
|
|
||||||
guint16 checksum = 0x0;
|
|
||||||
guint8 fw_version[5] = {0x0};
|
guint8 fw_version[5] = {0x0};
|
||||||
g_autoptr(GByteArray) ota_cmd = g_byte_array_new();
|
g_autoptr(GByteArray) ota_cmd = g_byte_array_new();
|
||||||
g_autoptr(GByteArray) receiver_cmd = g_byte_array_new();
|
g_autoptr(GByteArray) receiver_cmd = g_byte_array_new();
|
||||||
@ -484,19 +481,16 @@ fu_pxi_wireless_device_fw_upgrade(FuDevice *device,
|
|||||||
if (fw == NULL)
|
if (fw == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
buf = g_bytes_get_data(fw, &bufsz);
|
|
||||||
checksum = fu_pxi_common_sum16(buf, bufsz);
|
|
||||||
|
|
||||||
/* ota fw upgrade command */
|
/* ota fw upgrade command */
|
||||||
fu_byte_array_append_uint8(ota_cmd, 0x0c); /* ota fw upgrade command length */
|
fu_byte_array_append_uint8(ota_cmd, 0x0c); /* ota fw upgrade command length */
|
||||||
fu_byte_array_append_uint8(
|
fu_byte_array_append_uint8(
|
||||||
ota_cmd,
|
ota_cmd,
|
||||||
FU_PXI_DEVICE_CMD_FW_UPGRADE); /* ota fw upgrade command opccode */
|
FU_PXI_DEVICE_CMD_FW_UPGRADE); /* ota fw upgrade command opccode */
|
||||||
fu_byte_array_append_uint32(ota_cmd,
|
fu_byte_array_append_uint32(ota_cmd,
|
||||||
bufsz,
|
g_bytes_get_size(fw),
|
||||||
G_LITTLE_ENDIAN); /* ota fw upgrade command fw size */
|
G_LITTLE_ENDIAN); /* ota fw upgrade command fw size */
|
||||||
fu_byte_array_append_uint16(ota_cmd,
|
fu_byte_array_append_uint16(ota_cmd,
|
||||||
checksum,
|
fu_common_sum16_bytes(fw),
|
||||||
G_LITTLE_ENDIAN); /* ota fw upgrade command checksum */
|
G_LITTLE_ENDIAN); /* ota fw upgrade command checksum */
|
||||||
|
|
||||||
version = fu_firmware_get_version(firmware);
|
version = fu_firmware_get_version(firmware);
|
||||||
|
@ -302,7 +302,7 @@ fu_steelseries_gamepad_write_firmware_chunks(FuDevice *device,
|
|||||||
|
|
||||||
for (guint id = 0; id < chunks->len; id++) {
|
for (guint id = 0; id < chunks->len; id++) {
|
||||||
FuChunk *chunk = g_ptr_array_index(chunks, id);
|
FuChunk *chunk = g_ptr_array_index(chunks, id);
|
||||||
guint16 chunk_checksum = 0;
|
guint16 chunk_checksum;
|
||||||
guint8 data[STEELSERIES_BUFFER_CONTROL_SIZE] = {0xA3};
|
guint8 data[STEELSERIES_BUFFER_CONTROL_SIZE] = {0xA3};
|
||||||
|
|
||||||
/* block ID */
|
/* block ID */
|
||||||
@ -324,11 +324,9 @@ fu_steelseries_gamepad_write_firmware_chunks(FuDevice *device,
|
|||||||
error))
|
error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
for (guint i = 3; i < STEELSERIES_BUFFER_TRANSFER_SIZE + 3; i++)
|
|
||||||
chunk_checksum += data[i];
|
|
||||||
|
|
||||||
/* block checksum */
|
/* block checksum */
|
||||||
/* probably not necessary */
|
/* probably not necessary */
|
||||||
|
chunk_checksum = fu_common_sum16(data + 3, STEELSERIES_BUFFER_TRANSFER_SIZE);
|
||||||
if (!fu_common_write_uint16_safe(data,
|
if (!fu_common_write_uint16_safe(data,
|
||||||
STEELSERIES_BUFFER_CONTROL_SIZE,
|
STEELSERIES_BUFFER_CONTROL_SIZE,
|
||||||
0x03 + STEELSERIES_BUFFER_TRANSFER_SIZE,
|
0x03 + STEELSERIES_BUFFER_TRANSFER_SIZE,
|
||||||
|
@ -310,8 +310,6 @@ fu_synaptics_mst_device_update_esm(FuSynapticsMstDevice *self,
|
|||||||
self->layer,
|
self->layer,
|
||||||
self->rad);
|
self->rad);
|
||||||
|
|
||||||
for (guint32 i = 0; i < esm_sz; i++)
|
|
||||||
checksum += *(payload_data + EEPROM_ESM_OFFSET + i);
|
|
||||||
if (!fu_synaptics_mst_device_get_flash_checksum(self,
|
if (!fu_synaptics_mst_device_get_flash_checksum(self,
|
||||||
esm_sz,
|
esm_sz,
|
||||||
EEPROM_ESM_OFFSET,
|
EEPROM_ESM_OFFSET,
|
||||||
@ -321,6 +319,7 @@ fu_synaptics_mst_device_update_esm(FuSynapticsMstDevice *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ESM checksum same */
|
/* ESM checksum same */
|
||||||
|
checksum = fu_common_sum32(payload_data + EEPROM_ESM_OFFSET, esm_sz);
|
||||||
if (checksum == flash_checksum) {
|
if (checksum == flash_checksum) {
|
||||||
g_debug("ESM checksum already matches");
|
g_debug("ESM checksum already matches");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -368,10 +367,7 @@ fu_synaptics_mst_device_update_esm(FuSynapticsMstDevice *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check ESM checksum */
|
/* check ESM checksum */
|
||||||
checksum = 0;
|
|
||||||
flash_checksum = 0;
|
flash_checksum = 0;
|
||||||
for (guint32 i = 0; i < esm_sz; i++)
|
|
||||||
checksum += *(payload_data + EEPROM_ESM_OFFSET + i);
|
|
||||||
if (!fu_synaptics_mst_device_get_flash_checksum(self,
|
if (!fu_synaptics_mst_device_get_flash_checksum(self,
|
||||||
esm_sz,
|
esm_sz,
|
||||||
EEPROM_ESM_OFFSET,
|
EEPROM_ESM_OFFSET,
|
||||||
@ -424,7 +420,7 @@ fu_synaptics_mst_device_update_tesla_leaf_firmware(FuSynapticsMstDevice *self,
|
|||||||
self->layer,
|
self->layer,
|
||||||
self->rad);
|
self->rad);
|
||||||
for (guint32 retries_cnt = 0;; retries_cnt++) {
|
for (guint32 retries_cnt = 0;; retries_cnt++) {
|
||||||
guint32 checksum = 0;
|
guint32 checksum;
|
||||||
guint32 flash_checksum = 0;
|
guint32 flash_checksum = 0;
|
||||||
|
|
||||||
if (!fu_synaptics_mst_device_set_flash_sector_erase(self, 0xffff, 0, error))
|
if (!fu_synaptics_mst_device_set_flash_sector_erase(self, 0xffff, 0, error))
|
||||||
@ -469,15 +465,13 @@ fu_synaptics_mst_device_update_tesla_leaf_firmware(FuSynapticsMstDevice *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check data just written */
|
/* check data just written */
|
||||||
for (guint32 i = 0; i < payload_len; i++)
|
|
||||||
checksum += *(payload_data + i);
|
|
||||||
|
|
||||||
if (!fu_synaptics_mst_device_get_flash_checksum(self,
|
if (!fu_synaptics_mst_device_get_flash_checksum(self,
|
||||||
payload_len,
|
payload_len,
|
||||||
0,
|
0,
|
||||||
&flash_checksum,
|
&flash_checksum,
|
||||||
error))
|
error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
checksum = fu_common_sum32(payload_data, payload_len);
|
||||||
if (checksum == flash_checksum)
|
if (checksum == flash_checksum)
|
||||||
break;
|
break;
|
||||||
g_debug("attempt %u: checksum %x didn't match %x",
|
g_debug("attempt %u: checksum %x didn't match %x",
|
||||||
|
@ -130,15 +130,6 @@ fu_plugin_uefi_capsule_get_splash_data(guint width, guint height, GError **error
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint8
|
|
||||||
fu_plugin_uefi_capsule_calc_checksum(const guint8 *buf, gsize sz)
|
|
||||||
{
|
|
||||||
guint8 csum = 0;
|
|
||||||
for (gsize i = 0; i < sz; i++)
|
|
||||||
csum += buf[i];
|
|
||||||
return csum;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
fu_plugin_uefi_capsule_write_splash_data(FuPlugin *plugin,
|
fu_plugin_uefi_capsule_write_splash_data(FuPlugin *plugin,
|
||||||
FuDevice *device,
|
FuDevice *device,
|
||||||
@ -209,11 +200,9 @@ fu_plugin_uefi_capsule_write_splash_data(FuPlugin *plugin,
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* header, payload and image has to add to zero */
|
/* header, payload and image has to add to zero */
|
||||||
csum +=
|
csum += fu_common_sum8((guint8 *)&capsule_header, sizeof(capsule_header));
|
||||||
fu_plugin_uefi_capsule_calc_checksum((guint8 *)&capsule_header, sizeof(capsule_header));
|
csum += fu_common_sum8((guint8 *)&header, sizeof(header));
|
||||||
csum += fu_plugin_uefi_capsule_calc_checksum((guint8 *)&header, sizeof(header));
|
csum += fu_common_sum8_bytes(blob);
|
||||||
csum += fu_plugin_uefi_capsule_calc_checksum(g_bytes_get_data(blob, NULL),
|
|
||||||
g_bytes_get_size(blob));
|
|
||||||
header.checksum = 0x100 - csum;
|
header.checksum = 0x100 - csum;
|
||||||
|
|
||||||
/* write capsule file */
|
/* write capsule file */
|
||||||
|
@ -56,13 +56,9 @@ fu_wacom_emr_device_setup(FuDevice *device, GError **error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static guint8
|
static guint8
|
||||||
fu_wacom_emr_device_calc_checksum(guint8 init1, const guint8 *buf, guint8 bufsz)
|
fu_wacom_emr_device_calc_checksum(guint8 init1, const guint8 *buf, gsize bufsz)
|
||||||
{
|
{
|
||||||
guint8 sum = 0;
|
return init1 + ~(fu_common_sum8(buf, bufsz)) + 1;
|
||||||
sum += init1;
|
|
||||||
for (guint i = 0; i < bufsz; i++)
|
|
||||||
sum += buf[i];
|
|
||||||
return ~sum + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -12,27 +12,6 @@
|
|||||||
|
|
||||||
#include "fu-wac-common.h"
|
#include "fu-wac-common.h"
|
||||||
|
|
||||||
guint32
|
|
||||||
fu_wac_calculate_checksum32le(const guint8 *data, gsize len)
|
|
||||||
{
|
|
||||||
guint32 csum = 0x0;
|
|
||||||
g_return_val_if_fail(len % 4 == 0, G_MAXUINT32);
|
|
||||||
for (guint i = 0; i < len; i += 4) {
|
|
||||||
guint32 tmp;
|
|
||||||
memcpy(&tmp, &data[i], sizeof(guint32));
|
|
||||||
csum += GUINT32_FROM_LE(tmp);
|
|
||||||
}
|
|
||||||
return GUINT32_TO_LE(csum);
|
|
||||||
}
|
|
||||||
|
|
||||||
guint32
|
|
||||||
fu_wac_calculate_checksum32le_bytes(GBytes *blob)
|
|
||||||
{
|
|
||||||
gsize len = 0;
|
|
||||||
const guint8 *data = g_bytes_get_data(blob, &len);
|
|
||||||
return fu_wac_calculate_checksum32le(data, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
fu_wac_report_id_to_string(guint8 report_id)
|
fu_wac_report_id_to_string(guint8 report_id)
|
||||||
{
|
{
|
||||||
|
@ -37,10 +37,6 @@
|
|||||||
#define FU_WAC_REPORT_ID_GET_CURRENT_FIRMWARE_IDX 0xe2 /* GET_FEATURE */
|
#define FU_WAC_REPORT_ID_GET_CURRENT_FIRMWARE_IDX 0xe2 /* GET_FEATURE */
|
||||||
#define FU_WAC_REPORT_ID_MODULE 0xe4
|
#define FU_WAC_REPORT_ID_MODULE 0xe4
|
||||||
|
|
||||||
guint32
|
|
||||||
fu_wac_calculate_checksum32le(const guint8 *data, gsize len);
|
|
||||||
guint32
|
|
||||||
fu_wac_calculate_checksum32le_bytes(GBytes *blob);
|
|
||||||
const gchar *
|
const gchar *
|
||||||
fu_wac_report_id_to_string(guint8 report_id);
|
fu_wac_report_id_to_string(guint8 report_id);
|
||||||
void
|
void
|
||||||
|
@ -583,7 +583,7 @@ fu_wac_device_write_firmware(FuDevice *device,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* calculate expected checksum and save to device RAM */
|
/* calculate expected checksum and save to device RAM */
|
||||||
csum_local[i] = fu_wac_calculate_checksum32le_bytes(blob_block);
|
csum_local[i] = GUINT32_TO_LE(fu_common_sum32w_bytes(blob_block, G_LITTLE_ENDIAN));
|
||||||
if (g_getenv("FWUPD_WACOM_USB_VERBOSE") != NULL)
|
if (g_getenv("FWUPD_WACOM_USB_VERBOSE") != NULL)
|
||||||
g_debug("block checksum %02u: 0x%08x", i, csum_local[i]);
|
g_debug("block checksum %02u: 0x%08x", i, csum_local[i]);
|
||||||
if (!fu_wac_device_set_checksum_of_block(self, i, csum_local[i], error))
|
if (!fu_wac_device_set_checksum_of_block(self, i, csum_local[i], error))
|
||||||
|
@ -304,10 +304,7 @@ fu_wac_firmware_parse(FuFirmware *firmware,
|
|||||||
static guint8
|
static guint8
|
||||||
fu_wac_firmware_calc_checksum(GByteArray *buf)
|
fu_wac_firmware_calc_checksum(GByteArray *buf)
|
||||||
{
|
{
|
||||||
guint8 csum = 0;
|
return fu_common_sum8(buf->data, buf->len) ^ 0xFF;
|
||||||
for (guint i = 0; i < buf->len; i++)
|
|
||||||
csum += buf->data[i];
|
|
||||||
return csum ^ 0xFF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GBytes *
|
static GBytes *
|
||||||
|
Loading…
Reference in New Issue
Block a user