User:NeddySeagoon/Pi3

Background
Its been 4 years since the Raspberry Pi B was launched' with 256Mb RAM and a single core, 700MHz, armv6j CPU.

Installing Gentoo was pretty much a matter of following the handbook and adding in cross distcc to speed things up.

The Pi3 is provided with 32 bit software. Its a four core armv7a CPU on the surface. The tried and tested install methods should still work.

If you just want to drive your Ferrari to the corner shop, that's well documented on this wiki

The article is about running Gentoo on the Pi 3 in 64 bit mode, as an armv8a. That's what the CPU is capable of. There is no handbook nor any stage files for that yet.

The Raspberry Pi 3 is a bit of a dog on the I/O front. The four USB ports and the Ethernet port are all on a singe USB2 interface from the CPU. That's unchanged is the last four years. That gives 400Bit/sec for everything connected there,

The new WiFi and Bluetooth are grafted onto the SD card interface, so they contend for the available bandwidth too.

Overview
As there is no stage files, the conventional chroot install is out of the question. There is nothing to chroot into. The workaround for that is to build some armv8a code on some other system in a process known as cross compiling.

Cross compiling is the process of building packages on one architecture, (the build host) that are intended to run an another architecture (the target). I will be building on amd64 for armv8a.

That's a little bit of an exaggeration. If your 64 bit cross compiled kernel can get as far as a console, you may get kernel error messages.

Serial Console
A 3.3v serial port adaptor is required. You will need a USB to serial port adaptor as PC serial ports if you have one, uses either +/- 5v or +/-12v, depending on the age of your PC. Either will destroy a Pi serial port and may be more.

A USB to 5v serial port adaptor will destroy something too, so do check.

Das U-Boot
The Raspberry Pi does not normally use a boot loader. The boot files are loaded by the firmware. However, the CPU needs to be at the correct privilege level when control is passed to the kernel, or the kernel won't run. Das U-Boot is loaded in the normal way. It then loads the kernel and passes control to it with the correct privilege level for the kernel to run.

We need a 64 bit arm8a Das U-Boot to get things started.

Kernel
To run 64 bit code we need a 64 bit armv8a kernel. Once the CPU is switched into 64 bit mode, before even Das U-Boot is loaded, the 32 bit kernel will not run.

Cross Compiled Userspace
Once the kernel runs successfully, it will try to run /sbin/init, or whatever init= points to.

Systemd users are on there own. This author does not use systemd and is not about to start while bringing up 64 bit Gentoo on a Raspberry Pi3.

We need a cross tool chain and a target root filesystem to put all the armv8a code into. Its a really bad idea to emerge armv8a code to your build host.

Getting Started
On your main Gentoo system. There are other parameters you can pass to crossdev too.

This will create a cross toolchain that builds things into /usr/aarch64-unknown-linux-gnu/ This is the target root.

Eventually, you copy this directory to / on your Pi SDCard.

Once crossdev has finished, you will have a /usr/aarch64-unknown-linux-gnu/etc/portage which corresponds to your build host /etc/portage. The difference being that /usr/aarch64-unknown-linux-gnu/etc/portage applies when cross compiling for aarch64-unknown-linux-gnu.

Any number of cross compilers con be installed. Practice on something more well proven before you try 64 bit Raspberry Pi.

Target configuration
This consists of setting up /usr/aarch64-armv8a-unknown-gnu/etc/portage by hand.

make.conf
Copy your mirror list from the build host and any of your favourite options.

Optimists can set VIDEO_CARDS= and so on. Just like the Gentoo on your build host, these settings can be changed as needed.

Note that the default settings will share the hosts portage tree and distfiles but keep binary packaces and ongoing builds separate from the build hosts. This means its permissible to build for several targets at the same time.

cross make.profile
The default generic make.profile symbolic link needs to be changed. The cross make.profile (by hand)

Or use another arm64 profile that's more to your liking. Don't use eselect profile.

Cross Building the Kernel
mkdir /usr/aarch64-unknown-linux-gnu/usr/src

This is the kernels normal home.

Cross Building Packages
Execute

This sets up some symlinks so that

uses emerge, with the cross toolchain to install armv8a packages into /usr/aarch64-unknown-linux-gnu

emerge-wrapper needs to run every time you open a new shell to cross compile in.

Random Warnings And Caveats
/usr/aarch64-unknown-linux-gnu/ is empty when you start to cross compile, unlike a stage3 install, where a working host chroot is provided. None of the code here will run on the build host.

In theory will cross compile the system set. It will have a good go but it will fail for a number of reasons. * To avoid circular dependencies the @system set is assumed to always be present. * Some build systems don't support cross compiling * arm64 is not well tested - don't even think of using ACCEPT_KEYWORDS=arm64 * expect to use the keyword ** on a number of packages

USE=-cxx aarch64-armv8-linux-gnueabi-emerge @system -uDNav almost works.

Missing deps - fix by hand

gcc - uses wrong linker /usr/lib/gcc/x86_64-pc-linux-gnu/5.3.0/../../../../x86_64-pc-linux-gnu/bin/ld sys-apps/util-linux fails configure: error: udev selected but libudev not found even when libudev built sys-devel/llvm needs dev-util/ninja which fails using x86_64 tools

groff

