FORUMS
Remove All Ads from XDA

[REFERENCE] How to compile an Android kernel

13,717 posts
Thanks Meter: 50,713
 
By nathanchance, Recognized Developer / Recognized Contributor on 26th June 2017, 04:38 AM
Post Reply Email Thread
9th May 2019, 09:24 AM |#541  
Junior Member
Thanks Meter: 4
 
More
Quote:
Originally Posted by Uzephi

Odd your OEM didn't give you instructions... Motorola did for most of their releases...

https://github.com/MotorolaMobilityL...X27.109-34.txt is for the Z2.

Edit: I just followed that to install my CAF module, so I wouldn't know for your kernel.

hmm....that guide explains how to install the caf driver,i think I get it .SO from where do I download the prima wlan module files ? I am building an arm kernel for nougat 7.0 (msm8937).
 
 
15th May 2019, 07:40 AM |#542  
Junior Member
Thanks Meter: 4
 
More
Quote:
Originally Posted by Uzephi

Odd your OEM didn't give you instructions... Motorola did for most of their releases...

https://github.com/MotorolaMobilityL...X27.109-34.txt is for the Z2.

Edit: I just followed that to install my CAF module, so I wouldn't know for your kernel.

Thanks. By the way , do the kernel sources provided by OEM's have CAF tags merged in them? If not , then do I have to merge the CAF tag in my stock kernel source and then add the wlan driver or can I add wlan without adding the caf tags?
Thank You
The Following User Says Thank You to rath007 For This Useful Post: [ View ] Gift rath007 Ad-Free
15th May 2019, 02:23 PM |#543  
Uzephi's Avatar
Recognized Contributor
Flag Phoenix
Thanks Meter: 1,730
 
More
Quote:
Originally Posted by rath007

Thanks. By the way , do the kernel sources provided by OEM's have CAF tags merged in them? If not , then do I have to merge the CAF tag in my stock kernel source and then add the wlan driver or can I add wlan without adding the caf tags?
Thank You

Depends on the oem.
15th May 2019, 03:51 PM |#544  
Junior Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by rath007

Thanks. By the way , do the kernel sources provided by OEM's have CAF tags merged in them? If not , then do I have to merge the CAF tag in my stock kernel source and then add the wlan driver or can I add wlan without adding the caf tags?
Thank You

I have the same problem. I have a lenovo device with msm8937.The problem is that the open source code on their website does not have any wlan drivers.There is no reference to what is the current CAF tag or any instructions on how to merge the wlan drivers ? I tried a lot of steps but all failed.I gave up eventully. If you find a solution on how to do it please do tell.
Thanks
17th May 2019, 06:26 AM |#545  
Junior Member
Thanks Meter: 1
 
More
How to select the toolchain for a 64-bit android device?
Thanks for the great introduction. I am very new to kernel customization and I need a help in choosing the right tool-chain for my OnePlus 6T kernel source code.
I have downloaded kernel source from https://github.com/OnePlusOSS/androi...lus_sdm845.git
I found "[ro.product.cpu.abi]: [arm64-v8a]" in device properties. So this device is based on 64-bit architecture.
Then I went to the https://android.googlesource.com/pla...x-android-4.9/ link which you have given in your description. I am confused on which branch I should clone for my device OR is it fine to continue with other step by choosing the master branch from google tool-chains?

Please guide me. I will be very helpful to you.
Thanks.
The Following User Says Thank You to Vats12 For This Useful Post: [ View ] Gift Vats12 Ad-Free
18th May 2019, 02:52 PM |#546  
Was it necessary to quote the entire OP?
Yesterday, 11:08 PM |#547  
RogerF81's Avatar
Senior Member
Flag Mannheim
Thanks Meter: 1,362
 
More
Hello, I have a question: I want to compile a kernel for the Pixel 2 XL. I chose Sultan's, just to learn it. I think I have downloaded and set the correct toolchains, this is what I did:

