Skip to content
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

Boot from memory device path #305

Conversation

rbradford
Copy link
Member

  • efi: Refactor device path protocol parsing
  • efi: Refactor construction of file based device path
  • efi: Refactor EFI device path generatation for loaded image
  • efi: Use DevicePath::generate() for executing the main EFI binary
  • efi: Consistently support filenames up to 256 characters
  • efi: Move FileDevicePathProtocol struct to where it is used
  • efi: Clarify naming of type for two FileDevicePathProtocol
  • efi: Add support for memory mapped device path
  • efi: Add support for booting from a memory mapped device path
  • efi: Refactor code for loading image

GRUB on (at least RISC-V) loads the guest kernel directly into memory and then
expects the firmware to parse it from there - it does this by using a device
path of type PCI and subtype memory mapped.

With this change the Linux kernel boots on RISC-V if the kernel command line is
modified to specify a fixed rootfs as there are issues with the initramfs.

@rbradford rbradford force-pushed the 2023-12-18-boot-from-memory-device-path branch from 93ec0f8 to ba896c6 Compare December 19, 2023 18:10
@rbradford rbradford requested a review from retrage December 22, 2023 17:38
Copy link
Contributor

@retrage retrage left a comment

Choose a reason for hiding this comment

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

It looks good to me. I just have a few minor suggestions:

  • Use the offset_of!() macro to calculate the offset to the field
  • Avoid hardcoding the length of the device path
  • The max length of the path should be 256 in UCS2 (16 bits)

src/efi/mod.rs Outdated Show resolved Hide resolved
src/efi/mod.rs Outdated Show resolved Hide resolved
src/efi/mod.rs Outdated Show resolved Hide resolved
src/efi/mod.rs Outdated Show resolved Hide resolved
src/efi/mod.rs Outdated Show resolved Hide resolved
src/efi/mod.rs Outdated Show resolved Hide resolved
src/efi/mod.rs Outdated Show resolved Hide resolved
src/efi/mod.rs Outdated Show resolved Hide resolved
src/efi/mod.rs Outdated Show resolved Hide resolved
Convert the EFI device path protocol structure into a Rust structure in
order to be able to handle different device path types (e.g. memory
backed) in the future.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
Rather than construct the device path when creating the image handle do
so earlier so that ultimately a NULL path could be provided in the case
of loading from memory.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
Add a DevicePath::generate() method to generate the device path from the
parsed device path.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
Previously the path in the FileDevicePathProtocol was limited to 128
ascii characters.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
This will prevent it clashing when generating other types of device
paths.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
Grub will load the kernel into memory and ask the firmware to parse that
as a PE binary. In order to reuse the existing infrastructure the memory
range provided is turned into a struct that implements the fat::Read
trait.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
Remove some duplicated code for loading an image by extracting it out to
its own function.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
@rbradford rbradford force-pushed the 2023-12-18-boot-from-memory-device-path branch from ba896c6 to 70e286b Compare December 29, 2023 11:25
@rbradford rbradford merged commit 83d88b6 into cloud-hypervisor:main Dec 29, 2023
5 checks passed
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