[Raspberry Pi Development] sandpox:
Hi all

If you just need Raspberry Pi 3 to run headless linux and unleash its full 64bit power then you can compile vanilla kernel (kernel.org) for Raspberry Pi 3 using this tutorial.

YOU NEED TO USE THIS WITH ARM64 LINUX DISTRIBUTION

I don't know if it's my custom distribution's fault or kernel fault but when I use arm64 kernel on Raspberry Pi's Github then it's panic because fs driver on heavy load.

This tutorial doesn't use u-boot for booting the kernel, instead I use the firmware as it is.

This tutorial has been tested on Ubuntu 16.10, 17.04 host and you just need to copy and paste, it will work.

First of all, you need to setup build environment by using command below (maybe not all of these are necessary but this is how I usually setup my Android build environment and it's work for kernel build too):

sudo apt update
sudo apt install -y bison bc build-essential flex git-core gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libxml2 libxml2-utils lzop schedtool xsltproc zlib1g-dev g++-multilib gcc-multilib lib32ncurses5-dev lib32z1-dev

Now you need to get the aarch64 toolchain, here I'll use Linaro because it will somewhat improve performance but you can use the gcc-aarch64-linux-gnu if you want.

This code will download Linaro 6.3.1 and extract it to /opt/ for use later on:

wget http://releases.linaro.org/components/toolchain/binaries/latest/aarch64-linux-gnu/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu.tar.xz
sudo tar -xvf gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu.tar.xz -C /opt/

Now you need to clone kernel source code, this will takes some time on slow connection even though I did make it only clone the latest commit (shadow clone) but without clone the whole history:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git --depth=1 -b linux-4.10.y

You can change the linux-4.10.y to another branch if you want, this branch clone will give you the latest version of that particular kernel version (4.10).

Now start the compilation, here I'm using a build machine with 14 cores, you can replace -j14 with your CPU core number for faster build, don't set it to higher than your real CPU core or it will slow your machine down:

cd linux-stable
mkdir MODULES BOOT

#
# Export necessary variable
#
export CROSS_COMPILE=/opt/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
export ARCH=arm64

#
# Make arm64 default defconfig
#
make defconfig -j14

#
# You must enable FB_SIMPLE or it will not boot
#
sed -i 's/# CONFIG_FB_SIMPLE is not set/CONFIG_FB_SIMPLE=y/g' .config

#
# Here I enable ethernet driver as built-in because you'll need it in some situation like kernel module not loaded
#
sed -i 's/CONFIG_USB_USBNET=m/CONFIG_USB_USBNET=y/g' .config
sed -i 's/CONFIG_USB_NET_SMSC95XX=m/CONFIG_USB_NET_SMSC95XX=y/g' .config

#
# Disable these heavy module which we will not use it at all
#
sed -i 's/CONFIG_DRM_NOUVEAU=m/# CONFIG_DRM_NOUVEAU is not set/g' .config
sed -i 's/CONFIG_DRM_TEGRA=m/# CONFIG_DRM_TEGRA is not set/g' .config

#
# Making the modules, copy it to ./MODULES
#
make modules -j14
make modules_install -j14 INSTALL_MOD_PATH=MODULES/

#
# Making the kernel and dtbs
#
make Image dtbs -j14

#
# It's compiled, copy it to ./BOOT for easy to work with
#
cp ./arch/arm64/boot/Image ./BOOT/Image
cp ./arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dtb ./BOOT/

You should have all the necessary file from build kernel in 2 directory (BOOT, MODULES) if nothing wrong happens.

[INSTALL KERNEL]

Plug the MicroSDcard of Raspberry Pi 3 to your computer and copy ./BOOT/Image and ./BOOT/bcm2837-rpi-3-b.dtb to partition #1 (vfat)

Edit the config.txt and add lines below, edit if already exist, this will: active arm64 mode, use device_tree for boot kernel, use kernel named Image:

arm_control=0x200
device_tree=bcm2837-rpi-3-b.dtb
kernel=Image

[INSTALL MODULES]

Now you have to mount the Raspberry Pi 3 Linux OS partition (usually is partition #2) to your system to copy file into it

Make backup and delete every directory in /lib/modules/ of OS partition

Copy ./MODULES/lib/modules/* to /lib/modules/ of OS partition using root

Now it's basically done, unmount/safely eject the sdcard and plug it to your Raspberry Pi 3, boot it up.

Modules might not loaded automatically, run this command on Raspberry Pi 3 shell:

sudo find "/lib/modules" -mindepth 1 -maxdepth 1 -type d | while read DIR; do echo ${DIR}; BASEDIR=$(basename "${DIR}"); echo " *** depmod ${BASEDIR}"; depmod -b "/" -a "${BASEDIR}"; done

Now modules should be loaded and will be loaded automatically on next boot.

Disclaimer:

- Only Kernel 4.9 and above are supported Raspberry Pi 3 AArch64

- Wifi/Bluetooth will not work since driver still haven't implemented

- Other function might not work

Tested/working:

- USB

- Ethernet

- HDMI

- UART

- GPU acceleration