Android kernel compilation graphic tutorial

Reprint: http://www.miui.com/thread-683503-1-1.html

 

Step 0 Compilation preparation
First, the following environment for compiling the kernel is introduced.
Host: Ubuntu 11.04 (32bit)
Target: HTC Desire HD (G10) Installation system HTC official system 2.3 (kernel version 2.6.35)
need to download files:
1> Android source code (only for HTC)
http://www.htcdev. com/devcenter/downloads
1. Select Desire HD -- Carrier -- Region -- v2.3
2. Desire HD N/AN /A MR 2.6.35 v2.3 89.6 MB
3. Click to download

2> Cross compilation tool:
http ://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi/arm-2008q3-41-arm-none-linux-gnueabi.bin

Step 1 Install the cross toolchain
and enter the cross compilation directory you just downloaded , execute the following command
$ chmod a+x arm-2008q3-41-arm-none-linux-gnueabi.bin
$ ./arm-2008q3-41-arm-none-linux-gnueabi.bin
-------- ------------------------------------------------
Explained here Now, since installing the cross-compilation chain requires a dash shell (Ubuntu default)
If you made changes before, you need to switch back and
use the command:
$ sudo dpkg-reconfigure -plow dash
   Install as /bin/sh? No
---------------------- -----------------------------------


Enter the installation, it is more foolish, Next can go down, but to Remember the following installation directory, the third step is to

download the Android source code and decompress it when configuring the cross-compilation tool of the Makefile in the third step
: http://www.htcdev.com/devcenter/downloads
$ tar zxvf ace-2.6.35-gb -MR.tar.gz
to get the directory ace-2.6.35-gb-MR
(remember this directory, steps 3 and 5 are required)
Note that after modifying the Makefile (step 3), execute make (step 5) Do it in this directory.

Step 3 Configure the cross-compilation tool in the Makefile.
Since the directory where I installed the cross-compilation tool in the first step is /home/XXX/
, I enter the source code directory, which is the address of the decompression in the second step.
$ vim Makefile
Modify Makefile 193 line, it becomes (note that the last character is - oh)
CROSS_COMPILE ?= /home/XXX/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-
If there is no line 193, you can: /CROSS_COMPILE quick positioning


Step 4 Extract the confg.gz file.
This step needs to enter the shell of the real machine through adb. The specific steps are as follows (if you have already used the real machine to debug, it will be skipped automatically)
---------- -----The dividing line of step 4 starts -----------------
1. Do not plug in the mobile phone
$ lsusb to
observe the results

2. Plug in the mobile phone
$ lsusb
and observe the results
again One more line,

Bus 002 Device 004: ID 0bb4:0ca2 High Tech Computer Corp.
Yes, this is the information of your machine. Note the two-segment value after the ID below.

3. Write the following information
in /etc/udev/rules.d/70-android.rules SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0ca2"

$ sudo vim /etc/udev /rules.d/70-android.rules
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0ca2"
:wq
$ sudo chmod a+rx /etc/udev/rules.d/70 -android.rules


4.


$ cd ~/androidworkspace/android-sdk-linux/platform-tools
$ sudo service udev restart
$ sudo ./adb kill-server
$ ./adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
HC0CVRX02200 device

We found that the device has been found, which means that adb is available.
Maybe students who have developed applications on Android and have used real machine debugging may be familiar with the above process.
--------------- End of dividing line for step 4 ----------------- -
well, if adb works, then It's easy to do

It can be coquettish in the shell.
# ./adb shell
# ls
We can find a directory called proc
# cd proc
# ls | grep config.gz
We found a file called config.gz, this is the file we need to extract in step 4.
ctrl+c to exit, or enter exit.

Last step,
$ ./adb pull /proc/config.gz
At this time, you will find that in the current directory, there is a file called config.gz

$ gunzip config.gz

If you find a file called config in the current directory, congratulations, the extraction is successful.

Step 5 Add config to the kernel source directory, and compile the kernel.

This step is still in the directory where adb is located.
$ mv ./config.gz XXXX/ace-2.6.35-gb-MR/.config
$ ls -a
You can ls -a Check to see if the copying of .config is completed
(the directory after the first command is of course the source directory. In step 2, I will tell you to remember it...
Explain that ./config.gz refers to the config in the current directory .gz file, and .config is equivalent to the file name is called .config, don’t be too entangled)
make
after about 10 minutes (this is related to your computer, in theory, the more cores, the higher the memory, the faster the compilation)
successfully . The following message will prompt
  Kernel: arch/arm/boot/Image is ready
  SHIPPED arch/arm/boot/compressed/lib1funcs.S
  AS arch/arm/boot/compressed/lib1funcs.o
  LD arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready

You're done! congratulations!

Step 6 KO is
completed, write a summary, or share this article with other compatriots!
---------------------
To sum up, what we did.
Let's make an assumption that if all the environments have been configured, then just download the source code -> enter the source code directory -> make is ok, but why do you need to do so many steps?
The first is to cross-compile
the source code. Since your machine is x86, and the architecture of your mobile phone is arm, you need to cross-compile
(to make an image analogy, I don’t know if it is appropriate, that is, the computer will say something called X86 language, and the mobile phone can speak a language called arm, they need a translation, this translation is a cross-compilation tool )
The second is the .config file
      , because a .config file is needed when compiling, in fact, you can do without this file at all , execute make menuconfig to configure the kernel compilation options. However, those kernel configurations are too cumbersome, so we can get them in through the existing .config files. Where do we come from? Of course, it has been flashed to the ROM in the phone. Therefore, we can summarize it as the following steps,
download the source code -> enter the source code directory -> get
.
----------------------
Innovation, Share, Growth.
Let's work hard and make progress together!
My Name is Kero.

Screenshot-1.png (54.01 KB, Downloads: 4)

 

Screenshot-1.png

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326434632&siteId=291194637