Setting up an sh4 sbuild environment based on qemu-sh4

NOTE: Due to a bug in jessie's qemu, it doesn't work on 64-bit hosts. Use unstable/stretch or qemu-user-static:i386.

The whole sbuild setup is rather simple and deviates only slightly from a regular sbuild setup on a native architecture. The only additions are installing support packages for qemu and copying the binary qemu-sh4-static into /usr/bin of the chroot:

root@jessie32:~> apt-get install sbuild qemu-user-static binfmt-support schroot devscripts debian-ports-archive-keyring
root@jessie32:/srv/chroots> cd /srv/chroots
root@jessie32:/srv/chroots> debootstrap --variant=buildd --foreign --arch=sh4 --include=debian-ports-archive-keyring unstable sid-sh4-sbuild
root@jessie32:/srv/chroots> mkdir ~/.gnupg
root@jessie32:/srv/chroots> sbuild-update --keygen
root@jessie32:/srv/chroots> cat /etc/schroot/chroot.d/sid-sh4-sbuild
description=Debian sid chroot for sh4
root@jessie32:/srv/chroots> adduser glaubitz sbuild
root@jessie32:/srv/chroots> cp -av /usr/bin/qemu-sh4-static /srv/chroots/sid-sh4-sbuild/usr/bin
root@jessie32:/srv/chroots> chroot sid-sh4-sbuild
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
I have no name!@jessie32:/# ./debootstrap/debootstrap --second-stage

After that, we just need to configure apt in the chroot:

root@jessie32:/# cat /etc/apt/sources.list
# binary default
deb unstable main
deb unreleased main
deb unstable main

# source
deb-src unstable main
deb-src buildd-unstable main
#deb-src experimental main
#deb-src buildd-experimental main

# binary experimental
#deb experimental main
#deb buildd-experimental main

# source experimental
#deb-src experimental main

After that, it should be possible to build packages for sh4 for any user in the sbuild group:

glaubitz@jessie32:~> mkdir sh4
glaubitz@jessie32:~> cd sh4
glaubitz@jessie32:~/sh4> dget -u
glaubitz@jessie32:~/sh4> sbuild --arch=sh4 --arch-all --source --force-orig-source -d sid xbill_2.1-8.dsc

In order to speed up the build process by disabling make check, set "nobench" and "nocheck" as DEB_BUILD_OPTIONS:

glaubitz@jessie32:~/sh4> export DEB_BUILD_OPTIONS="nobench nocheck" ; sbuild --arch=sh4 --arch-all --source --force-orig-source -d sid xbill_2.1-8.dsc

Of course, you can just chroot into the sh4 chroot and run any application like you would do on a native system.


There are several minor issues with qemu-sh4 which currently need workarounds or patches.

fakeroot command gets stuck

During package builds, it was observed that the fakeroot command which is usually invoked during package build may get stuck when running fakeroot debian/rules clean or other commands. In order to workaround this issue, just set the name of the fakeroot binary to an empty string in /etc/sbuild/sbuild.conf on the qemu host:

# Type: STRING
# Path to fakeroot binary
$fakeroot = '';

Unsupported syscall: 186

Another issue with qemu-sh4 is the missing implementation of the sigaltstack syscall (see: which becomes apparent with the following qemu message when installing any python packages in the chroot:

qemu: Unsupported syscall: 186

The aforementioned qemu upstream bug report contains the necessary patch to enable sigaltstack in qemu-sh4.