User:Vanjo9800/Raspberry Pi 3 - 64-bit Gentoo

Do you really need the 64-bit Gentoo?
The first question you should ask yourself before trying anything is whether you need that 64-bit OS on an ARM processor with just 1GB of RAM. As a whole, the 64-bit operating system is a good thing because it can work better with long numbers. The reason for that are the 64-bit pointers. Some problems use such numbers and the 64-bit Gentoo will speed up their work. However, there is a big drawback. These 64-bit pointers require RAM memory. While normal PC's have around 2 or even more than 4, the Raspberry Pi 3 has only 1 GB, so sometimes the RAM is filled with the pointers and the Pi goes out of RAM. In order, to avoid the RAM to be filled, the processor should do less tasks simultaneously which lowers performance. Up to now I cannot give you a proper benchmark, but I would try to give you ASAP. I put 64-bit experimenting which one would prove better. If you are like me, you can freely continue the rest. If you are going to use that somewhere important, think about whether do you really need this.

SD card setup
For a start, the partitions of the SD card should be configured properly. The SD card must have two partitions: one boot partition and one root partition. The boot partition should have a FAT32 file system while the user can choose between multiple file systems for the root partition. In my configuration, I use EXT4 file system for the root partition. Here is how you can create your partitions:

where sdX is the SD card how is it displayed from lsblk.

Then just do the following: Type o. This will clear out any partitions on the drive. Type p to list partitions. There should be no partitions left. Type n, then p for primary, 1 for the first partition on the drive, press ENTER to accept the default first sector, then type +100M for the last sector. Type t, then c to set the first partition to type W95 FAT32 (LBA). Type n, then p for primary, 2 for the second partition on the drive, and then press ENTER twice to accept the default first and last sector. Write the partition table and exit by typing w.

At last, you should format the two partitions doing this:

Then we would mount these partitions:

Now, the SD card is properly formatted and you shall continue with the next steps

Booting process
The first thing that should be done in order to boot a 64-bit kernel, is to have a 64-bit bootloader.

Das U-Boot
Currently, I have managed to setup my Raspberry Pi 3 with a U-Boot bootloader. It is hard to just download the source code of U-Boot, configure it and compile it. This is not enough because it should be stubbed in order the four cores of the Raspberry to work. I have not managed to stub it on myself, so I use Electron752's stubbed version. You can download it with the following command:

This allows us to have a working bootloader with a shell. But it would be better to have an autoboot. So in order to have an autoboot we need to create a boot.scr.uimg. This is an image which U-Boot loads automatically if its shell is not activated by the user.

In order to create that image, we need to create a list of commands which the bootloader should run in order to boot. The list of commands I use is the following: fatload mmc 0:1 ${fdt_addr_r} bcm2837-rpi-3-b.dtb fatload mmc 0:1 ${kernel_addr_r} image setenv bootargs console=tty0 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait booti ${kernel_addr_r} - ${fdt_addr_r}

The list of commands should be saved as boot.scr. In the list of commands above, the third line is the one with the kernel command line. While booting we would ignore the built-in command line of the kernel and would use our own. Our own line is configurable in the third line of the boot commands. To it init=/usr/lib/systemd/systemd can be added in order systemd to be enabled on the Raspberry Pi.

When we have boot.scr containing all boot commands, the next step is creating the image. It can be done by directly installing the U-Boot tools.

After that the following command should be run in order to create the image:

Then the uboot-stubbed.bin and boot.scr.uimg should be copied into the boot partition:

After that, the bootloader setup is ready and we should go to setup the kernel and the root filesystem.