Code:
PATH="~/tc/linux-x86/bin:~/tc/aarch64-linux-android-4.9/bin:~/tc/arm-linux-androideabi-android-4.9/bin:${PATH}" \
> make -j$(nproc --all) O=out \
>                       ARCH=arm64 \
>                       CC=clang \
>                       CLANG_TRIPLE=aarch64-linux-gnu- \
>                       CROSS_COMPILE=aarch64-linux-android- \
This was the output:
Code:
> 
android/                    .gitmodules
AndroidKernel.mk            include/
arch/                       init/
backported-features         ipc/
block/                      Kbuild
build.config                Kconfig
build.config.clang.lto      kernel/
build.config.debug_api      lib/
build.config.debug_hang     .mailmap
build.config.debug_locking  MAINTAINERS
build.config.debug_memory   Makefile
build.config.gcc            mm/
build.config.kasan          net/
certs/                      out/
COPYING                     README
CREDITS                     REPORTING-BUGS
crypto/                     samples/
Documentation/              scripts/
drivers/                    security/
firmware/                   sound/
fs/                         tools/
.get_maintainer.ignore      usr/
.git/                       virt/
.gitignore                  .wireguard-fetch-lock
> 
android/                    .gitmodules
AndroidKernel.mk            include/
arch/                       init/
backported-features         ipc/
block/                      Kbuild
build.config                Kconfig
build.config.clang.lto      kernel/
build.config.debug_api      lib/
build.config.debug_hang     .mailmap
build.config.debug_locking  MAINTAINERS
build.config.debug_memory   Makefile
build.config.gcc            mm/
build.config.kasan          net/
certs/                      out/
COPYING                     README
CREDITS                     REPORTING-BUGS
crypto/                     samples/
Documentation/              scripts/
drivers/                    security/
firmware/                   sound/
fs/                         tools/
.get_maintainer.ignore      usr/
.git/                       virt/
.gitignore                  .wireguard-fetch-lock
> 
android/                    .gitmodules
AndroidKernel.mk            include/
arch/                       init/
backported-features         ipc/
block/                      Kbuild
build.config                Kconfig
build.config.clang.lto      kernel/
build.config.debug_api      lib/
build.config.debug_hang     .mailmap
build.config.debug_locking  MAINTAINERS
build.config.debug_memory   Makefile
build.config.gcc            mm/
build.config.kasan          net/
certs/                      out/
COPYING                     README
CREDITS                     REPORTING-BUGS
crypto/                     samples/
Documentation/              scripts/
drivers/                    security/
firmware/                   sound/
fs/                         tools/
.get_maintainer.ignore      usr/
.git/                       virt/
.gitignore                  .wireguard-fetch-lock
> 
android/                    .gitmodules
AndroidKernel.mk            include/
arch/                       init/
backported-features         ipc/
block/                      Kbuild
build.config                Kconfig
build.config.clang.lto      kernel/
build.config.debug_api      lib/
build.config.debug_hang     .mailmap
build.config.debug_locking  MAINTAINERS
build.config.debug_memory   Makefile
build.config.gcc            mm/
build.config.kasan          net/
certs/                      out/
COPYING                     README
CREDITS                     REPORTING-BUGS
crypto/                     samples/
Documentation/              scripts/
drivers/                    security/
firmware/                   sound/
fs/                         tools/
.get_maintainer.ignore      usr/
.git/                       virt/
.gitignore                  .wireguard-fetch-lock


I wanted to use this directly, but I only could write this in terminal afterwards:
Code:
>   CROSS_COMPILE_ARM32=arm-linux-androideabi-
Then, the output was the following:

Code:
make[1]: Entering directory '/home/rogerf81/sultan/sultan_kernel/out'
  CHK     include/config/kernel.release
  Using .. as source for kernel
  GEN     ./Makefile
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  CHK     include/generated/asm-offsets.h
  CALL    ../scripts/checksyscalls.sh
  VDSOL   arch/arm64/kernel/vdso/vdso.so.dbg
/usr/bin/ld: unrecognised emulation mode: aarch64linux
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om elf_k1om i386pep i386pe
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [../arch/arm64/kernel/vdso/Makefile:48: arch/arm64/kernel/vdso/vdso.so.dbg] Error 1
make[1]: *** [arch/arm64/Makefile:214: vdso_prepare] Error 2
make[1]: Leaving directory '/home/rogerf81/sultan/sultan_kernel/out'
make: *** [Makefile:154: sub-make] Error 2


So what am I doing wrong? Can someone help me please?
Today, 01:18 AM |#548  
onliner's Avatar
Senior Member
Flag Queens
Thanks Meter: 830
 
