Andorid system configuration and compilation process

Source: Internet
Author: User

The android system is hitting the smartphone and tablet markets with a burst of ears. It revolutionizes the concept of traditional mobile phones and shuffled mobile phones and tablets, the most valuable thing is that his openness (although not completely open) has attracted a large number of engineers to transform it and improve it. Anyone can download its source code to see its true nature. This section describes how to configure an android system from the ground up. We will not talk about how to obtain the android source code here. This article is based on the assumption that you have obtained the source code from the android official website.
1. Create a company directory in // vendor /.
Mkdir vendor/<company_name>
In this step, we first create a directory under the vendor (supplier) and name it with your company name. If there is no company, just compile it (:
2. Create a products directory beneath the company directory you created in step 1.
Mkdir vendor/<company_name>/products/
Create a directory with the name of your product.
3. Create a product-specific makefile, called vendor/<company_name>/products/<first_product_name>. mk, that between des at least the following code:
$ (Call inherit-product, $ (SRC_TARGET_DIR)/product/generic. mk)
#
# Overrides
PRODUCT_NAME: = <first_product_name>
PRODUCT_DEVICE: = <board_name>

Create an mk file in the/products/directory. The content format is as follows:
 
$ (Call inherit-product, $ (SRC_TARGET_DIR)/product/generic. mk)

# Overrides
PRODUCT_MANUFACTURER: = FriendlyARM
PRODUCT_BRAND: = FriendlyARM
PRODUCT_NAME: = mini6410
PRODUCT_DEVICE: = mini6410
**************************************** ***********
The path of mini6410.mk is/Android-2.2/vendor/friendly-arm/products/mini6410.mk l, which also verifies the preceding steps 1 and 2.

4. Add an optional definition to the *. mk File above.
5. In the products directory, create an AndroidProducts. mk file that point to (and is responsible for finding) the individual product make files.
#
# This file shoshould set PRODUCT_MAKEFILES to a list of product makefiles
# To expose to the build system. LOCAL_DIR will already be set
# The directory containing this file.
#
# This file may not rely on the value of any variable other
# LOCAL_DIR; do not use any conditionals, and do not look up
# Value of any variable that isn' t set in this file or in a file that
# It nodes.
#

PRODUCT_MAKEFILES: =/
$ (LOCAL_DIR)/first_product_name.mk/
Follow this template.
6. create a board-specific directory beneath your company directory that matches the PRODUCT_DEVICE variable <board_name> referenced in the product-specific make file above. this will include a make file that gets accessed by any product using this board.
Mkdir vendor/<company_name>/<board_name>

Add a directory under your company's directory named the name of the Board, for example, Android-2.2/vendor/friendly-arm/mini6410, where mini6410 is the name of the Development Board, files in this directory are important. Next, let's use the mini6410 example for a better description.
7. Create the BoardConfig. mk file in the Android-2.2/vendor/friendly-arm/mini6410 directory.
First, let's take a look at the content of this file:

[Cpp]
# Config. mk
#
# Product-specific compile-time definitions.
#
 
# The generic product target doesn' t have any hardware-specific pieces.
TARGET_CPU_ABI: = armeabi
TARGET_NO_BOOTLOADER: = true
TARGET_NO_KERNEL: = true
TARGET_PROVIDES_INIT_RC: = true
 
# Customized map
TARGET_PRELINKER_MAP: = vendor/friendly-arm/products/prelink-linux-arm-FA.map
 
# Hardware 3D
TARGET_HARDWARE_3D: = false
 
# Audio
BOARD_USES_ALSA_AUDIO: = true
BUILD_WITH_ALSA_UTILS: = true
 
# Camera
BOARD_CAMERA_LIBRARIES: = libcamera
Board_initiate_libraries: = lib89cjpeg
 
# Wi-Fi
BOARD_HAVE_LIBWIFI: = true
# BOARD_WPA_SUPPLICANT_DRIVER: = WEXT
BOARD_WPA_SUPPLICANT_DRIVER: = CUSTOM
# CONFIG_DRIVER_NL80211: = true
WPA_BUILD_SUPPLICANT: = true
# WPA_SUPPLICANT_VERSION: = VER_0_6_X
CONFIG_CTRL_IFACE: = y
 
# Bluetooth
BOARD_HAVE_BLUETOOTH: = true
 
# GPS
BOARD_GPS_LIBRARIES: = libgps
BoardConfig. what is the mk file? From the above example code, you may be able to guess, BoardConfig. mk is used to customize the functions of your device, such as whether camera or GPS navigation is supported. This file is an important custom file in the android system.
8. Modify system attributes.
This item is not required, but in most cases, we need to modify system attributes in deep customization of the system.
How to modify it? Create a system. prop file under/Android-2.2/vendor/friendly-arm/mini6410/, as shown in the following figure:
# System. prop
# This overrides settings in the products/generic/system. prop file
#
# Rild. libpath =/system/lib/libreference-ril.so
# Rild. libargs =-d/dev/ttyS0
9. Add the AndroidProducts. mk file to/Android-2.2/vendor/friendly-arm/products. This file can contain multiple board_name.mk files, that is, multiple devices. The Code is as follows:
PRODUCT_MAKEFILES: =/
$ (LOCAL_DIR)/first_product_name.mk/
$ (LOCAL_DIR)/second_product_name.mk
10. Add the Android. mk file under/Android-2.2/vendor/friendly-arm/mini6410. The file contains at least the following content:
[Cpp] view plaincopy
# Make file for new hardware from
#
LOCAL_PATH: = $ (call my-dir)
#
# This is here to use the pre-built kernel
Ifeq ($ (TARGET_PREBUILT_KERNEL ),)
TARGET_PREBUILT_KERNEL: = $ (LOCAL_PATH)/kernel
Endif
#
File: =$ (INSTALLED_KERNEL_TARGET)
ALL_PREBUILT + = $ (file)
$ (File): $ (TARGET_PREBUILT_KERNEL) | $ (ACP)
$ (Transform-prebuilt-to-target)
#
# No boot loader, so we don't need any of that stuff ..
#
LOCAL_PATH: = vendor/<company_name>/<board_name>
#
Include $ (CLEAR_VARS)
#
# Include more board specific stuff here? Such as Audio parameters.

So far, the preliminary customization is basically complete. The architecture of this configuration is shown in:
 
Android organizes components in various systems in the form of modules. Eng's professional vocabulary is Module, which is the Android. mk that you can see in almost every directory. You can simply divide all Make files in Android into four types:
1. For config
This type of file mainly configures the product and board, and selects the corresponding tool based on your Host and Target, and sets the corresponding General Compilation options:
Build/core/config. mk summary of config
Build/core/envsetup. mk generate dir config and so on
Build/target/product config
Build/target/board config
Build/core/combo build flags config
Here we will explain the board and product here. Borad is mainly designed for hardware chip configurations, such as whether to provide certain hardware functions, such as GPU, or whether the chip supports floating point operations. Product is a pointer to the current chip configuration. It defines the personalized configuration of the product to be produced. It mainly refers to the APK configuration and the product to which the APK will be included, which APK is not provided in the current product.
Config. mk is a general concept that defines the HOST tools required for module compilation and how to compile various modules. For example, BUILT_PREBUILT defines how to compile the pre-compilation module. Envsetup. mk mainly reads some variables written by envsetup. sh to the environment variables to configure the output directory during the compilation process. combo mainly defines the compiler and compilation options that combine Host and Target.
2. Module Compile
This type of file mainly defines how to process the Android. mk Module and how to generate the target Module. The generation rules of these modules are defined in config. mk. Let's take a look:
CLEAR_VARS: = $ (BUILD_SYSTEM)/clear_vars.mk
BUILD_HOST_STATIC_LIBRARY: = $ (BUILD_SYSTEM)/host_static_library.mk
BUILD_HOST_SHARED_LIBRARY: = $ (BUILD_SYSTEM)/host_shared_library.mk
BUILD_STATIC_LIBRARY: = $ (BUILD_SYSTEM)/static_library.mk
BUILD_RAW_STATIC_LIBRARY: = $ (BUILD_SYSTEM)/raw_static_library.mk
BUILD_SHARED_LIBRARY: = $ (BUILD_SYSTEM)/shared_library.mk
BUILD_EXECUTABLE: = $ (BUILD_SYSTEM)/executable. mk
BUILD_RAW_EXECUTABLE: = $ (BUILD_SYSTEM)/raw_executable.mk
BUILD_HOST_EXECUTABLE: = $ (BUILD_SYSTEM)/host_executable.mk
BUILD_PACKAGE: = $ (BUILD_SYSTEM)/package. mk
BUILD_HOST_PREBUILT: = $ (BUILD_SYSTEM)/host_prebuilt.mk
BUILD_PREBUILT: = $ (BUILD_SYSTEM)/prebuilt. mk
BUILD_MULTI_PREBUILT: = $ (BUILD_SYSTEM)/multi_prebuilt.mk
BUILD_JAVA_LIBRARY: = $ (BUILD_SYSTEM)/java_library.mk
BUILD_STATIC_JAVA_LIBRARY: = $ (BUILD_SYSTEM)/static_java_library.mk
BUILD_HOST_JAVA_LIBRARY: = $ (BUILD_SYSTEM)/host_java_library.mk
BUILD_DROIDDOC: = $ (BUILD_SYSTEM)/droiddoc. mk
BUILD_COPY_HEADERS: = $ (BUILD_SYSTEM)/copy_headers.mk
BUILD_KEY_CHAR_MAP: = $ (BUILD_SYSTEM)/key_char_map.mk
Except that CLEAR_VARS is a clear local variable, all other variables correspond to a module generation rule. Each local module will include one of them to generate the target module. Most of the above. mk will contain base_rules.mk, which is the basic file for processing the module. It is recommended that you write all the local modules to see why Android. mk should be written in this way.
3. Local Module
The Makefile file of the local module is Android. mk, which is almost everywhere in Android. During Android compilation, the following functions are used to traverse Android in all subdirectories. mk, once found, will not continue to look for the layer sub-directory (all the top-level Android defined by your module. mk must contain Android. mk ).
Subdir_makefiles + =/
$ (Shell build/tools/findleaves. sh -- prune = "./out" $ (subdirs) Android. mk)
Different types of local modules have different syntaxes, but they are basically the same. They only have different variables. You can refer to how to add modules as mentioned in the previous post.
Android uses LOCAL_MODULE_TAGS to determine whether local modules will be compiled into the system. PRODUCT and LOCAL_MODULE_TAGS are used to determine which application packages will be compiled into the system. If you do not specify LOCAL_MODULE_TAGS, the default value is user. In addition, you can use buildspec. mk to specify the modules that need to be compiled into the system.
You can also use mm to compile the specified module, or use make clean-module_name to delete the specified module.
4. Package
This mainly refers to the build/core/Makefile file, which defines various img generation methods, including ramdisk. img userdata. img system. img update.zip recover. img and so on. Let's take a look at how these img are generated, corresponding to several commonly used make goals:
In the actual process, we can also edit the generated files under the out directory, and then manually package the corresponding img to generate the appropriate img. The most common is to add prebuilt files to be integrated.

All makefiles use build/core/main. the mk file is organized together and defines a default goals: droid. When we press Make in the TOP directory, it is equivalent to executing make droid. When Make include all files, after parsing all make my files, the system will look for the rules for generating droid and generate their dependencies in sequence until all satisfied modules are compiled, then use the corresponding tool to package it into the corresponding img.
Basically, the Android building system is organized together in this way. Let's talk about some idle things. The first is how to speed up the Android compilation process, because every time Android traverses all Android. mk, whether it is to compile the entire project or only compile a module. Therefore, you can save the traversal result and read the file directly next time, but it is prone to errors, so be sure to include all. mk. When adding a new file, confirm to delete the original file. Below is a makefile that I wrote to speed up compilation. Replace the following statement with the corresponding part of main. mk:
FROM:
Subdir_makefiles + =/
$ (Shell build/tools/findleaves. sh -- prune = "./out" $ (subdirs) Android. mk)
TO:
Ifneq ($ (ONE_SHOT_MAKEFILE ),)
Else
Ifneq ($ (CASH_MK), true)
Subdir_makefiles + =/
$ (Shell build/tools/findleaves. sh -- prune = "./out" $ (subdirs) Android. mk)
Else
Subdir-makefiles-cash: = $ (shell cat build/subdir_mk_cash)
Ifeq ($ (subdir-makefiles-cash ),)
$ (Warning No. mk cash, create now !)
Subdir_makefiles + =/
$ (Shell build/tools/findleaves. sh -- prune = "./out" $ (subdirs) Android. mk)
Mk-to-file :=$ (shell echo $ (subdir_makefiles)> build/subdir_mk_cash)
Else
$ (Warning Using cash mk !)
Subdir_makefiles: = $ (shell cat build/subdir_mk_cash)
Endif
Endif
Endif
Use CASH_MK = true to enable the quick compilation function. Because no error detection is performed, be careful when using it.
The last one is the problem of sdk api extension. Android can compile its own SDK and expand the corresponding sdk api. Now, I have not carefully studied it, to understand only one crude method, add the corresponding class in frameworks/base/core/java.

Author: zhengmeifu

Related Article

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.