NixOS on ARM/Raspberry Pi 3: Difference between revisions
imported>Samueldr Split off the Raspberry Pi 3 information in its own spin-off page |
m Add missing closing paren. |
||
(12 intermediate revisions by 10 users not shown) | |||
Line 43: | Line 43: | ||
First follow the [[NixOS_on_ARM#Installation|generic installation steps]] to get the installer image and install using the [[NixOS_on_ARM#NixOS_installation_.26_configuration|installation and configuration steps]]. | First follow the [[NixOS_on_ARM#Installation|generic installation steps]] to get the installer image and install using the [[NixOS_on_ARM#NixOS_installation_.26_configuration|installation and configuration steps]]. | ||
{{warning|1=To avoid running out of memory and ''failing'' to build, it is advised to create a swap file (see e.g. [https://wiki.archlinux.org/title/swap#Swap_file_creation]) ''before'' executing <code>nixos-rebuild</code> for the first time.}} | |||
=== Raspberry Pi 3B and 3B+ === | === Raspberry Pi 3B and 3B+ === | ||
Line 48: | Line 50: | ||
Both the AArch64 and ARMv7 images boot out-of-the-box. Using the 64-bit AArch64 image is highly recommended, as the availability of binaries is much better and allows the use of the 64-bit instruction set. | Both the AArch64 and ARMv7 images boot out-of-the-box. Using the 64-bit AArch64 image is highly recommended, as the availability of binaries is much better and allows the use of the 64-bit instruction set. | ||
For the UART console, edit <code>/extlinux/extlinux.conf</code> on the | For the UART console, edit <code>/extlinux/extlinux.conf</code> on the main partition of the SD card to set <code>console=ttyS1,115200n8</code> in the kernel boot parameters, making sure to replace the existing <code>console=ttyS0,115200n8</code> parameter. Use the following GPIO Pins with an USB-TTL connector: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
GND - 3rd in top row, black cable | GND - 3rd in top row, black cable | ||
Line 54: | Line 56: | ||
GPIO 15 RXD - 5th in top row, green cable | GPIO 15 RXD - 5th in top row, green cable | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Use <code>nix-shell -p screen --run "screen /dev/ttyUSB0 115200"</code> to connect to the console. | Use <code>nix-shell -p screen --run "screen /dev/ttyUSB0 115200"</code> (or <code>nix run nixpkgs#screen -- /dev/ttyUSB0 115200</code> if you're using nix flakes) to connect to the console. | ||
{{note|The mainline kernel (tested with nixos kernel 4.18.7) [https://github.com/raspberrypi/linux/wiki/Upstreaming#downstream-drivers does not include support for cpu frequency scaling] on the Raspberry Pi. To get higher clock speed, set [https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md <code><nowiki>force_turbo=1</nowiki></code>] in <code>/boot/config.txt</code> }} | {{note|The mainline kernel (tested with nixos kernel 4.18.7) [https://github.com/raspberrypi/linux/wiki/Upstreaming#downstream-drivers does not include support for cpu frequency scaling] on the Raspberry Pi. To get higher clock speed, set [https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md <code><nowiki>force_turbo=1</nowiki></code>] in <code>/boot/config.txt</code> with {{nixos:option|boot.loader.raspberryPi.firmwareConfig}}}} | ||
<syntaxhighlight lang=nix> | <syntaxhighlight lang=nix> | ||
Line 66: | Line 68: | ||
== Tools == | == Tools == | ||
The raspberry tools are available in the <code> | The raspberry tools are available in the <code>libraspberrypi</code> package and include commands like <code>vcgencmd</code> to measure temperature and CPU frequency. | ||
== Audio == | == Audio == | ||
Line 94: | Line 96: | ||
If the Raspberry Pi downstream kernel is used the serial interface is named <code>serial0</code> instead. | If the Raspberry Pi downstream kernel is used the serial interface is named <code>serial0</code> instead. | ||
=== Early boot === | |||
Raspberry Pi 3's UART rate is tied to the GPU core frequency, set by default to 400MHz on Raspberry Pi 3 and later. This results in garbled serial output in bootloaders. Setting <code>core_freq=250</code> in <code>config.txt</code> solves this issue (as per [https://forums.raspberrypi.com/viewtopic.php?p=942203#p942203 thread on the Raspberry Pi forum]). | |||
It can be done declaratively as such: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
{ config, pkgs, lib, ... }: | |||
{ | |||
boot.loader.raspberryPi = { | |||
enable = true; | |||
version = 3; | |||
firmwareConfig = '' | |||
core_freq=250 | |||
''; | |||
}; | |||
} | |||
</nowiki>}} | |||
Note that this [https://github.com/RealVNC/raspi-documentation/blob/fc6b4711f91791db7acd19ae743fcfddc9c89546/configuration/config-txt/overclocking.md#overclocking-options may have a negative impact on performance]: | |||
<blockquote>Frequency of the GPU processor core in MHz. It has an impact on CPU performance because it drives the L2 cache and memory bus.</blockquote> | |||
== Bluetooth == | == Bluetooth == | ||
Line 149: | Line 174: | ||
Using the 3.3v serial port via the pin headers (exact location depends on hardware version) will get u-boot output and, when configured, a Linux kernel console. | Using the 3.3v serial port via the pin headers (exact location depends on hardware version) will get u-boot output and, when configured, a Linux kernel console. | ||
=== Updating U-Boot === | |||
[https://github.com/NixOS/nixpkgs/issues/82455#issuecomment-959797355 These steps can be followed to update the platform firmware.] | |||
== Troubleshooting == | == Troubleshooting == | ||
Line 168: | Line 197: | ||
===WiFi / WLAN=== | ===WiFi / WLAN=== | ||
For a possible solution to 802.11 wireless connectivity issues, see: https://github.com/NixOS/nixpkgs/issues/82462#issuecomment-604634627 | For a possible solution to 802.11 wireless connectivity issues, see: https://github.com/NixOS/nixpkgs/issues/82462#issuecomment-604634627 | ||
In case <code>wlan0</code> is missing, try overlaying an older <code>firmwareLinuxNonfree</code> confirmed to be working: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
{ config, pkgs, lib, ... }: | |||
{ | |||
nixpkgs.overlays = [ | |||
(self: super: { | |||
firmwareLinuxNonfree = super.firmwareLinuxNonfree.overrideAttrs (old: { | |||
version = "2020-12-18"; | |||
src = pkgs.fetchgit { | |||
url = | |||
"https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git"; | |||
rev = "b79d2396bc630bfd9b4058459d3e82d7c3428599"; | |||
sha256 = "1rb5b3fzxk5bi6kfqp76q1qszivi0v1kdz1cwj2llp5sd9ns03b5"; | |||
}; | |||
outputHash = "1p7vn2hfwca6w69jhw5zq70w44ji8mdnibm1z959aalax6ndy146"; | |||
}); | |||
}) | |||
]; | |||
} | |||
</nowiki>}} | |||
===HDMI=== | ===HDMI=== | ||
Line 184: | Line 235: | ||
=== Raspberry Pi 3B+ HDMI output issues === | === Raspberry Pi 3B+ HDMI output issues === | ||
{{outdated|Since late 2019 the situation '''must''' have changed. Please test and update this section.}} | |||
As of 2019/08/19, the u-boot build and kernel build can disagree about the name of the dtb file for the Raspberry Pi 3B+. This happens because the upstream filename has changed, and the built u-boot has hardcoded expectations for the filename to load. | As of 2019/08/19, the u-boot build and kernel build can disagree about the name of the dtb file for the Raspberry Pi 3B+. This happens because the upstream filename has changed, and the built u-boot has hardcoded expectations for the filename to load. | ||
Line 191: | Line 244: | ||
See {{issue|66960}}. | See {{issue|66960}}. | ||
=== HDMI output issue with kernel | === HDMI output issue with kernel ~6.1 (NixOS 23.05 or NixOS unstable) === | ||
( | When using HDMI and hardware acceleration (e.g. Kodi), an application may fail to start and/or crash with a dmesg like: | ||
<pre> | |||
[232195.380745] [drm:vc4_bo_create [vc4]] *ERROR* Failed to allocate from CMA: | |||
[232195.380751] [drm] kernel: 432kb BOs (1) | |||
[232195.380755] [drm] dumb: 69064kb BOs (14) | |||
[306160.152488] cma: cma_alloc: alloc failed, req-size: 142 pages, ret: -16 | |||
[306160.152498] [vc_sm_cma_ioctl_alloc]: dma_alloc_coherent alloc of 581632 bytes failed | |||
[306160.152501] [vc_sm_cma_ioctl_alloc]: something failed - cleanup. ret -12 | |||
[317686.623989] [drm:vc4_bo_create [vc4]] *ERROR* Failed to allocate from CMA: | |||
[317686.623998] [drm] dumb: 74752kb BOs (16) | |||
</pre> | |||
A workaround is to increase the pre-allocated CMA space (which, as of writing, defaults to 65M): | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
{ config, pkgs, lib, ... }: | |||
{ | { | ||
boot. | boot.kernelParams = ["cma=320M"]; | ||
} | } | ||
</ | </nowiki>}} | ||
< | For more information see a post in raspberry pi forum<ref>https://forums.raspberrypi.com/viewtopic.php?t=285068</ref> and thios github issue<ref>https://github.com/raspberrypi/linux/issues/3861</ref>. |