Raspberry Pi4 64 Bit Install

Overview
The Raspberry Pi 4 has been out for a few months and already the community has got everything working in 64 bit mode.

Curious users need to be familiar with the use of a cross toolchain or have access to another armv8a system to build a 64 bit kernel for the Pi 4.

What Works
Everything.

Not Tested (by me)
Analogue Video Output Analogue Audio Output Camera Screen

I don't have hardware to test the camera or screen.

The Installation Method
You may cross compile the kernel as described below, but I suggest installing qemu with static aarch64 user emulation and then treating it as a standard Gentoo installation, following similar to the amd64 handbook after taking into account the rest of the pi specific notes on this page, copying over /usr/bin/qemu-aarch64 to the /mnt/gentoo/usr/bin/ after unpacking the stage 3.

Pi specific: it needs a fat32 partition to boot from, and it does not use a regular bootloader.

The Pi 4 Kernel
Get the aarch64-unknown-linux-gnu cross toolchain.

To cross compile the kernel, start with

Check the other kernel configuration settings given in configure the kernel.

Kernel Tweaks
The Pi 4 USB 3 supports USB Attached SCSI (CONFIG_USB_UAS). Unlike bulk mode, it allows commands to USB storage devices to be overlapped. Enable USB Attached SCSI in the kernel if a USB3 storage device will be used.

The default CPU governor (CPU_FREQ_DEFAULT_GOV) is powersave. This runs the CRU at 600MHz all he time. CPU governors can be controlled in /proc or the default CPU governor can be changed to be ondemand.

Power Over Ethernet requires a .dto file to be loaded as well as kernel support.

The 4G RAM Pi 4 can build the 64 bit kernel in about an hour but a 64 bit toolchain is required, so the very first kernel cannot be built natively on the Pi.

Build and Install the Kernel
Build and install the kernel, device tree and kernel modules an described in install the kernel binary,

Build and install the device tree and overlays by running make dtb, then copy the resulting device tree and overlay files to /boot

Note, that the dtb may change during kernel updates, remember to keep updating them when you update the rest of the kernel.

Install the firmware
All the firmware needed to boot the pi is found in.

/boot/config.txt
The following options may or may not be useful and are unchanged from earlier versions of the Raspberry Pi.

Note as well there is a new alternative audio mode that does not use the audio=on dtparamater. disable_overscan=1 hdmi_drive=2 dtparam=audio=on
 * 1) have a properly sized image
 * 1) for sound over HDMI
 * 1) Enable audio (loads snd_bcm2835)

/boot/cmdline.txt
Take this time to review and edit /boot/cmdline.txt to point to the root file system.

Note that rootfstype is not necessarily needed and that elevator=deadline has no effect on recent kernels as well. console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

Odds and Ends

microSD trim/discard
The microSD interface supports the trim command. Pi4_~arm64 ~ # fstrim -av /boot: 7.7 GiB (8250073088 bytes) trimmed on /dev/mmcblk0p1 If you have a suitable microSD card, consider adding fstrim to a weekly or monthly cron job.

USB Attached SCSI
The USB3 interface appears to support the kernels UAS (USB Attached SCSI) option. Its harmless to enable. Unfortunately, my USB3 to SATA cable does not work with UAS. Enable it in the kernel as its harmless. Search for USB_UAS <*>  USB Attached SCSI

WiFi
WiFi needs three firmware files in /lib/firmware/brcm/ brcmfmac43455-sdio.bin brcmfmac43455-sdio.clm_blob brcmfmac43455-sdio.txt Which is almost but not quite the same as the Pi3. The catch is in where  produces different results for the Pi3 and Pi4 files. The Pi4 version returns boardflags3=0x44200100 The Pi3 version returns boardflags3=0x48200100 With the wrong brcmfmac43455-sdio.txt file, bluetooth works but not WiFi.

These files, including the pi 4 version of above file, are found in, to install it you'll also need to install  with the savedconfig useflag and remove the conflicting files from the saved configuration, and then remerge linux-firmware to apply the new deconflicted savedconfig: /lib/firmware/brcm/brcmfmac43430-sdio.bin /lib/firmware/brcm/brcmfmac43430-sdio.txt /lib/firmware/brcm/brcmfmac43436-sdio.bin /lib/firmware/brcm/brcmfmac43436-sdio.clm_blob /lib/firmware/brcm/brcmfmac43436-sdio.txt /lib/firmware/brcm/brcmfmac43455-sdio.bin /lib/firmware/brcm/brcmfmac43455-sdio.clm_blob /lib/firmware/brcm/brcmfmac43455-sdio.txt /lib/firmware/brcm/brcmfmac43456-sdio.bin /lib/firmware/brcm/brcmfmac43456-sdio.clm_blob /lib/firmware/brcm/brcmfmac43456-sdio.txt

Eeprom Updates
provides the eeprom files and the updater, and as well as a service to check and apply the updates.

There are 3 release channels of firmware updates


 * critical - Default - rarely updated
 * stable - Updated when new/advanced features have been successfully beta tested.
 * beta - New or experimental features are tested here first.

To configure which release channel you'd like the updater service to follow, edit /etc/conf.d/rpi-eeprom-update

Power Over Ethernet
The Pi3b PoE HAT will power the P4 and a USB SSD.

Fan control works.

CFLAGS
CFLAGS="-march=armv8-a+crc+simd -mtune=cortex-a72 -ftree-vectorize -O2 -pipe -fomit-frame-pointer"

Using. Cortex-A72 mandatorily supports  and. But no crypto extension on BCM2835/RPi4. Adding  and   to utilize more registers.

gcc-6.x allows the use of  but that will prevent the use of distcc. The above is the same as gcc-6.3 would set for  anyway.

USB Attached SSD
Users with USB3 attached SSDs may have noticed that trim is not supported. Its a feature of USB storage that trim is disabled by default. Trim can be enabled with mixed success. Only USB3 is supported and the USB3 to SSD bridge device must be able to pass the trim command.

One other thing to note, the Raspberry pi currently only supports booting from usb mass storage devices (including external hard drives) that have a 512 byte logical sector size. You may need to reformat (with the drive manufacturer's utility) them to enable 512 byte emulation.

Acknowledgements
NeddySeagoon for taking over maintenance and upstreaming many ebuilds from sakaki's overlay after sakaki's retirement ( Neddy's fork )

sakakis topic on the [//www.raspberrypi.org/forums/viewtopic.php?p=1491136 Raspberry Pi forums]

All the contributors to [//github.com/raspberrypi/linux/issues/3032 issue 3032] on the Raspberry Pi github repo