• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Root Compiling A Kernel from source

kanaida

Android Expert
Dec 2, 2010
788
336
This is mostly directed to PG. :)

I set up my ubuntu 10.04 box, got the LG source, set up the build environment, set the LG kernel config, tuned stuff a bit, and manged to compile it. However I don't see a zImage anywhere. There was no errors or anything. Kind of odd. I did see in the output folder a whole bunch of .o files.

I used the toolchain that CM suggested in some forum post since I was only building the kernel.

Not sure if I missed anything?

I also tried downloading the CM7 source, and I was working on making a port. Well trying to learn how to anyways. I'm starting to get better at using the tools, just don't understand that 'Lunch' and make bacon thing too well LOL... it's funny seeing android source coming with a lunch menu, litteraly.
 
Thanks lol... it's not exactly like there's a manual :)
Here's what I see in here. I'm not sure what I compiled, I might just restart the process. I used a shortcut or two hehe :D, didn't think they actually had a readme with instructions so i didn't notice till later on.

Code:
kanaida@android-vm:~/android-lg/kernel/arch/arm/boot$ ls -R
.:
bootp  compressed  install.sh  Makefile

./bootp:
bootp.lds  initrd.S  init.S  kernel.S  Makefile

./compressed:
big-endian.S  head.S         head-sharpsl.S  Makefile        ofw-shark.c   piggy.lzo.S
decompress.c  head-sa1100.S  head-xscale.S   Makefile.debug  piggy.gzip.S  vmlinux.lds.in
head-l7200.S  head-shark.S   ll_char_wr.S    misc.c          piggy.lzma.S
kanaida@android-vm:~/android-lg/kernel/arch/arm/boot$
 
Upvote 0
Ah, nevermind I compiled it... finally lol..
all this crap cause they didn't make a simple shell script and clear instructions.

Here's what I did:

sync'd the android repo

copied the ~/android folder to ~/android-ms910 (so i don't mess up my original copies)
copied the lg source's kernel folder to ~/android-ms910/android/system
Merged the lg source's open source to ~/android-ms910/android/system

Created this script ~/android-ms910/android/system/build_default_kernel.sh
echo LG-MS910 Kernel Build
echo Setting up build environment...
KS=$(pwd)/kernel/scripts
CC=$(pwd)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin
CC1=$(pwd)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/libexec/gcc/arm-eabi/4.4.3
#CC=/home/kanaida/arm-toolchain/bin
#CC1=/home/kanaida/arm-toolchain/libexec/gcc/arm-none-eabi/4.6.1
export PATH=${KS}:${CC}:${CC1}:$PATH
export TARGET_PRODUCT=lge_bryce
export BUILD_LG_HW_MS910_REV=5
export TARGET_BUILD_VARIANT=user
export TARGET_LTE_IMAGE=persist
cd kernel
echo Loading Kernel Defaults for MS910...
make ARCH=arm lge_bryce-perf_defconfig
echo Compiling Kernel...
#make clean -j16 ARCH=arm CROSS_COMPILE=${CC}/arm-eabi-
make -j16 ARCH=arm CROSS_COMPILE=${CC}/arm-eabi-
echo Kernel Built.
cd arch/arm/boot

Ran it, and compiled my zImage successfully.
Now I just need to know how to turn that into a flashable zip somehow.
 
Upvote 0
Ah, nevermind I compiled it... finally lol..
all this crap cause they didn't make a simple shell script and clear instructions.

Here's what I did:

sync'd the android repo

copied the ~/android folder to ~/android-ms910 (so i don't mess up my original copies)
copied the lg source's kernel folder to ~/android-ms910/android/system
Merged the lg source's open source to ~/android-ms910/android/system

Created this script ~/android-ms910/android/system/build_default_kernel.sh


Ran it, and compiled my zImage successfully.
Now I just need to know how to turn that into a flashable zip somehow.

I'm no dev but, You need to unpack a boot.IMG and put the zImage/kernel in it and pack it back up. Then just to test it replace the boot.IMG in one of PGs kernel zips and then flash it. But remember what I said at the beginning of this :D:D:D;)
 
Upvote 0
I know it goes something like that, but really I just need to know the commands and if I need some files to do it. I know it's simple, just haven't found a clear command line example or anything. I'm just glad it compiled, took days to get all this stuff up and running in a virtual machine and sync repos, then figure out what to do with vague instructions. This coming from someone who's been using linux everyday for a few years and built my own kernels and been a network admin and programmer for about 10 years lol... it's very hard stuff to attempt to learn.
 
Upvote 0
I notice everyone here uses linux enviroments. Im still green in the programming world, but is it not possible to accomplish these things in java. Always thought android was java based.

Android is not java like you think, it's very complicated. It's A modified Linux kernel (a fork) + Something Like Java called Dalvik + A set of android libraries.
 
  • Like
Reactions: synergy7
Upvote 0
u made that alot more complicated than it needed to be lol.

my kernel src (all of em) are in a separate dir named Kernel/kernel_name. I said screw LGs Android src/patch wtfe it pose to be and used the toolchain from the CM repo.

all the cc crap I ignored, added all the export stuff to the Makefile in the root of the kernel src and used my build script

Code:
#Let's make sure the environment is clean and ready to compile the kernel
echo "Cleaning house!!"
make mrproper
echo "House cleaned, lets build a kernel!!!"
#
# Lets set the kernel defconfig
echo "defconfig = plague_defconfig"
make ARCH=arm plague_defconfig
#
# Let's build a kernel
echo "Now compiling kernel, go get a soda! ;)"
ARCH=arm CROSS_COMPILE=~/Android/CM9/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- make zImage -j4
#
if [ -f arch/arm/boot/zImage ]; then
      echo "Plague has been compiled!!! You can find it in arcg/arm/boot/zImage"
else
      echo "Kernel did not compile, please check for errors!!"
fi
and all it really does is saves me from having to type out:

Code:
make ARCH=arm plague_defconfig

ARCH=arm CROSS_COMPILE=~/Android/CM9/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- make zImage -j4
each time I go to compile a new kernel. So I have all my kernel src in one place and my CM src in its own place ;)

And in the LG src itself has a readme that tells ya how to do it the LG way which is nothing like AOSP or CM lol.
 
Upvote 0
Thanks, I know I made it harder haha. I made my own build script too, just in an sh file not the make configuration itself. I'm still familiarizing myself with the build/make system.

What are the commands to take the compiled zImage and make my own flashable zip though? , that's what I need. I've been dying to flash the new kernel I made lol
 
Upvote 0
Thanks, I know I made it harder haha. I made my own build script too, just in an sh file not the make configuration itself. I'm still familiarizing myself with the build/make system.

What are the commands to take the compiled zImage and make my own flashable zip though? , that's what I need. I've been dying to flash the new kernel I made lol
easiest way would be use my plague kernel zip and run it thru the kitchen and unpack the boot.img n swap in your zimage in place of mine. Then repack the boot.img, build the zip, then copy to sdcard n flash.

AK instructions:

  1. place zip in original_update
  2. nav to root of AK
  3. type ./menu
  4. option 1
  5. select your zip
  6. select 0 for advanced options
  7. select 20 for boot image options
  8. select w to unpack boot.img etc
  9. swap zImage out
  10. b to repack boot.img
  11. 99 to build zip
By using my kernel zip or even mt's will save you from rewriting the updater-script. ;)
 
  • Like
Reactions: gbiggie
Upvote 0
Thanks.

I've seen the kitchen, just didn't know if it was compatible.
This is the one?

Never mind, It worked! thanks a million :) First successful kernel build.
Okay, so now if I make some APK's i want to pop in there I can just make the folder structure in the working folder and re-build I take it?

