Coverage Report

Created: 2025-11-11 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/fu-oprom-struct.c
Line
Count
Source
1
/* auto-generated, do not modify */
2
#include "config.h"
3
4
#include <glib.h>
5
6
#include "fu-oprom-struct.h"
7
#include "fu-byte-array.h"
8
#include "fu-mem-private.h"
9
#include "fu-string.h"
10
11
#ifdef G_LOG_DOMAIN
12
  #undef G_LOG_DOMAIN
13
#endif
14
0
#define G_LOG_DOMAIN "FuStruct"
15
16
static const gchar *
17
fu_oprom_machine_type_to_string(FuOpromMachineType val)
18
0
{
19
0
    if (val == FU_OPROM_MACHINE_TYPE_X64)
20
0
        return "x64";
21
0
    return NULL;
22
0
}
23
24
static const gchar *
25
fu_oprom_subsystem_to_string(FuOpromSubsystem val)
26
0
{
27
0
    if (val == FU_OPROM_SUBSYSTEM_EFI_BOOT_SRV_DRV)
28
0
        return "efi-boot-srv-drv";
29
0
    return NULL;
30
0
}
31
32
static const gchar *
33
fu_oprom_compression_type_to_string(FuOpromCompressionType val)
34
0
{
35
0
    if (val == FU_OPROM_COMPRESSION_TYPE_NONE)
36
0
        return "none";
37
0
    return NULL;
38
0
}
39
40
static const gchar *
41
fu_oprom_indicator_flags_to_string(FuOpromIndicatorFlags val)
42
0
{
43
0
    if (val == FU_OPROM_INDICATOR_FLAG_NONE)
44
0
        return "none";
45
0
    if (val == FU_OPROM_INDICATOR_FLAG_LAST)
46
0
        return "last";
47
0
    return NULL;
48
0
}
49
/**
50
 * fu_struct_oprom_ref: (skip):
51
 **/
52
FuStructOprom *
53
fu_struct_oprom_ref(FuStructOprom *st)
54
0
{
55
0
    g_return_val_if_fail(st != NULL, NULL);
56
0
    st->refcount++;
57
0
    return st;
58
0
}
59
/**
60
 * fu_struct_oprom_unref: (skip):
61
 **/
62
void
63
fu_struct_oprom_unref(FuStructOprom *st)
64
32.8k
{
65
32.8k
    g_return_if_fail(st != NULL);
66
32.8k
    if (st->refcount == 0) {
67
0
        g_critical("FuStructOprom refcount already zero");
68
0
        return;
69
0
    }
70
32.8k
    if (--st->refcount > 0)
71
0
        return;
72
32.8k
    if (st->buf != NULL)
73
32.8k
        g_byte_array_unref(st->buf);
74
32.8k
    g_free(st);
75
32.8k
}
76
static FuStructOprom *
77
fu_struct_oprom_new_internal(void)
78
32.8k
{
79
32.8k
    FuStructOprom *st = g_new0(FuStructOprom, 1);
80
32.8k
    st->refcount = 1;
81
32.8k
    return st;
82
32.8k
}
83
84
/* getters */
85
/**
86
 * fu_struct_oprom_get_signature: (skip):
87
 **/
88
static guint16
89
fu_struct_oprom_get_signature(const FuStructOprom *st)
90
59.5k
{
91
59.5k
    g_return_val_if_fail(st != NULL, 0x0);
92
59.5k
    return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN);
93
59.5k
}
94
/**
95
 * fu_struct_oprom_get_image_size: (skip):
96
 **/
97
guint16
98
fu_struct_oprom_get_image_size(const FuStructOprom *st)
99
0
{
100
0
    g_return_val_if_fail(st != NULL, 0x0);
101
0
    return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN);
102
0
}
103
/**
104
 * fu_struct_oprom_get_init_func_entry_point: (skip):
105
 **/
106
guint32
107
fu_struct_oprom_get_init_func_entry_point(const FuStructOprom *st)
108
0
{
109
0
    g_return_val_if_fail(st != NULL, 0x0);
110
0
    return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN);
111
0
}
112
/**
113
 * fu_struct_oprom_get_subsystem: (skip):
114
 **/
