User:Kitty/RPi3 Cross Binhost Guide

This guide is designed to help you with creating a local binhost for cross compiling packages to your Raspberry Pi. It assumes that you are using a Raspberry Pi 3, in 64 bit mode, with systemd. It should also prove helpful with other targets, but you will have to change a couple things here and there.

WARNING: The author(s) make no warranty or claim whatsoever that this information is correct, proper, or safe to use. It is intended only as a reference.

= Binhost Setup = We assume that you already have a live copy of Gentoo installed on a PC, most likely x86_64.

Set Up Crossdev
If you haven't yet, set up a crossdev toolchain on your binhost for the target platform.

Set Your Profile
On your binhost, set the profile to match the profile that you wish to use on your Raspberry Pi.

Configure make.conf
On your binhost, edit  and copy over your ,  ,  , and   lines, as well as anything else (especially   variables) that might affect package selection and compilation. Do NOT remove any of the other variables that are already in this file, and do NOT directly copy the file from your Raspberry Pi.

Also, make sure that your  is set correctly for efficient compiles on your binhost.

Install Qemu Userland
Optionally, you may install Qemu Userland to help facilitate the compilation of some packages which need to run native code. This will help some packages avoid cross-compile failures, and shouldn't bother anything else in your system. This requires that your kernel have  enabled.

Create/edit a package.use file to instruct portage to compile qemu for the target architecture.

Compile and install the package to the binhost.

Create a wrapper that will set the emulated CPU, and instruct qemu to the location of the linker libraries.

Compile the wrapper.

Move the wrapper into place.

Add a file to  instructing aarch64 binaries to be executed with qemu.

Restart the  service to make your changes take effect.

Bootstrapping your Binhost
One of the hardest parts of this guide is going to be getting your binhost crossdev environment bootstrapped, and I'm not going to go into too much detail because the actual steps can vary. You're going to need a good bit of knowledge on how to resolve dependencies, and not everything is going to compile.

A good place to start would be:

... and then start fixing whatever is broken. Certain packages will refuse to cross-compile. See below for more details.

= Raspberry Pi Setup = Firstly, you will want to get a running install of Gentoo on your Raspberry Pi. I have personally used Sakaki-'s RPi3 Gentoo Image. You could also follow the Raspberry_Pi_3_64_bit_Install Guide here on the wiki.

Create SSH keys
For the simplest setup, using SSH to transfer the binary files would seem to be the easiest. If you want to get a little more involved, or have a little more security for your binhost, you may opt for other binary hosting options as found in the Binary_package_guide.

On your Raspberry Pi, create SSH keys for root.

After this command has completed, copy the contents of  to   on your binhost. The user on your binhost should be non-root, for security purposes.

Target make.conf
On your Raspberry Pi, open  and make sure that it contains the following two lines:

Change the  line, replacing USERNAME with the username you used while setting up SSH keys, and replacing BINHOSTIP with the IP address of your binhost. If a previous  line exists, it should be removed.

= Using Your Binhost = Presumably, after the setup is completed, you should be able to run any  operation on your binhost first, using , and then running the same operation on your target. After computing dependencies, your target should show a vast majority of the packages as being binaries.

= Problems = Many packages will simply refuse to cross-compile. Thankfully, in what would seem to be the majority of cases, only small packages are the problem.

If you have a package that will not cross-compile, either  it on the host with the   option, or make a binary package from the already installed package using. Then, copy the package from  to the matching spot in   and install it using:

By default,  will restrict access permissions to the packages it builds, presumably because of security concerns in building packages from existing files. In order to facilitate easier copying of package files when using, the following line may be added to   on your Raspberry Pi: