PinePhone

the pinephone is Article description::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/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 https://wiki.gentoo.org/wiki/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 your /etc/portage/package.accept_keywords to get a kernel that supports it.

TODO: test kernel configurations, write defconfig and config guide

Option 1: p-boot
p-boot is a bootloader designed specificially for the pinephone. it has a menu that lets you select different kernels at boot time, like grub does. It also allows you to boot into FEL mode.

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:

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
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

Wifi/Bluetooth
uses RTL8723BS/RTL8723CS

GPU
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.

you can also adjust the GPU frequency