[G Tablet Android Development] blackSwanBB:
This is a intermediate guide for anyone who wants to manually compile their own kernel for the GTablet. If you merely want to use a prebuilt kernel then this is not for you. Personally, I am no expert on kernel development or bash scripting (which I will reference) but I get a kick out of analyzing and modifying bits and pieces here and there. I will not be covering retrieving all dependencies. This guide was written to work with pershoot's kernel repository. Every step has been tested using a fresh installation of Ubuntu 10.10 x64.

Step 1 - Obtaining tools and kernel source:

Install git-core.

[optional] Install ncurses-dev (if you want to use menuconfig to modify the kernel selections).

[optional] Install lib32stdc++ (if your development machine is running a x64 variant of linux). This is a necessary step to use the prebuilt android toolchain as it is compiled for a 32 bit machine.

sudo apt-get install git-core libncurses-dev lib32stdc++6

[optional] The next git clone steps will copy the repositories to the current directory, all following example will assume that you are cloning to "/usr/src/tegratab".

mkdir /usr/src/tegratab

Note: You need to be a member of the "src" group to modify the contents of "/usr/src" without sudoing. After adding yourself to the "src" group you need to restart for the permissions to take effect.

usermod -a -G src `whoami`
sudo reboot

Retrieve the prebuilt android toolchain.

git clone git://android.git.kernel.org/platform/prebuilt.git

Clone pershoot's "Gtablet Kernel 2.6.32" source repository.

git clone https://github.com/pershoot/gtab-2632.git

Note: We'll continue with the assumption of the following directory structure. Subsequent code snipets will use absolute paths so if your installation differs, just update the commands to adjust.

/usr/src/tegratab
/usr/src/tegratab/gtab-2632
/usr/src/tegratab/prebuilt

Step 2 - Kernel Configuration:

During the kernel compilation, the make utility utilizes the ".config" file in the kernel source's root directory to determine how the kernel should be compiled.

So before we begin the actual kernel compilation we need to perform the configuration.

To use pershoot's kernel configuration do the following:

make -C /usr/src/tegratab/gtab-2632/ ARCH=arm pershoot_tegra_harmony_android_defconfig

Note: When specifying the defconfig file, the make utility searches the arch/$ARCH/configs directory.

This will simply copy pershoot's defconfig file to the .config file (and update the timestamp). We could have bypassed the make utility and done this manually as follows:

cp /usr/src/tegratab/gtab-2632/arch/arm/configs/pershoot_tegra_harmony_android_defconfig /usr/src/tegratab/gtab-2632/.config

To manually modify the kernel configuration you have several options:

1. Generate the ".config" file (described above) and manually edit it.

vi /usr/src/tegratab/gtab-2632/.config

2. Create your own defconfig file and manually edit it.

cp /usr/src/tegratab/gtab-2632/arch/arm/configs/pershoot_tegra_harmony_android_defconfig /usr/src/tegratab/gtab-2632/arch/arm/configs/custom_tegra_harmony_android_defconfig
vi /usr/src/tegratab/gtab-2632/arch/arm/configs/custom_tegra_harmony_android_defconfig

Then use the make utility to generate (i.e. copy to the ".config") based on the new defconfig file.

make -C /usr/src/tegratab/gtab-2632/ ARCH=arm custom_tegra_harmony_android_defconfig

3. Use the menuconfig tool which comes with the linux source. This is the recommended solution to manually configuring the kernel. The menuconfig's initial kernel configuration selections are based on the ".config" file, so it should be generated first. After configuring the kernel as you please, you will have option when exiting the menuconfig tool to save your selections to the ".config" file.

make -C /usr/src/tegratab/gtab-2632/ ARCH=arm menuconfig

The optimal solution would be to define the initial kernel configuration selection and menuconfig simulaneously, the previous listings are mostly for educational purposes.

make -C /usr/src/tegratab/gtab-2632/ ARCH=arm pershoot_tegra_harmony_android_defconfig menuconfig

Step 3 - Kernel Compilation:

Now that the kernel has been configured it can finally compiled.

Make the kernel image itself (the resulting kernel image will be located at /usr/src/tegratab/gtab-2632/arch/arm/boot/zImage):

make -C /usr/src/tegratab/gtab-2632/ ARCH=arm CROSS_COMPILE=/usr/src/tegratab/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- zImage

To make the kernel modules (typically used to add support for new hardware and/or filesystems, or for adding system calls):

