projects github about
Raspberry Pi 3 64-bit kernel

Cross-Build Prerequisites

For building our own 64-bit kernel fom scratch using the Raspberry Pi Foundation repository, a couple of dependencies are needed. You may however use the mainline kernel though i haven’t tried to use it.

18/10/13: Procedure for compiling the mainline kernel is the same for raspberry pi foundation except that mainline kernel doesn't create an overlays folder. For further research as to why...
Host machine: Ubuntu 18.04.1. Procedure for compiling kernel-4.18 is the same just replace the brach to rpi-4.18.y.
Removed initrd.img as is not needed to boot.
1
2
3
4
5
6
7
8
9
//make sure these are installed:
crossbuild-essential-arm64
bison
flex
device-tree-compiler
pkg-config
ncurses-dev
libssl-dev
git

we also need: kernel RPi Repo file_download RPi firmware file_download

bootcode.bin, start.elf, fixup.dat as this are the min. files to boot. The rest of star.* and fixup.* files for graphical desktop or better yet include them all.

Compile the Kernel

Use any Linux machine of your choice or Windows 10’s Bash to compile the kernel is all up to you. To get the kernel we need, we can either download it as a compressed file using the links above or we could use git to make it simpler.

1
git clone --depth 1 --branch rpi-4.14.y https://github.com/raspberrypi/linux.git rpi-4.14.70
1
2
3
mkdir bo_4.14
sudo make -C rpi-4.14.70/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=$HOME/bo_4.14 bcmrpi3_defconfig
sudo make -C rpi-4.14.70/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=$HOME/bo_4.14 -j4
bcmrpi3_defconfig - arm64 config using Raspberry Pi Foundation Kernel
defconfig - arm64 config using mainline kernel
-C source folder/. O=$HOME/output-folder - Output directory.
-jX - build the kernel in a multithreaded way where: X = [Num of core x 2]
Image file @ $HOME/bo_4.14/arch/arm64/boot/
bcm2710-rpi-3-b.dtb @ $HOME/bo_4.14/arch/arm64/boot/dts/broadcom/

Create config.txt and cmdline.txt

For the config.txt and cmdline.txt, we have to create those files and add these lines.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//config.txt

# Serial console output!
enable_uart=1

# 64bit-mode
# arm_control=0x200 is deprecated https://www.raspberrypi.org/documentation/configuration/config-txt/misc.md
arm_64bit=1

# Uncomment below to use your custom named kernel
#kernel=your-kernel.img

# For i2c & spi
dtparam=i2c_arm=on
dtparam=spi=on

# Enable audio (loads snd_bcm2835)
dtparam=audio=on
1
2
3
//cmd.txt

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

Transfer the necessary files to the MicroSD

Rename the Image file we had earlier to kernel8.img. start.elf file knows kernel8.img file is a kernel to load.

1
2
3
4
5
6
7
8
9
//MicroSD card should now contain these files below

bootcode.bin
start.elf
fixup.dat
config.txt
cmdline.txt
kernel8.img
bcm2710-rpi-3-b.dtb

Boot to test

Place the MicroSD on to the Raspberry Pi 3 and power it on. You can now then verify at this point that our kernel boot as well and will stop at some point since we still do not have a filesystem.

If it did not boot or no display at all, we will use U-Boot.

Next is Creating the filesystem for our Raspberry Pi 3 using Ubuntu Base.

Reference :

https://wiki.ubuntu.com/ARM/RaspberryPi/RaspberryPi3
https://wiki.ubuntu.com/Base
https://www.raspberrypi.org/documentation/linux/kernel/building.md
https://kernelnomicon.org/?p=682