Skip to content

Conversation

nicholasbishop
Copy link
Member

@nicholasbishop nicholasbishop commented Nov 3, 2022

There are over 50 device path node types in the spec, of all shapes and sizes. Previously we just had support for three of them, and even for those we only supported reading them, not building new ones. This PR fixes that but it takes a fair amount of code -- apologies for the rather large PR :)

A lot of the code is generated; see xtask/src/device_path/README.md for an overview of why and how.

Fixes #401
Fixes #420

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

@nicholasbishop nicholasbishop force-pushed the bishop-build-device-path-codegen-12 branch 2 times, most recently from 16c7bbf to 866daef Compare November 7, 2022 03:05
@GabrielMajeri
Copy link
Collaborator

Thanks for the amazing effort to finish the addition of device path node types! There was some discussion in the past about using automatic code generation to cover more of the UEFI spec, but this is the first concrete implementation of the idea.

@nicholasbishop nicholasbishop force-pushed the bishop-build-device-path-codegen-12 branch from 866daef to ee6b57b Compare November 7, 2022 19:24
Copy link
Collaborator

@GabrielMajeri GabrielMajeri left a comment

Choose a reason for hiding this comment

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

The PR looks good to me now. @phip1611 what do you think?

See xtask/src/device_path/README.md for details of the design. The
actual generated code is added in the following commit.
The `device_path` module now exposes the generated submodules containing
all the packed node types.

The `device_path::build` module contains `DevicePathBuilder`, which
allows for constructing new device paths. It also exposes the generated
submodules containing all the builder node types.
These have been replaced by the generated types in `device_path_gen.rs`.
@nicholasbishop nicholasbishop force-pushed the bishop-build-device-path-codegen-12 branch from ee6b57b to 67df1eb Compare November 11, 2022 21:16
compilation-time drawbacks. It also introduces a new problem: `build.rs`
may not integrate well with non-cargo build systems.

That brings us to the solution actually implemented here, which is to
Copy link
Member

@phip1611 phip1611 Nov 11, 2022

Choose a reason for hiding this comment

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

Excellent write-up!

@phip1611
Copy link
Member

Thanks for putting all the effort into this! Awesome!

@phip1611 what do you think?

My knowledge regarding this part of the UEFI spec is very limited. But what I see looks very good!

@nicholasbishop nicholasbishop merged commit 1068d2e into rust-osdev:main Nov 11, 2022
@nicholasbishop nicholasbishop deleted the bishop-build-device-path-codegen-12 branch November 11, 2022 21:47
@phip1611
Copy link
Member

phip1611 commented Nov 11, 2022

Can someone give me please a high-level description in 2-3 sentences about what device path nodes are and especially where they are useful? When does an UEFI-application developer needs them? @nicholasbishop @GabrielMajeri

@nicholasbishop
Copy link
Member Author

I have a brief page in the book that tries to explain a bit, although it could definitely benefit from some more concrete examples: https://rust-osdev.github.io/uefi-rs/HEAD/concepts/device_paths.html

You can think of device paths as kind of like a different take on the Unix view of "everything is a file mounted somewhere under /". On a Linux system you might access a disk block device as /dev/sda. With device paths, you would instead have a more complicated sequence of nodes that maybe starts with some ACPI nodes, then maybe a node for the bus the drive is attached to, then a node for the disk itself. And unlike Unix paths which are treated as text, device paths are made up of binary nodes that vary quite a bit from one node type to another. To make things a little more confusing, one device path node type is a media file path, which can contain a normal-looking path like efi\boot\bootx64.efi. That kind of node would normally come towards the end of a device path, after nodes saying what disk that path belongs too.

Device paths can be helpful for distinguishing between handles and understanding their relationship. For example, all partitions on all disks attached to the system could have handles that support the BlockIO protocol. By looking at the common parent nodes in the associated device path, you could figure out which partitions are on which disk.

Hopefully that helps a bit clarify a bit :)

@phip1611
Copy link
Member

Very informative, thank you! :)

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.

Add an API for constructing device paths Expand the DevicePath API to make it easy to work with specific device path node types
3 participants