diff --git a/src/boot/chid.c b/src/boot/chid.c index 6005b0e8654..69e68e7d019 100644 --- a/src/boot/chid.c +++ b/src/boot/chid.c @@ -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; diff --git a/src/boot/chid.h b/src/boot/chid.h index c31f08d53b5..17096cc8622 100644 --- a/src/boot/chid.h +++ b/src/boot/chid.h @@ -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 index 00000000000..ef769eecadc --- /dev/null +++ b/src/boot/hwids/device4.json @@ -0,0 +1,9 @@ +{ + "type": "uefi-fw", + "name": "Device 4", + "fwid": "test,vmware", + "hwids": [ + "208a77d5-ba4b-518a-8ea7-18eab0e50654", + "4a8a248d-9e6b-5216-b83e-6cdf9bde8d0d" + ] +} diff --git a/src/boot/meson.build b/src/boot/meson.build index d48d79648b2..cc5102c5518 100644 --- a/src/boot/meson.build +++ b/src/boot/meson.build @@ -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, diff --git a/src/boot/pe.c b/src/boot/pe.c index b69254e1ef3..173b2c0898f 100644 --- a/src/boot/pe.c +++ b/src/boot/pe.c @@ -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; diff --git a/src/boot/test-chid-match.c b/src/boot/test-chid-match.c index e9df4e12269..415681f201c 100644 --- a/src/boot/test-chid-match.c +++ b/src/boot/test-chid-match.c @@ -10,40 +10,65 @@ 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[] = { { - .manufacturer = "First Vendor", - .product_name = "Device 1", - .product_sku = "KD01", - .family = "Laptop X", - .baseboard_product = "FODM1", - .baseboard_manufacturer = "First ODM", + .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 = "Second Vendor", - .product_name = "Device 2", - .product_sku = "KD02", - .family = "Laptop 2", - .baseboard_product = "SODM2", - .baseboard_manufacturer = "Second 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 = "First Vendor", - .product_name = "Device 3", - .product_sku = "KD03", - .family = "Tablet Y", - .baseboard_product = "FODM2", - .baseboard_manufacturer = "First 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, + }, + { + .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); } }