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/uboot-builder: allow setting specific dtb #169297

Closed

Conversation

c0deaddict
Copy link
Member

Description of changes

Uboot on Raspberry Pi's is loading the wrong DTB file for some unknown reason. For example on a Pi 3B it's loading bcm2837 instead of bcm2710. This has been corrected with the following fixup on the linux-rpi kernel:

# Make copies of the DTBs named after the upstream names so that U-Boot finds them.

However, this fixup doesn't work anymore if custom hardware.deviceTree.overlays are used, since the overlays are compiled from source (?). I've looked for a proper workaround and came up with this patch. This patch allows specifying a specific DTB that needs to be loaded, instead of Uboot choosing one. The boot.loader.generic-extlinux-compatible already supports this option but this isn't passed by the raspberrypi uboot builder.

For the Pi 3B i've used this setting to fixate the correct DTB:

hardware.deviceTree.name = "broadcom/bcm2710-rpi-3-b.dtb";
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • 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/)
  • 22.05 Release Notes (or backporting 21.11 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
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@c0deaddict c0deaddict force-pushed the raspberrypi-uboot-specific-dtb branch from 07bf762 to 84157d7 Compare April 26, 2022 17:36
Copy link
Contributor

@klemensn klemensn left a comment

Choose a reason for hiding this comment

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

Device-tree specifications and blobs are known to break on updates so being able to use your own (hopefully known-to-work) file is definitely useful.


builderUboot = import ./uboot-builder.nix { inherit pkgs configTxt; inherit (cfg) version; };
builderGeneric = import ./raspberrypi-builder.nix { inherit pkgs configTxt; };

builder =
if cfg.uboot.enable then
"${builderUboot} -g ${toString cfg.uboot.configurationLimit} -t ${timeoutStr} -c"
"${builderUboot} -g ${toString cfg.uboot.configurationLimit} -t ${timeoutStr}"
+ lib.optionalString (dtCfg.name != null) " -n ${dtCfg.name}"
Copy link
Contributor

Choose a reason for hiding this comment

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

dtCfg.name is now an arbitrary user-provided string, so best use lib.strings.escapeShellArg.

Better yet, always sanitze:

builder = escapeShellArgs (
  if cfg.uboot.enable then [
    builderUboot
    "-g" "${toString cfg.uboot.configurationLimit}"
    "-t" timeoutStr
  ] ++ lib.optionals (dtCfg.name != null) [
    "-c" dtCfg.name
  ]  else [
    builderGeneric
    "-c"
  ]
);


builderUboot = import ./uboot-builder.nix { inherit pkgs configTxt; inherit (cfg) version; };
builderGeneric = import ./raspberrypi-builder.nix { inherit pkgs configTxt; };

builder =
if cfg.uboot.enable then
"${builderUboot} -g ${toString cfg.uboot.configurationLimit} -t ${timeoutStr} -c"
"${builderUboot} -g ${toString cfg.uboot.configurationLimit} -t ${timeoutStr}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just append the optional -n name after -c and thus diff churn?

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 7, 2023
@sorki
Copy link
Member

sorki commented Oct 19, 2023

I'm closing this since the boot.loader.raspberryPi was deprecated in #241534

You should migrate to boot.loader.generic-extlinux-compatible and you can find some pointers in #241534 (comment) while we figure out a better upgrade path which is being worked on at #261857

@sorki sorki closed this Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants