Skip to content

Add DevicePath functions/utilities #10

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

Merged
merged 6 commits into from
Jun 27, 2017
Merged

Add DevicePath functions/utilities #10

merged 6 commits into from
Jun 27, 2017

Conversation

csssuf
Copy link
Owner

@csssuf csssuf commented Jun 22, 2017

Primary changes:

  • DevicePathUtilities for manipulating DevicePathProtocol structs
  • DevicePathFromText for parsing strings into DevicePathProtocol structs
  • create_file_device_node for creating DevicePathProtocol structs for files

@csssuf csssuf requested a review from bgilbert June 22, 2017 19:21

for i in 0..filename_len as isize{
unsafe {
*file_name_ptr.offset(i) = *filename.as_ptr().offset(i) as u16;

Choose a reason for hiding this comment

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

Should be setting file_name_ptr from filename_ptr, not filename.as_ptr().

Also maybe some better names?

impl DevicePathFromTextProtocol {
pub fn text_to_device_path_node(&self, path: &str) -> Result<&DevicePathProtocol, Status> {
str_to_utf16_ptr(path)
.map(|utf16_str| unsafe { &*((self.text_to_device_path_node)(utf16_str)) })

Choose a reason for hiding this comment

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

Is utf16_str leaked?


pub fn text_to_device_path(&self, path: &str) -> Result<&DevicePathProtocol, Status> {
str_to_utf16_ptr(path)
.map(|utf16_str| unsafe { &*((self.text_to_device_path)(utf16_str)) })

Choose a reason for hiding this comment

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

Likewise.

.boot_services()
.locate_protocol::<DevicePathUtilitiesProtocol>(0 as *const CVoid)
.and_then(|utilities| {
utilities.create_device_node(4, 4, node_size_bytes as u16)

Choose a reason for hiding this comment

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

Is 4 worth a couple of constants?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, probably. Realistically the best thing to do is to flesh out all the DevicePath types and subtypes from the spec, I was just a little hesitant to do that since we're not using many of them.

@csssuf
Copy link
Owner Author

csssuf commented Jun 27, 2017

Updated with requested changes.


for i in 0..filename_len as isize{
unsafe {
*node_filename_ptr.offset(i) = *filename_ptr.offset(i) as u16;

Choose a reason for hiding this comment

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

Is as u16 redundant here?


#[allow(non_camel_case_types)]
#[repr(u8)]
pub enum MessagingSubTypes {

Choose a reason for hiding this comment

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

Please either sort, or leave a comment explaining the sort order.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Sorted by value, since the spec order doesn't seem to have any rhyme or reason.

IPv6 = 0xD,
UART = 0xE,
USBClass = 0xF,
// The EFI specification calls this type "1394", but that won't work as an enum variant for

Choose a reason for hiding this comment

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

Nope.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Oops, yep. Thanks.

csssuf added 6 commits June 27, 2017 15:24
Add enums for all device path types as laid out in the UEFI spec. Also,
add implementations of Into<u8> for each.
Instead of using *const u16s and Console.write_raw() in
DevicePathToTextProtocol, use &str and write() instead.
Add a function to allocate and create a DevicePathProtocol struct
containing a filename.
CVoid is needed for passing to some functions.
@csssuf csssuf merged commit ad3bd8f into master Jun 27, 2017
@csssuf csssuf deleted the device-path branch June 27, 2017 23:18
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.

2 participants