I'm gonna write something to better control cpu, and get some better battery stats. Hopefully figure out how to put it in the power or settings menu. A standalone app works too if that's a pain.
 
Upvote 0
Well it's a start. It all works except wireless for some reason. kinda strange but at least everything else seems to work ok.
did you use my src or stock LG src? Or did you change the versioning in the config? if so you have to compile the modules for it. ;)

also if you used stock src you can just grab the stock wireless.ko n use it.
 
Upvote 0
It''s a fresh new kernel built from LG source, with a few modifications of my own. I only used your zip file from the blitz kernel as a cointainer, replacing it's zImage.

I'll try injecting that wireless.ko as you mentioned. Funny thing is, I had it build the wireless broadcom drivers into the kernel as opposed to a module to try and get it to work and nothing.
 
Upvote 0
By any chance have you found out what makes the cpu governor keep going back to ondemand? I figured out how to add the interactive gov to the kernel source, built it and flashed. I thought it might work, but something keeps changing it back about every 60 seconds.

It's almost like something is polling and checking the value then setting it, because it's not immediate. I'm not using any cpu setting apps. Just good old 'echo'. then I cat the output a few times to see if it sticks, and same thing always about 60 secs then back to ondemand. :thinking:
 
Upvote 0
By any chance have you found out what makes the cpu governor keep going back to ondemand? I figured out how to add the interactive gov to the kernel source, built it and flashed. I thought it might work, but something keeps changing it back about every 60 seconds.

It's almost like something is polling and checking the value then setting it, because it's not immediate. I'm not using any cpu setting apps. Just good old 'echo'. then I cat the output a few times to see if it sticks, and same thing always about 60 secs then back to ondemand. :thinking:

I noticed on another kernel I did that I might have left something out of the Kconfig.

Other than that not sure unless its in one of the init files. I found another smartassv2 I wanna try and a lagfree governor. ;)
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones