FORUMS

[REFERENCE] How to compile an Android kernel

13,740 posts
Thanks Meter: 50,824
 
By nathanchance, Recognized Developer / Recognized Contributor on 26th June 2017, 04:38 AM
Post Reply Email Thread
2nd March 2020, 05:57 PM |#701  
nathanchance's Avatar
OP Recognized Developer / Recognized Contributor
Flag Mesa, AZ
Thanks Meter: 50,824
 
More
Quote:
Originally Posted by wojtoo

@nathanchance thx for great work
But how to build kernel with gcc 9.2.0
could you please add manual for that

Unfortunately, my time nowadays is limited between my job, school, and more important open source projects.

However, compiling with GCC 9.2.0 is the same as compiling with GCC 4.9.4, you point the CROSS_COMPILE variable at the GCC 9.2.0 toolchain (or use PATH and update the CROSS_COMPILE prefix to match) and go from there. There are probably going to be new warnings that you will need to solve and there are potentially some other commits that you will need to pick to get a boot off.

If anyone else wants to pitch in and write something up, I'd be happy to add it to the OP.
The Following 8 Users Say Thank You to nathanchance For This Useful Post: [ View ]
21st March 2020, 04:47 AM |#702  
Junior Member
Thanks Meter: 0
 
More
Cannot Compile
I am using make 4.1 and tried multiple tool chains. Which toolchain do you recommend for Ubuntu 16.04. I am trying to compile the kernel and I am coming to issues like: include/trace/events/sched.h:783:2: error: #error "Unsupported NR_CPUS for lb tracepoint." I am not using -j option.

Can you help to figure it out. I am trying to build the kernel with realtek and ralink modules but I am not able to build it.
28th March 2020, 10:27 AM |#703  
Member
Thanks Meter: 9
 
Donate to Me
More
Trying to do this with the PIxel 4 XL is generating a really bizarre error.

Code:
In file included from ../scripts/selinux/genheaders/genheaders.c:19:
../security/selinux/include/classmap.h:247:2: error: #error New address family defined, please update secclass_map.
  247 | #error New address family defined, please update secclass_map.
      |  ^~~~~
Commands:
Code:
make mrproper
make O=out clean
make O=out mrproper
make O=out ARCH=arm64 floral_defconfig
make O=out ARCH=arm64 menuconfig
PATH=/.../clang-r353983c/bin/:$PATH make -j8 O=out ARCH=arm64 CC=clang CLANG_TRIPLE=aarch64-linux-gnu- CROSS_COMPILE=/.../aarch64-linux-android-4.9/bin/aarch64-linux-android- CROSS_COMPILE_ARM32=/.../arm-linux-androideabi-4.9/bin/arm-linux-androideabi-
I am using commit e58a32340f442ce44af7123d502ba4eec69cefc5 from https://android.googlesource.com/kernel/msm/
The Following User Says Thank You to gudenau For This Useful Post: [ View ] Gift gudenau Ad-Free
28th March 2020, 01:38 PM |#704  
Junior Member
Thanks Meter: 0
 
More
Kernel Compile
You are specifying two paths for cross_compiling.
For arm64 only a 64 bit toolchain will compile.
If I was you I would do.: export CROSS_COMPILE=/path/to/your/chain/aarch64-linux-android-
export ARCH=arm64
It looks like you are building for 64 bit and 32 bit architecture in your PATH but only 64 bit in your make command.

It has been reported on of glibc 2.29 and newer to have the same build error. Perhaps try an older version of glibc than 2.29.

Let me know if it helps. Good Luck.
28th March 2020, 06:21 PM |#705  
Member
Thanks Meter: 9
 
Donate to Me
More
Quote:
Originally Posted by Keskebeu

You are specifying two paths for cross_compiling.
For arm64 only a 64 bit toolchain will compile.
If I was you I would do.: export CROSS_COMPILE=/path/to/your/chain/aarch64-linux-android-
export ARCH=arm64
It looks like you are building for 64 bit and 32 bit architecture in your PATH but only 64 bit in your make command.

