[REFERENCE] OnePlus 6 kernel source with linux-stable (4.9.135)

nathanchance

Senior Recognized Developer / Recognized Contribut
Jul 22, 2015
13,748
49,941
113
25
Mesa, AZ
Introduction

Hello everyone, this is a thread to introduce both users and kernel developers to the concept of linux-stable as well as give developers some tips and a tree to either merge into their own, use as a base, or just as a reference. Feel free to ask questions and enjoy!


What is it?

linux-stable is, as the name implies, the stable branch of the Linux kernel, the base of Android. The phone could not run without the Linux kernel (at least not without reworking a lot of stuff). The Android kernels are based on the longterm stable trees:
Longterm

There are usually several "longterm maintenance" kernel releases provided for the purposes of backporting bugfixes for older kernel trees. Only important bugfixes are applied to such kernels and they don't usually see very frequent releases, especially for older trees.
Source: https://www.kernel.org/category/releases.html

All Linux development happens on the master branch, which is governed by Linus Torvalds. When issues are discovered there, the fixes are applied then backported to these various stable trees for consumption. It is not uncommon for a fix to need to go back a few years.

There is a LOT more information available in the notes repo in the android-linux-stable organization if you care to learn more in-depth: https://github.com/android-linux-stable/notes


What does this mean for me?

If you are a developer, this means you should be merging these changes into your own tree. These are vetted, stable fixes to real world problems and they are being handed out for free. It does not take long to get up to date (as you can just merge this tree directly into your own or do it yourself using the tree as a reference) and once you are up to date, there is usually a release once every two weeks, give or take. I provide a rebuttal to a lot of various complaints here. If you still feel like there is a good reason not to do this, please let me know, I'll be happy to try and debate on it!

If you are a user, it means that you should be looking for and using kernels that have these fixes, as it shows the developers care for your security and stability. The current version for this device is 4.9.65 on OxygenOS 5.x and 4.9.106 on OxygenOS 9.0/Open Beta while the current version upstream is 4.9.135 so all you need to do is go into Settings > About phone and look at the kernel version to know if you are up to date.


How do I use?

If you are a developer, the reference tree is located in the android-linux-stable organization: https://github.com/android-linux-stable/op6

This can either be merged into your existing kernel tree if you have one or be used as a fresh base. You do not need my permission to use it nor do you need to give me credit (although it would be appreciated).

If you are a user, use a kernel that has the changes added in!


Getting notified about updates

There are a few ways to get notified of linux-stable updates:


Getting help

If you have any issues with getting these changes into your tree or want to ask a question, there are a few different ways to do it:
  • Post in this thread
  • Join the linux-stable support chat on Telegram: https://t.me/joinchat/C1UAJ1EMSX31PCFdwLnOSg
  • File an issue either in the android-linux-stable notes repo or the android-linux-stable repo for this device

When requesting help, please give some solid details as to what you are struggling with, as I am happy to provide assistant and clarity but not to do something for you (unless I screwed up).
 
Last edited:

nathanchance

Senior Recognized Developer / Recognized Contribut
Jul 22, 2015
13,748
49,941
113
25
Mesa, AZ
Who got 1 star ? really ?

btw, @nathanchance you have 5 star from me, good work ,and it is nice to see you here.
As always, good job with informing users , waiting for your kernel :)
Ratings mean absolutely nothing and I feel sorry for anyone who puts any stock in them but thanks :)

My kernel should be out tonight.
 

nathanchance

Senior Recognized Developer / Recognized Contribut
Jul 22, 2015
13,748
49,941
113
25
Mesa, AZ
  • Like
Reactions: black_file

phenoxis

Member
Aug 25, 2016
25
3
0
Could you please provide instructions on how to flash a kernel?

Earlier, I could just extract the boot.img file from one of the ROM images and then extract+repackage with my built Image.gz-dtb using mkbootimg.
The newer Android ROMs seem to only contain a package.bin file instead.
 

nathanchance

Senior Recognized Developer / Recognized Contribut
Jul 22, 2015
13,748
49,941
113
25
Mesa, AZ
Could you please provide instructions on how to flash a kernel?

