Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 Richard Hughes <richard@hughsie.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1+ |
| 5 | */ |
| 6 | |
| 7 | #pragma once |
| 8 | |
| 9 | #include <glib-object.h> |
| 10 | #include <fwupd.h> |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 11 | #include <xmlb.h> |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 12 | |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 13 | #include "fu-chunk.h" |
| 14 | #include "fu-firmware.h" |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 15 | |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 16 | #define FU_TYPE_FIRMWARE (fu_firmware_get_type ()) |
| 17 | G_DECLARE_DERIVABLE_TYPE (FuFirmware, fu_firmware, FU, FIRMWARE, GObject) |
| 18 | |
Richard Hughes | 52441f2 | 2021-03-12 21:21:10 +0000 | [diff] [blame^] | 19 | /** |
| 20 | * FuFirmwareExportFlags: |
| 21 | * @FU_FIRMWARE_EXPORT_FLAG_NONE: No flags set |
| 22 | * @FU_FIRMWARE_EXPORT_FLAG_INCLUDE_DEBUG: Include debug information when exporting |
| 23 | * @FU_FIRMWARE_EXPORT_FLAG_ASCII_DATA: Write the data as UTF-8 strings |
| 24 | * |
| 25 | * The firmware export flags. |
| 26 | **/ |
| 27 | #define FU_FIRMWARE_EXPORT_FLAG_NONE (0u) /* Since: 1.6.0 */ |
| 28 | #define FU_FIRMWARE_EXPORT_FLAG_INCLUDE_DEBUG (1u << 0) /* Since: 1.6.0 */ |
| 29 | #define FU_FIRMWARE_EXPORT_FLAG_ASCII_DATA (1u << 1) /* Since: 1.6.0 */ |
| 30 | typedef guint64 FuFirmwareExportFlags; |
| 31 | |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 32 | struct _FuFirmwareClass |
| 33 | { |
| 34 | GObjectClass parent_class; |
| 35 | gboolean (*parse) (FuFirmware *self, |
| 36 | GBytes *fw, |
| 37 | guint64 addr_start, |
| 38 | guint64 addr_end, |
| 39 | FwupdInstallFlags flags, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 40 | GError **error) |
| 41 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 42 | GBytes *(*write) (FuFirmware *self, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 43 | GError **error) |
| 44 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 52441f2 | 2021-03-12 21:21:10 +0000 | [diff] [blame^] | 45 | void (*export) (FuFirmware *self, |
| 46 | FuFirmwareExportFlags flags, |
| 47 | XbBuilderNode *bn); |
Richard Hughes | 6819f9e | 2019-09-19 17:37:30 +0100 | [diff] [blame] | 48 | gboolean (*tokenize) (FuFirmware *self, |
| 49 | GBytes *fw, |
| 50 | FwupdInstallFlags flags, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 51 | GError **error) |
| 52 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 41400a8 | 2020-09-21 13:43:15 +0100 | [diff] [blame] | 53 | gboolean (*build) (FuFirmware *self, |
| 54 | XbNode *n, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 55 | GError **error) |
| 56 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 57 | gchar *(*get_checksum) (FuFirmware *self, |
| 58 | GChecksumType csum_kind, |
| 59 | GError **error) |
| 60 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 61 | /*< private >*/ |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 62 | gpointer padding[26]; |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
Richard Hughes | 6da96cd | 2020-09-17 10:28:42 +0100 | [diff] [blame] | 65 | /** |
| 66 | * FuFirmwareFlags: |
| 67 | * @FU_FIRMWARE_FLAG_NONE: No flags set |
| 68 | * @FU_FIRMWARE_FLAG_DEDUPE_ID: Dedupe imges by ID |
| 69 | * @FU_FIRMWARE_FLAG_DEDUPE_IDX: Dedupe imges by IDX |
Richard Hughes | 54bc512 | 2021-02-11 09:29:03 +0000 | [diff] [blame] | 70 | * @FU_FIRMWARE_FLAG_HAS_CHECKSUM: Has a CRC or checksum to test internal consistency |
| 71 | * @FU_FIRMWARE_FLAG_HAS_VID_PID: Has a vendor or product ID in the firmware |
Richard Hughes | 6da96cd | 2020-09-17 10:28:42 +0100 | [diff] [blame] | 72 | * |
| 73 | * The firmware flags. |
| 74 | **/ |
| 75 | #define FU_FIRMWARE_FLAG_NONE (0u) /* Since: 1.5.0 */ |
| 76 | #define FU_FIRMWARE_FLAG_DEDUPE_ID (1u << 0) /* Since: 1.5.0 */ |
| 77 | #define FU_FIRMWARE_FLAG_DEDUPE_IDX (1u << 1) /* Since: 1.5.0 */ |
Richard Hughes | 54bc512 | 2021-02-11 09:29:03 +0000 | [diff] [blame] | 78 | #define FU_FIRMWARE_FLAG_HAS_CHECKSUM (1u << 2) /* Since: 1.5.6 */ |
| 79 | #define FU_FIRMWARE_FLAG_HAS_VID_PID (1u << 3) /* Since: 1.5.6 */ |
Richard Hughes | 6da96cd | 2020-09-17 10:28:42 +0100 | [diff] [blame] | 80 | typedef guint64 FuFirmwareFlags; |
| 81 | |
Richard Hughes | 52441f2 | 2021-03-12 21:21:10 +0000 | [diff] [blame^] | 82 | #define FU_FIRMWARE_ID_PAYLOAD "payload" |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 83 | #define FU_FIRMWARE_ID_SIGNATURE "signature" |
Richard Hughes | 52441f2 | 2021-03-12 21:21:10 +0000 | [diff] [blame^] | 84 | #define FU_FIRMWARE_ID_HEADER "header" |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 85 | |
Richard Hughes | 6da96cd | 2020-09-17 10:28:42 +0100 | [diff] [blame] | 86 | const gchar *fu_firmware_flag_to_string (FuFirmwareFlags flag); |
| 87 | FuFirmwareFlags fu_firmware_flag_from_string (const gchar *flag); |
| 88 | |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 89 | FuFirmware *fu_firmware_new (void); |
| 90 | FuFirmware *fu_firmware_new_from_bytes (GBytes *fw); |
Richard Hughes | 1d16352 | 2021-01-29 15:54:30 +0000 | [diff] [blame] | 91 | FuFirmware *fu_firmware_new_from_gtypes (GBytes *fw, |
| 92 | FwupdInstallFlags flags, |
| 93 | GError **error, |
| 94 | ...); |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 95 | gchar *fu_firmware_to_string (FuFirmware *self); |
Richard Hughes | 52441f2 | 2021-03-12 21:21:10 +0000 | [diff] [blame^] | 96 | void fu_firmware_export (FuFirmware *self, |
| 97 | FuFirmwareExportFlags flags, |
| 98 | XbBuilderNode *bn); |
| 99 | gchar *fu_firmware_export_to_xml (FuFirmware *self, |
| 100 | FuFirmwareExportFlags flags, |
| 101 | GError **error); |
Richard Hughes | fd3c8ae | 2019-10-21 16:01:38 +0100 | [diff] [blame] | 102 | const gchar *fu_firmware_get_version (FuFirmware *self); |
| 103 | void fu_firmware_set_version (FuFirmware *self, |
| 104 | const gchar *version); |
Richard Hughes | 86c6c2d | 2021-02-15 10:54:37 +0000 | [diff] [blame] | 105 | guint64 fu_firmware_get_version_raw (FuFirmware *self); |
| 106 | void fu_firmware_set_version_raw (FuFirmware *self, |
| 107 | guint64 version_raw); |
Richard Hughes | 6da96cd | 2020-09-17 10:28:42 +0100 | [diff] [blame] | 108 | void fu_firmware_add_flag (FuFirmware *firmware, |
| 109 | FuFirmwareFlags flag); |
| 110 | gboolean fu_firmware_has_flag (FuFirmware *firmware, |
| 111 | FuFirmwareFlags flag); |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 112 | const gchar *fu_firmware_get_filename (FuFirmware *self); |
| 113 | void fu_firmware_set_filename (FuFirmware *self, |
| 114 | const gchar *filename); |
| 115 | const gchar *fu_firmware_get_id (FuFirmware *self); |
| 116 | void fu_firmware_set_id (FuFirmware *self, |
| 117 | const gchar *id); |
| 118 | guint64 fu_firmware_get_addr (FuFirmware *self); |
| 119 | void fu_firmware_set_addr (FuFirmware *self, |
| 120 | guint64 addr); |
| 121 | guint64 fu_firmware_get_offset (FuFirmware *self); |
| 122 | void fu_firmware_set_offset (FuFirmware *self, |
| 123 | guint64 offset); |
Richard Hughes | 8f63180 | 2021-03-10 13:50:38 +0000 | [diff] [blame] | 124 | gsize fu_firmware_get_size (FuFirmware *self); |
| 125 | void fu_firmware_set_size (FuFirmware *self, |
Richard Hughes | 752c8de | 2021-03-13 16:23:26 +0000 | [diff] [blame] | 126 | gsize size); |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 127 | guint64 fu_firmware_get_idx (FuFirmware *self); |
| 128 | void fu_firmware_set_idx (FuFirmware *self, |
| 129 | guint64 idx); |
| 130 | GBytes *fu_firmware_get_bytes (FuFirmware *self, |
| 131 | GError **error); |
| 132 | void fu_firmware_set_bytes (FuFirmware *self, |
| 133 | GBytes *bytes); |
Richard Hughes | 55853e3 | 2021-03-10 13:48:08 +0000 | [diff] [blame] | 134 | guint8 fu_firmware_get_alignment (FuFirmware *self); |
| 135 | void fu_firmware_set_alignment (FuFirmware *self, |
| 136 | guint8 alignment); |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 137 | void fu_firmware_add_chunk (FuFirmware *self, |
| 138 | FuChunk *chk); |
| 139 | GPtrArray *fu_firmware_get_chunks (FuFirmware *self, |
| 140 | GError **error); |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 141 | |
Richard Hughes | 6819f9e | 2019-09-19 17:37:30 +0100 | [diff] [blame] | 142 | gboolean fu_firmware_tokenize (FuFirmware *self, |
| 143 | GBytes *fw, |
| 144 | FwupdInstallFlags flags, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 145 | GError **error) |
| 146 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 41400a8 | 2020-09-21 13:43:15 +0100 | [diff] [blame] | 147 | gboolean fu_firmware_build (FuFirmware *self, |
| 148 | XbNode *n, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 149 | GError **error) |
| 150 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 52441f2 | 2021-03-12 21:21:10 +0000 | [diff] [blame^] | 151 | gboolean fu_firmware_build_from_xml (FuFirmware *self, |
| 152 | const gchar *xml, |
| 153 | GError **error) |
| 154 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 155 | gboolean fu_firmware_parse (FuFirmware *self, |
| 156 | GBytes *fw, |
| 157 | FwupdInstallFlags flags, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 158 | GError **error) |
| 159 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | f591a35 | 2019-10-10 15:30:44 +0100 | [diff] [blame] | 160 | gboolean fu_firmware_parse_file (FuFirmware *self, |
| 161 | GFile *file, |
| 162 | FwupdInstallFlags flags, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 163 | GError **error) |
| 164 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 165 | gboolean fu_firmware_parse_full (FuFirmware *self, |
| 166 | GBytes *fw, |
| 167 | guint64 addr_start, |
| 168 | guint64 addr_end, |
| 169 | FwupdInstallFlags flags, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 170 | GError **error) |
| 171 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 172 | GBytes *fu_firmware_write (FuFirmware *self, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 173 | GError **error) |
| 174 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 175 | GBytes *fu_firmware_write_chunk (FuFirmware *self, |
| 176 | guint64 address, |
| 177 | guint64 chunk_sz_max, |
| 178 | GError **error) |
| 179 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | f591a35 | 2019-10-10 15:30:44 +0100 | [diff] [blame] | 180 | gboolean fu_firmware_write_file (FuFirmware *self, |
| 181 | GFile *file, |
Richard Hughes | a2abc42 | 2020-12-22 09:38:59 +0000 | [diff] [blame] | 182 | GError **error) |
| 183 | G_GNUC_WARN_UNUSED_RESULT; |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 184 | gchar *fu_firmware_get_checksum (FuFirmware *self, |
| 185 | GChecksumType csum_kind, |
| 186 | GError **error); |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 187 | |
| 188 | void fu_firmware_add_image (FuFirmware *self, |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 189 | FuFirmware *img); |
Richard Hughes | 3e9fafc | 2020-09-24 13:08:21 +0100 | [diff] [blame] | 190 | gboolean fu_firmware_remove_image (FuFirmware *self, |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 191 | FuFirmware *img, |
Richard Hughes | 3e9fafc | 2020-09-24 13:08:21 +0100 | [diff] [blame] | 192 | GError **error); |
| 193 | gboolean fu_firmware_remove_image_by_idx (FuFirmware *self, |
| 194 | guint64 idx, |
| 195 | GError **error); |
| 196 | gboolean fu_firmware_remove_image_by_id (FuFirmware *self, |
| 197 | const gchar *id, |
| 198 | GError **error); |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 199 | GPtrArray *fu_firmware_get_images (FuFirmware *self); |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 200 | FuFirmware *fu_firmware_get_image_by_id (FuFirmware *self, |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 201 | const gchar *id, |
| 202 | GError **error); |
| 203 | GBytes *fu_firmware_get_image_by_id_bytes (FuFirmware *self, |
| 204 | const gchar *id, |
| 205 | GError **error); |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 206 | FuFirmware *fu_firmware_get_image_by_idx (FuFirmware *self, |
Richard Hughes | 7afd7cb | 2019-08-07 11:42:42 +0100 | [diff] [blame] | 207 | guint64 idx, |
| 208 | GError **error); |
| 209 | GBytes *fu_firmware_get_image_by_idx_bytes (FuFirmware *self, |
| 210 | guint64 idx, |
| 211 | GError **error); |
Richard Hughes | 1981c63 | 2021-03-09 09:44:12 +0000 | [diff] [blame] | 212 | FuFirmware *fu_firmware_get_image_by_checksum (FuFirmware *self, |
Richard Hughes | ac92758 | 2021-01-05 11:06:33 +0000 | [diff] [blame] | 213 | const gchar *checksum, |
| 214 | GError **error); |