[Galaxy Tab 7.7 Android Development] mengpo:
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://xdaforums.com/archive/index.php/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:

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):

Untar it either in /opt (with su permission) or create of directory for it.

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=0EFA22A80FBED4451C1D9C823E3440C4[/url]

You will have an archive unzip it and copy the kernel part into the kernel_P68XX and then untar it.

mkdir ~/kernel_P68XX
tar xvf Kernel.tar.gz -C ~/kernel_P68XX

You can remove it if you want.

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

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:

export ARCH=arm
export CROSS_COMPILE=~/arm-2009q3/bin/arm-none-linux-gnueabi-
make P8-wifi_defconfig

You’ll have this :

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.

nano .config

Search for

CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE=""

Change to

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.

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:

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 :

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.

nano drivers/media/video/samsung/mali/Makefile

Search for this chain string : SVN, you’ll find this one :

# 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:

SVN=REV:=1

Relaunch the make

make -jX

Where X is the number of tasks you want to run simultaneously. As for me, I use 4 or 5.

Second one :

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.

nano drivers/media/video/Samsung/ump/Makefile

Search for this chain string : SVN, you’ll find this one :

# 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:

SVN=REV:=1

Relaunch the make

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 :

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 :

extern struct fb_ops s3cfb_ops;
extern inline struct s3cfb_global *get_fimd_global(int id);

Remove “inline”:

extern struct fb_ops s3cfb_ops;
extern struct s3cfb_global *get_fimd_global(int id);

Redo the make command :

make -jX{/code]

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

[COLOR="blue"][B]Final Step: Include modules to your kernel[/B][/COLOR]
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 :

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

$ 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 !