Running LineageOS on Raspberry Pi 3B

2 minute read

Setup Build Environment

Follow instructions in Running Android Oreo on Raspberry Pi 3B to setup build environment under Ubuntu.

Download Source Code

repo init -u git://github.com/LineageOS/android.git -b lineage-15.1 --repo-url=https://github.com/fudongbai/git-repo
curl --create-dirs -L -o .repo/local_manifests/manifest_brcm_rpi3.xml -O -L https://raw.githubusercontent.com/lineage-rpi/android_local_manifest/lineage-15.1/manifest_brcm_rpi3.xml
repo sync -c

Replace repo server to get reliable connection in China:

sed -i 's/android.googlesource.com/aosp.tuna.tsinghua.edu.cn/g' .repo/manifest.xml

Apply patches:

cd frameworks/base/
git am 0001-rpi3-modify-generic-keyboard-layout.patch
cd vendor/lineage/
git am 0001-disable-adb-authentication-by-default.patch

Also apply below patch to make lcd display work properly:

diff --git a/boot/config.txt b/boot/config.txt
index ba753a9..51ac804 100644
--- a/boot/config.txt
+++ b/boot/config.txt
@@ -9,8 +9,9 @@ dtparam=audio=on
 # Display
 hdmi_force_hotplug=1
 hdmi_drive=2
-hdmi_group=1
-hdmi_mode=4
+hdmi_group=2
+hdmi_mode=87
+hdmi_cvt=800 480 60 1
 disable_overscan=1
 #framebuffer_width=1280
 #framebuffer_height=720

Build Lineage

prebuilts/misc/linux-x86/ccache/ccache -M 50G
. build/envsetup.sh
lunch lineage_rpi3-userdebug
make kernel ramdisk systemimage vendorimage

Make sdcard image

There is a shell script in device/brcm/rpi3 to do this, this script need kpartx to be installed:

sudo apt-get install kpartx

Now go to device/brcm/rpi3 to make the writable sdcard image:

cd device/brcm/rpi3
sudo sudo ./mkimg.sh

Build arm64 kernel image

For using KASAN, you need to build 64 bit kernel, as of this writing the kernel from github has been updated to 4.14.129.

Create defconfig

First create kernel defconfig based on arch/arm64/configs/bcmrpi3_defconfig, kernel/configs/android-base.config and kernel/configs/android-recommended.config

Make sure apply below patch to your defconfig:

+CONFIG_INPUT_EVDEV=y
-CONFIG_FRAMEBUFFER_CONSOLE=y # with this lcd screen not work

Without option CONFIG_INPUT_EVDEV, system_server will suffer endless crash: input

Build kernel image

sudo apt-get install gcc-aarch64-linux-gnu -y
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make lineageos_rpi3b_defconfig
ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make

Boot config

Add these to config.txt:

arm_64bit=1

Comment this 32 bit kernel image
#kernel=zImage

If kernel8.img is presented on Pi 3, it will be loaded in preference and will be working in 64-bit mode, the kernel image must be uncompressed.

In case of using large kernels, enabling CONFIG_KASAN for my case, change default ramdisk load address to followkernel to make sure the kernel will not overlap the ramdisk:

-initramfs ramdisk.img 0x01f00000
+initramfs ramdisk.img followkernel

Test new kernel

adb root
adb shell mkdir /data/boot
adb shell mount -t vfat /dev/block/mmcblk0p1 /data/boot
adb push arch/arm64/boot/Image /data/boot/kernel8.img
adb push arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b-plus.dtb /data/boot

Oh, don’t forget replace bcm2710-rpi-3-b-plus.dtb in boot partition, otherwise, we cannot bring up ethernet, and kernel will dump below messages during bootup:

[    4.211240] lan78xx 1-1.1.1:1.0 (unnamed net_device) (uninitialized): can't register MDIO bus
[    4.220131] lan78xx 1-1.1.1:1.0 (unnamed net_device) (uninitialized): MDIO INIT FAILED.....
[    4.228790] lan78xx 1-1.1.1:1.0 (unnamed net_device) (uninitialized): Bind routine FAILED

Reboot android and checkout kernel version:

Linux version 4.14.129-v8+ (fdbai@fdbai-desktop) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9)) #11 SMP PREEMPT Sun Jul 21 12:09:15 CST 2019

Find full message here.

References