Building #ARM #Raspbian packages on your #Intel PC

If you are a maintainer of a software project as I am, you probably spend a lot of time testing and deploying code. The more platforms you add the harder this gets and at some point you need to think carefully what you can do to minimize manual work.

I build things for Ubuntu/Debian/Raspian and Windows. In the beginning a lot of the deployment here was done on each platform. Hours spent on this for each release. Frustrating. I decided to do some scripts that would make it possible to do the first tree automatically. Saving time if I could get it to work.

I found Stein Magnus Jodal‘s excellent article Building ARM Debian packages with pbuilder and his the only one that should take credit for the things I describe here. I am just a copy cat in this case, well more or less, just adding some vital things.

I had no major problem to get buildings for Ubuntu and Debian to work with pbuilder following Stein Magnis Jodal’s document. The ARM builds was another thing. What I got was this

...
 qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x60184bcc
 qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x600019f9
...

qemu (or rather pbuilder-satisfydepends) fails when checking dependencies. After a long struggle I found that replacing pbuilder-satisfydepends with pbuilder-satisfydepends-apt was a solution to this problem.

I repeat the steps from Stein Magnis Jodal’s document here with my changes and updates and comments to get things working. Again credit is to Stein Magnis Jodal.

Setup pbuilder environment

Add a file .pbuilderrc to your root acount with the following content

!/bin/sh
 set -e
 if [ "$OS" == "debian" ]; then
     MIRRORSITE="http://ftp.se.debian.org/debian/"
     COMPONENTS="main contrib non-free"
     DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}"
         "--keyring=/usr/share/keyrings/debian-archive-keyring.gpg")
     : ${DIST:="stretch"}
     : ${ARCH:="amd64"}
     if [ "$DIST" == "jessie" ]; then
         #EXTRAPACKAGES="$EXTRAPACKAGES debian-backports-keyring"
         OTHERMIRROR="$OTHERMIRROR | deb $MIRRORSITE jessie-backports $COMPONENTS"
     fi
 elif [ "$OS" == "raspbian" ]; then
     MIRRORSITE="http://ftp.acc.umu.se/mirror/raspbian/raspbian/"
     COMPONENTS="main contrib non-free"
     PBUILDERSATISFYDEPENDSCMD="/usr/lib/pbuilder/pbuilder-satisfydepends-apt"
     DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}"
         "--keyring=/usr/share/keyrings/raspbian-archive-keyring.gpg")
     : ${DIST:="stretch"}
     : ${ARCH:="armhf"}
 elif [ "$OS" == "ubuntu" ]; then
     MIRRORSITE="http://se.archive.ubuntu.com/ubuntu/"
     COMPONENTS="main restricted universe multiverse"
     DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}"
         "--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg")
 else
     echo "Unknown OS: $OS"
     exit 1
 fi
 if [ "$DIST" == "" ]; then
     echo "DIST is not set"
     exit 1
 fi

Note the PBUILDERSATISFYDEPENDSCMD under the Raspbian section.

Now pbuilder will require three environment variables (in upper case) for it’s use

OS

The os you build for.It can be set to ubuntu, debian or raspbian

ARCH

The arcitecture you are builing for. It can be any of amd64, i386, armel, or armhf. Yes som eother supported arcitecure also of course.

DIST

Distribution of the os. For Debian/Raspbian buster, stretch, jessie. For Ubuntu eoan, disco, bionic, xenial, trusty. Well others shoudl work to.

If you are on a PC qemu-debootstrap is used for the ARM builds. So you have to install it with

sudo apt install pbuilder qemu-user-static

We also need the keyrings. For Ubuntu and Debian install them with

sudo apt install ubuntu-keyring debian-archive-keyring

If that for some reason does not work you can fetch the keyring fro Debian at https://packages.debian.org/sid/all/ubuntu-keyring/download and for Ubuntu keyring can be fetched here https://launchpad.net/ubuntu/+source/ubuntu-keyring