make -C /usr/src/tegratab/gtab-2632/ ARCH=arm CROSS_COMPILE=/usr/src/tegratab/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- modules

Step 4 - Packaging the Kernel for Deployment to the GTablet:

Now it's time to create the package file that will be used to install the new kernel.

This is where it used to get a bit tricky but luckily some great work from Pershoot and Koush has made it much easier.

Alternate Methods / References:

[FAQ] Flashing UPDATE.ZIP the old fashioned way (How and Did It Work?)	http://xdaforums.com/showthread.php?t=892090

HOWTO: Unpack, Edit, and Re-Pack Boot Images)	http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack,_Edit,_and_Re-Pack_Boot_Images

Building Android kernel images)	http://www.cianer.com/androidg1/28-building-android-kernel-images

Ignore those, we'll do it the easy way:

Save a copy of pershoot's boot- zip from http://droidbasement.com/ to use as a template:

wget http://droidbasement.com/gtab/kernels/2632/1/boot-cm_2632.27-xtra-vfpv3_fp-010711.zip -O /usr/src/tegratab/boot-template.zip

Make a temporary directory so we can perform the staging:

mkdir /usr/src/tegratab/staging

Unzip the boot template here:

unzip -d /usr/src/tegratab/staging /usr/src/tegratab/boot-template.zip

Copy the kernel image which was built to this staging directory:

cp -v /usr/src/tegratab/gtab-2632/arch/arm/boot/zImage /usr/src/tegratab/staging/kernel/zImage

Install the kernel modules which were built:

make -C /usr/src/tegratab/gtab-2632/ ARCH=arm INSTALL_MOD_PATH=/usr/src/tegratab/staging/system modules_install

Replace the original bcm4329 kernel module which was extracted from the boot-template with the newly compiled kernel module:

cp -v /usr/src/tegratab/staging/system/lib/modules/2.6.32.28-cyanogenmod/kernel/drivers/net/wireless/bcm4329/dhd.ko /usr/src/tegratab/staging/system/lib/hw/wlan/bcm4329.ko

Remove the two symlink directories in our staging directory, these were created during the kernel module installation:

rm -v /usr/src/tegratab/staging/system/lib/modules/2.6.32.28-cyanogenmod/source
rm -v /usr/src/tegratab/staging/system/lib/modules/2.6.32.28-cyanogenmod/build

Zip the result:

cd /usr/src/tegratab/staging
zip -r /usr/src/tegratab/boot-custom-kernel *

[optional]Cleanup the staging directory:

cd /usr/src/tegratab
rm -R /usr/src/tegratab/staging

Step 5 - Package Installation

Boot into Clockwork Recovery.

Navigate to "mounts and storage".

Select "mount USB storage".

Copy /usr/src/tegratab/boot-custom-kernel.zip to the mounted filesystem.

Select "Unmount USB storage".

Navigate to "install zip from sdcard" => "choose zip from sdcard" => "boot-custom-kernel.zip".

Select "Yes - Install boot-custom-kernel.zip".

Select "reboot system now".

It's now installed!

Once reboot is complete navigate to the "Settings" => "About device".

Check "Kernel version", it should specify the some details about your new build.

2.6.32.28-cyanogenmod

swan@hawthorne-vm #1​

References:

Android Development: http://source.android.com/source/download.html

Here's a brief description of the command line options which were used:

-C dir, --directory=dir
Change to directory dir before reading the makefiles or doing anything else. If multiple -C options are specified, each is interpreted relative to the previous one: -C /
-C etc is equivalent to -C /etc. This is typically used with recursive invocations of make.

ARCH=<architecture>

# When performing cross compilation for other architectures ARCH shall be set
# to the target architecture. (See arch/* for the possibilities).
# ARCH can be set during invocation of make:
# make ARCH=ia64
# Another way is to have ARCH set in the environment.
# The default ARCH is the host where make is executed.

CROSS_COMPILE=<toolchain>

# CROSS_COMPILE specify the prefix used for all executables used
# during compilation. Only gcc and related bin-utils executables
# are prefixed with $(CROSS_COMPILE).
# CROSS_COMPILE can be set on the command line
# make CROSS_COMPILE=ia64-linux-
# Alternatively CROSS_COMPILE can be set in the environment.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
#ARCH ?= arm
#CROSS_COMPILE ?=$(CURDIR)/../prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-

INSTALL_MOD_PATH=<module-target-path>

# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
# relocations required by build roots. This is not defined in the
# makefile but the argument can be passed to make if needed.

Scripts:

Kernel Configuration Script:

[size=3]AR[color=#000000]=[/color]arm

[color=#000080][b]if[/b][/color] [color=#000000][ -[/color]n [color=#ddbb00]"$1"[/color] [color=#000000]] && [ -[/color]n [color=#ddbb00]"$2"[/color] [color=#000000]][/color]
[color=#000080][b]then[/b][/color]
[color=#0000ff]make[/color] [color=#000000]-[/color]C [color=#000000]$1[/color] ARCH[color=#000000]=[/color][color=#000000]$AR $2[/color] menuconfig
[color=#000080][b]else[/b][/color]
[color=#000080]echo[/color] [color=#ddbb00]"Usage: $0 [source-dir] [defconfig]"[/color]
[color=#000080][b]fi[/b][/color]
[/size]

Kernel Compilation / Packing Script:

[size=3][color=#ff0000][i]#!/bin/sh[/i][/color]
CC[color=#000000]=/[/color]usr[color=#000000]/[/color]src[color=#000000]/[/color]tegratab[color=#000000]/[/color]prebuilt[color=#000000]/[/color]linux[color=#000000]-[/color]x86[color=#000000]/[/color]toolchain[color=#000000]/[/color]arm[color=#000000]-[/color]eabi[color=#000000]-[/color][color=#008800]4.4.0[/color][color=#000000]/[/color]bin[color=#000000]/[/color]arm[color=#000000]-[/color]eabi[color=#000000]-[/color]
AR[color=#000000]=[/color]arm

PREFIX[color=#000000]=[/color][color=#ddbb00]`echo $1 | sed -e 's/[/]*$//' -e 's/[/]/_/'`[/color]
POSTFIX[color=#000000]=[/color][color=#ddbb00]`date +%Y_%m_%e_%H%M%S`[/color]

KSOURCE_DIR[color=#000000]=[/color][color=#000000]$1[/color]
TARGET_NAME[color=#000000]=[/color][color=#000000]$PREFIX[/color][color=#000000]-[/color][color=#000000]$POSTFIX[/color]
SAMPLE_ZIP[color=#000000]=/[/color]usr[color=#000000]/[/color]src[color=#000000]/[/color]tegratab[color=#000000]/[/color]boot[color=#000000]-[/color]template.[color=#0000ff]zip[/color]

OUTPUT_ZIP[color=#000000]=/[/color]usr[color=#000000]/[/color]src[color=#000000]/[/color]tegratab[color=#000000]/[/color][color=#000000]$TARGET_NAME[/color]
STAGING_DIR[color=#000000]=/[/color]tmp[color=#000000]/[/color][color=#000000]$TARGET_NAME[/color]

do_compile[color=#000000]()[/color]
[color=#000000]{[/color]
[color=#000080]echo[/color] [color=#ddbb00]"do_compile()"[/color]

[color=#ff0000][i]# Build the kernel image.[/i][/color]
[color=#0000ff]make[/color] [color=#000000]-[/color]C [color=#000000]$KSOURCE_DIR[/color] ARCH[color=#000000]=[/color][color=#000000]$AR[/color] CROSS_COMPILE[color=#000000]=[/color][color=#000000]$CC[/color] zImage
[color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]return[/color] $?[color=#000000];[/color] [color=#000080][b]fi[/b][/color]

[color=#ff0000][i]# Build the kernel modules.[/i][/color]
[color=#0000ff]make[/color] [color=#000000]-[/color]C [color=#000000]$KSOURCE_DIR[/color] ARCH[color=#000000]=[/color][color=#000000]$AR[/color] CROSS_COMPILE[color=#000000]=[/color][color=#000000]$CC[/color] modules
[color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]return[/color] $?[color=#000000];[/color] [color=#000080][b]fi[/b][/color]

[color=#000000]}[/color]

do_staging[color=#000000]()[/color]
[color=#000000]{[/color]
[color=#000080]echo[/color] [color=#ddbb00]"do_staging()"[/color]

[color=#ff0000][i]# Unzip the sample update zip to create update structure[/i][/color]
[color=#ff0000][i]# and provide update scripts / utilities.[/i][/color]
[color=#0000ff]unzip[/color] [color=#000000]-[/color]d [color=#000000]$STAGING_DIR $SAMPLE_ZIP[/color]
[color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]return[/color] $?[color=#000000];[/color] [color=#000080][b]fi[/b][/color]
[color=#000000]}[/color]

do_populate[color=#000000]()[/color]
[color=#000000]{[/color]
[color=#000080]echo[/color] [color=#ddbb00]"do_populate()"[/color]

[color=#ff0000][i]# Copy the resulting image to the staging dir.[/i][/color]
[color=#0000ff]cp[/color] [color=#000000]-[/color]v [color=#000000]$KSOURCE_DIR[/color][color=#000000]/[/color]arch[color=#000000]/[/color][color=#000000]$AR[/color][color=#000000]/[/color]boot[color=#000000]/[/color]zImage [color=#000000]$STAGING_DIR[/color][color=#000000]/[/color]kernel[color=#000000]/[/color]
[color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]return[/color] $?[color=#000000];[/color] [color=#000080][b]fi[/b][/color]

[color=#ff0000][i]# Install the built modules to the staging dir.[/i][/color]
[color=#0000ff]make[/color] [color=#000000]-[/color]C [color=#000000]$KSOURCE_DIR[/color] ARCH[color=#000000]=[/color][color=#000000]$AR[/color] INSTALL_MOD_PATH[color=#000000]=[/color][color=#000000]$STAGING_DIR[/color][color=#000000]/[/color]system modules_install
[color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]return[/color] $?[color=#000000];[/color] [color=#000080][b]fi[/b][/color]

[color=#ff0000][i]# Remove symlinks.[/i][/color]
[color=#0000ff]rm[/color] [color=#000000]-[/color]v [color=#ddbb00]`find $STAGING_DIR -type l`[/color]
[color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]return[/color] $?[color=#000000];[/color] [color=#000080][b]fi[/b][/color]

[color=#ff0000][i]# Zip up the results. [/i][/color]
[color=#000080]cd[/color] [color=#000000]$STAGING_DIR[/color]
[color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]return[/color] $?[color=#000000];[/color] [color=#000080][b]fi[/b][/color]

[color=#0000ff]zip[/color] [color=#000000]-[/color]r [color=#000000]$OUTPUT_ZIP[/color] [color=#000000]*[/color]
[color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]return[/color] $?[color=#000000];[/color] [color=#000080][b]fi[/b][/color]

[color=#000080]cd[/color] [color=#000000]-[/color]
[color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]return[/color] $?[color=#000000];[/color] [color=#000080][b]fi[/b][/color]
[color=#000000]}[/color]

do_cleanup[color=#000000]()[/color]
[color=#000000]{[/color]
[color=#000080]echo[/color] [color=#ddbb00]"do_cleanup()"[/color]

[color=#0000ff]rm[/color] [color=#000000]-[/color]v [color=#000000]-[/color]r [color=#000000]$STAGING_DIR[/color]
[color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]return[/color] $?[color=#000000];[/color] [color=#000080][b]fi[/b][/color]
[color=#000000]}[/color]

[color=#000080][b]if[/b][/color] [color=#000000][ -[/color]z [color=#000000]$1[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]echo[/color] [color=#ddbb00]"Usage: $0 [source-dir]"[/color][color=#000000];[/color] [color=#000080]exit[/color] [color=#008800]1[/color][color=#000000];[/color] [color=#000080][b]fi[/b][/color]
do_compile[color=#000000];[/color] [color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]exit[/color] [color=#008800]1[/color][color=#000000];[/color] [color=#000080][b]fi[/b][/color]
do_staging[color=#000000];[/color] [color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] do_cleanup[color=#000000];[/color] [color=#000080]exit[/color] [color=#008800]1[/color][color=#000000];[/color] [color=#000080][b]fi[/b][/color]
do_populate[color=#000000];[/color] [color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] do_cleanup[color=#000000];[/color] [color=#000080]exit[/color] [color=#008800]1[/color][color=#000000];[/color] [color=#000080][b]fi[/b][/color]
do_cleanup[color=#000000];[/color] [color=#000080][b]if[/b][/color] [color=#000000][[/color] $? [color=#000000]-[/color]ne [color=#008800]0[/color] [color=#000000]];[/color] [color=#000080][b]then[/b][/color] [color=#000080]exit[/color] [color=#008800]1[/color][color=#000000];[/color] [color=#000080][b]fi[/b][/color]
[color=#000080]exit[/color] [color=#008800]0[/color]
[/size]