115
FuOpromSubsystem
116
fu_struct_oprom_get_subsystem(const FuStructOprom *st)
117
845
{
118
845
    g_return_val_if_fail(st != NULL, 0x0);
119
845
    return fu_memread_uint16(st->buf->data + 8, G_LITTLE_ENDIAN);
120
845
}
121
/**
122
 * fu_struct_oprom_get_machine_type: (skip):
123
 **/
124
FuOpromMachineType
125
fu_struct_oprom_get_machine_type(const FuStructOprom *st)
126
845
{
127
845
    g_return_val_if_fail(st != NULL, 0x0);
128
845
    return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN);
129
845
}
130
/**
131
 * fu_struct_oprom_get_compression_type: (skip):
132
 **/
133
FuOpromCompressionType
134
fu_struct_oprom_get_compression_type(const FuStructOprom *st)
135
845
{
136
845
    g_return_val_if_fail(st != NULL, 0x0);
137
845
    return fu_memread_uint16(st->buf->data + 12, G_LITTLE_ENDIAN);
138
845
}
139
/**
140
 * fu_struct_oprom_get_efi_image_offset: (skip):
141
 **/
142
guint16
143
fu_struct_oprom_get_efi_image_offset(const FuStructOprom *st)
144
0
{
145
0
    g_return_val_if_fail(st != NULL, 0x0);
146
0
    return fu_memread_uint16(st->buf->data + 22, G_LITTLE_ENDIAN);
147
0
}
148
/**
149
 * fu_struct_oprom_get_pci_header_offset: (skip):
150
 **/
151
guint16
152
fu_struct_oprom_get_pci_header_offset(const FuStructOprom *st)
153
845
{
154
845
    g_return_val_if_fail(st != NULL, 0x0);
155
845
    return fu_memread_uint16(st->buf->data + 24, G_LITTLE_ENDIAN);
156
845
}
157
/**
158
 * fu_struct_oprom_get_expansion_header_offset: (skip):
159
 **/
160
guint16
161
fu_struct_oprom_get_expansion_header_offset(const FuStructOprom *st)
162
745
{
163
745
    g_return_val_if_fail(st != NULL, 0x0);
164
745
    return fu_memread_uint16(st->buf->data + 26, G_LITTLE_ENDIAN);
165
745
}
166
167
/* setters */
168
/**
169
 * fu_struct_oprom_set_signature: (skip):
170
 **/
171
static void
172
fu_struct_oprom_set_signature(FuStructOprom *st, guint16 value)
173
727
{
174
727
    g_return_if_fail(st != NULL);
175
727
    fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN);
176
727
}
177
/**
178
 * fu_struct_oprom_set_image_size: (skip):
179
 **/
180
void
181
fu_struct_oprom_set_image_size(FuStructOprom *st, guint16 value)
182
727
{
183
727
    g_return_if_fail(st != NULL);
184
727
    fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN);
185
727
}
186
/**
187
 * fu_struct_oprom_set_init_func_entry_point: (skip):
188
 **/
189
void
190
fu_struct_oprom_set_init_func_entry_point(FuStructOprom *st, guint32 value)
191
0
{
192
0
    g_return_if_fail(st != NULL);
193
0
    fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN);
194
0
}
195
/**
196
 * fu_struct_oprom_set_subsystem: (skip):
197
 **/
198
void
199
fu_struct_oprom_set_subsystem(FuStructOprom *st, FuOpromSubsystem value)
200
727
{
201
727
    g_return_if_fail(st != NULL);
202
727
    fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN);
203
727
}
204
/**
205
 * fu_struct_oprom_set_machine_type: (skip):
206
 **/
207
void
208
fu_struct_oprom_set_machine_type(FuStructOprom *st, FuOpromMachineType value)
209
727
{
210
727
    g_return_if_fail(st != NULL);
211
727
    fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN);
212
727
}
213
/**
214
 * fu_struct_oprom_set_compression_type: (skip):
215
 **/
216
void
217
fu_struct_oprom_set_compression_type(FuStructOprom *st, FuOpromCompressionType value)
218
727
{
219
727
    g_return_if_fail(st != NULL);
220
727
    fu_memwrite_uint16(st->buf->data + 12, value, G_LITTLE_ENDIAN);
221
727
}
222
/**
223
 * fu_struct_oprom_set_efi_image_offset: (skip):
224
 **/
225
void
226
fu_struct_oprom_set_efi_image_offset(FuStructOprom *st, guint16 value)
227
0
{
228
0
    g_return_if_fail(st != NULL);
229
0
    fu_memwrite_uint16(st->buf->data + 22, value, G_LITTLE_ENDIAN);
230
0
}
231
/**
232
 * fu_struct_oprom_set_pci_header_offset: (skip):
233
 **/