The keyring for Raspbian you can get here

 wget http://archive.raspbian.org/raspbian/pool/main/r/raspbian-archive-keyring/raspbian-archive-keyring_20120528.2_all.deb  
sudo dpkg -i raspbian-archive-keyring_20120528.2_all.deb

Now you need to build the chroots. You do this with steps like

sudo mkdir -p /var/cache/pbuilder/debian-stretch-amd64/aptcache/  
sudo OS=debian DIST=stretch ARCH=amd64 pbuilder --create

Replace OS/DIST/ARCH for your needs.

All you need now is the Debian source package for the code you want to work with. Go to the folder where it is and issue

sudo OS=debian DIST=stretch ARCH=armhf pbuilder build *.dsc

Replace OS/DIST/ARCH for your needs.

If all goes well you find the resulting package in

/var/cache/pbuilder//var/cache/pbuilder/debian-stretch-amd64/result/

replace ‘stretch’, ‘amd64’ and ‘debian’ as to you settings for DIST, ARCH and OS.

If you rather want you can go into an unpacked source folder and issu

tar xvf ../src-pkg.debian.tar.xz
tar xvf ../src-pkg.orig.tar.gz
sudo OS=debian DIST=stretch ARCH=amd64 pdebuild

Again replace OS/DIST/ARCH for your needs.

Thats it really.

I experienced situation when dh-autoreconf was not available in the chroot and when it did not get installed. This was for Ubuntu. If this happens you can instll it manually with

sudo OS=ubuntu DIST=xenial ARCH=amd64 pbuilder --login --save-after-exec 
apt install dh-autoreconf 
exit

Hope this can save some time for someone. And again thanks to Stein Magnis Jodal for his work.

Lazy section

Below is some code you can use if you think typing on a keyboard is tiresome…

Ubuntu

sudo mkdir -p /var/cache/pbuilder/ubuntu-trusty-amd64/aptcache/
sudo OS=ubuntu DIST=trusty ARCH=amd64 pbuilder --create
sudo OS=ubuntu DIST=trusty ARCH=amd64 pbuilder build vscpl2drv-automation1_1.1.0-1.dsc

sudo mkdir -p /var/cache/pbuilder/ubuntu-xenial-amd64/aptcache/
sudo OS=ubuntu DIST=xenial ARCH=amd64 pbuilder --create
sudo OS=ubuntu DIST=xenial ARCH=amd64 pbuilder build vscpl2drv-automation1_1.1.0-1.dsc

sudo mkdir -p /var/cache/pbuilder/ubuntu-bionic-amd64/aptcache/
sudo OS=ubuntu DIST=bionic ARCH=amd64 pbuilder --create
sudo OS=ubuntu DIST=bionic ARCH=amd64 pbuilder build vscpl2drv-automation1_1.1.0-1.dsc

sudo mkdir -p /var/cache/pbuilder/ubuntu-disco-amd64/aptcache/
sudo OS=ubuntu DIST=disco ARCH=amd64 pbuilder --create
sudo OS=ubuntu DIST=disco ARCH=amd64 pbuilder build vscpl2drv-automation1_1.1.0-1.dsc

sudo mkdir -p /var/cache/pbuilder/ubuntu-eoan-amd64/aptcache/
sudo OS=ubuntu DIST=eoan ARCH=amd64 pbuilder --create
sudo OS=ubuntu DIST=eoan ARCH=amd64 pbuilder build vscpl2drv-automation1_1.1.0-1.dsc

Debian

For the arm builds you may need to add the line

PBUILDERSATISFYDEPENDSCMD="/usr/lib/pbuilder/pbuilder-satisfydepends-apt"

to your pbuilder configuration (.pbuilderrc) file.

sudo mkdir -p /var/cache/pbuilder/raspbian-jessie-amd64/aptcache/
sudo OS=raspbian DIST=jessie ARCH=amd64 pbuilder --create
sudo OS=raspbian DIST=jessie ARCH=amd64 pbuilder build *.dsc

