Project

General

Profile

Actions

Wiki

Getting ArchLinux ARM running on the Nexbox A95x

Common steps

Format the SD Card

Insert the SD Card you will be booting from.

fdisk /dev/mmcblk0

# create two partitions (or more if you want)
# first partition should be bootable, W95 FAT32, 512MB
# second partition should be your rootfs, f2fs is a good choice.
# write partition data.
# make sure it gets picked up by the kernel before you continue.

# format your partitions:
# mkfs.vfat -n boot /dev/mmcblk0p1
# mkfs.f2fs -l rootfs /dev/mmcblk0p2

Setup the rootfs.

We can copy the compiled modules and firmware later when we choose a kernel.

cd /tmp
wget http://au.mirror.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz

sudo su - 
mount LABEL=rootfs /mnt/
bsdtar -xpf /tmp/ArchLinuxARM-aarch64-latest.tar.gz -C /mnt/
sync
sudo umount /mnt/
sync

Prep your device to boot from SDCard

I used the toothpick method and it worked fine. (unplug the power press the reset key hidden under the AV plug with a toothpick and plug the power keeping the reset key pressed until it loads)

It should now boot up your new ArchLinux ARM installation, with a fresh kernel.

Method 1: using balbes150 kernel

Note: I had too many stability problems with kernel 4.12.9 and the 4.13-rc. 4.13-rc would hang in some conditions (fairly frequently) and 4.12.9 would stacktrace in the network driver and the network would not recover. I am not sure yet whether this is my device, or buggy code/drivers in the balbes150 kernel. Will be trying an amlogic one next (4.9.26)

Build the kernel, DTBs, modules, and setup the boot partition

#Get balbes kernel source
cd /tmp
git clone git@github.com:150balbes/Amlogic_s905-kernel.git
cd Amlogic_s905-kernel

#Checkout a stable tag
git checkout tags/v20170828_4.12.9

export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=arm64

make clean
make mrproper

# Download the .config attached to this page, or get one with:
#   wget "https://raw.githubusercontent.com/150balbes/build/amlogic/config/kernel/linux-amlogics905x-dev.config_4.12.9" 
# Copy it to /tmp/Amlogic_s905-kernel/.config

make oldconfig

make menuconfig  #do any tweaks to the config

make -j4 Image dtbs
make -j4 modules

# Install the modules and firmware to a sub-directory. We will copy them to rootfs later.
make INSTALL_MOD_PATH=build-${ARCH}-modules INSTALL_MOD_STRIP=1 modules_install
make INSTALL_MOD_PATH=build-${ARCH}-modules INSTALL_MOD_STRIP=1 firmware_install

# Copy the DTB to the SDCard boot partition as 'dtb.img'
cp arch/arm64/boot/dts/amlogic/meson-gxl-s905x-nexbox-a95x.dtb /run/media/someuser/boot/dtb.img

# Copy the kernel image to the SDCard boot partition
cp arch/arm64/boot/Image /run/media/someuser/boot/

# Create a s905_autostart script, this is used to tell u-boot how to execute the kernel, and with what command line params.
cat > /run/media/someuser/boot/s905_autostart.booti.txt <<EOF
setenv kernel_loadaddr "0x01080000" 
setenv hdmimode "1080p60hz" 
setenv display_bpp "24" 
setenv init_hdmi "hdmimode=${hdmimode} m_bpp=${display_bpp} vout=${hdmimode},enable" 
setenv condev "console=ttyS0,115200n8 console=tty0 no_console_suspend consoleblank=0" 
setenv bootargs "root=/dev/mmcblk1p2 rootwait rw ${condev} ${init_hdmi} fsck.repair=yes net.ifnames=0" 
setenv boot_start booti ${kernel_loadaddr} - ${dtb_mem_addr}
if fatload mmc 0:1 ${kernel_loadaddr} Image; then if fatload mmc 0:1 ${dtb_mem_addr} dtb.img; then run boot_start; else store dtb read ${dtb_mem_addr}; run boot_start;fi;fi;
EOF

# Compile the autostart script to a usable u-boot format:
cd /run/media/someuser/boot/
mkimage -A arm -O linux -T script -C none -d s905_autostart.booti.txt s905_autoscript

Continue setting up the rootfs, copy the compiled modules and firmware

cd /tmp
sudo mount LABEL=rootfs /mnt/

