mirror of
https://github.com/systemd/systemd.git
synced 2025-01-18 10:04:04 +03:00
chid_match: match only against the provided device type
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.
This commit is contained in:
parent
5d0ac3528b
commit
5d614bae74
@ -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;
|
||||
|
@ -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);
|
||||
|
9
src/boot/hwids/device4.json
Normal file
9
src/boot/hwids/device4.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "uefi-fw",
|
||||
"name": "Device 4",
|
||||
"fwid": "test,vmware",
|
||||
"hwids": [
|
||||
"208a77d5-ba4b-518a-8ea7-18eab0e50654",
|
||||
"4a8a248d-9e6b-5216-b83e-6cdf9bde8d0d"
|
||||
]
|
||||
}
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user