234
void
235
fu_struct_oprom_set_pci_header_offset(FuStructOprom *st, guint16 value)
236
727
{
237
727
    g_return_if_fail(st != NULL);
238
727
    fu_memwrite_uint16(st->buf->data + 24, value, G_LITTLE_ENDIAN);
239
727
}
240
/**
241
 * fu_struct_oprom_set_expansion_header_offset: (skip):
242
 **/
243
void
244
fu_struct_oprom_set_expansion_header_offset(FuStructOprom *st, guint16 value)
245
2
{
246
2
    g_return_if_fail(st != NULL);
247
2
    fu_memwrite_uint16(st->buf->data + 26, value, G_LITTLE_ENDIAN);
248
2
}
249
/**
250
 * fu_struct_oprom_new: (skip):
251
 **/
252
FuStructOprom *
253
fu_struct_oprom_new(void)
254
727
{
255
727
    FuStructOprom *st = fu_struct_oprom_new_internal();
256
727
    st->buf = g_byte_array_sized_new(28);
257
727
    fu_byte_array_set_size(st->buf, 28, 0x0);
258
727
    fu_struct_oprom_set_signature(st, 0xAA55);
259
727
    fu_struct_oprom_set_pci_header_offset(st, 28);
260
727
    return st;
261
727
}
262
/**
263
 * fu_struct_oprom_to_string: (skip):
264
 **/
265
static gchar *
266
fu_struct_oprom_to_string(const FuStructOprom *st)
267
0
{
268
0
    g_autoptr(GString) str = g_string_new("FuStructOprom:\n");
269
0
    g_return_val_if_fail(st != NULL, NULL);
270
0
    g_string_append_printf(str, "  image_size: 0x%x\n",
271
0
                           (guint) fu_struct_oprom_get_image_size(st));
272
0
    g_string_append_printf(str, "  init_func_entry_point: 0x%x\n",
273
0
                           (guint) fu_struct_oprom_get_init_func_entry_point(st));
274
0
    {
275
0
        const gchar *tmp = fu_oprom_subsystem_to_string(fu_struct_oprom_get_subsystem(st));
276
0
        if (tmp != NULL) {
277
0
            g_string_append_printf(str, "  subsystem: 0x%x [%s]\n", (guint) fu_struct_oprom_get_subsystem(st), tmp);
278
0
        } else {
279
0
            g_string_append_printf(str, "  subsystem: 0x%x\n", (guint) fu_struct_oprom_get_subsystem(st));
280
0
        }
281
0
    }
282
0
    {
283
0
        const gchar *tmp = fu_oprom_machine_type_to_string(fu_struct_oprom_get_machine_type(st));
284
0
        if (tmp != NULL) {
285
0
            g_string_append_printf(str, "  machine_type: 0x%x [%s]\n", (guint) fu_struct_oprom_get_machine_type(st), tmp);
286
0
        } else {
287
0
            g_string_append_printf(str, "  machine_type: 0x%x\n", (guint) fu_struct_oprom_get_machine_type(st));
288
0
        }
289
0
    }
290
0
    {
291
0
        const gchar *tmp = fu_oprom_compression_type_to_string(fu_struct_oprom_get_compression_type(st));
292
0
        if (tmp != NULL) {
293
0
            g_string_append_printf(str, "  compression_type: 0x%x [%s]\n", (guint) fu_struct_oprom_get_compression_type(st), tmp);
294
0
        } else {
295
0
            g_string_append_printf(str, "  compression_type: 0x%x\n", (guint) fu_struct_oprom_get_compression_type(st));
296
0
        }
297
0
    }
298
0
    g_string_append_printf(str, "  efi_image_offset: 0x%x\n",
299
0
                           (guint) fu_struct_oprom_get_efi_image_offset(st));
300
0
    g_string_append_printf(str, "  pci_header_offset: 0x%x\n",
301
0
                           (guint) fu_struct_oprom_get_pci_header_offset(st));
302
0
    g_string_append_printf(str, "  expansion_header_offset: 0x%x\n",
303
0
                           (guint) fu_struct_oprom_get_expansion_header_offset(st));
304
0
    if (str->len > 0)
305
0
        g_string_set_size(str, str->len - 1);
306
0
    return g_string_free(g_steal_pointer(&str), FALSE);
307
0
}
308
static gboolean
309
fu_struct_oprom_validate_internal(FuStructOprom *st, GError **error)
310
30.6k
{
311
30.6k
    g_return_val_if_fail(st != NULL, FALSE);
312
30.6k
    if (fu_struct_oprom_get_signature(st) != 0xAA55) {
313
28.9k
        g_set_error(error,
314
28.9k
                    FWUPD_ERROR,
315
28.9k
                    FWUPD_ERROR_INVALID_DATA,
316
28.9k
                    "constant FuStructOprom.signature was not valid, "
317
28.9k
                    "expected 0x%x and got 0x%x",
318
28.9k
                    (guint) 0xAA55,
319
28.9k
                    (guint) fu_struct_oprom_get_signature(st));
320
28.9k
        return FALSE;
321
28.9k
    }
322
1.69k
    return TRUE;
323
30.6k
}
324
/**
325
 * fu_struct_oprom_validate_stream: (skip):
326
 **/
