This is an umbrella repo for my Pinephone
and MobileNixos experiemnts. The repo is
a bit oldschoolish as it doesn't use NixFlakes. The dependant repositories
are pinned as Git submodules (use git clone --recursive ..
).
- What is it?
- Hardware
- Usage
- How to use this repository
- Flashing external SDcard with Jumpdrive utility
- Flashing the internal eMMC card with a Mobile NixOS example configuration
- Determining the version of Pinephone's hardware
- Updating Mobilenixos over SSH
- Setting up a remote build agent
- On updating the MobileNixos and Nixpkgs submodules
- Switching to a Phosh configuration
- Running applications from the Phosh configuraiton via SSH
- Running the Phosh config in a QEMU emulator
- Updating the modem firmware
- Notes
- Resources
- A Pinephone and a USB cable
- A host PC with the Nix package manager installed
- 32Gb SDcard and USB cardreader
- Checkout the Git submodules
(host) $ git submodule update --init
- Enter the nix-shell to set the
PATH
andNIX_PATH
variable:(host) $ nix-shell
.
- The original document https://wiki.pine64.org/wiki/PinePhone_Installation_Instructions#Using_JumpDrive
- Jumpdrive page https://github.com/dreemurrs-embedded/Jumpdrive
The algorithm:
- Insert the TF-sdcard to your cardreader and connect it to the Host PC
- Run the flash-jumpdrive.sh script
sh ./script/flash-jumpdrive.sh
- Make sure the script detects the sdcard correctly, press
y
- Type in the
sudo
password if set. The sdcard is now the jumpdrive sdcard - Move the sdcard from the cardreader to the Pinephone
- Boot the Pinephone and connect it to the PC with USB cable. eMMC flash will
appear in the list of Host PC's block devices (verify it with
lsblk
).
Now one can flash the phone's internal eMMC from the Host PC.
- Tomf blog provided a good set of instructions https://git.sr.ht/~tomf/notes/tree/master/item/pinephone-nixos-getting-started.md
- Aarch64 image issue mobile-nixos/mobile-nixos#373
- On resizing partitions mobile-nixos/mobile-nixos#342
- A status Issue on MobileNixos installer mobile-nixos/mobile-nixos#374
Here we flash the Pinephone with the bootable MobileNixos configuration example.nix. Currently it has only an absolute minimum of features, like GUI+Wifi.
-
Enable the
binfmt
boot option of the Host PC's kernel as described in the Tom'f blog. -
Make sure that:
- External SDcard is flashed with Jumpdrive utility
- The pinephone is booted from Jumpdrive SDcard, connected to the Host PC and
the internal eMMC is listed among the PC block devices (
lsblk
).
-
Make sure that
mobile-nixos
andnixpkgs
submodules are checked-out (git submodule update --init --recursive
). -
Edit the
DEVL
variable of flash-mobile-nixos. Set it to the correct name of internal eMMC device. -
Run
flash-mobile-nixos.sh
-
Upon completion, turn the Pinephone off, remove the Jumpdrive sdcard from the Pinephone and turn it on again. Nixos XFCE example image should boot and the XFCE desktop should finally appear.
-
Manually resize the partition table on disk and the root filesystem, check the result with
df -h
.(pinephone) $ sudo cfdisk /dev/mmcblk2 ... Add the remaining free space to the /dev/mmcblk2p4 partition ... Write the new partition (pinephone) $ sudo resize2fs /dev/mmcblk2p4
-
The result may look like:
- Note 1: I only tested the
binfmt
hack described in Tomf's blog. - Note 2: The Original configuration doesn't enable SSH by mistake. This mobile-nixos PR fixes it: mobile-nixos/mobile-nixos#455 In this repo the changes should be already applied.
(pinephone) $ cat /proc/device-tree/model
1.2
1.1 is the Braveheart and 1.2 is a Community or Beta PinePhone. However Community editions have subversions like 1.2, 1.2a, 1.2b. Those might have additional hardware fixes.
The below method allows updating the Stage-2
software. The idea is to build the
toplevel package and then upload it's closure using nix-copy-closure
over SSH.
A related PR comment with a discussion
- Make meaningful changes in the
example.nix
configuration. - Turn the Pinephone on, connect it to a local WiFi network, figure out
its IP address. Say, we got a
192.168.1.38
. - Adjust the
DEVIP
variable of build-switch-toplevel.sh accordingly, and run it. Depending on the current SSH settings, the script may ask for ssh password several times (nixos
by default).(host) $ build-switch-toplevel.sh switch
The Pinephone software should be switched to the just-built profile. The old profile should be accessable through the recovery menu (shown at reboot+volume up).
Note: build-switch-phosh.sh script works with the phosh.nix config in a similar manner.
The source wiki page https://nixos.wiki/wiki/Distributed_build
Here we teach the Host PC's nixos to use the Pinephone as a remote build agent. Not sure, but it seems that it works faster than host-based build using qemu which also works by default.
- Determine which user runs builds on the Host PC. For NixOS hosts, the user is
root
. - Manyally setup the passwordless SSH loging from the Host PC's root user to
the pinephone, typically asa follows:
- Add the root's public SSH keys to the
root@pinephone
(done in theexample.nix
. - Rebuild and switch the Pinephone's configuration with
build-switch-toplevel.sh switch
- Add the
pinephone-builder
section into the/root/.ssh/config
of the Host.
- Add the root's public SSH keys to the
- Assuming that the Host PC is a NixOS, we need to update it's config with a
snippet like the following:
{ config, pkgs, ... }: { nix.buildMachines = [ { hostName = "pinephone-builder"; sshUser = "root"; systems = ["aarch64-linux"]; maxJobs = 1; speedFactor = 2; mandatoryFeatures = [ ]; } ] ; nix.distributedBuilds = true; }
- To test that the Pinephone's store is available:
(host) $ sudo nix ping-store --store ssh://pinephone-builder && echo ok ok
- To make sure that the builder does ditribute builds to the Pinephone:
(host) $ vim modules/nixpkgs/pkgs/tools/misc/mc/default.nix ... edit smth to force rebuilding (TODO: how to --check distributed build?) (host) $ build-mobile-nixos.sh -j0 -A pkgs.mc
- Watch the host's log and the pinephone's
htop
.
- MobileNixos includes pkgs.nix which seems to pin a specific version of nixpkgs
- A related issue mobile-nixos/mobile-nixos#93
- An old comment from 2020 https://discourse.nixos.org/t/build-image-for-pinephone-fail/10002/4
- Scripts from this repo force MobileNixos to use the nixpkgs from the
Git-submodule. The submodule, in turn, should be set to the version mentioned
in the
pkgs.nix
- Phosh demo PR mobile-nixos/mobile-nixos#352
- Pinephone page of NixOS wiki https://nixos.wiki/wiki/PinePhone
-
Make sure that the Pinephone is on, its Wifi is working and the passwordless SSH login is set up
-
Run the
build-switch-phosh.sh
(host) $ build-switch-phosh.sh switch
-
The result may look like
GUI on the phone's screen
- Login tho the Pinephone using SSH
- Set variables
- For the wayland apps:
export WAYLAND_DISPLAY=wayland-0
- For the Telegram
export QT_QPA_PLATFORM=wayland
- For the wayland apps:
- Run apps from the command line, they should appear on the phone's screen.
GUI on the host
- Install
weston
andwaypipe
- Run
weston
as host's X-client. Click on the termina icon - Run
(host+weston) $ waypipe ssh nixos@pinephone <WAYLAND_APP>
. See the application's screen appear inside the weston window on the host.
- A related discussion mobile-nixos/mobile-nixos#3
Notes:
- Actually, building the qemu image takes some time. It may be faster to run simple things on a real device.
- TODO: figure out how to adjust the screen size to that of real pinephone.
This is a hard one.
- Stable quctel fw branch at the time of the writing and an updating
guide
- The guide is overall correct, but Mobilenixos currently uses Megi's kernel
which has
modem-power
driver which also should be disabled. - My issue regarding the EDL mode Biktorgj/quectel_eg25_recovery#13
- The guide is overall correct, but Mobilenixos currently uses Megi's kernel
which has
- An issue describing how to disable
modem-power
driver mobile-nixos/mobile-nixos#457
- In general, we follow the Quectel's guide.
- Make sure
pkgs.android-tools
presents in the system packages section of the pinephone configuration. - Temporary disable the modem-control service:
systemd.services."modem-control".enable = false;
- Reboot the pinephone. Modem should be powered off.
- Stop the ModemManager
(pinephone) $ systemctl stop ModemManager
- Power the modem on using
dumb
methodecho 2 > /sys/class/modem-power/modem-power/device/powered
- Generate the magic AT commands
(pinephone) $ journalctl -b | grep 'ADB KEY' ... ADB KEY is '31281228' ... (pinephone) $ curl https://xnux.eu/devices/feature/qadbkey-unlock.c > qadbkey-unlock.c (pinephone) $ gcc qadbkey-unlock.c -lcrypt -o qadbkey-unlock (pinephone) $ ./qadbkey-unlock 31281228 ... Prints three AT commands: two to unlock the ADB and one to lock it back.
- Send the first two AT commands to the Modem's serial port
/dev/ttyUSB2
(useminicom
, or start the ModemManager with --debug and usemmcli
or use other serial communicatin methods) - An additional usb device should appear.
adb
should be able to recognize it as aunnamed device
. Proceed with Quectel's manual:(pinephone) # adb reboot edl
. - Proceed with Quectel's manual to the
./qfirehose -f ./
part. - Upon successful update, disable the adb by sending the third magic AT
command, generated by
qadbkey-unlock
. - Re-enable the
modem-control
service and reboot the pinephone.
- To make a shallow fetch of a specific commit, do
git fetch [remote] --depth 1 origin <full_commit_hash>
- Get eg25-manager to work mobile-nixos/mobile-nixos#348
- As I wrote in this issue, it turns out that Megi's driver is probably better than eg25-manager in terms of power management. Still, eg25-manager does have some benefits in terms of GPS management and voice calls settings.
- Some docs in power subsystem
- https://www.kernel.org/doc/html/latest/power/pci.html
- search for
SET_SYSTEM_SLEEP_PM_OPS
- search for
- https://www.kernel.org/doc/html/v4.14/driver-api/pm/devices.html
- https://www.kernel.org/doc/html/latest/power/pci.html
- Crust firmware
- Probably, it is already installed in Pinephones >= 1.2
- Crust wifi thread on Pine64 https://forum.pine64.org/showthread.php?tid=11184
- Crust deep sleep thread on Pine64 https://forum.pine64.org/showthread.php?tid=9957&page=6&highlight=crust+data
- https://ivoberger.com/posts/port-forwarding-with-iptables/
- Install legace iptables, disable the firewall
- Set
iptables -t nat -A POSTROUTING ! -s 127.0.0.1 -j MASQUERADE
- TODO: explore
networking.firewall
settings
-
Sometimes host can't receive the IP addres. One could set it manually to
172.16.42.2
and connect to172.16.42.1
sudo ifconfig enp0s20f0u1 172.16.42.2 netmask 255.255.255.0
build-switch-phosh.sh -A config.system.build.kernel.src
Author's phone probably has a defected crystall on a low-precision clock.
- Crust issue (resolved) crust-firmware/crust#203
MobileNixos on Pinephone
- NixOS wiki about Pinephones https://nixos.wiki/wiki/PinePhone
- PR about Phosh integration mobile-nixos/mobile-nixos#352
- All Pinephone open issues and PRs https://github.com/NixOS/mobile-nixos/issues?q=is%3Aopen+pinephone
- Megi's modem driver https://xnux.eu/devices/feature/modem-pp.html
- Mobilenixos+modem issue mobile-nixos/mobile-nixos#348 (comment)
- MobileNixos uses Megi's modem driver. An alternative approach would be to port e25-manager
- Linux kernel device tree at the time of the writing https://github.com/megous/linux/blob/b1f383fd3c70e21a8062fdc3f59403d2a26edc9f/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone-1.2.dts#L1
MobileNixos general
- Getting started https://mobile.nixos.org/getting-started.html
- Discource https://discourse.nixos.org/t/mobile-nixos-progress-thread/342/51
- GitHub https://github.com/NixOS/mobile-nixos
- Hydra status page https://hydra.nixos.org/build/134431266#tabs-buildinputs
- Custom Qemu port (no GPU) https://unxp.fr/post/2020/pinephone_on_qemu_emulation/
- PR related to the emulation mobile-nixos/mobile-nixos#253
- NixOS wiki on Aarch64 emulation https://nixos.wiki/wiki/NixOS_on_ARM#Compiling_through_QEMU
- PR, emulation mobile-nixos/mobile-nixos#3
- Power consumption issue mobile-nixos/mobile-nixos#13
PinePhone general
- PinePhone Installation Instructions https://wiki.pine64.org/wiki/PinePhone_Installation_Instructions
- nOOb microSD flashing https://wiki.pine64.org/wiki/NOOB#Step-by-Step_Instructions_to_Flashing_MicroSD_Cards
- https://news.ycombinator.com/item?id=23130247
- MicroSD extender https://pine64.com/product/pinephone-microsd-extender/
- PostmarketOS docs on Pinephone https://wiki.postmarketos.org/wiki/PINE64_PinePhone_(pine64-pinephone)
- Jumpdrive https://github.com/dreemurrs-embedded/Jumpdrive
- Jumpdrive boot menu issue dreemurrs-embedded/Jumpdrive#11
- Crust firmware Github page https://github.com/crust-firmware/crust
- On updating the modem's firmware https://forum.manjaro.org/t/manjaro-arm-beta13-with-phosh-pinephone/79665/14
- Megi modem driver docs https://xnux.eu/devices/feature/modem-pp.html
- Manjaro modem discussion https://forum.manjaro.org/t/manjaro-arm-beta13-with-phosh-pinephone/79665/14
- Pinephone page on modem fw update https://wiki.pine64.org/wiki/PinePhone#Firmware_update
- Open-source modem fw (risky?) https://github.com/Biktorgj/pinephone_modem_sdk
Mobile nixers
- https://github.com/knedlsepp/flakephone
- Noob question from me https://discourse.nixos.org/t/mobile-nixos-progress-thread/342/57?u=sergeymironov
- Tomf blog https://git.sr.ht/~tomf/notes/tree/master/item/pinephone-nixos-getting-started.md
- Mhuesch https://github.com/mhuesch/pinephone-mobile-nixos-flake-example
Fun
- Nix maintainers, discovering Nix icon on the PinePhone site, to their surprise https://discourse.nixos.org/t/nixos-on-home-page-of-pinephone/4765