trivial: Provide some defines for common image names

This commit is contained in:
Richard Hughes 2019-11-08 14:30:07 +00:00 committed by Mario Limonciello
parent c5384e9173
commit 2414f24b8a
7 changed files with 22 additions and 9 deletions

View File

@ -416,10 +416,14 @@ fu_ebitdo_device_write_firmware (FuDevice *device,
} }
/* get header and payload */ /* get header and payload */
fw_hdr = fu_firmware_get_image_by_id_bytes (firmware, "header", error); fw_hdr = fu_firmware_get_image_by_id_bytes (firmware,
FU_FIRMWARE_IMAGE_ID_HEADER,
error);
if (fw_hdr == NULL) if (fw_hdr == NULL)
return FALSE; return FALSE;
fw_payload = fu_firmware_get_image_by_id_bytes (firmware, "payload", error); fw_payload = fu_firmware_get_image_by_id_bytes (firmware,
FU_FIRMWARE_IMAGE_ID_PAYLOAD,
error);
if (fw_payload == NULL) if (fw_payload == NULL)
return FALSE; return FALSE;

View File

@ -78,13 +78,13 @@ fu_ebitdo_firmware_parse (FuFirmware *firmware,
/* add header */ /* add header */
fw_hdr = g_bytes_new_from_bytes (fw, 0x0, sizeof(FuEbitdoFirmwareHeader)); fw_hdr = g_bytes_new_from_bytes (fw, 0x0, sizeof(FuEbitdoFirmwareHeader));
fu_firmware_image_set_id (img_hdr, "header"); fu_firmware_image_set_id (img_hdr, FU_FIRMWARE_IMAGE_ID_HEADER);
fu_firmware_image_set_bytes (img_hdr, fw_hdr); fu_firmware_image_set_bytes (img_hdr, fw_hdr);
fu_firmware_add_image (firmware, img_hdr); fu_firmware_add_image (firmware, img_hdr);
/* add payload */ /* add payload */
fw_payload = g_bytes_new_from_bytes (fw, sizeof(FuEbitdoFirmwareHeader), payload_len); fw_payload = g_bytes_new_from_bytes (fw, sizeof(FuEbitdoFirmwareHeader), payload_len);
fu_firmware_image_set_id (img_payload, "payload"); fu_firmware_image_set_id (img_payload, FU_FIRMWARE_IMAGE_ID_PAYLOAD);
fu_firmware_image_set_addr (img_payload, GUINT32_FROM_LE(hdr->destination_addr)); fu_firmware_image_set_addr (img_payload, GUINT32_FROM_LE(hdr->destination_addr));
fu_firmware_image_set_bytes (img_payload, fw_payload); fu_firmware_image_set_bytes (img_payload, fw_payload);
fu_firmware_add_image (firmware, img_payload); fu_firmware_add_image (firmware, img_payload);

View File

@ -470,7 +470,9 @@ fu_solokey_device_write_firmware (FuDevice *device,
} }
/* verify the signature and reboot back to runtime */ /* verify the signature and reboot back to runtime */
fw_sig = fu_firmware_get_image_by_id_bytes (firmware, "signature", error); fw_sig = fu_firmware_get_image_by_id_bytes (firmware,
FU_FIRMWARE_IMAGE_ID_SIGNATURE,
error);
if (fw_sig == NULL) if (fw_sig == NULL)
return FALSE; return FALSE;
return fu_solokey_device_verify (self, fw_sig, error); return fu_solokey_device_verify (self, fw_sig, error);

View File

@ -88,7 +88,7 @@ fu_solokey_firmware_parse (FuFirmware *firmware,
g_string_append (base64_websafe, "=="); g_string_append (base64_websafe, "==");
fw_sig = _g_base64_decode_to_bytes (base64_websafe->str); fw_sig = _g_base64_decode_to_bytes (base64_websafe->str);
fu_firmware_image_set_bytes (img_sig, fw_sig); fu_firmware_image_set_bytes (img_sig, fw_sig);
fu_firmware_image_set_id (img_sig, "signature"); fu_firmware_image_set_id (img_sig, FU_FIRMWARE_IMAGE_ID_SIGNATURE);
fu_firmware_add_image (firmware, img_sig); fu_firmware_add_image (firmware, img_sig);
return TRUE; return TRUE;
} }

View File

@ -28,6 +28,10 @@ struct _FuFirmwareImageClass
gpointer padding[28]; gpointer padding[28];
}; };
#define FU_FIRMWARE_IMAGE_ID_PAYLOAD "payload"
#define FU_FIRMWARE_IMAGE_ID_SIGNATURE "signature"
#define FU_FIRMWARE_IMAGE_ID_HEADER "header"
FuFirmwareImage *fu_firmware_image_new (GBytes *bytes); FuFirmwareImage *fu_firmware_image_new (GBytes *bytes);
gchar *fu_firmware_image_to_string (FuFirmwareImage *self); gchar *fu_firmware_image_to_string (FuFirmwareImage *self);

View File

@ -268,7 +268,7 @@ fu_ihex_firmware_parse (FuFirmware *firmware,
if (buf_signature->len > 0) { if (buf_signature->len > 0) {
g_autoptr(GBytes) data_sig = g_bytes_new (buf_signature->data, buf_signature->len); g_autoptr(GBytes) data_sig = g_bytes_new (buf_signature->data, buf_signature->len);
g_autoptr(FuFirmwareImage) img_sig = fu_firmware_image_new (data_sig); g_autoptr(FuFirmwareImage) img_sig = fu_firmware_image_new (data_sig);
fu_firmware_image_set_id (img_sig, "signature"); fu_firmware_image_set_id (img_sig, FU_FIRMWARE_IMAGE_ID_SIGNATURE);
fu_firmware_add_image (firmware, img_sig); fu_firmware_add_image (firmware, img_sig);
} }
return TRUE; return TRUE;
@ -313,7 +313,8 @@ dfu_firmware_to_ihex_image (FuFirmwareImage *img, GString *str, GError **error)
return FALSE; return FALSE;
/* special case */ /* special case */
if (g_strcmp0 (fu_firmware_image_get_id (img), "signature") == 0) if (g_strcmp0 (fu_firmware_image_get_id (img),
FU_FIRMWARE_IMAGE_ID_SIGNATURE) == 0)
record_type = DFU_INHX32_RECORD_TYPE_SIGNATURE; record_type = DFU_INHX32_RECORD_TYPE_SIGNATURE;
/* get number of chunks */ /* get number of chunks */

View File

@ -3816,7 +3816,9 @@ fu_firmware_ihex_signed_func (void)
g_assert_cmpint (g_bytes_get_size (data_fw), ==, 136); g_assert_cmpint (g_bytes_get_size (data_fw), ==, 136);
/* get the signed image */ /* get the signed image */
data_sig = fu_firmware_get_image_by_id_bytes (firmware, "signature", &error); data_sig = fu_firmware_get_image_by_id_bytes (firmware,
FU_FIRMWARE_IMAGE_ID_SIGNATURE,
&error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_nonnull (data_sig); g_assert_nonnull (data_sig);
data = g_bytes_get_data (data_sig, &len); data = g_bytes_get_data (data_sig, &len);