[[ -d /mnt/lib/firmware ]] && echo Removing existing firmware drivers from rootfs && rm -rf /mnt/lib/firmware
rsync -av /tmp/Amlogic_s905-kernel/build-arm64-modules/lib/firmware /mnt/lib/
rsync -av /tmp/Amlogic_s905-kernel/build-arm64-modules/lib/modules/* /mnt/lib/modules/

Insert your SDCard into the Nexbox A95x and reboot into your new ArchLinux installation.

Using Amlogic 4.9.26 kernel

Get the kernel.

git clone git@github.com:ianmatt/amlogic-kernel-4.9.26.git
cd amlogic-kernel-4.9.26.git

Apply this patch to compile with latest GCC cross compile toolchain:

cat >turn-off-warnings-as-errors.patch <<EOF
--- Makefile
+++ Makefile-no-warnings
@@ -301,7 +301,7 @@

 HOSTCC       = gcc
 HOSTCXX      = g++
-HOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
+HOSTCFLAGS   = -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
 HOSTCXXFLAGS = -O2

 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
@@ -395,11 +395,10 @@

 KBUILD_CPPFLAGS := -D__KERNEL__

-KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
+KBUILD_CFLAGS   := -Wundef -Wstrict-prototypes -Wno-trigraphs \
            -fno-strict-aliasing -fno-common \
            -Werror-implicit-function-declaration \
            -Wno-format-security \
-           -Werror    \
            -std=gnu89 $(call cc-option,-fno-PIE)

EOF

patch < turn-off-warnings-as-errors.patch

Build your kernel.

WIP WIP WIP

Note: I'm fairly sure there are some broken modules within the amlogic branches, so not all things can be enabled.

I used this config as a basis to avoid dealing with broken code on compile:

https://raw.githubusercontent.com/150balbes/Amlogic_s905-kernel/khadas-4.9/config_20180219

cd /tmp/amlogic-kernel-4.9.26.git
make clean && make mrproper
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-

cd /tmp
wget https://raw.githubusercontent.com/150balbes/Amlogic_s905-kernel/khadas-4.9/config_20180219
cp config_20180219 /tmp/amlogic-kernel-4.9.26.git/.config

cd amlogic-kernel-4.9.26.git
make oldconfig
make menuconfig  #set your params

Initial Ramdisk

If you want to use an init ramdisk, best to start with an existing one and modify it to suit your needs. I downloaded a full ArchLinux image from here:

https://s159f.storage.yandex.net/rdisk/fd5bcc9d4f6daf4d1448b62d6bfa4c07474fff69e2d1a11a96c0208481f951bc/5a9b9eeb/Lb2ke34_zZnnnWClJXZlU3ZLw8P5-NoK3wD0Hr9XVrVACA24F79NPsRedwDF3IvkaFN7Fnwdviq5kZufodLfjA==?uid=0&filename=S905X_S912_ArchLinux_20170519_4_9_26.img.xz&disposition=attachment&hash=IV1g2qtqp/OgENLIqR29g2t6hqZPScQOoHu6s/7uTD4%3D%3A/S905X_S912_ArchLinux_20170519_4_9_26.img.xz&limit=0&content_type=application%2Foctet-stream&fsize=380325840&hid=69f77d69b8a767255d8ee7c8ce2fffbd&media_type=data&tknv=v2&rtoken=lReXXWHyimxk&force_default=no&ycrid=na-4669e41cf245c8b193784177e2f5a3a2-downloader17f&ts=5669115a550c0&s=183568521f1c116ab53d02ef5c80a7554989c77ef6af5fdde7284312d4ab6ed2&pb=U2FsdGVkX19l22p30tbA_3YhhOy0BpJWvycTttghgFVm87wnvngI_43woNmZiZk0Rho_nODYSWYnzzm9jNXr6jKy42kF-gRB6tRCCIf07Xs

It's a full disk image. Use the following to have loopdev activate partitions on the image:

losetup -Pf <image>

Copy off the initrd and dtb.img

sudo mount -o ro /dev/loop2p1 /mnt/
cp /mnt/dtb.img /tmp/
cp /mnt/uInitrd /tmp/

Extract out the initrd:

mkdir /tmp/initrd-out
cd /tmp/initrd-out
dd if=/tmp/uInitrd bs=1 skip=64 | gunzip -c > /tmp/uInitrd.cpio
cpio -idv < /tmp/uInitrd.cpio

Copy in whatever modules you need in your ramdisk. Don't forget to rename /lib/modules/<kernel_name> to appropriate name if your kernel name is different.

Rebuild the initrd:

cd /tmp/initrd-out
find . | cpio --create --format='newc' | gzip > ../newramdisk.img
cd ..
mkimage -A arm64 -O linux -T ramdisk -C none -a 0x13000000 -n "initrd with f2fs" -d newramdisk.img newInitrd.img

Create a new s905_autoscript to tell the u-boot how to boot:

cat >/tmp/s905_autoscript_new.txt <<EOF
setenv kernel_loadaddr "0x11000000" 
setenv initrd_loadaddr "0x13000000" 
setenv hdmimode "1080p60hz" 
setenv display_bpp "24" 
setenv init_hdmi "hdmimode=${hdmimode} m_bpp=${display_bpp} vout=${hdmimode},enable" 
setenv condev "console=ttyS0,115200n8 console=tty0 no_console_suspend consoleblank=0" 
setenv bootargs "root=/dev/mmcblk1p2 rw ${condev} ${init_hdmi} fsck.repair=yes net.ifnames=0" 
setenv boot_start booti ${kernel_loadaddr} ${initrd_loadaddr} ${dtb_mem_addr}
if fatload mmc 0:1 ${initrd_loadaddr} uInitrd; then if fatload mmc 0:1 ${kernel_loadaddr} zImage; then if fatload mmc 0:1 ${dtb_mem_addr} dtb.img; then run boot_start; else store dtb read ${dtb_mem_addr}; run boot_start;fi;fi;fi;
EOF

# Compile the autostart script to a usable u-boot format:
cd /run/media/someuser/boot/
mkimage -A arm -O linux -T script -C none -d /tmp/s905_autoscript_new.txt s905_autoscript

Updated by Kamikaze over 1 year ago ยท 6 revisions