Fourth chapter source code download and compile

Source: Internet
Author: User

Android porting is primarily the porting of the Linux kernel, and the Linux kernel porting is primarily a Linux-powered migration. To develop and test Linux drivers, two sets of development environments are built under Ubuntu Linux: the Android application development environment and the Linux kernel development environment. Need to download and compile the source code, because the Android source code contains a lot of things, such as embedded in the Android system of the source code of the application, the Android SDK with the various tools of the source code, the Android NDK source code, as well as the HAL source code, Therefore, the download, compilation and testing of the Android source code is more complicated and cumbersome, here is the relatively simple download and compilation of the Linux kernel source code methods and procedures.

The downloaded Android source code does not contain the Linux kernel source code, if you want to use the Linux kernel, you must download the Linux kernel source code separately, you must download the Linux kernel source code used in Android from the URL provided by Google.

1. Download the Linux kernel source code: Execute the command "# git clone https://android.googlesource.com/kernel/common,git" to download the latest Linux kernel source code, the download will take a long time. After the download is complete, there will be a common directory under the current directory, enter the directory, and execute the command "# git branch-a" to see which remote repositories are currently available. To export the latest Linux kernel from the repository according to the version, you can use the command "# git checkout-b android-3.0 remotes/origin/android-3.0" To export the Linux 3.0 kernel. Google provides a Linux kernel goldfish for the Android emulator, which can be used with the command "# git clone http://android.googlesource.com/kernel/goldfish.git" Download the kernel. After the download is complete, go to the Goldfish directory and execute the command "# git checkout-b android-goldfish-2.6.29 remotes/origin/android-goldfish-2.6.29" to export goldfish.

The directory structure of the 2.Linux kernel source code, there are many directories such as Arch,block,documentation,drivers,firmware,fs,include.

3. Install the Android kernel's build environment: compiling the Linux kernel under Ubuntu Linux requires the installation of a cross-compiler. A cross-compiler is a program that compiles on the CPU of a architecture to run on a B-schema CPU. This is mainly because the compiler is unable to install on the target platform or the target platform has low performance, and is forced to compile on platforms with a higher performance limit. Before compiling the Linux kernel, you need to configure the makefile file under the root directory of the Linux kernel source code. Open makefile, find arch and cross_compile, and set these two variables to the following values "arch? = Arm

Cross_compile?= arm-none-linux-gnueabi-", where the arch variable means that the Linux source code is compiled into a Linux kernel that can run on an arm architecture. The cross_compile variable represents the prefix of the cross compiler. Open the Cross compiler's Bin directory, you can see a lot of commands that start with arm-none-linux-gnueabi-, such as ARM-NONE-LINUX-GNUEABI-GCC, Arm-none-linux-gnueabi-gdb, and so on. Because compiling the Linux kernel may use many of these commands, for convenience, the Linux kernel allows values to only set the prefix of these commands, and the corresponding compilation commands can be found. The steps for installing the cross compiler are as follows:

① Preparation: Copy arm-linux-gcc-4.3.2.tgz files and arm-none-linux-gnueabi-arm-2008q3-72-for-linux.tar.bz2 files to your working directory

② decompression compiler: Using commands

"# Tar ZXVF arm-linux-gcc-4.3.2.tgz-c/

# tar jxvf arm-none-linux-gnueabi-arm-2008q3-72-for-linux.tar.bz2-c/"

Unzip two compressed files

③ Verify that the cross compiler is successfully installed, use the command "# ls/usr/local/arm-l" ④ to install LIBNCURSES5, in order to configure the kernel make menuconfig, LIBNCURSES5 can provide a beautiful interface for the Linux terminal of the character interface, using the command "# apt-get install Libncurses5-dev"

4. Configure and compile the Linux kernel: if the kernel source code directory is "/root/linux_kernel", use the command

"# Export Path=/root/compilers/arm-none-linux-gnueabi/bin: $PATH

# CD ~/linux_kernel

# Make Clean

# make "

Compiling the Linux kernel, the make clean command is used to purge files that are mostly read-generated by the. O,. Ko, etc., but retain the configuration file. Generally, the new downloaded Linux source root directory does not have a. config file, and this file determines which functions and modules are composed of the Linux kernel that the build is compiled from. The first time you get the Linux kernel, you should first use one of the 4 commands to configure the Linux kernel to produce a. config file at the root of the Linux kernel source code. Before configuring the Linux kernel, it is generally necessary to determine your own requirements, what driver modules are required, whether debugging is supported, which CPU types are supported, and so on. 4 configuration commands must be executed at the root of the Linux source code.

①make Config: This command configures the Linux kernel in textual form. The value in parentheses after the configuration item is the current value of the configuration item, if there are multiple values in brackets, the first is the default value, and if not set, the default value is retained by pressing ENTER directly.

②make Menuconfig: Configures the Linux kernel in a character-interface-style menu. The menu item description with a "--" after the configuration interface also has a submenu. Press the ENTER key to enter the sub-menu. Many menu items are preceded by brackets, which can be either "M" or "*" or empty. You can only set "*" or empty in parentheses before the menu item. The value in brackets indicates how the Linux kernel component of the current menu item is embedded in the Linux kernel. [M] indicates that the. ko file is dynamically installed in the Linux kernel in the form of a module. [Y] means that the Linux kernel component is embedded in the Linux kernel. When the Linux kernel starts successfully, these components are loaded automatically. If NULL indicates that the Linux kernel component is not included in the current Linux kernel. By pressing the "M" key you can set the value in brackets to "M", and press "Y" to set the value in brackets to "Y". Press the SPACEBAR to toggle between [M], [Y], and white space. Finally, after exiting the setup interface via exit, if you modify the settings, you will be asked if you want to keep the settings. If you select Yes, the. config file is regenerated based on the settings you just made.

③make Oldconfig: Similar to make config, the user configuration is also requested by the character interface. However, it shows fewer configuration items that require users to participate than make CONFIG. Most configuration items will give default values and do not require user configuration. Only configuration items with new in the back require user configuration, which are newly added features of the current Linux kernel version.

④make xconfig: Configure the Linux kernel as a graphical interface, using the shared library of QT, to execute this command, you must install QT, you can use the command "# apt-get install Libqt4-dev". After Qt is installed, perform make xconfig. In the interface, you can save the settings from the Save installation above, or you can use the Open button to open other profiles. One important thing in configuration is the cross-compiler signature. Use the Make Menuconfig command. Once the Linux kernel is successfully compiled, a zimage file is generated in the <linux kernel source root directory >/arch/arm/boot directory. This file is the binary version of the Linux kernel. Can be installed directly on the board using Zimage, or you can use the command "# EMULATOR-AVD Myavd-kernel/root/kernel/goldfish/arch/arm/boot/zimage" Testing the Linux kernel in the Android emulator requires the use of a zimage file compiled by goldfish, MYAVD is an AVD name.

Fourth chapter source code download and compile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.