[GUIDE] Compiling and Installing Custom Kernel (based on pershoot's Kernel from git)
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.
Code:
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".
Code:
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.
Code:
usermod -a -G src `whoami`
sudo reboot
Retrieve the prebuilt android toolchain.
Code:
git clone git://android.git.kernel.org/platform/prebuilt.git
Clone pershoot's "Gtablet Kernel 2.6.32" source repository.
Code:
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.
Code:
/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:
Code:
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:
Code:
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.
Code:
vi /usr/src/tegratab/gtab-2632/.config
2. Create your own defconfig file and manually edit it.
Code:
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.
Code:
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.
Code:
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.
Code:
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):
Code:
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):
Code:
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://forum.xda-developers.com/showthread.php?t=892090
HOWTO: Unpack, Edit, and Re-Pack Boot Images)
http://android-dls.com/wiki/index.ph...ck_Boot_Images
Building Android kernel images)
http://www.cianer.com/androidg1/28-b...-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:
Code:
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:
Code:
mkdir /usr/src/tegratab/staging
Unzip the boot template here:
Code:
unzip -d /usr/src/tegratab/staging /usr/src/tegratab/boot-template.zip
Copy the kernel image which was built to this staging directory:
Code:
cp -v /usr/src/tegratab/gtab-2632/arch/arm/boot/zImage /usr/src/tegratab/staging/kernel/zImage
Install the kernel modules which were built:
Code:
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:
Code:
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:
Code:
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:
Code:
cd /usr/src/tegratab/staging
zip -r /usr/src/tegratab/boot-custom-kernel *
[optional]Cleanup the staging directory:
Code:
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:
Code:
-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:
Code:
AR=arm
if [ -n "$1" ] && [ -n "$2" ]
then
make -C $1 ARCH=$AR $2 menuconfig
else
echo "Usage: $0 [source-dir] [defconfig]"
fi
Kernel Compilation / Packing Script:
Code:
#!/bin/sh
CC=/usr/src/tegratab/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
AR=arm
PREFIX=`echo $1 | sed -e 's/[/]*$//' -e 's/[/]/_/'`
POSTFIX=`date +%Y_%m_%e_%H%M%S`
KSOURCE_DIR=$1
TARGET_NAME=$PREFIX-$POSTFIX
SAMPLE_ZIP=/usr/src/tegratab/boot-template.zip
OUTPUT_ZIP=/usr/src/tegratab/$TARGET_NAME
STAGING_DIR=/tmp/$TARGET_NAME
do_compile()
{
echo "do_compile()"
# Build the kernel image.
make -C $KSOURCE_DIR ARCH=$AR CROSS_COMPILE=$CC zImage
if [ $? -ne 0 ]; then return $?; fi
# Build the kernel modules.
make -C $KSOURCE_DIR ARCH=$AR CROSS_COMPILE=$CC modules
if [ $? -ne 0 ]; then return $?; fi
}
do_staging()
{
echo "do_staging()"
# Unzip the sample update zip to create update structure
# and provide update scripts / utilities.
unzip -d $STAGING_DIR $SAMPLE_ZIP
if [ $? -ne 0 ]; then return $?; fi
}
do_populate()
{
echo "do_populate()"
# Copy the resulting image to the staging dir.
cp -v $KSOURCE_DIR/arch/$AR/boot/zImage $STAGING_DIR/kernel/
if [ $? -ne 0 ]; then return $?; fi
# Install the built modules to the staging dir.
make -C $KSOURCE_DIR ARCH=$AR INSTALL_MOD_PATH=$STAGING_DIR/system modules_install
if [ $? -ne 0 ]; then return $?; fi
# Remove symlinks.
rm -v `find $STAGING_DIR -type l`
if [ $? -ne 0 ]; then return $?; fi
# Zip up the results.
cd $STAGING_DIR
if [ $? -ne 0 ]; then return $?; fi
zip -r $OUTPUT_ZIP *
if [ $? -ne 0 ]; then return $?; fi
cd -
if [ $? -ne 0 ]; then return $?; fi
}
do_cleanup()
{
echo "do_cleanup()"
rm -v -r $STAGING_DIR
if [ $? -ne 0 ]; then return $?; fi
}
if [ -z $1 ]; then echo "Usage: $0 [source-dir]"; exit 1; fi
do_compile; if [ $? -ne 0 ]; then exit 1; fi
do_staging; if [ $? -ne 0 ]; then do_cleanup; exit 1; fi
do_populate; if [ $? -ne 0 ]; then do_cleanup; exit 1; fi
do_cleanup; if [ $? -ne 0 ]; then exit 1; fi
exit 0