Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
blackSwanBB
Old
(Last edited by blackSwanBB; 21st January 2011 at 06:19 PM.) Reason: Added step to replace the original bcm4329 kernel module.
#1  
Junior Member - OP
Thanks Meter 16
Posts: 15
Join Date: Dec 2010
Post [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
The Following 16 Users Say Thank You to blackSwanBB For This Useful Post: [ Click to Expand ]
 
jmdearras
Old
#2  
Senior Member
Thanks Meter 14
Posts: 371
Join Date: Aug 2008
Location: RIchmond, Virginia
Thanks! I appreciate this. Time to start hacking, again.
 
tonm156
Old
#3  
Member
Thanks Meter 0
Posts: 39
Join Date: Nov 2008
Location: Collegeville, PA
Very nice and thanks for sharing the knowledge. Can't wait to try it out.

Sent from my DROIDX using XDA App
Phone: Galaxy Nexus
ROM: GummyNex 0.6.6
Kernel: Minimalistic Kernel 1.7.1

Tablet: Samsung Galaxy Tab 10.1
ROM: GALAXY TASK 13.1 Slim
Kernel: Pershoot 2.6.36.4 - OC-VFPv3-d16_FP
 
roebeet
Old
#4  
roebeet's Avatar
Senior Member
Thanks Meter 1402
Posts: 3,472
Join Date: Jul 2010
Location: Pennsylvania
This is exactly the type of HOWTO I was looking for. Many thanks!!
Android devices: ASUS Transformer, Notion Ink Adam, Cowon D3
 
blackSwanBB
Old
#5  
Junior Member - OP
Thanks Meter 16
Posts: 15
Join Date: Dec 2010
Quote:
Originally Posted by roebeet View Post
This is exactly the type of HOWTO I was looking for. Many thanks!!
Many thanks to you roebeet! I just wanted to give back to the community which has given me so much.
 
browner
Old
#6  
Junior Member
Thanks Meter 0
Posts: 6
Join Date: Jan 2011
Great instructions but I think you are missing one thing. In staging/system/lib/hw/wlan/bcm4329.ko it is the original .ko from the boot-template.zip file.
I think you need to move and rename kernel/drivers/net/wireless/bcm4329/dhd.ko and use it to overwrite bcm4329.ko. I haven't tried it yet but that's my theory.
 
dblanketyblank
Old
#7  
Junior Member
Thanks Meter 0
Posts: 11
Join Date: Jan 2011
If this is intermediate tutorial is there something more basic? I'm interested in learning more, but not sure where to start.
 
kornyone
Old
(Last edited by kornyone; 21st January 2011 at 04:55 AM.)
#8  
kornyone's Avatar
Recognized Developer
Thanks Meter 664
Posts: 171
Join Date: Aug 2008
Location: Austin, TX

 
DONATE TO ME
Thanks a bunch to Pershoot, Koush, and yourself for the hard work and documentation.
 
blackSwanBB
Old
#9  
Junior Member - OP
Thanks Meter 16
Posts: 15
Join Date: Dec 2010
Quote:
Originally Posted by dblanketyblank View Post
If this is intermediate tutorial is there something more basic? I'm interested in learning more, but not sure where to start.
Is there a certain step that alludes you, or where you taking aback due to the guide being labeled as an "intermediate tutorial"?

How well do you understand computers and linux?
Do you know anything about computer programming?
What sort of things do you want to learn more about?
 
blackSwanBB
Old
#10  
Junior Member - OP
Thanks Meter 16
Posts: 15
Join Date: Dec 2010
Quote:
Originally Posted by browner View Post
Great instructions but I think you are missing one thing. In staging/system/lib/hw/wlan/bcm4329.ko it is the original .ko from the boot-template.zip file.
I think you need to move and rename kernel/drivers/net/wireless/bcm4329/dhd.ko and use it to overwrite bcm4329.ko. I haven't tried it yet but that's my theory.

I agree that to utilize the bcm4329 module which was compiled during the "make modules" step that you would need to replace the bcm4329.ko from the boot-template.

I haven't done much analysis of this yet, but my assumption is that the rom knows to explicitly load that module. A quick vbindiff shows that the bcm4329.ko (from the latest pershoot release) and the dhd.ko (built from pershoot's git repository) are not identical.

As such, I did not include a step to explicitly remove the bcm4329 kernel module from the boot-template.

I do however, recommend that you pull the latest pershoot release and update the boot-template.zip or wget the latest copy of pershoot's release and use it as the boot-template.zip (I didn't want to have to update the tutorial with each pershoot release to reference the latest package, so I referenced his first release).

I'll research this a bit more this weekend so I have a better understanding. If you want to test out the dhd.ko you should be able to use adb to rmmod bcm4329 and insmod the dhd.ko.

See this thread: http://forum.xda-developers.com/showthread.php?t=906628

 
Post Reply+
Tags
compile configure kernel
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...