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

nixos/systemd-boot: add support for devicetree entry #319422

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

jmbaur
Copy link
Contributor

@jmbaur jmbaur commented Jun 13, 2024

Description of changes

The Boot Loader Specification allows for using a key called "devicetree" for specifying which devicetree the bootloader should use during boot. With regards to systemd-boot, this key is used to specify which file should be picked up from the ESP to install to the EFI DTB Configuration Table. Linux then uses this Configuration Table to setup the machine. This change is similar to the one done in #295096, where that change was for adding DTB support to systemd-stub, and this is for systemd-boot.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@ElvishJerricco
Copy link
Contributor

How do we feel about how this relates to the inclusion of device trees in bootspec v2?

@jmbaur jmbaur force-pushed the systemd-boot-devicetree branch 3 times, most recently from be5f8f7 to 738a5b3 Compare July 17, 2024 02:44
@JulienMalka
Copy link
Member

How do we feel about how this relates to the inclusion of device trees in bootspec v2?

I think we can add it as an extension pending bootspec V2 RFC completion.

@colemickens
Copy link
Member

Hi. I'm testing this instead of my attempt in #331003.

I noticed there's a newline missing:

╰🡒  cat /tmp/sda1/loader/entries/nixos-generation-1.conf
title NixOS
version Generation 1 NixOS Vicuna 24.11.20240730.b3ef191 (Linux 6.10.0-next-20240725), built on 1970-01-06
linux /EFI/nixos/l6n5mwmryhawmrx3crs5ikwqx94y5igi-linux-6.10.0-next-20240725-Image.efi
initrd  /EFI/nixos/p16gw3jx2s49zyq71z4kwjvrhh5d8mmi-initrd-linux-6.10.0-next-20240725-initrd.efi
options init=/nix/store/r29fw33486lly64xfjhy7fcfvkn2gk06-nixos-system-sdxbootstrap-24.11.20240730.b3ef191/init clk_ignore_unused pd_ignore_unused efi=novamap root=fstab loglevel=4
machine-id 04151900790d4a23b84af8b95772a6bc
sort-key nixor-defaultdevicetree /EFI/nixos/qcom-x1e80100-lenovo-yoga-slim7x.dtb.efi

note how the devicetree line is appended to the sort-key line instead of being on its own line.

Otherwise, this is sharp, definitely nicer than my approach. I'd love to see something like this make it in.

@jmbaur
Copy link
Contributor Author

jmbaur commented Jul 31, 2024

Thanks @colemickens! I hadn't been able to get around to testing after the latest rebase, should be good now

@jmbaur
Copy link
Contributor Author

jmbaur commented Jul 31, 2024

@ofborg test systemd-boot.basic systemd-boot.bootCounting

@colemickens
Copy link
Member

@jmbaur seems fixed. I don't want to ask too much, but a new test for this would be cool.

@jmbaur
Copy link
Contributor Author

jmbaur commented Jul 31, 2024

Not too much at all, we should be able to use qemu's dumbdtb to do it. I'll whip one up

The [Boot Loader Specification](https://uapi-group.org/specifications/specs/boot_loader_specification/)
allows for using a key called "devicetree" for specifying which
devicetree the bootloader should use during boot. With regards to
systemd-boot, this key is used to specify which file should be picked up
from the ESP to install to the EFI DTB Configuration Table. Linux then uses
this Configuration Table to setup the machine. This change is similar to
the one done in NixOS#295096, where that
change was for adding DTB support to systemd-stub, and this is for
systemd-boot.
@jmbaur
Copy link
Contributor Author

jmbaur commented Aug 1, 2024

So testing this in an actually bootable scenario isn't as straightforward as I thought it might be. Since qemu will create the devicetree blob based on the configured peripherals requested on the command line at runtime, we would have to duplicate all the flags that the test framework passes in order to take advantage of the dumpdtb parameter to get a working dtb. Since these flags might change over time as the NixOS VM test framework changes, it would probably be a frustrating problem where tests start to fail for strange reasons where the DTBs don't match up. Instead, I added an assertion with just a dummy dtb file to ensure that the boot entry files are populated correctly, but it is not expected for the entry to be bootable by qemu. In the real-world this isn't an issue as the DTB is available prior to boot (usually built from linux source).

@jmbaur jmbaur closed this Aug 1, 2024
@jmbaur jmbaur reopened this Aug 1, 2024
@jmbaur
Copy link
Contributor Author

jmbaur commented Aug 1, 2024

Shoot, the comment button is too close to the Close with comment button, my bad :)

@jmbaur
Copy link
Contributor Author

jmbaur commented Aug 2, 2024

@ofborg test systemd-boot.specialisation

Copy link
Member

@JulienMalka JulienMalka left a comment

Choose a reason for hiding this comment

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

The code looks good to me although I did not test this on real hardware.

@fpletz fpletz merged commit 97ebf11 into NixOS:master Aug 6, 2024
38 of 39 checks passed
@jmbaur jmbaur deleted the systemd-boot-devicetree branch August 6, 2024 13:25
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/announcing-abandoning-nixos-snapdragon-elite/50422/1

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

Successfully merging this pull request may close these issues.

7 participants