Gentoo on a PinePhone en

By stealthgun on Friday 26 February 2021 20:30 - Comments (1)
Category: Algemeen, Views: 6.398

I've been looking at the PinePhone for a long time and this year I decided to get one msyelf.
The one that I ordered is the PinePhone KDE version with the Convergence package. So I have 32gb eccm and 3gb Ram.

The thing is knew allready is that the OS it came wiith i would not see boot. Because my Linux distro of choice is Gentoo. With the low specs of a phone I am also very intressted in what I can get out of a phone with Gentoo Linux.

Where to Begin
So first l've looked at allready availible documentation and I found some.
Gentoo Pinephone wiki entry 1
Gentoo Pinephone wiki entry 2

Both where good starting points but are both missing abit of information, so hence this blog post.

So for the disk I am gonna do the following:
eccm:
128mb of nothing (needs to be a linux partition)
5Gb is swap (to make sure the system thinks we always have enough RAM)
~26GB of / (ext4) (Just the rest of the left space)

SDcard
180 gb of /home (ext4)
72 gb of /var (ext4)

You can follow juist the normal prepare disks from the gentoo installation.

/var is a large directory same goes for /home so thats why I want to have those two on a SDcard wich should save enough space for the rest of the OS installation. On the eccm disk since for my own Linux Desktop PC excluding those two directories the system uses 18gb space.

Due to some software for the pinephone beeing non open-rc compatible I have to use systemd, I do not like this choice but without systemd your system is gonna be less usable as a phone.

So eventough I do not like systemd I do think its the best option for the installation so use the systemd arm64 stage3 for your installation.

I am using postmarketOS from a sdcard to boot and from there just follow the amd64 handbook to create the system and chroot into it.

nano is not installed by default so if you want to use it you can just do apk add nano.

Build the system
Since the phone itself is quite weak you can use distcc to speed it all up if you want I am not going into the distcc settings and options in this blog.

The make.conf I am using is:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /usr/share/portage/config/make.conf.example for a more
# detailed example.
CHOST="aarch64-unknown-linux-gnu"
COMMON_FLAGS="-march=armv8-a+crypto+crc -mtune=cortex-a53 -O2 -pipe -fomit-frame-pointer -ftree-vectorize"
CFLAGFS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
MAKEOPTS="-j5"

# NOTE: This stage was built with the bindist Use flag enabled
PORTDIR="/var/db/repos/gentoo"
DISTDIR="/var/cache/distfiles"
PKGDIR="/var/cache/binpkgs"

# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C

#Use flags
USE="wayland phosh gles2 p-boot eg25-manager pinephone chromium samba truetype alsa elogind bluetooth cups ipv6 omemo pulseaudio dhcpcd systemd networkmanager -opengl egl wifi mobile"

#Needed for the video drivers
VIDEO_CARDS="lima"

#Gentoo Mirror
GENTOO_MIRRORS="https://ftp.snt.utwente.nl/pub/os/linux/gentoo"


Ive added the following file aswell
code:
1
nano -w /mnt/gentoo/etc/portage/package.use/pinephone


code:
1
/etc/portage/package.use/pinephone

content
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sys-apps/systemd cryptsetup homed
media-libs/mesa -llvm
>=x11-libs/libdrm-2.4.102 libkms
net-misc/networkmanager connection-sharing
media-libs/libsdl2 gles2 -tslib
media-libs/libvpx postproc
sys-libs/zlib minizip
media-fonts/dejavu -X
media-video/vlc -X opus
media-tv/v4l-utils -bpf -qt5
media-video/ffmpeg vaapi
sci-geosciences/gpsd -X -qt5 python
>=media-plugins/grilo-plugins-0.3.12 flickr
>=sys-libs/zlib-1.2.11-r3 static-libs
media-libs/libsdl2 kms tslib
>=media-video/ffmpeg-4.3.1 opus
x11-libs/tslib -sdl
net-wireless/bluez user-session
x11-libs/cairo gles2-only
net-libs/webkit-gtk gles2-only
>=dev-lang/python-3.9.2 -bluetooth -sqlite


And unmask some packages at the moment since Gnome 40 is beeing tested on.

code:
1
nano -w /etc/portage/package.unmask


