Play Armbian OS with Phicomm Box

5 minute read

Armbian is an operation system based on Debian and Ubuntu, created for ARM-based development boards, it also supports a wide variety of TV boxes, and a lot of them are shipped with Amlogic SoCs, such as S905 and S912 series.

I bought two TV boxes with S905D and S912 respectively, manufactured by Phicomm. As these two boxes are pretty old, there is no official build images for them, 150balbes has maintained a repo for Amlogic SoC based boards, download from yadisk for later use, the latest version is is 20200715.

Downgrade Firmware

According to the tutorial created by webpad, in order to boot from USB drive, the firmware has to be degraded to V2.19, my N1 box has V2.27: Phicomm N1 version so follow the below steps to downgrade the stock firmware:

  1. Download firmware image from weiyun(password: nzwy53)

    # N1
    75da954d0c4cbcd4a86cee501b40c5aa  boot.img
    80bd2efed2f76b6eca56f7e026549e1a  bootloader.img
    cac6ed1ded5bb1d9cfad39b2b1c6cd8a  recovery.img
    
    # T1
    24c57e548eb98e7ebfc24f5f1ca110b2  boot.img
    567a870ebf1b8e5d2bee77e37c3f87ce  bootloader.img
    f4b6b79ad15f0a7e0cb9be1219e8a828  recovery.img
    
  2. Enable adb

    For N1: Click the version number four times to enable adb, there will be a toast at the end.

    For T1: Install PhiTvRemote, launch settings with this app, and enable adb debug in Remote debugging section: Phicomm T1 Settings

  3. Do adb connect 192.168.100.3

  4. Create udev rule for fastboot:

    cat << EOT >>  /etc/udev/rules.d/51-android.rules
    SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{idVendor}=="18d1", ATTR{idProduct}=="0d02", MODE:="0666"
    EOT
    sudo udevadm control -R
    
  5. Connect N1 box to Ubuntu computer with dual male USB cable.

  6. reboot to fastboot mode: adb reboot fastboot, you should see your box with fastboot devices, if not, check the troubleshooting section.

  7. Flash prepared images with fastboot command:

    fastboot flash bootloader bootloader.img
    fastboot flash boot boot.img
    fastboot flash recovery recovery.img
    fastboot reboot
    

Install Armbian

  1. Flash the previously downloaded armbian image to USB driver.
  2. Enable ssh access by creating an empty file in BOOT partition named ssh:
    touch /media/fdbai/BOOT/ssh
    
  3. Choose right dtb file:
    # For Phicomm N1
    sed -i s/meson-g12b-odroid-n2/meson-gxl-s905d-phicomm-n1/g /media/fdbai/BOOT/uEnv.txt
    # For Phicomm T1
    sed -i s/meson-g12b-odroid-n2/meson-gxm-q201.dtb/g /media/fdbai/BOOT/uEnv.txt
    
  4. Now we are ready for booting Armbian, do adb reboot update to make N1 to boot from USB, this may involve system reboot for about 3 times.

  5. Login with root, the default password for root is 1234.

Resize ROOT Partition

By default, the root partition is too small, even an apt update will fail with no space left error:

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1         32768   557055   524288  256M  e W95 FAT16 (LBA)
/dev/sda2        557056  3883007  3325952  1.6G 83 Linux

To enlarge the root partition, first delete root partition with fdisk, then create a new partition with same start sector:

root@aml:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 14.6 GiB, 15665725440 bytes, 30597120 sectors
Disk model: Storage Device
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x26f2c373

Device     Boot  Start     End Sectors  Size Id Type
/dev/sda1        32768  557055  524288  256M  e W95 FAT16 (LBA)
/dev/sda2       557056 3883007 3325952  1.6G 83 Linux

Command (m for help): d
Partition number (1,2, default 2):

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p):
Partition number (2-4, default 2):
First sector (2048-30597119, default 2048): 557056
Last sector, +/-sectors or +/-size{K,M,G,T,P} (557056-30597119, default 30597119):

Created a new partition 2 of type 'Linux' and of size 14.3 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: Y

The signature will be removed by a write command.

Command (m for help): w
The partition table has been altered.
Syncing disks.

Then resize the newly created root partition with:

root@aml:~# resize2fs /dev/sda2
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/sda2 is now 3755008 (4k) blocks long.

Check this out with df command:

root@aml:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            738M     0  738M   0% /dev
tmpfs           175M  3.2M  172M   2% /run
/dev/sda2        14G  1.3G   13G  10% /
tmpfs           871M     0  871M   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           871M     0  871M   0% /sys/fs/cgroup
tmpfs           871M  8.0K  871M   1% /tmp
/dev/sda1       256M   75M  181M  30% /boot
/dev/zram0       49M  3.0M   42M   7% /var/log
tmpfs           175M     0  175M   0% /run/user/1000

Install Software

Software is managed by armbian-config, go to Software ➜ softy to choose what you are interested, currently supported software packages are:

Install to Internal eMMC

You can install the system to the internal eMMC by script /root/install-aml.sh to free your USB drive.

Current version is not stable, installing to eMMC is highly not recommended.

Troubleshooting

N1 box not really rebooted to fastboot mode

A: You should use adb shell reboot fastboot instead of adb reboot fastboot

No permission for listing devices

fastboot devices
no permissions (user in plugdev group; are your udev rules wrong?); see [http://developer.android.com/tools/device.html]

A: Don’t forget to create udev rules.

e2fsprogs: resize2fs: online resizing always fails

Some USB drive may cause resize2fs failed with IO error if you choose to remove ext4 signature:

root@aml:~# resize2fs /dev/sda2
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
resize2fs: Input/output error While checking for on-line resizing support

# dmesg
[  178.500868] EXT4-fs (sda2): resizing filesystem from 415744 to 3739648 blocks
[  191.097773] EXT4-fs (sda2): resized to 1572864 blocks
[  202.780357] EXT4-fs (sda2): resized to 2621440 blocks
[  214.064304] EXT4-fs (sda2): resized to 3670016 blocks
[  214.122156] sd 0:0:0:0: [sda] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE cmd_age=0s
[  214.129719] sd 0:0:0:0: [sda] tag#0 Sense Key : Not Ready [current]
[  214.136023] sd 0:0:0:0: [sda] tag#0 Add. Sense: Logical unit communication time-out
[  214.143622] sd 0:0:0:0: [sda] tag#0 CDB: Write(10) 2a 00 01 c8 80 30 00 00 f0 00
[  214.150935] blk_update_request: I/O error, dev sda, sector 29917232 op 0x1:(WRITE) flags 0x4000 phys_seg 30 prio class 0
[  214.346519] EXT4-fs warning (device sda2): ext4_resize_fs:2064: error (-5) occurred during file system resize
[  214.355064] EXT4-fs (sda2): resized filesystem to 3670016

A: Do not remove the signature or change another USB drive.