[REFERENCE] How to compile an Android kernel

y2kbugleung

Senior Member
Mar 2, 2011
411
65
48
Hong Kong
This is my first time to compile an Android kernel.
I am following this guide: https://developer.sony.com/develop/...nux-kernel-for-xperia-devices#tutorial-step-3

It always warn me when I run "make":
CC scripts/mod/empty.o
In file included from ././include/linux/compiler_types.h:74:0,
from <command-line>:0:
./include/linux/compiler-gcc.h:15:3: error: #error Sorry, your compiler is too old - please upgrade it.
# error Sorry, your compiler is too old - please upgrade it.
^
make[1]: *** [scripts/Makefile.build:283: scripts/mod/empty.o] Error 1
make: *** [Makefile:1197: prepare0] Error 2
I have installed the latest GCC 10.2 already:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 10.2.0-13ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-JvwpWM/gcc-10-10.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-JvwpWM/gcc-10-10.2.0/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (Ubuntu 10.2.0-13ubuntu1)
How should I fix the problem?

Thanks.
 

EliasGraf

New member
Oct 26, 2020
2
0
0
Dumping/splitting image failed. Aborting....

I am unable to flash the image with anykernel3 using TWRP 3.4.0-0.


anykernel.sh
Code:
# AnyKernel3 Ramdisk Mod Script
# osm0sis @ xda-developers

