Compare commits
2 Commits
4859bce6c7
...
d18381595c
Author | SHA1 | Date |
---|---|---|
Ani Sinha | d18381595c | |
Ani Sinha | c5d061949c |
|
@ -22,9 +22,12 @@
|
|||
#include "util.h"
|
||||
|
||||
/* Validate the descriptor macros a bit that they match our expectations */
|
||||
assert_cc(DEVICE_DESCRIPTOR_DEVICETREE == UINT32_C(0x1000001C));
|
||||
assert_cc(DEVICE_DESCRIPTOR_DEVICETREE == UINT32_C(0x10000020));
|
||||
assert_cc(DEVICE_DESCRIPTOR_EFIFW == UINT32_C(0x20000020));
|
||||
assert_cc(DEVICE_SIZE_FROM_DESCRIPTOR(DEVICE_DESCRIPTOR_DEVICETREE) == sizeof(Device));
|
||||
assert_cc(DEVICE_TYPE_FROM_DESCRIPTOR(DEVICE_DESCRIPTOR_DEVICETREE) == DEVICE_TYPE_DEVICETREE);
|
||||
assert_cc(DEVICE_SIZE_FROM_DESCRIPTOR(DEVICE_DESCRIPTOR_EFIFW) == sizeof(Device));
|
||||
assert_cc(DEVICE_TYPE_FROM_DESCRIPTOR(DEVICE_DESCRIPTOR_EFIFW) == DEVICE_TYPE_EFIFW);
|
||||
|
||||
/**
|
||||
* smbios_to_hashable_string() - Convert ascii smbios string to stripped char16_t.
|
||||
|
@ -107,13 +110,15 @@ EFI_STATUS chid_match(const void *hwid_buffer, size_t hwid_length, const Device
|
|||
return log_error_status(status, "Failed to populate board CHIDs: %m");
|
||||
|
||||
size_t n_devices = 0;
|
||||
uint32_t dev_type;
|
||||
|
||||
/* Count devices and check validity */
|
||||
for (; (n_devices + 1) * sizeof(*devices) < hwid_length;) {
|
||||
|
||||
dev_type = DEVICE_TYPE_FROM_DESCRIPTOR(devices[n_devices].descriptor);
|
||||
if (devices[n_devices].descriptor == DEVICE_DESCRIPTOR_EOL)
|
||||
break;
|
||||
if (devices[n_devices].descriptor != DEVICE_DESCRIPTOR_DEVICETREE)
|
||||
if ((dev_type != DEVICE_TYPE_EFIFW) && (dev_type != DEVICE_TYPE_DEVICETREE))
|
||||
return EFI_UNSUPPORTED;
|
||||
n_devices++;
|
||||
}
|
||||
|
|
|
@ -11,11 +11,13 @@
|
|||
|
||||
enum {
|
||||
DEVICE_TYPE_DEVICETREE = 0x1, /* A devicetree blob */
|
||||
DEVICE_TYPE_EFIFW, /* an efi firmware blob */
|
||||
|
||||
/* Maybe later additional types for:
|
||||
* - CoCo Bring-Your-Own-Firmware
|
||||
* - ACPI DSDT Overrides
|
||||
* - … */
|
||||
_DEVICE_TYPE_MAX,
|
||||
};
|
||||
|
||||
#define DEVICE_SIZE_FROM_DESCRIPTOR(u) ((uint32_t) (u) & UINT32_C(0x0FFFFFFF))
|
||||
|
@ -23,6 +25,7 @@ enum {
|
|||
#define DEVICE_MAKE_DESCRIPTOR(type, size) (((uint32_t) (size) | ((uint32_t) type << 28)))
|
||||
|
||||
#define DEVICE_DESCRIPTOR_DEVICETREE DEVICE_MAKE_DESCRIPTOR(DEVICE_TYPE_DEVICETREE, sizeof(Device))
|
||||
#define DEVICE_DESCRIPTOR_EFIFW DEVICE_MAKE_DESCRIPTOR(DEVICE_TYPE_EFIFW, sizeof(Device))
|
||||
#define DEVICE_DESCRIPTOR_EOL UINT32_C(0)
|
||||
|
||||
typedef struct Device {
|
||||
|
@ -36,6 +39,14 @@ typedef struct Device {
|
|||
uint32_t name_offset; /* nul-terminated string or 0 if not present */
|
||||
uint32_t compatible_offset; /* nul-terminated string or 0 if not present */
|
||||
} devicetree;
|
||||
struct {
|
||||
/* Offsets are relative to the beginning of the .hwids PE section.
|
||||
They are nul-terminated strings when present or 0 if not present */
|
||||
uint32_t id_offset; /* identifier for the firmware blob */
|
||||
uint32_t metadata_offset; /* firmware metadata string */
|
||||
uint32_t compatible_offset; /* compatibility identifier to match a specific fw blob */
|
||||
} efifw;
|
||||
|
||||
/* fields for other descriptor types… */
|
||||
};
|
||||
} _packed_ Device;
|
||||
|
@ -45,16 +56,19 @@ assert_cc(offsetof(Device, descriptor) == 0);
|
|||
assert_cc(offsetof(Device, chid) == 4);
|
||||
assert_cc(offsetof(Device, devicetree.name_offset) == 20);
|
||||
assert_cc(offsetof(Device, devicetree.compatible_offset) == 24);
|
||||
assert_cc(sizeof(Device) == 28);
|
||||
assert_cc(offsetof(Device, efifw.id_offset) == 20);
|
||||
assert_cc(offsetof(Device, efifw.metadata_offset) == 24);
|
||||
assert_cc(offsetof(Device, efifw.compatible_offset) == 28);
|
||||
assert_cc(sizeof(Device) == 32);
|
||||
|
||||
static inline const char* device_get_name(const void *base, const Device *device) {
|
||||
static inline const char* device_get_devicetree_name(const void *base, const Device *device) {
|
||||
if (device->descriptor != DEVICE_DESCRIPTOR_DEVICETREE)
|
||||
return NULL;
|
||||
|
||||
return device->devicetree.name_offset == 0 ? NULL : (const char *) ((const uint8_t *) base + device->devicetree.name_offset);
|
||||
}
|
||||
|
||||
static inline const char* device_get_compatible(const void *base, const Device *device) {
|
||||
static inline const char* device_get_devicetree_compatible(const void *base, const Device *device) {
|
||||
if (device->descriptor != DEVICE_DESCRIPTOR_DEVICETREE)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ static bool pe_use_this_dtb(
|
|||
if (!device || !base)
|
||||
return false;
|
||||
|
||||
const char *compatible = device_get_compatible(base, device);
|
||||
const char *compatible = device_get_devicetree_compatible(base, device);
|
||||
if (!compatible)
|
||||
return false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue