From be33aaaf94e697ac449011b0cbdcfbcdaa20cb5a Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Tue, 7 Feb 2023 11:52:16 +0000 Subject: [PATCH] Fix fwupdtool firmware-convert to work with image-less formats Converting 'simple' non-nested formats like Intel Hex into nested formats like DfuSe needs us to create a binary child firmware to avoid missing data. Fixes https://github.com/fwupd/fwupd/issues/5493 --- src/fu-tool.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/fu-tool.c b/src/fu-tool.c index 8617afeb5..721201222 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -2617,6 +2617,20 @@ fu_util_firmware_convert(FuUtilPrivate *priv, gchar **values, GError **error) fu_firmware_add_image(firmware_dst, img); } + /* copy data as fallback, preferring a binary blob to the export */ + if (images->len == 0) { + g_autoptr(GBytes) fw = NULL; + g_autoptr(FuFirmware) img = NULL; + fw = fu_firmware_get_bytes(firmware_src, NULL); + if (fw == NULL) { + fw = fu_firmware_write(firmware_src, error); + if (fw == NULL) + return FALSE; + } + img = fu_firmware_new_from_bytes(fw); + fu_firmware_add_image(firmware_dst, img); + } + /* write new file */ blob_dst = fu_firmware_write(firmware_dst, error); if (blob_dst == NULL)