FORUMS
Remove All Ads from XDA
H10 Turbo

[Tutorial][Kernel]How-to: Compile a kernel for P68XX

64 posts
Thanks Meter: 52
 
By mengpo, Member on 22nd August 2012, 09:35 AM
Post Reply Email Thread
I know there are a lot of tutorial to compile an Android Kernel but samsung is known to release buggy kernels and none of them tells how to deal with error.

Sources:
- a bunch of others kernel building tutorial on xda (like this one : http://forum.xda-developers.com/arch...t-1557045.html)


First and foremost, you MUST use a GNU/Linux (hereafter 'Linux') distribution. Don’t use OSX or Cygwin, I got a lot of problem with them.

The easiest way is to get the latest version of Ubuntu Linux. I personally, I’m using archlinux but the installation is a bit complex for this kind of use only.


Step 0: Pre-project Setup (optionnal)
This link will help you to use the main android commands into your newly linux environment: [SCRIPT] [Ubuntu] ADB, AAPT, APKTool, Android SDK/NDK, and udev rules auto-installer
I did not use them for this but it could be useful sometime in other tasks


Step 1: Setting up a build environment
First, you will need to install the required packages:
Code:
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev g++-multilib lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline-gplv2-dev lib32z-dev libgl1-mesa-dev git
Some of these packages won’t work but normally dependencies will be resolved by apt the package manager.

Next, you will need a Cross-Compile Toolchain, and for our purposes we will be using this specifically CodeSourcery release (2009q3):
[url=https://sourcery.mentor.com/GNUToolchain/package5353/public/arm-none-eabi/arm-2009q3-68-arm-none-eabi-i686-pc-linux-gnu.tar.bz2 [/url]
Untar it either in /opt (with su permission) or create of directory for it.
Code:
cd ~/
tar xvjf arm-2009q3-68-arm-none-eabi-i686-pc-linux-gnu.tar.bz2
It’s very important for the P68XX kernel to use this toolchain. Otherwise, you’ll have errors while compiling it and trust me, you don’t want this type of errors (look at my mdnie.c (insérer lien) thread for example). As a matter fact, I tried all of the toolchains given by the mentor website and only this one works on my linux.


Step 2: Pulling the Kernel Source
Now, we have to download the kernel from: [url=http://opensource.samsung.com/index.jsp;jsessionid=0EFA22A80FBED4451C1D9C823E344 0C4[/url]
You will have an archive unzip it and copy the kernel part into the kernel_P68XX and then untar it.
Code:
mkdir ~/kernel_P68XX
tar xvf Kernel.tar.gz -C ~/kernel_P68XX
You can remove it if you want.
Code:
rm Kernel.tar.gz
Now you have to download and extract the initrd from the samsung zImage found in the official ICS image :
  • For the UK P6810[url=http://www.hotfile.com/dl/165045602/118260c/P6810XXLPL_P6810OXALPL_XEU.zip.html[/url]
    For the Open Austria P6800 [url=http://www.hotfile.com/dl/166221509/de0b31d/P6800XXLQ2_P6800OXALQ2_ATO.zip.html[/url]
Download the zip, unzip it, untar it and copy the zImage as followed.
Then, download also and use unpack-initramfs (both files are attached at the end of this thread).
Code:
mkdir ~/initrd
mv zImage ~/initrd
mv unpack-initramfs ~/initrd
cd ~/initrd
Sudo chmod +x unpack-initramfs
./unpack-initramfs zImage

Step 3: Build the Kernel
Finally, what you've been waiting for!

We have to export a few things first, to prepare the build environment. Open a terminal and type:
Code:
export ARCH=arm
export CROSS_COMPILE=~/arm-2009q3/bin/arm-none-linux-gnueabi-
make P8-wifi_defconfig
You’ll have this :
Code:
HOSTCC  scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED
scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/lex.zconf.c
SHIPPED
scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to
.config
#
Now edit the kernel’s configuration.
Code:
nano .config
Search for
Code:
CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE=""
Change to
Code:
CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE="../initrd"
Where initrd is the folder where you extracted the zImage initramfs.

Here, you can make substiantials changes to your kernel .This step is really important if you want to customize your kernel (ie : enabling features such as governors, add init.d, cifs, file systems etc.) (we'll see this on the next tutorial). But do it only if you know what you’re doing. Don’t forget to back up your file config (named .config).

Now you can build it.
Code:
make –jX
Where X is the number of tasks you want to run simultaneously. As for me, I use 4 or 5.

Now, watch the output at the end carefully and you'll see the necessary files that we need:
Code:
OBJCOPY arch/arm/boot/Image
Kernel: arch/arm/boot/Image is ready
AS arch/arm/boot/compressed/head.o
GZIP arch/arm/boot/compressed/piggy.gzip
AS arch/arm/boot/compressed/piggy.gzip.o
CC arch/arm/boot/compressed/misc.o
CC arch/arm/boot/compressed/decompress.o
SHIPPED arch/arm/boot/compressed/lib1funcs.S
AS arch/arm/boot/compressed/lib1funcs.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
Building modules, stage 2.
MODPOST 4 modules
CC drivers/net/wireless/ath/ath.mod.o
LD [M] drivers/net/wireless/ath/ath.ko
CC drivers/net/wireless/ath/ath6kl/ath6kl_sdio.mod.o
LD [M] drivers/net/wireless/ath/ath6kl/ath6kl_sdio.ko
CC drivers/scsi/scsi_wait_scan.mod.o
LD [M] drivers/scsi/scsi_wait_scan.ko
CC net/wireless_ath/cfg80211.mod.o
LD [M] net/wireless_ath/cfg80211.ko
Anything marked with an [M] will need to be remembered, as well as the location of the compiled kernel at /arch/arm/boot/zImage

Step 4: Dealing with Samsung's errors
Well that would be it, if Samsung had done the job properly but as far as I’m concerned I got three errors :
First one :
Code:
CC drivers/media/video/samsung/mali/common/mali_kernel_core.o
arm-none-eabi-gcc: non: No such file or directory
arm-none-eabi-gcc: versionné: No such file or directory
arm-none-eabi-gcc: non: No such file or directory
arm-none-eabi-gcc: versionné": No such file or directory
cc1: warnings being treated as errors
<command-line>:0: error: missing terminating " character
drivers/media/video/samsung/mali/common/mali_kernel_core.c: In function 'mali_kernel_constructor':
drivers/media/video/samsung/mali/common/mali_kernel_core.c:172: error: missing terminating " character
drivers/media/video/samsung/mali/common/mali_kernel_core.c:172: error: expected expression before ')' token
make[5]: *** [drivers/media/video/samsung/mali/common/mali_kernel_core.o]
Erreur 1
make[4]: ***
[drivers/media/video/samsung/mali] Erreur 2
make[3]: ***
[drivers/media/video/samsung] Erreur 2
make[2]: ***
[drivers/media/video] Erreur 2
make[1]: *** [drivers/media]
Erreur 2
make: *** [drivers] Erreur 2
A way to fix this error is to change the SVN version Makefile in drivers/media/video/Samsung/mali/Makefile. I did not dig into it but I’m sure that one of the term return a wrong value. So I changed it to the number : 1. You can assign any value you want as far as it is not a variable.
Code:
nano drivers/media/video/samsung/mali/Makefile
Search for this chain string : SVN, you’ll find this one :
Code:
 # Get subversion revision number, fall back to 0000 if no svn info is available
SVN_REV:=$(shell ((svnversion | grep -qv exported && echo -n 'Revision: ' && sv… … …
Replace with:
Code:
SVN=REV:=1
Relaunch the make
Code:
make -jX
Where X is the number of tasks you want to run simultaneously. As for me, I use 4 or 5.

Second one :
Code:
arm-none-eabi-gcc: non: No such file or directory
arm-none-eabi-gcc: versionné: No such file or directory
arm-none-eabi-gcc: non: No such file or directory
arm-none-eabi-gcc: versionné": No such file or directory
cc1: warnings being treated as errors
<command-line>:0: error: missing terminating " character
drivers/media/video/samsung/ump/linux/ump_kernel_linux.c:
In function 'ump_initialize_module': drivers/media/video/samsung/ump/linux/ump_kernel_linux.c:128:
error: missing terminating " character
drivers/media/video/samsung/ump/linux/ump_kernel_linux.c:128:
error: expected expression before ')' token
drivers/media/video/samsung/ump/linux/ump_kernel_linux.c:
At top level:
drivers/media/video/samsung/ump/linux/ump_kernel_linux.c:472:
error: missing terminating " character
drivers/media/video/samsung/ump/linux/ump_kernel_linux.c:472:
error: expected expression before ',' token
make[5]: ***
[drivers/media/video/samsung/ump/linux/ump_kernel_linux.o] Erreur 1
make[4]: ***
[drivers/media/video/samsung/ump] Erreur 2
make[3]: ***
[drivers/media/video/samsung] Erreur 2
make[2]: ***
[drivers/media/video] Erreur 2
make[1]: *** [drivers/media]
Erreur 2
make: *** [drivers] Erreur 2
Do exactly the same manipulation as said above :
Modify the Makefile in drivers/media/video/Samsung/ump/Makefile.
Code:
nano drivers/media/video/Samsung/ump/Makefile
Search for this chain string : SVN, you’ll find this one :
Code:
 # Get subversion revision number, fall back to 0000 if no svn info is available
SVN_REV:=$(shell ((svnversion | grep -qv exported && echo -n 'Revision: ' && sv… … …
Replace with:
Code:
SVN=REV:=1
Relaunch the make
Code:
make -jX
Where X is the number of tasks you want to run simultaneously. As for me, I use 4 or 5.

Last error but not the least :
Code:
drivers/video/samsung/lcdfreq.c: In function 'level_store':
drivers/video/samsung/s3cfb.h:262:
sorry, unimplemented: inlining failed in call to 'get_fimd_global': function
body not available
drivers/video/samsung/lcdfreq.c:150:
sorry, unimplemented: called from here
drivers/video/samsung/s3cfb.h:262:
sorry, unimplemented: inlining failed in call to 'get_fimd_global': function
body not available
drivers/video/samsung/lcdfreq.c:176:
sorry, unimplemented: called from here
make[3]: ***
[drivers/video/samsung/lcdfreq.o] Erreur 1
make[2]: ***
[drivers/video/samsung] Erreur 2
make[1]: *** [drivers/video]
Erreur 2
make: *** [drivers] Erreur 2
Fix this is very simple but took me a lot of time. I found the solution in some patch explainations for the mainstream kernel. The only thing you have to do is : remove the word “inline” in this file drivers/video/Samsung/s3cfb.h
Search for this :
Code:
extern struct fb_ops     s3cfb_ops;
extern inline struct s3cfb_global     *get_fimd_global(int id);
Remove “inline”:
Code:
extern struct fb_ops      s3cfb_ops;
extern struct s3cfb_global     *get_fimd_global(int id);
Redo the make command :
[code]make -jX{/code]

Now you’ve got your kernel built but it's not finished yet !

Final Step: Include modules to your kernel
At first, I was very surprised by this step but it is essential otherwise your kernel won’t work. Actually, modules included by samsung in the initrd uncompressed before are not working as if. So you have to do this :
in the initrd you made, copy the *.ko into initrd/lib/modules
Code:
 cp drivers/net/wireless/ath/ath.ko drivers/net/wireless/ath/ath6kl/ath6kl_sdio.ko drivers/scsi/scsi_wait_scan.ko net/wireless_ath/cfg80211.ko ../initrd/lib/modules
Overwrite them if asked.
Clean your code, use your backup config file and rebuilt the kernel :
Code:
Make distclean
Make clean
Cp your_backup_file kernel_P68XX/.config
make –jX
Where X is the number of tasks you want to run simultaneously. As for me, I use 4 or 5.

Your final kernel is here : /arch/arm/boot/zImage

Kernel Installation
Flash via heimdall
Code:
$ adb reboot download
$ heimdall flash --kernel path/to/zImage
Maybe there's another way to do this so feel free to leave comments

Good luck !
Attached Files
File Type: zip unpack-initramfs.zip - [Click for QR Code] (2.0 KB, 224 views)
The Following 23 Users Say Thank You to mengpo For This Useful Post: [ View ] Gift mengpo Ad-Free
 
 
22nd August 2012, 11:35 AM |#2  
alxwlc's Avatar
Senior Member
Flag Kuala Lumpur
Thanks Meter: 97
 
Donate to Me
More
Thanks for sharing..
The Following User Says Thank You to alxwlc For This Useful Post: [ View ] Gift alxwlc Ad-Free
22nd August 2012, 12:11 PM |#4  
dedraks's Avatar
Senior Member
Flag Belo Horizonte
Thanks Meter: 302
 
Donate to Me
More
Thanks man.

Enviado de meu GT-P6800 usando o Tapatalk 2
The Following User Says Thank You to dedraks For This Useful Post: [ View ] Gift dedraks Ad-Free
22nd August 2012, 02:29 PM |#5  
OP Member
Flag lyon
Thanks Meter: 52
 
More
Thanks guys !

Next to come : Install the kernel via cwm, Kernel optimisations and Build a custom rom for these devices.
The Following User Says Thank You to mengpo For This Useful Post: [ View ] Gift mengpo Ad-Free
23rd August 2012, 12:01 AM |#6  
dedraks's Avatar
Senior Member
Flag Belo Horizonte
Thanks Meter: 302
 
Donate to Me
More
Running my first home built kernel.



I love android. :P
The Following 2 Users Say Thank You to dedraks For This Useful Post: [ View ] Gift dedraks Ad-Free
23rd August 2012, 12:21 AM |#7  
OP Member
Flag lyon
Thanks Meter: 52
 
More
Smile
Quote:
Originally Posted by dedraks

Running my first home built kernel.



I love android. :P

So cool you did it
Congrats !
23rd August 2012, 12:29 AM |#8  
Senior Member
Thanks Meter: 173
 
More
Awesome tutorial mengpo, thanks
The Following User Says Thank You to Astrix Ashburn For This Useful Post: [ View ] Gift Astrix Ashburn Ad-Free
23rd August 2012, 01:58 AM |#9  
Senior Member
Flag Seattle
Thanks Meter: 1,020
 
Donate to Me
More
Quote:
Originally Posted by mengpo

Next to come : Install the kernel via cwm

Easiest to just flash via heimdall
Code:
$ adb reboot download
$ heimdall flash --kernel path/to/zImage
The Following User Says Thank You to locerra For This Useful Post: [ View ] Gift locerra Ad-Free
23rd August 2012, 07:14 AM |#10  
OP Member
Flag lyon
Thanks Meter: 52
 
More
Quote:
Originally Posted by locerra

Easiest to just flash via heimdall

Code:
$ adb reboot download
$ heimdall flash --kernel path/to/zImage


I did not know it was so simple !!
I'll change the tuto then !
Thanks again !
23rd August 2012, 12:49 PM |#11  
Senior Member
New York
Thanks Meter: 145
 
More
Thanks a lot !
I havent coded for ages and setting up the environment was discouraging me from even thinking about trying to play with the kernel
This is extremely useful
Post Reply Subscribe to Thread

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

Advanced Search
Display Modes