More
Quote:
Originally Posted by RogerF81

Hello, I have a question: I want to compile a kernel for the Pixel 2 XL. I chose Sultan's, just to learn it. I think I have downloaded and set the correct toolchains, this is what I did:



This was the output:


I wanted to use this directly, but I only could write this in terminal afterwards:


Then, the output was the following:



So what am I doing wrong? Can someone help me please?

1- The cross compile ARM32 should have the path of the arm toolchain.
2- Sultan uses GCC to build his kernel, so he disabled the Clang-related features in the defconfig (check the defconfig history to revert the commits) and he did some treewide changes to fix GCC warnings that can cause problems with Clang (Again, check the history to revert the commits).
The Following User Says Thank You to onliner For This Useful Post: [ View ] Gift onliner Ad-Free
Today, 05:37 AM |#549  
Junior Member
Thanks Meter: 1
 
More
Quote:
Originally Posted by Sands207

Was it necessary to quote the entire OP?

I am just new to this site and was not familiar with "[Quote]" tag. I have removed that.
Sorry for inconvenience.
Today, 08:54 AM |#550  
RogerF81's Avatar
Senior Member
Flag Mannheim
Thanks Meter: 1,362
 
More
Quote:
Originally Posted by onliner

1- The cross compile ARM32 should have the path of the arm toolchain.
2- Sultan uses GCC to build his kernel, so he disabled the Clang-related features in the defconfig (check the defconfig history to revert the commits) and he did some treewide changes to fix GCC warnings that can cause problems with Clang (Again, check the history to revert the commits).

First of all, thank you so much for your answer!

To point 1: Didn't I do that? Or am I missing something?

To point 2: I missed at least this Thanks for the heads-up. So either I use the same tc which Sultan used, or I have revert these specific commits, to be able to use Clang.


EDIT: Ok, now I tried to compile with GCC. This is what I did (of course in the correct toolchain folders):
Code:
export CROSS_COMPILE=$(pwd)/bin/aarch64-linux-
export CROSS_COMPILE_ARM32=$(pwd)/bin/arm-linux-gnueabi-
and then in the kernel folder:
Code:
export ARCH=arm64 && export SUBARCH=arm64
make clean
with the following output:
Code:
ake[1]: Entering directory '/home/rogerf81/sultan/sultan_kernel/out'
  CLEAN   .
  CLEAN   arch/arm64/kernel/vdso
  CLEAN   arch/arm64/kernel/vdso32
find: ‘arch/arm64/boot/dts/’: No such file or directory
find: ‘arch/arm64/boot/dts/’: No such file or directory
  CLEAN   .tmp_versions
make[1]: Leaving directory '/home/rogerf81/sultan/sultan_kernel/out
'


Code:
make mrproper
with following output:
Code:
make[1]: Entering directory '/home/rogerf81/sultan/sultan_kernel/out'
find: ‘arch/arm64/boot/dts/’: No such file or directory
find: ‘arch/arm64/boot/dts/’: No such file or directory
  CLEAN   scripts/basic
  CLEAN   scripts/kconfig
  CLEAN   include/config include/generated arch/arm64/include/generated
  CLEAN   .config
make[1]: Leaving directory '/home/rogerf81/sultan/sultan_kernel/out'


Code:
make wahoo_defconfig
output:
Code:
make[1]: Entering directory '/home/rogerf81/sultan/sultan_kernel/out'
  HOSTCC  scripts/basic/fixdep
  GEN     ./Makefile
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#
make[1]: Leaving directory '/home/rogerf81/sultan/sultan_kernel/out'


And finally,
Code:
make -j$(nproc --all)
with the final output + errors:
Code:
make[1]: Entering directory '/home/rogerf81/sultan/sultan_kernel/out'
  GEN     ./Makefile