It has been reported on of glibc 2.29 and newer to have the same build error. Perhaps try an older version of glibc than 2.29.

Let me know if it helps. Good Luck.

If I don't specify CROSS_COMPILE_ARM32 the build fails, I am using the toolchains from Google.
Clang: https://android.googlesource.com/pla...host/linux-x86
AARCH64: https://android.googlesource.com/pla...ux-android-4.9
ARM: https://android.googlesource.com/pla...ndroideabi-4.9

Don't know why the official toolchain would not be able to build the kernel.
28th March 2020, 08:52 PM |#706  
Junior Member
Thanks Meter: 0
 
More
Kernel Build
________________________________________

https://android.googlesource.com/pla.../android10-dev

Try this toolchain instead. The one you pointed me does not have gcc. I would suggest you use ndk prebuilt toolchain version 16b. Which are best and easy to find.

In your main kernel dir you want to build do with root privileges:

[email protected]#export ARCH=arm64
[email protected]#export CROSS_COMPILE=/path/to/your/toolchain/
aarch64-linux-android-

make clean && make mrproper
make yourdevice_defconfig (this can be found in arch/arm64/configs directory of your building kernel)

make menuconfig
make

You do not need clang to build a kernel. I just ended up building a custom kernel without clang.
29th March 2020, 11:45 PM |#707  
Junior Member
Thanks Meter: 0
 
More
So, I've downloaded the kernel for my ocean device and made it some changes. In step two you mention that I have to download a cross compiler. Can't I run the commands in linux ubuntu console directly? If not so, I'm confused about wich cross compiler to download. Could you give me a little light in this matter? Thank you very much.
PS: It's my first time in everything
30th March 2020, 05:15 AM |#708  
Member
Thanks Meter: 9
 
Donate to Me
More
Quote:
Originally Posted by Keskebeu

________________________________________

https://android.googlesource.com/pla.../android10-dev

Try this toolchain instead. The one you pointed me does not have gcc. I would suggest you use ndk prebuilt toolchain version 16b. Which are best and easy to find.

In your main kernel dir you want to build do with root privileges:

[email protected]#export ARCH=arm64
[email protected]#export CROSS_COMPILE=/path/to/your/toolchain/
aarch64-linux-android-

make clean && make mrproper
make yourdevice_defconfig (this can be found in arch/arm64/configs directory of your building kernel)

make menuconfig
make

You do not need clang to build a kernel. I just ended up building a custom kernel without clang.

But Google builds the kernel with clang and the gcc toolchains have sleeps built in to make them slow.
Today, 03:08 AM |#709  
nathanchance's Avatar
OP Recognized Developer / Recognized Contributor
Flag Mesa, AZ
Thanks Meter: 50,824
 
More
Quote:
Originally Posted by gudenau

Trying to do this with the PIxel 4 XL is generating a really bizarre error.

Code:
In file included from ../scripts/selinux/genheaders/genheaders.c:19:
../security/selinux/include/classmap.h:247:2: error: #error New address family defined, please update secclass_map.
  247 | #error New address family defined, please update secclass_map.
      |  ^~~~~
Commands:
Code:
make mrproper
make O=out clean
make O=out mrproper
make O=out ARCH=arm64 floral_defconfig
make O=out ARCH=arm64 menuconfig
PATH=/.../clang-r353983c/bin/:$PATH make -j8 O=out ARCH=arm64 CC=clang CLANG_TRIPLE=aarch64-linux-gnu- CROSS_COMPILE=/.../aarch64-linux-android-4.9/bin/aarch64-linux-android- CROSS_COMPILE_ARM32=/.../arm-linux-androideabi-4.9/bin/arm-linux-androideabi-
I am using commit e58a32340f442ce44af7123d502ba4eec69cefc5 from https://android.googlesource.com/kernel/msm/

Either build android-10.0.0_r0.49, where this was fixed because of a linux-stable merge or cherry-pick the actual fix: https://android.googlesource.com/ker...f93fe3fffc0d6c
The Following User Says Thank You to nathanchance For This Useful Post: [ View ]
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes