How to install Arch Linux ARM on Allwinner Devices
General steps should be well known to most Arch Linux users:
- get the right rootfs tarball from https://archlinuxarm.org
- prepare a partition table and format filesystems on the microSD card
- mount the filesystems
- extract rootfs tarball to the filesystems
- modify configuration files so that you can somehow access the device when it boots
- get the kernel and the bootloader for the device
- copy the kernel to the boot partition
- install the bootloader by copying it to the SD card starting 8kiB from the start
Where this differs is that there's no generic kernel for all devices, so you have to build a specific one, with configuration suited to the device or a small set of similar devices. And the installation of the kernel and u-boot is a manual process not handled by the package manager.
Getting the rootfs
If installing on ARMv8 device (A64, H5, H6, …)
wget http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz
If installing on ARMv7 device (H3, A83T, A13, …)
wget http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz
Prepare the partition table and filesystems
If your distro is using udisk
or
automountig, you need to be careful or disable it. The guide assumes your distro
is not doing some magic automounting in the background.
Replace
/dev/sdX
with the device where your SD card is located.
sfdisk /dev/sdX <<EOF label: dos unit: sectors 4MiB,252MiB, 256MiB,, EOF mkfs.vfat -n BOOT /dev/sdX1 mkfs.f2fs -f -l ROOT /dev/sdX2
Mount the filesystems and extract the rootfs tarball
mount /dev/sdX2 /mnt mkdir -p /mnt/boot mount /dev/sdX1 /mnt/boot bsdtar -xpf ArchLinuxARM-armv7-latest.tar.gz -C /mnt # or (see above) bsdtar -xpf ArchLinuxARM-aarch64-latest.tar.gz -C /mnt
Fixup configuration
Setup /mnt/etc/fstab
at the very
least.
You'll need it to contain:
/dev/mmcblk0p1 /boot vfat rw 0 1 /dev/mmcblk0p2 / f2fs rw,relatime 0 0
You may also want to setup wifi, or enable USB
networking, via g_ether
driver and some
systemd-netword
config files to setup the IP addresses and
gateways. How to do that should be a general Linux networking knowledge, and it
is documented on Arch Linux wiki.
Install the kernel and the bootloader
For the sake of brevity, I'll only tell you how to install my pre-built binary kernel and bootloader.
Go to https://xff.cz/kernels/ and
download the latest version of the right kernel package. Names mean:
pp
for PinePhone, pb
for PocketBook, one
,
pc
, pc2
, pi3
for Orange Pi One/PC/PC2/3
respectively.
Extract the package and follow the README file inside.
You'll just need to copy some files to the right place in your mounted
filesystems on the SD card, and flash the bootloader to the boot block via
dd
, and perhaps customize the kernel boot arguments to tell the
kernel where to find the root filesystem. You'll need to install
uboot-tools
to be able to package the bootloader configuration
script.
Umount the filesystems
umount /mnt/boot umount /mnt sync
Now you should have a bootable microSD card. Just put it in your device and have fun.
PinePhone Example
For example, when trying to install the kernel and the bootloader on a SD card for PinePhone, the end result is expected to look like this:
- Get the
pp.tar.gz
from the above website, it contains the necessary files - SD card is partitioned so that first partition has a FAT filesystem and starts at 1MiB offset from the start of the SD card or further
- The 1MiB empty space at the beginning is used to hold the
partition table and the bootloader (
uboot.bin
file)- The
bootloader binary needs to be placed at 8KiB offset from the start of the SD
card (or eMMC) via
dd if=uboot.bin of=/dev/sdX bs=1024 seek=8
command (replace/dev/sdX
with the device of the SD card – the whole device, not one of the partitions)
- The
bootloader binary needs to be placed at 8KiB offset from the start of the SD
card (or eMMC) via
- The first partition
will hold a FAT filesystem with files
board.itb
andboot.scr
(boot.scr
is generated fromboot.cmd
usingmkimage -A arm64 -T script -C none -d boot.cmd boot.scr
)- Modify
the
boot.cmd
first and change thebootargs
to remove theloglevel=0
andquiet
arguments to see any possible errors during boot (by default thebootargs
specify the root partition as the second partition of the SD card) - The files need to be
in the root folder of the FAT filesystem on the first partition (so if you mount
the first partition of the SD card to
/mnt/boot
on your PC, place them there)
- Modify
the
- My kernel only supports the boot from
f2fs
, so make sure you use this filesystem for therootfs
of Arch Linux ARM - The second partition on the SD
card must contain an extracted Arch Linux ARM aarch64 rootfs tarball content on
a
f2fs
fielsystem.
Connecting to your device
The challenge here is to configure networking without having a shell access to the running PP.
You'll have to update the configuration files for PP using the SD card reader on your PC.
By default Arch Linux ARM will load most
of the modules that are needed to enable networking over USB, except for
g_cdc
.
With this module loaded, PinePhone will see a
usb0
network interface. When connected via USB to a PC, the PC will
create network interface for the other side of the network link, too. On my
workstation's Arch Linux, this interface is named predictably
enp0s20u1
:). The name will be different based on what port you'll
stick the PP's USB cable to. You can check dmesg
or
ip l
to get the interface name.
You'll also have to
configure the both ends of the network link. There are many ways to do it, so
let's just use the simplest way and assign a static IP addresses to both sides
of the link (10.0.0.2
on PP and 10.0.0.1
on
the PC).
PinePhone SD card
Add a
configuration file at etc/modules-load.d/usb0.conf
to make sure
g_cdc
module is loaded on boot:
g_cdc
Add the etc/systemd/network/usb0.network
file to the rootfs on the SD card so systemd-networkd will configure the network
interface:
[Match] Name=usb0 [Network] Address=10.0.0.2/24 Gateway=10.0.0.1 DHCP=no
To be able to easily ssh to the PP, you may also copy
your key to /root/.ssh/authorized_keys
at this time.
PC
On your PC, if you're using systemd, create the following
file at /etc/systemd/network/pp.network
:
[Match] Name=yourinterfacename [Network] Address=10.0.0.1/24 DHCP=no
Don't forget to
restart systemd-networkd
.
Put the SD card to the PinePhone
and you should now be able to ssh to root@10.0.0.2
.