Simple way to setup an arm chroot for building packages for your arm devices. This is an alternative to cross-compiling where you are limited to only linking against the libs in your toolchain.
You can store the chroot wherever you like. I choose to store it in a disk-image which I mount to my filesystem.
First create a raw disk.
$ dd of=archlinuxarm.img bs=1 seek=4G count=0
Make a ext4
filesystem of the whole disk-image
$ mkfs.ext4 -F archlinuxarm.img
Mount the disk-image somewhere
$ mkdir arm-chroot
# mount archlinuxarm.img arm-chroot
Get the arm root-fs you want to use and copy it to the chroot folder. I use the sun7i archlinuxarm root-fs (same as I have on my Cubietruck).
$ wget http://archlinuxarm.org/os/ArchLinuxARM-sun7i-latest.tar.gz
# tar -xf ArchLinuxArm-sun7i-latest.tar.gz -C arm-chroot
You can use qemu-user-static
to interpret the ARM instructions in the chroot
[1]. Get it from AUR if you are on Archlinux.
Copy the qemu-arm-static
binary to the chroot.
# cp /usr/bin/qemu-arm-static arm-chroot/usr/bin
Register the qemu-arm-static
as an ARM interpreter in the kernel (using
binfmt_misc
kernel module (package binfmt-qemu-static)) [1].
# echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
I have made a tool to make this easier, available here.
Finally bind {/proc,/dev,/dev/pts,/sys}
and chroot into the chroot.
# mount -t proc /proc arm-chroot/proc
# mount -o bind /dev arm-chroot/dev
# mount -o bind /dev/pts arm-chroot/dev/pts
# mount -o bind /sys arm-chroot/sys
# chroot arm-chroot /bin/bash
When in the chroot check that it is working
[chroot]# uname -a
Linux saturn 3.14.6-1-ARCH #1 SMP PREEMPT Sun Jun 8 10:08:38 CEST 2014 armv7l GNU/Linux
Depending on the rootfs you used you might want to set the nameserver
to
something like 8.8.8.8
in /ect/resolv.conf
in order to lookup services by
domainname (or copy the /etc/resolv.conf
from your host system).
When you are done, exit the chroot and unmount everything
[chroot]# exit
# umount arm-chroot/{sys,proc,dev/pts,dev}
# umount arm-chroot