当前目录build
./core/Makefile:802:INSTALLED_SYSTEMIMAGE := $(PRODUCT_OUT)/system.img
生成文件位置
./core/Makefile:828:systemimage: $(INSTALLED_SYSTEMIMAGE)
systemimage就是该镜像文件生成的目标项。使用make systemimage可以显式直接生成system.img
823 $(INSTALLED_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE) $(RECOVERY_FROM_BOOT_PATCH) | $(ACP)
824 @echo "Install system fs image: $@"
825 $(copy-file-to-target)
826 $(hide) $(call assert-max-image-size,$@ $(RECOVERY_FROM_BOOT_PATCH),$(B OARD_SYSTEMIMAGE_PARTITION_SIZE),yaffs)
799 $(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE)
800 $(call build-systemimage-target,$@)
最终system.img依赖BUILT_SYSTEMIMAGE,BUILT_SYSTEMIMAGE会调用build-systemimage-target生成。
build-systemimage-target定义:
790 define build-systemimage-target
791 @echo "Target system fs image: $(1)"
792 @mkdir -p $(dir $(1)) $(systemimage_intermediates) && rm -rf $(systemimag e_intermediates)/system_image_info.txt
793 $(call generate-userimage-prop-dictionary, $(systemimage_intermediates)/s ystem_image_info.txt, skip_fsck=true)
794 $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
795 ./build/tools/releasetools/build_image.py \
796 $(TARGET_OUT) $(systemimage_intermediates)/system_image_info.txt $(1)
797 endef
首先生成镜像文件参数文件,然后根据参数文件和相应目录生成system.img文件。主要会用到build_image.py脚本。
build/tools/releasetools/build_image.py:
#!/usr/bin/env python
#
# Copyright (C) 2011 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR COND