scripts/kconfig/conf  --silentoldconfig Kconfig
  CHK     include/config/kernel.release
  UPD     include/config/kernel.release
  Using .. as source for kernel
  GEN     ./Makefile
  WRAP    arch/arm64/include/generated/asm/bug.h
  WRAP    arch/arm64/include/generated/asm/bugs.h
  WRAP    arch/arm64/include/generated/asm/clkdev.h
  WRAP    arch/arm64/include/generated/asm/cputime.h
  WRAP    arch/arm64/include/generated/asm/current.h
  WRAP    arch/arm64/include/generated/asm/delay.h
  WRAP    arch/arm64/include/generated/asm/div64.h
  WRAP    arch/arm64/include/generated/asm/dma.h
  WRAP    arch/arm64/include/generated/asm/dma-contiguous.h
  WRAP    arch/arm64/include/generated/asm/early_ioremap.h
  WRAP    arch/arm64/include/generated/asm/emergency-restart.h
  WRAP    arch/arm64/include/generated/asm/errno.h
  WRAP    arch/arm64/include/generated/asm/ftrace.h
  WRAP    arch/arm64/include/generated/asm/hash.h
  WRAP    arch/arm64/include/generated/asm/hw_irq.h
  WRAP    arch/arm64/include/generated/asm/ioctl.h
  WRAP    arch/arm64/include/generated/asm/ioctls.h
  WRAP    arch/arm64/include/generated/asm/ipcbuf.h
  WRAP    arch/arm64/include/generated/asm/irq_regs.h
  WRAP    arch/arm64/include/generated/asm/kdebug.h
  WRAP    arch/arm64/include/generated/asm/kmap_types.h
  WRAP    arch/arm64/include/generated/asm/kvm_para.h
  WRAP    arch/arm64/include/generated/asm/local.h
  WRAP    arch/arm64/include/generated/asm/local64.h
  WRAP    arch/arm64/include/generated/asm/mcs_spinlock.h
  WRAP    arch/arm64/include/generated/asm/mm-arch-hooks.h
  WRAP    arch/arm64/include/generated/asm/mman.h
  WRAP    arch/arm64/include/generated/asm/msgbuf.h
  WRAP    arch/arm64/include/generated/asm/msi.h
  WRAP    arch/arm64/include/generated/asm/mutex.h
  WRAP    arch/arm64/include/generated/asm/pci.h
  WRAP    arch/arm64/include/generated/asm/pci-bridge.h
  WRAP    arch/arm64/include/generated/asm/poll.h
  WRAP    arch/arm64/include/generated/asm/preempt.h
  WRAP    arch/arm64/include/generated/asm/resource.h
  WRAP    arch/arm64/include/generated/asm/rwsem.h
  WRAP    arch/arm64/include/generated/asm/sections.h
  WRAP    arch/arm64/include/generated/asm/segment.h
  WRAP    arch/arm64/include/generated/asm/sembuf.h
  WRAP    arch/arm64/include/generated/asm/serial.h
  WRAP    arch/arm64/include/generated/asm/shmbuf.h
  WRAP    arch/arm64/include/generated/asm/simd.h
  WRAP    arch/arm64/include/generated/asm/sizes.h
  WRAP    arch/arm64/include/generated/asm/socket.h
  WRAP    arch/arm64/include/generated/asm/sockios.h
  WRAP    arch/arm64/include/generated/asm/swab.h
  WRAP    arch/arm64/include/generated/asm/switch_to.h
  WRAP    arch/arm64/include/generated/asm/termbits.h
  WRAP    arch/arm64/include/generated/asm/termios.h
  WRAP    arch/arm64/include/generated/asm/topology.h
  WRAP    arch/arm64/include/generated/asm/trace_clock.h
  WRAP    arch/arm64/include/generated/asm/types.h
  WRAP    arch/arm64/include/generated/asm/unaligned.h
  WRAP    arch/arm64/include/generated/asm/user.h
  WRAP    arch/arm64/include/generated/asm/vga.h
  WRAP    arch/arm64/include/generated/asm/xor.h
  WRAP    arch/arm64/include/generated/uapi/asm/kvm_para.h
  CHK     include/generated/uapi/linux/version.h
  UPD     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  HOSTCC  scripts/basic/bin2c
  CC      kernel/bounds.s
  CHK     include/generated/bounds.h
  UPD     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  UPD     include/generated/timeconst.h
  CC      arch/arm64/kernel/asm-offsets.s
  CHK     include/generated/asm-offsets.h
  UPD     include/generated/asm-offsets.h
  CALL    ../scripts/checksyscalls.sh
  LDS     arch/arm64/kernel/vdso/vdso.lds
  VDSOC   arch/arm64/kernel/vdso/vgettimeofday.o
  VDSOA   arch/arm64/kernel/vdso/note.o
  VDSOA   arch/arm64/kernel/vdso/sigreturn.o
  VDSOL   arch/arm64/kernel/vdso/vdso.so.dbg
  VDSOSYM include/generated/vdso-offsets.h
  LDS     arch/arm64/kernel/vdso32/vdso.lds
  VDSOC32   arch/arm64/kernel/vdso32/vgettimeofday.o
  VDSOA32   arch/arm64/kernel/vdso32/sigreturn.o
  VDSOL32   arch/arm64/kernel/vdso32/vdso.so.raw
  HOSTCC  arch/arm64/kernel/vdso32/../../../arm/vdso/vdsomunge
  MUNGE   arch/arm64/kernel/vdso32/vdso.so.dbg
  VDSOSYM include/generated/vdso32-offsets.h