327
gboolean
328
fu_struct_oprom_validate_stream(GInputStream *stream, gsize offset, GError **error)
329
31.2k
{
330
31.2k
    g_autoptr(FuStructOprom) st = fu_struct_oprom_new_internal();
331
31.2k
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
332
31.2k
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
333
31.2k
    st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
334
31.2k
    if (st->buf == NULL) {
335
0
        g_prefix_error(error, "FuStructOprom failed read of 0x%x: ", (guint) 28);
336
0
        return FALSE;
337
0
    }
338
31.2k
    if (st->buf->len != 28) {
339
1.47k
        g_set_error(error,
340
1.47k
                    FWUPD_ERROR,
341
1.47k
                    FWUPD_ERROR_INVALID_DATA,
342
1.47k
                    "FuStructOprom requested 0x%x and got 0x%x",
343
1.47k
                    (guint) 28,
344
1.47k
                    (guint) st->buf->len);
345
1.47k
        return FALSE;
346
1.47k
    }
347
29.7k
    return fu_struct_oprom_validate_internal(st, error);
348
31.2k
}
349
static gboolean
350
fu_struct_oprom_parse_internal(FuStructOprom *st, GError **error)
351
845
{
352
845
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
353
0
        g_autofree gchar *str = fu_struct_oprom_to_string(st);
354
0
        g_debug("%s", str);
355
0
    }
356
845
    if (!fu_struct_oprom_validate_internal(st, error))
357
0
        return FALSE;
358
845
    return TRUE;
359
845
}
360
/**
361
 * fu_struct_oprom_parse_stream: (skip):
362
 **/
363
FuStructOprom *
364
fu_struct_oprom_parse_stream(GInputStream *stream, gsize offset, GError **error)
365
845
{
366
845
    g_autoptr(FuStructOprom) st = fu_struct_oprom_new_internal();
367
845
    st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
368
845
    if (st->buf == NULL) {
369
0
        g_prefix_error(error, "FuStructOprom failed read of 0x%x: ", (guint) 28);
370
0
        return NULL;
371
0
    }
372
845
    if (st->buf->len != 28) {
373
0
        g_set_error(error,
374
0
                    FWUPD_ERROR,
375
0
                    FWUPD_ERROR_INVALID_DATA,
376
0
                    "FuStructOprom requested 0x%x and got 0x%x",
377
0
                    (guint) 28,
378
0
                    (guint) st->buf->len);
379
0
        return NULL;
380
0
    }
381
845
    if (!fu_struct_oprom_parse_internal(st, error))
382
0
        return NULL;
383
845
    return g_steal_pointer(&st);
384
845
}
385
/**
386
 * fu_struct_oprom_pci_ref: (skip):
387
 **/
388
FuStructOpromPci *
389
fu_struct_oprom_pci_ref(FuStructOpromPci *st)
390
0
{
391
0
    g_return_val_if_fail(st != NULL, NULL);
392
0
    st->refcount++;
393
0
    return st;
394
0
}
395
/**
396
 * fu_struct_oprom_pci_unref: (skip):
397
 **/
