diff --git a/docs/fwupd-docs.xml b/docs/fwupd-docs.xml index ce95c036c..f8aa60a74 100644 --- a/docs/fwupd-docs.xml +++ b/docs/fwupd-docs.xml @@ -56,7 +56,6 @@ - diff --git a/libfwupdplugin/fu-device.c b/libfwupdplugin/fu-device.c index a7d5ebd07..fadea55af 100644 --- a/libfwupdplugin/fu-device.c +++ b/libfwupdplugin/fu-device.c @@ -2802,7 +2802,7 @@ fu_device_prepare_firmware (FuDevice *self, } /* check size */ - fw_def = fu_firmware_get_image_default_bytes (firmware, NULL); + fw_def = fu_firmware_get_bytes (firmware, NULL); if (fw_def != NULL) { guint64 fw_sz = (guint64) g_bytes_get_size (fw_def); if (priv->size_max > 0 && fw_sz > priv->size_max) { diff --git a/libfwupdplugin/fu-dfu-firmware.c b/libfwupdplugin/fu-dfu-firmware.c index c77ddd5d8..e45dab6d2 100644 --- a/libfwupdplugin/fu-dfu-firmware.c +++ b/libfwupdplugin/fu-dfu-firmware.c @@ -286,7 +286,6 @@ fu_dfu_firmware_parse (FuFirmware *firmware, FuDfuFirmware *self = FU_DFU_FIRMWARE (firmware); FuDfuFirmwarePrivate *priv = GET_PRIVATE (self); gsize len = g_bytes_get_size (fw); - g_autoptr(FuFirmwareImage) image = NULL; g_autoptr(GBytes) contents = NULL; /* parse footer */ @@ -297,8 +296,7 @@ fu_dfu_firmware_parse (FuFirmware *firmware, contents = fu_common_bytes_new_offset (fw, 0, len - priv->footer_len, error); if (contents == NULL) return FALSE; - image = fu_firmware_image_new (contents); - fu_firmware_add_image (firmware, image); + fu_firmware_set_bytes (firmware, contents); return TRUE; } @@ -342,7 +340,7 @@ fu_dfu_firmware_write (FuFirmware *firmware, GError **error) } /* add footer */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return NULL; return fu_dfu_firmware_append_footer (self, fw, error); diff --git a/libfwupdplugin/fu-dfuse-firmware.c b/libfwupdplugin/fu-dfuse-firmware.c index 7b8ae4ca2..fe86e41ad 100644 --- a/libfwupdplugin/fu-dfuse-firmware.c +++ b/libfwupdplugin/fu-dfuse-firmware.c @@ -88,7 +88,7 @@ fu_firmware_image_chunk_parse (FuDfuseFirmware *self, return g_steal_pointer (&chk); } -static FuFirmwareImage * +static FuFirmware * fu_dfuse_firmware_image_parse (FuDfuseFirmware *self, GBytes *bytes, gsize *offset, @@ -97,7 +97,7 @@ fu_dfuse_firmware_image_parse (FuDfuseFirmware *self, DfuSeImageHdr hdr = { 0x0 }; gsize bufsz = 0; const guint8 *buf = g_bytes_get_data (bytes, &bufsz); - g_autoptr(FuFirmwareImage) image = fu_firmware_image_new (NULL); + g_autoptr(FuFirmware) image = fu_firmware_new (); /* verify image signature */ if (!fu_memcpy_safe ((guint8 *) &hdr, sizeof(hdr), 0x0, /* dst */ @@ -113,11 +113,11 @@ fu_dfuse_firmware_image_parse (FuDfuseFirmware *self, } /* set properties */ - fu_firmware_image_set_idx (image, hdr.alt_setting); + fu_firmware_set_idx (image, hdr.alt_setting); if (GUINT32_FROM_LE (hdr.target_named) == 0x01) { g_autofree gchar *img_id = NULL; img_id = g_strndup (hdr.target_name, sizeof(hdr.target_name)); - fu_firmware_image_set_id (image, img_id); + fu_firmware_set_id (image, img_id); } /* no chunks */ @@ -139,7 +139,7 @@ fu_dfuse_firmware_image_parse (FuDfuseFirmware *self, error); if (chk == NULL) return NULL; - fu_firmware_image_add_chunk (image, chk); + fu_firmware_add_chunk (image, chk); } /* success */ @@ -205,7 +205,7 @@ fu_dfuse_firmware_parse (FuFirmware *firmware, /* parse the image targets */ offset += sizeof(hdr); for (guint i = 0; i < hdr.targets; i++) { - g_autoptr(FuFirmwareImage) image = NULL; + g_autoptr(FuFirmware) image = NULL; image = fu_dfuse_firmware_image_parse (FU_DFUSE_FIRMWARE (firmware), fw, &offset, error); @@ -217,7 +217,7 @@ fu_dfuse_firmware_parse (FuFirmware *firmware, } static GBytes * -fu_firmware_image_chunk_write (FuChunk *chk) +fu_firmware_chunk_write (FuChunk *chk) { DfuSeElementHdr hdr = { 0x0 }; const guint8 *data = fu_chunk_get_data (chk); @@ -233,7 +233,7 @@ fu_firmware_image_chunk_write (FuChunk *chk) } static GBytes * -fu_dfuse_firmware_image_write (FuFirmwareImage *image, GError **error) +fu_dfuse_firmware_write_image (FuFirmware *image, GError **error) { DfuSeImageHdr hdr = { 0x0 }; gsize totalsz = 0; @@ -243,12 +243,12 @@ fu_dfuse_firmware_image_write (FuFirmwareImage *image, GError **error) /* get total size */ blobs = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref); - chunks = fu_firmware_image_get_chunks (image, error); + chunks = fu_firmware_get_chunks (image, error); if (chunks == NULL) return NULL; for (guint i = 0; i < chunks->len; i++) { FuChunk *chk = g_ptr_array_index (chunks, i); - GBytes *bytes = fu_firmware_image_chunk_write (chk); + GBytes *bytes = fu_firmware_chunk_write (chk); g_ptr_array_add (blobs, bytes); totalsz += g_bytes_get_size (bytes); } @@ -258,11 +258,11 @@ fu_dfuse_firmware_image_write (FuFirmwareImage *image, GError **error) /* add prefix */ memcpy (hdr.sig, "Target", 6); - hdr.alt_setting = fu_firmware_image_get_idx (image); - if (fu_firmware_image_get_id (image) != NULL) { + hdr.alt_setting = fu_firmware_get_idx (image); + if (fu_firmware_get_id (image) != NULL) { hdr.target_named = GUINT32_TO_LE (0x01); g_strlcpy ((gchar *) &hdr.target_name, - fu_firmware_image_get_id (image), + fu_firmware_get_id (image), sizeof(hdr.target_name)); } hdr.target_size = GUINT32_TO_LE (totalsz); @@ -293,9 +293,9 @@ fu_dfuse_firmware_write (FuFirmware *firmware, GError **error) blobs = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref); images = fu_firmware_get_images (FU_FIRMWARE (firmware)); for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); + FuFirmware *img = g_ptr_array_index (images, i); g_autoptr(GBytes) blob = NULL; - blob = fu_dfuse_firmware_image_write (img, error); + blob = fu_dfuse_firmware_write_image (img, error); if (blob == NULL) return NULL; totalsz += g_bytes_get_size (blob); diff --git a/libfwupdplugin/fu-efi-signature-list.c b/libfwupdplugin/fu-efi-signature-list.c index 8dc1bb6f1..72be3f53d 100644 --- a/libfwupdplugin/fu-efi-signature-list.c +++ b/libfwupdplugin/fu-efi-signature-list.c @@ -74,8 +74,8 @@ fu_efi_signature_list_parse_item (FuEfiSignatureList *self, sig_owner = fwupd_guid_to_string (&guid, FWUPD_GUID_FLAG_MIXED_ENDIAN); data = g_bytes_new (sig_data, sig_datasz); sig = fu_efi_signature_new (sig_kind, sig_owner); - fu_firmware_image_set_bytes (FU_FIRMWARE_IMAGE (sig), data); - fu_firmware_add_image (FU_FIRMWARE (self), FU_FIRMWARE_IMAGE (sig)); + fu_firmware_set_bytes (FU_FIRMWARE (sig), data); + fu_firmware_add_image (FU_FIRMWARE (self), FU_FIRMWARE (sig)); return TRUE; } diff --git a/libfwupdplugin/fu-efi-signature.c b/libfwupdplugin/fu-efi-signature.c index 9dd714d29..d070888c8 100644 --- a/libfwupdplugin/fu-efi-signature.c +++ b/libfwupdplugin/fu-efi-signature.c @@ -18,12 +18,12 @@ */ struct _FuEfiSignature { - FuFirmwareImage parent_instance; + FuFirmware parent_instance; FuEfiSignatureKind kind; gchar *owner; }; -G_DEFINE_TYPE (FuEfiSignature, fu_efi_signature, FU_TYPE_FIRMWARE_IMAGE) +G_DEFINE_TYPE (FuEfiSignature, fu_efi_signature, FU_TYPE_FIRMWARE) /** * fu_efi_signature_kind_to_string: @@ -100,12 +100,14 @@ fu_efi_signature_get_owner (FuEfiSignature *self) } static gchar * -fu_efi_signature_get_checksum (FuFirmwareImage *firmware_image, +fu_efi_signature_get_checksum (FuFirmware *firmware, GChecksumType csum_kind, GError **error) { - FuEfiSignature *self = FU_EFI_SIGNATURE (firmware_image); - g_autoptr(GBytes) data = fu_firmware_image_get_bytes (firmware_image); + FuEfiSignature *self = FU_EFI_SIGNATURE (firmware); + g_autoptr(GBytes) data = fu_firmware_get_bytes (firmware, error); + if (data == NULL) + return NULL; /* special case: this is *literally* a hash */ if (self->kind == FU_EFI_SIGNATURE_KIND_SHA256 && @@ -136,9 +138,9 @@ static void fu_efi_signature_class_init (FuEfiSignatureClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - FuFirmwareImageClass *firmware_image_class = FU_FIRMWARE_IMAGE_CLASS (klass); + FuFirmwareClass *firmware_class = FU_FIRMWARE_CLASS (klass); object_class->finalize = fu_efi_signature_finalize; - firmware_image_class->get_checksum = fu_efi_signature_get_checksum; + firmware_class->get_checksum = fu_efi_signature_get_checksum; } static void diff --git a/libfwupdplugin/fu-efi-signature.h b/libfwupdplugin/fu-efi-signature.h index 62ce9290c..54bb19388 100644 --- a/libfwupdplugin/fu-efi-signature.h +++ b/libfwupdplugin/fu-efi-signature.h @@ -8,10 +8,10 @@ #include -#include "fu-firmware-image.h" +#include "fu-firmware.h" #define FU_TYPE_EFI_SIGNATURE (fu_efi_signature_get_type ()) -G_DECLARE_FINAL_TYPE (FuEfiSignature, fu_efi_signature, FU, EFI_SIGNATURE, FuFirmwareImage) +G_DECLARE_FINAL_TYPE (FuEfiSignature, fu_efi_signature, FU, EFI_SIGNATURE, FuFirmware) typedef enum { FU_EFI_SIGNATURE_KIND_UNKNOWN, diff --git a/libfwupdplugin/fu-firmware-image-private.h b/libfwupdplugin/fu-firmware-image-private.h deleted file mode 100644 index 708e335e9..000000000 --- a/libfwupdplugin/fu-firmware-image-private.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (C) 2019 Richard Hughes - * - * SPDX-License-Identifier: LGPL-2.1+ - */ - -#pragma once - -#include "fu-firmware-image.h" - -void fu_firmware_image_add_string (FuFirmwareImage *self, - guint idt, - GString *str); diff --git a/libfwupdplugin/fu-firmware-image.c b/libfwupdplugin/fu-firmware-image.c deleted file mode 100644 index 6e1104867..000000000 --- a/libfwupdplugin/fu-firmware-image.c +++ /dev/null @@ -1,737 +0,0 @@ -/* - * Copyright (C) 2019 Richard Hughes - * - * SPDX-License-Identifier: LGPL-2.1+ - */ - -#define G_LOG_DOMAIN "FuFirmware" - -#include "config.h" - -#include "fu-common.h" -#include "fu-chunk-private.h" -#include "fu-firmware-image-private.h" - -/** - * SECTION:fu-firmware-image - * @short_description: a firmware image section - * - * An object that represents an image within the firmware file. - */ - -typedef struct { - gchar *id; - GBytes *bytes; - guint64 addr; - guint64 offset; - guint64 idx; - gchar *version; - gchar *filename; - GPtrArray *chunks; /* nullable, element-type FuChunk */ -} FuFirmwareImagePrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (FuFirmwareImage, fu_firmware_image, G_TYPE_OBJECT) -#define GET_PRIVATE(o) (fu_firmware_image_get_instance_private (o)) - -/** - * fu_firmware_image_get_version: - * @self: A #FuFirmwareImage - * - * Gets an optional version that represents the firmware image. - * - * Returns: a string, or %NULL - * - * Since: 1.3.4 - **/ -const gchar * -fu_firmware_image_get_version (FuFirmwareImage *self) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), NULL); - return priv->version; -} - -/** - * fu_firmware_image_set_version: - * @self: A #FuFirmwareImage - * @version: (nullable): A string version, or %NULL - * - * Sets an optional version that represents the firmware image. - * - * Since: 1.3.4 - **/ -void -fu_firmware_image_set_version (FuFirmwareImage *self, const gchar *version) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_if_fail (FU_IS_FIRMWARE_IMAGE (self)); - - /* not changed */ - if (g_strcmp0 (priv->version, version) == 0) - return; - - g_free (priv->version); - priv->version = g_strdup (version); -} - -/** - * fu_firmware_image_get_filename: - * @self: A #FuFirmwareImage - * - * Gets an optional filename that represents the image source or destination. - * - * Returns: a string, or %NULL - * - * Since: 1.5.0 - **/ -const gchar * -fu_firmware_image_get_filename (FuFirmwareImage *self) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), NULL); - return priv->filename; -} - -/** - * fu_firmware_image_set_filename: - * @self: A #FuFirmwareImage - * @filename: (nullable): A string filename, or %NULL - * - * Sets an optional filename that represents the image source or destination. - * - * Since: 1.5.0 - **/ -void -fu_firmware_image_set_filename (FuFirmwareImage *self, const gchar *filename) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_if_fail (FU_IS_FIRMWARE_IMAGE (self)); - - /* not changed */ - if (g_strcmp0 (priv->filename, filename) == 0) - return; - - g_free (priv->filename); - priv->filename = g_strdup (filename); -} - -/** - * fu_firmware_image_set_id: - * @self: a #FuPlugin - * @id: (nullable): image ID, e.g. "config" - * - * Since: 1.3.1 - **/ -void -fu_firmware_image_set_id (FuFirmwareImage *self, const gchar *id) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_if_fail (FU_IS_FIRMWARE_IMAGE (self)); - - /* not changed */ - if (g_strcmp0 (priv->id, id) == 0) - return; - - g_free (priv->id); - priv->id = g_strdup (id); -} - -/** - * fu_firmware_image_get_id: - * @self: a #FuPlugin - * - * Gets the image ID, typically set at construction. - * - * Returns: image ID, e.g. "config" - * - * Since: 1.3.1 - **/ -const gchar * -fu_firmware_image_get_id (FuFirmwareImage *self) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), NULL); - return priv->id; -} - -/** - * fu_firmware_image_set_addr: - * @self: a #FuPlugin - * @addr: integer - * - * Sets the base address of the image. - * - * Since: 1.3.1 - **/ -void -fu_firmware_image_set_addr (FuFirmwareImage *self, guint64 addr) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_if_fail (FU_IS_FIRMWARE_IMAGE (self)); - priv->addr = addr; -} - -/** - * fu_firmware_image_get_addr: - * @self: a #FuPlugin - * - * Gets the base address of the image. - * - * Returns: integer - * - * Since: 1.3.1 - **/ -guint64 -fu_firmware_image_get_addr (FuFirmwareImage *self) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), G_MAXUINT64); - return priv->addr; -} - -/** - * fu_firmware_image_set_offset: - * @self: a #FuPlugin - * @offset: integer - * - * Sets the base offset of the image. - * - * Since: 1.5.0 - **/ -void -fu_firmware_image_set_offset (FuFirmwareImage *self, guint64 offset) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_if_fail (FU_IS_FIRMWARE_IMAGE (self)); - priv->offset = offset; -} - -/** - * fu_firmware_image_get_offset: - * @self: a #FuPlugin - * - * Gets the base offset of the image. - * - * Returns: integer - * - * Since: 1.5.0 - **/ -guint64 -fu_firmware_image_get_offset (FuFirmwareImage *self) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), G_MAXUINT64); - return priv->offset; -} - -/** - * fu_firmware_image_set_idx: - * @self: a #FuPlugin - * @idx: integer - * - * Sets the index of the image which is used for ordering. - * - * Since: 1.3.1 - **/ -void -fu_firmware_image_set_idx (FuFirmwareImage *self, guint64 idx) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_if_fail (FU_IS_FIRMWARE_IMAGE (self)); - priv->idx = idx; -} - -/** - * fu_firmware_image_get_idx: - * @self: a #FuPlugin - * - * Gets the index of the image which is used for ordering. - * - * Returns: integer - * - * Since: 1.3.1 - **/ -guint64 -fu_firmware_image_get_idx (FuFirmwareImage *self) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), G_MAXUINT64); - return priv->idx; -} - -/** - * fu_firmware_image_set_bytes: - * @self: a #FuPlugin - * @bytes: A #GBytes - * - * Sets the contents of the image if not created with fu_firmware_image_new(). - * - * Since: 1.3.1 - **/ -void -fu_firmware_image_set_bytes (FuFirmwareImage *self, GBytes *bytes) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_if_fail (FU_IS_FIRMWARE_IMAGE (self)); - g_return_if_fail (bytes != NULL); - g_return_if_fail (priv->bytes == NULL); - priv->bytes = g_bytes_ref (bytes); -} - -/** - * fu_firmware_image_get_bytes: - * @self: a #FuPlugin - * - * Gets the data set using fu_firmware_image_set_bytes(). - * - * This should only really be used by objects subclassing #FuFirmwareImage as - * images are normally exported to a file using fu_firmware_image_write(). - * - * Returns: (transfer full): a #GBytes of the data, or %NULL if the bytes is not set - * - * Since: 1.5.0 - **/ -GBytes * -fu_firmware_image_get_bytes (FuFirmwareImage *self) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), NULL); - if (priv->bytes == NULL) - return NULL; - return g_bytes_ref (priv->bytes); -} -/** - * fu_firmware_image_get_chunks: - * @self: a #FuFirmwareImage - * @error: A #GError, or %NULL - * - * Gets the optional image chunks. - * - * Return value: (transfer container) (element-type FuChunk) (nullable): chunk data, or %NULL - * - * Since: 1.5.6 - **/ -GPtrArray * -fu_firmware_image_get_chunks (FuFirmwareImage *self, GError **error) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - - /* set */ - if (priv->chunks != NULL) - return g_ptr_array_ref (priv->chunks); - - /* lets build something plausible */ - if (priv->bytes != NULL) { - g_autoptr(GPtrArray) chunks = NULL; - g_autoptr(FuChunk) chk = NULL; - chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); - chk = fu_chunk_bytes_new (priv->bytes); - fu_chunk_set_idx (chk, priv->idx); - fu_chunk_set_address (chk, priv->addr); - g_ptr_array_add (chunks, g_steal_pointer (&chk)); - return g_steal_pointer (&chunks); - } - - /* nothing to do */ - g_set_error_literal (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_FOUND, - "no bytes or chunks found in firmware"); - return NULL; -} - -/** - * fu_firmware_image_add_chunk: - * @self: a #FuFirmwareImage - * @chk: a #FuChunk - * - * Adds a chunk to the image. - * - * Since: 1.5.6 - **/ -void -fu_firmware_image_add_chunk (FuFirmwareImage *self, FuChunk *chk) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_return_if_fail (FU_IS_FIRMWARE_IMAGE (self)); - g_return_if_fail (FU_IS_CHUNK (chk)); - if (priv->chunks == NULL) - priv->chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); - g_ptr_array_add (priv->chunks, g_object_ref (chk)); -} - -/** - * fu_firmware_image_get_checksum: - * @self: a #FuPlugin - * @csum_kind: a #GChecksumType, e.g. %G_CHECKSUM_SHA256 - * @error: A #GError, or %NULL - * - * Returns a checksum of the data. - * - * Returns: (transfer full): a checksum string, or %NULL if the checksum is not available - * - * Since: 1.5.5 - **/ -gchar * -fu_firmware_image_get_checksum (FuFirmwareImage *self, - GChecksumType csum_kind, - GError **error) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - FuFirmwareImageClass *klass = FU_FIRMWARE_IMAGE_GET_CLASS (self); - - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - - /* subclassed */ - if (klass->get_checksum != NULL) - return klass->get_checksum (self, csum_kind, error); - - /* internal data */ - if (priv->bytes == NULL) { - g_set_error (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_FOUND, - "no bytes found in firmware bytes %s", - priv->id); - return NULL; - } - return g_compute_checksum_for_bytes (csum_kind, priv->bytes); -} - -/** - * fu_firmware_image_parse: - * @self: A #FuFirmwareImage - * @fw: A #GBytes - * @flags: some #FwupdInstallFlags, e.g. %FWUPD_INSTALL_FLAG_FORCE - * @error: A #GError, or %NULL - * - * Parses a firmware image, typically checking image CRCs and/or headers. - * - * Returns: %TRUE for success - * - * Since: 1.5.0 - **/ -gboolean -fu_firmware_image_parse (FuFirmwareImage *self, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) -{ - FuFirmwareImageClass *klass = FU_FIRMWARE_IMAGE_GET_CLASS (self); - - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), FALSE); - g_return_val_if_fail (fw != NULL, FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - /* subclassed */ - if (klass->parse != NULL) - return klass->parse (self, fw, flags, error); - - /* just add entire blob */ - fu_firmware_image_set_bytes (self, fw); - return TRUE; -} - -/** - * fu_firmware_image_build: - * @self: A #FuFirmwareImage - * @n: A #XbNode - * @error: A #GError, or %NULL - * - * Builds a firmware image from an XML manifest. - * - * Returns: %TRUE for success - * - * Since: 1.5.0 - **/ -gboolean -fu_firmware_image_build (FuFirmwareImage *self, XbNode *n, GError **error) -{ - FuFirmwareImageClass *klass = FU_FIRMWARE_IMAGE_GET_CLASS (self); - guint64 tmpval; - const gchar *tmp; - g_autoptr(GPtrArray) chunks = NULL; - g_autoptr(XbNode) data = NULL; - - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), FALSE); - g_return_val_if_fail (XB_IS_NODE (n), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - tmp = xb_node_query_text (n, "version", NULL); - if (tmp != NULL) - fu_firmware_image_set_version (self, tmp); - tmp = xb_node_query_text (n, "id", NULL); - if (tmp != NULL) - fu_firmware_image_set_id (self, tmp); - tmpval = xb_node_query_text_as_uint (n, "idx", NULL); - if (tmpval != G_MAXUINT64) - fu_firmware_image_set_idx (self, tmpval); - tmpval = xb_node_query_text_as_uint (n, "addr", NULL); - if (tmpval != G_MAXUINT64) - fu_firmware_image_set_addr (self, tmpval); - tmpval = xb_node_query_text_as_uint (n, "offset", NULL); - if (tmpval != G_MAXUINT64) - fu_firmware_image_set_offset (self, tmpval); - tmp = xb_node_query_text (n, "filename", NULL); - if (tmp != NULL) { - g_autoptr(GBytes) blob = NULL; - blob = fu_common_get_contents_bytes (tmp, error); - if (blob == NULL) - return FALSE; - fu_firmware_image_set_bytes (self, blob); - fu_firmware_image_set_filename (self, tmp); - } - data = xb_node_query_first (n, "data", NULL); - if (data != NULL && xb_node_get_text (data) != NULL) { - gsize bufsz = 0; - g_autofree guchar *buf = NULL; - g_autoptr(GBytes) blob = NULL; - buf = g_base64_decode (xb_node_get_text (data), &bufsz); - blob = g_bytes_new (buf, bufsz); - fu_firmware_image_set_bytes (self, blob); - } else if (data != NULL) { - g_autoptr(GBytes) blob = NULL; - blob = g_bytes_new (NULL, 0); - fu_firmware_image_set_bytes (self, blob); - } - - /* optional chunks */ - chunks = xb_node_query (n, "chunks/chunk", 0, NULL); - if (chunks != NULL) { - for (guint i = 0; i < chunks->len; i++) { - XbNode *c = g_ptr_array_index (chunks, i); - g_autoptr(FuChunk) chk = fu_chunk_bytes_new (NULL); - fu_chunk_set_idx (chk, i); - if (!fu_chunk_build (chk, c, error)) - return FALSE; - fu_firmware_image_add_chunk (self, chk); - } - } - - /* subclassed */ - if (klass->build != NULL) { - if (!klass->build (self, n, error)) - return FALSE; - } - - /* success */ - return TRUE; -} - -/** - * fu_firmware_image_write: - * @self: a #FuPlugin - * @error: A #GError, or %NULL - * - * Writes the image, which will try to call a superclassed ->write() function. - * - * By default (and in most cases) this just provides the value set by the - * fu_firmware_image_set_bytes() function. - * - * Returns: (transfer full): a #GBytes of the bytes, or %NULL if the bytes is not set - * - * Since: 1.3.3 - **/ -GBytes * -fu_firmware_image_write (FuFirmwareImage *self, GError **error) -{ - FuFirmwareImageClass *klass = FU_FIRMWARE_IMAGE_GET_CLASS (self); - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - - /* optional vfunc */ - if (klass->write != NULL) - return klass->write (self, error); - - /* set */ - if (priv->bytes != NULL) - return g_bytes_ref (priv->bytes); - - /* fall back to chunks */ - if (priv->chunks != NULL && priv->chunks->len == 1) { - FuChunk *chk = g_ptr_array_index (priv->chunks, 0); - return fu_chunk_get_bytes (chk); - } - - /* failed */ - g_set_error (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_FOUND, - "no bytes found in firmware bytes %s", priv->id); - return NULL; -} - -/** - * fu_firmware_image_write_chunk: - * @self: a #FuFirmwareImage - * @address: an address greater than dfu_element_get_address() - * @chunk_sz_max: the size of the new chunk - * @error: a #GError, or %NULL - * - * Gets a block of data from the image. If the contents of the image is - * smaller than the requested chunk size then the #GBytes will be smaller - * than @chunk_sz_max. Use fu_common_bytes_pad() if padding is required. - * - * If the @address is larger than the size of the image then an error is returned. - * - * Return value: (transfer full): a #GBytes, or %NULL - * - * Since: 1.3.1 - **/ -GBytes * -fu_firmware_image_write_chunk (FuFirmwareImage *self, - guint64 address, - guint64 chunk_sz_max, - GError **error) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - gsize chunk_left; - guint64 offset; - - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (self), NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - - /* check address requested is larger than base address */ - if (address < priv->addr) { - g_set_error (error, - FWUPD_ERROR, - FWUPD_ERROR_INTERNAL, - "requested address 0x%x less than base address 0x%x", - (guint) address, (guint) priv->addr); - return NULL; - } - - /* offset into data */ - offset = address - priv->addr; - if (offset > g_bytes_get_size (priv->bytes)) { - g_set_error (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_FOUND, - "offset 0x%x larger than data size 0x%x", - (guint) offset, - (guint) g_bytes_get_size (priv->bytes)); - return NULL; - } - - /* if we have less data than requested */ - chunk_left = g_bytes_get_size (priv->bytes) - offset; - if (chunk_sz_max > chunk_left) { - return fu_common_bytes_new_offset (priv->bytes, - offset, - chunk_left, - error); - } - - /* check chunk */ - return fu_common_bytes_new_offset (priv->bytes, - offset, - chunk_sz_max, - error); -} - -void -fu_firmware_image_add_string (FuFirmwareImage *self, guint idt, GString *str) -{ - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - FuFirmwareImageClass *klass = FU_FIRMWARE_IMAGE_GET_CLASS (self); - - fu_common_string_append_kv (str, idt, G_OBJECT_TYPE_NAME (self), NULL); - if (priv->id != NULL) - fu_common_string_append_kv (str, idt, "ID", priv->id); - if (priv->idx != 0x0) - fu_common_string_append_kx (str, idt, "Index", priv->idx); - if (priv->addr != 0x0) - fu_common_string_append_kx (str, idt, "Address", priv->addr); - if (priv->offset != 0x0) - fu_common_string_append_kx (str, idt, "Offset", priv->offset); - if (priv->version != NULL) - fu_common_string_append_kv (str, idt, "Version", priv->version); - if (priv->filename != NULL) - fu_common_string_append_kv (str, idt, "Filename", priv->filename); - if (priv->bytes != NULL) { - fu_common_string_append_kx (str, idt, "Data", - g_bytes_get_size (priv->bytes)); - } - - /* add chunks */ - if (priv->chunks != NULL) { - for (guint i = 0; i < priv->chunks->len; i++) { - FuChunk *chk = g_ptr_array_index (priv->chunks, i); - fu_chunk_add_string (chk, idt + 1, str); - } - } - - /* vfunc */ - if (klass->to_string != NULL) - klass->to_string (self, idt, str); -} - -/** - * fu_firmware_image_to_string: - * @self: A #FuFirmwareImage - * - * This allows us to easily print the object. - * - * Returns: a string value, or %NULL for invalid. - * - * Since: 1.3.1 - **/ -gchar * -fu_firmware_image_to_string (FuFirmwareImage *self) -{ - GString *str = g_string_new (NULL); - fu_firmware_image_add_string (self, 0, str); - return g_string_free (str, FALSE); -} - -static void -fu_firmware_image_init (FuFirmwareImage *self) -{ -} - -static void -fu_firmware_image_finalize (GObject *object) -{ - FuFirmwareImage *self = FU_FIRMWARE_IMAGE (object); - FuFirmwareImagePrivate *priv = GET_PRIVATE (self); - g_free (priv->id); - g_free (priv->version); - g_free (priv->filename); - if (priv->bytes != NULL) - g_bytes_unref (priv->bytes); - if (priv->chunks != NULL) - g_ptr_array_unref (priv->chunks); - G_OBJECT_CLASS (fu_firmware_image_parent_class)->finalize (object); -} - -static void -fu_firmware_image_class_init (FuFirmwareImageClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = fu_firmware_image_finalize; -} - -/** - * fu_firmware_image_new: - * @bytes: Optional #GBytes - * - * Creates an empty firmware_image object. - * - * Returns: a #FuFirmwareImage - * - * Since: 1.3.1 - **/ -FuFirmwareImage * -fu_firmware_image_new (GBytes *bytes) -{ - FuFirmwareImage *self = g_object_new (FU_TYPE_FIRMWARE_IMAGE, NULL); - if (bytes != NULL) - fu_firmware_image_set_bytes (self, bytes); - return self; -} diff --git a/libfwupdplugin/fu-firmware-image.h b/libfwupdplugin/fu-firmware-image.h deleted file mode 100644 index 8bf3d1791..000000000 --- a/libfwupdplugin/fu-firmware-image.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2019 Richard Hughes - * - * SPDX-License-Identifier: LGPL-2.1+ - */ - -#pragma once - -#include -#include -#include - -#include "fu-chunk.h" - -#define FU_TYPE_FIRMWARE_IMAGE (fu_firmware_image_get_type ()) -G_DECLARE_DERIVABLE_TYPE (FuFirmwareImage, fu_firmware_image, FU, FIRMWARE_IMAGE, GObject) - -struct _FuFirmwareImageClass -{ - GObjectClass parent_class; - gboolean (*parse) (FuFirmwareImage *self, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) - G_GNUC_WARN_UNUSED_RESULT; - void (*to_string) (FuFirmwareImage *self, - guint idt, - GString *str); - GBytes *(*write) (FuFirmwareImage *self, - GError **error) - G_GNUC_WARN_UNUSED_RESULT; - gboolean (*build) (FuFirmwareImage *self, - XbNode *n, - GError **error) - G_GNUC_WARN_UNUSED_RESULT; - gchar *(*get_checksum)(FuFirmwareImage *self, - GChecksumType csum_kind, - GError **error) - G_GNUC_WARN_UNUSED_RESULT; - /*< private >*/ - gpointer padding[26]; -}; - -#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); -gchar *fu_firmware_image_to_string (FuFirmwareImage *self); - -const gchar *fu_firmware_image_get_version (FuFirmwareImage *self); -void fu_firmware_image_set_version (FuFirmwareImage *self, - const gchar *version); -const gchar *fu_firmware_image_get_filename (FuFirmwareImage *self); -void fu_firmware_image_set_filename (FuFirmwareImage *self, - const gchar *filename); -const gchar *fu_firmware_image_get_id (FuFirmwareImage *self); -void fu_firmware_image_set_id (FuFirmwareImage *self, - const gchar *id); -guint64 fu_firmware_image_get_addr (FuFirmwareImage *self); -void fu_firmware_image_set_addr (FuFirmwareImage *self, - guint64 addr); -guint64 fu_firmware_image_get_offset (FuFirmwareImage *self); -void fu_firmware_image_set_offset (FuFirmwareImage *self, - guint64 offset); -guint64 fu_firmware_image_get_idx (FuFirmwareImage *self); -void fu_firmware_image_set_idx (FuFirmwareImage *self, - guint64 idx); -GBytes *fu_firmware_image_get_bytes (FuFirmwareImage *self); -void fu_firmware_image_set_bytes (FuFirmwareImage *self, - GBytes *bytes); -void fu_firmware_image_add_chunk (FuFirmwareImage *self, - FuChunk *chk); -GPtrArray *fu_firmware_image_get_chunks (FuFirmwareImage *self, - GError **error); -gchar *fu_firmware_image_get_checksum (FuFirmwareImage *self, - GChecksumType csum_kind, - GError **error); -gboolean fu_firmware_image_parse (FuFirmwareImage *self, - GBytes *fw, - FwupdInstallFlags flags, - GError **error) - G_GNUC_WARN_UNUSED_RESULT; -gboolean fu_firmware_image_build (FuFirmwareImage *self, - XbNode *n, - GError **error) - G_GNUC_WARN_UNUSED_RESULT; -GBytes *fu_firmware_image_write (FuFirmwareImage *self, - GError **error) - G_GNUC_WARN_UNUSED_RESULT; -GBytes *fu_firmware_image_write_chunk (FuFirmwareImage *self, - guint64 address, - guint64 chunk_sz_max, - GError **error) - G_GNUC_WARN_UNUSED_RESULT; diff --git a/libfwupdplugin/fu-firmware.c b/libfwupdplugin/fu-firmware.c index b83bf95b1..addcc2244 100644 --- a/libfwupdplugin/fu-firmware.c +++ b/libfwupdplugin/fu-firmware.c @@ -8,9 +8,9 @@ #include "config.h" +#include "fu-chunk-private.h" #include "fu-common.h" #include "fu-firmware.h" -#include "fu-firmware-image-private.h" /** * SECTION:fu-firmware @@ -22,9 +22,16 @@ typedef struct { FuFirmwareFlags flags; - GPtrArray *images; /* FuFirmwareImage */ + GPtrArray *images; /* FuFirmware */ gchar *version; guint64 version_raw; + GBytes *bytes; + gchar *id; + gchar *filename; + guint64 idx; + guint64 addr; + guint64 offset; + GPtrArray *chunks; /* nullable, element-type FuChunk */ } FuFirmwarePrivate; G_DEFINE_TYPE_WITH_PRIVATE (FuFirmware, fu_firmware, G_TYPE_OBJECT) @@ -197,6 +204,343 @@ fu_firmware_set_version_raw (FuFirmware *self, guint64 version_raw) priv->version_raw = version_raw; } +/** + * fu_firmware_get_filename: + * @self: A #FuFirmware + * + * Gets an optional filename that represents the image source or destination. + * + * Returns: a string, or %NULL + * + * Since: 1.6.0 + **/ +const gchar * +fu_firmware_get_filename (FuFirmware *self) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (FU_IS_FIRMWARE (self), NULL); + return priv->filename; +} + +/** + * fu_firmware_set_filename: + * @self: A #FuFirmware + * @filename: (nullable): A string filename, or %NULL + * + * Sets an optional filename that represents the image source or destination. + * + * Since: 1.6.0 + **/ +void +fu_firmware_set_filename (FuFirmware *self, const gchar *filename) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_if_fail (FU_IS_FIRMWARE (self)); + + /* not changed */ + if (g_strcmp0 (priv->filename, filename) == 0) + return; + + g_free (priv->filename); + priv->filename = g_strdup (filename); +} + +/** + * fu_firmware_set_id: + * @self: a #FuPlugin + * @id: (nullable): image ID, e.g. "config" + * + * Since: 1.6.0 + **/ +void +fu_firmware_set_id (FuFirmware *self, const gchar *id) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_if_fail (FU_IS_FIRMWARE (self)); + + /* not changed */ + if (g_strcmp0 (priv->id, id) == 0) + return; + + g_free (priv->id); + priv->id = g_strdup (id); +} + +/** + * fu_firmware_get_id: + * @self: a #FuPlugin + * + * Gets the image ID, typically set at construction. + * + * Returns: image ID, e.g. "config" + * + * Since: 1.6.0 + **/ +const gchar * +fu_firmware_get_id (FuFirmware *self) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (FU_IS_FIRMWARE (self), NULL); + return priv->id; +} + +/** + * fu_firmware_set_addr: + * @self: a #FuPlugin + * @addr: integer + * + * Sets the base address of the image. + * + * Since: 1.6.0 + **/ +void +fu_firmware_set_addr (FuFirmware *self, guint64 addr) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_if_fail (FU_IS_FIRMWARE (self)); + priv->addr = addr; +} + +/** + * fu_firmware_get_addr: + * @self: a #FuPlugin + * + * Gets the base address of the image. + * + * Returns: integer + * + * Since: 1.6.0 + **/ +guint64 +fu_firmware_get_addr (FuFirmware *self) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (FU_IS_FIRMWARE (self), G_MAXUINT64); + return priv->addr; +} + +/** + * fu_firmware_set_offset: + * @self: a #FuPlugin + * @offset: integer + * + * Sets the base offset of the image. + * + * Since: 1.6.0 + **/ +void +fu_firmware_set_offset (FuFirmware *self, guint64 offset) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_if_fail (FU_IS_FIRMWARE (self)); + priv->offset = offset; +} + +/** + * fu_firmware_get_offset: + * @self: a #FuPlugin + * + * Gets the base offset of the image. + * + * Returns: integer + * + * Since: 1.6.0 + **/ +guint64 +fu_firmware_get_offset (FuFirmware *self) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (FU_IS_FIRMWARE (self), G_MAXUINT64); + return priv->offset; +} + +/** + * fu_firmware_set_idx: + * @self: a #FuPlugin + * @idx: integer + * + * Sets the index of the image which is used for ordering. + * + * Since: 1.6.0 + **/ +void +fu_firmware_set_idx (FuFirmware *self, guint64 idx) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_if_fail (FU_IS_FIRMWARE (self)); + priv->idx = idx; +} + +/** + * fu_firmware_get_idx: + * @self: a #FuPlugin + * + * Gets the index of the image which is used for ordering. + * + * Returns: integer + * + * Since: 1.6.0 + **/ +guint64 +fu_firmware_get_idx (FuFirmware *self) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (FU_IS_FIRMWARE (self), G_MAXUINT64); + return priv->idx; +} + +/** + * fu_firmware_set_bytes: + * @self: a #FuPlugin + * @bytes: A #GBytes + * + * Sets the contents of the image if not created with fu_firmware_new_from_bytes(). + * + * Since: 1.6.0 + **/ +void +fu_firmware_set_bytes (FuFirmware *self, GBytes *bytes) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_if_fail (FU_IS_FIRMWARE (self)); + g_return_if_fail (bytes != NULL); + g_return_if_fail (priv->bytes == NULL); + if (priv->bytes != NULL) + g_bytes_unref (priv->bytes); + priv->bytes = g_bytes_ref (bytes); +} + +/** + * fu_firmware_get_bytes: + * @self: a #FuPlugin + * @error: A #GError, or %NULL + * + * Gets the firmware payload, which does not have any header or footer included. + * + * If there is more than one potential payload or image section then fu_firmware_add_image() + * should be used instead. + * + * Returns: (transfer full): a #GBytes, or %NULL if the payload has never been set + * + * Since: 1.6.0 + **/ +GBytes * +fu_firmware_get_bytes (FuFirmware *self, GError **error) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_val_if_fail (FU_IS_FIRMWARE (self), NULL); + if (priv->bytes == NULL) { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "no payload set"); + return NULL; + } + return g_bytes_ref (priv->bytes); +} + +/** + * fu_firmware_get_chunks: + * @self: a #FuFirmware + * @error: A #GError, or %NULL + * + * Gets the optional image chunks. + * + * Return value: (transfer container) (element-type FuChunk) (nullable): chunk data, or %NULL + * + * Since: 1.6.0 + **/ +GPtrArray * +fu_firmware_get_chunks (FuFirmware *self, GError **error) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + + g_return_val_if_fail (FU_IS_FIRMWARE (self), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + /* set */ + if (priv->chunks != NULL) + return g_ptr_array_ref (priv->chunks); + + /* lets build something plausible */ + if (priv->bytes != NULL) { + g_autoptr(GPtrArray) chunks = NULL; + g_autoptr(FuChunk) chk = NULL; + chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); + chk = fu_chunk_bytes_new (priv->bytes); + fu_chunk_set_idx (chk, priv->idx); + fu_chunk_set_address (chk, priv->addr); + g_ptr_array_add (chunks, g_steal_pointer (&chk)); + return g_steal_pointer (&chunks); + } + + /* nothing to do */ + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "no bytes or chunks found in firmware"); + return NULL; +} + +/** + * fu_firmware_add_chunk: + * @self: a #FuFirmware + * @chk: a #FuChunk + * + * Adds a chunk to the image. + * + * Since: 1.6.0 + **/ +void +fu_firmware_add_chunk (FuFirmware *self, FuChunk *chk) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + g_return_if_fail (FU_IS_FIRMWARE (self)); + g_return_if_fail (FU_IS_CHUNK (chk)); + if (priv->chunks == NULL) + priv->chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); + g_ptr_array_add (priv->chunks, g_object_ref (chk)); +} + +/** + * fu_firmware_get_checksum: + * @self: a #FuPlugin + * @csum_kind: a #GChecksumType, e.g. %G_CHECKSUM_SHA256 + * @error: A #GError, or %NULL + * + * Returns a checksum of the payload data. + * + * Returns: (transfer full): a checksum string, or %NULL if the checksum is not available + * + * Since: 1.6.0 + **/ +gchar * +fu_firmware_get_checksum (FuFirmware *self, + GChecksumType csum_kind, + GError **error) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + FuFirmwareClass *klass = FU_FIRMWARE_GET_CLASS (self); + + g_return_val_if_fail (FU_IS_FIRMWARE (self), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + /* subclassed */ + if (klass->get_checksum != NULL) + return klass->get_checksum (self, csum_kind, error); + + /* internal data */ + if (priv->bytes == NULL) { + g_set_error (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "no bytes found in firmware bytes %s", + priv->id); + return NULL; + } + return g_compute_checksum_for_bytes (csum_kind, priv->bytes); +} + /** * fu_firmware_tokenize: * @self: A #FuFirmware @@ -253,7 +597,6 @@ fu_firmware_parse_full (FuFirmware *self, GError **error) { FuFirmwareClass *klass = FU_FIRMWARE_GET_CLASS (self); - g_autoptr(FuFirmwareImage) img = NULL; g_return_val_if_fail (FU_IS_FIRMWARE (self), FALSE); g_return_val_if_fail (fw != NULL, FALSE); @@ -277,8 +620,7 @@ fu_firmware_parse_full (FuFirmware *self, return klass->parse (self, fw, addr_start, addr_end, flags, error); /* just add entire blob */ - img = fu_firmware_image_new (fw); - fu_firmware_add_image (self, img); + fu_firmware_set_bytes (self, fw); return TRUE; } @@ -340,7 +682,7 @@ fu_firmware_parse (FuFirmware *self, GBytes *fw, FwupdInstallFlags flags, GError * * Additionally, extra nodes can be included under `` and `` * which can be parsed by the subclassed objects. You should verify the - * subclassed object `FuFirmwareImage->build` vfunc for the specific additional + * subclassed object `FuFirmware->build` vfunc for the specific additional * options supported. * * Plugins should manually g_type_ensure() subclassed image objects if not @@ -356,8 +698,11 @@ fu_firmware_build (FuFirmware *self, XbNode *n, GError **error) { FuFirmwareClass *klass = FU_FIRMWARE_GET_CLASS (self); const gchar *tmp; + guint64 tmpval; guint64 version_raw; + g_autoptr(GPtrArray) chunks = NULL; g_autoptr(GPtrArray) xb_images = NULL; + g_autoptr(XbNode) data = NULL; g_return_val_if_fail (FU_IS_FIRMWARE (self), FALSE); g_return_val_if_fail (XB_IS_NODE (n), FALSE); @@ -370,13 +715,60 @@ fu_firmware_build (FuFirmware *self, XbNode *n, GError **error) version_raw = xb_node_query_text_as_uint (n, "version_raw", NULL); if (version_raw != G_MAXUINT64) fu_firmware_set_version_raw (self, version_raw); + tmp = xb_node_query_text (n, "id", NULL); + if (tmp != NULL) + fu_firmware_set_id (self, tmp); + tmpval = xb_node_query_text_as_uint (n, "idx", NULL); + if (tmpval != G_MAXUINT64) + fu_firmware_set_idx (self, tmpval); + tmpval = xb_node_query_text_as_uint (n, "addr", NULL); + if (tmpval != G_MAXUINT64) + fu_firmware_set_addr (self, tmpval); + tmpval = xb_node_query_text_as_uint (n, "offset", NULL); + if (tmpval != G_MAXUINT64) + fu_firmware_set_offset (self, tmpval); + tmp = xb_node_query_text (n, "filename", NULL); + if (tmp != NULL) { + g_autoptr(GBytes) blob = NULL; + blob = fu_common_get_contents_bytes (tmp, error); + if (blob == NULL) + return FALSE; + fu_firmware_set_bytes (self, blob); + fu_firmware_set_filename (self, tmp); + } + data = xb_node_query_first (n, "data", NULL); + if (data != NULL && xb_node_get_text (data) != NULL) { + gsize bufsz = 0; + g_autofree guchar *buf = NULL; + g_autoptr(GBytes) blob = NULL; + buf = g_base64_decode (xb_node_get_text (data), &bufsz); + blob = g_bytes_new (buf, bufsz); + fu_firmware_set_bytes (self, blob); + } else if (data != NULL) { + g_autoptr(GBytes) blob = NULL; + blob = g_bytes_new (NULL, 0); + fu_firmware_set_bytes (self, blob); + } + + /* optional chunks */ + chunks = xb_node_query (n, "chunks/chunk", 0, NULL); + if (chunks != NULL) { + for (guint i = 0; i < chunks->len; i++) { + XbNode *c = g_ptr_array_index (chunks, i); + g_autoptr(FuChunk) chk = fu_chunk_bytes_new (NULL); + fu_chunk_set_idx (chk, i); + if (!fu_chunk_build (chk, c, error)) + return FALSE; + fu_firmware_add_chunk (self, chk); + } + } /* parse images */ - xb_images = xb_node_query (n, "image", 0, NULL); + xb_images = xb_node_query (n, "firmware", 0, NULL); if (xb_images != NULL) { for (guint i = 0; i < xb_images->len; i++) { XbNode *xb_image = g_ptr_array_index (xb_images, i); - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; tmp = xb_node_get_attr (xb_image, "gtype"); if (tmp != NULL) { GType gtype = g_type_from_name (tmp); @@ -389,9 +781,9 @@ fu_firmware_build (FuFirmware *self, XbNode *n, GError **error) } img = g_object_new (gtype, NULL); } else { - img = fu_firmware_image_new (NULL); + img = fu_firmware_new (); } - if (!fu_firmware_image_build (img, xb_image, error)) + if (!fu_firmware_build (img, xb_image, error)) return FALSE; fu_firmware_add_image (self, img); } @@ -452,6 +844,7 @@ GBytes * fu_firmware_write (FuFirmware *self, GError **error) { FuFirmwareClass *klass = FU_FIRMWARE_GET_CLASS (self); + FuFirmwarePrivate *priv = GET_PRIVATE (self); g_return_val_if_fail (FU_IS_FIRMWARE (self), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); @@ -460,8 +853,84 @@ fu_firmware_write (FuFirmware *self, GError **error) if (klass->write != NULL) return klass->write (self, error); + /* set */ + if (priv->bytes != NULL) + return g_bytes_ref (priv->bytes); + /* just add default blob */ - return fu_firmware_get_image_default_bytes (self, error); + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "no payload set"); + return NULL; +} + +/** + * fu_firmware_write_chunk: + * @self: a #FuFirmware + * @address: an address smaller than fu_firmware_get_addr() + * @chunk_sz_max: the size of the new chunk + * @error: a #GError, or %NULL + * + * Gets a block of data from the image. If the contents of the image is + * smaller than the requested chunk size then the #GBytes will be smaller + * than @chunk_sz_max. Use fu_common_bytes_pad() if padding is required. + * + * If the @address is larger than the size of the image then an error is returned. + * + * Return value: (transfer full): a #GBytes, or %NULL + * + * Since: 1.6.0 + **/ +GBytes * +fu_firmware_write_chunk (FuFirmware *self, + guint64 address, + guint64 chunk_sz_max, + GError **error) +{ + FuFirmwarePrivate *priv = GET_PRIVATE (self); + gsize chunk_left; + guint64 offset; + + g_return_val_if_fail (FU_IS_FIRMWARE (self), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + /* check address requested is larger than base address */ + if (address < priv->addr) { + g_set_error (error, + FWUPD_ERROR, + FWUPD_ERROR_INTERNAL, + "requested address 0x%x less than base address 0x%x", + (guint) address, (guint) priv->addr); + return NULL; + } + + /* offset into data */ + offset = address - priv->addr; + if (offset > g_bytes_get_size (priv->bytes)) { + g_set_error (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "offset 0x%x larger than data size 0x%x", + (guint) offset, + (guint) g_bytes_get_size (priv->bytes)); + return NULL; + } + + /* if we have less data than requested */ + chunk_left = g_bytes_get_size (priv->bytes) - offset; + if (chunk_sz_max > chunk_left) { + return fu_common_bytes_new_offset (priv->bytes, + offset, + chunk_left, + error); + } + + /* check chunk */ + return fu_common_bytes_new_offset (priv->bytes, + offset, + chunk_sz_max, + error); } /** @@ -499,7 +968,7 @@ fu_firmware_write_file (FuFirmware *self, GFile *file, GError **error) /** * fu_firmware_add_image: * @self: a #FuPlugin - * @img: A #FuFirmwareImage + * @img: A #FuFirmware * * Adds an image to the firmware. * @@ -509,25 +978,25 @@ fu_firmware_write_file (FuFirmware *self, GFile *file, GError **error) * Since: 1.3.1 **/ void -fu_firmware_add_image (FuFirmware *self, FuFirmwareImage *img) +fu_firmware_add_image (FuFirmware *self, FuFirmware *img) { FuFirmwarePrivate *priv = GET_PRIVATE (self); g_return_if_fail (FU_IS_FIRMWARE (self)); - g_return_if_fail (FU_IS_FIRMWARE_IMAGE (img)); + g_return_if_fail (FU_IS_FIRMWARE (img)); /* dedupe */ for (guint i = 0; i < priv->images->len; i++) { - FuFirmwareImage *img_tmp = g_ptr_array_index (priv->images, i); + FuFirmware *img_tmp = g_ptr_array_index (priv->images, i); if (priv->flags & FU_FIRMWARE_FLAG_DEDUPE_ID) { - if (g_strcmp0 (fu_firmware_image_get_id (img_tmp), - fu_firmware_image_get_id (img)) == 0) { + if (g_strcmp0 (fu_firmware_get_id (img_tmp), + fu_firmware_get_id (img)) == 0) { g_ptr_array_remove_index (priv->images, i); break; } } if (priv->flags & FU_FIRMWARE_FLAG_DEDUPE_IDX) { - if (fu_firmware_image_get_idx (img_tmp) == - fu_firmware_image_get_idx (img)) { + if (fu_firmware_get_idx (img_tmp) == + fu_firmware_get_idx (img)) { g_ptr_array_remove_index (priv->images, i); break; } @@ -540,7 +1009,7 @@ fu_firmware_add_image (FuFirmware *self, FuFirmwareImage *img) /** * fu_firmware_remove_image: * @self: a #FuPlugin - * @img: A #FuFirmwareImage + * @img: A #FuFirmware * @error: A #GError, or %NULL * * Remove an image from the firmware. @@ -550,12 +1019,12 @@ fu_firmware_add_image (FuFirmware *self, FuFirmwareImage *img) * Since: 1.5.0 **/ gboolean -fu_firmware_remove_image (FuFirmware *self, FuFirmwareImage *img, GError **error) +fu_firmware_remove_image (FuFirmware *self, FuFirmware *img, GError **error) { FuFirmwarePrivate *priv = GET_PRIVATE (self); g_return_val_if_fail (FU_IS_FIRMWARE (self), FALSE); - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (img), FALSE); + g_return_val_if_fail (FU_IS_FIRMWARE (img), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (g_ptr_array_remove (priv->images, img)) @@ -566,7 +1035,7 @@ fu_firmware_remove_image (FuFirmware *self, FuFirmwareImage *img, GError **error FWUPD_ERROR, FWUPD_ERROR_NOT_FOUND, "image %s not found in firmware", - fu_firmware_image_get_id (img)); + fu_firmware_get_id (img)); return FALSE; } @@ -586,7 +1055,7 @@ gboolean fu_firmware_remove_image_by_idx (FuFirmware *self, guint64 idx, GError **error) { FuFirmwarePrivate *priv = GET_PRIVATE (self); - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_return_val_if_fail (FU_IS_FIRMWARE (self), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -614,7 +1083,7 @@ gboolean fu_firmware_remove_image_by_id (FuFirmware *self, const gchar *id, GError **error) { FuFirmwarePrivate *priv = GET_PRIVATE (self); - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_return_val_if_fail (FU_IS_FIRMWARE (self), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -632,7 +1101,7 @@ fu_firmware_remove_image_by_id (FuFirmware *self, const gchar *id, GError **erro * * Returns all the images in the firmware. * - * Returns: (transfer container) (element-type FuFirmwareImage): images + * Returns: (transfer container) (element-type FuFirmware): images * * Since: 1.3.1 **/ @@ -646,7 +1115,7 @@ fu_firmware_get_images (FuFirmware *self) imgs = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); for (guint i = 0; i < priv->images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (priv->images, i); + FuFirmware *img = g_ptr_array_index (priv->images, i); g_ptr_array_add (imgs, g_object_ref (img)); } return g_steal_pointer (&imgs); @@ -660,11 +1129,11 @@ fu_firmware_get_images (FuFirmware *self) * * Gets the firmware image using the image ID. * - * Returns: (transfer full): a #FuFirmwareImage, or %NULL if the image is not found + * Returns: (transfer full): a #FuFirmware, or %NULL if the image is not found * * Since: 1.3.1 **/ -FuFirmwareImage * +FuFirmware * fu_firmware_get_image_by_id (FuFirmware *self, const gchar *id, GError **error) { FuFirmwarePrivate *priv = GET_PRIVATE (self); @@ -673,8 +1142,8 @@ fu_firmware_get_image_by_id (FuFirmware *self, const gchar *id, GError **error) g_return_val_if_fail (error == NULL || *error == NULL, NULL); for (guint i = 0; i < priv->images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (priv->images, i); - if (g_strcmp0 (fu_firmware_image_get_id (img), id) == 0) + FuFirmware *img = g_ptr_array_index (priv->images, i); + if (g_strcmp0 (fu_firmware_get_id (img), id) == 0) return g_object_ref (img); } g_set_error (error, @@ -692,17 +1161,17 @@ fu_firmware_get_image_by_id (FuFirmware *self, const gchar *id, GError **error) * * Gets the firmware image bytes using the image ID. * - * Returns: (transfer full): a #GBytes of a #FuFirmwareImage, or %NULL if the image is not found + * Returns: (transfer full): a #GBytes of a #FuFirmware, or %NULL if the image is not found * * Since: 1.3.1 **/ GBytes * fu_firmware_get_image_by_id_bytes (FuFirmware *self, const gchar *id, GError **error) { - g_autoptr(FuFirmwareImage) img = fu_firmware_get_image_by_id (self, id, error); + g_autoptr(FuFirmware) img = fu_firmware_get_image_by_id (self, id, error); if (img == NULL) return NULL; - return fu_firmware_image_write (img, error); + return fu_firmware_write (img, error); } /** @@ -713,11 +1182,11 @@ fu_firmware_get_image_by_id_bytes (FuFirmware *self, const gchar *id, GError **e * * Gets the firmware image using the image index. * - * Returns: (transfer full): a #FuFirmwareImage, or %NULL if the image is not found + * Returns: (transfer full): a #FuFirmware, or %NULL if the image is not found * * Since: 1.3.1 **/ -FuFirmwareImage * +FuFirmware * fu_firmware_get_image_by_idx (FuFirmware *self, guint64 idx, GError **error) { FuFirmwarePrivate *priv = GET_PRIVATE (self); @@ -726,8 +1195,8 @@ fu_firmware_get_image_by_idx (FuFirmware *self, guint64 idx, GError **error) g_return_val_if_fail (error == NULL || *error == NULL, NULL); for (guint i = 0; i < priv->images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (priv->images, i); - if (fu_firmware_image_get_idx (img) == idx) + FuFirmware *img = g_ptr_array_index (priv->images, i); + if (fu_firmware_get_idx (img) == idx) return g_object_ref (img); } g_set_error (error, @@ -746,11 +1215,11 @@ fu_firmware_get_image_by_idx (FuFirmware *self, guint64 idx, GError **error) * Gets the firmware image using the image checksum. The checksum type is guessed * based on the length of the input string. * - * Returns: (transfer full): a #FuFirmwareImage, or %NULL if the image is not found + * Returns: (transfer full): a #FuFirmware, or %NULL if the image is not found * * Since: 1.5.5 **/ -FuFirmwareImage * +FuFirmware * fu_firmware_get_image_by_checksum (FuFirmware *self, const gchar *checksum, GError **error) @@ -764,12 +1233,12 @@ fu_firmware_get_image_by_checksum (FuFirmware *self, csum_kind = fwupd_checksum_guess_kind (checksum); for (guint i = 0; i < priv->images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (priv->images, i); + FuFirmware *img = g_ptr_array_index (priv->images, i); g_autofree gchar *checksum_tmp = NULL; - /* if this expensive then the subclassed FuFirmwareImage can + /* if this expensive then the subclassed FuFirmware can * cache the result as required */ - checksum_tmp = fu_firmware_image_get_checksum (img, csum_kind, error); + checksum_tmp = fu_firmware_get_checksum (img, csum_kind, error); if (checksum_tmp == NULL) return NULL; if (g_strcmp0 (checksum_tmp, checksum) == 0) @@ -790,72 +1259,76 @@ fu_firmware_get_image_by_checksum (FuFirmware *self, * * Gets the firmware image bytes using the image index. * - * Returns: (transfer full): a #GBytes of a #FuFirmwareImage, or %NULL if the image is not found + * Returns: (transfer full): a #GBytes of a #FuFirmware, or %NULL if the image is not found * * Since: 1.3.1 **/ GBytes * fu_firmware_get_image_by_idx_bytes (FuFirmware *self, guint64 idx, GError **error) { - g_autoptr(FuFirmwareImage) img = fu_firmware_get_image_by_idx (self, idx, error); + g_autoptr(FuFirmware) img = fu_firmware_get_image_by_idx (self, idx, error); if (img == NULL) return NULL; - return fu_firmware_image_write (img, error); + return fu_firmware_write (img, error); } -/** - * fu_firmware_get_image_default: - * @self: a #FuPlugin - * @error: A #GError, or %NULL - * - * Gets the default firmware image. - * - * NOTE: If the firmware has multiple images included then fu_firmware_get_image_by_id() - * or fu_firmware_get_image_by_idx() must be used rather than this function. - * - * Returns: (transfer full): a #FuFirmwareImage, or %NULL if the image is not found - * - * Since: 1.3.1 - **/ -FuFirmwareImage * -fu_firmware_get_image_default (FuFirmware *self, GError **error) +static void +fu_firmware_add_string (FuFirmware *self, guint idt, GString *str) { + FuFirmwareClass *klass = FU_FIRMWARE_GET_CLASS (self); FuFirmwarePrivate *priv = GET_PRIVATE (self); - if (priv->images->len == 0) { - g_set_error_literal (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_FOUND, - "no images in firmware"); - return NULL; - } - if (priv->images->len > 1) { - g_set_error_literal (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_FOUND, - "multiple images present in firmware"); - return NULL; - } - return g_object_ref (FU_FIRMWARE_IMAGE (g_ptr_array_index (priv->images, 0))); -} -/** - * fu_firmware_get_image_default_bytes: - * @self: a #FuPlugin - * @error: A #GError, or %NULL - * - * Gets the default firmware image. - * - * Returns: (transfer full): a #GBytes of the image, or %NULL if the image is not found - * - * Since: 1.3.1 - **/ -GBytes * -fu_firmware_get_image_default_bytes (FuFirmware *self, GError **error) -{ - g_autoptr(FuFirmwareImage) img = fu_firmware_get_image_default (self, error); - if (img == NULL) - return NULL; - return fu_firmware_image_write (img, error); + /* subclassed type */ + fu_common_string_append_kv (str, idt, G_OBJECT_TYPE_NAME (self), NULL); + if (priv->flags != FU_FIRMWARE_FLAG_NONE) { + g_autoptr(GString) tmp = g_string_new (""); + for (guint i = 0; i < 64; i++) { + if ((priv->flags & ((guint64) 1 << i)) == 0) + continue; + g_string_append_printf (tmp, "%s|", + fu_firmware_flag_to_string ((guint64) 1 << i)); + } + if (tmp->len > 0) + g_string_truncate (tmp, tmp->len - 1); + fu_common_string_append_kv (str, idt, "Flags", tmp->str); + } + if (priv->id != NULL) + fu_common_string_append_kv (str, idt, "ID", priv->id); + if (priv->idx != 0x0) + fu_common_string_append_kx (str, idt, "Index", priv->idx); + if (priv->version != NULL) + fu_common_string_append_kv (str, idt, "Version", priv->version); + if (priv->version_raw != 0x0) + fu_common_string_append_kx (str, idt, "VersionRaw", priv->version_raw); + if (priv->addr != 0x0) + fu_common_string_append_kx (str, idt, "Address", priv->addr); + if (priv->offset != 0x0) + fu_common_string_append_kx (str, idt, "Offset", priv->offset); + if (priv->version != NULL) + fu_common_string_append_kv (str, idt, "Version", priv->version); + if (priv->filename != NULL) + fu_common_string_append_kv (str, idt, "Filename", priv->filename); + if (priv->bytes != NULL) { + fu_common_string_append_kx (str, idt, "Data", + g_bytes_get_size (priv->bytes)); + } + + /* add chunks */ + if (priv->chunks != NULL) { + for (guint i = 0; i < priv->chunks->len; i++) { + FuChunk *chk = g_ptr_array_index (priv->chunks, i); + fu_chunk_add_string (chk, 1, str); + } + } + + /* vfunc */ + if (klass->to_string != NULL) + klass->to_string (self, idt, str); + + for (guint i = 0; i < priv->images->len; i++) { + FuFirmware *img = g_ptr_array_index (priv->images, i); + fu_firmware_add_string (img, idt + 1, str); + } } /** @@ -871,38 +1344,8 @@ fu_firmware_get_image_default_bytes (FuFirmware *self, GError **error) gchar * fu_firmware_to_string (FuFirmware *self) { - FuFirmwareClass *klass = FU_FIRMWARE_GET_CLASS (self); - FuFirmwarePrivate *priv = GET_PRIVATE (self); GString *str = g_string_new (NULL); - - /* subclassed type */ - fu_common_string_append_kv (str, 0, G_OBJECT_TYPE_NAME (self), NULL); - if (priv->flags != FU_FIRMWARE_FLAG_NONE) { - g_autoptr(GString) tmp = g_string_new (""); - for (guint i = 0; i < 64; i++) { - if ((priv->flags & ((guint64) 1 << i)) == 0) - continue; - g_string_append_printf (tmp, "%s|", - fu_firmware_flag_to_string ((guint64) 1 << i)); - } - if (tmp->len > 0) - g_string_truncate (tmp, tmp->len - 1); - fu_common_string_append_kv (str, 0, "Flags", tmp->str); - } - if (priv->version != NULL) - fu_common_string_append_kv (str, 0, "Version", priv->version); - if (priv->version_raw != 0x0) - fu_common_string_append_kx (str, 0, "VersionRaw", priv->version_raw); - - /* vfunc */ - if (klass->to_string != NULL) - klass->to_string (self, 0, str); - - for (guint i = 0; i < priv->images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (priv->images, i); - fu_firmware_image_add_string (img, 1, str); - } - + fu_firmware_add_string (self, 0, str); return g_string_free (str, FALSE); } @@ -919,6 +1362,12 @@ fu_firmware_finalize (GObject *object) FuFirmware *self = FU_FIRMWARE (object); FuFirmwarePrivate *priv = GET_PRIVATE (self); g_free (priv->version); + g_free (priv->id); + g_free (priv->filename); + if (priv->bytes != NULL) + g_bytes_unref (priv->bytes); + if (priv->chunks != NULL) + g_ptr_array_unref (priv->chunks); g_ptr_array_unref (priv->images); G_OBJECT_CLASS (fu_firmware_parent_class)->finalize (object); } @@ -960,9 +1409,7 @@ FuFirmware * fu_firmware_new_from_bytes (GBytes *fw) { FuFirmware *self = fu_firmware_new (); - g_autoptr(FuFirmwareImage) img = NULL; - img = fu_firmware_image_new (fw); - fu_firmware_add_image (self, img); + fu_firmware_set_bytes (self, fw); return self; } diff --git a/libfwupdplugin/fu-firmware.h b/libfwupdplugin/fu-firmware.h index 4bf02c4ba..a1e31978d 100644 --- a/libfwupdplugin/fu-firmware.h +++ b/libfwupdplugin/fu-firmware.h @@ -8,8 +8,10 @@ #include #include +#include -#include "fu-firmware-image.h" +#include "fu-chunk.h" +#include "fu-firmware.h" #define FU_TYPE_FIRMWARE (fu_firmware_get_type ()) G_DECLARE_DERIVABLE_TYPE (FuFirmware, fu_firmware, FU, FIRMWARE, GObject) @@ -39,8 +41,12 @@ struct _FuFirmwareClass XbNode *n, GError **error) G_GNUC_WARN_UNUSED_RESULT; + gchar *(*get_checksum) (FuFirmware *self, + GChecksumType csum_kind, + GError **error) + G_GNUC_WARN_UNUSED_RESULT; /*< private >*/ - gpointer padding[27]; + gpointer padding[26]; }; /** @@ -60,6 +66,10 @@ struct _FuFirmwareClass #define FU_FIRMWARE_FLAG_HAS_VID_PID (1u << 3) /* Since: 1.5.6 */ typedef guint64 FuFirmwareFlags; +#define FU_FIRMWARE_ID_PAYLOAD "payload" +#define FU_FIRMWARE_ID_SIGNATURE "signature" +#define FU_FIRMWARE_ID_HEADER "header" + const gchar *fu_firmware_flag_to_string (FuFirmwareFlags flag); FuFirmwareFlags fu_firmware_flag_from_string (const gchar *flag); @@ -80,6 +90,29 @@ void fu_firmware_add_flag (FuFirmware *firmware, FuFirmwareFlags flag); gboolean fu_firmware_has_flag (FuFirmware *firmware, FuFirmwareFlags flag); +const gchar *fu_firmware_get_filename (FuFirmware *self); +void fu_firmware_set_filename (FuFirmware *self, + const gchar *filename); +const gchar *fu_firmware_get_id (FuFirmware *self); +void fu_firmware_set_id (FuFirmware *self, + const gchar *id); +guint64 fu_firmware_get_addr (FuFirmware *self); +void fu_firmware_set_addr (FuFirmware *self, + guint64 addr); +guint64 fu_firmware_get_offset (FuFirmware *self); +void fu_firmware_set_offset (FuFirmware *self, + guint64 offset); +guint64 fu_firmware_get_idx (FuFirmware *self); +void fu_firmware_set_idx (FuFirmware *self, + guint64 idx); +GBytes *fu_firmware_get_bytes (FuFirmware *self, + GError **error); +void fu_firmware_set_bytes (FuFirmware *self, + GBytes *bytes); +void fu_firmware_add_chunk (FuFirmware *self, + FuChunk *chk); +GPtrArray *fu_firmware_get_chunks (FuFirmware *self, + GError **error); gboolean fu_firmware_tokenize (FuFirmware *self, GBytes *fw, @@ -110,15 +143,23 @@ gboolean fu_firmware_parse_full (FuFirmware *self, GBytes *fu_firmware_write (FuFirmware *self, GError **error) G_GNUC_WARN_UNUSED_RESULT; +GBytes *fu_firmware_write_chunk (FuFirmware *self, + guint64 address, + guint64 chunk_sz_max, + GError **error) + G_GNUC_WARN_UNUSED_RESULT; gboolean fu_firmware_write_file (FuFirmware *self, GFile *file, GError **error) G_GNUC_WARN_UNUSED_RESULT; +gchar *fu_firmware_get_checksum (FuFirmware *self, + GChecksumType csum_kind, + GError **error); void fu_firmware_add_image (FuFirmware *self, - FuFirmwareImage *img); + FuFirmware *img); gboolean fu_firmware_remove_image (FuFirmware *self, - FuFirmwareImage *img, + FuFirmware *img, GError **error); gboolean fu_firmware_remove_image_by_idx (FuFirmware *self, guint64 idx, @@ -127,22 +168,18 @@ gboolean fu_firmware_remove_image_by_id (FuFirmware *self, const gchar *id, GError **error); GPtrArray *fu_firmware_get_images (FuFirmware *self); -FuFirmwareImage *fu_firmware_get_image_by_id (FuFirmware *self, +FuFirmware *fu_firmware_get_image_by_id (FuFirmware *self, const gchar *id, GError **error); GBytes *fu_firmware_get_image_by_id_bytes (FuFirmware *self, const gchar *id, GError **error); -FuFirmwareImage *fu_firmware_get_image_by_idx (FuFirmware *self, +FuFirmware *fu_firmware_get_image_by_idx (FuFirmware *self, guint64 idx, GError **error); GBytes *fu_firmware_get_image_by_idx_bytes (FuFirmware *self, guint64 idx, GError **error); -FuFirmwareImage *fu_firmware_get_image_by_checksum (FuFirmware *self, +FuFirmware *fu_firmware_get_image_by_checksum (FuFirmware *self, const gchar *checksum, GError **error); -FuFirmwareImage *fu_firmware_get_image_default (FuFirmware *self, - GError **error); -GBytes *fu_firmware_get_image_default_bytes (FuFirmware *self, - GError **error); diff --git a/libfwupdplugin/fu-fmap-firmware.c b/libfwupdplugin/fu-fmap-firmware.c index 65257a55e..4f4da4316 100644 --- a/libfwupdplugin/fu-fmap-firmware.c +++ b/libfwupdplugin/fu-fmap-firmware.c @@ -122,7 +122,7 @@ fu_fmap_firmware_parse (FuFirmware *firmware, for (gsize i = 0; i < GUINT16_FROM_LE (fmap.nareas); i++) { FuFmapArea area; - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(GBytes) bytes = NULL; g_autofree gchar *area_name = NULL; @@ -136,7 +136,6 @@ fu_fmap_firmware_parse (FuFirmware *firmware, if (area.size == 0) continue; - img = fu_firmware_image_new (NULL); bytes = fu_common_bytes_new_offset (fw, (gsize) GUINT32_FROM_LE (area.offset), (gsize) GUINT32_FROM_LE (area.size), @@ -144,10 +143,10 @@ fu_fmap_firmware_parse (FuFirmware *firmware, if (bytes == NULL) return FALSE; area_name = g_strndup ((const gchar *) area.name, FU_FMAP_FIRMWARE_STRLEN); - fu_firmware_image_set_id (img, area_name); - fu_firmware_image_set_idx (img, i + 1); - fu_firmware_image_set_addr (img, GUINT32_FROM_LE (area.offset)); - fu_firmware_image_set_bytes (img, bytes); + img = fu_firmware_new_from_bytes (bytes); + fu_firmware_set_id (img, area_name); + fu_firmware_set_idx (img, i + 1); + fu_firmware_set_addr (img, GUINT32_FROM_LE (area.offset)); fu_firmware_add_image (firmware, img); if (g_strcmp0 (area_name, FMAP_AREANAME) == 0) { @@ -155,7 +154,7 @@ fu_fmap_firmware_parse (FuFirmware *firmware, version = g_strdup_printf ("%d.%d", fmap.ver_major, fmap.ver_minor); - fu_firmware_image_set_version (img, version); + fu_firmware_set_version (img, version); } offset += sizeof(area); } @@ -196,8 +195,10 @@ fu_fmap_firmware_write (FuFirmware *firmware, GError **error) /* add header */ total_sz = offset = sizeof(hdr) + (sizeof(FuFmapArea) * images->len); for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); - g_autoptr(GBytes) fw = fu_firmware_image_get_bytes (img); + FuFirmware *img = g_ptr_array_index (images, i); + g_autoptr(GBytes) fw = fu_firmware_get_bytes (img, error); + if (fw == NULL) + return NULL; total_sz += g_bytes_get_size (fw); } hdr.size = GUINT32_TO_LE (priv->offset + total_sz); @@ -205,9 +206,9 @@ fu_fmap_firmware_write (FuFirmware *firmware, GError **error) /* add each area */ for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); - const gchar *id = fu_firmware_image_get_id (img); - g_autoptr(GBytes) fw = fu_firmware_image_get_bytes (img); + FuFirmware *img = g_ptr_array_index (images, i); + const gchar *id = fu_firmware_get_id (img); + g_autoptr(GBytes) fw = fu_firmware_get_bytes (img, NULL); FuFmapArea area = { .offset = GUINT32_TO_LE (priv->offset + offset), .size = GUINT32_TO_LE (g_bytes_get_size (fw)), @@ -222,8 +223,8 @@ fu_fmap_firmware_write (FuFirmware *firmware, GError **error) /* add the images */ for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); - g_autoptr(GBytes) fw = fu_firmware_image_get_bytes (img); + FuFirmware *img = g_ptr_array_index (images, i); + g_autoptr(GBytes) fw = fu_firmware_get_bytes (img, NULL); g_byte_array_append (buf, g_bytes_get_data (fw, NULL), g_bytes_get_size (fw)); diff --git a/libfwupdplugin/fu-ifd-firmware.c b/libfwupdplugin/fu-ifd-firmware.c index 81875b24e..016d3baaa 100644 --- a/libfwupdplugin/fu-ifd-firmware.c +++ b/libfwupdplugin/fu-ifd-firmware.c @@ -209,7 +209,7 @@ fu_ifd_firmware_parse (FuFirmware *firmware, guint32 freg_base = FU_IFD_FREG_BASE(priv->flash_descriptor_regs[i]); guint32 freg_limt = FU_IFD_FREG_LIMIT(priv->flash_descriptor_regs[i]); guint32 freg_size = freg_limt - freg_base; - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(GBytes) contents = NULL; guint8 bit_r = 0; guint8 bit_w = 0; @@ -224,11 +224,11 @@ fu_ifd_firmware_parse (FuFirmware *firmware, if (contents == NULL) return FALSE; img = fu_ifd_image_new (); - fu_firmware_image_set_bytes (img, contents); - fu_firmware_image_set_addr (img, freg_base); - fu_firmware_image_set_idx (img, i); + fu_firmware_set_bytes (img, contents); + fu_firmware_set_addr (img, freg_base); + fu_firmware_set_idx (img, i); if (freg_str != NULL) - fu_firmware_image_set_id (img, freg_str); + fu_firmware_set_id (img, freg_str); fu_firmware_add_image (firmware, img); /* is writable by anything other than the region itself */ @@ -303,9 +303,12 @@ fu_ifd_firmware_write (FuFirmware *firmware, GError **error) /* get total size */ for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); - g_autoptr(GBytes) blob = fu_firmware_image_get_bytes (img); - guint32 freg_base = fu_firmware_image_get_addr (img); + FuFirmware *img = g_ptr_array_index (images, i); + g_autoptr(GBytes) blob = NULL; + guint32 freg_base = fu_firmware_get_addr (img); + blob = fu_firmware_get_bytes (img, error); + if (blob == NULL) + return NULL; bufsz_max = MAX(freg_base + MAX(g_bytes_get_size (blob), 0x1000), bufsz_max); } fu_byte_array_set_size (buf, bufsz_max); @@ -345,10 +348,12 @@ fu_ifd_firmware_write (FuFirmware *firmware, GError **error) guint32 freg_base = 0x7FFF000; guint32 freg_limt = 0x0; guint32 flreg; - g_autoptr(FuFirmwareImage) img = fu_firmware_get_image_by_idx (firmware, i, NULL); + g_autoptr(FuFirmware) img = fu_firmware_get_image_by_idx (firmware, i, NULL); if (img != NULL) { - g_autoptr(GBytes) blob = fu_firmware_image_get_bytes (img); - freg_base = fu_firmware_image_get_addr (img); + g_autoptr(GBytes) blob = fu_firmware_get_bytes (img, error); + if (blob == NULL) + return NULL; + freg_base = fu_firmware_get_addr (img); freg_limt = freg_base + g_bytes_get_size (blob); } flreg = ((freg_limt << 4) & 0xFFFF0000) | (freg_base >> 12); @@ -361,10 +366,11 @@ fu_ifd_firmware_write (FuFirmware *firmware, GError **error) /* write images at correct offsets */ for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); - g_autoptr(GBytes) blob = fu_firmware_image_get_bytes (img); - g_assert (blob != NULL); - if (!fu_memcpy_safe (buf->data, buf->len, fu_firmware_image_get_addr (img), + FuFirmware *img = g_ptr_array_index (images, i); + g_autoptr(GBytes) blob = fu_firmware_get_bytes (img, error); + if (blob == NULL) + return NULL; + if (!fu_memcpy_safe (buf->data, buf->len, fu_firmware_get_addr (img), g_bytes_get_data (blob, NULL), g_bytes_get_size (blob), 0x0, g_bytes_get_size (blob), error)) return NULL; diff --git a/libfwupdplugin/fu-ifd-image.c b/libfwupdplugin/fu-ifd-image.c index 712a6c02b..ef2cdf68e 100644 --- a/libfwupdplugin/fu-ifd-image.c +++ b/libfwupdplugin/fu-ifd-image.c @@ -14,11 +14,11 @@ typedef struct { FuIfdAccess access[FU_IFD_REGION_MAX]; } FuIfdImagePrivate; -G_DEFINE_TYPE_WITH_PRIVATE (FuIfdImage, fu_ifd_image, FU_TYPE_FIRMWARE_IMAGE) +G_DEFINE_TYPE_WITH_PRIVATE (FuIfdImage, fu_ifd_image, FU_TYPE_FIRMWARE) #define GET_PRIVATE(o) (fu_ifd_image_get_instance_private (o)) static void -fu_ifd_image_to_string (FuFirmwareImage *image, guint idt, GString *str) +fu_ifd_image_to_string (FuFirmware *image, guint idt, GString *str) { FuIfdImage *self = FU_IFD_IMAGE (image); FuIfdImagePrivate *priv = GET_PRIVATE (self); @@ -75,19 +75,19 @@ fu_ifd_image_init (FuIfdImage *self) static void fu_ifd_image_class_init (FuIfdImageClass *klass) { - FuFirmwareImageClass *klass_image = FU_FIRMWARE_IMAGE_CLASS (klass); + FuFirmwareClass *klass_image = FU_FIRMWARE_CLASS (klass); klass_image->to_string = fu_ifd_image_to_string; } /** * fu_ifd_image_new: * - * Creates a new #FuFirmwareImage + * Creates a new #FuFirmware * * Since: 1.6.0 **/ -FuFirmwareImage * +FuFirmware * fu_ifd_image_new (void) { - return FU_FIRMWARE_IMAGE (g_object_new (FU_TYPE_IFD_IMAGE, NULL)); + return FU_FIRMWARE (g_object_new (FU_TYPE_IFD_IMAGE, NULL)); } diff --git a/libfwupdplugin/fu-ifd-image.h b/libfwupdplugin/fu-ifd-image.h index e1d68b734..debe6fa26 100644 --- a/libfwupdplugin/fu-ifd-image.h +++ b/libfwupdplugin/fu-ifd-image.h @@ -6,18 +6,18 @@ #pragma once -#include "fu-firmware-image.h" +#include "fu-firmware.h" #include "fu-ifd-common.h" #define FU_TYPE_IFD_IMAGE (fu_ifd_image_get_type ()) -G_DECLARE_DERIVABLE_TYPE (FuIfdImage, fu_ifd_image, FU, IFD_IMAGE, FuFirmwareImage) +G_DECLARE_DERIVABLE_TYPE (FuIfdImage, fu_ifd_image, FU, IFD_IMAGE, FuFirmware) struct _FuIfdImageClass { - FuFirmwareImageClass parent_class; + FuFirmwareClass parent_class; }; -FuFirmwareImage *fu_ifd_image_new (void); +FuFirmware *fu_ifd_image_new (void); void fu_ifd_image_set_access (FuIfdImage *self, FuIfdRegion region, FuIfdAccess access); diff --git a/libfwupdplugin/fu-ihex-firmware.c b/libfwupdplugin/fu-ihex-firmware.c index 9e4e7d2f0..72200a16d 100644 --- a/libfwupdplugin/fu-ihex-firmware.c +++ b/libfwupdplugin/fu-ihex-firmware.c @@ -201,7 +201,6 @@ fu_ihex_firmware_parse (FuFirmware *firmware, guint32 addr_last = 0x0; guint32 img_addr = G_MAXUINT32; guint32 seg_addr = 0x0; - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (NULL); g_autoptr(GBytes) img_bytes = NULL; g_autoptr(GByteArray) buf = g_byte_array_new (); @@ -320,8 +319,8 @@ fu_ihex_firmware_parse (FuFirmware *firmware, } if (rcd->data->len > 0) { g_autoptr(GBytes) data_sig = g_bytes_new (rcd->data->data, rcd->data->len); - g_autoptr(FuFirmwareImage) img_sig = fu_firmware_image_new (data_sig); - fu_firmware_image_set_id (img_sig, FU_FIRMWARE_IMAGE_ID_SIGNATURE); + g_autoptr(FuFirmware) img_sig = fu_firmware_new_from_bytes (data_sig); + fu_firmware_set_id (img_sig, FU_FIRMWARE_ID_SIGNATURE); fu_firmware_add_image (firmware, img_sig); } got_sig = TRUE; @@ -350,10 +349,9 @@ fu_ihex_firmware_parse (FuFirmware *firmware, /* add single image */ img_bytes = g_bytes_new (buf->data, buf->len); - fu_firmware_image_set_bytes (img, img_bytes); if (img_addr != G_MAXUINT32) - fu_firmware_image_set_addr (img, img_addr); - fu_firmware_add_image (firmware, img); + fu_firmware_set_addr (firmware, img_addr); + fu_firmware_set_bytes (firmware, img_bytes); return TRUE; } @@ -381,29 +379,18 @@ fu_ihex_firmware_emit_chunk (GString *str, } static gboolean -fu_ihex_firmware_image_to_string (FuFirmwareImage *img, GString *str, GError **error) +fu_ihex_firmware_image_to_string (GBytes *bytes, guint32 addr, guint8 record_type, + GString *str, GError **error) { const guint8 *data; const guint chunk_size = 16; gsize len; guint32 address_offset_last = 0x0; - guint8 record_type = FU_IHEX_FIRMWARE_RECORD_TYPE_DATA; - g_autoptr(GBytes) bytes = NULL; - - /* get data */ - bytes = fu_firmware_image_write (img, error); - if (bytes == NULL) - return FALSE; - - /* special case */ - if (g_strcmp0 (fu_firmware_image_get_id (img), - FU_FIRMWARE_IMAGE_ID_SIGNATURE) == 0) - record_type = FU_IHEX_FIRMWARE_RECORD_TYPE_SIGNATURE; /* get number of chunks */ data = g_bytes_get_data (bytes, &len); for (gsize i = 0; i < len; i += chunk_size) { - guint32 address_tmp = fu_firmware_image_get_addr (img) + i; + guint32 address_tmp = addr + i; guint32 address_offset = (address_tmp >> 16) & 0xffff; gsize chunk_len = MIN (len - i, 16); @@ -426,15 +413,29 @@ fu_ihex_firmware_image_to_string (FuFirmwareImage *img, GString *str, GError **e static GBytes * fu_ihex_firmware_write (FuFirmware *firmware, GError **error) { - g_autoptr(GPtrArray) imgs = NULL; - g_autoptr(GString) str = NULL; + g_autoptr(GBytes) fw = NULL; + g_autoptr(FuFirmware) img_sig = NULL; + g_autoptr(GString) str = g_string_new (""); - /* write all the element data */ - str = g_string_new (""); - imgs = fu_firmware_get_images (firmware); - for (guint i = 0; i < imgs->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (imgs, i); - if (!fu_ihex_firmware_image_to_string (img, str, error)) + /* payload */ + fw = fu_firmware_get_bytes (firmware, error); + if (fw == NULL) + return NULL; + if (!fu_ihex_firmware_image_to_string (fw, + fu_firmware_get_addr (firmware), + FU_IHEX_FIRMWARE_RECORD_TYPE_DATA, + str, error)) + return NULL; + + /* signature */ + img_sig = fu_firmware_get_image_by_id (firmware, FU_FIRMWARE_ID_SIGNATURE, NULL); + if (img_sig != NULL) { + g_autoptr(GBytes) img_fw = fu_firmware_get_bytes (img_sig, error); + if (img_fw == NULL) + return NULL; + if (!fu_ihex_firmware_image_to_string (img_fw, 0, + FU_IHEX_FIRMWARE_RECORD_TYPE_SIGNATURE, + str, error)) return NULL; } diff --git a/libfwupdplugin/fu-self-test.c b/libfwupdplugin/fu-self-test.c index 677eb88f4..3ffb26153 100644 --- a/libfwupdplugin/fu-self-test.c +++ b/libfwupdplugin/fu-self-test.c @@ -1650,7 +1650,7 @@ fu_firmware_ihex_func (void) ret = fu_firmware_parse (firmware, data_file, FWUPD_INSTALL_FLAG_NONE, &error); g_assert_no_error (error); g_assert (ret); - data_fw = fu_firmware_get_image_default_bytes (firmware, &error); + data_fw = fu_firmware_get_bytes (firmware, &error); g_assert_no_error (error); g_assert_nonnull (data_fw); g_assert_cmpint (g_bytes_get_size (data_fw), ==, 136); @@ -1705,14 +1705,14 @@ fu_firmware_ihex_signed_func (void) ret = fu_firmware_parse (firmware, data_file, FWUPD_INSTALL_FLAG_NONE, &error); g_assert_no_error (error); g_assert (ret); - data_fw = fu_firmware_get_image_by_id_bytes (firmware, NULL, &error); + data_fw = fu_firmware_get_bytes (firmware, &error); g_assert_no_error (error); g_assert_nonnull (data_fw); g_assert_cmpint (g_bytes_get_size (data_fw), ==, 136); /* get the signed image */ data_sig = fu_firmware_get_image_by_id_bytes (firmware, - FU_FIRMWARE_IMAGE_ID_SIGNATURE, + FU_FIRMWARE_ID_SIGNATURE, &error); g_assert_no_error (error); g_assert_nonnull (data_sig); @@ -1731,8 +1731,6 @@ fu_firmware_ihex_offset_func (void) g_autofree gchar *str = NULL; g_autoptr(FuFirmware) firmware = fu_ihex_firmware_new (); g_autoptr(FuFirmware) firmware_verify = fu_ihex_firmware_new (); - g_autoptr(FuFirmwareImage) img_verify = NULL; - g_autoptr(FuFirmwareImage) img = NULL; g_autoptr(GBytes) data_bin = NULL; g_autoptr(GBytes) data_dummy = NULL; g_autoptr(GBytes) data_verify = NULL; @@ -1740,9 +1738,8 @@ fu_firmware_ihex_offset_func (void) /* add a 4 byte image in high memory */ data_dummy = g_bytes_new_static ("foo", 4); - img = fu_firmware_image_new (data_dummy); - fu_firmware_image_set_addr (img, 0x80000000); - fu_firmware_add_image (firmware, img); + fu_firmware_set_addr (firmware, 0x80000000); + fu_firmware_set_bytes (firmware, data_dummy); data_bin = fu_firmware_write (firmware, &error); g_assert_no_error (error); g_assert (data_bin != NULL); @@ -1757,11 +1754,8 @@ fu_firmware_ihex_offset_func (void) ret = fu_firmware_parse (firmware_verify, data_bin, FWUPD_INSTALL_FLAG_NONE, &error); g_assert_no_error (error); g_assert (ret); - img_verify = fu_firmware_get_image_default (firmware_verify, &error); - g_assert_no_error (error); - g_assert (img_verify != NULL); - g_assert_cmpint (fu_firmware_image_get_addr (img_verify), ==, 0x80000000); - data_verify = fu_firmware_image_write (img_verify, &error); + g_assert_cmpint (fu_firmware_get_addr (firmware_verify), ==, 0x80000000); + data_verify = fu_firmware_get_bytes (firmware_verify, &error); g_assert_no_error (error); g_assert (data_verify != NULL); g_assert_cmpint (g_bytes_get_size (data_verify), ==, 0x4); @@ -1786,7 +1780,7 @@ fu_firmware_srec_func (void) ret = fu_firmware_parse (firmware, data_srec, FWUPD_INSTALL_FLAG_NONE, &error); g_assert_no_error (error); g_assert (ret); - data_bin = fu_firmware_get_image_default_bytes (firmware, &error); + data_bin = fu_firmware_get_bytes (firmware, &error); g_assert_no_error (error); g_assert_nonnull (data_bin); g_assert_cmpint (g_bytes_get_size (data_bin), ==, 136); @@ -1839,7 +1833,7 @@ fu_firmware_build_func (void) gboolean ret; g_autofree gchar *str = NULL; g_autoptr(FuFirmware) firmware = fu_firmware_new (); - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(GBytes) blob = NULL; g_autoptr(GBytes) blob2 = NULL; g_autoptr(GError) error = NULL; @@ -1851,19 +1845,19 @@ fu_firmware_build_func (void) "\n" "\n" " 1.2.3\n" - " \n" + " \n" " 4.5.6\n" " header\n" " 456\n" " 0x456\n" " aGVsbG8=\n" - " \n" - " \n" + " \n" + " \n" " 7.8.9\n" " header\n" " 789\n" " 0x789\n" - " \n" + " \n" "\n"; blob = g_bytes_new_static (buf, strlen (buf)); g_assert_no_error (error); @@ -1891,10 +1885,10 @@ fu_firmware_build_func (void) img = fu_firmware_get_image_by_id (firmware, "header", &error); g_assert_no_error (error); g_assert_nonnull (img); - g_assert_cmpstr (fu_firmware_image_get_version (img), ==, "4.5.6"); - g_assert_cmpint (fu_firmware_image_get_idx (img), ==, 456); - g_assert_cmpint (fu_firmware_image_get_addr (img), ==, 0x456); - blob2 = fu_firmware_image_write (img, &error); + g_assert_cmpstr (fu_firmware_get_version (img), ==, "4.5.6"); + g_assert_cmpint (fu_firmware_get_idx (img), ==, 456); + g_assert_cmpint (fu_firmware_get_addr (img), ==, 0x456); + blob2 = fu_firmware_write (img, &error); g_assert_no_error (error); g_assert_nonnull (blob2); g_assert_cmpint (g_bytes_get_size (blob2), ==, 5); @@ -1903,9 +1897,9 @@ fu_firmware_build_func (void) } static gsize -fu_firmware_dfuse_image_get_size (FuFirmwareImage *self) +fu_firmware_dfuse_image_get_size (FuFirmware *self) { - g_autoptr(GPtrArray) chunks = fu_firmware_image_get_chunks (self, NULL); + g_autoptr(GPtrArray) chunks = fu_firmware_get_chunks (self, NULL); gsize length = 0; for (guint i = 0; i < chunks->len; i++) { FuChunk *chk = g_ptr_array_index (chunks, i); @@ -1920,7 +1914,7 @@ fu_firmware_dfuse_get_size (FuFirmware *firmware) gsize length = 0; g_autoptr(GPtrArray) images = fu_firmware_get_images (firmware); for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *image = g_ptr_array_index (images, i); + FuFirmware *image = g_ptr_array_index (images, i); length += fu_firmware_dfuse_image_get_size (image); } return length; @@ -1964,7 +1958,7 @@ fu_firmware_fmap_func (void) g_autofree gchar *filename = NULL; g_autofree gchar *img_str = NULL; g_autoptr(FuFirmware) firmware = fu_fmap_firmware_new (); - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(GBytes) img_blob = NULL; g_autoptr(GBytes) roundtrip = NULL; g_autoptr(GBytes) roundtrip_orig = NULL; @@ -1987,7 +1981,9 @@ fu_firmware_fmap_func (void) img = fu_firmware_get_image_by_id (firmware, "FMAP", &error); g_assert_no_error (error); g_assert_nonnull (img); - img_blob = fu_firmware_image_get_bytes (img); + img_blob = fu_firmware_get_bytes (img, &error); + g_assert_no_error (error); + g_assert_nonnull (img_blob); g_assert_cmpint (g_bytes_get_size (img_blob), ==, 0xb); img_str = g_strndup (g_bytes_get_data (img_blob, NULL), g_bytes_get_size (img_blob)); @@ -2066,7 +2062,7 @@ fu_firmware_dfu_func (void) g_assert_cmpint (fu_dfu_firmware_get_vid (FU_DFU_FIRMWARE (firmware)), ==, 0x1234); g_assert_cmpint (fu_dfu_firmware_get_pid (FU_DFU_FIRMWARE (firmware)), ==, 0x4321); g_assert_cmpint (fu_dfu_firmware_get_release (FU_DFU_FIRMWARE (firmware)), ==, 0xdead); - data_bin = fu_firmware_get_image_default_bytes (firmware, &error); + data_bin = fu_firmware_get_bytes (firmware, &error); g_assert_no_error (error); g_assert_nonnull (data_bin); g_assert_cmpint (g_bytes_get_size (data_bin), ==, 136); @@ -2086,22 +2082,22 @@ fu_firmware_func (void) { gboolean ret; g_autoptr(FuFirmware) firmware = fu_firmware_new (); - g_autoptr(FuFirmwareImage) img1 = fu_firmware_image_new (NULL); - g_autoptr(FuFirmwareImage) img2 = fu_firmware_image_new (NULL); - g_autoptr(FuFirmwareImage) img_id = NULL; - g_autoptr(FuFirmwareImage) img_idx = NULL; + g_autoptr(FuFirmware) img1 = fu_firmware_new (); + g_autoptr(FuFirmware) img2 = fu_firmware_new (); + g_autoptr(FuFirmware) img_id = NULL; + g_autoptr(FuFirmware) img_idx = NULL; g_autoptr(GError) error = NULL; g_autoptr(GPtrArray) images = NULL; g_autofree gchar *str = NULL; - fu_firmware_image_set_addr (img1, 0x200); - fu_firmware_image_set_idx (img1, 13); - fu_firmware_image_set_id (img1, "primary"); - fu_firmware_image_set_filename (img1, "BIOS.bin"); + fu_firmware_set_addr (img1, 0x200); + fu_firmware_set_idx (img1, 13); + fu_firmware_set_id (img1, "primary"); + fu_firmware_set_filename (img1, "BIOS.bin"); fu_firmware_add_image (firmware, img1); - fu_firmware_image_set_addr (img2, 0x400); - fu_firmware_image_set_idx (img2, 23); - fu_firmware_image_set_id (img2, "secondary"); + fu_firmware_set_addr (img2, 0x400); + fu_firmware_set_idx (img2, 23); + fu_firmware_set_id (img2, "secondary"); fu_firmware_add_image (firmware, img2); img_id = fu_firmware_get_image_by_id (firmware, "NotGoingToExist", &error); @@ -2111,9 +2107,9 @@ fu_firmware_func (void) img_id = fu_firmware_get_image_by_id (firmware, "primary", &error); g_assert_no_error (error); g_assert_nonnull (img_id); - g_assert_cmpint (fu_firmware_image_get_addr (img_id), ==, 0x200); - g_assert_cmpint (fu_firmware_image_get_idx (img_id), ==, 13); - g_assert_cmpstr (fu_firmware_image_get_id (img_id), ==, "primary"); + g_assert_cmpint (fu_firmware_get_addr (img_id), ==, 0x200); + g_assert_cmpint (fu_firmware_get_idx (img_id), ==, 13); + g_assert_cmpstr (fu_firmware_get_id (img_id), ==, "primary"); img_idx = fu_firmware_get_image_by_idx (firmware, 123456, &error); g_assert_error (error, FWUPD_ERROR, FWUPD_ERROR_NOT_FOUND); @@ -2122,18 +2118,18 @@ fu_firmware_func (void) img_idx = fu_firmware_get_image_by_idx (firmware, 23, &error); g_assert_no_error (error); g_assert_nonnull (img_idx); - g_assert_cmpint (fu_firmware_image_get_addr (img_idx), ==, 0x400); - g_assert_cmpint (fu_firmware_image_get_idx (img_idx), ==, 23); - g_assert_cmpstr (fu_firmware_image_get_id (img_idx), ==, "secondary"); + g_assert_cmpint (fu_firmware_get_addr (img_idx), ==, 0x400); + g_assert_cmpint (fu_firmware_get_idx (img_idx), ==, 23); + g_assert_cmpstr (fu_firmware_get_id (img_idx), ==, "secondary"); str = fu_firmware_to_string (firmware); g_assert_cmpstr (str, ==, "FuFirmware:\n" - " FuFirmwareImage:\n" + " FuFirmware:\n" " ID: primary\n" " Index: 0xd\n" " Address: 0x200\n" " Filename: BIOS.bin\n" - " FuFirmwareImage:\n" + " FuFirmware:\n" " ID: secondary\n" " Index: 0x17\n" " Address: 0x400\n"); @@ -2156,45 +2152,45 @@ static void fu_firmware_dedupe_func (void) { g_autoptr(FuFirmware) firmware = fu_firmware_new (); - g_autoptr(FuFirmwareImage) img1 = fu_firmware_image_new (NULL); - g_autoptr(FuFirmwareImage) img1_old = fu_firmware_image_new (NULL); - g_autoptr(FuFirmwareImage) img2 = fu_firmware_image_new (NULL); - g_autoptr(FuFirmwareImage) img2_old = fu_firmware_image_new (NULL); - g_autoptr(FuFirmwareImage) img_id = NULL; - g_autoptr(FuFirmwareImage) img_idx = NULL; + g_autoptr(FuFirmware) img1 = fu_firmware_new (); + g_autoptr(FuFirmware) img1_old = fu_firmware_new (); + g_autoptr(FuFirmware) img2 = fu_firmware_new (); + g_autoptr(FuFirmware) img2_old = fu_firmware_new (); + g_autoptr(FuFirmware) img_id = NULL; + g_autoptr(FuFirmware) img_idx = NULL; g_autoptr(GError) error = NULL; fu_firmware_add_flag (firmware, FU_FIRMWARE_FLAG_DEDUPE_ID); fu_firmware_add_flag (firmware, FU_FIRMWARE_FLAG_DEDUPE_IDX); - fu_firmware_image_set_idx (img1_old, 13); - fu_firmware_image_set_id (img1_old, "DAVE"); + fu_firmware_set_idx (img1_old, 13); + fu_firmware_set_id (img1_old, "DAVE"); fu_firmware_add_image (firmware, img1_old); - fu_firmware_image_set_idx (img1, 13); - fu_firmware_image_set_id (img1, "primary"); + fu_firmware_set_idx (img1, 13); + fu_firmware_set_id (img1, "primary"); fu_firmware_add_image (firmware, img1); - fu_firmware_image_set_idx (img2_old, 123456); - fu_firmware_image_set_id (img2_old, "secondary"); + fu_firmware_set_idx (img2_old, 123456); + fu_firmware_set_id (img2_old, "secondary"); fu_firmware_add_image (firmware, img2_old); - fu_firmware_image_set_idx (img2, 23); - fu_firmware_image_set_id (img2, "secondary"); + fu_firmware_set_idx (img2, 23); + fu_firmware_set_id (img2, "secondary"); fu_firmware_add_image (firmware, img2); img_id = fu_firmware_get_image_by_id (firmware, "primary", &error); g_assert_no_error (error); g_assert_nonnull (img_id); - g_assert_cmpint (fu_firmware_image_get_idx (img_id), ==, 13); - g_assert_cmpstr (fu_firmware_image_get_id (img_id), ==, "primary"); + g_assert_cmpint (fu_firmware_get_idx (img_id), ==, 13); + g_assert_cmpstr (fu_firmware_get_id (img_id), ==, "primary"); img_idx = fu_firmware_get_image_by_idx (firmware, 23, &error); g_assert_no_error (error); g_assert_nonnull (img_idx); - g_assert_cmpint (fu_firmware_image_get_idx (img_idx), ==, 23); - g_assert_cmpstr (fu_firmware_image_get_id (img_idx), ==, "secondary"); + g_assert_cmpint (fu_firmware_get_idx (img_idx), ==, 23); + g_assert_cmpstr (fu_firmware_get_id (img_idx), ==, "secondary"); } static void diff --git a/libfwupdplugin/fu-srec-firmware.c b/libfwupdplugin/fu-srec-firmware.c index b8e18be30..056ade5ff 100644 --- a/libfwupdplugin/fu-srec-firmware.c +++ b/libfwupdplugin/fu-srec-firmware.c @@ -280,7 +280,6 @@ fu_srec_firmware_parse (FuFirmware *firmware, guint16 data_cnt = 0; guint32 addr32_last = 0; guint32 img_address = 0; - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (NULL); g_autoptr(GBytes) img_bytes = NULL; g_autoptr(GByteArray) outbuf = g_byte_array_new (); @@ -310,7 +309,7 @@ fu_srec_firmware_parse (FuFirmware *firmware, g_string_append_c (modname, tmp); } if (modname->len != 0) - fu_firmware_image_set_id (img, modname->str); + fu_firmware_set_id (firmware, modname->str); got_hdr = TRUE; continue; } @@ -387,9 +386,8 @@ fu_srec_firmware_parse (FuFirmware *firmware, /* add single image */ img_bytes = g_bytes_new (outbuf->data, outbuf->len); - fu_firmware_image_set_bytes (img, img_bytes); - fu_firmware_image_set_addr (img, img_address); - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, img_bytes); + fu_firmware_set_addr (firmware, img_address); return TRUE; } diff --git a/libfwupdplugin/fwupdplugin.h b/libfwupdplugin/fwupdplugin.h index 57d3d05e0..74e46d356 100644 --- a/libfwupdplugin/fwupdplugin.h +++ b/libfwupdplugin/fwupdplugin.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index 170b0b02c..92ef1e2c8 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -406,21 +406,8 @@ LIBFWUPDPLUGIN_1.3.1 { fu_firmware_get_image_by_id_bytes; fu_firmware_get_image_by_idx; fu_firmware_get_image_by_idx_bytes; - fu_firmware_get_image_default; - fu_firmware_get_image_default_bytes; fu_firmware_get_images; fu_firmware_get_type; - fu_firmware_image_get_addr; - fu_firmware_image_get_id; - fu_firmware_image_get_idx; - fu_firmware_image_get_type; - fu_firmware_image_new; - fu_firmware_image_set_addr; - fu_firmware_image_set_bytes; - fu_firmware_image_set_id; - fu_firmware_image_set_idx; - fu_firmware_image_to_string; - fu_firmware_image_write_chunk; fu_firmware_new; fu_firmware_new_from_bytes; fu_firmware_parse; @@ -473,7 +460,6 @@ LIBFWUPDPLUGIN_1.3.3 { fu_dfu_firmware_set_version; fu_dfu_firmware_set_vid; fu_firmware_get_version; - fu_firmware_image_write; fu_firmware_parse_file; fu_firmware_set_version; fu_firmware_write_file; @@ -493,8 +479,6 @@ LIBFWUPDPLUGIN_1.3.3 { LIBFWUPDPLUGIN_1.3.4 { global: fu_archive_iterate; - fu_firmware_image_get_version; - fu_firmware_image_set_version; fu_ihex_firmware_get_records; fu_usb_device_get_spec; local: *; @@ -627,13 +611,6 @@ LIBFWUPDPLUGIN_1.5.0 { fu_firmware_flag_from_string; fu_firmware_flag_to_string; fu_firmware_has_flag; - fu_firmware_image_build; - fu_firmware_image_get_bytes; - fu_firmware_image_get_filename; - fu_firmware_image_get_offset; - fu_firmware_image_parse; - fu_firmware_image_set_filename; - fu_firmware_image_set_offset; fu_firmware_remove_image; fu_firmware_remove_image_by_id; fu_firmware_remove_image_by_idx; @@ -705,7 +682,6 @@ LIBFWUPDPLUGIN_1.5.5 { fu_efi_signature_list_new; fu_efivar_get_monitor; fu_firmware_get_image_by_checksum; - fu_firmware_image_get_checksum; local: *; } LIBFWUPDPLUGIN_1.5.4; @@ -730,8 +706,6 @@ LIBFWUPDPLUGIN_1.5.6 { fu_common_uri_get_scheme; fu_dfuse_firmware_get_type; fu_dfuse_firmware_new; - fu_firmware_image_add_chunk; - fu_firmware_image_get_chunks; fu_firmware_new_from_gtypes; fu_firmware_strparse_uint16_safe; fu_firmware_strparse_uint24_safe; @@ -782,6 +756,22 @@ LIBFWUPDPLUGIN_1.5.8 { LIBFWUPDPLUGIN_1.6.0 { global: + fu_firmware_add_chunk; + fu_firmware_get_addr; + fu_firmware_get_bytes; + fu_firmware_get_checksum; + fu_firmware_get_chunks; + fu_firmware_get_filename; + fu_firmware_get_id; + fu_firmware_get_idx; + fu_firmware_get_offset; + fu_firmware_set_addr; + fu_firmware_set_bytes; + fu_firmware_set_filename; + fu_firmware_set_id; + fu_firmware_set_idx; + fu_firmware_set_offset; + fu_firmware_write_chunk; fu_ifd_access_to_string; fu_ifd_firmware_check_jedec_cmd; fu_ifd_firmware_get_type; diff --git a/libfwupdplugin/meson.build b/libfwupdplugin/meson.build index 662c0da5a..c61cf00dd 100644 --- a/libfwupdplugin/meson.build +++ b/libfwupdplugin/meson.build @@ -13,7 +13,6 @@ fwupdplugin_src = [ 'fu-volume.c', # fuzzing 'fu-firmware.c', # fuzzing 'fu-firmware-common.c', # fuzzing - 'fu-firmware-image.c', # fuzzing 'fu-dfuse-firmware.c', # fuzzing 'fu-fmap-firmware.c', # fuzzing 'fu-hwids.c', @@ -52,7 +51,6 @@ fwupdplugin_headers = [ 'fu-volume.h', 'fu-firmware.h', 'fu-firmware-common.h', - 'fu-firmware-image.h', 'fu-fmap-firmware.h', 'fu-dfuse-firmware.h', 'fu-hwids.h', diff --git a/plugins/altos/fu-altos-device.c b/plugins/altos/fu-altos-device.c index 07028a9db..15ef299d2 100644 --- a/plugins/altos/fu-altos-device.c +++ b/plugins/altos/fu-altos-device.c @@ -246,7 +246,6 @@ fu_altos_device_write_firmware (FuDevice *device, const gsize data_len; guint flash_len; g_autoptr(FuDeviceLocker) locker = NULL; - g_autoptr(FuFirmwareImage) img = NULL; g_autoptr(GBytes) fw = NULL; g_autoptr(GString) buf = g_string_new (NULL); @@ -278,25 +277,20 @@ fu_altos_device_write_firmware (FuDevice *device, return FALSE; } - /* load ihex blob */ - img = fu_firmware_get_image_default (firmware, error); - if (img == NULL) - return FALSE; - /* check the start address */ - if (fu_firmware_image_get_addr (img) != self->addr_base) { + if (fu_firmware_get_addr (firmware) != self->addr_base) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_FILE, "start address not correct %" G_GUINT64_FORMAT ":" "%" G_GUINT64_FORMAT, - fu_firmware_image_get_addr (img), + fu_firmware_get_addr (firmware), self->addr_base); return FALSE; } /* check firmware will fit */ - fw = fu_firmware_image_write (img, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; data = g_bytes_get_data (fw, (gsize *) &data_len); diff --git a/plugins/altos/fu-altos-firmware.c b/plugins/altos/fu-altos-firmware.c index 680c39c6c..aff0d551e 100644 --- a/plugins/altos/fu-altos-firmware.c +++ b/plugins/altos/fu-altos-firmware.c @@ -88,12 +88,10 @@ fu_altos_firmware_parse (FuFirmware *firmware, if (g_strcmp0 (name, ".text") == 0) { Elf_Data *data = elf_getdata (scn, NULL); if (data != NULL && data->d_buf != NULL) { - g_autoptr(FuFirmwareImage) img = NULL; g_autoptr(GBytes) bytes = NULL; bytes = g_bytes_new (data->d_buf, data->d_size); - img = fu_firmware_image_new (bytes); - fu_firmware_image_set_addr (img, shdr.sh_addr); - fu_firmware_add_image (firmware, img); + fu_firmware_set_addr (firmware, shdr.sh_addr); + fu_firmware_set_bytes (firmware, bytes); } return TRUE; } diff --git a/plugins/ata/fu-ata-device.c b/plugins/ata/fu-ata-device.c index 0cd900900..8033514cc 100644 --- a/plugins/ata/fu-ata-device.c +++ b/plugins/ata/fu-ata-device.c @@ -724,7 +724,7 @@ fu_ata_device_write_firmware (FuDevice *device, g_autoptr(GPtrArray) chunks = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/bcm57xx/fu-bcm57xx-device.c b/plugins/bcm57xx/fu-bcm57xx-device.c index b55591460..0c16aa1d5 100644 --- a/plugins/bcm57xx/fu-bcm57xx-device.c +++ b/plugins/bcm57xx/fu-bcm57xx-device.c @@ -393,9 +393,9 @@ fu_bcm57xx_device_prepare_firmware (FuDevice *device, g_autoptr(GBytes) fw_old = NULL; g_autoptr(FuFirmware) firmware = fu_bcm57xx_firmware_new (); g_autoptr(FuFirmware) firmware_tmp = fu_bcm57xx_firmware_new (); - g_autoptr(FuFirmwareImage) img_ape = NULL; - g_autoptr(FuFirmwareImage) img_stage1 = NULL; - g_autoptr(FuFirmwareImage) img_stage2 = NULL; + g_autoptr(FuFirmware) img_ape = NULL; + g_autoptr(FuFirmware) img_stage1 = NULL; + g_autoptr(FuFirmware) img_stage2 = NULL; g_autoptr(GPtrArray) images = NULL; /* try to parse NVRAM, stage1 or APE */ @@ -450,9 +450,9 @@ fu_bcm57xx_device_prepare_firmware (FuDevice *device, /* the src and dst dictionaries may be in different order */ images = fu_firmware_get_images (firmware); for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); + FuFirmware *img = g_ptr_array_index (images, i); if (FU_IS_BCM57XX_DICT_IMAGE (img)) { - fu_firmware_image_set_idx (img, 0x80 + dict_cnt); + fu_firmware_set_idx (img, 0x80 + dict_cnt); dict_cnt++; } } diff --git a/plugins/bcm57xx/fu-bcm57xx-dict-image.c b/plugins/bcm57xx/fu-bcm57xx-dict-image.c index ee8afa89b..55d393804 100644 --- a/plugins/bcm57xx/fu-bcm57xx-dict-image.c +++ b/plugins/bcm57xx/fu-bcm57xx-dict-image.c @@ -12,15 +12,15 @@ #include "fu-bcm57xx-dict-image.h" struct _FuBcm57xxDictImage { - FuFirmwareImage parent_instance; + FuFirmware parent_instance; guint8 target; guint8 kind; }; -G_DEFINE_TYPE (FuBcm57xxDictImage, fu_bcm57xx_dict_image, FU_TYPE_FIRMWARE_IMAGE) +G_DEFINE_TYPE (FuBcm57xxDictImage, fu_bcm57xx_dict_image, FU_TYPE_FIRMWARE) static void -fu_bcm57xx_dict_image_to_string (FuFirmwareImage *image, guint idt, GString *str) +fu_bcm57xx_dict_image_to_string (FuFirmware *image, guint idt, GString *str) { FuBcm57xxDictImage *self = FU_BCM57XX_DICT_IMAGE (image); if (self->target != 0xff) @@ -30,8 +30,10 @@ fu_bcm57xx_dict_image_to_string (FuFirmwareImage *image, guint idt, GString *str } static gboolean -fu_bcm57xx_dict_image_parse (FuFirmwareImage *image, +fu_bcm57xx_dict_image_parse (FuFirmware *image, GBytes *fw, + guint64 addr_start, + guint64 addr_end, FwupdInstallFlags flags, GError **error) { @@ -45,12 +47,12 @@ fu_bcm57xx_dict_image_parse (FuFirmwareImage *image, error); if (fw_nocrc == NULL) return FALSE; - fu_firmware_image_set_bytes (image, fw_nocrc); + fu_firmware_set_bytes (image, fw_nocrc); return TRUE; } static GBytes * -fu_bcm57xx_dict_image_write (FuFirmwareImage *image, GError **error) +fu_bcm57xx_dict_image_write (FuFirmware *image, GError **error) { const guint8 *buf; gsize bufsz = 0; @@ -59,14 +61,9 @@ fu_bcm57xx_dict_image_write (FuFirmwareImage *image, GError **error) g_autoptr(GBytes) fw_nocrc = NULL; /* get the CRC-less data */ - fw_nocrc = fu_firmware_image_get_bytes (image); - if (fw_nocrc == NULL) { - g_set_error_literal (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_SUPPORTED, - "not supported"); + fw_nocrc = fu_firmware_get_bytes (image, error); + if (fw_nocrc == NULL) return NULL; - } /* add to a mutable buffer */ buf = g_bytes_get_data (fw_nocrc, &bufsz); @@ -80,7 +77,7 @@ fu_bcm57xx_dict_image_write (FuFirmwareImage *image, GError **error) } static gboolean -fu_bcm57xx_dict_image_build (FuFirmwareImage *image, XbNode *n, GError **error) +fu_bcm57xx_dict_image_build (FuFirmware *image, XbNode *n, GError **error) { FuBcm57xxDictImage *self = FU_BCM57XX_DICT_IMAGE (image); guint64 tmp; @@ -121,13 +118,13 @@ fu_bcm57xx_dict_image_ensure_id (FuBcm57xxDictImage *self) if (self->target == ids[i].target && self->kind == ids[i].kind) { g_debug ("using %s for %02x:%02x", ids[i].id, self->target, self->kind); - fu_firmware_image_set_id (FU_FIRMWARE_IMAGE (self), ids[i].id); + fu_firmware_set_id (FU_FIRMWARE (self), ids[i].id); return; } } id = g_strdup_printf ("dict-%02x-%02x", self->target, self->kind); g_warning ("falling back to %s, please report", id); - fu_firmware_image_set_id (FU_FIRMWARE_IMAGE (self), id); + fu_firmware_set_id (FU_FIRMWARE (self), id); } void @@ -166,15 +163,15 @@ fu_bcm57xx_dict_image_init (FuBcm57xxDictImage *self) static void fu_bcm57xx_dict_image_class_init (FuBcm57xxDictImageClass *klass) { - FuFirmwareImageClass *klass_image = FU_FIRMWARE_IMAGE_CLASS (klass); + FuFirmwareClass *klass_image = FU_FIRMWARE_CLASS (klass); klass_image->parse = fu_bcm57xx_dict_image_parse; klass_image->write = fu_bcm57xx_dict_image_write; klass_image->build = fu_bcm57xx_dict_image_build; klass_image->to_string = fu_bcm57xx_dict_image_to_string; } -FuFirmwareImage * +FuFirmware * fu_bcm57xx_dict_image_new (void) { - return FU_FIRMWARE_IMAGE (g_object_new (FU_TYPE_BCM57XX_DICT_IMAGE, NULL)); + return FU_FIRMWARE (g_object_new (FU_TYPE_BCM57XX_DICT_IMAGE, NULL)); } diff --git a/plugins/bcm57xx/fu-bcm57xx-dict-image.h b/plugins/bcm57xx/fu-bcm57xx-dict-image.h index 5f376078a..de80a786d 100644 --- a/plugins/bcm57xx/fu-bcm57xx-dict-image.h +++ b/plugins/bcm57xx/fu-bcm57xx-dict-image.h @@ -6,12 +6,12 @@ #pragma once -#include "fu-firmware-image.h" +#include "fu-firmware.h" #define FU_TYPE_BCM57XX_DICT_IMAGE (fu_bcm57xx_dict_image_get_type ()) -G_DECLARE_FINAL_TYPE (FuBcm57xxDictImage, fu_bcm57xx_dict_image, FU, BCM57XX_DICT_IMAGE, FuFirmwareImage) +G_DECLARE_FINAL_TYPE (FuBcm57xxDictImage, fu_bcm57xx_dict_image, FU, BCM57XX_DICT_IMAGE, FuFirmware) -FuFirmwareImage *fu_bcm57xx_dict_image_new (void); +FuFirmware *fu_bcm57xx_dict_image_new (void); void fu_bcm57xx_dict_image_set_kind (FuBcm57xxDictImage *self, guint8 kind); guint8 fu_bcm57xx_dict_image_get_kind (FuBcm57xxDictImage *self); diff --git a/plugins/bcm57xx/fu-bcm57xx-firmware.c b/plugins/bcm57xx/fu-bcm57xx-firmware.c index 2595d200d..9f1264da2 100644 --- a/plugins/bcm57xx/fu-bcm57xx-firmware.c +++ b/plugins/bcm57xx/fu-bcm57xx-firmware.c @@ -61,13 +61,13 @@ fu_bcm57xx_firmware_parse_header (FuBcm57xxFirmware *self, GBytes *fw, GError ** &self->phys_addr, G_BIG_ENDIAN, error); } -static FuFirmwareImage * +static FuFirmware * fu_bcm57xx_firmware_parse_info (FuBcm57xxFirmware *self, GBytes *fw, GError **error) { gsize bufsz = 0x0; guint32 mac_addr0 = 0; const guint8 *buf = g_bytes_get_data (fw, &bufsz); - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); + g_autoptr(FuFirmware) img = fu_firmware_new_from_bytes (fw); /* if the MAC is set non-zero this is an actual backup rather than a container */ if (!fu_common_read_uint32_safe (buf, bufsz, BCM_NVRAM_INFO_MAC_ADDR0, @@ -84,11 +84,11 @@ fu_bcm57xx_firmware_parse_info (FuBcm57xxFirmware *self, GBytes *fw, GError **er return NULL; /* success */ - fu_firmware_image_set_id (img, "info"); + fu_firmware_set_id (img, "info"); return g_steal_pointer (&img); } -static FuFirmwareImage * +static FuFirmware * fu_bcm57xx_firmware_parse_stage1 (FuBcm57xxFirmware *self, GBytes *fw, guint32 *out_stage1_sz, @@ -100,7 +100,7 @@ fu_bcm57xx_firmware_parse_stage1 (FuBcm57xxFirmware *self, guint32 stage1_sz; guint32 stage1_off = 0; const guint8 *buf = g_bytes_get_data (fw, &bufsz); - g_autoptr(FuFirmwareImage) img = fu_bcm57xx_stage1_image_new (); + g_autoptr(FuFirmware) img = fu_bcm57xx_stage1_image_new (); g_autoptr(GBytes) blob = NULL; if (!fu_common_read_uint32_safe (buf, bufsz, @@ -133,7 +133,7 @@ fu_bcm57xx_firmware_parse_stage1 (FuBcm57xxFirmware *self, blob = fu_common_bytes_new_offset (fw, stage1_off, stage1_sz, error); if (blob == NULL) return NULL; - if (!fu_firmware_image_parse (img, blob, flags, error)) + if (!fu_firmware_parse (img, blob, flags, error)) return NULL; /* needed for stage2 */ @@ -141,12 +141,12 @@ fu_bcm57xx_firmware_parse_stage1 (FuBcm57xxFirmware *self, *out_stage1_sz = stage1_sz; /* success */ - fu_firmware_image_set_id (img, "stage1"); - fu_firmware_image_set_offset (img, stage1_off); + fu_firmware_set_id (img, "stage1"); + fu_firmware_set_offset (img, stage1_off); return g_steal_pointer (&img); } -static FuFirmwareImage * +static FuFirmware * fu_bcm57xx_firmware_parse_stage2 (FuBcm57xxFirmware *self, GBytes *fw, guint32 stage1_sz, @@ -157,7 +157,7 @@ fu_bcm57xx_firmware_parse_stage2 (FuBcm57xxFirmware *self, const guint8 *buf = g_bytes_get_data (fw, &bufsz); guint32 stage2_off = 0; guint32 stage2_sz = 0; - g_autoptr(FuFirmwareImage) img = fu_bcm57xx_stage2_image_new (); + g_autoptr(FuFirmware) img = fu_bcm57xx_stage2_image_new (); g_autoptr(GBytes) blob = NULL; stage2_off = BCM_NVRAM_STAGE1_BASE + stage1_sz; @@ -179,12 +179,12 @@ fu_bcm57xx_firmware_parse_stage2 (FuBcm57xxFirmware *self, blob = fu_common_bytes_new_offset (fw, stage2_off + 0x8, stage2_sz, error); if (blob == NULL) return NULL; - if (!fu_firmware_image_parse (img, blob, flags, error)) + if (!fu_firmware_parse (img, blob, flags, error)) return NULL; /* success */ - fu_firmware_image_set_id (img, "stage2"); - fu_firmware_image_set_offset (img, stage2_off); + fu_firmware_set_id (img, "stage2"); + fu_firmware_set_offset (img, stage2_off); return g_steal_pointer (&img); } @@ -199,7 +199,7 @@ fu_bcm57xx_firmware_parse_dict (FuBcm57xxFirmware *self, GBytes *fw, guint idx, guint32 dict_sz; guint32 base = BCM_NVRAM_DIRECTORY_BASE + (idx * BCM_NVRAM_DIRECTORY_SZ); const guint8 *buf = g_bytes_get_data (fw, &bufsz); - g_autoptr(FuFirmwareImage) img = fu_bcm57xx_dict_image_new (); + g_autoptr(FuFirmware) img = fu_bcm57xx_dict_image_new (); g_autoptr(GBytes) blob = NULL; /* header */ @@ -223,14 +223,14 @@ fu_bcm57xx_firmware_parse_dict (FuBcm57xxFirmware *self, GBytes *fw, guint idx, dict_sz = (dict_info & 0x00FFFFFF) * sizeof(guint32); /* implies that maximum size is 16 MB */ fu_bcm57xx_dict_image_set_target (FU_BCM57XX_DICT_IMAGE (img), (dict_info & 0x0F000000) >> 24); fu_bcm57xx_dict_image_set_kind (FU_BCM57XX_DICT_IMAGE (img), (dict_info & 0xF0000000) >> 28); - fu_firmware_image_set_addr (img, dict_addr); - fu_firmware_image_set_offset (img, dict_off); - fu_firmware_image_set_idx (img, 0x80 + idx); + fu_firmware_set_addr (img, dict_addr); + fu_firmware_set_offset (img, dict_off); + fu_firmware_set_idx (img, 0x80 + idx); /* empty */ if (dict_sz == 0) { blob = g_bytes_new (NULL, 0); - fu_firmware_image_set_bytes (img, blob); + fu_firmware_set_bytes (img, blob); fu_firmware_add_image (FU_FIRMWARE (self), img); return TRUE; } @@ -247,7 +247,7 @@ fu_bcm57xx_firmware_parse_dict (FuBcm57xxFirmware *self, GBytes *fw, guint idx, blob = fu_common_bytes_new_offset (fw, dict_off, dict_sz, error); if (blob == NULL) return FALSE; - if (!fu_firmware_image_parse (img, blob, flags, error)) + if (!fu_firmware_parse (img, blob, flags, error)) return FALSE; /* success */ @@ -268,11 +268,11 @@ fu_bcm57xx_firmware_parse (FuFirmware *firmware, guint32 magic = 0; guint32 stage1_sz = 0; const guint8 *buf = g_bytes_get_data (fw, &bufsz); - g_autoptr(FuFirmwareImage) img_info2 = NULL; - g_autoptr(FuFirmwareImage) img_info = NULL; - g_autoptr(FuFirmwareImage) img_stage1 = NULL; - g_autoptr(FuFirmwareImage) img_stage2 = NULL; - g_autoptr(FuFirmwareImage) img_vpd = NULL; + g_autoptr(FuFirmware) img_info2 = NULL; + g_autoptr(FuFirmware) img_info = NULL; + g_autoptr(FuFirmware) img_stage1 = NULL; + g_autoptr(FuFirmware) img_stage2 = NULL; + g_autoptr(FuFirmware) img_vpd = NULL; g_autoptr(GBytes) blob_header = NULL; g_autoptr(GBytes) blob_info2 = NULL; g_autoptr(GBytes) blob_info = NULL; @@ -284,12 +284,12 @@ fu_bcm57xx_firmware_parse (FuFirmware *firmware, /* standalone APE */ if (magic == BCM_APE_HEADER_MAGIC) { - g_autoptr(FuFirmwareImage) img = fu_bcm57xx_dict_image_new (); + g_autoptr(FuFirmware) img = fu_bcm57xx_dict_image_new (); fu_bcm57xx_dict_image_set_target (FU_BCM57XX_DICT_IMAGE (img), 0xD); fu_bcm57xx_dict_image_set_kind (FU_BCM57XX_DICT_IMAGE (img), 0x0); - fu_firmware_image_set_bytes (img, fw); - fu_firmware_image_set_addr (img, BCM_CODE_DIRECTORY_ADDR_APE); - fu_firmware_image_set_id (img, "ape"); + fu_firmware_set_bytes (img, fw); + fu_firmware_set_addr (img, BCM_CODE_DIRECTORY_ADDR_APE); + fu_firmware_set_id (img, "ape"); fu_firmware_add_image (firmware, img); return TRUE; } @@ -297,8 +297,8 @@ fu_bcm57xx_firmware_parse (FuFirmware *firmware, /* standalone stage1 */ if (magic == BCM_STAGE1_HEADER_MAGIC_BROADCOM || magic == BCM_STAGE1_HEADER_MAGIC_MEKLORT) { - img_stage1 = fu_firmware_image_new (fw); - fu_firmware_image_set_id (img_stage1, "stage1"); + img_stage1 = fu_firmware_new_from_bytes (fw); + fu_firmware_set_id (img_stage1, "stage1"); fu_firmware_add_image (firmware, img_stage1); return TRUE; } @@ -341,7 +341,7 @@ fu_bcm57xx_firmware_parse (FuFirmware *firmware, g_prefix_error (error, "failed to parse info: "); return FALSE; } - fu_firmware_image_set_offset (img_info, BCM_NVRAM_INFO_BASE); + fu_firmware_set_offset (img_info, BCM_NVRAM_INFO_BASE); fu_firmware_add_image (firmware, img_info); /* VPD */ @@ -351,9 +351,9 @@ fu_bcm57xx_firmware_parse (FuFirmware *firmware, error); if (blob_vpd == NULL) return FALSE; - img_vpd = fu_firmware_image_new (blob_vpd); - fu_firmware_image_set_id (img_vpd, "vpd"); - fu_firmware_image_set_offset (img_vpd, BCM_NVRAM_VPD_BASE); + img_vpd = fu_firmware_new_from_bytes (blob_vpd); + fu_firmware_set_id (img_vpd, "vpd"); + fu_firmware_set_offset (img_vpd, BCM_NVRAM_VPD_BASE); fu_firmware_add_image (firmware, img_vpd); /* info2 */ @@ -363,9 +363,9 @@ fu_bcm57xx_firmware_parse (FuFirmware *firmware, error); if (blob_info2 == NULL) return FALSE; - img_info2 = fu_firmware_image_new (blob_info2); - fu_firmware_image_set_id (img_info2, "info2"); - fu_firmware_image_set_offset (img_info2, BCM_NVRAM_INFO2_BASE); + img_info2 = fu_firmware_new_from_bytes (blob_info2); + fu_firmware_set_id (img_info2, "info2"); + fu_firmware_set_offset (img_info2, BCM_NVRAM_INFO2_BASE); fu_firmware_add_image (firmware, img_info2); /* stage1 */ @@ -435,11 +435,11 @@ fu_bcm57xx_firmware_write (FuFirmware *firmware, GError **error) gsize off = BCM_NVRAM_STAGE1_BASE; FuBcm57xxFirmware *self = FU_BCM57XX_FIRMWARE (firmware); g_autoptr(GByteArray) buf = g_byte_array_sized_new (self->source_size); - g_autoptr(FuFirmwareImage) img_info2 = NULL; - g_autoptr(FuFirmwareImage) img_info = NULL; - g_autoptr(FuFirmwareImage) img_stage1 = NULL; - g_autoptr(FuFirmwareImage) img_stage2 = NULL; - g_autoptr(FuFirmwareImage) img_vpd = NULL; + g_autoptr(FuFirmware) img_info2 = NULL; + g_autoptr(FuFirmware) img_info = NULL; + g_autoptr(FuFirmware) img_stage1 = NULL; + g_autoptr(FuFirmware) img_stage2 = NULL; + g_autoptr(FuFirmware) img_vpd = NULL; g_autoptr(GBytes) blob_info2 = NULL; g_autoptr(GBytes) blob_info = NULL; g_autoptr(GBytes) blob_stage1 = NULL; @@ -451,14 +451,14 @@ fu_bcm57xx_firmware_write (FuFirmware *firmware, GError **error) img_stage1 = fu_firmware_get_image_by_id (firmware, "stage1", error); if (img_stage1 == NULL) return NULL; - blob_stage1 = fu_firmware_image_write (img_stage1, error); + blob_stage1 = fu_firmware_write (img_stage1, error); if (blob_stage1 == NULL) return NULL; off += g_bytes_get_size (blob_stage1); img_stage2 = fu_firmware_get_image_by_id (firmware, "stage2", error); if (img_stage2 == NULL) return NULL; - blob_stage2 = fu_firmware_image_write (img_stage2, error); + blob_stage2 = fu_firmware_write (img_stage2, error); if (blob_stage2 == NULL) return NULL; off += g_bytes_get_size (blob_stage2); @@ -473,17 +473,17 @@ fu_bcm57xx_firmware_write (FuFirmware *firmware, GError **error) /* add directory entries */ blob_dicts = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref); for (guint i = 0; i < 8; i++) { - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(GBytes) blob = NULL; img = fu_firmware_get_image_by_idx (firmware, 0x80 + i, NULL); if (img != NULL) { - blob = fu_firmware_image_write (img, error); + blob = fu_firmware_write (img, error); if (blob == NULL) return NULL; } if (blob != NULL) { - fu_byte_array_append_uint32 (buf, fu_firmware_image_get_addr (img), G_BIG_ENDIAN); + fu_byte_array_append_uint32 (buf, fu_firmware_get_addr (img), G_BIG_ENDIAN); fu_byte_array_append_uint32 (buf, (g_bytes_get_size (blob) / sizeof(guint32)) | (guint32) fu_bcm57xx_dict_image_get_target (FU_BCM57XX_DICT_IMAGE (img)) << 24 | @@ -506,7 +506,7 @@ fu_bcm57xx_firmware_write (FuFirmware *firmware, GError **error) /* add info */ img_info = fu_firmware_get_image_by_id (firmware, "info", NULL); if (img_info != NULL) { - blob_info = fu_firmware_image_write (img_info, error); + blob_info = fu_firmware_write (img_info, error); if (blob_info == NULL) return NULL; } else { @@ -524,7 +524,7 @@ fu_bcm57xx_firmware_write (FuFirmware *firmware, GError **error) /* add vpd */ img_vpd = fu_firmware_get_image_by_id (firmware, "vpd", NULL); if (img_vpd != NULL) { - blob_vpd = fu_firmware_image_write (img_vpd, error); + blob_vpd = fu_firmware_write (img_vpd, error); if (blob_vpd == NULL) return NULL; } else { @@ -535,7 +535,7 @@ fu_bcm57xx_firmware_write (FuFirmware *firmware, GError **error) /* add info2 */ img_info2 = fu_firmware_get_image_by_id (firmware, "info2", NULL); if (img_info2 != NULL) { - blob_info2 = fu_firmware_image_write (img_info2, error); + blob_info2 = fu_firmware_write (img_info2, error); if (blob_info2 == NULL) return NULL; } else { diff --git a/plugins/bcm57xx/fu-bcm57xx-stage1-image.c b/plugins/bcm57xx/fu-bcm57xx-stage1-image.c index 28c353b5c..a39f9b0eb 100644 --- a/plugins/bcm57xx/fu-bcm57xx-stage1-image.c +++ b/plugins/bcm57xx/fu-bcm57xx-stage1-image.c @@ -13,14 +13,16 @@ #include "fu-bcm57xx-stage1-image.h" struct _FuBcm57xxStage1Image { - FuFirmwareImage parent_instance; + FuFirmware parent_instance; }; -G_DEFINE_TYPE (FuBcm57xxStage1Image, fu_bcm57xx_stage1_image, FU_TYPE_FIRMWARE_IMAGE) +G_DEFINE_TYPE (FuBcm57xxStage1Image, fu_bcm57xx_stage1_image, FU_TYPE_FIRMWARE) static gboolean -fu_bcm57xx_stage1_image_parse (FuFirmwareImage *image, +fu_bcm57xx_stage1_image_parse (FuFirmware *image, GBytes *fw, + guint64 addr_start, + guint64 addr_end, FwupdInstallFlags flags, GError **error) { @@ -42,7 +44,7 @@ fu_bcm57xx_stage1_image_parse (FuFirmwareImage *image, if (fwversion != 0x0) { g_autofree gchar *tmp = NULL; tmp = fu_common_version_from_uint32 (fwversion, FWUPD_VERSION_FORMAT_TRIPLET); - fu_firmware_image_set_version (image, tmp); + fu_firmware_set_version (image, tmp); } else { guint32 bufver[4] = { '\0' }; guint32 veraddr = 0x0; @@ -66,7 +68,7 @@ fu_bcm57xx_stage1_image_parse (FuFirmwareImage *image, return FALSE; veritem = fu_bcm57xx_veritem_new ((guint8 *) bufver, sizeof(bufver)); if (veritem != NULL) - fu_firmware_image_set_version (image, veritem->version); + fu_firmware_set_version (image, veritem->version); } fw_nocrc = fu_common_bytes_new_offset (fw, 0x0, @@ -74,12 +76,12 @@ fu_bcm57xx_stage1_image_parse (FuFirmwareImage *image, error); if (fw_nocrc == NULL) return FALSE; - fu_firmware_image_set_bytes (image, fw_nocrc); + fu_firmware_set_bytes (image, fw_nocrc); return TRUE; } static GBytes * -fu_bcm57xx_stage1_image_write (FuFirmwareImage *image, GError **error) +fu_bcm57xx_stage1_image_write (FuFirmware *image, GError **error) { const guint8 *buf; gsize bufsz = 0; @@ -89,14 +91,9 @@ fu_bcm57xx_stage1_image_write (FuFirmwareImage *image, GError **error) g_autoptr(GBytes) fw_align = NULL; /* get the CRC-less data */ - fw_nocrc = fu_firmware_image_get_bytes (image); - if (fw_nocrc == NULL) { - g_set_error_literal (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_SUPPORTED, - "not supported"); + fw_nocrc = fu_firmware_get_bytes (image, error); + if (fw_nocrc == NULL) return NULL; - } /* this has to be aligned by DWORDs */ fw_align = fu_common_bytes_align (fw_nocrc, sizeof(guint32), 0xff); @@ -120,13 +117,13 @@ fu_bcm57xx_stage1_image_init (FuBcm57xxStage1Image *self) static void fu_bcm57xx_stage1_image_class_init (FuBcm57xxStage1ImageClass *klass) { - FuFirmwareImageClass *klass_image = FU_FIRMWARE_IMAGE_CLASS (klass); + FuFirmwareClass *klass_image = FU_FIRMWARE_CLASS (klass); klass_image->parse = fu_bcm57xx_stage1_image_parse; klass_image->write = fu_bcm57xx_stage1_image_write; } -FuFirmwareImage * +FuFirmware * fu_bcm57xx_stage1_image_new (void) { - return FU_FIRMWARE_IMAGE (g_object_new (FU_TYPE_BCM57XX_STAGE1_IMAGE, NULL)); + return FU_FIRMWARE (g_object_new (FU_TYPE_BCM57XX_STAGE1_IMAGE, NULL)); } diff --git a/plugins/bcm57xx/fu-bcm57xx-stage1-image.h b/plugins/bcm57xx/fu-bcm57xx-stage1-image.h index c895a193a..41b4a58ce 100644 --- a/plugins/bcm57xx/fu-bcm57xx-stage1-image.h +++ b/plugins/bcm57xx/fu-bcm57xx-stage1-image.h @@ -6,9 +6,9 @@ #pragma once -#include "fu-firmware-image.h" +#include "fu-firmware.h" #define FU_TYPE_BCM57XX_STAGE1_IMAGE (fu_bcm57xx_stage1_image_get_type ()) -G_DECLARE_FINAL_TYPE (FuBcm57xxStage1Image, fu_bcm57xx_stage1_image, FU, BCM57XX_STAGE1_IMAGE, FuFirmwareImage) +G_DECLARE_FINAL_TYPE (FuBcm57xxStage1Image, fu_bcm57xx_stage1_image, FU, BCM57XX_STAGE1_IMAGE, FuFirmware) -FuFirmwareImage *fu_bcm57xx_stage1_image_new (void); +FuFirmware *fu_bcm57xx_stage1_image_new (void); diff --git a/plugins/bcm57xx/fu-bcm57xx-stage2-image.c b/plugins/bcm57xx/fu-bcm57xx-stage2-image.c index 577cbb1a1..ce07ae239 100644 --- a/plugins/bcm57xx/fu-bcm57xx-stage2-image.c +++ b/plugins/bcm57xx/fu-bcm57xx-stage2-image.c @@ -12,14 +12,16 @@ #include "fu-bcm57xx-stage2-image.h" struct _FuBcm57xxStage2Image { - FuFirmwareImage parent_instance; + FuFirmware parent_instance; }; -G_DEFINE_TYPE (FuBcm57xxStage2Image, fu_bcm57xx_stage2_image, FU_TYPE_FIRMWARE_IMAGE) +G_DEFINE_TYPE (FuBcm57xxStage2Image, fu_bcm57xx_stage2_image, FU_TYPE_FIRMWARE) static gboolean -fu_bcm57xx_stage2_image_parse (FuFirmwareImage *image, +fu_bcm57xx_stage2_image_parse (FuFirmware *image, GBytes *fw, + guint64 addr_start, + guint64 addr_end, FwupdInstallFlags flags, GError **error) { @@ -33,12 +35,12 @@ fu_bcm57xx_stage2_image_parse (FuFirmwareImage *image, error); if (fw_nocrc == NULL) return FALSE; - fu_firmware_image_set_bytes (image, fw_nocrc); + fu_firmware_set_bytes (image, fw_nocrc); return TRUE; } static GBytes * -fu_bcm57xx_stage2_image_write (FuFirmwareImage *image, GError **error) +fu_bcm57xx_stage2_image_write (FuFirmware *image, GError **error) { const guint8 *buf; gsize bufsz = 0; @@ -46,14 +48,9 @@ fu_bcm57xx_stage2_image_write (FuFirmwareImage *image, GError **error) g_autoptr(GBytes) fw_nocrc = NULL; /* get the CRC-less data */ - fw_nocrc = fu_firmware_image_get_bytes (image); - if (fw_nocrc == NULL) { - g_set_error_literal (error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_SUPPORTED, - "not supported"); + fw_nocrc = fu_firmware_get_bytes (image, error); + if (fw_nocrc == NULL) return NULL; - } /* add to a mutable buffer */ buf = g_bytes_get_data (fw_nocrc, &bufsz); @@ -77,13 +74,13 @@ fu_bcm57xx_stage2_image_init (FuBcm57xxStage2Image *self) static void fu_bcm57xx_stage2_image_class_init (FuBcm57xxStage2ImageClass *klass) { - FuFirmwareImageClass *klass_image = FU_FIRMWARE_IMAGE_CLASS (klass); + FuFirmwareClass *klass_image = FU_FIRMWARE_CLASS (klass); klass_image->parse = fu_bcm57xx_stage2_image_parse; klass_image->write = fu_bcm57xx_stage2_image_write; } -FuFirmwareImage * +FuFirmware * fu_bcm57xx_stage2_image_new (void) { - return FU_FIRMWARE_IMAGE (g_object_new (FU_TYPE_BCM57XX_STAGE2_IMAGE, NULL)); + return FU_FIRMWARE (g_object_new (FU_TYPE_BCM57XX_STAGE2_IMAGE, NULL)); } diff --git a/plugins/bcm57xx/fu-bcm57xx-stage2-image.h b/plugins/bcm57xx/fu-bcm57xx-stage2-image.h index b971e1ace..7de688673 100644 --- a/plugins/bcm57xx/fu-bcm57xx-stage2-image.h +++ b/plugins/bcm57xx/fu-bcm57xx-stage2-image.h @@ -6,9 +6,9 @@ #pragma once -#include "fu-firmware-image.h" +#include "fu-firmware.h" #define FU_TYPE_BCM57XX_STAGE2_IMAGE (fu_bcm57xx_stage2_image_get_type ()) -G_DECLARE_FINAL_TYPE (FuBcm57xxStage2Image, fu_bcm57xx_stage2_image, FU, BCM57XX_STAGE2_IMAGE, FuFirmwareImage) +G_DECLARE_FINAL_TYPE (FuBcm57xxStage2Image, fu_bcm57xx_stage2_image, FU, BCM57XX_STAGE2_IMAGE, FuFirmware) -FuFirmwareImage *fu_bcm57xx_stage2_image_new (void); +FuFirmware *fu_bcm57xx_stage2_image_new (void); diff --git a/plugins/ccgx/fu-ccgx-dmc-device.c b/plugins/ccgx/fu-ccgx-dmc-device.c index 56a45c2d1..45a222843 100644 --- a/plugins/ccgx/fu-ccgx-dmc-device.c +++ b/plugins/ccgx/fu-ccgx-dmc-device.c @@ -339,7 +339,7 @@ fu_ccgx_dmc_get_image_write_status_cb (FuDevice *device, gpointer user_data, GEr static gboolean fu_ccgx_dmc_write_firmware_image (FuDevice *device, - FuCcgxDmcFirmwareImageRecord *img_rcd, + FuCcgxDmcFirmwareRecord *img_rcd, gsize *fw_data_written, const gsize fw_data_size, GError **error) @@ -400,7 +400,7 @@ fu_ccgx_dmc_write_firmware (FuDevice *device, GError **error) { FuCcgxDmcDevice *self = FU_CCGX_DMC_DEVICE (device); - FuCcgxDmcFirmwareImageRecord *img_rcd = NULL; + FuCcgxDmcFirmwareRecord *img_rcd = NULL; DmcIntRqt dmc_int_rqt = {0}; GBytes *custom_meta_blob; GBytes *fwct_blob; diff --git a/plugins/ccgx/fu-ccgx-dmc-firmware.c b/plugins/ccgx/fu-ccgx-dmc-firmware.c index 654948cb4..d30d7d300 100644 --- a/plugins/ccgx/fu-ccgx-dmc-firmware.c +++ b/plugins/ccgx/fu-ccgx-dmc-firmware.c @@ -28,7 +28,7 @@ struct _FuCcgxDmcFirmware { G_DEFINE_TYPE (FuCcgxDmcFirmware, fu_ccgx_dmc_firmware, FU_TYPE_FIRMWARE) static void -fu_ccgx_dmc_firmware_image_record_free (FuCcgxDmcFirmwareImageRecord *rcd) +fu_ccgx_dmc_firmware_record_free (FuCcgxDmcFirmwareRecord *rcd) { if (rcd->seg_records != NULL) g_ptr_array_unref (rcd->seg_records); @@ -43,7 +43,7 @@ fu_ccgx_dmc_firmware_segment_record_free (FuCcgxDmcFirmwareSegmentRecord *rcd) g_free (rcd); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC(FuCcgxDmcFirmwareImageRecord, fu_ccgx_dmc_firmware_image_record_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(FuCcgxDmcFirmwareRecord, fu_ccgx_dmc_firmware_record_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC(FuCcgxDmcFirmwareSegmentRecord, fu_ccgx_dmc_firmware_segment_record_free) GPtrArray * @@ -86,7 +86,7 @@ static gboolean fu_ccgx_dmc_firmware_parse_segment (FuFirmware *firmware, const guint8 *buf, gsize bufsz, - FuCcgxDmcFirmwareImageRecord *img_rcd, + FuCcgxDmcFirmwareRecord *img_rcd, gsize *seg_off, FwupdInstallFlags flags, GError **error) @@ -185,10 +185,10 @@ fu_ccgx_dmc_firmware_parse_image (FuFirmware *firmware, /* set initial segment info offset */ for (guint32 i = 0; i < image_count; i++) { - g_autoptr(FuCcgxDmcFirmwareImageRecord) img_rcd = NULL; + g_autoptr(FuCcgxDmcFirmwareRecord) img_rcd = NULL; /* read image info */ - img_rcd = g_new0 (FuCcgxDmcFirmwareImageRecord, 1); + img_rcd = g_new0 (FuCcgxDmcFirmwareRecord, 1); if (!fu_common_read_uint8_safe (buf, bufsz, img_off + G_STRUCT_OFFSET(FwctImageInfo, row_size), &img_rcd->row_size, error)) @@ -255,7 +255,7 @@ fu_ccgx_dmc_firmware_parse (FuFirmware *firmware, guint32 hdr_signature = 0; guint8 hdr_image_count = 0; const guint8 *buf = g_bytes_get_data (fw, &bufsz); - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); + g_autoptr(FuFirmware) img = fu_firmware_new_from_bytes (fw); /* check for 'F' 'W' 'C' 'T' in signature */ if (!fu_common_read_uint32_safe (buf, bufsz, 0x0, @@ -335,7 +335,7 @@ fu_ccgx_dmc_firmware_parse (FuFirmware *firmware, return FALSE; /* add something, although we'll use the records for the update */ - fu_firmware_image_set_addr (img, 0x0); + fu_firmware_set_addr (img, 0x0); fu_firmware_add_image (firmware, img); return TRUE; } @@ -388,9 +388,12 @@ fu_ccgx_dmc_firmware_write (FuFirmware *firmware, GError **error) /* add segments */ for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); - g_autoptr(GBytes) img_bytes = fu_firmware_image_get_bytes (img); - g_autoptr(GPtrArray) chunks = fu_chunk_array_new_from_bytes (img_bytes, 0x0, 0x0, 64); + FuFirmware *img = g_ptr_array_index (images, i); + g_autoptr(GPtrArray) chunks = NULL; + g_autoptr(GBytes) img_bytes = fu_firmware_get_bytes (img, error); + if (img_bytes == NULL) + return NULL; + chunks = fu_chunk_array_new_from_bytes (img_bytes, 0x0, 0x0, 64); fu_byte_array_append_uint8 (buf, 0x0); /* img_id */ fu_byte_array_append_uint8 (buf, 0x0); /* type */ fu_byte_array_append_uint16 (buf, 0x0, G_LITTLE_ENDIAN); /* start_row, unknown */ @@ -405,12 +408,12 @@ fu_ccgx_dmc_firmware_write (FuFirmware *firmware, GError **error) /* add image headers */ for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); + FuFirmware *img = g_ptr_array_index (images, i); gsize csumbufsz = DMC_HASH_SIZE; gsize img_offset = sizeof(FwctInfo) + (i * sizeof(FwctImageInfo)); guint8 csumbuf[DMC_HASH_SIZE] = { 0x0 }; g_autoptr(GChecksum) csum = g_checksum_new (G_CHECKSUM_SHA256); - g_autoptr(GBytes) img_bytes = fu_firmware_image_get_bytes (img); + g_autoptr(GBytes) img_bytes = fu_firmware_get_bytes (img, NULL); g_autoptr(GBytes) img_padded = NULL; g_autoptr(GPtrArray) chunks = NULL; @@ -438,7 +441,7 @@ fu_ccgx_dmc_firmware_write (FuFirmware *firmware, GError **error) static void fu_ccgx_dmc_firmware_init (FuCcgxDmcFirmware *self) { - self->image_records = g_ptr_array_new_with_free_func ((GFreeFunc) fu_ccgx_dmc_firmware_image_record_free); + self->image_records = g_ptr_array_new_with_free_func ((GFreeFunc) fu_ccgx_dmc_firmware_record_free); fu_firmware_add_flag (FU_FIRMWARE (self), FU_FIRMWARE_FLAG_HAS_CHECKSUM); } diff --git a/plugins/ccgx/fu-ccgx-dmc-firmware.h b/plugins/ccgx/fu-ccgx-dmc-firmware.h index fd9929b90..c3ee5a5b3 100644 --- a/plugins/ccgx/fu-ccgx-dmc-firmware.h +++ b/plugins/ccgx/fu-ccgx-dmc-firmware.h @@ -25,7 +25,7 @@ typedef struct { guint8 img_digest[32]; guint8 num_img_segments; GPtrArray *seg_records; -} FuCcgxDmcFirmwareImageRecord; +} FuCcgxDmcFirmwareRecord; FuFirmware *fu_ccgx_dmc_firmware_new (void); GPtrArray *fu_ccgx_dmc_firmware_get_image_records (FuCcgxDmcFirmware *self); diff --git a/plugins/ccgx/fu-ccgx-firmware.c b/plugins/ccgx/fu-ccgx-firmware.c index e137e0047..bb9b5b081 100644 --- a/plugins/ccgx/fu-ccgx-firmware.c +++ b/plugins/ccgx/fu-ccgx-firmware.c @@ -159,7 +159,6 @@ fu_ccgx_firmware_record_calc_checksum (FuCcgxFirmwareRecord *rcd) static gboolean fu_ccgx_firmware_parse_md_block (FuCcgxFirmware *self, - FuFirmwareImage *img, FwupdInstallFlags flags, GError **error) { @@ -289,7 +288,6 @@ fu_ccgx_firmware_parse (FuFirmware *firmware, guint32 device_id = 0; const gchar *data = g_bytes_get_data (fw, &sz); g_auto(GStrv) lines = fu_common_strnsplit (data, sz, "\n", -1); - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); /* parse header */ if (lines[0] == NULL) { @@ -335,17 +333,17 @@ fu_ccgx_firmware_parse (FuFirmware *firmware, /* address is first data entry */ if (self->records->len > 0) { FuCcgxFirmwareRecord *rcd = g_ptr_array_index (self->records, 0); - fu_firmware_image_set_addr (img, rcd->row_number); + fu_firmware_set_addr (firmware, rcd->row_number); } /* parse metadata block */ - if (!fu_ccgx_firmware_parse_md_block (self, img, flags, error)) { + if (!fu_ccgx_firmware_parse_md_block (self, flags, error)) { g_prefix_error (error, "failed to parse metadata: "); return FALSE; } /* add something, although we'll use the records for the update */ - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, fw); return TRUE; } @@ -405,7 +403,7 @@ fu_ccgx_firmware_write (FuFirmware *firmware, GError **error) (guint) 0x0); /* Checksum, or 0x0 */ /* add image in chunks */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return NULL; chunks = fu_chunk_array_new_from_bytes (fw, 0x0, 0x0, 0x100); diff --git a/plugins/colorhug/fu-colorhug-device.c b/plugins/colorhug/fu-colorhug-device.c index 6e43e424a..ba58e5432 100644 --- a/plugins/colorhug/fu-colorhug-device.c +++ b/plugins/colorhug/fu-colorhug-device.c @@ -378,7 +378,7 @@ fu_colorhug_device_write_firmware (FuDevice *device, g_autoptr(GPtrArray) chunks = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/cros-ec/fu-cros-ec-firmware.c b/plugins/cros-ec/fu-cros-ec-firmware.c index 12001174c..25efb3b83 100644 --- a/plugins/cros-ec/fu-cros-ec-firmware.c +++ b/plugins/cros-ec/fu-cros-ec-firmware.c @@ -73,8 +73,8 @@ fu_cros_ec_firmware_parse (FuFirmware *firmware, FuCrosEcFirmwareSection *section = g_ptr_array_index (self->sections, i); const gchar *fmap_name; const gchar *fmap_fwid_name; - g_autoptr(FuFirmwareImage) img = NULL; - g_autoptr(FuFirmwareImage) fwid_img = NULL; + g_autoptr(FuFirmware) img = NULL; + g_autoptr(FuFirmware) fwid_img = NULL; g_autoptr(GBytes) payload_bytes = NULL; g_autoptr(GBytes) fwid_bytes = NULL; @@ -108,7 +108,7 @@ fu_cros_ec_firmware_parse (FuFirmware *firmware, fmap_fwid_name); return FALSE; } - fwid_bytes = fu_firmware_image_write (fwid_img, error); + fwid_bytes = fu_firmware_write (fwid_img, error); if (fwid_bytes == NULL) { g_prefix_error (error, "unable to get bytes from %s: ", @@ -122,17 +122,17 @@ fu_cros_ec_firmware_parse (FuFirmware *firmware, g_bytes_get_size (fwid_bytes), error)) return FALSE; - payload_bytes = fu_firmware_image_write (img, error); + payload_bytes = fu_firmware_write (img, error); if (payload_bytes == NULL) { g_prefix_error (error, "unable to get bytes from %s: ", fmap_name); return FALSE; } - section->offset = fu_firmware_image_get_addr (img); + section->offset = fu_firmware_get_addr (img); section->size = g_bytes_get_size (payload_bytes); - fu_firmware_image_set_version (img, section->raw_version); - section->image_idx = fu_firmware_image_get_idx (img); + fu_firmware_set_version (img, section->raw_version); + section->image_idx = fu_firmware_get_idx (img); if (!fu_cros_ec_parse_version (section->raw_version, §ion->version, diff --git a/plugins/dell-dock/fu-dell-dock-hub.c b/plugins/dell-dock/fu-dell-dock-hub.c index 3fdfaccda..2e30447ad 100644 --- a/plugins/dell-dock/fu-dell-dock-hub.c +++ b/plugins/dell-dock/fu-dell-dock-hub.c @@ -65,7 +65,7 @@ fu_dell_dock_hub_write_fw (FuDevice *device, g_return_val_if_fail (FU_IS_FIRMWARE (firmware), FALSE); /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; data = g_bytes_get_data (fw, &fw_size); diff --git a/plugins/dell-dock/fu-dell-dock-i2c-ec.c b/plugins/dell-dock/fu-dell-dock-i2c-ec.c index 85a2f1cd3..793dcb391 100644 --- a/plugins/dell-dock/fu-dell-dock-i2c-ec.c +++ b/plugins/dell-dock/fu-dell-dock-i2c-ec.c @@ -777,7 +777,7 @@ fu_dell_dock_ec_write_fw (FuDevice *device, g_return_val_if_fail (FU_IS_FIRMWARE (firmware), FALSE); /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; data = g_bytes_get_data (fw, &fw_size); diff --git a/plugins/dell-dock/fu-dell-dock-i2c-mst.c b/plugins/dell-dock/fu-dell-dock-i2c-mst.c index c42a3bdfe..9aac6846d 100644 --- a/plugins/dell-dock/fu-dell-dock-i2c-mst.c +++ b/plugins/dell-dock/fu-dell-dock-i2c-mst.c @@ -753,7 +753,7 @@ fu_dell_dock_mst_write_fw (FuDevice *device, g_return_val_if_fail (fu_device_get_proxy (device) != NULL, FALSE); /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; data = g_bytes_get_data (fw, NULL); diff --git a/plugins/dell-dock/fu-dell-dock-i2c-tbt.c b/plugins/dell-dock/fu-dell-dock-i2c-tbt.c index 2177726e4..6f9d686cf 100644 --- a/plugins/dell-dock/fu-dell-dock-i2c-tbt.c +++ b/plugins/dell-dock/fu-dell-dock-i2c-tbt.c @@ -69,7 +69,7 @@ fu_dell_dock_tbt_write_fw (FuDevice *device, g_return_val_if_fail (FU_IS_FIRMWARE (firmware), FALSE); /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; buffer = g_bytes_get_data (fw, &image_size); diff --git a/plugins/dell-dock/fu-dell-dock-status.c b/plugins/dell-dock/fu-dell-dock-status.c index d3dae678f..1a89edbd7 100644 --- a/plugins/dell-dock/fu-dell-dock-status.c +++ b/plugins/dell-dock/fu-dell-dock-status.c @@ -75,7 +75,7 @@ fu_dell_dock_status_write (FuDevice *device, g_return_val_if_fail (FU_IS_FIRMWARE (firmware), FALSE); /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; data = g_bytes_get_data (fw, &length); diff --git a/plugins/dfu-csr/fu-dfu-csr-device.c b/plugins/dfu-csr/fu-dfu-csr-device.c index 843f76779..34e5465a1 100644 --- a/plugins/dfu-csr/fu-dfu-csr-device.c +++ b/plugins/dfu-csr/fu-dfu-csr-device.c @@ -368,7 +368,7 @@ fu_dfu_csr_device_download (FuDevice *device, g_autoptr(GPtrArray) chunks = NULL; /* get default image */ - blob = fu_firmware_get_image_default_bytes (firmware, error); + blob = fu_firmware_get_bytes (firmware, error); if (blob == NULL) return FALSE; diff --git a/plugins/dfu/fu-dfu-device.c b/plugins/dfu/fu-dfu-device.c index 798541248..b76d6f36f 100644 --- a/plugins/dfu/fu-dfu-device.c +++ b/plugins/dfu/fu-dfu-device.c @@ -1657,7 +1657,7 @@ fu_dfu_device_download (FuDfuDevice *self, return FALSE; } for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *image = g_ptr_array_index (images, i); + FuFirmware *image = g_ptr_array_index (images, i); FuDfuTargetTransferFlags flags_local = DFU_TARGET_TRANSFER_FLAG_NONE; const gchar *alt_name; guint8 alt; @@ -1666,7 +1666,7 @@ fu_dfu_device_download (FuDfuDevice *self, g_autoptr(FuDfuTarget) target_tmp = NULL; g_autoptr(GError) error_local = NULL; - alt = fu_firmware_image_get_idx (image); + alt = fu_firmware_get_idx (image); target_tmp = fu_dfu_device_get_target_by_alt_setting (self, alt, error); if (target_tmp == NULL) return FALSE; diff --git a/plugins/dfu/fu-dfu-target.c b/plugins/dfu/fu-dfu-target.c index 02e219162..96d708796 100644 --- a/plugins/dfu/fu-dfu-target.c +++ b/plugins/dfu/fu-dfu-target.c @@ -15,7 +15,7 @@ * want to update one target on the device. Most users will want to * update all the targets on the device at the same time. * - * See also: #FuDfuDevice, #FuFirmwareImage + * See also: #FuDfuDevice, #FuFirmware */ #include "config.h" @@ -1082,7 +1082,7 @@ fu_dfu_target_upload (FuDfuTarget *self, guint16 zone_cur; guint32 zone_size = 0; guint32 zone_last = G_MAXUINT; - g_autoptr(FuFirmwareImage) image = NULL; + g_autoptr(FuFirmware) image = NULL; g_return_val_if_fail (FU_IS_DFU_TARGET (self), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -1114,9 +1114,9 @@ fu_dfu_target_upload (FuDfuTarget *self, } /* create a new image */ - image = fu_firmware_image_new (NULL); - fu_firmware_image_set_id (image, priv->alt_name); - fu_firmware_image_set_idx (image, priv->alt_setting); + image = fu_firmware_new (); + fu_firmware_set_id (image, priv->alt_name); + fu_firmware_set_idx (image, priv->alt_setting); /* get all the sectors for the device */ for (guint i = 0; i < priv->sectors->len; i++) { @@ -1145,7 +1145,7 @@ fu_dfu_target_upload (FuDfuTarget *self, return FALSE; /* this chunk was uploaded okay */ - fu_firmware_image_add_chunk (image, chk); + fu_firmware_add_chunk (image, chk); } /* success */ @@ -1299,7 +1299,7 @@ fu_dfu_target_download_element (FuDfuTarget *self, /** * fu_dfu_target_download: * @self: a #FuDfuTarget - * @image: a #FuFirmwareImage + * @image: a #FuFirmware * @flags: flags to use, e.g. %DFU_TARGET_TRANSFER_FLAG_VERIFY * @error: a #GError, or %NULL * @@ -1310,7 +1310,7 @@ fu_dfu_target_download_element (FuDfuTarget *self, **/ gboolean fu_dfu_target_download (FuDfuTarget *self, - FuFirmwareImage *image, + FuFirmware *image, FuDfuTargetTransferFlags flags, GError **error) { @@ -1318,7 +1318,7 @@ fu_dfu_target_download (FuDfuTarget *self, g_autoptr(GPtrArray) chunks = NULL; g_return_val_if_fail (FU_IS_DFU_TARGET (self), FALSE); - g_return_val_if_fail (FU_IS_FIRMWARE_IMAGE (image), FALSE); + g_return_val_if_fail (FU_IS_FIRMWARE (image), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); /* ensure populated */ @@ -1339,7 +1339,7 @@ fu_dfu_target_download (FuDfuTarget *self, return FALSE; /* download all chunks in the image to the device */ - chunks = fu_firmware_image_get_chunks (image, error); + chunks = fu_firmware_get_chunks (image, error); if (chunks == NULL) return FALSE; if (chunks->len == 0) { diff --git a/plugins/dfu/fu-dfu-target.h b/plugins/dfu/fu-dfu-target.h index bc9b385ff..6578e897c 100644 --- a/plugins/dfu/fu-dfu-target.h +++ b/plugins/dfu/fu-dfu-target.h @@ -81,7 +81,7 @@ gboolean fu_dfu_target_upload (FuDfuTarget *self, gboolean fu_dfu_target_setup (FuDfuTarget *self, GError **error); gboolean fu_dfu_target_download (FuDfuTarget *self, - FuFirmwareImage *image, + FuFirmware *image, FuDfuTargetTransferFlags flags, GError **error); gboolean fu_dfu_target_mass_erase (FuDfuTarget *self, diff --git a/plugins/dfu/fu-dfu-tool.c b/plugins/dfu/fu-dfu-tool.c index bbe59b39e..ffa335742 100644 --- a/plugins/dfu/fu-dfu-tool.c +++ b/plugins/dfu/fu-dfu-tool.c @@ -437,8 +437,8 @@ fu_dfu_tool_replace_data (FuDfuTool *self, gchar **values, GError **error) /* get each data segment */ images = fu_firmware_get_images (firmware); for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *image = g_ptr_array_index (images, i); - g_autoptr(GPtrArray) chunks = fu_firmware_image_get_chunks (image, error); + FuFirmware *image = g_ptr_array_index (images, i); + g_autoptr(GPtrArray) chunks = fu_firmware_get_chunks (image, error); if (chunks == NULL) return FALSE; for (guint j = 0; j < chunks->len; j++) { @@ -646,7 +646,7 @@ fu_dfu_tool_write_alt (FuDfuTool *self, gchar **values, GError **error) g_autofree gchar *str_debug = NULL; g_autoptr(FuDfuDevice) device = NULL; g_autoptr(FuFirmware) firmware = NULL; - g_autoptr(FuFirmwareImage) image = NULL; + g_autoptr(FuFirmware) image = NULL; g_autoptr(FuDfuTarget) target = NULL; g_autoptr(FuDeviceLocker) locker = NULL; g_autoptr(GFile) file = NULL; @@ -741,7 +741,7 @@ fu_dfu_tool_write_alt (FuDfuTool *self, gchar **values, GError **error) } } else { g_print ("WARNING: Using default firmware image\n"); - image = fu_firmware_get_image_default (firmware, error); + image = fu_firmware_get_image_by_id (firmware, NULL, error); if (image == NULL) return FALSE; } diff --git a/plugins/ebitdo/fu-ebitdo-device.c b/plugins/ebitdo/fu-ebitdo-device.c index 3b8581e90..e29d8cfdd 100644 --- a/plugins/ebitdo/fu-ebitdo-device.c +++ b/plugins/ebitdo/fu-ebitdo-device.c @@ -423,13 +423,11 @@ fu_ebitdo_device_write_firmware (FuDevice *device, /* get header and payload */ fw_hdr = fu_firmware_get_image_by_id_bytes (firmware, - FU_FIRMWARE_IMAGE_ID_HEADER, + FU_FIRMWARE_ID_HEADER, error); if (fw_hdr == NULL) return FALSE; - fw_payload = fu_firmware_get_image_by_id_bytes (firmware, - FU_FIRMWARE_IMAGE_ID_PAYLOAD, - error); + fw_payload = fu_firmware_get_bytes (firmware, error); if (fw_payload == NULL) return FALSE; diff --git a/plugins/ebitdo/fu-ebitdo-firmware.c b/plugins/ebitdo/fu-ebitdo-firmware.c index 5f0feb13c..5aecda22a 100644 --- a/plugins/ebitdo/fu-ebitdo-firmware.c +++ b/plugins/ebitdo/fu-ebitdo-firmware.c @@ -34,8 +34,7 @@ fu_ebitdo_firmware_parse (FuFirmware *firmware, FuEbitdoFirmwareHeader *hdr; guint32 payload_len; g_autofree gchar *version = NULL; - g_autoptr(FuFirmwareImage) img_hdr = fu_firmware_image_new (NULL); - g_autoptr(FuFirmwareImage) img_payload = fu_firmware_image_new (NULL); + g_autoptr(FuFirmware) img_hdr = fu_firmware_new (); g_autoptr(GBytes) fw_hdr = NULL; g_autoptr(GBytes) fw_payload = NULL; @@ -84,8 +83,8 @@ fu_ebitdo_firmware_parse (FuFirmware *firmware, error); if (fw_hdr == NULL) return FALSE; - fu_firmware_image_set_id (img_hdr, FU_FIRMWARE_IMAGE_ID_HEADER); - fu_firmware_image_set_bytes (img_hdr, fw_hdr); + fu_firmware_set_id (img_hdr, FU_FIRMWARE_ID_HEADER); + fu_firmware_set_bytes (img_hdr, fw_hdr); fu_firmware_add_image (firmware, img_hdr); /* add payload */ @@ -95,10 +94,9 @@ fu_ebitdo_firmware_parse (FuFirmware *firmware, error); if (fw_payload == NULL) return FALSE; - 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_bytes (img_payload, fw_payload); - fu_firmware_add_image (firmware, img_payload); + fu_firmware_set_id (firmware, FU_FIRMWARE_ID_PAYLOAD); + fu_firmware_set_addr (firmware, GUINT32_FROM_LE(hdr->destination_addr)); + fu_firmware_set_bytes (firmware, fw_payload); return TRUE; } diff --git a/plugins/elantp/fu-elantp-firmware.c b/plugins/elantp/fu-elantp-firmware.c index 99ba1d4cd..1770e57cd 100644 --- a/plugins/elantp/fu-elantp-firmware.c +++ b/plugins/elantp/fu-elantp-firmware.c @@ -59,7 +59,6 @@ fu_elantp_firmware_parse (FuFirmware *firmware, guint16 iap_addr_wrds; guint16 module_id_wrds; const guint8 *buf = g_bytes_get_data (fw, &bufsz); - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); /* presumably in words */ if (!fu_common_read_uint16_safe (buf, bufsz, ETP_IAP_START_ADDR_WRDS * 2, @@ -110,7 +109,7 @@ fu_elantp_firmware_parse (FuFirmware *firmware, } /* whole image */ - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, fw); return TRUE; } @@ -140,7 +139,7 @@ fu_elantp_firmware_write (FuFirmware *firmware, GError **error) g_autoptr(GBytes) blob = NULL; /* only one image supported */ - blob = fu_firmware_get_image_default_bytes (firmware, error); + blob = fu_firmware_get_bytes (firmware, error); if (blob == NULL) return NULL; diff --git a/plugins/elantp/fu-elantp-hid-device.c b/plugins/elantp/fu-elantp-hid-device.c index 99291e4e7..fff60e843 100644 --- a/plugins/elantp/fu-elantp-hid-device.c +++ b/plugins/elantp/fu-elantp-hid-device.c @@ -305,7 +305,7 @@ fu_elantp_hid_device_write_firmware (FuDevice *device, g_autoptr(GPtrArray) chunks = NULL; /* simple image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/elantp/fu-elantp-i2c-device.c b/plugins/elantp/fu-elantp-i2c-device.c index e8432b3fd..0bc6f1424 100644 --- a/plugins/elantp/fu-elantp-i2c-device.c +++ b/plugins/elantp/fu-elantp-i2c-device.c @@ -354,7 +354,7 @@ fu_elantp_i2c_device_write_firmware (FuDevice *device, g_autoptr(GPtrArray) chunks = NULL; /* simple image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/emmc/fu-emmc-device.c b/plugins/emmc/fu-emmc-device.c index d8f47710c..dbce8fa3e 100644 --- a/plugins/emmc/fu-emmc-device.c +++ b/plugins/emmc/fu-emmc-device.c @@ -336,7 +336,7 @@ fu_emmc_device_write_firmware (FuDevice *device, if (!fu_emmc_read_extcsd (FU_EMMC_DEVICE (device), ext_csd, sizeof (ext_csd), error)) return FALSE; - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; fw_size = g_bytes_get_size (fw); diff --git a/plugins/ep963x/fu-ep963x-device.c b/plugins/ep963x/fu-ep963x-device.c index 5c309f42e..7f2dd841e 100644 --- a/plugins/ep963x/fu-ep963x-device.c +++ b/plugins/ep963x/fu-ep963x-device.c @@ -224,7 +224,7 @@ fu_ep963x_device_write_firmware (FuDevice *device, g_autoptr(GPtrArray) blocks = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/ep963x/fu-ep963x-firmware.c b/plugins/ep963x/fu-ep963x-firmware.c index 2c7a41b27..7fa15020f 100644 --- a/plugins/ep963x/fu-ep963x-firmware.c +++ b/plugins/ep963x/fu-ep963x-firmware.c @@ -29,7 +29,6 @@ fu_ep963x_firmware_parse (FuFirmware *firmware, { gsize len = 0x0; const guint8 *data = g_bytes_get_data (fw, &len); - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); /* check size */ if (len != FU_EP963_FIRMWARE_SIZE) { @@ -51,7 +50,7 @@ fu_ep963x_firmware_parse (FuFirmware *firmware, } /* success */ - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, fw); return TRUE; } diff --git a/plugins/fastboot/fu-fastboot-device.c b/plugins/fastboot/fu-fastboot-device.c index 71813d35f..799e19763 100644 --- a/plugins/fastboot/fu-fastboot-device.c +++ b/plugins/fastboot/fu-fastboot-device.c @@ -616,7 +616,7 @@ fu_fastboot_device_write_firmware (FuDevice *device, g_autoptr(GBytes) fw = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/fresco-pd/fu-fresco-pd-device.c b/plugins/fresco-pd/fu-fresco-pd-device.c index d550e4f3d..3e683eca1 100644 --- a/plugins/fresco-pd/fu-fresco-pd-device.c +++ b/plugins/fresco-pd/fu-fresco-pd-device.c @@ -257,7 +257,7 @@ fu_fresco_pd_device_write_firmware (FuDevice *device, g_autoptr(GBytes) fw = NULL; /* get default blob, which we know is already bigger than FirmwareMin */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; buf = g_bytes_get_data (fw, &bufsz); diff --git a/plugins/fresco-pd/fu-fresco-pd-firmware.c b/plugins/fresco-pd/fu-fresco-pd-firmware.c index beab8fa94..302db833d 100644 --- a/plugins/fresco-pd/fu-fresco-pd-firmware.c +++ b/plugins/fresco-pd/fu-fresco-pd-firmware.c @@ -43,7 +43,6 @@ fu_fresco_pd_firmware_parse (FuFirmware *firmware, gsize bufsz = 0; const guint8 *buf = g_bytes_get_data (fw, &bufsz); g_autofree gchar *version = NULL; - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); /* read version block */ if (!fu_memcpy_safe (ver, sizeof(ver), 0x0, /* dst */ @@ -56,8 +55,8 @@ fu_fresco_pd_firmware_parse (FuFirmware *firmware, /* set version number */ version = fu_fresco_pd_version_from_buf (ver); - fu_firmware_image_set_version (img, version); - fu_firmware_add_image (firmware, img); + fu_firmware_set_version (firmware, version); + fu_firmware_set_bytes (firmware, fw); return TRUE; } diff --git a/plugins/goodix-moc/fu-goodixmoc-device.c b/plugins/goodix-moc/fu-goodixmoc-device.c index 2d90f28fc..813a63b40 100644 --- a/plugins/goodix-moc/fu-goodixmoc-device.c +++ b/plugins/goodix-moc/fu-goodixmoc-device.c @@ -335,7 +335,7 @@ fu_goodixmoc_device_write_firmware (FuDevice *device, g_autoptr(GPtrArray) chunks = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/hailuck/fu-hailuck-bl-device.c b/plugins/hailuck/fu-hailuck-bl-device.c index 96acb72b0..585792796 100644 --- a/plugins/hailuck/fu-hailuck-bl-device.c +++ b/plugins/hailuck/fu-hailuck-bl-device.c @@ -204,7 +204,7 @@ fu_hailuck_bl_device_write_firmware (FuDevice *device, g_autofree guint8 *chk0_data = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/hailuck/fu-hailuck-kbd-firmware.c b/plugins/hailuck/fu-hailuck-kbd-firmware.c index 25c15f7c5..a2f5c1fd0 100644 --- a/plugins/hailuck/fu-hailuck-kbd-firmware.c +++ b/plugins/hailuck/fu-hailuck-kbd-firmware.c @@ -25,7 +25,6 @@ fu_hailuck_kbd_firmware_parse (FuFirmware *firmware, GError **error) { GPtrArray *records = fu_ihex_firmware_get_records (FU_IHEX_FIRMWARE (firmware)); - g_autoptr(FuFirmwareImage) img = NULL; g_autoptr(GByteArray) buf = g_byte_array_new (); g_autoptr(GBytes) fw_new = NULL; @@ -76,8 +75,7 @@ fu_hailuck_kbd_firmware_parse (FuFirmware *firmware, /* whole image */ fw_new = g_byte_array_free_to_bytes (g_steal_pointer (&buf)); - img = fu_firmware_image_new (fw_new); - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, fw_new); return TRUE; } diff --git a/plugins/hailuck/fu-hailuck-tp-device.c b/plugins/hailuck/fu-hailuck-tp-device.c index 14abfdee4..26b3d7f39 100644 --- a/plugins/hailuck/fu-hailuck-tp-device.c +++ b/plugins/hailuck/fu-hailuck-tp-device.c @@ -109,7 +109,7 @@ fu_hailuck_tp_device_write_firmware (FuDevice *device, }; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/logitech-hidpp/fu-logitech-hidpp-bootloader-nordic.c b/plugins/logitech-hidpp/fu-logitech-hidpp-bootloader-nordic.c index 92447b41e..8f15b4f83 100644 --- a/plugins/logitech-hidpp/fu-logitech-hidpp-bootloader-nordic.c +++ b/plugins/logitech-hidpp/fu-logitech-hidpp-bootloader-nordic.c @@ -205,7 +205,7 @@ fu_logitech_hidpp_bootloader_nordic_write_firmware (FuDevice *device, g_autoptr(GPtrArray) reqs = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/logitech-hidpp/fu-logitech-hidpp-bootloader-texas.c b/plugins/logitech-hidpp/fu-logitech-hidpp-bootloader-texas.c index 9b99a89b5..89b2f817c 100644 --- a/plugins/logitech-hidpp/fu-logitech-hidpp-bootloader-texas.c +++ b/plugins/logitech-hidpp/fu-logitech-hidpp-bootloader-texas.c @@ -120,7 +120,7 @@ fu_logitech_hidpp_bootloader_texas_write_firmware (FuDevice *device, g_autoptr(FuLogitechHidPpBootloaderRequest) req = fu_logitech_hidpp_bootloader_request_new (); /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/logitech-hidpp/fu-logitech-hidpp-peripheral.c b/plugins/logitech-hidpp/fu-logitech-hidpp-peripheral.c index 4f55698ca..3aa1ab197 100644 --- a/plugins/logitech-hidpp/fu-logitech-hidpp-peripheral.c +++ b/plugins/logitech-hidpp/fu-logitech-hidpp-peripheral.c @@ -942,7 +942,7 @@ fu_logitech_hidpp_peripheral_write_firmware (FuDevice *device, } /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/modem-manager/fu-mm-device.c b/plugins/modem-manager/fu-mm-device.c index 48a1c89c3..1d42c17da 100644 --- a/plugins/modem-manager/fu-mm-device.c +++ b/plugins/modem-manager/fu-mm-device.c @@ -666,7 +666,7 @@ fu_mm_device_write_firmware (FuDevice *device, g_autoptr(GPtrArray) array = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/nvme/fu-nvme-device.c b/plugins/nvme/fu-nvme-device.c index ed5d806dc..eb41aff48 100644 --- a/plugins/nvme/fu-nvme-device.c +++ b/plugins/nvme/fu-nvme-device.c @@ -324,7 +324,7 @@ fu_nvme_device_write_firmware (FuDevice *device, self->write_block_size : 0x1000; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/pixart-rf/fu-pxi-device.c b/plugins/pixart-rf/fu-pxi-device.c index 7ca898d75..74d4368c1 100644 --- a/plugins/pixart-rf/fu-pxi-device.c +++ b/plugins/pixart-rf/fu-pxi-device.c @@ -206,7 +206,7 @@ fu_pxi_device_check_support_resume (FuPxiDevice *self, guint16 checksum_tmp = 0x0; /* get the default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; @@ -499,7 +499,7 @@ fu_pxi_device_fw_upgrade (FuPxiDevice *self, FuFirmware *firmware, GError **erro g_autoptr(GBytes) fw = NULL; g_autoptr(GByteArray) req = g_byte_array_new (); - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; buf = g_bytes_get_data (fw, &bufsz); @@ -551,7 +551,7 @@ fu_pxi_device_write_firmware (FuDevice *device, g_autoptr(GError) error_local = NULL; /* get the default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/pixart-rf/fu-pxi-firmware.c b/plugins/pixart-rf/fu-pxi-firmware.c index baaa4eac0..cef887c7a 100644 --- a/plugins/pixart-rf/fu-pxi-firmware.c +++ b/plugins/pixart-rf/fu-pxi-firmware.c @@ -35,7 +35,6 @@ fu_pxi_firmware_parse (FuFirmware *firmware, gsize bufsz = 0; guint32 version_raw = 0; guint8 fw_header[PIXART_RF_FW_HEADER_SIZE]; - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); /* get buf */ buf = g_bytes_get_data (fw, &bufsz); @@ -87,7 +86,7 @@ fu_pxi_firmware_parse (FuFirmware *firmware, } /* success */ - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, fw); return TRUE; } @@ -103,7 +102,7 @@ fu_pxi_firmware_write (FuFirmware *firmware, GError **error) }; /* data first */ - blob = fu_firmware_get_image_default_bytes (firmware, error); + blob = fu_firmware_get_bytes (firmware, error); if (blob == NULL) return NULL; buf = g_byte_array_sized_new (g_bytes_get_size (blob) + sizeof (fw_header)); diff --git a/plugins/rts54hid/fu-rts54hid-device.c b/plugins/rts54hid/fu-rts54hid-device.c index be0952c43..022b86472 100644 --- a/plugins/rts54hid/fu-rts54hid-device.c +++ b/plugins/rts54hid/fu-rts54hid-device.c @@ -264,7 +264,7 @@ fu_rts54hid_device_write_firmware (FuDevice *device, g_autoptr(GPtrArray) chunks = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/rts54hid/fu-rts54hid-module.c b/plugins/rts54hid/fu-rts54hid-module.c index 512e7a67b..ee78074c9 100644 --- a/plugins/rts54hid/fu-rts54hid-module.c +++ b/plugins/rts54hid/fu-rts54hid-module.c @@ -234,7 +234,7 @@ fu_rts54hid_module_write_firmware (FuDevice *module, g_autoptr(GPtrArray) chunks = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/rts54hub/fu-rts54hub-device.c b/plugins/rts54hub/fu-rts54hub-device.c index 4c8a6b4b5..ff4c0a4a5 100644 --- a/plugins/rts54hub/fu-rts54hub-device.c +++ b/plugins/rts54hub/fu-rts54hub-device.c @@ -404,7 +404,7 @@ fu_rts54hub_device_write_firmware (FuDevice *device, g_autoptr(GPtrArray) chunks = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/rts54hub/fu-rts54hub-rtd21xx-device.c b/plugins/rts54hub/fu-rts54hub-rtd21xx-device.c index d533b8e11..f5f7acc5d 100644 --- a/plugins/rts54hub/fu-rts54hub-rtd21xx-device.c +++ b/plugins/rts54hub/fu-rts54hub-rtd21xx-device.c @@ -392,7 +392,7 @@ fu_rts54hub_rtd21xx_device_write_firmware (FuDevice *device, return FALSE; /* simple image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; fwbuf = g_bytes_get_data (fw, &fwbufsz); diff --git a/plugins/solokey/fu-solokey-device.c b/plugins/solokey/fu-solokey-device.c index 95af4c67a..517d1b46d 100644 --- a/plugins/solokey/fu-solokey-device.c +++ b/plugins/solokey/fu-solokey-device.c @@ -438,22 +438,16 @@ fu_solokey_device_write_firmware (FuDevice *device, GError **error) { FuSolokeyDevice *self = FU_SOLOKEY_DEVICE (device); - g_autoptr(FuFirmwareImage) img = NULL; g_autoptr(GBytes) fw = NULL; g_autoptr(GBytes) fw_sig = NULL; g_autoptr(GPtrArray) chunks = NULL; - /* get main image */ - img = fu_firmware_get_image_by_id (firmware, NULL, error); - if (img == NULL) - return FALSE; - /* build packets */ - fw = fu_firmware_image_write (img, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; chunks = fu_chunk_array_new_from_bytes (fw, - fu_firmware_image_get_addr (img), + fu_firmware_get_addr (firmware), 0x00, /* page_sz */ 2048); @@ -486,7 +480,7 @@ fu_solokey_device_write_firmware (FuDevice *device, /* verify the signature and reboot back to runtime */ fw_sig = fu_firmware_get_image_by_id_bytes (firmware, - FU_FIRMWARE_IMAGE_ID_SIGNATURE, + FU_FIRMWARE_ID_SIGNATURE, error); if (fw_sig == NULL) return FALSE; diff --git a/plugins/solokey/fu-solokey-firmware.c b/plugins/solokey/fu-solokey-firmware.c index 67fc066dc..79cb2c8ac 100644 --- a/plugins/solokey/fu-solokey-firmware.c +++ b/plugins/solokey/fu-solokey-firmware.c @@ -39,8 +39,7 @@ fu_solokey_firmware_parse (FuFirmware *firmware, JsonObject *json_obj; const gchar *base64; g_autoptr(FuFirmware) ihex_firmware = fu_ihex_firmware_new (); - g_autoptr(FuFirmwareImage) img = NULL; - g_autoptr(FuFirmwareImage) img_sig = fu_firmware_image_new (NULL); + g_autoptr(FuFirmware) img_sig = fu_firmware_new (); g_autoptr(GBytes) fw_ihex = NULL; g_autoptr(GBytes) fw_sig = NULL; g_autoptr(GString) base64_websafe = NULL; @@ -90,10 +89,11 @@ fu_solokey_firmware_parse (FuFirmware *firmware, fw_ihex = _g_base64_decode_to_bytes (base64); if (!fu_firmware_parse (ihex_firmware, fw_ihex, flags, error)) return FALSE; - img = fu_firmware_get_image_default (ihex_firmware, error); - if (img == NULL) + fw = fu_firmware_get_bytes (ihex_firmware, error); + if (fw == NULL) return FALSE; - fu_firmware_add_image (firmware, img); + fu_firmware_set_addr (firmware, fu_firmware_get_addr (ihex_firmware)); + fu_firmware_set_bytes (firmware, fw); /* signature */ base64 = json_object_get_string_member (json_obj, "signature"); @@ -109,8 +109,8 @@ fu_solokey_firmware_parse (FuFirmware *firmware, fu_common_string_replace (base64_websafe, "_", "/"); g_string_append (base64_websafe, "=="); fw_sig = _g_base64_decode_to_bytes (base64_websafe->str); - fu_firmware_image_set_bytes (img_sig, fw_sig); - fu_firmware_image_set_id (img_sig, FU_FIRMWARE_IMAGE_ID_SIGNATURE); + fu_firmware_set_bytes (img_sig, fw_sig); + fu_firmware_set_id (img_sig, FU_FIRMWARE_ID_SIGNATURE); fu_firmware_add_image (firmware, img_sig); return TRUE; } diff --git a/plugins/superio/fu-superio-it89-device.c b/plugins/superio/fu-superio-it89-device.c index d24c3f28e..8f2921bfc 100644 --- a/plugins/superio/fu-superio-it89-device.c +++ b/plugins/superio/fu-superio-it89-device.c @@ -652,7 +652,7 @@ fu_superio_it89_device_write_firmware (FuDevice *device, return FALSE; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/synaptics-cxaudio/fu-synaptics-cxaudio-firmware.c b/plugins/synaptics-cxaudio/fu-synaptics-cxaudio-firmware.c index 3c4813ef2..f85c22f4b 100644 --- a/plugins/synaptics-cxaudio/fu-synaptics-cxaudio-firmware.c +++ b/plugins/synaptics-cxaudio/fu-synaptics-cxaudio-firmware.c @@ -146,7 +146,6 @@ fu_synaptics_cxaudio_firmware_parse (FuFirmware *firmware, GPtrArray *records = fu_srec_firmware_get_records (FU_SREC_FIRMWARE (firmware)); guint8 dev_kind_candidate = G_MAXUINT8; g_autofree guint8 *shadow = g_malloc0 (FU_SYNAPTICS_CXAUDIO_EEPROM_SHADOW_SIZE); - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); /* copy shadow EEPROM */ for (guint i = 0; i < records->len; i++) { @@ -281,7 +280,7 @@ fu_synaptics_cxaudio_firmware_parse (FuFirmware *firmware, } /* this isn't used, but it seems a good thing to add */ - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, fw); return TRUE; } diff --git a/plugins/synaptics-mst/fu-synaptics-mst-device.c b/plugins/synaptics-mst/fu-synaptics-mst-device.c index 21334008b..b2a4e55a5 100644 --- a/plugins/synaptics-mst/fu-synaptics-mst-device.c +++ b/plugins/synaptics-mst/fu-synaptics-mst-device.c @@ -819,7 +819,7 @@ fu_synaptics_mst_device_write_firmware (FuDevice *device, gsize payload_len; g_autoptr(FuDeviceLocker) locker = NULL; - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; payload_data = g_bytes_get_data (fw, &payload_len); diff --git a/plugins/synaptics-mst/fu-synaptics-mst-firmware.c b/plugins/synaptics-mst/fu-synaptics-mst-firmware.c index 090e9f0d0..b0a4593fa 100644 --- a/plugins/synaptics-mst/fu-synaptics-mst-firmware.c +++ b/plugins/synaptics-mst/fu-synaptics-mst-firmware.c @@ -43,13 +43,12 @@ fu_synaptics_mst_firmware_parse (FuFirmware *firmware, FuSynapticsMstFirmware *self = FU_SYNAPTICS_MST_FIRMWARE (firmware); const guint8 *buf; gsize bufsz; - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); buf = g_bytes_get_data (fw, &bufsz); if (!fu_common_read_uint16_safe (buf, bufsz, ADDR_CUSTOMER_ID, &self->board_id, G_BIG_ENDIAN, error)) return FALSE; - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, fw); return TRUE; } diff --git a/plugins/synaptics-prometheus/fu-synaprom-firmware.c b/plugins/synaptics-prometheus/fu-synaprom-firmware.c index 6f61adc1d..2aa84bbee 100644 --- a/plugins/synaptics-prometheus/fu-synaprom-firmware.c +++ b/plugins/synaptics-prometheus/fu-synaprom-firmware.c @@ -34,7 +34,7 @@ typedef struct __attribute__((packed)) { #define FU_SYNAPROM_FIRMWARE_TAG_MAX 0xfff0 #define FU_SYNAPROM_FIRMWARE_SIGSIZE 0x0100 -#define FU_SYNAPROM_FIRMWARE_IMAGE_COUNT_MAX 64 +#define FU_SYNAPROM_FIRMWARE_COUNT_MAX 64 static const gchar * fu_synaprom_firmware_tag_to_string (guint16 tag) @@ -90,7 +90,7 @@ fu_synaprom_firmware_parse (FuFirmware *firmware, guint32 hdrsz; guint32 tag; g_autoptr(GBytes) bytes = NULL; - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; /* verify item header */ memcpy (&header, buf, sizeof(header)); @@ -129,19 +129,19 @@ fu_synaprom_firmware_parse (FuFirmware *firmware, tag, fu_synaprom_firmware_tag_to_string (tag), hdrsz); - img = fu_firmware_image_new (bytes); - fu_firmware_image_set_idx (img, tag); - fu_firmware_image_set_id (img, fu_synaprom_firmware_tag_to_string (tag)); + img = fu_firmware_new_from_bytes (bytes); + fu_firmware_set_idx (img, tag); + fu_firmware_set_id (img, fu_synaprom_firmware_tag_to_string (tag)); fu_firmware_add_image (firmware, img); /* sanity check */ - if (img_cnt++ > FU_SYNAPROM_FIRMWARE_IMAGE_COUNT_MAX) { + if (img_cnt++ > FU_SYNAPROM_FIRMWARE_COUNT_MAX) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "maximum number of images exceeded, " "maximum is 0x%02x", - (guint) FU_SYNAPROM_FIRMWARE_IMAGE_COUNT_MAX); + (guint) FU_SYNAPROM_FIRMWARE_COUNT_MAX); return FALSE; } @@ -176,7 +176,7 @@ fu_synaprom_firmware_write (FuFirmware *firmware, GError **error) g_byte_array_append (blob, (const guint8 *) &hdr, sizeof(hdr)); /* add payload */ - payload = fu_firmware_get_image_default_bytes (firmware, error); + payload = fu_firmware_get_bytes (firmware, error); if (payload == NULL) return NULL; fu_byte_array_append_uint16 (blob, diff --git a/plugins/synaptics-rmi/fu-synaptics-rmi-firmware.c b/plugins/synaptics-rmi/fu-synaptics-rmi-firmware.c index 02fb17295..5d8ed59cf 100644 --- a/plugins/synaptics-rmi/fu-synaptics-rmi-firmware.c +++ b/plugins/synaptics-rmi/fu-synaptics-rmi-firmware.c @@ -154,13 +154,13 @@ fu_synaptics_rmi_firmware_add_image (FuFirmware *firmware, const gchar *id, GError **error) { g_autoptr(GBytes) bytes = NULL; - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; bytes = fu_common_bytes_new_offset (fw, offset, sz, error); if (bytes == NULL) return FALSE; - img = fu_firmware_image_new (bytes); - fu_firmware_image_set_id (img, id); + img = fu_firmware_new_from_bytes (bytes); + fu_firmware_set_id (img, id); fu_firmware_add_image (firmware, img); return TRUE; } @@ -516,14 +516,14 @@ fu_synaptics_rmi_firmware_write_v0x (FuFirmware *firmware, GError **error) FuSynapticsRmiFirmware *self = FU_SYNAPTICS_RMI_FIRMWARE (firmware); GByteArray *buf = g_byte_array_new (); gsize bufsz = 0; - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(GBytes) buf_blob = NULL; /* default image */ - img = fu_firmware_get_image_default (firmware, error); + img = fu_firmware_get_image_by_id (firmware, "ui", error); if (img == NULL) return NULL; - buf_blob = fu_firmware_image_write (img, error); + buf_blob = fu_firmware_write (img, error); if (buf_blob == NULL) return NULL; bufsz = g_bytes_get_size (buf_blob); @@ -553,7 +553,7 @@ fu_synaptics_rmi_firmware_write_v10 (FuFirmware *firmware, GError **error) FuSynapticsRmiFirmware *self = FU_SYNAPTICS_RMI_FIRMWARE (firmware); GByteArray *buf = g_byte_array_new (); gsize bufsz = 0; - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(GBytes) buf_blob = NULL; /* header | desc_hdr | offset_table | desc | flash_config | @@ -571,10 +571,10 @@ fu_synaptics_rmi_firmware_write_v10 (FuFirmware *firmware, GError **error) }; /* default image */ - img = fu_firmware_get_image_default (firmware, error); + img = fu_firmware_get_image_by_id (firmware, "ui", error); if (img == NULL) return NULL; - buf_blob = fu_firmware_image_write (img, error); + buf_blob = fu_firmware_write (img, error); if (buf_blob == NULL) return NULL; bufsz = g_bytes_get_size (buf_blob); diff --git a/plugins/thunderbolt/fu-thunderbolt-device.c b/plugins/thunderbolt/fu-thunderbolt-device.c index b49dd1c80..9c1125df8 100644 --- a/plugins/thunderbolt/fu-thunderbolt-device.c +++ b/plugins/thunderbolt/fu-thunderbolt-device.c @@ -743,7 +743,7 @@ fu_thunderbolt_device_write_firmware (FuDevice *device, g_autoptr(GBytes) blob_fw = NULL; /* get default image */ - blob_fw = fu_firmware_get_image_default_bytes (firmware, error); + blob_fw = fu_firmware_get_bytes (firmware, error); if (blob_fw == NULL) return FALSE; diff --git a/plugins/thunderbolt/fu-thunderbolt-firmware.c b/plugins/thunderbolt/fu-thunderbolt-firmware.c index 62c1fe2a3..4785f6fea 100644 --- a/plugins/thunderbolt/fu-thunderbolt-firmware.c +++ b/plugins/thunderbolt/fu-thunderbolt-firmware.c @@ -170,7 +170,7 @@ fu_thunderbolt_firmware_read_location (FuThunderboltFirmware *self, g_autoptr(GBytes) fw = NULL; /* get blob */ - fw = fu_firmware_get_image_default_bytes (FU_FIRMWARE (self), error); + fw = fu_firmware_get_bytes (FU_FIRMWARE (self), error); if (fw == NULL) return FALSE; srcbuf = g_bytes_get_data (fw, &srcbufsz); @@ -396,10 +396,9 @@ fu_thunderbolt_firmware_parse (FuFirmware *firmware, { 0 } }; g_autofree gchar *version_str = NULL; - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); /* add this straight away so we can read it without a self */ - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, fw); /* subclassed */ if (klass_firmware->parse != NULL) { diff --git a/plugins/uefi-capsule/fu-uefi-device.c b/plugins/uefi-capsule/fu-uefi-device.c index 8dafc5e7b..ec157df08 100644 --- a/plugins/uefi-capsule/fu-uefi-device.c +++ b/plugins/uefi-capsule/fu-uefi-device.c @@ -555,7 +555,7 @@ fu_uefi_device_write_firmware (FuDevice *device, } /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/uefi-dbx/fu-dbxtool.c b/plugins/uefi-dbx/fu-dbxtool.c index 2de667d13..01fec05b2 100644 --- a/plugins/uefi-dbx/fu-dbxtool.c +++ b/plugins/uefi-dbx/fu-dbxtool.c @@ -61,8 +61,8 @@ fu_dbxtool_siglist_inclusive (FuFirmware *outer, FuFirmware *inner) for (guint i = 0; i < sigs->len; i++) { FuEfiSignature *sig = g_ptr_array_index (sigs, i); g_autofree gchar *checksum = NULL; - g_autoptr(FuFirmwareImage) img = NULL; - checksum = fu_firmware_image_get_checksum (FU_FIRMWARE_IMAGE (sig), + g_autoptr(FuFirmware) img = NULL; + checksum = fu_firmware_get_checksum (FU_FIRMWARE (sig), G_CHECKSUM_SHA256, NULL); if (checksum == NULL) continue; @@ -181,7 +181,7 @@ main (int argc, char *argv[]) for (guint i = 0; i < sigs->len; i++) { FuEfiSignature *sig = g_ptr_array_index (sigs, i); g_autofree gchar *checksum = NULL; - checksum = fu_firmware_image_get_checksum (FU_FIRMWARE_IMAGE (sig), + checksum = fu_firmware_get_checksum (FU_FIRMWARE (sig), G_CHECKSUM_SHA256, NULL); g_print ("%4u: {%s} {%s} %s\n", diff --git a/plugins/uefi-dbx/fu-uefi-dbx-common.c b/plugins/uefi-dbx/fu-uefi-dbx-common.c index bd8fc4f0e..4a36f3b1f 100644 --- a/plugins/uefi-dbx/fu-uefi-dbx-common.c +++ b/plugins/uefi-dbx/fu-uefi-dbx-common.c @@ -52,7 +52,7 @@ fu_uefi_dbx_signature_list_validate_volume (FuEfiSignatureList *siglist, FuVolum for (guint i = 0; i < files->len; i++) { const gchar *fn = g_ptr_array_index (files, i); g_autofree gchar *checksum = NULL; - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(GError) error_local = NULL; /* get checksum of file */ diff --git a/plugins/uefi-dbx/fu-uefi-dbx-device.c b/plugins/uefi-dbx/fu-uefi-dbx-device.c index 40e812ada..d888795a3 100644 --- a/plugins/uefi-dbx/fu-uefi-dbx-device.c +++ b/plugins/uefi-dbx/fu-uefi-dbx-device.c @@ -29,7 +29,7 @@ fu_uefi_dbx_device_write_firmware (FuDevice *device, g_autoptr(GBytes) fw = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; @@ -119,9 +119,9 @@ fu_uefi_dbx_device_probe (FuDevice *device, GError **error) g_autofree gchar *devid1 = NULL; g_autofree gchar *devid2 = NULL; - checksum = fu_firmware_image_get_checksum (FU_FIRMWARE_IMAGE (sig), - G_CHECKSUM_SHA256, - error); + checksum = fu_firmware_get_checksum (FU_FIRMWARE (sig), + G_CHECKSUM_SHA256, + error); if (checksum == NULL) return FALSE; checksum_up = g_utf8_strup (checksum, -1); diff --git a/plugins/uefi-pk/fu-plugin-uefi-pk.c b/plugins/uefi-pk/fu-plugin-uefi-pk.c index c2957c702..41bbc6c99 100644 --- a/plugins/uefi-pk/fu-plugin-uefi-pk.c +++ b/plugins/uefi-pk/fu-plugin-uefi-pk.c @@ -81,7 +81,9 @@ fu_plugin_uefi_pk_parse_signature (FuPlugin *plugin, } /* parse certificate */ - blob = fu_firmware_image_get_bytes (FU_FIRMWARE_IMAGE (sig)); + blob = fu_firmware_get_bytes (FU_FIRMWARE (sig), error); + if (blob == NULL) + return FALSE; d.size = g_bytes_get_size (blob); d.data = (unsigned char *) g_bytes_get_data (blob, NULL); rc = gnutls_x509_crt_import (crt, &d, GNUTLS_X509_FMT_DER); @@ -125,7 +127,7 @@ gboolean fu_plugin_coldplug (FuPlugin *plugin, GError **error) { FuPluginData *priv = fu_plugin_get_data (plugin); - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(FuFirmware) pk = fu_efi_signature_list_new (); g_autoptr(GBytes) pk_blob = NULL; g_autoptr(GPtrArray) sigs = NULL; diff --git a/plugins/vli/fu-vli-pd-device.c b/plugins/vli/fu-vli-pd-device.c index d7714315e..7c581f95b 100644 --- a/plugins/vli/fu-vli-pd-device.c +++ b/plugins/vli/fu-vli-pd-device.c @@ -471,7 +471,7 @@ fu_vli_pd_device_write_firmware (FuDevice *device, g_autoptr(GBytes) fw = NULL; /* binary blob */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/vli/fu-vli-pd-firmware.c b/plugins/vli/fu-vli-pd-firmware.c index 209912464..f4f36dc74 100644 --- a/plugins/vli/fu-vli-pd-firmware.c +++ b/plugins/vli/fu-vli-pd-firmware.c @@ -78,7 +78,6 @@ fu_vli_pd_firmware_parse (FuFirmware *firmware, guint32 fwver; const guint8 *buf = g_bytes_get_data (fw, &bufsz); g_autofree gchar *fwver_str = NULL; - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); /* map header from new offset location */ if (!fu_memcpy_safe ((guint8 *) &self->hdr, sizeof(self->hdr), 0x0, @@ -153,7 +152,7 @@ fu_vli_pd_firmware_parse (FuFirmware *firmware, } /* whole image */ - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, fw); return TRUE; } diff --git a/plugins/vli/fu-vli-pd-parade-device.c b/plugins/vli/fu-vli-pd-parade-device.c index 82d371f65..9cb0cc382 100644 --- a/plugins/vli/fu-vli-pd-parade-device.c +++ b/plugins/vli/fu-vli-pd-parade-device.c @@ -447,7 +447,7 @@ fu_vli_pd_parade_device_write_firmware (FuDevice *device, g_autoptr(GPtrArray) blocks = NULL; /* simple image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/vli/fu-vli-usbhub-device.c b/plugins/vli/fu-vli-usbhub-device.c index 71f2426c8..4e2cccb57 100644 --- a/plugins/vli/fu-vli-usbhub-device.c +++ b/plugins/vli/fu-vli-usbhub-device.c @@ -713,7 +713,7 @@ fu_vli_usbhub_device_update_v1 (FuVliUsbhubDevice *self, g_autoptr(GBytes) fw = NULL; /* simple image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; @@ -815,7 +815,7 @@ fu_vli_usbhub_device_update_v2 (FuVliUsbhubDevice *self, FuFirmware *firmware, G g_autoptr(GBytes) fw = NULL; /* simple image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/vli/fu-vli-usbhub-firmware.c b/plugins/vli/fu-vli-usbhub-firmware.c index 6cb9d701e..cd77413cb 100644 --- a/plugins/vli/fu-vli-usbhub-firmware.c +++ b/plugins/vli/fu-vli-usbhub-firmware.c @@ -56,7 +56,6 @@ fu_vli_usbhub_firmware_parse (FuFirmware *firmware, guint16 version = 0x0; guint8 tmp = 0x0; const guint8 *buf = g_bytes_get_data (fw, &bufsz); - g_autoptr(FuFirmwareImage) img = fu_firmware_image_new (fw); /* map into header */ if (!fu_memcpy_safe ((guint8 *) &self->hdr, sizeof(self->hdr), 0x0, @@ -200,7 +199,7 @@ fu_vli_usbhub_firmware_parse (FuFirmware *firmware, } /* whole image */ - fu_firmware_add_image (firmware, img); + fu_firmware_set_bytes (firmware, fw); return TRUE; } diff --git a/plugins/vli/fu-vli-usbhub-pd-device.c b/plugins/vli/fu-vli-usbhub-pd-device.c index 072aa784d..0474ce917 100644 --- a/plugins/vli/fu-vli-usbhub-pd-device.c +++ b/plugins/vli/fu-vli-usbhub-pd-device.c @@ -201,7 +201,7 @@ fu_vli_usbhub_pd_device_write_firmware (FuDevice *device, g_autoptr(GBytes) fw = NULL; /* simple image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/vli/fu-vli-usbhub-rtd21xx-device.c b/plugins/vli/fu-vli-usbhub-rtd21xx-device.c index cc69fca20..57e3b1e57 100644 --- a/plugins/vli/fu-vli-usbhub-rtd21xx-device.c +++ b/plugins/vli/fu-vli-usbhub-rtd21xx-device.c @@ -313,7 +313,7 @@ fu_vli_usbhub_rtd21xx_device_write_firmware (FuDevice *device, return FALSE; /* simple image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; fwbuf = g_bytes_get_data (fw, &fwbufsz); diff --git a/plugins/wacom-raw/fu-wacom-device.c b/plugins/wacom-raw/fu-wacom-device.c index d96a14fc6..359fba832 100644 --- a/plugins/wacom-raw/fu-wacom-device.c +++ b/plugins/wacom-raw/fu-wacom-device.c @@ -215,27 +215,23 @@ fu_wacom_device_write_firmware (FuDevice *device, FuWacomDevice *self = FU_WACOM_DEVICE (device); FuWacomDevicePrivate *priv = GET_PRIVATE (self); FuWacomDeviceClass *klass = FU_WACOM_DEVICE_GET_CLASS (device); - g_autoptr(FuFirmwareImage) img = NULL; g_autoptr(GBytes) fw = NULL; g_autoptr(GPtrArray) chunks = NULL; /* use the correct image from the firmware */ - img = fu_firmware_get_image_default (firmware, error); - if (img == NULL) - return FALSE; g_debug ("using element at addr 0x%0x", - (guint) fu_firmware_image_get_addr (img)); + (guint) fu_firmware_get_addr (firmware)); /* check start address and size */ - if (fu_firmware_image_get_addr (img) != priv->flash_base_addr) { + if (fu_firmware_get_addr (firmware) != priv->flash_base_addr) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "base addr invalid: 0x%05x", - (guint) fu_firmware_image_get_addr (img)); + (guint) fu_firmware_get_addr (firmware)); return FALSE; } - fw = fu_firmware_image_write (img, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; if (g_bytes_get_size (fw) > priv->flash_size) { diff --git a/plugins/wacom-usb/fu-self-test.c b/plugins/wacom-usb/fu-self-test.c index 78de13a3a..482d544ab 100644 --- a/plugins/wacom-usb/fu-self-test.c +++ b/plugins/wacom-usb/fu-self-test.c @@ -21,7 +21,7 @@ fu_wac_firmware_parse_func (void) gboolean ret; g_autofree gchar *fn = NULL; g_autoptr(FuFirmware) firmware = fu_wac_firmware_new (); - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(GBytes) blob_block = NULL; g_autoptr(GBytes) bytes = NULL; g_autoptr(GError) error = NULL; @@ -40,12 +40,12 @@ fu_wac_firmware_parse_func (void) g_assert_true (ret); /* get image data */ - img = fu_firmware_get_image_default (firmware, &error); + img = fu_firmware_get_image_by_id (firmware, 0, &error); g_assert_no_error (error); g_assert_nonnull (img); /* get block */ - blob_block = fu_firmware_image_write_chunk (img, 0x8008000, 1024, &error); + blob_block = fu_firmware_write_chunk (img, 0x8008000, 1024, &error); g_assert_no_error (error); g_assert_nonnull (blob_block); fu_wac_buffer_dump ("IMG", FU_WAC_REPORT_ID_MODULE, diff --git a/plugins/wacom-usb/fu-wac-device.c b/plugins/wacom-usb/fu-wac-device.c index 0e57eef59..fce01ca0b 100644 --- a/plugins/wacom-usb/fu-wac-device.c +++ b/plugins/wacom-usb/fu-wac-device.c @@ -456,14 +456,14 @@ fu_wac_device_write_firmware (FuDevice *device, gsize blocks_done = 0; gsize blocks_total = 0; g_autofree guint32 *csum_local = NULL; - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; g_autoptr(GHashTable) fd_blobs = NULL; /* use the correct image from the firmware */ img = fu_firmware_get_image_by_idx (firmware, self->firmware_index == 1 ? 1 : 0, error); if (img == NULL) return FALSE; - g_debug ("using image at addr 0x%0x", (guint) fu_firmware_image_get_addr (img)); + g_debug ("using image at addr 0x%0x", (guint) fu_firmware_get_addr (img)); /* enter flash mode */ if (!fu_wac_device_switch_to_flash_loader (self, error)) @@ -505,7 +505,7 @@ fu_wac_device_write_firmware (FuDevice *device, if (fu_wav_device_flash_descriptor_is_wp (fd)) continue; - blob_tmp = fu_firmware_image_write_chunk (img, + blob_tmp = fu_firmware_write_chunk (img, fd->start_addr, fd->block_sz, NULL); diff --git a/plugins/wacom-usb/fu-wac-firmware.c b/plugins/wacom-usb/fu-wac-firmware.c index 1135eda48..aa5fc78df 100644 --- a/plugins/wacom-usb/fu-wac-firmware.c +++ b/plugins/wacom-usb/fu-wac-firmware.c @@ -187,8 +187,9 @@ fu_wac_firmware_parse (FuFirmware *firmware, /* end */ if (g_strcmp0 (cmd, "S7") == 0) { g_autoptr(GBytes) blob = NULL; + g_autoptr(GBytes) fw_srec = NULL; g_autoptr(FuFirmware) firmware_srec = fu_srec_firmware_new (); - g_autoptr(FuFirmwareImage) img = NULL; + g_autoptr(FuFirmware) img = NULL; FuFirmwareWacHeaderRecord *hdr; /* get the correct relocated start address */ @@ -213,10 +214,12 @@ fu_wac_firmware_parse (FuFirmware *firmware, blob = g_bytes_new (image_buffer->str, image_buffer->len); if (!fu_firmware_parse_full (firmware_srec, blob, hdr->addr, 0x0, flags, error)) return FALSE; - img = fu_firmware_get_image_default (firmware_srec, error); - if (img == NULL) + fw_srec = fu_firmware_get_bytes (firmware_srec, error); + if (fw_srec == NULL) return FALSE; - fu_firmware_image_set_idx (img, images_cnt); + fu_firmware_set_bytes (img, fw_srec); + fu_firmware_set_addr (img, fu_firmware_get_addr (firmware_srec)); + fu_firmware_set_idx (img, images_cnt); fu_firmware_add_image (firmware, img); images_cnt++; diff --git a/plugins/wacom-usb/fu-wac-module-bluetooth.c b/plugins/wacom-usb/fu-wac-module-bluetooth.c index 5c7ada5a7..fb18650f9 100644 --- a/plugins/wacom-usb/fu-wac-module-bluetooth.c +++ b/plugins/wacom-usb/fu-wac-module-bluetooth.c @@ -123,7 +123,7 @@ fu_wac_module_bluetooth_write_firmware (FuDevice *device, g_autoptr(GBytes) fw = NULL; /* get default image */ - fw = fu_firmware_get_image_default_bytes (firmware, error); + fw = fu_firmware_get_bytes (firmware, error); if (fw == NULL) return FALSE; diff --git a/plugins/wacom-usb/fu-wac-module-touch.c b/plugins/wacom-usb/fu-wac-module-touch.c index 3cc2b8d09..6b1bcbabb 100644 --- a/plugins/wacom-usb/fu-wac-module-touch.c +++ b/plugins/wacom-usb/fu-wac-module-touch.c @@ -41,23 +41,18 @@ fu_wac_module_touch_write_firmware (FuDevice *device, { FuWacModule *self = FU_WAC_MODULE (device); gsize blocks_total = 0; - g_autoptr(FuFirmwareImage) img = NULL; g_autoptr(GBytes) fw = NULL; g_autoptr(GPtrArray) chunks = NULL; - /* use the correct image from the firmware */ - img = fu_firmware_get_image_default (firmware, error); - if (img == NULL) - return FALSE; g_debug ("using element at addr 0x%0x", - (guint) fu_firmware_image_get_addr (img)); - fw = fu_firmware_image_write (img, error); - if (fw == NULL) - return FALSE; + (guint) fu_firmware_get_addr (firmware)); /* build each data packet */ + fw = fu_firmware_get_bytes (firmware, error); + if (fw == NULL) + return FALSE; chunks = fu_chunk_array_new_from_bytes (fw, - fu_firmware_image_get_addr (img), + fu_firmware_get_addr (firmware), 0x0, /* page_sz */ 128); /* packet_sz */ blocks_total = chunks->len + 2; diff --git a/src/fu-tool.c b/src/fu-tool.c index 64ac0f36f..6a0ca5f7d 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -1984,22 +1984,24 @@ fu_util_firmware_extract (FuUtilPrivate *priv, gchar **values, GError **error) g_print ("%s", str); images = fu_firmware_get_images (firmware); for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); + FuFirmware *img = g_ptr_array_index (images, i); g_autofree gchar *fn = NULL; g_autoptr(GBytes) blob_img = NULL; /* get raw image without generated header, footer or crc */ - blob_img = fu_firmware_image_get_bytes (img); - if (blob_img == NULL || g_bytes_get_size (blob_img) == 0) + blob_img = fu_firmware_get_bytes (img, error); + if (blob_img == NULL) + return FALSE; + if (g_bytes_get_size (blob_img) == 0) continue; /* use suitable filename */ - if (fu_firmware_image_get_filename (img) != NULL) { - fn = g_strdup (fu_firmware_image_get_filename (img)); - } else if (fu_firmware_image_get_id (img) != NULL) { - fn = g_strdup_printf ("id-%s.fw", fu_firmware_image_get_id (img)); - } else if (fu_firmware_image_get_idx (img) != 0x0) { - fn = g_strdup_printf ("idx-0x%x.fw", (guint) fu_firmware_image_get_idx (img)); + if (fu_firmware_get_filename (img) != NULL) { + fn = g_strdup (fu_firmware_get_filename (img)); + } else if (fu_firmware_get_id (img) != NULL) { + fn = g_strdup_printf ("id-%s.fw", fu_firmware_get_id (img)); + } else if (fu_firmware_get_idx (img) != 0x0) { + fn = g_strdup_printf ("idx-0x%x.fw", (guint) fu_firmware_get_idx (img)); } else { fn = g_strdup_printf ("img-0x%x.fw", i); } @@ -2179,7 +2181,7 @@ fu_util_firmware_convert (FuUtilPrivate *priv, gchar **values, GError **error) firmware_dst = g_object_new (gtype_dst, NULL); images = fu_firmware_get_images (firmware_src); for (guint i = 0; i < images->len; i++) { - FuFirmwareImage *img = g_ptr_array_index (images, i); + FuFirmware *img = g_ptr_array_index (images, i); fu_firmware_add_image (firmware_dst, img); } diff --git a/src/fuzzing/bcm57xx.builder.xml b/src/fuzzing/bcm57xx.builder.xml index ce7d36e04..3fc927055 100644 --- a/src/fuzzing/bcm57xx.builder.xml +++ b/src/fuzzing/bcm57xx.builder.xml @@ -1,18 +1,18 @@ 1.2.3 - + 7.8.9 stage1 0x01 bcm57xx-stage1.bin - - + + stage2 - - + + ape 0x7 aGVsbG8gd29ybGQ= - + diff --git a/src/fuzzing/ccgx-dmc.builder.xml b/src/fuzzing/ccgx-dmc.builder.xml index 00be2eb22..b7038c159 100644 --- a/src/fuzzing/ccgx-dmc.builder.xml +++ b/src/fuzzing/ccgx-dmc.builder.xml @@ -1,6 +1,4 @@ 0x1000800 - - aGVsbG8gd29ybGQ= - + aGVsbG8gd29ybGQ= diff --git a/src/fuzzing/ccgx.builder.xml b/src/fuzzing/ccgx.builder.xml index 8f4608739..8a7f181fe 100644 --- a/src/fuzzing/ccgx.builder.xml +++ b/src/fuzzing/ccgx.builder.xml @@ -1,6 +1,4 @@ 0x1F00 - - aGVsbG8gd29ybGQ= - + aGVsbG8gd29ybGQ= diff --git a/src/fuzzing/cros-ec.builder.xml b/src/fuzzing/cros-ec.builder.xml index 2072504d4..9d784c6c3 100644 --- a/src/fuzzing/cros-ec.builder.xml +++ b/src/fuzzing/cros-ec.builder.xml @@ -1,19 +1,19 @@ 0x3000 - + RO_FRID Y2hlZXNlX3YxLjEuMTc1NS00ZGE5NTIwICAgICAgICA= - - + + RW_FWID Y2hlZXNlX3YxLjEuMTc1NS00ZGE5NTIwICAgICAgICA= - - + + EC_RO Y2hlZXNlX3YxLjEuMTc1NS00ZGE5NTIwICAgICAgICA= - - + + EC_RW Y2hlZXNlX3YxLjEuMTc1NS00ZGE5NTIwICAgICAgICA= - + diff --git a/src/fuzzing/dfuse.builder.xml b/src/fuzzing/dfuse.builder.xml index 0aea91a78..378628fab 100644 --- a/src/fuzzing/dfuse.builder.xml +++ b/src/fuzzing/dfuse.builder.xml @@ -2,7 +2,7 @@ 0x1234 0x5678 0x8642 - + 0x1 one @@ -15,8 +15,8 @@ 0x8005678 - - + + two 0x7 @@ -25,5 +25,5 @@ 0x8000000 - + diff --git a/src/fuzzing/elantp.builder.xml b/src/fuzzing/elantp.builder.xml index b9286a022..1ce3cede3 100644 --- a/src/fuzzing/elantp.builder.xml +++ b/src/fuzzing/elantp.builder.xml @@ -1,7 +1,5 @@ 0xe00 0x2 - - aGVsbG8gd29ybGQ= - + aGVsbG8gd29ybGQ= diff --git a/src/fuzzing/fmap.builder.xml b/src/fuzzing/fmap.builder.xml index d48089b44..fcf47b644 100644 --- a/src/fuzzing/fmap.builder.xml +++ b/src/fuzzing/fmap.builder.xml @@ -1,11 +1,11 @@ 0x10 - + FMAP aGVsbG8gd29ybGQ= - - + + TEST V29ybGQh - + diff --git a/src/fuzzing/ifd.builder.xml b/src/fuzzing/ifd.builder.xml index f7417ef4c..53d9047ea 100644 --- a/src/fuzzing/ifd.builder.xml +++ b/src/fuzzing/ifd.builder.xml @@ -4,16 +4,16 @@ 0x310330 0x325c00f5 0x42 - + bios 0x1 0x1000 aGVsbG8gd29ybGQ= - - + + me 0x2 0x2000 V29ybGQh - + diff --git a/src/fuzzing/pixart.builder.xml b/src/fuzzing/pixart.builder.xml index 852795b56..c4f2b46b4 100644 --- a/src/fuzzing/pixart.builder.xml +++ b/src/fuzzing/pixart.builder.xml @@ -1,6 +1,4 @@ 0x00010203 - - aGVsbG8gd29ybGQ= - + aGVsbG8gd29ybGQ= diff --git a/src/fuzzing/rmi-0x.builder.xml b/src/fuzzing/rmi-0x.builder.xml index 8a0389f9b..b55f18020 100644 --- a/src/fuzzing/rmi-0x.builder.xml +++ b/src/fuzzing/rmi-0x.builder.xml @@ -1,7 +1,7 @@ 0x01 Example - + ZGF2ZQ== - + diff --git a/src/fuzzing/rmi-10.builder.xml b/src/fuzzing/rmi-10.builder.xml index 9911531a6..6b5b3f5f5 100644 --- a/src/fuzzing/rmi-10.builder.xml +++ b/src/fuzzing/rmi-10.builder.xml @@ -1,7 +1,7 @@ 0x10 Example - + ZGF2ZQ== - + diff --git a/src/fuzzing/synaprom.builder.xml b/src/fuzzing/synaprom.builder.xml index 1caaebd6b..e88f2eaa0 100644 --- a/src/fuzzing/synaprom.builder.xml +++ b/src/fuzzing/synaprom.builder.xml @@ -1,7 +1,7 @@ 1.2 - + 0x42 aGVsbG8gd29ybGQ= - +