e42.uk Circle Device

 

Quick Reference

Gentoo on Raspberry Pi

Gentoo, being a source distribution, is not the best fit for a Raspberry Pi. Compiling all the packages takes a lot of time and is not the best for your SD Card. To counter this problem we can use distcc and crossdev but I would prefer to use crossdev and the binary packages option for my Pi.

Lets get started... I am going to create packages for nano, it is a relatively simple but has a few dependencies.

Setup crossdev and Custom Repository

Firsly emerge sys-devel/crossdev and create the required directories and files.

emerge sys-devel/crossdev
mkdir -p /usr/local/portage/crossdev/{profiles,metadata}
echo 'crossdev' > /usr/local/portage/crossdev/profiles/repo_name
echo 'masters = gentoo' > /usr/local/portage/crossdev/metadata/layout.conf
chown -R portage:portage /usr/local/portage/crossdev

Tell portage to use the gentoo repository and as the fallback and crossdev will create ebuilds in /usr/local/portage/crossdev for the generated packages. Below is /etc/portage/repos.conf/crossdev.conf (if you don't have /etc/portage/repos.conf/ you should create it):

[crossdev]
priority = 9999
masters = gentoo
auto-sync = no
location = /usr/local/portage/crossdev

Initialise the repository:

crossdev -t armv7a-hardfloat-linux-gnueabi --stable --init-target -oO /usr/local/portage/crossdev

Change the use flags to disable some use flags (I am not sure if this is required...):

echo "cross-armv7a-hardfloat-linux-gnueabi/gcc -sanitize -vtv" >> /etc/portage/package.use/crossdev

Create the toolchain:

crossdev -t armv7a-hardfloat-linux-gnueabi --stable -oO /usr/local/portage/crossdev

Cool! with that you should be able to compile a very simple hello world C programme with your ARM cross compiler. If you cannot then you should get this working before continuing. See Appendix A for how to do this.

Configure the make.profile and make.conf

Check in /usr/armv7a-hardfloat-linux-gnueabi/etc/portage/make.conf and if I were you I would put buildpkg in your features line, it is probably already there, mine looks like this:

FEATURES="-collision-protect sandbox buildpkg noman noinfo nodoc"

You can build packages on a per emerge basis by specifying it at emerge time with --buildpkg but you might forget ;-).

These steps set the correct profile, by default you are probably using the embedded profile which will not work to emerge stuff for your Pi:

cd /usr/armv7a-hardfloat-linux-gnueabi
ln -s /usr/portage/profiles/default/linux/arm/13.0/armv7a/ etc/portage/make.profile

Emerge nano

Now the fun part emerging nano:

armv7a-hardfloat-linux-gnueabi-emerge app-editors/nano

This on my system portage pulled in 5 packages:

sys-libs/zlib-1.2.11
sys-libs/ncurses-6.0-r1:0/6
virtual/libintl-0-r2
sys-apps/file-5.30
app-editors/nano-2.7.5

This may take some time, you can always make it faster by changing the MAKEOPTS="-j4" in /usr/armv7a-hardfloat-linux-gnueabi/etc/portage/make.conf depending on your system.

Once complete the emerge should have installed executables and generated some binary packages in the packages directory:

/usr/armv7a-hardfloat-linux-gnueabi/packages/

Now you can install them on your Pi.

Installing a Binary Package

Now it is time to get the package on your Raspberry Pi. For this I would recommend configuring a binary package host.

I plan on configuring a public one some time soon hosted on this server to use it please look at my binary package host page. Configuring a binary package host is a little out of scope please see the Gentoo Wiki.

To get the packages on your Pi copy them from the armv7a-hardfloat-linux-gnueabi/packages/ directory to the /usr/portage/packages/ directory (or wherever you configured your PKGDIR). The structure is important!

Now you can try and emerge nano, make sure your portage tree is at least as up to date as the tree on the generating machine.

emerge -pv --usepkgonly app-editors/nano

The output looks like this (with pretty colours):

[binary     U ~] app-editors/nano-2.7.5::gentoo [2.5.3::gentoo] USE="magic ncurses nls spell unicode -debug -justify -minimal -slang -static" 0 KiB

The only thing I should say now is be careful of USE flags and KEYWORDS. Of course remove the -pv to actually install the package.

nano --version
GNU nano, version 2.5.3
(C) 1999..2016 Free Software Foundation, Inc.
Email: nano@nano-editor.org    Web: http://www.nano-editor.org/
Compiled options: --disable-justify --disable-wrapping-as-root --enable-utf8

After emerge:

GNU nano, version 2.7.5
(C) 1999..2016 Free Software Foundation, Inc.
(C) 2014..2017 the contributors to nano
Email: nano@nano-editor.org    Web: https://nano-editor.org/
Compiled options: --disable-justify --disable-wrapping-as-root --enable-utf8

I bet you were surprised weren't you!?

Appendix A

Writing and Compiling a simple programme for Raspberry Pi 2. Create main.c with the following content.

#include <stdio.h>

int main(int argc, char * argv[]) {
    fprintf(stdout, "Hello World!");
}

Then compile it like this:

armv7a-hardfloat-linux-gnueabi-gcc -o main main.c

And try to execute the resulting file on your Raspberry Pi.

References

Quick Links: Techie Stuff | General | Personal | Quick Reference