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

feat: add support for the RaspberryPi CM4 #170528

Merged
merged 15 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions nixos/modules/installer/sd-card/sd-image-aarch64.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
# Supported in newer board revisions
arm_boost=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1
Comment on lines +43 to +46
Copy link
Member

Choose a reason for hiding this comment

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

This might be problematic, depending on the CM4 usage. Is it a good idea to outright apply this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the vast majority of users will want this, and the minority who don't can still override it.


[all]
# Boot in 64-bit mode.
arm_64bit=1
Expand All @@ -65,6 +71,9 @@
cp ${pkgs.ubootRaspberryPi4_64bit}/u-boot.bin firmware/u-boot-rpi4.bin
cp ${pkgs.raspberrypi-armstubs}/armstub8-gic.bin firmware/armstub8-gic.bin
cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-4-b.dtb firmware/
cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-400.dtb firmware/
cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-cm4.dtb firmware/
cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-cm4s.dtb firmware/
'';
populateRootCommands = ''
mkdir -p ./files/boot
Expand Down
3 changes: 3 additions & 0 deletions nixos/modules/profiles/all-hardware.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ in
# SD cards.
"sdhci_pci"

# NVMe drives
"nvme"

# Firewire support. Not tested.
"ohci1394" "sbp2"

Expand Down
35 changes: 6 additions & 29 deletions pkgs/misc/uboot/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
, openssl
, swig
, meson-tools
, which
, armTrustedFirmwareAllwinner
, armTrustedFirmwareAllwinnerH616
, armTrustedFirmwareRK3328
Expand All @@ -19,10 +20,10 @@
}:

let
defaultVersion = "2021.10";
defaultVersion = "2022.01";
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 the newer version?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because our precious patches don't work there yet.

I might try rebasing them later, but I must admit I'm running out of gas :P

Copy link
Member

@samueldr samueldr Apr 27, 2022

Choose a reason for hiding this comment

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

[See other comment too]

I know I haven't been updating the last two releases (I wonder why r-ryantm didn't notice, and no one else did), but the goal is to prevent any kind of foward-incompatible drift; so we shouldn't block the upgrade to the current version.

defaultSrc = fetchurl {
url = "ftp://ftp.denx.de/pub/u-boot/u-boot-${defaultVersion}.tar.bz2";
sha256 = "1m0bvwv8r62s4wk4w3cmvs888dhv9gnfa98dczr4drk2jbhj7ryd";
hash = "sha256-gbRUMifbIowD+KG/XdvIE7C7j2VVzkYGTvchpvxoBBM=";
};
buildUBoot = {
version ? null
Expand Down Expand Up @@ -66,11 +67,14 @@ let
p.setuptools # for pkg_resources
]))
swig
which # for scripts/dtc-version.sh
];
depsBuildBuild = [ buildPackages.stdenv.cc ];

hardeningDisable = [ "all" ];

enableParallelBuilding = true;
lovesegfault marked this conversation as resolved.
Show resolved Hide resolved

makeFlags = [
"DTC=dtc"
"CROSS_COMPILE=${stdenv.cc.targetPrefix}"
Expand Down Expand Up @@ -102,9 +106,6 @@ let
runHook postInstall
'';

# make[2]: *** No rule to make target 'lib/efi_loader/helloworld.efi', needed by '__build'. Stop.
enableParallelBuilding = false;

dontStrip = true;

meta = with lib; {
Expand Down Expand Up @@ -373,14 +374,6 @@ in {
CONFIG_USB_EHCI_GENERIC=y
CONFIG_USB_XHCI_HCD=y
'';
extraPatches = [
# https://patchwork.ozlabs.org/project/uboot/list/?series=268007&state=%2A&archive=both
# Remove when upgrading to 2022.01
(fetchpatch {
url = "https://patchwork.ozlabs.org/series/268007/mbox/";
sha256 = "sha256-xn4Q959dgoB63zlmJepI41AXAf1kCycIGcmu4IIVjmE=";
})
];
extraMeta.platforms = [ "i686-linux" "x86_64-linux" ];
filesToInstall = [ "u-boot.rom" ];
};
Expand All @@ -401,28 +394,12 @@ in {
defconfig = "rpi_3_32b_defconfig";
extraMeta.platforms = ["armv7l-linux"];
filesToInstall = ["u-boot.bin"];
extraPatches = [
# Remove when updating to 2022.01
# https://patchwork.ozlabs.org/project/uboot/list/?series=273129&archive=both&state=*
(fetchpatch {
url = "https://patchwork.ozlabs.org/series/273129/mbox/";
sha256 = "sha256-/Gu7RNvBNYCGqdFRzQ11qPDDxgGVpwKYYw1CpumIGfU=";
})
];
};

ubootRaspberryPi3_64bit = buildUBoot {
defconfig = "rpi_3_defconfig";
extraMeta.platforms = ["aarch64-linux"];
filesToInstall = ["u-boot.bin"];
extraPatches = [
# Remove when updating to 2022.01
# https://patchwork.ozlabs.org/project/uboot/list/?series=273129&archive=both&state=*
(fetchpatch {
url = "https://patchwork.ozlabs.org/series/273129/mbox/";
sha256 = "sha256-/Gu7RNvBNYCGqdFRzQ11qPDDxgGVpwKYYw1CpumIGfU=";
})
];
};

ubootRaspberryPi4_32bit = buildUBoot {
Expand Down
17 changes: 8 additions & 9 deletions pkgs/os-specific/linux/firmware/raspberrypi-wireless/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,19 @@ stdenv.mkDerivation {
mkdir -p "$out/lib/firmware/brcm"

# Wifi firmware
shopt -s extglob
for filename in firmware-nonfree/brcm/brcmfmac434??{,s}-sdio.*; do
cp "$filename" "$out/lib/firmware/brcm"
done
cp -rv "$NIX_BUILD_TOP/firmware-nonfree/debian/config/brcm80211/." "$out/lib/firmware/"

# Bluetooth firmware
cp bluez-firmware/broadcom/*.hcd "$out/lib/firmware/brcm"
cp -rv "$NIX_BUILD_TOP/bluez-firmware/broadcom/." "$out/lib/firmware/brcm"

# CM4 symlink must be added since it's missing from upstream
pushd $out/lib/firmware/brcm &>/dev/null
ln -s "./brcmfmac43455-sdio.txt" "$out/lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,4-compute-module.txt"
popd &>/dev/null

runHook postInstall
'';

outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = "sha256-Fw8EC1jzszWg9rNH01oaOIHnSYDuF6ov6ulmIAPuNz4=";

Comment on lines -45 to -48
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK all firmware packages should use FOD to reduce unneeded rebuilds. [citation needed].

(Personally I find it is an abuse of FODs, though that might only apply to the big linux-firmware package.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this doesn't really cause any big rebuilds AFAICT

meta = with lib; {
description = "Firmware for builtin Wifi/Bluetooth devices in the Raspberry Pi 3+ and Zero W";
homepage = "https://github.com/RPi-Distro/firmware-nonfree";
Expand Down