Cross Compile

From Rockchip open source Document
Revision as of 17:31, 15 December 2017 by Jacob (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Application Cross Compile

To cross compile debian application, we need debian stretch os and setup multiarch enviroment.
The following wiki will introduce you two ways to do it.

 

Docker(Multiarch)


Docker is a open-source application container engin and we can use it to prepare a application cross compile environment.
To cross compile via docker, please refer to readme in docker-rockchip.

 

 

Chroot-ARM(QEMU)


Install qemu

apt-get install qemu-user-static

Download debian arm image

wget https://releases.linaro.org/debian/images/alip-armhf/17.02/linaro-jessie-alip-20161117-32.tar.gz
sudo tar -xpf *.tar.gz

Download below script  and name it to ch-mount.sh

#!/bin/bash
function mnt() {
    echo "MOUNTING"
    sudo mount -t proc /proc ${2}proc
    sudo mount -t sysfs /sys ${2}sys
    sudo mount -o bind /dev ${2}dev
    sudo mount --bind ${3} ${2}home/linaro/host

    sudo chroot   ${2}
}
function umnt() {
    echo "UNMOUNTING"
    sudo umount ${2}proc
    sudo umount ${2}sys
    sudo umount ${2}dev
    sudo umount ${2}home/linaro/host
}
if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
    mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
    umnt $1 $2
else
    echo ""
    echo "Either 1'st, 2'nd or both parameters were missing"
    echo ""
    echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
    echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
    echo ""
    echo "For example: ch-mount -m /media/sdcard/"
    echo ""
    echo 1st parameter : ${1}
    echo 2nd parameter : ${2}
fi

Copy qemu and network configure to rootfs

sudo cp -b /etc/resolv.conf binary/etc/resolv.conf
sudo cp /usr/bin/qemu-arm-static binary/usr/bin

Chroot to arm rootfs:

ch-mount.sh -m binary/ {THE DIRECTORY  YOU WANT TO ACCESS IN CHROOT}
# change to a normal user. passwd:linaro
su linaro 
# install env
sudo apt-get update
sudo apt-get install gcc
# start build
make, cmake ......
exit
# Don't forget to umount
ch-mount.sh -u binary/

 

Chroot-X86(MultiArch)


Build the chroot

sudo debootstrap --arch amd64 stretch ~/work/linaro-alip/cross-env  http://httpredir.debian.org/debian


To enter

sudo chroot ~/work/linaro-alip/cross-env


add the following repository to etc/apt/source.list

deb-src http://httpredir.debian.org/debian stretch main
deb http://emdebian.org/tools/debian/ stretch main


prepare Multiarch

dpkg --add-architecture armhf
apt-get update
apt-get install curl
curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
apt-get update
apt-get install  crossbuild-essential-armhf


get zlib source

wget http://www.zlib.net/zlib-1.2.8.tar.gz
tar -xvzf zlib-1.2.8.tar.gz
cd zlib-1.2.8


installing zlib's cross-dependencies

apt-get build-dep -a armhf zlib
or
apt-get install xxxx:armhf


configure the zlib library

CC=arm-linux-gnueabihf-gcc ./configure --prefix=/usr/


compile it

make


install it

mkdir out
make install DESTDIR=./out

Documents


https://wiki.debian.org/Multiarch/HOWTO
https://wiki.debian.org/sbuild
https://wiki.ubuntu.com/SimpleSbuild
https://wiki.linaro.org/Platform/DevPlatform/CrossCompile/UsingMultiArch
https://wiki.ubuntu.com/CrossBuilding
https://wiki.linaro.org/Platform/DevPlatform/CrossCompile/CrossBuilding
https://wiki.linaro.org/Platform/DevPlatform/CrossCompile/CrossbuildingQuickStart
http://comments.gmane.org/gmane.linux.embedded.yocto.general/15379
https://help.launchpad.net/Packaging/PPA
https://www.debian.org/devel/buildd/