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