Earlier, I could just extract the boot.img file from one of the ROM images and then extract+repackage with my built Image.gz-dtb using mkbootimg.
The newer Android ROMs seem to only contain a package.bin file instead.
Easiest way is to temporarily boot TWRP on stock then run

Code:
adb shell dd if=/dev/block/bootdevice/by-name/boot$(getprop ro.boot.slot_suffix) of=/tmp/boot.img
adb pull /tmp/boot.img .
then just unpack like you have before.

Sent from my Pixel 2 XL using XDA Labs
 

phenoxis

Member
Aug 25, 2016
25
3
0
Easiest way is to temporarily boot TWRP on stock then run

Code:
adb shell dd if=/dev/block/bootdevice/by-name/boot$(getprop ro.boot.slot_suffix) of=/tmp/boot.img
adb pull /tmp/boot.img .
then just unpack like you have before.
I followed your advice with both the original OnePlus 6 kernel source and your android-linux-stable repo. I was able to build the kernel, repack it and flash it, but with both repos, the device is sitting with the bootanimation for about half hour or so. Do both repositories need additional work before it can boot?

I packaged boot.img with the following command:
Code:
mkbootimg --base 0 --pagesize 4096 --kernel_offset 0x00008000 --ramdisk_offset 0x01000000 
--second_offset 0x00f00000 --tags_offset 0x00000100 
--cmdline 'androidboot.hardware=qcom androidboot.console=ttyMSM0 video=vfb:640x400,bpp=32,memsize=3072000 
msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 service_locator.enable=1 swiotlb=2048 
androidboot.configfs=true androidboot.usbcontroller=a600000.dwc3 buildvariant=user' --kernel kernel --ramdisk ramdisk -o boot_1.img
 

nathanchance

Senior Recognized Developer / Recognized Contribut
Jul 22, 2015
13,748
49,941
113
25
Mesa, AZ
I followed your advice with both the original OnePlus 6 kernel source and your android-linux-stable repo. I was able to build the kernel, repack it and flash it, but with both repos, the device is sitting with the bootanimation for about half hour or so. Do both repositories need additional work before it can boot?

I packaged boot.img with the following command:
Code:
mkbootimg --base 0 --pagesize 4096 --kernel_offset 0x00008000 --ramdisk_offset 0x01000000 
--second_offset 0x00f00000 --tags_offset 0x00000100 
--cmdline 'androidboot.hardware=qcom androidboot.console=ttyMSM0 video=vfb:640x400,bpp=32,memsize=3072000 
msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 service_locator.enable=1 swiotlb=2048 
androidboot.configfs=true androidboot.usbcontroller=a600000.dwc3 buildvariant=user' --kernel kernel --ramdisk ramdisk -o boot_1.img
They shouldn't... Did you use Image.gz-dtb as the kernel?
 

phenoxis

Member
Aug 25, 2016
25
3
0
They shouldn't... Did you use Image.gz-dtb as the kernel?
Yes, I'm certain I did.
My full script is:
Code:
unmkbootimg --kernel kernel --ramdisk ramdisk -i boot.img.bk   #This is what I obtained from your dd if=... of=/tmp/boot.img command
cp /android/kernel/opo6-stable/arch/arm64/boot/Image.gz-dtb kernel
mkbootimg --base 0 --pagesize 4096 --kernel_offset 0x00008000 --ramdisk_offset 0x01000000 
--second_offset 0x00f00000 --tags_offset 0x00000100 
--cmdline 'androidboot.hardware=qcom androidboot.console=ttyMSM0 video=vfb:640x400,bpp=32,memsize=3072000 
msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 service_locator.enable=1 swiotlb=2048 
androidboot.configfs=true androidboot.usbcontroller=a600000.dwc3 buildvariant=user' 
--kernel kernel --ramdisk ramdisk -o boot_1.img
fastboot flash boot boot_1.img
 

nathanchance

