-
-
Notifications
You must be signed in to change notification settings - Fork 186
uefi: significantly improve ergonomics of Handle (device path and component2 protocols) #1858
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
base: main
Are you sure you want to change the base?
Conversation
8dd6b43 to
b9c1651
Compare
Clean up the mess and follow our convention: - pub mod - mod - pub use - use
This change is a prerequisite for the subsequent commit introducing Display. Display already provides a to_string() method, so keeping the existing name would cause ambiguity. While fully qualified paths could be used to disambiguate, a dedicated name is significantly more convenient. It also makes the distinction between standard Rust strings and UEFI (UTF-16) strings explicit.
For device paths, it is very convenient to use the DevicePathToText protocol to visualize/print the device path. By providing a convenient Display impl, we improve the ergonomics of device paths significantly and reducing boilerplate.
b9c1651 to
312e542
Compare
In practice, UEFI applications frequently need to extract additional metadata from handles for logging, debugging, and user-facing selection. The Device Path and Component Name 2 protocols provide this information, but accessing them repeatedly requires non-trivial boilerplate. This change introduces convenience helpers on Handle to streamline common queries and improve ergonomics when working with these protocols.
312e542 to
a3c3e1e
Compare
| crate::proto::device_path::DevicePath, | ||
| crate::proto::driver::ComponentName2, | ||
| }; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix the cargo doc error:
| #[cfg(doc)] | |
| use crate::Status; |
| /// ); | ||
| /// ``` | ||
| #[cfg(feature = "alloc")] | ||
| pub fn component_name2(&self) -> Result<ScopedProtocol<ComponentName2>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the interests of keeping the API higher level, maybe we should call this just component_name?
| /// cn2_prot.controller_name(handle, None, "en").unwrap() | ||
| /// ); | ||
| /// ``` | ||
| #[cfg(feature = "alloc")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this cfg needed?
| /// .expect("should have device path"); | ||
| /// log::info!("device path: {device_path}"); | ||
| /// ``` | ||
| #[cfg(feature = "alloc")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, seems like this should work without alloc.
This PR prepares and implements a significant simplification of handling typical tasks with handles: printing a device path and using the component2 protocol.
addboot::open_protocol_[exclusive]if_exists()helpers (eventually replacing the base methods which we could deprecate)Handle::device_path()andHandle::component_name2()This improves the convenience and ergonomics in every Rust uefi code base I've seen so far at work and in private projects.
Checklist