Difference between revisions of "NixOS on ARM/Libre Computer ROC-RK3328-CC"

From NixOS Wiki
Jump to: navigation, search
m (explain postBuildCommands)
m (rollback unauthorized mass edits)
Tag: Rollback
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{ARM/breadcrumb}}
+
This page has been moved to the official NixOS Wiki:
<div class="infobox">
 
{|class="table"
 
!colspan="2" class="title"|Libre Computer ROC-RK3328-CC
 
|-
 
|colspan="2"|[[File:ROC-RK3328-CC.png|frameless|256px|A Libre Computer ROC-RK3328-CC.]]
 
|-
 
!Manufacturer
 
|Firefly for Libre Computer
 
|-
 
!Architecture
 
|AArch64
 
|-
 
!Bootloader
 
| Upstream U-Boot
 
|-
 
!Boot options
 
|microSD, eMMC, SPI NOR Flash
 
|}
 
</div>
 
  
The ROC-RK3328-CC (Renegade) is a single board computer built around the Rockchip RK3328 SoC. It is very similar to the [[NixOS_on_ARM/PINE64_ROCK64|ROCK64]].
+
    ⇒ '''[https://wiki.nixos.org/wiki/NixOS_on_ARM/Libre_Computer_ROC-RK3328-CC NixOS on ARM/Libre Computer ROC-RK3328-CC]'''
  
There are three models of the board, with 1, 2 or 4 GB of RAM. It can boot from an microSD card or an eMMC. It also has a 128 Mbit SPI flash that can be used to store the bootloader.
+
''— samueldr, Lead of NixOS on ARM.''
 
 
== Status ==
 
 
 
This board has upstream U-Boot and kernel support, although the mainline kernel may still be missing some features. NixOS can be installed using manual partitioning and <code>nixos-install</code> or by modifying the aarch64 installation image as described in the next section.
 
 
 
U-Boot for this board is packaged in nixpkgs, and Hydra builds can be found here:
 
 
 
https://hydra.nixos.org/job/nixpkgs/trunk/ubootRock64.aarch64-linux
 
 
 
This bootloader is not entirely open, incorporating a binary blob for the tertiary program loader (TPL).
 
If your have nix installed you can download the latest version with (This command also works on different
 
architectures since it can be downloaded from the binary cache):
 
 
 
<syntaxHighlight lang=console>
 
$ nix-build '<nixpkgs>' -A ubootRock64 --argstr system aarch64-linux
 
$ ls -la result
 
-r--r--r-- 2 root root    107683 Jan  1  1970 idbloader.img
 
dr-xr-xr-x 1 root root        40 Jan  1  1970 nix-support
 
-r--r--r-- 2 root root    789504 Jan  1  1970 u-boot.itb
 
</syntaxHighlight>
 
 
 
== Board-specific installation notes ==
 
 
 
U-Boot needs to be copied to specific sectors on the microSD card, eMMC or image with <code>dd</code>.
 
 
 
