The Pinephone is a cheap, generic, arm64 smartphone produced with the goal of supporting user-modifiable operating systems and hardware. It uses an Allwinner "sunxi" A64 processor, a Quectel EG-25G Modem, and can boot from either microSD (removable storage) or eMMC (internal storage). It comes in a couple variants that don't really affect the installation process.
Due to hardware differences, don't expect to run desktop programs normally. Consider using less computer-intensive and keyboard-dependent alternatives to common programs.
Initial chroot and disk setup
NOTE: the disk setup depends a lot on the bootloader choice. if you use p-boot, you need a MBR partition table, and /boot stays on the / filesystem.
Option 1: Using another operating system as installation medium
TODO: make an official Gentoo minimal install ISO for the pinephone? (or arm64 in general, but it would need touchscreen support)
This seems like the easiest option for installing on eMMC, although it takes a long time to compile.
this method works by installing another OS on the pinephone that can be ssh'd into, then using that to partition the flash, unpack stage3, and chroot, etcetera. You can install Gentoo on eMMC by installing the other operating system on microSD, but you can also install Gentoo on the microSD, by first installing another OS on the eMMC (https://wiki.pine64.org/index.php/PinePhone#Flashing_eMMC_using_Jumpdrive).
I've had problems with mounting and formatting eMMC with postmarketOS (seems it has to do with the way that filesystems are mounted by it's initramfs), but I have tried the unofficial fedora Linux port, and it works fine. postmarketOS has a nice ssh-over-USB feature (https://wiki.postmarketos.org/wiki/SSH), which should be considered for any Gentoo minimal install ISO.
Option 2: cross-compilation from another Gentoo system
TODO: write and test something similar to Raspberry_Pi_3_64_bit_Install.
This is the easiest option for installing on microSD.
The eMMC can be exposed via USB by installing jumpdrive on a microSD (https://wiki.pine64.org/index.php/PinePhone#Flashing_eMMC_using_Jumpdrive).
TODO: see if you can mount the filesystem directly with jumpdrive and not just flash ISOs.
Compiling the kernel
The new mainline kernels include the sun50i-a64-pinephone-1.X.dtb file (where 1.X is the hardware version), which you need for your bootloader. As of December 2020, the latest stable gentoo-sources doesn't have it yet so you will have to add "sys-kernel/gentoo-sources ~arm64" to /etc/portage/package.accept_keywords to get a kernel that supports it.
make menuconfig # (or some pinephone_defconfig)
TODO: test kernel configurations, write defconfig and config guide
Installing the bootloader
Option 1: p-boot
because this package is hardware-specific should it be distributed as a binary?
TODO: figure this out and get back to you with an ebuild.
Building from source
To compile p-boot, you need the ninja build system. You also need a second compiler (arm-none-eabi-gcc), which you can get with crossdev as so:
emerge -av git ninja crossdev
crossdev --target arm-none-eabi
git clone https://megous.com/git/p-boot/
then you have to build the firmware, which requires aarch64-linux-musl-gcc and or1k-linux-musl-gcc compilers.
crossdev --target aarch64-linux-musl
crossdev --target or1k-linux-musl
Option 2: U-boot
u-boot is a a bootloader for embedded devices. it's supported by the SoC manufacturer, and works on the pine64 which has the same processor.
TODO: figure this out and get back to you.
Installing the user interface
TODO: make a separate page for (each?) mobile WM?
Option 1: sway with custom configuration
sway is a wayland window manager. maybe wayland might be less computationally expensive? unlike managers such i3, you can use the mouse, so maybe it would work well on a touchscreen. you could increase the border size to make windows easier to drag and use window scaling to make things larger. I just need to replace dmenu with a touchscreen alternative, and make an on-screen keyboard for wayland, and you could set those to the volume buttons respectively, and then set swaylock to the power button. you would just need a way to drag windows between virtual workspaces with the touchscreen.
from my user experience with sxmo, it is slowed down by the phone's processor and the lack of touchscreen controls. it just takes too long to scroll with the volume buttons
TODO: make wayland on-screen keyboard
TODO: make touch-screen alternative to dmenu
You can bindsym to the volume and power buttons with XF86XK_AudioRaiseVolume, XF86XK_AudioLowerVolume, and XF86XK_PowerOff repectively
TODO: include an example ~/.config/sway/config
Option 2: framebuffer terminal with on-screen keyboard
TODO: port this from postmarketOS
Option 3: ubports' WM
TODO: port this from ubports
Option 4: Phosh
TODO: make an overlay with phosh
Option 5: KDE mobile
TODO: make an overlay with kde mobile
the Allwinner A64 has a mali 400 GPU, which is supported by the lima driver. To enable support for lima, add VIDEO_CARDS="lima" to your /etc/portage/make.conf.
The main way programs can take advantage the GPU on this hardware is through OpenGL. Specifically, it supports OpenGL ES 2, so consider using "gles2" and "gles2-only" alongside your other useflags. Don't enable the "opengl" useflag, as this seems to override the "gles2-only" useflag on packages like media-libs/mesa.
VIDEO_CARDS="lima" USE="gles2 gles2-only ..."
you can also adjust the GPU frequency