Linux kernel building how-to - HTC One SV

I got this dang phone because I was told it was compatible with GSM networks and of course I was such a noob then. LOL, since then though I have taught myself a great deal in a short amount of time with endless nights searching all corners of the internet for links, hints, secrets and of course roms and kernels.
I dont care about a rom at this point I want and need a custom kernel for this phone I have no OS but when I run RUU it works fine-ish. I solve each problem as they come up but I am getting so tired of all the nonsense I have to do to this phone.
Unfortunately unless circumstances change I am stuck with it because I have had some major life changes and I cant afford another phone like I am on a romin and egg diet poor.
If someone could just cook up a kernel for this dang phone I will be forever grateful. I will test, logcat whatever u want to make it easier for u just help please this.:fingers-crossed::fingers-crossed:
Device: K2PLCCL pvt ship s-off RL
CID-11111111
Hboot 2.21
Radio 1.12.00.1029
OpenDSP-v10.2.0268.0401
eMMC1024 mb

Fant0m3 said:
I got this dang phone because I was told it was compatible with GSM networks and of course I was such a noob then. LOL, since then though I have taught myself a great deal in a short amount of time with endless nights searching all corners of the internet for links, hints, secrets and of course roms and kernels.
I dont care about a rom at this point I want and need a custom kernel for this phone I have no OS but when I run RUU it works fine-ish. I solve each problem as they come up but I am getting so tired of all the nonsense I have to do to this phone.
Unfortunately unless circumstances change I am stuck with it because I have had some major life changes and I cant afford another phone like I am on a romin and egg diet poor.
If someone could just cook up a kernel for this dang phone I will be forever grateful. I will test, logcat whatever u want to make it easier for u just help please this.:fingers-crossed::fingers-crossed:
Device: K2PLCCL pvt ship s-off RL
CID-11111111
Hboot 2.21
Radio 1.12.00.1029
OpenDSP-v10.2.0268.0401
eMMC1024 mb
Click to expand...
Click to collapse
I can help you through a PM on how to set your computer up properly so you can build a kernel yourself. Can begin building it without modifications then when ready, start adding some patches which in most cases is merely just copying and pasting assuming the patch is compatible.
It really isn't difficult.
You need linux installed firstly if running windows.
Sent from my C525c using Tapatalk

U ROCK!!!!!
Modding.MyMind Won't be from me lol. Just found out this morning that I am going to be a father.
Sent from my C525c using Tapatalk
Congrats man I have a bundle of kids love them all my newest one is 3months....:good:
So u helping me would be amazing. You are using the word not hard about k2plc. Anything and everything about this phone is difficult except the hardware....lol. So I did some real heavy research today about my errors on flashing, why things won't go to my device and why I keep getting mount errors. It's the kernel as we all know, but I don't think it will be as such a daunting task to create one I mean once I know what I am doing.
Brief rundown I was bait and switched into this phone long story there. I have recently had a string of bad luck so I'm strapped to find a new one. Everything that I know I've learned over the last two months with a ton of trial and errors many bricks conquered and many triumphs achieved.
With that said I do get lost a bit on terminology and stuff. But I unlocked bootloader installed adb both wired and wireless.
Super cid phone 2twice two different ways lol. Last one stuck cause I turned off the ota odex. Flashed three roms all with the same problem no data and no mms. So some patients may be in order.
Also about linux I thought it was I am just not SElinux I downloaded this
arm-eabi-4.6-d73a051b1fd1d98f5c2463354fb67898f0090bdb.tar and this just recently and ran them as well. Am I suppesed to run them to phone or computer...the Java commands confuse me like crazy right now as I am still new.
Now back to what I researched. I found this file it talks all about SElinux and how it effects your kernel. Cant we just in some way disable those two or three scripts that is blocking from converting and flashing roms, boots. and zips.
selinuxproject.org/~jmorris/lss2011_slides/caseforseandroid.pdg
PM me modding and I will give you my email...I check that more often.
I've learned that our Kernel is SElinux blocked and u have to know and use proper toolchain to bypass this. sorry cant post links yet

@Fant0m3, I'm pretty sure your device is not using selinux. You can confirm just by opening up es file explorer on your device and selecting, "/", which from their you will see "file_context" amongst others. Our kernel source comes with selinux in it, but selinux is not enabled through the defconfig file from the source. You would have to modify that file, build your kernel, flash/install kernel, then at that point you would have selinux support. However, I seriously doubt your kernel is using selinux.
In addition, do not flash any Rom to your device unless the Rom is specific to your device. You can't just use roms from other devices. It does not work that way. If it did, then there would be no need for the HTC One SV, the HTC One M8, the Samsung Galaxy, etc, etc. There would just be one android phone like you see with the iPhone, however, this is obviously not the case.
The toolchain is required to build your kernel from source. And 4.6 is exactly the one you properly need to build your kernel.
Anyways, hope some of this was helpful/useful insight.
Edit: Open a terminal (ctrl + alt + t). First install the necessary packages; copy paste the code below and hit enter. This will set up your linux system for proper development, like building a kernel for example.
Code:
sudo apt-get update && sudo apt-get install git-core gnupg flex bison gperf libsdl1.2-dev libesd0-dev libwxgtk2.8-dev squashfs-tools build-essential zip curl libncurses5-dev zlib1g-dev openjdk-6-jre openjdk-6-jdk pngcrush schedtool libxml2 libxml2-utils xsltproc lzop libc6-dev schedtool g++-multilib lib32z1-dev lib32ncurses5-dev lib32readline-gplv2-dev gcc-multilib
Sent from my C525c using Tapatalk

@ ModdingMyMind
Okay lol I was half asleep writing that last night.
When I am in recovery mode, I run TWRP 2.7.0.1 and when I bring up the logcat it say Kernel lacks support for reading SElinux. When I was reading that article, which it will not allow me to link yet otherwise I would, it was saying that the kernel was built with linux support but was built with SElinux support.
Either way not that big of deal. I am willing wanting to learn how to build a kernel and hopefully more as I learn and continue to learn
I flashed those other roms before I realized that I shouldn't run them on this phone. But I was under the impression that we can and thats part of the reason we root our phones is to run AOSP roms. The reason we cant with this phone is because there isnt an kernel built to read such open sources. Also and AOSP rom to my understanding is basically just replacing all your visual effects and removing the stock one. Basically the same thing like GOlauncher or NextLauncher does but its better cause u eliminate the processes from your stock rom so it doesnt bog your system down. I could and can be wrong I am a lot with this new found interest in Android applications.
so what is that code you posted. Please forgive me I am a noob and dont get the lingo and kinda need layman's terms for things and explanations. I learn very quick though so explaining the process once should more than suffice. I am only recently divulging into the forums cause I am more comfortable with my abilities and refrained from sounding like a complete NOOB.

Ubuntu?
Okay I have def heard the name did not know and was a bit confused on what it was. Now I know <---- told u NOOB who learns on his own lol. I am downloading now but I already have a program I think that does the same thing "phantomjs" and no relation to my name I have used my online name for 20 years lol.
Now does this program do the same thing and should I even install ubuntu.
What is the best way to designate which device to download stuff to I find this has been coming up lately usually people just say download this...blah blah blah. But never designate the best path or device to use for the download. NOOB remember. I usually figure it out but adds more time to my process as I then have to research something else. I am getting the hang of it though.
Also is there an application out there that will designate what system will run what applications and download them into the corresponding folder to either be transferred to the proper corresponding folder i.e.:
Microsoft applications go to microsoft folder.
Linux goes to a Linux folder or a fold you created for linux apps.
Android goes to a android folder.
Mac goes to some apple folder if u choose to work on Iphones and such.
If not this seems like a very oversighted program that could easily be created/tested/deployed and would be very useful to keep your computer clean.
Excuse me but my mind works a billion times a minute and this is why I want to divulge myself in this stuff because there is never an end to the useful things that could be created.
Why I am on that again why the play store more interactive to your mobile device it seems just a few scripts and build files and they could diagnose what phone is being used and only show and promote to u which applications are compatible with said phone...excuse me for rambling
:silly::cyclops:

