Installing Debian on the Pinebook Pro

@brion on mastodon:

If you want the Linux-circa-2004 experience back, just try Linux on ARM!

  • everything compiles slowly
  • distro-hopping to find better hardware support
  • oops, you need proprietary drivers for that
  • forum posts hold the authoritative documentation and code for your distro

:D

In November last year, I ordered a Pinebook Pro from Pine64. The Pinebook Pro is a 14" (1080p) ARM laptop based on a RK3399 SOC. It has an eMMC built in and it is possible to add an NVMe SSD drive using an adapter. In addition it also has a micro SD card reader and can boot from that. The notebook is very lightweight and the case seems solid. The bottom cover is attached using normal Philips head screws and there is a lot of detailed documentation in the wiki about the parts of the board and how to access the internals.

I’m not really a fan of the keyboard, because in my opinion it feels a bit cheap - pressing the keys does not feel as smooth as I’m used to from other keyboards, like from the Thinkpad x230 or the 2012 MacBook Air. In addition to that I made the mistake of choosing an ANSI keyboard, which makes it harder for me to reach the Enter key. The big advantage of the device is definitely the battery. In the first week of playing around with the device (not using it that much, but doing a lot of tests with booting different images) I didn’t even unpack the power supply. Another nice feature are the privacy switches - when you press F1, F2 or F3 for 10 seconds you cut the power for the BT/WiFI module (F1), the webcam (F2) or the microphone (F3). At least that’s the theory, it does not work with my Pinebook, but there is a firmware update for the keyboard that I did not yet install, which might fix that.

I also really like how the Pinebook Pro creators keep you up to date with news regarding their products and related software. They publish monthly updates about updates in their blog, they also try to take part in the discussions in the pine64 forum and they have a presence on the fediverse (there are more communication channels, but those are the ones I follow/used).

There are a couple of different pre built operating system images one can dd to SD cards or the eMMC and there are also some scripts to install (instead of dding) systems. The laptop comes preinstalled with what is usually (in the forums and the wiki) called Debian Desktop. It is a Debian based image with a Mate Desktop and a lot of modifications. The images for this system are distributed via a github repository. I did not find any source code for the images nor documentation about the changes from upstream Debian, so I have no idea how they are built (the archives behind the Source code links on the release page of the images only contain the README.md file). I only started the preinstalled system once or twice, but it seemed to work very well (suspend worked) and it ships a lot of useful software for end users. But I did not take a deeper look at this image. There are also two Ubuntu based images listed in the Pine64 wiki, one of which comes with LXDE as desktop system, the other one with the Mate Desktop. They are also distributed via github release pages, but in these cases the repository also contains the code of the build scripts. Manjaro, an Arch Linux based distribution, also provides images for the Pinebook Pro. Besides those there are Armbian images, Android images, Chromium images and some more.

I did not really want to use any of the provided images, but rather install my own Debian system. There is an installer script which installs Debian on a SD card or the eMMC using debootstrap. This script does a lot of useful stuff, and a good part of my approach of installing Debian is based on it.

I installed Debian on an SD card using my older HP laptop. There are two main parts one needs that are not part of Debian yet, a heavily patched kernel on the one hand and the u-boot bootloader, also with some patches. There is a great tutorial on how to build an (almost) upstream u-boot for the Pinebook. This is based on this git repository which contains the u-boot upstream sources modified to work on the Pinebook and with some changes to the boot order. The main path is this one which was posted to the u-boot mailinglist in November, but I’m not sure whats the status of it. Lets hope it will be merged upstream for the next release of u-boot.

For the kernel there is a repository in the manjaor gitlab and the maintainer of this kernel repository announced that they plan on mainlining the patches. The only thing not working yet is suspend to RAM. I’m currently using the v5.5-rc7-panfrost-fixes branch of the kernel.

To crossbuild the kernel, I had to first prepare my build machine (which is AMD64):

