본문 바로가기

Embedded/Android Phone

[GT-I9082] 4.Kernel build

1. Install ubuntu 12.04 or 14.04.1

How to Install Ubuntu 13 10 (Saucy Salamander) in Virtual Box A Step By Step Tutorial


2. Setting up building environment


JAVA 6 Install

sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java6-installer


Installing required packages


Android 12.04

sudo apt-get install git-core gnupg ccache lzop flex bison gperf build-essential zip curl zlib1g-dev \ zlib1g-dev:i386 libc6-dev lib32ncurses5 lib32z1 lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev \ libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib \ mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 \ lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev \ libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev \ libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python $ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so


Android 14.04.1

sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2 bin86 qt4-dev-tools wget libncurses5 git-core nautilus-open-terminal


curl Install

sudo apt-get install curl


Installing Repo

$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo


Installing toolchain

$ mkdir toolchains
$ cd toolchains
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6


Add arm toolchain to path

open bashrc

$ vi ~/.bashrc

add toolchain path

export CROSS_COMPILE=arm-eabi-
export ARCH=arm
PATH=$PATH:/home/user/toolchains/arm-eabi-4.6/bin

update path

$ source ~/.bashrc


test path

$ arm-eabi-gcc --version
arm-eabi-gcc (GCC) 4.6.x-google 20120106 (prerelease)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


3. Getting the kernel source and Compile


Getting the kernel source

git clone https://github.com/pawitp/android_device_samsung_i9082.git -b cm-11.0
$ git clone https://github.com/pawitp/android_kernel_samsung_i9082.git -b cm-11.0

Compiling kernel

make distclean
$ make cyanogenmod_i9082_defconfig
$ make -j4


4. Crafting an Android boot.img


Prepare mkbootimage and unmkbootimg


Download mkbootimage

$ git clone https://android.googlesource.com/platform/system/core bootimg-tools


compile mkbootimage

$ cd bootimg-tools
$ cd libmincrypt/
$ gcc -c *.c -I../include
$ ar rcs libmincrypt.a *.o
$ cd ../mkbootimg
$ gcc mkbootimg.c -o mkbootimg -I../include ../libmincrypt/libmincrypt.a
$ cd ../cpio
$ gcc mkbootfs.c  -o mkbootfs -I../include


Download unmkbootimg

$ wget https://github.com/pbatard/bootimg-tools/archive/master.zip
$ unzip master.zip
$ cd bootimg-tools-master/mkbootimg/


compile unmkbootimg

$ gcc -o unmkbootimg unmkbootimg.c



5. 컴파일된 kernel을 bootimg에 추가하기


① 다운받은 CM11 ROM(cm-11-20140917-UNOFFICIAL-i9082.zip)을 Archive Manager로 열면 boot.img파일이 있습니다.



② boot.img 파일을 특정 폴더에 압축해제 합니다.


③ 컴파일된 unmkbootimg와 mkbootimg파일을 같은 폴더로 복사합니다.


④ unmkbootimg을 이용하여 boot.img 압축을 해제합니다.

    압축해제하면 kernel, ramdisk.cpio.gz 2개의 파일 생성됩니다.

$ ./unmkbootimg -i boot.img

kernel written to 'kernel' (4760360 bytes)
ramdisk written to 'ramdisk.cpio.gz' (556218 bytes)

To rebuild this boot image, you can use the command:
  mkbootimg --base 0 --pagesize 4096 --kernel_offset 0xa2008000 --ramdisk_offset 0xa3000000 --second_offset 0xa2f00000 --tags_offset 0xa2000100 --cmdline 'console=ttyS0,115200n8 mem=832M@0xA2000000 androidboot.console=ttyS0 vc-cma-mem=0/176M@0xCB000000' --kernel kernel --ramdisk ramdisk.cpio.gz -o boot.img


⑤ 압축해제시 "To rebuild this boot image, you can use the command:..." 메세지를 이용하여 

    boot.img파일을 만들기 때문에 다른 곳에 꼭 기록해 두셔야 합니다.


⑥ 위에서 컴파일한 커널 이미지 파일 zImage는 kernel source path 아래의 arch/arm/boot/폴더에 존재합니다.

    zImage을 boot.img파일이 존재하는 폴더로 복사합니다.


⑦ mkbootimg 파일을 이용하여 boot.img파이을 생성합니다.


$ ./mkbootimg --base 0 --pagesize 4096 --kernel_offset 0xa2008000 --ramdisk_offset 0xa3000000 --second_offset 0xa2f00000 --tags_offset 0xa2000100 --cmdline 'console=ttyS0,115200n8 mem=832M@0xA2000000 androidboot.console=ttyS0 vc-cma-mem=0/176M@0xCB000000' --kernel zImage --ramdisk ramdisk.cpio.gz -o boot.img

위의 mkbootimg 명령어중에서 붉은색 zImage 텍스트가 위에서 컴파일한 커널 이미지를 사용하여 boot.img파일을

만든다는 것입니다.


⑧ Archive Manager를 이용하여 cm-11-20140917-UNOFFICIAL-i9082.zip 압축파일의 boot.img을 삭제하고 새로운 boot.img를 추가합니다.


⑨ cm-11-20140917-UNOFFICIAL-i9082.zip파일을 폰의 sdcard에 복사한 후 업데이트 하면 됩니다.


자료출처:

[GUIDE][TUT]Building a kernel from source[EASY WAY]

[Guide] How to build kernel from source on ubuntu 13.10...