## AnyKernel setup
# begin properties
properties() { '
kernel.string=ExampleKernel by osm0sis @ xda-developers
do.devicecheck=1
do.modules=0
do.systemless=1
do.cleanup=1
do.cleanuponabort=0
device.name1=dumpling
device.name2=
device.name3=
device.name4=
device.name5=
supported.versions=
supported.patchlevels=
'; } # end properties

# I have tried both "/boot" and "/system" for block
block=/dev/block/platform/soc/1da4000.ufshc/by-name/boot;

is_slot_device=0;
ramdisk_compression=auto;


## AnyKernel methods (DO NOT CHANGE)
# import patching functions/variables - see for reference
. tools/ak3-core.sh;


## AnyKernel file attributes
# set permissions/ownership for included ramdisk files
set_perm_recursive 0 0 755 644 $ramdisk/*;
set_perm_recursive 0 0 750 750 $ramdisk/init* $ramdisk/sbin;


## AnyKernel install
dump_boot;

# begin ramdisk changes

# init.rc
backup_file init.rc;
replace_string init.rc "cpuctl cpu,timer_slack" "mount cgroup none /dev/cpuctl cpu" "mount cgroup none /dev/cpuctl cpu,timer_slack";

# init.tuna.rc
backup_file init.tuna.rc;
insert_line init.tuna.rc "nodiratime barrier=0" after "mount_all /fstab.tuna" "\tmount ext4 /dev/block/platform/omap/omap_hsmmc.0/by-name/userdata /data remount nosuid nodev noatime nodiratime barrier=0";
append_file init.tuna.rc "bootscript" init.tuna;

# fstab.tuna
backup_file fstab.tuna;
patch_fstab fstab.tuna /system ext4 options "noatime,barrier=1" "noatime,nodiratime,barrier=0";
patch_fstab fstab.tuna /cache ext4 options "barrier=1" "barrier=0,nomblk_io_submit";
patch_fstab fstab.tuna /data ext4 options "data=ordered" "nomblk_io_submit,data=writeback";
append_file fstab.tuna "usbdisk" fstab;

# end ramdisk changes

write_boot;
## end install
zip command
Code:
zip -r9 kernel.zip * -x .git *placeholder README.md kernel.zip zip up kernel.sh
Kernel I want to compile: cannot post links so just this for you: github/DerpFest-Devices/kernel_oneplus_msm8998
 
Last edited:
Nov 7, 2020
1
0
1
I am trying to build for phoenixin, getting this error htt ps: //del. dog /gghipuckog

I think this is because of gcc wrapper, which I didn't understand what to do with, I am a newbie so it'd be great if anyone help me, (can't send full del dog link due to xda error)
 

newbit

Senior Member
Nov 16, 2008
116
56
58
Hi nathanchance,

thanks for your thread, I am struggling a bit to get make running. Maybe you could help me out please?

I would like to build a goldfish kernel 5.4
Code:
uname -r && uname -v
5.4.61-android11-2-00064-g4271ad6e8ade-ab6991359
#1 SMP PREEMPT Mon Nov 23 17:45:44 UTC 2020
Code:
git clone -b android-goldfish-5.4-dev --single-branch https://android.googlesource.com/kernel/goldfish
Because of your github page, I figured I need the CLANG Toolchain instead of the GCC 4.9.
The GCC 4.9 worked very well with a 4.14. Goldfish kernel. I also git cloned the recommend CLANG Toolchain.
Code:
git clone \
    -b android-11.0.0_r27 \
    --single-branch https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86
After my exports from within goldfish:
export PATH=$PATH:$(pwd)/../linux-x86/clang-r383902b/bin
export PATH=$PATH:$(pwd)/../x86_64-linux-android-4.9/bin


I try to run a make savedefconfig:

Code:
make savedefconfig ARCH=x86_64 \
                   CC=clang \
                   CLANG_TRIPLE=aarch64-linux-gnu- \
                   CROSS_COMPILE=x86_64-linux-android-
But it breaks right away with this message:
Code:
scripts/kconfig/conf  --savedefconfig=defconfig Kconfig
scripts/Kconfig.include:39:  gold linker 'x86_64-linux-android-ld' not supported
make[1]: *** [scripts/kconfig/Makefile:78: savedefconfig] Error 1
make: *** [Makefile:571: savedefconfig] Error 2
(I do have a .config file from an AVD, which I want to create a defconfig of it...)

I am getting a bit confused, because of your statements:
PATH="<path to clang folder>/bin:<path to 64-bit gcc folder>/bin:<path to 32-bit gcc folder>/bin:${PATH}"
When using AOSP Clang, you should use AOSP's GCC to avoid weird incompatibility issues.
I thought when using a 5.4 Kernel, GCC is obsolete and CLANG replaced it?! What am I missing here? Which 64-bit GCC is needed? The 4.9 pops up the error message above.

Update 09.01.2021
I actually made it work! The Kernel now builds without Errors! And the bootup sequence
from the stock kernel is identical until Run /init as init process

Code:
[    1.383866] Run /init as init process
[    1.388899] init: init first stage started!
[    1.390740] init: Loading module /lib/modules/btbcm.ko with args ""
[    1.392283] btbcm: disagrees about version of symbol module_layout
[    1.393818] init: Failed to insmod '/lib/modules/btbcm.ko' with args ''
[    1.395154] init: LoadWithAliases was unable to load btbcm
[    1.396361] init: [libfs_mgr]ReadFstabFromDt(): failed to read fstab from dt
[    1.398041] init: Using Android DT directory /proc/device-tree/firmware/android/
[    1.425461] init: bool android::init::BlockDevInitializer::InitDevices(std::set<std::string>): partition(s) not found in /sys, waiting for their uevent(s): metadata, super, vbmeta
[   11.438802] init: Wait for partitions returned after 10010ms
[   11.440723] init: bool android::init::BlockDevInitializer::InitDevices(std::set<std::string>): partition(s) not found after polling timeout: metadata, super, vbmeta
[   11.445314] init: Failed to mount required partitions early ...
[   11.447176] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00007f00
I guess the real issu lies in btbcm: disagrees about version of symbol module_layout
The stock kernel at this point, just keeps loading module after module.
I've compared the Module.symvers from the common and goldfish 5.4 Kernel, and they
even differ in the first 2 lines. I guess this the End Of The Line ? Any Idea how I can get
the right kernel source with the proper symbol versions? Or how I can adjust my build configs?

Code:
### Kernel try with Android 11 Kernel 5.4
mkdir avdkernel5.4compile && cd avdkernel5.4compile

git clone \
    -b android-11.0.0_r28 \
    --single-branch https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9

git clone -b android-11.0.0_r28 --single-branch https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/
git clone -b android-goldfish-5.4-dev --single-branch https://android.googlesource.com/kernel/goldfish
git clone https://android.googlesource.com/kernel/prebuilts/build-tools

mkdir clang-r383902 && cd clang-r383902
wget https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/android-11.0.0_r28/clang-r383902.tar.gz
tar -xzf clang-r383902.tar.gz && cd ..

git clone -b android11-5.4 --single-branch https://android.googlesource.com/kernel/common
git clone -b android11-5.4 --single-branch https://android.googlesource.com/kernel/common-modules/ common-modules/virtual-device
####
Code:
### export stuff:
cd goldfish
export ARCH=x86_64
export CLANG_TRIPLE=x86_64-linux-gnu-
export CROSS_COMPILE=x86_64-linux-androidkernel-
export LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=$(pwd)/../x86_64-linux-android-4.9/bin
export CLANG_PREBUILT_BIN=$(pwd)/../clang-r383902/bin
export BUILDTOOLS_PREBUILT_BIN=$(pwd)/../build-tools/linux-x86
DEVEXPS="CC=clang LD=ld.lld NM=llvm-nm OBJCOPY=llvm-objcopy DEPMOD=depmod EXTRA_CMDS='' STOP_SHIP_TRACEPRINTK=1 DO_NOT_STRIP_MODULES=1"
export PATH=$PATH:$LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN:$CLANG_PREBUILT_BIN:$BUILDTOOLS_PREBUILT_BIN
###
Code:
### merging adb pulled .config with cloned kernel devconfigs
cp ../config .config
make savedefconfig $DEVEXPS
mv defconfig arch/x86/configs/avd_pulled_defconfig && rm .config

./scripts/kconfig/merge_config.sh -m \
    ./arch/x86/configs/avd_pulled_defconfig \
    ./arch/x86/configs/gki_defconfig
x86_64_defconfig

make savedefconfig $DEVEXPS
mv defconfig arch/x86/configs/merged_gki_avd_pulled_defconfig && rm .config
### build the kernel
make $DEVEXPS merged_gki_avd_pulled_defconfig
time make $DEVEXPS -j$(nproc)
###
Update 12.01.2021
This time, I really made it working! I "just" had to add the EXTRAVERSION from the original stock Kernel Build to the LOCALVERSION in the .config file.
[ 0.000000] Linux version 5.4.61-android11-2-00064-g4271ad6e8ade-ab6991359 ([email protected]) (Android (6443078 based on r383902) clang version 11.0.1 (https://android.googlesource.com/toolchain/llvm-project b397f81060ce6d701042b782172ed13bee898b79), LLD 11.0.1 (/buildbot/tmp/tmp6_m7QH b397f81060ce6d701042b782172ed13bee898b79)) #1 SMP PREEMPT Mon Nov 23 17:45:44 UTC 2020
-g4271ad6e8ade
And then the build kernel from the common source became to:
[ 0.000000] Linux version 5.4.61-g4271ad6e8ade-00014-g158eae717346 ([email protected]) (Android (6443078 based on r383902) clang version 11.0.1 (https://android.googlesource.com/toolchain/llvm-project b397f81060ce6d701042b782172ed13bee898b79), LLD 11.0.1 (/buildbot/tmp/tmp6_m7QH b397f81060ce6d701042b782172ed13bee898b79)) #1 SMP PREEMPT Mon Jan 11 12:58:18 CET 2021

Now it boots the Android 11 (R) AVD with Google Play Store APIs.
Also I've updated my rootAVD script to root it with Magisk-v21.2
More details soon in a seperated [GUIDE]

Thanks for reading
NewBit
 
Last edited:
  • Like
Reactions: KaMyKaSii

ebrahimwaleed

Member
Jun 18, 2016
31
3
8
hello i have been trying for a month now to compile kernel for my huawei enjoy max ars-al00 i tried too many tool chain i always get error related to the tool chain like error while loading shared library or there is some some missing files and -fstack-protector-strong not support by compiler i tired making it to not set any help will be lovely and what should i provide for better help
 

newbit

Senior Member
Nov 16, 2008
116
56
58
hello i have been trying for a month now to compile kernel for my huawei enjoy max ars-al00 i tried too many tool chain i always get error related to the tool chain like error while loading shared library or there is some some missing files and -fstack-protector-strong not support by compiler i tired making it to not set any help will be lovely and what should i provide for better help
I can try to help...
What are the details of your Build / Development Environment?
And where is your Kernel Source to download?
In the Huawei Kernels I buld, was allways a little HowTo in form of a Readme.txt what one needs to do to get the source build.
Cheers
NewBit
 
  • Like
Reactions: ebrahimwaleed

ebrahimwaleed

Member
Jun 18, 2016
31
3
8
I can try to help...
What are the details of your Build / Development Environment?
And where is your Kernel Source to download?
In the Huawei Kernels I buld, was allways a little HowTo in form of a Readme.txt what one needs to do to get the source build.
Cheers
NewBit
i am using ubuntu desktop latest version
installed all the requirements
and here is the kernel source code

i would to chat with you through telegram if its possible

 

newbit

Senior Member
Nov 16, 2008
116
56
58
i am using ubuntu desktop latest version
installed all the requirements
and here is the kernel source code

i would to chat with you through telegram if its possible

I had quite some issues with the newest ubuntu version. Some libs were depreciated, especially the QT libs, so I had to go back to an older version for my huawei p9 plus kernel. Try a 19er Version or even lower.

Your README_Kernel.txt says very similar to the P9 Plus what to do:
Code:
################################################################################
1. How to Build
    - get Toolchain
        From android git server , codesourcery and etc ..
         - aarch64-linux-android-4.9

    - edit Makefile
        edit "CROSS_COMPILE" to right toolchain path(You downloaded).
        EX)   CROSS_COMPILE= $(android platform directory you download)/android/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
        Ex)   CROSS_COMPILE=/usr/local/toolchain/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
        // check the location of toolchain
        or
        Ex)   export CROSS_COMPILE=arm-linux-androideabi-
        Ex)   export PATH=$PATH:<toolchain_parent_dir>/aarch64-linux-android-4.9/bin

        $ make ARCH=arm64 merge_msm8953_64_defconfig
        $ make ARCH=arm64 Image.gz-dtb

2. Output files
    - Kernel : arch/arm64/boot/Image.gz-dtb
    - module : drivers/*/*.o

3. How to Clean
        $ make ARCH=arm64 distclean
################################################################################

Check out my post How to build the kernel for your Huawei P9 Plus
There you will find the build tools to install, also the toolchain. I would try with one, that is closest
to your Kernel Date. Unsupported NDK Downloads

Btw: I assume your Bootloader is already unlocked? If not, don't bother to build the kernel.

Thanks for your Telegram offer, but lets keep the discussion here, so others can benefit from this as well.

Cheers
NewBit
 
  • Like
Reactions: ebrahimwaleed

ebrahimwaleed

Member
Jun 18, 2016
31
3
8
I had quite some issues with the newest ubuntu version. Some libs were depreciated, especially the QT libs, so I had to go back to an older version for my huawei p9 plus kernel. Try a 19er Version or even lower.

Your README_Kernel.txt says very similar to the P9 Plus what to do:
Code:
################################################################################
1. How to Build
    - get Toolchain
        From android git server , codesourcery and etc ..
         - aarch64-linux-android-4.9

    - edit Makefile
        edit "CROSS_COMPILE" to right toolchain path(You downloaded).
        EX)   CROSS_COMPILE= $(android platform directory you download)/android/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
        Ex)   CROSS_COMPILE=/usr/local/toolchain/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
        // check the location of toolchain
        or
        Ex)   export CROSS_COMPILE=arm-linux-androideabi-
        Ex)   export PATH=$PATH:<toolchain_parent_dir>/aarch64-linux-android-4.9/bin

        $ make ARCH=arm64 merge_msm8953_64_defconfig
        $ make ARCH=arm64 Image.gz-dtb