code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
gui-libs/gtk
gnome-base/gnome-shell
gnome-extra/gnome-shell-extensions
x11-wm/mutter
x11-libs/pango
dev-cpp/pangomm
dev-libs/vala-common
dev-lang/vala
gnome-base/nautilus
app-misc/tracker
app-misc/tracker-miners
gnome-base/gnome-settings-daemon
gnome-extra/gnome-calendar
media-sound/gnome-music


As always with gentoo change the USE flags as you see fit, this is what I want for my system.
The reason why -march is not native, is the fact that for distcc you need to specify the flags.

The VIDEO_CARDS needs to be set to "lima" and its important to set the use flags"gles2" since else the video-card might not work optimal because this way you force the emedded opengl settings.

Now to be sure lets set the accept_keywords (I dont want everything on unstable):
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#Gnome
gnome-extra/chrome-gnome-shell ~arm64
mail-client/geary ~arm64
net-im/chatty ~arm64
x11-misc/squeekboard ~arm64
net-dns/dnsmasq ~arm64
media-video/megapixels ~arm64
media-libs/hdr-plus ~arm64
media-sound/lollypop ~arm64
x11-themes/sound-theme-librem5 ~arm64
media-sound/gnome-music ~arm64
gui-libs/libhandy ~arm64
dev-libs/feedbackd ~arm64
gnome-extra/evolution-data-server ~arm64
mail-client/evolution ~arm64
sci-geosciences/gnome-maps ~arm64
gnome-extra/iio-sensor-proxy ~arm64
app-editors/gedit ~arm64
gnome-base/gnome-control-center ~arm64
gnome-extra/gnome-contacts ~arm64
gnome-extra/gnome-calculator ~arm64
gnome-extra/gnome-calendar ~arm64
gnome-extra/gnome-clocks ~arm64
gnome-base/gnome-keyring ~arm64
gnome-base/gnome-desktop ~arm64
gnome-base/gnome-session ~arm64
gnome-base/gsettings-desktop-schemas ~arm64
gnome-base/nautilus ~arm64
media-video/totem ~arm64
app-dicts/gnome-dictionary ~arm64
gnome-extra/gnome-power-manager ~arm64
gnome-extra/sushi ~arm64
net-libs/gnome-online-accounts ~arm64
net-libs/webkit-gtk ~arm64
x11-themes/adwaita-icon-theme ~arm64
x11-themes/gnome-backgrounds ~arm64
www-client/epiphany ~arm64
x11-terms/gnome-terminal ~arm64
app-text/evince ~arm64
x11-libs/vte ~arm64
gnome-base/gnome-shell ~arm64
app-misc/tracker ~arm64
dev-libs/libportal ~arm64
app-misc/tracker-miners ~arm64
dev-libs/gjs ~arm64
gui-libs/gtk ~arm64
x11-libs/gtk+ ~arm64
x11-wm/mutter ~arm64
net-wireless/gnome-bluetooth ~arm64
net-libs/libnma ~arm64
dev-libs/libgweather ~arm64
gnome-base/gnome-settings-daemon ~arm64
gnome-extra/gnome-system-monitor ~arm64
gnome-base/gdm ~arm64
app-misc/jq ~arm64
sci-geosciences/geocode-glib ~arm64
x11-misc/colord ~arm64
dev-libs/glib ~arm64
gnome-extra/zenity ~arm64
dev-util/sysprof ~arm64
dev-util/sysprof-capture ~arm64
dev-util/sysprof-common ~arm64
dev-libs/libdazzle ~arm64
7media-libs/hdr-plus ~arm64
media-gfx/zbar ~arm64
dev-libs/folks ~arm64
media-libs/gsound ~arm64
gnome-extra/gnome-color-manager ~arm64
gnome-base/libgnomekbd ~arm64
gnome-extra/nm-applet ~arm64
dev-libs/libpeas ~arm64
gui-libs/tepl ~arm64
gui-libs/amtk ~arm64
dev-libs/olm ~arm64
dev-libs/gom ~arm64
net-misc/modemmanager ~arm64
net-libs/libqmi ~arm64
media-sound/callaudiod ~arm64
dev-util/wayland-scanner ~arm64
x11-themes/gnome-backgrounds ~arm64
x11-libs/pango ~arm64
gnome-base/gnome-desktop ~arm64
sci-geosciences/gnome-maps ~arm64
gnome-extra/evolution-ews ~arm64
gnome-extra/portfolio ~arm64
gnome-extra/gnome-weather ~arm64
sci-geosciences/gnome-maps ~arm64
media-libs/libchamplain ~arm64
net-libs/libgfbgraph ~arm64

