[Q] Building Nexus S kernel - Nexus S Q&A, Help & Troubleshooting

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-

Related

[32B Magic] boot.img issues. Need help!

I have been trying to compile Froyo source for days now. Reason: I need a ROM tweaked to my needs. I would'nt say I am entirely unsuccessful except for boot.img. Cutting long story short. Let my script do the talking:
cd ~/mydroid
git clone git://android.git.kernel.org/kernel/msm.git
cd ~/mydroid/msm
make ARCH=arm msm_defconfig
make ARCH=arm CROSS_COMPILE=~/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- zImage -j4
Click to expand...
Click to collapse
It takes time but source does compile without much hassle. I get the .img(s) in ~/mydroid/out/target/product/dream directory. Now the problem is my boot.img refuses to boot the phone. ddms doesn't show any logs either. Just to be sure I even downloaded, renamed (as <msm>) & compiled the original kernel source from
wget http://member.america.htc.com/download/RomCode/Source_and_Binaries/dream_9af60ed4.tar.bz2
Click to expand...
Click to collapse
but no success. Temporarily I am using superF's boot.img and gapps from CM6. ROM is very fast and looks stable. Probably the only thing that's broken is wifi. Which I assume can be interrelated.
Can anyone please guide me in the right direction.. Screenies to show that I am mostly on the right track except for boot.img fsck up!
P.S. I hope I have posted in correct section; it says Android development.
Even though the thread remained unanswered; I even been working on this issue on my own. I have tried every trick (that I can think of) of the trade.
1st attempt: I pulled .config from the brand new CM6, replaced existing .config and commented out msm def_config and did:
PHP:
make ARCH=arm CROSS_COMPILE=$SOURCE_FOLDER/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- oldconfig
make ARCH=arm CROSS_COMPILE=$SOURCE_FOLDER/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- zimage
Upon compiling; the system asked a dozen question which I bypassed by pressing enter. After a while I got boot.img in --/out/--directory which did'nt work after using fastboot.
./fastboot boot /home/amit/mydroid/out/target/product/dream/boot.img
Click to expand...
Click to collapse
The phone just froze with a standard Vodafone splash screen.
2nd attempt: Replaced contents of existing msm def_config with content of .config that I pulled earlier from CM6 and did standard "make ARCH=arm msm_defconfig". Same fsking result upon compiling .
I have a feeling that I have been $crewing up on .config but I may be wrong. I request all of you stalwarts to step in & help me out. I have pasted my script for reference:
PHP:
#!/bin/bash
#git clone git://android.git.kernel.org/kernel/msm.git
#unzip the proprietary files from HTC for Sapphire
cd /home/amit/mydroid
if [ ! -d vendor/htc/dream/proprietary ]
then
cd ~/mydroid/device/htc/dream/
./unzip-files.sh
fi
cd ~/mydroid/msm
make ARCH=arm msm_defconfig
#make ARCH=arm CROSS_COMPILE=~/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- oldconfig
make ARCH=arm CROSS_COMPILE=~/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- zImage
if [ -f ~/mydroid/msm/arch/arm/boot/zImage ]
then
cp ~/mydroid/msm/arch/arm/boot/zImage ~/mydroid/device/htc/dream/kernel
fi
cd ~/mydroid/system/wlan/ti/sta_dk_4_0_4_32
make KERNEL_DIR=~/mydroid/msm/ ARCH=arm CROSS_COMPILE=~/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- -j4
if [ -f ~/mydroid/system/wlan/ti/sta_dk_4_0_4_32/wlan.ko ]
then
cp ~/mydroid/system/wlan/ti/sta_dk_4_0_4_32/wlan.ko ~/mydroid/device/htc/dream/wlan.ko
fi
cd ~/mydroid
. build/envsetup.sh
lunch
make otapackage
#get to compiled folder
cd ~/mydroid/out/target/product/dream
echo 'Your files ready for flashing are here:'
ls *.zip

