• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Put some miscellaneous rules here
2
3# HACK: clear LOCAL_PATH from including last build target before calling
4# intermedites-dir-for
5LOCAL_PATH := $(BUILD_SYSTEM)
6
7# -----------------------------------------------------------------
8# Define rules to copy PRODUCT_COPY_FILES defined by the product.
9# PRODUCT_COPY_FILES contains words like <source file>:<dest file>[:<owner>].
10# <dest file> is relative to $(PRODUCT_OUT), so it should look like,
11# e.g., "system/etc/file.xml".
12# The filter part means "only eval the copy-one-file rule if this
13# src:dest pair is the first one to match the same dest"
14#$(1): the src:dest pair
15#$(2): the dest
16define check-product-copy-files
17$(if $(filter-out $(TARGET_COPY_OUT_SYSTEM_OTHER)/%,$(2)), \
18  $(if $(filter %.apk, $(2)),$(error \
19     Prebuilt apk found in PRODUCT_COPY_FILES: $(1), use BUILD_PREBUILT instead!)))
20endef
21# filter out the duplicate <source file>:<dest file> pairs.
22unique_product_copy_files_pairs :=
23$(foreach cf,$(PRODUCT_COPY_FILES), \
24    $(if $(filter $(unique_product_copy_files_pairs),$(cf)),,\
25        $(eval unique_product_copy_files_pairs += $(cf))))
26unique_product_copy_files_destinations :=
27product_copy_files_ignored :=
28$(foreach cf,$(unique_product_copy_files_pairs), \
29    $(eval _src := $(call word-colon,1,$(cf))) \
30    $(eval _dest := $(call word-colon,2,$(cf))) \
31    $(call check-product-copy-files,$(cf),$(_dest)) \
32    $(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \
33        $(eval product_copy_files_ignored += $(cf)), \
34        $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
35        $(if $(filter %.xml,$(_dest)),\
36            $(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\
37            $(if $(and $(filter %.jar,$(_dest)),$(filter $(basename $(notdir $(_dest))),$(PRODUCT_LOADED_BY_PRIVILEGED_MODULES))),\
38                $(eval $(call copy-and-uncompress-dexs,$(_src),$(_fulldest))), \
39                $(if $(filter init%rc,$(notdir $(_dest)))$(filter %/etc/init,$(dir $(_dest))),\
40                    $(eval $(call copy-init-script-file-checked,$(_src),$(_fulldest))),\
41                    $(eval $(call copy-one-file,$(_src),$(_fulldest)))))) \
42        $(eval unique_product_copy_files_destinations += $(_dest))))
43
44# Dump a list of overriden (and ignored PRODUCT_COPY_FILES entries)
45pcf_ignored_file := $(PRODUCT_OUT)/product_copy_files_ignored.txt
46$(pcf_ignored_file): PRIVATE_IGNORED := $(sort $(product_copy_files_ignored))
47$(pcf_ignored_file):
48	echo "$(PRIVATE_IGNORED)" | tr " " "\n" >$@
49
50$(call dist-for-goals,droidcore,$(pcf_ignored_file):logs/$(notdir $(pcf_ignored_file)))
51
52pcf_ignored_file :=
53product_copy_files_ignored :=
54unique_product_copy_files_pairs :=
55unique_product_copy_files_destinations :=
56
57# -----------------------------------------------------------------
58# Returns the max allowed size for an image suitable for hash verification
59# (e.g., boot.img, recovery.img, etc).
60# The value 69632 derives from MAX_VBMETA_SIZE + MAX_FOOTER_SIZE in $(AVBTOOL).
61# $(1): partition size to flash the image
62define get-hash-image-max-size
63$(if $(1), \
64  $(if $(filter true,$(BOARD_AVB_ENABLE)), \
65    $(eval _hash_meta_size := 69632), \
66    $(eval _hash_meta_size := 0)) \
67  $(1)-$(_hash_meta_size))
68endef
69
70# -----------------------------------------------------------------
71# Define rules to copy headers defined in copy_headers.mk
72# If more than one makefile declared a header, print a warning,
73# then copy the last one defined. This matches the previous make
74# behavior.
75has_dup_copy_headers :=
76$(foreach dest,$(ALL_COPIED_HEADERS), \
77    $(eval _srcs := $(ALL_COPIED_HEADERS.$(dest).SRC)) \
78    $(eval _src := $(lastword $(_srcs))) \
79    $(if $(call streq,$(_src),$(_srcs)),, \
80        $(warning Duplicate header copy: $(dest)) \
81        $(warning _ Using $(_src)) \
82        $(warning __ from $(lastword $(ALL_COPIED_HEADERS.$(dest).MAKEFILE))) \
83        $(eval _makefiles := $$(wordlist 1,$(call int_subtract,$(words $(ALL_COPIED_HEADERS.$(dest).MAKEFILE)),1),$$(ALL_COPIED_HEADERS.$$(dest).MAKEFILE))) \
84        $(foreach src,$(wordlist 1,$(call int_subtract,$(words $(_srcs)),1),$(_srcs)), \
85            $(warning _ Ignoring $(src)) \
86            $(warning __ from $(firstword $(_makefiles))) \
87            $(eval _makefiles := $$(wordlist 2,9999,$$(_makefiles)))) \
88        $(eval has_dup_copy_headers := true)) \
89    $(eval $(call copy-one-header,$(_src),$(dest))))
90all_copied_headers: $(ALL_COPIED_HEADERS)
91
92ifdef has_dup_copy_headers
93  has_dup_copy_headers :=
94  ifneq ($(BUILD_BROKEN_DUP_COPY_HEADERS),true)
95    $(error duplicate header copies are no longer allowed. For more information about headers, see: https://android.googlesource.com/platform/build/soong/+/master/docs/best_practices.md#headers)
96  endif
97endif
98
99# -----------------------------------------------------------------
100# docs/index.html
101ifeq (,$(TARGET_BUILD_APPS))
102gen := $(OUT_DOCS)/index.html
103ALL_DOCS += $(gen)
104$(gen): frameworks/base/docs/docs-redirect-index.html
105	@mkdir -p $(dir $@)
106	@cp -f $< $@
107endif
108
109ndk_doxygen_out := $(OUT_NDK_DOCS)
110ndk_headers := $(SOONG_OUT_DIR)/ndk/sysroot/usr/include
111ndk_docs_src_dir := frameworks/native/docs
112ndk_doxyfile := $(ndk_docs_src_dir)/Doxyfile
113ifneq ($(wildcard $(ndk_docs_src_dir)),)
114ndk_docs_srcs := $(addprefix $(ndk_docs_src_dir)/,\
115    $(call find-files-in-subdirs,$(ndk_docs_src_dir),"*",.))
116$(ndk_doxygen_out)/index.html: $(ndk_docs_srcs) $(SOONG_OUT_DIR)/ndk.timestamp
117	@mkdir -p $(ndk_doxygen_out)
118	@echo "Generating NDK docs to $(ndk_doxygen_out)"
119	@( cat $(ndk_doxyfile); \
120	    echo "INPUT=$(ndk_headers)"; \
121	    echo "HTML_OUTPUT=$(ndk_doxygen_out)" \
122	) | doxygen -
123
124# Note: Not a part of the docs target because we don't have doxygen available.
125# You can run this target locally if you have doxygen installed.
126ndk-docs: $(ndk_doxygen_out)/index.html
127.PHONY: ndk-docs
128endif
129
130$(call dist-for-goals,sdk,$(API_FINGERPRINT))
131
132# -----------------------------------------------------------------
133# property_overrides_split_enabled
134property_overrides_split_enabled :=
135ifeq ($(BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED), true)
136  property_overrides_split_enabled := true
137endif
138
139# -----------------------------------------------------------------
140# FINAL_VENDOR_DEFAULT_PROPERTIES will be installed in vendor/default.prop if
141# property_overrides_split_enabled is true. Otherwise it will be installed in
142# ROOT/default.prop.
143ifdef BOARD_VNDK_VERSION
144  ifeq ($(BOARD_VNDK_VERSION),current)
145    FINAL_VENDOR_DEFAULT_PROPERTIES := ro.vndk.version=$(PLATFORM_VNDK_VERSION)
146  else
147    FINAL_VENDOR_DEFAULT_PROPERTIES := ro.vndk.version=$(BOARD_VNDK_VERSION)
148  endif
149  ifdef BOARD_VNDK_RUNTIME_DISABLE
150    FINAL_VENDOR_DEFAULT_PROPERTIES += ro.vndk.lite=true
151  endif
152else
153  FINAL_VENDOR_DEFAULT_PROPERTIES := ro.vndk.version=$(PLATFORM_VNDK_VERSION)
154  FINAL_VENDOR_DEFAULT_PROPERTIES += ro.vndk.lite=true
155endif
156FINAL_VENDOR_DEFAULT_PROPERTIES += \
157    $(call collapse-pairs, $(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))
158
159# Add cpu properties for bionic and ART.
160FINAL_VENDOR_DEFAULT_PROPERTIES += ro.bionic.arch=$(TARGET_ARCH)
161FINAL_VENDOR_DEFAULT_PROPERTIES += ro.bionic.cpu_variant=$(TARGET_CPU_VARIANT_RUNTIME)
162FINAL_VENDOR_DEFAULT_PROPERTIES += ro.bionic.2nd_arch=$(TARGET_2ND_ARCH)
163FINAL_VENDOR_DEFAULT_PROPERTIES += ro.bionic.2nd_cpu_variant=$(TARGET_2ND_CPU_VARIANT_RUNTIME)
164
165FINAL_VENDOR_DEFAULT_PROPERTIES += persist.sys.dalvik.vm.lib.2=libart.so
166FINAL_VENDOR_DEFAULT_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).variant=$(DEX2OAT_TARGET_CPU_VARIANT_RUNTIME)
167ifneq ($(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
168  FINAL_VENDOR_DEFAULT_PROPERTIES += dalvik.vm.isa.$(TARGET_ARCH).features=$(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
169endif
170
171ifdef TARGET_2ND_ARCH
172  FINAL_VENDOR_DEFAULT_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).variant=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT_RUNTIME)
173  ifneq ($($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
174    FINAL_VENDOR_DEFAULT_PROPERTIES += dalvik.vm.isa.$(TARGET_2ND_ARCH).features=$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)
175  endif
176endif
177
178# Although these variables are prefixed with TARGET_RECOVERY_, they are also needed under charger
179# mode (via libminui).
180ifdef TARGET_RECOVERY_DEFAULT_ROTATION
181FINAL_VENDOR_DEFAULT_PROPERTIES += \
182    ro.minui.default_rotation=$(TARGET_RECOVERY_DEFAULT_ROTATION)
183endif
184ifdef TARGET_RECOVERY_OVERSCAN_PERCENT
185FINAL_VENDOR_DEFAULT_PROPERTIES += \
186    ro.minui.overscan_percent=$(TARGET_RECOVERY_OVERSCAN_PERCENT)
187endif
188ifdef TARGET_RECOVERY_PIXEL_FORMAT
189FINAL_VENDOR_DEFAULT_PROPERTIES += \
190    ro.minui.pixel_format=$(TARGET_RECOVERY_PIXEL_FORMAT)
191endif
192FINAL_VENDOR_DEFAULT_PROPERTIES := $(call uniq-pairs-by-first-component, \
193    $(FINAL_VENDOR_DEFAULT_PROPERTIES),=)
194
195# -----------------------------------------------------------------
196# prop.default
197
198BUILDINFO_SH := build/make/tools/buildinfo.sh
199BUILDINFO_COMMON_SH := build/make/tools/buildinfo_common.sh
200
201# Generates a set of sysprops common to all partitions to a file.
202# $(1): Partition name
203# $(2): Output file name
204define generate-common-build-props
205	PRODUCT_BRAND="$(PRODUCT_BRAND)" \
206	PRODUCT_DEVICE="$(TARGET_DEVICE)" \
207	PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
208	PRODUCT_MODEL="$(PRODUCT_MODEL)" \
209	PRODUCT_NAME="$(TARGET_PRODUCT)" \
210	$(call generate-common-build-props-with-product-vars-set,$(1),$(2))
211endef
212
213# Like the above macro, but requiring the relevant PRODUCT_ environment
214# variables to be set when called.
215define generate-common-build-props-with-product-vars-set
216	BUILD_FINGERPRINT="$(BUILD_FINGERPRINT_FROM_FILE)" \
217	BUILD_ID="$(BUILD_ID)" \
218	BUILD_NUMBER="$(BUILD_NUMBER_FROM_FILE)" \
219	BUILD_VERSION_TAGS="$(BUILD_VERSION_TAGS)" \
220	DATE="$(DATE_FROM_FILE)" \
221	PLATFORM_SDK_VERSION="$(PLATFORM_SDK_VERSION)" \
222	PLATFORM_VERSION="$(PLATFORM_VERSION)" \
223	TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \
224	bash $(BUILDINFO_COMMON_SH) "$(1)" >> $(2)
225endef
226
227ifdef property_overrides_split_enabled
228INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_OUT)/etc/prop.default
229INSTALLED_DEFAULT_PROP_OLD_TARGET := $(TARGET_ROOT_OUT)/default.prop
230ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_OLD_TARGET)
231$(INSTALLED_DEFAULT_PROP_OLD_TARGET): $(INSTALLED_DEFAULT_PROP_TARGET)
232else
233# legacy path
234INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_ROOT_OUT)/default.prop
235endif
236ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_TARGET)
237FINAL_DEFAULT_PROPERTIES := \
238    $(call collapse-pairs, $(ADDITIONAL_DEFAULT_PROPERTIES)) \
239    $(call collapse-pairs, $(PRODUCT_SYSTEM_DEFAULT_PROPERTIES))
240ifndef property_overrides_split_enabled
241  FINAL_DEFAULT_PROPERTIES += \
242      $(call collapse-pairs, $(FINAL_VENDOR_DEFAULT_PROPERTIES))
243endif
244FINAL_DEFAULT_PROPERTIES := $(call uniq-pairs-by-first-component, \
245    $(FINAL_DEFAULT_PROPERTIES),=)
246
247intermediate_system_build_prop := $(call intermediates-dir-for,ETC,system_build_prop)/build.prop
248
249$(INSTALLED_DEFAULT_PROP_TARGET): $(BUILDINFO_COMMON_SH) $(intermediate_system_build_prop)
250	@echo Target buildinfo: $@
251	@mkdir -p $(dir $@)
252	@rm -f $@
253	$(hide) echo "#" > $@; \
254	        echo "# ADDITIONAL_DEFAULT_PROPERTIES" >> $@; \
255	        echo "#" >> $@;
256	$(hide) $(foreach line,$(FINAL_DEFAULT_PROPERTIES), \
257	    echo "$(line)" >> $@;)
258	$(hide) build/make/tools/post_process_props.py $@
259ifdef property_overrides_split_enabled
260	$(hide) mkdir -p $(TARGET_ROOT_OUT)
261	$(hide) ln -sf system/etc/prop.default $(INSTALLED_DEFAULT_PROP_OLD_TARGET)
262endif
263
264# -----------------------------------------------------------------
265# vendor default.prop
266INSTALLED_VENDOR_DEFAULT_PROP_TARGET :=
267ifdef property_overrides_split_enabled
268INSTALLED_VENDOR_DEFAULT_PROP_TARGET := $(TARGET_OUT_VENDOR)/default.prop
269ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_VENDOR_DEFAULT_PROP_TARGET)
270
271$(INSTALLED_VENDOR_DEFAULT_PROP_TARGET): $(INSTALLED_DEFAULT_PROP_TARGET)
272	@echo Target buildinfo: $@
273	@mkdir -p $(dir $@)
274	$(hide) echo "#" > $@; \
275	        echo "# ADDITIONAL VENDOR DEFAULT PROPERTIES" >> $@; \
276	        echo "#" >> $@;
277	$(hide) $(foreach line,$(FINAL_VENDOR_DEFAULT_PROPERTIES), \
278	    echo "$(line)" >> $@;)
279	$(hide) build/make/tools/post_process_props.py $@
280
281endif  # property_overrides_split_enabled
282
283# -----------------------------------------------------------------
284# build.prop
285INSTALLED_BUILD_PROP_TARGET := $(TARGET_OUT)/build.prop
286ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_BUILD_PROP_TARGET)
287FINAL_BUILD_PROPERTIES := \
288    $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))
289FINAL_BUILD_PROPERTIES := $(call uniq-pairs-by-first-component, \
290    $(FINAL_BUILD_PROPERTIES),=)
291
292# A list of arbitrary tags describing the build configuration.
293# Force ":=" so we can use +=
294BUILD_VERSION_TAGS := $(BUILD_VERSION_TAGS)
295ifeq ($(TARGET_BUILD_TYPE),debug)
296  BUILD_VERSION_TAGS += debug
297endif
298# The "test-keys" tag marks builds signed with the old test keys,
299# which are available in the SDK.  "dev-keys" marks builds signed with
300# non-default dev keys (usually private keys from a vendor directory).
301# Both of these tags will be removed and replaced with "release-keys"
302# when the target-files is signed in a post-build step.
303ifeq ($(DEFAULT_SYSTEM_DEV_CERTIFICATE),build/target/product/security/testkey)
304BUILD_KEYS := test-keys
305else
306BUILD_KEYS := dev-keys
307endif
308BUILD_VERSION_TAGS += $(BUILD_KEYS)
309BUILD_VERSION_TAGS := $(subst $(space),$(comma),$(sort $(BUILD_VERSION_TAGS)))
310
311# A human-readable string that descibes this build in detail.
312build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER_FROM_FILE) $(BUILD_VERSION_TAGS)
313$(intermediate_system_build_prop): PRIVATE_BUILD_DESC := $(build_desc)
314
315# The string used to uniquely identify the combined build and product; used by the OTA server.
316ifeq (,$(strip $(BUILD_FINGERPRINT)))
317  ifeq ($(strip $(HAS_BUILD_NUMBER)),false)
318    BF_BUILD_NUMBER := $(BUILD_USERNAME)$$($(DATE_FROM_FILE) +%m%d%H%M)
319  else
320    BF_BUILD_NUMBER := $(file <$(BUILD_NUMBER_FILE))
321  endif
322  BUILD_FINGERPRINT := $(PRODUCT_BRAND)/$(TARGET_PRODUCT)/$(TARGET_DEVICE):$(PLATFORM_VERSION)/$(BUILD_ID)/$(BF_BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)
323endif
324# unset it for safety.
325BF_BUILD_NUMBER :=
326
327BUILD_FINGERPRINT_FILE := $(PRODUCT_OUT)/build_fingerprint.txt
328ifneq (,$(shell mkdir -p $(PRODUCT_OUT) && echo $(BUILD_FINGERPRINT) >$(BUILD_FINGERPRINT_FILE) && grep " " $(BUILD_FINGERPRINT_FILE)))
329  $(error BUILD_FINGERPRINT cannot contain spaces: "$(file <$(BUILD_FINGERPRINT_FILE))")
330endif
331BUILD_FINGERPRINT_FROM_FILE := $$(cat $(BUILD_FINGERPRINT_FILE))
332# unset it for safety.
333BUILD_FINGERPRINT :=
334
335# The string used to uniquely identify the system build; used by the OTA server.
336# This purposefully excludes any product-specific variables.
337ifeq (,$(strip $(BUILD_THUMBPRINT)))
338  BUILD_THUMBPRINT := $(PLATFORM_VERSION)/$(BUILD_ID)/$(BUILD_NUMBER_FROM_FILE):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)
339endif
340
341BUILD_THUMBPRINT_FILE := $(PRODUCT_OUT)/build_thumbprint.txt
342ifneq (,$(shell mkdir -p $(PRODUCT_OUT) && echo $(BUILD_THUMBPRINT) >$(BUILD_THUMBPRINT_FILE) && grep " " $(BUILD_THUMBPRINT_FILE)))
343  $(error BUILD_THUMBPRINT cannot contain spaces: "$(file <$(BUILD_THUMBPRINT_FILE))")
344endif
345BUILD_THUMBPRINT_FROM_FILE := $$(cat $(BUILD_THUMBPRINT_FILE))
346# unset it for safety.
347BUILD_THUMBPRINT :=
348
349KNOWN_OEM_THUMBPRINT_PROPERTIES := \
350    ro.product.brand \
351    ro.product.name \
352    ro.product.device
353OEM_THUMBPRINT_PROPERTIES := $(filter $(KNOWN_OEM_THUMBPRINT_PROPERTIES),\
354    $(PRODUCT_OEM_PROPERTIES))
355
356# Display parameters shown under Settings -> About Phone
357ifeq ($(TARGET_BUILD_VARIANT),user)
358  # User builds should show:
359  # release build number or branch.buld_number non-release builds
360
361  # Dev. branches should have DISPLAY_BUILD_NUMBER set
362  ifeq (true,$(DISPLAY_BUILD_NUMBER))
363    BUILD_DISPLAY_ID := $(BUILD_ID).$(BUILD_NUMBER_FROM_FILE) $(BUILD_KEYS)
364  else
365    BUILD_DISPLAY_ID := $(BUILD_ID) $(BUILD_KEYS)
366  endif
367else
368  # Non-user builds should show detailed build information
369  BUILD_DISPLAY_ID := $(build_desc)
370endif
371
372# Accepts a whitespace separated list of product locales such as
373# (en_US en_AU en_GB...) and returns the first locale in the list with
374# underscores replaced with hyphens. In the example above, this will
375# return "en-US".
376define get-default-product-locale
377$(strip $(subst _,-, $(firstword $(1))))
378endef
379
380# TARGET_BUILD_FLAVOR and ro.build.flavor are used only by the test
381# harness to distinguish builds. Only add _asan for a sanitized build
382# if it isn't already a part of the flavor (via a dedicated lunch
383# config for example).
384TARGET_BUILD_FLAVOR := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)
385ifneq (, $(filter address, $(SANITIZE_TARGET)))
386ifeq (,$(findstring _asan,$(TARGET_BUILD_FLAVOR)))
387TARGET_BUILD_FLAVOR := $(TARGET_BUILD_FLAVOR)_asan
388endif
389endif
390
391ifdef TARGET_SYSTEM_PROP
392system_prop_file := $(TARGET_SYSTEM_PROP)
393else
394system_prop_file := $(wildcard $(TARGET_DEVICE_DIR)/system.prop)
395endif
396$(intermediate_system_build_prop): $(BUILDINFO_SH) $(BUILDINFO_COMMON_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(system_prop_file) $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(API_FINGERPRINT)
397	@echo Target buildinfo: $@
398	@mkdir -p $(dir $@)
399	$(hide) echo > $@
400ifneq ($(PRODUCT_OEM_PROPERTIES),)
401	$(hide) echo "#" >> $@; \
402	        echo "# PRODUCT_OEM_PROPERTIES" >> $@; \
403	        echo "#" >> $@;
404	$(hide) $(foreach prop,$(PRODUCT_OEM_PROPERTIES), \
405	    echo "import /oem/oem.prop $(prop)" >> $@;)
406endif
407	$(hide) PRODUCT_BRAND="$(PRODUCT_SYSTEM_BRAND)" \
408	        PRODUCT_MANUFACTURER="$(PRODUCT_SYSTEM_MANUFACTURER)" \
409	        PRODUCT_MODEL="$(PRODUCT_SYSTEM_MODEL)" \
410	        PRODUCT_NAME="$(PRODUCT_SYSTEM_NAME)" \
411	        PRODUCT_DEVICE="$(PRODUCT_SYSTEM_DEVICE)" \
412	        $(call generate-common-build-props-with-product-vars-set,system,$@)
413	$(hide) TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \
414	        TARGET_BUILD_FLAVOR="$(TARGET_BUILD_FLAVOR)" \
415	        TARGET_DEVICE="$(TARGET_DEVICE)" \
416	        PRODUCT_DEFAULT_LOCALE="$(call get-default-product-locale,$(PRODUCT_LOCALES))" \
417	        PRODUCT_DEFAULT_WIFI_CHANNELS="$(PRODUCT_DEFAULT_WIFI_CHANNELS)" \
418	        PRIVATE_BUILD_DESC="$(PRIVATE_BUILD_DESC)" \
419	        BUILD_ID="$(BUILD_ID)" \
420	        BUILD_DISPLAY_ID="$(BUILD_DISPLAY_ID)" \
421	        DATE="$(DATE_FROM_FILE)" \
422	        BUILD_USERNAME="$(BUILD_USERNAME)" \
423	        BUILD_HOSTNAME="$(BUILD_HOSTNAME)" \
424	        BUILD_NUMBER="$(BUILD_NUMBER_FROM_FILE)" \
425	        BOARD_BUILD_SYSTEM_ROOT_IMAGE="$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)" \
426	        AB_OTA_UPDATER="$(AB_OTA_UPDATER)" \
427	        PLATFORM_VERSION="$(PLATFORM_VERSION)" \
428	        PLATFORM_SECURITY_PATCH="$(PLATFORM_SECURITY_PATCH)" \
429	        PLATFORM_BASE_OS="$(PLATFORM_BASE_OS)" \
430	        PLATFORM_SDK_VERSION="$(PLATFORM_SDK_VERSION)" \
431	        PLATFORM_PREVIEW_SDK_VERSION="$(PLATFORM_PREVIEW_SDK_VERSION)" \
432	        PLATFORM_PREVIEW_SDK_FINGERPRINT="$$(cat $(API_FINGERPRINT))" \
433	        PLATFORM_VERSION_CODENAME="$(PLATFORM_VERSION_CODENAME)" \
434	        PLATFORM_VERSION_ALL_CODENAMES="$(PLATFORM_VERSION_ALL_CODENAMES)" \
435	        PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION="$(PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION)" \
436	        BUILD_VERSION_TAGS="$(BUILD_VERSION_TAGS)" \
437	        $(if $(OEM_THUMBPRINT_PROPERTIES),BUILD_THUMBPRINT="$(BUILD_THUMBPRINT_FROM_FILE)") \
438	        TARGET_CPU_ABI_LIST="$(TARGET_CPU_ABI_LIST)" \
439	        TARGET_CPU_ABI_LIST_32_BIT="$(TARGET_CPU_ABI_LIST_32_BIT)" \
440	        TARGET_CPU_ABI_LIST_64_BIT="$(TARGET_CPU_ABI_LIST_64_BIT)" \
441	        TARGET_CPU_ABI="$(TARGET_CPU_ABI)" \
442	        TARGET_CPU_ABI2="$(TARGET_CPU_ABI2)" \
443	        bash $(BUILDINFO_SH) >> $@
444	$(hide) $(foreach file,$(system_prop_file), \
445	    if [ -f "$(file)" ]; then \
446	        echo Target buildinfo from: "$(file)"; \
447	        echo "" >> $@; \
448	        echo "#" >> $@; \
449	        echo "# from $(file)" >> $@; \
450	        echo "#" >> $@; \
451	        cat $(file) >> $@; \
452	        echo "# end of $(file)" >> $@; \
453	    fi;)
454	$(if $(FINAL_BUILD_PROPERTIES), \
455	    $(hide) echo >> $@; \
456	            echo "#" >> $@; \
457	            echo "# ADDITIONAL_BUILD_PROPERTIES" >> $@; \
458	            echo "#" >> $@; )
459	$(hide) $(foreach line,$(FINAL_BUILD_PROPERTIES), \
460	    echo "$(line)" >> $@;)
461	$(hide) build/make/tools/post_process_props.py $@ $(PRODUCT_SYSTEM_PROPERTY_BLACKLIST)
462
463build_desc :=
464
465ifeq (,$(filter true, $(TARGET_NO_KERNEL) $(TARGET_NO_RECOVERY)))
466INSTALLED_RECOVERYIMAGE_TARGET := $(PRODUCT_OUT)/recovery.img
467else
468INSTALLED_RECOVERYIMAGE_TARGET :=
469endif
470
471$(INSTALLED_BUILD_PROP_TARGET): $(intermediate_system_build_prop) $(INSTALLED_RECOVERYIMAGE_TARGET)
472	@echo "Target build info: $@"
473	$(hide) grep -v 'ro.product.first_api_level' $(intermediate_system_build_prop) > $@
474
475# -----------------------------------------------------------------
476# vendor build.prop
477#
478# For verifying that the vendor build is what we think it is
479INSTALLED_VENDOR_BUILD_PROP_TARGET := $(TARGET_OUT_VENDOR)/build.prop
480ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_VENDOR_BUILD_PROP_TARGET)
481
482ifdef property_overrides_split_enabled
483FINAL_VENDOR_BUILD_PROPERTIES += \
484    $(call collapse-pairs, $(PRODUCT_PROPERTY_OVERRIDES))
485FINAL_VENDOR_BUILD_PROPERTIES := $(call uniq-pairs-by-first-component, \
486    $(FINAL_VENDOR_BUILD_PROPERTIES),=)
487endif  # property_overrides_split_enabled
488
489$(INSTALLED_VENDOR_BUILD_PROP_TARGET): $(BUILDINFO_COMMON_SH) $(intermediate_system_build_prop)
490	@echo Target vendor buildinfo: $@
491	@mkdir -p $(dir $@)
492	$(hide) echo > $@
493ifeq ($(PRODUCT_USE_DYNAMIC_PARTITIONS),true)
494	$(hide) echo ro.boot.dynamic_partitions=true >> $@
495endif
496ifeq ($(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS),true)
497	$(hide) echo ro.boot.dynamic_partitions_retrofit=true >> $@
498endif
499	$(hide) grep 'ro.product.first_api_level' $(intermediate_system_build_prop) >> $@ || true
500	$(hide) echo ro.vendor.build.security_patch="$(VENDOR_SECURITY_PATCH)">>$@
501	$(hide) echo ro.vendor.product.cpu.abilist="$(TARGET_CPU_ABI_LIST)">>$@
502	$(hide) echo ro.vendor.product.cpu.abilist32="$(TARGET_CPU_ABI_LIST_32_BIT)">>$@
503	$(hide) echo ro.vendor.product.cpu.abilist64="$(TARGET_CPU_ABI_LIST_64_BIT)">>$@
504	$(hide) echo ro.product.board="$(TARGET_BOOTLOADER_BOARD_NAME)">>$@
505	$(hide) echo ro.board.platform="$(TARGET_BOARD_PLATFORM)">>$@
506	$(hide) echo ro.hwui.use_vulkan="$(TARGET_USES_VULKAN)">>$@
507ifdef TARGET_SCREEN_DENSITY
508	$(hide) echo ro.sf.lcd_density="$(TARGET_SCREEN_DENSITY)">>$@
509endif
510	$(hide) $(call generate-common-build-props,vendor,$@)
511	$(hide) echo "#" >> $@; \
512	        echo "# BOOTIMAGE_BUILD_PROPERTIES" >> $@; \
513	        echo "#" >> $@;
514	$(hide) echo ro.bootimage.build.date=`$(DATE_FROM_FILE)`>>$@
515	$(hide) echo ro.bootimage.build.date.utc=`$(DATE_FROM_FILE) +%s`>>$@
516	$(hide) echo ro.bootimage.build.fingerprint="$(BUILD_FINGERPRINT_FROM_FILE)">>$@
517	$(hide) echo "#" >> $@; \
518	        echo "# ADDITIONAL VENDOR BUILD PROPERTIES" >> $@; \
519	        echo "#" >> $@;
520	$(hide) cat $(INSTALLED_ANDROID_INFO_TXT_TARGET) | grep 'require version-' | sed -e 's/require version-/ro.build.expect./g' >> $@
521ifdef property_overrides_split_enabled
522	$(hide) $(foreach line,$(FINAL_VENDOR_BUILD_PROPERTIES), \
523	    echo "$(line)" >> $@;)
524endif  # property_overrides_split_enabled
525	$(hide) build/make/tools/post_process_props.py $@ $(PRODUCT_VENDOR_PROPERTY_BLACKLIST)
526
527# -----------------------------------------------------------------
528# product build.prop
529INSTALLED_PRODUCT_BUILD_PROP_TARGET := $(TARGET_OUT_PRODUCT)/build.prop
530ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_PRODUCT_BUILD_PROP_TARGET)
531
532ifdef TARGET_PRODUCT_PROP
533product_prop_files := $(TARGET_PRODUCT_PROP)
534else
535product_prop_files := $(wildcard $(TARGET_DEVICE_DIR)/product.prop)
536endif
537
538FINAL_PRODUCT_PROPERTIES += \
539    $(call collapse-pairs, $(PRODUCT_PRODUCT_PROPERTIES) $(ADDITIONAL_PRODUCT_PROPERTIES))
540FINAL_PRODUCT_PROPERTIES := $(call uniq-pairs-by-first-component, \
541    $(FINAL_PRODUCT_PROPERTIES),=)
542
543$(INSTALLED_PRODUCT_BUILD_PROP_TARGET): $(BUILDINFO_COMMON_SH) $(product_prop_files)
544	@echo Target product buildinfo: $@
545	@mkdir -p $(dir $@)
546	$(hide) echo > $@
547ifdef BOARD_USES_PRODUCTIMAGE
548	$(hide) $(call generate-common-build-props,product,$@)
549endif  # BOARD_USES_PRODUCTIMAGE
550	$(hide) $(foreach file,$(product_prop_files), \
551	    if [ -f "$(file)" ]; then \
552	        echo Target product properties from: "$(file)"; \
553	        echo "" >> $@; \
554	        echo "#" >> $@; \
555	        echo "# from $(file)" >> $@; \
556	        echo "#" >> $@; \
557	        cat $(file) >> $@; \
558	        echo "# end of $(file)" >> $@; \
559	    fi;)
560	$(hide) echo "#" >> $@; \
561	        echo "# ADDITIONAL PRODUCT PROPERTIES" >> $@; \
562	        echo "#" >> $@; \
563	        echo "ro.build.characteristics=$(TARGET_AAPT_CHARACTERISTICS)" >> $@;
564	$(hide) $(foreach line,$(FINAL_PRODUCT_PROPERTIES), \
565	    echo "$(line)" >> $@;)
566	$(hide) build/make/tools/post_process_props.py $@
567
568# ----------------------------------------------------------------
569# odm build.prop
570INSTALLED_ODM_BUILD_PROP_TARGET := $(TARGET_OUT_ODM)/etc/build.prop
571ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_ODM_BUILD_PROP_TARGET)
572
573FINAL_ODM_BUILD_PROPERTIES += \
574    $(call collapse-pairs, $(PRODUCT_ODM_PROPERTIES))
575FINAL_ODM_BUILD_PROPERTIES := $(call uniq-pairs-by-first-component, \
576    $(FINAL_ODM_BUILD_PROPERTIES),=)
577
578$(INSTALLED_ODM_BUILD_PROP_TARGET): $(BUILDINFO_COMMON_SH)
579	@echo Target odm buildinfo: $@
580	@mkdir -p $(dir $@)
581	$(hide) echo > $@
582	$(hide) echo ro.odm.product.cpu.abilist="$(TARGET_CPU_ABI_LIST)">>$@
583	$(hide) echo ro.odm.product.cpu.abilist32="$(TARGET_CPU_ABI_LIST_32_BIT)">>$@
584	$(hide) echo ro.odm.product.cpu.abilist64="$(TARGET_CPU_ABI_LIST_64_BIT)">>$@
585	$(hide) $(call generate-common-build-props,odm,$@)
586	$(hide) echo "#" >> $@; \
587	        echo "# ADDITIONAL ODM BUILD PROPERTIES" >> $@; \
588	        echo "#" >> $@;
589	$(hide) $(foreach line,$(FINAL_ODM_BUILD_PROPERTIES), \
590	    echo "$(line)" >> $@;)
591	$(hide) build/make/tools/post_process_props.py $@
592
593# -----------------------------------------------------------------
594# product_services build.prop (unless it's merged into /product)
595ifdef MERGE_PRODUCT_SERVICES_INTO_PRODUCT
596  ifneq (,$(PRODUCT_PRODUCT_SERVICES_PROPERTIES))
597    $(error PRODUCT_PRODUCT_SERVICES_PROPERTIES is not supported in this build.)
598  endif
599else
600INSTALLED_PRODUCT_SERVICES_BUILD_PROP_TARGET := $(TARGET_OUT_PRODUCT_SERVICES)/build.prop
601ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_PRODUCT_SERVICES_BUILD_PROP_TARGET)
602
603FINAL_PRODUCT_SERVICES_PROPERTIES += \
604    $(call collapse-pairs, $(PRODUCT_PRODUCT_SERVICES_PROPERTIES))
605FINAL_PRODUCT_SERVICES_PROPERTIES := $(call uniq-pairs-by-first-component, \
606    $(FINAL_PRODUCT_SERVICES_PROPERTIES),=)
607$(INSTALLED_PRODUCT_SERVICES_BUILD_PROP_TARGET): $(BUILDINFO_COMMON_SH)
608	@echo Target product_services buildinfo: $@
609	@mkdir -p $(dir $@)
610	$(hide) echo > $@
611ifdef BOARD_USES_PRODUCT_SERVICESIMAGE
612	$(hide) $(call generate-common-build-props,product_services,$@)
613endif  # BOARD_USES_PRODUCT_SERVICESIMAGE
614	$(hide) echo "#" >> $@; \
615	        echo "# ADDITIONAL PRODUCT_SERVICES PROPERTIES" >> $@; \
616	        echo "#" >> $@;
617	$(hide) $(foreach line,$(FINAL_PRODUCT_SERVICES_PROPERTIES), \
618	    echo "$(line)" >> $@;)
619	$(hide) build/make/tools/post_process_props.py $@
620endif # MERGE_PRODUCT_SERVICES_INTO_PRODUCT
621
622# ----------------------------------------------------------------
623
624# -----------------------------------------------------------------
625# sdk-build.prop
626#
627# There are certain things in build.prop that we don't want to
628# ship with the sdk; remove them.
629
630# This must be a list of entire property keys followed by
631# "=" characters, without any internal spaces.
632sdk_build_prop_remove := \
633	ro.build.user= \
634	ro.build.host= \
635	ro.product.brand= \
636	ro.product.manufacturer= \
637	ro.product.device=
638# TODO: Remove this soon-to-be obsolete property
639sdk_build_prop_remove += ro.build.product=
640INSTALLED_SDK_BUILD_PROP_TARGET := $(PRODUCT_OUT)/sdk/sdk-build.prop
641$(INSTALLED_SDK_BUILD_PROP_TARGET): $(INSTALLED_BUILD_PROP_TARGET)
642	@echo SDK buildinfo: $@
643	@mkdir -p $(dir $@)
644	$(hide) grep -v "$(subst $(space),\|,$(strip \
645	            $(sdk_build_prop_remove)))" $< > $@.tmp
646	$(hide) for x in $(sdk_build_prop_remove); do \
647	            echo "$$x"generic >> $@.tmp; done
648	$(hide) mv $@.tmp $@
649
650# -----------------------------------------------------------------
651# package stats
652PACKAGE_STATS_FILE := $(PRODUCT_OUT)/package-stats.txt
653PACKAGES_TO_STAT := \
654    $(sort $(filter $(TARGET_OUT)/% $(TARGET_OUT_DATA)/%, \
655	$(filter %.jar %.apk, $(ALL_DEFAULT_INSTALLED_MODULES))))
656$(PACKAGE_STATS_FILE): $(PACKAGES_TO_STAT)
657	@echo Package stats: $@
658	@mkdir -p $(dir $@)
659	$(hide) rm -f $@
660ifeq ($(PACKAGES_TO_STAT),)
661# Create empty package stats file if target builds no jar(s) or apk(s).
662	$(hide) touch $@
663else
664	$(hide) build/make/tools/dump-package-stats $^ > $@
665endif
666
667.PHONY: package-stats
668package-stats: $(PACKAGE_STATS_FILE)
669
670# -----------------------------------------------------------------
671# Cert-to-package mapping.  Used by the post-build signing tools.
672# Use a macro to add newline to each echo command
673define _apkcerts_write_line
674$(hide) echo -n 'name="$(1).apk" certificate="$2" private_key="$3"' >> $5
675$(if $(4), $(hide) echo -n ' compressed="$4"' >> $5)
676$(hide) echo '' >> $5
677
678endef
679
680name := $(TARGET_PRODUCT)
681ifeq ($(TARGET_BUILD_TYPE),debug)
682  name := $(name)_debug
683endif
684name := $(name)-apkcerts-$(FILE_NAME_TAG)
685intermediates := \
686	$(call intermediates-dir-for,PACKAGING,apkcerts)
687APKCERTS_FILE := $(intermediates)/$(name).txt
688# We don't need to really build all the modules.
689# TODO: rebuild APKCERTS_FILE if any app change its cert.
690$(APKCERTS_FILE):
691	@echo APK certs list: $@
692	@mkdir -p $(dir $@)
693	@rm -f $@
694	$(foreach p,$(PACKAGES),\
695	  $(if $(PACKAGES.$(p).EXTERNAL_KEY),\
696	    $(call _apkcerts_write_line,$(p),"EXTERNAL","",$(PACKAGES.$(p).COMPRESSED),$@),\
697	    $(call _apkcerts_write_line,$(p),$(PACKAGES.$(p).CERTIFICATE),$(PACKAGES.$(p).PRIVATE_KEY),$(PACKAGES.$(p).COMPRESSED),$@)))
698	# In case value of PACKAGES is empty.
699	$(hide) touch $@
700
701.PHONY: apkcerts-list
702apkcerts-list: $(APKCERTS_FILE)
703
704ifneq (,$(TARGET_BUILD_APPS))
705  $(call dist-for-goals, apps_only, $(APKCERTS_FILE):apkcerts.txt)
706  $(call dist-for-goals, apps_only, $(SOONG_APEX_KEYS_FILE):apexkeys.txt)
707endif
708
709
710# -----------------------------------------------------------------
711# build system stats
712BUILD_SYSTEM_STATS := $(PRODUCT_OUT)/build_system_stats.txt
713$(BUILD_SYSTEM_STATS):
714	@rm -f $@
715	@$(foreach s,$(STATS.MODULE_TYPE),echo "modules_type_make,$(s),$(words $(STATS.MODULE_TYPE.$(s)))" >>$@;)
716	@$(foreach s,$(STATS.SOONG_MODULE_TYPE),echo "modules_type_soong,$(s),$(STATS.SOONG_MODULE_TYPE.$(s))" >>$@;)
717$(call dist-for-goals,droidcore,$(BUILD_SYSTEM_STATS))
718
719# -----------------------------------------------------------------
720# build /product/etc/security/avb/system_other.avbpubkey if needed
721ifdef BUILDING_SYSTEM_OTHER_IMAGE
722ifeq ($(BOARD_AVB_ENABLE),true)
723INSTALLED_PRODUCT_SYSTEM_OTHER_AVBKEY_TARGET := $(TARGET_OUT_PRODUCT_ETC)/security/avb/system_other.avbpubkey
724ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_PRODUCT_SYSTEM_OTHER_AVBKEY_TARGET)
725endif # BOARD_AVB_ENABLE
726endif # BUILDING_SYSTEM_OTHER_IMAGE
727
728# -----------------------------------------------------------------
729# Modules ready to be converted to Soong, ordered by how many
730# modules depend on them.
731SOONG_CONV := $(sort $(SOONG_CONV))
732SOONG_CONV_DATA := $(call intermediates-dir-for,PACKAGING,soong_conversion)/soong_conv_data
733$(SOONG_CONV_DATA):
734	@rm -f $@
735	@$(foreach s,$(SOONG_CONV),echo "$(s),$(SOONG_CONV.$(s).TYPE),$(sort $(SOONG_CONV.$(s).PROBLEMS)),$(sort $(filter-out $(SOONG_ALREADY_CONV),$(SOONG_CONV.$(s).DEPS)))" >>$@;)
736
737SOONG_TO_CONVERT_SCRIPT := build/make/tools/soong_to_convert.py
738SOONG_TO_CONVERT := $(PRODUCT_OUT)/soong_to_convert.txt
739$(SOONG_TO_CONVERT): $(SOONG_CONV_DATA) $(SOONG_TO_CONVERT_SCRIPT)
740	@rm -f $@
741	$(hide) $(SOONG_TO_CONVERT_SCRIPT) $< >$@
742$(call dist-for-goals,droidcore,$(SOONG_TO_CONVERT))
743
744# -----------------------------------------------------------------
745# Modules use -Wno-error, or added default -Wall -Werror
746WALL_WERROR := $(PRODUCT_OUT)/wall_werror.txt
747$(WALL_WERROR):
748	@rm -f $@
749	echo "# Modules using -Wno-error" >> $@
750	for m in $(sort $(SOONG_MODULES_USING_WNO_ERROR) $(MODULES_USING_WNO_ERROR)); do echo $$m >> $@; done
751	echo "# Modules added default -Wall" >> $@
752	for m in $(sort $(SOONG_MODULES_ADDED_WALL) $(MODULES_ADDED_WALL)); do echo $$m >> $@; done
753
754$(call dist-for-goals,droidcore,$(WALL_WERROR))
755
756# -----------------------------------------------------------------
757# Modules missing profile files
758PGO_PROFILE_MISSING := $(PRODUCT_OUT)/pgo_profile_file_missing.txt
759$(PGO_PROFILE_MISSING):
760	@rm -f $@
761	echo "# Modules missing PGO profile files" >> $@
762	for m in $(SOONG_MODULES_MISSING_PGO_PROFILE_FILE); do echo $$m >> $@; done
763
764$(call dist-for-goals,droidcore,$(PGO_PROFILE_MISSING))
765
766# -----------------------------------------------------------------
767# The dev key is used to sign this package, and as the key required
768# for future OTA packages installed by this system.  Actual product
769# deliverables will be re-signed by hand.  We expect this file to
770# exist with the suffixes ".x509.pem" and ".pk8".
771DEFAULT_KEY_CERT_PAIR := $(strip $(DEFAULT_SYSTEM_DEV_CERTIFICATE))
772
773
774# Rules that need to be present for the all targets, even
775# if they don't do anything.
776.PHONY: systemimage
777systemimage:
778
779# -----------------------------------------------------------------
780
781.PHONY: event-log-tags
782
783# Produce an event logs tag file for everything we know about, in order
784# to properly allocate numbers.  Then produce a file that's filtered
785# for what's going to be installed.
786
787all_event_log_tags_file := $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
788
789event_log_tags_file := $(TARGET_OUT)/etc/event-log-tags
790
791# Include tags from all packages that we know about
792all_event_log_tags_src := \
793    $(sort $(foreach m, $(ALL_MODULES), $(ALL_MODULES.$(m).EVENT_LOG_TAGS)))
794
795# PDK builds will already have a full list of tags that needs to get merged
796# in with the ones from source
797pdk_fusion_log_tags_file := $(patsubst $(PRODUCT_OUT)/%,$(_pdk_fusion_intermediates)/%,$(filter $(event_log_tags_file),$(ALL_PDK_FUSION_FILES)))
798
799$(all_event_log_tags_file): PRIVATE_SRC_FILES := $(all_event_log_tags_src) $(pdk_fusion_log_tags_file)
800$(all_event_log_tags_file): $(all_event_log_tags_src) $(pdk_fusion_log_tags_file) $(MERGETAGS) build/make/tools/event_log_tags.py
801	$(hide) mkdir -p $(dir $@)
802	$(hide) $(MERGETAGS) -o $@ $(PRIVATE_SRC_FILES)
803
804# Include tags from all packages included in this product, plus all
805# tags that are part of the system (ie, not in a vendor/ or device/
806# directory).
807event_log_tags_src := \
808    $(sort $(foreach m,\
809      $(PRODUCT_PACKAGES) \
810      $(call module-names-for-tag-list,user), \
811      $(ALL_MODULES.$(m).EVENT_LOG_TAGS)) \
812      $(filter-out vendor/% device/% out/%,$(all_event_log_tags_src)))
813
814$(event_log_tags_file): PRIVATE_SRC_FILES := $(event_log_tags_src) $(pdk_fusion_log_tags_file)
815$(event_log_tags_file): PRIVATE_MERGED_FILE := $(all_event_log_tags_file)
816$(event_log_tags_file): $(event_log_tags_src) $(all_event_log_tags_file) $(pdk_fusion_log_tags_file) $(MERGETAGS) build/make/tools/event_log_tags.py
817	$(hide) mkdir -p $(dir $@)
818	$(hide) $(MERGETAGS) -o $@ -m $(PRIVATE_MERGED_FILE) $(PRIVATE_SRC_FILES)
819
820event-log-tags: $(event_log_tags_file)
821
822ALL_DEFAULT_INSTALLED_MODULES += $(event_log_tags_file)
823
824
825# #################################################################
826# Targets for boot/OS images
827# #################################################################
828ifneq ($(strip $(TARGET_NO_BOOTLOADER)),true)
829  INSTALLED_BOOTLOADER_MODULE := $(PRODUCT_OUT)/bootloader
830  ifeq ($(strip $(TARGET_BOOTLOADER_IS_2ND)),true)
831    INSTALLED_2NDBOOTLOADER_TARGET := $(PRODUCT_OUT)/2ndbootloader
832  else
833    INSTALLED_2NDBOOTLOADER_TARGET :=
834  endif
835else
836  INSTALLED_BOOTLOADER_MODULE :=
837  INSTALLED_2NDBOOTLOADER_TARGET :=
838endif # TARGET_NO_BOOTLOADER
839ifneq ($(strip $(TARGET_NO_KERNEL)),true)
840  INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
841else
842  INSTALLED_KERNEL_TARGET :=
843endif
844
845# -----------------------------------------------------------------
846# the root dir
847INTERNAL_ROOT_FILES := $(filter $(TARGET_ROOT_OUT)/%, \
848	$(ALL_GENERATED_SOURCES) \
849	$(ALL_DEFAULT_INSTALLED_MODULES))
850
851INSTALLED_FILES_FILE_ROOT := $(PRODUCT_OUT)/installed-files-root.txt
852INSTALLED_FILES_JSON_ROOT := $(INSTALLED_FILES_FILE_ROOT:.txt=.json)
853$(INSTALLED_FILES_FILE_ROOT): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_ROOT)
854$(INSTALLED_FILES_FILE_ROOT) : $(INTERNAL_ROOT_FILES) $(FILESLIST)
855	@echo Installed file list: $@
856	@mkdir -p $(dir $@)
857	@rm -f $@
858	$(hide) $(FILESLIST) $(TARGET_ROOT_OUT) > $(@:.txt=.json)
859	$(hide) build/make/tools/fileslist_util.py -c $(@:.txt=.json) > $@
860
861$(call dist-for-goals, sdk win_sdk sdk_addon, $(INSTALLED_FILES_FILE_ROOT))
862
863#------------------------------------------------------------------
864# dtb
865ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
866INSTALLED_DTBIMAGE_TARGET := $(PRODUCT_OUT)/dtb.img
867ifdef BOARD_PREBUILT_DTBIMAGE_DIR
868$(INSTALLED_DTBIMAGE_TARGET) : $(sort $(wildcard $(BOARD_PREBUILT_DTBIMAGE_DIR)/*.dtb))
869	cat $^ > $@
870endif
871endif
872
873# -----------------------------------------------------------------
874# the ramdisk
875ifdef BUILDING_RAMDISK_IMAGE
876INTERNAL_RAMDISK_FILES := $(filter $(TARGET_RAMDISK_OUT)/%, \
877	$(ALL_GENERATED_SOURCES) \
878	$(ALL_DEFAULT_INSTALLED_MODULES))
879
880INSTALLED_FILES_FILE_RAMDISK := $(PRODUCT_OUT)/installed-files-ramdisk.txt
881INSTALLED_FILES_JSON_RAMDISK := $(INSTALLED_FILES_FILE_RAMDISK:.txt=.json)
882$(INSTALLED_FILES_FILE_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_RAMDISK)
883$(INSTALLED_FILES_FILE_RAMDISK) : $(INTERNAL_RAMDISK_FILES) $(FILESLIST)
884	@echo Installed file list: $@
885	@mkdir -p $(TARGET_RAMDISK_OUT)
886	@mkdir -p $(dir $@)
887	@rm -f $@
888	$(hide) $(FILESLIST) $(TARGET_RAMDISK_OUT) > $(@:.txt=.json)
889	$(hide) build/make/tools/fileslist_util.py -c $(@:.txt=.json) > $@
890
891$(call dist-for-goals, sdk win_sdk sdk_addon, $(INSTALLED_FILES_FILE_RAMDISK))
892BUILT_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img
893
894# We just build this directly to the install location.
895INSTALLED_RAMDISK_TARGET := $(BUILT_RAMDISK_TARGET)
896$(INSTALLED_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_RAMDISK_FILES) $(INSTALLED_FILES_FILE_RAMDISK) | $(MINIGZIP)
897	$(call pretty,"Target ram disk: $@")
898	$(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RAMDISK_OUT) | $(MINIGZIP) > $@
899
900.PHONY: ramdisk-nodeps
901ramdisk-nodeps: $(MKBOOTFS) | $(MINIGZIP)
902	@echo "make $@: ignoring dependencies"
903	$(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RAMDISK_OUT) | $(MINIGZIP) > $(INSTALLED_RAMDISK_TARGET)
904
905endif # BUILDING_RAMDISK_IMAGE
906
907
908INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
909
910ifneq ($(strip $(TARGET_NO_KERNEL)),true)
911
912# -----------------------------------------------------------------
913# the boot image, which is a collection of other images.
914INTERNAL_BOOTIMAGE_ARGS := \
915	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
916	--kernel $(INSTALLED_KERNEL_TARGET)
917
918ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
919  INTERNAL_BOOTIMAGE_ARGS += --dtb $(INSTALLED_DTBIMAGE_TARGET)
920endif
921
922ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
923INTERNAL_BOOTIMAGE_ARGS += --ramdisk $(INSTALLED_RAMDISK_TARGET)
924endif
925
926INTERNAL_BOOTIMAGE_FILES := $(filter-out --%,$(INTERNAL_BOOTIMAGE_ARGS))
927
928ifdef BOARD_KERNEL_BASE
929  INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
930endif
931
932ifdef BOARD_KERNEL_PAGESIZE
933  INTERNAL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
934endif
935
936ifeq ($(PRODUCT_SUPPORTS_VERITY),true)
937ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
938VERITY_KEYID := veritykeyid=id:`openssl x509 -in $(PRODUCT_VERITY_SIGNING_KEY).x509.pem -text \
939                | grep keyid | sed 's/://g' | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]' | sed 's/keyid//g'`
940endif
941endif
942
943INTERNAL_KERNEL_CMDLINE := $(strip $(INTERNAL_KERNEL_CMDLINE) buildvariant=$(TARGET_BUILD_VARIANT) $(VERITY_KEYID))
944ifdef INTERNAL_KERNEL_CMDLINE
945INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)"
946endif
947
948INTERNAL_MKBOOTIMG_VERSION_ARGS := \
949    --os_version $(PLATFORM_VERSION) \
950    --os_patch_level $(PLATFORM_SECURITY_PATCH)
951
952# We build recovery as boot image if BOARD_USES_RECOVERY_AS_BOOT is true.
953ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
954ifeq ($(TARGET_BOOTIMAGE_USE_EXT2),true)
955$(error TARGET_BOOTIMAGE_USE_EXT2 is not supported anymore)
956
957else ifeq (true,$(BOARD_AVB_ENABLE)) # TARGET_BOOTIMAGE_USE_EXT2 != true
958
959$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(AVBTOOL) $(INTERNAL_BOOTIMAGE_FILES) $(BOARD_AVB_BOOT_KEY_PATH)
960	$(call pretty,"Target boot image: $@")
961	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
962	$(hide) $(call assert-max-image-size,$@,$(call get-hash-image-max-size,$(BOARD_BOOTIMAGE_PARTITION_SIZE)))
963	$(hide) $(AVBTOOL) add_hash_footer \
964	  --image $@ \
965	  --partition_size $(BOARD_BOOTIMAGE_PARTITION_SIZE) \
966	  --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) \
967	  $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)
968
969.PHONY: bootimage-nodeps
970bootimage-nodeps: $(MKBOOTIMG) $(AVBTOOL) $(BOARD_AVB_BOOT_KEY_PATH)
971	@echo "make $@: ignoring dependencies"
972	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
973	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(call get-hash-image-max-size,$(BOARD_BOOTIMAGE_PARTITION_SIZE)))
974	$(hide) $(AVBTOOL) add_hash_footer \
975	  --image $(INSTALLED_BOOTIMAGE_TARGET) \
976	  --partition_size $(BOARD_BOOTIMAGE_PARTITION_SIZE) \
977	  --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) \
978	  $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)
979
980else ifeq (true,$(PRODUCT_SUPPORTS_BOOT_SIGNER)) # BOARD_AVB_ENABLE != true
981
982$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(BOOT_SIGNER)
983	$(call pretty,"Target boot image: $@")
984	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
985	$(BOOT_SIGNER) /boot $@ $(PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCT_VERITY_SIGNING_KEY).x509.pem $@
986	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
987
988.PHONY: bootimage-nodeps
989bootimage-nodeps: $(MKBOOTIMG) $(BOOT_SIGNER)
990	@echo "make $@: ignoring dependencies"
991	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
992	$(BOOT_SIGNER) /boot $(INSTALLED_BOOTIMAGE_TARGET) $(PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCT_VERITY_SIGNING_KEY).x509.pem $(INSTALLED_BOOTIMAGE_TARGET)
993	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
994
995else ifeq (true,$(PRODUCT_SUPPORTS_VBOOT)) # PRODUCT_SUPPORTS_BOOT_SIGNER != true
996
997$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(VBOOT_SIGNER) $(FUTILITY)
998	$(call pretty,"Target boot image: $@")
999	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@.unsigned
1000	$(VBOOT_SIGNER) $(FUTILITY) $@.unsigned $(PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $@.keyblock $@
1001	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
1002
1003.PHONY: bootimage-nodeps
1004bootimage-nodeps: $(MKBOOTIMG) $(VBOOT_SIGNER) $(FUTILITY)
1005	@echo "make $@: ignoring dependencies"
1006	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET).unsigned
1007	$(VBOOT_SIGNER) $(FUTILITY) $(INSTALLED_BOOTIMAGE_TARGET).unsigned $(PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(INSTALLED_BOOTIMAGE_TARGET).keyblock $(INSTALLED_BOOTIMAGE_TARGET)
1008	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
1009
1010else # PRODUCT_SUPPORTS_VBOOT != true
1011
1012$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES)
1013	$(call pretty,"Target boot image: $@")
1014	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
1015	$(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE))
1016
1017.PHONY: bootimage-nodeps
1018bootimage-nodeps: $(MKBOOTIMG)
1019	@echo "make $@: ignoring dependencies"
1020	$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_BOOTIMAGE_TARGET)
1021	$(hide) $(call assert-max-image-size,$(INSTALLED_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE))
1022
1023endif # TARGET_BOOTIMAGE_USE_EXT2
1024endif # BOARD_USES_RECOVERY_AS_BOOT
1025
1026else # TARGET_NO_KERNEL == "true"
1027ifdef BOARD_PREBUILT_BOOTIMAGE
1028ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
1029# Remove when b/63676296 is resolved.
1030$(error Prebuilt bootimage is only supported for AB targets)
1031endif
1032$(eval $(call copy-one-file,$(BOARD_PREBUILT_BOOTIMAGE),$(INSTALLED_BOOTIMAGE_TARGET)))
1033else # BOARD_PREBUILT_BOOTIMAGE not defined
1034INSTALLED_BOOTIMAGE_TARGET :=
1035endif # BOARD_PREBUILT_BOOTIMAGE
1036endif # TARGET_NO_KERNEL
1037
1038# -----------------------------------------------------------------
1039# NOTICE files
1040#
1041# We are required to publish the licenses for all code under BSD, GPL and
1042# Apache licenses (and possibly other more exotic ones as well). We err on the
1043# side of caution, so the licenses for other third-party code are included here
1044# too.
1045#
1046# This needs to be before the systemimage rules, because it adds to
1047# ALL_DEFAULT_INSTALLED_MODULES, which those use to pick which files
1048# go into the systemimage.
1049
1050.PHONY: notice_files
1051
1052# Create the rule to combine the files into text and html/xml forms
1053# $(1) - xml_excluded_vendor_product|xml_vendor|xml_product|html
1054# $(2) - Plain text output file
1055# $(3) - HTML/XML output file
1056# $(4) - File title
1057# $(5) - Directory to use.  Notice files are all $(4)/src.  Other
1058#		 directories in there will be used for scratch
1059# $(6) - Dependencies for the output files
1060#
1061# The algorithm here is that we go collect a hash for each of the notice
1062# files and write the names of the files that match that hash.  Then
1063# to generate the real files, we go print out all of the files and their
1064# hashes.
1065#
1066# These rules are fairly complex, so they depend on this makefile so if
1067# it changes, they'll run again.
1068#
1069# TODO: We could clean this up so that we just record the locations of the
1070# original notice files instead of making rules to copy them somwehere.
1071# Then we could traverse that without quite as much bash drama.
1072define combine-notice-files
1073$(2) $(3): PRIVATE_MESSAGE := $(4)
1074$(2) $(3): PRIVATE_DIR := $(5)
1075$(2) : $(3)
1076$(3) : $(6) $(BUILD_SYSTEM)/Makefile build/make/tools/generate-notice-files.py
1077	build/make/tools/generate-notice-files.py --text-output $(2) \
1078	    $(if $(filter $(1),xml_excluded_extra_partitions),-e vendor -e product -e product_services --xml-output, \
1079	      $(if $(filter $(1),xml_vendor),-i vendor --xml-output, \
1080	        $(if $(filter $(1),xml_product),-i product --xml-output, \
1081	          $(if $(filter $(1),xml_product_services),-i product_services --xml-output, \
1082	            --html-output)))) $(3) \
1083	    -t $$(PRIVATE_MESSAGE) -s $$(PRIVATE_DIR)/src
1084notice_files: $(2) $(3)
1085endef
1086
1087# Notice file logic isn't relevant for TARGET_BUILD_APPS
1088ifndef TARGET_BUILD_APPS
1089
1090# TODO These intermediate NOTICE.txt/NOTICE.html files should go into
1091# TARGET_OUT_NOTICE_FILES now that the notice files are gathered from
1092# the src subdirectory.
1093target_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE.txt
1094tools_notice_file_txt := $(HOST_OUT_INTERMEDIATES)/NOTICE.txt
1095tools_notice_file_html := $(HOST_OUT_INTERMEDIATES)/NOTICE.html
1096kernel_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/kernel.txt
1097winpthreads_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/winpthreads.txt
1098pdk_fusion_notice_files := $(filter $(TARGET_OUT_NOTICE_FILES)/%, $(ALL_PDK_FUSION_FILES))
1099
1100# TODO(b/69865032): Make PRODUCT_NOTICE_SPLIT the default behavior.
1101ifneq ($(PRODUCT_NOTICE_SPLIT),true)
1102target_notice_file_html := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html
1103target_notice_file_html_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html.gz
1104installed_notice_html_or_xml_gz := $(TARGET_OUT)/etc/NOTICE.html.gz
1105$(eval $(call combine-notice-files, html, \
1106	        $(target_notice_file_txt), \
1107	        $(target_notice_file_html), \
1108	        "Notices for files contained in the filesystem images in this directory:", \
1109	        $(TARGET_OUT_NOTICE_FILES), \
1110	        $(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file) $(pdk_fusion_notice_files)))
1111$(target_notice_file_html_gz): $(target_notice_file_html) | $(MINIGZIP)
1112	$(hide) $(MINIGZIP) -9 < $< > $@
1113$(installed_notice_html_or_xml_gz): $(target_notice_file_html_gz)
1114	$(copy-file-to-target)
1115else
1116target_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE.xml
1117target_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.xml.gz
1118installed_notice_html_or_xml_gz := $(TARGET_OUT)/etc/NOTICE.xml.gz
1119
1120target_vendor_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.txt
1121target_vendor_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.xml
1122target_vendor_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.xml.gz
1123installed_vendor_notice_xml_gz := $(TARGET_OUT_VENDOR)/etc/NOTICE.xml.gz
1124
1125target_product_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT.txt
1126target_product_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT.xml
1127target_product_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT.xml.gz
1128installed_product_notice_xml_gz := $(TARGET_OUT_PRODUCT)/etc/NOTICE.xml.gz
1129
1130target_product_services_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT_SERVICES.txt
1131target_product_services_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT_SERVICES.xml
1132target_product_services_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT_SERVICES.xml.gz
1133installed_product_services_notice_xml_gz := $(TARGET_OUT_PRODUCT_SERVICES)/etc/NOTICE.xml.gz
1134
1135# Notice files are copied to TARGET_OUT_NOTICE_FILES as a side-effect of their module
1136# being built. A notice xml file must depend on all modules that could potentially
1137# install a license file relevant to it.
1138license_modules := $(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file) $(pdk_fusion_notice_files)
1139# Phonys/fakes don't have notice files (though their deps might)
1140license_modules := $(filter-out $(TARGET_OUT_FAKE)/%,$(license_modules))
1141license_modules_vendor := $(filter $(TARGET_OUT_VENDOR)/%,$(license_modules))
1142license_modules_product := $(filter $(TARGET_OUT_PRODUCT)/%,$(license_modules))
1143license_modules_product_services := $(filter $(TARGET_OUT_PRODUCT_SERVICES)/%,$(license_modules))
1144license_modules_agg := $(license_modules_vendor) $(license_modules_product) $(license_modules_product_services)
1145license_modules_rest := $(filter-out $(license_modules_agg),$(license_modules))
1146
1147$(eval $(call combine-notice-files, xml_excluded_extra_partitions, \
1148	        $(target_notice_file_txt), \
1149	        $(target_notice_file_xml), \
1150	        "Notices for files contained in the filesystem images in this directory:", \
1151	        $(TARGET_OUT_NOTICE_FILES), \
1152	        $(license_modules_rest)))
1153$(eval $(call combine-notice-files, xml_vendor, \
1154	        $(target_vendor_notice_file_txt), \
1155	        $(target_vendor_notice_file_xml), \
1156	        "Notices for files contained in the vendor filesystem image in this directory:", \
1157	        $(TARGET_OUT_NOTICE_FILES), \
1158	        $(license_modules_vendor)))
1159$(eval $(call combine-notice-files, xml_product, \
1160	        $(target_product_notice_file_txt), \
1161	        $(target_product_notice_file_xml), \
1162	        "Notices for files contained in the product filesystem image in this directory:", \
1163	        $(TARGET_OUT_NOTICE_FILES), \
1164	        $(license_modules_product)))
1165$(eval $(call combine-notice-files, xml_product_services, \
1166	        $(target_product_services_notice_file_txt), \
1167	        $(target_product_services_notice_file_xml), \
1168	        "Notices for files contained in the product_services filesystem image in this directory:", \
1169	        $(TARGET_OUT_NOTICE_FILES), \
1170	        $(license_modules_product_services)))
1171
1172$(target_notice_file_xml_gz): $(target_notice_file_xml) | $(MINIGZIP)
1173	$(hide) $(MINIGZIP) -9 < $< > $@
1174$(target_vendor_notice_file_xml_gz): $(target_vendor_notice_file_xml) | $(MINIGZIP)
1175	$(hide) $(MINIGZIP) -9 < $< > $@
1176$(target_product_notice_file_xml_gz): $(target_product_notice_file_xml) | $(MINIGZIP)
1177	$(hide) $(MINIGZIP) -9 < $< > $@
1178$(target_product_services_notice_file_xml_gz): $(target_product_services_notice_file_xml) | $(MINIGZIP)
1179	$(hide) $(MINIGZIP) -9 < $< > $@
1180$(installed_notice_html_or_xml_gz): $(target_notice_file_xml_gz)
1181	$(copy-file-to-target)
1182$(installed_vendor_notice_xml_gz): $(target_vendor_notice_file_xml_gz)
1183	$(copy-file-to-target)
1184$(installed_product_notice_xml_gz): $(target_product_notice_file_xml_gz)
1185	$(copy-file-to-target)
1186
1187# No notice file for product_services if its contents are merged into /product.
1188# The notices will be part of the /product notice file.
1189ifndef MERGE_PRODUCT_SERVICES_INTO_PRODUCT
1190$(installed_product_services_notice_xml_gz): $(target_product_services_notice_file_xml_gz)
1191	$(copy-file-to-target)
1192endif
1193
1194# if we've been run my mm, mmm, etc, don't reinstall this every time
1195ifeq ($(ONE_SHOT_MAKEFILE),)
1196  ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_or_xml_gz)
1197  ALL_DEFAULT_INSTALLED_MODULES += $(installed_vendor_notice_xml_gz)
1198  ALL_DEFAULT_INSTALLED_MODULES += $(installed_product_notice_xml_gz)
1199  ALL_DEFAULT_INSTALLED_MODULES += $(installed_product_services_notice_xml_gz)
1200endif
1201endif # PRODUCT_NOTICE_SPLIT
1202
1203ifeq ($(ONE_SHOT_MAKEFILE),)
1204  ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_or_xml_gz)
1205endif
1206
1207$(eval $(call combine-notice-files, html, \
1208	        $(tools_notice_file_txt), \
1209	        $(tools_notice_file_html), \
1210	        "Notices for files contained in the tools directory:", \
1211	        $(HOST_OUT_NOTICE_FILES), \
1212	        $(ALL_DEFAULT_INSTALLED_MODULES) \
1213	        $(winpthreads_notice_file)))
1214
1215endif  # TARGET_BUILD_APPS
1216
1217# The kernel isn't really a module, so to get its module file in there, we
1218# make the target NOTICE files depend on this particular file too, which will
1219# then be in the right directory for the find in combine-notice-files to work.
1220$(kernel_notice_file): \
1221	    $(BUILD_SYSTEM)/LINUX_KERNEL_COPYING \
1222	    | $(ACP)
1223	@echo Copying: $@
1224	$(hide) mkdir -p $(dir $@)
1225	$(hide) $(ACP) $< $@
1226
1227$(winpthreads_notice_file): \
1228	    $(BUILD_SYSTEM)/WINPTHREADS_COPYING \
1229	    | $(ACP)
1230	@echo Copying: $@
1231	$(hide) mkdir -p $(dir $@)
1232	$(hide) $(ACP) $< $@
1233
1234# -----------------------------------------------------------------
1235# Build a keystore with the authorized keys in it, used to verify the
1236# authenticity of downloaded OTA packages.
1237#
1238# This rule adds to ALL_DEFAULT_INSTALLED_MODULES, so it needs to come
1239# before the rules that use that variable to build the image.
1240ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_ETC)/security/otacerts.zip
1241$(TARGET_OUT_ETC)/security/otacerts.zip: PRIVATE_CERT := $(DEFAULT_KEY_CERT_PAIR).x509.pem
1242$(TARGET_OUT_ETC)/security/otacerts.zip: $(SOONG_ZIP)
1243$(TARGET_OUT_ETC)/security/otacerts.zip: $(DEFAULT_KEY_CERT_PAIR).x509.pem
1244	$(hide) rm -f $@
1245	$(hide) mkdir -p $(dir $@)
1246	$(hide) $(SOONG_ZIP) -o $@ -C $(dir $(PRIVATE_CERT)) -f $(PRIVATE_CERT)
1247
1248# Carry the public key for update_engine if it's a non-IoT target that
1249# uses the AB updater. We use the same key as otacerts but in RSA public key
1250# format.
1251ifeq ($(AB_OTA_UPDATER),true)
1252ifneq ($(PRODUCT_IOT),true)
1253ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem
1254$(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem: $(DEFAULT_KEY_CERT_PAIR).x509.pem
1255	$(hide) rm -f $@
1256	$(hide) mkdir -p $(dir $@)
1257	$(hide) openssl x509 -pubkey -noout -in $< > $@
1258
1259ALL_DEFAULT_INSTALLED_MODULES += \
1260    $(TARGET_RECOVERY_ROOT_OUT)/system/etc/update_engine/update-payload-key.pub.pem
1261$(TARGET_RECOVERY_ROOT_OUT)/system/etc/update_engine/update-payload-key.pub.pem: \
1262	    $(TARGET_OUT_ETC)/update_engine/update-payload-key.pub.pem
1263	$(hide) cp -f $< $@
1264endif
1265endif
1266
1267.PHONY: otacerts
1268otacerts: $(TARGET_OUT_ETC)/security/otacerts.zip
1269
1270
1271# #################################################################
1272# Targets for user images
1273# #################################################################
1274
1275INTERNAL_USERIMAGES_EXT_VARIANT :=
1276ifeq ($(TARGET_USERIMAGES_USE_EXT2),true)
1277INTERNAL_USERIMAGES_EXT_VARIANT := ext2
1278else
1279ifeq ($(TARGET_USERIMAGES_USE_EXT3),true)
1280INTERNAL_USERIMAGES_EXT_VARIANT := ext3
1281else
1282ifeq ($(TARGET_USERIMAGES_USE_EXT4),true)
1283INTERNAL_USERIMAGES_EXT_VARIANT := ext4
1284endif
1285endif
1286endif
1287
1288# These options tell the recovery updater/installer how to mount the partitions writebale.
1289# <fstype>=<fstype_opts>[|<fstype_opts>]...
1290# fstype_opts := <opt>[,<opt>]...
1291#         opt := <name>[=<value>]
1292# The following worked on Nexus devices with Kernel 3.1, 3.4, 3.10
1293DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS := ext4=max_batch_time=0,commit=1,data=ordered,barrier=1,errors=panic,nodelalloc
1294
1295ifneq (true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED))
1296  INTERNAL_USERIMAGES_SPARSE_EXT_FLAG := -s
1297endif
1298
1299INTERNAL_USERIMAGES_DEPS := $(SIMG2IMG)
1300INTERNAL_USERIMAGES_DEPS += $(MKEXTUSERIMG) $(MAKE_EXT4FS) $(E2FSCK) $(TUNE2FS)
1301ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
1302INTERNAL_USERIMAGES_DEPS += $(MKF2FSUSERIMG) $(MAKE_F2FS)
1303endif
1304
1305ifeq ($(BOARD_AVB_ENABLE),true)
1306INTERNAL_USERIMAGES_DEPS += $(AVBTOOL)
1307endif
1308
1309ifneq (true,$(TARGET_USERIMAGES_SPARSE_SQUASHFS_DISABLED))
1310  INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG := -s
1311endif
1312ifneq ($(filter $(BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE) $(BOARD_PRODUCT_SERVICESIMAGE_FILE_SYSTEM_TYPE) $(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE) $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE) $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE),squashfs),)
1313INTERNAL_USERIMAGES_DEPS += $(MAKE_SQUASHFS) $(MKSQUASHFSUSERIMG) $(IMG2SIMG)
1314endif
1315
1316INTERNAL_USERIMAGES_BINARY_PATHS := $(sort $(dir $(INTERNAL_USERIMAGES_DEPS)))
1317
1318ifeq (true,$(PRODUCT_SUPPORTS_VERITY))
1319INTERNAL_USERIMAGES_DEPS += $(BUILD_VERITY_METADATA) $(BUILD_VERITY_TREE) $(APPEND2SIMG) $(VERITY_SIGNER)
1320ifeq (true,$(PRODUCT_SUPPORTS_VERITY_FEC))
1321INTERNAL_USERIMAGES_DEPS += $(FEC)
1322endif
1323endif
1324
1325SELINUX_FC := $(call intermediates-dir-for,ETC,file_contexts.bin)/file_contexts.bin
1326INTERNAL_USERIMAGES_DEPS += $(SELINUX_FC)
1327
1328INTERNAL_USERIMAGES_DEPS += $(BLK_ALLOC_TO_BASE_FS)
1329
1330INTERNAL_USERIMAGES_DEPS += $(MKE2FS_CONF)
1331
1332ifeq (true,$(PRODUCT_USE_DYNAMIC_PARTITIONS))
1333
1334ifeq ($(PRODUCT_SUPPORTS_VERITY),true)
1335  $(error vboot 1.0 doesn't support logical partition)
1336endif
1337
1338# TODO(b/80195851): Should not define BOARD_AVB_SYSTEM_KEY_PATH without
1339# BOARD_AVB_SYSTEM_DETACHED_VBMETA.
1340
1341endif # PRODUCT_USE_DYNAMIC_PARTITIONS
1342
1343# $(1): the path of the output dictionary file
1344# $(2): a subset of "system vendor cache userdata product product_services oem odm"
1345# $(3): additional "key=value" pairs to append to the dictionary file.
1346define generate-image-prop-dictionary
1347$(if $(filter $(2),system),\
1348    $(if $(BOARD_SYSTEMIMAGE_PARTITION_SIZE),$(hide) echo "system_size=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE)" >> $(1))
1349    $(if $(INTERNAL_SYSTEM_OTHER_PARTITION_SIZE),$(hide) echo "system_other_size=$(INTERNAL_SYSTEM_OTHER_PARTITION_SIZE)" >> $(1))
1350    $(if $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "system_fs_type=$(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1351    $(if $(BOARD_SYSTEMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "system_extfs_inode_count=$(BOARD_SYSTEMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1352    $(if $(BOARD_SYSTEMIMAGE_EXTFS_RSV_PCT),$(hide) echo "system_extfs_rsv_pct=$(BOARD_SYSTEMIMAGE_EXTFS_RSV_PCT)" >> $(1))
1353    $(if $(BOARD_SYSTEMIMAGE_JOURNAL_SIZE),$(hide) echo "system_journal_size=$(BOARD_SYSTEMIMAGE_JOURNAL_SIZE)" >> $(1))
1354    $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "system_squashfs_compressor=$(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1355    $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "system_squashfs_compressor_opt=$(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1356    $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "system_squashfs_block_size=$(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1357    $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "system_squashfs_disable_4k_align=$(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1358    $(if $(PRODUCT_SYSTEM_BASE_FS_PATH),$(hide) echo "system_base_fs_file=$(PRODUCT_SYSTEM_BASE_FS_PATH)" >> $(1))
1359    $(if $(PRODUCT_SYSTEM_HEADROOM),$(hide) echo "system_headroom=$(PRODUCT_SYSTEM_HEADROOM)" >> $(1))
1360    $(if $(BOARD_SYSTEMIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "system_reserved_size=$(BOARD_SYSTEMIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1361)
1362$(if $(filter $(2),userdata),\
1363    $(if $(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "userdata_fs_type=$(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1364    $(if $(BOARD_USERDATAIMAGE_PARTITION_SIZE),$(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(1))
1365)
1366$(if $(filter $(2),cache),\
1367    $(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1368    $(if $(BOARD_CACHEIMAGE_PARTITION_SIZE),$(hide) echo "cache_size=$(BOARD_CACHEIMAGE_PARTITION_SIZE)" >> $(1))
1369)
1370$(if $(filter $(2),vendor),\
1371    $(if $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "vendor_fs_type=$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1372    $(if $(BOARD_VENDORIMAGE_EXTFS_INODE_COUNT),$(hide) echo "vendor_extfs_inode_count=$(BOARD_VENDORIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1373    $(if $(BOARD_VENDORIMAGE_EXTFS_RSV_PCT),$(hide) echo "vendor_extfs_rsv_pct=$(BOARD_VENDORIMAGE_EXTFS_RSV_PCT)" >> $(1))
1374    $(if $(BOARD_VENDORIMAGE_PARTITION_SIZE),$(hide) echo "vendor_size=$(BOARD_VENDORIMAGE_PARTITION_SIZE)" >> $(1))
1375    $(if $(BOARD_VENDORIMAGE_JOURNAL_SIZE),$(hide) echo "vendor_journal_size=$(BOARD_VENDORIMAGE_JOURNAL_SIZE)" >> $(1))
1376    $(if $(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "vendor_squashfs_compressor=$(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1377    $(if $(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "vendor_squashfs_compressor_opt=$(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1378    $(if $(BOARD_VENDORIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "vendor_squashfs_block_size=$(BOARD_VENDORIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1379    $(if $(BOARD_VENDORIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "vendor_squashfs_disable_4k_align=$(BOARD_VENDORIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1380    $(if $(PRODUCT_VENDOR_BASE_FS_PATH),$(hide) echo "vendor_base_fs_file=$(PRODUCT_VENDOR_BASE_FS_PATH)" >> $(1))
1381    $(if $(BOARD_VENDORIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "vendor_reserved_size=$(BOARD_VENDORIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1382)
1383$(if $(filter $(2),product),\
1384    $(if $(BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "product_fs_type=$(BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1385    $(if $(BOARD_PRODUCTIMAGE_EXTFS_INODE_COUNT),$(hide) echo "product_extfs_inode_count=$(BOARD_PRODUCTIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1386    $(if $(BOARD_PRODUCTIMAGE_EXTFS_RSV_PCT),$(hide) echo "product_extfs_rsv_pct=$(BOARD_PRODUCTIMAGE_EXTFS_RSV_PCT)" >> $(1))
1387    $(if $(BOARD_PRODUCTIMAGE_PARTITION_SIZE),$(hide) echo "product_size=$(BOARD_PRODUCTIMAGE_PARTITION_SIZE)" >> $(1))
1388    $(if $(BOARD_PRODUCTIMAGE_JOURNAL_SIZE),$(hide) echo "product_journal_size=$(BOARD_PRODUCTIMAGE_JOURNAL_SIZE)" >> $(1))
1389    $(if $(BOARD_PRODUCTIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "product_squashfs_compressor=$(BOARD_PRODUCTIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1390    $(if $(BOARD_PRODUCTIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "product_squashfs_compressor_opt=$(BOARD_PRODUCTIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1391    $(if $(BOARD_PRODUCTIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "product_squashfs_block_size=$(BOARD_PRODUCTIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1392    $(if $(BOARD_PRODUCTIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "product_squashfs_disable_4k_align=$(BOARD_PRODUCTIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1393    $(if $(PRODUCT_PRODUCT_BASE_FS_PATH),$(hide) echo "product_base_fs_file=$(PRODUCT_PRODUCT_BASE_FS_PATH)" >> $(1))
1394    $(if $(BOARD_PRODUCTIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "product_reserved_size=$(BOARD_PRODUCTIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1395)
1396$(if $(filter $(2),product_services),\
1397    $(if $(BOARD_PRODUCT_SERVICESIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "product_services_fs_type=$(BOARD_PRODUCT_SERVICESIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1398    $(if $(BOARD_PRODUCT_SERVICESIMAGE_EXTFS_INODE_COUNT),$(hide) echo "product_services_extfs_inode_count=$(BOARD_PRODUCT_SERVICESIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1399    $(if $(BOARD_PRODUCT_SERVICESIMAGE_EXTFS_RSV_PCT),$(hide) echo "product_services_extfs_rsv_pct=$(BOARD_PRODUCT_SERVICESIMAGE_EXTFS_RSV_PCT)" >> $(1))
1400    $(if $(BOARD_PRODUCT_SERVICESIMAGE_PARTITION_SIZE),$(hide) echo "product_services_size=$(BOARD_PRODUCT_SERVICESIMAGE_PARTITION_SIZE)" >> $(1))
1401    $(if $(BOARD_PRODUCT_SERVICESIMAGE_JOURNAL_SIZE),$(hide) echo "product_services_journal_size=$(BOARD_PRODUCT_SERVICESIMAGE_JOURNAL_SIZE)" >> $(1))
1402    $(if $(BOARD_PRODUCT_SERVICESIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "product_services_squashfs_compressor=$(BOARD_PRODUCT_SERVICESIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1403    $(if $(BOARD_PRODUCT_SERVICESIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "product_services_squashfs_compressor_opt=$(BOARD_PRODUCT_SERVICESIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1404    $(if $(BOARD_PRODUCT_SERVICESIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "product_services_squashfs_block_size=$(BOARD_PRODUCT_SERVICESIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1405    $(if $(BOARD_PRODUCT_SERVICESIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "product_services_squashfs_disable_4k_align=$(BOARD_PRODUCT_SERVICESIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1406    $(if $(BOARD_PRODUCT_SERVICESIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "product_services_reserved_size=$(BOARD_PRODUCT_SERVICESIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1407)
1408$(if $(filter $(2),odm),\
1409    $(if $(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "odm_fs_type=$(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1410    $(if $(BOARD_ODMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "odm_extfs_inode_count=$(BOARD_ODMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1411    $(if $(BOARD_ODMIMAGE_EXTFS_RSV_PCT),$(hide) echo "odm_extfs_rsv_pct=$(BOARD_ODMIMAGE_EXTFS_RSV_PCT)" >> $(1))
1412    $(if $(BOARD_ODMIMAGE_PARTITION_SIZE),$(hide) echo "odm_size=$(BOARD_ODMIMAGE_PARTITION_SIZE)" >> $(1))
1413    $(if $(BOARD_ODMIMAGE_JOURNAL_SIZE),$(hide) echo "odm_journal_size=$(BOARD_ODMIMAGE_JOURNAL_SIZE)" >> $(1))
1414    $(if $(BOARD_ODMIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "odm_squashfs_compressor=$(BOARD_ODMIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1415    $(if $(BOARD_ODMIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "odm_squashfs_compressor_opt=$(BOARD_ODMIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1416    $(if $(BOARD_ODMIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "odm_squashfs_block_size=$(BOARD_ODMIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1417    $(if $(BOARD_ODMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "odm_squashfs_disable_4k_align=$(BOARD_ODMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1418    $(if $(PRODUCT_ODM_BASE_FS_PATH),$(hide) echo "odm_base_fs_file=$(PRODUCT_ODM_BASE_FS_PATH)" >> $(1))
1419    $(if $(BOARD_ODMIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "odm_reserved_size=$(BOARD_ODMIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1420)
1421$(if $(filter $(2),oem),\
1422    $(if $(BOARD_OEMIMAGE_PARTITION_SIZE),$(hide) echo "oem_size=$(BOARD_OEMIMAGE_PARTITION_SIZE)" >> $(1))
1423    $(if $(BOARD_OEMIMAGE_JOURNAL_SIZE),$(hide) echo "oem_journal_size=$(BOARD_OEMIMAGE_JOURNAL_SIZE)" >> $(1))
1424    $(if $(BOARD_OEMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "oem_extfs_inode_count=$(BOARD_OEMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1425    $(if $(BOARD_OEMIMAGE_EXTFS_RSV_PCT),$(hide) echo "oem_extfs_rsv_pct=$(BOARD_OEMIMAGE_EXTFS_RSV_PCT)" >> $(1))
1426)
1427$(hide) echo "ext_mkuserimg=$(notdir $(MKEXTUSERIMG))" >> $(1)
1428
1429$(if $(INTERNAL_USERIMAGES_EXT_VARIANT),$(hide) echo "fs_type=$(INTERNAL_USERIMAGES_EXT_VARIANT)" >> $(1))
1430$(if $(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG),$(hide) echo "extfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG)" >> $(1))
1431$(if $(INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG),$(hide) echo "squashfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG)" >> $(1))
1432$(if $(BOARD_EXT4_SHARE_DUP_BLOCKS),$(hide) echo "ext4_share_dup_blocks=$(BOARD_EXT4_SHARE_DUP_BLOCKS)" >> $(1))
1433$(if $(BOARD_FLASH_LOGICAL_BLOCK_SIZE), $(hide) echo "flash_logical_block_size=$(BOARD_FLASH_LOGICAL_BLOCK_SIZE)" >> $(1))
1434$(if $(BOARD_FLASH_ERASE_BLOCK_SIZE), $(hide) echo "flash_erase_block_size=$(BOARD_FLASH_ERASE_BLOCK_SIZE)" >> $(1))
1435$(hide) echo "selinux_fc=$(SELINUX_FC)" >> $(1)
1436$(if $(PRODUCT_SUPPORTS_BOOT_SIGNER),$(hide) echo "boot_signer=$(PRODUCT_SUPPORTS_BOOT_SIGNER)" >> $(1))
1437$(if $(PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity=$(PRODUCT_SUPPORTS_VERITY)" >> $(1))
1438$(if $(PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_key=$(PRODUCT_VERITY_SIGNING_KEY)" >> $(1))
1439$(if $(PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_signer_cmd=$(notdir $(VERITY_SIGNER))" >> $(1))
1440$(if $(PRODUCT_SUPPORTS_VERITY_FEC),$(hide) echo "verity_fec=$(PRODUCT_SUPPORTS_VERITY_FEC)" >> $(1))
1441$(if $(filter eng, $(TARGET_BUILD_VARIANT)),$(hide) echo "verity_disable=true" >> $(1))
1442$(if $(PRODUCT_SYSTEM_VERITY_PARTITION),$(hide) echo "system_verity_block_device=$(PRODUCT_SYSTEM_VERITY_PARTITION)" >> $(1))
1443$(if $(PRODUCT_VENDOR_VERITY_PARTITION),$(hide) echo "vendor_verity_block_device=$(PRODUCT_VENDOR_VERITY_PARTITION)" >> $(1))
1444$(if $(PRODUCT_PRODUCT_VERITY_PARTITION),$(hide) echo "product_verity_block_device=$(PRODUCT_PRODUCT_VERITY_PARTITION)" >> $(1))
1445$(if $(PRODUCT_PRODUCT_SERVICES_VERITY_PARTITION),$(hide) echo "product_services_verity_block_device=$(PRODUCT_PRODUCT_SERVICES_VERITY_PARTITION)" >> $(1))
1446$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot=$(PRODUCT_SUPPORTS_VBOOT)" >> $(1))
1447$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_key=$(PRODUCT_VBOOT_SIGNING_KEY)" >> $(1))
1448$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_subkey=$(PRODUCT_VBOOT_SIGNING_SUBKEY)" >> $(1))
1449$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "futility=$(notdir $(FUTILITY))" >> $(1))
1450$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_signer_cmd=$(VBOOT_SIGNER)" >> $(1))
1451$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_avbtool=$(notdir $(AVBTOOL))" >> $(1))
1452$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1453$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_add_hashtree_footer_args=$(BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1454$(if $(BOARD_AVB_ENABLE),\
1455    $(if $(BOARD_AVB_SYSTEM_KEY_PATH),\
1456        $(hide) echo "avb_system_key_path=$(BOARD_AVB_SYSTEM_KEY_PATH)" >> $(1)
1457        $(hide) echo "avb_system_algorithm=$(BOARD_AVB_SYSTEM_ALGORITHM)" >> $(1)
1458        $(hide) echo "avb_system_rollback_index_location=$(BOARD_AVB_SYSTEM_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1459$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_other_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1460$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_other_add_hashtree_footer_args=$(BOARD_AVB_SYSTEM_OTHER_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1461$(if $(BOARD_AVB_ENABLE),\
1462    $(if $(BOARD_AVB_SYSTEM_OTHER_KEY_PATH),\
1463        $(hide) echo "avb_system_other_key_path=$(BOARD_AVB_SYSTEM_OTHER_KEY_PATH)" >> $(1)
1464        $(hide) echo "avb_system_other_algorithm=$(BOARD_AVB_SYSTEM_OTHER_ALGORITHM)" >> $(1)))
1465$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_vendor_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1466$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_vendor_add_hashtree_footer_args=$(BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1467$(if $(BOARD_AVB_ENABLE),\
1468    $(if $(BOARD_AVB_VENDOR_KEY_PATH),\
1469        $(hide) echo "avb_vendor_key_path=$(BOARD_AVB_VENDOR_KEY_PATH)" >> $(1)
1470        $(hide) echo "avb_vendor_algorithm=$(BOARD_AVB_VENDOR_ALGORITHM)" >> $(1)
1471        $(hide) echo "avb_vendor_rollback_index_location=$(BOARD_AVB_VENDOR_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1472$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_product_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1473$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_product_add_hashtree_footer_args=$(BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1474$(if $(BOARD_AVB_ENABLE),\
1475    $(if $(BOARD_AVB_PRODUCT_KEY_PATH),\
1476        $(hide) echo "avb_product_key_path=$(BOARD_AVB_PRODUCT_KEY_PATH)" >> $(1)
1477        $(hide) echo "avb_product_algorithm=$(BOARD_AVB_PRODUCT_ALGORITHM)" >> $(1)
1478        $(hide) echo "avb_product_rollback_index_location=$(BOARD_AVB_PRODUCT_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1479$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_product_services_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1480$(if $(BOARD_AVB_ENABLE),\
1481    $(hide) echo "avb_product_services_add_hashtree_footer_args=$(BOARD_AVB_PRODUCT_SERVICES_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1482$(if $(BOARD_AVB_ENABLE),\
1483    $(if $(BOARD_AVB_PRODUCT_SERVICES_KEY_PATH),\
1484        $(hide) echo "avb_product_services_key_path=$(BOARD_AVB_PRODUCT_SERVICES_KEY_PATH)" >> $(1)
1485        $(hide) echo "avb_product_services_algorithm=$(BOARD_AVB_PRODUCT_SERVICES_ALGORITHM)" >> $(1)
1486        $(hide) echo "avb_product_services_rollback_index_location=$(BOARD_AVB_PRODUCT_SERVICES_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1487$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_odm_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1488$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_odm_add_hashtree_footer_args=$(BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1489$(if $(BOARD_AVB_ENABLE),\
1490    $(if $(BOARD_AVB_ODM_KEY_PATH),\
1491        $(hide) echo "avb_odm_key_path=$(BOARD_AVB_ODM_KEY_PATH)" >> $(1)
1492        $(hide) echo "avb_odm_algorithm=$(BOARD_AVB_ODM_ALGORITHM)" >> $(1)
1493        $(hide) echo "avb_odm_rollback_index_location=$(BOARD_AVB_ODM_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1494$(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
1495    $(hide) echo "recovery_as_boot=true" >> $(1))
1496$(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)),\
1497    $(hide) echo "system_root_image=true" >> $(1))
1498$(hide) echo "root_dir=$(TARGET_ROOT_OUT)" >> $(1)
1499$(if $(PRODUCT_USE_DYNAMIC_PARTITION_SIZE),$(hide) echo "use_dynamic_partition_size=true" >> $(1))
1500$(if $(3),$(hide) $(foreach kv,$(3),echo "$(kv)" >> $(1);))
1501endef
1502
1503# $(1): the path of the output dictionary file
1504# $(2): additional "key=value" pairs to append to the dictionary file.
1505define generate-userimage-prop-dictionary
1506$(call generate-image-prop-dictionary,$(1),system vendor cache userdata product product_services oem odm,$(2))
1507endef
1508
1509# $(1): the path of the input dictionary file, where each line has the format key=value
1510# $(2): the key to look up
1511define read-image-prop-dictionary
1512$$(grep '$(2)=' $(1) | cut -f2- -d'=')
1513endef
1514
1515# $(1): modules list
1516# $(2): output dir
1517# $(3): mount point
1518# $(4): staging dir
1519# Depmod requires a well-formed kernel version so 0.0 is used as a placeholder.
1520define build-image-kernel-modules
1521    $(hide) rm -rf $(2)/lib/modules
1522    $(hide) mkdir -p $(2)/lib/modules
1523    $(hide) cp $(1) $(2)/lib/modules/
1524    $(hide) rm -rf $(4)
1525    $(hide) mkdir -p $(4)/lib/modules/0.0/$(3)lib/modules
1526    $(hide) cp $(1) $(4)/lib/modules/0.0/$(3)lib/modules
1527    $(hide) $(DEPMOD) -b $(4) 0.0
1528    $(hide) sed -e 's/\(.*modules.*\):/\/\1:/g' -e 's/ \([^ ]*modules[^ ]*\)/ \/\1/g' $(4)/lib/modules/0.0/modules.dep > $(2)/lib/modules/modules.dep
1529    $(hide) cp $(4)/lib/modules/0.0/modules.alias $(2)/lib/modules
1530endef
1531
1532# -----------------------------------------------------------------
1533# Recovery image
1534
1535# Recovery image exists if we are building recovery, or building recovery as boot.
1536ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)))
1537
1538INTERNAL_RECOVERYIMAGE_FILES := $(filter $(TARGET_RECOVERY_OUT)/%, \
1539    $(ALL_DEFAULT_INSTALLED_MODULES))
1540
1541INSTALLED_FILES_FILE_RECOVERY := $(PRODUCT_OUT)/installed-files-recovery.txt
1542INSTALLED_FILES_JSON_RECOVERY := $(INSTALLED_FILES_FILE_RECOVERY:.txt=.json)
1543
1544# TODO(b/30414428): Can't depend on INTERNAL_RECOVERYIMAGE_FILES alone like other
1545# INSTALLED_FILES_FILE_* rules. Because currently there're cp/rsync/rm commands in
1546# build-recoveryimage-target, which would touch the files under TARGET_RECOVERY_OUT and race with
1547# the call to FILELIST.
1548ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
1549$(INSTALLED_FILES_FILE_RECOVERY): $(INSTALLED_BOOTIMAGE_TARGET)
1550else
1551$(INSTALLED_FILES_FILE_RECOVERY): $(INSTALLED_RECOVERYIMAGE_TARGET)
1552endif
1553
1554$(INSTALLED_FILES_FILE_RECOVERY): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_RECOVERY)
1555$(INSTALLED_FILES_FILE_RECOVERY): $(INTERNAL_RECOVERYIMAGE_FILES) $(FILESLIST)
1556	@echo Installed file list: $@
1557	@mkdir -p $(dir $@)
1558	@rm -f $@
1559	$(hide) $(FILESLIST) $(TARGET_RECOVERY_ROOT_OUT) > $(@:.txt=.json)
1560	$(hide) build/make/tools/fileslist_util.py -c $(@:.txt=.json) > $@
1561
1562recovery_initrc := $(call include-path-for, recovery)/etc/init.rc
1563recovery_sepolicy := \
1564    $(TARGET_RECOVERY_ROOT_OUT)/sepolicy \
1565    $(TARGET_RECOVERY_ROOT_OUT)/plat_file_contexts \
1566    $(TARGET_RECOVERY_ROOT_OUT)/vendor_file_contexts \
1567    $(TARGET_RECOVERY_ROOT_OUT)/plat_property_contexts \
1568    $(TARGET_RECOVERY_ROOT_OUT)/vendor_property_contexts \
1569    $(TARGET_RECOVERY_ROOT_OUT)/odm_file_contexts \
1570    $(TARGET_RECOVERY_ROOT_OUT)/odm_property_contexts \
1571    $(TARGET_RECOVERY_ROOT_OUT)/product_file_contexts \
1572    $(TARGET_RECOVERY_ROOT_OUT)/product_property_contexts
1573
1574# Passed into rsync from non-recovery root to recovery root, to avoid overwriting recovery-specific
1575# SELinux files
1576IGNORE_RECOVERY_SEPOLICY := $(patsubst $(TARGET_RECOVERY_OUT)/%,--exclude=/%,$(recovery_sepolicy))
1577
1578recovery_kernel := $(INSTALLED_KERNEL_TARGET) # same as a non-recovery system
1579recovery_ramdisk := $(PRODUCT_OUT)/ramdisk-recovery.img
1580recovery_resources_common := $(call include-path-for, recovery)/res
1581
1582# Set recovery_density to a density bucket based on TARGET_SCREEN_DENSITY, PRODUCT_AAPT_PREF_CONFIG,
1583# or mdpi, in order of preference. We support both specific buckets (e.g. xdpi) and numbers,
1584# which get remapped to a bucket.
1585recovery_density := $(or $(TARGET_SCREEN_DENSITY),$(PRODUCT_AAPT_PREF_CONFIG),mdpi)
1586ifeq (,$(filter xxxhdpi xxhdpi xhdpi hdpi mdpi,$(recovery_density)))
1587recovery_density_value := $(patsubst %dpi,%,$(recovery_density))
1588# We roughly use the medium point between the primary densities to split buckets.
1589# ------160------240------320----------480------------640------
1590#       mdpi     hdpi    xhdpi        xxhdpi        xxxhdpi
1591recovery_density := $(strip \
1592  $(or $(if $(filter $(shell echo $$(($(recovery_density_value) >= 560))),1),xxxhdpi),\
1593       $(if $(filter $(shell echo $$(($(recovery_density_value) >= 400))),1),xxhdpi),\
1594       $(if $(filter $(shell echo $$(($(recovery_density_value) >= 280))),1),xhdpi),\
1595       $(if $(filter $(shell echo $$(($(recovery_density_value) >= 200))),1),hdpi,mdpi)))
1596endif
1597
1598ifneq (,$(wildcard $(recovery_resources_common)-$(recovery_density)))
1599recovery_resources_common := $(recovery_resources_common)-$(recovery_density)
1600else
1601recovery_resources_common := $(recovery_resources_common)-xhdpi
1602endif
1603
1604# Select the 18x32 font on high-density devices (xhdpi and up); and the 12x22 font on other devices.
1605# Note that the font selected here can be overridden for a particular device by putting a font.png
1606# in its private recovery resources.
1607ifneq (,$(filter xxxhdpi xxhdpi xhdpi,$(recovery_density)))
1608recovery_font := $(call include-path-for, recovery)/fonts/18x32.png
1609else
1610recovery_font := $(call include-path-for, recovery)/fonts/12x22.png
1611endif
1612
1613
1614# We will only generate the recovery background text images if the variable
1615# TARGET_RECOVERY_UI_SCREEN_WIDTH is defined. For devices with xxxhdpi and xxhdpi, we set the
1616# variable to the commonly used values here, if it hasn't been intialized elsewhere. While for
1617# devices with lower density, they must have TARGET_RECOVERY_UI_SCREEN_WIDTH defined in their
1618# BoardConfig in order to use this feature.
1619ifeq ($(recovery_density),xxxhdpi)
1620TARGET_RECOVERY_UI_SCREEN_WIDTH ?= 1440
1621else ifeq ($(recovery_density),xxhdpi)
1622TARGET_RECOVERY_UI_SCREEN_WIDTH ?= 1080
1623endif
1624
1625ifneq ($(TARGET_RECOVERY_UI_SCREEN_WIDTH),)
1626# Subtracts the margin width and menu indent from the screen width; it's safe to be conservative.
1627ifeq ($(TARGET_RECOVERY_UI_MARGIN_WIDTH),)
1628  recovery_image_width := $$(($(TARGET_RECOVERY_UI_SCREEN_WIDTH) - 10))
1629else
1630  recovery_image_width := $$(($(TARGET_RECOVERY_UI_SCREEN_WIDTH) - $(TARGET_RECOVERY_UI_MARGIN_WIDTH) - 10))
1631endif
1632
1633
1634RECOVERY_INSTALLING_TEXT_FILE := $(call intermediates-dir-for,PACKAGING,recovery_text_res)/installing_text.png
1635RECOVERY_INSTALLING_SECURITY_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/installing_security_text.png
1636RECOVERY_ERASING_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/erasing_text.png
1637RECOVERY_ERROR_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/error_text.png
1638RECOVERY_NO_COMMAND_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/no_command_text.png
1639
1640RECOVERY_CANCEL_WIPE_DATA_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/cancel_wipe_data_text.png
1641RECOVERY_FACTORY_DATA_RESET_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/factory_data_reset_text.png
1642RECOVERY_TRY_AGAIN_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/try_again_text.png
1643RECOVERY_WIPE_DATA_CONFIRMATION_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/wipe_data_confirmation_text.png
1644RECOVERY_WIPE_DATA_MENU_HEADER_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/wipe_data_menu_header_text.png
1645
1646generated_recovery_text_files := \
1647  $(RECOVERY_INSTALLING_TEXT_FILE) \
1648  $(RECOVERY_INSTALLING_SECURITY_TEXT_FILE) \
1649  $(RECOVERY_ERASING_TEXT_FILE) \
1650  $(RECOVERY_ERROR_TEXT_FILE) \
1651  $(RECOVERY_NO_COMMAND_TEXT_FILE) \
1652  $(RECOVERY_CANCEL_WIPE_DATA_TEXT_FILE) \
1653  $(RECOVERY_FACTORY_DATA_RESET_TEXT_FILE) \
1654  $(RECOVERY_TRY_AGAIN_TEXT_FILE) \
1655  $(RECOVERY_WIPE_DATA_CONFIRMATION_TEXT_FILE) \
1656  $(RECOVERY_WIPE_DATA_MENU_HEADER_TEXT_FILE)
1657
1658resource_dir := $(call include-path-for, recovery)/tools/recovery_l10n/res/
1659image_generator_jar := $(HOST_OUT_JAVA_LIBRARIES)/RecoveryImageGenerator.jar
1660zopflipng := $(HOST_OUT_EXECUTABLES)/zopflipng
1661$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_SOURCE_FONTS := $(recovery_noto-fonts_dep) $(recovery_roboto-fonts_dep)
1662$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_FONT_FILES_DIR := $(call intermediates-dir-for,PACKAGING,recovery_font_files)
1663$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RESOURCE_DIR := $(resource_dir)
1664$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_IMAGE_GENERATOR_JAR := $(image_generator_jar)
1665$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_ZOPFLIPNG := $(zopflipng)
1666$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_IMAGE_WIDTH := $(recovery_image_width)
1667$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_BACKGROUND_TEXT_LIST := \
1668  recovery_installing \
1669  recovery_installing_security \
1670  recovery_erasing \
1671  recovery_error \
1672  recovery_no_command
1673$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_WIPE_DATA_TEXT_LIST := \
1674  recovery_cancel_wipe_data \
1675  recovery_factory_data_reset \
1676  recovery_try_again \
1677  recovery_wipe_data_menu_header \
1678  recovery_wipe_data_confirmation
1679$(RECOVERY_INSTALLING_TEXT_FILE): .KATI_IMPLICIT_OUTPUTS := $(filter-out $(RECOVERY_INSTALLING_TEXT_FILE),$(generated_recovery_text_files))
1680$(RECOVERY_INSTALLING_TEXT_FILE): $(image_generator_jar) $(resource_dir) $(recovery_noto-fonts_dep) $(recovery_roboto-fonts_dep) $(zopflipng)
1681	# Prepares the font directory.
1682	@rm -rf $(PRIVATE_RECOVERY_FONT_FILES_DIR)
1683	@mkdir -p $(PRIVATE_RECOVERY_FONT_FILES_DIR)
1684	$(foreach filename,$(PRIVATE_SOURCE_FONTS), cp $(filename) $(PRIVATE_RECOVERY_FONT_FILES_DIR) &&) true
1685	@rm -rf $(dir $@)
1686	@mkdir -p $(dir $@)
1687	$(foreach text_name,$(PRIVATE_RECOVERY_BACKGROUND_TEXT_LIST) $(PRIVATE_RECOVERY_WIPE_DATA_TEXT_LIST), \
1688	  $(eval output_file := $(dir $@)/$(patsubst recovery_%,%_text.png,$(text_name))) \
1689	  $(eval center_alignment := $(if $(filter $(text_name),$(PRIVATE_RECOVERY_BACKGROUND_TEXT_LIST)), --center_alignment)) \
1690	  java -jar $(PRIVATE_IMAGE_GENERATOR_JAR) \
1691	    --image_width $(PRIVATE_RECOVERY_IMAGE_WIDTH) \
1692	    --text_name $(text_name) \
1693	    --font_dir $(PRIVATE_RECOVERY_FONT_FILES_DIR) \
1694	    --resource_dir $(PRIVATE_RESOURCE_DIR) \
1695	    --output_file $(output_file) $(center_alignment) && \
1696	  $(PRIVATE_ZOPFLIPNG) -y --iterations=1 --filters=0 $(output_file) $(output_file) > /dev/null &&) true
1697else
1698RECOVERY_INSTALLING_TEXT_FILE :=
1699RECOVERY_INSTALLING_SECURITY_TEXT_FILE :=
1700RECOVERY_ERASING_TEXT_FILE :=
1701RECOVERY_ERROR_TEXT_FILE :=
1702RECOVERY_NO_COMMAND_TEXT_FILE :=
1703RECOVERY_CANCEL_WIPE_DATA_TEXT_FILE :=
1704RECOVERY_FACTORY_DATA_RESET_TEXT_FILE :=
1705RECOVERY_TRY_AGAIN_TEXT_FILE :=
1706RECOVERY_WIPE_DATA_CONFIRMATION_TEXT_FILE :=
1707RECOVERY_WIPE_DATA_MENU_HEADER_TEXT_FILE :=
1708endif # TARGET_RECOVERY_UI_SCREEN_WIDTH
1709
1710ifndef TARGET_PRIVATE_RES_DIRS
1711TARGET_PRIVATE_RES_DIRS := $(wildcard $(TARGET_DEVICE_DIR)/recovery/res)
1712endif
1713recovery_resource_deps := $(shell find $(recovery_resources_common) \
1714  $(TARGET_PRIVATE_RES_DIRS) -type f)
1715recovery_resource_deps += $(generated_recovery_text_files)
1716
1717
1718ifdef TARGET_RECOVERY_FSTAB
1719recovery_fstab := $(TARGET_RECOVERY_FSTAB)
1720else
1721recovery_fstab := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery.fstab))
1722endif
1723ifdef TARGET_RECOVERY_WIPE
1724recovery_wipe := $(TARGET_RECOVERY_WIPE)
1725else
1726recovery_wipe :=
1727endif
1728
1729# Traditionally with non-A/B OTA we have:
1730#   boot.img + recovery-from-boot.p + recovery-resource.dat = recovery.img.
1731# recovery-resource.dat is needed only if we carry an imgdiff patch of the boot and recovery images
1732# and invoke install-recovery.sh on the first boot post an OTA update.
1733#
1734# We no longer need that if one of the following conditions holds:
1735#   a) We carry a full copy of the recovery image - no patching needed
1736#      (BOARD_USES_FULL_RECOVERY_IMAGE = true);
1737#   b) We build a single image that contains boot and recovery both - no recovery image to install
1738#      (BOARD_USES_RECOVERY_AS_BOOT = true);
1739#   c) We mount the system image as / and therefore do not have a ramdisk in boot.img
1740#      (BOARD_BUILD_SYSTEM_ROOT_IMAGE = true).
1741#   d) We include the recovery DTBO image within recovery - not needing the resource file as we
1742#      do bsdiff because boot and recovery will contain different number of entries
1743#      (BOARD_INCLUDE_RECOVERY_DTBO = true).
1744#   e) We include the recovery ACPIO image within recovery - not needing the resource file as we
1745#      do bsdiff because boot and recovery will contain different number of entries
1746#      (BOARD_INCLUDE_RECOVERY_ACPIO = true).
1747
1748ifeq (,$(filter true, $(BOARD_USES_FULL_RECOVERY_IMAGE) $(BOARD_USES_RECOVERY_AS_BOOT) \
1749  $(BOARD_BUILD_SYSTEM_ROOT_IMAGE) $(BOARD_INCLUDE_RECOVERY_DTBO) $(BOARD_INCLUDE_RECOVERY_ACPIO)))
1750# Named '.dat' so we don't attempt to use imgdiff for patching it.
1751RECOVERY_RESOURCE_ZIP := $(TARGET_OUT)/etc/recovery-resource.dat
1752else
1753RECOVERY_RESOURCE_ZIP :=
1754endif
1755
1756INSTALLED_RECOVERY_BUILD_PROP_TARGET := $(TARGET_RECOVERY_ROOT_OUT)/prop.default
1757
1758$(INSTALLED_RECOVERY_BUILD_PROP_TARGET): PRIVATE_RECOVERY_UI_PROPERTIES := \
1759    TARGET_RECOVERY_UI_ANIMATION_FPS:animation_fps \
1760    TARGET_RECOVERY_UI_MARGIN_HEIGHT:margin_height \
1761    TARGET_RECOVERY_UI_MARGIN_WIDTH:margin_width \
1762    TARGET_RECOVERY_UI_MENU_UNUSABLE_ROWS:menu_unusable_rows \
1763    TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE:progress_bar_baseline \
1764    TARGET_RECOVERY_UI_TOUCH_LOW_THRESHOLD:touch_low_threshold \
1765    TARGET_RECOVERY_UI_TOUCH_HIGH_THRESHOLD:touch_high_threshold \
1766    TARGET_RECOVERY_UI_VR_STEREO_OFFSET:vr_stereo_offset
1767
1768# Parses the given list of build variables and writes their values as build properties if defined.
1769# For example, if a target defines `TARGET_RECOVERY_UI_MARGIN_HEIGHT := 100`,
1770# `ro.recovery.ui.margin_height=100` will be appended to the given output file.
1771# $(1): Map from the build variable names to property names
1772# $(2): Output file
1773define append-recovery-ui-properties
1774echo "#" >> $(2)
1775echo "# RECOVERY UI BUILD PROPERTIES" >> $(2)
1776echo "#" >> $(2)
1777$(foreach prop,$(1), \
1778    $(eval _varname := $(call word-colon,1,$(prop))) \
1779    $(eval _propname := $(call word-colon,2,$(prop))) \
1780    $(eval _value := $($(_varname))) \
1781    $(if $(_value), \
1782        echo ro.recovery.ui.$(_propname)=$(_value) >> $(2) &&)) true
1783endef
1784
1785$(INSTALLED_RECOVERY_BUILD_PROP_TARGET): \
1786	    $(INSTALLED_DEFAULT_PROP_TARGET) \
1787	    $(INSTALLED_VENDOR_DEFAULT_PROP_TARGET) \
1788	    $(intermediate_system_build_prop) \
1789	    $(INSTALLED_VENDOR_BUILD_PROP_TARGET) \
1790	    $(INSTALLED_ODM_BUILD_PROP_TARGET) \
1791	    $(INSTALLED_PRODUCT_BUILD_PROP_TARGET) \
1792	    $(INSTALLED_PRODUCT_SERVICES_BUILD_PROP_TARGET)
1793	@echo "Target recovery buildinfo: $@"
1794	$(hide) mkdir -p $(dir $@)
1795	$(hide) rm -f $@
1796	$(hide) cat $(INSTALLED_DEFAULT_PROP_TARGET) > $@
1797	$(hide) cat $(INSTALLED_VENDOR_DEFAULT_PROP_TARGET) >> $@
1798	$(hide) cat $(intermediate_system_build_prop) >> $@
1799	$(hide) cat $(INSTALLED_VENDOR_BUILD_PROP_TARGET) >> $@
1800	$(hide) cat $(INSTALLED_ODM_BUILD_PROP_TARGET) >> $@
1801	$(hide) cat $(INSTALLED_PRODUCT_BUILD_PROP_TARGET) >> $@
1802	$(hide) cat $(INSTALLED_PRODUCT_SERVICES_BUILD_PROP_TARGET) >> $@
1803	$(call append-recovery-ui-properties,$(PRIVATE_RECOVERY_UI_PROPERTIES),$@)
1804
1805INTERNAL_RECOVERYIMAGE_ARGS := \
1806	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
1807	--kernel $(recovery_kernel) \
1808	--ramdisk $(recovery_ramdisk)
1809
1810# Assumes this has already been stripped
1811ifdef INTERNAL_KERNEL_CMDLINE
1812  INTERNAL_RECOVERYIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)"
1813endif
1814ifdef BOARD_KERNEL_BASE
1815  INTERNAL_RECOVERYIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
1816endif
1817ifdef BOARD_KERNEL_PAGESIZE
1818  INTERNAL_RECOVERYIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
1819endif
1820ifdef BOARD_INCLUDE_RECOVERY_DTBO
1821ifdef BOARD_PREBUILT_RECOVERY_DTBOIMAGE
1822  INTERNAL_RECOVERYIMAGE_ARGS += --recovery_dtbo $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE)
1823else
1824  INTERNAL_RECOVERYIMAGE_ARGS += --recovery_dtbo $(BOARD_PREBUILT_DTBOIMAGE)
1825endif
1826endif
1827ifdef BOARD_INCLUDE_RECOVERY_ACPIO
1828  INTERNAL_RECOVERYIMAGE_ARGS += --recovery_acpio $(BOARD_RECOVERY_ACPIO)
1829endif
1830ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
1831  INTERNAL_RECOVERYIMAGE_ARGS += --dtb $(INSTALLED_DTBIMAGE_TARGET)
1832endif
1833
1834# Keys authorized to sign OTA packages this build will accept.  The
1835# build always uses dev-keys for this; release packaging tools will
1836# substitute other keys for this one.
1837OTA_PUBLIC_KEYS := $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem
1838
1839# Generate a file containing the keys that will be read by the
1840# recovery binary.
1841RECOVERY_INSTALL_OTA_KEYS := \
1842	$(call intermediates-dir-for,PACKAGING,ota_keys)/otacerts.zip
1843$(RECOVERY_INSTALL_OTA_KEYS): PRIVATE_OTA_PUBLIC_KEYS := $(OTA_PUBLIC_KEYS)
1844$(RECOVERY_INSTALL_OTA_KEYS): extra_keys := $(patsubst %,%.x509.pem,$(PRODUCT_EXTRA_RECOVERY_KEYS))
1845$(RECOVERY_INSTALL_OTA_KEYS): $(SOONG_ZIP) $(OTA_PUBLIC_KEYS) $(extra_keys)
1846	$(hide) rm -f $@
1847	$(hide) mkdir -p $(dir $@)
1848	$(hide) $(SOONG_ZIP) -o $@ $(foreach key_file, $(PRIVATE_OTA_PUBLIC_KEYS) $(extra_keys), -C $(dir $(key_file)) -f $(key_file))
1849
1850RECOVERYIMAGE_ID_FILE := $(PRODUCT_OUT)/recovery.id
1851
1852# $(1): output file
1853define build-recoveryimage-target
1854  # Making recovery image
1855  $(hide) mkdir -p $(TARGET_RECOVERY_OUT)
1856  $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/sdcard $(TARGET_RECOVERY_ROOT_OUT)/tmp
1857  # Copying baseline ramdisk...
1858  # Use rsync because "cp -Rf" fails to overwrite broken symlinks on Mac.
1859  $(hide) rsync -a --exclude=sdcard $(IGNORE_RECOVERY_SEPOLICY) $(IGNORE_CACHE_LINK) $(TARGET_ROOT_OUT) $(TARGET_RECOVERY_OUT)
1860  # Modifying ramdisk contents...
1861  $(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)),, \
1862    $(hide) ln -sf /system/bin/init $(TARGET_RECOVERY_ROOT_OUT)/init)
1863  $(if $(BOARD_RECOVERY_KERNEL_MODULES), \
1864    $(call build-image-kernel-modules,$(BOARD_RECOVERY_KERNEL_MODULES),$(TARGET_RECOVERY_ROOT_OUT),,$(call intermediates-dir-for,PACKAGING,depmod_recovery)))
1865  # Removes $(TARGET_RECOVERY_ROOT_OUT)/init*.rc EXCEPT init.recovery*.rc.
1866  $(hide) find $(TARGET_RECOVERY_ROOT_OUT) -maxdepth 1 -name 'init*.rc' -type f -not -name "init.recovery.*.rc" | xargs rm -f
1867  $(hide) cp -f $(recovery_initrc) $(TARGET_RECOVERY_ROOT_OUT)/
1868  $(hide) cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/ 2> /dev/null || true # Ignore error when the src file doesn't exist.
1869  $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/res
1870  $(hide) rm -rf $(TARGET_RECOVERY_ROOT_OUT)/res/*
1871  $(hide) cp -rf $(recovery_resources_common)/* $(TARGET_RECOVERY_ROOT_OUT)/res
1872  $(hide) $(foreach recovery_text_file,$(generated_recovery_text_files), \
1873    cp -rf $(recovery_text_file) $(TARGET_RECOVERY_ROOT_OUT)/res/images/ &&) true
1874  $(hide) cp -f $(recovery_font) $(TARGET_RECOVERY_ROOT_OUT)/res/images/font.png
1875  $(hide) $(foreach item,$(TARGET_PRIVATE_RES_DIRS), \
1876    cp -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/$(newline))
1877  $(hide) $(foreach item,$(recovery_fstab), \
1878    cp -f $(item) $(TARGET_RECOVERY_ROOT_OUT)/system/etc/recovery.fstab)
1879  $(if $(strip $(recovery_wipe)), \
1880    $(hide) cp -f $(recovery_wipe) $(TARGET_RECOVERY_ROOT_OUT)/system/etc/recovery.wipe)
1881  $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/system/etc/security
1882  $(hide) cp $(RECOVERY_INSTALL_OTA_KEYS) $(TARGET_RECOVERY_ROOT_OUT)/system/etc/security/otacerts.zip
1883  $(hide) ln -sf prop.default $(TARGET_RECOVERY_ROOT_OUT)/default.prop
1884  $(BOARD_RECOVERY_IMAGE_PREPARE)
1885  $(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RECOVERY_ROOT_OUT) | $(MINIGZIP) > $(recovery_ramdisk)
1886  $(if $(filter true,$(PRODUCT_SUPPORTS_VBOOT)), \
1887    $(hide) $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1).unsigned, \
1888    $(hide) $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1) --id > $(RECOVERYIMAGE_ID_FILE))
1889  $(if $(filter true,$(PRODUCT_SUPPORTS_BOOT_SIGNER)),\
1890    $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
1891      $(BOOT_SIGNER) /boot $(1) $(PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1),\
1892      $(BOOT_SIGNER) /recovery $(1) $(PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1)\
1893    )\
1894  )
1895  $(if $(filter true,$(PRODUCT_SUPPORTS_VBOOT)), \
1896    $(VBOOT_SIGNER) $(FUTILITY) $(1).unsigned $(PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(1).keyblock $(1))
1897  $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)), \
1898    $(hide) $(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(BOARD_BOOTIMAGE_PARTITION_SIZE))), \
1899    $(hide) $(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(BOARD_RECOVERYIMAGE_PARTITION_SIZE))))
1900  $(if $(filter true,$(BOARD_AVB_ENABLE)), \
1901    $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)), \
1902      $(hide) $(AVBTOOL) add_hash_footer --image $(1) --partition_size $(BOARD_BOOTIMAGE_PARTITION_SIZE) --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS),\
1903      $(hide) $(AVBTOOL) add_hash_footer --image $(1) --partition_size $(BOARD_RECOVERYIMAGE_PARTITION_SIZE) --partition_name recovery $(INTERNAL_AVB_RECOVERY_SIGNING_ARGS) $(BOARD_AVB_RECOVERY_ADD_HASH_FOOTER_ARGS)))
1904endef
1905
1906ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
1907ifeq (true,$(PRODUCT_SUPPORTS_BOOT_SIGNER))
1908$(INSTALLED_BOOTIMAGE_TARGET) : $(BOOT_SIGNER)
1909endif
1910ifeq (true,$(PRODUCT_SUPPORTS_VBOOT))
1911$(INSTALLED_BOOTIMAGE_TARGET) : $(VBOOT_SIGNER)
1912endif
1913ifeq (true,$(BOARD_AVB_ENABLE))
1914$(INSTALLED_BOOTIMAGE_TARGET) : $(AVBTOOL) $(BOARD_AVB_BOOT_KEY_PATH)
1915endif
1916ifdef BOARD_INCLUDE_RECOVERY_DTBO
1917ifdef BOARD_PREBUILT_RECOVERY_DTBOIMAGE
1918$(INSTALLED_BOOTIMAGE_TARGET): $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE)
1919else
1920$(INSTALLED_BOOTIMAGE_TARGET): $(BOARD_PREBUILT_DTBOIMAGE)
1921endif
1922endif
1923ifdef BOARD_INCLUDE_RECOVERY_ACPIO
1924$(INSTALLED_BOOTIMAGE_TARGET): $(BOARD_RECOVERY_ACPIO)
1925endif
1926ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
1927$(INSTALLED_BOOTIMAGE_TARGET): $(INSTALLED_DTBIMAGE_TARGET)
1928endif
1929
1930$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
1931	    $(INTERNAL_ROOT_FILES) \
1932	    $(INSTALLED_RAMDISK_TARGET) \
1933	    $(INTERNAL_RECOVERYIMAGE_FILES) \
1934	    $(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
1935	    $(INSTALLED_2NDBOOTLOADER_TARGET) \
1936	    $(INSTALLED_RECOVERY_BUILD_PROP_TARGET) \
1937	    $(recovery_resource_deps) \
1938	    $(recovery_fstab) \
1939	    $(RECOVERY_INSTALL_OTA_KEYS) \
1940	    $(BOARD_RECOVERY_KERNEL_MODULES) \
1941	    $(DEPMOD)
1942	$(call pretty,"Target boot image from recovery: $@")
1943	$(call build-recoveryimage-target, $@)
1944endif # BOARD_USES_RECOVERY_AS_BOOT
1945
1946ifdef BOARD_INCLUDE_RECOVERY_DTBO
1947ifdef BOARD_PREBUILT_RECOVERY_DTBOIMAGE
1948$(INSTALLED_RECOVERYIMAGE_TARGET): $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE)
1949else
1950$(INSTALLED_RECOVERYIMAGE_TARGET): $(BOARD_PREBUILT_DTBOIMAGE)
1951endif
1952endif
1953ifdef BOARD_INCLUDE_RECOVERY_ACPIO
1954$(INSTALLED_RECOVERYIMAGE_TARGET): $(BOARD_RECOVERY_ACPIO)
1955endif
1956ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
1957$(INSTALLED_RECOVERYIMAGE_TARGET): $(INSTALLED_DTBIMAGE_TARGET)
1958endif
1959
1960$(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
1961	    $(INTERNAL_ROOT_FILES) \
1962	    $(INSTALLED_RAMDISK_TARGET) \
1963	    $(INSTALLED_BOOTIMAGE_TARGET) \
1964	    $(INTERNAL_RECOVERYIMAGE_FILES) \
1965	    $(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
1966	    $(INSTALLED_2NDBOOTLOADER_TARGET) \
1967	    $(INSTALLED_RECOVERY_BUILD_PROP_TARGET) \
1968	    $(recovery_resource_deps) \
1969	    $(recovery_fstab) \
1970	    $(RECOVERY_INSTALL_OTA_KEYS) \
1971	    $(BOARD_RECOVERY_KERNEL_MODULES) \
1972	    $(DEPMOD)
1973	$(call build-recoveryimage-target, $@)
1974
1975ifdef RECOVERY_RESOURCE_ZIP
1976$(RECOVERY_RESOURCE_ZIP): $(INSTALLED_RECOVERYIMAGE_TARGET) | $(ZIPTIME)
1977	$(hide) mkdir -p $(dir $@)
1978	$(hide) find $(TARGET_RECOVERY_ROOT_OUT)/res -type f | sort | zip -0qrjX $@ -@
1979	$(remove-timestamps-from-package)
1980endif
1981
1982.PHONY: recoveryimage-nodeps
1983recoveryimage-nodeps:
1984	@echo "make $@: ignoring dependencies"
1985	$(call build-recoveryimage-target, $(INSTALLED_RECOVERYIMAGE_TARGET))
1986
1987else # INSTALLED_RECOVERYIMAGE_TARGET not defined
1988RECOVERY_RESOURCE_ZIP :=
1989endif
1990
1991.PHONY: recoveryimage
1992recoveryimage: $(INSTALLED_RECOVERYIMAGE_TARGET) $(RECOVERY_RESOURCE_ZIP)
1993
1994ifneq ($(BOARD_NAND_PAGE_SIZE),)
1995$(error MTD device is no longer supported and thus BOARD_NAND_PAGE_SIZE is deprecated.)
1996endif
1997
1998ifneq ($(BOARD_NAND_SPARE_SIZE),)
1999$(error MTD device is no longer supported and thus BOARD_NAND_SPARE_SIZE is deprecated.)
2000endif
2001
2002# -----------------------------------------------------------------
2003# the debug ramdisk, which is the original ramdisk plus additional
2004# files: force_debuggable, adb_debug.prop and userdebug sepolicy.
2005# When /force_debuggable is present, /init will load userdebug sepolicy
2006# and property files to allow adb root, if the device is unlocked.
2007
2008ifdef BUILDING_RAMDISK_IMAGE
2009BUILT_DEBUG_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk-debug.img
2010INSTALLED_DEBUG_RAMDISK_TARGET := $(BUILT_DEBUG_RAMDISK_TARGET)
2011
2012INTERNAL_DEBUG_RAMDISK_FILES := $(filter $(TARGET_DEBUG_RAMDISK_OUT)/%, \
2013    $(ALL_GENERATED_SOURCES) \
2014    $(ALL_DEFAULT_INSTALLED_MODULES))
2015
2016# Note: TARGET_DEBUG_RAMDISK_OUT will be $(PRODUCT_OUT)/debug_ramdisk/first_stage_ramdisk,
2017# if BOARD_USES_RECOVERY_AS_BOOT is true. Otherwise, it will be $(PRODUCT_OUT)/debug_ramdisk.
2018# But the root dir of the ramdisk to build is always $(PRODUCT_OUT)/debug_ramdisk.
2019my_debug_ramdisk_root_dir := $(PRODUCT_OUT)/debug_ramdisk
2020
2021INSTALLED_FILES_FILE_DEBUG_RAMDISK := $(PRODUCT_OUT)/installed-files-ramdisk-debug.txt
2022INSTALLED_FILES_JSON_DEBUG_RAMDISK := $(INSTALLED_FILES_FILE_DEBUG_RAMDISK:.txt=.json)
2023$(INSTALLED_FILES_FILE_DEBUG_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_DEBUG_RAMDISK)
2024$(INSTALLED_FILES_FILE_DEBUG_RAMDISK): DEBUG_RAMDISK_ROOT_DIR := $(my_debug_ramdisk_root_dir)
2025
2026# Cannot just depend on INTERNAL_DEBUG_RAMDISK_FILES like other INSTALLED_FILES_FILE_* rules.
2027# Because ramdisk-debug.img will rsync from either ramdisk.img or ramdisk-recovery.img.
2028# Need to depend on the built ramdisk-debug.img, to get a complete list of the installed files.
2029$(INSTALLED_FILES_FILE_DEBUG_RAMDISK) : $(INSTALLED_DEBUG_RAMDISK_TARGET)
2030$(INSTALLED_FILES_FILE_DEBUG_RAMDISK) : $(INTERNAL_DEBUG_RAMDISK_FILES) $(FILESLIST)
2031	echo Installed file list: $@
2032	mkdir -p $(dir $@)
2033	rm -f $@
2034	$(FILESLIST) $(DEBUG_RAMDISK_ROOT_DIR) > $(@:.txt=.json)
2035	build/make/tools/fileslist_util.py -c $(@:.txt=.json) > $@
2036
2037# ramdisk-debug.img will rsync the content from either ramdisk.img or ramdisk-recovery.img,
2038# depending on whether BOARD_USES_RECOVERY_AS_BOOT is set or not.
2039ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2040my_debug_ramdisk_sync_dir := $(TARGET_RECOVERY_ROOT_OUT)
2041else
2042my_debug_ramdisk_sync_dir := $(TARGET_RAMDISK_OUT)
2043endif # BOARD_USES_RECOVERY_AS_BOOT
2044
2045$(INSTALLED_DEBUG_RAMDISK_TARGET): DEBUG_RAMDISK_SYNC_DIR := $(my_debug_ramdisk_sync_dir)
2046$(INSTALLED_DEBUG_RAMDISK_TARGET): DEBUG_RAMDISK_ROOT_DIR := $(my_debug_ramdisk_root_dir)
2047
2048ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2049# ramdisk-recovery.img isn't a make target, need to depend on boot.img if it's for recovery.
2050$(INSTALLED_DEBUG_RAMDISK_TARGET): $(INSTALLED_BOOTIMAGE_TARGET)
2051else
2052# Depends on ramdisk.img, note that some target has ramdisk.img but no boot.img, e.g., emulator.
2053$(INSTALLED_DEBUG_RAMDISK_TARGET): $(INSTALLED_RAMDISK_TARGET)
2054endif # BOARD_USES_RECOVERY_AS_BOOT
2055$(INSTALLED_DEBUG_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_DEBUG_RAMDISK_FILES) | $(MINIGZIP)
2056	$(call pretty,"Target debug ram disk: $@")
2057	mkdir -p $(TARGET_DEBUG_RAMDISK_OUT)
2058	touch $(TARGET_DEBUG_RAMDISK_OUT)/force_debuggable
2059	rsync -a $(DEBUG_RAMDISK_SYNC_DIR)/ $(DEBUG_RAMDISK_ROOT_DIR)
2060	$(MKBOOTFS) -d $(TARGET_OUT) $(DEBUG_RAMDISK_ROOT_DIR) | $(MINIGZIP) > $@
2061
2062.PHONY: ramdisk_debug-nodeps
2063ramdisk_debug-nodeps: DEBUG_RAMDISK_SYNC_DIR := $(my_debug_ramdisk_sync_dir)
2064ramdisk_debug-nodeps: DEBUG_RAMDISK_ROOT_DIR := $(my_debug_ramdisk_root_dir)
2065ramdisk_debug-nodeps: $(MKBOOTFS) | $(MINIGZIP)
2066	echo "make $@: ignoring dependencies"
2067	mkdir -p $(TARGET_DEBUG_RAMDISK_OUT)
2068	touch $(TARGET_DEBUG_RAMDISK_OUT)/force_debuggable
2069	rsync -a $(DEBUG_RAMDISK_SYNC_DIR)/ $(DEBUG_RAMDISK_ROOT_DIR)
2070	$(MKBOOTFS) -d $(TARGET_OUT) $(DEBUG_RAMDISK_ROOT_DIR) | $(MINIGZIP) > $(INSTALLED_DEBUG_RAMDISK_TARGET)
2071
2072my_debug_ramdisk_sync_dir :=
2073my_debug_ramdisk_root_dir :=
2074
2075endif # BUILDING_RAMDISK_IMAGE
2076
2077# -----------------------------------------------------------------
2078# the boot-debug.img, which is the kernel plus ramdisk-debug.img
2079#
2080# Note: it's intentional to skip signing for boot-debug.img, because it
2081# can only be used if the device is unlocked with verification error.
2082ifneq ($(strip $(TARGET_NO_KERNEL)),true)
2083
2084INSTALLED_DEBUG_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot-debug.img
2085
2086# Replace ramdisk.img in $(MKBOOTIMG) ARGS with ramdisk-debug.img to build boot-debug.img
2087ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2088INTERNAL_DEBUG_BOOTIMAGE_ARGS := $(subst $(recovery_ramdisk),$(INSTALLED_DEBUG_RAMDISK_TARGET), $(INTERNAL_RECOVERYIMAGE_ARGS))
2089else
2090INTERNAL_DEBUG_BOOTIMAGE_ARGS := $(subst $(INSTALLED_RAMDISK_TARGET),$(INSTALLED_DEBUG_RAMDISK_TARGET), $(INTERNAL_BOOTIMAGE_ARGS))
2091endif
2092
2093# If boot.img is chained but boot-debug.img is not signed, libavb in bootloader
2094# will fail to find valid AVB metadata from the end of /boot, thus stop booting.
2095# Using a test key to sign boot-debug.img to continue booting with the mismatched
2096# public key, if the device is unlocked.
2097ifneq ($(BOARD_AVB_BOOT_KEY_PATH),)
2098BOARD_AVB_DEBUG_BOOT_KEY_PATH := external/avb/test/data/testkey_rsa2048.pem
2099$(INSTALLED_DEBUG_BOOTIMAGE_TARGET): PRIVATE_AVB_DEBUG_BOOT_SIGNING_ARGS := \
2100  --algorithm SHA256_RSA2048 --key $(BOARD_AVB_DEBUG_BOOT_KEY_PATH)
2101$(INSTALLED_DEBUG_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_DEBUG_BOOT_KEY_PATH)
2102endif
2103
2104# Depends on original boot.img and ramdisk-debug.img, to build the new boot-debug.img
2105$(INSTALLED_DEBUG_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_BOOTIMAGE_TARGET) $(INSTALLED_DEBUG_RAMDISK_TARGET)
2106	$(call pretty,"Target boot debug image: $@")
2107	$(MKBOOTIMG) $(INTERNAL_DEBUG_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
2108	$(if $(BOARD_AVB_BOOT_KEY_PATH),\
2109	  $(call assert-max-image-size,$@,$(call get-hash-image-max-size,$(BOARD_BOOTIMAGE_PARTITION_SIZE))); \
2110	  $(AVBTOOL) add_hash_footer \
2111	    --image $@ \
2112	    --partition_size $(BOARD_BOOTIMAGE_PARTITION_SIZE) \
2113	    --partition_name boot $(PRIVATE_AVB_DEBUG_BOOT_SIGNING_ARGS), \
2114	  $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE)))
2115
2116.PHONY: bootimage_debug-nodeps
2117bootimage_debug-nodeps: $(MKBOOTIMG)
2118	echo "make $@: ignoring dependencies"
2119	$(MKBOOTIMG) $(INTERNAL_DEBUG_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(INSTALLED_DEBUG_BOOTIMAGE_TARGET)
2120	$(if $(BOARD_AVB_BOOT_KEY_PATH),\
2121	  $(call assert-max-image-size,$(INSTALLED_DEBUG_BOOTIMAGE_TARGET),$(call get-hash-image-max-size,$(BOARD_BOOTIMAGE_PARTITION_SIZE))); \
2122	  $(AVBTOOL) add_hash_footer \
2123	    --image $(INSTALLED_DEBUG_BOOTIMAGE_TARGET) \
2124	    --partition_size $(BOARD_BOOTIMAGE_PARTITION_SIZE) \
2125	    --partition_name boot $(PRIVATE_AVB_DEBUG_BOOT_SIGNING_ARGS), \
2126	  $(call assert-max-image-size,$(INSTALLED_DEBUG_BOOTIMAGE_TARGET),$(BOARD_BOOTIMAGE_PARTITION_SIZE)))
2127
2128endif # TARGET_NO_KERNEL
2129
2130# -----------------------------------------------------------------
2131# system image
2132#
2133# Remove overridden packages from $(ALL_PDK_FUSION_FILES)
2134PDK_FUSION_SYSIMG_FILES := \
2135    $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
2136        $(ALL_PDK_FUSION_FILES))
2137
2138INTERNAL_SYSTEMIMAGE_FILES := $(sort $(filter $(TARGET_OUT)/%, \
2139    $(ALL_GENERATED_SOURCES) \
2140    $(ALL_DEFAULT_INSTALLED_MODULES) \
2141    $(PDK_FUSION_SYSIMG_FILES) \
2142    $(RECOVERY_RESOURCE_ZIP)) \
2143    $(PDK_FUSION_SYMLINK_STAMP))
2144
2145FULL_SYSTEMIMAGE_DEPS := $(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_USERIMAGES_DEPS)
2146
2147# ASAN libraries in the system image - add dependency.
2148ASAN_IN_SYSTEM_INSTALLED := $(TARGET_OUT)/asan.tar.bz2
2149ifneq (,$(filter address, $(SANITIZE_TARGET)))
2150  ifeq (true,$(SANITIZE_TARGET_SYSTEM))
2151    FULL_SYSTEMIMAGE_DEPS += $(ASAN_IN_SYSTEM_INSTALLED)
2152  endif
2153endif
2154
2155FULL_SYSTEMIMAGE_DEPS += $(INTERNAL_ROOT_FILES) $(INSTALLED_FILES_FILE_ROOT)
2156
2157# -----------------------------------------------------------------
2158ifdef BUILDING_SYSTEM_IMAGE
2159
2160# installed file list
2161# Depending on anything that $(BUILT_SYSTEMIMAGE) depends on.
2162# We put installed-files.txt ahead of image itself in the dependency graph
2163# so that we can get the size stat even if the build fails due to too large
2164# system image.
2165INSTALLED_FILES_FILE := $(PRODUCT_OUT)/installed-files.txt
2166INSTALLED_FILES_JSON := $(INSTALLED_FILES_FILE:.txt=.json)
2167$(INSTALLED_FILES_FILE): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON)
2168$(INSTALLED_FILES_FILE): $(FULL_SYSTEMIMAGE_DEPS) $(FILESLIST)
2169	@echo Installed file list: $@
2170	@mkdir -p $(dir $@)
2171	@rm -f $@
2172	$(hide) $(FILESLIST) $(TARGET_OUT) > $(@:.txt=.json)
2173	$(hide) build/make/tools/fileslist_util.py -c $(@:.txt=.json) > $@
2174
2175.PHONY: installed-file-list
2176installed-file-list: $(INSTALLED_FILES_FILE)
2177
2178$(call dist-for-goals, sdk win_sdk sdk_addon, $(INSTALLED_FILES_FILE))
2179
2180systemimage_intermediates := \
2181    $(call intermediates-dir-for,PACKAGING,systemimage)
2182BUILT_SYSTEMIMAGE := $(systemimage_intermediates)/system.img
2183
2184# Create symlink /system/vendor to /vendor if necessary.
2185ifdef BOARD_USES_VENDORIMAGE
2186define create-system-vendor-symlink
2187$(hide) if [ -d $(TARGET_OUT)/vendor ] && [ ! -h $(TARGET_OUT)/vendor ]; then \
2188  echo 'Non-symlink $(TARGET_OUT)/vendor detected!' 1>&2; \
2189  echo 'You cannot install files to $(TARGET_OUT)/vendor while building a separate vendor.img!' 1>&2; \
2190  exit 1; \
2191fi
2192$(hide) ln -sf /vendor $(TARGET_OUT)/vendor
2193endef
2194else
2195define create-system-vendor-symlink
2196endef
2197endif
2198
2199# Create symlink /system/product to /product if necessary.
2200ifdef BOARD_USES_PRODUCTIMAGE
2201define create-system-product-symlink
2202$(hide) if [ -d $(TARGET_OUT)/product ] && [ ! -h $(TARGET_OUT)/product ]; then \
2203  echo 'Non-symlink $(TARGET_OUT)/product detected!' 1>&2; \
2204  echo 'You cannot install files to $(TARGET_OUT)/product while building a separate product.img!' 1>&2; \
2205  exit 1; \
2206fi
2207$(hide) ln -sf /product $(TARGET_OUT)/product
2208endef
2209else
2210define create-system-product-symlink
2211endef
2212endif
2213
2214# Create symlink /system/product_services to /product_services if necessary.
2215ifdef BOARD_USES_PRODUCT_SERVICESIMAGE
2216define create-system-product_services-symlink
2217$(hide) if [ -d $(TARGET_OUT)/product_services ] && [ ! -h $(TARGET_OUT)/product_services ]; then \
2218  echo 'Non-symlink $(TARGET_OUT)/product_services detected!' 1>&2; \
2219  echo 'You cannot install files to $(TARGET_OUT)/product_services while building a separate product_services.img!' 1>&2; \
2220  exit 1; \
2221fi
2222$(hide) ln -sf /product_services $(TARGET_OUT)/product_services
2223endef
2224else
2225define create-system-product_services-symlink
2226endef
2227endif
2228
2229# Create symlink /vendor/odm to /odm if necessary.
2230ifdef BOARD_USES_ODMIMAGE
2231define create-vendor-odm-symlink
2232$(hide) if [ -d $(TARGET_OUT_VENDOR)/odm ] && [ ! -h $(TARGET_OUT_VENDOR)/odm ]; then \
2233  echo 'Non-symlink $(TARGET_OUT_VENDOR)/odm detected!' 1>&2; \
2234  echo 'You cannot install files to $(TARGET_OUT_VENDOR)/odm while building a separate odm.img!' 1>&2; \
2235  exit 1; \
2236fi
2237$(hide) ln -sf /odm $(TARGET_OUT_VENDOR)/odm
2238endef
2239else
2240define create-vendor-odm-symlink
2241endef
2242endif
2243
2244# $(1): output file
2245define build-systemimage-target
2246  @echo "Target system fs image: $(1)"
2247  $(call create-system-vendor-symlink)
2248  $(call create-system-product-symlink)
2249  $(call create-system-product_services-symlink)
2250  $(call check-apex-libs-absence-on-disk)
2251  @mkdir -p $(dir $(1)) $(systemimage_intermediates) && rm -rf $(systemimage_intermediates)/system_image_info.txt
2252  $(call generate-image-prop-dictionary, $(systemimage_intermediates)/system_image_info.txt,system, \
2253      skip_fsck=true)
2254  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
2255      build/make/tools/releasetools/build_image.py \
2256      $(TARGET_OUT) $(systemimage_intermediates)/system_image_info.txt $(1) $(TARGET_OUT) \
2257      || ( mkdir -p $${DIST_DIR}; cp $(INSTALLED_FILES_FILE) $${DIST_DIR}/installed-files-rescued.txt; \
2258           exit 1 )
2259endef
2260
2261$(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE) $(BUILD_IMAGE_SRCS)
2262	$(call build-systemimage-target,$@)
2263
2264INSTALLED_SYSTEMIMAGE_TARGET := $(PRODUCT_OUT)/system.img
2265SYSTEMIMAGE_SOURCE_DIR := $(TARGET_OUT)
2266
2267# INSTALLED_SYSTEMIMAGE_TARGET used to be named INSTALLED_SYSTEMIMAGE. Create an alias for backward
2268# compatibility, in case device-specific Makefiles still refer to the old name.
2269INSTALLED_SYSTEMIMAGE := $(INSTALLED_SYSTEMIMAGE_TARGET)
2270
2271# The system partition needs room for the recovery image as well.  We
2272# now store the recovery image as a binary patch using the boot image
2273# as the source (since they are very similar).  Generate the patch so
2274# we can see how big it's going to be, and include that in the system
2275# image size check calculation.
2276ifneq ($(INSTALLED_BOOTIMAGE_TARGET),)
2277ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
2278ifneq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
2279ifneq (,$(filter true, $(BOARD_BUILD_SYSTEM_ROOT_IMAGE) $(BOARD_INCLUDE_RECOVERY_DTBO) $(BOARD_INCLUDE_RECOVERY_ACPIO)))
2280diff_tool := $(HOST_OUT_EXECUTABLES)/bsdiff
2281else
2282diff_tool := $(HOST_OUT_EXECUTABLES)/imgdiff
2283endif
2284intermediates := $(call intermediates-dir-for,PACKAGING,recovery_patch)
2285RECOVERY_FROM_BOOT_PATCH := $(intermediates)/recovery_from_boot.p
2286$(RECOVERY_FROM_BOOT_PATCH): PRIVATE_DIFF_TOOL := $(diff_tool)
2287$(RECOVERY_FROM_BOOT_PATCH): \
2288	    $(INSTALLED_RECOVERYIMAGE_TARGET) \
2289	    $(INSTALLED_BOOTIMAGE_TARGET) \
2290	    $(diff_tool)
2291	@echo "Construct recovery from boot"
2292	mkdir -p $(dir $@)
2293	$(PRIVATE_DIFF_TOOL) $(INSTALLED_BOOTIMAGE_TARGET) $(INSTALLED_RECOVERYIMAGE_TARGET) $@
2294else # $(BOARD_USES_FULL_RECOVERY_IMAGE) == true
2295RECOVERY_FROM_BOOT_PATCH := $(INSTALLED_RECOVERYIMAGE_TARGET)
2296endif # BOARD_USES_FULL_RECOVERY_IMAGE
2297endif # INSTALLED_RECOVERYIMAGE_TARGET
2298endif # INSTALLED_BOOTIMAGE_TARGET
2299
2300$(INSTALLED_SYSTEMIMAGE_TARGET): $(BUILT_SYSTEMIMAGE) $(RECOVERY_FROM_BOOT_PATCH)
2301	@echo "Install system fs image: $@"
2302	$(copy-file-to-target)
2303	$(hide) $(call assert-max-image-size,$@ $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
2304
2305systemimage: $(INSTALLED_SYSTEMIMAGE_TARGET)
2306
2307.PHONY: systemimage-nodeps snod
2308systemimage-nodeps snod: $(filter-out systemimage-nodeps snod,$(MAKECMDGOALS)) \
2309	            | $(INTERNAL_USERIMAGES_DEPS)
2310	@echo "make $@: ignoring dependencies"
2311	$(call build-systemimage-target,$(INSTALLED_SYSTEMIMAGE_TARGET))
2312	$(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMIMAGE_TARGET),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
2313
2314ifneq (,$(filter systemimage-nodeps snod, $(MAKECMDGOALS)))
2315ifeq (true,$(WITH_DEXPREOPT))
2316$(warning Warning: with dexpreopt enabled, you may need a full rebuild.)
2317endif
2318endif
2319
2320endif # BUILDING_SYSTEM_IMAGE
2321
2322.PHONY: sync syncsys
2323sync syncsys: $(INTERNAL_SYSTEMIMAGE_FILES)
2324
2325#######
2326## system tarball
2327define build-systemtarball-target
2328  $(call pretty,"Target system fs tarball: $(INSTALLED_SYSTEMTARBALL_TARGET)")
2329  $(call create-system-vendor-symlink)
2330  $(call create-system-product-symlink)
2331  $(call create-system-product_services-symlink)
2332  $(MKTARBALL) $(FS_GET_STATS) \
2333    $(PRODUCT_OUT) system $(PRIVATE_SYSTEM_TAR) \
2334    $(INSTALLED_SYSTEMTARBALL_TARGET) $(TARGET_OUT)
2335endef
2336
2337ifndef SYSTEM_TARBALL_FORMAT
2338    SYSTEM_TARBALL_FORMAT := bz2
2339endif
2340
2341system_tar := $(PRODUCT_OUT)/system.tar
2342INSTALLED_SYSTEMTARBALL_TARGET := $(system_tar).$(SYSTEM_TARBALL_FORMAT)
2343$(INSTALLED_SYSTEMTARBALL_TARGET): PRIVATE_SYSTEM_TAR := $(system_tar)
2344$(INSTALLED_SYSTEMTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_SYSTEMIMAGE_FILES)
2345	$(build-systemtarball-target)
2346
2347.PHONY: systemtarball-nodeps
2348systemtarball-nodeps: $(FS_GET_STATS) \
2349                      $(filter-out systemtarball-nodeps stnod,$(MAKECMDGOALS))
2350	$(build-systemtarball-target)
2351
2352.PHONY: stnod
2353stnod: systemtarball-nodeps
2354
2355# -----------------------------------------------------------------
2356## platform.zip: system, plus other files to be used in PDK fusion build,
2357## in a zip file
2358##
2359## PDK_PLATFORM_ZIP_PRODUCT_BINARIES is used to store specified files to platform.zip.
2360## The variable will be typically set from BoardConfig.mk.
2361## Files under out dir will be rejected to prevent possible conflicts with other rules.
2362ifneq (,$(BUILD_PLATFORM_ZIP))
2363pdk_odex_javalibs := $(strip $(foreach m,$(DEXPREOPT.MODULES.JAVA_LIBRARIES),\
2364  $(if $(filter $(DEXPREOPT.$(m).INSTALLED_STRIPPED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m))))
2365pdk_odex_apps := $(strip $(foreach m,$(DEXPREOPT.MODULES.APPS),\
2366  $(if $(filter $(DEXPREOPT.$(m).INSTALLED_STRIPPED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m))))
2367pdk_classes_dex := $(strip \
2368  $(foreach m,$(pdk_odex_javalibs),$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar) \
2369  $(foreach m,$(pdk_odex_apps),$(call intermediates-dir-for,APPS,$(m))/package.dex.apk))
2370
2371pdk_odex_config_mk := $(PRODUCT_OUT)/pdk_dexpreopt_config.mk
2372$(pdk_odex_config_mk): PRIVATE_JAVA_LIBRARIES := $(pdk_odex_javalibs)
2373$(pdk_odex_config_mk): PRIVATE_APPS := $(pdk_odex_apps)
2374$(pdk_odex_config_mk) :
2375	@echo "PDK odex config makefile: $@"
2376	$(hide) mkdir -p $(dir $@)
2377	$(hide) echo "# Auto-generated. Do not modify." > $@
2378	$(hide) echo "PDK.DEXPREOPT.JAVA_LIBRARIES:=$(PRIVATE_JAVA_LIBRARIES)" >> $@
2379	$(hide) echo "PDK.DEXPREOPT.APPS:=$(PRIVATE_APPS)" >> $@
2380	$(foreach m,$(PRIVATE_JAVA_LIBRARIES),\
2381	  $(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar)" >> $@$(newline)\
2382	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\
2383	  $(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\
2384	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\
2385	  )
2386	$(foreach m,$(PRIVATE_APPS),\
2387	  $(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,APPS,$(m))/package.dex.apk)" >> $@$(newline)\
2388	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\
2389	  $(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\
2390	  $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\
2391	  $(hide) echo "PDK.DEXPREOPT.$(m).PRIVILEGED_MODULE:=$(DEXPREOPT.$(m).PRIVILEGED_MODULE)" >> $@$(newline)\
2392	  $(hide) echo "PDK.DEXPREOPT.$(m).VENDOR_MODULE:=$(DEXPREOPT.$(m).VENDOR_MODULE)" >> $@$(newline)\
2393	  $(hide) echo "PDK.DEXPREOPT.$(m).TARGET_ARCH:=$(DEXPREOPT.$(m).TARGET_ARCH)" >> $@$(newline)\
2394	  $(hide) echo "PDK.DEXPREOPT.$(m).STRIPPED_SRC:=$(patsubst $(PRODUCT_OUT)/%,%,$(DEXPREOPT.$(m).INSTALLED_STRIPPED))" >> $@$(newline)\
2395	  )
2396
2397PDK_PLATFORM_ZIP_PRODUCT_BINARIES := $(filter-out $(OUT_DIR)/%,$(PDK_PLATFORM_ZIP_PRODUCT_BINARIES))
2398INSTALLED_PLATFORM_ZIP := $(PRODUCT_OUT)/platform.zip
2399
2400$(INSTALLED_PLATFORM_ZIP): PRIVATE_DEX_FILES := $(pdk_classes_dex)
2401$(INSTALLED_PLATFORM_ZIP): PRIVATE_ODEX_CONFIG := $(pdk_odex_config_mk)
2402$(INSTALLED_PLATFORM_ZIP) : $(SOONG_ZIP)
2403# dependencies for the other partitions are defined below after their file lists
2404# are known
2405$(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES) $(pdk_classes_dex) $(pdk_odex_config_mk) $(API_FINGERPRINT)
2406	$(call pretty,"Platform zip package: $(INSTALLED_PLATFORM_ZIP)")
2407	rm -f $@ $@.lst
2408	echo "-C $(PRODUCT_OUT)" >> $@.lst
2409	echo "-D $(TARGET_OUT)" >> $@.lst
2410	echo "-D $(TARGET_OUT_NOTICE_FILES)" >> $@.lst
2411	echo "$(addprefix -f $(TARGET_OUT_UNSTRIPPED)/,$(PDK_SYMBOL_FILES_LIST))" >> $@.lst
2412ifdef BUILDING_VENDOR_IMAGE
2413	echo "-D $(TARGET_OUT_VENDOR)" >> $@.lst
2414endif
2415ifdef BUILDING_PRODUCT_IMAGE
2416	echo "-D $(TARGET_OUT_PRODUCT)" >> $@.lst
2417endif
2418ifdef BUILDING_PRODUCT_SERVICES_IMAGE
2419	echo "-D $(TARGET_OUT_PRODUCT_SERVICES)" >> $@.lst
2420endif
2421ifdef BUILDING_ODM_IMAGE
2422	echo "-D $(TARGET_OUT_ODM)" >> $@.lst
2423endif
2424ifneq ($(PDK_PLATFORM_JAVA_ZIP_CONTENTS),)
2425	echo "-C $(OUT_DIR)" >> $@.lst
2426	for f in $(filter-out $(PRIVATE_DEX_FILES),$(addprefix -f $(OUT_DIR)/,$(PDK_PLATFORM_JAVA_ZIP_CONTENTS))); do \
2427	  if [ -e $$f ]; then \
2428	    echo "-f $$f"; \
2429	  fi \
2430	done >> $@.lst
2431endif
2432ifneq ($(PDK_PLATFORM_ZIP_PRODUCT_BINARIES),)
2433        echo "-C . $(addprefix -f ,$(PDK_PLATFORM_ZIP_PRODUCT_BINARIES))" >> $@.lst
2434endif
2435	@# Add dex-preopt files and config.
2436	$(if $(PRIVATE_DEX_FILES),\
2437	  echo "-C $(OUT_DIR) $(addprefix -f ,$(PRIVATE_DEX_FILES))") >> $@.lst
2438	echo "-C $(dir $(API_FINGERPRINT)) -f $(API_FINGERPRINT)" >> $@.lst
2439	touch $(PRODUCT_OUT)/pdk.mk
2440	echo "-C $(PRODUCT_OUT) -f $(PRIVATE_ODEX_CONFIG) -f $(PRODUCT_OUT)/pdk.mk" >> $@.lst
2441	$(SOONG_ZIP) --ignore_missing_files -o $@ @$@.lst
2442
2443.PHONY: platform
2444platform: $(INSTALLED_PLATFORM_ZIP)
2445
2446.PHONY: platform-java
2447platform-java: platform
2448
2449# Dist the platform.zip
2450ifneq (,$(filter platform platform-java, $(MAKECMDGOALS)))
2451$(call dist-for-goals, platform platform-java, $(INSTALLED_PLATFORM_ZIP))
2452endif
2453
2454endif # BUILD_PLATFORM_ZIP
2455
2456# -----------------------------------------------------------------
2457## boot tarball
2458define build-boottarball-target
2459    $(hide) echo "Target boot fs tarball: $(INSTALLED_BOOTTARBALL_TARGET)"
2460    $(hide) mkdir -p $(PRODUCT_OUT)/boot
2461    $(hide) cp -f $(INTERNAL_BOOTIMAGE_FILES) $(PRODUCT_OUT)/boot/.
2462    $(hide) echo $(INTERNAL_KERNEL_CMDLINE) > $(PRODUCT_OUT)/boot/cmdline
2463    $(hide) $(MKTARBALL) $(FS_GET_STATS) \
2464                 $(PRODUCT_OUT) boot $(PRIVATE_BOOT_TAR) \
2465                 $(INSTALLED_BOOTTARBALL_TARGET) $(TARGET_OUT)
2466endef
2467
2468ifndef BOOT_TARBALL_FORMAT
2469    BOOT_TARBALL_FORMAT := bz2
2470endif
2471
2472boot_tar := $(PRODUCT_OUT)/boot.tar
2473INSTALLED_BOOTTARBALL_TARGET := $(boot_tar).$(BOOT_TARBALL_FORMAT)
2474$(INSTALLED_BOOTTARBALL_TARGET): PRIVATE_BOOT_TAR := $(boot_tar)
2475$(INSTALLED_BOOTTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_BOOTIMAGE_FILES)
2476	$(build-boottarball-target)
2477
2478.PHONY: boottarball-nodeps btnod
2479boottarball-nodeps btnod: $(FS_GET_STATS) \
2480                      $(filter-out boottarball-nodeps btnod,$(MAKECMDGOALS))
2481	$(build-boottarball-target)
2482
2483
2484# -----------------------------------------------------------------
2485# data partition image
2486INTERNAL_USERDATAIMAGE_FILES := \
2487    $(filter $(TARGET_OUT_DATA)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
2488
2489ifdef BUILDING_USERDATA_IMAGE
2490userdataimage_intermediates := \
2491    $(call intermediates-dir-for,PACKAGING,userdata)
2492BUILT_USERDATAIMAGE_TARGET := $(PRODUCT_OUT)/userdata.img
2493
2494define build-userdataimage-target
2495  $(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
2496  @mkdir -p $(TARGET_OUT_DATA)
2497  @mkdir -p $(userdataimage_intermediates) && rm -rf $(userdataimage_intermediates)/userdata_image_info.txt
2498  $(call generate-image-prop-dictionary, $(userdataimage_intermediates)/userdata_image_info.txt,userdata,skip_fsck=true)
2499  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
2500      build/make/tools/releasetools/build_image.py \
2501      $(TARGET_OUT_DATA) $(userdataimage_intermediates)/userdata_image_info.txt $(INSTALLED_USERDATAIMAGE_TARGET) $(TARGET_OUT)
2502  $(hide) $(call assert-max-image-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_PARTITION_SIZE))
2503endef
2504
2505# We just build this directly to the install location.
2506INSTALLED_USERDATAIMAGE_TARGET := $(BUILT_USERDATAIMAGE_TARGET)
2507INSTALLED_USERDATAIMAGE_TARGET_DEPS := \
2508    $(INTERNAL_USERIMAGES_DEPS) \
2509    $(INTERNAL_USERDATAIMAGE_FILES) \
2510    $(BUILD_IMAGE_SRCS)
2511$(INSTALLED_USERDATAIMAGE_TARGET): $(INSTALLED_USERDATAIMAGE_TARGET_DEPS)
2512	$(build-userdataimage-target)
2513
2514.PHONY: userdataimage-nodeps
2515userdataimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
2516	$(build-userdataimage-target)
2517
2518endif # BUILDING_USERDATA_IMAGE
2519
2520# ASAN libraries in the system image - build rule.
2521ASAN_OUT_DIRS_FOR_SYSTEM_INSTALL := $(sort $(patsubst $(PRODUCT_OUT)/%,%,\
2522  $(TARGET_OUT_SHARED_LIBRARIES) \
2523  $(2ND_TARGET_OUT_SHARED_LIBRARIES) \
2524  $(TARGET_OUT_VENDOR_SHARED_LIBRARIES) \
2525  $(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)))
2526# Extra options: Enforce the system user for the files to avoid having to change ownership.
2527ASAN_SYSTEM_INSTALL_OPTIONS := --owner=1000 --group=1000
2528# Note: experimentally, it seems not worth it to try to get "best" compression. We don't save
2529#       enough space.
2530$(ASAN_IN_SYSTEM_INSTALLED): $(INSTALLED_USERDATAIMAGE_TARGET_DEPS)
2531	tar cfj $(ASAN_IN_SYSTEM_INSTALLED) $(ASAN_SYSTEM_INSTALL_OPTIONS) -C $(TARGET_OUT_DATA)/.. $(ASAN_OUT_DIRS_FOR_SYSTEM_INSTALL) >/dev/null
2532
2533#######
2534## data partition tarball
2535define build-userdatatarball-target
2536    $(call pretty,"Target userdata fs tarball: " \
2537                  "$(INSTALLED_USERDATATARBALL_TARGET)")
2538    $(MKTARBALL) $(FS_GET_STATS) \
2539	    $(PRODUCT_OUT) data $(PRIVATE_USERDATA_TAR) \
2540	    $(INSTALLED_USERDATATARBALL_TARGET) $(TARGET_OUT)
2541endef
2542
2543userdata_tar := $(PRODUCT_OUT)/userdata.tar
2544INSTALLED_USERDATATARBALL_TARGET := $(userdata_tar).bz2
2545$(INSTALLED_USERDATATARBALL_TARGET): PRIVATE_USERDATA_TAR := $(userdata_tar)
2546$(INSTALLED_USERDATATARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_USERDATAIMAGE_FILES)
2547	$(build-userdatatarball-target)
2548
2549$(call dist-for-goals,userdatatarball,$(INSTALLED_USERDATATARBALL_TARGET))
2550
2551.PHONY: userdatatarball-nodeps
2552userdatatarball-nodeps: $(FS_GET_STATS)
2553	$(build-userdatatarball-target)
2554
2555
2556# -----------------------------------------------------------------
2557# partition table image
2558ifdef BOARD_BPT_INPUT_FILES
2559
2560BUILT_BPTIMAGE_TARGET := $(PRODUCT_OUT)/partition-table.img
2561BUILT_BPTJSON_TARGET := $(PRODUCT_OUT)/partition-table.bpt
2562
2563INTERNAL_BVBTOOL_MAKE_TABLE_ARGS := \
2564	--output_gpt $(BUILT_BPTIMAGE_TARGET) \
2565	--output_json $(BUILT_BPTJSON_TARGET) \
2566	$(foreach file, $(BOARD_BPT_INPUT_FILES), --input $(file))
2567
2568ifdef BOARD_BPT_DISK_SIZE
2569INTERNAL_BVBTOOL_MAKE_TABLE_ARGS += --disk_size $(BOARD_BPT_DISK_SIZE)
2570endif
2571
2572define build-bptimage-target
2573  $(call pretty,"Target partition table image: $(INSTALLED_BPTIMAGE_TARGET)")
2574  $(hide) $(BPTTOOL) make_table $(INTERNAL_BVBTOOL_MAKE_TABLE_ARGS) $(BOARD_BPT_MAKE_TABLE_ARGS)
2575endef
2576
2577INSTALLED_BPTIMAGE_TARGET := $(BUILT_BPTIMAGE_TARGET)
2578$(BUILT_BPTJSON_TARGET): $(INSTALLED_BPTIMAGE_TARGET)
2579	$(hide) touch -c $(BUILT_BPTJSON_TARGET)
2580
2581$(INSTALLED_BPTIMAGE_TARGET): $(BPTTOOL) $(BOARD_BPT_INPUT_FILES)
2582	$(build-bptimage-target)
2583
2584.PHONY: bptimage-nodeps
2585bptimage-nodeps:
2586	$(build-bptimage-target)
2587
2588endif # BOARD_BPT_INPUT_FILES
2589
2590# -----------------------------------------------------------------
2591# cache partition image
2592ifdef BUILDING_CACHE_IMAGE
2593INTERNAL_CACHEIMAGE_FILES := \
2594    $(filter $(TARGET_OUT_CACHE)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
2595
2596cacheimage_intermediates := \
2597    $(call intermediates-dir-for,PACKAGING,cache)
2598BUILT_CACHEIMAGE_TARGET := $(PRODUCT_OUT)/cache.img
2599
2600define build-cacheimage-target
2601  $(call pretty,"Target cache fs image: $(INSTALLED_CACHEIMAGE_TARGET)")
2602  @mkdir -p $(TARGET_OUT_CACHE)
2603  @mkdir -p $(cacheimage_intermediates) && rm -rf $(cacheimage_intermediates)/cache_image_info.txt
2604  $(call generate-image-prop-dictionary, $(cacheimage_intermediates)/cache_image_info.txt,cache,skip_fsck=true)
2605  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
2606      build/make/tools/releasetools/build_image.py \
2607      $(TARGET_OUT_CACHE) $(cacheimage_intermediates)/cache_image_info.txt $(INSTALLED_CACHEIMAGE_TARGET) $(TARGET_OUT)
2608  $(hide) $(call assert-max-image-size,$(INSTALLED_CACHEIMAGE_TARGET),$(BOARD_CACHEIMAGE_PARTITION_SIZE))
2609endef
2610
2611# We just build this directly to the install location.
2612INSTALLED_CACHEIMAGE_TARGET := $(BUILT_CACHEIMAGE_TARGET)
2613$(INSTALLED_CACHEIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_CACHEIMAGE_FILES) $(BUILD_IMAGE_SRCS)
2614	$(build-cacheimage-target)
2615
2616.PHONY: cacheimage-nodeps
2617cacheimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
2618	$(build-cacheimage-target)
2619
2620else # BUILDING_CACHE_IMAGE
2621# we need to ignore the broken cache link when doing the rsync
2622IGNORE_CACHE_LINK := --exclude=cache
2623endif # BUILDING_CACHE_IMAGE
2624
2625# -----------------------------------------------------------------
2626# system_other partition image
2627ifdef BUILDING_SYSTEM_OTHER_IMAGE
2628ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
2629# Marker file to identify that odex files are installed
2630INSTALLED_SYSTEM_OTHER_ODEX_MARKER := $(TARGET_OUT_SYSTEM_OTHER)/system-other-odex-marker
2631ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_SYSTEM_OTHER_ODEX_MARKER)
2632$(INSTALLED_SYSTEM_OTHER_ODEX_MARKER):
2633	$(hide) touch $@
2634endif
2635
2636INTERNAL_SYSTEMOTHERIMAGE_FILES := \
2637    $(filter $(TARGET_OUT_SYSTEM_OTHER)/%,\
2638      $(ALL_DEFAULT_INSTALLED_MODULES)\
2639      $(ALL_PDK_FUSION_FILES)) \
2640    $(PDK_FUSION_SYMLINK_STAMP)
2641
2642# system_other dex files are installed as a side-effect of installing system image files
2643INTERNAL_SYSTEMOTHERIMAGE_FILES += $(INTERNAL_SYSTEMIMAGE_FILES)
2644
2645INSTALLED_FILES_FILE_SYSTEMOTHER := $(PRODUCT_OUT)/installed-files-system-other.txt
2646INSTALLED_FILES_JSON_SYSTEMOTHER := $(INSTALLED_FILES_FILE_SYSTEMOTHER:.txt=.json)
2647$(INSTALLED_FILES_FILE_SYSTEMOTHER): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_SYSTEMOTHER)
2648$(INSTALLED_FILES_FILE_SYSTEMOTHER) : $(INTERNAL_SYSTEMOTHERIMAGE_FILES) $(FILESLIST)
2649	@echo Installed file list: $@
2650	@mkdir -p $(dir $@)
2651	@rm -f $@
2652	$(hide) $(FILESLIST) $(TARGET_OUT_SYSTEM_OTHER) > $(@:.txt=.json)
2653	$(hide) build/make/tools/fileslist_util.py -c $(@:.txt=.json) > $@
2654
2655# Determines partition size for system_other.img.
2656ifeq ($(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS),true)
2657ifneq ($(filter system,$(BOARD_SUPER_PARTITION_BLOCK_DEVICES)),)
2658INTERNAL_SYSTEM_OTHER_PARTITION_SIZE := $(BOARD_SUPER_PARTITION_SYSTEM_DEVICE_SIZE)
2659endif
2660endif
2661
2662ifndef INTERNAL_SYSTEM_OTHER_PARTITION_SIZE
2663INTERNAL_SYSTEM_OTHER_PARTITION_SIZE:= $(BOARD_SYSTEMIMAGE_PARTITION_SIZE)
2664endif
2665
2666systemotherimage_intermediates := \
2667    $(call intermediates-dir-for,PACKAGING,system_other)
2668BUILT_SYSTEMOTHERIMAGE_TARGET := $(PRODUCT_OUT)/system_other.img
2669
2670# Note that we assert the size is SYSTEMIMAGE_PARTITION_SIZE since this is the 'b' system image.
2671define build-systemotherimage-target
2672  $(call pretty,"Target system_other fs image: $(INSTALLED_SYSTEMOTHERIMAGE_TARGET)")
2673  @mkdir -p $(TARGET_OUT_SYSTEM_OTHER)
2674  @mkdir -p $(systemotherimage_intermediates) && rm -rf $(systemotherimage_intermediates)/system_other_image_info.txt
2675  $(call generate-image-prop-dictionary, $(systemotherimage_intermediates)/system_other_image_info.txt,system,skip_fsck=true)
2676  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
2677      build/make/tools/releasetools/build_image.py \
2678      $(TARGET_OUT_SYSTEM_OTHER) $(systemotherimage_intermediates)/system_other_image_info.txt $(INSTALLED_SYSTEMOTHERIMAGE_TARGET) $(TARGET_OUT)
2679  $(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMOTHERIMAGE_TARGET),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
2680endef
2681
2682# We just build this directly to the install location.
2683INSTALLED_SYSTEMOTHERIMAGE_TARGET := $(BUILT_SYSTEMOTHERIMAGE_TARGET)
2684ifneq (true,$(SANITIZE_LITE))
2685# Only create system_other when not building the second stage of a SANITIZE_LITE build.
2686$(INSTALLED_SYSTEMOTHERIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_SYSTEMOTHERIMAGE_FILES) $(INSTALLED_FILES_FILE_SYSTEMOTHER)
2687	$(build-systemotherimage-target)
2688endif
2689
2690.PHONY: systemotherimage-nodeps
2691systemotherimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
2692	$(build-systemotherimage-target)
2693
2694endif # BUILDING_SYSTEM_OTHER_IMAGE
2695
2696
2697# -----------------------------------------------------------------
2698# vendor partition image
2699ifdef BUILDING_VENDOR_IMAGE
2700INTERNAL_VENDORIMAGE_FILES := \
2701    $(filter $(TARGET_OUT_VENDOR)/%,\
2702      $(ALL_DEFAULT_INSTALLED_MODULES)\
2703      $(ALL_PDK_FUSION_FILES)) \
2704    $(PDK_FUSION_SYMLINK_STAMP)
2705
2706# Final Vendor VINTF manifest including fragments. This is not assembled
2707# on the device because it depends on everything in a given device
2708# image which defines a vintf_fragment.
2709ifdef BUILT_VENDOR_MANIFEST
2710BUILT_ASSEMBLED_VENDOR_MANIFEST := $(PRODUCT_OUT)/verified_assembled_vendor_manifest.xml
2711ifeq (true,$(PRODUCT_ENFORCE_VINTF_MANIFEST))
2712ifneq ($(strip $(DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE) $(DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE)),)
2713$(BUILT_ASSEMBLED_VENDOR_MANIFEST): PRIVATE_SYSTEM_ASSEMBLE_VINTF_ENV_VARS := VINTF_ENFORCE_NO_UNUSED_HALS=true
2714endif # DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE or DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE
2715endif # PRODUCT_ENFORCE_VINTF_MANIFEST
2716$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(HOST_OUT_EXECUTABLES)/assemble_vintf
2717$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(BUILT_SYSTEM_MATRIX)
2718$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(BUILT_VENDOR_MANIFEST)
2719$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(INTERNAL_VENDORIMAGE_FILES)
2720
2721$(BUILT_ASSEMBLED_VENDOR_MANIFEST): PRIVATE_FLAGS :=
2722
2723# -- Kernel version and configurations.
2724ifeq ($(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS),true)
2725
2726# BOARD_KERNEL_CONFIG_FILE and BOARD_KERNEL_VERSION can be used to override the values extracted
2727# from INSTALLED_KERNEL_TARGET.
2728ifdef BOARD_KERNEL_CONFIG_FILE
2729ifdef BOARD_KERNEL_VERSION
2730$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(BOARD_KERNEL_CONFIG_FILE)
2731$(BUILT_ASSEMBLED_VENDOR_MANIFEST): PRIVATE_FLAGS += --kernel $(BOARD_KERNEL_VERSION):$(BOARD_KERNEL_CONFIG_FILE)
2732my_board_extracted_kernel := true
2733endif # BOARD_KERNEL_VERSION
2734endif # BOARD_KERNEL_CONFIG_FILE
2735
2736ifneq ($(my_board_extracted_kernel),true)
2737ifndef INSTALLED_KERNEL_TARGET
2738$(warning No INSTALLED_KERNEL_TARGET is defined when PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS \
2739    is true. Information about the updated kernel cannot be built into OTA update package. \
2740    You can fix this by: (1) setting TARGET_NO_KERNEL to false and installing the built kernel \
2741    to $(PRODUCT_OUT)/kernel, so that kernel information will be extracted from the built kernel; \
2742    or (2) extracting kernel configuration and defining BOARD_KERNEL_CONFIG_FILE and \
2743    BOARD_KERNEL_VERSION manually; or (3) unsetting PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS \
2744    manually.)
2745else
2746intermediates := $(call intermediates-dir-for,ETC,$(notdir $(BUILT_ASSEMBLED_VENDOR_MANIFEST)))
2747
2748# Tools for decompression that is not in PATH.
2749# Check $(EXTRACT_KERNEL) for decompression algorithms supported by the script.
2750# Algorithms that are in the script but not in this list will be found in PATH.
2751my_decompress_tools := \
2752    lz4:$(HOST_OUT_EXECUTABLES)/lz4 \
2753
2754my_kernel_configs := $(intermediates)/kernel_configs.txt
2755my_kernel_version := $(intermediates)/kernel_version.txt
2756$(my_kernel_configs): .KATI_IMPLICIT_OUTPUTS := $(my_kernel_version)
2757$(my_kernel_configs): PRIVATE_KERNEL_VERSION_FILE := $(my_kernel_version)
2758$(my_kernel_configs): PRIVATE_DECOMPRESS_TOOLS := $(my_decompress_tools)
2759$(my_kernel_configs): $(foreach pair,$(my_decompress_tools),$(call word-colon,2,$(pair)))
2760$(my_kernel_configs): $(EXTRACT_KERNEL) $(INSTALLED_KERNEL_TARGET)
2761	$< --tools $(PRIVATE_DECOMPRESS_TOOLS) --input $(INSTALLED_KERNEL_TARGET) \
2762	  --output-configs $@ \
2763	  --output-version $(PRIVATE_KERNEL_VERSION_FILE)
2764
2765$(BUILT_ASSEMBLED_VENDOR_MANIFEST): $(my_kernel_configs) $(my_kernel_version)
2766$(BUILT_ASSEMBLED_VENDOR_MANIFEST): PRIVATE_FLAGS += --kernel $$(cat $(my_kernel_version)):$(my_kernel_configs)
2767
2768intermediates :=
2769my_kernel_configs :=
2770my_kernel_version :=
2771my_decompress_tools :=
2772
2773endif # my_board_extracted_kernel
2774my_board_extracted_kernel :=
2775
2776endif # INSTALLED_KERNEL_TARGET
2777endif # PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS
2778
2779$(BUILT_ASSEMBLED_VENDOR_MANIFEST):
2780	@echo "Verifying vendor VINTF manifest."
2781	PRODUCT_ENFORCE_VINTF_MANIFEST=$(PRODUCT_ENFORCE_VINTF_MANIFEST) \
2782	$(PRIVATE_SYSTEM_ASSEMBLE_VINTF_ENV_VARS) \
2783	$(HOST_OUT_EXECUTABLES)/assemble_vintf \
2784	    $(PRIVATE_FLAGS) \
2785	    -c $(BUILT_SYSTEM_MATRIX) \
2786	    -i $(BUILT_VENDOR_MANIFEST) \
2787	    $$([ -d $(TARGET_OUT_VENDOR)/etc/vintf/manifest ] && \
2788	        find $(TARGET_OUT_VENDOR)/etc/vintf/manifest -type f -name "*.xml" | \
2789	        sed "s/^/-i /" | tr '\n' ' ') -o $@
2790endif # BUILT_VENDOR_MANIFEST
2791
2792# platform.zip depends on $(INTERNAL_VENDORIMAGE_FILES).
2793$(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_VENDORIMAGE_FILES)
2794
2795INSTALLED_FILES_FILE_VENDOR := $(PRODUCT_OUT)/installed-files-vendor.txt
2796INSTALLED_FILES_JSON_VENDOR := $(INSTALLED_FILES_FILE_VENDOR:.txt=.json)
2797$(INSTALLED_FILES_FILE_VENDOR): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_VENDOR)
2798$(INSTALLED_FILES_FILE_VENDOR) : $(INTERNAL_VENDORIMAGE_FILES) $(FILESLIST)
2799	@echo Installed file list: $@
2800	@mkdir -p $(dir $@)
2801	@rm -f $@
2802	$(hide) $(FILESLIST) $(TARGET_OUT_VENDOR) > $(@:.txt=.json)
2803	$(hide) build/make/tools/fileslist_util.py -c $(@:.txt=.json) > $@
2804
2805vendorimage_intermediates := \
2806    $(call intermediates-dir-for,PACKAGING,vendor)
2807BUILT_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
2808define build-vendorimage-target
2809  $(call pretty,"Target vendor fs image: $(INSTALLED_VENDORIMAGE_TARGET)")
2810  @mkdir -p $(TARGET_OUT_VENDOR)
2811  $(call create-vendor-odm-symlink)
2812  @mkdir -p $(vendorimage_intermediates) && rm -rf $(vendorimage_intermediates)/vendor_image_info.txt
2813  $(call generate-image-prop-dictionary, $(vendorimage_intermediates)/vendor_image_info.txt,vendor,skip_fsck=true)
2814  $(if $(BOARD_VENDOR_KERNEL_MODULES), \
2815    $(call build-image-kernel-modules,$(BOARD_VENDOR_KERNEL_MODULES),$(TARGET_OUT_VENDOR),vendor/,$(call intermediates-dir-for,PACKAGING,depmod_vendor)))
2816  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
2817      build/make/tools/releasetools/build_image.py \
2818      $(TARGET_OUT_VENDOR) $(vendorimage_intermediates)/vendor_image_info.txt $(INSTALLED_VENDORIMAGE_TARGET) $(TARGET_OUT)
2819  $(hide) $(call assert-max-image-size,$(INSTALLED_VENDORIMAGE_TARGET),$(BOARD_VENDORIMAGE_PARTITION_SIZE))
2820endef
2821
2822# We just build this directly to the install location.
2823INSTALLED_VENDORIMAGE_TARGET := $(BUILT_VENDORIMAGE_TARGET)
2824ifdef BUILT_VENDOR_MANIFEST
2825$(INSTALLED_VENDORIMAGE_TARGET): $(BUILT_ASSEMBLED_VENDOR_MANIFEST)
2826endif
2827$(INSTALLED_VENDORIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_VENDORIMAGE_FILES) $(INSTALLED_FILES_FILE_VENDOR) $(BUILD_IMAGE_SRCS) $(DEPMOD) $(BOARD_VENDOR_KERNEL_MODULES)
2828	$(build-vendorimage-target)
2829
2830.PHONY: vendorimage-nodeps vnod
2831vendorimage-nodeps vnod: | $(INTERNAL_USERIMAGES_DEPS) $(DEPMOD)
2832	$(build-vendorimage-target)
2833
2834sync: $(INTERNAL_VENDORIMAGE_FILES)
2835
2836else ifdef BOARD_PREBUILT_VENDORIMAGE
2837INSTALLED_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
2838$(eval $(call copy-one-file,$(BOARD_PREBUILT_VENDORIMAGE),$(INSTALLED_VENDORIMAGE_TARGET)))
2839endif
2840
2841# -----------------------------------------------------------------
2842# product partition image
2843ifdef BUILDING_PRODUCT_IMAGE
2844INTERNAL_PRODUCTIMAGE_FILES := \
2845    $(filter $(TARGET_OUT_PRODUCT)/%,\
2846      $(ALL_DEFAULT_INSTALLED_MODULES)\
2847      $(ALL_PDK_FUSION_FILES)) \
2848    $(PDK_FUSION_SYMLINK_STAMP)
2849
2850# platform.zip depends on $(INTERNAL_PRODUCTIMAGE_FILES).
2851$(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_PRODUCTIMAGE_FILES)
2852
2853INSTALLED_FILES_FILE_PRODUCT := $(PRODUCT_OUT)/installed-files-product.txt
2854INSTALLED_FILES_JSON_PRODUCT := $(INSTALLED_FILES_FILE_PRODUCT:.txt=.json)
2855$(INSTALLED_FILES_FILE_PRODUCT): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_PRODUCT)
2856$(INSTALLED_FILES_FILE_PRODUCT) : $(INTERNAL_PRODUCTIMAGE_FILES) $(FILESLIST)
2857	@echo Installed file list: $@
2858	@mkdir -p $(dir $@)
2859	@rm -f $@
2860	$(hide) $(FILESLIST) $(TARGET_OUT_PRODUCT) > $(@:.txt=.json)
2861	$(hide) build/tools/fileslist_util.py -c $(@:.txt=.json) > $@
2862
2863productimage_intermediates := \
2864    $(call intermediates-dir-for,PACKAGING,product)
2865BUILT_PRODUCTIMAGE_TARGET := $(PRODUCT_OUT)/product.img
2866define build-productimage-target
2867  $(call pretty,"Target product fs image: $(INSTALLED_PRODUCTIMAGE_TARGET)")
2868  @mkdir -p $(TARGET_OUT_PRODUCT)
2869  @mkdir -p $(productimage_intermediates) && rm -rf $(productimage_intermediates)/product_image_info.txt
2870  $(call generate-image-prop-dictionary, $(productimage_intermediates)/product_image_info.txt,product,skip_fsck=true)
2871  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
2872      ./build/tools/releasetools/build_image.py \
2873      $(TARGET_OUT_PRODUCT) $(productimage_intermediates)/product_image_info.txt $(INSTALLED_PRODUCTIMAGE_TARGET) $(TARGET_OUT)
2874  $(hide) $(call assert-max-image-size,$(INSTALLED_PRODUCTIMAGE_TARGET),$(BOARD_PRODUCTIMAGE_PARTITION_SIZE))
2875endef
2876
2877# We just build this directly to the install location.
2878INSTALLED_PRODUCTIMAGE_TARGET := $(BUILT_PRODUCTIMAGE_TARGET)
2879$(INSTALLED_PRODUCTIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_PRODUCTIMAGE_FILES) $(INSTALLED_FILES_FILE_PRODUCT) $(BUILD_IMAGE_SRCS)
2880	$(build-productimage-target)
2881
2882.PHONY: productimage-nodeps pnod
2883productimage-nodeps pnod: | $(INTERNAL_USERIMAGES_DEPS)
2884	$(build-productimage-target)
2885
2886sync: $(INTERNAL_PRODUCTIMAGE_FILES)
2887
2888else ifdef BOARD_PREBUILT_PRODUCTIMAGE
2889INSTALLED_PRODUCTIMAGE_TARGET := $(PRODUCT_OUT)/product.img
2890$(eval $(call copy-one-file,$(BOARD_PREBUILT_PRODUCTIMAGE),$(INSTALLED_PRODUCTIMAGE_TARGET)))
2891endif
2892
2893# -----------------------------------------------------------------
2894# Final Framework VINTF manifest including fragments. This is not assembled
2895# on the device because it depends on everything in a given device
2896# image which defines a vintf_fragment.
2897
2898BUILT_ASSEMBLED_FRAMEWORK_MANIFEST := $(PRODUCT_OUT)/verified_assembled_framework_manifest.xml
2899$(BUILT_ASSEMBLED_FRAMEWORK_MANIFEST): $(HOST_OUT_EXECUTABLES)/assemble_vintf \
2900                                       $(BUILT_VENDOR_MATRIX) \
2901                                       $(BUILT_SYSTEM_MANIFEST) \
2902                                       $(FULL_SYSTEMIMAGE_DEPS) \
2903                                       $(BUILT_PRODUCT_MANIFEST) \
2904                                       $(BUILT_PRODUCTIMAGE_TARGET)
2905	@echo "Verifying framework VINTF manifest."
2906	PRODUCT_ENFORCE_VINTF_MANIFEST=$(PRODUCT_ENFORCE_VINTF_MANIFEST) \
2907	$(HOST_OUT_EXECUTABLES)/assemble_vintf \
2908	    -o $@ \
2909	    -c $(BUILT_VENDOR_MATRIX) \
2910	    -i $(BUILT_SYSTEM_MANIFEST) \
2911	    $(addprefix -i ,\
2912	      $(filter $(TARGET_OUT)/etc/vintf/manifest/%.xml,$(FULL_SYSTEMIMAGE_DEPS)) \
2913	      $(BUILT_PRODUCT_MANIFEST) \
2914	      $(filter $(TARGET_OUT_PRODUCT)/etc/vintf/manifest/%.xml,$(INTERNAL_PRODUCTIMAGE_FILES)))
2915
2916droidcore: $(BUILT_ASSEMBLED_FRAMEWORK_MANIFEST)
2917
2918# -----------------------------------------------------------------
2919# product_services partition image
2920ifdef BUILDING_PRODUCT_SERVICES_IMAGE
2921INTERNAL_PRODUCT_SERVICESIMAGE_FILES := \
2922    $(filter $(TARGET_OUT_PRODUCT_SERVICES)/%,\
2923      $(ALL_DEFAULT_INSTALLED_MODULES)\
2924      $(ALL_PDK_FUSION_FILES)) \
2925    $(PDK_FUSION_SYMLINK_STAMP)
2926
2927# platform.zip depends on $(INTERNAL_PRODUCT_SERVICESIMAGE_FILES).
2928$(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_PRODUCT_SERVICESIMAGE_FILES)
2929
2930INSTALLED_FILES_FILE_PRODUCT_SERVICES := $(PRODUCT_OUT)/installed-files-product_services.txt
2931INSTALLED_FILES_JSON_PRODUCT_SERVICES := $(INSTALLED_FILES_FILE_PRODUCT_SERVICES:.txt=.json)
2932$(INSTALLED_FILES_FILE_PRODUCT_SERVICES): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_PRODUCT_SERVICES)
2933$(INSTALLED_FILES_FILE_PRODUCT_SERVICES) : $(INTERNAL_PRODUCT_SERVICESIMAGE_FILES) $(FILESLIST)
2934	@echo Installed file list: $@
2935	@mkdir -p $(dir $@)
2936	@rm -f $@
2937	$(hide) $(FILESLIST) $(TARGET_OUT_PRODUCT_SERVICES) > $(@:.txt=.json)
2938	$(hide) build/tools/fileslist_util.py -c $(@:.txt=.json) > $@
2939
2940product_servicesimage_intermediates := \
2941    $(call intermediates-dir-for,PACKAGING,product_services)
2942BUILT_PRODUCT_SERVICESIMAGE_TARGET := $(PRODUCT_OUT)/product_services.img
2943define build-product_servicesimage-target
2944  $(call pretty,"Target product_services fs image: $(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET)")
2945  @mkdir -p $(TARGET_OUT_PRODUCT_SERVICES)
2946  @mkdir -p $(product_servicesimage_intermediates) && rm -rf $(product_servicesimage_intermediates)/product_services_image_info.txt
2947  $(call generate-image-prop-dictionary, $(product_servicesimage_intermediates)/product_services_image_info.txt,product_services, skip_fsck=true)
2948  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
2949      ./build/tools/releasetools/build_image.py \
2950      $(TARGET_OUT_PRODUCT_SERVICES) $(product_servicesimage_intermediates)/product_services_image_info.txt $(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET) $(TARGET_OUT)
2951  $(hide) $(call assert-max-image-size,$(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET),$(BOARD_PRODUCT_SERVICESIMAGE_PARTITION_SIZE))
2952endef
2953
2954# We just build this directly to the install location.
2955INSTALLED_PRODUCT_SERVICESIMAGE_TARGET := $(BUILT_PRODUCT_SERVICESIMAGE_TARGET)
2956$(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_PRODUCT_SERVICESIMAGE_FILES) $(INSTALLED_FILES_FILE_PRODUCT_SERVICES) $(BUILD_IMAGE_SRCS)
2957	$(build-product_servicesimage-target)
2958
2959.PHONY: productservicesimage-nodeps psnod
2960productservicesimage-nodeps psnod: | $(INTERNAL_USERIMAGES_DEPS)
2961	$(build-product_servicesimage-target)
2962
2963sync: $(INTERNAL_PRODUCT_SERVICESIMAGE_FILES)
2964
2965else ifdef BOARD_PREBUILT_PRODUCT_SERVICESIMAGE
2966INSTALLED_PRODUCT_SERVICESIMAGE_TARGET := $(PRODUCT_OUT)/product_services.img
2967$(eval $(call copy-one-file,$(BOARD_PREBUILT_PRODUCT_SERVICESIMAGE),$(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET)))
2968endif
2969
2970# -----------------------------------------------------------------
2971# odm partition image
2972ifdef BUILDING_ODM_IMAGE
2973INTERNAL_ODMIMAGE_FILES := \
2974    $(filter $(TARGET_OUT_ODM)/%,\
2975      $(ALL_DEFAULT_INSTALLED_MODULES)\
2976      $(ALL_PDK_FUSION_FILES)) \
2977    $(PDK_FUSION_SYMLINK_STAMP)
2978# platform.zip depends on $(INTERNAL_ODMIMAGE_FILES).
2979$(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_ODMIMAGE_FILES)
2980
2981INSTALLED_FILES_FILE_ODM := $(PRODUCT_OUT)/installed-files-odm.txt
2982INSTALLED_FILES_JSON_ODM := $(INSTALLED_FILES_FILE_ODM:.txt=.json)
2983$(INSTALLED_FILES_FILE_ODM): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_ODM)
2984$(INSTALLED_FILES_FILE_ODM) : $(INTERNAL_ODMIMAGE_FILES) $(FILESLIST)
2985	@echo Installed file list: $@
2986	@mkdir -p $(dir $@)
2987	@rm -f $@
2988	$(hide) $(FILESLIST) $(TARGET_OUT_ODM) > $(@:.txt=.json)
2989	$(hide) build/tools/fileslist_util.py -c $(@:.txt=.json) > $@
2990
2991odmimage_intermediates := \
2992    $(call intermediates-dir-for,PACKAGING,odm)
2993BUILT_ODMIMAGE_TARGET := $(PRODUCT_OUT)/odm.img
2994define build-odmimage-target
2995  $(call pretty,"Target odm fs image: $(INSTALLED_ODMIMAGE_TARGET)")
2996  @mkdir -p $(TARGET_OUT_ODM)
2997  @mkdir -p $(odmimage_intermediates) && rm -rf $(odmimage_intermediates)/odm_image_info.txt
2998  $(call generate-userimage-prop-dictionary, $(odmimage_intermediates)/odm_image_info.txt, skip_fsck=true)
2999  $(if $(BOARD_ODM_KERNEL_MODULES), \
3000    $(call build-image-kernel-modules,$(BOARD_ODM_KERNEL_MODULES),$(TARGET_OUT_ODM),odm/,$(call intermediates-dir-for,PACKAGING,depmod_odm)))
3001  $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
3002      ./build/tools/releasetools/build_image.py \
3003      $(TARGET_OUT_ODM) $(odmimage_intermediates)/odm_image_info.txt $(INSTALLED_ODMIMAGE_TARGET) $(TARGET_OUT)
3004  $(hide) $(call assert-max-image-size,$(INSTALLED_ODMIMAGE_TARGET),$(BOARD_ODMIMAGE_PARTITION_SIZE))
3005endef
3006
3007# We just build this directly to the install location.
3008INSTALLED_ODMIMAGE_TARGET := $(BUILT_ODMIMAGE_TARGET)
3009$(INSTALLED_ODMIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_ODMIMAGE_FILES) $(INSTALLED_FILES_FILE_ODM) $(BUILD_IMAGE_SRCS) $(DEPMOD) $(BOARD_ODM_KERNEL_MODULES)
3010	$(build-odmimage-target)
3011
3012.PHONY: odmimage-nodeps onod
3013odmimage-nodeps onod: | $(INTERNAL_USERIMAGES_DEPS) $(DEPMOD)
3014	$(build-odmimage-target)
3015
3016sync: $(INTERNAL_ODMIMAGE_FILES)
3017
3018else ifdef BOARD_PREBUILT_ODMIMAGE
3019INSTALLED_ODMIMAGE_TARGET := $(PRODUCT_OUT)/odm.img
3020$(eval $(call copy-one-file,$(BOARD_PREBUILT_ODMIMAGE),$(INSTALLED_ODMIMAGE_TARGET)))
3021endif
3022
3023# -----------------------------------------------------------------
3024# dtbo image
3025ifdef BOARD_PREBUILT_DTBOIMAGE
3026INSTALLED_DTBOIMAGE_TARGET := $(PRODUCT_OUT)/dtbo.img
3027
3028ifeq ($(BOARD_AVB_ENABLE),true)
3029$(INSTALLED_DTBOIMAGE_TARGET): $(BOARD_PREBUILT_DTBOIMAGE) $(AVBTOOL) $(BOARD_AVB_DTBO_KEY_PATH)
3030	cp $(BOARD_PREBUILT_DTBOIMAGE) $@
3031	$(AVBTOOL) add_hash_footer \
3032	    --image $@ \
3033	    --partition_size $(BOARD_DTBOIMG_PARTITION_SIZE) \
3034	    --partition_name dtbo $(INTERNAL_AVB_DTBO_SIGNING_ARGS) \
3035	    $(BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS)
3036else
3037$(INSTALLED_DTBOIMAGE_TARGET): $(BOARD_PREBUILT_DTBOIMAGE)
3038	cp $(BOARD_PREBUILT_DTBOIMAGE) $@
3039endif
3040
3041endif # BOARD_PREBUILT_DTBOIMAGE
3042
3043# Returns a list of image targets corresponding to the given list of partitions. For example, it
3044# returns "$(INSTALLED_PRODUCTIMAGE_TARGET)" for "product", or "$(INSTALLED_SYSTEMIMAGE_TARGET)
3045# $(INSTALLED_VENDORIMAGE_TARGET)" for "system vendor".
3046# (1): list of partitions like "system", "vendor" or "system product product_services".
3047define images-for-partitions
3048$(strip $(foreach item,$(1),$(INSTALLED_$(call to-upper,$(item))IMAGE_TARGET)))
3049endef
3050
3051# -----------------------------------------------------------------
3052# vbmeta image
3053ifeq ($(BOARD_AVB_ENABLE),true)
3054
3055BUILT_VBMETAIMAGE_TARGET := $(PRODUCT_OUT)/vbmeta.img
3056AVB_CHAIN_KEY_DIR := $(TARGET_OUT_INTERMEDIATES)/avb_chain_keys
3057
3058ifdef BOARD_AVB_KEY_PATH
3059$(if $(BOARD_AVB_ALGORITHM),,$(error BOARD_AVB_ALGORITHM is not defined))
3060else
3061# If key path isn't specified, use the 4096-bit test key.
3062BOARD_AVB_ALGORITHM := SHA256_RSA4096
3063BOARD_AVB_KEY_PATH := external/avb/test/data/testkey_rsa4096.pem
3064endif
3065
3066# AVB signing for system_other.img.
3067ifdef BUILDING_SYSTEM_OTHER_IMAGE
3068ifdef BOARD_AVB_SYSTEM_OTHER_KEY_PATH
3069$(if $(BOARD_AVB_SYSTEM_OTHER_ALGORITHM),,$(error BOARD_AVB_SYSTEM_OTHER_ALGORITHM is not defined))
3070else
3071# If key path isn't specified, use the same key as BOARD_AVB_KEY_PATH.
3072BOARD_AVB_SYSTEM_OTHER_KEY_PATH := $(BOARD_AVB_KEY_PATH)
3073BOARD_AVB_SYSTEM_OTHER_ALGORITHM := $(BOARD_AVB_ALGORITHM)
3074endif
3075
3076$(INSTALLED_PRODUCT_SYSTEM_OTHER_AVBKEY_TARGET): $(AVBTOOL) $(BOARD_AVB_SYSTEM_OTHER_KEY_PATH)
3077	@echo Extracting system_other avb key: $@
3078	@rm -f $@
3079	@mkdir -p $(dir $@)
3080	$(AVBTOOL) extract_public_key --key $(BOARD_AVB_SYSTEM_OTHER_KEY_PATH) --output $@
3081
3082ifndef BOARD_AVB_SYSTEM_OTHER_ROLLBACK_INDEX
3083BOARD_AVB_SYSTEM_OTHER_ROLLBACK_INDEX := $(PLATFORM_SECURITY_PATCH_TIMESTAMP)
3084endif
3085
3086BOARD_AVB_SYSTEM_OTHER_ADD_HASHTREE_FOOTER_ARGS += --rollback_index $(BOARD_AVB_SYSTEM_OTHER_ROLLBACK_INDEX)
3087endif # end of AVB for BUILDING_SYSTEM_OTHER_IMAGE
3088
3089INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES := \
3090    $(BOARD_AVB_VBMETA_SYSTEM) \
3091    $(BOARD_AVB_VBMETA_VENDOR)
3092
3093# Not allowing the same partition to appear in multiple groups.
3094ifneq ($(words $(sort $(INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES))),$(words $(INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES)))
3095  $(error BOARD_AVB_VBMETA_SYSTEM and BOARD_AVB_VBMETA_VENDOR cannot have duplicates)
3096endif
3097
3098# Appends os version and security patch level as a AVB property descriptor
3099
3100BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS += \
3101    --prop com.android.build.system.os_version:$(PLATFORM_VERSION) \
3102    --prop com.android.build.system.security_patch:$(PLATFORM_SECURITY_PATCH)
3103
3104BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS += \
3105    --prop com.android.build.product.os_version:$(PLATFORM_VERSION) \
3106    --prop com.android.build.product.security_patch:$(PLATFORM_SECURITY_PATCH)
3107
3108BOARD_AVB_PRODUCT_SERVICES_ADD_HASHTREE_FOOTER_ARGS += \
3109    --prop com.android.build.product_services.os_version:$(PLATFORM_VERSION) \
3110    --prop com.android.build.product_services.security_patch:$(PLATFORM_SECURITY_PATCH)
3111
3112BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS += \
3113    --prop com.android.build.boot.os_version:$(PLATFORM_VERSION)
3114
3115BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS += \
3116    --prop com.android.build.vendor.os_version:$(PLATFORM_VERSION)
3117
3118BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS += \
3119    --prop com.android.build.odm.os_version:$(PLATFORM_VERSION)
3120
3121# The following vendor- and odm-specific images needs explicit SPL set per board.
3122ifdef BOOT_SECURITY_PATCH
3123BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS += \
3124    --prop com.android.build.boot.security_patch:$(BOOT_SECURITY_PATCH)
3125endif
3126
3127ifdef VENDOR_SECURITY_PATCH
3128BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS += \
3129    --prop com.android.build.vendor.security_patch:$(VENDOR_SECURITY_PATCH)
3130endif
3131
3132ifdef ODM_SECURITY_PATCH
3133BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS += \
3134    --prop com.android.build.odm.security_patch:$(ODM_SECURITY_PATCH)
3135endif
3136
3137BOOT_FOOTER_ARGS := BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS
3138DTBO_FOOTER_ARGS := BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS
3139SYSTEM_FOOTER_ARGS := BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS
3140VENDOR_FOOTER_ARGS := BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS
3141RECOVERY_FOOTER_ARGS := BOARD_AVB_RECOVERY_ADD_HASH_FOOTER_ARGS
3142PRODUCT_FOOTER_ARGS := BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS
3143PRODUCT_SERVICES_FOOTER_ARGS := BOARD_AVB_PRODUCT_SERVICES_ADD_HASHTREE_FOOTER_ARGS
3144ODM_FOOTER_ARGS := BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS
3145
3146# Helper function that checks and sets required build variables for an AVB chained partition.
3147# $(1): the partition to enable AVB chain, e.g., boot or system or vbmeta_system.
3148define _check-and-set-avb-chain-args
3149$(eval part := $(1))
3150$(eval PART=$(call to-upper,$(part)))
3151
3152$(eval _key_path := BOARD_AVB_$(PART)_KEY_PATH)
3153$(eval _signing_algorithm := BOARD_AVB_$(PART)_ALGORITHM)
3154$(eval _rollback_index := BOARD_AVB_$(PART)_ROLLBACK_INDEX)
3155$(eval _rollback_index_location := BOARD_AVB_$(PART)_ROLLBACK_INDEX_LOCATION)
3156$(if $($(_key_path)),,$(error $(_key_path) is not defined))
3157$(if $($(_signing_algorithm)),,$(error $(_signing_algorithm) is not defined))
3158$(if $($(_rollback_index)),,$(error $(_rollback_index) is not defined))
3159$(if $($(_rollback_index_location)),,$(error $(_rollback_index_location) is not defined))
3160
3161# Set INTERNAL_AVB_(PART)_SIGNING_ARGS
3162$(eval _signing_args := INTERNAL_AVB_$(PART)_SIGNING_ARGS)
3163$(eval $(_signing_args) := \
3164    --algorithm $($(_signing_algorithm)) --key $($(_key_path)))
3165
3166$(eval INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
3167    --chain_partition $(part):$($(_rollback_index_location)):$(AVB_CHAIN_KEY_DIR)/$(part).avbpubkey)
3168
3169# Set rollback_index via footer args for non-chained vbmeta image. Chained vbmeta image will pick up
3170# the index via a separate flag (e.g. BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX).
3171$(if $(filter $(part),$(part:vbmeta_%=%)),\
3172    $(eval _footer_args := $(PART)_FOOTER_ARGS) \
3173    $(eval $($(_footer_args)) += --rollback_index $($(_rollback_index))))
3174endef
3175
3176# Checks and sets the required build variables for an AVB partition. The partition will be
3177# configured as a chained partition, if BOARD_AVB_<partition>_KEY_PATH is defined. Otherwise the
3178# image descriptor will be included into vbmeta.img, unless it has been already added to any chained
3179# VBMeta image.
3180# $(1): Partition name, e.g. boot or system.
3181define check-and-set-avb-args
3182$(eval _in_chained_vbmeta := $(filter $(1),$(INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES)))
3183$(if $(BOARD_AVB_$(call to-upper,$(1))_KEY_PATH),\
3184    $(if $(_in_chained_vbmeta),\
3185        $(error Chaining partition "$(1)" in chained VBMeta image is not supported)) \
3186    $(call _check-and-set-avb-chain-args,$(1)),\
3187    $(if $(_in_chained_vbmeta),,\
3188        $(eval INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
3189            --include_descriptors_from_image $(call images-for-partitions,$(1)))))
3190endef
3191
3192ifdef INSTALLED_BOOTIMAGE_TARGET
3193$(eval $(call check-and-set-avb-args,boot))
3194endif
3195
3196$(eval $(call check-and-set-avb-args,system))
3197
3198ifdef INSTALLED_VENDORIMAGE_TARGET
3199$(eval $(call check-and-set-avb-args,vendor))
3200endif
3201
3202ifdef INSTALLED_PRODUCTIMAGE_TARGET
3203$(eval $(call check-and-set-avb-args,product))
3204endif
3205
3206ifdef INSTALLED_PRODUCT_SERVICESIMAGE_TARGET
3207$(eval $(call check-and-set-avb-args,product_services))
3208endif
3209
3210ifdef INSTALLED_ODMIMAGE_TARGET
3211$(eval $(call check-and-set-avb-args,odm))
3212endif
3213
3214ifdef INSTALLED_DTBOIMAGE_TARGET
3215$(eval $(call check-and-set-avb-args,dtbo))
3216endif
3217
3218ifdef INSTALLED_RECOVERYIMAGE_TARGET
3219$(eval $(call check-and-set-avb-args,recovery))
3220endif
3221
3222# Not using INSTALLED_VBMETA_SYSTEMIMAGE_TARGET as it won't be set yet.
3223ifdef BOARD_AVB_VBMETA_SYSTEM
3224$(eval $(call check-and-set-avb-args,vbmeta_system))
3225endif
3226
3227ifdef BOARD_AVB_VBMETA_VENDOR
3228$(eval $(call check-and-set-avb-args,vbmeta_vendor))
3229endif
3230
3231# Add kernel cmdline descriptor for kernel to mount system.img as root with
3232# dm-verity. This works when system.img is either chained or not-chained:
3233# - chained: The --setup_as_rootfs_from_kernel option will add dm-verity kernel
3234#   cmdline descriptor to system.img
3235# - not-chained: The --include_descriptors_from_image option for make_vbmeta_image
3236#   will include the kernel cmdline descriptor from system.img into vbmeta.img
3237ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
3238ifeq ($(filter system, $(BOARD_SUPER_PARTITION_PARTITION_LIST)),)
3239BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS += --setup_as_rootfs_from_kernel
3240endif
3241endif
3242
3243BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --padding_size 4096
3244BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS += --padding_size 4096
3245BOARD_AVB_MAKE_VBMETA_VENDOR_IMAGE_ARGS += --padding_size 4096
3246
3247ifeq (eng,$(filter eng, $(TARGET_BUILD_VARIANT)))
3248# We only need the flag in top-level vbmeta.img.
3249BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --set_hashtree_disabled_flag
3250endif
3251
3252ifdef BOARD_AVB_ROLLBACK_INDEX
3253BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --rollback_index $(BOARD_AVB_ROLLBACK_INDEX)
3254endif
3255
3256ifdef BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX
3257BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS += \
3258    --rollback_index $(BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX)
3259endif
3260
3261ifdef BOARD_AVB_VBMETA_VENDOR_ROLLBACK_INDEX
3262BOARD_AVB_MAKE_VBMETA_VENDOR_IMAGE_ARGS += \
3263    --rollback_index $(BOARD_AVB_VBMETA_VENDOR_ROLLBACK_INDEX)
3264endif
3265
3266# $(1): the directory to extract public keys to
3267define extract-avb-chain-public-keys
3268  $(if $(BOARD_AVB_BOOT_KEY_PATH),\
3269    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_BOOT_KEY_PATH) \
3270      --output $(1)/boot.avbpubkey)
3271  $(if $(BOARD_AVB_SYSTEM_KEY_PATH),\
3272    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_SYSTEM_KEY_PATH) \
3273      --output $(1)/system.avbpubkey)
3274  $(if $(BOARD_AVB_VENDOR_KEY_PATH),\
3275    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VENDOR_KEY_PATH) \
3276      --output $(1)/vendor.avbpubkey)
3277  $(if $(BOARD_AVB_PRODUCT_KEY_PATH),\
3278    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_PRODUCT_KEY_PATH) \
3279      --output $(1)/product.avbpubkey)
3280  $(if $(BOARD_AVB_PRODUCT_SERVICES_KEY_PATH),\
3281    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_PRODUCT_SERVICES_KEY_PATH) \
3282      --output $(1)/product_services.avbpubkey)
3283  $(if $(BOARD_AVB_ODM_KEY_PATH),\
3284    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_ODM_KEY_PATH) \
3285      --output $(1)/odm.avbpubkey)
3286  $(if $(BOARD_AVB_DTBO_KEY_PATH),\
3287    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_DTBO_KEY_PATH) \
3288      --output $(1)/dtbo.avbpubkey)
3289  $(if $(BOARD_AVB_RECOVERY_KEY_PATH),\
3290    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_RECOVERY_KEY_PATH) \
3291      --output $(1)/recovery.avbpubkey)
3292  $(if $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH),\
3293    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH) \
3294        --output $(1)/vbmeta_system.avbpubkey)
3295  $(if $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH),\
3296    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH) \
3297        --output $(1)/vbmeta_vendor.avbpubkey)
3298endef
3299
3300# Builds a chained VBMeta image. This VBMeta image will contain the descriptors for the partitions
3301# specified in BOARD_AVB_VBMETA_<NAME>. The built VBMeta image will be included into the top-level
3302# vbmeta image as a chained partition. For example, if a target defines `BOARD_AVB_VBMETA_SYSTEM
3303# := system product_services`, `vbmeta_system.img` will be created that includes the descriptors
3304# for `system.img` and `product_services.img`. `vbmeta_system.img` itself will be included into
3305# `vbmeta.img` as a chained partition.
3306# $(1): VBMeta image name, such as "vbmeta_system", "vbmeta_vendor" etc.
3307# $(2): Output filename.
3308define build-chained-vbmeta-image
3309  $(call pretty,"Target chained vbmeta image: $@")
3310  $(hide) $(AVBTOOL) make_vbmeta_image \
3311      $(INTERNAL_AVB_$(call to-upper,$(1))_SIGNING_ARGS) \
3312      $(BOARD_AVB_MAKE_$(call to-upper,$(1))_IMAGE_ARGS) \
3313      $(foreach image,$(BOARD_AVB_$(call to-upper,$(1))), \
3314          --include_descriptors_from_image $(call images-for-partitions,$(image))) \
3315      --output $@
3316endef
3317
3318ifdef BOARD_AVB_VBMETA_SYSTEM
3319INSTALLED_VBMETA_SYSTEMIMAGE_TARGET := $(PRODUCT_OUT)/vbmeta_system.img
3320$(INSTALLED_VBMETA_SYSTEMIMAGE_TARGET): \
3321	    $(AVBTOOL) \
3322	    $(call images-for-partitions,$(BOARD_AVB_VBMETA_SYSTEM)) \
3323	    $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH)
3324	$(call build-chained-vbmeta-image,vbmeta_system)
3325endif
3326
3327ifdef BOARD_AVB_VBMETA_VENDOR
3328INSTALLED_VBMETA_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vbmeta_vendor.img
3329$(INSTALLED_VBMETA_VENDORIMAGE_TARGET): \
3330	    $(AVBTOOL) \
3331	    $(call images-for-partitions,$(BOARD_AVB_VBMETA_VENDOR)) \
3332	    $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH)
3333	$(call build-chained-vbmeta-image,vbmeta_vendor)
3334endif
3335
3336define build-vbmetaimage-target
3337  $(call pretty,"Target vbmeta image: $(INSTALLED_VBMETAIMAGE_TARGET)")
3338  $(hide) mkdir -p $(AVB_CHAIN_KEY_DIR)
3339  $(call extract-avb-chain-public-keys, $(AVB_CHAIN_KEY_DIR))
3340  $(hide) $(AVBTOOL) make_vbmeta_image \
3341    $(INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS) \
3342    $(PRIVATE_AVB_VBMETA_SIGNING_ARGS) \
3343    $(BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS) \
3344    --output $@
3345  $(hide) rm -rf $(AVB_CHAIN_KEY_DIR)
3346endef
3347
3348INSTALLED_VBMETAIMAGE_TARGET := $(BUILT_VBMETAIMAGE_TARGET)
3349$(INSTALLED_VBMETAIMAGE_TARGET): PRIVATE_AVB_VBMETA_SIGNING_ARGS := \
3350    --algorithm $(BOARD_AVB_ALGORITHM) --key $(BOARD_AVB_KEY_PATH)
3351
3352$(INSTALLED_VBMETAIMAGE_TARGET): \
3353	    $(AVBTOOL) \
3354	    $(INSTALLED_BOOTIMAGE_TARGET) \
3355	    $(INSTALLED_SYSTEMIMAGE_TARGET) \
3356	    $(INSTALLED_VENDORIMAGE_TARGET) \
3357	    $(INSTALLED_PRODUCTIMAGE_TARGET) \
3358	    $(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET) \
3359	    $(INSTALLED_ODMIMAGE_TARGET) \
3360	    $(INSTALLED_DTBOIMAGE_TARGET) \
3361	    $(INSTALLED_RECOVERYIMAGE_TARGET) \
3362	    $(INSTALLED_VBMETA_SYSTEMIMAGE_TARGET) \
3363	    $(INSTALLED_VBMETA_VENDORIMAGE_TARGET) \
3364	    $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH) \
3365	    $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH) \
3366	    $(BOARD_AVB_KEY_PATH)
3367	$(build-vbmetaimage-target)
3368
3369.PHONY: vbmetaimage-nodeps
3370vbmetaimage-nodeps:
3371	$(build-vbmetaimage-target)
3372
3373endif # BOARD_AVB_ENABLE
3374
3375# -----------------------------------------------------------------
3376# Check image sizes <= size of super partition
3377
3378ifeq (,$(TARGET_BUILD_APPS))
3379# Do not check for apps-only build
3380
3381ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
3382
3383# (1): list of items like "system", "vendor", "product", "product_services"
3384# return: map each item into a command ( wrapped in $$() ) that reads the size
3385define read-size-of-partitions
3386$(foreach image,$(call images-for-partitions,$(1)),$$( \
3387    build/make/tools/releasetools/sparse_img.py --get_partition_size $(image)))
3388endef
3389
3390# round result to BOARD_SUPER_PARTITION_ALIGNMENT
3391#$(1): the calculated size
3392ifeq (,$(BOARD_SUPER_PARTITION_ALIGNMENT))
3393define round-partition-size
3394$(1)
3395endef
3396else
3397define round-partition-size
3398$$((($(1)+$(BOARD_SUPER_PARTITION_ALIGNMENT)-1)/$(BOARD_SUPER_PARTITION_ALIGNMENT)*$(BOARD_SUPER_PARTITION_ALIGNMENT)))
3399endef
3400endif
3401
3402define super-slot-suffix
3403$(if $(filter true,$(AB_OTA_UPDATER)),$(if $(filter true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)),,_a))
3404endef
3405
3406droid_targets: check-all-partition-sizes
3407
3408.PHONY: check-all-partition-sizes check-all-partition-sizes-nodeps
3409
3410# Add image dependencies so that generated_*_image_info.txt are written before checking.
3411check-all-partition-sizes: \
3412    build/make/tools/releasetools/sparse_img.py \
3413    $(call images-for-partitions,$(BOARD_SUPER_PARTITION_PARTITION_LIST))
3414
3415ifeq ($(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS),true)
3416# Check sum(super partition block devices) == super partition
3417# Non-retrofit devices already defines BOARD_SUPER_PARTITION_SUPER_DEVICE_SIZE = BOARD_SUPER_PARTITION_SIZE
3418define check-super-partition-size
3419  size_list="$(foreach device,$(call to-upper,$(BOARD_SUPER_PARTITION_BLOCK_DEVICES)),$(BOARD_SUPER_PARTITION_$(device)_DEVICE_SIZE))"; \
3420  sum_sizes_expr=$$(sed -e 's/ /+/g' <<< "$${size_list}"); \
3421  max_size_expr="$(BOARD_SUPER_PARTITION_SIZE)"; \
3422  if [ $$(( $${sum_sizes_expr} )) -ne $$(( $${max_size_expr} )) ]; then \
3423    echo "The sum of super partition block device sizes is not equal to BOARD_SUPER_PARTITION_SIZE:"; \
3424    echo $${sum_sizes_expr} '!=' $${max_size_expr}; \
3425    exit 1; \
3426  else \
3427    echo "The sum of super partition block device sizes is equal to BOARD_SUPER_PARTITION_SIZE:"; \
3428    echo $${sum_sizes_expr} '==' $${max_size_expr}; \
3429  fi
3430endef
3431endif
3432
3433# $(1): human-readable max size string
3434# $(2): max size expression
3435# $(3): list of partition names
3436define check-sum-of-partition-sizes
3437  partition_size_list="$$(for i in $(call read-size-of-partitions,$(3)); do \
3438    echo $(call round-partition-size,$${i}); \
3439  done)"; \
3440  sum_sizes_expr=$$(tr '\n' '+' <<< "$${partition_size_list}" | sed 's/+$$//'); \
3441  if [ $$(( $${sum_sizes_expr} )) -gt $$(( $(2) )) ]; then \
3442    echo "The sum of sizes of [$(strip $(3))] is larger than $(strip $(1)):"; \
3443    echo $${sum_sizes_expr} '==' $$(( $${sum_sizes_expr} )) '>' "$(2)" '==' $$(( $(2) )); \
3444    exit 1; \
3445  else \
3446    echo "The sum of sizes of [$(strip $(3))] is within $(strip $(1)):"; \
3447    echo $${sum_sizes_expr} '==' $$(( $${sum_sizes_expr} )) '<=' "$(2)" '==' $$(( $(2) )); \
3448  fi;
3449endef
3450
3451define check-all-partition-sizes-target
3452  # Check sum(all partitions) <= super partition (/ 2 for A/B devices launched with dynamic partitions)
3453  $(if $(BOARD_SUPER_PARTITION_SIZE),$(if $(BOARD_SUPER_PARTITION_PARTITION_LIST), \
3454    $(call check-sum-of-partition-sizes,BOARD_SUPER_PARTITION_SIZE$(if $(call super-slot-suffix), / 2), \
3455      $(BOARD_SUPER_PARTITION_SIZE)$(if $(call super-slot-suffix), / 2),$(BOARD_SUPER_PARTITION_PARTITION_LIST))))
3456
3457  # For each group, check sum(partitions in group) <= group size
3458  $(foreach group,$(call to-upper,$(BOARD_SUPER_PARTITION_GROUPS)), \
3459    $(if $(BOARD_$(group)_SIZE),$(if $(BOARD_$(group)_PARTITION_LIST), \
3460      $(call check-sum-of-partition-sizes,BOARD_$(group)_SIZE,$(BOARD_$(group)_SIZE),$(BOARD_$(group)_PARTITION_LIST)))))
3461
3462  # Check sum(all group sizes) <= super partition (/ 2 for A/B devices launched with dynamic partitions)
3463  if [[ ! -z $(BOARD_SUPER_PARTITION_SIZE) ]]; then \
3464    group_size_list="$(foreach group,$(call to-upper,$(BOARD_SUPER_PARTITION_GROUPS)),$(BOARD_$(group)_SIZE))"; \
3465    sum_sizes_expr=$$(sed -e 's/ /+/g' <<< "$${group_size_list}"); \
3466    max_size_tail=$(if $(call super-slot-suffix)," / 2"); \
3467    max_size_expr="$(BOARD_SUPER_PARTITION_SIZE)$${max_size_tail}"; \
3468    if [ $$(( $${sum_sizes_expr} )) -gt $$(( $${max_size_expr} )) ]; then \
3469      echo "The sum of sizes of [$(strip $(BOARD_SUPER_PARTITION_GROUPS))] is larger than BOARD_SUPER_PARTITION_SIZE$${max_size_tail}:"; \
3470      echo $${sum_sizes_expr} '==' $$(( $${sum_sizes_expr} )) '>' $${max_size_expr} '==' $$(( $${max_size_expr} )); \
3471      exit 1; \
3472    else \
3473      echo "The sum of sizes of [$(strip $(BOARD_SUPER_PARTITION_GROUPS))] is within BOARD_SUPER_PARTITION_SIZE$${max_size_tail}:"; \
3474      echo $${sum_sizes_expr} '==' $$(( $${sum_sizes_expr} )) '<=' $${max_size_expr} '==' $$(( $${max_size_expr} )); \
3475    fi \
3476  fi
3477endef
3478
3479check-all-partition-sizes check-all-partition-sizes-nodeps:
3480	$(call check-all-partition-sizes-target)
3481	$(call check-super-partition-size)
3482
3483endif # PRODUCT_BUILD_SUPER_PARTITION
3484
3485endif # TARGET_BUILD_APPS
3486
3487# -----------------------------------------------------------------
3488# bring in the installer image generation defines if necessary
3489ifeq ($(TARGET_USE_DISKINSTALLER),true)
3490include bootable/diskinstaller/config.mk
3491endif
3492
3493# -----------------------------------------------------------------
3494# host tools needed to build dist and OTA packages
3495
3496ifeq ($(BUILD_OS),darwin)
3497  build_ota_package := false
3498  build_otatools_package := false
3499else
3500  # set build_ota_package, and allow opt-out below
3501  build_ota_package := true
3502  ifeq ($(TARGET_SKIP_OTA_PACKAGE),true)
3503    build_ota_package := false
3504  endif
3505  ifneq (,$(filter address, $(SANITIZE_TARGET)))
3506    build_ota_package := false
3507  endif
3508  ifeq ($(TARGET_PRODUCT),sdk)
3509    build_ota_package := false
3510  endif
3511  ifneq ($(filter generic%,$(TARGET_DEVICE)),)
3512    build_ota_package := false
3513  endif
3514  ifeq ($(TARGET_NO_KERNEL),true)
3515    build_ota_package := false
3516  endif
3517  ifeq ($(recovery_fstab),)
3518    build_ota_package := false
3519  endif
3520  ifeq ($(TARGET_BUILD_PDK),true)
3521    build_ota_package := false
3522  endif
3523
3524  # set build_otatools_package, and allow opt-out below
3525  build_otatools_package := true
3526  ifeq ($(TARGET_SKIP_OTATOOLS_PACKAGE),true)
3527    build_otatools_package := false
3528  endif
3529endif
3530
3531ifeq ($(build_otatools_package),true)
3532OTATOOLS :=  $(HOST_OUT_EXECUTABLES)/minigzip \
3533  $(HOST_OUT_EXECUTABLES)/aapt \
3534  $(HOST_OUT_EXECUTABLES)/checkvintf \
3535  $(HOST_OUT_EXECUTABLES)/mkbootfs \
3536  $(HOST_OUT_EXECUTABLES)/mkbootimg \
3537  $(HOST_OUT_EXECUTABLES)/fs_config \
3538  $(HOST_OUT_EXECUTABLES)/zipalign \
3539  $(HOST_OUT_EXECUTABLES)/bsdiff \
3540  $(HOST_OUT_EXECUTABLES)/imgdiff \
3541  $(HOST_OUT_JAVA_LIBRARIES)/signapk.jar \
3542  $(HOST_OUT_JAVA_LIBRARIES)/BootSignature.jar \
3543  $(HOST_OUT_JAVA_LIBRARIES)/VeritySigner.jar \
3544  $(HOST_OUT_EXECUTABLES)/mke2fs \
3545  $(HOST_OUT_EXECUTABLES)/mkuserimg_mke2fs \
3546  $(HOST_OUT_EXECUTABLES)/e2fsdroid \
3547  $(HOST_OUT_EXECUTABLES)/tune2fs \
3548  $(HOST_OUT_EXECUTABLES)/mksquashfsimage.sh \
3549  $(HOST_OUT_EXECUTABLES)/mksquashfs \
3550  $(HOST_OUT_EXECUTABLES)/mkf2fsuserimg.sh \
3551  $(HOST_OUT_EXECUTABLES)/make_f2fs \
3552  $(HOST_OUT_EXECUTABLES)/sload_f2fs \
3553  $(HOST_OUT_EXECUTABLES)/simg2img \
3554  $(HOST_OUT_EXECUTABLES)/e2fsck \
3555  $(HOST_OUT_EXECUTABLES)/generate_verity_key \
3556  $(HOST_OUT_EXECUTABLES)/verity_signer \
3557  $(HOST_OUT_EXECUTABLES)/verity_verifier \
3558  $(HOST_OUT_EXECUTABLES)/append2simg \
3559  $(HOST_OUT_EXECUTABLES)/img2simg \
3560  $(HOST_OUT_EXECUTABLES)/boot_signer \
3561  $(HOST_OUT_EXECUTABLES)/fec \
3562  $(HOST_OUT_EXECUTABLES)/brillo_update_payload \
3563  $(HOST_OUT_EXECUTABLES)/lib/shflags/shflags \
3564  $(HOST_OUT_EXECUTABLES)/delta_generator \
3565  $(HOST_OUT_EXECUTABLES)/care_map_generator \
3566  $(HOST_OUT_EXECUTABLES)/fc_sort \
3567  $(HOST_OUT_EXECUTABLES)/sefcontext_compile \
3568  $(LPMAKE) \
3569  $(AVBTOOL) \
3570  $(BLK_ALLOC_TO_BASE_FS) \
3571  $(BROTLI) \
3572  $(BUILD_VERITY_METADATA) \
3573  $(BUILD_VERITY_TREE)
3574
3575ifeq (true,$(PRODUCT_SUPPORTS_VBOOT))
3576OTATOOLS += \
3577  $(FUTILITY) \
3578  $(VBOOT_SIGNER)
3579endif
3580
3581# Shared libraries.
3582OTATOOLS += \
3583  $(HOST_LIBRARY_PATH)/libc++$(HOST_SHLIB_SUFFIX) \
3584  $(HOST_LIBRARY_PATH)/liblog$(HOST_SHLIB_SUFFIX) \
3585  $(HOST_LIBRARY_PATH)/libcutils$(HOST_SHLIB_SUFFIX) \
3586  $(HOST_LIBRARY_PATH)/libselinux$(HOST_SHLIB_SUFFIX) \
3587  $(HOST_LIBRARY_PATH)/libcrypto_utils$(HOST_SHLIB_SUFFIX) \
3588  $(HOST_LIBRARY_PATH)/libcrypto-host$(HOST_SHLIB_SUFFIX) \
3589  $(HOST_LIBRARY_PATH)/libext2fs-host$(HOST_SHLIB_SUFFIX) \
3590  $(HOST_LIBRARY_PATH)/libext2_blkid-host$(HOST_SHLIB_SUFFIX) \
3591  $(HOST_LIBRARY_PATH)/libext2_com_err-host$(HOST_SHLIB_SUFFIX) \
3592  $(HOST_LIBRARY_PATH)/libext2_e2p-host$(HOST_SHLIB_SUFFIX) \
3593  $(HOST_LIBRARY_PATH)/libext2_misc$(HOST_SHLIB_SUFFIX) \
3594  $(HOST_LIBRARY_PATH)/libext2_profile-host$(HOST_SHLIB_SUFFIX) \
3595  $(HOST_LIBRARY_PATH)/libext2_quota-host$(HOST_SHLIB_SUFFIX) \
3596  $(HOST_LIBRARY_PATH)/libext2_uuid-host$(HOST_SHLIB_SUFFIX) \
3597  $(HOST_LIBRARY_PATH)/libconscrypt_openjdk_jni$(HOST_SHLIB_SUFFIX) \
3598  $(HOST_LIBRARY_PATH)/libbrillo$(HOST_SHLIB_SUFFIX) \
3599  $(HOST_LIBRARY_PATH)/libbrillo-stream$(HOST_SHLIB_SUFFIX) \
3600  $(HOST_LIBRARY_PATH)/libchrome$(HOST_SHLIB_SUFFIX) \
3601  $(HOST_LIBRARY_PATH)/libcurl-host$(HOST_SHLIB_SUFFIX) \
3602  $(HOST_LIBRARY_PATH)/libevent-host$(HOST_SHLIB_SUFFIX) \
3603  $(HOST_LIBRARY_PATH)/libprotobuf-cpp-lite$(HOST_SHLIB_SUFFIX) \
3604  $(HOST_LIBRARY_PATH)/libssl-host$(HOST_SHLIB_SUFFIX) \
3605  $(HOST_LIBRARY_PATH)/libz-host$(HOST_SHLIB_SUFFIX) \
3606  $(HOST_LIBRARY_PATH)/libsparse-host$(HOST_SHLIB_SUFFIX) \
3607  $(HOST_LIBRARY_PATH)/libbase$(HOST_SHLIB_SUFFIX) \
3608  $(HOST_LIBRARY_PATH)/libpcre2$(HOST_SHLIB_SUFFIX) \
3609  $(HOST_LIBRARY_PATH)/libbrotli$(HOST_SHLIB_SUFFIX) \
3610  $(HOST_LIBRARY_PATH)/liblp$(HOST_SHLIB_SUFFIX) \
3611  $(HOST_LIBRARY_PATH)/libext4_utils$(HOST_SHLIB_SUFFIX) \
3612  $(HOST_LIBRARY_PATH)/libfec$(HOST_SHLIB_SUFFIX) \
3613  $(HOST_LIBRARY_PATH)/libsquashfs_utils$(HOST_SHLIB_SUFFIX)
3614
3615
3616.PHONY: otatools
3617otatools: $(OTATOOLS)
3618
3619BUILT_OTATOOLS_PACKAGE := $(PRODUCT_OUT)/otatools.zip
3620$(BUILT_OTATOOLS_PACKAGE): zip_root := $(call intermediates-dir-for,PACKAGING,otatools)/otatools
3621
3622OTATOOLS_DEPS := \
3623  system/extras/ext4_utils/mke2fs.conf \
3624  $(sort $(shell find build/target/product/security -type f -name "*.x509.pem" -o -name "*.pk8" -o \
3625      -name verity_key))
3626
3627ifneq (,$(wildcard device))
3628OTATOOLS_DEPS += \
3629  $(sort $(shell find device $(wildcard vendor) -type f -name "*.pk8" -o -name "verifiedboot*" -o \
3630      -name "*.x509.pem" -o -name "oem*.prop"))
3631endif
3632ifneq (,$(wildcard external/avb))
3633OTATOOLS_DEPS += \
3634  $(sort $(shell find external/avb/test/data -type f -name "testkey_*.pem" -o \
3635      -name "atx_metadata.bin"))
3636endif
3637ifneq (,$(wildcard system/update_engine))
3638OTATOOLS_DEPS += \
3639  $(sort $(shell find system/update_engine/scripts -name "*.pyc" -prune -o -type f -print))
3640endif
3641
3642OTATOOLS_RELEASETOOLS := \
3643  $(sort $(shell find build/make/tools/releasetools -name "*.pyc" -prune -o -type f))
3644
3645ifeq (true,$(PRODUCT_SUPPORTS_VBOOT))
3646OTATOOLS_DEPS += \
3647  $(sort $(shell find external/vboot_reference/tests/devkeys -type f))
3648endif
3649
3650$(BUILT_OTATOOLS_PACKAGE): $(OTATOOLS) $(OTATOOLS_DEPS) $(OTATOOLS_RELEASETOOLS) $(SOONG_ZIP)
3651	@echo "Package OTA tools: $@"
3652	$(hide) rm -rf $@ $(zip_root)
3653	$(hide) mkdir -p $(dir $@) $(zip_root)/bin $(zip_root)/framework $(zip_root)/releasetools
3654	$(call copy-files-with-structure,$(OTATOOLS),$(HOST_OUT)/,$(zip_root))
3655	$(hide) cp $(SOONG_ZIP) $(zip_root)/bin/
3656	$(hide) cp -r -d -p build/make/tools/releasetools/* $(zip_root)/releasetools
3657	$(hide) rm -rf $@ $(zip_root)/releasetools/*.pyc
3658	$(hide) $(SOONG_ZIP) -o $@ -C $(zip_root) -D $(zip_root) \
3659	  -C . $(addprefix -f ,$(OTATOOLS_DEPS))
3660
3661.PHONY: otatools-package
3662otatools-package: $(BUILT_OTATOOLS_PACKAGE)
3663
3664endif # build_otatools_package
3665
3666# -----------------------------------------------------------------
3667# A zip of the directories that map to the target filesystem.
3668# This zip can be used to create an OTA package or filesystem image
3669# as a post-build step.
3670#
3671name := $(TARGET_PRODUCT)
3672ifeq ($(TARGET_BUILD_TYPE),debug)
3673  name := $(name)_debug
3674endif
3675name := $(name)-target_files-$(FILE_NAME_TAG)
3676
3677intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
3678BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
3679$(BUILT_TARGET_FILES_PACKAGE): intermediates := $(intermediates)
3680$(BUILT_TARGET_FILES_PACKAGE): \
3681	    zip_root := $(intermediates)/$(name)
3682
3683# $(1): Directory to copy
3684# $(2): Location to copy it to
3685# The "ls -A" is to prevent "acp s/* d" from failing if s is empty.
3686define package_files-copy-root
3687  if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
3688    mkdir -p $(2) && \
3689    $(ACP) -rd $(strip $(1))/* $(2); \
3690  fi
3691endef
3692
3693built_ota_tools :=
3694
3695# We can't build static executables when SANITIZE_TARGET=address
3696ifeq (,$(filter address, $(SANITIZE_TARGET)))
3697built_ota_tools += \
3698    $(call intermediates-dir-for,EXECUTABLES,updater,,,$(TARGET_PREFER_32_BIT))/updater
3699endif
3700
3701$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_OTA_TOOLS := $(built_ota_tools)
3702
3703$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_API_VERSION := $(RECOVERY_API_VERSION)
3704$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_FSTAB_VERSION := $(RECOVERY_FSTAB_VERSION)
3705
3706ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
3707# default to common dir for device vendor
3708tool_extensions := $(TARGET_DEVICE_DIR)/../common
3709else
3710tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
3711endif
3712tool_extension := $(wildcard $(tool_extensions)/releasetools.py)
3713$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_TOOL_EXTENSIONS := $(tool_extensions)
3714$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_TOOL_EXTENSION := $(tool_extension)
3715
3716ifeq ($(AB_OTA_UPDATER),true)
3717updater_dep := system/update_engine/update_engine.conf
3718else
3719# Build OTA tools if not using the AB Updater.
3720updater_dep := $(built_ota_tools)
3721endif
3722$(BUILT_TARGET_FILES_PACKAGE): $(updater_dep)
3723
3724# If we are using recovery as boot, output recovery files to BOOT/.
3725ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
3726$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := BOOT
3727else
3728$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := RECOVERY
3729endif
3730
3731ifeq ($(AB_OTA_UPDATER),true)
3732  ifdef OSRELEASED_DIRECTORY
3733    $(BUILT_TARGET_FILES_PACKAGE): $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_id
3734    $(BUILT_TARGET_FILES_PACKAGE): $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_version
3735    $(BUILT_TARGET_FILES_PACKAGE): $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/system_version
3736  endif
3737endif
3738
3739# Run fs_config while creating the target files package
3740# $1: root directory
3741# $2: add prefix
3742define fs_config
3743(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) -R "$(2)"
3744endef
3745
3746# $(1): file
3747define dump-dynamic-partitions-info
3748  $(if $(filter true,$(PRODUCT_USE_DYNAMIC_PARTITIONS)), \
3749    echo "use_dynamic_partitions=true" >> $(1))
3750  $(if $(filter true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)), \
3751    echo "dynamic_partition_retrofit=true" >> $(1))
3752  echo "lpmake=$(notdir $(LPMAKE))" >> $(1)
3753  $(if $(filter true,$(PRODUCT_BUILD_SUPER_PARTITION)), $(if $(BOARD_SUPER_PARTITION_SIZE), \
3754    echo "build_super_partition=true" >> $(1)))
3755  $(if $(filter true,$(BOARD_BUILD_RETROFIT_DYNAMIC_PARTITIONS_OTA_PACKAGE)), \
3756    echo "build_retrofit_dynamic_partitions_ota_package=true" >> $(1))
3757  echo "super_metadata_device=$(BOARD_SUPER_PARTITION_METADATA_DEVICE)" >> $(1)
3758  $(if $(BOARD_SUPER_PARTITION_BLOCK_DEVICES), \
3759    echo "super_block_devices=$(BOARD_SUPER_PARTITION_BLOCK_DEVICES)" >> $(1))
3760  $(foreach device,$(BOARD_SUPER_PARTITION_BLOCK_DEVICES), \
3761    echo "super_$(device)_device_size=$(BOARD_SUPER_PARTITION_$(call to-upper,$(device))_DEVICE_SIZE)" >> $(1);)
3762  $(if $(BOARD_SUPER_PARTITION_PARTITION_LIST), \
3763    echo "dynamic_partition_list=$(BOARD_SUPER_PARTITION_PARTITION_LIST)" >> $(1))
3764  $(if $(BOARD_SUPER_PARTITION_GROUPS),
3765    echo "super_partition_groups=$(BOARD_SUPER_PARTITION_GROUPS)" >> $(1))
3766  $(foreach group,$(BOARD_SUPER_PARTITION_GROUPS), \
3767    echo "super_$(group)_group_size=$(BOARD_$(call to-upper,$(group))_SIZE)" >> $(1); \
3768    $(if $(BOARD_$(call to-upper,$(group))_PARTITION_LIST), \
3769      echo "super_$(group)_partition_list=$(BOARD_$(call to-upper,$(group))_PARTITION_LIST)" >> $(1);))
3770  $(if $(filter true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED)), \
3771    echo "build_non_sparse_super_partition=true" >> $(1))
3772  $(if $(filter true,$(BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE)), \
3773    echo "super_image_in_update_package=true" >> $(1))
3774endef
3775
3776# Depending on the various images guarantees that the underlying
3777# directories are up-to-date.
3778$(BUILT_TARGET_FILES_PACKAGE): \
3779	    $(INSTALLED_RAMDISK_TARGET) \
3780	    $(INSTALLED_BOOTIMAGE_TARGET) \
3781	    $(INSTALLED_RADIOIMAGE_TARGET) \
3782	    $(INSTALLED_RECOVERYIMAGE_TARGET) \
3783	    $(FULL_SYSTEMIMAGE_DEPS) \
3784	    $(INSTALLED_USERDATAIMAGE_TARGET) \
3785	    $(INSTALLED_CACHEIMAGE_TARGET) \
3786	    $(INSTALLED_VENDORIMAGE_TARGET) \
3787	    $(INSTALLED_PRODUCTIMAGE_TARGET) \
3788	    $(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET) \
3789	    $(INSTALLED_VBMETAIMAGE_TARGET) \
3790	    $(INSTALLED_ODMIMAGE_TARGET) \
3791	    $(INSTALLED_DTBOIMAGE_TARGET) \
3792	    $(INTERNAL_SYSTEMOTHERIMAGE_FILES) \
3793	    $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
3794	    $(INSTALLED_KERNEL_TARGET) \
3795	    $(INSTALLED_DTBIMAGE_TARGET) \
3796	    $(INSTALLED_2NDBOOTLOADER_TARGET) \
3797	    $(BOARD_PREBUILT_DTBOIMAGE) \
3798	    $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE) \
3799	    $(BOARD_RECOVERY_ACPIO) \
3800	    $(PRODUCT_SYSTEM_BASE_FS_PATH) \
3801	    $(PRODUCT_VENDOR_BASE_FS_PATH) \
3802	    $(PRODUCT_PRODUCT_BASE_FS_PATH) \
3803	    $(PRODUCT_PRODUCT_SERVICES_BASE_FS_PATH) \
3804	    $(PRODUCT_ODM_BASE_FS_PATH) \
3805	    $(LPMAKE) \
3806	    $(SELINUX_FC) \
3807	    $(APKCERTS_FILE) \
3808	    $(SOONG_APEX_KEYS_FILE) \
3809	    $(SOONG_ZIP) \
3810	    $(HOST_OUT_EXECUTABLES)/fs_config \
3811	    $(HOST_OUT_EXECUTABLES)/imgdiff \
3812	    $(HOST_OUT_EXECUTABLES)/bsdiff \
3813	    $(HOST_OUT_EXECUTABLES)/care_map_generator \
3814	    $(BUILD_IMAGE_SRCS) \
3815	    $(BUILT_ASSEMBLED_FRAMEWORK_MANIFEST) \
3816	    $(BUILT_ASSEMBLED_VENDOR_MANIFEST) \
3817	    $(BUILT_SYSTEM_MATRIX) \
3818	    $(BUILT_VENDOR_MATRIX) \
3819	    | $(ACP)
3820	@echo "Package target files: $@"
3821	$(call create-system-vendor-symlink)
3822	$(call create-system-product-symlink)
3823	$(call create-system-product_services-symlink)
3824	$(call create-vendor-odm-symlink)
3825	$(hide) rm -rf $@ $@.list $(zip_root)
3826	$(hide) mkdir -p $(dir $@) $(zip_root)
3827ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)))
3828	@# Components of the recovery image
3829	$(hide) mkdir -p $(zip_root)/$(PRIVATE_RECOVERY_OUT)
3830	$(hide) $(call package_files-copy-root, \
3831	    $(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/$(PRIVATE_RECOVERY_OUT)/RAMDISK)
3832ifdef INSTALLED_KERNEL_TARGET
3833	$(hide) cp $(INSTALLED_KERNEL_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/kernel
3834endif
3835ifdef INSTALLED_2NDBOOTLOADER_TARGET
3836	$(hide) cp $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/second
3837endif
3838ifdef BOARD_INCLUDE_RECOVERY_DTBO
3839ifdef BOARD_PREBUILT_RECOVERY_DTBOIMAGE
3840	$(hide) cp $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/recovery_dtbo
3841else
3842	$(hide) cp $(BOARD_PREBUILT_DTBOIMAGE) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/recovery_dtbo
3843endif
3844endif
3845ifdef BOARD_INCLUDE_RECOVERY_ACPIO
3846	$(hide) cp $(BOARD_RECOVERY_ACPIO) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/recovery_acpio
3847endif
3848ifdef INSTALLED_DTBIMAGE_TARGET
3849	$(hide) cp $(INSTALLED_DTBIMAGE_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/dtb
3850endif
3851ifdef INTERNAL_KERNEL_CMDLINE
3852	$(hide) echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/cmdline
3853endif
3854ifdef BOARD_KERNEL_BASE
3855	$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/base
3856endif
3857ifdef BOARD_KERNEL_PAGESIZE
3858	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/pagesize
3859endif
3860endif # INSTALLED_RECOVERYIMAGE_TARGET defined or BOARD_USES_RECOVERY_AS_BOOT is true
3861	@# Components of the boot image
3862	$(hide) mkdir -p $(zip_root)/BOOT
3863	$(hide) mkdir -p $(zip_root)/ROOT
3864	$(hide) $(call package_files-copy-root, \
3865	    $(TARGET_ROOT_OUT),$(zip_root)/ROOT)
3866	@# If we are using recovery as boot, this is already done when processing recovery.
3867ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
3868ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
3869	$(hide) $(call package_files-copy-root, \
3870	    $(TARGET_RAMDISK_OUT),$(zip_root)/BOOT/RAMDISK)
3871endif
3872ifdef INSTALLED_KERNEL_TARGET
3873	$(hide) cp $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/kernel
3874endif
3875ifdef INSTALLED_2NDBOOTLOADER_TARGET
3876	$(hide) cp $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second
3877endif
3878ifdef INSTALLED_DTBIMAGE_TARGET
3879	$(hide) cp $(INSTALLED_DTBIMAGE_TARGET) $(zip_root)/BOOT/dtb
3880endif
3881ifdef INTERNAL_KERNEL_CMDLINE
3882	$(hide) echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
3883endif
3884ifdef BOARD_KERNEL_BASE
3885	$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base
3886endif
3887ifdef BOARD_KERNEL_PAGESIZE
3888	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesize
3889endif
3890endif # BOARD_USES_RECOVERY_AS_BOOT
3891	$(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\
3892	            mkdir -p $(zip_root)/RADIO; \
3893	            cp $(t) $(zip_root)/RADIO/$(notdir $(t));)
3894ifdef BUILDING_SYSTEM_IMAGE
3895	@# Contents of the system image
3896	$(hide) $(call package_files-copy-root, \
3897	    $(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
3898endif
3899ifdef BUILDING_USERDATA_IMAGE
3900	@# Contents of the data image
3901	$(hide) $(call package_files-copy-root, \
3902	    $(TARGET_OUT_DATA),$(zip_root)/DATA)
3903endif
3904ifdef BUILDING_VENDOR_IMAGE
3905	@# Contents of the vendor image
3906	$(hide) $(call package_files-copy-root, \
3907	    $(TARGET_OUT_VENDOR),$(zip_root)/VENDOR)
3908endif
3909ifdef BUILDING_PRODUCT_IMAGE
3910	@# Contents of the product image
3911	$(hide) $(call package_files-copy-root, \
3912	    $(TARGET_OUT_PRODUCT),$(zip_root)/PRODUCT)
3913endif
3914ifdef BUILDING_PRODUCT_SERVICES_IMAGE
3915	@# Contents of the product_services image
3916	$(hide) $(call package_files-copy-root, \
3917	    $(TARGET_OUT_PRODUCT_SERVICES),$(zip_root)/PRODUCT_SERVICES)
3918endif
3919ifdef BUILDING_ODM_IMAGE
3920	@# Contents of the odm image
3921	$(hide) $(call package_files-copy-root, \
3922	    $(TARGET_OUT_ODM),$(zip_root)/ODM)
3923endif
3924ifdef BUILDING_SYSTEM_OTHER_IMAGE
3925	@# Contents of the system_other image
3926	$(hide) $(call package_files-copy-root, \
3927	    $(TARGET_OUT_SYSTEM_OTHER),$(zip_root)/SYSTEM_OTHER)
3928endif
3929	@# Extra contents of the OTA package
3930	$(hide) mkdir -p $(zip_root)/OTA
3931	$(hide) cp $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/
3932ifneq ($(AB_OTA_UPDATER),true)
3933ifneq ($(built_ota_tools),)
3934	$(hide) mkdir -p $(zip_root)/OTA/bin
3935	$(hide) cp $(PRIVATE_OTA_TOOLS) $(zip_root)/OTA/bin/
3936endif
3937endif
3938	@# Files that do not end up in any images, but are necessary to
3939	@# build them.
3940	$(hide) mkdir -p $(zip_root)/META
3941	$(hide) cp $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
3942	$(hide) cp $(SOONG_APEX_KEYS_FILE) $(zip_root)/META/apexkeys.txt
3943ifneq ($(tool_extension),)
3944	$(hide) cp $(PRIVATE_TOOL_EXTENSION) $(zip_root)/META/
3945endif
3946	$(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
3947	$(hide) cp $(SELINUX_FC) $(zip_root)/META/file_contexts.bin
3948	$(hide) echo "recovery_api_version=$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/misc_info.txt
3949	$(hide) echo "fstab_version=$(PRIVATE_RECOVERY_FSTAB_VERSION)" >> $(zip_root)/META/misc_info.txt
3950ifdef BOARD_FLASH_BLOCK_SIZE
3951	$(hide) echo "blocksize=$(BOARD_FLASH_BLOCK_SIZE)" >> $(zip_root)/META/misc_info.txt
3952endif
3953ifdef BOARD_BOOTIMAGE_PARTITION_SIZE
3954	$(hide) echo "boot_size=$(BOARD_BOOTIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
3955endif
3956ifeq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
3957	$(hide) echo "no_recovery=true" >> $(zip_root)/META/misc_info.txt
3958endif
3959ifdef BOARD_INCLUDE_RECOVERY_DTBO
3960	$(hide) echo "include_recovery_dtbo=true" >> $(zip_root)/META/misc_info.txt
3961endif
3962ifdef BOARD_INCLUDE_RECOVERY_ACPIO
3963	$(hide) echo "include_recovery_acpio=true" >> $(zip_root)/META/misc_info.txt
3964endif
3965ifdef BOARD_RECOVERYIMAGE_PARTITION_SIZE
3966	$(hide) echo "recovery_size=$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
3967endif
3968ifdef TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS
3969	@# TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS can be empty to indicate that nothing but defaults should be used.
3970	$(hide) echo "recovery_mount_options=$(TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $(zip_root)/META/misc_info.txt
3971else
3972	$(hide) echo "recovery_mount_options=$(DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $(zip_root)/META/misc_info.txt
3973endif
3974	$(hide) echo "tool_extensions=$(PRIVATE_TOOL_EXTENSIONS)" >> $(zip_root)/META/misc_info.txt
3975	$(hide) echo "default_system_dev_certificate=$(DEFAULT_SYSTEM_DEV_CERTIFICATE)" >> $(zip_root)/META/misc_info.txt
3976ifdef PRODUCT_EXTRA_RECOVERY_KEYS
3977	$(hide) echo "extra_recovery_keys=$(PRODUCT_EXTRA_RECOVERY_KEYS)" >> $(zip_root)/META/misc_info.txt
3978endif
3979	$(hide) echo 'mkbootimg_args=$(BOARD_MKBOOTIMG_ARGS)' >> $(zip_root)/META/misc_info.txt
3980	$(hide) echo 'mkbootimg_version_args=$(INTERNAL_MKBOOTIMG_VERSION_ARGS)' >> $(zip_root)/META/misc_info.txt
3981	$(hide) echo "multistage_support=1" >> $(zip_root)/META/misc_info.txt
3982	$(hide) echo "blockimgdiff_versions=3,4" >> $(zip_root)/META/misc_info.txt
3983ifneq ($(OEM_THUMBPRINT_PROPERTIES),)
3984	# OTA scripts are only interested in fingerprint related properties
3985	$(hide) echo "oem_fingerprint_properties=$(OEM_THUMBPRINT_PROPERTIES)" >> $(zip_root)/META/misc_info.txt
3986endif
3987ifneq ($(PRODUCT_SYSTEM_BASE_FS_PATH),)
3988	$(hide) cp $(PRODUCT_SYSTEM_BASE_FS_PATH) \
3989	  $(zip_root)/META/$(notdir $(PRODUCT_SYSTEM_BASE_FS_PATH))
3990endif
3991ifneq ($(PRODUCT_VENDOR_BASE_FS_PATH),)
3992	$(hide) cp $(PRODUCT_VENDOR_BASE_FS_PATH) \
3993	  $(zip_root)/META/$(notdir $(PRODUCT_VENDOR_BASE_FS_PATH))
3994endif
3995ifneq ($(PRODUCT_PRODUCT_BASE_FS_PATH),)
3996	$(hide) cp $(PRODUCT_PRODUCT_BASE_FS_PATH) \
3997	  $(zip_root)/META/$(notdir $(PRODUCT_PRODUCT_BASE_FS_PATH))
3998endif
3999ifneq ($(PRODUCT_PRODUCT_SERVICES_BASE_FS_PATH),)
4000	$(hide) cp $(PRODUCT_PRODUCT_SERVICES_BASE_FS_PATH) \
4001	  $(zip_root)/META/$(notdir $(PRODUCT_PRODUCT_SERVICES_BASE_FS_PATH))
4002endif
4003ifneq ($(PRODUCT_ODM_BASE_FS_PATH),)
4004	$(hide) cp $(PRODUCT_ODM_BASE_FS_PATH) \
4005	  $(zip_root)/META/$(notdir $(PRODUCT_ODM_BASE_FS_PATH))
4006endif
4007ifneq (,$(filter address, $(SANITIZE_TARGET)))
4008	# We need to create userdata.img with real data because the instrumented libraries are in userdata.img.
4009	$(hide) echo "userdata_img_with_data=true" >> $(zip_root)/META/misc_info.txt
4010endif
4011ifeq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
4012	$(hide) echo "full_recovery_image=true" >> $(zip_root)/META/misc_info.txt
4013endif
4014ifeq ($(BOARD_AVB_ENABLE),true)
4015	$(hide) echo "avb_enable=true" >> $(zip_root)/META/misc_info.txt
4016	$(hide) echo "avb_vbmeta_key_path=$(BOARD_AVB_KEY_PATH)" >> $(zip_root)/META/misc_info.txt
4017	$(hide) echo "avb_vbmeta_algorithm=$(BOARD_AVB_ALGORITHM)" >> $(zip_root)/META/misc_info.txt
4018	$(hide) echo "avb_vbmeta_args=$(BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS)" >> $(zip_root)/META/misc_info.txt
4019	$(hide) echo "avb_boot_add_hash_footer_args=$(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)" >> $(zip_root)/META/misc_info.txt
4020ifdef BOARD_AVB_BOOT_KEY_PATH
4021	$(hide) echo "avb_boot_key_path=$(BOARD_AVB_BOOT_KEY_PATH)" >> $(zip_root)/META/misc_info.txt
4022	$(hide) echo "avb_boot_algorithm=$(BOARD_AVB_BOOT_ALGORITHM)" >> $(zip_root)/META/misc_info.txt
4023	$(hide) echo "avb_boot_rollback_index_location=$(BOARD_AVB_BOOT_ROLLBACK_INDEX_LOCATION)" >> $(zip_root)/META/misc_info.txt
4024endif # BOARD_AVB_BOOT_KEY_PATH
4025	$(hide) echo "avb_recovery_add_hash_footer_args=$(BOARD_AVB_RECOVERY_ADD_HASH_FOOTER_ARGS)" >> $(zip_root)/META/misc_info.txt
4026ifdef BOARD_AVB_RECOVERY_KEY_PATH
4027	$(hide) echo "avb_recovery_key_path=$(BOARD_AVB_RECOVERY_KEY_PATH)" >> $(zip_root)/META/misc_info.txt
4028	$(hide) echo "avb_recovery_algorithm=$(BOARD_AVB_RECOVERY_ALGORITHM)" >> $(zip_root)/META/misc_info.txt
4029	$(hide) echo "avb_recovery_rollback_index_location=$(BOARD_AVB_RECOVERY_ROLLBACK_INDEX_LOCATION)" >> $(zip_root)/META/misc_info.txt
4030endif # BOARD_AVB_RECOVERY_KEY_PATH
4031ifneq (,$(strip $(BOARD_AVB_VBMETA_SYSTEM)))
4032	$(hide) echo "avb_vbmeta_system=$(BOARD_AVB_VBMETA_SYSTEM)" >> $(zip_root)/META/misc_info.txt
4033	$(hide) echo "avb_vbmeta_system_args=$(BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS)" >> $(zip_root)/META/misc_info.txt
4034	$(hide) echo "avb_vbmeta_system_key_path=$(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH)" >> $(zip_root)/META/misc_info.txt
4035	$(hide) echo "avb_vbmeta_system_algorithm=$(BOARD_AVB_VBMETA_SYSTEM_ALGORITHM)" >> $(zip_root)/META/misc_info.txt
4036	$(hide) echo "avb_vbmeta_system_rollback_index_location=$(BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX_LOCATION)" >> $(zip_root)/META/misc_info.txt
4037endif # BOARD_AVB_VBMETA_SYSTEM
4038ifneq (,$(strip $(BOARD_AVB_VBMETA_VENDOR)))
4039	$(hide) echo "avb_vbmeta_vendor=$(BOARD_AVB_VBMETA_VENDOR)" >> $(zip_root)/META/misc_info.txt
4040	$(hide) echo "avb_vbmeta_vendor_args=$(BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS)" >> $(zip_root)/META/misc_info.txt
4041	$(hide) echo "avb_vbmeta_vendor_key_path=$(BOARD_AVB_VBMETA_VENDOR_KEY_PATH)" >> $(zip_root)/META/misc_info.txt
4042	$(hide) echo "avb_vbmeta_vendor_algorithm=$(BOARD_AVB_VBMETA_VENDOR_ALGORITHM)" >> $(zip_root)/META/misc_info.txt
4043	$(hide) echo "avb_vbmeta_vendor_rollback_index_location=$(BOARD_AVB_VBMETA_VENDOR_ROLLBACK_INDEX_LOCATION)" >> $(zip_root)/META/misc_info.txt
4044endif # BOARD_AVB_VBMETA_VENDOR_KEY_PATH
4045endif # BOARD_AVB_ENABLE
4046ifdef BOARD_BPT_INPUT_FILES
4047	$(hide) echo "board_bpt_enable=true" >> $(zip_root)/META/misc_info.txt
4048	$(hide) echo "board_bpt_make_table_args=$(BOARD_BPT_MAKE_TABLE_ARGS)" >> $(zip_root)/META/misc_info.txt
4049	$(hide) echo "board_bpt_input_files=$(BOARD_BPT_INPUT_FILES)" >> $(zip_root)/META/misc_info.txt
4050endif
4051ifdef BOARD_BPT_DISK_SIZE
4052	$(hide) echo "board_bpt_disk_size=$(BOARD_BPT_DISK_SIZE)" >> $(zip_root)/META/misc_info.txt
4053endif
4054	$(call generate-userimage-prop-dictionary, $(zip_root)/META/misc_info.txt)
4055ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
4056ifdef BUILDING_SYSTEM_IMAGE
4057	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
4058	    build/make/tools/releasetools/make_recovery_patch $(zip_root) $(zip_root)
4059endif # BUILDING_SYSTEM_IMAGE
4060endif
4061ifeq ($(AB_OTA_UPDATER),true)
4062	@# When using the A/B updater, include the updater config files in the zip.
4063	$(hide) cp $(TOPDIR)system/update_engine/update_engine.conf $(zip_root)/META/update_engine_config.txt
4064	$(hide) for part in $(AB_OTA_PARTITIONS); do \
4065	  echo "$${part}" >> $(zip_root)/META/ab_partitions.txt; \
4066	done
4067	$(hide) for conf in $(AB_OTA_POSTINSTALL_CONFIG); do \
4068	  echo "$${conf}" >> $(zip_root)/META/postinstall_config.txt; \
4069	done
4070	@# Include the build type in META/misc_info.txt so the server can easily differentiate production builds.
4071	$(hide) echo "build_type=$(TARGET_BUILD_VARIANT)" >> $(zip_root)/META/misc_info.txt
4072	$(hide) echo "ab_update=true" >> $(zip_root)/META/misc_info.txt
4073ifdef OSRELEASED_DIRECTORY
4074	$(hide) cp $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_id $(zip_root)/META/product_id.txt
4075	$(hide) cp $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_version $(zip_root)/META/product_version.txt
4076	$(hide) cp $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/system_version $(zip_root)/META/system_version.txt
4077endif
4078endif
4079ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
4080	@# If breakpad symbols have been generated, add them to the zip.
4081	$(hide) $(ACP) -r $(TARGET_OUT_BREAKPAD) $(zip_root)/BREAKPAD
4082endif
4083ifdef BOARD_PREBUILT_VENDORIMAGE
4084	$(hide) mkdir -p $(zip_root)/IMAGES
4085	$(hide) cp $(INSTALLED_VENDORIMAGE_TARGET) $(zip_root)/IMAGES/
4086endif
4087ifdef BOARD_PREBUILT_PRODUCTIMAGE
4088	$(hide) mkdir -p $(zip_root)/IMAGES
4089	$(hide) cp $(INSTALLED_PRODUCTIMAGE_TARGET) $(zip_root)/IMAGES/
4090endif
4091ifdef BOARD_PREBUILT_PRODUCT_SERVICESIMAGE
4092	$(hide) mkdir -p $(zip_root)/IMAGES
4093	$(hide) cp $(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET) $(zip_root)/IMAGES/
4094endif
4095ifdef BOARD_PREBUILT_BOOTIMAGE
4096	$(hide) mkdir -p $(zip_root)/IMAGES
4097	$(hide) cp $(INSTALLED_BOOTIMAGE_TARGET) $(zip_root)/IMAGES/
4098endif
4099ifdef BOARD_PREBUILT_ODMIMAGE
4100	$(hide) mkdir -p $(zip_root)/IMAGES
4101	$(hide) cp $(INSTALLED_ODMIMAGE_TARGET) $(zip_root)/IMAGES/
4102endif
4103ifdef BOARD_PREBUILT_DTBOIMAGE
4104	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
4105	$(hide) cp $(INSTALLED_DTBOIMAGE_TARGET) $(zip_root)/PREBUILT_IMAGES/
4106	$(hide) echo "has_dtbo=true" >> $(zip_root)/META/misc_info.txt
4107ifeq ($(BOARD_AVB_ENABLE),true)
4108	$(hide) echo "dtbo_size=$(BOARD_DTBOIMG_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
4109	$(hide) echo "avb_dtbo_add_hash_footer_args=$(BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS)" >> $(zip_root)/META/misc_info.txt
4110ifdef BOARD_AVB_DTBO_KEY_PATH
4111	$(hide) echo "avb_dtbo_key_path=$(BOARD_AVB_DTBO_KEY_PATH)" >> $(zip_root)/META/misc_info.txt
4112	$(hide) echo "avb_dtbo_algorithm=$(BOARD_AVB_DTBO_ALGORITHM)" >> $(zip_root)/META/misc_info.txt
4113	$(hide) echo "avb_dtbo_rollback_index_location=$(BOARD_AVB_DTBO_ROLLBACK_INDEX_LOCATION)" \
4114	    >> $(zip_root)/META/misc_info.txt
4115endif # BOARD_AVB_DTBO_KEY_PATH
4116endif # BOARD_AVB_ENABLE
4117endif # BOARD_PREBUILT_DTBOIMAGE
4118	$(call dump-dynamic-partitions-info,$(zip_root)/META/misc_info.txt)
4119	@# The radio images in BOARD_PACK_RADIOIMAGES will be additionally copied from RADIO/ into
4120	@# IMAGES/, which then will be added into <product>-img.zip. Such images must be listed in
4121	@# INSTALLED_RADIOIMAGE_TARGET.
4122	$(hide) $(foreach part,$(BOARD_PACK_RADIOIMAGES), \
4123	    echo $(part) >> $(zip_root)/META/pack_radioimages.txt;)
4124	@# Run fs_config on all the system, vendor, boot ramdisk,
4125	@# and recovery ramdisk files in the zip, and save the output
4126ifdef BUILDING_SYSTEM_IMAGE
4127	$(hide) $(call fs_config,$(zip_root)/SYSTEM,system/) > $(zip_root)/META/filesystem_config.txt
4128endif
4129ifdef BUILDING_VENDOR_IMAGE
4130	$(hide) $(call fs_config,$(zip_root)/VENDOR,vendor/) > $(zip_root)/META/vendor_filesystem_config.txt
4131endif
4132ifdef BUILDING_PRODUCT_IMAGE
4133	$(hide) $(call fs_config,$(zip_root)/PRODUCT,product/) > $(zip_root)/META/product_filesystem_config.txt
4134endif
4135ifdef BUILDING_PRODUCT_SERVICES_IMAGE
4136	$(hide) $(call fs_config,$(zip_root)/PRODUCT_SERVICES,product_services/) > $(zip_root)/META/product_services_filesystem_config.txt
4137endif
4138ifdef BUILDING_ODM_IMAGE
4139	$(hide) $(call fs_config,$(zip_root)/ODM,odm/) > $(zip_root)/META/odm_filesystem_config.txt
4140endif
4141	@# ROOT always contains the files for the root under normal boot.
4142	$(hide) $(call fs_config,$(zip_root)/ROOT,) > $(zip_root)/META/root_filesystem_config.txt
4143ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
4144	@# BOOT/RAMDISK exists and contains the ramdisk for recovery if using BOARD_USES_RECOVERY_AS_BOOT.
4145	$(hide) $(call fs_config,$(zip_root)/BOOT/RAMDISK,) > $(zip_root)/META/boot_filesystem_config.txt
4146endif
4147ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
4148	@# BOOT/RAMDISK also exists and contains the first stage ramdisk if not using BOARD_BUILD_SYSTEM_ROOT_IMAGE.
4149	$(hide) $(call fs_config,$(zip_root)/BOOT/RAMDISK,) > $(zip_root)/META/boot_filesystem_config.txt
4150endif
4151ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
4152	$(hide) $(call fs_config,$(zip_root)/RECOVERY/RAMDISK,) > $(zip_root)/META/recovery_filesystem_config.txt
4153endif
4154ifdef BUILDING_SYSTEM_OTHER_IMAGE
4155	$(hide) $(call fs_config,$(zip_root)/SYSTEM_OTHER,system/) > $(zip_root)/META/system_other_filesystem_config.txt
4156endif
4157	@# Metadata for compatibility verification.
4158	$(hide) cp $(BUILT_SYSTEM_MATRIX) $(zip_root)/META/system_matrix.xml
4159	$(hide) cp $(BUILT_ASSEMBLED_FRAMEWORK_MANIFEST) $(zip_root)/META/system_manifest.xml
4160ifdef BUILT_ASSEMBLED_VENDOR_MANIFEST
4161	$(hide) cp $(BUILT_ASSEMBLED_VENDOR_MANIFEST) $(zip_root)/META/vendor_manifest.xml
4162endif
4163ifdef BUILT_VENDOR_MATRIX
4164	$(hide) cp $(BUILT_VENDOR_MATRIX) $(zip_root)/META/vendor_matrix.xml
4165endif
4166ifneq ($(BOARD_SUPER_PARTITION_GROUPS),)
4167	$(hide) echo "super_partition_groups=$(BOARD_SUPER_PARTITION_GROUPS)" > $(zip_root)/META/dynamic_partitions_info.txt
4168	@# Remove 'vendor' from the group partition list if the image is not available. This should only
4169	@# happen to AOSP targets built without vendor.img. We can't remove the partition from the
4170	@# BoardConfig file, as it's still needed elsewhere (e.g. when creating super_empty.img).
4171	$(foreach group,$(BOARD_SUPER_PARTITION_GROUPS), \
4172	    $(eval _group_partition_list := $(BOARD_$(call to-upper,$(group))_PARTITION_LIST)) \
4173	    $(if $(INSTALLED_VENDORIMAGE_TARGET),,$(eval _group_partition_list := $(filter-out vendor,$(_group_partition_list)))) \
4174	    echo "$(group)_size=$(BOARD_$(call to-upper,$(group))_SIZE)" >> $(zip_root)/META/dynamic_partitions_info.txt; \
4175	    $(if $(_group_partition_list), \
4176	        echo "$(group)_partition_list=$(_group_partition_list)" >> $(zip_root)/META/dynamic_partitions_info.txt;))
4177endif # BOARD_SUPER_PARTITION_GROUPS
4178	@# TODO(b/134525174): Remove `-r` after addressing the issue with recovery patch generation.
4179	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
4180	    build/make/tools/releasetools/add_img_to_target_files -a -r -v -p $(HOST_OUT) $(zip_root)
4181	@# Zip everything up, preserving symlinks and placing META/ files first to
4182	@# help early validation of the .zip file while uploading it.
4183	$(hide) find $(zip_root)/META | sort >$@.list
4184	$(hide) find $(zip_root) -path $(zip_root)/META -prune -o -print | sort >>$@.list
4185	$(hide) $(SOONG_ZIP) -d -o $@ -C $(zip_root) -l $@.list
4186
4187.PHONY: target-files-package
4188target-files-package: $(BUILT_TARGET_FILES_PACKAGE)
4189
4190ifneq ($(filter $(MAKECMDGOALS),target-files-package),)
4191$(call dist-for-goals, target-files-package, $(BUILT_TARGET_FILES_PACKAGE))
4192endif
4193
4194# -----------------------------------------------------------------
4195# NDK Sysroot Package
4196NDK_SYSROOT_TARGET := $(PRODUCT_OUT)/ndk_sysroot.tar.bz2
4197$(NDK_SYSROOT_TARGET): $(SOONG_OUT_DIR)/ndk.timestamp
4198	@echo Package NDK sysroot...
4199	$(hide) tar cjf $@ -C $(SOONG_OUT_DIR) ndk
4200
4201$(call dist-for-goals,sdk,$(NDK_SYSROOT_TARGET))
4202
4203ifeq ($(build_ota_package),true)
4204# -----------------------------------------------------------------
4205# OTA update package
4206
4207# $(1): output file
4208# $(2): additional args
4209define build-ota-package-target
4210PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
4211   build/make/tools/releasetools/ota_from_target_files -v \
4212   --block \
4213   --extracted_input_target_files $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE)) \
4214   -p $(HOST_OUT) \
4215   $(if $(OEM_OTA_CONFIG), -o $(OEM_OTA_CONFIG)) \
4216   $(2) \
4217   $(BUILT_TARGET_FILES_PACKAGE) $(1)
4218endef
4219
4220name := $(TARGET_PRODUCT)
4221ifeq ($(TARGET_BUILD_TYPE),debug)
4222  name := $(name)_debug
4223endif
4224name := $(name)-ota-$(FILE_NAME_TAG)
4225
4226INTERNAL_OTA_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
4227
4228INTERNAL_OTA_METADATA := $(PRODUCT_OUT)/ota_metadata
4229
4230$(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
4231
4232ifeq ($(AB_OTA_UPDATER),true)
4233$(INTERNAL_OTA_PACKAGE_TARGET): $(BRILLO_UPDATE_PAYLOAD)
4234else
4235$(INTERNAL_OTA_PACKAGE_TARGET): $(BROTLI)
4236endif
4237
4238$(INTERNAL_OTA_PACKAGE_TARGET): .KATI_IMPLICIT_OUTPUTS := $(INTERNAL_OTA_METADATA)
4239
4240$(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) \
4241	    build/make/tools/releasetools/ota_from_target_files
4242	@echo "Package OTA: $@"
4243	$(call build-ota-package-target,$@,-k $(KEY_CERT_PAIR) --output_metadata_path $(INTERNAL_OTA_METADATA))
4244
4245.PHONY: otapackage
4246otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)
4247
4248ifeq ($(BOARD_BUILD_RETROFIT_DYNAMIC_PARTITIONS_OTA_PACKAGE),true)
4249name := $(TARGET_PRODUCT)
4250ifeq ($(TARGET_BUILD_TYPE),debug)
4251  name := $(name)_debug
4252endif
4253name := $(name)-ota-retrofit-$(FILE_NAME_TAG)
4254
4255INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
4256
4257$(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
4258
4259ifeq ($(AB_OTA_UPDATER),true)
4260$(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET): $(BRILLO_UPDATE_PAYLOAD)
4261else
4262$(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET): $(BROTLI)
4263endif
4264
4265$(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) \
4266	    build/make/tools/releasetools/ota_from_target_files
4267	@echo "Package OTA (retrofit dynamic partitions): $@"
4268	$(call build-ota-package-target,$@,-k $(KEY_CERT_PAIR) --retrofit_dynamic_partitions)
4269
4270.PHONY: otardppackage
4271
4272otapackage otardppackage: $(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET)
4273
4274endif # BOARD_BUILD_RETROFIT_DYNAMIC_PARTITIONS_OTA_PACKAGE
4275
4276endif    # build_ota_package
4277
4278# -----------------------------------------------------------------
4279# A zip of the appcompat directory containing logs
4280APPCOMPAT_ZIP := $(PRODUCT_OUT)/appcompat.zip
4281# For apps_only build we'll establish the dependency later in build/make/core/main.mk.
4282ifndef TARGET_BUILD_APPS
4283$(APPCOMPAT_ZIP): $(INSTALLED_SYSTEMIMAGE_TARGET) \
4284	    $(INSTALLED_RAMDISK_TARGET) \
4285	    $(INSTALLED_BOOTIMAGE_TARGET) \
4286	    $(INSTALLED_USERDATAIMAGE_TARGET) \
4287	    $(INSTALLED_VENDORIMAGE_TARGET) \
4288	    $(INSTALLED_PRODUCTIMAGE_TARGET) \
4289	    $(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET)
4290endif
4291$(APPCOMPAT_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,appcompat)/filelist
4292$(APPCOMPAT_ZIP): $(SOONG_ZIP)
4293	@echo "appcompat logs: $@"
4294	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
4295	$(hide) mkdir -p $(dir $@) $(PRODUCT_OUT)/appcompat $(dir $(PRIVATE_LIST_FILE))
4296	$(hide) find $(PRODUCT_OUT)/appcompat | sort >$(PRIVATE_LIST_FILE)
4297	$(hide) $(SOONG_ZIP) -d -o $@ -C $(PRODUCT_OUT)/appcompat -l $(PRIVATE_LIST_FILE)
4298
4299# -----------------------------------------------------------------
4300# A zip of the symbols directory.  Keep the full paths to make it
4301# more obvious where these files came from.
4302#
4303name := $(TARGET_PRODUCT)
4304ifeq ($(TARGET_BUILD_TYPE),debug)
4305  name := $(name)_debug
4306endif
4307name := $(name)-symbols-$(FILE_NAME_TAG)
4308
4309SYMBOLS_ZIP := $(PRODUCT_OUT)/$(name).zip
4310# For apps_only build we'll establish the dependency later in build/make/core/main.mk.
4311ifndef TARGET_BUILD_APPS
4312$(SYMBOLS_ZIP): $(INSTALLED_SYSTEMIMAGE_TARGET) \
4313	    $(INSTALLED_RAMDISK_TARGET) \
4314	    $(INSTALLED_BOOTIMAGE_TARGET) \
4315	    $(INSTALLED_USERDATAIMAGE_TARGET) \
4316	    $(INSTALLED_VENDORIMAGE_TARGET) \
4317	    $(INSTALLED_PRODUCTIMAGE_TARGET) \
4318	    $(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET) \
4319	    $(INSTALLED_ODMIMAGE_TARGET) \
4320	    $(updater_dep)
4321endif
4322$(SYMBOLS_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,symbols)/filelist
4323$(SYMBOLS_ZIP): $(SOONG_ZIP)
4324	@echo "Package symbols: $@"
4325	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
4326	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_UNSTRIPPED) $(dir $(PRIVATE_LIST_FILE))
4327	$(hide) find -L $(TARGET_OUT_UNSTRIPPED) -type f | sort >$(PRIVATE_LIST_FILE)
4328	$(hide) $(SOONG_ZIP) -d -o $@ -C $(OUT_DIR)/.. -l $(PRIVATE_LIST_FILE)
4329# -----------------------------------------------------------------
4330# A zip of the coverage directory.
4331#
4332name := $(TARGET_PRODUCT)
4333ifeq ($(TARGET_BUILD_TYPE),debug)
4334name := $(name)_debug
4335endif
4336name := $(name)-coverage-$(FILE_NAME_TAG)
4337COVERAGE_ZIP := $(PRODUCT_OUT)/$(name).zip
4338ifndef TARGET_BUILD_APPS
4339$(COVERAGE_ZIP): $(INSTALLED_SYSTEMIMAGE_TARGET) \
4340	    $(INSTALLED_RAMDISK_TARGET) \
4341	    $(INSTALLED_BOOTIMAGE_TARGET) \
4342	    $(INSTALLED_USERDATAIMAGE_TARGET) \
4343	    $(INSTALLED_VENDORIMAGE_TARGET) \
4344	    $(INSTALLED_PRODUCTIMAGE_TARGET) \
4345	    $(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET) \
4346	    $(INSTALLED_ODMIMAGE_TARGET)
4347endif
4348$(COVERAGE_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,coverage)/filelist
4349$(COVERAGE_ZIP): $(SOONG_ZIP)
4350	@echo "Package coverage: $@"
4351	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
4352	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_COVERAGE) $(dir $(PRIVATE_LIST_FILE))
4353	$(hide) find $(TARGET_OUT_COVERAGE) | sort >$(PRIVATE_LIST_FILE)
4354	$(hide) $(SOONG_ZIP) -d -o $@ -C $(TARGET_OUT_COVERAGE) -l $(PRIVATE_LIST_FILE)
4355
4356# -----------------------------------------------------------------
4357# A zip of the Android Apps. Not keeping full path so that we don't
4358# include product names when distributing
4359#
4360name := $(TARGET_PRODUCT)
4361ifeq ($(TARGET_BUILD_TYPE),debug)
4362  name := $(name)_debug
4363endif
4364name := $(name)-apps-$(FILE_NAME_TAG)
4365
4366APPS_ZIP := $(PRODUCT_OUT)/$(name).zip
4367$(APPS_ZIP): $(INSTALLED_SYSTEMIMAGE_TARGET)
4368	@echo "Package apps: $@"
4369	$(hide) rm -rf $@
4370	$(hide) mkdir -p $(dir $@)
4371	$(hide) apps_to_zip=`find $(TARGET_OUT_APPS) $(TARGET_OUT_APPS_PRIVILEGED) -mindepth 2 -maxdepth 3 -name "*.apk"`; \
4372	if [ -z "$$apps_to_zip" ]; then \
4373	    echo "No apps to zip up. Generating empty apps archive." ; \
4374	    a=$$(mktemp /tmp/XXXXXXX) && touch $$a && zip $@ $$a && zip -d $@ $$a; \
4375	else \
4376	    zip -qjX $@ $$apps_to_zip; \
4377	fi
4378
4379ifeq (true,$(EMMA_INSTRUMENT))
4380#------------------------------------------------------------------
4381# An archive of classes for use in generating code-coverage reports
4382# These are the uninstrumented versions of any classes that were
4383# to be instrumented.
4384# Any dependencies are set up later in build/make/core/main.mk.
4385
4386JACOCO_REPORT_CLASSES_ALL := $(PRODUCT_OUT)/jacoco-report-classes-all.jar
4387$(JACOCO_REPORT_CLASSES_ALL) :
4388	@echo "Collecting uninstrumented classes"
4389	$(hide) find $(TARGET_COMMON_OUT_ROOT) $(HOST_COMMON_OUT_ROOT) -name "jacoco-report-classes.jar" | \
4390	    zip -@ -0 -q -X $@
4391# Meaning of these options:
4392# -@ scan stdin for file paths to add to the zip
4393# -0 don't do any compression
4394# -q supress most output
4395# -X skip storing extended file attributes
4396
4397endif # EMMA_INSTRUMENT=true
4398
4399
4400#------------------------------------------------------------------
4401# A zip of Proguard obfuscation dictionary files.
4402# Only for apps_only build.
4403#
4404ifdef TARGET_BUILD_APPS
4405PROGUARD_DICT_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-$(FILE_NAME_TAG).zip
4406# the dependency will be set up later in build/make/core/main.mk.
4407$(PROGUARD_DICT_ZIP) :
4408	@echo "Packaging Proguard obfuscation dictionary files."
4409	$(hide) dict_files=`find $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS -name proguard_dictionary`; \
4410	    if [ -n "$$dict_files" ]; then \
4411	      unobfuscated_jars=$${dict_files//proguard_dictionary/classes.jar}; \
4412	      zip -qX $@ $$dict_files $$unobfuscated_jars; \
4413	    else \
4414	      touch $(dir $@)/zipdummy; \
4415	      (cd $(dir $@) && zip -q $(notdir $@) zipdummy); \
4416	      zip -qd $@ zipdummy; \
4417	      rm $(dir $@)/zipdummy; \
4418	    fi
4419
4420endif # TARGET_BUILD_APPS
4421
4422# -----------------------------------------------------------------
4423# super partition image (dist)
4424
4425ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
4426
4427# BOARD_SUPER_PARTITION_SIZE must be defined to build super image.
4428ifneq ($(BOARD_SUPER_PARTITION_SIZE),)
4429
4430# Dump variables used by build_super_image.py.
4431define dump-super-image-info
4432  $(call dump-dynamic-partitions-info,$(1))
4433  $(if $(filter true,$(AB_OTA_UPDATER)), \
4434    echo "ab_update=true" >> $(1))
4435endef
4436
4437ifneq (true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS))
4438
4439# For real devices and for dist builds, build super image from target files to an intermediate directory.
4440INTERNAL_SUPERIMAGE_DIST_TARGET := $(call intermediates-dir-for,PACKAGING,super.img)/super.img
4441$(INTERNAL_SUPERIMAGE_DIST_TARGET): extracted_input_target_files := $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE))
4442$(INTERNAL_SUPERIMAGE_DIST_TARGET): $(LPMAKE) $(BUILT_TARGET_FILES_PACKAGE) $(BUILD_SUPER_IMAGE)
4443	$(call pretty,"Target super fs image from target files: $@")
4444	PATH=$(dir $(LPMAKE)):$$PATH \
4445	    $(BUILD_SUPER_IMAGE) -v $(extracted_input_target_files) $@
4446
4447# Skip packing it in dist package because it is in update package.
4448ifneq (true,$(BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE))
4449$(call dist-for-goals,dist_files,$(INTERNAL_SUPERIMAGE_DIST_TARGET))
4450endif
4451
4452.PHONY: superimage_dist
4453superimage_dist: $(INTERNAL_SUPERIMAGE_DIST_TARGET)
4454
4455endif # PRODUCT_RETROFIT_DYNAMIC_PARTITIONS != "true"
4456endif # BOARD_SUPER_PARTITION_SIZE != ""
4457endif # PRODUCT_BUILD_SUPER_PARTITION == "true"
4458
4459# -----------------------------------------------------------------
4460# super partition image for development
4461
4462ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
4463ifneq ($(BOARD_SUPER_PARTITION_SIZE),)
4464ifneq (true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS))
4465
4466# Build super.img by using $(INSTALLED_*IMAGE_TARGET) to $(1)
4467# $(1): built image path
4468# $(2): misc_info.txt path; its contents should match expectation of build_super_image.py
4469define build-superimage-target
4470  mkdir -p $(dir $(2))
4471  rm -rf $(2)
4472  $(call dump-super-image-info,$(2))
4473  $(foreach p,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
4474    echo "$(p)_image=$(INSTALLED_$(call to-upper,$(p))IMAGE_TARGET)" >> $(2);)
4475  mkdir -p $(dir $(1))
4476  PATH=$(dir $(LPMAKE)):$$PATH \
4477    $(BUILD_SUPER_IMAGE) -v $(2) $(1)
4478endef
4479
4480INSTALLED_SUPERIMAGE_TARGET := $(PRODUCT_OUT)/super.img
4481INSTALLED_SUPERIMAGE_DEPENDENCIES := $(LPMAKE) $(BUILD_SUPER_IMAGE) \
4482    $(foreach p, $(BOARD_SUPER_PARTITION_PARTITION_LIST), $(INSTALLED_$(call to-upper,$(p))IMAGE_TARGET))
4483
4484# If BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT is set, super.img is built from images in the
4485# $(PRODUCT_OUT) directory, and is built to $(PRODUCT_OUT)/super.img. Also, it will
4486# be built for non-dist builds. This is useful for devices that uses super.img directly, e.g.
4487# virtual devices.
4488ifeq (true,$(BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT))
4489$(INSTALLED_SUPERIMAGE_TARGET): $(INSTALLED_SUPERIMAGE_DEPENDENCIES)
4490	$(call pretty,"Target super fs image for debug: $@")
4491	$(call build-superimage-target,$(INSTALLED_SUPERIMAGE_TARGET),\
4492	  $(call intermediates-dir-for,PACKAGING,superimage_debug)/misc_info.txt)
4493
4494droidcore: $(INSTALLED_SUPERIMAGE_TARGET)
4495
4496# For devices that uses super image directly, the superimage target points to the file in $(PRODUCT_OUT).
4497.PHONY: superimage
4498superimage: $(INSTALLED_SUPERIMAGE_TARGET)
4499endif # BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT
4500
4501# Build $(PRODUCT_OUT)/super.img without dependencies.
4502.PHONY: superimage-nodeps supernod
4503superimage-nodeps supernod: intermediates :=
4504superimage-nodeps supernod: | $(INSTALLED_SUPERIMAGE_DEPENDENCIES)
4505	$(call pretty,"make $(INSTALLED_SUPERIMAGE_TARGET): ignoring dependencies")
4506	$(call build-superimage-target,$(INSTALLED_SUPERIMAGE_TARGET),\
4507	  $(call intermediates-dir-for,PACKAGING,superimage-nodeps)/misc_info.txt)
4508
4509endif # PRODUCT_RETROFIT_DYNAMIC_PARTITIONS != "true"
4510endif # BOARD_SUPER_PARTITION_SIZE != ""
4511endif # PRODUCT_BUILD_SUPER_PARTITION == "true"
4512
4513# -----------------------------------------------------------------
4514# super empty image
4515
4516ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
4517ifneq ($(BOARD_SUPER_PARTITION_SIZE),)
4518
4519INSTALLED_SUPERIMAGE_EMPTY_TARGET := $(PRODUCT_OUT)/super_empty.img
4520$(INSTALLED_SUPERIMAGE_EMPTY_TARGET): intermediates := $(call intermediates-dir-for,PACKAGING,super_empty)
4521$(INSTALLED_SUPERIMAGE_EMPTY_TARGET): $(LPMAKE) $(BUILD_SUPER_IMAGE)
4522	$(call pretty,"Target empty super fs image: $@")
4523	mkdir -p $(intermediates)
4524	rm -rf $(intermediates)/misc_info.txt
4525	$(call dump-super-image-info,$(intermediates)/misc_info.txt)
4526	PATH=$(dir $(LPMAKE)):$$PATH \
4527	    $(BUILD_SUPER_IMAGE) -v $(intermediates)/misc_info.txt $@
4528
4529$(call dist-for-goals,dist_files,$(INSTALLED_SUPERIMAGE_EMPTY_TARGET))
4530
4531endif # BOARD_SUPER_PARTITION_SIZE != ""
4532endif # PRODUCT_BUILD_SUPER_PARTITION == "true"
4533
4534
4535# -----------------------------------------------------------------
4536# The update package
4537
4538name := $(TARGET_PRODUCT)
4539ifeq ($(TARGET_BUILD_TYPE),debug)
4540  name := $(name)_debug
4541endif
4542name := $(name)-img-$(FILE_NAME_TAG)
4543
4544INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
4545
4546$(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(ZIP2ZIP)
4547
4548ifeq (true,$(BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE))
4549$(INTERNAL_UPDATE_PACKAGE_TARGET): $(INTERNAL_SUPERIMAGE_DIST_TARGET)
4550	@echo "Package: $@"
4551	# Filter out super_empty and images in BOARD_SUPER_PARTITION_PARTITION_LIST.
4552	# Filter out system_other for launch DAP devices because it is in super image.
4553	# Include OTA/super_*.img for retrofit devices and super.img for non-retrofit
4554	# devices.
4555	$(hide) $(ZIP2ZIP) -i $(BUILT_TARGET_FILES_PACKAGE) -o $@ \
4556	  -x IMAGES/super_empty.img \
4557	  $(foreach partition,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
4558	    -x IMAGES/$(partition).img) \
4559	  $(if $(filter system, $(BOARD_SUPER_PARTITION_PARTITION_LIST)), \
4560	    $(if $(filter true, $(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)),, \
4561	      -x IMAGES/system_other.img)) \
4562	  $(if $(filter true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)), \
4563	    $(foreach device,$(BOARD_SUPER_PARTITION_BLOCK_DEVICES), \
4564	      OTA/super_$(device).img:super_$(device).img)) \
4565	  OTA/android-info.txt:android-info.txt "IMAGES/*.img:."
4566	$(if $(INTERNAL_SUPERIMAGE_DIST_TARGET), zip -q -j -u $@ $(INTERNAL_SUPERIMAGE_DIST_TARGET))
4567else
4568$(INTERNAL_UPDATE_PACKAGE_TARGET):
4569	@echo "Package: $@"
4570	$(hide) $(ZIP2ZIP) -i $(BUILT_TARGET_FILES_PACKAGE) -o $@ \
4571	  OTA/android-info.txt:android-info.txt "IMAGES/*.img:."
4572endif # BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE
4573
4574.PHONY: updatepackage
4575updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
4576
4577
4578# -----------------------------------------------------------------
4579# dalvik something
4580.PHONY: dalvikfiles
4581dalvikfiles: $(INTERNAL_DALVIK_MODULES)
4582
4583ifeq ($(BUILD_QEMU_IMAGES),true)
4584MK_QEMU_IMAGE_SH := device/generic/goldfish/tools/mk_qemu_image.sh
4585MK_COMBINE_QEMU_IMAGE_SH := device/generic/goldfish/tools/mk_combined_img.py
4586SGDISK_HOST := $(HOST_OUT_EXECUTABLES)/sgdisk
4587
4588ifdef INSTALLED_SYSTEMIMAGE_TARGET
4589INSTALLED_QEMU_SYSTEMIMAGE := $(PRODUCT_OUT)/system-qemu.img
4590INSTALLED_SYSTEM_QEMU_CONFIG := $(PRODUCT_OUT)/system-qemu-config.txt
4591$(INSTALLED_SYSTEM_QEMU_CONFIG): $(INSTALLED_SUPERIMAGE_TARGET) $(INSTALLED_VBMETAIMAGE_TARGET)
4592	@echo "$(PRODUCT_OUT)/vbmeta.img vbmeta 1" > $@
4593	@echo "$(INSTALLED_SUPERIMAGE_TARGET) super 2" >> $@
4594$(INSTALLED_QEMU_SYSTEMIMAGE): $(INSTALLED_VBMETAIMAGE_TARGET) $(MK_COMBINE_QEMU_IMAGE_SH) $(SGDISK_HOST) $(SIMG2IMG) \
4595    $(INSTALLED_SUPERIMAGE_TARGET) $(INSTALLED_SYSTEM_QEMU_CONFIG)
4596	@echo Create system-qemu.img now
4597	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); \
4598     $(MK_COMBINE_QEMU_IMAGE_SH) -i $(INSTALLED_SYSTEM_QEMU_CONFIG) -o $@)
4599
4600systemimage: $(INSTALLED_QEMU_SYSTEMIMAGE)
4601droidcore: $(INSTALLED_QEMU_SYSTEMIMAGE)
4602endif
4603ifdef INSTALLED_VENDORIMAGE_TARGET
4604INSTALLED_QEMU_VENDORIMAGE := $(PRODUCT_OUT)/vendor-qemu.img
4605$(INSTALLED_QEMU_VENDORIMAGE): $(INSTALLED_VENDORIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST) $(SIMG2IMG)
4606	@echo Create vendor-qemu.img
4607	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); $(MK_QEMU_IMAGE_SH) $(INSTALLED_VENDORIMAGE_TARGET))
4608
4609vendorimage: $(INSTALLED_QEMU_VENDORIMAGE)
4610droidcore: $(INSTALLED_QEMU_VENDORIMAGE)
4611endif
4612ifdef INSTALLED_PRODUCTIMAGE_TARGET
4613INSTALLED_QEMU_PRODUCTIMAGE := $(PRODUCT_OUT)/product-qemu.img
4614$(INSTALLED_QEMU_PRODUCTIMAGE): $(INSTALLED_PRODUCTIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST) $(SIMG2IMG)
4615	@echo Create product-qemu.img
4616	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); $(MK_QEMU_IMAGE_SH) $(INSTALLED_PRODUCTIMAGE_TARGET))
4617
4618productimage: $(INSTALLED_QEMU_PRODUCTIMAGE)
4619droidcore: $(INSTALLED_QEMU_PRODUCTIMAGE)
4620endif
4621ifdef INSTALLED_PRODUCT_SERVICESIMAGE_TARGET
4622INSTALLED_QEMU_PRODUCT_SERVICESIMAGE := $(PRODUCT_OUT)/product_services-qemu.img
4623$(INSTALLED_QEMU_PRODUCT_SERVICESIMAGE): $(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST) $(SIMG2IMG)
4624	@echo Create product_services-qemu.img
4625	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); $(MK_QEMU_IMAGE_SH) $(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET))
4626
4627productservicesimage: $(INSTALLED_QEMU_PRODUCT_SERVICESIMAGE)
4628droidcore: $(INSTALLED_QEMU_PRODUCT_SERVICESIMAGE)
4629endif
4630ifdef INSTALLED_ODMIMAGE_TARGET
4631INSTALLED_QEMU_ODMIMAGE := $(PRODUCT_OUT)/odm-qemu.img
4632$(INSTALLED_QEMU_ODMIMAGE): $(INSTALLED_ODMIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST)
4633	@echo Create odm-qemu.img
4634	(export SGDISK=$(SGDISK_HOST); $(MK_QEMU_IMAGE_SH) $(INSTALLED_ODMIMAGE_TARGET))
4635
4636odmimage: $(INSTALLED_QEMU_ODMIMAGE)
4637droidcore: $(INSTALLED_QEMU_ODMIMAGE)
4638endif
4639
4640QEMU_VERIFIED_BOOT_PARAMS := $(PRODUCT_OUT)/VerifiedBootParams.textproto
4641MK_VBMETA_BOOT_KERNEL_CMDLINE_SH := device/generic/goldfish/tools/mk_vbmeta_boot_params.sh
4642$(QEMU_VERIFIED_BOOT_PARAMS): $(INSTALLED_VBMETAIMAGE_TARGET) $(INSTALLED_SYSTEMIMAGE_TARGET) \
4643    $(MK_VBMETA_BOOT_KERNEL_CMDLINE_SH) $(AVBTOOL)
4644	@echo Creating $@
4645	(export AVBTOOL=$(AVBTOOL); $(MK_VBMETA_BOOT_KERNEL_CMDLINE_SH) $(INSTALLED_VBMETAIMAGE_TARGET) \
4646    $(INSTALLED_SYSTEMIMAGE_TARGET) $(QEMU_VERIFIED_BOOT_PARAMS))
4647
4648systemimage: $(QEMU_VERIFIED_BOOT_PARAMS)
4649droidcore: $(QEMU_VERIFIED_BOOT_PARAMS)
4650
4651endif
4652# -----------------------------------------------------------------
4653# The emulator package
4654ifeq ($(BUILD_EMULATOR),true)
4655INTERNAL_EMULATOR_PACKAGE_FILES += \
4656        $(HOST_OUT_EXECUTABLES)/emulator$(HOST_EXECUTABLE_SUFFIX) \
4657        prebuilts/qemu-kernel/$(TARGET_ARCH)/kernel-qemu \
4658        $(INSTALLED_RAMDISK_TARGET) \
4659        $(INSTALLED_SYSTEMIMAGE_TARGET) \
4660        $(INSTALLED_USERDATAIMAGE_TARGET)
4661
4662name := $(TARGET_PRODUCT)-emulator-$(FILE_NAME_TAG)
4663
4664INTERNAL_EMULATOR_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
4665
4666$(INTERNAL_EMULATOR_PACKAGE_TARGET): $(INTERNAL_EMULATOR_PACKAGE_FILES)
4667	@echo "Package: $@"
4668	$(hide) zip -qjX $@ $(INTERNAL_EMULATOR_PACKAGE_FILES)
4669
4670endif
4671# -----------------------------------------------------------------
4672# Old PDK stuffs, retired
4673# The pdk package (Platform Development Kit)
4674
4675#ifneq (,$(filter pdk,$(MAKECMDGOALS)))
4676#  include development/pdk/Pdk.mk
4677#endif
4678
4679
4680# -----------------------------------------------------------------
4681# The SDK
4682
4683# The SDK includes host-specific components, so it belongs under HOST_OUT.
4684sdk_dir := $(HOST_OUT)/sdk/$(TARGET_PRODUCT)
4685
4686# Build a name that looks like:
4687#
4688#     linux-x86   --> android-sdk_12345_linux-x86
4689#     darwin-x86  --> android-sdk_12345_mac-x86
4690#     windows-x86 --> android-sdk_12345_windows
4691#
4692sdk_name := android-sdk_$(FILE_NAME_TAG)
4693ifeq ($(HOST_OS),darwin)
4694  INTERNAL_SDK_HOST_OS_NAME := mac
4695else
4696  INTERNAL_SDK_HOST_OS_NAME := $(HOST_OS)
4697endif
4698ifneq ($(HOST_OS),windows)
4699  INTERNAL_SDK_HOST_OS_NAME := $(INTERNAL_SDK_HOST_OS_NAME)-$(SDK_HOST_ARCH)
4700endif
4701sdk_name := $(sdk_name)_$(INTERNAL_SDK_HOST_OS_NAME)
4702
4703sdk_dep_file := $(sdk_dir)/sdk_deps.mk
4704
4705ATREE_FILES :=
4706-include $(sdk_dep_file)
4707
4708# if we don't have a real list, then use "everything"
4709ifeq ($(strip $(ATREE_FILES)),)
4710ATREE_FILES := \
4711	$(ALL_DEFAULT_INSTALLED_MODULES) \
4712	$(INSTALLED_RAMDISK_TARGET) \
4713	$(ALL_DOCS) \
4714	$(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/api-stubs-docs_annotations.zip \
4715	$(ALL_SDK_FILES)
4716endif
4717
4718atree_dir := development/build
4719
4720
4721sdk_atree_files := \
4722	$(atree_dir)/sdk.exclude.atree \
4723	$(atree_dir)/sdk-$(HOST_OS)-$(SDK_HOST_ARCH).atree
4724
4725# development/build/sdk-android-<abi>.atree is used to differentiate
4726# between architecture models (e.g. ARMv5TE versus ARMv7) when copying
4727# files like the kernel image. We use TARGET_CPU_ABI because we don't
4728# have a better way to distinguish between CPU models.
4729ifneq (,$(strip $(wildcard $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree)))
4730  sdk_atree_files += $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree
4731endif
4732
4733ifneq ($(PRODUCT_SDK_ATREE_FILES),)
4734sdk_atree_files += $(PRODUCT_SDK_ATREE_FILES)
4735else
4736sdk_atree_files += $(atree_dir)/sdk.atree
4737endif
4738
4739include $(BUILD_SYSTEM)/sdk_font.mk
4740
4741deps := \
4742	$(target_notice_file_txt) \
4743	$(tools_notice_file_txt) \
4744	$(OUT_DOCS)/offline-sdk-timestamp \
4745	$(SYMBOLS_ZIP) \
4746	$(COVERAGE_ZIP) \
4747	$(APPCOMPAT_ZIP) \
4748	$(INSTALLED_SYSTEMIMAGE_TARGET) \
4749	$(INSTALLED_QEMU_SYSTEMIMAGE) \
4750	$(INSTALLED_QEMU_VENDORIMAGE) \
4751	$(QEMU_VERIFIED_BOOT_PARAMS) \
4752	$(INSTALLED_USERDATAIMAGE_TARGET) \
4753	$(INSTALLED_RAMDISK_TARGET) \
4754	$(INSTALLED_SDK_BUILD_PROP_TARGET) \
4755	$(INSTALLED_BUILD_PROP_TARGET) \
4756	$(ATREE_FILES) \
4757	$(sdk_atree_files) \
4758	$(HOST_OUT_EXECUTABLES)/atree \
4759	$(HOST_OUT_EXECUTABLES)/line_endings \
4760	$(SDK_FONT_DEPS)
4761
4762INTERNAL_SDK_TARGET := $(sdk_dir)/$(sdk_name).zip
4763$(INTERNAL_SDK_TARGET): PRIVATE_NAME := $(sdk_name)
4764$(INTERNAL_SDK_TARGET): PRIVATE_DIR := $(sdk_dir)/$(sdk_name)
4765$(INTERNAL_SDK_TARGET): PRIVATE_DEP_FILE := $(sdk_dep_file)
4766$(INTERNAL_SDK_TARGET): PRIVATE_INPUT_FILES := $(sdk_atree_files)
4767
4768# Set SDK_GNU_ERROR to non-empty to fail when a GNU target is built.
4769#
4770#SDK_GNU_ERROR := true
4771
4772$(INTERNAL_SDK_TARGET): $(deps)
4773	@echo "Package SDK: $@"
4774	$(hide) rm -rf $(PRIVATE_DIR) $@
4775	$(hide) for f in $(target_gnu_MODULES); do \
4776	  if [ -f $$f ]; then \
4777	    echo SDK: $(if $(SDK_GNU_ERROR),ERROR:,warning:) \
4778	        including GNU target $$f >&2; \
4779	    FAIL=$(SDK_GNU_ERROR); \
4780	  fi; \
4781	done; \
4782	if [ $$FAIL ]; then exit 1; fi
4783	$(hide) echo $(notdir $(SDK_FONT_DEPS)) | tr " " "\n"  > $(SDK_FONT_TEMP)/fontsInSdk.txt
4784	$(hide) ( \
4785	    ATREE_STRIP="$(HOST_STRIP) -x" \
4786	    $(HOST_OUT_EXECUTABLES)/atree \
4787	    $(addprefix -f ,$(PRIVATE_INPUT_FILES)) \
4788	        -m $(PRIVATE_DEP_FILE) \
4789	        -I . \
4790	        -I $(PRODUCT_OUT) \
4791	        -I $(HOST_OUT) \
4792	        -I $(TARGET_COMMON_OUT_ROOT) \
4793	        -v "PLATFORM_NAME=android-$(PLATFORM_VERSION)" \
4794	        -v "OUT_DIR=$(OUT_DIR)" \
4795	        -v "HOST_OUT=$(HOST_OUT)" \
4796	        -v "TARGET_ARCH=$(TARGET_ARCH)" \
4797	        -v "TARGET_CPU_ABI=$(TARGET_CPU_ABI)" \
4798	        -v "DLL_EXTENSION=$(HOST_SHLIB_SUFFIX)" \
4799	        -v "FONT_OUT=$(SDK_FONT_TEMP)" \
4800	        -o $(PRIVATE_DIR) && \
4801	    cp -f $(target_notice_file_txt) \
4802	            $(PRIVATE_DIR)/system-images/android-$(PLATFORM_VERSION)/$(TARGET_CPU_ABI)/NOTICE.txt && \
4803	    cp -f $(tools_notice_file_txt) $(PRIVATE_DIR)/platform-tools/NOTICE.txt && \
4804	    HOST_OUT_EXECUTABLES=$(HOST_OUT_EXECUTABLES) HOST_OS=$(HOST_OS) \
4805	        development/build/tools/sdk_clean.sh $(PRIVATE_DIR) && \
4806	    chmod -R ug+rwX $(PRIVATE_DIR) && \
4807	    cd $(dir $@) && zip -rqX $(notdir $@) $(PRIVATE_NAME) \
4808	) || ( rm -rf $(PRIVATE_DIR) $@ && exit 44 )
4809
4810
4811# Is a Windows SDK requested? If so, we need some definitions from here
4812# in order to find the Linux SDK used to create the Windows one.
4813MAIN_SDK_NAME := $(sdk_name)
4814MAIN_SDK_DIR  := $(sdk_dir)
4815MAIN_SDK_ZIP  := $(INTERNAL_SDK_TARGET)
4816ifneq ($(filter win_sdk winsdk-tools,$(MAKECMDGOALS)),)
4817include $(TOPDIR)development/build/tools/windows_sdk.mk
4818endif
4819
4820# -----------------------------------------------------------------
4821# Findbugs
4822INTERNAL_FINDBUGS_XML_TARGET := $(PRODUCT_OUT)/findbugs.xml
4823INTERNAL_FINDBUGS_HTML_TARGET := $(PRODUCT_OUT)/findbugs.html
4824$(INTERNAL_FINDBUGS_XML_TARGET): $(ALL_FINDBUGS_FILES)
4825	@echo UnionBugs: $@
4826	$(hide) $(FINDBUGS_DIR)/unionBugs $(ALL_FINDBUGS_FILES) \
4827	> $@
4828$(INTERNAL_FINDBUGS_HTML_TARGET): $(INTERNAL_FINDBUGS_XML_TARGET)
4829	@echo ConvertXmlToText: $@
4830	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl \
4831	$(INTERNAL_FINDBUGS_XML_TARGET) > $@
4832
4833# -----------------------------------------------------------------
4834# Findbugs
4835
4836# -----------------------------------------------------------------
4837# These are some additional build tasks that need to be run.
4838ifneq ($(dont_bother),true)
4839include $(sort $(wildcard $(BUILD_SYSTEM)/tasks/*.mk))
4840-include $(sort $(wildcard vendor/*/build/tasks/*.mk))
4841-include $(sort $(wildcard device/*/build/tasks/*.mk))
4842-include $(sort $(wildcard product/*/build/tasks/*.mk))
4843# Also the project-specific tasks
4844-include $(sort $(wildcard vendor/*/*/build/tasks/*.mk))
4845-include $(sort $(wildcard device/*/*/build/tasks/*.mk))
4846-include $(sort $(wildcard product/*/*/build/tasks/*.mk))
4847# Also add test specifc tasks
4848include $(sort $(wildcard platform_testing/build/tasks/*.mk))
4849include $(sort $(wildcard test/vts/tools/build/tasks/*.mk))
4850endif
4851
4852include $(BUILD_SYSTEM)/product-graph.mk
4853
4854# -----------------------------------------------------------------
4855# Create SDK repository packages. Must be done after tasks/* since
4856# we need the addon rules defined.
4857ifneq ($(sdk_repo_goal),)
4858include $(TOPDIR)development/build/tools/sdk_repo.mk
4859endif
4860