Building armv7h packages on a x86 system

From ParabolaWiki
Jump to: navigation, search

How to build armv7h packages on a x86 system. This article focuses on configuration of package building tools on a x86_64 or i686 system.

1 Libretools

libretools added support for building armv7h packages on x86 systems. It will take care of most of the details that go into making and accessing the chroot for you. If you are going to be building a lot of packages for the Parabola project you are advised to use this method.

First, install binfmt-qemu-static, which is suggested by libretools as an optional dependency.

 # pacman -S binfmt-qemu-static
Note: You cannot use the dynamically linked qemu because the host libraries will not be accessible from inside the chroot.

If using Systemd, enable and start the service systemd-binfmt.service.

 # systemctl enable --now systemd-binfmt.service

And in the case of OpenRC, do the same with binfmt. This is commonly already done.

 # rc-update add binfmt boot && service binfmt start

Before we download armv7h packages some extra signing keys must be trusted. When possible, Parabola leverages free packages that originally came from Arch ARM.

First make sure the pacman keyring has been initialized:

# pacman-key --init

Import, local-sign and install the archlinuxarm keyring in steps. That will get trust bootstraped without ever disabling signature verification in pacman.conf:

# pacman -U https://www.parabola.nu/packages/core/any/archlinuxarm-keyring/download/
# pacman-key --lsign-key builder@archlinuxarm.org
# pacman -U https://www.parabola.nu/packages/core/any/archlinuxarm-keyring/download/
Note: In case those URLs are unavailable, use any other up-to-date mirror. Use the most recent package versions, for example:
# pacman -U https://repo.parabola.nu/core/os/armv7h/archlinuxarm-keyring-20140119-1-any.pkg.tar.xz
# pacman-key --lsign-key builder@archlinuxarm.org
# pacman -U https://repo.parabola.nu/core/os/armv7h/archlinuxarm-keyring-20140119-1-any.pkg.tar.xz


Then follow the package maintainer guide, passing -A armv7h at the librechroot make step to create an armv7h chroot. You are done!

2 QEMU and/or Proot

If you don't feel like setting up an environment for libretools, what follows are two similar methods for using QEMU directly to emulate an ARM machine running on an armv7h chroot directory. The first one uses the faster binfmt-qemu-static, like #libretools above; while the second one goes through proot to make use of the same binfmt-qemu trick that allows non-native binaries to be associated with an emulator depending on their format. In all cases, this is akin to how shebangs have traditionally been used to pass scripts to the appropriate interpreter without the user having to specify it. Either way, you must first have an armv7h chroot directory:

2.1 Create Parabola image

Follow ARM_Installation_Guide#Create_Parabola_installation_image

2.2 Static QEMU (option 1)

To be able to chroot into a target file system without proot, the qemu emulator for the target CPU needs to be accessible from inside the chroot jail.

Install binfmt-qemu-static as described at the beginning of the #Libretools section:

 # pacman -S binfmt-qemu-static
 # systemctl enable --now systemd-binfmt.service

Next, copy the emulator for the target architecture to the path registered by binfmt-support. You need to do the following, substituting parabola-arm-workdir/mnt/ for whatever your armv7h image root folder happens to be called:

 # cp -a /usr/bin/qemu-arm-static parabola-arm-workdir/mnt/usr/bin

Prepare and enter to the chroot:

 # mount -o rbind /dev parabola-arm-workdir/mnt/dev
 # mount -o bind /sys parabola-arm-workdir/mnt/sys
 # mount -o bind /tmp parabola-arm-workdir/mnt/tmp
 # mount -t proc none parabola-arm-workdir/mnt/proc
 # rm parabola-arm-workdir/mnt/etc/resolv.conf
 # cp -a /etc/resolv.conf parabola-arm-workdir/mnt/etc
 # mkdir parabola-arm-workdir/mnt/rootfs
 # mount -o bind / parabola-arm-workdir/mnt/rootfs
 # chroot parabola-arm-workdir/mnt/ /bin/bash
 # mount -o bind /rootfs/${PATH TO parabola-arm-workdir/mnt} /

2.3 PRoot (option 2)

PRoot is a user-space implementation of chroot, mount --bind, and binfmt_misc. This means that users don't need any privileges or setup to do things like using an arbitrary directory as the new root filesystem, making files accessible somewhere else in the filesystem hierarchy, or executing programs built for another CPU architecture transparently through QEMU user-mode. Also, developers can use PRoot as a generic GNU/Linux process instrumentation engine thanks to its extension mechanism, see CARE for an example. Technically PRoot relies on ptrace, an unprivileged system-call available in every Linux kernel.

To install, you run:

# pacman -S proot

Install qemu-arch-extra:

# pacman -S qemu-arch-extra

Finally prepare and enter to the chroot, substituting parabola-arm-workdir/mnt/ for whatever your armv7h image root folder happens to be called:

 # mount -o rbind /dev parabola-arm-workdir/mnt/dev
 # mount -o bind /sys parabola-arm-workdir/mnt/sys
 # mount -o bind /tmp parabola-arm-workdir/mnt/tmp
 # mount -t proc none parabola-arm-workdir/mnt/proc
 # rm parabola-arm-workdir/mnt/etc/resolv.conf
 # cp -a /etc/resolv.conf parabola-arm-workdir/mnt/etc
 # cd /mnt
 # proot -0 -q /usr/bin/qemu-arm -r parabola-arm-workdir/mnt/

2.4 Configuring chroot

2.4.1 Initialize keyring

# pacman-key --init
# pacman-key --populate archlinux
# pacman-key --populate archlinuxarm
# pacman-key --populate parabola
Note: This step can take quite a while, be patient. (see Pacman-Key)

2.4.2 Generating locales

Before a locale can be enabled on the system, it has to be generated. The current generated/available locales can be viewed with:

$ locale -a

The locales that can be generated are listed in the /etc/locale.gen file: their names are defined using the format [language][_TERRITORY][.CODESET][@modifier]. To generate a locale, first uncomment the corresponding line in the file (or comment to remove); when doing this, also consider localizations needed by other users on the system and specific variables. For example, for American-English uncomment en_US.UTF-8 UTF-8. When done, save the file and generate the uncommented locale(s) by executing:

# locale-gen
Note: locale-gen also runs with every update of glibc.

2.4.3 Add a user

Finally, add a normal user (eg. username)

# useradd -m username
Note: It will be needed to build packages with makepkg command

2.5 Build package

2.5.1 Makepkg configuration

Refer to https://wiki.archlinux.org/index.php/Makepkg#Configuration.

2.5.2 Build package

Refer to https://wiki.archlinux.org/index.php/Makepkg#Usage.

2.6 Troubleshooting

2.6.1 Pacman and certificates

When trying to use pacman, if you see errors like:

 error: failed retrieving file '$PACKAGE' from $MIRROR : error setting certificate verify locations:
   CAfile: /etc/ssl/certs/ca-certificates.crt
   CApath: none
 warning: failed to retrieve some files
 error: failed to commit transaction (download library error)
 Errors occurred, no packages were upgraded.

Try copying the needed certificates from your real machine:

 # sudo cp -a /etc/ssl/certs/ca-certificates.crt /mnt/chroot-armv7h/etc/ssl/certs/
 # sudo cp -a /etc/ca-certificates/extracted/tls-ca-bundle.pem /mnt/chroot-armv7h/etc/ca-certificates/extracted/

That or switch to an HTTP (not HTTPS) mirror in /etc/pacman.d/mirrorlist.

3 Cross-compiler

This article or section is out of date.
Please help improve the wiki by updating the article and correcting mistakes.

See cross compiler.