2. Output files
    - Kernel : arch/arm64/boot/Image.gz-dtb
    - module : drivers/*/*.o

3. How to Clean
        $ make ARCH=arm64 distclean
################################################################################

Check out my post How to build the kernel for your Huawei P9 Plus
There you will find the build tools to install, also the toolchain. I would try with one, that is closest
to your Kernel Date. Unsupported NDK Downloads

Btw: I assume your Bootloader is already unlocked? If not, don't bother to build the kernel.

Thanks for your Telegram offer, but lets keep the discussion here, so others can benefit from this as well.

Cheers
NewBit
yes my bootloader is unlocked okay i will check ur post and reply back to you and thanks in advance <3
 

newbit

Senior Member
Nov 16, 2008
116
56
58
yes my bootloader is unlocked okay i will check ur post and reply back to you and thanks in advance <3
I almost got it working. After disabling the huawei cfi feature in the devconfig, which is not the merge_msm8953_64_defconfig as in the
README_Kernel.txt proposed. It is merge_sdm660_64_defconfig

It starts compiling, with the 16 and 17 NDK toolchain. After approx. 100 manually include changes, from <> to "",
i.e. #include <athdefs.h> > #include "athdefs.h"
it kept compiling, until some missing wlan drivers in kernel/vendor/qcom/opensource/wlan/
Which I could get from the linux foundation as mentioned somewhere in the kernel source.
But still, the end of the line is a missing athdefs.h from the file: /kernel/drivers/wlan_driver/core/dp/ol/inc/ol_txrx_ctrl_api.h

This athdefs.h I couldn't find it anywhere in the source, so I took one from the linux foundation, but this just generates a ton of other issues.
Can you pull the file /proc/config.gz from your phone?
What is your kernel version? uname -a

Cheers NewBit
 
  • Like
Reactions: ebrahimwaleed

ebrahimwaleed

Member
Jun 18, 2016
31
3
8
I almost got it working. After disabling the huawei cfi feature in the devconfig, which is not the merge_msm8953_64_defconfig as in the
README_Kernel.txt proposed. It is merge_sdm660_64_defconfig

It starts compiling, with the 16 and 17 NDK toolchain. After approx. 100 manually include changes, from <> to "",
i.e. #include <athdefs.h> > #include "athdefs.h"
it kept compiling, until some missing wlan drivers in kernel/vendor/qcom/opensource/wlan/
Which I could get from the linux foundation as mentioned somewhere in the kernel source.
But still, the end of the line is a missing athdefs.h from the file: /kernel/drivers/wlan_driver/core/dp/ol/inc/ol_txrx_ctrl_api.h

This athdefs.h I couldn't find it anywhere in the source, so I took one from the linux foundation, but this just generates a ton of other issues.
Can you pull the file /proc/config.gz from your phone?
What is your kernel version? uname -a

Cheers NewBit
i have just updated the phone to android pie i will install twrp and root it tomorrow morning and can you tell me how to pull /proc/config.gz
and there is another source code for android pie 9.1 i dont know if this will change anything but here is pie source code
 

newbit

Senior Member
Nov 16, 2008
116
56
58
i have just updated the phone to android pie i will install twrp and root it tomorrow morning and can you tell me how to pull /proc/config.gz
and there is another source code for android pie 9.1 i dont know if this will change anything but here is pie source code
yeah good luck with the new kernel source. keep me updated once you finished building it

[Update 29.01.2021]
Hey @ebrahimwaleed,
what is the status? Any progress?

I've created a github repo with your PIE Source and committed some of my changes to it.
I was able to download and extract the defconfig file from the Firmware FullOTA-MF ARS-AL00 9.1.0.160(C00E160R2P5) 2019.12.09
Some changes were necessary to get make starting, like the cfi to n and the cert to the kernel sources cert.
The kernel starts compiling, quite long, but then it breaks with issues I can't figure out to fix.
There is not much more I can do for you, so you have to take it from here. I can't get the missing opensource drivers proper into the source.
I fixed the Kbuild file so far, that it has the right path to it, also some other includes, but the code doesn't match the version/style Huawei used.
There are still some things I figured so far.
  • the kernel/drivers/wlan_driver is actually qcacld-3.0
  • in there must be a/the hw_qca_decoupled
  • fw-api is missing at all but its needed -> athdefs.h, it belongs in drivers or rather the same hierarchy as qcacld-3.0
  • qca-wifi-host-cmn is in drivers, but it is not complete, i.e. target_if is missing but requested from the Kbuild
  • the only version hint I could find is in kernel/drivers/wlan_driver/core/mac/inc/qwlan_version.h -> 5.1.1.69P
  • all this usally belongs in kernel/drivers/staging
  • checkout some work on that from @nathanchance
I've tried several branches from the codeaurora around Nov 2018 until May 2019. But at the end, there are always too many symbols not known
or the too many warnings regarding the syntax.

I hope it will bring you something further than before.
Here are some commands I used, it might help you to pick up where I left:
Bash:
mkdir workdir && cd ~/workdir
git clone https://github.com/newbit1/ARES_PIE_EMUI9.1.0_opensource.git Code_Opensource
VER=r17c
wget https://dl.google.com/android/repository/android-ndk-$VER-linux-x86_64.zip
unzip android-ndk-$VER-linux-x86_64.zip android-ndk-$VER/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/*
mv android-ndk-$VER/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 aarch64-linux-android-4.9 && rm -Rf android-ndk-$VER
export CROSS_COMPILE=$(pwd)/aarch64-linux-android-4.9/bin/aarch64-linux-android-
export LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=$(pwd)/aarch64-linux-android-4.9/bin
export PATH=$PATH:$(pwd)/aarch64-linux-android-4.9/bin
cd Code_Opensource/kernel/
make ARCH=arm64 FIRMWARE_sdm660_64_defconfig
make ARCH=arm64 xconfig
make ARCH=arm64 -j$(nproc)
cd ~/workdir/Code_Opensource/kernel/drivers/wlan_driver
cd ~/workdir/Code_Opensource/kernel/vendor/qcom/opensource/wlan/
SDM660BRANCH=LA.UM.7.2.r1-04000-sdm660.0
git clone -b $SDM660BRANCH --single-branch https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/wlan/qca-wifi-host-cmn
git clone -b $SDM660BRANCH --single-branch https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/wlan/qcacld-3.0
git clone -b $SDM660BRANCH --single-branch https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/wlan/fw-api
Regarding the cfi.so
It seems that the GCC libexec/cc1 is generating or referring to this file on runtime. It is a bit above my head, but this libexec is ment
to access a shared lib path on your host, to files, which are not supposed to be able to run from "normal" users. This could be a reason
why I only get one hit on a forum mentioning the same file cfi.so, even with the same issue I guess, it is in Russian. But that's it, can't find anything
else and don't know what it is really supposed to do. CFI could stand for Code Flow Integration...

Installing GCC: Configuration
Control Flow Integrity
Control Flow Integrity Design Documentation

Cheers
NewBit
 
Last edited:
  • Love
Reactions: ebrahimwaleed

kyvaith

Member
Sep 8, 2007
31
9
28
Hi,

In past I've created definitions and build first Android TV x86 ISO which was near perfection, so I have some knowlage about AOSP building and troubleshooting in *nix environment.

This week I've decided to build kernel for my Nvidia Shield TV 2017 and I'm feeling like an idiot since I don't know where to start.

The problem is Nvidia released full AOSP tree only for Android 8 (GFE 7.x.x) and for Android 9 (GFE 8.x.x) there are only some definitions in manifest.:

fully buildable tree: https://nv-tegra.nvidia.com/gitweb/...artner;hb=refs/heads/rel-24-foster-r7-partner

tree I want to use to build kernel: https://nv-tegra.nvidia.com/gitweb/...source;hb=refs/heads/rel-32-shield-opensource

there is even no build tools in updated tree...

I wanted to just do mp bootimage -j5 to build boot image but it's impossible.

Also I don't know how to build kernel outside AOSP tree.

Hint: somebody compiled kernel for Pie here but author is not answering question how to do this by ourself https://forum.xda-developers.com/t/kernel-rooted-pie-performance-enhanced-overclock-kernel.3943079/

Please point me a direction how can I build this kernel. I'd like to backport DVB support to it and aff some firmware blobs.

Thank you,
Tom.
 

ebrahimwaleed

Member
Jun 18, 2016
31
3
8
yeah good luck with the new kernel source. keep me updated once you finished building it

[Update 29.01.2021]
Hey @ebrahimwaleed,
what is the status? Any progress?

I've created a github repo with your PIE Source and committed some of my changes to it.
I was able to download and extract the defconfig file from the Firmware FullOTA-MF ARS-AL00 9.1.0.160(C00E160R2P5) 2019.12.09
Some changes were necessary to get make starting, like the cfi to n and the cert to the kernel sources cert.
The kernel starts compiling, quite long, but then it breaks with issues I can't figure out to fix.
There is not much more I can do for you, so you have to take it from here. I can't get the missing opensource drivers proper into the source.
I fixed the Kbuild file so far, that it has the right path to it, also some other includes, but the code doesn't match the version/style Huawei used.
There are still some things I figured so far.
  • the kernel/drivers/wlan_driver is actually qcacld-3.0
  • in there must be a/the hw_qca_decoupled
  • fw-api is missing at all but its needed -> athdefs.h, it belongs in drivers or rather the same hierarchy as qcacld-3.0
  • qca-wifi-host-cmn is in drivers, but it is not complete, i.e. target_if is missing but requested from the Kbuild
  • the only version hint I could find is in kernel/drivers/wlan_driver/core/mac/inc/qwlan_version.h -> 5.1.1.69P
  • all this usally belongs in kernel/drivers/staging
  • checkout some work on that from @nathanchance
I've tried several branches from the codeaurora around Nov 2018 until May 2019. But at the end, there are always too many symbols not known
or the too many warnings regarding the syntax.

I hope it will bring you something further than before.
Here are some commands I used, it might help you to pick up where I left:
Bash:
mkdir workdir && cd ~/workdir
git clone https://github.com/newbit1/ARES_PIE_EMUI9.1.0_opensource.git Code_Opensource
VER=r17c
wget https://dl.google.com/android/repository/android-ndk-$VER-linux-x86_64.zip
unzip android-ndk-$VER-linux-x86_64.zip android-ndk-$VER/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/*
mv android-ndk-$VER/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 aarch64-linux-android-4.9 && rm -Rf android-ndk-$VER
export CROSS_COMPILE=$(pwd)/aarch64-linux-android-4.9/bin/aarch64-linux-android-
export LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=$(pwd)/aarch64-linux-android-4.9/bin
export PATH=$PATH:$(pwd)/aarch64-linux-android-4.9/bin
cd Code_Opensource/kernel/
make ARCH=arm64 FIRMWARE_sdm660_64_defconfig
make ARCH=arm64 xconfig
make ARCH=arm64 -j$(nproc)
cd ~/workdir/Code_Opensource/kernel/drivers/wlan_driver
cd ~/workdir/Code_Opensource/kernel/vendor/qcom/opensource/wlan/
SDM660BRANCH=LA.UM.7.2.r1-04000-sdm660.0
git clone -b $SDM660BRANCH --single-branch https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/wlan/qca-wifi-host-cmn
git clone -b $SDM660BRANCH --single-branch https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/wlan/qcacld-3.0
git clone -b $SDM660BRANCH --single-branch https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/wlan/fw-api
Regarding the cfi.so
It seems that the GCC libexec/cc1 is generating or referring to this file on runtime. It is a bit above my head, but this libexec is ment
to access a shared lib path on your host, to files, which are not supposed to be able to run from "normal" users. This could be a reason
why I only get one hit on a forum mentioning the same file cfi.so, even with the same issue I guess, it is in Russian. But that's it, can't find anything
else and don't know what it is really supposed to do. CFI could stand for Code Flow Integration...

Installing GCC: Configuration
Control Flow Integrity
Control Flow Integrity Design Documentation

Cheers
NewBit
update 1
i am working on phone original firmware and unlocking the bootloader after the update it is locked and the phone firmware will be updated to 9.1.0.174 but i think the kernel is the same i will check the kernel version as soon as i install the the latest firmware and back it up

update 2
after following all you steps now when i compile the kernel with FIRMWARE_sdm660_64_defconfig there are 2 missing drivers i will dump the kernel.img from the phone and try to unpack it and provide it in a link idk but i think it might help

i get
Bash:
CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  HOSTCC  scripts/sign-file
  CHK     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/extract-cert
find lcdkit qcom folder, include it now!
  CC      kernel/bounds.s
  CHK     include/generated/timeconst.h
  UPD     include/generated/timeconst.h
  CHK     include/generated/bounds.h
  UPD     include/generated/bounds.h
  CC      arch/arm64/kernel/asm-offsets.s
  CHK     include/generated/asm-offsets.h
  UPD     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
drivers/wlan_driver/Kbuild:218: CONFIG_with_build_kernel
drivers/wlan_driver/Kbuild:679: drivers/../vendor/qcom/opensource/wlan/qcacld-3.0/hw_qca_decoupled/Kbuild: No such file or directory
make[2]: *** No rule to make target 'drivers/../vendor/qcom/opensource/wlan/qcacld-3.0/hw_qca_decoupled/Kbuild'.  Stop.
make[1]: *** [scripts/Makefile.modbuiltin:54: drivers/wlan_driver] Error 2
make: *** [Makefile:1221: drivers/modules.builtin] Error 2
make: *** Waiting for unfinished jobs....
and thanks for all what you have done really god bless you this is the first progress i had since a month<3
Cheers
 
Last edited:

ebrahimwaleed

Member
Jun 18, 2016
31
3
8
yeah good luck with the new kernel source. keep me updated once you finished building it

[Update 29.01.2021]
Hey @ebrahimwaleed,
what is the status? Any progress?

I've created a github repo with your PIE Source and committed some of my changes to it.
I was able to download and extract the defconfig file from the Firmware FullOTA-MF ARS-AL00 9.1.0.160(C00E160R2P5) 2019.12.09
Some changes were necessary to get make starting, like the cfi to n and the cert to the kernel sources cert.
The kernel starts compiling, quite long, but then it breaks with issues I can't figure out to fix.
There is not much more I can do for you, so you have to take it from here. I can't get the missing opensource drivers proper into the source.
I fixed the Kbuild file so far, that it has the right path to it, also some other includes, but the code doesn't match the version/style Huawei used.
There are still some things I figured so far.
  • the kernel/drivers/wlan_driver is actually qcacld-3.0
  • in there must be a/the hw_qca_decoupled
  • fw-api is missing at all but its needed -> athdefs.h, it belongs in drivers or rather the same hierarchy as qcacld-3.0
  • qca-wifi-host-cmn is in drivers, but it is not complete, i.e. target_if is missing but requested from the Kbuild
  • the only version hint I could find is in kernel/drivers/wlan_driver/core/mac/inc/qwlan_version.h -> 5.1.1.69P
  • all this usally belongs in kernel/drivers/staging
  • checkout some work on that from @nathanchance
I've tried several branches from the codeaurora around Nov 2018 until May 2019. But at the end, there are always too many symbols not known
or the too many warnings regarding the syntax.

I hope it will bring you something further than before.
Here are some commands I used, it might help you to pick up where I left:
Bash:
mkdir workdir && cd ~/workdir
git clone https://github.com/newbit1/ARES_PIE_EMUI9.1.0_opensource.git Code_Opensource
VER=r17c
wget https://dl.google.com/android/repository/android-ndk-$VER-linux-x86_64.zip
unzip android-ndk-$VER-linux-x86_64.zip android-ndk-$VER/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/*
mv android-ndk-$VER/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 aarch64-linux-android-4.9 && rm -Rf android-ndk-$VER
export CROSS_COMPILE=$(pwd)/aarch64-linux-android-4.9/bin/aarch64-linux-android-
export LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=$(pwd)/aarch64-linux-android-4.9/bin
export PATH=$PATH:$(pwd)/aarch64-linux-android-4.9/bin
cd Code_Opensource/kernel/
make ARCH=arm64 FIRMWARE_sdm660_64_defconfig
make ARCH=arm64 xconfig
make ARCH=arm64 -j$(nproc)
cd ~/workdir/Code_Opensource/kernel/drivers/wlan_driver
cd ~/workdir/Code_Opensource/kernel/vendor/qcom/opensource/wlan/
SDM660BRANCH=LA.UM.7.2.r1-04000-sdm660.0
git clone -b $SDM660BRANCH --single-branch https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/wlan/qca-wifi-host-cmn
git clone -b $SDM660BRANCH --single-branch https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/wlan/qcacld-3.0
git clone -b $SDM660BRANCH --single-branch https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/wlan/fw-api
Regarding the cfi.so
It seems that the GCC libexec/cc1 is generating or referring to this file on runtime. It is a bit above my head, but this libexec is ment
to access a shared lib path on your host, to files, which are not supposed to be able to run from "normal" users. This could be a reason
why I only get one hit on a forum mentioning the same file cfi.so, even with the same issue I guess, it is in Russian. But that's it, can't find anything
else and don't know what it is really supposed to do. CFI could stand for Code Flow Integration...

Installing GCC: Configuration
Control Flow Integrity
Control Flow Integrity Design Documentation

Cheers
NewBit
after doing some researches about the CFI from what i have found the cfi stands for Control flow integrity please can you have a look here " https://source.android.com/devices/tech/debug/kcfi " and here "https://android-developers.googleblog.com/2018/10/control-flow-integrity-in-android-kernel.html"
 

tohtorin

Senior Member
Jun 22, 2016
148
118
53
Lammi
www.drg.fi
Hi.

I am trying to compile stock kernel for OnePlus 8T and cannot get it to build.
What I am doing wrong? Wrong clang version? (Tried 2 of em) Wrong defconfig? Wrong gcc?

I have clang r383902b and AOSP 4.9 gcc toolchain.

This is what I have tried so far:

1. git clone https://github.com/OnePlusOSS/android_kernel_oneplus_sm8250
3. cd android_kernel_oneplus_sm8250
2. git checkout oneplus/SM8250_R_11.0
3. run these exports:

export ARCH=arm64
export SUBARCH=arm64
export DTC_EXT=dtc

4. mkdir out

5. make O=out ARCH=arm64 defconfig (what is ringh config for the device? there is 3 of em:

cuttlefish_defconfig
defconfig
ranchu64_defconfig

What should I use? (Tried even grab one from phones /proc/config.gz without luck)

6. PATH=/home/user/android/clang-r383902b/bin:/home/user/android/toolchain/bin:${PATH} make -j$(nproc --all) O=out ARCH=arm64 CC=clang CLANG_TRIPLE=aarch64-linux-gnu- CROSS_COMPILE=aarch64-linux-android-

This asks few questions:

Clang Shadow Call Stack (SHADOW_CALL_STACK) [N/y/?] (NEW)

I answered no.

> 1. no automatic initialization (weakest) (INIT_STACK_NONE)
2. 0xAA-init everything on the stack (strongest) (INIT_STACK_ALL) (NEW)
choice[1-2?]:

Just pressed enter.

It starts compiling (few minutes) until it fails:



In file included from ../arch/arm64/kernel/machine_kexec.c:27:
../arch/arm64/kernel/cpu-reset.h:19:31: error: static declaration of 'cpu_soft_restart' follows non-static declaration
static inline void __noreturn cpu_soft_restart(unsigned long entry, ^
../arch/arm64/include/asm/proc-fns.h:35:6: note: previous declaration is here
void cpu_soft_restart(phys_addr_t cpu_reset,
^
../arch/arm64/kernel/machine_kexec.c:217:58: error: too many arguments to function call, expected 2, have 4
cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, 0);
~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~
../arch/arm64/include/asm/proc-fns.h:35:1: note: 'cpu_soft_restart' declared here
void cpu_soft_restart(phys_addr_t cpu_reset,
^
2 errors generated.

make[2]: *** [../scripts/Makefile.build:339: arch/arm64/kernel/machine_kexec.o] Error 1
make[1]: *** [/storage/android/android_kernel_oneplus_sm8250/Makefile:1181: arch/arm64/kernel] Error 2
make[1]: *** Waiting for unfinished jobs....

CC arch/arm64/xen/../../arm/xen/grant-table.o

CC arch/arm64/xen/../../arm/xen/p2m.o

CC arch/arm64/xen/../../arm/xen/mm.o

AS arch/arm64/xen/hypercall.o

CC arch/arm64/xen/../../arm/xen/efi.o

AR arch/arm64/xen/built-in.a

make[1]: Leaving directory '/storage/android/android_kernel_oneplus_sm8250/out'

make: *** [Makefile:146: sub-make] Error 2