#Phosh
dev-embedded/imx-usb-loader ~arm64
dev-embedded/jlink ~arm64
dev-embedded/mfgtool ~arm64
dev-embedded/mkbootimg ~arm64
gui-wm/phosh ~arm64
gui-wm/phosh-meta ~arm64
x11-wm/phoc ~arm64
gnome-extra/postmarketos-tweaks ~arm64

#Webclients
www-client/chromium ~arm64
www-client/microsoft-edge-dev ~arm64
www-client/firefox ~arm64
www-client/chromium-bin ~arm64

#Phone things
app-mobilephone/flashlight ~arm64
app-mobilephone/mobile-config-firefox ~arm64
app-mobilephone/pinephone-modem-scripts ~arm64
app-mobilephone/pinephone-softsleep ~arm64
app-mobilephone/pinephone ~arm64
app-mobilephone/usb-tethering ~arm64
net-voip/calls ~arm64
x11-plugins/purple-mm-sms ~arm64
net-misc/ofono ~arm64
net-misc/ofonoctl ~arm64
net-misc/eg25-manager ~arm64
net-dialup/atinout ~arm64
dev-libs/libphonenumber ~arm64
sys-firmware/anx7688-firmware ~arm64
sys-firmware/ov5640-firmware ~arm64
sys-firmware/rtl8723bt-firmware ~arm64

#Other
virtual/libgudev ~arm64
sys-power/gtherm ~arm64
sys-kernel/pinephone-sources ~arm64
sys-kernel/gentoo-sources ~arm64
media-libs/alsa-ucm-pinephone ~arm64
media-sound/wys ~arm64
net-vpn/networkmanager-openvpn ~arm64
app-office/LibreOffice ~arm64
app-misc/neofetch ~arm64
media-libs/mesa ~arm64
net-misc/owncloud-client ~arm64
app-emulation/snapd ~arm64
sys-boot/osk-sdl ~arm64
sci-geosciences/gpsd ~arm64
dev-libs/wayland ~arm64
dev-util/gdbus-codegen ~arm64
app-emulation/lxc ~arm64
dev-libs/properties-cpp ~arm64
dev-util/android-tools ~arm64
dev-libs/libwacom ~arm64
dev-libs/gobject-introspection ~arm64
dev-libs/gobject-introspection-common ~arm64
media-plugins/grilo-plugins ~arm64
app-text/asciidoc ~arm64
net-libs/libqmi ~arm64
media-libs/gstreamer ~arm64
dev-util/gdbus-codegen ~arm64
dev-libs/glib ~arm64
dev-python/nautilus-python ~arm64
dev-lang/vala ~arm64
dev-libs/vala-common ~arm64
dev-util/ninja ~arm64
sys-apps/systemd ~arm64
sys-kernel/linux-headers ~arm64
net-misc/networkmanager ~arm64
net-misc/modemmanager ~arm64
net-misc/dhcpcd ~arm64
app-accessibility/at-spi2-core ~arm64
dev-python/pylast ~arm64
media-plugins/gst-plugins-taglib ~arm64

#Geary
dev-lang/vala ~arm64
dev-libs/vala-common ~arm64
net-mail/ytnef ~arm64
dev-perl/MIME-tools ~arm64
sys-libs/glibc ~arm64
app-text/nuspell ~arm64
net-libs/libvoikko ~arm64
dev-libs/glib ~arm64

#Neofetch
www-client/w3m ~arm64
x11-apps/xrandr ~arm64
x11-apps/xwininfo ~arm64

#Anbox
net-proxy/squid ~arm64


The first emerge I am doing is (after the initial sync):
code:
1
emerge --ask app-eselect/eselect-repository dev-vcs/git app-admin/sudo


Now I can add the extra repo my own repo GJDWebserver:
code:
1
eselect repository add gjdwebserver git https://github.com/stealthgun/gjdwebserver-overlay.git


Now sync again and we can select a profile, keep in mind that we are selection a systemd profile:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pine64-pinephone / # eselect profile list
Available profile symlink targets:
  [1]   default/linux/arm64/17.0 (stable)
  [2]   default/linux/arm64/17.0/desktop (stable)
  [3]   default/linux/arm64/17.0/desktop/gnome (stable)
  [4]   default/linux/arm64/17.0/desktop/gnome/systemd (stable)
  [5]   default/linux/arm64/17.0/desktop/plasma (stable)
  [6]   default/linux/arm64/17.0/desktop/plasma/systemd (stable)
  [7]   default/linux/arm64/17.0/desktop/systemd (stable)
  [8]   default/linux/arm64/17.0/developer (stable)
  [9]   default/linux/arm64/17.0/systemd (stable) *
  [10]  default/linux/arm64/17.0/big-endian (exp)
  [11]  default/linux/arm64/17.0/musl (exp)
  [12]  default/linux/arm64/17.0/musl/hardened (exp)
pine64-pinephone / # eselect profile set 4


After doing this you can emerge @world and after that the tools you want to use this is gonna take some time.

The emerge I did was:
code:
1
emerge --ask app-admin/syslog-ng sys-process/cronie sys-kernel/pinephone-sources net-misc/dhcpcd net-wireless/iw net-wireless/wpa_supplicant sys-apps/mlocate net-misc/openssh


Building the kernel
Since we a system with packages its time to build the kernel.

code:
1
2
3
4
5
6
7
8
9
10
11
12
pine64-pinephone / # emerge -ask pinephone-sources (if not done before)
pine64-pinephone / # eselect kernel list
Available kernel symlink targets:
  [1]   linux-5.11.0-r1 *
pine64-pinephone / # cd /usr/src/linux
pine64-pinephone / # make pinephone_defconfig
pine64-pinephone / # make Image dtbs modules
pine64-pinephone / # cp ./arch/arm64/boot/Image /boot/vmlinuz-5.11.0-r1-pinephone-arm64
pine64-pinephone / # cp ./arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone*.dtb /boot
pine64-pinephone / # make modules_install
pine64-pinephone / # make firmware_install
pine64-pinephone / # make headers_install INSTALL_HDR_PATH=/usr


If you want to use anbox add the following to the .config after make pinephone_defconfig
code:
1
2
3
4
5
6
7
8
9
10
CONFIG_ANDROID=y
CONFIG_ANDROID_BINDER_IPC=m
CONFIG_ANDROID_BINDERFS=y
CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"
CONFIG_MACVLAN=y
CONFIG_BRIDGE=y
CONFIG_TUN=y
CONFIG_USER_NS=y
CONFIG_UTS_NS=y
CONFIG_VETH=y


This aswell is gonna take some times, so take a coffee break.

Bootloader
If you have the kernel done its time to create the bootloader

You can follow the p-boot README to install p-boot binary and other files into pinephone's /boot folder.

You can clone to git repo into /tmp using
code:
1
pine64-pinephone /tmp # git clone https://megous.com/git/p-boot



And if you dont want to build it all just copy everything in dist/ to boot
code:
1
2
3
4
pine64-pinephone /tmp/p-boot # cd dist/
pine64-pinephone /tmp/p-boot/dist # ls
fw-debug.bin  fw.bin  p-boot-conf  p-boot-conf-native  p-boot-serial.bin  p-boot.bin
pine64-pinephone /tmp/p-boot/dist # cp * /boot/


What is missing at this point is an initramfs we can build that using dracut
code:
1
emerge --ask sys-kernel/dracut


The config /etc/dracut.conf should look like this
code:
1
2
3
4
5
6
7
8
9
# PUT YOUR CONFIG IN separate files
# in /etc/dracut.conf.d named "<name>.conf"
# SEE man dracut.conf(5) for options

# Equivalent to -H
hostonly="yes"

# Choose compression program for the image
compress="lz4"


Create and edit the file /etc/dracut.conf.d/dracut-pp.conf
code:
1
nano -w /etc/dracut.conf.d/dracut-pp.conf


code:
1
2
3
4
5
6
7
8
9
10
# load kernel modules that's needed to run accelarated osk SDL
force_drivers+=" lima gpu_sched goodix evdev sun6i_mipi_dsi sun8i-drm-hdmi sun8i-mixer panel-sitronix-st7703 "
# pmic
force_drivers+=" axp20x-pek axp20x_adc "
# force feedback
force_drivers+=" gpio-vibra "
# encryption module
force_drivers+=" crc-t10dif "
# emmc/sd driver
force_drivers+=" sunxi-mmc "


Then in /boot run
code:
1
pine64-pinephone /boot # dracut -m "rootfs-block base" --host-only --kver 5.11.0