You can use [https://github.com/Mic92/nixos-aarch64-images nixos-aarch64-images] to get an rock64 compatible disk image
 
or running the commands manually.
 
 
 
Download/build U-Boot for the board, and write <code>idbloader.img</code> and <code>u-boot.itb</code>.
 
Replace in the command below <code>/dev/mmcblkX</code> with the correct device to the sdcard i.e.  <code>/dev/mmcblk0</code>. You can use the <code>lsblk</code> command to get a list of all devices:
 
 
 
<syntaxhighlight lang="bash">
 
dd if=idbloader.img of=/dev/mmcblkX conv=fsync,notrunc bs=512 seek=64
 
dd if=u-boot.itb of=/dev/mmcblkX conv=fsync,notrunc bs=512 seek=16384
 
</syntaxhighlight>
 
 
 
This will make the first partition of the installation device unmountable and it can be deleted, but the space needs to be kept to not overwrite the bootloader with another filesystem.
 
 
 
 
 
{{note|Prior to NixOS 20.03, a downstream version of U-Boot 2017.09 was packaged, which placed U-Boot in a single <code>idbloader.img</code> file. If that version is used, simply disregard the second command above.}}
 
 
 
== Build your own image natively ==
 
 
 
You can customize image by using the following snippet.
 
 
 
<syntaxHighlight lang=nix>
 
# save as sd-image.nix somewhere
 
{ ... }: {
 
  # only needed for crosscompilation
 
  nixpkgs.crossSystem = lib.systems.elaborate lib.systems.examples.aarch64-multiplatform;
 
 
 
  imports = [
 
    <nixpkgs/nixos/modules/installer/sd-card/sd-image-aarch64.nix>
 
  ];
 
 
 
  nixpkgs.config.allowUnfree = true; # needed for ubootRock64
 
  # at the time of writing the u-boot version from FireFly hasn't been successfully ported yet
 
  # so we use the one from Rock64
 
  sdImage.postBuildCommands = with pkgs; ''
 
    dd if=${ubootRock64}/idbloader.img of=$img conv=fsync,notrunc bs=512 seek=64
 
    dd if=${ubootRock64}/u-boot.itb of=$img conv=fsync,notrunc bs=512 seek=16384
 
  '';
 
 
 
  # put your own configuration here, for example ssh keys:
 
  users.extraUsers.root.openssh.authorizedKeys.keys = [
 
    "ssh-ed25519 AAAAC3NzaC1lZDI1.... username@tld"
 
  ];
 
}
 
</syntaxHighlight>
 
 
 
Then build with:
 
 
 
<syntaxHighlight lang=shell>
 
$ nix-build '<nixpkgs/nixos>' \
 
    -A config.system.build.sdImage \
 
    -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/9bc841f.tar.gz \ # pinned to nixos-unstable on 2022-03-23
 
    -I nixos-config=./sd-image.nix</syntaxHighlight>
 
 
 
== USB ==
 
To enable USB power ''GPIO1_D2'' must be pulled high. D2 translates to 26 (D=4, 4*8+2=26). This is most easily done with the following systemd service.
 
 
 
<syntaxHighlight lang=nix>
 
  systemd.services."usb-enable" = {
 
    enable = true;
 
    script = "${pkgs.libgpiod}/bin/gpioset 1 26=1";
 
    wantedBy = [ "default.target" ];
 
  };
 
</syntaxHighlight>
 
 
 
== Serial console==
 
 
 
The ROC-RK3328-CC uses a GPIO pinout compatible with the Raspberry Pi 2 and newer. This means that the following pins can be used to connect a serial adapter:
 
 
 
{| class="table"
 
|-
 
!colspan="2" style="background: #fafafa"| Pi-2 Bus
 
|-
 
! Pin
 
! Function
 
|-
 
| 6
 
| GND
 
|-
 
| 8
 
| UART0_TX
 
|-
 
| 10
 
| UART0_RX
 
|}
 
 
 
The serial console runs at 1500000 baud in the bootloader. When using the standard NixOS aarch64 sd image, set <code>console=tty1 console=ttyS2,1500000n8</code> as kernel option in <code>extlinux/extlinux.conf</code> on the boot partition of the sdimage to get a serial linux console (tty1 is for standard HDMI output and ttyS2 is for the serial, baud rate setting is optional, simple console=ttyS2 seems to be working fine too). For debugging, <code>console=uart8250,mmio32,0xff130000</code> should give you an early UART console, before the full serial console is up.
 
 
 
From the host computer run (update /dev/ttyUSB0 with your USB-to-serial device)
 
 
 
<code>
 
nix-shell -p python3Packages.pyserial --run 'python3 -m serial.tools.miniterm --exit-char 24 --raw /dev/ttyUSB0 1500000'
 
</code>
 
 
 
== Compatibility notes ==
 
 
 
{| class="table arm-compatibility"
 
|
 
! style="background: #fafafa" | Mainline kernel
 
|-
 
! Ethernet
 
| Works
 
|-
 
! USB
 
| As of 5.4, USB 3.0 does not work
 
|-
 
! HDMI
 
| Video works, Sound does not
 
| -
 
|}
 
 
 
== Resources ==
 
 
 
* [https://www.libre.computer/products/rk3328/ Official product page]
 
* [https://roc-rk3328-cc.readthedocs.io/en/latest/intro.html Official Getting Started Guide]
 

Latest revision as of 11:05, 6 April 2024

This page has been moved to the official NixOS Wiki:

    ⇒ NixOS on ARM/Libre Computer ROC-RK3328-CC

— samueldr, Lead of NixOS on ARM.