Quantcast
Channel: Linux Device Hacking
Viewing all articles
Browse latest Browse all 3189

HowTo: Install chroot and cross compile kernel/packages for armel (no replies)

$
0
0
(still under construction, will continue later)

First remark is that cross compiling is quite east. Thus, native compilation on ARM devices is a waste of time (you need ca. 2.5h on ARM to build openssl vs. 5-10min on modern desktop using single thread!).

Second remark is that compilation always creates a mess. You need to install sources, compiler, libraries, devel packages and so on. Even if you try to delete unneeded things afterwards then there are always some remainings. So, it is always a good idea to separate the host side os from the build environment by creating chroot (a linux inside of another linux). After compilation you may simply delete the chroot directory.
In case of cross compilation you actually create a mixture of packages from different architectures (host and target). I would not even consider doing this without chroot cage.

Third remark is that googling about cross building on debian is a bit confusing. It is because in debian there are few different ways to cross-build a packages which offer different level of automation and separation between host side os and chroot environment. Choose one and stick with it! If you use different tutorials make sure that all are based on the same scenario.
I decided to keep everything in chroot (actually this is the only solution for me since I’m not a debian user).

1. Creating debian chroot.

First step is to create base chroot directory. If you distro has a debootstrap (it does not have to be debian) then it is quite simple. Run the following

# download packages:
debootstrap --arch amd64 --foreign --variant=minbase jessie /the/chroot/directory http://ftp.us.debian.org/debian/
# enter chroot:
chroot /the/chroot/directory /bin/bash -l
# install packages:
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C /debootstrap/debootstrap --second-stage
# some packages need following directory:
mkdir /root/tmp
# leave chroot:
exit


Done! You have a minimal jessie debian in the directory /the/chroot/directory. The thing you need to remember is that some programs need the access to pseudo file systems (proc, dev, sys..). To mount it do the following:

cd /the/chroot/directory
for DIR in dev dev/pts proc sys
  do
    mount -o bind /$DIR $DIR
  done


The second step is to install packages needed for cross compiling. Edit the file /the/chroot/directory/etc/apt/sources.list. Make sure that pseudo file system are mounted and enter the chroot. Add armel architecture:

apt-get update
dpkg --add-architecture armel


If you use jessie then some packages need to be loaded from the embedian repository. Thus you need to add appropriate repository and archive key:

echo deb http://emdebian.org/tools/debian/ jessie main >> /etc/apt/sources.list
apt-get install curl
curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
apt-get update


In case of stretch it may be necessary to put "deb [arch=amd64,armel]" at the beginning of the appropriate line in the sources.list.

Now install the packages used for armel cross building:

apt-get install gcc-arm-linux-gnueabi dpkg-dev libc6:armel libncurses5-dev libssl-dev bc debhelper

Done!
Actually when I started to google about debian chroot I expected to find tar balls ready to unpack and use. I was quite disappointed because I did not find any. So, if your distro does not have debootstrap simply download the once prepared by me:
jessie-clean.amd.txz (28MB)
jessie-cross-armel.amd64.txz (102MB)
stretch-clean.amd64.txz (32MB)
stretch-cross-armel.amd64.txz (188MB)


2. Cross build a package

3. Cross compile the linux kernel

to be continued...

Viewing all articles
Browse latest Browse all 3189

Trending Articles