Running LineageOS 16 on Raspberry Pi 3B

3 minute read

Setup Build Environment

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

Download Source Code

Follow the instruction below to get aosp source code:

repo init -u git://github.com/LineageOS/android.git -b lineage-16.0 --repo-url=https://github.com/fudongbai/git-repo
git clone https://github.com/fudongbai/android_local_manifest .repo/local_manifests -b lineage-16.0
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:

repo start 0801 --all
cd frameworks/base/
git am 0001-rpi3-modify-generic-keyboard-layout.patch

Build Lineage

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

Make sdcard image

There is a shell script in device/brcm/rpi3 to do this, this script needs 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

Verify sdcard image

Flash lineage-16.0-20190803-rpi3.img with dd command or Etcher tool:

sudo dd bs=4M if=lineage-16.0-20190803-rpi3.img of=/dev/sdc conv=fsync

We can find android verison in Settings: lineage 16

or in build property: build prop

Build arm64 lineage OS image

Because we are building arm64 system, the library gralloc and hwcomposer need to rebuild, thanks to andriod-rpi team’s great work, it saves a lot of time, I’ve forked these git repos and added them to local_manifest(commit 1e4d654).

I build 64-bit image because Hardware-assisted AddressSanitizer (HWASan) only works on aarch64 hardware, this build is only used for learning how HWASan works, and I still wanna keep the 32-bit build, so I created a separate project for this purpose and pushed 64-bit related changes there.

BoardConfig

The most important part to build 64-bit image is to set the right TARGET_ARCH, TARGET_ARCH_VARIANT and TARGET_CPU_ABI, raspberry pi 3b has arm cortex-a53 on board, so the board config should be like this:

 TARGET_BOARD_PLATFORM := bcm2710

-TARGET_ARCH := arm
-TARGET_ARCH_VARIANT := armv7-a-neon
-TARGET_CPU_ABI := armeabi-v7a
+TARGET_ARCH := arm64
+TARGET_ARCH_VARIANT := armv8-a
+TARGET_CPU_ABI := arm64-v8a
 TARGET_CPU_ABI2 := armeabi
 TARGET_CPU_VARIANT := cortex-a53

For building 64-bit kernel, default compiler and defconfig should be specified:

 # Kernel
-BOARD_KERNEL_IMAGE_NAME := zImage
-TARGET_KERNEL_CONFIG := lineageos_rpi3_defconfig
-TARGET_KERNEL_CROSS_COMPILE_PREFIX := arm-linux-gnueabihf-
+BOARD_KERNEL_IMAGE_NAME := Image
+TARGET_KERNEL_CONFIG := lineageos_rpi3b_defconfig
+TARGET_KERNEL_CROSS_COMPILE_PREFIX := aarch64-linux-gnu-
 TARGET_KERNEL_SOURCE := kernel/brcm/rpi3

Trouble shooting

Build failure

Build android after changing BoardConfig.mk report below error:

build/make/core/main.mk:640: error: OverlayHostTests.LOCAL_TARGET_REQUIRED_MODULES : illegal value OverlayHostTests_BadSignatureOverlay : not a device module. If you want to specify host modules to be required to be installed along with your host module, add those module names to LOCAL_REQUIRED_MODULES instead.
22:49:46 ckati failed with: exit status 1

Look for similar 64-bit product, they all include core_64_bit.mk like this, so add this to rpi3b.mk:

+$(call inherit-product, $(SRC_TARGET_DIR)/product/core_64_bit.mk)

vc4 not working

I have not make vc4 working yet, kernel report Failed to get pix clock when doing vc4_hdmi_bind:

[    0.397202] [drm:vc4_hdmi_bind] *ERROR* Failed to get pixel clock
[    0.397251] vc4-drm soc:gpu: failed to bind 3f902000.hdmi (ops vc4_hdmi_ops): -517
[    0.397401] vc4-drm soc:gpu: master bind failed: -517

The author of VC4 graphics driver Eric says:

that log just looks like a custom kernel where you missed the power domain driver.

mount sdcard image

If you need to check files in the sdcard image, config.txt in boot partition for example, use fdsik -l to list partitions:

fdisk -l lineageos-16.0-20190805-rpi3b.img
Disk lineageos-16.0-20190805-rpi3b.img: 4 GiB, 4294967296 bytes, 8388608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc67d7f78

Device                             Boot   Start     End Sectors  Size Id Type
lineageos-16.0-20190805-rpi3b.img1 *       2048  526335  524288  256M  c W95 FAT32 (LBA)
lineageos-16.0-20190805-rpi3b.img2       526336 2623487 2097152    1G 83 Linux
lineageos-16.0-20190805-rpi3b.img3      2623488 3147775  524288  256M 83 Linux
lineageos-16.0-20190805-rpi3b.img4      3147776 8388607 5240832  2.5G 83 Linux

The boot partition can be mount with this command:

sudo mount -t vfat lineageos-16.0-20190805-rpi3b.img /tmp/rpi3/ -o loop,offset=$((2048 * 512))

References