make[3]: *** No rule to make target 'scripts/dtc-aosp/dtc/dtc.c', needed by 'scripts/dtc-aosp/dtc/dtc.o'.  Stop.
make[2]: *** [../scripts/Makefile.build:559: scripts/dtc-aosp] Error 2
make[1]: *** [/home/rogerf81/sultan/sultan_kernel/Makefile:565: scripts] Error 2
make[1]: Leaving directory '/home/rogerf81/sultan/sultan_kernel/out'
make: *** [Makefile:154: sub-make] Error 2


What did I do wrong this time? Do I use the wrong toolchain perhaps? I'm using the tc linked by Sultan for cross_compile and the gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabi tc for cross_compile_arm32.
Or did I point something wrong? Thanks in advance for any help
Today, 02:30 PM |#551  
Junior Member
Thanks Meter: 1
 
More
Hi RogerF81,

I am able to compile the kernel source code for my OnePlus 6T device as following:
- Download latest dtc from https://packages.ubuntu.com/cosmic/a...piler/download and install it.
- Clone kernel source code: git clone https://github.com/OnePlusOSS/androi...lus_sdm845.git
- Clone ToolChain: git clone -b linaro-4.9-arm-linux-androideabi https://github.com/ArchiDroid/Toolchain prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-linaro-4.8
- Open terminal at prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-linaro-4.9 and run: export CROSS_COMPILE=$(pwd)/bin/aarch64-linux-android-
- Navigate to kernel source code path in the same terminal.
- export ARCH=arm64 && export SUBARCH=arm64
- make clean
- make mrproper
- mkdir Out
- make O=Out sdm845_defconfig
- make O=Out DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y DTC_EXT=dtc -j4

Following are the last lines of compilation:
```
CC drivers/media/platform/msm/broadcast/tspp.mod.o
CC drivers/media/platform/msm/dvb/adapter/mpq-adapter.mod.o
CC drivers/media/platform/msm/dvb/demux/mpq-dmx-hw-plugin.mod.o
GZIP arch/arm64/boot/Image.gz
CC drivers/soc/qcom/llcc_perfmon.mod.o
CC drivers/video/backlight/lcd.mod.o
CC net/bridge/br_netfilter.mod.o
LD [M] drivers/char/rdbg.ko
LD [M] drivers/media/platform/msm/broadcast/tspp.ko
LD [M] drivers/media/platform/msm/dvb/adapter/mpq-adapter.ko
LD [M] drivers/media/platform/msm/dvb/demux/mpq-dmx-hw-plugin.ko
LD [M] drivers/soc/qcom/llcc_perfmon.ko
LD [M] drivers/video/backlight/lcd.ko
LD [M] net/bridge/br_netfilter.ko
CAT arch/arm64/boot/Image.gz-dtb
make[1]: Leaving directory '/home/.../KernelCustomization/android_kernel_oneplus_sdm845/Out'
```
If it helps you then I will be glad

--------------------------------------------

I need help at next step i.e.
- What is the correct image file that I should use to flash on my device. Is it arch/arm64/boot/Image.gz-dtb OR arch/arm64/boot/Image.gz OR arch/arm64/boot/Image
- What are the correct steps to flash it. Is there any documentation somewhere for this?

If any can share this knowledge with me OR any relevant link then I will be very thankful to that person.

Happy Codding.
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