Set Up Your Gentoo PC for Cross Compilation with crossdev - sakaki-/gentoo-on-b3 GitHub Wiki

Leverage the power of your PC as a cross-compilation tool for your B3!

Introduction

If you have a PC running Gentoo Linux, you can easily set it up for cross-compilation using the crossdev tool: it can build B3-compatible binaries much faster than the B3 itself can. For example, you can compile a kernel for your B3 in around 10 minutes on a modern PC.

It isn't hard to set up - all the steps you'll need are provided in this guide.

Installing the gentoo-b3 Repository

As of version >=2.2.16 of Portage, my custom Gentoo overlay for the B3 is best installed via the new plug-in sync system.

If you haven't already installed git(1), do so first:

gentoo_pc ~ # emerge --ask --verbose dev-vcs/git

Next, create a custom /etc/portage/repos.conf entry for the gentoo-b3 overlay, so Portage knows what to do. Make sure that /etc/portage/repos.conf exists, and is a directory. Then, fire up your favourite editor:

gentoo_pc ~ # nano -w /etc/portage/repos.conf/gentoo-b3.conf

and put the following text in the file:

[gentoo-b3]

# Gentoo overlay for the Excito B3 miniserver
# Maintainer: sakaki ([email protected])

location = /usr/local/portage/gentoo-b3
sync-type = git
sync-uri = https://github.com/sakaki-/gentoo-b3-overlay.git
priority = 50
auto-sync = yes

Then run:

gentoo_pc ~ # emaint sync --repo gentoo-b3

If you are running on the stable branch by default, allow ~<your-pc-arch> keyword files from this repository. To do so, make sure that /etc/portage/package.accept_keywords exists, and is a directory. Then issue: e.g.:

gentoo_pc ~ # echo '*/*::gentoo-b3 ~amd64' >> /etc/portage/package.accept_keywords/gentoo-b3-repo

You should now be able to install packages from this repository on your PC! Do so now, to install the buildkernel-b3 tool:

gentoo_pc ~ # emerge --ask --verbose sys-kernel/buildkernel-b3

Creating the Cross-Compilation Toolchain

If you haven't already done so, begin by emerging crossdev and dosfstools on your PC:

gentoo_pc ~ # emerge --ask --verbose sys-devel/crossdev sys-fs/dosfstools

Next, since in the absence of any specific instructions crossdev will use the lowest priority overlay it finds in /etc/portage/repos.conf/ as home (almost certainly not what you want!), we need to set up an overlay specifically for crossdev's use (this only needs to be done once). Begin by creating the file /etc/portage/repos.conf/crossdev.conf and editing it to contain the following text:

[crossdev]

location = /usr/local/portage-crossdev
priority = 10
masters = gentoo
auto-sync = no

Then to prepare /usr/local/portage-crossdev for use, issue:

gentoo_pc ~ # mkdir -pv /usr/local/portage-crossdev
gentoo_pc ~ # crossdev --stable -t armv5tel-softfloat-linux-gnueabi --init-target -oO /usr/local/portage-crossdev

If the above command issues warnings about missing attributes, these may safely be ignored; the --init-target action will fix them.

Next, if your main Portage tree does not use checksummed manifests (and for avoidance of doubt, this will not apply to most users, who should therefore skip this step), you'll also need to issue:

gentoo_pc ~ # echo 'thin-manifests = true' >> /usr/local/portage-crossdev/metadata/layout.conf

And that's the preparation done! Now, we can use crossdev to build a cross-toolchain for our target architecture, using the 'stable branch' tools (i.e., non-bleeding-edge versions of gcc etc.). Issue:

gentoo_pc ~ # crossdev --stable -t armv5tel-softfloat-linux-gnueabi -oO /usr/local/portage-crossdev

This may take a little time to run. Once it completes, congratulations, you have a shiny new cross-compilation toolchain on your PC! There's just one last step: ensure that you have an appropriate profile in place in your cross-environment. To do this, issue:

gentoo_pc ~ # cd /usr/armv5tel-softfloat-linux-gnueabi/etc/portage
gentoo_pc portage # rm -f make.profile
gentoo_pc portage # ln -s /usr/portage/profiles/default/linux/arm/17.0/armv5te make.profile

and you're done!

Next Steps

Now that you have a toolchain, you can make use of it to:

  • compile a B3 kernel directly on your PC (see this guide); and
  • set up distcc so that your PC can act as a distributed compilation server for your B3 (see this guide).