Coverage Report

Created: 2025-08-03 06:57

/src/fwupd/libfwupdplugin/fu-ifd-bios.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2021 Richard Hughes <richard@hughsie.com>
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
7
8.42k
#define G_LOG_DOMAIN "FuIfdBios"
8
9
#include "config.h"
10
11
#include "fu-efi-volume.h"
12
#include "fu-ifd-bios.h"
13
#include "fu-input-stream.h"
14
15
/**
16
 * FuIfdBios:
17
 *
18
 * An Intel BIOS section.
19
 *
20
 * See also: [class@FuFirmware]
21
 */
22
23
G_DEFINE_TYPE(FuIfdBios, fu_ifd_bios, FU_TYPE_IFD_IMAGE)
24
25
#define FU_IFD_BIOS_FIT_SIGNATURE 0x5449465F
26
27
static gboolean
28
fu_ifd_bios_parse(FuFirmware *firmware,
29
      GInputStream *stream,
30
      FuFirmwareParseFlags flags,
31
      GError **error)
32
1.72k
{
33
1.72k
  gsize offset = 0;
34
1.72k
  gsize streamsz = 0;
35
1.72k
  guint img_cnt = 0;
36
37
  /* get size */
38
1.72k
  if (!fu_input_stream_size(stream, &streamsz, error))
39
0
    return FALSE;
40
41
  /* read each volume in order */
42
13.8k
  while (offset < streamsz) {
43
12.0k
    g_autoptr(FuFirmware) firmware_tmp = fu_efi_volume_new();
44
12.0k
    g_autoptr(GError) error_local = NULL;
45
46
    /* FV */
47
12.0k
    if (!fu_firmware_parse_stream(firmware_tmp, stream, offset, flags, &error_local)) {
48
8.42k
      g_debug("failed to read volume @0x%x of 0x%x: %s",
49
8.42k
        (guint)offset,
50
8.42k
        (guint)streamsz,
51
8.42k
        error_local->message);
52
8.42k
      offset += 0x1000;
53
8.42k
      continue;
54
8.42k
    }
55
3.66k
    fu_firmware_set_offset(firmware_tmp, offset);
56
3.66k
    if (!fu_firmware_add_image_full(firmware, firmware_tmp, error))
57
0
      return FALSE;
58
59
    /* next! */
60
3.66k
    offset += fu_firmware_get_size(firmware_tmp);
61
3.66k
    img_cnt++;
62
3.66k
  }
63
64
  /* found nothing */
65
1.72k
  if (img_cnt == 0) {
66
294
    g_set_error_literal(error,
67
294
            FWUPD_ERROR,
68
294
            FWUPD_ERROR_INVALID_FILE,
69
294
            "no EFI firmware volumes");
70
294
    return FALSE;
71
294
  }
72
73
  /* success */
74
1.42k
  return TRUE;
75
1.72k
}
76
77
static void
78
fu_ifd_bios_init(FuIfdBios *self)
79
1.72k
{
80
1.72k
  fu_firmware_set_alignment(FU_FIRMWARE(self), FU_FIRMWARE_ALIGNMENT_4K);
81
1.72k
  fu_firmware_set_images_max(FU_FIRMWARE(self), 1024);
82
1.72k
}
83
84
static void
85
fu_ifd_bios_class_init(FuIfdBiosClass *klass)
86
1
{
87
1
  FuFirmwareClass *firmware_class = FU_FIRMWARE_CLASS(klass);
88
1
  firmware_class->parse = fu_ifd_bios_parse;
89
1
}
90
91
/**
92
 * fu_ifd_bios_new:
93
 *
94
 * Creates a new #FuFirmware
95
 *
96
 * Since: 1.6.2
97
 **/
98
FuFirmware *
99
fu_ifd_bios_new(void)
100
1.72k
{
101
1.72k
  return FU_FIRMWARE(g_object_new(FU_TYPE_IFD_BIOS, NULL));
102
1.72k
}