Difference between revisions of "NixOS on ARM/Firefly AIO-3399C"

From NixOS Wiki
Jump to: navigation, search
(fix archive.org link)
(add installation instructuions for emmc)
Line 23: Line 23:
 
</div>
 
</div>
 
== Status ==
 
== Status ==
 +
The board '''boots NixOS from eMMC''' with the downstream u-boot and Rockchip trusted boot blob. Also flashing Rockchip tertiary bootloader (**idbloader**).
  
It can boot the image provided by firefly on [http://www.t-firefly.com/doc/download/54.html the chinese download page], click on '''Ubuntu (GPT)'''. The image has also been uploaded to [https://archive.org/details/AIO-3399C archive.org].
+
Additionally image provided by firefly on [http://www.t-firefly.com/doc/download/54.html the chinese download page], click on '''Ubuntu (GPT)'''. The image has also been uploaded to [https://archive.org/details/AIO-3399C archive.org].
  
The official documentation, which is a pretty good state, can be found at [http://wiki.t-firefly.com/en/AIO-3399C/ the wiki of firefly]. However as of right now i was unable to:
+
The official documentation, which is a pretty good state, can be found at [http://wiki.t-firefly.com/en/AIO-3399C/ the wiki of firefly].
  
* build an nixos image which can be booted as root image from the emmc (root image must be build as "android" boot)
 
* build an sd-image with a kernel which detects the card at stage one with NixOS (cannot find rootfs)
 
* build the the bootloader with NixOS (blobs and trustedboot comes from rockchip)
 
  
== Board-specific installation notes ==
+
== Serial console ==
 
 
== Serial console==
 
 
On the board there are 3 pins which have a 2.54mm pitch, this is the debug console with the text DEBUG on it. Starting from the middle to the side of the board:
 
On the board there are 3 pins which have a 2.54mm pitch, this is the debug console with the text DEBUG on it. Starting from the middle to the side of the board:
  
Line 51: Line 47:
 
<syntaxHighlight lang=nix>
 
<syntaxHighlight lang=nix>
 
{
 
{
   boot.kernelParams = ["console=ttyS2,1500000n8" "earlycon=uart8250,mmio32,0xff1a0000" "earlyprintk"];
+
   boot.kernelParams = lib.mkForce ["console=ttyS2,1500000n8" "earlycon=uart8250,mmio32,0xff1a0000" "earlyprintk"];
 
}
 
}
 
</syntaxHighlight>
 
</syntaxHighlight>
== Compatibility notes ==
+
Make sure you disable other consoles (tty0) as they seem to interfere with the output.
See the [http://opensource.rock-chips.com/wiki_Status_Matrix Rockchip compatibility matrix]. Uboot requires the Rockchip Miniloader and an arm trusted boot image.
+
 
 +
== Board-specific installation notes ==
 +
 
 +
=== Installation onto eMMC ==
 +
{{note|it may be necessary to first flash the ubuntu gpt image before overriding the partitions with NixOS, use <code>upgrade_tool UF ./AIO-3399C-UBUNTU16.04-LVDS-GPT.img</code>}}
 +
==== boot parts ====
 +
For booting the Image you will need the following parts:
 +
 
 +
# idbloader (rockchip proprietary)
 +
# u-boot customized by firefly
 +
# ARM Trusted image customized for working with uboot
 +
 
 +
The whole setup can be built by hand with the following scripts originally from user '''samueldr'''.
  
=== Downstream kernel ===
+
<syntaxHighlight lang=bash>
 +
git clone https://github.com/makefu/ROC-RK3399-PC-overlay.git builder && cd builder
 +
nix-build -A pkgsCross.aarch64-multiplatform.AIO-3399C.firmware
 +
ls result/
 +
cp result/{idbloader.img,uboot.img,trust.img} .
 +
</syntaxHighlight>
  
The downstream kernel sources can be found on github at [https://github.com/FireflyTeam/kernel]. The stable kernel branch they are maintaining is <code>4.4</code>, however mainline 4.19 should already work according to the [http://opensource.rock-chips.com/wiki_Status_Matrix Rockchip compatibility matrix].
+
==== boot and rootfs ====
 +
The latest linux kernel (4.19 and up) is working with this board. Instead of building the image yourself you can fetch the latest sd-image from hydra and dd the created images onto the separate partitions.
 +
You can find all the successful builds in [https://hydra.nixos.org/job/nixos/release-18.09-aarch64/nixos.sd_image.aarch64-linux hydra @ nixos:release-18.09-aarch64:nixos.sd_image.aarch64-linux]
  
=== u-boot ===
+
<syntaxHighlight lang=bash>
Firefly maintains an own u-boot fork at [https://github.com/FireflyTeam/u-boot]
+
# get the latest link directly from hydra
 +
wget https://hydra.nixos.org/build/89033499/download/1/nixos-sd-image-18.09.2227.ea0820818a7-aarch64-linux.img -O sd.img
 +
udisksctl loop-setup -f sd.img -r
 +
dd if=/dev/loop0p1 boot.img
 +
dd if=/dev/loop0p2 root.img
 +
</syntaxHighlight>
  
=== Flashing via Rockchip Loader Mode ===
+
==== Bringing the device into Rockchip loader mode ====
The board can easily be flashed by booting the device into the Rockchip ''loader'' mode.
+
The board can easily be flashed by booting the device into the Rockchip ''loader'' mode. The device exposes the emmc with the rockusb protocol to a connected host pc.
  
 
To bring the device in the loader mode:
 
To bring the device in the loader mode:
Line 74: Line 94:
 
# Short press the 'reset' button and release the 'Recovery' button afterwards
 
# Short press the 'reset' button and release the 'Recovery' button afterwards
  
==== Firefly upgrade_tool ====
+
==== flashing all boot parts ====
 +
<syntaxHighlight lang=bash>
 +
# You should have the following files available:
 +
$ ls *.img
 +
boot.img root.img trust.img uboot.img idbloader.img
 +
 
 +
# enter loader or maskrom mode
 +
nix-build -A AIO-3399C.upgrade_tool
 +
# optional: re-flash the rockchip loader, haven't tested
 +
# result/bin/upgrade_tool UL idbloader.img
 +
result/bin/upgrade_tool di -u uboot.img -t trust.img -boot ./boot.img -rootfs root.img
 +
result/bin/upgrade_tool rd # reset
 +
</syntaxHighlight>
 +
 
 +
Now cross fingers, the system should boot into NixOS now, the getty BAUD rate
 +
will change to <code>115200</code>.
 +
 
 +
 
 +
== Compatibility notes ==
 +
See the [http://opensource.rock-chips.com/wiki_Status_Matrix Rockchip compatibility matrix]. Uboot requires the Rockchip Miniloader and an arm trusted boot image.
 +
 
 +
=== Downstream kernel ===
 +
 
 +
The downstream kernel sources can be found on github at [https://github.com/FireflyTeam/kernel]. The stable kernel branch they are maintaining is <code>4.4</code>, however mainline 4.19 is already work according to the [http://opensource.rock-chips.com/wiki_Status_Matrix Rockchip compatibility matrix].
 +
 
 +
=== u-boot ===
 +
Firefly maintains an own u-boot fork at [https://github.com/FireflyTeam/u-boot].
 +
 
 +
=== Firefly upgrade_tool ===
 
Firefly provides an <code>upgrade_tool</code> which is a modified [http://opensource.rock-chips.com/wiki_Upgradetool rock-chip upgrade tool]. Using the upstream tool however may result in weird errors like being unable to flash the image or being unable to erase the flash. To be sure use the [https://archive.org/details/AIO-33399C archive.org mirror].
 
Firefly provides an <code>upgrade_tool</code> which is a modified [http://opensource.rock-chips.com/wiki_Upgradetool rock-chip upgrade tool]. Using the upstream tool however may result in weird errors like being unable to flash the image or being unable to erase the flash. To be sure use the [https://archive.org/details/AIO-33399C archive.org mirror].
  
 
However, because the software is essentially a blob, you will need to either patchelf the thing or use '''steam-run''':
 
However, because the software is essentially a blob, you will need to either patchelf the thing or use '''steam-run''':
 
<syntaxHighlight lang=bash>nix-shell -p steam-run --run "steam-run ./upgrade_tool"</syntaxHighlight>
 
<syntaxHighlight lang=bash>nix-shell -p steam-run --run "steam-run ./upgrade_tool"</syntaxHighlight>
 +
 +
I tried flashing with the open-source rkflashtool (in the same repo as the
 +
u-boot stuff), however i was unable to actually connect to the device neither in
 +
"loader" nor in "maskrom" mode. I resorted to using the closed source blob
 +
<code>upgrade_tool</code> which works directly.
  
 
=== Rockchip MaskROM Mode ===
 
=== Rockchip MaskROM Mode ===

Revision as of 22:03, 18 February 2019

Firefly AIO-3399C
A Firefly AIO-3399C attached to LVDS
Manufacturer Firefly
Architecture AArch64
Bootloader u-boot with ARM trusted boot and Rockchip Miniloader
Boot order official: eMMC
Maintainer makefu

Status

The board boots NixOS from eMMC with the downstream u-boot and Rockchip trusted boot blob. Also flashing Rockchip tertiary bootloader (**idbloader**).

Additionally image provided by firefly on the chinese download page, click on Ubuntu (GPT). The image has also been uploaded to archive.org.

The official documentation, which is a pretty good state, can be found at the wiki of firefly.


Serial console

On the board there are 3 pins which have a 2.54mm pitch, this is the debug console with the text DEBUG on it. Starting from the middle to the side of the board:

  • GND (Black Wire)
  • RX (White Wire)
  • TX (Green Wire)
  • VCC, only the silver trace point and not a pin

Baud rate is 1500000 Connect to it via:

nix-shell -p picocom --run "picocom -b 1500000 /dev/ttyUSB0"

When you build your own image, you need the following extra kernel command-line parameters to get serial output:

{
  boot.kernelParams = lib.mkForce ["console=ttyS2,1500000n8" "earlycon=uart8250,mmio32,0xff1a0000" "earlyprintk"];
}

Make sure you disable other consoles (tty0) as they seem to interfere with the output.

Board-specific installation notes

= Installation onto eMMC

Note: it may be necessary to first flash the ubuntu gpt image before overriding the partitions with NixOS, use upgrade_tool UF ./AIO-3399C-UBUNTU16.04-LVDS-GPT.img

boot parts

For booting the Image you will need the following parts:

  1. idbloader (rockchip proprietary)
  2. u-boot customized by firefly
  3. ARM Trusted image customized for working with uboot

The whole setup can be built by hand with the following scripts originally from user samueldr.

git clone https://github.com/makefu/ROC-RK3399-PC-overlay.git builder && cd builder
nix-build -A pkgsCross.aarch64-multiplatform.AIO-3399C.firmware
ls result/
cp result/{idbloader.img,uboot.img,trust.img} .

boot and rootfs

The latest linux kernel (4.19 and up) is working with this board. Instead of building the image yourself you can fetch the latest sd-image from hydra and dd the created images onto the separate partitions. You can find all the successful builds in hydra @ nixos:release-18.09-aarch64:nixos.sd_image.aarch64-linux

# get the latest link directly from hydra
wget https://hydra.nixos.org/build/89033499/download/1/nixos-sd-image-18.09.2227.ea0820818a7-aarch64-linux.img -O sd.img
udisksctl loop-setup -f sd.img -r
dd if=/dev/loop0p1 boot.img
dd if=/dev/loop0p2 root.img

Bringing the device into Rockchip loader mode

The board can easily be flashed by booting the device into the Rockchip loader mode. The device exposes the emmc with the rockusb protocol to a connected host pc.

To bring the device in the loader mode:

  1. Disconnect from power
  2. Connect USB-C from the board to your computer
  3. Hold 'Recovery' button pressed
  4. Connect power, wait for 2 (or more) seconds
  5. Short press the 'reset' button and release the 'Recovery' button afterwards

flashing all boot parts

# You should have the following files available:
$ ls *.img
boot.img root.img trust.img uboot.img idbloader.img

# enter loader or maskrom mode
nix-build -A AIO-3399C.upgrade_tool
# optional: re-flash the rockchip loader, haven't tested
# result/bin/upgrade_tool UL idbloader.img
result/bin/upgrade_tool di -u uboot.img -t trust.img -boot ./boot.img -rootfs root.img
result/bin/upgrade_tool rd # reset

Now cross fingers, the system should boot into NixOS now, the getty BAUD rate will change to 115200.


Compatibility notes

See the Rockchip compatibility matrix. Uboot requires the Rockchip Miniloader and an arm trusted boot image.

Downstream kernel

The downstream kernel sources can be found on github at [1]. The stable kernel branch they are maintaining is 4.4, however mainline 4.19 is already work according to the Rockchip compatibility matrix.

u-boot

Firefly maintains an own u-boot fork at [2].

Firefly upgrade_tool

Firefly provides an upgrade_tool which is a modified rock-chip upgrade tool. Using the upstream tool however may result in weird errors like being unable to flash the image or being unable to erase the flash. To be sure use the archive.org mirror.

However, because the software is essentially a blob, you will need to either patchelf the thing or use steam-run:

nix-shell -p steam-run --run "steam-run ./upgrade_tool"

I tried flashing with the open-source rkflashtool (in the same repo as the u-boot stuff), however i was unable to actually connect to the device neither in "loader" nor in "maskrom" mode. I resorted to using the closed source blob upgrade_tool which works directly.

Rockchip MaskROM Mode

Maskrom mode is a way to get extended privileges when flashing but you need to shorten two trace points on the board. Follow the official documentation. However the loader mode should be enough for most things.

Resources