Raspberry Pi4 64 Bit Install

From Gentoo Wiki
Jump to: navigation, search

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

Follow the method described in Raspberry Pi 3 64 bit Install

The Pi 4 differs in the kernel build, the /boot/config.txt content and the requirement for some code from raspberrypi/tools

The Pi 4 Kernel

Get the aarch64-unknown-linux-gnu cross toolchain.

To cross compile the kernel, start with

user $ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu- make bcm2711_defconfig

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, install the device tree, now named bcm2711-rpi-4-b.dtb and install the kernel modules.

Important
As with the Pi3, there are 32 bit and 64 bit versions of the device tree binary bcm2711-rpi-4-b.dtb the 64 bit version must be used

/boot/config.txt

The following is a bare minimum /boot/config.txt

# set 64 bit mode
arm_64bit=1

enable_gic=1
armstub=armstub8-gic.bin

The usual

# have a properly sized image
disable_overscan=1
# for sound over HDMI
hdmi_drive=2
# Enable audio (loads snd_bcm2835)
dtparam=audio=on

may or may not be useful and are unchanged from earlier versions of the Raspberry Pi.

rasberrypi/tools

Rasberrypi/tools provides armstub8-gic.bin which must be copied to /boot

Naturally, its in a git repo. Clone it beside the Pi Sources and Pi Firmware repos.

user $git clone https://github.com/raspberrypi/tools

build the contents of tools/armstubs

user $cd tools/armstubs
user $make CC8=aarch64-unknown-linux-gnu-gcc LD8=aarch64-unknown-linux-gnu-ld OBJCOPY8=aarch64-unknown-linux-gnu-objcopy OBJDUMP8=aarch64-unknown-linux-gnu-objdump armstub8-gic.bin
root #cp armstub8-gic.bin /mnt/gentoo/boot/
Warning
/dev/sdk1 follows the Raspberry Pi 3 64 bit Install guide example.

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 brcmfmac43455-sdio.txt where grep boardflags3 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.

Firmware Updates

The Pi4 has firmware. It no longer uses bootcode.bin, even if its present.

Be sure to keep your firmware up to date. New features are promised and optimisations like Power Reduction are already available.

There is a small trap for the unwary. The firmware updater program as distributed is an arm 32 bit program. The good news is that Sakakis genpi64 overlay has all the bits required to build an arm64 version in the normal Gentoo fashion.

# Required to update Pi4 firmware.
media-libs/raspberrypi-userland::genpi64
dev-embedded/rpi4-eeprom-images::genpi64
dev-embedded/rpi4-eeprom-updater::genpi64

Power Over Ethernet

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

Fan control works.

Random hints

CFLAGS

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

Using -mtune=cortex-a72. Cortex-A72 mandatorily supports +crc and +simd. But no crypto extension on BCM2835/RPi4. Adding -ftree-vectorize and -fomit-frame-pointer to utilize more registers.

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

Acknowledgements

sakakis topic on the Raspberry Pi forums

All the contributors to issue 3032 on the Raspberry Pi github repo