Home | History | Annotate | Download | only in core
      1 # Put some miscellaneous rules here
      2 
      3 # HACK: clear LOCAL_PATH from including last build target before calling
      4 # intermedites-dir-for
      5 LOCAL_PATH := $(BUILD_SYSTEM)
      6 
      7 # Pick a reasonable string to use to identify files.
      8 ifneq (,$(filter eng.%,$(BUILD_NUMBER)))
      9   # BUILD_NUMBER has a timestamp in it, which means that
     10   # it will change every time.  Pick a stable value.
     11   FILE_NAME_TAG := eng.$(USER)
     12 else
     13   FILE_NAME_TAG := $(BUILD_NUMBER)
     14 endif
     15 
     16 # -----------------------------------------------------------------
     17 # Define rules to copy PRODUCT_COPY_FILES defined by the product.
     18 # PRODUCT_COPY_FILES contains words like <source file>:<dest file>[:<owner>].
     19 # <dest file> is relative to $(PRODUCT_OUT), so it should look like,
     20 # e.g., "system/etc/file.xml".
     21 # The filter part means "only eval the copy-one-file rule if this
     22 # src:dest pair is the first one to match the same dest"
     23 #$(1): the src:dest pair
     24 define check-product-copy-files
     25 $(if $(filter %.apk, $(call word-colon, 2, $(1))),$(error \
     26     Prebuilt apk found in PRODUCT_COPY_FILES: $(1), use BUILD_PREBUILT instead!))
     27 endef
     28 # filter out the duplicate <source file>:<dest file> pairs.
     29 unique_product_copy_files_pairs :=
     30 $(foreach cf,$(PRODUCT_COPY_FILES), \
     31     $(if $(filter $(unique_product_copy_files_pairs),$(cf)),,\
     32         $(eval unique_product_copy_files_pairs += $(cf))))
     33 unique_product_copy_files_destinations :=
     34 $(foreach cf,$(unique_product_copy_files_pairs), \
     35     $(eval _src := $(call word-colon,1,$(cf))) \
     36     $(eval _dest := $(call word-colon,2,$(cf))) \
     37     $(call check-product-copy-files,$(cf)) \
     38     $(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \
     39         $(info PRODUCT_COPY_FILES $(cf) ignored.), \
     40         $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
     41         $(if $(filter %.xml,$(_dest)),\
     42             $(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\
     43             $(eval $(call copy-one-file,$(_src),$(_fulldest)))) \
     44         $(eval ALL_DEFAULT_INSTALLED_MODULES += $(_fulldest)) \
     45         $(eval unique_product_copy_files_destinations += $(_dest))))
     46 unique_product_copy_files_pairs :=
     47 unique_product_copy_files_destinations :=
     48 
     49 # -----------------------------------------------------------------
     50 # Define rules to copy headers defined in copy_headers.mk
     51 # If more than one makefile declared a header, print a warning,
     52 # then copy the last one defined. This matches the previous make
     53 # behavior.
     54 $(foreach dest,$(ALL_COPIED_HEADERS), \
     55     $(eval _srcs := $(ALL_COPIED_HEADERS.$(dest).SRC)) \
     56     $(eval _src := $(word $(words $(_srcs)),$(_srcs))) \
     57     $(if $(call streq,$(_src),$(_srcs)),, \
     58         $(warning Duplicate header copy: $(dest)) \
     59 	$(warning Defined in: $(ALL_COPIED_HEADERS.$(dest).MAKEFILE))) \
     60     $(eval $(call copy-one-header,$(_src),$(dest))))
     61 all_copied_headers: $(ALL_COPIED_HEADERS)
     62 
     63 # -----------------------------------------------------------------
     64 # docs/index.html
     65 ifeq (,$(TARGET_BUILD_APPS))
     66 gen := $(OUT_DOCS)/index.html
     67 ALL_DOCS += $(gen)
     68 $(gen): frameworks/base/docs/docs-redirect-index.html
     69 	@mkdir -p $(dir $@)
     70 	@cp -f $< $@
     71 endif
     72 
     73 # -----------------------------------------------------------------
     74 # property_overrides_split_enabled
     75 property_overrides_split_enabled :=
     76 ifeq ($(BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED), true)
     77   property_overrides_split_enabled := true
     78 endif
     79 
     80 # -----------------------------------------------------------------
     81 # prop.default
     82 ifdef property_overrides_split_enabled
     83 INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_OUT)/etc/prop.default
     84 INSTALLED_DEFAULT_PROP_OLD_TARGET := $(TARGET_ROOT_OUT)/default.prop
     85 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_OLD_TARGET)
     86 $(INSTALLED_DEFAULT_PROP_OLD_TARGET): $(INSTALLED_DEFAULT_PROP_TARGET)
     87 else
     88 # legacy path
     89 INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_ROOT_OUT)/default.prop
     90 endif
     91 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_TARGET)
     92 FINAL_DEFAULT_PROPERTIES := \
     93     $(call collapse-pairs, $(ADDITIONAL_DEFAULT_PROPERTIES))
     94 ifndef property_overrides_split_enabled
     95   FINAL_DEFAULT_PROPERTIES += \
     96       $(call collapse-pairs, $(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))
     97 endif
     98 FINAL_DEFAULT_PROPERTIES := $(call uniq-pairs-by-first-component, \
     99     $(FINAL_DEFAULT_PROPERTIES),=)
    100 
    101 intermediate_system_build_prop := $(call intermediates-dir-for,ETC,system_build_prop)/build.prop
    102 
    103 $(INSTALLED_DEFAULT_PROP_TARGET): $(intermediate_system_build_prop)
    104 	@echo Target buildinfo: $@
    105 	@mkdir -p $(dir $@)
    106 	@rm -f $@
    107 	$(hide) echo "#" > $@; \
    108 	        echo "# ADDITIONAL_DEFAULT_PROPERTIES" >> $@; \
    109 	        echo "#" >> $@;
    110 	$(hide) $(foreach line,$(FINAL_DEFAULT_PROPERTIES), \
    111 		echo "$(line)" >> $@;)
    112 	$(hide) echo "#" >> $@; \
    113 	        echo "# BOOTIMAGE_BUILD_PROPERTIES" >> $@; \
    114 	        echo "#" >> $@;
    115 	$(hide) echo ro.bootimage.build.date=`$(DATE_FROM_FILE)`>>$@
    116 	$(hide) echo ro.bootimage.build.date.utc=`$(DATE_FROM_FILE) +%s`>>$@
    117 	$(hide) echo ro.bootimage.build.fingerprint="$(BUILD_FINGERPRINT_FROM_FILE)">>$@
    118 	$(hide) build/tools/post_process_props.py $@
    119 ifdef property_overrides_split_enabled
    120 	$(hide) mkdir -p $(TARGET_ROOT_OUT)
    121 	$(hide) ln -sf system/etc/prop.default $(INSTALLED_DEFAULT_PROP_OLD_TARGET)
    122 endif
    123 
    124 # -----------------------------------------------------------------
    125 # vendor default.prop
    126 INSTALLED_VENDOR_DEFAULT_PROP_TARGET :=
    127 ifdef property_overrides_split_enabled
    128 INSTALLED_VENDOR_DEFAULT_PROP_TARGET := $(TARGET_OUT_VENDOR)/default.prop
    129 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_VENDOR_DEFAULT_PROP_TARGET)
    130 
    131 FINAL_VENDOR_DEFAULT_PROPERTIES += \
    132     $(call collapse-pairs, $(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))
    133 FINAL_VENDOR_DEFAULT_PROPERTIES := $(call uniq-pairs-by-first-component, \
    134     $(FINAL_VENDOR_DEFAULT_PROPERTIES),=)
    135 
    136 $(INSTALLED_VENDOR_DEFAULT_PROP_TARGET): $(INSTALLED_DEFAULT_PROP_TARGET)
    137 	@echo Target buildinfo: $@
    138 	@mkdir -p $(dir $@)
    139 	$(hide) echo "#" > $@; \
    140 	        echo "# ADDITIONAL VENDOR DEFAULT PROPERTIES" >> $@; \
    141 	        echo "#" >> $@;
    142 	$(hide) $(foreach line,$(FINAL_VENDOR_DEFAULT_PROPERTIES), \
    143 		echo "$(line)" >> $@;)
    144 	$(hide) build/tools/post_process_props.py $@
    145 
    146 endif  # property_overrides_split_enabled
    147 
    148 # -----------------------------------------------------------------
    149 # build.prop
    150 INSTALLED_BUILD_PROP_TARGET := $(TARGET_OUT)/build.prop
    151 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_BUILD_PROP_TARGET)
    152 FINAL_BUILD_PROPERTIES := \
    153     $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))
    154 FINAL_BUILD_PROPERTIES := $(call uniq-pairs-by-first-component, \
    155     $(FINAL_BUILD_PROPERTIES),=)
    156 
    157 # A list of arbitrary tags describing the build configuration.
    158 # Force ":=" so we can use +=
    159 BUILD_VERSION_TAGS := $(BUILD_VERSION_TAGS)
    160 ifeq ($(TARGET_BUILD_TYPE),debug)
    161   BUILD_VERSION_TAGS += debug
    162 endif
    163 # The "test-keys" tag marks builds signed with the old test keys,
    164 # which are available in the SDK.  "dev-keys" marks builds signed with
    165 # non-default dev keys (usually private keys from a vendor directory).
    166 # Both of these tags will be removed and replaced with "release-keys"
    167 # when the target-files is signed in a post-build step.
    168 ifeq ($(DEFAULT_SYSTEM_DEV_CERTIFICATE),build/target/product/security/testkey)
    169 BUILD_KEYS := test-keys
    170 else
    171 BUILD_KEYS := dev-keys
    172 endif
    173 BUILD_VERSION_TAGS += $(BUILD_KEYS)
    174 BUILD_VERSION_TAGS := $(subst $(space),$(comma),$(sort $(BUILD_VERSION_TAGS)))
    175 
    176 # A human-readable string that descibes this build in detail.
    177 build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER_FROM_FILE) $(BUILD_VERSION_TAGS)
    178 $(intermediate_system_build_prop): PRIVATE_BUILD_DESC := $(build_desc)
    179 
    180 # The string used to uniquely identify the combined build and product; used by the OTA server.
    181 ifeq (,$(strip $(BUILD_FINGERPRINT)))
    182   ifneq ($(filter eng.%,$(BUILD_NUMBER)),)
    183     # Trim down BUILD_FINGERPRINT: the default BUILD_NUMBER makes it easily exceed
    184     # the Android system property length limit (PROPERTY_VALUE_MAX=92).
    185     BF_BUILD_NUMBER := $(shell echo $${USER:0:6})$(shell $(DATE) +%m%d%H%M)
    186   else
    187     BF_BUILD_NUMBER := $(BUILD_NUMBER)
    188   endif
    189   BUILD_FINGERPRINT := $(PRODUCT_BRAND)/$(TARGET_PRODUCT)/$(TARGET_DEVICE):$(PLATFORM_VERSION)/$(BUILD_ID)/$(BF_BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)
    190 endif
    191 ifneq ($(words $(BUILD_FINGERPRINT)),1)
    192   $(error BUILD_FINGERPRINT cannot contain spaces: "$(BUILD_FINGERPRINT)")
    193 endif
    194 
    195 $(shell mkdir -p $(PRODUCT_OUT) && echo $(BUILD_FINGERPRINT) > $(PRODUCT_OUT)/build_fingerprint.txt)
    196 BUILD_FINGERPRINT_FROM_FILE := $$(cat $(PRODUCT_OUT)/build_fingerprint.txt)
    197 
    198 # The string used to uniquely identify the system build; used by the OTA server.
    199 # This purposefully excludes any product-specific variables.
    200 ifeq (,$(strip $(BUILD_THUMBPRINT)))
    201   BUILD_THUMBPRINT := $(PLATFORM_VERSION)/$(BUILD_ID)/$(BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)
    202 endif
    203 ifneq ($(words $(BUILD_THUMBPRINT)),1)
    204   $(error BUILD_THUMBPRINT cannot contain spaces: "$(BUILD_THUMBPRINT)")
    205 endif
    206 
    207 KNOWN_OEM_THUMBPRINT_PROPERTIES := \
    208     ro.product.brand \
    209     ro.product.name \
    210     ro.product.device
    211 OEM_THUMBPRINT_PROPERTIES := $(filter $(KNOWN_OEM_THUMBPRINT_PROPERTIES),\
    212     $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES))
    213 
    214 # Display parameters shown under Settings -> About Phone
    215 ifeq ($(TARGET_BUILD_VARIANT),user)
    216   # User builds should show:
    217   # release build number or branch.buld_number non-release builds
    218 
    219   # Dev. branches should have DISPLAY_BUILD_NUMBER set
    220   ifeq (true,$(DISPLAY_BUILD_NUMBER))
    221     BUILD_DISPLAY_ID := $(BUILD_ID).$(BUILD_NUMBER_FROM_FILE) $(BUILD_KEYS)
    222   else
    223     BUILD_DISPLAY_ID := $(BUILD_ID) $(BUILD_KEYS)
    224   endif
    225 else
    226   # Non-user builds should show detailed build information
    227   BUILD_DISPLAY_ID := $(build_desc)
    228 endif
    229 
    230 # Accepts a whitespace separated list of product locales such as
    231 # (en_US en_AU en_GB...) and returns the first locale in the list with
    232 # underscores replaced with hyphens. In the example above, this will
    233 # return "en-US".
    234 define get-default-product-locale
    235 $(strip $(subst _,-, $(firstword $(1))))
    236 endef
    237 
    238 BUILDINFO_SH := build/tools/buildinfo.sh
    239 VENDOR_BUILDINFO_SH := build/tools/vendor_buildinfo.sh
    240 
    241 # TARGET_BUILD_FLAVOR and ro.build.flavor are used only by the test
    242 # harness to distinguish builds. Only add _asan for a sanitized build
    243 # if it isn't already a part of the flavor (via a dedicated lunch
    244 # config for example).
    245 TARGET_BUILD_FLAVOR := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)
    246 ifdef SANITIZE_TARGET
    247 ifeq (,$(findstring _asan,$(TARGET_BUILD_FLAVOR)))
    248 TARGET_BUILD_FLAVOR := $(TARGET_BUILD_FLAVOR)_asan
    249 endif
    250 endif
    251 
    252 ifdef TARGET_SYSTEM_PROP
    253 system_prop_file := $(TARGET_SYSTEM_PROP)
    254 else
    255 system_prop_file := $(wildcard $(TARGET_DEVICE_DIR)/system.prop)
    256 endif
    257 $(intermediate_system_build_prop): $(VENDOR_BUILDINFO_SH) $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(system_prop_file) $(INSTALLED_ANDROID_INFO_TXT_TARGET)
    258 	@echo Target buildinfo: $@
    259 	@mkdir -p $(dir $@)
    260 	$(hide) echo > $@
    261 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES),)
    262 	$(hide) echo "#" >> $@; \
    263 	        echo "# PRODUCT_OEM_PROPERTIES" >> $@; \
    264 	        echo "#" >> $@;
    265 	$(hide) $(foreach prop,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES), \
    266 		echo "import /oem/oem.prop $(prop)" >> $@;)
    267 endif
    268 	$(hide) TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \
    269 			TARGET_BUILD_FLAVOR="$(TARGET_BUILD_FLAVOR)" \
    270 			TARGET_DEVICE="$(TARGET_DEVICE)" \
    271 			PRODUCT_NAME="$(TARGET_PRODUCT)" \
    272 			PRODUCT_BRAND="$(PRODUCT_BRAND)" \
    273 			PRODUCT_DEFAULT_LOCALE="$(call get-default-product-locale,$(PRODUCT_LOCALES))" \
    274 			PRODUCT_DEFAULT_WIFI_CHANNELS="$(PRODUCT_DEFAULT_WIFI_CHANNELS)" \
    275 			PRODUCT_MODEL="$(PRODUCT_MODEL)" \
    276 			PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
    277 			PRIVATE_BUILD_DESC="$(PRIVATE_BUILD_DESC)" \
    278 			BUILD_ID="$(BUILD_ID)" \
    279 			BUILD_DISPLAY_ID="$(BUILD_DISPLAY_ID)" \
    280 			DATE="$(DATE_FROM_FILE)" \
    281 			BUILD_NUMBER="$(BUILD_NUMBER_FROM_FILE)" \
    282 			BOARD_BUILD_SYSTEM_ROOT_IMAGE="$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)" \
    283 			AB_OTA_UPDATER="$(AB_OTA_UPDATER)" \
    284 			PLATFORM_VERSION="$(PLATFORM_VERSION)" \
    285 			PLATFORM_SECURITY_PATCH="$(PLATFORM_SECURITY_PATCH)" \
    286 			PLATFORM_BASE_OS="$(PLATFORM_BASE_OS)" \
    287 			PLATFORM_SDK_VERSION="$(PLATFORM_SDK_VERSION)" \
    288 			PLATFORM_PREVIEW_SDK_VERSION="$(PLATFORM_PREVIEW_SDK_VERSION)" \
    289 			PLATFORM_VERSION_CODENAME="$(PLATFORM_VERSION_CODENAME)" \
    290 			PLATFORM_VERSION_ALL_CODENAMES="$(PLATFORM_VERSION_ALL_CODENAMES)" \
    291 			BUILD_VERSION_TAGS="$(BUILD_VERSION_TAGS)" \
    292 			BUILD_FINGERPRINT="$(BUILD_FINGERPRINT_FROM_FILE)" \
    293 			$(if $(OEM_THUMBPRINT_PROPERTIES),BUILD_THUMBPRINT="$(BUILD_THUMBPRINT)") \
    294 			TARGET_CPU_ABI_LIST="$(TARGET_CPU_ABI_LIST)" \
    295 			TARGET_CPU_ABI_LIST_32_BIT="$(TARGET_CPU_ABI_LIST_32_BIT)" \
    296 			TARGET_CPU_ABI_LIST_64_BIT="$(TARGET_CPU_ABI_LIST_64_BIT)" \
    297 			TARGET_CPU_ABI="$(TARGET_CPU_ABI)" \
    298 			TARGET_CPU_ABI2="$(TARGET_CPU_ABI2)" \
    299 			TARGET_AAPT_CHARACTERISTICS="$(TARGET_AAPT_CHARACTERISTICS)" \
    300 	        bash $(BUILDINFO_SH) >> $@
    301 ifndef property_overrides_split_enabled
    302 	$(hide) TARGET_DEVICE="$(TARGET_DEVICE)" \
    303 			PRODUCT_NAME="$(TARGET_PRODUCT)" \
    304 			PRODUCT_BRAND="$(PRODUCT_BRAND)" \
    305 			PRODUCT_MODEL="$(PRODUCT_MODEL)" \
    306 			PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
    307 			TARGET_BOOTLOADER_BOARD_NAME="$(TARGET_BOOTLOADER_BOARD_NAME)" \
    308 			TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \
    309 	        bash $(VENDOR_BUILDINFO_SH) >> $@
    310 endif
    311 	$(hide) $(foreach file,$(system_prop_file), \
    312 		if [ -f "$(file)" ]; then \
    313 			echo "#" >> $@; \
    314 			echo Target buildinfo from: "$(file)"; \
    315 			echo "# from $(file)" >> $@; \
    316 			echo "#" >> $@; \
    317 			cat $(file) >> $@; \
    318 		fi;)
    319 	$(if $(FINAL_BUILD_PROPERTIES), \
    320 		$(hide) echo >> $@; \
    321 		        echo "#" >> $@; \
    322 		        echo "# ADDITIONAL_BUILD_PROPERTIES" >> $@; \
    323 		        echo "#" >> $@; )
    324 	$(hide) $(foreach line,$(FINAL_BUILD_PROPERTIES), \
    325 		echo "$(line)" >> $@;)
    326 	$(hide) cat $(INSTALLED_ANDROID_INFO_TXT_TARGET) | grep 'require version-' | sed -e 's/require version-/ro.build.expect./g' >> $@
    327 	$(hide) build/tools/post_process_props.py $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_PROPERTY_BLACKLIST)
    328 
    329 build_desc :=
    330 
    331 ifeq (,$(filter true, $(TARGET_NO_KERNEL) $(TARGET_NO_RECOVERY)))
    332 INSTALLED_RECOVERYIMAGE_TARGET := $(PRODUCT_OUT)/recovery.img
    333 else
    334 INSTALLED_RECOVERYIMAGE_TARGET :=
    335 endif
    336 
    337 $(INSTALLED_BUILD_PROP_TARGET): $(intermediate_system_build_prop) $(INSTALLED_RECOVERYIMAGE_TARGET)
    338 	@echo "Target build info: $@"
    339 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
    340 	$(hide) grep -v 'ro.product.first_api_level' $(intermediate_system_build_prop) > $@
    341 else
    342 	$(hide) cat $(intermediate_system_build_prop) > $@
    343 endif
    344 ifdef INSTALLED_RECOVERYIMAGE_TARGET
    345 	$(hide) echo ro.expect.recovery_id=`cat $(RECOVERYIMAGE_ID_FILE)` >> $@
    346 endif
    347 
    348 # -----------------------------------------------------------------
    349 # vendor build.prop
    350 #
    351 # For verifying that the vendor build is what we think it is
    352 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
    353 INSTALLED_VENDOR_BUILD_PROP_TARGET := $(TARGET_OUT_VENDOR)/build.prop
    354 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_VENDOR_BUILD_PROP_TARGET)
    355 
    356 ifdef property_overrides_split_enabled
    357 FINAL_VENDOR_BUILD_PROPERTIES += \
    358     $(call collapse-pairs, $(PRODUCT_PROPERTY_OVERRIDES))
    359 FINAL_VENDOR_BUILD_PROPERTIES := $(call uniq-pairs-by-first-component, \
    360     $(FINAL_VENDOR_BUILD_PROPERTIES),=)
    361 endif  # property_overrides_split_enabled
    362 
    363 $(INSTALLED_VENDOR_BUILD_PROP_TARGET): $(VENDOR_BUILDINFO_SH) $(intermediate_system_build_prop)
    364 	@echo Target vendor buildinfo: $@
    365 	@mkdir -p $(dir $@)
    366 	$(hide) echo > $@
    367 	$(hide) grep 'ro.product.first_api_level' $(intermediate_system_build_prop) >> $@ || true
    368 	$(hide) echo ro.vendor.build.date=`$(DATE_FROM_FILE)`>>$@
    369 	$(hide) echo ro.vendor.build.date.utc=`$(DATE_FROM_FILE) +%s`>>$@
    370 	$(hide) echo ro.vendor.build.fingerprint="$(BUILD_FINGERPRINT_FROM_FILE)">>$@
    371 ifdef property_overrides_split_enabled
    372 	$(hide) TARGET_DEVICE="$(TARGET_DEVICE)" \
    373 			PRODUCT_NAME="$(TARGET_PRODUCT)" \
    374 			PRODUCT_BRAND="$(PRODUCT_BRAND)" \
    375 			PRODUCT_MODEL="$(PRODUCT_MODEL)" \
    376 			PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
    377 			TARGET_BOOTLOADER_BOARD_NAME="$(TARGET_BOOTLOADER_BOARD_NAME)" \
    378 			TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \
    379 	        bash $(VENDOR_BUILDINFO_SH) >> $@
    380 	$(hide) echo "#" >> $@; \
    381 	        echo "# ADDITIONAL VENDOR BUILD PROPERTIES" >> $@; \
    382 	        echo "#" >> $@;
    383 	$(hide) $(foreach line,$(FINAL_VENDOR_BUILD_PROPERTIES), \
    384 		echo "$(line)" >> $@;)
    385 	$(hide) build/tools/post_process_props.py $@
    386 endif  # property_overrides_split_enabled
    387 endif  # BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
    388 
    389 # ----------------------------------------------------------------
    390 
    391 # -----------------------------------------------------------------
    392 # sdk-build.prop
    393 #
    394 # There are certain things in build.prop that we don't want to
    395 # ship with the sdk; remove them.
    396 
    397 # This must be a list of entire property keys followed by
    398 # "=" characters, without any internal spaces.
    399 sdk_build_prop_remove := \
    400 	ro.build.user= \
    401 	ro.build.host= \
    402 	ro.product.brand= \
    403 	ro.product.manufacturer= \
    404 	ro.product.device=
    405 # TODO: Remove this soon-to-be obsolete property
    406 sdk_build_prop_remove += ro.build.product=
    407 INSTALLED_SDK_BUILD_PROP_TARGET := $(PRODUCT_OUT)/sdk/sdk-build.prop
    408 $(INSTALLED_SDK_BUILD_PROP_TARGET): $(INSTALLED_BUILD_PROP_TARGET)
    409 	@echo SDK buildinfo: $@
    410 	@mkdir -p $(dir $@)
    411 	$(hide) grep -v "$(subst $(space),\|,$(strip \
    412 				$(sdk_build_prop_remove)))" $< > $@.tmp
    413 	$(hide) for x in $(sdk_build_prop_remove); do \
    414 				echo "$$x"generic >> $@.tmp; done
    415 	$(hide) mv $@.tmp $@
    416 
    417 # -----------------------------------------------------------------
    418 # package stats
    419 PACKAGE_STATS_FILE := $(PRODUCT_OUT)/package-stats.txt
    420 PACKAGES_TO_STAT := \
    421     $(sort $(filter $(TARGET_OUT)/% $(TARGET_OUT_DATA)/%, \
    422 	$(filter %.jar %.apk, $(ALL_DEFAULT_INSTALLED_MODULES))))
    423 $(PACKAGE_STATS_FILE): $(PACKAGES_TO_STAT)
    424 	@echo Package stats: $@
    425 	@mkdir -p $(dir $@)
    426 	$(hide) rm -f $@
    427 ifeq ($(PACKAGES_TO_STAT),)
    428 # Create empty package stats file if target builds no jar(s) or apk(s).
    429 	$(hide) touch $@
    430 else
    431 	$(hide) build/tools/dump-package-stats $^ > $@
    432 endif
    433 
    434 .PHONY: package-stats
    435 package-stats: $(PACKAGE_STATS_FILE)
    436 
    437 # -----------------------------------------------------------------
    438 # Cert-to-package mapping.  Used by the post-build signing tools.
    439 # Use a macro to add newline to each echo command
    440 define _apkcerts_write_line
    441 $(hide) echo -n 'name="$(1).apk" certificate="$2" private_key="$3"' >> $5
    442 $(if $(4), $(hide) echo -n ' compressed="$4"' >> $5)
    443 $(hide) echo '' >> $5
    444 
    445 endef
    446 
    447 name := $(TARGET_PRODUCT)
    448 ifeq ($(TARGET_BUILD_TYPE),debug)
    449   name := $(name)_debug
    450 endif
    451 name := $(name)-apkcerts-$(FILE_NAME_TAG)
    452 intermediates := \
    453 	$(call intermediates-dir-for,PACKAGING,apkcerts)
    454 APKCERTS_FILE := $(intermediates)/$(name).txt
    455 # We don't need to really build all the modules.
    456 # TODO: rebuild APKCERTS_FILE if any app change its cert.
    457 $(APKCERTS_FILE):
    458 	@echo APK certs list: $@
    459 	@mkdir -p $(dir $@)
    460 	@rm -f $@
    461 	$(foreach p,$(PACKAGES),\
    462 	  $(if $(PACKAGES.$(p).EXTERNAL_KEY),\
    463 	    $(call _apkcerts_write_line,$(p),"EXTERNAL","",$(PACKAGES.$(p).COMPRESSED),$@),\
    464 	    $(call _apkcerts_write_line,$(p),$(PACKAGES.$(p).CERTIFICATE),$(PACKAGES.$(p).PRIVATE_KEY),$(PACKAGES.$(p).COMPRESSED),$@)))
    465 	# In case value of PACKAGES is empty.
    466 	$(hide) touch $@
    467 
    468 .PHONY: apkcerts-list
    469 apkcerts-list: $(APKCERTS_FILE)
    470 
    471 ifneq (,$(TARGET_BUILD_APPS))
    472   $(call dist-for-goals, apps_only, $(APKCERTS_FILE):apkcerts.txt)
    473 endif
    474 
    475 # -----------------------------------------------------------------
    476 # build system stats
    477 BUILD_SYSTEM_STATS := $(PRODUCT_OUT)/build_system_stats.txt
    478 $(BUILD_SYSTEM_STATS):
    479 	@rm -f $@
    480 	@$(foreach s,$(STATS.MODULE_TYPE),echo "modules_type_make,$(s),$(words $(STATS.MODULE_TYPE.$(s)))" >>$@;)
    481 	@$(foreach s,$(STATS.SOONG_MODULE_TYPE),echo "modules_type_soong,$(s),$(STATS.SOONG_MODULE_TYPE.$(s))" >>$@;)
    482 $(call dist-for-goals,droidcore,$(BUILD_SYSTEM_STATS))
    483 
    484 # -----------------------------------------------------------------
    485 # Modules ready to be converted to Soong, ordered by how many
    486 # modules depend on them.
    487 SOONG_CONV := $(sort $(SOONG_CONV))
    488 SOONG_CONV_DATA := $(call intermediates-dir-for,PACKAGING,soong_conversion)/soong_conv_data
    489 $(SOONG_CONV_DATA):
    490 	@rm -f $@
    491 	@$(foreach s,$(SOONG_CONV),echo "$(s),$(sort $(SOONG_CONV.$(s).PROBLEMS)),$(sort $(filter-out $(SOONG_ALREADY_CONV),$(SOONG_CONV.$(s).DEPS)))" >>$@;)
    492 
    493 SOONG_TO_CONVERT_SCRIPT := build/tools/soong_to_convert.py
    494 SOONG_TO_CONVERT := $(PRODUCT_OUT)/soong_to_convert.txt
    495 $(SOONG_TO_CONVERT): $(SOONG_CONV_DATA) $(SOONG_TO_CONVERT_SCRIPT)
    496 	@rm -f $@
    497 	$(hide) $(SOONG_TO_CONVERT_SCRIPT) $< >$@
    498 $(call dist-for-goals,droidcore,$(SOONG_TO_CONVERT))
    499 
    500 # -----------------------------------------------------------------
    501 # The dev key is used to sign this package, and as the key required
    502 # for future OTA packages installed by this system.  Actual product
    503 # deliverables will be re-signed by hand.  We expect this file to
    504 # exist with the suffixes ".x509.pem" and ".pk8".
    505 DEFAULT_KEY_CERT_PAIR := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
    506 
    507 
    508 # Rules that need to be present for the all targets, even
    509 # if they don't do anything.
    510 .PHONY: systemimage
    511 systemimage:
    512 
    513 # -----------------------------------------------------------------
    514 
    515 .PHONY: event-log-tags
    516 
    517 # Produce an event logs tag file for everything we know about, in order
    518 # to properly allocate numbers.  Then produce a file that's filtered
    519 # for what's going to be installed.
    520 
    521 all_event_log_tags_file := $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
    522 
    523 event_log_tags_file := $(TARGET_OUT)/etc/event-log-tags
    524 
    525 # Include tags from all packages that we know about
    526 all_event_log_tags_src := \
    527     $(sort $(foreach m, $(ALL_MODULES), $(ALL_MODULES.$(m).EVENT_LOG_TAGS)))
    528 
    529 # PDK builds will already have a full list of tags that needs to get merged
    530 # in with the ones from source
    531 pdk_fusion_log_tags_file := $(patsubst $(PRODUCT_OUT)/%,$(_pdk_fusion_intermediates)/%,$(filter $(event_log_tags_file),$(ALL_PDK_FUSION_FILES)))
    532 
    533 $(all_event_log_tags_file): PRIVATE_SRC_FILES := $(all_event_log_tags_src) $(pdk_fusion_log_tags_file)
    534 $(all_event_log_tags_file): $(all_event_log_tags_src) $(pdk_fusion_log_tags_file) $(MERGETAGS) build/tools/event_log_tags.py
    535 	$(hide) mkdir -p $(dir $@)
    536 	$(hide) $(MERGETAGS) -o $@ $(PRIVATE_SRC_FILES)
    537 
    538 # Include tags from all packages included in this product, plus all
    539 # tags that are part of the system (ie, not in a vendor/ or device/
    540 # directory).
    541 event_log_tags_src := \
    542     $(sort $(foreach m,\
    543       $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES) \
    544       $(call module-names-for-tag-list,user), \
    545       $(ALL_MODULES.$(m).EVENT_LOG_TAGS)) \
    546       $(filter-out vendor/% device/% out/%,$(all_event_log_tags_src)))
    547 
    548 $(event_log_tags_file): PRIVATE_SRC_FILES := $(event_log_tags_src) $(pdk_fusion_log_tags_file)
    549 $(event_log_tags_file): PRIVATE_MERGED_FILE := $(all_event_log_tags_file)
    550 $(event_log_tags_file): $(event_log_tags_src) $(all_event_log_tags_file) $(pdk_fusion_log_tags_file) $(MERGETAGS) build/tools/event_log_tags.py
    551 	$(hide) mkdir -p $(dir $@)
    552 	$(hide) $(MERGETAGS) -o $@ -m $(PRIVATE_MERGED_FILE) $(PRIVATE_SRC_FILES)
    553 
    554 event-log-tags: $(event_log_tags_file)
    555 
    556 ALL_DEFAULT_INSTALLED_MODULES += $(event_log_tags_file)
    557 
    558 
    559 # #################################################################
    560 # Targets for boot/OS images
    561 # #################################################################
    562 ifneq ($(strip $(TARGET_NO_BOOTLOADER)),true)
    563   INSTALLED_BOOTLOADER_MODULE := $(PRODUCT_OUT)/bootloader
    564   ifeq ($(strip $(TARGET_BOOTLOADER_IS_2ND)),true)
    565     INSTALLED_2NDBOOTLOADER_TARGET := $(PRODUCT_OUT)/2ndbootloader
    566   else
    567     INSTALLED_2NDBOOTLOADER_TARGET :=
    568   endif
    569 else
    570   INSTALLED_BOOTLOADER_MODULE :=
    571   INSTALLED_2NDBOOTLOADER_TARGET :=
    572 endif # TARGET_NO_BOOTLOADER
    573 ifneq ($(strip $(TARGET_NO_KERNEL)),true)
    574   INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
    575 else
    576   INSTALLED_KERNEL_TARGET :=
    577 endif
    578 
    579 # -----------------------------------------------------------------
    580 # the ramdisk
    581 INTERNAL_RAMDISK_FILES := $(filter $(TARGET_ROOT_OUT)/%, \
    582 	$(ALL_GENERATED_SOURCES) \
    583 	$(ALL_DEFAULT_INSTALLED_MODULES))
    584 
    585 BUILT_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img
    586 
    587 # We just build this directly to the install location.
    588 INSTALLED_RAMDISK_TARGET := $(BUILT_RAMDISK_TARGET)
    589 $(INSTALLED_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_RAMDISK_FILES) | $(MINIGZIP)
    590 	$(call pretty,"Target ram disk: $@")
    591 	$(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_ROOT_OUT) | $(MINIGZIP) > $@
    592 
    593 .PHONY: ramdisk-nodeps
    594 ramdisk-nodeps: $(MKBOOTFS) | $(MINIGZIP)
    595 	@echo "make $@: ignoring dependencies"
    596 	$(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_ROOT_OUT) | $(MINIGZIP) > $(INSTALLED_RAMDISK_TARGET)
    597 
    598 ifneq ($(strip $(TARGET_NO_KERNEL)),true)
    599 
    600 # -----------------------------------------------------------------
    601 # the boot image, which is a collection of other images.
    602 INTERNAL_BOOTIMAGE_ARGS := \
    603 	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
    604 	--kernel $(INSTALLED_KERNEL_TARGET)
    605 
    606 ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
    607 INTERNAL_BOOTIMAGE_ARGS += --ramdisk $(INSTALLED_RAMDISK_TARGET)
    608 endif
    609 
    610 INTERNAL_BOOTIMAGE_FILES := $(filter-out --%,$(INTERNAL_BOOTIMAGE_ARGS))
    611 
    612 ifdef BOARD_KERNEL_BASE
    613   INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
    614 endif
    615 
    616 ifdef BOARD_KERNEL_PAGESIZE
    617   INTERNAL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
    618 endif
    619 
    620 ifeq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),true)
    621 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
    622 VERITY_KEYID := veritykeyid=id:`openssl x509 -in $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem -text \
    623                 | grep keyid | sed 's/://g' | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]' | sed 's/keyid//g'`
    624 endif
    625 endif
    626 
    627 INTERNAL_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE) buildvariant=$(TARGET_BUILD_VARIANT) $(VERITY_KEYID))
    628 ifdef INTERNAL_KERNEL_CMDLINE
    629 INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)"
    630 endif
    631 
    632 INTERNAL_MKBOOTIMG_VERSION_ARGS := \
    633     --os_version $(PLATFORM_VERSION) \
    634     --os_patch_level $(PLATFORM_SECURITY_PATCH)
    635 
    636 INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
    637 
    638 # BOARD_USES_RECOVERY_AS_BOOT = true must have BOARD_BUILD_SYSTEM_ROOT_IMAGE = true.
    639 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
    640 ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
    641   $(error BOARD_BUILD_SYSTEM_ROOT_IMAGE must be enabled for BOARD_USES_RECOVERY_AS_BOOT.)
    642 endif
    643 endif
    644 
    645 # We build recovery as boot image if BOARD_USES_RECOVERY_AS_BOOT is true.
    646 ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
    647 ifeq ($(TARGET_BOOTIMAGE_USE_EXT2),true)
    648 $(error TARGET_BOOTIMAGE_USE_EXT2 is not supported anymore)
    649 
    650 else ifeq (true,$(BOARD_AVB_ENABLE)) # TARGET_BOOTIMAGE_USE_EXT2 != true
    651 
    652 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(AVBTOOL) $(INTERNAL_BOOTIMAGE_FILES) $(BOARD_AVB_BOOT_KEY_PATH)
    653 	$(call pretty,"Target boot image: $@")
    654 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
    655 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    656 	$(hide) $(AVBTOOL) add_hash_footer \
    657 	  --image $@ \
    658 	  --partition_size $(BOARD_BOOTIMAGE_PARTITION_SIZE) \
    659 	  --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) \
    660 	  $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)
    661 
    662 .PHONY: bootimage-nodeps
    663 bootimage-nodeps: $(MKBOOTIMG) $(AVBTOOL) $(BOARD_AVB_BOOT_KEY_PATH)
    664 	@echo "make $@: ignoring dependencies"
    665 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
    666 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    667 	$(hide) $(AVBTOOL) add_hash_footer \
    668 	  --image $@ \
    669 	  --partition_size $(BOARD_BOOTIMAGE_PARTITION_SIZE) \
    670 	  --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) \
    671 	  $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)
    672 
    673 else ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER)) # BOARD_AVB_ENABLE != true
    674 
    675 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(BOOT_SIGNER)
    676 	$(call pretty,"Target boot image: $@")
    677 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
    678 	$(BOOT_SIGNER) /boot $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $@
    679 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    680 
    681 .PHONY: bootimage-nodeps
    682 bootimage-nodeps: $(MKBOOTIMG) $(BOOT_SIGNER)
    683 	@echo "make $@: ignoring dependencies"
    684 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
    685 	$(BOOT_SIGNER) /boot $(INSTALLED_BOOTIMAGE_TARGET) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $(INSTALLED_BOOTIMAGE_TARGET)
    686 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    687 
    688 else ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)) # PRODUCT_SUPPORTS_BOOT_SIGNER != true
    689 
    690 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(VBOOT_SIGNER) $(FUTILITY)
    691 	$(call pretty,"Target boot image: $@")
    692 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@.unsigned
    693 	$(VBOOT_SIGNER) $(FUTILITY) $@.unsigned $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $@.keyblock $@
    694 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    695 
    696 .PHONY: bootimage-nodeps
    697 bootimage-nodeps: $(MKBOOTIMG) $(VBOOT_SIGNER) $(FUTILITY)
    698 	@echo "make $@: ignoring dependencies"
    699 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET).unsigned
    700 	$(VBOOT_SIGNER) $(FUTILITY) $(INSTALLED_BOOTIMAGE_TARGET).unsigned $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(INSTALLED_BOOTIMAGE_TARGET).keyblock $(INSTALLED_BOOTIMAGE_TARGET)
    701 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    702 
    703 else # PRODUCT_SUPPORTS_VBOOT != true
    704 
    705 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES)
    706 	$(call pretty,"Target boot image: $@")
    707 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
    708 	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    709 
    710 .PHONY: bootimage-nodeps
    711 bootimage-nodeps: $(MKBOOTIMG)
    712 	@echo "make $@: ignoring dependencies"
    713 	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
    714 	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
    715 
    716 endif # TARGET_BOOTIMAGE_USE_EXT2
    717 endif # BOARD_USES_RECOVERY_AS_BOOT
    718 
    719 else	# TARGET_NO_KERNEL
    720 INTERNAL_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE))
    721 # HACK: The top-level targets depend on the bootimage.  Not all targets
    722 # can produce a bootimage, though, and emulator targets need the ramdisk
    723 # instead.  Fake it out by calling the ramdisk the bootimage.
    724 # TODO: make the emulator use bootimages, and make mkbootimg accept
    725 #       kernel-less inputs.
    726 INSTALLED_BOOTIMAGE_TARGET := $(INSTALLED_RAMDISK_TARGET)
    727 endif
    728 
    729 # -----------------------------------------------------------------
    730 # NOTICE files
    731 #
    732 # We are required to publish the licenses for all code under BSD, GPL and
    733 # Apache licenses (and possibly other more exotic ones as well). We err on the
    734 # side of caution, so the licenses for other third-party code are included here
    735 # too.
    736 #
    737 # This needs to be before the systemimage rules, because it adds to
    738 # ALL_DEFAULT_INSTALLED_MODULES, which those use to pick which files
    739 # go into the systemimage.
    740 
    741 .PHONY: notice_files
    742 
    743 # Create the rule to combine the files into text and html/xml forms
    744 # $(1) - xml_excluded_vendor|xml_vendor|html
    745 # $(2) - Plain text output file
    746 # $(3) - HTML/XML output file
    747 # $(4) - File title
    748 # $(5) - Directory to use.  Notice files are all $(4)/src.  Other
    749 #		 directories in there will be used for scratch
    750 # $(6) - Dependencies for the output files
    751 #
    752 # The algorithm here is that we go collect a hash for each of the notice
    753 # files and write the names of the files that match that hash.  Then
    754 # to generate the real files, we go print out all of the files and their
    755 # hashes.
    756 #
    757 # These rules are fairly complex, so they depend on this makefile so if
    758 # it changes, they'll run again.
    759 #
    760 # TODO: We could clean this up so that we just record the locations of the
    761 # original notice files instead of making rules to copy them somwehere.
    762 # Then we could traverse that without quite as much bash drama.
    763 define combine-notice-files
    764 $(2) $(3): PRIVATE_MESSAGE := $(4)
    765 $(2) $(3): PRIVATE_DIR := $(5)
    766 $(2) : $(3)
    767 $(3) : $(6) $(BUILD_SYSTEM)/Makefile build/tools/generate-notice-files.py
    768 	build/tools/generate-notice-files.py --text-output $(2) \
    769 		$(if $(filter $(1),xml_excluded_vendor),-e vendor --xml-output, \
    770 		  $(if $(filter $(1),xml_vendor),-i vendor --xml-output, \
    771 		    --html-output)) $(3) \
    772 		-t $$(PRIVATE_MESSAGE) -s $$(PRIVATE_DIR)/src
    773 notice_files: $(2) $(3)
    774 endef
    775 
    776 # TODO These intermediate NOTICE.txt/NOTICE.html files should go into
    777 # TARGET_OUT_NOTICE_FILES now that the notice files are gathered from
    778 # the src subdirectory.
    779 
    780 target_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE.txt
    781 target_notice_file_html_or_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html
    782 target_notice_file_html_or_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html.gz
    783 installed_notice_html_or_xml_gz := $(TARGET_OUT)/etc/NOTICE.html.gz
    784 tools_notice_file_txt := $(HOST_OUT_INTERMEDIATES)/NOTICE.txt
    785 tools_notice_file_html := $(HOST_OUT_INTERMEDIATES)/NOTICE.html
    786 
    787 ifeq ($(PRODUCT_FULL_TREBLE),true)
    788 target_notice_file_html_or_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE.xml
    789 target_notice_file_html_or_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.xml.gz
    790 installed_notice_html_or_xml_gz := $(TARGET_OUT)/etc/NOTICE.xml.gz
    791 
    792 target_vendor_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.txt
    793 target_vendor_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.xml
    794 target_vendor_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.xml.gz
    795 installed_vendor_notice_xml_gz := $(TARGET_OUT_VENDOR)/etc/NOTICE.xml.gz
    796 endif
    797 
    798 ifndef TARGET_BUILD_APPS
    799 kernel_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/kernel.txt
    800 winpthreads_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/winpthreads.txt
    801 pdk_fusion_notice_files := $(filter $(TARGET_OUT_NOTICE_FILES)/%, $(ALL_PDK_FUSION_FILES))
    802 
    803 ifdef target_vendor_notice_file_xml_gz
    804 $(eval $(call combine-notice-files, xml_excluded_vendor, \
    805 			$(target_notice_file_txt), \
    806 			$(target_notice_file_html_or_xml), \
    807 			"Notices for files contained in the filesystem images in this directory:", \
    808 			$(TARGET_OUT_NOTICE_FILES), \
    809 			$(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file) $(pdk_fusion_notice_files)))
    810 $(eval $(call combine-notice-files, xml_vendor, \
    811 			$(target_vendor_notice_file_txt), \
    812 			$(target_vendor_notice_file_xml), \
    813 			"Notices for files contained in the vendor filesystem image in this directory:", \
    814 			$(TARGET_OUT_NOTICE_FILES), \
    815 			$(target_notice_file_html_or_xml)))
    816 else
    817 $(eval $(call combine-notice-files, html, \
    818 			$(target_notice_file_txt), \
    819 			$(target_notice_file_html_or_xml), \
    820 			"Notices for files contained in the filesystem images in this directory:", \
    821 			$(TARGET_OUT_NOTICE_FILES), \
    822 			$(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file) $(pdk_fusion_notice_files)))
    823 endif
    824 
    825 $(eval $(call combine-notice-files, html, \
    826 			$(tools_notice_file_txt), \
    827 			$(tools_notice_file_html), \
    828 			"Notices for files contained in the tools directory:", \
    829 			$(HOST_OUT_NOTICE_FILES), \
    830 			$(ALL_DEFAULT_INSTALLED_MODULES) \
    831 			$(winpthreads_notice_file)))
    832 
    833 # Install the html file at /system/etc/NOTICE.html.gz.
    834 # This is not ideal, but this is very late in the game, after a lot of
    835 # the module processing has already been done -- in fact, we used the
    836 # fact that all that has been done to get the list of modules that we
    837 # need notice files for.
    838 $(target_notice_file_html_or_xml_gz): $(target_notice_file_html_or_xml) | $(MINIGZIP)
    839 	$(hide) $(MINIGZIP) -9 < $< > $@
    840 $(installed_notice_html_or_xml_gz): $(target_notice_file_html_or_xml_gz)
    841 	$(copy-file-to-target)
    842 
    843 ifdef target_vendor_notice_file_xml_gz
    844 # Install the vendor html file at /vendor/etc/NOTICE.xml.gz.
    845 $(target_vendor_notice_file_xml_gz): $(target_vendor_notice_file_xml) | $(MINIGZIP)
    846 	$(hide) $(MINIGZIP) -9 < $< > $@
    847 $(installed_vendor_notice_xml_gz): $(target_vendor_notice_file_xml_gz)
    848 	$(copy-file-to-target)
    849 endif
    850 
    851 # if we've been run my mm, mmm, etc, don't reinstall this every time
    852 ifeq ($(ONE_SHOT_MAKEFILE),)
    853   ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_or_xml_gz)
    854   ifdef target_vendor_notice_file_xml_gz
    855     ALL_DEFAULT_INSTALLED_MODULES += $(installed_vendor_notice_xml_gz)
    856   endif
    857 endif
    858 endif  # TARGET_BUILD_APPS
    859 
    860 # The kernel isn't really a module, so to get its module file in there, we
    861 # make the target NOTICE files depend on this particular file too, which will
    862 # then be in the right directory for the find in combine-notice-files to work.
    863 $(kernel_notice_file): \
    864 	    $(BUILD_SYSTEM)/LINUX_KERNEL_COPYING \
    865 	    | $(ACP)
    866 	@echo Copying: $@
    867 	$(hide) mkdir -p $(dir $@)
    868 	$(hide) $(ACP) $< $@
    869 
    870 $(winpthreads_notice_file): \
    871 	    $(BUILD_SYSTEM)/WINPTHREADS_COPYING \
    872 	    | $(ACP)
    873 	@echo Copying: $@
    874 	$(hide) mkdir -p $(dir $@)
    875 	$(hide) $(ACP) $< $@
    876 
    877 # -----------------------------------------------------------------
    878 # Build a keystore with the authorized keys in it, used to verify the
    879 # authenticity of downloaded OTA packages.
    880 #
    881 # This rule adds to ALL_DEFAULT_INSTALLED_MODULES, so it needs to come
    882 # before the rules that use that variable to build the image.
    883 ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_ETC)/security/otacerts.zip
    884 $(TARGET_OUT_ETC)/security/otacerts.zip: KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
    885 $(TARGET_OUT_ETC)/security/otacerts.zip: $(addsuffix .x509.pem,$(DEFAULT_KEY_CERT_PAIR)) | $(ZIPTIME)
    886 	$(hide) rm -f $@
    887 	$(hide) mkdir -p $(dir $@)
    888 	$(hide) zip -qjX $@ $<
    889 	$(remove-timestamps-from-package)
    890 
    891 # Carry the public key for update_engine if it's a non-IoT target that
    892 # uses the AB updater. We use the same key as otacerts but in RSA public key
    893 # format.
    894 ifeq ($(AB_OTA_UPDATER),true)
    895 ifneq ($(PRODUCT_IOT),true)
    896 ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem
    897 $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem: $(addsuffix .x509.pem,$(DEFAULT_KEY_CERT_PAIR))
    898 	$(hide) rm -f $@
    899 	$(hide) mkdir -p $(dir $@)
    900 	$(hide) openssl x509 -pubkey -noout -in $< > $@
    901 
    902 ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_RECOVERY_ROOT_OUT)/etc/update_engine/update-payload-key.pub.pem
    903 $(TARGET_RECOVERY_ROOT_OUT)/etc/update_engine/update-payload-key.pub.pem: $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem
    904 	$(hide) cp -f $< $@
    905 endif
    906 endif
    907 
    908 .PHONY: otacerts
    909 otacerts: $(TARGET_OUT_ETC)/security/otacerts.zip
    910 
    911 
    912 # #################################################################
    913 # Targets for user images
    914 # #################################################################
    915 
    916 INTERNAL_USERIMAGES_EXT_VARIANT :=
    917 ifeq ($(TARGET_USERIMAGES_USE_EXT2),true)
    918 INTERNAL_USERIMAGES_USE_EXT := true
    919 INTERNAL_USERIMAGES_EXT_VARIANT := ext2
    920 else
    921 ifeq ($(TARGET_USERIMAGES_USE_EXT3),true)
    922 INTERNAL_USERIMAGES_USE_EXT := true
    923 INTERNAL_USERIMAGES_EXT_VARIANT := ext3
    924 else
    925 ifeq ($(TARGET_USERIMAGES_USE_EXT4),true)
    926 INTERNAL_USERIMAGES_USE_EXT := true
    927 INTERNAL_USERIMAGES_EXT_VARIANT := ext4
    928 endif
    929 endif
    930 endif
    931 
    932 # These options tell the recovery updater/installer how to mount the partitions writebale.
    933 # <fstype>=<fstype_opts>[|<fstype_opts>]...
    934 # fstype_opts := <opt>[,<opt>]...
    935 #         opt := <name>[=<value>]
    936 # The following worked on Nexus devices with Kernel 3.1, 3.4, 3.10
    937 DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS := ext4=max_batch_time=0,commit=1,data=ordered,barrier=1,errors=panic,nodelalloc
    938 
    939 ifneq (true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED))
    940   INTERNAL_USERIMAGES_SPARSE_EXT_FLAG := -s
    941 endif
    942 
    943 ifeq ($(INTERNAL_USERIMAGES_USE_EXT),true)
    944 INTERNAL_USERIMAGES_DEPS := $(SIMG2IMG)
    945 INTERNAL_USERIMAGES_DEPS += $(MKEXTUSERIMG) $(MAKE_EXT4FS) $(E2FSCK)
    946 ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
    947 INTERNAL_USERIMAGES_DEPS += $(MKF2FSUSERIMG) $(MAKE_F2FS)
    948 endif
    949 endif
    950 
    951 ifeq ($(BOARD_AVB_ENABLE),true)
    952 INTERNAL_USERIMAGES_DEPS += $(AVBTOOL)
    953 endif
    954 
    955 ifneq (true,$(TARGET_USERIMAGES_SPARSE_SQUASHFS_DISABLED))
    956   INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG := -s
    957 endif
    958 ifneq ($(filter $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE) $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE),squashfs),)
    959 INTERNAL_USERIMAGES_DEPS += $(MAKE_SQUASHFS) $(MKSQUASHFSUSERIMG) $(IMG2SIMG)
    960 endif
    961 
    962 INTERNAL_USERIMAGES_BINARY_PATHS := $(sort $(dir $(INTERNAL_USERIMAGES_DEPS)))
    963 
    964 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY))
    965 INTERNAL_USERIMAGES_DEPS += $(BUILD_VERITY_TREE) $(APPEND2SIMG) $(VERITY_SIGNER)
    966 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC))
    967 INTERNAL_USERIMAGES_DEPS += $(FEC)
    968 endif
    969 endif
    970 
    971 SELINUX_FC := $(call intermediates-dir-for,ETC,file_contexts.bin)/file_contexts.bin
    972 INTERNAL_USERIMAGES_DEPS += $(SELINUX_FC)
    973 
    974 INTERNAL_USERIMAGES_DEPS += $(BLK_ALLOC_TO_BASE_FS)
    975 
    976 ifeq ($(INTERNAL_USERIMAGES_USE_EXT),true)
    977 INTERNAL_USERIMAGES_DEPS += $(MKE2FS_CONF)
    978 endif
    979 
    980 # $(1): the path of the output dictionary file
    981 # $(2): additional "key=value" pairs to append to the dictionary file.
    982 define generate-userimage-prop-dictionary
    983 $(hide) echo "ext_mkuserimg=$(notdir $(MKEXTUSERIMG))" >> $(1)
    984 $(if $(INTERNAL_USERIMAGES_EXT_VARIANT),$(hide) echo "fs_type=$(INTERNAL_USERIMAGES_EXT_VARIANT)" >> $(1))
    985 $(if $(BOARD_SYSTEMIMAGE_PARTITION_SIZE),$(hide) echo "system_size=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE)" >> $(1))
    986 $(if $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "system_fs_type=$(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    987 $(if $(BOARD_SYSTEMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "system_extfs_inode_count=$(BOARD_SYSTEMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
    988 $(if $(BOARD_SYSTEMIMAGE_JOURNAL_SIZE),$(hide) echo "system_journal_size=$(BOARD_SYSTEMIMAGE_JOURNAL_SIZE)" >> $(1))
    989 $(if $(BOARD_HAS_EXT4_RESERVED_BLOCKS),$(hide) echo "has_ext4_reserved_blocks=$(BOARD_HAS_EXT4_RESERVED_BLOCKS)" >> $(1))
    990 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "system_squashfs_compressor=$(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
    991 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "system_squashfs_compressor_opt=$(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
    992 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "system_squashfs_block_size=$(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
    993 $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "system_squashfs_disable_4k_align=$(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
    994 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH),$(hide) echo "system_base_fs_file=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH)" >> $(1))
    995 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_HEADROOM),$(hide) echo "system_headroom=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_HEADROOM)" >> $(1))
    996 $(if $(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "userdata_fs_type=$(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
    997 $(if $(BOARD_USERDATAIMAGE_PARTITION_SIZE),$(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(1))
    998 $(if $(BOARD_FLASH_LOGICAL_BLOCK_SIZE), $(hide) echo "flash_logical_block_size=$(BOARD_FLASH_LOGICAL_BLOCK_SIZE)" >> $(1))
    999 $(if $(BOARD_FLASH_ERASE_BLOCK_SIZE), $(hide) echo "flash_erase_block_size=$(BOARD_FLASH_ERASE_BLOCK_SIZE)" >> $(1))
   1000 $(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
   1001 $(if $(BOARD_CACHEIMAGE_PARTITION_SIZE),$(hide) echo "cache_size=$(BOARD_CACHEIMAGE_PARTITION_SIZE)" >> $(1))
   1002 $(if $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "vendor_fs_type=$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
   1003 $(if $(BOARD_VENDORIMAGE_EXTFS_INODE_COUNT),$(hide) echo "vendor_extfs_inode_count=$(BOARD_VENDORIMAGE_EXTFS_INODE_COUNT)" >> $(1))
   1004 $(if $(BOARD_VENDORIMAGE_PARTITION_SIZE),$(hide) echo "vendor_size=$(BOARD_VENDORIMAGE_PARTITION_SIZE)" >> $(1))
   1005 $(if $(BOARD_VENDORIMAGE_JOURNAL_SIZE),$(hide) echo "vendor_journal_size=$(BOARD_VENDORIMAGE_JOURNAL_SIZE)" >> $(1))
   1006 $(if $(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "vendor_squashfs_compressor=$(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
   1007 $(if $(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "vendor_squashfs_compressor_opt=$(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
   1008 $(if $(BOARD_VENDORIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "vendor_squashfs_block_size=$(BOARD_VENDORIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
   1009 $(if $(BOARD_VENDORIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "vendor_squashfs_disable_4k_align=$(BOARD_VENDORIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
   1010 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH),$(hide) echo "vendor_base_fs_file=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH)" >> $(1))
   1011 $(if $(BOARD_OEMIMAGE_PARTITION_SIZE),$(hide) echo "oem_size=$(BOARD_OEMIMAGE_PARTITION_SIZE)" >> $(1))
   1012 $(if $(BOARD_OEMIMAGE_JOURNAL_SIZE),$(hide) echo "oem_journal_size=$(BOARD_OEMIMAGE_JOURNAL_SIZE)" >> $(1))
   1013 $(if $(BOARD_OEMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "oem_extfs_inode_count=$(BOARD_OEMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
   1014 $(if $(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG),$(hide) echo "extfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG)" >> $(1))
   1015 $(if $(INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG),$(hide) echo "squashfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG)" >> $(1))
   1016 $(hide) echo "selinux_fc=$(SELINUX_FC)" >> $(1)
   1017 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER),$(hide) echo "boot_signer=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER)" >> $(1))
   1018 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY)" >> $(1))
   1019 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_key=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY)" >> $(1))
   1020 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_signer_cmd=$(notdir $(VERITY_SIGNER))" >> $(1))
   1021 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC),$(hide) echo "verity_fec=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY_FEC)" >> $(1))
   1022 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION),$(hide) echo "system_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION)" >> $(1))
   1023 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION),$(hide) echo "vendor_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION)" >> $(1))
   1024 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)" >> $(1))
   1025 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_key=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY)" >> $(1))
   1026 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_subkey=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY)" >> $(1))
   1027 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "futility=$(notdir $(FUTILITY))" >> $(1))
   1028 $(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_signer_cmd=$(VBOOT_SIGNER)" >> $(1))
   1029 $(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_avbtool=$(notdir $(AVBTOOL))" >> $(1))
   1030 $(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
   1031 $(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_add_hashtree_footer_args=$(BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
   1032 $(if $(BOARD_AVB_ENABLE),\
   1033     $(if $(BOARD_AVB_SYSTEM_KEY_PATH),\
   1034         $(hide) echo "avb_system_key_path=$(BOARD_AVB_SYSTEM_KEY_PATH)" >> $(1)
   1035         $(hide) echo "avb_system_algorithm=$(BOARD_AVB_SYSTEM_ALGORITHM)" >> $(1)
   1036         $(hide) echo "avb_system_rollback_index_location=$(BOARD_AVB_SYSTEM_ROLLBACK_INDEX_LOCATION)" >> $(1)))
   1037 $(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_vendor_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
   1038 $(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_vendor_add_hashtree_footer_args=$(BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
   1039 $(if $(BOARD_AVB_ENABLE),\
   1040     $(if $(BOARD_AVB_VENDOR_KEY_PATH),\
   1041         $(hide) echo "avb_vendor_key_path=$(BOARD_AVB_VENDOR_KEY_PATH)" >> $(1)
   1042         $(hide) echo "avb_vendor_algorithm=$(BOARD_AVB_VENDOR_ALGORITHM)" >> $(1)
   1043         $(hide) echo "avb_vendor_rollback_index_location=$(BOARD_AVB_VENDOR_ROLLBACK_INDEX_LOCATION)" >> $(1)))
   1044 $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
   1045     $(hide) echo "recovery_as_boot=true" >> $(1))
   1046 $(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)),\
   1047     $(hide) echo "system_root_image=true" >> $(1);\
   1048     echo "ramdisk_dir=$(TARGET_ROOT_OUT)" >> $(1))
   1049 $(if $(2),$(hide) $(foreach kv,$(2),echo "$(kv)" >> $(1);))
   1050 endef
   1051 
   1052 # -----------------------------------------------------------------
   1053 # Recovery image
   1054 
   1055 # Recovery image exists if we are building recovery, or building recovery as boot.
   1056 ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)))
   1057 
   1058 INTERNAL_RECOVERYIMAGE_FILES := $(filter $(TARGET_RECOVERY_OUT)/%, \
   1059     $(ALL_DEFAULT_INSTALLED_MODULES))
   1060 
   1061 recovery_initrc := $(call include-path-for, recovery)/etc/init.rc
   1062 recovery_sepolicy := \
   1063     $(TARGET_RECOVERY_ROOT_OUT)/sepolicy \
   1064     $(TARGET_RECOVERY_ROOT_OUT)/plat_file_contexts \
   1065     $(TARGET_RECOVERY_ROOT_OUT)/nonplat_file_contexts \
   1066     $(TARGET_RECOVERY_ROOT_OUT)/plat_property_contexts \
   1067     $(TARGET_RECOVERY_ROOT_OUT)/nonplat_property_contexts
   1068 # Passed into rsync from non-recovery root to recovery root, to avoid overwriting recovery-specific
   1069 # SELinux files
   1070 IGNORE_RECOVERY_SEPOLICY := $(patsubst $(TARGET_RECOVERY_OUT)/%,--exclude=/%,$(recovery_sepolicy))
   1071 
   1072 recovery_kernel := $(INSTALLED_KERNEL_TARGET) # same as a non-recovery system
   1073 recovery_ramdisk := $(PRODUCT_OUT)/ramdisk-recovery.img
   1074 recovery_build_props := $(intermediate_system_build_prop)
   1075 ifdef property_overrides_split_enabled
   1076 recovery_build_props += $(INSTALLED_VENDOR_BUILD_PROP_TARGET)
   1077 endif
   1078 recovery_resources_common := $(call include-path-for, recovery)/res
   1079 
   1080 # Set recovery_density to the density bucket of the device.
   1081 recovery_density := unknown
   1082 ifneq (,$(PRODUCT_AAPT_PREF_CONFIG))
   1083 # If PRODUCT_AAPT_PREF_CONFIG includes a dpi bucket, then use that value.
   1084 recovery_density := $(filter %dpi,$(PRODUCT_AAPT_PREF_CONFIG))
   1085 else
   1086 # Otherwise, use the default medium density.
   1087 recovery_densities := mdpi
   1088 endif
   1089 
   1090 ifneq (,$(wildcard $(recovery_resources_common)-$(recovery_density)))
   1091 recovery_resources_common := $(recovery_resources_common)-$(recovery_density)
   1092 else
   1093 recovery_resources_common := $(recovery_resources_common)-xhdpi
   1094 endif
   1095 
   1096 # Select the 18x32 font on high-density devices (xhdpi and up); and
   1097 # the 12x22 font on other devices.  Note that the font selected here
   1098 # can be overridden for a particular device by putting a font.png in
   1099 # its private recovery resources.
   1100 
   1101 ifneq (,$(filter xxxhdpi 560dpi xxhdpi 400dpi xhdpi,$(recovery_density)))
   1102 recovery_font := $(call include-path-for, recovery)/fonts/18x32.png
   1103 else
   1104 recovery_font := $(call include-path-for, recovery)/fonts/12x22.png
   1105 endif
   1106 
   1107 ifndef TARGET_PRIVATE_RES_DIRS
   1108 TARGET_PRIVATE_RES_DIRS := $(wildcard $(TARGET_DEVICE_DIR)/recovery/res)
   1109 endif
   1110 recovery_resource_deps := $(shell find $(recovery_resources_common) \
   1111   $(TARGET_PRIVATE_RES_DIRS) -type f)
   1112 ifdef TARGET_RECOVERY_FSTAB
   1113 recovery_fstab := $(TARGET_RECOVERY_FSTAB)
   1114 else
   1115 recovery_fstab := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery.fstab))
   1116 endif
   1117 ifdef TARGET_RECOVERY_WIPE
   1118 recovery_wipe := $(TARGET_RECOVERY_WIPE)
   1119 else
   1120 recovery_wipe :=
   1121 endif
   1122 
   1123 # Prior to A/B update, we used to have:
   1124 #   boot.img + recovery-from-boot.p + recovery-resource.dat = recovery.img.
   1125 # recovery-resource.dat is needed only if we carry a patch of the boot and
   1126 # recovery images and invoke install-recovery.sh on the first boot post an
   1127 # OTA update.
   1128 #
   1129 # We no longer need that if one of the following conditions holds:
   1130 #   a) We carry a full copy of the recovery image
   1131 #      (BOARD_USES_FULL_RECOVERY_IMAGE = true);
   1132 #   b) We build a single image that contains boot and recovery both
   1133 #      (BOARD_USES_RECOVERY_AS_BOOT = true).
   1134 
   1135 ifeq (,$(filter true, $(BOARD_USES_FULL_RECOVERY_IMAGE) $(BOARD_USES_RECOVERY_AS_BOOT)))
   1136 # Named '.dat' so we don't attempt to use imgdiff for patching it.
   1137 RECOVERY_RESOURCE_ZIP := $(TARGET_OUT)/etc/recovery-resource.dat
   1138 else
   1139 RECOVERY_RESOURCE_ZIP :=
   1140 endif
   1141 
   1142 ifeq ($(TARGET_PRIVATE_RES_DIRS),)
   1143   $(info No private recovery resources for TARGET_DEVICE $(TARGET_DEVICE))
   1144 endif
   1145 
   1146 ifeq ($(recovery_fstab),)
   1147   $(info No recovery.fstab for TARGET_DEVICE $(TARGET_DEVICE))
   1148 endif
   1149 
   1150 INTERNAL_RECOVERYIMAGE_ARGS := \
   1151 	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
   1152 	--kernel $(recovery_kernel) \
   1153 	--ramdisk $(recovery_ramdisk)
   1154 
   1155 # Assumes this has already been stripped
   1156 ifdef INTERNAL_KERNEL_CMDLINE
   1157   INTERNAL_RECOVERYIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)"
   1158 endif
   1159 ifdef BOARD_KERNEL_BASE
   1160   INTERNAL_RECOVERYIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
   1161 endif
   1162 ifdef BOARD_KERNEL_PAGESIZE
   1163   INTERNAL_RECOVERYIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
   1164 endif
   1165 
   1166 # Keys authorized to sign OTA packages this build will accept.  The
   1167 # build always uses dev-keys for this; release packaging tools will
   1168 # substitute other keys for this one.
   1169 OTA_PUBLIC_KEYS := $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem
   1170 
   1171 # Generate a file containing the keys that will be read by the
   1172 # recovery binary.
   1173 RECOVERY_INSTALL_OTA_KEYS := \
   1174 	$(call intermediates-dir-for,PACKAGING,ota_keys)/keys
   1175 DUMPKEY_JAR := $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar
   1176 $(RECOVERY_INSTALL_OTA_KEYS): PRIVATE_OTA_PUBLIC_KEYS := $(OTA_PUBLIC_KEYS)
   1177 $(RECOVERY_INSTALL_OTA_KEYS): extra_keys := $(patsubst %,%.x509.pem,$(PRODUCT_EXTRA_RECOVERY_KEYS))
   1178 $(RECOVERY_INSTALL_OTA_KEYS): $(OTA_PUBLIC_KEYS) $(DUMPKEY_JAR) $(extra_keys)
   1179 	@echo "DumpPublicKey: $@ <= $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys)"
   1180 	@rm -rf $@
   1181 	@mkdir -p $(dir $@)
   1182 	$(JAVA) -jar $(DUMPKEY_JAR) $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys) > $@
   1183 
   1184 RECOVERYIMAGE_ID_FILE := $(PRODUCT_OUT)/recovery.id
   1185 
   1186 # $(1): modules list
   1187 # $(2): output dir
   1188 # $(3): mount point
   1189 # $(4): staging dir
   1190 # Depmod requires a well-formed kernel version so 0.0 is used as a placeholder.
   1191 define build-image-kernel-modules
   1192     $(hide) rm -rf $(2)/lib/modules
   1193     $(hide) mkdir -p $(2)/lib/modules
   1194     $(hide) cp $(1) $(2)/lib/modules/
   1195     $(hide) rm -rf $(4)
   1196     $(hide) mkdir -p $(4)/lib/modules/0.0/$(3)lib/modules
   1197     $(hide) cp $(1) $(4)/lib/modules/0.0/$(3)lib/modules
   1198     $(hide) $(DEPMOD) -b $(4) 0.0
   1199     $(hide) sed -e 's/\(.*modules.*\):/\/\1:/g' -e 's/ \([^ ]*modules[^ ]*\)/ \/\1/g' $(4)/lib/modules/0.0/modules.dep > $(2)/lib/modules/modules.dep
   1200     $(hide) cp $(4)/lib/modules/0.0/modules.alias $(2)/lib/modules
   1201 endef
   1202 
   1203 # $(1): output file
   1204 define build-recoveryimage-target
   1205   @echo ----- Making recovery image ------
   1206   $(hide) mkdir -p $(TARGET_RECOVERY_OUT)
   1207   $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/etc $(TARGET_RECOVERY_ROOT_OUT)/sdcard $(TARGET_RECOVERY_ROOT_OUT)/tmp
   1208   @echo Copying baseline ramdisk...
   1209   # Use rsync because "cp -Rf" fails to overwrite broken symlinks on Mac.
   1210   $(hide) rsync -a --exclude=etc --exclude=sdcard $(IGNORE_RECOVERY_SEPOLICY) $(IGNORE_CACHE_LINK) $(TARGET_ROOT_OUT) $(TARGET_RECOVERY_OUT)
   1211   # Copy adbd from system/bin to recovery/root/sbin
   1212   $(hide) cp -f $(TARGET_OUT_EXECUTABLES)/adbd $(TARGET_RECOVERY_ROOT_OUT)/sbin/adbd
   1213   @echo Modifying ramdisk contents...
   1214   $(if $(BOARD_RECOVERY_KERNEL_MODULES), \
   1215     $(call build-image-kernel-modules,$(BOARD_RECOVERY_KERNEL_MODULES),$(TARGET_RECOVERY_ROOT_OUT),,$(call intermediates-dir-for,PACKAGING,depmod_recovery)))
   1216   $(hide) rm -f $(TARGET_RECOVERY_ROOT_OUT)/init*.rc
   1217   $(hide) cp -f $(recovery_initrc) $(TARGET_RECOVERY_ROOT_OUT)/
   1218   $(hide) cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/ || true # Ignore error when the src file doesn't exist.
   1219   $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/res
   1220   $(hide) rm -rf $(TARGET_RECOVERY_ROOT_OUT)/res/*
   1221   $(hide) cp -rf $(recovery_resources_common)/* $(TARGET_RECOVERY_ROOT_OUT)/res
   1222   $(hide) cp -f $(recovery_font) $(TARGET_RECOVERY_ROOT_OUT)/res/images/font.png
   1223   $(hide) $(foreach item,$(TARGET_PRIVATE_RES_DIRS), \
   1224     cp -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/$(newline))
   1225   $(hide) $(foreach item,$(recovery_fstab), \
   1226     cp -f $(item) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.fstab)
   1227   $(if $(strip $(recovery_wipe)), \
   1228     $(hide) cp -f $(recovery_wipe) $(TARGET_RECOVERY_ROOT_OUT)/etc/recovery.wipe)
   1229   $(hide) cp $(RECOVERY_INSTALL_OTA_KEYS) $(TARGET_RECOVERY_ROOT_OUT)/res/keys
   1230   $(hide) cat $(INSTALLED_DEFAULT_PROP_TARGET) \
   1231           > $(TARGET_RECOVERY_ROOT_OUT)/prop.default
   1232   $(if $(INSTALLED_VENDOR_DEFAULT_PROP_TARGET), \
   1233     $(hide) cat $(INSTALLED_VENDOR_DEFAULT_PROP_TARGET) \
   1234             >> $(TARGET_RECOVERY_ROOT_OUT)/prop.default)
   1235   $(hide) cat $(recovery_build_props) \
   1236           >> $(TARGET_RECOVERY_ROOT_OUT)/prop.default
   1237   $(hide) ln -sf prop.default $(TARGET_RECOVERY_ROOT_OUT)/default.prop
   1238   $(BOARD_RECOVERY_IMAGE_PREPARE)
   1239   $(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)), \
   1240     $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/system_root; \
   1241             rm -rf $(TARGET_RECOVERY_ROOT_OUT)/system; \
   1242             ln -sf /system_root/system $(TARGET_RECOVERY_ROOT_OUT)/system) # Mount the system_root_image to /system_root and symlink /system.
   1243   $(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RECOVERY_ROOT_OUT) | $(MINIGZIP) > $(recovery_ramdisk)
   1244   $(if $(filter true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)), \
   1245     $(hide) $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1).unsigned, \
   1246     $(hide) $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1) --id > $(RECOVERYIMAGE_ID_FILE))
   1247   $(if $(filter true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER)),\
   1248     $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
   1249       $(BOOT_SIGNER) /boot $(1) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1),\
   1250       $(BOOT_SIGNER) /recovery $(1) $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1)\
   1251     )\
   1252   )
   1253   $(if $(filter true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT)), \
   1254     $(VBOOT_SIGNER) $(FUTILITY) $(1).unsigned $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(1).keyblock $(1))
   1255   $(if $(and $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),$(filter true,$(BOARD_AVB_ENABLE))), \
   1256       $(hide) $(AVBTOOL) add_hash_footer \
   1257         --image $(1) \
   1258         --partition_size $(BOARD_BOOTIMAGE_PARTITION_SIZE) \
   1259         --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) \
   1260         $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS))
   1261   $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)), \
   1262     $(hide) $(call assert-max-image-size,$(1),$(BOARD_BOOTIMAGE_PARTITION_SIZE)), \
   1263     $(hide) $(call assert-max-image-size,$(1),$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)))
   1264   @echo ----- Made recovery image: $(1) --------
   1265 endef
   1266 
   1267 ADBD := $(TARGET_OUT_EXECUTABLES)/adbd
   1268 
   1269 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
   1270 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_BOOT_SIGNER))
   1271 $(INSTALLED_BOOTIMAGE_TARGET) : $(BOOT_SIGNER)
   1272 endif
   1273 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT))
   1274 $(INSTALLED_BOOTIMAGE_TARGET) : $(VBOOT_SIGNER)
   1275 endif
   1276 ifeq (true,$(BOARD_AVB_ENABLE))
   1277 $(INSTALLED_BOOTIMAGE_TARGET) : $(AVBTOOL) $(BOARD_AVB_BOOT_KEY_PATH)
   1278 endif
   1279 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) $(ADBD) \
   1280 		$(INSTALLED_RAMDISK_TARGET) \
   1281 		$(INTERNAL_RECOVERYIMAGE_FILES) \
   1282 		$(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
   1283 		$(INSTALLED_2NDBOOTLOADER_TARGET) \
   1284 		$(recovery_build_props) $(recovery_resource_deps) \
   1285 		$(recovery_fstab) \
   1286 		$(RECOVERY_INSTALL_OTA_KEYS) \
   1287 		$(INSTALLED_VENDOR_DEFAULT_PROP_TARGET) \
   1288 		$(BOARD_RECOVERY_KERNEL_MODULES) \
   1289 		$(DEPMOD)
   1290 		$(call pretty,"Target boot image from recovery: $@")
   1291 		$(call build-recoveryimage-target, $@)
   1292 endif
   1293 
   1294 $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) $(ADBD) \
   1295 		$(INSTALLED_RAMDISK_TARGET) \
   1296 		$(INSTALLED_BOOTIMAGE_TARGET) \
   1297 		$(INTERNAL_RECOVERYIMAGE_FILES) \
   1298 		$(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
   1299 		$(INSTALLED_2NDBOOTLOADER_TARGET) \
   1300 		$(recovery_build_props) $(recovery_resource_deps) \
   1301 		$(recovery_fstab) \
   1302 		$(RECOVERY_INSTALL_OTA_KEYS) \
   1303 		$(INSTALLED_VENDOR_DEFAULT_PROP_TARGET) \
   1304 		$(BOARD_RECOVERY_KERNEL_MODULES) \
   1305 		$(DEPMOD)
   1306 		$(call build-recoveryimage-target, $@)
   1307 
   1308 ifdef RECOVERY_RESOURCE_ZIP
   1309 $(RECOVERY_RESOURCE_ZIP): $(INSTALLED_RECOVERYIMAGE_TARGET) | $(ZIPTIME)
   1310 	$(hide) mkdir -p $(dir $@)
   1311 	$(hide) find $(TARGET_RECOVERY_ROOT_OUT)/res -type f | sort | zip -0qrjX $@ -@
   1312 	$(remove-timestamps-from-package)
   1313 endif
   1314 
   1315 .PHONY: recoveryimage-nodeps
   1316 recoveryimage-nodeps:
   1317 	@echo "make $@: ignoring dependencies"
   1318 	$(call build-recoveryimage-target, $(INSTALLED_RECOVERYIMAGE_TARGET))
   1319 
   1320 else # INSTALLED_RECOVERYIMAGE_TARGET not defined
   1321 RECOVERY_RESOURCE_ZIP :=
   1322 endif
   1323 
   1324 .PHONY: recoveryimage
   1325 recoveryimage: $(INSTALLED_RECOVERYIMAGE_TARGET) $(RECOVERY_RESOURCE_ZIP)
   1326 
   1327 ifeq ($(BOARD_NAND_PAGE_SIZE),)
   1328 BOARD_NAND_PAGE_SIZE := 2048
   1329 endif
   1330 
   1331 ifeq ($(BOARD_NAND_SPARE_SIZE),)
   1332 BOARD_NAND_SPARE_SIZE := 64
   1333 endif
   1334 
   1335 # -----------------------------------------------------------------
   1336 # system image
   1337 #
   1338 # Remove overridden packages from $(ALL_PDK_FUSION_FILES)
   1339 PDK_FUSION_SYSIMG_FILES := \
   1340     $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
   1341         $(ALL_PDK_FUSION_FILES))
   1342 
   1343 INTERNAL_SYSTEMIMAGE_FILES := $(filter $(TARGET_OUT)/%, \
   1344     $(ALL_GENERATED_SOURCES) \
   1345     $(ALL_DEFAULT_INSTALLED_MODULES) \
   1346     $(PDK_FUSION_SYSIMG_FILES) \
   1347     $(RECOVERY_RESOURCE_ZIP))
   1348 
   1349 FULL_SYSTEMIMAGE_DEPS := $(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_USERIMAGES_DEPS)
   1350 
   1351 # ASAN libraries in the system image - add dependency.
   1352 ASAN_IN_SYSTEM_INSTALLED := $(TARGET_OUT)/asan.tar.bz2
   1353 ifneq (,$(SANITIZE_TARGET))
   1354   ifeq (true,$(SANITIZE_TARGET_SYSTEM))
   1355     FULL_SYSTEMIMAGE_DEPS += $(ASAN_IN_SYSTEM_INSTALLED)
   1356   endif
   1357 endif
   1358 
   1359 # -----------------------------------------------------------------
   1360 # installed file list
   1361 # Depending on anything that $(BUILT_SYSTEMIMAGE) depends on.
   1362 # We put installed-files.txt ahead of image itself in the dependency graph
   1363 # so that we can get the size stat even if the build fails due to too large
   1364 # system image.
   1365 INSTALLED_FILES_FILE := $(PRODUCT_OUT)/installed-files.txt
   1366 $(INSTALLED_FILES_FILE): $(FULL_SYSTEMIMAGE_DEPS) $(FILESLIST)
   1367 	@echo Installed file list: $@
   1368 	@mkdir -p $(dir $@)
   1369 	@rm -f $@
   1370 	$(hide) $(FILESLIST) $(TARGET_OUT) > $(@:.txt=.json)
   1371 	$(hide) build/tools/fileslist_util.py -c $(@:.txt=.json) > $@
   1372 
   1373 .PHONY: installed-file-list
   1374 installed-file-list: $(INSTALLED_FILES_FILE)
   1375 
   1376 $(call dist-for-goals, sdk win_sdk sdk_addon, $(INSTALLED_FILES_FILE))
   1377 
   1378 systemimage_intermediates := \
   1379     $(call intermediates-dir-for,PACKAGING,systemimage)
   1380 BUILT_SYSTEMIMAGE := $(systemimage_intermediates)/system.img
   1381 
   1382 # Create symlink /system/vendor to /vendor if necessary.
   1383 ifdef BOARD_USES_VENDORIMAGE
   1384 define create-system-vendor-symlink
   1385 $(hide) if [ -d $(TARGET_OUT)/vendor ] && [ ! -h $(TARGET_OUT)/vendor ]; then \
   1386   echo 'Non-symlink $(TARGET_OUT)/vendor detected!' 1>&2; \
   1387   echo 'You cannot install files to $(TARGET_OUT)/vendor while building a separate vendor.img!' 1>&2; \
   1388   exit 1; \
   1389 fi
   1390 $(hide) ln -sf /vendor $(TARGET_OUT)/vendor
   1391 endef
   1392 else
   1393 define create-system-vendor-symlink
   1394 endef
   1395 endif
   1396 
   1397 # $(1): output file
   1398 define build-systemimage-target
   1399   @echo "Target system fs image: $(1)"
   1400   $(call create-system-vendor-symlink)
   1401   @mkdir -p $(dir $(1)) $(systemimage_intermediates) && rm -rf $(systemimage_intermediates)/system_image_info.txt
   1402   $(call generate-userimage-prop-dictionary, $(systemimage_intermediates)/system_image_info.txt, \
   1403       skip_fsck=true)
   1404   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1405       ./build/tools/releasetools/build_image.py \
   1406       $(TARGET_OUT) $(systemimage_intermediates)/system_image_info.txt $(1) $(TARGET_OUT) \
   1407       || ( echo "Out of space? the tree size of $(TARGET_OUT) is (MB): " 1>&2 ;\
   1408            du -sm $(TARGET_OUT) 1>&2;\
   1409            if [ "$(INTERNAL_USERIMAGES_EXT_VARIANT)" == "ext4" ]; then \
   1410                maxsize=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE); \
   1411                if [ "$(BOARD_HAS_EXT4_RESERVED_BLOCKS)" == "true" ]; then \
   1412                    maxsize=$$((maxsize - 4096 * 4096)); \
   1413                fi; \
   1414                echo "The max is $$(( maxsize / 1048576 )) MB." 1>&2 ;\
   1415            else \
   1416                echo "The max is $$(( $(BOARD_SYSTEMIMAGE_PARTITION_SIZE) / 1048576 )) MB." 1>&2 ;\
   1417            fi; \
   1418            mkdir -p $(DIST_DIR); cp $(INSTALLED_FILES_FILE) $(DIST_DIR)/installed-files-rescued.txt; \
   1419            exit 1 )
   1420 endef
   1421 
   1422 $(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE) $(BUILD_IMAGE_SRCS)
   1423 	$(call build-systemimage-target,$@)
   1424 
   1425 INSTALLED_SYSTEMIMAGE := $(PRODUCT_OUT)/system.img
   1426 SYSTEMIMAGE_SOURCE_DIR := $(TARGET_OUT)
   1427 
   1428 # The system partition needs room for the recovery image as well.  We
   1429 # now store the recovery image as a binary patch using the boot image
   1430 # as the source (since they are very similar).  Generate the patch so
   1431 # we can see how big it's going to be, and include that in the system
   1432 # image size check calculation.
   1433 ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   1434 ifneq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
   1435 intermediates := $(call intermediates-dir-for,PACKAGING,recovery_patch)
   1436 RECOVERY_FROM_BOOT_PATCH := $(intermediates)/recovery_from_boot.p
   1437 $(RECOVERY_FROM_BOOT_PATCH): $(INSTALLED_RECOVERYIMAGE_TARGET) \
   1438                              $(INSTALLED_BOOTIMAGE_TARGET) \
   1439 			     $(HOST_OUT_EXECUTABLES)/imgdiff \
   1440 	                     $(HOST_OUT_EXECUTABLES)/bsdiff
   1441 	@echo "Construct recovery from boot"
   1442 	mkdir -p $(dir $@)
   1443 	PATH=$(HOST_OUT_EXECUTABLES):$$PATH $(HOST_OUT_EXECUTABLES)/imgdiff $(INSTALLED_BOOTIMAGE_TARGET) $(INSTALLED_RECOVERYIMAGE_TARGET) $@
   1444 else # $(BOARD_USES_FULL_RECOVERY_IMAGE) == true
   1445 RECOVERY_FROM_BOOT_PATCH := $(INSTALLED_RECOVERYIMAGE_TARGET)
   1446 endif
   1447 endif
   1448 
   1449 
   1450 $(INSTALLED_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE) $(RECOVERY_FROM_BOOT_PATCH)
   1451 	@echo "Install system fs image: $@"
   1452 	$(copy-file-to-target)
   1453 	$(hide) $(call assert-max-image-size,$@ $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
   1454 
   1455 systemimage: $(INSTALLED_SYSTEMIMAGE)
   1456 
   1457 .PHONY: systemimage-nodeps snod
   1458 systemimage-nodeps snod: $(filter-out systemimage-nodeps snod,$(MAKECMDGOALS)) \
   1459 	            | $(INTERNAL_USERIMAGES_DEPS)
   1460 	@echo "make $@: ignoring dependencies"
   1461 	$(call build-systemimage-target,$(INSTALLED_SYSTEMIMAGE))
   1462 	$(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMIMAGE),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
   1463 
   1464 ifneq (,$(filter systemimage-nodeps snod, $(MAKECMDGOALS)))
   1465 ifeq (true,$(WITH_DEXPREOPT))
   1466 $(warning Warning: with dexpreopt enabled, you may need a full rebuild.)
   1467 endif
   1468 endif
   1469 
   1470 .PHONY: sync
   1471 sync: $(INTERNAL_SYSTEMIMAGE_FILES)
   1472 
   1473 #######
   1474 ## system tarball
   1475 define build-systemtarball-target
   1476   $(call pretty,"Target system fs tarball: $(INSTALLED_SYSTEMTARBALL_TARGET)")
   1477   $(call create-system-vendor-symlink)
   1478   $(MKTARBALL) $(FS_GET_STATS) \
   1479     $(PRODUCT_OUT) system $(PRIVATE_SYSTEM_TAR) \
   1480     $(INSTALLED_SYSTEMTARBALL_TARGET) $(TARGET_OUT)
   1481 endef
   1482 
   1483 ifndef SYSTEM_TARBALL_FORMAT
   1484     SYSTEM_TARBALL_FORMAT := bz2
   1485 endif
   1486 
   1487 system_tar := $(PRODUCT_OUT)/system.tar
   1488 INSTALLED_SYSTEMTARBALL_TARGET := $(system_tar).$(SYSTEM_TARBALL_FORMAT)
   1489 $(INSTALLED_SYSTEMTARBALL_TARGET): PRIVATE_SYSTEM_TAR := $(system_tar)
   1490 $(INSTALLED_SYSTEMTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_SYSTEMIMAGE_FILES)
   1491 	$(build-systemtarball-target)
   1492 
   1493 .PHONY: systemtarball-nodeps
   1494 systemtarball-nodeps: $(FS_GET_STATS) \
   1495                       $(filter-out systemtarball-nodeps stnod,$(MAKECMDGOALS))
   1496 	$(build-systemtarball-target)
   1497 
   1498 .PHONY: stnod
   1499 stnod: systemtarball-nodeps
   1500 
   1501 # -----------------------------------------------------------------
   1502 ## platform.zip: system, plus other files to be used in PDK fusion build,
   1503 ## in a zip file
   1504 ##
   1505 ## PDK_PLATFORM_ZIP_PRODUCT_BINARIES is used to store specified files to platform.zip.
   1506 ## The variable will be typically set from BoardConfig.mk.
   1507 ## Files under out dir will be rejected to prevent possible conflicts with other rules.
   1508 pdk_odex_javalibs := $(strip $(foreach m,$(DEXPREOPT.MODULES.JAVA_LIBRARIES),\
   1509   $(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m))))
   1510 pdk_odex_apps := $(strip $(foreach m,$(DEXPREOPT.MODULES.APPS),\
   1511   $(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m))))
   1512 pdk_classes_dex := $(strip \
   1513   $(foreach m,$(pdk_odex_javalibs),$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar) \
   1514   $(foreach m,$(pdk_odex_apps),$(call intermediates-dir-for,APPS,$(m))/package.dex.apk))
   1515 
   1516 pdk_odex_config_mk := $(PRODUCT_OUT)/pdk_dexpreopt_config.mk
   1517 $(pdk_odex_config_mk): PRIVATE_JAVA_LIBRARIES := $(pdk_odex_javalibs)
   1518 $(pdk_odex_config_mk): PRIVATE_APPS := $(pdk_odex_apps)
   1519 $(pdk_odex_config_mk) :
   1520 	@echo "PDK odex config makefile: $@"
   1521 	$(hide) mkdir -p $(dir $@)
   1522 	$(hide) echo "# Auto-generated. Do not modify." > $@
   1523 	$(hide) echo "PDK.DEXPREOPT.JAVA_LIBRARIES:=$(PRIVATE_JAVA_LIBRARIES)" >> $@
   1524 	$(hide) echo "PDK.DEXPREOPT.APPS:=$(PRIVATE_APPS)" >> $@
   1525 	$(foreach m,$(PRIVATE_JAVA_LIBRARIES),\
   1526 	  $(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar)" >> $@$(newline)\
   1527 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\
   1528 	  $(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\
   1529 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\
   1530 	  )
   1531 	$(foreach m,$(PRIVATE_APPS),\
   1532 	  $(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,APPS,$(m))/package.dex.apk)" >> $@$(newline)\
   1533 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\
   1534 	  $(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\
   1535 	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\
   1536 	  $(hide) echo "PDK.DEXPREOPT.$(m).PRIVILEGED_MODULE:=$(DEXPREOPT.$(m).PRIVILEGED_MODULE)" >> $@$(newline)\
   1537 	  $(hide) echo "PDK.DEXPREOPT.$(m).VENDOR_MODULE:=$(DEXPREOPT.$(m).VENDOR_MODULE)" >> $@$(newline)\
   1538 	  $(hide) echo "PDK.DEXPREOPT.$(m).TARGET_ARCH:=$(DEXPREOPT.$(m).TARGET_ARCH)" >> $@$(newline)\
   1539 	  $(hide) echo "PDK.DEXPREOPT.$(m).STRIPPED_SRC:=$(patsubst $(PRODUCT_OUT)/%,%,$(DEXPREOPT.$(m).INSTALLED_STRIPPED))" >> $@$(newline)\
   1540 	  )
   1541 
   1542 PDK_PLATFORM_ZIP_PRODUCT_BINARIES := $(filter-out $(OUT_DIR)/%,$(PDK_PLATFORM_ZIP_PRODUCT_BINARIES))
   1543 INSTALLED_PLATFORM_ZIP := $(PRODUCT_OUT)/platform.zip
   1544 
   1545 $(INSTALLED_PLATFORM_ZIP): PRIVATE_DEX_FILES := $(pdk_classes_dex)
   1546 $(INSTALLED_PLATFORM_ZIP): PRIVATE_ODEX_CONFIG := $(pdk_odex_config_mk)
   1547 $(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES) $(pdk_odex_config_mk)
   1548 	$(call pretty,"Platform zip package: $(INSTALLED_PLATFORM_ZIP)")
   1549 	$(hide) rm -f $@
   1550 	$(hide) cd $(dir $@) && zip -qryX $(notdir $@) \
   1551 		$(TARGET_COPY_OUT_SYSTEM) \
   1552 		$(patsubst $(PRODUCT_OUT)/%, %, $(TARGET_OUT_NOTICE_FILES)) \
   1553 		$(addprefix symbols/,$(PDK_SYMBOL_FILES_LIST))
   1554 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1555 	$(hide) cd $(dir $@) && zip -qryX $(notdir $@) \
   1556 		$(TARGET_COPY_OUT_VENDOR)
   1557 endif
   1558 ifneq ($(PDK_PLATFORM_JAVA_ZIP_CONTENTS),)
   1559 	$(hide) cd $(OUT_DIR) && zip -qryX $(patsubst $(OUT_DIR)/%,%,$@) $(PDK_PLATFORM_JAVA_ZIP_CONTENTS)
   1560 endif
   1561 ifneq ($(PDK_PLATFORM_ZIP_PRODUCT_BINARIES),)
   1562 	$(hide) zip -qryX $@ $(PDK_PLATFORM_ZIP_PRODUCT_BINARIES)
   1563 endif
   1564 	@# Add dex-preopt files and config.
   1565 	$(if $(PRIVATE_DEX_FILES),$(hide) cd $(OUT_DIR) && zip -qryX $(patsubst $(OUT_DIR)/%,%,$@ $(PRIVATE_DEX_FILES)))
   1566 	$(hide) zip -qryXj $@ $(PRIVATE_ODEX_CONFIG)
   1567 
   1568 .PHONY: platform
   1569 platform: $(INSTALLED_PLATFORM_ZIP)
   1570 
   1571 .PHONY: platform-java
   1572 platform-java: platform
   1573 
   1574 # Dist the platform.zip
   1575 ifneq (,$(filter platform platform-java, $(MAKECMDGOALS)))
   1576 $(call dist-for-goals, platform platform-java, $(INSTALLED_PLATFORM_ZIP))
   1577 endif
   1578 
   1579 # -----------------------------------------------------------------
   1580 ## boot tarball
   1581 define build-boottarball-target
   1582     $(hide) echo "Target boot fs tarball: $(INSTALLED_BOOTTARBALL_TARGET)"
   1583     $(hide) mkdir -p $(PRODUCT_OUT)/boot
   1584     $(hide) cp -f $(INTERNAL_BOOTIMAGE_FILES) $(PRODUCT_OUT)/boot/.
   1585     $(hide) echo $(INTERNAL_KERNEL_CMDLINE) > $(PRODUCT_OUT)/boot/cmdline
   1586     $(hide) $(MKTARBALL) $(FS_GET_STATS) \
   1587                  $(PRODUCT_OUT) boot $(PRIVATE_BOOT_TAR) \
   1588                  $(INSTALLED_BOOTTARBALL_TARGET) $(TARGET_OUT)
   1589 endef
   1590 
   1591 ifndef BOOT_TARBALL_FORMAT
   1592     BOOT_TARBALL_FORMAT := bz2
   1593 endif
   1594 
   1595 boot_tar := $(PRODUCT_OUT)/boot.tar
   1596 INSTALLED_BOOTTARBALL_TARGET := $(boot_tar).$(BOOT_TARBALL_FORMAT)
   1597 $(INSTALLED_BOOTTARBALL_TARGET): PRIVATE_BOOT_TAR := $(boot_tar)
   1598 $(INSTALLED_BOOTTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_BOOTIMAGE_FILES)
   1599 	$(build-boottarball-target)
   1600 
   1601 .PHONY: boottarball-nodeps btnod
   1602 boottarball-nodeps btnod: $(FS_GET_STATS) \
   1603                       $(filter-out boottarball-nodeps btnod,$(MAKECMDGOALS))
   1604 	$(build-boottarball-target)
   1605 
   1606 
   1607 # -----------------------------------------------------------------
   1608 # data partition image
   1609 INTERNAL_USERDATAIMAGE_FILES := \
   1610     $(filter $(TARGET_OUT_DATA)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
   1611 
   1612 # Don't build userdata.img if it's extfs but no partition size
   1613 skip_userdata.img :=
   1614 ifdef INTERNAL_USERIMAGES_EXT_VARIANT
   1615 ifndef BOARD_USERDATAIMAGE_PARTITION_SIZE
   1616 skip_userdata.img := true
   1617 endif
   1618 endif
   1619 
   1620 ifneq ($(skip_userdata.img),true)
   1621 userdataimage_intermediates := \
   1622     $(call intermediates-dir-for,PACKAGING,userdata)
   1623 BUILT_USERDATAIMAGE_TARGET := $(PRODUCT_OUT)/userdata.img
   1624 
   1625 define build-userdataimage-target
   1626   $(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
   1627   @mkdir -p $(TARGET_OUT_DATA)
   1628   @mkdir -p $(userdataimage_intermediates) && rm -rf $(userdataimage_intermediates)/userdata_image_info.txt
   1629   $(call generate-userimage-prop-dictionary, $(userdataimage_intermediates)/userdata_image_info.txt, skip_fsck=true)
   1630   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1631       ./build/tools/releasetools/build_image.py \
   1632       $(TARGET_OUT_DATA) $(userdataimage_intermediates)/userdata_image_info.txt $(INSTALLED_USERDATAIMAGE_TARGET) $(TARGET_OUT)
   1633   $(hide) $(call assert-max-image-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_PARTITION_SIZE))
   1634 endef
   1635 
   1636 # We just build this directly to the install location.
   1637 INSTALLED_USERDATAIMAGE_TARGET := $(BUILT_USERDATAIMAGE_TARGET)
   1638 INSTALLED_USERDATAIMAGE_TARGET_DEPS := \
   1639     $(INTERNAL_USERIMAGES_DEPS) \
   1640     $(INTERNAL_USERDATAIMAGE_FILES) \
   1641     $(BUILD_IMAGE_SRCS)
   1642 $(INSTALLED_USERDATAIMAGE_TARGET): $(INSTALLED_USERDATAIMAGE_TARGET_DEPS)
   1643 	$(build-userdataimage-target)
   1644 
   1645 .PHONY: userdataimage-nodeps
   1646 userdataimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1647 	$(build-userdataimage-target)
   1648 
   1649 endif # not skip_userdata.img
   1650 skip_userdata.img :=
   1651 
   1652 # ASAN libraries in the system image - build rule.
   1653 ASAN_OUT_DIRS_FOR_SYSTEM_INSTALL := $(sort $(patsubst $(PRODUCT_OUT)/%,%,\
   1654   $(TARGET_OUT_SHARED_LIBRARIES) \
   1655   $(2ND_TARGET_OUT_SHARED_LIBRARIES) \
   1656   $(TARGET_OUT_VENDOR_SHARED_LIBRARIES) \
   1657   $(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)))
   1658 # Extra options: Enforce the system user for the files to avoid having to change ownership.
   1659 ASAN_SYSTEM_INSTALL_OPTIONS := --owner=1000 --group=1000
   1660 # Note: experimentally, it seems not worth it to try to get "best" compression. We don't save
   1661 #       enough space.
   1662 $(ASAN_IN_SYSTEM_INSTALLED): $(INSTALLED_USERDATAIMAGE_TARGET_DEPS)
   1663 	tar cfj $(ASAN_IN_SYSTEM_INSTALLED) $(ASAN_SYSTEM_INSTALL_OPTIONS) -C $(TARGET_OUT_DATA)/.. $(ASAN_OUT_DIRS_FOR_SYSTEM_INSTALL) >/dev/null
   1664 
   1665 #######
   1666 ## data partition tarball
   1667 define build-userdatatarball-target
   1668     $(call pretty,"Target userdata fs tarball: " \
   1669                   "$(INSTALLED_USERDATATARBALL_TARGET)")
   1670     $(MKTARBALL) $(FS_GET_STATS) \
   1671 		$(PRODUCT_OUT) data $(PRIVATE_USERDATA_TAR) \
   1672 		$(INSTALLED_USERDATATARBALL_TARGET) $(TARGET_OUT)
   1673 endef
   1674 
   1675 userdata_tar := $(PRODUCT_OUT)/userdata.tar
   1676 INSTALLED_USERDATATARBALL_TARGET := $(userdata_tar).bz2
   1677 $(INSTALLED_USERDATATARBALL_TARGET): PRIVATE_USERDATA_TAR := $(userdata_tar)
   1678 $(INSTALLED_USERDATATARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_USERDATAIMAGE_FILES)
   1679 	$(build-userdatatarball-target)
   1680 
   1681 $(call dist-for-goals,userdatatarball,$(INSTALLED_USERDATATARBALL_TARGET))
   1682 
   1683 .PHONY: userdatatarball-nodeps
   1684 userdatatarball-nodeps: $(FS_GET_STATS)
   1685 	$(build-userdatatarball-target)
   1686 
   1687 
   1688 # -----------------------------------------------------------------
   1689 # partition table image
   1690 ifdef BOARD_BPT_INPUT_FILES
   1691 
   1692 BUILT_BPTIMAGE_TARGET := $(PRODUCT_OUT)/partition-table.img
   1693 BUILT_BPTJSON_TARGET := $(PRODUCT_OUT)/partition-table.bpt
   1694 
   1695 INTERNAL_BVBTOOL_MAKE_TABLE_ARGS := \
   1696 	--output_gpt $(BUILT_BPTIMAGE_TARGET) \
   1697 	--output_json $(BUILT_BPTJSON_TARGET) \
   1698 	$(foreach file, $(BOARD_BPT_INPUT_FILES), --input $(file))
   1699 
   1700 ifdef BOARD_BPT_DISK_SIZE
   1701 INTERNAL_BVBTOOL_MAKE_TABLE_ARGS += --disk_size $(BOARD_BPT_DISK_SIZE)
   1702 endif
   1703 
   1704 define build-bptimage-target
   1705   $(call pretty,"Target partition table image: $(INSTALLED_BPTIMAGE_TARGET)")
   1706   $(hide) $(BPTTOOL) make_table $(INTERNAL_BVBTOOL_MAKE_TABLE_ARGS) $(BOARD_BPT_MAKE_TABLE_ARGS)
   1707 endef
   1708 
   1709 INSTALLED_BPTIMAGE_TARGET := $(BUILT_BPTIMAGE_TARGET)
   1710 $(BUILT_BPTJSON_TARGET): $(INSTALLED_BPTIMAGE_TARGET)
   1711 	$(hide) touch -c $(BUILT_BPTJSON_TARGET)
   1712 
   1713 $(INSTALLED_BPTIMAGE_TARGET): $(BPTTOOL) $(BOARD_BPT_INPUT_FILES)
   1714 	$(build-bptimage-target)
   1715 
   1716 .PHONY: bptimage-nodeps
   1717 bptimage-nodeps:
   1718 	$(build-bptimage-target)
   1719 
   1720 endif # BOARD_BPT_INPUT_FILES
   1721 
   1722 # -----------------------------------------------------------------
   1723 # cache partition image
   1724 ifdef BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
   1725 INTERNAL_CACHEIMAGE_FILES := \
   1726     $(filter $(TARGET_OUT_CACHE)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
   1727 
   1728 cacheimage_intermediates := \
   1729     $(call intermediates-dir-for,PACKAGING,cache)
   1730 BUILT_CACHEIMAGE_TARGET := $(PRODUCT_OUT)/cache.img
   1731 
   1732 define build-cacheimage-target
   1733   $(call pretty,"Target cache fs image: $(INSTALLED_CACHEIMAGE_TARGET)")
   1734   @mkdir -p $(TARGET_OUT_CACHE)
   1735   @mkdir -p $(cacheimage_intermediates) && rm -rf $(cacheimage_intermediates)/cache_image_info.txt
   1736   $(call generate-userimage-prop-dictionary, $(cacheimage_intermediates)/cache_image_info.txt, skip_fsck=true)
   1737   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1738       ./build/tools/releasetools/build_image.py \
   1739       $(TARGET_OUT_CACHE) $(cacheimage_intermediates)/cache_image_info.txt $(INSTALLED_CACHEIMAGE_TARGET) $(TARGET_OUT)
   1740   $(hide) $(call assert-max-image-size,$(INSTALLED_CACHEIMAGE_TARGET),$(BOARD_CACHEIMAGE_PARTITION_SIZE))
   1741 endef
   1742 
   1743 # We just build this directly to the install location.
   1744 INSTALLED_CACHEIMAGE_TARGET := $(BUILT_CACHEIMAGE_TARGET)
   1745 $(INSTALLED_CACHEIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_CACHEIMAGE_FILES) $(BUILD_IMAGE_SRCS)
   1746 	$(build-cacheimage-target)
   1747 
   1748 .PHONY: cacheimage-nodeps
   1749 cacheimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1750 	$(build-cacheimage-target)
   1751 
   1752 else # BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
   1753 # we need to ignore the broken cache link when doing the rsync
   1754 IGNORE_CACHE_LINK := --exclude=cache
   1755 endif # BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
   1756 
   1757 # -----------------------------------------------------------------
   1758 # system_other partition image
   1759 ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
   1760 BOARD_USES_SYSTEM_OTHER := true
   1761 
   1762 # Marker file to identify that odex files are installed
   1763 INSTALLED_SYSTEM_OTHER_ODEX_MARKER := $(TARGET_OUT_SYSTEM_OTHER)/system-other-odex-marker
   1764 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_SYSTEM_OTHER_ODEX_MARKER)
   1765 $(INSTALLED_SYSTEM_OTHER_ODEX_MARKER):
   1766 	$(hide) touch $@
   1767 endif
   1768 
   1769 ifdef BOARD_USES_SYSTEM_OTHER
   1770 INTERNAL_SYSTEMOTHERIMAGE_FILES := \
   1771     $(filter $(TARGET_OUT_SYSTEM_OTHER)/%,\
   1772       $(ALL_DEFAULT_INSTALLED_MODULES)\
   1773       $(ALL_PDK_FUSION_FILES))
   1774 
   1775 INSTALLED_FILES_FILE_SYSTEMOTHER := $(PRODUCT_OUT)/installed-files-system-other.txt
   1776 $(INSTALLED_FILES_FILE_SYSTEMOTHER) : $(INTERNAL_SYSTEMOTHERIMAGE_FILES) $(FILESLIST)
   1777 	@echo Installed file list: $@
   1778 	@mkdir -p $(dir $@)
   1779 	@rm -f $@
   1780 	$(hide) $(FILESLIST) $(TARGET_OUT_SYSTEM_OTHER) > $(@:.txt=.json)
   1781 	$(hide) build/tools/fileslist_util.py -c $(@:.txt=.json) > $@
   1782 
   1783 systemotherimage_intermediates := \
   1784     $(call intermediates-dir-for,PACKAGING,system_other)
   1785 BUILT_SYSTEMOTHERIMAGE_TARGET := $(PRODUCT_OUT)/system_other.img
   1786 
   1787 # Note that we assert the size is SYSTEMIMAGE_PARTITION_SIZE since this is the 'b' system image.
   1788 define build-systemotherimage-target
   1789   $(call pretty,"Target system_other fs image: $(INSTALLED_SYSTEMOTHERIMAGE_TARGET)")
   1790   @mkdir -p $(TARGET_OUT_SYSTEM_OTHER)
   1791   @mkdir -p $(systemotherimage_intermediates) && rm -rf $(systemotherimage_intermediates)/system_other_image_info.txt
   1792   $(call generate-userimage-prop-dictionary, $(systemotherimage_intermediates)/system_other_image_info.txt, skip_fsck=true)
   1793   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1794       ./build/tools/releasetools/build_image.py \
   1795       $(TARGET_OUT_SYSTEM_OTHER) $(systemotherimage_intermediates)/system_other_image_info.txt $(INSTALLED_SYSTEMOTHERIMAGE_TARGET) $(TARGET_OUT)
   1796   $(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMOTHERIMAGE_TARGET),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
   1797 endef
   1798 
   1799 # We just build this directly to the install location.
   1800 INSTALLED_SYSTEMOTHERIMAGE_TARGET := $(BUILT_SYSTEMOTHERIMAGE_TARGET)
   1801 $(INSTALLED_SYSTEMOTHERIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_SYSTEMOTHERIMAGE_FILES) $(INSTALLED_FILES_FILE_SYSTEMOTHER)
   1802 	$(build-systemotherimage-target)
   1803 
   1804 .PHONY: systemotherimage-nodeps
   1805 systemotherimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
   1806 	$(build-systemotherimage-target)
   1807 
   1808 endif # BOARD_USES_SYSTEM_OTHER
   1809 
   1810 
   1811 # -----------------------------------------------------------------
   1812 # vendor partition image
   1813 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   1814 INTERNAL_VENDORIMAGE_FILES := \
   1815     $(filter $(TARGET_OUT_VENDOR)/%,\
   1816       $(ALL_DEFAULT_INSTALLED_MODULES)\
   1817       $(ALL_PDK_FUSION_FILES))
   1818 
   1819 # platform.zip depends on $(INTERNAL_VENDORIMAGE_FILES).
   1820 $(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_VENDORIMAGE_FILES)
   1821 
   1822 INSTALLED_FILES_FILE_VENDOR := $(PRODUCT_OUT)/installed-files-vendor.txt
   1823 $(INSTALLED_FILES_FILE_VENDOR) : $(INTERNAL_VENDORIMAGE_FILES) $(FILESLIST)
   1824 	@echo Installed file list: $@
   1825 	@mkdir -p $(dir $@)
   1826 	@rm -f $@
   1827 	$(hide) $(FILESLIST) $(TARGET_OUT_VENDOR) > $(@:.txt=.json)
   1828 	$(hide) build/tools/fileslist_util.py -c $(@:.txt=.json) > $@
   1829 
   1830 vendorimage_intermediates := \
   1831     $(call intermediates-dir-for,PACKAGING,vendor)
   1832 BUILT_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
   1833 define build-vendorimage-target
   1834   $(call pretty,"Target vendor fs image: $(INSTALLED_VENDORIMAGE_TARGET)")
   1835   @mkdir -p $(TARGET_OUT_VENDOR)
   1836   @mkdir -p $(vendorimage_intermediates) && rm -rf $(vendorimage_intermediates)/vendor_image_info.txt
   1837   $(call generate-userimage-prop-dictionary, $(vendorimage_intermediates)/vendor_image_info.txt, skip_fsck=true)
   1838   $(if $(BOARD_VENDOR_KERNEL_MODULES), \
   1839     $(call build-image-kernel-modules,$(BOARD_VENDOR_KERNEL_MODULES),$(TARGET_OUT_VENDOR),vendor/,$(call intermediates-dir-for,PACKAGING,depmod_vendor)))
   1840   $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
   1841       ./build/tools/releasetools/build_image.py \
   1842       $(TARGET_OUT_VENDOR) $(vendorimage_intermediates)/vendor_image_info.txt $(INSTALLED_VENDORIMAGE_TARGET) $(TARGET_OUT)
   1843   $(hide) $(call assert-max-image-size,$(INSTALLED_VENDORIMAGE_TARGET),$(BOARD_VENDORIMAGE_PARTITION_SIZE))
   1844 endef
   1845 
   1846 # We just build this directly to the install location.
   1847 INSTALLED_VENDORIMAGE_TARGET := $(BUILT_VENDORIMAGE_TARGET)
   1848 $(INSTALLED_VENDORIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_VENDORIMAGE_FILES) $(INSTALLED_FILES_FILE_VENDOR) $(BUILD_IMAGE_SRCS) $(DEPMOD) $(BOARD_VENDOR_KERNEL_MODULES)
   1849 	$(build-vendorimage-target)
   1850 
   1851 .PHONY: vendorimage-nodeps vnod
   1852 vendorimage-nodeps vnod: | $(INTERNAL_USERIMAGES_DEPS) $(DEPMOD)
   1853 	$(build-vendorimage-target)
   1854 
   1855 sync: $(INTERNAL_VENDORIMAGE_FILES)
   1856 
   1857 else ifdef BOARD_PREBUILT_VENDORIMAGE
   1858 INSTALLED_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
   1859 $(eval $(call copy-one-file,$(BOARD_PREBUILT_VENDORIMAGE),$(INSTALLED_VENDORIMAGE_TARGET)))
   1860 endif
   1861 
   1862 # -----------------------------------------------------------------
   1863 # dtbo image
   1864 ifdef BOARD_PREBUILT_DTBOIMAGE
   1865 INSTALLED_DTBOIMAGE_TARGET := $(PRODUCT_OUT)/dtbo.img
   1866 
   1867 ifeq ($(BOARD_AVB_ENABLE),true)
   1868 $(INSTALLED_DTBOIMAGE_TARGET): $(BOARD_PREBUILT_DTBOIMAGE) $(AVBTOOL) $(BOARD_AVB_DTBO_KEY_PATH)
   1869 	cp $(BOARD_PREBUILT_DTBOIMAGE) $@
   1870 	$(AVBTOOL) add_hash_footer \
   1871 		--image $@ \
   1872 		--partition_size $(BOARD_DTBOIMG_PARTITION_SIZE) \
   1873 		--partition_name dtbo $(INTERNAL_AVB_DTBO_SIGNING_ARGS) \
   1874 		$(BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS)
   1875 else
   1876 $(INSTALLED_DTBOIMAGE_TARGET): $(BOARD_PREBUILT_DTBOIMAGE)
   1877 	cp $(BOARD_PREBUILT_DTBOIMAGE) $@
   1878 endif
   1879 
   1880 endif
   1881 
   1882 # Convert to lower case without requiring a shell, which isn't cacheable.
   1883 to-lower = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,\
   1884 $(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,\
   1885 $(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,\
   1886 $(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
   1887 # Convert to upper case without requiring a shell, which isn't cacheable.
   1888 to-upper=$(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E,$(subst f,F,$(subst g,G,\
   1889 $(subst h,H,$(subst i,I,$(subst j,J,$(subst k,K,$(subst l,L,$(subst m,M,$(subst n,N,$(subst o,O,\
   1890 $(subst p,P,$(subst q,Q,$(subst r,R,$(subst s,S,$(subst t,T,$(subst u,U,$(subst v,V,$(subst w,W,\
   1891 $(subst x,X,$(subst y,Y,$(subst z,Z,$1))))))))))))))))))))))))))
   1892 
   1893 # -----------------------------------------------------------------
   1894 # vbmeta image
   1895 ifeq ($(BOARD_AVB_ENABLE),true)
   1896 
   1897 BUILT_VBMETAIMAGE_TARGET := $(PRODUCT_OUT)/vbmeta.img
   1898 AVB_CHAIN_KEY_DIR := $(TARGET_OUT_INTERMEDIATES)/avb_chain_keys
   1899 
   1900 ifdef BOARD_AVB_KEY_PATH
   1901 $(if $(BOARD_AVB_ALGORITHM),,$(error BOARD_AVB_ALGORITHM is not defined))
   1902 else
   1903 # If key path isn't specified, use the 4096-bit test key.
   1904 BOARD_AVB_ALGORITHM := SHA256_RSA4096
   1905 BOARD_AVB_KEY_PATH := external/avb/test/data/testkey_rsa4096.pem
   1906 endif
   1907 
   1908 INTERNAL_AVB_SIGNING_ARGS := \
   1909     --algorithm $(BOARD_AVB_ALGORITHM) --key $(BOARD_AVB_KEY_PATH)
   1910 
   1911 BOOT_FOOTER_ARGS := BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS
   1912 DTBO_FOOTER_ARGS := BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS
   1913 SYSTEM_FOOTER_ARGS := BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS
   1914 VENDOR_FOOTER_ARGS := BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS
   1915 
   1916 # Check and set required build variables for a chain partition.
   1917 # $(1): the partition to enable AVB chain, e.g., BOOT or SYSTEM.
   1918 define check-and-set-avb-chain-args
   1919 $(eval PART := $(1))
   1920 $(eval part=$(call to-lower,$(PART)))
   1921 
   1922 $(eval _key_path := BOARD_AVB_$(PART)_KEY_PATH)
   1923 $(eval _signing_algorithm := BOARD_AVB_$(PART)_ALGORITHM)
   1924 $(eval _rollback_index := BOARD_AVB_$(PART)_ROLLBACK_INDEX)
   1925 $(eval _rollback_index_location := BOARD_AVB_$(PART)_ROLLBACK_INDEX_LOCATION)
   1926 $(if $($(_key_path)),,$(error $(_key_path) is not defined))
   1927 $(if $($(_signing_algorithm)),,$(error $(_signing_algorithm) is not defined))
   1928 $(if $($(_rollback_index)),,$(error $(_rollback_index) is not defined))
   1929 $(if $($(_rollback_index_location)),,$(error $(_rollback_index_location) is not defined))
   1930 
   1931 # Set INTERNAL_AVB_(PART)_SIGNING_ARGS
   1932 $(eval _signing_args := INTERNAL_AVB_$(PART)_SIGNING_ARGS)
   1933 $(eval $(_signing_args) := \
   1934     --algorithm $($(_signing_algorithm)) --key $($(_key_path)))
   1935 
   1936 $(eval INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
   1937     --chain_partition $(part):$($(_rollback_index_location)):$(AVB_CHAIN_KEY_DIR)/$(part).avbpubkey)
   1938 
   1939 # Set rollback_index via footer args
   1940 $(eval _footer_args := $(PART)_FOOTER_ARGS)
   1941 $(eval $($(_footer_args)) += --rollback_index $($(_rollback_index)))
   1942 endef
   1943 
   1944 ifdef BOARD_AVB_BOOT_KEY_PATH
   1945 $(eval $(call check-and-set-avb-chain-args,BOOT))
   1946 else
   1947 INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
   1948     --include_descriptors_from_image $(INSTALLED_BOOTIMAGE_TARGET)
   1949 endif
   1950 
   1951 ifdef BOARD_AVB_SYSTEM_KEY_PATH
   1952 $(eval $(call check-and-set-avb-chain-args,SYSTEM))
   1953 else
   1954 INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
   1955     --include_descriptors_from_image $(INSTALLED_SYSTEMIMAGE)
   1956 endif
   1957 
   1958 ifdef INSTALLED_VENDORIMAGE_TARGET
   1959 ifdef BOARD_AVB_VENDOR_KEY_PATH
   1960 $(eval $(call check-and-set-avb-chain-args,VENDOR))
   1961 else
   1962 INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
   1963     --include_descriptors_from_image $(INSTALLED_VENDORIMAGE_TARGET)
   1964 endif
   1965 endif
   1966 
   1967 ifdef INSTALLED_DTBOIMAGE_TARGET
   1968 ifdef BOARD_AVB_DTBO_KEY_PATH
   1969 $(eval $(call check-and-set-avb-chain-args,DTBO))
   1970 else
   1971 INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
   1972     --include_descriptors_from_image $(INSTALLED_DTBOIMAGE_TARGET)
   1973 endif
   1974 endif
   1975 
   1976 BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --padding_size 4096
   1977 
   1978 # Add kernel cmdline descriptor for kernel to mount system.img as root with
   1979 # dm-verity. This works when system.img is either chained or not-chained:
   1980 # - chained: The --setup_as_rootfs_from_kernel option will add dm-verity kernel
   1981 #   cmdline descriptor to system.img
   1982 # - not-chained: The --include_descriptors_from_image option for make_vbmeta_image
   1983 #   will include the kernel cmdline descriptor from system.img into vbmeta.img
   1984 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
   1985 BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS += --setup_as_rootfs_from_kernel
   1986 endif
   1987 
   1988 ifdef BOARD_AVB_ROLLBACK_INDEX
   1989 BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --rollback_index $(BOARD_AVB_ROLLBACK_INDEX)
   1990 endif
   1991 
   1992 ifndef BOARD_BOOTIMAGE_PARTITION_SIZE
   1993   $(error BOARD_BOOTIMAGE_PARTITION_SIZE must be set for BOARD_AVB_ENABLE)
   1994 endif
   1995 
   1996 ifndef BOARD_SYSTEMIMAGE_PARTITION_SIZE
   1997   $(error BOARD_SYSTEMIMAGE_PARTITION_SIZE must be set for BOARD_AVB_ENABLE)
   1998 endif
   1999 
   2000 # $(1): the directory to extract public keys to
   2001 define extract-avb-chain-public-keys
   2002   $(if $(BOARD_AVB_BOOT_KEY_PATH),\
   2003     $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_BOOT_KEY_PATH) \
   2004       --output $(1)/boot.avbpubkey)
   2005   $(if $(BOARD_AVB_SYSTEM_KEY_PATH),\
   2006     $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_SYSTEM_KEY_PATH) \
   2007       --output $(1)/system.avbpubkey)
   2008   $(if $(BOARD_AVB_VENDOR_KEY_PATH),\
   2009     $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VENDOR_KEY_PATH) \
   2010       --output $(1)/vendor.avbpubkey)
   2011   $(if $(BOARD_AVB_DTBO_KEY_PATH),\
   2012     $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_DTBO_KEY_PATH) \
   2013       --output $(1)/dtbo.avbpubkey)
   2014 endef
   2015 
   2016 define build-vbmetaimage-target
   2017   $(call pretty,"Target vbmeta image: $(INSTALLED_VBMETAIMAGE_TARGET)")
   2018   $(hide) mkdir -p $(AVB_CHAIN_KEY_DIR)
   2019   $(call extract-avb-chain-public-keys, $(AVB_CHAIN_KEY_DIR))
   2020   $(hide) $(AVBTOOL) make_vbmeta_image \
   2021     $(INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS) \
   2022     $(INTERNAL_AVB_SIGNING_ARGS) \
   2023     $(BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS) \
   2024     --output $@
   2025   $(hide) rm -rf $(AVB_CHAIN_KEY_DIR)
   2026 endef
   2027 
   2028 INSTALLED_VBMETAIMAGE_TARGET := $(BUILT_VBMETAIMAGE_TARGET)
   2029 $(INSTALLED_VBMETAIMAGE_TARGET): $(AVBTOOL) $(INSTALLED_BOOTIMAGE_TARGET) $(INSTALLED_SYSTEMIMAGE) $(INSTALLED_VENDORIMAGE_TARGET) $(INSTALLED_DTBOIMAGE_TARGET) $(BOARD_AVB_KEY_PATH)
   2030 	$(build-vbmetaimage-target)
   2031 
   2032 .PHONY: vbmetaimage-nodeps
   2033 vbmetaimage-nodeps:
   2034 	$(build-vbmetaimage-target)
   2035 
   2036 else ifeq (true,$(BOARD_BUILD_DISABLED_VBMETAIMAGE))
   2037 BUILT_DISABLED_VBMETAIMAGE := $(PRODUCT_OUT)/vbmeta.img
   2038 
   2039 INSTALLED_VBMETAIMAGE_TARGET := $(BUILT_DISABLED_VBMETAIMAGE)
   2040 $(INSTALLED_VBMETAIMAGE_TARGET): $(AVBTOOL)
   2041 	$(hide) $(AVBTOOL) make_vbmeta_image \
   2042 	  --flag 2 --padding_size 4096 --output $@
   2043 
   2044 endif # BOARD_AVB_ENABLE
   2045 
   2046 # -----------------------------------------------------------------
   2047 # bring in the installer image generation defines if necessary
   2048 ifeq ($(TARGET_USE_DISKINSTALLER),true)
   2049 include bootable/diskinstaller/config.mk
   2050 endif
   2051 
   2052 # -----------------------------------------------------------------
   2053 # host tools needed to build dist and OTA packages
   2054 
   2055 build_ota_package := true
   2056 ifeq ($(TARGET_SKIP_OTA_PACKAGE),true)
   2057 build_ota_package := false
   2058 endif
   2059 ifeq ($(BUILD_OS),darwin)
   2060 build_ota_package := false
   2061 endif
   2062 ifneq ($(strip $(SANITIZE_TARGET)),)
   2063 build_ota_package := false
   2064 endif
   2065 ifeq ($(TARGET_PRODUCT),sdk)
   2066 build_ota_package := false
   2067 endif
   2068 ifneq ($(filter generic%,$(TARGET_DEVICE)),)
   2069 build_ota_package := false
   2070 endif
   2071 ifeq ($(TARGET_NO_KERNEL),true)
   2072 build_ota_package := false
   2073 endif
   2074 ifeq ($(recovery_fstab),)
   2075 build_ota_package := false
   2076 endif
   2077 ifeq ($(TARGET_BUILD_PDK),true)
   2078 build_ota_package := false
   2079 endif
   2080 
   2081 ifeq ($(build_ota_package),true)
   2082 OTATOOLS :=  $(HOST_OUT_EXECUTABLES)/minigzip \
   2083   $(HOST_OUT_EXECUTABLES)/aapt \
   2084   $(HOST_OUT_EXECUTABLES)/mkbootfs \
   2085   $(HOST_OUT_EXECUTABLES)/mkbootimg \
   2086   $(HOST_OUT_EXECUTABLES)/fs_config \
   2087   $(HOST_OUT_EXECUTABLES)/zipalign \
   2088   $(HOST_OUT_EXECUTABLES)/bsdiff \
   2089   $(HOST_OUT_EXECUTABLES)/imgdiff \
   2090   $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar \
   2091   $(HOST_OUT_JAVA_LIBRARIES)/signapk.jar \
   2092   $(HOST_OUT_JAVA_LIBRARIES)/BootSignature.jar \
   2093   $(HOST_OUT_JAVA_LIBRARIES)/VeritySigner.jar \
   2094   $(HOST_OUT_EXECUTABLES)/make_ext4fs \
   2095   $(HOST_OUT_EXECUTABLES)/mkuserimg.sh \
   2096   $(HOST_OUT_EXECUTABLES)/mke2fs \
   2097   $(HOST_OUT_EXECUTABLES)/mkuserimg_mke2fs.sh \
   2098   $(HOST_OUT_EXECUTABLES)/e2fsdroid \
   2099   $(HOST_OUT_EXECUTABLES)/mksquashfsimage.sh \
   2100   $(HOST_OUT_EXECUTABLES)/mksquashfs \
   2101   $(HOST_OUT_EXECUTABLES)/mkf2fsuserimg.sh \
   2102   $(HOST_OUT_EXECUTABLES)/make_f2fs \
   2103   $(HOST_OUT_EXECUTABLES)/simg2img \
   2104   $(HOST_OUT_EXECUTABLES)/e2fsck \
   2105   $(HOST_OUT_EXECUTABLES)/build_verity_tree \
   2106   $(HOST_OUT_EXECUTABLES)/verity_signer \
   2107   $(HOST_OUT_EXECUTABLES)/verity_verifier \
   2108   $(HOST_OUT_EXECUTABLES)/append2simg \
   2109   $(HOST_OUT_EXECUTABLES)/img2simg \
   2110   $(HOST_OUT_EXECUTABLES)/boot_signer \
   2111   $(HOST_OUT_EXECUTABLES)/fec \
   2112   $(HOST_OUT_EXECUTABLES)/brillo_update_payload \
   2113   $(HOST_OUT_EXECUTABLES)/lib/shflags/shflags \
   2114   $(HOST_OUT_EXECUTABLES)/delta_generator \
   2115   $(AVBTOOL) \
   2116   $(BLK_ALLOC_TO_BASE_FS) \
   2117   $(BRO)
   2118 
   2119 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT))
   2120 OTATOOLS += \
   2121   $(FUTILITY) \
   2122   $(VBOOT_SIGNER)
   2123 endif
   2124 
   2125 # Shared libraries.
   2126 OTATOOLS += \
   2127   $(HOST_LIBRARY_PATH)/libc++$(HOST_SHLIB_SUFFIX) \
   2128   $(HOST_LIBRARY_PATH)/liblog$(HOST_SHLIB_SUFFIX) \
   2129   $(HOST_LIBRARY_PATH)/libcutils$(HOST_SHLIB_SUFFIX) \
   2130   $(HOST_LIBRARY_PATH)/libselinux$(HOST_SHLIB_SUFFIX) \
   2131   $(HOST_LIBRARY_PATH)/libcrypto-host$(HOST_SHLIB_SUFFIX) \
   2132   $(HOST_LIBRARY_PATH)/libext2fs-host$(HOST_SHLIB_SUFFIX) \
   2133   $(HOST_LIBRARY_PATH)/libext2_blkid-host$(HOST_SHLIB_SUFFIX) \
   2134   $(HOST_LIBRARY_PATH)/libext2_com_err-host$(HOST_SHLIB_SUFFIX) \
   2135   $(HOST_LIBRARY_PATH)/libext2_e2p-host$(HOST_SHLIB_SUFFIX) \
   2136   $(HOST_LIBRARY_PATH)/libext2_misc$(HOST_SHLIB_SUFFIX) \
   2137   $(HOST_LIBRARY_PATH)/libext2_profile-host$(HOST_SHLIB_SUFFIX) \
   2138   $(HOST_LIBRARY_PATH)/libext2_quota-host$(HOST_SHLIB_SUFFIX) \
   2139   $(HOST_LIBRARY_PATH)/libext2_uuid-host$(HOST_SHLIB_SUFFIX) \
   2140   $(HOST_LIBRARY_PATH)/libconscrypt_openjdk_jni$(HOST_SHLIB_SUFFIX) \
   2141   $(HOST_LIBRARY_PATH)/libbrillo$(HOST_SHLIB_SUFFIX) \
   2142   $(HOST_LIBRARY_PATH)/libbrillo-stream$(HOST_SHLIB_SUFFIX) \
   2143   $(HOST_LIBRARY_PATH)/libchrome$(HOST_SHLIB_SUFFIX) \
   2144   $(HOST_LIBRARY_PATH)/libcurl-host$(HOST_SHLIB_SUFFIX) \
   2145   $(HOST_LIBRARY_PATH)/libevent-host$(HOST_SHLIB_SUFFIX) \
   2146   $(HOST_LIBRARY_PATH)/libprotobuf-cpp-lite$(HOST_SHLIB_SUFFIX) \
   2147   $(HOST_LIBRARY_PATH)/libssl-host$(HOST_SHLIB_SUFFIX) \
   2148   $(HOST_LIBRARY_PATH)/libz-host$(HOST_SHLIB_SUFFIX) \
   2149   $(HOST_LIBRARY_PATH)/libsparse-host$(HOST_SHLIB_SUFFIX) \
   2150   $(HOST_LIBRARY_PATH)/libbase$(HOST_SHLIB_SUFFIX) \
   2151   $(HOST_LIBRARY_PATH)/libpcre2$(HOST_SHLIB_SUFFIX) \
   2152   $(HOST_LIBRARY_PATH)/libbrotli$(HOST_SHLIB_SUFFIX)
   2153 
   2154 
   2155 .PHONY: otatools
   2156 otatools: $(OTATOOLS)
   2157 
   2158 BUILT_OTATOOLS_PACKAGE := $(PRODUCT_OUT)/otatools.zip
   2159 $(BUILT_OTATOOLS_PACKAGE): zip_root := $(call intermediates-dir-for,PACKAGING,otatools)/otatools
   2160 
   2161 OTATOOLS_DEPS := \
   2162   system/extras/verity/build_verity_metadata.py \
   2163   system/extras/ext4_utils/mke2fs.conf \
   2164   external/avb/test/data/testkey_rsa4096.pem \
   2165   $(shell find build/target/product/security -type f -name \*.x509.pem -o -name \*.pk8 -o \
   2166       -name verity_key | sort) \
   2167   $(shell find device vendor -type f -name \*.pk8 -o -name verifiedboot\* -o \
   2168       -name \*.x509.pem -o -name oem\*.prop | sort)
   2169 
   2170 OTATOOLS_RELEASETOOLS := \
   2171   $(shell find build/tools/releasetools -name \*.pyc -prune -o -type f | sort)
   2172 
   2173 ifeq (true,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VBOOT))
   2174 OTATOOLS_DEPS += \
   2175   $(shell find external/vboot_reference/tests/devkeys -type f | sort)
   2176 endif
   2177 
   2178 $(BUILT_OTATOOLS_PACKAGE): $(OTATOOLS) $(OTATOOLS_DEPS) $(OTATOOLS_RELEASETOOLS) | $(ACP)
   2179 	@echo "Package OTA tools: $@"
   2180 	$(hide) rm -rf $@ $(zip_root)
   2181 	$(hide) mkdir -p $(dir $@) $(zip_root)/bin $(zip_root)/framework $(zip_root)/releasetools
   2182 	$(call copy-files-with-structure,$(OTATOOLS),$(HOST_OUT)/,$(zip_root))
   2183 	$(hide) $(ACP) -r -d -p build/tools/releasetools/* $(zip_root)/releasetools
   2184 	$(hide) rm -rf $@ $(zip_root)/releasetools/*.pyc
   2185 	$(hide) (cd $(zip_root) && zip -qryX $(abspath $@) *)
   2186 	$(hide) echo $(OTATOOLS_DEPS) | xargs zip -qryX $(abspath $@)>/dev/null || true
   2187 
   2188 .PHONY: otatools-package
   2189 otatools-package: $(BUILT_OTATOOLS_PACKAGE)
   2190 
   2191 endif # build_ota_package
   2192 
   2193 # -----------------------------------------------------------------
   2194 # A zip of the directories that map to the target filesystem.
   2195 # This zip can be used to create an OTA package or filesystem image
   2196 # as a post-build step.
   2197 #
   2198 name := $(TARGET_PRODUCT)
   2199 ifeq ($(TARGET_BUILD_TYPE),debug)
   2200   name := $(name)_debug
   2201 endif
   2202 name := $(name)-target_files-$(FILE_NAME_TAG)
   2203 
   2204 intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
   2205 BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
   2206 $(BUILT_TARGET_FILES_PACKAGE): intermediates := $(intermediates)
   2207 $(BUILT_TARGET_FILES_PACKAGE): \
   2208 		zip_root := $(intermediates)/$(name)
   2209 
   2210 # $(1): Directory to copy
   2211 # $(2): Location to copy it to
   2212 # The "ls -A" is to prevent "acp s/* d" from failing if s is empty.
   2213 define package_files-copy-root
   2214   if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
   2215     mkdir -p $(2) && \
   2216     $(ACP) -rd $(strip $(1))/* $(2); \
   2217   fi
   2218 endef
   2219 
   2220 built_ota_tools :=
   2221 
   2222 # We can't build static executables when SANITIZE_TARGET=address
   2223 ifeq ($(strip $(SANITIZE_TARGET)),)
   2224 built_ota_tools += \
   2225     $(call intermediates-dir-for,EXECUTABLES,updater,,,$(TARGET_PREFER_32_BIT))/updater
   2226 endif
   2227 
   2228 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_OTA_TOOLS := $(built_ota_tools)
   2229 
   2230 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_API_VERSION := $(RECOVERY_API_VERSION)
   2231 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_FSTAB_VERSION := $(RECOVERY_FSTAB_VERSION)
   2232 
   2233 ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
   2234 # default to common dir for device vendor
   2235 tool_extensions := $(TARGET_DEVICE_DIR)/../common
   2236 else
   2237 tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
   2238 endif
   2239 tool_extension := $(wildcard $(tool_extensions)/releasetools.py)
   2240 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_TOOL_EXTENSIONS := $(tool_extensions)
   2241 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_TOOL_EXTENSION := $(tool_extension)
   2242 
   2243 ifeq ($(AB_OTA_UPDATER),true)
   2244 # Build zlib fingerprint if using the AB Updater.
   2245 updater_dep := $(TARGET_OUT_COMMON_GEN)/zlib_fingerprint
   2246 updater_dep += system/update_engine/update_engine.conf
   2247 else
   2248 # Build OTA tools if not using the AB Updater.
   2249 updater_dep := $(built_ota_tools)
   2250 endif
   2251 $(BUILT_TARGET_FILES_PACKAGE): $(updater_dep)
   2252 
   2253 # If we are using recovery as boot, output recovery files to BOOT/.
   2254 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
   2255 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := BOOT
   2256 else
   2257 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := RECOVERY
   2258 endif
   2259 
   2260 ifeq ($(AB_OTA_UPDATER),true)
   2261   ifdef BRILLO_VENDOR_PARTITIONS
   2262     $(BUILT_TARGET_FILES_PACKAGE): $(foreach p,$(BRILLO_VENDOR_PARTITIONS),\
   2263                                      $(call word-colon,1,$(p))/$(call word-colon,2,$(p)))
   2264   endif
   2265   ifdef OSRELEASED_DIRECTORY
   2266     $(BUILT_TARGET_FILES_PACKAGE): $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_id
   2267     $(BUILT_TARGET_FILES_PACKAGE): $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_version
   2268     $(BUILT_TARGET_FILES_PACKAGE): $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/system_version
   2269   endif
   2270 endif
   2271 
   2272 # Run fs_config while creating the target files package
   2273 # $1: root directory
   2274 # $2: add prefix
   2275 define fs_config
   2276 (cd $(1); find . -type d | sed 's,$$,/,'; find . \! -type d) | cut -c 3- | sort | sed 's,^,$(2),' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC)
   2277 endef
   2278 
   2279 # Depending on the various images guarantees that the underlying
   2280 # directories are up-to-date.
   2281 $(BUILT_TARGET_FILES_PACKAGE): \
   2282 		$(INSTALLED_BOOTIMAGE_TARGET) \
   2283 		$(INSTALLED_RADIOIMAGE_TARGET) \
   2284 		$(INSTALLED_RECOVERYIMAGE_TARGET) \
   2285 		$(FULL_SYSTEMIMAGE_DEPS) \
   2286 		$(INSTALLED_USERDATAIMAGE_TARGET) \
   2287 		$(INSTALLED_CACHEIMAGE_TARGET) \
   2288 		$(INSTALLED_VENDORIMAGE_TARGET) \
   2289 		$(INSTALLED_VBMETAIMAGE_TARGET) \
   2290 		$(INSTALLED_DTBOIMAGE_TARGET) \
   2291 		$(INTERNAL_SYSTEMOTHERIMAGE_FILES) \
   2292 		$(INSTALLED_ANDROID_INFO_TXT_TARGET) \
   2293 		$(INSTALLED_KERNEL_TARGET) \
   2294 		$(INSTALLED_2NDBOOTLOADER_TARGET) \
   2295 		$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH) \
   2296 		$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH) \
   2297 		$(SELINUX_FC) \
   2298 		$(APKCERTS_FILE) \
   2299 		$(SOONG_ZIP) \
   2300 		$(HOST_OUT_EXECUTABLES)/fs_config \
   2301 		$(HOST_OUT_EXECUTABLES)/imgdiff \
   2302 		$(HOST_OUT_EXECUTABLES)/bsdiff \
   2303 		$(BUILD_IMAGE_SRCS) \
   2304 		$(INSTALLED_VENDOR_MANIFEST) \
   2305 		$(INSTALLED_VENDOR_MATRIX) \
   2306 		| $(ACP)
   2307 	@echo "Package target files: $@"
   2308 	$(call create-system-vendor-symlink)
   2309 	$(hide) rm -rf $@ $@.list $(zip_root)
   2310 	$(hide) mkdir -p $(dir $@) $(zip_root)
   2311 ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)))
   2312 	@# Components of the recovery image
   2313 	$(hide) mkdir -p $(zip_root)/$(PRIVATE_RECOVERY_OUT)
   2314 	$(hide) $(call package_files-copy-root, \
   2315 		$(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/$(PRIVATE_RECOVERY_OUT)/RAMDISK)
   2316 ifdef INSTALLED_KERNEL_TARGET
   2317 	$(hide) cp $(INSTALLED_KERNEL_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/kernel
   2318 endif
   2319 ifdef INSTALLED_2NDBOOTLOADER_TARGET
   2320 	$(hide) cp $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/second
   2321 endif
   2322 ifdef INTERNAL_KERNEL_CMDLINE
   2323 	$(hide) echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/cmdline
   2324 endif
   2325 ifdef BOARD_KERNEL_BASE
   2326 	$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/base
   2327 endif
   2328 ifdef BOARD_KERNEL_PAGESIZE
   2329 	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/pagesize
   2330 endif
   2331 endif # INSTALLED_RECOVERYIMAGE_TARGET defined or BOARD_USES_RECOVERY_AS_BOOT is true
   2332 	@# Components of the boot image
   2333 	$(hide) mkdir -p $(zip_root)/BOOT
   2334 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
   2335 	$(hide) mkdir -p $(zip_root)/ROOT
   2336 	$(hide) $(call package_files-copy-root, \
   2337 		$(TARGET_ROOT_OUT),$(zip_root)/ROOT)
   2338 else
   2339 	$(hide) $(call package_files-copy-root, \
   2340 		$(TARGET_ROOT_OUT),$(zip_root)/BOOT/RAMDISK)
   2341 endif
   2342 	@# If we are using recovery as boot, this is already done when processing recovery.
   2343 ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
   2344 ifdef INSTALLED_KERNEL_TARGET
   2345 	$(hide) cp $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/kernel
   2346 endif
   2347 ifdef INSTALLED_2NDBOOTLOADER_TARGET
   2348 	$(hide) cp $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second
   2349 endif
   2350 ifdef INTERNAL_KERNEL_CMDLINE
   2351 	$(hide) echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
   2352 endif
   2353 ifdef BOARD_KERNEL_BASE
   2354 	$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base
   2355 endif
   2356 ifdef BOARD_KERNEL_PAGESIZE
   2357 	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesize
   2358 endif
   2359 endif # BOARD_USES_RECOVERY_AS_BOOT
   2360 	$(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\
   2361 	            mkdir -p $(zip_root)/RADIO; \
   2362 	            cp $(t) $(zip_root)/RADIO/$(notdir $(t));)
   2363 	@# Contents of the system image
   2364 	$(hide) $(call package_files-copy-root, \
   2365 		$(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
   2366 	@# Contents of the data image
   2367 	$(hide) $(call package_files-copy-root, \
   2368 		$(TARGET_OUT_DATA),$(zip_root)/DATA)
   2369 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   2370 	@# Contents of the vendor image
   2371 	$(hide) $(call package_files-copy-root, \
   2372 		$(TARGET_OUT_VENDOR),$(zip_root)/VENDOR)
   2373 endif
   2374 ifdef INSTALLED_SYSTEMOTHERIMAGE_TARGET
   2375 	@# Contents of the system_other image
   2376 	$(hide) $(call package_files-copy-root, \
   2377 		$(TARGET_OUT_SYSTEM_OTHER),$(zip_root)/SYSTEM_OTHER)
   2378 endif
   2379 	@# Extra contents of the OTA package
   2380 	$(hide) mkdir -p $(zip_root)/OTA
   2381 	$(hide) cp $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/
   2382 ifneq ($(AB_OTA_UPDATER),true)
   2383 ifneq ($(built_ota_tools),)
   2384 	$(hide) mkdir -p $(zip_root)/OTA/bin
   2385 	$(hide) cp $(PRIVATE_OTA_TOOLS) $(zip_root)/OTA/bin/
   2386 endif
   2387 endif
   2388 	@# Files that do not end up in any images, but are necessary to
   2389 	@# build them.
   2390 	$(hide) mkdir -p $(zip_root)/META
   2391 	$(hide) cp $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
   2392 ifneq ($(tool_extension),)
   2393 	$(hide) cp $(PRIVATE_TOOL_EXTENSION) $(zip_root)/META/
   2394 endif
   2395 	$(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
   2396 	$(hide) cp $(SELINUX_FC) $(zip_root)/META/file_contexts.bin
   2397 	$(hide) echo "recovery_api_version=$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/misc_info.txt
   2398 	$(hide) echo "fstab_version=$(PRIVATE_RECOVERY_FSTAB_VERSION)" >> $(zip_root)/META/misc_info.txt
   2399 ifdef BOARD_FLASH_BLOCK_SIZE
   2400 	$(hide) echo "blocksize=$(BOARD_FLASH_BLOCK_SIZE)" >> $(zip_root)/META/misc_info.txt
   2401 endif
   2402 ifdef BOARD_BOOTIMAGE_PARTITION_SIZE
   2403 	$(hide) echo "boot_size=$(BOARD_BOOTIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
   2404 endif
   2405 ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),)
   2406 	$(hide) echo "recovery_as_boot=$(BOARD_USES_RECOVERY_AS_BOOT)" >> $(zip_root)/META/misc_info.txt
   2407 endif
   2408 ifeq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   2409 	$(hide) echo "no_recovery=true" >> $(zip_root)/META/misc_info.txt
   2410 endif
   2411 ifdef BOARD_RECOVERYIMAGE_PARTITION_SIZE
   2412 	$(hide) echo "recovery_size=$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
   2413 endif
   2414 ifdef BOARD_HAS_EXT4_RESERVED_BLOCKS
   2415 	$(hide) echo "has_ext4_reserved_blocks=$(BOARD_HAS_EXT4_RESERVED_BLOCKS)" >> $(zip_root)/META/misc_info.txt
   2416 endif
   2417 ifdef TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS
   2418 	@# TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS can be empty to indicate that nothing but defaults should be used.
   2419 	$(hide) echo "recovery_mount_options=$(TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $(zip_root)/META/misc_info.txt
   2420 else
   2421 	$(hide) echo "recovery_mount_options=$(DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $(zip_root)/META/misc_info.txt
   2422 endif
   2423 	$(hide) echo "tool_extensions=$(PRIVATE_TOOL_EXTENSIONS)" >> $(zip_root)/META/misc_info.txt
   2424 	$(hide) echo "default_system_dev_certificate=$(DEFAULT_SYSTEM_DEV_CERTIFICATE)" >> $(zip_root)/META/misc_info.txt
   2425 ifdef PRODUCT_EXTRA_RECOVERY_KEYS
   2426 	$(hide) echo "extra_recovery_keys=$(PRODUCT_EXTRA_RECOVERY_KEYS)" >> $(zip_root)/META/misc_info.txt
   2427 endif
   2428 	$(hide) echo 'mkbootimg_args=$(BOARD_MKBOOTIMG_ARGS)' >> $(zip_root)/META/misc_info.txt
   2429 	$(hide) echo 'mkbootimg_version_args=$(INTERNAL_MKBOOTIMG_VERSION_ARGS)' >> $(zip_root)/META/misc_info.txt
   2430 	$(hide) echo "multistage_support=1" >> $(zip_root)/META/misc_info.txt
   2431 	$(hide) echo "blockimgdiff_versions=3,4" >> $(zip_root)/META/misc_info.txt
   2432 ifneq ($(OEM_THUMBPRINT_PROPERTIES),)
   2433 	# OTA scripts are only interested in fingerprint related properties
   2434 	$(hide) echo "oem_fingerprint_properties=$(OEM_THUMBPRINT_PROPERTIES)" >> $(zip_root)/META/misc_info.txt
   2435 endif
   2436 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH),)
   2437 	$(hide) cp $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH) \
   2438 	  $(zip_root)/META/$(notdir $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH))
   2439 endif
   2440 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH),)
   2441 	$(hide) cp $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH) \
   2442 	  $(zip_root)/META/$(notdir $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_BASE_FS_PATH))
   2443 endif
   2444 ifneq ($(strip $(SANITIZE_TARGET)),)
   2445 	# We need to create userdata.img with real data because the instrumented libraries are in userdata.img.
   2446 	$(hide) echo "userdata_img_with_data=true" >> $(zip_root)/META/misc_info.txt
   2447 endif
   2448 ifeq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
   2449 	$(hide) echo "full_recovery_image=true" >> $(zip_root)/META/misc_info.txt
   2450 endif
   2451 ifeq ($(BOARD_AVB_ENABLE),true)
   2452 	$(hide) echo "avb_enable=true" >> $(zip_root)/META/misc_info.txt
   2453 	$(hide) echo "avb_vbmeta_key_path=$(BOARD_AVB_KEY_PATH)" >> $(zip_root)/META/misc_info.txt
   2454 	$(hide) echo "avb_vbmeta_algorithm=$(BOARD_AVB_ALGORITHM)" >> $(zip_root)/META/misc_info.txt
   2455 	$(hide) echo "avb_vbmeta_args=$(BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS)" >> $(zip_root)/META/misc_info.txt
   2456 	$(hide) echo "avb_boot_add_hash_footer_args=$(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)" >> $(zip_root)/META/misc_info.txt
   2457 ifdef BOARD_AVB_BOOT_KEY_PATH
   2458 	$(hide) echo "avb_boot_key_path=$(BOARD_AVB_BOOT_KEY_PATH)" >> $(zip_root)/META/misc_info.txt
   2459 	$(hide) echo "avb_boot_algorithm=$(BOARD_AVB_BOOT_ALGORITHM)" >> $(zip_root)/META/misc_info.txt
   2460 	$(hide) echo "avb_boot_rollback_index_location=$(BOARD_AVB_BOOT_ROLLBACK_INDEX_LOCATION)" >> $(zip_root)/META/misc_info.txt
   2461 endif # BOARD_AVB_BOOT_KEY_PATH
   2462 endif # BOARD_AVB_ENABLE
   2463 ifdef BOARD_BPT_INPUT_FILES
   2464 	$(hide) echo "board_bpt_enable=true" >> $(zip_root)/META/misc_info.txt
   2465 	$(hide) echo "board_bpt_make_table_args=$(BOARD_BPT_MAKE_TABLE_ARGS)" >> $(zip_root)/META/misc_info.txt
   2466 	$(hide) echo "board_bpt_input_files=$(BOARD_BPT_INPUT_FILES)" >> $(zip_root)/META/misc_info.txt
   2467 endif
   2468 ifdef BOARD_BPT_DISK_SIZE
   2469 	$(hide) echo "board_bpt_disk_size=$(BOARD_BPT_DISK_SIZE)" >> $(zip_root)/META/misc_info.txt
   2470 endif
   2471 	$(call generate-userimage-prop-dictionary, $(zip_root)/META/misc_info.txt)
   2472 ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   2473 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   2474 	    ./build/tools/releasetools/make_recovery_patch $(zip_root) $(zip_root)
   2475 endif
   2476 ifeq ($(AB_OTA_UPDATER),true)
   2477 	@# When using the A/B updater, include the updater config files in the zip.
   2478 	$(hide) cp $(TOPDIR)system/update_engine/update_engine.conf $(zip_root)/META/update_engine_config.txt
   2479 	$(hide) cp $(TARGET_OUT_COMMON_GEN)/zlib_fingerprint $(zip_root)/META/zlib_fingerprint.txt
   2480 	$(hide) for part in $(AB_OTA_PARTITIONS); do \
   2481 	  echo "$${part}" >> $(zip_root)/META/ab_partitions.txt; \
   2482 	done
   2483 	$(hide) for conf in $(AB_OTA_POSTINSTALL_CONFIG); do \
   2484 	  echo "$${conf}" >> $(zip_root)/META/postinstall_config.txt; \
   2485 	done
   2486 	@# Include the build type in META/misc_info.txt so the server can easily differentiate production builds.
   2487 	$(hide) echo "build_type=$(TARGET_BUILD_VARIANT)" >> $(zip_root)/META/misc_info.txt
   2488 	$(hide) echo "ab_update=true" >> $(zip_root)/META/misc_info.txt
   2489 ifdef BRILLO_VENDOR_PARTITIONS
   2490 	$(hide) mkdir -p $(zip_root)/VENDOR_IMAGES
   2491 	$(hide) for f in $(BRILLO_VENDOR_PARTITIONS); do \
   2492 	  pair1="$$(echo $$f | awk -F':' '{print $$1}')"; \
   2493 	  pair2="$$(echo $$f | awk -F':' '{print $$2}')"; \
   2494 	  src=$${pair1}/$${pair2}; \
   2495 	  dest=$(zip_root)/VENDOR_IMAGES/$${pair2}; \
   2496 	  mkdir -p $$(dirname "$${dest}"); \
   2497 	  cp $${src} $${dest}; \
   2498 	done;
   2499 endif
   2500 ifdef OSRELEASED_DIRECTORY
   2501 	$(hide) cp $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_id $(zip_root)/META/product_id.txt
   2502 	$(hide) cp $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_version $(zip_root)/META/product_version.txt
   2503 	$(hide) cp $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/system_version $(zip_root)/META/system_version.txt
   2504 endif
   2505 endif
   2506 ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
   2507 	@# If breakpad symbols have been generated, add them to the zip.
   2508 	$(hide) $(ACP) -r $(TARGET_OUT_BREAKPAD) $(zip_root)/BREAKPAD
   2509 endif
   2510 # BOARD_BUILD_DISABLED_VBMETAIMAGE is used to build a special vbmeta.img
   2511 # that disables AVB verification. The content is fixed and we can just copy
   2512 # it to $(zip_root)/IMAGES without passing some info into misc_info.txt for
   2513 # regeneration.
   2514 ifeq (true,$(BOARD_BUILD_DISABLED_VBMETAIMAGE))
   2515 	$(hide) mkdir -p $(zip_root)/IMAGES
   2516 	$(hide) cp $(INSTALLED_VBMETAIMAGE_TARGET) $(zip_root)/IMAGES/
   2517 endif
   2518 ifdef BOARD_PREBUILT_VENDORIMAGE
   2519 	$(hide) mkdir -p $(zip_root)/IMAGES
   2520 	$(hide) cp $(INSTALLED_VENDORIMAGE_TARGET) $(zip_root)/IMAGES/
   2521 endif
   2522 ifdef BOARD_PREBUILT_DTBOIMAGE
   2523 	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
   2524 	$(hide) cp $(INSTALLED_DTBOIMAGE_TARGET) $(zip_root)/PREBUILT_IMAGES/
   2525 	$(hide) echo "has_dtbo=true" >> $(zip_root)/META/misc_info.txt
   2526 ifeq ($(BOARD_AVB_ENABLE),true)
   2527 	$(hide) echo "dtbo_size=$(BOARD_DTBOIMG_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
   2528 	$(hide) echo "avb_dtbo_add_hash_footer_args=$(BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS)" >> $(zip_root)/META/misc_info.txt
   2529 ifdef BOARD_AVB_DTBO_KEY_PATH
   2530 	$(hide) echo "avb_dtbo_key_path=$(BOARD_AVB_DTBO_KEY_PATH)" >> $(zip_root)/META/misc_info.txt
   2531 	$(hide) echo "avb_dtbo_algorithm=$(BOARD_AVB_DTBO_ALGORITHM)" >> $(zip_root)/META/misc_info.txt
   2532 	$(hide) echo "avb_dtbo_rollback_index_location=$(BOARD_AVB_DTBO_ROLLBACK_INDEX_LOCATION)" \
   2533 	    >> $(zip_root)/META/misc_info.txt
   2534 endif # BOARD_AVB_DTBO_KEY_PATH
   2535 endif # BOARD_AVB_ENABLE
   2536 endif # BOARD_PREBUILT_DTBOIMAGE
   2537 	@# The radio images in BOARD_PACK_RADIOIMAGES will be additionally copied from RADIO/ into
   2538 	@# IMAGES/, which then will be added into <product>-img.zip. Such images must be listed in
   2539 	@# INSTALLED_RADIOIMAGE_TARGET.
   2540 	$(hide) $(foreach part,$(BOARD_PACK_RADIOIMAGES), \
   2541 	    echo $(part) >> $(zip_root)/META/pack_radioimages.txt;)
   2542 	@# Run fs_config on all the system, vendor, boot ramdisk,
   2543 	@# and recovery ramdisk files in the zip, and save the output
   2544 	$(hide) $(call fs_config,$(zip_root)/SYSTEM,system/) > $(zip_root)/META/filesystem_config.txt
   2545 ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
   2546 	$(hide) $(call fs_config,$(zip_root)/VENDOR,vendor/) > $(zip_root)/META/vendor_filesystem_config.txt
   2547 endif
   2548 ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
   2549 	$(hide) $(call fs_config,$(zip_root)/ROOT,) > $(zip_root)/META/root_filesystem_config.txt
   2550 endif
   2551 	$(hide) $(call fs_config,$(zip_root)/BOOT/RAMDISK,) > $(zip_root)/META/boot_filesystem_config.txt
   2552 ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
   2553 	$(hide) $(call fs_config,$(zip_root)/RECOVERY/RAMDISK,) > $(zip_root)/META/recovery_filesystem_config.txt
   2554 endif
   2555 ifdef INSTALLED_SYSTEMOTHERIMAGE_TARGET
   2556 	$(hide) $(call fs_config,$(zip_root)/SYSTEM_OTHER,system/) > $(zip_root)/META/system_other_filesystem_config.txt
   2557 endif
   2558 
   2559 ifeq ($(PRODUCT_FULL_TREBLE),true)
   2560 	@# Metadata for compatibility verification.
   2561 	$(hide) cp $(BUILT_SYSTEM_MANIFEST) $(zip_root)/META/system_manifest.xml
   2562 	$(hide) cp $(BUILT_SYSTEM_COMPATIBILITY_MATRIX) $(zip_root)/META/system_matrix.xml
   2563 ifdef BUILT_VENDOR_MANIFEST
   2564 	$(hide) cp $(BUILT_VENDOR_MANIFEST) $(zip_root)/META/vendor_manifest.xml
   2565 endif
   2566 ifdef BUILT_VENDOR_MATRIX
   2567 	$(hide) cp $(BUILT_VENDOR_MATRIX) $(zip_root)/META/vendor_matrix.xml
   2568 endif
   2569 endif
   2570 
   2571 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   2572 	    ./build/tools/releasetools/add_img_to_target_files -a -v -p $(HOST_OUT) $(zip_root)
   2573 	@# Zip everything up, preserving symlinks and placing META/ files first to
   2574 	@# help early validation of the .zip file while uploading it.
   2575 	$(hide) find $(zip_root)/META | sort >$@.list
   2576 	$(hide) find $(zip_root) -path $(zip_root)/META -prune -o -print | sort >>$@.list
   2577 	$(hide) $(SOONG_ZIP) -d -o $@ -C $(zip_root) -l $@.list
   2578 
   2579 .PHONY: target-files-package
   2580 target-files-package: $(BUILT_TARGET_FILES_PACKAGE)
   2581 
   2582 ifneq ($(filter $(MAKECMDGOALS),target-files-package),)
   2583 $(call dist-for-goals, target-files-package, $(BUILT_TARGET_FILES_PACKAGE))
   2584 endif
   2585 
   2586 # -----------------------------------------------------------------
   2587 # NDK Sysroot Package
   2588 NDK_SYSROOT_TARGET := $(PRODUCT_OUT)/ndk_sysroot.tar.bz2
   2589 $(NDK_SYSROOT_TARGET): ndk
   2590 	@echo Package NDK sysroot...
   2591 	$(hide) tar cjf $@ -C $(SOONG_OUT_DIR) ndk
   2592 
   2593 $(call dist-for-goals,sdk,$(NDK_SYSROOT_TARGET))
   2594 
   2595 ifeq ($(build_ota_package),true)
   2596 # -----------------------------------------------------------------
   2597 # OTA update package
   2598 
   2599 name := $(TARGET_PRODUCT)
   2600 ifeq ($(TARGET_BUILD_TYPE),debug)
   2601   name := $(name)_debug
   2602 endif
   2603 name := $(name)-ota-$(FILE_NAME_TAG)
   2604 
   2605 INTERNAL_OTA_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   2606 
   2607 $(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
   2608 
   2609 ifeq ($(AB_OTA_UPDATER),true)
   2610 $(INTERNAL_OTA_PACKAGE_TARGET): $(BRILLO_UPDATE_PAYLOAD)
   2611 else
   2612 $(INTERNAL_OTA_PACKAGE_TARGET): $(BRO)
   2613 endif
   2614 
   2615 $(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) \
   2616 		build/tools/releasetools/ota_from_target_files
   2617 	@echo "Package OTA: $@"
   2618 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
   2619 	   ./build/tools/releasetools/ota_from_target_files -v \
   2620 	   --block \
   2621 	   --extracted_input_target_files $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE)) \
   2622 	   -p $(HOST_OUT) \
   2623 	   -k $(KEY_CERT_PAIR) \
   2624 	   $(if $(OEM_OTA_CONFIG), -o $(OEM_OTA_CONFIG)) \
   2625 	   $(BUILT_TARGET_FILES_PACKAGE) $@
   2626 
   2627 .PHONY: otapackage
   2628 otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)
   2629 
   2630 endif    # build_ota_package
   2631 
   2632 # -----------------------------------------------------------------
   2633 # The update package
   2634 
   2635 name := $(TARGET_PRODUCT)
   2636 ifeq ($(TARGET_BUILD_TYPE),debug)
   2637   name := $(name)_debug
   2638 endif
   2639 name := $(name)-img-$(FILE_NAME_TAG)
   2640 
   2641 INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   2642 
   2643 $(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(ZIP2ZIP)
   2644 	@echo "Package: $@"
   2645 	$(hide) $(ZIP2ZIP) -i $(BUILT_TARGET_FILES_PACKAGE) -o $@ \
   2646 	   OTA/android-info.txt:android-info.txt "IMAGES/*.img:."
   2647 
   2648 .PHONY: updatepackage
   2649 updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
   2650 
   2651 # -----------------------------------------------------------------
   2652 # A zip of the symbols directory.  Keep the full paths to make it
   2653 # more obvious where these files came from.
   2654 #
   2655 name := $(TARGET_PRODUCT)
   2656 ifeq ($(TARGET_BUILD_TYPE),debug)
   2657   name := $(name)_debug
   2658 endif
   2659 name := $(name)-symbols-$(FILE_NAME_TAG)
   2660 
   2661 SYMBOLS_ZIP := $(PRODUCT_OUT)/$(name).zip
   2662 # For apps_only build we'll establish the dependency later in build/core/main.mk.
   2663 ifndef TARGET_BUILD_APPS
   2664 $(SYMBOLS_ZIP): $(INSTALLED_SYSTEMIMAGE) \
   2665 		$(INSTALLED_BOOTIMAGE_TARGET) \
   2666 		$(INSTALLED_USERDATAIMAGE_TARGET) \
   2667 		$(INSTALLED_VENDORIMAGE_TARGET) \
   2668 		$(updater_dep)
   2669 endif
   2670 $(SYMBOLS_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,symbols)/filelist
   2671 $(SYMBOLS_ZIP): $(SOONG_ZIP)
   2672 	@echo "Package symbols: $@"
   2673 	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
   2674 	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_UNSTRIPPED) $(dir $(PRIVATE_LIST_FILE))
   2675 	$(hide) find $(TARGET_OUT_UNSTRIPPED) | sort >$(PRIVATE_LIST_FILE)
   2676 	$(hide) $(SOONG_ZIP) -d -o $@ -C $(OUT_DIR)/.. -l $(PRIVATE_LIST_FILE)
   2677 # -----------------------------------------------------------------
   2678 # A zip of the coverage directory.
   2679 #
   2680 name := $(TARGET_PRODUCT)
   2681 ifeq ($(TARGET_BUILD_TYPE),debug)
   2682 name := $(name)_debug
   2683 endif
   2684 name := $(name)-coverage-$(FILE_NAME_TAG)
   2685 COVERAGE_ZIP := $(PRODUCT_OUT)/$(name).zip
   2686 ifndef TARGET_BUILD_APPS
   2687 $(COVERAGE_ZIP): $(INSTALLED_SYSTEMIMAGE) \
   2688 		$(INSTALLED_BOOTIMAGE_TARGET) \
   2689 		$(INSTALLED_USERDATAIMAGE_TARGET) \
   2690 		$(INSTALLED_VENDORIMAGE_TARGET)
   2691 endif
   2692 $(COVERAGE_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,coverage)/filelist
   2693 $(COVERAGE_ZIP): $(SOONG_ZIP)
   2694 	@echo "Package coverage: $@"
   2695 	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
   2696 	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_COVERAGE) $(dir $(PRIVATE_LIST_FILE))
   2697 	$(hide) find $(TARGET_OUT_COVERAGE) | sort >$(PRIVATE_LIST_FILE)
   2698 	$(hide) $(SOONG_ZIP) -d -o $@ -C $(TARGET_OUT_COVERAGE) -l $(PRIVATE_LIST_FILE)
   2699 
   2700 # -----------------------------------------------------------------
   2701 # A zip of the Android Apps. Not keeping full path so that we don't
   2702 # include product names when distributing
   2703 #
   2704 name := $(TARGET_PRODUCT)
   2705 ifeq ($(TARGET_BUILD_TYPE),debug)
   2706   name := $(name)_debug
   2707 endif
   2708 name := $(name)-apps-$(FILE_NAME_TAG)
   2709 
   2710 APPS_ZIP := $(PRODUCT_OUT)/$(name).zip
   2711 $(APPS_ZIP): $(INSTALLED_SYSTEMIMAGE)
   2712 	@echo "Package apps: $@"
   2713 	$(hide) rm -rf $@
   2714 	$(hide) mkdir -p $(dir $@)
   2715 	$(hide) apps_to_zip=`find $(TARGET_OUT_APPS) $(TARGET_OUT_APPS_PRIVILEGED) -mindepth 2 -maxdepth 3 -name "*.apk"`; \
   2716 	if [ -z "$$apps_to_zip" ]; then \
   2717 		echo "No apps to zip up. Generating empty apps archive." ; \
   2718 		a=$$(mktemp /tmp/XXXXXXX) && touch $$a && zip $@ $$a && zip -d $@ $$a; \
   2719 	else \
   2720 		zip -qjX $@ $$apps_to_zip; \
   2721 	fi
   2722 
   2723 ifeq (true,$(EMMA_INSTRUMENT))
   2724   #------------------------------------------------------------------
   2725   # An archive of classes for use in generating code-coverage reports
   2726   # These are the uninstrumented versions of any classes that were
   2727   # to be instrumented.
   2728   # Any dependencies are set up later in build/core/main.mk.
   2729 
   2730   ifeq ($(ANDROID_COMPILE_WITH_JACK),false)
   2731     JACOCO_REPORT_CLASSES_ALL := $(PRODUCT_OUT)/jacoco-report-classes-all.jar
   2732 $(JACOCO_REPORT_CLASSES_ALL) :
   2733 	@echo "Collecting uninstrumented classes"
   2734 	$(hide) find $(TARGET_COMMON_OUT_ROOT) $(HOST_COMMON_OUT_ROOT) -name "jacoco-report-classes.jar" | \
   2735 		zip -@ -0 -q -X $@
   2736 # Meaning of these options:
   2737 # -@ scan stdin for file paths to add to the zip
   2738 # -0 don't do any compression
   2739 # -q supress most output
   2740 # -X skip storing extended file attributes
   2741 
   2742   else
   2743     EMMA_META_ZIP := $(PRODUCT_OUT)/emma_meta.zip
   2744 $(EMMA_META_ZIP) :
   2745 	@echo "Collecting Emma coverage meta files."
   2746 	$(hide) find $(TARGET_COMMON_OUT_ROOT) $(HOST_COMMON_OUT_ROOT) -name "coverage.em" | \
   2747 		zip -@ -qX $@
   2748 endif
   2749 
   2750 endif # EMMA_INSTRUMENT=true
   2751 
   2752 
   2753 #------------------------------------------------------------------
   2754 # A zip of Proguard obfuscation dictionary files.
   2755 # Only for apps_only build.
   2756 #
   2757 ifdef TARGET_BUILD_APPS
   2758 PROGUARD_DICT_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-$(FILE_NAME_TAG).zip
   2759 # the dependency will be set up later in build/core/main.mk.
   2760 $(PROGUARD_DICT_ZIP) :
   2761 	@echo "Packaging Proguard obfuscation dictionary files."
   2762 	$(hide) dict_files=`find $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS -name proguard_dictionary -o -name jack_dictionary`; \
   2763 		if [ -n "$$dict_files" ]; then \
   2764 		  unobfuscated_jars=$${dict_files//proguard_dictionary/classes.jar}; \
   2765 		  zip -qX $@ $$dict_files $$unobfuscated_jars; \
   2766 		else \
   2767 		  touch $(dir $@)/zipdummy; \
   2768 		  (cd $(dir $@) && zip -q $(notdir $@) zipdummy); \
   2769 		  zip -qd $@ zipdummy; \
   2770 		  rm $(dir $@)/zipdummy; \
   2771 		fi
   2772 
   2773 endif # TARGET_BUILD_APPS
   2774 
   2775 # -----------------------------------------------------------------
   2776 # dalvik something
   2777 .PHONY: dalvikfiles
   2778 dalvikfiles: $(INTERNAL_DALVIK_MODULES)
   2779 
   2780 ifeq ($(BUILD_QEMU_IMAGES),true)
   2781 INSTALLED_QEMU_SYSTEMIMAGE := $(PRODUCT_OUT)/system-qemu.img
   2782 MK_QEMU_IMAGE_SH := device/generic/goldfish/tools/mk_qemu_image.sh
   2783 SGDISK_HOST := $(HOST_OUT_EXECUTABLES)/sgdisk
   2784 $(INSTALLED_QEMU_SYSTEMIMAGE): $(INSTALLED_SYSTEMIMAGE) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST)
   2785 	@echo Create system-qemu.img
   2786 	(export SGDISK=$(SGDISK_HOST); $(MK_QEMU_IMAGE_SH) ${PRODUCT_OUT}/system.img)
   2787 
   2788 systemimage: $(INSTALLED_QEMU_SYSTEMIMAGE)
   2789 droidcore: $(INSTALLED_QEMU_SYSTEMIMAGE)
   2790 ifeq ($(BOARD_USES_VENDORIMAGE),true)
   2791 INSTALLED_QEMU_VENDORIMAGE := $(PRODUCT_OUT)/vendor-qemu.img
   2792 $(INSTALLED_QEMU_VENDORIMAGE): $(INSTALLED_VENDORIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST)
   2793 	@echo Create vendor-qemu.img
   2794 	(export SGDISK=$(SGDISK_HOST); $(MK_QEMU_IMAGE_SH) ${PRODUCT_OUT}/vendor.img)
   2795 
   2796 vendorimage: $(INSTALLED_QEMU_VENDORIMAGE)
   2797 droidcore: $(INSTALLED_QEMU_VENDORIMAGE)
   2798 endif
   2799 endif
   2800 # -----------------------------------------------------------------
   2801 # The emulator package
   2802 ifeq ($(BUILD_EMULATOR),true)
   2803 INTERNAL_EMULATOR_PACKAGE_FILES += \
   2804         $(HOST_OUT_EXECUTABLES)/emulator$(HOST_EXECUTABLE_SUFFIX) \
   2805         prebuilts/qemu-kernel/$(TARGET_ARCH)/kernel-qemu \
   2806         $(INSTALLED_RAMDISK_TARGET) \
   2807 		$(INSTALLED_SYSTEMIMAGE) \
   2808 		$(INSTALLED_USERDATAIMAGE_TARGET)
   2809 
   2810 name := $(TARGET_PRODUCT)-emulator-$(FILE_NAME_TAG)
   2811 
   2812 INTERNAL_EMULATOR_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
   2813 
   2814 $(INTERNAL_EMULATOR_PACKAGE_TARGET): $(INTERNAL_EMULATOR_PACKAGE_FILES)
   2815 	@echo "Package: $@"
   2816 	$(hide) zip -qjX $@ $(INTERNAL_EMULATOR_PACKAGE_FILES)
   2817 
   2818 endif
   2819 # -----------------------------------------------------------------
   2820 # Old PDK stuffs, retired
   2821 # The pdk package (Platform Development Kit)
   2822 
   2823 #ifneq (,$(filter pdk,$(MAKECMDGOALS)))
   2824 #  include development/pdk/Pdk.mk
   2825 #endif
   2826 
   2827 
   2828 # -----------------------------------------------------------------
   2829 # The SDK
   2830 
   2831 # The SDK includes host-specific components, so it belongs under HOST_OUT.
   2832 sdk_dir := $(HOST_OUT)/sdk/$(TARGET_PRODUCT)
   2833 
   2834 # Build a name that looks like:
   2835 #
   2836 #     linux-x86   --> android-sdk_12345_linux-x86
   2837 #     darwin-x86  --> android-sdk_12345_mac-x86
   2838 #     windows-x86 --> android-sdk_12345_windows
   2839 #
   2840 sdk_name := android-sdk_$(FILE_NAME_TAG)
   2841 ifeq ($(HOST_OS),darwin)
   2842   INTERNAL_SDK_HOST_OS_NAME := mac
   2843 else
   2844   INTERNAL_SDK_HOST_OS_NAME := $(HOST_OS)
   2845 endif
   2846 ifneq ($(HOST_OS),windows)
   2847   INTERNAL_SDK_HOST_OS_NAME := $(INTERNAL_SDK_HOST_OS_NAME)-$(SDK_HOST_ARCH)
   2848 endif
   2849 sdk_name := $(sdk_name)_$(INTERNAL_SDK_HOST_OS_NAME)
   2850 
   2851 sdk_dep_file := $(sdk_dir)/sdk_deps.mk
   2852 
   2853 ATREE_FILES :=
   2854 -include $(sdk_dep_file)
   2855 
   2856 # if we don't have a real list, then use "everything"
   2857 ifeq ($(strip $(ATREE_FILES)),)
   2858 ATREE_FILES := \
   2859 	$(ALL_DEFAULT_INSTALLED_MODULES) \
   2860 	$(INSTALLED_RAMDISK_TARGET) \
   2861 	$(ALL_DOCS) \
   2862 	$(ALL_SDK_FILES)
   2863 endif
   2864 
   2865 atree_dir := development/build
   2866 
   2867 
   2868 sdk_atree_files := \
   2869 	$(atree_dir)/sdk.exclude.atree \
   2870 	$(atree_dir)/sdk-$(HOST_OS)-$(SDK_HOST_ARCH).atree
   2871 
   2872 # development/build/sdk-android-<abi>.atree is used to differentiate
   2873 # between architecture models (e.g. ARMv5TE versus ARMv7) when copying
   2874 # files like the kernel image. We use TARGET_CPU_ABI because we don't
   2875 # have a better way to distinguish between CPU models.
   2876 ifneq (,$(strip $(wildcard $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree)))
   2877   sdk_atree_files += $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree
   2878 endif
   2879 
   2880 ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ATREE_FILES),)
   2881 sdk_atree_files += $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ATREE_FILES)
   2882 else
   2883 sdk_atree_files += $(atree_dir)/sdk.atree
   2884 endif
   2885 
   2886 include $(BUILD_SYSTEM)/sdk_font.mk
   2887 
   2888 deps := \
   2889 	$(target_notice_file_txt) \
   2890 	$(tools_notice_file_txt) \
   2891 	$(OUT_DOCS)/offline-sdk-timestamp \
   2892 	$(SYMBOLS_ZIP) \
   2893 	$(COVERAGE_ZIP) \
   2894 	$(INSTALLED_SYSTEMIMAGE) \
   2895 	$(INSTALLED_QEMU_SYSTEMIMAGE) \
   2896 	$(INSTALLED_QEMU_VENDORIMAGE) \
   2897 	$(INSTALLED_USERDATAIMAGE_TARGET) \
   2898 	$(INSTALLED_RAMDISK_TARGET) \
   2899 	$(INSTALLED_SDK_BUILD_PROP_TARGET) \
   2900 	$(INSTALLED_BUILD_PROP_TARGET) \
   2901 	$(ATREE_FILES) \
   2902 	$(sdk_atree_files) \
   2903 	$(HOST_OUT_EXECUTABLES)/atree \
   2904 	$(HOST_OUT_EXECUTABLES)/line_endings \
   2905 	$(SDK_FONT_DEPS)
   2906 
   2907 INTERNAL_SDK_TARGET := $(sdk_dir)/$(sdk_name).zip
   2908 $(INTERNAL_SDK_TARGET): PRIVATE_NAME := $(sdk_name)
   2909 $(INTERNAL_SDK_TARGET): PRIVATE_DIR := $(sdk_dir)/$(sdk_name)
   2910 $(INTERNAL_SDK_TARGET): PRIVATE_DEP_FILE := $(sdk_dep_file)
   2911 $(INTERNAL_SDK_TARGET): PRIVATE_INPUT_FILES := $(sdk_atree_files)
   2912 
   2913 # Set SDK_GNU_ERROR to non-empty to fail when a GNU target is built.
   2914 #
   2915 #SDK_GNU_ERROR := true
   2916 
   2917 $(INTERNAL_SDK_TARGET): $(deps)
   2918 	@echo "Package SDK: $@"
   2919 	$(hide) rm -rf $(PRIVATE_DIR) $@
   2920 	$(hide) for f in $(target_gnu_MODULES); do \
   2921 	  if [ -f $$f ]; then \
   2922 	    echo SDK: $(if $(SDK_GNU_ERROR),ERROR:,warning:) \
   2923 	        including GNU target $$f >&2; \
   2924 	    FAIL=$(SDK_GNU_ERROR); \
   2925 	  fi; \
   2926 	done; \
   2927 	if [ $$FAIL ]; then exit 1; fi
   2928 	$(hide) echo $(notdir $(SDK_FONT_DEPS)) | tr " " "\n"  > $(SDK_FONT_TEMP)/fontsInSdk.txt
   2929 	$(hide) ( \
   2930 		ATREE_STRIP="strip -x" \
   2931 		$(HOST_OUT_EXECUTABLES)/atree \
   2932 		$(addprefix -f ,$(PRIVATE_INPUT_FILES)) \
   2933 			-m $(PRIVATE_DEP_FILE) \
   2934 			-I . \
   2935 			-I $(PRODUCT_OUT) \
   2936 			-I $(HOST_OUT) \
   2937 			-I $(TARGET_COMMON_OUT_ROOT) \
   2938 			-v "PLATFORM_NAME=android-$(PLATFORM_VERSION)" \
   2939 			-v "OUT_DIR=$(OUT_DIR)" \
   2940 			-v "HOST_OUT=$(HOST_OUT)" \
   2941 			-v "TARGET_ARCH=$(TARGET_ARCH)" \
   2942 			-v "TARGET_CPU_ABI=$(TARGET_CPU_ABI)" \
   2943 			-v "DLL_EXTENSION=$(HOST_SHLIB_SUFFIX)" \
   2944 			-v "FONT_OUT=$(SDK_FONT_TEMP)" \
   2945 			-v "JACK_SDKTOOL_VERSION=$(JACK_SDKTOOL_VERSION)" \
   2946 			-o $(PRIVATE_DIR) && \
   2947 		cp -f $(target_notice_file_txt) \
   2948 				$(PRIVATE_DIR)/system-images/android-$(PLATFORM_VERSION)/$(TARGET_CPU_ABI)/NOTICE.txt && \
   2949 		cp -f $(tools_notice_file_txt) $(PRIVATE_DIR)/platform-tools/NOTICE.txt && \
   2950 		HOST_OUT_EXECUTABLES=$(HOST_OUT_EXECUTABLES) HOST_OS=$(HOST_OS) \
   2951 			development/build/tools/sdk_clean.sh $(PRIVATE_DIR) && \
   2952 		chmod -R ug+rwX $(PRIVATE_DIR) && \
   2953 		cd $(dir $@) && zip -rqX $(notdir $@) $(PRIVATE_NAME) \
   2954 	) || ( rm -rf $(PRIVATE_DIR) $@ && exit 44 )
   2955 
   2956 
   2957 # Is a Windows SDK requested? If so, we need some definitions from here
   2958 # in order to find the Linux SDK used to create the Windows one.
   2959 MAIN_SDK_NAME := $(sdk_name)
   2960 MAIN_SDK_DIR  := $(sdk_dir)
   2961 MAIN_SDK_ZIP  := $(INTERNAL_SDK_TARGET)
   2962 ifneq ($(filter win_sdk winsdk-tools,$(MAKECMDGOALS)),)
   2963 include $(TOPDIR)development/build/tools/windows_sdk.mk
   2964 endif
   2965 
   2966 # -----------------------------------------------------------------
   2967 # Findbugs
   2968 INTERNAL_FINDBUGS_XML_TARGET := $(PRODUCT_OUT)/findbugs.xml
   2969 INTERNAL_FINDBUGS_HTML_TARGET := $(PRODUCT_OUT)/findbugs.html
   2970 $(INTERNAL_FINDBUGS_XML_TARGET): $(ALL_FINDBUGS_FILES)
   2971 	@echo UnionBugs: $@
   2972 	$(hide) $(FINDBUGS_DIR)/unionBugs $(ALL_FINDBUGS_FILES) \
   2973 	> $@
   2974 $(INTERNAL_FINDBUGS_HTML_TARGET): $(INTERNAL_FINDBUGS_XML_TARGET)
   2975 	@echo ConvertXmlToText: $@
   2976 	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl \
   2977 	$(INTERNAL_FINDBUGS_XML_TARGET) > $@
   2978 
   2979 # -----------------------------------------------------------------
   2980 # Findbugs
   2981 
   2982 # -----------------------------------------------------------------
   2983 # These are some additional build tasks that need to be run.
   2984 ifneq ($(dont_bother),true)
   2985 include $(sort $(wildcard $(BUILD_SYSTEM)/tasks/*.mk))
   2986 -include $(sort $(wildcard vendor/*/build/tasks/*.mk))
   2987 -include $(sort $(wildcard device/*/build/tasks/*.mk))
   2988 -include $(sort $(wildcard product/*/build/tasks/*.mk))
   2989 # Also the project-specific tasks
   2990 -include $(sort $(wildcard vendor/*/*/build/tasks/*.mk))
   2991 -include $(sort $(wildcard device/*/*/build/tasks/*.mk))
   2992 -include $(sort $(wildcard product/*/*/build/tasks/*.mk))
   2993 # Also add test specifc tasks
   2994 include $(sort $(wildcard platform_testing/build/tasks/*.mk))
   2995 include $(sort $(wildcard test/vts/tools/build/tasks/*.mk))
   2996 endif
   2997 
   2998 include $(BUILD_SYSTEM)/product-graph.mk
   2999 
   3000 # -----------------------------------------------------------------
   3001 # Create SDK repository packages. Must be done after tasks/* since
   3002 # we need the addon rules defined.
   3003 ifneq ($(sdk_repo_goal),)
   3004 include $(TOPDIR)development/build/tools/sdk_repo.mk
   3005 endif
   3006