To build from source such as a kernel for example it is highly recommended you install a linux distro. I personally use Ubuntu myself.
Your TWRP says their is no SElinux support from the kernel because the kernel used to build the twrp you are currently using was not built with SElinux support itself. The kernel source has to be modified in order to add SElinux support and therefore TWRP to show that there is SElinux support detected. I know, because I had to do this for my TWRP build .
I'm at work so I have only skimmed through some of your posts. Haven't read it all which is why my response is currently short.
Sent from my C525c using Tapatalk

Modderator
Just wanted to say to the moderator that I believe this conversation should be moved i.e. posted in its own thread for linux kernel building I am sure I am not the only noobish person looking for help in doing or building a kernel.

Alright, I'm back. In regards to AOSP. It won't just simply work for any device even if the kernel is modified for proper support. AOSP is a large open source project. Just like CM, OmniRom, etc. The source has to be download, then you must put together a device tree which is basically a bunch of ".mk" files along with things which are needed specifically for your device. Would go in grave detail about this, but that is a tutorial in itself. Nevertheless, once all that has bee setup, you proceed to build the Rom then install to your device and proceed to work out any bugs (which there will be bugs).
I do not use windows. I use linux. Linux is required in order to build/develop kernels, Roms, etc. If you are using windows then you must either split your system for dual booting between windows and linux or you must run a virtual program that will allow for linux to operate on your computer while also running windows at the same time. I HIGHLY RECOMMEND you remove windows and do a clean install of linux if you plan to develop.
Sent from my C525c using Tapatalk
---------- Post added at 10:19 PM ---------- Previous post was at 09:42 PM ----------
To build a kernel, it must be done on linux. You need an arm toolchain. For our kernel source, arm-eabi-4.6 is recommended. To use a different toolchain other than that would require you to make some changes to the kernel source to prevent build errors.
You have to export the path to your toolchain.
Here is a script I use when building my kernel. Study it and it should be helpful for you.
PHP:
#!/bin/bash
#######################################
# Remove prebuilt kernel from last build
#rm ~/cm11/kernel/htc/k2_cl/output/kernel/zImage
if [ -e zImage ]; then
rm zImage
fi
#######################################
#######################################
# Remove logs from last build
rm kernelcompile.log
rm modulecompile.log
#######################################
############################################################
# Set Default Path's here!
TOP_DIR=$PWD
# KERNEL_PATH is the folder where your kernel source is located.
KERNEL_PATH="/home/moddingmymind/cm11/kernel/htc/k2_cl"
# STRIP is the strip brinary from the toolchain to strip unneeded symbols after the build is finished to help reduce size.
STRIP="/home/moddingmymind/arm-eabi-4.6/bin/arm-eabi-strip"
# OUTPUT is the folder where I place my finish builds.
OUTPUT="/home/moddingmymind/cm11/kernel/htc/k2_cl/output"
# Set toolchain path here! This will be the directory to your current toolchain.
TOOLCHAIN="/home/moddingmymind/arm-eabi-4.6/bin/arm-eabi-"
############################################################
#######################################
# KBUILD_BUILD_VERSION will set the name of the final build.
export KBUILD_BUILD_VERSION="JesusFreak"
# KERNELDIR is the path to the folder where your kernel source is located at.
export KERNELDIR=$KERNEL_PATH
#######################################
#echo "Cleaning latest build"
# make is a simple command needed to build makefiles.
# ARCH is simply telling it what type of architecture the machine is.
# CROSS_COMPILE is merely pointing the building process to the actual toolchain needed to make this work.
# The following is simply determining how many processors your computer currently has and applies that to "-j#" where "#" is your total processors. This reflects the speed of your build.
make ARCH=arm CROSS_COMPILE=$TOOLCHAIN -j`grep 'processor' /proc/cpuinfo | wc -l` mrproper
# Making our .config
#Sources will always have a defconfig file. For the kernel, you MUST make your .config file specific to your device or your build WILL fail.
make k2_cl_defconfig
# Make our menuconfig before proceeding with the build.
# This will bring up a window where you can make neceassary changes to your kernel source through a gui implementation prior to building your source.
make menuconfig
# Make Kernel using proper number of processors and store verbose in log file for review.
make -j`grep 'processor' /proc/cpuinfo | wc -l` zImage ARCH=arm CROSS_COMPILE=$TOOLCHAIN >> kernelcompile.log 2>&1 || exit 1
# Make Modules using proper number of processors and store verbose in log file for review
make -j`grep 'processor' /proc/cpuinfo | wc -l` modules ARCH=arm CROSS_COMPILE=$TOOLCHAIN >> modulecompile.log 2>&1 || exit 1
# make ARCH=arm CROSS_COMPILE=$TOOLCHAIN -j4 modules >> modulecompile.log
# Copying kernel modules after making install of modules
sudo make modules_install
mkdir $OUTPUT/tempo;
cp -r '/lib/modules/3.4.10.JesusFreak/kernel' $OUTPUT/tempo/;
sudo rm -rf '/lib/modules/3.4.10.JesusFreak';
find $OUTPUT/tempo/kernel/ -name '*.ko' -exec cp -av {} $OUTPUT/modules/ \;
rm -rf $OUTPUT/tempo;
# Strip modules
cd $OUTPUT/modules
$STRIP --strip-unneeded *.ko
# Copy Kernel Image
rm -f $OUTPUT/$KBUILD_BUILD_VERSION.zip
cp -f $KERNEL_PATH/arch/arm/boot/zImage $OUTPUT/prebuilt/zImage
# CREATE A ZIP which is prebuilt for flashing in the recovery to install and use.
cd $OUTPUT
zip -r $KBUILD_BUILD_VERSION.zip *
# Remove builds after the zip is completed.
rm -f $OUTPUT/prebuilt/zImage
rm -f $OUTPUT/modules/*.ko
Sent from my C525c using Tapatalk

okay sweet
Okay so it seems I should have known this information before even making it this far with my phone lol...
So Ubuntu is not like a emulator I run over windows it is yet another more developer friendly system software correct? If it's true then it would be easier running and familurizing myself with the linux systems and it's applications. I'm dead serious on working towards development. It's finally something to ease the busy mind.
Could u point me in the right direction to what kinda hardware would be best suited for this type work. My business model is almost finished but I need research on the proper systems and costs for the personal business loan that I will be applying for. I'm currently just using dual laptops and a phone.
Yes the one SV. As much as this phone has troubled me it has almost helped in a way because of the frustrations that go along with it.
I am also at work so my grammer is probably horrid as I am on my phone.
Thanks for the patients and lessons this stuff is definitely not for those easily detered.

Hardware isn't a big to do issue when building a kernel. However, it is usually recommended to have a SDD vice HDD. This will run much faster and smoother while handling your sources. It is also suggested to have at least 6 gigs of ram or more. However, I use my laptop which currently only holds 2 gigs of ram and roughly 200 gigs for storage on my computer. In other words, my laptop is very weak, but I can still develop with it without any problems. Just have to be cautious of the laptops temperature to insure I don't kill it lol.
You can go to Ubuntu website. They have the system you can download to install on your computer. They also have a very detailed instruction on how to remove windows properly and how to install ubuntu properly. Make sure you save important stuff as needed because wants you remove windows everything will be lost.
Sent from my C525c using Tapatalk

Sorry
I went a bit MIA for a bit my work schedule, plus my ex wife and everything with my minions got me scattered I am still interested and working on wanting to go down this path and maybe further as I expand my knowledge. I will hopefully soon find some time to jump back in but I will most likely be stuck till this weekend without diving into this project. I do have another laptop that I plan to use for linux and will get it all set up and try to follow steps to with Ubuntu and u @moddingMyMind. Hopefully soon we can get this done. lol.....I was wondering if we could create a more generic one for other to download and flash into their system as well if not its cool I will just stick with mine.

Nah, a generic one won't happen. At best, you could make your patches for your source, then apply those patches to their sources. Build all of them, then create a flashable zip which will systematically determine which device is which as to allow itself to properly determine which kernel it should write to the device as well as to which proper partition. Wouldn't be that hard to put something like that together though.
I'm currently busy myself. I was successful at compiling GraphicsMagick for my device and am currently writing a shell script which will pick up all images from a twrp theme, determine their original sizes one by one, then determine their new sizes and finally making the changes to properly resize each image for it's ending porting results. It's almost done. I just need to figure out a script for handling the ui.xml so I can be complete with my project and thus be able to port TWRP themes in just minutes vices HOURS and even days in some cases if I am taking my sweet time.
Sent from my C525c using Tapatalk

That's awesome I'm still afraid to try a theme for teepee lol that is my life line as of late.
I was thinking though is there an app for your file system that will clean up any repeated files like let's say music or busybox applets and so on and so on. This would save me tons of time and storage space..... I think I may need a how to for dummies book lol... Just when I feel I have it figured out basically then I discover something new Smh...
BTW good luck I can test dummy things if needed as well
Sent from my HTC One SV using XDA Free mobile app

Fant0m3 said:
That's awesome I'm still afraid to try a theme for teepee lol that is my life line as of late.
I was thinking though is there an app for your file system that will clean up any repeated files like let's say music or busybox applets and so on and so on. This would save me tons of time and storage space..... I think I may need a how to for dummies book lol... Just when I feel I have it figured out basically then I discover something new Smh...
BTW good luck I can test dummy things if needed as well
Sent from my HTC One SV using XDA Free mobile app
Click to expand...
Click to collapse
A little trick to saving space with busybox on your phone.... Don't install it with symlinks which creates all those applets. Instead, just grap an app from the play store if you want which will supposedly install busybox and rename the app from .apk to .apk.zip. Extract the contents and you will find the busybox binary. Place the binary in /system/bin and give the binary permissions of either 755 or 777. Then to use busybox applets just type busybox for a list of commands. To use busybox for example would be like this:
busybox mv -f /sdcard/name.txt /sdcard/newname.txt
mv is an applet from busybox which will move files and stuff. But you can also use it to rename files which is what I demonstrated. Much more proficient than having a bunch of applets filling up your folder. However, be cautious when taking this route and using other peoples scripts. Most people, to include myself, will write scripts which may use busybox applets but will not call the applet with 'busybox'. So, if the applet is not symlinked to busybox then you may come across problems with the script. Easy fix though. Just open up the script and find all commands which are calling on busybox applets and just add 'busybox' before it, then save.
Sent from my C525c using Tapatalk

Again I have a dumb question but I'm lost with git hub and the git emulator. I followed a guide for compiling a kernel and I did what it asked but this seems routine any monkey can plug in data I wanna know how to actually download the toolchain and run it. Or is there like a dummies guide to what does what and how it works I have to be missing just simple steps
Sent from HTC One SV
k2plc----cricket version
deodexed-mod pack 5
unlocked-super cid-soff

Open up the terminal on your linux system.
Type and enter,
Code:
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6
When you enter that, it will clone the toolchain for 4.6 to whatever directory you are currently in, so now sure you change directories if you wish to have the toolchain cloned (downloaded) to a specific location.
Sent from my C525c using Tapatalk
---------- Post added at 07:22 AM ---------- Previous post was at 07:19 AM ----------
To direct the toolchain to your systems path so you can call on it then type and enter:
Code:
export PATH=$(pwd)/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH
Sent from my C525c using Tapatalk
---------- Post added at 07:25 AM ---------- Previous post was at 07:22 AM ----------
To build your kernel,
Code:
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=arm-eabi-
cd path/to/kernel/source
make k2_plc_cl_defconfig
make zImage
make modules
Now, go experiment lol.
Sent from my C525c using Tapatalk
---------- Post added at 07:28 AM ---------- Previous post was at 07:25 AM ----------
The kernel binary is output as: `arch/arm/boot/zImage
To see where the modules are built go and look at the "buildme.sh" script I use for my kernel and it will show you the directory to grab them. They will be needed or else your WiFi won't work if you install your newly built kernel.
Sent from my C525c using Tapatalk

1045
Don't know if i'm late to the party ,so to get things straight .Is anyone still willing to work on this i'm interested too.

Related

[GUIDE] Kernel Build Guide

This is a basic kernel build guide, to help those that keep coming into IRC asking for help.
If you follow this, you should have a working kernel that will work with ext4 or RFS.
NOTE::I wrote this at 1am, when Im kinda falling asleep, so there might be errors. Please let me know, and Ill fix it up
What you need:
A Linux system, with about 2gb free (This is written for 32bit systems, 64bit will need a compatible toolchain)
Development libraries
The kernel source
An ARM toolchain
An initramfs from an existing kernel
Downloads
EB13 source - search for D700 under mobile phone
Code Sourcery 2009q3 ARM toolchain
Daemon's Ext4/RFS Initramfs
Steps:
Set up the build environment
The first thing you need to do is set up the build environment.
For Ubuntu or other Debian-based system, you need the build-essential package and libncurses.
You can install this by running this command:
Code:
sudo apt-get install build-essential libncurses5-dev
If your not running Ubuntu/Debian, the packages are gcc, g++, libc-dev, and make.
Next, your going to need a directory for all your kernel build. You can't have spaces in any folder name. Im going to use /home/tortel/build/ for the rest of this guide.
Now you need to extract the kernel source to your directory. In the Samsung source file, its SPH-D700_kernel.tar
Next, extract the ARM toolchain into your build directory.
Last, extract your initramfs into the directory.
After this, your build directory should contain 4 things:
Code:
arm-2009q3/
eb13init/
Kernel/
build.sh
For this guide, Im not going to use the build.sh. If you want to, you'll need to configure that yourself.
Configure your kernel
Now the fun begins.
You need to edit the Kernel/Makefile file, and change line 184 to match where your toolchain is. My line 184:
Code:
CROSS_COMPILE ?= /home/tortel/build/arm2009q3/bin/arm-none-linux-gnueabi-
Now you need to configure the kernel.
The kernel configuration file is called .config, which is hidden by default (Ctrl+H shows hidden files in GNOME). You need to set lines 81-91, so it uses your initramfs. My lines:
Code:
CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE="/home/tortel/kernel/eb13init/"
CONFIG_INITRAMFS_ROOT_UID=0
CONFIG_INITRAMFS_ROOT_GID=0
CONFIG_RD_GZIP=y
CONFIG_RD_BZIP2=y
CONFIG_RD_LZMA=y
# CONFIG_INITRAMFS_COMPRESSION_NONE is not set
CONFIG_INITRAMFS_COMPRESSION_GZIP=y
# CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set
# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set
This will build your initramfs into the kernel image.
Now, your set to build.
Build the kernel
This is the easy part. Open a terminal, cd to build/Kernel and run make.
The commands:
Code:
cd build/Kernel/
make
If you have more than one core, you should add -j {1+ # of CPU cores} to make so it finishes faster. It only takes about 5min on my 2ghz C2D laptop.
Make it flashable!
Congrats, its built!
The file you want is Kernel/arch/arm/boot/zImage in your kernel source directory. After make finishes, run:
Code:
cp arch/arm/boot/zImage ..
This copies your kernel image file into your main build directory. Now, you need to put it into a flashable zip. To make it easy, here. Just throw the zImage into the root of that zip, put it on your SD card, and flash it.
Might want later
Advanced config stuff to come
Might want this too
Thank you for this, I'm glad too see this and others who have contributed great guides like this.
sent from "The Other Woman"
I was one of those people who kept bothering lol. I learned how to compile a kernal in two day though, now im on my way making a OC/UV Voodoo color kernal (coming soon) :]
Thanks alot
globalninja said:
I was one of those people who kept bothering lol. I learned how to compile a kernal in two day though, now im on my way making a OC/UV Voodoo color kernal (coming soon) :]
Thanks alot
Click to expand...
Click to collapse
what should I look into for making the changes necessary for an overclocking kernel?
Thanks for this helpful thread, and I had a question previously, that someone pm'ed me for. OP, please remove this reply if you feel inclined to. I had a question about the initramfs because my computer was having problems loading the page for the link.
Hey guys, kindof a noob to this.
How can I get an initramfs for DI18? Ideally, I could just use the one in the stock ROM unmodified, but I have no idea how to obtain it.
I figured it out! Used the scripts here to extract it from zImage:
http://forum.xda-developers.com/showthread.php?t=901152

Compile your own version of CM7 (possibly 9 and 10 too!) the easy way!

Compiling CM7 on the HTC Glacier (T-Mobile MyTouch 4g)
​
I was trying to learn how to compile CM7 from source on my Glacier as practice for when my new Nexus 4 arrives next month. I originally followed a guide by Sykopompos but it's severely out of date (and didn't work off the bat for me). I figured I'd turn this into a how-to to help anyone out with this. I'm assuming that with the proper blobs you can also use this to compile CM9 and CM10 (I will be testing this in the next few days).
Disclaimer: if you FUBUR your PC, I am not responsible, you do this at your own risk. ​You SHOULDN'T be able to mess up your PC if you go the VirtualBox route, however there is always a risk of bricking your device. (Although I'd assume if things went tits up you could just reflash a PD15IMG.zip and you'd just need to re-root your device.)
I used Ubuntu 10.04 LTS for this, feel try to with another version (I'd be weary past 11.10 as 12.04 and beyond aren't officially supported by AOSP.) I'll highlight any problem areas you need to be careful of.
This is based off of my experience compiling from source. I may be taking the long way around things, but it works. I am gearing this to the people new to android development (I've just recently gotten into it myself). I will be giving you things you need to copy and paste (for the most part) to make it easier.
This will cover setting up and compiling the source for a working rom, and the basics of custom kernel creation.
You MUST use 64-bit Ubuntu for gingerbread and later!
You can either install Ubuntu on a dedicated partition (Wubi doesn't give you enough space though, just FYI) or use VirtualBox(). If you go the VirtualBox route, you need to install the extension pack (Located on the same page as the download) for later steps to work.
Here are my recommendations (I used the VirtualBox route):
Disk space: 100gb is a good amount. Between downloading the source and my first build, I'm using 24.6gb (according to windows).
Ram: I gave the VM 4gb of my 8gb ram. You can use more or less, but I'd think that if you have less than 4gb of ram allocated, use a 8-12gb swap file just in case (you may not need it, I built with no problems with 4gb of ram and no swap)
Processor: I have a new Ivy Bridge processor that supports virtualization (If you have a K designation Core series (IE Core i5-2500K you don't support virtualization and your build will be... much slower). I gave VirtualBox 3 of my 4 cores, feel free to adjust as necessary (just leave at least one for your main system)
At this point, I'm trusting that you've successfully installed Ubuntu 10.04 64-bit LTS along with the VirtualBox additions (if you went the VirtualBox route). Make sure to run sudo apt-get update . (don't upgrade to 12.04 if it asks)
Thanks to Dragonswithin for updating me about OpenJDK working.
Installing Necessary packages
​
There are two packages that need to be handled differently from just a simple apt-get install. The first is git-core (the version in the repositories are extremely old and refuse to work correctly with this). The second is Sun-jdk6
First, do the following to add the source for the correct version of git-core.
Code:
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
Enter your password when prompted.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Install the following
Code:
sudo apt-get install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev gitg qt3-dev-tools libqt3-mt-dev eclipse valgrind zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 gedit lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev gitg pngcrush wput openjdk-6-jre
Hit enter when it asks if you want to proceed
Provided everything went smoothly above, you now have all the correct packages installed!
Next step: REPO​
Repo is the script provided by Google that makes it easier to deal with Android source via Git (at least what I gather from it).
The following is the code to get it setup.
Code:
cd ~
mkdir -p bin
export PATH=${PATH}:~/bin
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
doing cd ~/ is an easy way to bring you back to your home folder (IE /home/matada/)
mkdir creates a folder named bin in which we store the repo script.
Export PATH allows us to easily call repo by itself instead of having to use /home/matada/bin/repo
finally, chmod +a gives us everyone access to the repo file, while +x makes it executable (like a .exe or .msi file on windows). Congrats, Two things down!
Setting up the Android SDK​
As of this writing you can go one of two ways. Either manually download the SDK and select Linux(i386), extract it then move it to your home folder (/home/username/) and rename it androidsdk. Or you can just copy and paste the following (this works as of the current release of the SDK, I will try and remember to keep this updated, but I can't promise much)
Code:
cd ~/Downloads
wget http://dl.google.com/android/android-sdk_r21-linux.tgz
tar -xvzf android-sdk_r21-linux.tgz
mv android-sdk-linux ~/androidsdk
That's the SDK downloaded, now to install the packages we need in it.
Code:
~/androidsdk/tools/android
Select under tools:
Android SDK Tools (should be installed by default)
Android SDK Platform-Tools
(I'm not sure if the following is required or not, I did it to be on the safe side). Scroll down to Android 2.3.3 (API 10) and select
SDK Platform
Samples for SDK
and Google APIs
Hit install 4 packages, accept the terms and let it download and install (might take a little while based on your network speed) Once that is complete exit out.
The last step for the SDK is to add the following to your .bashrc (add the three lines to the top of the text)
Code:
gedit .bashrc
Then add:
#AndroidDev PATH
export PATH=${PATH}:~/androidsdk/tools
export PATH=${PATH}:~/androidsdk/platform-tools
Restart your system (the VM or your full linux install)
Congrats! Now ADB should be setup correctly, now for a quick test. Plug your phone into your PC. If you're using the VirtualBox way, go up to devices → USB devices and select T-Mobile MyTouch 4g.
Reopen your terminal and type in lsusb and you should see the following pop up:
Next enter
Code:
sudo gedit /etc/udev/rules.d/51-android.rules
and paste in the following:
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0666"
SUBSYSTEM==”usb”, ATTRS{idVendor}==”18d1″, SYMLINK+=”android_adb”, MODE=”0666″
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0666", GROUP="plugdev"
Then Save and exit
Now is as good of a time as any to keep a backup of your /system/ partition (and a good way to see if your androidSDK is setup correctly)
First enable development on your phone. For gingerbread it’s under the applications -> development -> then press Android Development.
Code:
cd ~/
mkdir stock
cd stock
adb pull /system/ ~/stock/
When it's complete:
Congrats, if that worked correctly the system setup is done! Time to download the source code!
Downloading the Source
​
the Cyanogenmod source is pretty large (my VM was using 15gb by the time it was finished, with another 1gb for the kernel source), so don’t use this if you tether your internet or you’ll be dead before you even start.
Here we go! (At this point you can build for Jellybean or ICS (just replace gingerbread with either jellybean or ICS (or ICS-Release)
Code:
cd ~/
mkdir -p android/source
cd ~/android/source
repo init -u git://github.com/CyanogenMod/android.git -b gingerbread
It’s going to ask for your name and e-mail (you can just hit enter twice to skip it), and then hit Y, enter and then Y and then enter again at the color selection. Your folder is now setup.
You MAY have to (out of the four times I’ve done this part I’ve had it happen once) manually specify your e-mail and name. If so:
Code:
git config --global user.email “[email protected]”
git config --global user.name “your name”
(it will error out saying “unable to auto-detect e-mail address" if this is the case)
Repo is the file we downloaded from Google earlier, it now sets up the source folder to clone the CyanogenMod repository, which we’re about to do now.
Code:
repo sync -j2
This starts the download from the CyanogenMod repository. This totally depends on your internet, and may take from 30-minutes to 12 hours. It’s around 5gb to download. At this point go get something to eat / drink, browse XDA Developers or Reddit and we’ll be back when it’s finished. (I happened to watch tonight’s episode of Walking Dead as a nice break )
And X amount of time later We’re back! (it was about an hour and a half for my connection)
Now to get into the nitty gritty of making it work for our Glacier. Unfortunately CM has taken out the easy button for Gingerbread so we need to do things by hand. No big deal, I’ll explain everything here.
The steps SHOULD be the same no matter if you do Gingerbread or ICS or even Jellybean, just adjust as needed (the repositories I include have Jellybean and ICS included)
First step, Include the Glacier in the vendorsetup for when we compile
Code:
gedit ~/android/source/vendor/cyanogen/vendorsetup.sh
Add in:
add_lunch_combo cyanogen_glacier-eng
Save and exit
Next we need to tell git where to find the files we need for the glacier. Again, change gingerbread to ICS or Jellybean (I don’t know the correct setting for the Kernel though) if you want to compile sometihng else.
This next step you’re going to have to do manually as it resides in a hidden folder.
Open your home folder then navigate to ~/android/system/ then hit Control+H to show hidden folders. Find .repo and when in the folder right click, create document -> empty File and name it local_manifest.xml (case sensitive) right click and open with gedit and:
Add in
Code:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<project name="CyanogenMod/android_device_htc_glacier" path="device/htc/glacier" revision="gingerbread" />
<project name="TheMuppets/proprietary_vendor_htc" path="vendor/htc" revision="gingerbread" />
<project name="CyanogenMod/htc-kernel-msm7x30" path="device/htc/kernel-msm7x30" revision="android-msm-2.6.35" />
</manifest>
Save and quit
Final modification that needs to be done
Code:
gedit ~/android/source/device/htc/glacier/glacier.mk
Line 33: change
“device/htc/vision/ueventd.vision.rc:root/ueventd.glacier.rc”
to
Code:
“device/htc/glacier/ueventd.glacier.rc:root/ueventd.glacier.rc”
(check the screenshot if you need help)
Save and quit
Next do repo sync again
Code:
cd ~/android/source/
repo sync
Next it’s time to get RomManager. You’re in the home stretch of compiling CM7. Only a few more steps!
Code:
cd ~/android/source/vendor/cyanogen
bash get-rommanager
Guess what, Time to compile! If you managed to get this far congratulations! (side note I wish I had a guide to get me this far!)
Alright. last few lines of code and you should be home free.
Code:
source /build/envsetup.sh
lunch cyanogen_glacier-eng
make clean
make bacon -j*
Before make bacon
*(If you want to speed the compile up, you can set -j to however many cores you have available to the VM or on your processor (I gave VirtualBox 3) so I would use -j3. If you only have a single core just omit the -j)
If you compiled successfully you should have a nice shiny cm7.zip sitting on your PC that’s ready to flash! If you just want to compile your own version of CM you’re done! Copy the resulting zip to your sdcard, and flash it in Clockworkmod or RomManager! The directory where the file is located will be displayed when the compile finishes successfully. Now! Stay tuned if you want your own kernel too!
Finished!
Remember to flash the correct gapps for your phone!
Making a custom Kernel
​
Ok, you made it this far, why not go for the full monty right? I don’t know much about making custom kernels (short of making them compile). Here’s a guide I found on a quick search. it rehashes part of what I’ve said here. (Although I didn’t use that source to make this guide. (Look below for my sources)
I’ll keep giving you the step by step here (I’m just going to skip the explanations of what stuff does), just incase you’re still not comfortable being let loose yet.
Code:
cd ~/android
mkdir kernel
cd kernel
git clone git://github.com/CyanogenMod/htc-kernel-msm7x30.git
cd htc-kernel-msm7x30
export CROSS_COMPILE=~/android/source//prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
export ARCH=arm
make xconfig
At this point you should eventually have a window pop up that looks like:
all you have to do is go to file load and navigate to ~/android/source/kernel/htc-kernel-msm7x30/arch/arm/configs and select “cyanogen_msm7230_defconfig” and hit load. then save and exit. You can tinker around with stuff BUT you can easily make your device freeze at the mytouch logo (you’d need to figure out what went wrong then reflash the kernel (or the rom when you kernel to work correctly).
Last step for compiling. (so anticlimatic)
make -j (if you set -j to something when you compiled CM7 feel free to use it again, if you didn’t omit the -j) Hit enter and you should wind up with a custom kernel and wifi module.
I ignored the wifi module since the same version was already in the sources on CM7. you will need to add it for CM9 and CM10).
The kernel is located at ~/android/source/kernel/htc-kernel-msm7x30/arch/arm/boot/ and wifi is located at ~/android/source/kernel/htc-kernel-msm7x30/drivers/net/wireless/bcm4329/
BE SURE TO BACK UP THE ORIGINALS (either copy them out to a safe spot, or rename them!)
you can either fastboot the kernel (I don’t know how to do it correctly yet so I will skip adding it for now) or put in the CM7 source at /android/system/device/htc/msm7x30-common/msm7230/
Rename zImage to kernel.
Wifi will also go to ~/android/system/device/htc/msm7x30-common/msm7230
In the end it should look like:
at this point do the following to recompile with the new kernel (and possibly wifi)
Code:
source ./build/envsetup.sh
lunch cyanogen_glacier-eng
make clean
make bacon -j (you know what to do now)
When it completes successfully, copy it to your SD card and flash it same as before and you’re set.
[URL=http://i.imgur.com/mfTxyh][IMG]http://i.imgur.com/mfTxyh.png[/IMG][/URL]
And finally (my rom works perfectly and is pretty quick. I'm impressed and satisfied)
[img]http://i.imgur.com/oMblE.png[/img]
I hope this will help someone, as it was a good learning experience for me.
The sources I used were:
Guide to Compiling Posted by Sykopompos . This gave some of the specifics of what I needed to do for the glacier (not all of it sadly)
Compiling from source GSM HTC Desire build page (Out of date but was a good launching off point.)
I owe a lot to the #cyanogenmod-dev IRC channel on Freenode. More specifically to the user Asturel who put up with my constant questions for getting it to work. (Just because he helped me doesn't mean he'll help y'all)
If you need any help feel free to post here, or PM me.
You can also DM me on twitter @zoeyalbini if you need some immediate assistance.
You can also find me (and a lot of other great developers) over on #cyanogenmod-dev if you want to connect with other devs. They seem to accept me fine!
And worst comes to worse you can e-mail me at matada89 (AT) gmail
Thanks for reading!
Thanks for the time you spent creating this guide.
Sent from my LG E960
GEEEEZZZZZ!!How long did it take you to post all of this!talking about filling up a thread from the start!!HAHA JK thanks for the info!alot to read,but probably worth it !again thanx..
[email protected] said:
GEEEEZZZZZ!!How long did it take you to post all of this!talking about filling up a thread from the start!!HAHA JK thanks for the info!alot to read,but probably worth it !again thanx..
Click to expand...
Click to collapse
To figure out everything to do this took about 6 hours. Writing the guide took about four hours. Checking line by line and getting pics (I compiled the rom using only the things I had written) . Posting it here took like 3 hours only because of the 10 post requirement. And doing pictures.. and formatting and other stuff. I'm not done yet (going to Try and compile both CM9 and CM10 following this guide. I'm in bed now as it's 5am.
Sent from my HTC Glacier using xda premium
Alright, since I'm an eager beaver (Or stupid as hell). I'm going to try and compile CM9 and CM10 and see what (if anything drastic) needs to be changed. Will report with a how-to later if it works.
Update: I Seem (almost done compiling) to have CM9 setup correctly, but haven't quite figured out making the Kernel.. Progress. Also, I may have something BIG to release on Christmas.... I'm excited!
Edit: CM9 compiled correctly and it currently working on first boot (Optimizing applications) Cool!
Great guide but most of it won't work on cm9 and definitely not cm10. Great effort though
THEindian said:
Great guide but most of it won't work on cm9 and definitely not cm10. Great effort though
Click to expand...
Click to collapse
Yeah I'm seeing that. I'll figure something out, might have to do a separate tutorial for 9 and 10. Hit a snag right now with a bootloop.
matada said:
Yeah I'm seeing that. I'll figure something out, might have to do a separate tutorial for 9 and 10. Hit a snag right now with a bootloop.
Click to expand...
Click to collapse
I'll be looking forward to the CM10 tutorial, when i was trying to compile it, i had to mash a bunch of guides together, then i realized that my computer wasn't strong enough to build android lol
---------- Post added at 05:33 PM ---------- Previous post was at 05:30 PM ----------
also, this should definetly be in the Android Development section, definetly worthy of the attention
THEindian said:
I'll be looking forward to the CM10 tutorial, when i was trying to compile it, i had to mash a bunch of guides together, then i realized that my computer wasn't strong enough to build android lol
---------- Post added at 05:33 PM ---------- Previous post was at 05:30 PM ----------
also, this should definetly be in the Android Development section, definetly worthy of the attention
Click to expand...
Click to collapse
I discussed the move with The Archangel and it was stated guides no longer go in the Development Sections. I'll live.
I have the source downloaded, but I'm having kernel errors. I tell it what to compile kernel wise, it still fails. I tried compiling separately and it fails too >.< I'd go take a break and play some Warcraft, but the servers are down for at least another 2 hours.
matada said:
I discussed the move with The Archangel and it was stated guides no longer go in the Development Sections. I'll live.
I have the source downloaded, but I'm having kernel errors. I tell it what to compile kernel wise, it still fails. I tried compiling separately and it fails too >.< I'd go take a break and play some Warcraft, but the servers are down for at least another 2 hours.
Click to expand...
Click to collapse
Ran into that. I didn't overcome that...
thanks so much for these guides. among the most clearly stated guides that i've come accross.
thanks again!!!
Sent from my HTC Glacier using xda premium
THEindian said:
Ran into that. I didn't overcome that...
Click to expand...
Click to collapse
I got it to compile with the Dirty kernel (Used in the old AwesomeICS rom), but it boot looped with audioflinger errors (Was missing libalsa.so (some audio file I forget the name and I'm at work right now),
I'm going to start again on Saturday, hopefully make some headroom.
So I don't have much of a clue what I'm doing but I got to this step
Final modification that needs to be done
Code:
gedit ~/android/source/device/htc/glacier/glacier.mk
Line 33: change
And all I get is a blank file. In fact I don't even have a glacier folder only a 7x30-recovery, common, msm7x30-common, and passion-common. Can anyone tell me what step I messed up?
EDIT:
Did a repo sync and the files showed up.
I can't even figure out how to get the JDK. Nomatter what guide I try I run into this:
There is only one alternative in link group java: /usr/lib/jvm/jdk1.6.0_37/bin/java
Nothing to configure.
lortay78 said:
I can't even figure out how to get the JDK. Nomatter what guide I try I run into this:
There is only one alternative in link group java: /usr/lib/jvm/jdk1.6.0_37/bin/java
Nothing to configure.
Click to expand...
Click to collapse
I may be wrong but I don't think that is an error. You only have jdk 1.6 installed so it is telling you that you have no other options to pick from. As 1.6 is the version you need you don't need to change the default.
lortay78 said:
I can't even figure out how to get the JDK. Nomatter what guide I try I run into this:
There is only one alternative in link group java: /usr/lib/jvm/jdk1.6.0_37/bin/java
Nothing to configure.
Click to expand...
Click to collapse
That's fine. continue on. I need to edit the first post to state if you have that, you're totally OK. I Just happened to have openJDK installed when I did it (hence why it shows up in screenshots)

[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.

[GUIDE][HACK]Cross Compiling for OSX on Linux with AOSP

Hi Folks
I wasn't sure where this should belong but as it is a bit of an Hack this forum is probably the most appropriate
Introduction
This short tutorial will show you how to patch the Android Build System to allow you to cross-compile Android AOSP host tools ( adb, fastboot etc ) for OSX using a linux based machine. This is something Google said was impossible or at the very least unsupported.
Assumptions
You have a linux based machine and working copy of the AOSP source tree.
You can/have successfully compile(d) a full Android Release from this tree.
A basic idea of how the Android Build System works is beneficial.
Getting Started
I've set-up a git repository which contains a binary copy of the OSX SDK 10.6 and the apple-darwin10-gcc cross compiler. So first things first. open a terminal and set the root of the AOSP sources tree to the current directory.
STAGE 1: Copy the OSX SDK
Step 1.
Clone the repo with the SDK and toolchain
Code:
git clone https://github.com/trevd/android_platform_build2.git build2
Step 2.
Create /Developer directory at your filesystem root, this is a known location for the SDKs
Code:
sudo mkdir /Developer
sudo chown $USER.$USER /Developer
Step 3.
Copy and unpack the SDK package
Code:
cp build2/osxsdks10.6.tar.gz /Developer
cd /Developer
tar -zxvf osxsdks10.6.tar.gz
rm osxsdks10.6.tar.gz
cd - # back to aosp root
STAGE 2 : Swapping the Toolchain
This is where the fun begins :laugh:
The Android Build system has the majority of the infrastructure in place already to build for OSX, the only problem is that you need OSX to build for OSX. However we can remedy that with a couple of dirty hacks :laugh:.
The prebuilts/gcc/darwin-x86 directory contains a toolchain compatible with osx ( mach-o binaries ). We are going to swap this for a linux compatible ( elf ) executables.
Step 4:
Copy and unpack the elf compatible darwin cross toolchain
Code:
cp build2/i686-apple-darwin-4.2.1.tar.gz prebuilts/gcc/linux-x86/host
cd prebuilts/gcc/linux-x86/host
tar -zxvf i686-apple-darwin-4.2.1.tar.gz
cd - # back to aosp root
Step 5:
Remove the mach-o binaries and symlink the elf binaries in it's place
Code:
cd prebuilts/gcc
rm -rf darwin-x86
ln -s linux-x86 darwin-x86
cd - # back to aosp root
Step 6:
We also need to replace the mach-o version of the ccache executable which live in the prebuilt/misc directory
Code:
cd prebuilts/misc
rm -rf darwin-x86
ln -s linux-x86 darwin-x86
cd - # back to aosp root
STAGE 3: Patching the build system .mk files
We need to patch a couple of files in the build directory namely the build/core/combo/HOST_darwin-x86.mk the main crux of this is swapping the ar tool for libtool so static libraries can be created without error.
Code:
patch -p1 < build2/build.patch
If the patch has been applied successfully you should see the following
Code:
patching file system/core/adb/Android.mk
patching file build/core/combo/HOST_darwin-x86.mk
patching file build/core/combo/select.mk
patching file build/core/envsetup.mk
patching file build/envsetup.sh
You are now ready to cross compile!! :good: ..... well not quite, but nearly.... here's why!
The Android Build System will attempt to build both the Target and Host files for most modules so I'd advise using a lunch option which already has a full target built for it or alternatively you can build the generic sdk using the following commands at the AOSP source tree root.
Code:
. build/envsetup.sh
lunch sdk-eng
make sdk
This will stop target dependency errors occurring when you build individual modules.
NOW we're ready to cross compile.
STAGE 4: Building Modules
At present module build is very much a piecemeal process. To build adb for example we need to build the dependencies first. This is not too onerous as most host modules have very few dependencies.
Building adb
adb has dependencies on the following libraries
Code:
external/zlib
external/openssl
system/core/liblog
system/core/libcutils
system/core/libzipfile
I've found the easiest way to compile the dependencies is to navigate to each directory in turn an use to "mm" build system command to compile the individual module. the commands I run to compile adb are as follows.
From AOSP Source Root
Code:
cd external/zlib
USE_DARWIN=true mm -j8
cd ../openssl
USE_DARWIN=true mm -j8
croot # go back to the AOSP root
cd system/core/liblog
USE_DARWIN=true mm -j8
cd ../libcutils
USE_DARWIN=true mm -j8
cd ../libzipfile/
USE_DARWIN=true mm -j8
cd ../adb
USE_DARWIN=true mm -j8
All being well you should now have and adb binary located at out/host/darwin-x86/bin/adb. running the file command on this binary should produce the following output
Code:
adb: Mach-O executable i386
Conclusion
Although this method is a little rough and ready, it should produce the desired results if you need to cross compile for OSX. The eventual goal would be to compile a full OSX Android SDK on linux in a similar manner to the way the windows-sdk is currently compiled. This requires more investigation as compiling the windows sdk on linux employs a little bit of trickery on the part of the build system.
Final Notes and FAQs:
Why can't I just type make <module> from the root?
Doing this triggers building of additional modules such as LLVM and clang which are to deployed out/host/darwin-x86/bin the build system then attempts to use binary later on. These are obviously built for the Mach-o architecture and as such are incompatible with the linux. This results in a build error which can and would be resolved by the above mentioned trickery ( see conclusion )
I use OSX binaries (along with Windows and my native Linux) in one of my projects. Thanks, I have always relied on finding compiled binaries elsewhere. Lack of an OSX aapt held up an update at one point.
One of those things that you don't really use until you need it, but I will try to remember to give it a shot. I don't have any doubt that it works.
mateorod said:
I use OSX binaries (along with Windows and my native Linux) in one of my projects. Thanks, I have always relied on finding compiled binaries elsewhere. Lack of an OSX aapt held up an update at one point.
One of those things that you don't really use until you need it, but I will try to remember to give it a shot. I don't have any doubt that it works.
Click to expand...
Click to collapse
Thanks. Yes this really is an edge case. Hopefully It will help some folks out.
Regarding aapt in particular.... It's perfectly possible to build aapt, however, we need to do some slight of hand with the clang and clang++ executables as libpng on which aapt depends uses these 2 binaries as part of it's build process.
Here's the build list and the clang trick if you want to try it some time.
Code:
build/libs/host
external/expat
external/zlib
system/core/liblog
system/core/libcutils
mkdir out/host/darwin-x86/bin
cp out/host/linux-x86/bin/clang out/host/darwin-x86/bin
cp out/host/linux-x86/bin/clang++ out/host/darwin-x86/bin
external/libpng
frameworks/base/libs/androidfw
frameworks/native/libs/utils
frameworks/base/tools/aapt
I started off with a clean out/host/darwin-x86 directory so I didn't miss any dependencies.
like I mentioned the clang "swap out" is something the make win_sdk option does automatically so with it a little more research I should be able to get the mac build to do the same but you'll have to "fill yer boots" with the ghetto method for now
For reference here's a link to the sdk building instructions http://tools.android.com/build which describes how to cross compile the windows sdk on linux ( in case anyone was wondering what the hell i'm on about)
My use case has come up
I will be cross-compiling for OSX today...specifically with aapt in mind. I will report back, but I fully expect it to work as described.
mateorod said:
My use case has come up
I will be cross-compiling for OSX today...specifically with aapt in mind. I will report back, but I fully expect it to work as described.
Click to expand...
Click to collapse
Cheers Man!
Hopefully no bitrot has crept in since april and now. I know I've changed my OS version since to Lubuntu 13.04, not like the OS version really matters any.
mateorod said:
but I fully expect it to work as described.
Click to expand...
Click to collapse
Then you Sir, are either Drunk or a Fool! LOL Keep expectations Quantum and only decided when the result is observed a'la Schrodinger Cat
okay...So I was trying to compile SlimRom (so as to get an OSX aapt binary with the SlimRom changes) and things did not necessarily go as planned. There were enough changes to the SlimRom android_build that your build/build.patch does not apply cleanly. I spent some time and tried to modify the patch so that it would work for both SlimRom, AOSP and probably others, but each android_build repo has some differences in surrounding the HOST_AR line, so commenting that just was not portable between flavors. Not cool.
Anyway, turns out that this method does not quite work out of the box for non-AOSP versions (not that you claimed that it did). I got some unfamiliar errors related to (I believe) some OSX toolchains. But in both times I tried this, I actually had to pretty immediately swap out of that flavor and so I was unable to do much debugging. (I keep all the flavors I build {CM, AOKP, SlimRom, PAC, PA, OpenPDroid, etc, etc, etc} all layered in one android/system/jellybean directory. It saves a ton of space, but only allows me to do one thing at a time.)
So the only feedback I have is nothing...I even formatted my hard drive in-between and forgot to put up a paste, so the errors are currently lost to history.
Things that I noticed, for better or worse
You recommend putting the SDKs in the root dir. I believe the documentation is recommending the Developer be placed in home (as per the SDK/ADT bundle docs).
You might want a
Code:
mv android_platform_build2 build2
line. I normally wouldn't bother, but it looks like you are trying to post a line-by-line guide.
I would put the recommendation that a full build be available to the out folder (or a built generic sdk) right at the top, since it is a preliminary step. I had to revert my handwritten changes, then build, then reapply the changes and rebuild since I thought it needed a clean out dir.
Did you have any trouble with git reverting the toolchain swap? On two separate machines, I had to go so far as to delete .repo/projects/prebuilts/gcc/* and prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6. It kept complaining of that the project in the .repo folder was a bad match. No amount of git trickery (which I am not terrible at) let me back out more easily.
I am willing to try again...but I have some other small things to attend to first. It is an admirable hack you have here sir. I will return to it soon and report back once more.
mateorod said:
okay...So I was trying to compile SlimRom (so as to get an OSX aapt binary with the SlimRom changes) and things did not necessarily go as planned. There were enough changes to the SlimRom android_build that your build/build.patch does not apply cleanly. I spent some time and tried to modify the patch so that it would work for both SlimRom, AOSP and probably others, but each android_build repo has some differences in surrounding the HOST_AR line, so commenting that just was not portable between flavors. Not cool.
Anyway, turns out that this method does not quite work out of the box for non-AOSP versions (not that you claimed that it did). I got some unfamiliar errors related to (I believe) some OSX toolchains. But in both times I tried this, I actually had to pretty immediately swap out of that flavor and so I was unable to do much debugging. (I keep all the flavors I build {CM, AOKP, SlimRom, PAC, PA, OpenPDroid, etc, etc, etc} all layered in one android/system/jellybean directory. It saves a ton of space, but only allows me to do one thing at a time.)
So the only feedback I have is nothing...I even formatted my hard drive in-between and forgot to put up a paste, so the errors are currently lost to history.
Things that I noticed, for better or worse
You recommend putting the SDKs in the root dir. I believe the documentation is recommending the Developer be placed in home (as per the SDK/ADT bundle docs).
You might want a
Code:
mv android_platform_build2 build2
line. I normally wouldn't bother, but it looks like you are trying to post a line-by-line guide.
I would put the recommendation that a full build be available to the out folder (or a built generic sdk) right at the top, since it is a preliminary step. I had to revert my handwritten changes, then build, then reapply the changes and rebuild since I thought it needed a clean out dir.
Did you have any trouble with git reverting the toolchain swap? On two separate machines, I had to go so far as to delete .repo/projects/prebuilts/gcc/* and prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6. It kept complaining of that the project in the .repo folder was a bad match. No amount of git trickery (which I am not terrible at) let me back out more easily.
I am willing to try again...but I have some other small things to attend to first. It is an admirable hack you have here sir. I will return to it soon and report back once more.
Click to expand...
Click to collapse
Hi
Thanks for this, It sounds like you've suffered an exercise in frustration there. I wasn't aware that "SlimRom" had a different aapt ( just out of general ignorance and not having paid any attention )
SDK - My Tree last time I used this was /Developer directory in the root - I think It comes from what the toolchain is expecting, I just gave it what it wants
mv android_platform_build2 build2 - Yep I did mean that it's the git clone line which wants changing
Code:
git clone https://github.com/trevd/android_platform_build2.git build2
SDK Recommendation - I shall move that to the top, even though it is already in there, It should probably be highlighted better and possible it's own "Stage"
Reverting the toolchain - Ahh , It appears I work slightly different from most in this respect. I have a general mistrust of SCM's ( I lost too much code on too many different SCM's, Probably through my own inability to use them correctly but ) what I do to revert to change is
Code:
cd prebuilts/gcc/darwin-x86/host/
rm -rf i686-apple-darwin-4.2.1
repo sync i686-apple-darwin-4.2.1
You can do this "trick" on any project in the source tree it's only on rare occasions where I screwed up badly that I have to delete anything in .repo/projects but I also have my distro in their own individual directories with there own full git trees, which is a massive waste of space and has a ton of redundancy due to the AOSP repositories being mirror by every single one but switching between them is a lot easier
If SlimRom's changes are localized to aapt, I'd be more inclined to drop it into the AOSP build and try that... If you have a link to slimrom's frameworks/base repository I'll grab it and try it myself.
On a final note there's a "full version" of the HOST_darwin make file in the build2/core/combo directory the changes to envsetup.mk and select.mk are minimal and can easily be applied manually. You don't need to patch the adb makefile if your not building it.
Again Thanks for the feedback

[Guide] Building post 2017 android kernel from source

About this guide
I have been building kernels for many machine types and have been fiddling around with custom android kernels for my own phone but to my great frustration the rules changed quite a lot for my new phone. It seems every kernel after 2017 is A LOT harder to build and needs quite some fiddling around te get it to boot. The documentation is terrible the least on the steps and all howtos are all outdated by now. This guide shares with you the secrets to build yourself a modern post 2017 kernel from source. I only own a op7 at this moment but I am pretty sure the rules apply to all devices.
So why do we need to build our own kernel? Well that's simple. I have scrolled through many custom kernels missing a simple module that I need. In my case binfmt. Perhaps you need a specific device driver compiled into your kernel or you want to hack in/patch in some special functions that are only needed by you. Or you love a certain kernel but need that one little adjustment in the configs that this kernel doesn’t have and so on.
Lets get through it step by step but I do assume you know something about Linux, you know how to use the terminal and that you have some knowledge on building binaries from source. Ready? Ok lets get started.
These steps are required to be followed to be successful:
1. Set up a building environment
2. Obtain the kernel source
3. Download the proper tool-chain
4. Adjust configuration files to match your needs
5. Build the actual kernel image
6. Backup your current boot.img!!!
7. Trow the image into a anykernel zip and flash it.
8. Close your eyes prey and run the kernel.
Prerequisites
You will need:
A fairly fast computer with lets say 4 gigs of RAM and a decent CPU.
A workable linux distribution that you can boot into (I prefer ubuntu bionic at this moment).
The kernel sources for your device.
ROOT!!
Lots of spare time.
A attitude that makes you unstoppable.
1. Setting up the building environment
Ok lets first open a terminal. You will need the terminal a lot. As a matter of fact it will be your friend through this guide so better get used to it. Assuming you are on a ubuntu like distribution lets fetch the important packages first
Code:
$sudo apt install build-essential bizon flex git
This command will install some of the prerequisites you need to do anything. More packages will need to be installed on the way but at least you will be able to type $make
Now lets create a working directory. Go into your home folder and create a working directory which will later on contain your kernel sources and tool chain.
Code:
$cd
$mkdir [COLOR="MediumTurquoise"]name-of-your-working-folder[/COLOR]
2. Obtain the kernel source
This one is tricky as my experience have learned me the kernel sources supplied by my own vendor are usually badly documented and contain a few bugs here and there resulting in either build errors or a unbootable kernel. So usually I grab a custom kernel that has minimal changes to the stock kernel and boots by only using a single kernel file without extra kernel modules attached. The custom kernels usually have the nasty building bugs flawed out and thus your chances for success are higher. I used the exkernel in my case and out of respect for the hard work of flang2 I bought the app that came along.
To get the sources google around and find the sources on for example git and click the download or clone button there and copy the link of the depository.
Then simply clone the depository to your working directory so after changing to your working directory type
Code:
$git clone link-you-just-copied
Git will now automatically clone the entire kernel source into the source sub-directory. You can change the name of this directory to make you life easier.
3. Download the proper tool-chain
This is where I lost many days and weeks of my life. Where do we find the proper tool-chain for our kernel?
You basically need 3 compilers
clang
GCC
device-tree-compiler
There are many versions of clang and GCC and you will need to find the one that matches your kernel and builds for your cpu architecture. I will assume in this guide that your CPU is aarch64 or arm64 (both names are used at the same time).
To obtain clang head over to the following address:
"https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/"
now in the tags and branches you can find the version of android you are looking for. If your kernel is for android 9 then use the android 9 tag. Click on it and then click tgz which will provide you with a huge tarball.
Create a folder in your working directory named toolchain en extract the contents of the tarball into the sub-folder clang.
You can try any subversion of clang there is but I recommend to simply peek into the build.config files located in the root of your kernel source directory which usually specify the exact subversion of clang used.
Time to get GCC which is easier since there is only one version right now.
Head over to
"https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/"
and use the correct version here as well. In my case I picked the latest build. Then do the same as for clang but name the sub-folder GCC or whatever you please to do.
And then finally get yourself the device-tree-compiler
Head over to
"https://github.com/dgibson/dtc/tree/v1.4.4"
and clone this depository into ~/your-working-directory/toolchain/
and navigate to the subdir you cloned it into
then build by typing
Code:
$make
any missing package errors will need you to install them using
Code:
$sudo apt install missing-package-name
and do make again until the build completes.
If all went well your tool-chain and working directory will look like this:
Code:
/[COLOR="mediumturquoise"]current-working-dir[/COLOR]/[COLOR="mediumturquoise"]kernel-source-dir[/COLOR]/
|
/toolchain/
|
/clang/
/gcc/
/dtc/
4. Adjust configuration files to match your needs
Lets first grab the correct defconfig file and setup the build directory. This defconfig file contains the default kernel configuration parameters which you propably want to adjust.
Head over to ~/working-directory/kernel-source-dir/arch/arm64/configs/
see what you can find there. I found the elementalX_defconfig file which is the file I needed to build the Exkernel from scratch. If you are trying a stock kernel dive a little bit deeper into the vendor folder and see if you can find a good config file there.
Alternatively sometimes the config is hidden on your device itself. Have a look at
/proc/config.gz
the file inside the archive contains a valid defconfig for your device but beware your may need to open it with menuconfig first and save it again to make it workable for the compiler script.
Place the defconfig file you like to use into the configs folder.
(Skip the following step if your are going to build your kernel for the first time because we first want to see it work.)
Now head over to your kernel source dir and type the following command
Code:
$PATH="~/[COLOR="mediumturquoise"]working-dir[/COLOR]/toolchain/clang/[COLOR="mediumturquoise"]clang-r353983c[/COLOR]/bin:~/[COLOR="mediumturquoise"]working-dir[/COLOR]/toolchain/gcc/a[COLOR="mediumturquoise"]arch64-linux-android-4.9[/COLOR]/bin:${PATH}" \
make menuconfig O=out \
ARCH=arm64 \
CC=clang \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-android-
now remember to use the correct paths to your tool-chain. In this command I use clang-r353983c but you may use a different version. The same applies for linux-android-4.9.
I would like to thank Nathan Chance for supplying documentation on the clang tool-chain on his github.
If all well you will be presented with a menu in which you can adjust things. First open the defconfig file you wish to use and then save the file after you are done. Now REMEMBER! With this command the menuconfig will save your new file into the /kernel-source-dir/out folder.
(end of the skipped step)
Now it is time to prepare our kernel build using the following command (do this from your kernel source dir) and remember that this command will look in the /kernel-source-dir/arch/arm64/configs/ directory
$make O=out ARCH=arm64 name-of-your-defconfig
If all goes well you will see something like configuration written to .config
Everything is up and ready to go. Your hart will start pounding from this moment on
5. Build the actual kernel image
This is where things get complicated. I hope you have many years to live because this part consumes time, a lot of it.
type
Code:
$PATH="~/[COLOR="mediumturquoise"]working-dir[/COLOR]/toolchain/clang/[COLOR="mediumturquoise"]clang-r353983c[/COLOR]/bin:~/[COLOR="mediumturquoise"]working-dir[/COLOR]/toolchain/gcc/[COLOR="mediumturquoise"]aarch64-linux-android-4.9[/COLOR]/bin:${PATH}" \
make -j$(nproc --all) O=out \
ARCH=arm64 \
CC=clang \
DTC=~/[COLOR="mediumturquoise"]working-directory[/COLOR]/toolchain/dtc/dtc \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-android-
ready set GO!
This will depending on your machine take between forever and eternally. You will witness many warnings on the DTC build seems normal these days and a few warnings on the CC part. Most important is that no errors are thrown at you.
If all goes well you will see a normal exit status and you will have a “working” kernel image.
“Error?: Well that happens. Try a different build of clang check your command line. And if all that fails try to find out what is wrong in the source and that means digging through thousands of forum pages until you find out whats wrong. But using the google tools usually goes well.”
Almost there go and check
kernel-source-dir/out/arch/arm64/boot
and there should be a image-dtb or image.gz-dtb file depending on you settings.
That is your kernel image right there. The difference in size between image and image-dtb should not be huge. 10Megs in difference usually means your dtb is not good but trying is the only way to find out if it works.
6. Backup your current boot.img!!!
You know what to do here right? Do not skip this step unless you like bricked devices or want to reflash and lose your data and all that kind of stuff. Not sure what you are doing stop here or backup your entire device including system vendor etc.
7. Trow the image into a anykernel zip and flash it.
Ok something changed in the last few years. Unpacking repacking and booting using fastboot somehow gives me problems. Dm-verity errors and all kind of red screens. Signing the boot image results into new errors. Well this is how I did it.
Get yourself a anykernel zip file. I used the Exkernel.zip because it only contains a kernel image which I like. Open the zip in a good zip tool (I used ark) and replace the image-dtb file with the one you created. Place this new zip you created on a memory stick and then….
Flash it using twrp or any tool of choice.
8. Close your eyes prey and run the kernel.
Two things can happen.
1. Blank screen nothing happens. Only god can help you, repeat all the steps.
2. Your android starts booting. Start crying of joy
Check in your android if this is indeed the kernel you build. If so time to make some adjustments to your configs or happily enjoy your boosted phone.
Now please remember. If you plan to distribute your kernel that you do the correct steps of accrediting the original programmer and trow the source online. If you use a already custom kernel please respect the hard work of the maker and communicate your plans with him/her.

Categories

Resources