checking whether g++ accepts -g... yes checking that header files support C++... no configure: error: header files do not support C++

udev builds eudev fails.

@system is enough to boot ... but you need a 64 bit kernel too.

armv8a is not well tested - be prepared keyword things you want to try

Optional Additions to @system USE="-cxx -fortran" aarch64-armv8a-linux-gnueabi-emerge dcron metalog ntpd dhcpcd wpa_supplicant

USE="-cxx -fortran" aarch64-armv8a-linux-gnueabi-emerge sudo hexedit leafpad app-misc/screen orage eix genlop gentoolkit layman mirrorselect ufed mupdf wgetpaste strace fortune-mod-all alsa-utils x11-ssh-askpass acl iproute2 usbutils distcc dosfstools linux-firmware xorg-server xfce4-terminal xfwm4-themes thunar xfce4-meta xfce4-mixer xfce4-mount-plugin xfce4-taskmanager xfce4-verve-plugin Gets 301 packages to cross compile. Fails

libepoxy

graphite2 -- Check for working CXX compiler: /usr/bin/g++ -- Check for working CXX compiler: /usr/bin/g++ -- broken CMake Error at /usr/share/cmake/Modules/CMakeTestCXXCompiler.cmake:54 (message): The C++ compiler "/usr/bin/g++" is not able to compile a simple test program.

libical -- Check for working CXX compiler: /usr/bin/g++ -- Check for working CXX compiler: /usr/bin/g++ -- broken CMake Error at /usr/share/cmake/Modules/CMakeTestCXXCompiler.cmake:54 (message): The C++ compiler "/usr/bin/g++" is not able to compile a simple test program.

fortune-mod /bin/sh: line 6: ../util/strfile: cannot execute binary file: Exec format error

libgpg

gnome-icon-theme checking icon-naming-utils >= 0.8.7... no configure: error: icon-naming-utils >= 0.8.7 is required to build and install gnome-icon-theme

everything that needs C++

mupdf

perl I used the command:

aarch64-armv8a-linux-gnueabi-gcc -o try -march=armv8-a -O2 -pipe -fomit-frame-pointer -DOVR_DBL_DIG=14 -Wl,-O1 -Wl,--as-needed try.c -lpthread -lnsl -ldb -ldl -lm -lcrypt -lutil -lc ./try

and I got the following output:

/bin/sh: ./try: cannot execute binary file: Exec format error The program compiled OK, but exited with status 126.

dialog /usr/lib/gcc/x86_64-pc-linux-gnu/5.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/trace.o: Relocations in generic ELF (EM: 183) .libs/trace.o: error adding symbols: File in wrong format collect2: error: ld returned 1 exit status

screen configure: error: in `/usr/aarch64-armv8a-linux-gnueabi/tmp/portage/app-misc/screen-4.3.1-r1/work/screen-4.3.1': configure: error: cannot run test program while cross compiling See `config.log' for more details dbus-glib

Missing Dirs
mkdir dev home opt proc sys boot root in /usr/aarch64-unknown-linux-gnu/ as some of those dirs are needed to boot.


 * 1) 			 	 		 		

/dev/mmcblk0p1		/boot		vfat		noauto,noatime	1 2 /dev/mmcblk0p2		/		ext4		noatime		0 1
 * 1) NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.


 * 1) None of these ever
 * 2) /dev/cdrom		/mnt/cdrom	auto		noauto,ro	0 0
 * 3) /dev/fd0		/mnt/floppy	auto		noauto		0 0

mtab
Make /etc/mtab -> /proc/self/mounts in /usr/aarch64-unknown-linux-gnu/

/etc/inittab
s0:12345:respawn:/sbin/agetty -L 115200 ttyAMA0 vt340
 * 1) SERIAL CONSOLES


 * 1) Architecture specific features
 * f0:12345:respawn:/sbin/agetty 9600 ttyAMA0 vt100

Copy /usr/aarch64-unknown-linux-gnu/ to the root partition on your microSD card.

Configuring the system
Follow Configuring the system in the handbook. Adjust the paths given. Root is now.

Follow the handbook to set up services ... almost because you can't chroot in Populate

boot default  shutdown  sysinit

with symlinks in lieu of rc-update.

edit fstab.

Boot

https://www.raspberrypi.org/forums/viewtopic.php?f=72&t=137963 There is a config.txt entry to make the ARM start in 64-mode. arm_control=0x200

Kernel https://github.com/raspberrypi/linux/ rpi-4.1.y has been updated fo the Pi3 but only 32 bit mode.

Booting In 64 Bit Mode
Best test your serial console in 32 bit mode first. Its all you will have so you want to know it works You will need to add force_turbo=1 in config.txt to get the right baud rate.

Its 115200n1 for setting up minicom.

Create /proc /sys dev /home and /root in you new root fs

symlink /etc/mtab to /proc/self/mounts

Fix your /etc/fstab

/dev/mmcblk0p1         /boot           vfat            noauto,noatime  1 2 /dev/mmcblk0p2         /               ext4            noatime         0 1
 * 1) NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.

Fix /etc/inittab so you get a login prompt

s0:12345:respawn:/sbin/agetty -L 115200 ttyAMA0 vt100
 * 1) SERIAL CONSOLES

and don't forget to add a root password hash to /etc/shadow