]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
chid_match: match only against the provided device type 35747/head
authorAni Sinha <anisinha@redhat.com>
Tue, 24 Dec 2024 04:16:50 +0000 (09:46 +0530)
committerAni Sinha <anisinha@redhat.com>
Sun, 5 Jan 2025 04:10:55 +0000 (09:40 +0530)
When devices of different types are present, chid_match() should only try to
match the devices that are of specific type. The caller of chid_match()
provides the type of device to match against and chid_match() should only try
to find a match against this device type.

This change also adds necessary unit test changes for the new uefi firmware
type device entry.

src/boot/chid.c
src/boot/chid.h
src/boot/hwids/device4.json [new file with mode: 0644]
src/boot/meson.build
src/boot/pe.c
src/boot/test-chid-match.c

index 6005b0e8654092a5c8bcd990f97b2c269afffee0..69e68e7d019173d0ca72476257ba738db07e5455 100644 (file)
@@ -91,7 +91,7 @@ static EFI_STATUS populate_board_chids(EFI_GUID ret_chids[static CHID_TYPES_MAX]
         return EFI_SUCCESS;
 }
 
-EFI_STATUS chid_match(const void *hwid_buffer, size_t hwid_length, const Device **ret_device) {
+EFI_STATUS chid_match(const void *hwid_buffer, size_t hwid_length, uint32_t match_type, const Device **ret_device) {
         EFI_STATUS status;
 
         if ((uintptr_t) hwid_buffer % alignof(Device) != 0)
@@ -130,6 +130,8 @@ EFI_STATUS chid_match(const void *hwid_buffer, size_t hwid_length, const Device
                 FOREACH_ARRAY(dev, devices, n_devices) {
                         /* Can't take a pointer to a packed struct member, so copy to a local variable */
                         EFI_GUID chid = dev->chid;
+                        if (DEVICE_TYPE_FROM_DESCRIPTOR(dev->descriptor) != match_type)
+                                continue;
                         if (efi_guid_equal(&chids[*i], &chid)) {
                                 *ret_device = dev;
                                 return EFI_SUCCESS;
index c31f08d53b5b6a6162d21fa46f804c18d099bd77..17096cc86224d75f156b240e68e9e7f5c8dee3fc 100644 (file)
@@ -98,4 +98,4 @@ static inline const char* device_get_fwid(const void *base, const Device *device
         return off == 0 ? NULL : (const char *) ((const uint8_t *) base + off);
 }
 
-EFI_STATUS chid_match(const void *chids_buffer, size_t chids_length, const Device **ret_device);
+EFI_STATUS chid_match(const void *chids_buffer, size_t chids_length, uint32_t match_type, const Device **ret_device);
diff --git a/src/boot/hwids/device4.json b/src/boot/hwids/device4.json
new file mode 100644 (file)
index 0000000..ef769ee
--- /dev/null
@@ -0,0 +1,9 @@
+{
+    "type": "uefi-fw",
+    "name": "Device 4",
+    "fwid": "test,vmware",
+    "hwids": [
+        "208a77d5-ba4b-518a-8ea7-18eab0e50654",
+        "4a8a248d-9e6b-5216-b83e-6cdf9bde8d0d"
+    ]
+}
index d48d79648b29dd5aceefc4b8065651a130de28e5..cc5102c5518849dc01a763077047509fe3a38453 100644 (file)
@@ -31,7 +31,7 @@ generate_hwids_section_py = find_program('generate-hwids-section.py')
 if conf.get('ENABLE_UKIFY') == 1
         test_hwids_section_c = custom_target(
                 'test-hwids-section.c',
-                input : ['hwids/device1.json', 'hwids/device2.json', 'hwids/device3.json'],
+                input : ['hwids/device1.json', 'hwids/device2.json', 'hwids/device3.json', 'hwids/device4.json'],
                 output : 'test-hwids-section.c',
                 command : [generate_hwids_section_py, meson.current_source_dir()/'hwids'],
                 capture : true,
index b69254e1ef3b6b9b317cd10008f6e35f69e90e05..173b2c0898ff65cdda80f32e717cf4c65bce1b0c 100644 (file)
@@ -323,7 +323,7 @@ static void pe_locate_sections(
                 if (PE_SECTION_VECTOR_IS_SET(&hwids_section)) {
                         hwids = (const uint8_t *) SIZE_TO_PTR(validate_base) + hwids_section.memory_offset;
 
-                        EFI_STATUS err = chid_match(hwids, hwids_section.memory_size, &device);
+                        EFI_STATUS err = chid_match(hwids, hwids_section.memory_size, DEVICE_TYPE_DEVICETREE, &device);
                         if (err != EFI_SUCCESS) {
                                 log_error_status(err, "HWID matching failed, no DT blob will be selected: %m");
                                 hwids = NULL;
index e9df4e12269b38c707c2a00960592c05e1318a98..415681f201c77f7d1a099ed5bfcabd2d84a45bea 100644 (file)
 extern uint8_t hwids_section_data[];
 extern size_t hwids_section_len;
 
-static const RawSmbiosInfo smbios_info[] = {
+static struct {
+        const RawSmbiosInfo smbios_info;
+        uint32_t device_type;
+} info[] = {
+        {
+                .smbios_info =  {
+                        .manufacturer           = "First Vendor",
+                        .product_name           = "Device 1",
+                        .product_sku            = "KD01",
+                        .family                 = "Laptop X",
+                        .baseboard_product      = "FODM1",
+                        .baseboard_manufacturer = "First ODM",
+                },
+                .device_type = DEVICE_TYPE_DEVICETREE,
+        },
         {
-                .manufacturer           = "First Vendor",
-                .product_name           = "Device 1",
-                .product_sku            = "KD01",
-                .family                 = "Laptop X",
-                .baseboard_product      = "FODM1",
-                .baseboard_manufacturer = "First ODM",
+                .smbios_info = {
+                        .manufacturer           = "Second Vendor",
+                        .product_name           = "Device 2",
+                        .product_sku            = "KD02",
+                        .family                 = "Laptop 2",
+                        .baseboard_product      = "SODM2",
+                        .baseboard_manufacturer = "Second ODM",
+                },
+                .device_type = DEVICE_TYPE_DEVICETREE,
         },
         {
-                .manufacturer           = "Second Vendor",
-                .product_name           = "Device 2",
-                .product_sku            = "KD02",
-                .family                 = "Laptop 2",
-                .baseboard_product      = "SODM2",
-                .baseboard_manufacturer = "Second ODM",
+                .smbios_info = {
+                        .manufacturer           = "First Vendor",
+                        .product_name           = "Device 3",
+                        .product_sku            = "KD03",
+                        .family                 = "Tablet Y",
+                        .baseboard_product      = "FODM2",
+                        .baseboard_manufacturer = "First ODM",
+                },
+                .device_type = DEVICE_TYPE_DEVICETREE,
         },
         {
-                .manufacturer           = "First Vendor",
-                .product_name           = "Device 3",
-                .product_sku            = "KD03",
-                .family                 = "Tablet Y",
-                .baseboard_product      = "FODM2",
-                .baseboard_manufacturer = "First ODM",
+                .smbios_info = {
+                        .manufacturer           = "VMware, Inc.",
+                        .product_name           = "VMware20,1",
+                        .product_sku            = "0000000000000001",
+                        .family                 = "VMware",
+                        .baseboard_product      = "VBSA",
+                        .baseboard_manufacturer = "VMware, Inc.",
+                },
+                .device_type = DEVICE_TYPE_UEFI_FW,
         },
 };
 
 static struct {
         const char *name;
         const char *compatible;
+        const char *fwid;
 } results[] = {
-        { "Device 1", "test,device-1" },
-        { "Device 2", "test,device-2" },
-        { "Device 3", "test,device-3" },
+        { "Device 1", "test,device-1", NULL },
+        { "Device 2", "test,device-2", NULL },
+        { "Device 3", "test,device-3", NULL },
+        { "Device 4", NULL, "test,vmware" },
 };
 
 static RawSmbiosInfo current_info = {};
@@ -55,14 +80,16 @@ void smbios_raw_info_get_cached(RawSmbiosInfo *ret_info) {
 }
 
 TEST(chid_match) {
-        for (size_t i = 0; i < ELEMENTSOF(smbios_info); i++) {
-                current_info = smbios_info[i];
+        for (size_t i = 0; i < ELEMENTSOF(info); i++) {
+                current_info = info[i].smbios_info;
                 const Device *dev = NULL;
                 /* Match and check */
-                ASSERT_EQ(chid_match(hwids_section_data, hwids_section_len, &dev), EFI_SUCCESS);
+                ASSERT_EQ(chid_match(hwids_section_data, hwids_section_len, info[i].device_type, &dev), EFI_SUCCESS);
                 ASSERT_NOT_NULL(dev);
+                ASSERT_EQ(DEVICE_TYPE_FROM_DESCRIPTOR(dev->descriptor), info[i].device_type);
                 ASSERT_STREQ(device_get_name(hwids_section_data, dev), results[i].name);
                 ASSERT_STREQ(device_get_compatible(hwids_section_data, dev), results[i].compatible);
+                ASSERT_STREQ(device_get_fwid(hwids_section_data, dev), results[i].fwid);
         }
 }