Cross-build Debian Packages for mips64el Architecture

In this post, I will show how to cross-build an example Debian package, sl, for mips64el architecture on a amd64 host machine.

1 Install Prerequisites

On the host machine, install essential build tools for both amd64 host and mips64el target.

1
$ sudo apt install crossbuild-essential-mips64el build-essential

2 Configure Signing Key

TBD

3 Configure deb-src

By default, Debian may not include working deb-src sources in sources.list. In order to download the source code for a package, you need to first manually add (or uncomment) deb-srcs.

1
$ sudo apt edit-sources  # edit sources

You will see a text editor. If there are commented deb-srcs, uncomment them. If there are no deb-srcs at all, copy the deb lines, duplicate them, and change debs to deb-srcs in the duplicated lines. The following configuration is a valid example sources.list with deb-srcs.

1
2
3
4
5
6
7
8
deb http://mirrors.tuna.tsinghua.edu.cn/debian buster main
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian buster main

deb http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main

deb http://mirrors.tuna.tsinghua.edu.cn/debian buster-updates main
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian buster-updates main

You then need to update list of packages on the host.

1
$ sudo apt update

4 Prepare the Source Code and Build Dependencies for the Target Package

1
2
3
4
$ sudo dpkg --add-architecture mips64el # add mips64el architecture for build deps
$ sudo apt update # update list of packages
$ apt source sl # fetch the source code of sl
$ sudo apt-get build-dep -a mips64el sl # install build deps for sl

To build other packages, just replace sl with any other package name.

5 Build!

1
2
3
$ cd sl-5.02
$ CONFIG_SITE=/etc/dpkg-cross/cross-config.mips64el DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -a mips64el -Pcross,nocheck
$ cd ..

If you don’t want to sign the package, add -us -uc flags after dpkg-buildpackage.


Building for Loongson 2K1000 processor?

  • Make sure your Loongson GCC toolchain is properly set up (see this post),
  • Run source /opt/mips-loongson-gcc4.9-linux-gnu/gs264e-setup.sh to set up relevant environment variables,
  • Add -t mips-linux-gnu option to dpkg-buildpackage above so it will use the Loongson toolchain instead of the general one.

Then we get a nice sl_5.02-1_mips64el.deb package.

6 Upload the Package to the Target Machine and Run

1
2
3
4
$ scp sl_5.02-1_mips64el.deb 192.168.1.149: # copy the package to the target machine 192.168.1.149
$ ssh 192.168.1.149
> sudo dpkg -i sl_5.02-1_mips64el.deb # install the package on the target machine
> sl

image-20200528153816715

Voilà! You have a working sl running on mips64el target.

Reference

https://wiki.debian.org/CrossCompiling