Senior Recognized Developer / Recognized Contribut
Jul 22, 2015
13,748
49,941
113
25
Mesa, AZ
Yes, I'm certain I did.
My full script is:
Code:
unmkbootimg --kernel kernel --ramdisk ramdisk -i boot.img.bk   #This is what I obtained from your dd if=... of=/tmp/boot.img command
cp /android/kernel/opo6-stable/arch/arm64/boot/Image.gz-dtb kernel
mkbootimg --base 0 --pagesize 4096 --kernel_offset 0x00008000 --ramdisk_offset 0x01000000 
--second_offset 0x00f00000 --tags_offset 0x00000100 
--cmdline 'androidboot.hardware=qcom androidboot.console=ttyMSM0 video=vfb:640x400,bpp=32,memsize=3072000 
msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 service_locator.enable=1 swiotlb=2048 
androidboot.configfs=true androidboot.usbcontroller=a600000.dwc3 buildvariant=user' 
--kernel kernel --ramdisk ramdisk -o boot_1.img
fastboot flash boot boot_1.img
Try using this boot image: https://nathanchance.me/downloads/kernels/op6/stock/oos-5.1.8-boot.img

You may also check out Android Image Kitchen too, that's what I used before TWRP.
 

phenoxis

Member
Aug 25, 2016
25
3
0
First, thanks a ton for taking the time to help me out.

I tried unpacking/repacking with your boot.img file, and that didn't work either. However, your boot.img itself works just fine.

I just realized that my build produces a ton of warnings.
Code:
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/qcom,[email protected] has invalid length (8 bytes) (#address-cells == 2, #size-cells == 1)
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/qcom,[email protected] has invalid length (8 bytes) (#address-cells == 2, #size-cells == 1)
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/qcom,[email protected] has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/qcom,[email protected] has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/[email protected] has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/[email protected] has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
...
This is probably why my kernels are failing to boot. I'm essentially following the instructions you laid out on the github issue for this kernel.

Code:
export ARCH=arm64
export CROSS_COMPILE=/android/projects/cross-compile/aarch64-linux-android-4.9/bin/aarch64-linux-android-
make O=out sdm845-perf_defconfig
./scripts/config --file ./out/.config -e BUILD_ARM64_DT_OVERLAY
make O=out olddefconfig
make O=out DTC_EXT=dtc -j16
Following the comments in that issue, I'm running archlinux with the following software versions:
gcc
Code:
[email protected]:/android/kernel/opo6-stable$ gcc --version
gcc (GCC) 8.1.1 20180531
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
dtc
Code:
[email protected]:/android/kernel/opo6-stable$ dtc --version
Version: DTC 1.4.6
 

nathanchance

Senior Recognized Developer / Recognized Contribut
Jul 22, 2015
13,748
49,941
113
25
Mesa, AZ
First, thanks a ton for taking the time to help me out.

I tried unpacking/repacking with your boot.img file, and that didn't work either. However, your boot.img itself works just fine.

I just realized that my build produces a ton of warnings.
Code:
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/qcom,[email protected] has invalid length (8 bytes) (#address-cells == 2, #size-cells == 1)
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/qcom,[email protected] has invalid length (8 bytes) (#address-cells == 2, #size-cells == 1)
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/qcom,[email protected] has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/qcom,[email protected] has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/[email protected] has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
arch/arm64/boot/dts/qcom/enchilada-evb-overlay.dtbo: Warning (reg_format): "reg" property in /[email protected]/__overlay__/[email protected] has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
...
This is probably why my kernels are failing to boot. I'm essentially following the instructions you laid out on the github issue for this kernel.

Code:
export ARCH=arm64
export CROSS_COMPILE=/android/projects/cross-compile/aarch64-linux-android-4.9/bin/aarch64-linux-android-
make O=out sdm845-perf_defconfig
./scripts/config --file ./out/.config -e BUILD_ARM64_DT_OVERLAY
make O=out olddefconfig
make O=out DTC_EXT=dtc -j16
Following the comments in that issue, I'm running archlinux with the following software versions:
gcc
Code:
[email protected]:/android/kernel/opo6-stable$ gcc --version
gcc (GCC) 8.1.1 20180531
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
dtc
Code:
[email protected]:/android/kernel/opo6-stable$ dtc --version
Version: DTC 1.4.6
That's normal, I've hidden all of the warnings.

https://github.com/nathanchance/op6/commits/1d0f0ea36c0814efa36ef8b5c0c1ad9cb74cfe81

Those were the commits I used for my first boot. There is nothing in there that should be necessary to boot, just to make certain things work.
 
  • Like
Reactions: marko94