sudo mkdir -p /var/cache/pbuilder/raspbian-stretch-amd64/aptcache/
sudo OS=raspbian DIST=stretch ARCH=amd64 pbuilder --create
sudo OS=raspbian DIST=stretch ARCH=amd64 pbuilder build *.dsc

sudo mkdir -p /var/cache/pbuilder/raspbian-buster-amd64/aptcache/
sudo OS=raspbian DIST=buster ARCH=amd64 pbuilder --create
sudo OS=raspbian DIST=buster ARCH=amd64 pbuilder build *.dsc


sudo mkdir -p /var/cache/pbuilder/raspbian-jessie-i385/aptcache/
sudo OS=raspbian DIST=jessie ARCH=i385 pbuilder --create
sudo OS=raspbian DIST=jessie ARCH=i385 pbuilder build *.dsc

sudo mkdir -p /var/cache/pbuilder/raspbian-stretch-i385/aptcache/
sudo OS=raspbian DIST=stretch ARCH=i385 pbuilder --create
sudo OS=raspbian DIST=stretch ARCH=i385 pbuilder build *.dsc

sudo mkdir -p /var/cache/pbuilder/raspbian-buster-i385/aptcache/
sudo OS=raspbian DIST=buster ARCH=i385 pbuilder --create
sudo OS=raspbian DIST=buster ARCH=i385 pbuilder build *.dsc


sudo mkdir -p /var/cache/pbuilder/raspbian-jessie-armle/aptcache/
sudo OS=raspbian DIST=jessie ARCH=armle pbuilder --create
sudo OS=raspbian DIST=jessie ARCH=armle pbuilder build *.dsc

sudo mkdir -p /var/cache/pbuilder/raspbian-stretch-armle/aptcache/
sudo OS=raspbian DIST=stretch ARCH=armle pbuilder --create
sudo OS=raspbian DIST=stretch ARCH=armle pbuilder build *.dsc

sudo mkdir -p /var/cache/pbuilder/raspbian-buster-armle/aptcache/
sudo OS=raspbian DIST=buster ARCH=armle pbuilder --create
sudo OS=raspbian DIST=buster ARCH=armle pbuilder build *.dsc


sudo mkdir -p /var/cache/pbuilder/raspbian-jessie-armhf/aptcache/
sudo OS=raspbian DIST=jessie ARCH=armhf pbuilder --create
sudo OS=raspbian DIST=jessie ARCH=armhf pbuilder build *.dsc

sudo mkdir -p /var/cache/pbuilder/raspbian-stretch-armhf/aptcache/
sudo OS=raspbian DIST=stretch ARCH=armhf pbuilder --create
sudo OS=raspbian DIST=stretch ARCH=armhf pbuilder build *.dsc

sudo mkdir -p /var/cache/pbuilder/raspbian-buster-armhf/aptcache/
sudo OS=raspbian DIST=buster ARCH=armhf pbuilder --create
sudo OS=raspbian DIST=buster ARCH=armhf pbuilder build *.dsc

Raspbian

Use armle for Raspberry Pi 1

sudo mkdir -p /var/cache/pbuilder/raspbian-jessie-armhf/aptcache/
sudo OS=raspbian DIST=jessie ARCH=armhf pbuilder --create
sudo OS=raspbian DIST=jessie ARCH=armhf pbuilder build *.dsc

sudo mkdir -p /var/cache/pbuilder/raspbian-stretch-armhf/aptcache/
sudo OS=raspbian DIST=stretch ARCH=armhf pbuilder --create
sudo OS=raspbian DIST=stretch ARCH=armhf pbuilder build *.dsc

sudo mkdir -p /var/cache/pbuilder/raspbian-buster-armhf/aptcache/
sudo OS=raspbian DIST=buster ARCH=armhf pbuilder --create
sudo OS=raspbian DIST=buster ARCH=armhf pbuilder build *.dsc

This info is current when this is written but may not be when you read it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.