Your boot directory should now look something like this
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
pine64-pinephone /boot # ls -l
total 24284
-rw-r--r-- 1 root root      342 Feb 26 16:58 boot.conf
drwxr-xr-x 2 root root     4096 Feb 26 16:58 files
-rw-r--r-- 1 root root    59496 Feb 26 16:38 fw-debug.bin
-rw-r--r-- 1 root root    59496 Feb 26 16:38 fw.bin
-rw------- 1 root root 10551208 Feb 26 17:18 initramfs-5.11.0.img
drwx------ 2 root root     4096 Feb 26 16:32 lost+found
-rwxr-xr-x 1 root root    50512 Feb 26 16:38 p-boot-conf
-rwxr-xr-x 1 root root    44520 Feb 26 16:38 p-boot-conf-native
-rw-r--r-- 1 root root    27136 Feb 26 16:38 p-boot-serial.bin
-rw-r--r-- 1 root root    32768 Feb 26 16:38 p-boot.bin
-rw-r--r-- 1 root root    38825 Feb 26 16:18 sun50i-a64-pinephone-1.0.dtb
-rw-r--r-- 1 root root    39040 Feb 26 16:18 sun50i-a64-pinephone-1.1.dtb
-rw-r--r-- 1 root root    39027 Feb 26 16:18 sun50i-a64-pinephone-1.2.dtb
-rw-r--r-- 1 root root 14063624 Feb 26 16:18 vmlinuz-5.11.0-r1-pinephone-arm64


You need the first partition of the boot media formatted as linux (83) partition, with enough space for kernel and other files.

Now write the p-boot.bin to boot media
code:
1
$ sudo dd if=p-boot.bin of=/dev/mmcblk2 bs=1024 seek=8


The boot config should look something like this

code:
1
2
3
4
5
6
7
8
9
10
$ cat /boot/boot.conf
device_id = pp3 (PP 1.2a)
no          = 0
  name      = Gentoo 5.11.0 (EMMC)
  atf       = fw.bin
  dtb       = sun50i-a64-pinephone-1.2.dtb
  linux     = vmlinuz-5.11.0-r1-pinephone-arm64
  initramfs = initramfs-5.11.0.img
  bootargs  = console=tty1 console=ttyS0,115200 root=/dev/mmcblk2p3 rootfstype=ext4 rw rootwait quiet
  splash    = files/pboot2.argb


The command to write boot kernel and other files to boot partition

code:
1
2
$ cd /boot
$ ./p-boot-conf . /dev/mmcblk2p1


Before rebooting make sure you run
code:
1
emerge --ask sys-firmware/anx7688-firmware sys-firmware/ov5640-firmware sys-firmware/rtl8723bt-firmware


In order to get the correct firmware for the kernel

After your initial boot into the system you need to do
code:
1
2
3
4
root #hostnamectl set-hostname pinephone
root #localectl set-keymap us # or whatever your keyboard is
root #timedatectl set-timezone Europe/Amsterdam # or wathever your time-zone is
root #timedatectl set-ntp true


To use the phone/simcard without a password add your user to the "plugdev" group

Dont forget to add everything needed to automaticly start after booting.

Finalizing
After this and following just the normal Gentoo setup steps (if not done earlier) like your network config, locale, time and timezone settings you can boot into the system. You can just follow the handbook for this since its a generic setup and not arm64 or pinephone specific.

In part two we are going into making it a usable phone with phosh and anbox.

I will create more blogs about using the pinephone for real using Gentoo.
So I hope this blog is helpfull for you into considering Gentoo for your Linux Phone.

Update
I've been working on Phosh now and I have updated the accept_keywords list in the blog and my own overlay to get it all working. My phone is now running the emerge for it. A thing to keep in mind is that rust is getting pulled with it so its gonna be a hefty emerge on the phone itself.

Update 2
Added anbox steps into the blog for if you want to use anbox on the pinephone

Volgende: Gentoo on a PinePhone making it a usable phone 26-03 Gentoo on a PinePhone making it a usable phone
Volgende: Word of Warcraft Private Server (MariaDB naar Oracle APEX  Ontwikkelen) 05-'20 Word of Warcraft Private Server (MariaDB naar Oracle APEX Ontwikkelen)

Comments


By Tweakers user Gieltje, Sunday 28 February 2021 17:20

Always good to see another Gentoo user :), also cool project

Comments are closed