Skip to content

uefi-raw: Add Device Path protocol definitions. #1435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

uefi-raw: Add Device Path protocol definitions. #1435

wants to merge 3 commits into from

Conversation

kukrimate
Copy link

This pull requests adds definitions for examining device path components.

These were derived from edk2 (mainly the comments), so I added the edk2 license on top of the file.
I belive edk2's BSD type license is compatible with MPL-2.0, but is mixed license code okay in this project?

Some Device Paths have variable length trailer data, so a fully safe API
would be rather difficult to provide without reliance on custom DSTs
(and somewhat breaking the seperation of concerns between uefi-raw and uefi).

It does not matter for the header as it only contain u8s. However more
complex device paths that need to embed the header are also packed structs.

Signed-off-by: Mate Kukri <[email protected]>
Some Device Paths have variable length trailer data, so a fully safe API
would be rather difficult to provide without reliance on custom DSTs
(and somewhat breaking the seperation of concerns between uefi-raw and uefi).

Presence of this in just uefi-raw is still useful for applications intending
to examine Device Paths.

Signed-off-by: Mate Kukri <[email protected]>
#[derive(Debug)]
#[repr(C)]
#[derive(Copy,Clone,Debug)]
#[repr(C,packed)]
Copy link
Member

@phip1611 phip1611 Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: I'm fine with a unit test that ensures the ABI/size_of, tho! We also do this in other parts of the crate I think

Please don't use packed. Experience shows that packed makes
it annoying to access members. Only use it if it is necessary to get the
right layout.
Here, it doesn't seem to have an effect. Look:

#[repr(C)]
pub struct Base {
    pub major_type: u8,
    pub sub_type: u8,
    pub length: [u8; 2],
}

#[repr(C, packed)]
pub struct Packed {
    pub major_type: u8,
    pub sub_type: u8,
    pub length: [u8; 2],
}

fn main() {
    assert_eq!(size_of::<Base>(), size_of::<Packed>());
    assert_eq!(align_of::<Base>(), align_of::<Packed>());
}


/// PCI Device Path.
#[derive(Debug)]
#[repr(C,packed)]
Copy link
Member

@phip1611 phip1611 Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[repr(C,packed)]
#[repr(C)]

Same here. Please instead add a unit test that tests the ABI guarantees. Please only use packed if the default layout is wrong


/// PCCARD Device Path.
#[derive(Debug)]
#[repr(C,packed)]
Copy link
Member

@phip1611 phip1611 Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[repr(C,packed)]
#[repr(C)]

and here .. and so on

@@ -1,4 +1,60 @@
use crate::{guid, Char16, Guid};
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this is necessary. Right, @nicholasbishop ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree; we're just adding types defined in the UEFI spec here, no need to add the EDK2 license.

@phip1611
Copy link
Member

Thanks for the PR! I'll leave final feedback to @nicholasbishop who is more experienced with our Device Path code and infrastructure

@@ -1,4 +1,60 @@
use crate::{guid, Char16, Guid};
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree; we're just adding types defined in the UEFI spec here, no need to add the EDK2 license.

/// 0x00 - Public Device Address
/// 0x01 - Random Device Address
pub address_type: u8,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to hold off on manually adding specific device path node types to uefi-raw. In the uefi crate, we're autogenerating code for node types, and I think we can just extend that to generate code in uefi-raw too.

@kukrimate
Copy link
Author

I'd like to hold off on manually adding specific device path node types to uefi-raw. In the uefi crate, we're autogenerating code for node types, and I think we can just extend that to generate code in uefi-raw too.

Understood, this was code I origianlly did for for a project (personal) where I've been only using uefi-raw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants