Booting mobian and postmarketOS on pinephone
Posted by sky | Tags: Linux , Mobile , Open-Source , Personal , mobian , pinephone , postmarketOS , testing
I have used postmarketOS on pinephone (2gb) by installing to SD card. Recently, I install Tow-Boot and mobian in the internal eMMC as the original Linux OS becomes unuseable after a software update.
By default, the pinephone always boot up the Linux OS on the SD card. We need to remove the uboot software at the front of SD card first before Tow-Boot can boot up mobian by default, and boot up postmarketOS on SD card by holding the Volume Down button. (^1)
On a Linux computer, assuming the SD card is /dev/sdc , the following will remove the uboot software:
sudo dd if=/dev/zero of=/dev/sdc bs=8k seek=1 count=4
On the pinephone itself with postmarketOS, the SD card is /dev/mmcblk0 , the command will be:
sudo dd if=/dev/zero of=/dev/mmcblk0 bs=8k seek=1 count=4
After this, mobian can be booted up, but postmarketOS cannot be booted up when holding the Volume Down button. The issue (^3) can be resolved by modifying the /boot/boot.scr .
To restore the uboot firmware/bootloader image on SD card (^2), I mount the SD card (assuming it is /dev/mmcblk0 , which is not always the same on mobian) from mobian and restore the uboot image with the following:
sudo mount /dev/mmcblk0p2 /mnt
sudo dd if=/mnt/usr/share/u-boot/pine64-pinephone/u-boot-sunxi-with-spl-528.bin of=/dev/mmcblk0 bs=1024 seek=8
sudo umount /mnt
After restoring the uboot image, by default, the pinephone will boot up postmarketOS on the SD card. The above steps does allow us to boot up both Linux OS at least as a fallback mechanism.
To modify postmarketOS /boot/boot.scr (^4), we need to replace all instances of mmc_bootdev with devnum .
dumpimage -T script -o boot.txt /boot/boot.scr
sudo mv /boot/boot.scr /boot/boot.scr.0
In boot.txt, the first 8 non-printable chars is deleted. I use vi to edit, and the vi command to replace mmc_bootdev with devnum :
%s/mmc_bootdev/devnum
mkimage -A arm -O linux -T script -C none -n postmarketos -d boot.txt /boot/boot.scr
After this, we need to remove the uboot software at the front of SD card first before we can retest Tow-Boot.
Although Tow-Boot can now boot up postmarketos when holding the Volume Down button, the postmarketos always enter its debug shell which gives us a new problem (^5), it will hang when we want to continue the boot with pmos_continue_boot .
After this, reboot back to mobian to restore the postmarketos uboot image again so we can boot into postmarketos to modify its /boot/initramfs .
On postmarketos, I change /usr/share/initramfs/init_functions.sh check_keys function by removing the Volume Down key check and replace it with using Volume up key to enter debug shell :
check_keys() {
{
# If the user is pressing either the left control key or the volume up
# key then drop to a debug shell.
if iskey KEY_LEFTCTRL KEY_VOLUMEUP; then
debug_shell
# If instead they're pressing left shift , then fail boot
# and dump logs
elif iskey KEY_LEFTSHIFT; then
fail_halt_boot
fi
touch /tmp/debug_shell_exited
} &
while ! [ -e /tmp/debug_shell_exited ]; do
sleep 1
done
}
After modifying init_functions.sh , run the following to update initramfs :
sudo mkinitfs
After this, we need to remove the uboot software at the front of SD card first before we can retest Tow-Boot.
Finally, Tow-Boot boot up mobian by default, and boot up postmarketOS on SD card by holding the Volume Down button.
References:
- https://tow-boot.org/devices/pine64-pinephoneA64.html
- https://wiki.postmarketos.org/wiki/PINE64_PinePhone_(pine64-pinephone)#postmarketOS_installed_to_SD
- https://github.com/Tow-Boot/Tow-Boot/issues/286
- https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/3068
- https://gitlab.postmarketos.org/postmarketOS/pmaports/-/issues/3416