apt install crossbuild-essential-arm64 flex bison fakeroot build-essential bc libssl-dev

then I cloned the repository and copied the configuration the Manjaro kernel is using from their kernel package repository. I also had to disable compression of kernel modules.

git clone https://gitlab.manjaro.org/tsys/linux-pinebook-pro
cd linux-pinebook-pro
wget https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinebookpro/raw/master/config -O .config
scripts/config --set-str LOCALVERSION -custom
scripts/config --disable MODULE_COMPRESS
make -j`nproc` ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- KBUILD_IMAGE=arch/arm64/boot/Image deb-pkg

The developer who maintains the kernel also published a repository with firmware for the Broadcom Wifi module and the DisplayPort. Another manjaro repository contains the firmware for the bluetooth chip.

Next step was to bootstrap Debian. First I installed the packages to bootstrap a system with another architecture and then I prepared the SD card:

apt install qemu-user-static binfmt-support
sfdisk /dev/sdc < gpt.sfdisk
mkfs.ext4 /dev/sdc1
cryptsetup luksFormat /dev/sdc2
cryptsetup luksOpen /dev/sdc2 sdc2_crypt
mkfs.ext4 /dev/mapper/sdc2_crypt

With gpt.sfdisk containing the following partition layout:

label: gpt
unit: sectors

/dev/sdc1 : start=      442368, size=     1024000, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, name="Boot"
/dev/sdc2 : start=     1466368,                    type=0FC63DAF-8483-4772-8E79-3D69D8477DE4

Then I created a temporary folder, mounted the partitions and used qemu-debootstrap to install the base system:

CHROOT=`mktemp -d`
mount /dev/sdc2_crypt $CHROOT
mkdir $CHROOT/boot
mount /dev/sdc1 $CHROOT/boot

sudo qemu-debootstrap --arch=arm64 --include=u-boot-menu,initramfs-tools,sudo,network-manager,cryptsetup,cryptsetup-initramfs bullseye $CHROOT

Then I copied the kernel package I built on the SD card and installed it in the chroot. Part of the linux image is also a *.dtb file for the RK3399, which I had to copy to /boot (because u-boot needs this file and the /-filesystem is encrypted).

mount -o bind /dev $CHROOT/dev
mount -o bind /sys $CHROOT/sys
mount -t proc /proc $CHROOT/proc
chroot $CHROOT
dpkg -i linux-image-5.5.0-rc7-custom+_5.5.0-rc7-custom+-1_arm64.deb
cp /usr/lib/linux-image-5.5.0-rc7-custom+/rockchip/rk3399-pinebook-pro.dtb /boot/

echo UUID=$(blkid -s UUID -o value /dev/mapper/sdc2_crypt) / ext4 defaults 0 1 >> /etc/fstab
echo sdc2_crypt PARTUUID=$(blkid -s PARTUUID -o value /dev/sdc2 ) none luks,discard,initramfs >> /etc/crypttab
echo UUID=$(blkid -s UUID -o value /dev/sdc1) /boot ext4 defaults 0 1 >> /etc/fstab
Finally I pointed the u-boot-update script to the *.dtb file and added my user account:
# in /etc/defaults/u-boot
U_BOOT_FDT="rk3399-pinebook-pro.dtb"
U_BOOT_PARAMETERS="console=tty1"

adduser bisco
adduser bisco sudo

In the running system I then also enabled s2idle, because suspend to RAM does not work yet.

I haven’t had time to do any more tests on this device, but I hope I’ll get to that in February. If I manage to set up the system to a usable state, I’ll bring it to FOSDEM, which will be its first outside test…

On the software side most stuff until now works fine. The main downside is the missing TorBrowser package, but this is tracked upstream. Alacritty does not work and won’t in the near future, it seems. When I tried to use tilix, that led to #949952, so I’m using rxvt-unicode for now…

There is now also a wiki page for the Debian installer script which lists some issues and tips how to fix them.


debian arm pinebook