398
void
399
fu_struct_oprom_pci_unref(FuStructOpromPci *st)
400
1.56k
{
401
1.56k
    g_return_if_fail(st != NULL);
402
1.56k
    if (st->refcount == 0) {
403
0
        g_critical("FuStructOpromPci refcount already zero");
404
0
        return;
405
0
    }
406
1.56k
    if (--st->refcount > 0)
407
0
        return;
408
1.56k
    if (st->buf != NULL)
409
1.53k
        g_byte_array_unref(st->buf);
410
1.56k
    g_free(st);
411
1.56k
}
412
static FuStructOpromPci *
413
fu_struct_oprom_pci_new_internal(void)
414
1.56k
{
415
1.56k
    FuStructOpromPci *st = g_new0(FuStructOpromPci, 1);
416
1.56k
    st->refcount = 1;
417
1.56k
    return st;
418
1.56k
}
419
420
/* getters */
421
/**
422
 * fu_struct_oprom_pci_get_signature: (skip):
423
 **/
424
static guint32
425
fu_struct_oprom_pci_get_signature(const FuStructOpromPci *st)
426
844
{
427
844
    g_return_val_if_fail(st != NULL, 0x0);
428
844
    return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN);
429
844
}
430
/**
431
 * fu_struct_oprom_pci_get_vendor_id: (skip):
432
 **/
433
guint16
434
fu_struct_oprom_pci_get_vendor_id(const FuStructOpromPci *st)
435
748
{
436
748
    g_return_val_if_fail(st != NULL, 0x0);
437
748
    return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN);
438
748
}
439
/**
440
 * fu_struct_oprom_pci_get_device_id: (skip):
441
 **/
442
guint16
443
fu_struct_oprom_pci_get_device_id(const FuStructOpromPci *st)
444
748
{
445
748
    g_return_val_if_fail(st != NULL, 0x0);
446
748
    return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN);
447
748
}
448
/**
449
 * fu_struct_oprom_pci_get_device_list_pointer: (skip):
450
 **/
451
guint16
452
fu_struct_oprom_pci_get_device_list_pointer(const FuStructOpromPci *st)
453
0
{
454
0
    g_return_val_if_fail(st != NULL, 0x0);
455
0
    return fu_memread_uint16(st->buf->data + 8, G_LITTLE_ENDIAN);
456
0
}
457
/**
458
 * fu_struct_oprom_pci_get_structure_length: (skip):
459
 **/
460
guint16
461
fu_struct_oprom_pci_get_structure_length(const FuStructOpromPci *st)
462
0
{
463
0
    g_return_val_if_fail(st != NULL, 0x0);
464
0
    return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN);
465
0
}
466
/**
467
 * fu_struct_oprom_pci_get_structure_revision: (skip):
468
 **/
469
guint8
470
fu_struct_oprom_pci_get_structure_revision(const FuStructOpromPci *st)
471
0
{
472
0
    g_return_val_if_fail(st != NULL, 0x0);
473
0
    return st->buf->data[12];
474
0
}
475
/**
476
 * fu_struct_oprom_pci_get_class_code: (skip):
477
 **/
478
guint32
479
fu_struct_oprom_pci_get_class_code(const FuStructOpromPci *st)
480
0
{
481
0
    g_return_val_if_fail(st != NULL, 0x0);
482
0
    return fu_memread_uint24(st->buf->data + 13, G_LITTLE_ENDIAN);
483
0
}
484
/**
485
 * fu_struct_oprom_pci_get_image_length: (skip):
486
 **/
487
guint16
488
fu_struct_oprom_pci_get_image_length(const FuStructOpromPci *st)
489
748
{
490
748
    g_return_val_if_fail(st != NULL, 0x0);
491
748
    return fu_memread_uint16(st->buf->data + 16, G_LITTLE_ENDIAN);
492
748
}
493
/**
494
 * fu_struct_oprom_pci_get_image_revision: (skip):
495
 **/
496
guint16
497
fu_struct_oprom_pci_get_image_revision(const FuStructOpromPci *st)
498
0
{
499
0
    g_return_val_if_fail(st != NULL, 0x0);
500
0
    return fu_memread_uint16(st->buf->data + 18, G_LITTLE_ENDIAN);
501
0
}
502
/**
503
 * fu_struct_oprom_pci_get_code_type: (skip):
504
 **/
505
guint8
506
fu_struct_oprom_pci_get_code_type(const FuStructOpromPci *st)
507
745
{
508
745
    g_return_val_if_fail(st != NULL, 0x0);
509
745
    return st->buf->data[20];
510
745
}
511
/**
512
 * fu_struct_oprom_pci_get_indicator: (skip):
513
 **/
514
FuOpromIndicatorFlags
515
fu_struct_oprom_pci_get_indicator(const FuStructOpromPci *st)
516
745
{
517
745
    g_return_val_if_fail(st != NULL, 0x0);
518
745
    return st->buf->data[21];
519
745
}
520
/**
521
 * fu_struct_oprom_pci_get_max_runtime_image_length: (skip):
522
 **/
523
guint16
524
fu_struct_oprom_pci_get_max_runtime_image_length(const FuStructOpromPci *st)
525
0
{
526
0
    g_return_val_if_fail(st != NULL, 0x0);
527
0
    return fu_memread_uint16(st->buf->data + 22, G_LITTLE_ENDIAN);
528
0
}
529
/**
530
 * fu_struct_oprom_pci_get_conf_util_code_header_pointer: (skip):
531
 **/
532
guint16
533
fu_struct_oprom_pci_get_conf_util_code_header_pointer(const FuStructOpromPci *st)
534
0
{
535
0
    g_return_val_if_fail(st != NULL, 0x0);
536
0
    return fu_memread_uint16(st->buf->data + 24, G_LITTLE_ENDIAN);
537
0
}
538
/**
539
 * fu_struct_oprom_pci_get_dmtf_clp_entry_point_pointer: (skip):
540
 **/
541
guint16
542
fu_struct_oprom_pci_get_dmtf_clp_entry_point_pointer(const FuStructOpromPci *st)
543
0
{
544
0
    g_return_val_if_fail(st != NULL, 0x0);
545
0
    return fu_memread_uint16(st->buf->data + 26, G_LITTLE_ENDIAN);
546
0
}
547
548
/* setters */
549
/**
550
 * fu_struct_oprom_pci_set_signature: (skip):
551
 **/
552
static void
553
fu_struct_oprom_pci_set_signature(FuStructOpromPci *st, guint32 value)
554
727
{
555
727
    g_return_if_fail(st != NULL);
556
727
    fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN);
557
727
}
558
/**
559
 * fu_struct_oprom_pci_set_vendor_id: (skip):
560
 **/
561
void
562
fu_struct_oprom_pci_set_vendor_id(FuStructOpromPci *st, guint16 value)
563
727
{
564
727
    g_return_if_fail(st != NULL);
565
727
    fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN);
566
727
}
567
/**
568
 * fu_struct_oprom_pci_set_device_id: (skip):
569
 **/
570
void
571
fu_struct_oprom_pci_set_device_id(FuStructOpromPci *st, guint16 value)
572
727
{
573
727
    g_return_if_fail(st != NULL);
574
727
    fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN);
575
727
}
576
/**
577
 * fu_struct_oprom_pci_set_device_list_pointer: (skip):
578
 **/
579
void
580
fu_struct_oprom_pci_set_device_list_pointer(FuStructOpromPci *st, guint16 value)
581
0
{
582
0
    g_return_if_fail(st != NULL);
583
0
    fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN);
584
0
}
585
/**
586
 * fu_struct_oprom_pci_set_structure_length: (skip):
587
 **/
588
void
589
fu_struct_oprom_pci_set_structure_length(FuStructOpromPci *st, guint16 value)
590
0
{
591
0
    g_return_if_fail(st != NULL);
592
0
    fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN);
593
0
}
594
/**
595
 * fu_struct_oprom_pci_set_structure_revision: (skip):
596
 **/
597
void
598
fu_struct_oprom_pci_set_structure_revision(FuStructOpromPci *st, guint8 value)
599
0
{
600
0
    g_return_if_fail(st != NULL);
601
0
    st->buf->data[12] = value;
602
0
}
603
/**
604
 * fu_struct_oprom_pci_set_class_code: (skip):
605
 **/
606
void
607
fu_struct_oprom_pci_set_class_code(FuStructOpromPci *st, guint32 value)
608
0
{
609
0
    g_return_if_fail(st != NULL);
610
0
    fu_memwrite_uint24(st->buf->data + 13, value, G_LITTLE_ENDIAN);
611
0
}
612
/**
613
 * fu_struct_oprom_pci_set_image_length: (skip):
614
 **/
615
void
616
fu_struct_oprom_pci_set_image_length(FuStructOpromPci *st, guint16 value)
617
727
{
618
727
    g_return_if_fail(st != NULL);
619
727
    fu_memwrite_uint16(st->buf->data + 16, value, G_LITTLE_ENDIAN);
620
727
}
621
/**
622
 * fu_struct_oprom_pci_set_image_revision: (skip):
623
 **/
624
void
625
fu_struct_oprom_pci_set_image_revision(FuStructOpromPci *st, guint16 value)
626
0
{
627
0
    g_return_if_fail(st != NULL);
628
0
    fu_memwrite_uint16(st->buf->data + 18, value, G_LITTLE_ENDIAN);
629
0
}
630
/**
631
 * fu_struct_oprom_pci_set_code_type: (skip):
632
 **/
633
void
634
fu_struct_oprom_pci_set_code_type(FuStructOpromPci *st, guint8 value)
635
727
{
636
727
    g_return_if_fail(st != NULL);
637
727
    st->buf->data[20] = value;
638
727
}
639
/**
640
 * fu_struct_oprom_pci_set_indicator: (skip):
641
 **/
642
void
643
fu_struct_oprom_pci_set_indicator(FuStructOpromPci *st, FuOpromIndicatorFlags value)
644
211
{
645
211
    g_return_if_fail(st != NULL);
646
211
    st->buf->data[21] = value;
647
211
}
648
/**
649
 * fu_struct_oprom_pci_set_max_runtime_image_length: (skip):
650
 **/
651
void
652
fu_struct_oprom_pci_set_max_runtime_image_length(FuStructOpromPci *st, guint16 value)
653
0
{
654
0
    g_return_if_fail(st != NULL);
655
0
    fu_memwrite_uint16(st->buf->data + 22, value, G_LITTLE_ENDIAN);
656
0
}
657
/**
658
 * fu_struct_oprom_pci_set_conf_util_code_header_pointer: (skip):
659
 **/
660
void
661
fu_struct_oprom_pci_set_conf_util_code_header_pointer(FuStructOpromPci *st, guint16 value)
662
0
{
663
0
    g_return_if_fail(st != NULL);
664
0
    fu_memwrite_uint16(st->buf->data + 24, value, G_LITTLE_ENDIAN);
665
0
}
666
/**
667
 * fu_struct_oprom_pci_set_dmtf_clp_entry_point_pointer: (skip):
668
 **/
669
void
670
fu_struct_oprom_pci_set_dmtf_clp_entry_point_pointer(FuStructOpromPci *st, guint16 value)
671
0
{
672
0
    g_return_if_fail(st != NULL);
673
0
    fu_memwrite_uint16(st->buf->data + 26, value, G_LITTLE_ENDIAN);
674
0
}
675
/**
676
 * fu_struct_oprom_pci_new: (skip):
677
 **/
678
FuStructOpromPci *
679
fu_struct_oprom_pci_new(void)
680
727
{
681
727
    FuStructOpromPci *st = fu_struct_oprom_pci_new_internal();
682
727
    st->buf = g_byte_array_sized_new(28);
683
727
    fu_byte_array_set_size(st->buf, 28, 0x0);
684
727
    fu_struct_oprom_pci_set_signature(st, 0x52494350);
685
727
    return st;
686
727
}
687
/**
688
 * fu_struct_oprom_pci_to_string: (skip):
689
 **/
