FORUMS
Remove All Ads from XDA

[Guide] How to compile stock LG2X kernel from scratch

49 posts
Thanks Meter: 40
 
By kosi2801, Member on 3rd March 2012, 11:47 PM
Post Reply Email Thread
For some weeks I've been trying to set up an environment in which I'm able to compile the stock kernel for my LG2X on my own. Following various tips and hints were unsuccessful and several restarts were required until a kernel which was compiled on my own box was running on my phone. Since I had to patch together all the information because there was no complete guide available/findable, I'd like to list here all the steps from the beginning which I had to perform to boot my own compiled kernel. Maybe this is also useful for others. Note: again, this approach is for compiling STOCK kernel sources which are based on the public sources from LG. (The build process for CM is different and cannot be applied to stock kernels)

I began with a freshly installed Ubuntu 11.10 32bit (http://www.ubuntu.com/download/ubuntu/download) running in a VMware virtual machine. In it I entered a shell and switched to root to be able to perform the required actions:
Code:
sudo su -
The next step was to add the package-sources for the cross-compiler toolchain (see next step) and to bring the system up to the latest state.
Code:
add-apt-repository ppa:linaro-maintainers/toolchain
apt-get update
apt-get upgrade
This takes some time but after it's finished I installed the cross-compiler toolchain to be able to compile applications for the LGs ARM platform
Code:
apt-get install gcc-linaro
apt-get install gcc-linaro-arm-linux-gnueabi
After this I've been ready to begin with the source-works. I closed the root-shell and opened up a new one (required to make sure that all paths are correctly set and recognized again). Test it by executing
Code:
arm-linux-gnueabi-gcc --version
When this executed without error I started with downloading the sources for version 20q from http://www.lg.com/global/support/ope...delCode=LGP990 into a new directory.

When the file 'LGP990_Android_Gingerbread_V20Q.zip' had finished downloading I unzipped the complete package by
Code:
unzip LGP990_Android_Gingerbread_V20Q.zip
resulting in three files. A README, one .tar.gz with the ROM sources and finally one .tar.gz with the kernel sources. To unpack the kernel sources I issued
Code:
tar xvzf P990_Stardop_IFX_GingerBread_V20Q_KERNEL.tar.gz
and the complete LG 20q kernel sources were finally located in a new 'kernel' subdirectory.

The kernel sources themselves are not yet ready to be compiled. This is because LG most probably has a different/special build environment and our standard environment produces errors and unbootable kernels. Some patching is required to succeed to a running kernel.
Firstly the compilation options for the wireless module have to be tweaked as the default settings break compilation at some unused variables in the source. This is set to be just treated as warnings for the wireless-module by applying following patch:
Code:
diff -u -r original/kernel/drivers/net/wireless/bcm4329/Makefile kernel/drivers/net/wireless/bcm4329/Makefile
--- original/kernel/drivers/net/wireless/bcm4329/Makefile     2012-01-31 04:36:22.000000000 -0800
+++ kernel/drivers/net/wireless/bcm4329/Makefile     2012-02-14 11:41:59.972467559 -0800
@@ -53,7 +53,7 @@
     -DBCMLXSDMMC \
     -DBCMPLATFORM_BUS \
     -DSDIO_ISR_THREAD \
-     -Wall -Wstrict-prototypes -Werror \
+     -Wall -Wstrict-prototypes -Werror -Wno-unused-but-set-variable -Wno-array-bounds \
     -I$(SRCROOT) \
     -I$(SRCROOT)/include \
     -I$(SRCROOT)/shared \
Also the main Makefile requires tuning to contain the proper compilation options to produce code which correctly runs on the phone (thanks to spica1234 for providing me with the correct options).
Code:
diff -u -r original/kernel/Makefile kernel/Makefile
--- original/kernel/Makefile     2012-01-31 04:36:21.000000000 -0800
+++ kernel/Makefile     2012-02-28 13:21:20.038003539 -0800
@@ -323,12 +323,12 @@

CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
            -Wbitwise -Wno-return-void $(CF)
-MODFLAGS     = -DMODULE
-CFLAGS_MODULE   = $(MODFLAGS)
+MODFLAGS     = -DMODULE -mfloat-abi=softfp -mfpu=vfpv3-d16 -mtune=cortex-a9 -march=armv7-a -fno-common -fsingle-precision-constant -fno-gcse -funsafe-math-optimizations -ffinite-math-only -fgcse-las -fgcse-sm -fivopts -fbtr-bb-exclusive -fvect-cost-model -fmodulo-sched -fmodulo-sched-allow-regmoves
+CFLAGS_MODULE   = $(MODFLAGS)
AFLAGS_MODULE   = $(MODFLAGS)
LDFLAGS_MODULE  = -T $(srctree)/scripts/module-common.lds
-CFLAGS_KERNEL     =
-AFLAGS_KERNEL     =
+CFLAGS_KERNEL     =  -mfloat-abi=softfp -mfpu=vfpv3-d16 -mtune=cortex-a9 -march=armv7-a -fno-common -fsingle-precision-constant -fno-gcse -funsafe-math-optimizations -ffinite-math-only -fgcse-las -fgcse-sm -fivopts -fbtr-bb-exclusive -fvect-cost-model -fmodulo-sched -fmodulo-sched-allow-regmoves
+AFLAGS_KERNEL     = -mfloat-abi=softfp -mfpu=vfpv3-d16 -mtune=cortex-a9 -march=armv7-a -fno-common -fsingle-precision-constant -fno-gcse -funsafe-math-optimizations -ffinite-math-only -fgcse-las -fgcse-sm -fivopts -fbtr-bb-exclusive -fvect-cost-model -fmodulo-sched -fmodulo-sched-allow-regmoves
CFLAGS_GCOV     = -fprofile-arcs -ftest-coverage

# 20100705, sunghoon.kim@lge.com,[LGE_START]
@@ -544,7 +544,8 @@
ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
KBUILD_CFLAGS     += -Os
else
-KBUILD_CFLAGS     += -O2
+KBUILD_CFLAGS     += -Ofast
+KBUILD_CFLAGS += $(call cc-option, -Wno-unused-but-set-variable)
endif
We're not finished yet. We've to create the correct kernel configuration and (again) apply some patches. I'm not so sure about these changes but the kernel refused to boot on my phone without them. It is again provided by spica1234 and contains a number of changes. I did not research which of these changes allowed to boot since most of them are generally useful and I didn't do the work trying them out one-by-one.
Code:
make ARCH=arm star_ifx_defconfig
Code:
--- .config.orig        2012-02-28 13:22:09.322001449 -0800
+++ .config.spica_working       2012-03-02 08:41:21.757696988 -0800
@@ -1,7 +1,7 @@
#
# Automatically generated make config: don't edit
# Linux kernel version: 2.6.32.9-HP_2X_Xtreme_RC12-RevOTF
-# Tue Feb 28 13:22:09 2012
+# Tue Feb 28 13:24:15 2012
#
CONFIG_ARM=y
CONFIG_SYS_SUPPORTS_APM_EMULATION=y
@@ -56,16 +56,16 @@
CONFIG_LOG_BUF_SHIFT=18
CONFIG_GROUP_SCHED=y
CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
+CONFIG_RT_GROUP_SCHED=y
# CONFIG_USER_SCHED is not set
CONFIG_CGROUP_SCHED=y
CONFIG_CGROUPS=y
# CONFIG_CGROUP_DEBUG is not set
# CONFIG_CGROUP_NS is not set
-CONFIG_CGROUP_FREEZER=y
-CONFIG_CGROUP_DEVICE=y
+# CONFIG_CGROUP_FREEZER is not set
+# CONFIG_CGROUP_DEVICE is not set
# CONFIG_CPUSETS is not set
-CONFIG_CGROUP_CPUACCT=y
+# CONFIG_CGROUP_CPUACCT is not set
# CONFIG_RESOURCE_COUNTERS is not set
# CONFIG_SYSFS_DEPRECATED_V2 is not set
CONFIG_RELAY=y
@@ -121,7 +121,8 @@
# GCOV-based kernel profiling
#
# CONFIG_GCOV_KERNEL is not set
-# CONFIG_SLOW_WORK is not set
+CONFIG_SLOW_WORK=y
+# CONFIG_SLOW_WORK_DEBUG is not set
CONFIG_HAVE_GENERIC_DMA_COHERENT=y
CONFIG_SLABINFO=y
CONFIG_RT_MUTEXES=y
@@ -146,10 +147,10 @@
CONFIG_IOSCHED_DEADLINE=y
CONFIG_IOSCHED_CFQ=y
# CONFIG_DEFAULT_AS is not set
-# CONFIG_DEFAULT_DEADLINE is not set
-CONFIG_DEFAULT_CFQ=y
+CONFIG_DEFAULT_DEADLINE=y
+# CONFIG_DEFAULT_CFQ is not set
# CONFIG_DEFAULT_NOOP is not set
-CONFIG_DEFAULT_IOSCHED="cfq"
+CONFIG_DEFAULT_IOSCHED="deadline"
CONFIG_FREEZER=y

#
@@ -1676,16 +1677,25 @@
# File systems
#
CONFIG_EXT2_FS=y
-# CONFIG_EXT2_FS_XATTR is not set
-# CONFIG_EXT2_FS_XIP is not set
+CONFIG_EXT2_FS_XATTR=y
+# CONFIG_EXT2_FS_POSIX_ACL is not set
+# CONFIG_EXT2_FS_SECURITY is not set
+CONFIG_EXT2_FS_XIP=y
CONFIG_EXT3_FS=y
CONFIG_EXT3_DEFAULTS_TO_ORDERED=y
CONFIG_EXT3_FS_XATTR=y
# CONFIG_EXT3_FS_POSIX_ACL is not set
# CONFIG_EXT3_FS_SECURITY is not set
-# CONFIG_EXT4_FS is not set
+CONFIG_EXT4_FS=y
+CONFIG_EXT4_FS_XATTR=y
+# CONFIG_EXT4_FS_POSIX_ACL is not set
+# CONFIG_EXT4_FS_SECURITY is not set
+# CONFIG_EXT4_DEBUG is not set
+CONFIG_FS_XIP=y
CONFIG_JBD=y
# CONFIG_JBD_DEBUG is not set
+CONFIG_JBD2=y
+# CONFIG_JBD2_DEBUG is not set
CONFIG_FS_MBCACHE=y
# CONFIG_REISERFS_FS is not set
# CONFIG_JFS_FS is not set
@@ -1769,7 +1779,22 @@
# CONFIG_ROMFS_FS is not set
# CONFIG_SYSV_FS is not set
# CONFIG_UFS_FS is not set
-# CONFIG_NETWORK_FILESYSTEMS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+# CONFIG_NFS_FS is not set
+# CONFIG_NFSD is not set
+CONFIG_SMB_FS=m
+# CONFIG_SMB_NLS_DEFAULT is not set
+CONFIG_CIFS=m
+# CONFIG_CIFS_STATS is not set
+# CONFIG_CIFS_WEAK_PW_HASH is not set
+# CONFIG_CIFS_UPCALL is not set
+# CONFIG_CIFS_XATTR is not set
+# CONFIG_CIFS_DEBUG2 is not set
+# CONFIG_CIFS_DFS_UPCALL is not set
+# CONFIG_CIFS_EXPERIMENTAL is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set

#
# Partition Types
After these patches, were finally ready to compile the kernel
Code:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- STAR_TMUS_REV=TMUS_10 TARGET_STAR_HWREV=TMUS_E TARGET_MODEM=ifx
Now go grab some coffee. This takes a while. When it's finished, the compressed kernel-image is found in
arch/arm/boot/zImage

For the experienced kernel-hackers this might be enough. It wasn't for me and I wanted to have it easily installable like other kernels from the forum. So I downloaded a kernel zip package, eg. the one from spica1234 at http://forum.xda-developers.com/show...96&postcount=1
Any version will do as long as the kernel is contained in a .zip archive and installable via CWM. In my case I downloaded the kernel zip in a new directory 'build' and unpacked it.
Code:
unzip HP_2x_RC12-RevOTF-PRO.zip
This creates the subdirectories 'data', 'kernel', 'META-INF' and 'system'. Here we now have to replace the kernel and the kernel-modules with our self-compiled versions.
Code:
cd ~build/kernel
rm zImage
cp ~kernel/arch/arm/bootzImage ./zImage
cd ../system/lib/modules
rm *.ko
find ~kernel/ -name "*.ko" -exec cp '{}' . \;
cd ../../..
One last step, creating the zip which carries the new kernel:
Code:
zip -r -FS new_kernel.zip data/ kernel/ META-INF/ system/


This new_kernel.zip can now be flashed with CWM and should boot without problems.

For easier usage, I've attached the three patched files in the build_set.zip attachment so you don't have to patch the stock files by hand. Just extract it in the kernel directory and overwrite the existing files.


I hope I did not make any error in the compilation of this information and that it can be helpful for the interested reader.

Thanks goes especially to spica1234 and the material which he provided me to come through to a successful boot.
Attached Files
File Type: zip build_set.zip - [Click for QR Code] (30.5 KB, 95 views)
The Following 14 Users Say Thank You to kosi2801 For This Useful Post: [ View ] Gift kosi2801 Ad-Free
 
 
4th March 2012, 12:20 AM |#2  
spica1234's Avatar
Retired Recognized Developer
Flag India
Thanks Meter: 3,365
 
More
Very good explanation. I wish such useful info available b4 an year for me while i published 1st kernel at samdroid for my older device

Sent from my LG-P990 using Tapatalk
4th March 2012, 12:25 AM |#3  
Senior Member
Flag Plymouth/USA
Thanks Meter: 62
 
More
Bloody hell! I never realised it took so much to simply compile!!!! (I build JEE systems at work, but we scripted most of it, stuff that used to take a day and half now takes a few minutes).
4th March 2012, 12:59 AM |#4  
salisbury_steak's Avatar
Senior Member
Flag Manila
Thanks Meter: 665
 
More
Excellent guide Kosi! I'm a linux and kernel n00b and I understand your instructions pretty well.
4th March 2012, 02:27 AM |#5  
Stefan Gündhör's Avatar
Senior Member
Flag Hinterholz 8
Thanks Meter: 5,770
 
More
Ubuntu 11 is not the best choice though I currently use it myself. v11 can cause problems, especially when not compiling kernels but compiling Android ROMs.

Ubuntu 10 is the better choice.

Also there is a VMware Android Developer Environment available for download, providing nearly all the necessary tools for compilation preinstalled and set-up.

http://forum.xda-developers.com/show....php?t=1386918

You can compile your kernel directly in the virtual machine p.ex. on your Windows 7 PC. That's the way I do it for my kernel. VMware Player is available for free, so you can just run the image.
Also install VMware tools, so you can set up a directory for exchanging files between your Windows Host and the virtual Machine Ubuntu. In this directory I usually paste the compiled kernel for further use under Win7 (making the CWM update ZIPs).

Just note that you should have a dual/quadcore CPU strong enough to host the linux and compile the kernel in an acceptable time (usually it takes me 1-2 minutes for complete kernel compilation under virtual machine ubuntu using -j24 option on make).
5th March 2012, 02:05 PM |#6  
ghadap's Avatar
Senior Member
Flag Ampang
Thanks Meter: 15
 
More
Can u guys add a bit in this tutorial, example, at which file / folder need to edit for OCUV, add swap function, enable ext4, etc.. seriously like this thread..

Sent from my LG-P990 using XDA
10th March 2012, 12:22 PM |#7  
OP Member
Thanks Meter: 40
 
More
Quote:
Originally Posted by ghadap

Can u guys add a bit in this tutorial, example, at which file / folder need to edit for OCUV, add swap function, enable ext4, etc.. seriously like this thread..

As the topic of this thread is just how to get the stock kernel compiling I won't step into modifying it. Please open a separate thread for that.
Small hints though, OCUV requires deeper code changes, swap and ext4 can just be enabled in the kernel config.
10th March 2012, 02:01 PM |#8  
Senior Member
Thanks Meter: 813
 
More
Hey,

I follow the guide, but ubuntu (11.04 64 bit) doesn't find the pack
Code:
apt-get install gcc-linaro
so I can't install the pack
Code:
apt-get install gcc-linaro-arm-linux-gnueabi
Edit: With Ubuntu 11.10, it works.
14th March 2012, 06:17 AM |#9  
TrymHansen's Avatar
Senior Member
Thanks Meter: 967
 
More
Has anyone compiled and booted a kernel successfully with this guide? Can't get mine to boot, so before I look any further I'd thought I'd check if anyone else has gotten a workable kernel out of it.
14th March 2012, 10:13 AM |#10  
spica1234's Avatar
Retired Recognized Developer
Flag India
Thanks Meter: 3,365
 
More
Quote:
Originally Posted by TrymHansen

Has anyone compiled and booted a kernel successfully with this guide? Can't get mine to boot, so before I look any further I'd thought I'd check if anyone else has gotten a workable kernel out of it.

Which version it shows "arm-linux-gnueabi-gcc --version"
If its 4.6.2?

Sent from my LG-P990 using Tapatalk
15th March 2012, 11:51 AM |#11  
owain94's Avatar
Recognized Developer
Flag The Hague
Thanks Meter: 6,067
 
More
Quote:
Originally Posted by Stefan Gündhör

Ubuntu 11 is not the best choice though I currently use it myself. v11 can cause problems, especially when not compiling kernels but compiling Android ROMs.

Ubuntu 10 is the better choice.

Also there is a VMware Android Developer Environment available for download, providing nearly all the necessary tools for compilation preinstalled and set-up.

http://forum.xda-developers.com/show....php?t=1386918

You can compile your kernel directly in the virtual machine p.ex. on your Windows 7 PC. That's the way I do it for my kernel. VMware Player is available for free, so you can just run the image.
Also install VMware tools, so you can set up a directory for exchanging files between your Windows Host and the virtual Machine Ubuntu. In this directory I usually paste the compiled kernel for further use under Win7 (making the CWM update ZIPs).

Just note that you should have a dual/quadcore CPU strong enough to host the linux and compile the kernel in an acceptable time (usually it takes me 1-2 minutes for complete kernel compilation under virtual machine ubuntu using -j24 option on make).

Ubuntu 11.xx is still a good choise if you want to build ROMs it is very easy to set it up (it is just one step more then on 10.xx)

i also use ubuntu 11.10 and it is working fine for me with building android ROMs

and of course it can take 1-2 minutes but it also can take up to an hour for a kernel to compile
it all depends on how good your computer is
on my home computer i build a kernel in a matter of seconds (clobber builds)
but when i am at my girlfriend my build (also clobber) on her craptop will take up to 20 minutes

nice guide kosi2801!
Post Reply Subscribe to Thread

Tags
kernel stock compile

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes