mirror of
https://git.proxmox.com/git/fwupd
synced 2025-11-02 21:37:06 +00:00
ccgx: Verify the firmware app type when preparing firmware
This commit is contained in:
parent
754d85e282
commit
c6147bf340
@ -20,6 +20,7 @@
|
||||
struct _FuCcgxCyacdFirmwareImage {
|
||||
FuFirmwareImageClass parent_instance;
|
||||
GPtrArray *records;
|
||||
guint16 app_type;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (FuCcgxCyacdFirmwareImage, fu_ccgx_cyacd_firmware_image, FU_TYPE_FIRMWARE_IMAGE)
|
||||
@ -31,6 +32,13 @@ fu_ccgx_cyacd_firmware_image_get_records (FuCcgxCyacdFirmwareImage *self)
|
||||
return self->records;
|
||||
}
|
||||
|
||||
guint16
|
||||
fu_ccgx_cyacd_firmware_image_get_app_type (FuCcgxCyacdFirmwareImage *self)
|
||||
{
|
||||
g_return_val_if_fail (FU_IS_CCGX_CYACD_FIRMWARE_IMAGE (self), 0);
|
||||
return self->app_type;
|
||||
}
|
||||
|
||||
static void
|
||||
fu_ccgx_cyacd_firmware_image_record_free (FuCcgxCyacdFirmwareImageRecord *rcd)
|
||||
{
|
||||
@ -132,7 +140,8 @@ fu_ccgx_cyacd_firmware_image_parse_md_block (FuCcgxCyacdFirmwareImage *self, GEr
|
||||
if (!fu_common_read_uint32_safe (buf, bufsz, CCGX_APP_VERSION_OFFSET % bufsz,
|
||||
&version, G_LITTLE_ENDIAN, error))
|
||||
return FALSE;
|
||||
version_str = fu_common_version_from_uint32 (version, FWUPD_VERSION_FORMAT_QUAD);
|
||||
self->app_type = version & 0xffff;
|
||||
version_str = fu_ccgx_version_to_string (version);
|
||||
fu_firmware_image_set_version (FU_FIRMWARE_IMAGE (self), version_str);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -28,3 +28,4 @@ gboolean fu_ccgx_cyacd_firmware_image_add_record (FuCcgxCyacdFirmwareImage *sel
|
||||
const gchar *line,
|
||||
GError **error);
|
||||
GPtrArray *fu_ccgx_cyacd_firmware_image_get_records (FuCcgxCyacdFirmwareImage *self);
|
||||
guint16 fu_ccgx_cyacd_firmware_image_get_app_type (FuCcgxCyacdFirmwareImage *self);
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "fu-ccgx-hpi-common.h"
|
||||
#include "fu-ccgx-hpi-device.h"
|
||||
#include "fu-ccgx-cyacd-firmware.h"
|
||||
#include "fu-ccgx-cyacd-firmware-image.h"
|
||||
|
||||
struct _FuCcgxHpiDevice
|
||||
{
|
||||
@ -332,6 +333,7 @@ fu_ccgx_hpi_device_prepare_firmware (FuDevice *device,
|
||||
images = fu_firmware_get_images (firmware);
|
||||
for (guint i = 0; i < images->len; i++) {
|
||||
FuFirmwareImage *img = g_ptr_array_index (images, i);
|
||||
guint16 fw_app_type = fu_ccgx_cyacd_firmware_image_get_app_type (FU_CCGX_CYACD_FIRMWARE_IMAGE (img));
|
||||
if (fu_firmware_image_get_addr (img) != self->silicon_id) {
|
||||
g_set_error (error,
|
||||
FWUPD_ERROR,
|
||||
@ -342,6 +344,15 @@ fu_ccgx_hpi_device_prepare_firmware (FuDevice *device,
|
||||
(guint) fu_firmware_image_get_addr (img));
|
||||
return NULL;
|
||||
}
|
||||
if (fw_app_type != self->fw_app_type) {
|
||||
g_set_error (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_NOT_SUPPORTED,
|
||||
"app type mismatch on image %u, "
|
||||
"expected 0x%x, got 0x%x",
|
||||
i, self->fw_app_type, fw_app_type);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return g_steal_pointer (&firmware);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user