1# 2# Copyright (C) 2015 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17 18# Define rule to build one custom image. 19# Input variables: my_custom_imag_makefile 20 21$(call clear-var-list, $(custom_image_parameter_variables)) 22 23include $(my_custom_imag_makefile) 24 25my_custom_image_name := $(basename $(notdir $(my_custom_imag_makefile))) 26 27intermediates := $(call intermediates-dir-for,PACKAGING,$(my_custom_image_name)) 28my_built_custom_image := $(intermediates)/$(my_custom_image_name).img 29my_staging_dir := $(intermediates)/$(CUSTOM_IMAGE_MOUNT_POINT) 30 31# Collect CUSTOM_IMAGE_MODULES's installd files and their PICKUP_FILES. 32my_built_modules := 33my_copy_pairs := 34my_pickup_files := 35 36$(foreach m,$(CUSTOM_IMAGE_MODULES),\ 37 $(eval _pickup_files := $(strip $(ALL_MODULES.$(m).PICKUP_FILES)\ 38 $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PICKUP_FILES)))\ 39 $(eval _built_files := $(strip $(ALL_MODULES.$(m).BUILT_INSTALLED)\ 40 $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).BUILT_INSTALLED)))\ 41 $(if $(_pickup_files)$(_built_files),,\ 42 $(warning Unknown installed file for module '$(m)'))\ 43 $(eval my_pickup_files += $(_pickup_files))\ 44 $(foreach i, $(_built_files),\ 45 $(eval bui_ins := $(subst :,$(space),$(i)))\ 46 $(eval ins := $(word 2,$(bui_ins)))\ 47 $(if $(filter $(TARGET_OUT_ROOT)/%,$(ins)),\ 48 $(eval bui := $(word 1,$(bui_ins)))\ 49 $(eval my_built_modules += $(bui))\ 50 $(eval my_copy_dest := $(patsubst $(PRODUCT_OUT)/%,%,$(ins)))\ 51 $(eval my_copy_dest := $(subst /,$(space),$(my_copy_dest)))\ 52 $(eval my_copy_dest := $(wordlist 2,999,$(my_copy_dest)))\ 53 $(eval my_copy_dest := $(subst $(space),/,$(my_copy_dest)))\ 54 $(eval my_copy_pairs += $(bui):$(my_staging_dir)/$(my_copy_dest)))\ 55 )) 56 57my_kernel_module_copy_files := 58my_custom_image_modules_var := BOARD_$(strip $(call to-upper,$(my_custom_image_name)))_KERNEL_MODULES 59ifdef $(my_custom_image_modules_var) 60 my_kernel_module_copy_files += $(call build-image-kernel-modules,$(my_custom_image_modules_var),$(my_staging_dir),$(my_custom_image_name)/,$(call intermediates-dir-for,PACKAGING,depmod_$(my_custom_image_name))) 61endif 62 63# Collect CUSTOM_IMAGE_COPY_FILES. 64my_image_copy_files := 65$(foreach f,$(CUSTOM_IMAGE_COPY_FILES) $(my_kernel_module_copy_files),\ 66 $(eval pair := $(subst :,$(space),$(f)))\ 67 $(eval src := $(word 1,$(pair)))\ 68 $(eval my_image_copy_files += $(src))\ 69 $(eval my_copy_pairs += $(src):$(my_staging_dir)/$(word 2,$(pair)))) 70 71ifdef CUSTOM_IMAGE_AVB_KEY_PATH 72ifndef CUSTOM_IMAGE_AVB_ALGORITHM 73 $(error CUSTOM_IMAGE_AVB_ALGORITHM is not defined) 74endif 75ifndef CUSTOM_IMAGE_AVB_ROLLBACK_INDEX 76 $(error CUSTOM_IMAGE_AVB_ROLLBACK_INDEX is not defined) 77endif 78# set rollback_index via footer args 79CUSTOM_IMAGE_AVB_ADD_HASH_FOOTER_ARGS += --rollback_index $(CUSTOM_IMAGE_AVB_ROLLBACK_INDEX) 80CUSTOM_IMAGE_AVB_ADD_HASHTREE_FOOTER_ARGS += --rollback_index $(CUSTOM_IMAGE_AVB_ROLLBACK_INDEX) 81endif 82 83$(my_built_custom_image): PRIVATE_INTERMEDIATES := $(intermediates) 84$(my_built_custom_image): PRIVATE_MOUNT_POINT := $(CUSTOM_IMAGE_MOUNT_POINT) 85$(my_built_custom_image): PRIVATE_PARTITION_SIZE := $(CUSTOM_IMAGE_PARTITION_SIZE) 86$(my_built_custom_image): PRIVATE_FILE_SYSTEM_TYPE := $(CUSTOM_IMAGE_FILE_SYSTEM_TYPE) 87$(my_built_custom_image): PRIVATE_STAGING_DIR := $(my_staging_dir) 88$(my_built_custom_image): PRIVATE_COPY_PAIRS := $(my_copy_pairs) 89$(my_built_custom_image): PRIVATE_PICKUP_FILES := $(my_pickup_files) 90$(my_built_custom_image): PRIVATE_SELINUX := $(CUSTOM_IMAGE_SELINUX) 91$(my_built_custom_image): PRIVATE_SUPPORT_VERITY := $(CUSTOM_IMAGE_SUPPORT_VERITY) 92$(my_built_custom_image): PRIVATE_SUPPORT_VERITY_FEC := $(CUSTOM_IMAGE_SUPPORT_VERITY_FEC) 93$(my_built_custom_image): PRIVATE_VERITY_KEY := $(PRODUCT_VERITY_SIGNING_KEY) 94$(my_built_custom_image): PRIVATE_VERITY_BLOCK_DEVICE := $(CUSTOM_IMAGE_VERITY_BLOCK_DEVICE) 95$(my_built_custom_image): PRIVATE_DICT_FILE := $(CUSTOM_IMAGE_DICT_FILE) 96$(my_built_custom_image): PRIVATE_AVB_AVBTOOL := $(AVBTOOL) 97$(my_built_custom_image): PRIVATE_AVB_KEY_PATH := $(CUSTOM_IMAGE_AVB_KEY_PATH) 98$(my_built_custom_image): PRIVATE_AVB_ALGORITHM:= $(CUSTOM_IMAGE_AVB_ALGORITHM) 99$(my_built_custom_image): PRIVATE_AVB_HASH_ENABLE := $(CUSTOM_IMAGE_AVB_HASH_ENABLE) 100$(my_built_custom_image): PRIVATE_AVB_ADD_HASH_FOOTER_ARGS := $(CUSTOM_IMAGE_AVB_ADD_HASH_FOOTER_ARGS) 101$(my_built_custom_image): PRIVATE_AVB_HASHTREE_ENABLE := $(CUSTOM_IMAGE_AVB_HASHTREE_ENABLE) 102$(my_built_custom_image): PRIVATE_AVB_ADD_HASHTREE_FOOTER_ARGS := $(CUSTOM_IMAGE_AVB_ADD_HASHTREE_FOOTER_ARGS) 103ifeq (true,$(filter true, $(CUSTOM_IMAGE_AVB_HASH_ENABLE) $(CUSTOM_IMAGE_AVB_HASHTREE_ENABLE))) 104 $(my_built_custom_image): $(AVBTOOL) 105else ifneq (,$(filter true, $(CUSTOM_IMAGE_AVB_HASH_ENABLE) $(CUSTOM_IMAGE_AVB_HASHTREE_ENABLE))) 106 $(error Cannot set both CUSTOM_IMAGE_AVB_HASH_ENABLE and CUSTOM_IMAGE_AVB_HASHTREE_ENABLE to true) 107endif 108ifeq (true,$(CUSTOM_IMAGE_SUPPORT_VERITY_FEC)) 109 $(my_built_custom_image): $(FEC) 110endif 111$(my_built_custom_image): $(INTERNAL_USERIMAGES_DEPS) $(my_built_modules) $(my_image_copy_files) $(my_custom_image_modules_dep) \ 112 $(CUSTOM_IMAGE_DICT_FILE) 113 @echo "Build image $@" 114 $(hide) rm -rf $(PRIVATE_INTERMEDIATES) && mkdir -p $(PRIVATE_INTERMEDIATES) 115 $(hide) rm -rf $(PRIVATE_STAGING_DIR) && mkdir -p $(PRIVATE_STAGING_DIR) 116 # Copy all the files. 117 $(hide) $(foreach p,$(PRIVATE_COPY_PAIRS),\ 118 $(eval pair := $(subst :,$(space),$(p)))\ 119 mkdir -p $(dir $(word 2,$(pair)));\ 120 cp -Rf $(word 1,$(pair)) $(word 2,$(pair));) 121 $(if $($(PRIVATE_PICKUP_FILES)),$(hide) cp -Rf $(PRIVATE_PICKUP_FILES) $(PRIVATE_STAGING_DIR)) 122 # Generate the dict. 123 $(hide) echo "# For all accepted properties, see BuildImage() in tools/releasetools/build_image.py" > $(PRIVATE_INTERMEDIATES)/image_info.txt 124 $(hide) echo "mount_point=$(PRIVATE_MOUNT_POINT)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 125 $(hide) echo "partition_name=$(PRIVATE_MOUNT_POINT)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 126 $(hide) echo "fs_type=$(PRIVATE_FILE_SYSTEM_TYPE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 127 $(hide) echo "partition_size=$(PRIVATE_PARTITION_SIZE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 128 $(hide) echo "ext_mkuserimg=$(notdir $(MKEXTUSERIMG))" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 129 $(if $(PRIVATE_SELINUX),$(hide) echo "selinux_fc=$(SELINUX_FC)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 130 $(if $(PRIVATE_SUPPORT_VERITY),\ 131 $(hide) echo "verity=$(PRIVATE_SUPPORT_VERITY)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 132 echo "verity_key=$(PRIVATE_VERITY_KEY)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 133 echo "verity_signer_cmd=$(VERITY_SIGNER)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 134 echo "verity_block_device=$(PRIVATE_VERITY_BLOCK_DEVICE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 135 $(if $(PRIVATE_SUPPORT_VERITY_FEC),\ 136 $(hide) echo "verity_fec=$(PRIVATE_SUPPORT_VERITY_FEC)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 137 $(if $(filter eng, $(TARGET_BUILD_VARIANT)),$(hide) echo "verity_disable=true" >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 138 $(hide) echo "avb_avbtool=$(PRIVATE_AVB_AVBTOOL)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt 139 $(if $(PRIVATE_AVB_KEY_PATH),\ 140 $(hide) echo "avb_key_path=$(PRIVATE_AVB_KEY_PATH)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 141 echo "avb_algorithm=$(PRIVATE_AVB_ALGORITHM)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 142 $(if $(PRIVATE_AVB_HASH_ENABLE),\ 143 $(hide) echo "avb_hash_enable=$(PRIVATE_AVB_HASH_ENABLE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 144 echo "avb_add_hash_footer_args=$(PRIVATE_AVB_ADD_HASH_FOOTER_ARGS)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 145 $(if $(PRIVATE_AVB_HASHTREE_ENABLE),\ 146 $(hide) echo "avb_hashtree_enable=$(PRIVATE_AVB_HASHTREE_ENABLE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 147 echo "avb_add_hashtree_footer_args=$(PRIVATE_AVB_ADD_HASHTREE_FOOTER_ARGS)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 148 $(if $(PRIVATE_DICT_FILE),\ 149 $(hide) echo "# Properties from $(PRIVATE_DICT_FILE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\ 150 cat $(PRIVATE_DICT_FILE) >> $(PRIVATE_INTERMEDIATES)/image_info.txt) 151 # Generate the image. 152 $(if $(filter oem,$(PRIVATE_MOUNT_POINT)), \ 153 $(hide) echo "oem.buildnumber=$(BUILD_NUMBER_FROM_FILE)" >> $(PRIVATE_STAGING_DIR)/oem.prop) 154 $(hide) PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \ 155 $(BUILD_IMAGE) \ 156 $(PRIVATE_STAGING_DIR) $(PRIVATE_INTERMEDIATES)/image_info.txt $@ $(TARGET_OUT) 157 158my_installed_custom_image := $(PRODUCT_OUT)/$(notdir $(my_built_custom_image)) 159$(my_installed_custom_image) : $(my_built_custom_image) 160 $(call copy-file-to-new-target-with-cp) 161 162.PHONY: $(my_custom_image_name) 163custom_images $(my_custom_image_name) : $(my_installed_custom_image) 164 165# Archive the built image. 166$(call dist-for-goals, $(my_custom_image_name) custom_images,$(my_installed_custom_image)) 167 168my_staging_dir := 169my_built_modules := 170my_copy_dest := 171my_copy_pairs := 172my_pickup_files := 173