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

linux_rpi: add support for 64-bit Raspberry Pi 3 #46653

Closed
wants to merge 2 commits into from

Conversation

lopsided98
Copy link
Contributor

Motivation for this change

The Raspberry Pi vendor kernel has a config for a 64-bit Raspberry Pi 3 kernel, but this is currently not supported in NixOS. I need this config to use a driver that is not included in the upstream kernel.

The device trees are different for this config, so this requires a different postFixup phase for aarch64.

This kernel boots correctly and I have not found any issues with it.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@lopsided98 lopsided98 changed the title linux_rpi: add support for Raspberry Pi 3 linux_rpi: add support for 64-bit Raspberry Pi 3 Sep 14, 2018
@lopsided98
Copy link
Contributor Author

cc @dezgeg

@Mic92 Mic92 requested a review from dezgeg September 15, 2018 11:01
@mogorman
Copy link
Contributor

@lopsided98 if I wanted to try this pr on my pi how would I go about doing it?

@lopsided98
Copy link
Contributor Author

@mogorman Add boot.kernelPackages = pkgs.linuxPackages_rpi; to your config and then run nixos-rebuild -I nixpkgs=/path/to/nixpkgs switch where /path/to/nixpkgs is the nixpkgs git repo with this branch checked out.

@dezgeg
Copy link
Contributor

dezgeg commented Sep 20, 2018

Ah, I didn't know they support this configuration.

@lopsided98 How about writing the DTB conditionals like this though: dezgeg@f3ac96a? Can you runtime-test that one? At least it builds for me (after rebasing on top of the latest linux-rpi update I did so that it doesn't fail on bcm2710-rpi-cm3.dtb).

@lopsided98
Copy link
Contributor Author

@dezgeg Your patch boots correctly for me.

@mogorman
Copy link
Contributor

@lopsided98 thanks that booted for me. I did have a question if you know how to resolve. I am trying to get my clusterhat, clusterhat.com to show up. it uses the pi i2c hat logic to populate /proc/device-tree/hat

when using the raspberry pi kernel i thought it would just show up but it did not. I tried enabling i2c as described in some of the guides ive found but no change to my proc tree. do you happen to know how to fix this?

information about hat definition https://github.com/raspberrypi/hats

@lopsided98
Copy link
Contributor Author

@mogorman I don't know much about the hat spec, but it looks like the firmware/bootloader downloads a device tree overlay from the hat. By default, NixOS uses U-Boot as a intermediate bootloader between the standard RPi bootloader and the kernel. U-Boot does not pass device tree overlays from the RPi bootloader to the kernel, which is probably why your device is not detected (this also means dtoverlay options in config.txt have no effect).

You can switch to using just the RPi bootloader w/o U-Boot, by adding boot.loader.raspberryPi.enable = true to your config, and removing boot.loader.generic-extlinux-compatible.enable = true. Note that this will cause you to lose the generation selection menu, so if you ever break your configuration, you will have to manually modify your boot partition to boot an older generation (the files are there, there is just no way to automatically boot them).

@mogorman
Copy link
Contributor

in my config i have

  # NixOS wants to enable GRUB by default
  boot.loader.grub.enable = false;
  # Enables the generation of /boot/extlinux/extlinux.conf
  boot.loader.generic-extlinux-compatible.enable = false;
  boot.loader.raspberryPi.enable = true;
  boot.loader.raspberryPi.version = 3;
  boot.loader.raspberryPi.uboot.enable = true;
  boot.kernelPackages = pkgs.linuxPackages_rpi;

but it still boots up with the generic ext linux loader every time.

@lopsided98
Copy link
Contributor Author

@mogorman Remove this line:

boot.loader.raspberryPi.uboot.enable = true;

That option enables U-Boot, which also enables generic-extlinux-compatible behind the scenes. The difference between the the two is that raspberryPi.uboot installs the RPi U-Boot binary into the boot partition, while the generic-extlinux-compatible manages U-Boot's extlinux configuration files. generic-extlinux-compatible by itself is useful for boards that use U-Boot but have a different way of installing it that is not handled by NixOS.

@mogorman
Copy link
Contributor

@lopsided98 thank you for the advice. following that I am getting the raspberry pi firmware on boot but it doesnt seem to boot the linuxPackages_latest kernel or the rpi one when using aarch64. not sure why yet it just hangs on the rainbow screen.

@lopsided98
Copy link
Contributor Author

I just looked at my config and remembered that I had to add:

initramfs initrd followkernel

to config.txt to get it to boot. Once you get it booted, you can that line to boot.loader.raspberryPi.firmwareConfig.

@lopsided98
Copy link
Contributor Author

lopsided98 commented Sep 23, 2018

@mogorman Wait, are you using a Raspberry Pi 3? I assumed you were using a Zero because I didn't realize the clusterhat used a used a full sized Pi as well, but then I looked back at your config and saw that you had boot.loader.raspberryPi.version = 3 (of course I should have realized because you were asking about it on this PR).

In that case, your problem is probably that the RPi bootloader doesn't currently work out of the box with the RPi 3 in 64 bit mode in NixOS. By default it will look for a file named kernel8.img to boot in 64 bit mode, but NixOS installs the kernel to kernel7.img. I have a branch that fixes this, as well as another issue I forgot about with the different device tree location of the 64 bit kernel. Note that you still need the initramfs line.

Now ARMv6 and ARMv7 builds avoid installing DTBs for boards where the
resulting kernel won't run just like the aarch64 builds already do.
Also deduplicates the logic a bit.
@lopsided98
Copy link
Contributor Author

@mogorman See #47250

@mogorman
Copy link
Contributor

@lopsided98 thanks will read now

@dezgeg
Copy link
Contributor

dezgeg commented Sep 24, 2018

Changes applied in https://git.io/fAbII.

@dezgeg dezgeg closed this Sep 24, 2018
@lopsided98 lopsided98 deleted the linux-rpi-3 branch September 24, 2018 13:09
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.

None yet

4 participants