The Makefile, XXXXX.MK), shell script, Python script, etc.
MAKE file for three levels
1, the core of the entire compilation system Android/Build/Core/, such as the main.mk file
2, Make files for different manufacturers and different products are located on Android/Device/Company Name/Product Name/
device\qcom\msm8937_32\Android.mk
device\qcom\msm8937_32\AndroidBoard.mk
device\qcom\msm8937_32\BoardConfig.mk
device\qcom\msm8937_32\msm8937_32.mk
3, make files of each module. Each module has a total make file, which is uniformly Android.mk. The compilation system will scan the Android.mk in the source tree tree.
Compile the order of the maxe file when compiling the entire system
1, after typing the make command, the compilation system will read the makefile file under the source code root directory. The content is as follows:
### DO NOT EDIT THIS FILE ###
include build/core/main.mk
### DO NOT EDIT THIS FILE ###
2, the built/core/main.mk file contained in Makefile is the core of the code structure.
.PHONY: bootimage
bootimage: $(INSTALLED_BOOTIMAGE_TARGET)
.PHONY: vbmetaimage
vbmetaimage: $(INSTALLED_VBMETAIMAGE_TARGET)
.PHONY: auxiliary
auxiliary: $(INSTALLED_AUX_TARGETS)
# Build files and then package it into the rom formats
.PHONY: droidcore
droidcore: files \
systemimage \
$(INSTALLED_BOOTIMAGE_TARGET) \
$(INSTALLED_RECOVERYIMAGE_TARGET) \
$(INSTALLED_VBMETAIMAGE_TARGET) \
$(INSTALLED_USERDATAIMAGE_TARGET) \
$(INSTALLED_CACHEIMAGE_TARGET) \
$(INSTALLED_BPTIMAGE_TARGET) \
$(INSTALLED_VENDORIMAGE_TARGET) \
$(INSTALLED_SYSTEMOTHERIMAGE_TARGET) \
$(INSTALLED_FILES_FILE) \
$(INSTALLED_FILES_FILE_VENDOR) \
$(INSTALLED_FILES_FILE_SYSTEMOTHER)
Among them, you can see the compilation rules of various targets. Let’s analyze the process definition process of MAKE BOOTIMAGE’s Make file rules
After executing Make BootImage, the call order of the Makefile and XXX.MK files
1, MAKE BOOTIMAGE is a command used to compile the kernel.
.PHONY: bootimage
bootimage: $(INSTALLED_BOOTIMAGE_TARGET)
Build/Coremain.mk contains the makefile file in Build/Core
BUILD_SYSTEM := $(TOPDIR)build/core
include $(BUILD_SYSTEM)/Makefile
Installed_Bootimage_Target Value in the Makefile file
In Build/Core/Makefile, we can see
INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
2, Build/Core/Makefile we also see the dependency item of Installed_Bootimage_Target
$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(BOOT_SIGNER)
$(call pretty,"Target1 boot image: [email protected]")
$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output [email protected]
$(BOOT_SIGNER) /boot [email protected] $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem [email protected]
$(hide) $(call assert-max-image-size,[email protected],$(BOARD_BOOTIMAGE_PARTITION_SIZE))
Among them, $ (Hide) $ (mkbootimg) $ (Internet_Bootimage_args) $ (Internet_mkbootimg_version_args) $ (Board_MKBOOTIMG_ARGS) –Output[email protected]is the key compilation statement
need to use $ (mkbootimg) tools to generate bootImage for the Internet_Bootimage_args.
3, where the Internet_Bootimage_args is a compiled parameter, and its assignment is also in Build/Core/Makefile, as follows::
# -----------------------------------------------------------------
# the boot image, which is a collection of other images.
INTERNAL_BOOTIMAGE_ARGS := \
$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
--kernel $(INSTALLED_KERNEL_TARGET)
ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
INTERNAL_BOOTIMAGE_ARGS += --ramdisk $(INSTALLED_RAMDISK_TARGET)
endif
INTERNAL_BOOTIMAGE_FILES := $(filter-out --%,$(INTERNAL_BOOTIMAGE_ARGS))
ifdef BOARD_KERNEL_BASE
INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
endif
ifdef BOARD_KERNEL_PAGESIZE
INTERNAL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
endif
ifeq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),true)
ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
VERITY_KEYID := veritykeyid=id:`openssl x509 -in $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem -text \
| grep keyid | sed 's/://g' | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]' | sed 's/keyid//g'`
endif
endif
INTERNAL_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE) buildvariant=$(TARGET_BUILD_VARIANT) $(VERITY_KEYID))
ifdef INTERNAL_KERNEL_CMDLINE
INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)"
endif
You can see the BootImage compiled by we compiled several Image: Kernel, RAMDISK, CMDLINE, PAGESIZE. Let’s see that Kernel’s target is installed_kernel_target
The definition of
Installed_kernel_target is in this file
INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
4, to compile Installed_kernel_target goals, there must be dependency relationships. Here is some complicated to find dependency relationships. First of all, find relevant files
main.mk files will search for and the Android.mk file in all subdirectors inClude, so Build/Target/Board/Android.mk has also been quoted by Main.mk quoted
build\target\board\Android.mk
-include $(TARGET_DEVICE_DIR)/AndroidBoard.mk
Here the meaning of -INCLUDE is when the include androidboard.mk file is encountered when you encounter errors
Among them, target_device_dir is defined in build \ core \ envsetup.mk
TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(board_config_mk)))
BOARD_CONFIG_MK variable definition is defined in this file
# Boards may be defined under $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)
# or under vendor/*/$(TARGET_DEVICE). Search in both places, but
# make sure only one exists.
# Real boards should always be associated with an OEM vendor.
board_config_mk := \
$(strip $(sort $(wildcard \
$(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk \
$(shell test -d device && find -L device -maxdepth 4 -path '*/$(TARGET_DEVICE)/BoardConfig.mk') \
$(shell test -d vendor && find -L vendor -maxdepth 4 -path '*/$(TARGET_DEVICE)/BoardConfig.mk') \
)))
The script above will find the boardconfig.mk contained in the current project folder under the Device, Vendor folder. The path found in our example is Device \ QCOM \ MSM8937_32 \ Androidboard.mk
5, Installed_kernel_target, the dependency is in this Androidboard.mk file
device/qcom/msm8937_32/AndroidBoard.mk
$(INSTALLED_KERNEL_TARGET): $(TARGET_PREBUILT_KERNEL) | $(ACP)
$(transform-prebuilt-to-target)
6, target_prebuilt_kernel’s dependence is finally in Kernel
device \ QCOM \ MSM8937_32 \ Androidboard.mk will contain Androidkernel.mk under Kernel.
IFEQ ($ (target_kernel_source),),),),),),),),),),),),),),),),),),)
Target_kernel_source: = kernel
endif
Include $ (target_kernel_source) /androidkernel.mk
kernel \ androidkernel.mk as follows:
TARGET_PREBUILT_KERNEL := $(TARGET_PREBUILT_INT_KERNEL)
ifeq ($(TARGET_USES_UNCOMPRESSED_KERNEL),true)
$(info Using uncompressed kernel)
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/Image
else
ifeq ($(KERNEL_ARCH),arm64)
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/Image.gz
else
TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/zImage
endif
7, executing the make compile command in Androidkernel.mk will call the makefile file in the Kernel directory
$(KERNEL_OUT):
mkdir -p $(KERNEL_OUT)
$(KERNEL_CONFIG): $(KERNEL_OUT)
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_DEFCONFIG)
$(hide) if [ ! -z "$(KERNEL_CONFIG_OVERRIDE)" ]; then \
echo "Overriding kernel config with '$(KERNEL_CONFIG_OVERRIDE)'"; \
echo $(KERNEL_CONFIG_OVERRIDE) >> $(KERNEL_OUT)/.config; \
$(MAKE) -C $(TARGET_KERNEL_SOURCE) O=$(BUILD_ROOT_LOC)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) oldconfig; fi
So far, I finally finished the whole process of the Make Bootimage command