[ROM] Native Ubuntu on the Epic!

I got Ubuntu 13.04 to boot cleanly on my Epic! No chroot or VNC hacks involved!
This method loads a custom kernel using kexec and runs off a microSD card.
Check the end of the post for the kernel config and patches, xorg.conf, /etc/modules, the kexec zip, and a pre-built kernel.
I may eventually provide a pre-built root filesystem, but for now it's easy enough to build your own.
For the technically inclined, Debian, Arch Linux, MeeGo/Mer/Nemo/Tizen, Fedora, Gentoo, Slackware, and a few other distros should also work with this method.
Working as of March 30, 2013:
* Touchscreen, 10-point multitouch!
* Unaccelerated X11 with fbdev, framebuffer console disabled for cleaner boot.
* Charging, battery meter
* WiFi
* Sound! NB, the hack I used to get it working disables the codec shutdown sequence, which could affect battery life and prevent the phone from sleeping.
Partially working:
* Keyboard (incomplete layout; not sure what to do with Fn/3rd level key mapping)
* Cameras (recognized as V4L2 devices but VLC complains with "invalid pixel format" so the drivers probably need fixing)
* Sensors/autorotate (sensors recognized in kernel/X11/SDL, I'm working on auto rotation)
Not tested:
* Bluetooth
* GPS
* Calls/data: https://github.com/morphis/libsamsung-ipc
Step by step guide!
PREREQUISITES:
* An Epic 4G with a custom recovery and a microSD card. 2GB free space on the card recommended.
* A Linux computer. Sorry, Windows/Mac users, you're on your own.
Step 0: Get the files you need
Extract the contents of linux_epicmtd.zip to a new folder somewhere and change to that folder in your terminal.
Step 1: Partition your SD card
Please backup of the contents of your SD card before doing anything else.
You can do this by mounting USB storage, but I prefer to remove the card and put it in a USB card reader, that way it's harder to accidentally disconnect it and corrupt data.
What you want to do is shrink the FAT partition from a computer by 2GB and create a new ext2/4 partition out of that free space.
2GB should more than suffice for a minimal Ubuntu install, but if you intend to install Unity (ubuntu-desktop) or other big packages, you may need anywhere from 2GB to 4GB, or possibly more. Resize accordingly.
The following instructions assume the Linux partition you just created is labeled "Ubuntu" and the FAT partition you resized is labeled "microSD". If you don't label them, your mount points will be different.
Step 2: Install Ubuntu on the second partition
Code:
# Assumes your new Ubuntu partition is mounted at "/media/$USER/Ubuntu"
wget http://cdimage.ubuntu.com/ubuntu-core/daily/current/raring-core-armhf.tar.gz
tar xvf raring-core-armhf.tar.gz -C /media/$USER/Ubuntu
Step 3: Configure the filesystem
Code:
# to chroot into the ARM rootfs on a non-ARM computer:
sudo apt-get install qemu-user-static
sudo cp /usr/bin/qemu-arm-static /media/$USER/Ubuntu/usr/bin
sudo mount -o remount,dev /media/$USER/Ubuntu
sudo chroot /media/$USER/Ubuntu
# check /etc/apt/sources.list and make sure universe is enabled
apt-get update
apt-get dist-upgrade
# select your preferred desktop environment
apt-get install {k,x,l,}ubuntu-desktop e17 gnome-session-fallback plasma-active
adduser yournamehere
usermod -a -G audio yournamehere
passwd yournamehere
tzselect
# do anything else you want to do, exit the chroot, then run the following commands from your working folder:
sudo cp X11.txt to /media/$USER/Ubuntu/etc/X11/xorg.conf
sudo cp modules.txt /media/$USER/Ubuntu/etc/modules
adb pull /vendor/firmware/fw_bcmdhd.bin
adb pull /system/etc/wifi/nvram_net.txt
sudo cp fw_bcmdhd.bin nvram_net.txt /media/$USER/Ubuntu/lib/firmware
Step 4: Install the kernel, copy the kexec zip to your SD card, and boot!
Option 1: Use my pre-built kernel.
Code:
cp zImage /media/$USER/microSD
sudo tar xvf modules.tar.gz -C /media/$USER/Ubuntu
cp boot_zImage.zip /media/$USER/microSD
Option 2: Build the kernel from source.
Code:
sudo apt-get install build-essential git gcc-arm-linux-gnueabi libncurses5-dev
git clone git://github.com/CyanogenMod/android_kernel_samsung_epicmtd
cd android_kernel_samsung_epicmtd
git checkout cm-10.1
git apply ../linux_epicmtd.patch
export CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm
cp ../epicmtd_defconfig.txt .config
# make menuconfig if you want to enable the framebuffer console or customize anything
make -j8
sudo make modules_install INSTALL_MOD_PATH=/media/$USER/Ubuntu ARCH=arm
cp arch/arm/boot/zImage /media/$USER/microSD
cd ..
cp boot_zImage.zip /media/$USER/microSD
Reboot into recovery, install zip from sdcard, select boot_zImage.zip, and enjoy your new Ubuntu installation!
First! Very excited for this. Any screens available?
Sent from my Tangerine Dream Epic 4G using xda premium
Hmm can get my phone working on linux pretty flawlessly but my laptop just doesn't like it go figure. Anyways those are my issues [ would be cool if I could find someone to help me with my linux issues] but anyways this is pretty sweet .
Sent from my SPH-D700 using xda premium
Wow, did not see this coming! Gonna attempt this weekend. Awesome work
Sent from my MIUI V4 Epic 4G via Tapatalk 2 beta 5
How is 12.04 for PC in its current state? I'm on 11.10 and I would consider switching, if it wasn't buggy and what not.
Sent from my SPH-D700 using XDA
tdwp16 said:
How is 12.04 for PC in its current state? I'm on 11.10 and I would consider switching, if it wasn't buggy and what not.
Sent from my SPH-D700 using XDA
Click to expand...
Click to collapse
In my honest opinion, Ubuntu sucks since the 9.x days. I would try out the gnome version of LMDE (Linux Mint Debian Edition). You will never want to go back.
Sent from my SPH-D700 using Tapatalk
I tried out the last Linux mint. I kept having problems with the music player freezing my computer. idk how but that's the only thing that did it. So I switches back yo Ubuntu after using mint for a year or two and just loaded gnome shell.
Sent from my SPH-D700 using XDA
tdwp16 said:
I tried out the last Linux mint. I kept having problems with the music player freezing my computer. idk how but that's the only thing that did it. So I switches back yo Ubuntu after using mint for a year or two and just loaded gnome shell.
Sent from my SPH-D700 using XDA
Click to expand...
Click to collapse
LMDE is very different from the old mint.
Sent from my SPH-D700 using Tapatalk
I'll try it just because you said so marc. I'll just make another partition for it and play with it. If I like it I'll deff let you know.
Sent from my SPH-D700 using XDA
tdwp16 said:
I tried out the last Linux mint. I kept having problems with the music player freezing my computer. idk how but that's the only thing that did it. So I switches back yo Ubuntu after using mint for a year or two and just loaded gnome shell.
Sent from my SPH-D700 using XDA
Click to expand...
Click to collapse
weird, i had the EXACT same issue with my last debian install. A while back, but still weird...
beltsnspoons said:
weird, i had the EXACT same issue with my last debian install. A while back, but still weird...
Click to expand...
Click to collapse
I have no clue what it was. I tried everything. Looked up solutions ant there were none. I reinstalled 3 times and it still did it
Sent from my SPH-D700 using XDA
tdwp16 said:
How is 12.04 for PC in its current state? I'm on 11.10 and I would consider switching, if it wasn't buggy and what not.
Click to expand...
Click to collapse
12.04 is actually quite stable. I think they finally got GNOME Fallback ("Classic") right as well - it's set up more like 10.10 with some usability improvements. I never really liked Unity, but it also felt more stable than the version in 11.10 did.
tdwp16 said:
I have no clue what it was. I tried everything. Looked up solutions ant there were none. I reinstalled 3 times and it still did it
Sent from my SPH-D700 using XDA
Click to expand...
Click to collapse
You can always use vlc instead
Sent from my SPH-D700 using Tapatalk
marcusant said:
You can always use vnc instead
Click to expand...
Click to collapse
Correct me if I'm wrong, but I'm pretty sure they're referring to Debian and/or Linux Mint bugs on the desktop.
Somewhat off-topic, but with a guide this complicated, I don't expect many people to try it. The VNC hack still works, but it's too slow for me, which is the main reason I decided to boot natively.
On a somewhat related note, this can completely replace Android if you are so inclined, but unless you can figure out the internal storage, I still recommend booting from the SD card. You can permanently flash the kernel with Heimdall if you hate Android enough
Err... vlc
Sent from my SPH-D700 using Tapatalk
gTan64 said:
Correct me if I'm wrong, but I'm pretty sure they're referring to Debian and/or Linux Mint bugs on the desktop.
Somewhat off-topic, but with a guide this complicated, I don't expect many people to try it. The VNC hack still works, but it's too slow for me, which is the main reason I decided to boot natively.
On a somewhat related note, this can completely replace Android if you are so inclined, but unless you can figure out the internal storage, I still recommend booting from the SD card. You can permanently flash the kernel with Heimdall if you hate Android enough
Click to expand...
Click to collapse
I had a spell check error lol.
Sent from my SPH-D700 using Tapatalk
oh. em. gee.
awesome... When i finish with my epic i can turn it into a small little tablet now.
BtW, Debian beats the mint so hard... I hate Mint and Ubuntu so im glad those are not the only options.
Doing this right now, will report back with screenies soon.
Edit: everything went swimmingly up until step 3 (I know my way around linux but still pretty noobish):
[email protected]:~$ tar xvf /path/to/victory_patches.tar -C /path/to/
tar: /path/to/victory_patches.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
[email protected]:~$ cd android_kernel_samsung_victory
[email protected]:~/android_kernel_samsung_victory$ scripts/patch-kernel . /path/to/patches
bash: scripts/patch-kernel: No such file or directory
[email protected]:~/android_kernel_samsung_victory$ cp /path/to/victory_config.txt .config || make -C Kernel cyanogenmod_epicmtd_defconfig
cp: cannot stat `/path/to/victory_config.txt': No such file or directory
make: Entering directory `/home/xopher/android_kernel_samsung_victory/Kernel'
HOSTCC scripts/basic/fixdep
HOSTCC scripts/basic/docproc
HOSTCC scripts/basic/hash
HOSTCC scripts/kconfig/conf.o
scripts/kconfig/conf.c: In function ‘conf_sym’:
scripts/kconfig/conf.c:159:6: warning: variable ‘type’ set but not used [-Wunused-but-set-variable]
scripts/kconfig/conf.c: In function ‘conf_choice’:
scripts/kconfig/conf.c:231:6: warning: variable ‘type’ set but not used [-Wunused-but-set-variable]
scripts/kconfig/conf.c:307:9: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
scripts/kconfig/conf.c: In function ‘conf_askvalue’:
scripts/kconfig/conf.c:105:8: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
HOSTCC scripts/kconfig/kxgettext.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/lex.zconf.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
make: Leaving directory `/home/xopher/android_kernel_samsung_victory/Kernel'
[email protected]:~/android_kernel_samsung_victory$ # Check hints.txt for customization tips.
[email protected]:~/android_kernel_samsung_victory$ make -C Kernel menuconfigmake -C Kernel -j8
make: *** Kernel: No such file or directory. Stop.
[email protected]:~/android_kernel_samsung_victory$ make -C Kernel -j8
make: /home/bbelos/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc: Command not found
make: Entering directory `/home/xopher/android_kernel_samsung_victory/Kernel'
scripts/kconfig/conf -s arch/arm/Kconfig
make: Leaving directory `/home/xopher/android_kernel_samsung_victory/Kernel'
make: /home/bbelos/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc: Command not found
make: Entering directory `/home/xopher/android_kernel_samsung_victory/Kernel'
CHK include/linux/version.h
UPD include/linux/version.h
CHK include/generated/kernelversion.h
UPD include/generated/kernelversion.h
CHK include/generated/utsrelease.h
CC scripts/mod/empty.o
/bin/sh: /home/bbelos/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc: not found
make[2]: *** [scripts/mod/empty.o] Error 127
make[1]: *** [scripts/mod] Error 2
make: *** [scripts] Error 2
make: *** Waiting for unfinished jobs....
UPD include/generated/utsrelease.h
make: Leaving directory `/home/xopher/android_kernel_samsung_victory/Kernel'
[email protected]:~/android_kernel_samsung_victory$
Sent from my MIUI V4 Epic 4G via Tapatalk 2 beta 5
You are using /path/to/patches... you need to put the path there...
Sent from my SPH-D700 using Tapatalk

[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

[Completed] Ninja_wrapper error

building my very first nougat ROM for the GT-I9505 (Jfltexx) but I keep getting this error when use the brunch command.
Starting build with ninja
ninja: Entering directory `.'
ninja: error: '/home/lochlan/LAOS/out/target/product/jfltexx/obj/lib/libtime_genoff.so.toc', needed by '/home/lochlan/LAOS/out/target/product/jfltexx/obj/SHARED_LIBRARIES/libandroid_servers_intermediates/LINKED/libandroid_servers.so', 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/lochlan/LAOS'
I've done some research and still haven't come to a conclusion on what the hell it means...
Any and all help would be nice!
skyskidder said:
building my very first nougat ROM for the GT-I9505 (Jfltexx) but I keep getting this error when use the brunch command.
Starting build with ninja
ninja: Entering directory `.'
ninja: error: '/home/lochlan/LAOS/out/target/product/jfltexx/obj/lib/libtime_genoff.so.toc', needed by '/home/lochlan/LAOS/out/target/product/jfltexx/obj/SHARED_LIBRARIES/libandroid_servers_intermediates/LINKED/libandroid_servers.so', 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/lochlan/LAOS'
I've done some research and still haven't come to a conclusion on what the hell it means...
Any and all help would be nice!
Click to expand...
Click to collapse
Did you get the vendor repo for your device? Please pay attention on this. I think your vendor repo is outdated and file libtime_genoff.so is missing.
blinoff82 said:
Did you get the vendor repo for your device? Please pay attention on this. I think your vendor repo is outdated and file libtime_genoff.so is missing.
Click to expand...
Click to collapse
Hello, this is what I'm using for my vendor repo
https://github.com/JDCTeam/android_vendor_cm
And you are correct about libtime_genoff.so is missing. I checked all my repos for that file and have gotten no results. Any idea on what I should do?
P.S. Thanks for your help thus far! It means a lot!
skyskidder said:
Hello, this is what I'm using for my vendor repo
https://github.com/JDCTeam/android_vendor_cm
And you are correct about libtime_genoff.so is missing. I checked all my repos for that file and have gotten no results. Any idea on what I should do?
P.S. Thanks for your help thus far! It means a lot!
Click to expand...
Click to collapse
You should use another vendor blobs like this https://github.com/DonkeyCoyote/proprietary_vendor_samsung/tree/android-7.1/jflte.
Add in local_manifest (roomservice.xml):
<project name="DonkeyCoyote/proprietary_vendor_samsung" path="vendor/samsung" revision="android-7.1" remote="github" />
Then: "repo sync -j1 --force-sync" and build again.
I never encountered with Samsung devices, I hope I did not make a mistake with path...
blinoff82 said:
You should use another vendor blobs like this https://github.com/DonkeyCoyote/proprietary_vendor_samsung/tree/android-7.1/jflte.
Add in local_manifest (roomservice.xml):
<project name="DonkeyCoyote/proprietary_vendor_samsung" path="vendor/samsung" revision="android-7.1" remote="github" />
Then: "repo sync -j1 --force-sync" and build again.
I never encountered with Samsung devices, I hope I did not make a mistake with path...
Click to expand...
Click to collapse
Hey thanks for the idea on using this new repo for the device blobs and providing the link! But i have a few questions.
#1. There are severely many less files in this new repo. Why is that?
#2 This effect anything with my rom? if so like what?
You dont need to give me a full out explanation a brief one will do if you can, if you cant dont sweat it!
I will also try this new repo when i get home and I'll update you on how it goes.
Thank you so very much!
-Sky
skyskidder said:
#1. There are severely many less files in this new repo. Why is that?
#2 This effect anything with my rom? if so like what?
Click to expand...
Click to collapse
1. Because this repo ONLY for jflte.
2. No effect, this is just blobs needed for your device and for compilation.
blinoff82 said:
1. Because this repo ONLY for jflte.
2. No effect, this is just blobs needed for your device and for compilation.
Click to expand...
Click to collapse
Welp. I tried what you told me to do and Ive gotten farther but i ran into another error.
FAILED: /bin/bash -c "(make -j2 -C kernel/samsung/jf O=/home/lochlan/LAOS/out/target/product/jfltexx/obj/KERNEL_OBJ ARCH=arm CROSS_COMPILE="/home/lochlan/LAOS/prebuilts/misc/linux-x86/ccache/ccache arm-linux-androidkernel-" VARIANT_DEFCONFIG= SELINUX_DEFCONFIG= cyanogenmod_jf_defconfig ) && (if [ ! -z "" ]; then echo "Overriding kernel config with ''"; echo >> /home/lochlan/LAOS/out/target/product/jfltexx/obj/KERNEL_OBJ/.config; make -j2 -C kernel/samsung/jf O=/home/lochlan/LAOS/out/target/product/jfltexx/obj/KERNEL_OBJ ARCH=arm CROSS_COMPILE="/home/lochlan/LAOS/prebuilts/misc/linux-x86/ccache/ccache arm-linux-androidkernel-" oldconfig; fi ) && (make -j2 -C kernel/samsung/jf O=/home/lochlan/LAOS/out/target/product/jfltexx/obj/KERNEL_OBJ ARCH=arm CROSS_COMPILE="/home/lochlan/LAOS/prebuilts/misc/linux-x86/ccache/ccache arm-linux-androidkernel-" savedefconfig ) && (if [ ! -z "" ]; then echo "Using additional config ''"; kernel/samsung/jf/scripts/kconfig/merge_config.sh -m -O /home/lochlan/LAOS/out/target/product/jfltexx/obj/KERNEL_OBJ /home/lochlan/LAOS/out/target/product/jfltexx/obj/KERNEL_OBJ/.config kernel/samsung/jf/arch/arm/configs/; make -j2 -C kernel/samsung/jf O=/home/lochlan/LAOS/out/target/product/jfltexx/obj/KERNEL_OBJ ARCH=arm CROSS_COMPILE="/home/lochlan/LAOS/prebuilts/misc/linux-x86/ccache/ccache arm-linux-androidkernel-" KCONFIG_ALLCONFIG=/home/lochlan/LAOS/out/target/product/jfltexx/obj/KERNEL_OBJ/.config alldefconfig; fi )"
make: Entering directory '/home/lochlan/LAOS/kernel/samsung/jf'
GEN /home/lochlan/LAOS/out/target/product/jfltexx/obj/KERNEL_OBJ/Makefile
HOSTCC scripts/basic/fixdep
/home/lochlan/LAOS/kernel/samsung/jf/scripts/basic/fixdep.c:106:23: fatal error: sys/types.h: No such file or directory
compilation terminated.
scripts/Makefile.host:118: recipe for target 'scripts/basic/fixdep' failed
make[2]: *** [scripts/basic/fixdep] Error 1
/home/lochlan/LAOS/kernel/samsung/jf/Makefile:417: recipe for target 'scripts_basic' failed
make[1]: *** [scripts_basic] Error 2
Makefile:130: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2
make: Leaving directory '/home/lochlan/LAOS/kernel/samsung/jf'
[ 6% 2204/33925] target R.java/Manifest.java: framework-res (/home/lochlan/LAOS/out/target/common/obj/APPS/framework-res_intermediates/src/R.stamp)
warning: string 'candidates_style' has no default translation.
warning: string 'gsm_alphabet_default_charset' has no default translation.
warning: string 'wfcSpnFormat' has no default translation.
nothing matches overlay file default_wallpaper.png, for flavor hdpi-v4
nothing matches overlay file default_wallpaper.png, for flavor xhdpi-v4
nothing matches overlay file default_wallpaper.png, for flavor xxhdpi-v4
nothing matches overlay file default_wallpaper.png, for flavor xxxhdpi-v4
ninja: build stopped: subcommand failed.
build/core/ninja.mk:151: recipe for target 'ninja_wrapper' failed
make: *** [ninja_wrapper] Error 1
make: Leaving directory '/home/lochlan/LAOS'
#### make failed to build some targets (08:00 (mm:ss)) ####
Click to expand...
Click to collapse
Any idea what this error is?
Sorry my friend you should think for yourself. That's all.
http://stackoverflow.com/questions/37771339/sys-types-h-no-such-file-or-directory
:QUICK UPDATE:
I don't think I'm ready to tackle a project of this scale yet. My frustration, lack of knowledge of compiling and knowledge of repo commands, java, and the damn terminal have caused as of now to post pone my attempts at making a ROM. With exams coming up I have take EVEN MORE time away from my attempts.
:SIDE NOTES:
I feel I have made some progress since the last post I have made with the help of @binoff82 of course. Slowly but surely I'm getting there. With the expense of many broken things in my room... Including a fractured wrist...
In a few days and or weeks time I will update the thread with another post either explaining my progress or if I'm just going to halt my attempts completely for quite a while.
-Sky
P.S. I should probably take anger management classes...
skyskidder said:
:QUICK UPDATE:
I don't think I'm ready to tackle a project of this scale yet. My frustration, lack of knowledge of compiling and knowledge of repo commands, java, and the damn terminal have caused as of now to post pone my attempts at making a ROM. With exams coming up I have take EVEN MORE time away from my attempts.
:SIDE NOTES:
I feel I have made some progress since the last post I have made with the help of @binoff82 of course. Slowly but surely I'm getting there. With the expense of many broken things in my room... Including a fractured wrist...
In a few days and or weeks time I will update the thread with another post either explaining my progress or if I'm just going to halt my attempts completely for quite a while.
-Sky
P.S. I should probably take anger management classes...
Click to expand...
Click to collapse
Greetings and welcome to assist. Have you seen this excellent guide by jackeagle ?
https://forum.xda-developers.com/chef-central/android/guide-android-rom-development-t2814763
that thread is probably your best bet for advice
Good Luck
Sawdoctor
sawdoctor said:
Greetings and welcome to assist. Have you seen this excellent guide by jackeagle ?
https://forum.xda-developers.com/chef-central/android/guide-android-rom-development-t2814763
that thread is probably your best bet for advice
Good Luck
Sawdoctor
Click to expand...
Click to collapse
Hi, thanks for taking your time to help me. Sadly this is the original guide I have been following when attempting to build my ROM.

[REFERENCE] How to compile an Android kernel

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

Categories

Resources