690
static gchar *
691
fu_struct_oprom_pci_to_string(const FuStructOpromPci *st)
692
0
{
693
0
    g_autoptr(GString) str = g_string_new("FuStructOpromPci:\n");
694
0
    g_return_val_if_fail(st != NULL, NULL);
695
0
    g_string_append_printf(str, "  vendor_id: 0x%x\n",
696
0
                           (guint) fu_struct_oprom_pci_get_vendor_id(st));
697
0
    g_string_append_printf(str, "  device_id: 0x%x\n",
698
0
                           (guint) fu_struct_oprom_pci_get_device_id(st));
699
0
    g_string_append_printf(str, "  device_list_pointer: 0x%x\n",
700
0
                           (guint) fu_struct_oprom_pci_get_device_list_pointer(st));
701
0
    g_string_append_printf(str, "  structure_length: 0x%x\n",
702
0
                           (guint) fu_struct_oprom_pci_get_structure_length(st));
703
0
    g_string_append_printf(str, "  structure_revision: 0x%x\n",
704
0
                           (guint) fu_struct_oprom_pci_get_structure_revision(st));
705
0
    g_string_append_printf(str, "  class_code: 0x%x\n",
706
0
                           (guint) fu_struct_oprom_pci_get_class_code(st));
707
0
    g_string_append_printf(str, "  image_length: 0x%x\n",
708
0
                           (guint) fu_struct_oprom_pci_get_image_length(st));
709
0
    g_string_append_printf(str, "  image_revision: 0x%x\n",
710
0
                           (guint) fu_struct_oprom_pci_get_image_revision(st));
711
0
    g_string_append_printf(str, "  code_type: 0x%x\n",
712
0
                           (guint) fu_struct_oprom_pci_get_code_type(st));
713
0
    {
714
0
        const gchar *tmp = fu_oprom_indicator_flags_to_string(fu_struct_oprom_pci_get_indicator(st));
715
0
        if (tmp != NULL) {
716
0
            g_string_append_printf(str, "  indicator: 0x%x [%s]\n", (guint) fu_struct_oprom_pci_get_indicator(st), tmp);
717
0
        } else {
718
0
            g_string_append_printf(str, "  indicator: 0x%x\n", (guint) fu_struct_oprom_pci_get_indicator(st));
719
0
        }
720
0
    }
721
0
    g_string_append_printf(str, "  max_runtime_image_length: 0x%x\n",
722
0
                           (guint) fu_struct_oprom_pci_get_max_runtime_image_length(st));
723
0
    g_string_append_printf(str, "  conf_util_code_header_pointer: 0x%x\n",
724
0
                           (guint) fu_struct_oprom_pci_get_conf_util_code_header_pointer(st));
725
0
    g_string_append_printf(str, "  dmtf_clp_entry_point_pointer: 0x%x\n",
726
0
                           (guint) fu_struct_oprom_pci_get_dmtf_clp_entry_point_pointer(st));
727
0
    if (str->len > 0)
728
0
        g_string_set_size(str, str->len - 1);
729
0
    return g_string_free(g_steal_pointer(&str), FALSE);
730
0
}
731
static gboolean
732
fu_struct_oprom_pci_validate_internal(FuStructOpromPci *st, GError **error)
733
796
{
734
796
    g_return_val_if_fail(st != NULL, FALSE);
735
796
    if (fu_struct_oprom_pci_get_signature(st) != 0x52494350) {
736
48
        g_set_error(error,
737
48
                    FWUPD_ERROR,
738
48
                    FWUPD_ERROR_INVALID_DATA,
739
48
                    "constant FuStructOpromPci.signature was not valid, "
740
48
                    "expected 0x%x and got 0x%x",
741
48
                    (guint) 0x52494350,
742
48
                    (guint) fu_struct_oprom_pci_get_signature(st));
743
48
        return FALSE;
744
48
    }
745
748
    return TRUE;
746
796
}
747
static gboolean
748
fu_struct_oprom_pci_parse_internal(FuStructOpromPci *st, GError **error)
749
796
{
750
796
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
751
0
        g_autofree gchar *str = fu_struct_oprom_pci_to_string(st);
752
0
        g_debug("%s", str);
753
0
    }
754
796
    if (!fu_struct_oprom_pci_validate_internal(st, error))
755
48
        return FALSE;
756
748
    return TRUE;
757
796
}
758
/**
759
 * fu_struct_oprom_pci_parse_stream: (skip):
760
 **/
761
FuStructOpromPci *
762
fu_struct_oprom_pci_parse_stream(GInputStream *stream, gsize offset, GError **error)
763
841
{
764
841
    g_autoptr(FuStructOpromPci) st = fu_struct_oprom_pci_new_internal();
765
841
    st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
766
841
    if (st->buf == NULL) {
767
36
        g_prefix_error(error, "FuStructOpromPci failed read of 0x%x: ", (guint) 28);
768
36
        return NULL;
769
36
    }
770
805
    if (st->buf->len != 28) {
771
9
        g_set_error(error,
772
9
                    FWUPD_ERROR,
773
9
                    FWUPD_ERROR_INVALID_DATA,
774
9
                    "FuStructOpromPci requested 0x%x and got 0x%x",
775
9
                    (guint) 28,
776
9
                    (guint) st->buf->len);
777
9
        return NULL;
778
9
    }
779
796
    if (!fu_struct_oprom_pci_parse_internal(st, error))
780
48
        return NULL;
781
748
    return g_steal_pointer(&st);
782
796
}