AOSP Kernel build for Pixel 5

186 views
Skip to first unread message

Andrew Fernandes

unread,
Jun 15, 2021, 6:35:08 PMJun 15
to Android Building
I'm following the instructions on source.android.com for building kernels and unable to get it working on the Pixel 5.

There are a couple of paths I've taken with differing results.

1. Check out the aosp-kernel android-msm-redbull-4.19-android11-qpr2 branch
2. Run the build_redbull.sh (or build_rebull-gki.sh) script.
3. In the aosp directory, export TARGET_PREBUILT_KERNEL to the built Image.lz4-dtb from aosp-kernel
4. flash aosp using `fastboot flashall -w`
5. Observe bootloop, the devices never reaches a point where adbd starts and I can shell in

Then I saw from other posts that when recompiling the kernel the prebuilt kernel modules that are in the aosp repository are out of date and are being packaged into the vendor_boot image and failing to load.

So... next I tried copying all of the compiled aosp-kernel modules and images into the aosp/device/google/redbull-kernel directory and rebuilding.

This gets farther and I'm now able to adb shell into the device, but the display stays on the Android boot logo and various other services/sensors don't work.

So, my question is, what's the process for a successful build/flash of the aosp kernel on the Pixel 5?

For reference I'm using the aosp android-11.0.0_r37 branch and aosp kernel android-msm-redbull-4.19-android11-qpr2 branch.

Any help/instruction would be greatly appreciated!

Andrew Fernandes

unread,
Jun 23, 2021, 1:06:37 AMJun 23
to Android Building
I've found a couple of different solutions for anyone else who stumbles on this issue.

If you follow the directions and use TARGET_PREBUILT_KERNEL, all of the kernel modules in vendor.img and vendor_boot.img are out of sync. Not only do you need to get the updated kernel in the aosp build, but all of the updated kernel modules.

After building the kernel, I would suggest ignoring the TARGET_PREBUILT_KERNEL option and instead, just copy everything from aosp-kernel/out/android-msms-pixel-4.19/dist to aosp/device/google/redbull-kernel.

A little background, the vendor_boot.img has a ramdisk with kernel modules pulled from this directory.

Next is the problem with the vendor.img, which is cumbersome to unpack/repack with the updated kernel modules.

For the vendor.img, I suggest using product-based vendor overlay files. Vendor overlay files populate the product.img with the updated kernel modules that get overlaid on the vendor image on boot.


After doing all of the above and rebuilding asop, your vendor_boot.img and product.img (with vendor_overlay) has the updated kernel modules that will work with the new kernel.

Droid SMU

unread,
Jun 23, 2021, 1:10:18 AMJun 23
to Android Building
I am also encountering the same issue and used the same setup as you did.
The furthest I could go was copy all the kernel modules *.ko files into the aosp/device/google/redbull-kernel directory to solve the flashing issue.
After a successful flash, the device will boot until the point where it shows the android logo and gets stuck there.

Would appreciate some guidance on this. Thanks!

Droid SMU

unread,
Jun 23, 2021, 1:11:13 AMJun 23
to Android Building
Hi,

I managed to solve this issue! Was able to build and boot a custom kernel on the Pixel 5!
It seems that Google has made some architectural changes to the kernel in Android 11 as shown in the following link:

What I realized is that after building the kernel, it generates a boot.img and vendor_boot.img
Usually we only have boot.img but this time there is an additional vendor boot file. This led me to the idea that we need to also flash this file to the phone.

These are the steps that I generally performed:
  1. repo init -u https://android.googlesource.com/kernel/manifest -b android-msm-redbull-4.19-android11-qpr2
  2. repo sync
  3. Build custom kernel with build_redbull.sh script:
    ./build_redbull.sh
  4. After building, boot.img and vendor_boot.img gets created in kernel/out/android-msm-pixel-4.19/dist/ along with loadable modules and Image.lz4 and Image.lz4-dtb
  5. Go to AOSP folder.  Copy Image.lz4, Image.lz4-dtb, kernel-uapi-headers.tar.gz and all the *.ko kernel modules from
    kernel/out/android-msm-pixel-4.19/dist/ to aosp/device/google/redbull-kernel folder.

    You may back-up the aosp/device/google/redbull-kernel folder at another location in case we would like to restore to the default files.
  6. Run make to rebuild the images
  7. Copy the vendor_boot.img from kernel to out/target/product/redfin folder
  8. adb reboot bootloader
  9. fastboot flashall -w
fastboot version: 31.0.2-7242960
This was tested with AOSP android-11.0.0_r34 but I believe it can also work for other versions.

Hope this is able to help you save two weeks of development time. At least that was the time it took me to setup a base AOSP and kernel on the Pixel 5.

On Wednesday, 16 June 2021 at 06:35:08 UTC+8 afer...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages