Friday, October 19, 2012

Compile Android Kernel

1. First thing is find out kernel version used for your device, assume you already downloaded the source from AOSP.

$ cd /android/android-2.3.6_r0.9/device/samsung/crespo

$ git log kernel
commit c85d206feeedd1ee1c69d0e0fe9e529897a5288b
Author: JP Abgrall <jpa@google.com>
Date:   Tue Aug 2 13:47:09 2011 -0700

    kernel + wifi update: gpu only
   
      21fb4cb gpu: pvr: Update to DDK 1.6.16.4131.1.1
   
    Change-Id: I9d728a27256486ba0d2e39211d06ef7f2ebeab6b
    Signed-off-by: JP Abgrall <jpa@google.com>

commit 7af59186753f2c08ed4123e0d2693d0e11f48410
Author: Simon Wilson <simonwilson@google.com>
Date:   Wed Jun 8 19:15:05 2011 -0700

    update kernel
   
    3cc95e3 net: Reorder incoming packets in PPPoLAC and PPPoPNS.
    3128bc4 jbd2: fix fsync() tid wraparound bug
   
    Change-Id: If6a22a320491d52ccbe6abb97acf5e97886fe144

commit 7643328cd8f7eabbf2fed86899b1758308bb747a
Author: JP Abgrall <jpa@google.com>
Date:   Thu May 26 19:50:48 2011 -0700

    Revert "Custom kernel with data-usage support and persistence."
   
    This reverts commit 6a0bcab7b1eb1ca53dd26127ed623e23eeff70a9.

commit 6a0bcab7b1eb1ca53dd26127ed623e23eeff70a9
Author: JP Abgrall <jpa@google.com>
Date:   Thu May 26 19:50:27 2011 -0700

    Custom kernel with data-usage support and persistence.
   
    This is for a one-time build of Gingerbread MR3.
    Not for release.
   
    This kernel is based on
      https://partner.source.android.com/g/gitweb?p=kernel%2Fprivate%2Fsamsung.git;a=shortlog;h=refs%2Fheads%2Fandroid-samsung-2.6.35-gingerbread
       at commit 807fb588280ee28833ea7838e6fa79b9b14f66c1
   
     with the needed iface_stat, udp, ... changes on top:
       https://review.source.android.com/#change,21605
       https://review.source.android.com/#change,21093
   
   
    Change-Id: I558a7f14258c3d6c497995880356bc5a4106de62
    Signed-off-by: JP Abgrall <jpa@google.com>

commit 830fe0120276f51fc9bf5872ff190bae6839eb4b
Author: Simon Wilson <simonwilson@google.com>
Date:   Thu May 26 16:28:34 2011 -0700

    update kernel
   
    807fb58 net: wimax: wimax_status mismatch fixed.
   
    Change-Id: Ide8950f3f5db57e25e4b0682e181c8cb95717cd4

commit 794ceba05495001fe2bf495b23a76acb5263da17
Author: Simon Wilson <simonwilson@google.com>
Date:   Wed May 25 14:47:58 2011 -0700

    update kernel


The log should contain notes of the commit SHA1 for the appropriate kernel project. Keep this value at hand so that you can use it in a later step.


2. Downloading sources

$ git clone https://android.googlesource.com/kernel/samsung.git
$ cd samsung/

Display the branch

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/android-samsung-2.6.35-gingerbread
  remotes/origin/android-samsung-3.0-ics-mr1
  remotes/origin/android-samsung-3.0-jb
  remotes/origin/master
$ git checkout -b android-samsung-2.6.35-gingerbread origin/android-samsung-2.6.35-gingerbread


Checking out files: 100% (33879/33879), done.
Branch android-samsung-2.6.35-gingerbread set up to track remote branch android-samsung-2.6.35-gingerbread from origin.
Switched to a new branch 'android-samsung-2.6.35-gingerbread'


3. Assume Android-NDK is installed , if not please refer to NDK install page.

4. Setup Env

$export PATH=<android source>/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH
$export ARCH=arm
$export SUBARCH=arm
$export CROSS_COMPILE=arm-eabi-


4. Setup default config

$ make herring_defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/docproc
  HOSTCC  scripts/basic/hash
  HOSTCC  scripts/kconfig/conf.o
scripts/kconfig/conf.c: In function ‘conf_sym’:
scripts/kconfig/conf.c:159:6: warning: variable ‘type’ set but not used [-Wunused-but-set-variable]
scripts/kconfig/conf.c: In function ‘conf_choice’:
scripts/kconfig/conf.c:231:6: warning: variable ‘type’ set but not used [-Wunused-but-set-variable]
scripts/kconfig/conf.c:307:9: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
scripts/kconfig/conf.c: In function ‘conf_askvalue’:
scripts/kconfig/conf.c:105:8: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
  HOSTCC  scripts/kconfig/kxgettext.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
arch/arm/configs/herring_defconfig:323:warning: override: reassigning to symbol LOCALVERSION_AUTO
arch/arm/configs/herring_defconfig:333:warning: override: reassigning to symbol NET_ACTIVITY_STATS
#
# configuration written to .config
#





5. Compile
$ make -j4
.........

  CC      arch/arm/boot/compressed/decompress.o
  SHIPPED arch/arm/boot/compressed/lib1funcs.S
  AS      arch/arm/boot/compressed/lib1funcs.o
  CC      crypto/ansi_cprng.mod.o
  CC      drivers/net/wireless/bcm4329/bcm4329.mod.o
  CC      drivers/scsi/scsi_wait_scan.mod.o
  LD [M]  crypto/ansi_cprng.ko
  LD [M]  drivers/net/wireless/bcm4329/bcm4329.ko
  LD [M]  drivers/scsi/scsi_wait_scan.ko
  AS      arch/arm/boot/compressed/piggy.gzip.o
  LD      arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready

 $ cp arch/arm/boot/zImage ../../../android/android-2.3.6_r0.9/device/samsung/crespo/kernel

6. Flash to device....
$ cd <android src>
$ make -j4
$ fastboot flash -w