[REFERENCE] How to compile an Android kernel - Android Software/Hacking General [Developers Only]

Introduction
Hello everyone, I will be going over how to compile a kernel from beginning to end!
Prerequisites:
A Linux environment (preferably 64-bit)
Knowledge of how to navigate the command line
Common sense
A learning spirit, there will be no spoonfeeding here
What this guide will cover:
Downloading the source
Downloading a cross compiler
Building the kernel
Flashing the kernel
What this guide will NOT cover:
Setting up a build environment (plenty of existing Linux installation guides)
Adding features to the kernel (plenty of git cherry-picking guides)
I know this has been done before but on a cursory search, I have not seen a guide that was recently updated at all.
1. Downloading the source
If you have a custom kernel you want to build, move along after cloning the kernel using the git clone command below.
If you are compiling your stock kernel, it is ultimately up to you to know where to get your kernel source from but here are some common places:
Google: https://android.googlesource.com/kernel/msm/ (pick your architecture and look at the branches)
LG: http://opensource.lge.com/index
Samsung: http://opensource.samsung.com/reception.do
HTC: https://www.htcdev.com/devcenter/downloads
OnePlus: https://github.com/OnePlusOSS
Motorola: https://github.com/MotorolaMobilityLLC
Sony: https://github.com/sonyxperiadev/kernel
To download the kernel, you can either use git clone or download the tarball and extract it:
Code:
git clone -b <branch_to_checkout> <url> <desired_folder_name>
OR
tar -xvf <filename>
For example, if I wanted to grab the latest Nexus 6P from Google above:
Code:
git clone -b android-msm-angler-3.10-nougat-mr2 https://android.googlesource.com/kernel/msm/ angler
This will clone the kernel/msm repo into an angler folder and checkout the android-msm-angler-3.10-nougat-mr2 automatically.
I can try and help you locate your source if necessary.
2. Downloading a cross compiler
Since most Android devices are ARM based, we need a compiler that is targeting ARM devices. A host (or native) compiler will not work unless you are compiling on another ARM device.
You can either compile one yourself if you know how (crosstool-NG is a great tool for this) or download a prebuilt one. Luckily Google provides a high quality toolchain for this, in both an arm (32-bit) and arm64 (64-bit). It's up to you to know the architecture of your device. Typically speaking, most devices in the past two-three years are 64-bit.
Another popular toolchain is UberTC, which can be found here: https://bitbucket.org/matthewdalex/. Most kernels will need patches for anything higher than 4.9 and while I don't mind assisting with finding them, you should compile with Google's toolchain first.
Once you have decided, clone the toolchain:
Code:
git clone <url>
3. Compile the kernel
1. Point the Makefile to your compiler (run this from within the toolchain folder!!)
Code:
export CROSS_COMPILE=$(pwd)/bin/<toolchain_prefix>-
Example:
Code:
export CROSS_COMPILE=$(pwd)/bin/aarch64-linux-android-
NOTE #1: For kernels that can be compiled with Clang (like the Pixel 2), see this guide. I will support it here if there are any questions.
NOTE #2: Pixel and Pixel 2 users, you will need to follow these steps as well if compiling for Android Pie.
2. Tell the Makefile the architecture of the device
Code:
export ARCH=<arch> && export SUBARCH=<arch>
Example:
Code:
export ARCH=arm64 && export SUBARCH=arm64
3. Locate your proper defconfig
Navigate to the arch/<arch>/configs folder within the kernel source (e.g. arch/arm64/configs) and locate your device's or custom kernel developer's proper config file. For example, it will often be in the form of <codename>_defconfig or <kernel_name>_defconfig. Generic Qualcomm configs may be used as well (msm-perf_defconfig, msmcortex-perf_defconfig). When in doubt, ask here if you are confused. A defconfig tells the compiler what options to add to the kernel.
4. Build the kernel
Code:
make clean
make mrproper
make <defconfig_name>
make -j$(nproc --all)
If those commands succeed, you will have an Image, Image-dtb, Image.gz, or Image.gz-dtb file at the end.
If it failed, as was pointed out to me by @flar2 while making a complete idiot of myself, you may need to specify an output directory while making new CAF based kernels, like so:
Code:
mkdir -p out
make O=out clean
make O=out mrproper
make O=out <defconfig_name>
make O=out -j$(nproc --all)
If after that something is still broken, you may need to fix some headers or other issues. If it is a custom kernel, bring it up with your developer.
If it's an OEM, it's up to you to try and fix it, which we can assist with.
4. Flash the kernel
Assuming you were able to compile the kernel successfully, you now need to flash it! I will be covering two different ways to flash a compiled kernel: unpacking and repacking the boot image by hand using Android Image Kitchen or AnyKernel2, both by the brilliant @osm0sis. If there are any per-device nuances, please let me know and I'll add them here! Additionally, this section can vary drastically by device, you may need to consult developers of your device for assistance if necessary.
Android Image Kitchen
Pull your device's boot image from the latest image available for your device (whether it be a ROM or stock)
Download the latest Android Image Kitchen from this thread.
Run the following with the boot image:
Code:
unpackimg.sh <image_name>.img
Locate the zImage file and replace it with your kernel image (rename it to what came out of the boot image)
Run the following to repack:
Code:
repackimg.sh
Flash the new boot image with fastboot or TWRP!
AnyKernel2
Download the latest AnyKernel2 zip: https://github.com/osm0sis/AnyKernel2/archive/master.zip
Apply this patch to clean out all of the demo files:
Code:
wget https://github.com/nathanchance/AnyKernel2/commit/addb6ea860aab14f0ef684f6956d17418f95f29a.diff
patch -p1 < addb6ea860aab14f0ef684f6956d17418f95f29a.diff
rm addb6ea860aab14f0ef684f6956d17418f95f29a.diff
Place your kernel image in the root of the file.
Open the anykernel.sh file and modify the following values:
kernel.string: your kernel name
device.name#: List all of your device's codenames (from the /system/build.prop: ro.product.device, ro.build.product)
block: Your boot image's path in your fstab. The fstab can be opened from the root of your device and it will look something like this:
https://android.googlesource.com/device/huawei/angler/+/master/fstab.angler
The first column is the value you want to set block to.
After that, zip up the kernel and flash it!
Code:
zip -r9 kernel.zip * -x README.md kernel.zip
Tips and tricks
1. Remove GCC wrapper
A lot of kernels from CAF include a Python script that will essentially turn on -Werror, causing your build to error at the most benign stuff. This is necessary with higher GCC versions as there are a lot more warnings.
Here is the diff of what you need to change in the Makefile:
Code:
diff --git a/Makefile b/Makefile
index 1aaa760f255f..bfccd5594630 100644
--- a/Makefile
+++ b/Makefile
@@ -326,7 +326,7 @@ include $(srctree)/scripts/Kbuild.include
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
-REAL_CC = $(CROSS_COMPILE)gcc
+CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
@@ -340,10 +340,6 @@ DEPMOD = /sbin/depmod
PERL = perl
CHECK = sparse
-# Use the wrapper for the compiler. This wrapper scans for new
-# warnings and causes the build to stop upon encountering them.
-CC = $(srctree)/scripts/gcc-wrapper.py $(REAL_CC)
-
CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
-Wbitwise -Wno-return-void $(CF)
CFLAGS_MODULE =
2. Using a higher level GCC toolchain
Using a higher GCC toolchain (5.x, 6.x, 7.x or even 8.x) will require you to nuke the GCC wrapper script as above and use a unified GCC header file (pick the following if you have an include/linux/compiler-gcc#.h file):
3.4/3.10: https://git.kernel.org/pub/scm/linu...h?id=a4a4f1cd733fe5b345db4e8cc19bb8868d562a8a
3.18: https://git.kernel.org/pub/scm/linu...h?id=677fa15cd6d5b0843e7b9c58409f67d656b1ec2f
You may get a lot of warnings but they are not entirely necessary to fix.
3. Adding upstream Linux to kernel source
Once you have gotten familiar with git and the compilation process, you should consider upstreaming your kernel. This will allow you to stay on top of CVE and bug fixes by staying up to date with the latest work of the Linux kernel developers.
Receiving help
I am happy to answer anything that I touched on in this guide. I may point you to another thread if it's better suited but I don't mind off topic (within reason) within the thread. I also want this to be a collaborative effort; other developers, if you have something to add, correct, or improve upon, please let me know!
I am particular in how people ask for help. I do NOT respond to posts asking for a hand out ("How do I fix this?", "Please fix this!", etc.). I only respond to posts with clear logs and steps that you have tried. Basically, show me that you have read this guide and have a specific issue. I am not here to hold your hand through this, this is a developers' forum.

You're on fire with this kernel stuff
Sent from my LEX727 using XDA Labs

Nice and clear introduction on how to build a kernel. This small how-to was so simple, I can keep it in my head! Awesome!

A really helpful guide much needed around for upcoming developers. This is the perfect guide for them. Nice work ?
Sent from my ONE A2003 using Tapatalk

The guys a Feckn Champ.
Thanks a lot!!.

Thanks @The Flash
Enviado desde mi Nexus 6 mediante Tapatalk

The Flash said:
Introduction
I am happy to answer anything that I touched on in this guide. I may point you to another thread if it's better suited but I don't mind off topic (within reason) within the thread. I also want this to be a collaborative effort; other developers, if you have something to add, correct, or improve upon, please let me know!
I am particular in how people ask for help. I do NOT respond to posts asking for a hand out ("How do I fix this?", "Please fix this!", etc.). I only respond to posts with clear logs and steps that you have tried. Basically, show me that you have read this guide and have a specific issue. I am not here to hold your hand through this, this is a developers' forum.
Click to expand...
Click to collapse
On a scale of 1-10 how much Off-Topic is allowed ? :highfive::laugh::silly:
Nice guide :good: :highfive: ..

I have been using ./build_kernel.sh to compile kernels as was suggested by another guide and I'm wondering if there's any pros or cons doing it that way as opposed to using the make defconfig way.
They seem to be working ok but this is the second guide on xda that suggest the way you're doing it and I'm definitely open to change if this way is better. Any thoughts on the two methods would be much appreciated. I also would like to say thanks for these new guides as finding kernel dev info for newbies is very scarce and mostly outdated. I really look forward to seeing this thread take off. :good:

kevintm78 said:
I have been using ./build_kernel.sh to compile kernels as was suggested by another guide and I'm wondering if there's any pros or cons doing it that way as opposed to using the make defconfig way.
They seem to be working ok but this is the second guide on xda that suggest the way you're doing it and I'm definitely open to change if this way is better. Any thoughts on the two methods would be much appreciated. I also would like to say thanks for these new guides as finding kernel dev info for newbies is very scarce and mostly outdated. I really look forward to seeing this thread take off. :good:
Click to expand...
Click to collapse
Well this build_kernel.sh script is most likely doing just this. I personally use a script to compile and package my kernel, I would never do the "manual" way like this once you know how.

I have updated the OP with a note about compiling newer CAF releases (3.18 and 4.4 to my knowledge). As was pointed out by @flar2 while I was making an idiot of myself accusing him of violating the GPL (for which I truly do apologize), you may need to specify an output directory (by adding an O= flag). This is actually done automatically when a ROM compiles a kernel inline so you will only run into this while compiling standalone.
I have added it to my script here if you want an idea of how to add it to yours.

So here i'am what should i do to fix the initramfs problem?
I tried "chmod -R a+x kernel" but i still get the same problem.

AhmAdDev99 said:
So here i'am what should i do to fix the initramfs problem?
I tried "chmod -R a+x kernel" but i still get the same problem.
Click to expand...
Click to collapse
Why aren't you compiling in your home folder?

The Flash said:
Why aren't you compiling in your home folder?
Click to expand...
Click to collapse
Moved both kernel source and gcc to /home but still the same problem

AhmAdDev99 said:
Moved both kernel source and gcc to /home but still the same problem
Click to expand...
Click to collapse
Have you tried the bit about specifying an out folder?

The Flash said:
Have you tried the bit about specifying an out folder?
Click to expand...
Click to collapse
Yes , And this is exactly what i get
GEN /Kernel/android_kernel_samsung_t1-android-4.4/out/Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
GEN /Kernel/android_kernel_samsung_t1-android-4.4/out/Makefile
CHK include/linux/version.h
UPD include/linux/version.h
CHK include/generated/utsrelease.h
UPD include/generated/utsrelease.h
Using /Kernel/android_kernel_samsung_t1-android-4.4 as source for kernel
HOSTCC scripts/genksyms/genksyms.o
Generating include/generated/mach-types.h
CC kernel/bounds.s
GEN include/generated/bounds.h
CC arch/arm/kernel/asm-offsets.s
SHIPPED scripts/genksyms/lex.c
SHIPPED scripts/genksyms/parse.h
SHIPPED scripts/genksyms/keywords.c
SHIPPED scripts/genksyms/parse.c
HOSTCC scripts/genksyms/lex.o
CC scripts/mod/empty.o
HOSTCC scripts/mod/mk_elfconfig
GEN include/generated/asm-offsets.h
CALL /Kernel/android_kernel_samsung_t1-android-4.4/scripts/checksyscalls.sh
HOSTCC scripts/genksyms/parse.o
HOSTCC scripts/selinux/genheaders/genheaders
MKELF scripts/mod/elfconfig.h
HOSTCC scripts/mod/file2alias.o
HOSTCC scripts/selinux/mdp/mdp
HOSTCC scripts/mod/modpost.o
HOSTCC scripts/kallsyms
HOSTLD scripts/genksyms/genksyms
HOSTCC scripts/conmakehash
HOSTCC scripts/recordmcount
HOSTCC scripts/mod/sumversion.o
HOSTLD scripts/mod/modpost
CHK include/generated/compile.h
CC init/main.o
HOSTCC usr/gen_init_cpio
CC arch/arm/vfp/vfpmodule.o
UPD include/generated/compile.h
CC init/do_mounts.o
GEN usr/initramfs_data.cpio
File ../../ramdisk.cpio could not be opened for reading
line 32
File ../../ramdisk-recovery.cpio could not be opened for reading
line 33
/Kernel/android_kernel_samsung_t1-android-4.4/usr/Makefile:67: recipe for target 'usr/initramfs_data.cpio' failed
make[2]: *** [usr/initramfs_data.cpio] Error 255
/Kernel/android_kernel_samsung_t1-android-4.4/Makefile:945: recipe for target 'usr' failed
make[1]: *** [usr] Error 2
make[1]: *** Waiting for unfinished jobs....
AS arch/arm/vfp/entry.o
AS arch/arm/vfp/vfphw.o
CC arch/arm/vfp/vfpsingle.o
CC arch/arm/vfp/vfpdouble.o
CC init/do_mounts_rd.o
CC init/do_mounts_initrd.o
CC init/initramfs.o
CC init/calibrate.o
CC init/version.o
LD arch/arm/vfp/vfp.o
LD arch/arm/vfp/built-in.o
LD init/mounts.o
LD init/built-in.o
Makefile:130: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

I've been working a little more on my Pixel XL kernel. Question...
I do:
Code:
make clean && make mrproper
make marlin_defconfig
make menuconfig
I go through several options, save, and exit. But when I do "git status", it thinks nothing has changed? I'm not sure if that's true, or if it just doesn't track whatever files were modified by menuconfig (of which I have no idea which ones they are).

chevycam94 said:
I've been working a little more on my Pixel XL kernel. Question...
I do:
Code:
make clean && make mrproper
make marlin_defconfig
make menuconfig
I go through several options, save, and exit. But when I do "git status", it thinks nothing has changed? I'm not sure if that's true, or if it just doesn't track whatever files were modified by menuconfig (of which I have no idea which ones they are).
Click to expand...
Click to collapse
I'm sorry I forgot to reply to your message, I looked at it then left my computer. make menuconfig saves the changes to the .config file in the kernel source. You need to copy that file to your arch/arm64/configs/<defconfig_name>.

The Flash said:
I'm sorry I forgot to reply to your message, I looked at it then left my computer. make menuconfig saves the changes to the .config file in the kernel source. You need to copy that file to your arch/arm64/configs/<defconfig_name>.
Click to expand...
Click to collapse
No problem. I'm not in a huge rush. It builds, and runs better than any kernel I have tried yet. Not joking.
So you're saying I need to copy the contents of the .config file INTO the "marlin_defconfig" file? Just append those lines to the end of the file?
Also, did I mention my little headache with my 9 "section_mismatch" errors? Doesn't seem to affect anything, but on this same build VM, I can build any other kernel source without any issues at all. So strange.

chevycam94 said:
No problem. I'm not in a huge rush. It builds, and runs better than any kernel I have tried yet. Not joking.
So you're saying I need to copy the contents of the .config file INTO the "marlin_defconfig" file? Just append those lines to the end of the file?
Also, did I mention my little headache with my 9 "section_mismatch" errors? Doesn't seem to affect anything, but on this same build VM, I can build any other kernel source without any issues at all. So strange.
Click to expand...
Click to collapse
You should just be able to copy the whole file (cp .config arch/arm64/configs/marlin_defconfig).
You could run a git bisect on your kernel source and see if there is a commit causing those mismatch errors. Very rarely is that a result of a toolchain or environment configuration.

Hi..Sir Flash,
I want to ask a question for ARM Device. ( Nexus 6 )
This is right method for ARM?
example:
- - - - -
export CROSS_COMPILE=${HOME}/Kernel/Toolchain/bin/arm-eabi-
export ARCH=arm && export SUBARCH=arm
make clean && make mrproper
make shamu_defconfig
make -j$(nproc --all)
- - - - -
I want to know this about.
If this method is wronged, Please teach me Sir.
Thanks.
•••
Sent from my Google Nexus 5X using XDA Labs

Related

[Q] Building Nexus S kernel

With the official documentation being so out dated, I am having trouble compiling the kernel for the Nexus S.
I am running Ubuntu 10.10 64 bit
Here is where I stand:
Can anyone help me identify what I am doing wrong?
dirtmikeATstrabo:~/bin/kernel/samsung$ export ARCH=arm
dirtmikeATstrabo:~/bin/kernel/samsung$ export CROSS_COMPILE=arm-eabi-
dirtmikeATstrabo:~/bin/kernel/samsung$ make herring_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/basic/docproc
HOSTCC scripts/basic/hash
HOSTCC scripts/kconfig/conf.o
scripts/kconfig/conf.c: In function \u2018conf_askvalue\u2019:
scripts/kconfig/conf.c:105: warning: ignoring return value of \u2018fgets\u2019, declared with attribute warn_unused_result
scripts/kconfig/conf.c: In function \u2018conf_choice\u2019:
scripts/kconfig/conf.c:307: warning: ignoring return value of \u2018fgets\u2019, declared with attribute warn_unused_result
HOSTCC scripts/kconfig/kxgettext.o
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
arch/arm/configs/herring_defconfig:320:warning: override: reassigning to symbol LOCALVERSION_AUTO
arch/arm/configs/herring_defconfig:330:warning: override: reassigning to symbol NET_ACTIVITY_STATS
#
# configuration written to .config
#
dirtmikeATstrabo:~/bin/kernel/samsung$ make
scripts/kconfig/conf -s arch/arm/Kconfig
include/config/auto.conf:117:warning: symbol value 'elf64-x86-64' invalid for OUTPUT_FORMAT
include/config/auto.conf:174:warning: symbol value 'arch/x86/configs/x86_64_defconfig' invalid for ARCH_DEFCONFIG
include/config/auto.conf:399:warning: symbol value '-fcall-saved-rdi -fcall-saved-rsi -fcall-saved-rdx -fcall-saved-rcx -fcall-saved-r8 -fcall-saved-r9 -fcall-saved-r10 -fcall-saved-r11' invalid for ARCH_HWEIGHT_CFLAGS
*** Error during update of the kernel configuration.
make[2]: *** [silentoldconfig] Error 1
make[1]: *** [silentoldconfig] Error 2
make: *** No rule to make target `include/config/auto.conf', needed by `include/config/kernel.release'. Stop.
dirtmikeATstrabo:~/bin/kernel/samsung$
Can anyone help me out?
Thanks in advance,
Mike
Good to see additional people taking a stab at building a kernel. Because of work I don't have much time for developing but I'll pitch in where I can.
Why was this moved to Q&A. Building a kernel is development, is it not? Plus a lot more people will see it in that section versus Q&A.
jlevy73 said:
Why was this moved to Q&A. Building a kernel is development, is it not? Plus a lot more people will see it in that section versus Q&A.
Click to expand...
Click to collapse
I agree and thanks jlevy73!
Moved back to development, as this is most certainly working on developing. I apologize to the OP for any mod that may have moved this, and I assure you it was purely by mistake. Thank you for your understanding.
I got a lot of good help over at the cyanogenmod IRC when I was compiling my first kernel for the N1: http://www.cyanogenmod.com/irc
Jlevy also helped me out
Another source of good information is from xda member Gr8gorilla http://forum.xda-developers.com/member.php?u=2322181
He did a lot of kernel development for the N1 and now for Glacier but he's a good guy and knows a ton about kernels. Might be a good person to send a pm to and see if he can help out.
Agree about Gr8gorilla, this was the post that got me rolling: http://forum.xda-developers.com/showthread.php?t=662110
He also answered a few PMs I sent him when I was stuck.
Looks like about what I do. The only difference is that I do the build with:
make ARCH=arm CROSS_COMPILE=arm-eabi-
Which should be the same as what you are doing with your exports. But maybe worth a shot?
I am also having a difficult time getting a working kernel. However, I was able to fully build the kernel and did not get any error messages. This is what I did:
Code:
make ARCH=arm clean
make ARCH=arm herring_defconfig
make -j4 ARCH=arm CROSS_COMPILE=arm-eabi-
However the resulting kernel (zImage right???) wont boot. All I've done so far is pull the kernel from AOSP.
yes if you are just building the kernel it will be a resulting zImage that you will get.
you can then do either:
fastboot boot zimage <path to your zimage> - this will load the kernel as a one time boot, and upon the next reboot it will fall back to your original kernel.
fastboot flash zimage <path to your zimage> - this one will permanently flash the kernel to your phone.
the first option is very useful when developing your kernel and testing for issues etc.
BTW anyone who gets the kernel to build for the S, maybe play around with the batt driver and see if any optimizations are possible? just a thought.
RogerPodacter said:
fastboot boot zimage <path to your zimage> - this will load the kernel as a one time boot, and upon the next reboot it will fall back to your original kernel.
Click to expand...
Click to collapse
I tried that it resulted in more of the same The command I entered was (note I did not rename the output file, didn't seem necessary):
Code:
fastboot boot zimage zImage [note, the second zImage being my kernel]
I also tried which seems more appropriate:
Code:
fastboot boot zImage
Seems like I missed something during compiling?
Well I got my kernel to boot after a few varied attempts. I feel slightly stupid now, but it was a lot more simple that I imagined to be. Fastboot boot (or flash) expects a boot.img, not the kernel itself. Once I built a boot.img with my kernel it worked fine!
So now onto figuring out how to customize it!
ritcereal said:
I tried that it resulted in more of the same The command I entered was (note I did not rename the output file, didn't seem necessary):
Code:
fastboot boot zimage zImage [note, the second zImage being my kernel]
I also tried which seems more appropriate:
Code:
fastboot boot zImage
Seems like I missed something during compiling?
Click to expand...
Click to collapse
i should have said the second zImage must be the exact path to where your zimage is on your computer hard drive, AND it is case sensitive, so you must type zImage and not zimage.
anyway all you have to do if you want to edit the kernel is i'm sure you pulled down all the code on your ubuntu machine, just go find the driver/file you want to tweak, change the code, re-compile and flash that zimage and see. i've literally gone thru 75 zimages in one night just tweaking and flashing over and over till i got something that worked. brick my phone be damned, i didnt care! i attempted to load anything on my phone, withnand backups just in case...
RogerPodacter said:
i should have said the second zImage must be the exact path to where your zimage is on your computer hard drive, AND it is case sensitive, so you must type zImage and not zimage.
anyway all you have to do if you want to edit the kernel is i'm sure you pulled down all the code on your ubuntu machine, just go find the driver/file you want to tweak, change the code, re-compile and flash that zimage and see. i've literally gone thru 75 zimages in one night just tweaking and flashing over and over till i got something that worked. brick my phone be damned, i didnt care! i attempted to load anything on my phone, withnand backups just in case...
Click to expand...
Click to collapse
I tried doing it with the proper case on the zimage hence I had done:
Code:
fastboot boot zimage ./zImage
And it just wouldn't boot. It kept telling me it received boot.img lol so I don't know what I'm still missing
ritcereal said:
I am also having a difficult time getting a working kernel. However, I was able to fully build the kernel and did not get any error messages. This is what I did:
Code:
make ARCH=arm clean
make ARCH=arm herring_defconfig
make -j4 ARCH=arm CROSS_COMPILE=arm-eabi-
However the resulting kernel (zImage right???) wont boot. All I've done so far is pull the kernel from AOSP.
Click to expand...
Click to collapse
I can make ARCH=arm clean fine
I can make ARCH=arm herring_defconfig fine
I cannot make -j4 ARCH=arm CROSS_COMPILE=arm-eabi-
This is my output...I do know how to fix this. This was my originial post. Can anybody help me understand what the problem is? Please??
msATstrabo:~/bin/kernel/samsung$ make ARCH=arm clean
msATstrabo:~/bin/kernel/samsung$ make ARCH=arm herring_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/basic/docproc
HOSTCC scripts/basic/hash
HOSTCC scripts/kconfig/conf.o
scripts/kconfig/conf.c: In function \u2018conf_askvalue\u2019:
scripts/kconfig/conf.c:105: warning: ignoring return value of \u2018fgets\u2019, declared with attribute warn_unused_result
scripts/kconfig/conf.c: In function \u2018conf_choice\u2019:
scripts/kconfig/conf.c:307: warning: ignoring return value of \u2018fgets\u2019, declared with attribute warn_unused_result
HOSTCC scripts/kconfig/kxgettext.o
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
arch/arm/configs/herring_defconfig:320:warning: override: reassigning to symbol LOCALVERSION_AUTO
arch/arm/configs/herring_defconfig:330:warning: override: reassigning to symbol NET_ACTIVITY_STATS
#
# configuration written to .config
#
msATstrabo:~/bin/kernel/samsung$ make -j4 ARCH=arm CROSS_COMPILE=arm-eabi-
scripts/kconfig/conf -s arch/arm/Kconfig
include/config/auto.conf:117:warning: symbol value 'elf64-x86-64' invalid for OUTPUT_FORMAT
include/config/auto.conf:174:warning: symbol value 'arch/x86/configs/x86_64_defconfig' invalid for ARCH_DEFCONFIG
include/config/auto.conf:399:warning: symbol value '-fcall-saved-rdi -fcall-saved-rsi -fcall-saved-rdx -fcall-saved-rcx -fcall-saved-r8 -fcall-saved-r9 -fcall-saved-r10 -fcall-saved-r11' invalid for ARCH_HWEIGHT_CFLAGS
*** Error during update of the kernel configuration.
make[2]: *** [silentoldconfig] Error 1
make[1]: *** [silentoldconfig] Error 2
make: *** No rule to make target `include/config/auto.conf', needed by `include/config/kernel.release'. Stop.
msATstrabo:~/bin/kernel/samsung$
I would try it again with a fresh copy from kernel.org and see if the error continues. The kernel compiled fine for me without any changes.
What distribution (and arch) are you compiling on?
ritcereal said:
I would try it again with a fresh copy from kernel.org and see if the error continues. The kernel compiled fine for me without any changes.
What distribution (and arch) are you compiling on?
Click to expand...
Click to collapse
Ubuntu 10.10 64 bit.
I will try your suggestion.
I've been building on Ubuntu 10.04 64 bit and these should be similar enough to just work. Suppose if you keep having issues you could try 10.04 in a virtual machine to test but I doubt that will be necessary.
ritcereal said:
I've been building on Ubuntu 10.04 64 bit and these should be similar enough to just work. Suppose if you keep having issues you could try 10.04 in a virtual machine to test but I doubt that will be necessary.
Click to expand...
Click to collapse
This did the trick. Somehow there must of been some symlink hanging around. I suppose maybe a distclean would of worked to? Regardless, it's finally building!!!! YAY! Thanks a lot.
In short -
git clone http://android.git.kernel.org/kernel/samsung.git
make ARCH=arm herring_defconfig
make -j4 ARCH=arm CROSS_COMPILE=arm-eabi-

[GUIDE] How to Build and Package a Kernel [D2]

This thread aims to be a comprehensive guide to building and packaging kernels for US Variant Samsung Galaxy SIIIs
In my opinion, a kernel is a great way to get into building things for your device and its pretty easy to do too.
Intro
What is a kernel?
http://en.wikipedia.org/wiki/Kernel_(computing)
This guide is for US SGSIII's (d2att,d2cri,d2mtr,d2spr,d2tmo,d2usc,d2vzw,others?)
It may be possible to adapt this to other devices, but I am not responsible for anything that happens should you try to do this.
This guide assumes you have a general knowledge of the Linux operating system. If you've never used it, you might consider playing around
with it for awhile before attempting this guide.
Click to expand...
Click to collapse
Prerequisites
On all devices you must be rooted, on Verizon SGS3 (d2vzw) you must also have the unlocked (VRALE6) bootloader installed.
This is not the thread for figuring out how to do this. You can use the forum's search function to figure out how to do this on your device.
You'll need a computer or a virtual machine running ubuntu. You may be able to figure out how to get this working on other distributions,
but since ubuntu is generally the most accepted distribution to use for building android things, I'll stick to using that here.
At the time of this writing, I'm using ubuntu 12.10, 64-bit.
You'll need to install some packages on your ubuntu machine:
Code:
sudo apt-get install build-essential git zip unzip
On 64-bit you'll also need some multilib and 32-bit compatibility packages:
Code:
sudo apt-get install gcc-multilib g++-multilib lib32z1-dev
Click to expand...
Click to collapse
Setting up the Build Environment
Next, you'll need a toolchain which is used to actually build the kernel. You may download one of these:
GCC 4.4.3: Download || Mirror
GCC 4.6: Download || Mirror
GCC 4.7: Download || Mirror
If you aren't sure, go for 4.4.3 or 4.6.
4.7 requires some code changes to work. The original kernel developer may or may not have made these changes.
Here is what I needed to do in order for 4.7 to build, boot and have wifi work:
https://github.com/invisiblek/linux-msm-d2/commit/f8d7199d37cfbfa1bcb6b4bcae3fc15ae71fbdea
https://github.com/invisiblek/linux-msm-d2/commit/ea58076501e5874db7b934c215c4dae81ddfd0a6
The toolchains are also available in the android NDK.
*** There are many toolchains out there, some of you may know of the Linaro toolchain which is aimed to optimize your binary even further ***
*** If you choose to use a different toolchain, that is fine. Keep in mind that you may run into issues depending on the toolchain you use ***
You can check what your currently running kernel was built with by issuing these commands:
Code:
adb root
adb shell cat /proc/version
It should return something like:
Linux version 3.4.0-cyanogenmod-gc4f332c-00230-g93fb4aa-dirty ([email protected]) (gcc version 4.7 (GCC) ) #134 SMP PREEMPT Thu Feb 28 00:22:41 CST 2013
Click to expand...
Click to collapse
This shows my particular kernel here was built with GCC 4.7
You can use wget to download one of the links from above, in this instance we'll download version 4.4.3 from the first link:
Code:
wget http://invisiblek.org/arm-eabi-4.4.3.tar.bz2
Extract this to somewhere you will remember, probably your home directory.
Code:
mkdir arm-eabi-4.4.3
tar -xf arm-eabi-4.4.3.tar.bz2 -C arm-eabi-4.4.3/
Click to expand...
Click to collapse
Obtaining Source
Find someone's source to use as a base. This can be a source archive from Samsung, a kernel tree from CyanogenMod, or any other developer around that makes kernels for your device.
TIMEOUT
This is a good spot to stop and take note that the Linux kernel is licensed under the GNU General Public License (GPL): http://www.gnu.org/licenses/gpl-2.0.html
What does this mean you ask? It means that if you plan to share your kernel with the community (if it's good, please do so!) then you MUST share your
source code as well. I am not liable for what you choose to do once you start building kernels, but know this: if you share your kernel and do not
provide source code for it, you will get warnings from XDA for a determined amount of time, after that you may have your threads closed, deleted and
possibly your user account terminated. This is extremely important!
Also, you may run into more problems than just XDA. There are organizations out there that do take action if you consistently refuse to comply with the GPL.
I recommend you read this: http://www.gnu.org/licenses/gpl-2.0.html so that you are familiar with what legalities you are getting yourself into.
The main thing to remember is to share your source code if you decide to share your built kernel.
Click to expand...
Click to collapse
In this instance, we will use CyanogenMod's kernel source for the US Galaxy S3's. You may browse the source code here:
https://github.com/CyanogenMod/android_kernel_samsung_d2
You'll notice that the branch there is cm-10.1
This is the default branch of this repository on github. This means that if you intend to build this branch, you'll need to use it on CM version 10.1. Most
likely it will not function on another version.
To obtain the source code:
Code:
git clone https://github.com/CyanogenMod/android_kernel_samsung_d2
This will take a little while, be patient.
When done, you'll have a directory called android_kernel_samsung_d2, cd into this directory.
Code:
cd android_kernel_samsung_d2
Next, you'll need to set up a couple environment variables. These tell the system two things:
1. What CPU architecture to build for, in this case arm
2. Where to find the toolchain we downloaded earlier, so that the system can cross compile for arm
Code:
export ARCH=arm
export CROSS_COMPILE=~/arm-eabi-4.4.3/bin/arm-eabi-
You'll need to set these variables on each new session. You can modify your Makefile in the root of your kernel tree in order to have these set permanently.
Click to expand...
Click to collapse
Building
At this point you can make any changes to the source code that you want. If this is your first time, I recommend not making any changes and make sure you have a
sane build environment before adding any complications.
When you build a kernel, you need to choose a defconfig. This is a specialized configuration file, specifically tailored for your device.
CyanogenMod names their defconfigs for their devices like so: cyanogen_<device>_defconfig and they are located in arch/arm/configs/
Code:
ls arch/arm/configs/cyanogen*
In this example, we will build for d2vzw.
Set up your tree to build for the d2vzw:
Code:
make cyanogen_d2vzw_defconfig
(do this in your kernel's root directory, in this example it was android_kernel_samsung_d2/ )
Now you are ready to build:
First, determine how many cpu's your computer has. You'll use this number to determine how many jobs the compiler command will use. The more jobs you can use, the more
cpu threads the compile will take advantage of, thus you'll get faster builds. If you don't know, just assume you'll use the number 2. We'll use 2 as an example here.
Code:
make -j2
Where 2 is the number of CPU cores your build system has.
And now we wait...until it's done compiling...
You'll know it successfully compiled when you have this line when it stops:
Kernel: arch/arm/boot/zImage is ready
Click to expand...
Click to collapse
PROTIP:
If it stops somewhere other than "zImage is ready" then you had build errors. Try running the 'make' command with no options after it. This will run the compile on a single thread
and will cause it to stop compiling as soon as it hits an error. When you run it on multiple threads, it definitely goes much faster, but if an error occurs, the console doesn't stop
until it finishes all of its threads. Causing you to have to scroll up and search around for an error
Click to expand...
Click to collapse
Now, assuming the build completed successfully, you have two things you are concerned with: A zImage (the kernel binary itself) and your kernel modules, which get built based
on what was configured in your defconfig.
You'll find your zImage at: arch/arm/boot/zImage
Code:
ls arch/arm/boot/zImage
The modules are scattered all over the place, depending on where the source existed that they were compiled from. We can easily search for them using this command:
Code:
find . -name "*.ko"
If both of the previous commands completed, you are now ready to package your kernel up for testing.
Move up a directory before continuing.
Code:
cd ..
Click to expand...
Click to collapse
Packaging
You may know of an awesome developer by the name of koush.
Well, once upon a time, koush created a rather simple zip, called AnyKernel, that would flash a kernel on a device, regardless of what ramdisk the kernel has on it.
I've taken his zip and modified it for d2 devices and to work with the newer recoveries out there.
This has a script in it that will dump your current boot.img (kernel+ramdisk), unpack it, replace the kernel, repack it and flash it.
It'll also copy any modules to the proper directory (/system/lib/modules) and set permissions appropriately.
You can get a zip here: Download || Mirror
(You can get it here as well: https://github.com/invisiblek/AnyKernel )
(Everyone is invited to use this zip, it'll probably make your life easier to not have to worry about the ramdisk. Enjoy!)
IMPORTANT
This AnyKernel package is for US variations of the Galaxy S3.
NOT the international (I9300) or any other device.
There are checks in the updater-script that will ensure you are running a d2 device before it does anything.
If you were to remove these checks, and not modify the partition that it flashes to later, you could end up with a brick.
If you intend to adapt this package for another device (please, do this! its a very handy script!), make sure you know it well, or ask someone to help you determine your device's
partition scheme before using it.
The risk here is due to the fact that the script doesn't know your device's partition scheme. It is configured specifically for the d2 devices. Flashing it on something else, who's boot
partition is somewhere else, might cause a bad flash to the bootloader partition (bad bad news if this happens).
Just be careful if you want to use this on another device. You won't run into problems if you use this on a d2 device.
EDIT: I made modifications that should make this less likely, but please, if you intend to use this on a different device (which is completely fine!) make sure you configure
the scripts to flash to the proper partitions.
Click to expand...
Click to collapse
Download and extract one of the above, we'll again use the first link for this example:
Code:
wget http://invisiblek.org/AnyKernel_samsung-d2.zip
unzip AnyKernel_samsung-d2.zip -d AnyKernel/
Now we'll copy our newly compiled zImage (still referring to the same kernel directory we used above, your repo might be called something different)
Code:
cp android_kernel_samsung_d2/arch/arm/boot/zImage AnyKernel/kernel/
cp `find android_kernel_samsung_d2 -name "*.ko"` AnyKernel/modules/
Finally we are ready to zip this up and test out flashing it.
Code:
cd AnyKernel
zip ../MyAwesomeKernel.zip -r *
cd ..
You'll now have a file named MyAwesomeKernel.zip which you should be able to flash via custom recovery (TWRP or CWM)
Click to expand...
Click to collapse
Extra Credit/Protips
Learn to use git. It's very powerful and great way to store your code.
Learn to use adb. It's an invaluable tool for any android developer.
Touchwiz and AOSP-based kernels are different. This means you cannot take CyanogenMod's source, build a kernel and expect it to work on a Touchwiz-based ROM.
Build a ROM next: http://wiki.cyanogenmod.org/w/Build_for_d2vzw
Crackflash your own stuff!
ALWAYS NANDROID!
Click to expand...
Click to collapse
Source code for all of my projects can be found here: http://github.com/invisiblek
FAQ
Q: How do I update my source tree to the latest that is available from where I downloaded it?
A: This can be handy if, for instance, you are building a CyanogenMod kernel and they added some patches, after you downloaded the source, that you want to include in your next build. You'll want to cd to your kernel tree and issue a git pull:
Code:
cd android_kernel_samsung_d2
git pull
You may then continue with the building instructions.
This may, however, have other problems if you've made changes to files. You might run into conflicts. I won't cover fixing any of this here, its not in the scope of this thread.
Q: I'm using X as a kernel base, but Y has a patch that I really like. How do I get it in my kernel easily?
A: I'll let you check Google for this answer, but I'll give you a hint use: git cherry-pick
Nice tutorial bro! Always good to learn something new everyday
Really is a good thread,thanks
This guide would have made things too easy for me.
Too easy, indeed. haha
Great job, invisiblek! AnyKernel is the beez neez.
Ok so this is a noob question but I gotta ask anyway lol. Ok so I cloned the kernel source, I made my edits, now how do I push all this to my github?
I already have a github account, I already made a new repo for the kernel. Here's a link to my github if you need it...
https://github.com/ghicks12/d2vzw_kernel.git
spc_hicks09 said:
Ok so this is a noob question but I gotta ask anyway lol. Ok so I cloned the kernel source, I made my edits, now how do I push all this to my github?
I already have a github account, I already made a new repo for the kernel. Here's a link to my github if you need it...
https://github.com/ghicks12/d2vzw_kernel.git
Click to expand...
Click to collapse
git remote add origin git_location_you_created_on_github.git
git push -u origin somebranch
The -u is for first time run only, you can just git push afterwards.
Sent from my SCH-I535
GideonX said:
git remote add origin git_location_you_created_on_github.git
git push -u origin somebranch
The -u is for first time run only, you can just git push afterwards.
Sent from my SCH-I535
Click to expand...
Click to collapse
Thanks! When I run
Code:
git remote add origin https://github.com/ghicks12/d2vzw_kernel.git
I get this back:
Code:
fatal: remote origin already exists.
I'm editing a CM based kernel, not sure if that matters or not?
That just means you added the remote already. Just issue the push command then.
Sent from my SCH-I535
Why is this happening? I don't know what i did wrong
[email protected]:~/cm$ make VARIANT_DEFCONFIG=cyanogen_d2att_defconfig
scripts/kconfig/conf --silentoldconfig Kconfig
drivers/media/video/msm/Kconfig:123:warning: choice value used outside its choice group
drivers/media/video/msm/Kconfig:128:warning: choice value used outside its choice group
***
*** Configuration file ".config" not found!
***
*** Please run some configurator (e.g. "make oldconfig" or
*** "make menuconfig" or "make xconfig").
***
make[2]: *** [silentoldconfig] Error 1
make[1]: *** [silentoldconfig] Error 2
make: *** No rule to make target `include/config/auto.conf', needed by `include/config/kernel.release'. Stop.
[email protected]:~/cm$
Hey. I'm having some problems with some GIT terminology and procedures. I'm a .NET developer and I use TFS and SVN on a daily basis. Forgive me if this is complete off basis from what you'd do with GIT.
What I want to do is merge one branch into another branch. In other words I want to take the latest kernel source from my favorite dev and merge in the latest from cyanogen's 4.3 d2 branch. Is this a rebase thing? It doesn't seem like cherrypicking to me.
I have successfully compiled kernel and made modules.I inserted zImage and modules inside any kernel updater,flashed via TWRP.When reboot stuck in odin and it says could not do normal boot.

[INCOMPLETE HOW TO] Reconstruct Mi 4c kernel source

I'm writing this incomplete instruction for my friend @emfox based on the instruction I used to reconstruct Redmi 2 kernel source http://forum.xda-developers.com/and.../how-to-convert-qualcomms-dtb-to-dts-t3221223 Unfortunately I couldn't finish this instruction without Mi 4c device. This is just a quick look, short information, to check the possibility to reconstruct an open source kernel based on CAF project. It's will be hard but not impossible.
1. Clone MSM8992 vanilla kernel source, LA.BF64.1.2.2-02940-8x92.0 release for Marshmallow 6.0.1 (release LA.BF64.1.2.1.c1-05410-8x92.0 branch LA.BF64.1.2.1.c1_rb1.38 for Lollipop 5.1.1) https://www.codeaurora.org/cgit/quic/la/kernel/msm-3.10/?h=LA.BF64.1.2.2_rb4.22
Code:
git clone git://codeaurora.org/quic/la/kernel/msm-3.10 -b LA.BF64.1.2.2_rb4.22
2. Stock 4c kernel was compiled without CONFIG_IKCONFIG, vanilla kernel config libra_defconfig attached
3. Attached 3 dts file from stock kernel, msm8992-mtp-0xc.dts seem compatible to emfox device (qcom,board-id = <0xc 0x0>; )
4. Attached a vanilla dts file for MSM8992 MTP msm8992-mtp.dts as a result of LA.BF64.1.2.2_rb4.22 built
You can compare msm8992-mtp-0xc.dts to msm8992-mtp.dts using a diff tool (i.e. Kompare app) and start creating device tree source for Mi 4c: msm8992-mtp-libra.dts, msm8992-mtp-libra.dtsi, batterydata-itech-3020mah.dtsi, dsi-panel-sharp-rsp61322-1080p-video.dtsi, dsi-panel-auo-nt35596-1080p-video.dtsi, dsi-panel-lgd-nt35596-1080p-video.dtsi, dsi-panel-sharp-nt35595-1080p-video.dtsi, dsi-panel-jdi-nt35595-1080p-video.dtsi, msm8992-camera-sensor-mtp-libra.dtsi, etc. You can use https://github.com/kumajaya/android...mmit/3de4f3564a82f44049a8664d4383c6d3ed43cb47 as a reference. Mi 4c based on same board platform as LG G4 or Nexus 5X. Good luck!
How to build kernel outside Android source tree:
I assume your home directory is /home/user, kernel source inside /home/user/android/libra/kernel, Android source tree inside /home/user/android/system-13.0
1. Create an environtment text file, save it as /home/user/android/build-arm64.env (change CROSS_COMPILE to point to your toolchain):
Code:
export CROSS_COMPILE='/home/user/android/system-13.0/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-'
export LDFLAGS=''
export CFLAGS=''
export SUBARCH=arm64
export ARCH=arm64
2. Import environtment file above, create a build directory outside the kernel source tree (to keep the kernel source clean):
Code:
$ cd /home/user/android/libra/kernel
$ source /home/user/android/build-arm64.env
$ mkdir -p /home/user/android/libra/kernel-out
$ make O=/home/user/android/libra/kernel-out mrproper
3. Import the kernel config file, change the kernel configuration (if needed) and start the building process:
Code:
$ make O=/home/user/android/libra/kernel-out libra_defconfig
$ make O=/home/user/android/libra/kernel-out menuconfig
$ make O=/home/user/android/libra/kernel-out
4. Copy the resulting kernel and modules (if available) to a binary directory:
Code:
$ mkdir -p /home/user/android/libra/kernel-bin
$ mkdir -p /home/user/android/libra/kernel-bin/modules
$ cp /home/user/android/libra/kernel-out/arch/arm64/boot/Image /home/user/android/libra/kernel-bin/
$ find /home/user/android/libra/kernel-out/ -type f -name *.ko -exec cp {} /home/user/android/libra/kernel-bin/modules/ \;
Creating a boot image:
Remember, this is incomplete guide
Roger that! I thought you have bought xiaomi 4c several days ago.
You're so kind to provide this tutorial. Since I know nearly nothing about kernel development, I'll start learning it step by step.
Thanks for the instruction.
Also @ekkilm / Teamsuperluminal might be able to help :fingers-crossed:
Autines said:
Roger that! I thought you have bought xiaomi 4c several days ago.
Click to expand...
Click to collapse
No, too expensive and my main device still in very good condition :laugh:
emfox said:
You're so kind to provide this tutorial. Since I know nearly nothing about kernel development, I'll start learning it step by step.
Click to expand...
Click to collapse
No problem, you also helped me a lot.
kevinnol said:
Thanks for the instruction.
Also @ekkilm / Teamsuperluminal might be able to help :fingers-crossed:
Click to expand...
Click to collapse
You're welcome.
OK, I've gone through the buiding kernel outside android tree steps, and now am trying to build MSM8992 vanilla kernel source from inside cm13 source directory.
command is 'source build/envsetup.sh &&breakfast libra && mka bootimage', but always got a command not found error, don't know what is missing...
Code:
<manifest>
<remote name="ghub" fetch="git://github.com/"/>
<project name="xiaomi-dev/android_device_xiaomi_libra.git" path="device/xiaomi/libra" remote="ghub" revision="cm-13.0"/>
<project name="AndropaX/proprietary_vendor_xiaomi_libra" path="vendor/xiaomi/libra" remote="ghub" revision="master"/>
</manifest>
and put kernel source to kernel/xiaomi/libra.
The error is
Code:
host C++: libc++_static <= external/libcxx/src/strstream.cpp
host C++: libc++_static <= external/libcxx/src/system_error.cpp
host C++: libc++_static <= external/libcxx/src/thread.cpp
host C++: libc++_static <= external/libcxx/src/typeinfo.cpp
host C++: libc++_static <= external/libcxx/src/utility.cpp
host C++: libc++_static <= external/libcxx/src/valarray.cpp
host StaticLib: libc++abi (/home/emfox/android/system-13.0/out/host/linux-x86/obj/STATIC_LIBRARIES/libc++abi_intermediates/libc++abi.a)
host StaticLib: libmincrypt (/home/emfox/android/system-13.0/out/host/linux-x86/obj/STATIC_LIBRARIES/libmincrypt_intermediates/libmincrypt.a)
host C: acp <= build/tools/acp/acp.c
host StaticLib: libhost (/home/emfox/android/system-13.0/out/host/linux-x86/obj/STATIC_LIBRARIES/libhost_intermediates/libhost.a)
Building kernel...
/bin/bash: line 1: @: command not found
Export includes file: system/core/libcutils/Android.mk -- /home/emfox/android/system-13.0/out/host/linux-x86/obj/SHARED_LIBRARIES/libcutils_intermediates/export_includes
make[1]: Entering directory '/home/emfox/android/system-13.0/kernel'
make[1]: *** No rule to make target 'libra_defconfig'. Stop.
make[1]: Leaving directory '/home/emfox/android/system-13.0/kernel'
make[1]: Entering directory '/home/emfox/android/system-13.0/kernel'
make[1]: *** No rule to make target 'headers_install'. Stop.
make[1]: Leaving directory '/home/emfox/android/system-13.0/kernel'
kernel/xiaomi/libra/AndroidKernel.mk:110: recipe for target '/home/emfox/android/system-13.0/out/target/product/libra/obj/KERNEL_OBJ/.build_stamp' failed
make: *** [/home/emfox/android/system-13.0/out/target/product/libra/obj/KERNEL_OBJ/.build_stamp] Error 2
make: *** Waiting for unfinished jobs....
make: Leaving directory '/home/emfox/android/system-13.0'
#### make failed to build some targets (01:41 (mm:ss)) ####
Hi @emfox, i would gladly help you since i just finished cm12.1 build with device tree (i made a thread, with prebuilt kernel of course) and I'd like to start with cm13.
If you open source kernel has compiled correctly, can you do a "kernel_xiaomi_libra" github repository?
alterbang said:
Hi @emfox, i would gladly help you since i just finished cm12.1 build with device tree (i made a thread, with prebuilt kernel of course) and I'd like to start with cm13.
If you open source kernel has compiled correctly, can you do a "kernel_xiaomi_libra" github repository?
Click to expand...
Click to collapse
no, not really. I haven't finished the source.
I have little kernel hacking knowledge, so I'd like to set up and working environment first, then I'll go to deal these *dts files.
Ok, sorry then. I thought "'I've gone through the buiding kernel outside android tree steps," meant you had already finished
Maybe when I'll have some free time in the next days i will give the entire process a try!
alterbang said:
Ok, sorry then. I thought "'I've gone through the buiding kernel outside android tree steps," meant you had already finished
Maybe when I'll have some free time in the next days i will give the entire process a try!
Click to expand...
Click to collapse
oh, that would be great. I'm a developer but just on web and application domain, and have no much time to dig into kernel deeply. But I am learning
@emfox Don't forget copy libra_defconfig to arch/arm64/configs/
ketut.kumajaya said:
@emfox Don't forget copy libra_defconfig to arch/arm64/configs/
Click to expand...
Click to collapse
yes i have copied, or the error msg will be 'cannot found kernel configuration ...blabla'
emfox said:
yes i have copied, or the error msg will be 'cannot found kernel configuration ...blabla'
Click to expand...
Click to collapse
Please recheck your device board config, you can use LG G4 config as a reference https://github.com/CyanogenMod/andr...mon/blob/cm-13.0/BoardConfigCommon.mk#L49-L61
don't understand a thing from the coding but from what i have learned, kernel source would be awesome to develop more for the 4c. keep up the good work!
Yea would be really awesome, too bad xiaomi doesn't release it themself
Well there are a lot of crazy guys here on xda so there's still hope
Thinking to help @emfox to create a such template for 4c but no much free time here, just a short free time between my workload and no much interest without the device
ketut.kumajaya said:
Thinking to help @emfox to create a such template for 4c but no much free time here, just a short free time between my workload and no much interest without the device
Click to expand...
Click to collapse
yes, a working building directory structure will help me start the porting.
but no need hurry, we now have cm from www.teamsuperluminal.org. although it's close-sourced and use prebuilt kernel, still much better than miui.
Hi, anyone can give some more info how to build AOSP from nexus 5X?
am i alone like Taylor?
Looks like the kernel source will be released soon: http://en.miui.com/thread-235127-1-1.html

Need help for kernel Compile

I need some help of the developer to compile the kernel of the letv 1s. I tried to compile with the instruction provided on the letv 1s source code. I successfully compiled it with some warnings, although when I flash it, the phone failed to boot.
This is what I used to compile
------------------------------------------------------------------------------------------------------------------------
Le 1S Kernel Build mini-Howto
===============================
1. Build
--------
- get toolchain
From android git server, codesourcery etc.
- aarch64-linux-android-4.9
- Unpack kernel source
Suppose kernel source has been unpacked to <kernel> dir.
- make output folder
$ mkdir <kernel>/out
- export env variables
export correct "CROSS_COMPILE" to use the toolchain path you have downloaded.
$ export CROSS_COMPILE=<Your cross compilee dir>/aarch64-linux-android-4.9/bin/aarch64-linux-android-
$ export JOBS=16 # Can be CPU core # x 2
- build kernel
$ cd <kernel>
$ make -C $PWD O=$PWD/out ARCH=arm64 x500_defconfig
$ make -j$JOBS -C $PWD O=$PWD/out ARCH=arm64 KCFLAGS=-mno-android
2. Output files
---------------
- Kernel: out/arch/arm64/boot/Image
--------------------------------------------------------------------------------------------------------------------------
Expect help from @DroidThug & other developers
superac11 said:
I need some help of the developer to compile the kernel of the letv 1s. I tried to compile with the instruction provided on the letv 1s source code. I successfully compiled it with some warnings, although when I flash it, the phone failed to boot.
This is what I used to compile
------------------------------------------------------------------------------------------------------------------------
Le 1S Kernel Build mini-Howto
===============================
1. Build
--------
- get toolchain
From android git server, codesourcery etc.
- aarch64-linux-android-4.9
- Unpack kernel source
Suppose kernel source has been unpacked to <kernel> dir.
- make output folder
$ mkdir <kernel>/out
- export env variables
export correct "CROSS_COMPILE" to use the toolchain path you have downloaded.
$ export CROSS_COMPILE=<Your cross compilee dir>/aarch64-linux-android-4.9/bin/aarch64-linux-android-
$ export JOBS=16 # Can be CPU core # x 2
- build kernel
$ cd <kernel>
$ make -C $PWD O=$PWD/out ARCH=arm64 x500_defconfig
$ make -j$JOBS -C $PWD O=$PWD/out ARCH=arm64 KCFLAGS=-mno-android
2. Output files
---------------
- Kernel: out/arch/arm64/boot/Image
--------------------------------------------------------------------------------------------------------------------------
Expect help from @DroidThug & other developers
Click to expand...
Click to collapse
Hello.
Sorry for the late reply, but have Exams going on.
You can try using https://github.com/DroidThug/android_kernel_leeco_MT6795 as the source
I have fixed up stuff here and there. You may try compiling from here
Also, if you would like, you may use UBERTC from
https://github.com/DroidThug/aarch64-linux-android-gcc-4.9
You may also use the script from https://raw.githubusercontent.com/D...8bc37a9f01b6ddc77971754bdadd0e476/infernus.sh
DroidThug said:
Hello.
Sorry for the late reply, but have Exams going on.
You can try using https://github.com/DroidThug/android_kernel_leeco_MT6795 as the source
I have fixed up stuff here and there. You may try compiling from here
Also, if you would like, you may use UBERTC from
https://github.com/DroidThug/aarch64-linux-android-gcc-4.9
You may also use the script from https://raw.githubusercontent.com/D...8bc37a9f01b6ddc77971754bdadd0e476/infernus.sh
Click to expand...
Click to collapse
Thank you , Although i had already coompiled kernel and started to build the cm 13, everything gone good except brunch command,
----------------------------------------------------------------------------------------------------
[email protected]:/mnt/new/minimal$ lunch
You're building on Linux
Lunch menu... pick a combo:
1. cm_x500-eng 5. minimal_hammerhead-userdebug
2. cm_x500-user 6. minimal_mako-userdebug
3. cm_x500-userdebug 7. minimal_shamu-userdebug
4. minimal_angler-userdebug
Which would you like? [aosp_arm-eng] 1
build/core/product_config.mk:222: *** Can not locate config makefile for product "cm_x500". Stop.
WARNING: Trying to fetch a device that's already there
WARNING: device/LeTV/x500/minimal.dependencies file not found
build/core/product_config.mk:222: *** Can not locate config makefile for product "cm_x500". Stop.
** Don't have a product spec for: 'cm_x500'
** Do you have the right repo manifest?
[email protected]:/mnt/new/minimal$
superac11 said:
Thank you , Although i had already coompiled kernel and started to build the cm 13, everything gone good except brunch command,
----------------------------------------------------------------------------------------------------
[email protected]:/mnt/new/minimal$ lunch
You're building on Linux
Lunch menu... pick a combo:
1. cm_x500-eng 5. minimal_hammerhead-userdebug
2. cm_x500-user 6. minimal_mako-userdebug
3. cm_x500-userdebug 7. minimal_shamu-userdebug
4. minimal_angler-userdebug
Which would you like? [aosp_arm-eng] 1
build/core/product_config.mk:222: *** Can not locate config makefile for product "cm_x500". Stop.
WARNING: Trying to fetch a device that's already there
WARNING: device/LeTV/x500/minimal.dependencies file not found
build/core/product_config.mk:222: *** Can not locate config makefile for product "cm_x500". Stop.
** Don't have a product spec for: 'cm_x500'
** Do you have the right repo manifest?
[email protected]:/mnt/new/minimal$
Click to expand...
Click to collapse
You are building Minimal OS eh?
Minimal is based off AOSP, and the tree you use is of CyanogenMod.
You might have to edit stuff here and there

[GUIDE] Build Rom from Source For Tissot

What is ?
Android is the open-source operating system used for smartphones. Full Freedom for people using it
What is Source Code?
Android is an open-source software stack created for a wide array of devices with different form factors. The primary purposes of are to create an open software platform available for carriers, OEMs, and to make their innovative ideas a reality and to introduce a successful, real-world product that improves the mobile experience for users.The result is a full, production-quality consumer product with source code open for customization and porting.
So basically Allows to customize the things you like and make new things without any Restrictions. Cool isn’t it?
What is ROM ?
The ROM is the operating system. This is the User interface (Sense UI in HTC phones) and the file system for maintaining contacts etc. It is composed of a Linux kernel and various add-ons to achieve specific functionality.
What does a Rom Contain ?
Basically a Rom Contains following main things :
· Kernel
· Bootloader
· Recovery
· Radio
· Framework
· Apps
· core
· -runtime,Etc
Some Basics About Above Terms
Kernel :
A kernel is critical component of the and all operating systems. It can be seen as a sort of bridge between the applications and the actual hardware of a device. devices use the Linux kernel, but it's not the exact same kernel other Linux-based operating systems use. There's a lot of specific code built in, and Google's kernel maintainers have their work cut out for them. OEMs have to contribute as well, because they need to develop hardware drivers for the parts they're using for the kernel version they're using. This is why it takes a while for independent and hackers to port new versions to older devices and get everything working. Drivers written to work with the Gingerbread kernel on a phone won't necessarily work with the Ice Cream Sandwich kernel. And that's important, because one of the kernel's main functions is to control the hardware. It's a whole lot of source code, with more options while building it than you can imagine, but in the end it's just the intermediary between the hardware and the software. So basically if any instruction is given to mobile it first gives the command to kernel for the particular task execution.
Bootloader :
The bootloader is code that is executed before any Operating System starts to run. Bootloaders basically package the instructions to boot operating system kernel and most of them also have their own debugging or modification environment. Think of the bootloader as a security checkpoint for all those partitions. Because if you’re able to swap out what’s on those partitions, you’re able to break things if you don’t know what you’re doing. So basically it commands the kernel of your device to Boot the Device properly without any issues. So careful with bootloader since it can mess things very badly.
Recovery :
Recovery is defined in simple terms as a source of backup. Whenever your phone firmware is corrupted, the recovery does the job in helping you to restore or repair your faulty or buggy firmware into working condition. It is also used for flashing the Rom’s , kernel and many more things.
Radio
The lowest part of software layer is the radio: this is the very first thing that runs, just before the bootloader. It control all wireless communication like GSM Antenna, GPS etc.
What you’ll need
A relatively recent 64-bit computer (Linux, OS X, or Windows)(Virtual Machine will work as well) with a reasonable amount of RAM and about 100 GB of free storage (more if you enable ccache or build for multiple devices). The less RAM you have, the longer the build will take (aim for 8 GB or more). Using SSDs results in considerably faster build times than traditional hard drives.
A decent internet connection & reliable electricity
Some familiarity with basic operation and terminology. It would help if you’ve installed custom roms on other devices and are familiar with recovery. It may also be useful to know some basic command line concepts such as cd for “change directory”, the concept of directory hierarchies, that in Linux they are separated by /, etc.
Install the SDK
If you haven’t previously installed adb and fastboot, you can download them from Google. Extract it running:
Code:
unzip platform-tools-latest-linux.zip -d ~
Now you have to add adb and fastboot to your PATH. Open ~/.profile and add the following:
Code:
# add SDK platform tools to path
if [ -d "$HOME/platform-tools" ] ; then
PATH="$HOME/platform-tools:$PATH"
fi
Then, run source ~/.profile to update yur environment.
Install the build packages
Several packages are needed to build LineageOS. You can install these using your distribution’s package manager.
To build LineageOS, you’ll need:
bc bison build-essential curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libwxgtk3.0-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev
For Ubuntu versions older than 16.04 (xenial), substitute:
libwxgtk3.0-dev → libwxgtk2.8-dev
Java
Different versions of LineageOS require different JDK (Java Development Kit) versions.
LineageOS 14.1: OpenJDK 1.8 (install openjdk-8-jdk)
LineageOS 11.0-13.0: OpenJDK 1.7 (install openjdk-7-jdk)*
https://askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16-04-or-higher
Create the directories
You’ll need to set up some directories in your build environment.
To create them:
Code:
mkdir -p ~/bin
mkdir -p ~//lineage
Install the repo command
Enter the following to download the repo binary and make it executable (runnable):
Code:
curl [url]https://storage.googleapis.com/git-repo-downloads/repo[/url] > ~/bin/repo
chmod a+x ~/bin/repo
Put the ~/bin directory in your path of execution
In recent versions of Ubuntu, ~/bin should already be in your PATH. You can check this by opening ~/.profile with a text editor and verifying the following code exists (add it if it is missing):
Code:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
Then, run source ~/.profile to update your environment.
Initialize the LineageOS source repository
Code:
cd ~//lineage
repo init -u [url]https://github.com/LineageOS/.git[/url] -b lineage-15.1
Download the source code
Code:
repo sync -c -f --force-sync --no-clone-bundle --no-tags --optimized-fetch --prune
Prepare the device-specific code
Code:
git clone [url]https://github.com/TheScarastic/android_device_xiaomi_msm8953-common[/url] -b lineage-15.1 device/xiaomi/msm8953
git clone [url]https://github.com/TheScarastic/android_device_xiaomi_tissot[/url] -b lineage-15.1 device/xiaomi/tissot
git clone [url]https://github.com/TheScarastic/proprietary_vendor_xiaomi[/url] -b lineage-15.1 vendor/xiaomi
git clone [url]https://github.com/Tissot-Development/android_kernel_xiaomi_tissot[/url] -b 8.1 kernel/xiaomi/msm8953
Turn on caching to speed up build
Code:
export CCACHE_DIR=./.ccache
ccache -C
export USE_CCACHE=1
export CCACHE_COMPRESS=1
prebuilts/misc/linux-x86/ccache/ccache -M 50G
Configure jack
Jack is the new Java compiler used when building LineageOS 14.1. It is known to run out of memory - a simple fix is to run this command:
Code:
export _JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4G"
Make Clean Build
Code:
make clean
Initialize the build command
Code:
source build/envsetup.sh
Start Build
Code:
croot
brunch tissot
For More info:
https://source..com/source/requirements
https://wiki.lineageos.org/devices/cheeseburger/build
Thanks bro..
DGEEEK said:
Thanks bro..
Click to expand...
Click to collapse
Thany you for this guide! Will try this!
saski4711 said:
Thany you for this guide! Will try this!
Click to expand...
Click to collapse
:good:
Thanks for guide, btw what's the size of source code ?
prabhjot-singh said:
Thanks for guide, btw what's the size of source code ?
Click to expand...
Click to collapse
Around 20-25GB I think
Followed the above steps to the letter but I get an error right at the beginning:
Code:
ninja: error: 'kernel/xiaomi/msm8953/arch/arm64/configs/lineage_tissot_defconfig', needed by '/home/rossi/android/lineage/out/target/product/tissot/obj/KERNEL_OBJ/.config', missing and no known rule to make it
build/core/ninja.mk:151: recipe for target 'ninja_wrapper' failed
make: *** [ninja_wrapper] Error 1
make: Leaving directory '/home/rossi/android/lineage'
Current git broken? Any idea?
saski4711 said:
Followed the above steps to the letter but I get an error right at the beginning:
Code:
ninja: error: 'kernel/xiaomi/msm8953/arch/arm64/configs/lineage_tissot_defconfig', needed by '/home/rossi/android/lineage/out/target/product/tissot/obj/KERNEL_OBJ/.config', missing and no known rule to make it
build/core/ninja.mk:151: recipe for target 'ninja_wrapper' failed
make: *** [ninja_wrapper] Error 1
make: Leaving directory '/home/rossi/android/lineage'
Current git broken? Any idea?
Click to expand...
Click to collapse
Hello,
Don't use that kernel, as actually don't work properly in Xiaomi Mi A1. This error is caused because the file "lineage_tissot_defconfig" it's not named like that, exactly it's name is "tissot_defconfig", for your first build with lineage I recommend you to use the following sources, because are adapt for Lineage. Don't forget to use superuser privileges to compile, it avoids a lot of possible errors with normal user.
Device tree
Vendor
Kernel
Give thanks to user @ghpranav for sources :good:
Regards
black_arashi said:
Hello,
Don't use that kernel, as actually don't work properly in Xiaomi Mi A1. This error is caused because the file "lineage_tissot_defconfig" it's not named like that, exactly it's name is "tissot_defconfig", for your first build with lineage I recommend you to use the following sources, because are adapt for Lineage. Don't forget to use superuser privileges to compile, it avoids a lot of possible errors with normal user.
Device tree
Vendor
Kernel
Give thanks to user @ghpranav for sources :good:
Regards
Click to expand...
Click to collapse
Thanks for the info. I'm now past the error. Will take some time though since I'm building on my laptop :cyclops:
saski4711 said:
Thanks for the info. I'm now past the error. Will take some time though since I'm building on my laptop :cyclops:
Click to expand...
Click to collapse
Between 3 to 5h in modern pc, probably you will need between 7 to 10h in a laptop, depends on Nº of Cores and RAM, anyway, good luck in your first compilation :good:
black_arashi said:
Between 3 to 5h in modern pc, probably you will need between 7 to 10h in a laptop, depends on Nº of Cores and RAM, anyway, good luck in your first compilation :good:
Click to expand...
Click to collapse
Thx m8. Still no error. Compiling over night on single core to avoid throttling / overheating. :highfive:
saski4711 said:
Thx m8. Still no error. Compiling over night on single core to avoid throttling / overheating. :highfive:
Click to expand...
Click to collapse
Probably you will se a lot of "warning" don't apologice, it's normal, these warning issues is being solved during the compilation. Some info just in case
saski4711 said:
Followed the above steps to the letter but I get an error right at the beginning:
Current git broken? Any idea?
Click to expand...
Click to collapse
Rename tissot_defconfig to lineage_tissot_defconfig in arch/arm64/configs
Nice share brotherr :good:
Keep mia1 like the sky full of stars, so many custom rom :highfive::laugh:
Sent from my Xiaomi Mi A1 using XDA Labs
-Rhoby|™-Bugs said:
Nice share brotherr :good:
Keep mia1 like the sky full of stars, so many custom rom :highfive::laugh:
Click to expand...
Click to collapse
Thanks
Hello and thanks for the guide.
I am trying to build Dirty Unicorns 7.1.2 for tissot. I have downloaded kernel, vendor and device and repo synced DU n7x branch. I have also downloaded device_qcom_sepolicy and changed some files in device/xiaomi/tissot folder in order for the build to start normally. After 1.30 minutes of building i get this error
Code:
ninja: error: '/home/manoskav/du-tissot/out/target/product/tissot/obj/STATIC_LIBRARIES/bootctrl.msm8953_intermediates/export_includes', needed by '/home/manoskav/du-tissot/out/target/product/tissot/obj/EXECUTABLES/update_engine_sideload_intermediates/import_includes', missing and no known rule to make it
make: *** [build/core/ninja.mk:167: ninja_wrapper] Error 1
Maybe should i try n7x-caf branch or n7x is ok for tissot? Can anyone help me with the building process?
Thanks in advance.
mparmpas122321 said:
Hello and thanks for the guide.
I am trying to build Dirty Unicorns 7.1.2 for tissot. I have downloaded kernel, vendor and device and repo synced DU n7x branch. I have also downloaded device_qcom_sepolicy and changed some files in device/xiaomi/tissot folder in order for the build to start normally. After 1.30 minutes of building i get this error
Maybe should i try n7x-caf branch or n7x is ok for tissot? Can anyone help me with the building process?
Thanks in advance.
Click to expand...
Click to collapse
Hmm but seriously it's tougher bro because its bootctrl it need more configuration
I tried building for Tissot but I'm having this issue.
[email protected]:~/dos$ . build/envsetup.sh
including device/generic/car/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including vendor/discovery/vendorsetup.sh
[email protected]:~/dos$ brunch tissot
including vendor/discovery/vendorsetup.sh
build/core/product_config.mk:236: *** Can not locate config makefile for product "tissot". Stop.
build/core/product_config.mk:236: *** Can not locate config makefile for product "tissot". Stop.
No such item in brunch menu. Try 'breakfast'
[email protected]:~/dos$
Click to expand...
Click to collapse
Can anyone please help me out?
black_arashi said:
Hello,
Don't use that kernel, as actually don't work properly in Xiaomi Mi A1. This error is caused because the file "lineage_tissot_defconfig" it's not named like that, exactly it's name is "tissot_defconfig", for your first build with lineage I recommend you to use the following sources, because are adapt for Lineage. Don't forget to use superuser privileges to compile, it avoids a lot of possible errors with normal user.
Device tree
Vendor
Kernel
Give thanks to user @ghpranav for sources :good:
Regards
Click to expand...
Click to collapse
@black_arashi
Oh so ghpranav's repo has LOS source added into it? If so is there any Android Stock for all these?
Thanks

Categories

Resources