If you have questions or remarks, please contact me at the URL of this page, replacing the first dot with an at-sign. This page dates from February 2021.
After numerous attempts, I managed to boot the Orange Pi PC2 with Gentoo. Unfortunately a kernel problem
prevented it from running as a stable system. Whenever I started compiling things, it crashed with the
message:
rcu_sched detected stalls on CPUs/tasks
So I decided to stop hacking here, because it is no longer worth the effort.
At the various places I've been, both personally and for work, I've found that sometimes, the place would benefit from a flexible router with firewall. This router should have gigabit NIC and be able to run my custom Linux installation. Why? Because many off-the-shelf routers are costly and do not always facilitate what I want.
These routers are perfectly fine for most people, but I have been running Linux for over 25 years and am reasonably skilled in manually configuring firewalls, VLANs, networks and (dynamic) routing. So for me, anything off-the-shelf routers can do, I can configure myself. The only thing I need for that, is a small, cheap, Linux-capable system with a decent network interface.
I've first looked at the Raspberry Pi. At that time, it only had a 100MBit network interface. It was also accessed via USB drivers, making it the not-very-ideal solution for my custom router. Other embedded solutions exist that have one or more Gigabit network interfaces, such as the Soekris line, Intel Atom and other Mini-ITX boards. However, all of them are more expensive than an Orange Pi and have more resources than I need.
True, true, there are other SoC boards (Beaglebone, Olimex, probably more) that would also suit my needs. But in the end I bought an Orange Pi PC2, had it in my tech drawers for a long time and now the need has arisen once again to have a cheap but reasonably fast custom Linux router at my disposal. So here's how I did it.
no-multilib
version installed, meaning 64-bit only. It seems
this is the default nowadays./dev/mmcblk0
. If you use a USB MicroSDHC card dongle, it might register as a SCSI disk
under /dev/sd<something>
. Change the instructions below accordingly.
Execute commands as root. Again, this procedure assumes that your SD-card is accessible as
/dev/mmcblk0
. Change where appropriate.
emerge -uva dev-vcs/git
emerge -uva dev-embedded/u-boot-tools
emerge -uva sys-fs/f2fs-tools
Put this on an amd64
Gentoo system. These commands
were taken from the Crossdev section on the
Gentoo Wiki Crossdev build environment
. If you name the overlay crossdev
, the crossdev
commands below will automatically
install packages in this overlay.
mkdir -p /var/db/repos/crossdev/{profiles,metadata}
echo 'crossdev' > /var/db/repos/crossdev/profiles/repo_name
echo 'masters = gentoo' > /var/db/repos/crossdev/metadata/layout.conf
chown -R portage:portage /var/db/repos/crossdev
cat <<EOF >/etc/portage/repos.conf/crossdev.conf
[crossdev]
location = /var/db/repos/crossdev
priority = 10
masters = gentoo
auto-sync = no
EOF
ld: cannot find -lc
crossdev --stable --lenv 'USE=static-libs' --target aarch64
cd /usr/src
git clone --depth 1 https://github.com/ARM-software/arm-trusted-firmware.git atf
export ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu-
make -C atf PLAT=sun50i_a64 DEBUG=1 bl31
bl31.bin
file:export BL31=/usr/src/atf/build/sun50i_a64/debug/bl31.bin
cd /usr/src
opi-v2019.10
branch from the U-Boot repo at
https://megous.com/git/u-boot:git clone --depth 1 --branch opi-v2019.10 https://megous.com/git/u-boot uboot
export ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu-
make -C uboot orangepi_pc2_defconfig
ln -s /usr/bin/python3 /usr/bin/python2
make -C uboot
rm -f /usr/bin/python2
cd /usr/src
git clone --depth 1 https://megous.com/git/linux-firmware linux-firmware
asus.bin
firmware from
here, please download it,
rename it to asus.bin
and put it in the edid
(still to be created) directory
under /usr/src/linux-firmware
amd64
Gentoo system:cd /usr/src
git clone --depth 1 https://github.com/orangepi-xunlong/linux-orangepi.git orangepi
cd orangepi
export ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu-
make orangepi_defconfig
sed -rie
's/CONFIG_EXTRA_FIRMWARE_DIR="[^"]+"/CONFIG_EXTRA_FIRMWARE_DIR="\/usr\/src\/linux-firmware"/g'
/usr/src/orangepi/.config
make -j$(nproc) Image dtbs
W95 FAT32
(fdisk type b
) partition.
Add a swap partition (this guide assumes you did and that the root FS is on partition 3) and lastly a
Linux partition to contain your root filesystem. I recommend using f2fs
for your root
filesystem. My layout after partitioning looks like:Disk /dev/mmcblk0: 14.44 GiB, 15489564672 bytes, 30253056 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x00000000 Device Boot Start End Sectors Size Id Type /dev/mmcblk0p1 * 2048 264191 262144 128M b W95 FAT32 /dev/mmcblk0p2 264192 4458495 4194304 2G 82 Linux swap / Solaris /dev/mmcblk0p3 4458496 30253055 25794560 12.3G 83 Linux
mkfs.vfat /dev/mmcblk0p1
mkswap /dev/mmcblk0p2
mkfs.f2fs -l <hostname-of-orange-pi> /dev/mmcblk0p3
mkdir -p /mnt/tmp
mount /dev/mmcblk0p3 /mnt/tmp
.cd /var/tmp
tar -C /mnt/tmp -JxSvpf /var/tmp/stage3-arm64-systemd-*.tar.xz
*
for the root password in /mnt/tmp/etc/shadow
, otherwise you can't
login.
boot
subdir: mount /dev/mmcblk0p3 /mnt/tmp/boot
cp /usr/src/uboot/.config /mnt/tmp/boot/uboot.config
cat /usr/src/uboot/{spl/sunxi-spl.bin,u-boot.itb} > /mnt/tmp/boot/uboot.bin
dd if=/mnt/tmp/boot/uboot.bin of=/dev/mmcblk0 bs=1024 seek=8
cp /usr/src/orangepi/.config /mnt/tmp/boot/linux.config
cp /usr/src/orangepi/arch/arm64/boot/Image /mnt/tmp/boot
cp /usr/src/orangepi/arch/arm64/boot/dts/allwinner/sun50i-h5-orangepi-pc2.dtb
/mnt/tmp/boot/board.dtb
cat > /mnt/tmp/boot/board.its << EOF
/dts-v1/; / { description = "Orange Pi PC 2"; #address-cells = <1>; images { kernel-1 { description = "Xunlong Linux Kernel 5.4"; type = "kernel"; os = "linux"; arch = "arm64"; data = /incbin/("Image"); compression = "none"; load = <0x40080000>; entry = <0x40080000>; }; fdt-1 { description = "DTB for Orange Pi PC 2"; type = "flat_dt"; os = "linux"; arch = "arm64"; data = /incbin/("board.dtb"); compression = "none"; load = <0x4fa00000>; }; }; configurations { default = "conf-1"; conf-1 { description = "Default Configuration"; kernel = "kernel-1"; fdt = "fdt-1"; }; }; }; EOF
cd /mnt/tmp/boot
cat >/mnt/tmp/boot/Makefile <<EOF
all: boot.scr board.itb boot.scr: boot.cmd mkimage -A arm64 -T script -C none -d boot.cmd boot.scr board.itb: board.its Image board.dtb mkimage -f board.its board.itb
mkimage -f board.its board.itb
/mnt/tmp/boot/boot.cmd
with the following contents:# Kernel parameters setenv bootargs console=tty1 rootfstype=f2fs root=/dev/mmcblk0p3 rw rootwait panic=10 init=/lib/systemd/systemd # Load the FIT binary load mmc 0:1 0x44000000 board.itb # Boot it bootm 0x44000000
boot.scr
code:mkimage -A arm64 -T script -C none -d boot.cmd boot.scr
/var/tmp
: cd /var/tmp
umount /mnt/tmp/boot
umount /mnt/tmp
passwd root
Here are the things I've tried that did not work:
I used these pages to compose this procedure: