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!))) \
20$(if $(filter true,$(BUILD_BROKEN_VINTF_PRODUCT_COPY_FILES)),, \
21  $(if $(filter $(TARGET_COPY_OUT_SYSTEM)/etc/vintf/% \
22                $(TARGET_COPY_OUT_SYSTEM)/manifest.xml \
23                $(TARGET_COPY_OUT_SYSTEM)/compatibility_matrix.xml,$(2)), \
24    $(error VINTF metadata found in PRODUCT_COPY_FILES: $(1), use vintf_fragments instead!)) \
25  $(if $(filter $(TARGET_COPY_OUT_PRODUCT)/etc/vintf/%,$(2)), \
26    $(error VINTF metadata found in PRODUCT_COPY_FILES: $(1), \
27      use PRODUCT_MANIFEST_FILES / DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE / vintf_compatibility_matrix / vintf_fragments instead!)) \
28  $(if $(filter $(TARGET_COPY_OUT_SYSTEM_EXT)/etc/vintf/%,$(2)), \
29    $(error VINTF metadata found in PRODUCT_COPY_FILES: $(1), \
30      use vintf_compatibility_matrix / vintf_fragments instead!)) \
31  $(if $(filter $(TARGET_COPY_OUT_VENDOR)/etc/vintf/% \
32                $(TARGET_COPY_OUT_VENDOR)/manifest.xml \
33                $(TARGET_COPY_OUT_VENDOR)/compatibility_matrix.xml,$(2)), \
34    $(error VINTF metadata found in PRODUCT_COPY_FILES: $(1), \
35      use DEVICE_MANIFEST_FILE / DEVICE_MATRIX_FILE / vintf_compatibility_matrix / vintf_fragments instead!)) \
36  $(if $(filter $(TARGET_COPY_OUT_ODM)/etc/vintf/% \
37                $(TARGET_COPY_OUT_ODM)/etc/manifest%,$(2)), \
38    $(error VINTF metadata found in PRODUCT_COPY_FILES: $(1), \
39      use ODM_MANIFEST_FILES / vintf_fragments instead!)) \
40)
41endef
42
43# Phony target to check PRODUCT_COPY_FILES copy pairs don't contain ELF files
44.PHONY: check-elf-prebuilt-product-copy-files
45check-elf-prebuilt-product-copy-files:
46
47check_elf_prebuilt_product_copy_files := true
48ifneq (,$(filter true,$(BUILD_BROKEN_ELF_PREBUILT_PRODUCT_COPY_FILES)))
49check_elf_prebuilt_product_copy_files :=
50endif
51check_elf_prebuilt_product_copy_files_hint := \
52    found ELF prebuilt in PRODUCT_COPY_FILES, use cc_prebuilt_binary / cc_prebuilt_library_shared instead.
53
54# filter out the duplicate <source file>:<dest file> pairs.
55unique_product_copy_files_pairs :=
56$(foreach cf,$(PRODUCT_COPY_FILES), \
57    $(if $(filter $(unique_product_copy_files_pairs),$(cf)),,\
58        $(eval unique_product_copy_files_pairs += $(cf))))
59unique_product_copy_files_destinations :=
60product_copy_files_ignored :=
61$(foreach cf,$(unique_product_copy_files_pairs), \
62    $(eval _src := $(call word-colon,1,$(cf))) \
63    $(eval _dest := $(call word-colon,2,$(cf))) \
64    $(call check-product-copy-files,$(cf),$(_dest)) \
65    $(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \
66        $(eval product_copy_files_ignored += $(cf)), \
67        $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
68        $(if $(filter %.xml,$(_dest)),\
69            $(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\
70            $(if $(and $(filter %.jar,$(_dest)),$(filter $(basename $(notdir $(_dest))),$(PRODUCT_LOADED_BY_PRIVILEGED_MODULES))),\
71                $(eval $(call copy-and-uncompress-dexs,$(_src),$(_fulldest))), \
72                $(if $(filter init%rc,$(notdir $(_dest)))$(filter %/etc/init,$(dir $(_dest))),\
73                    $(eval $(call copy-init-script-file-checked,$(_src),$(_fulldest))),\
74                    $(if $(and $(filter true,$(check_elf_prebuilt_product_copy_files)), \
75                               $(filter bin lib lib64,$(subst /,$(space),$(_dest)))), \
76                        $(eval $(call copy-non-elf-file-checked,$(_src),$(_fulldest),$(check_elf_prebuilt_product_copy_files_hint))), \
77                        $(eval $(call copy-one-file,$(_src),$(_fulldest))))))) \
78        $(eval unique_product_copy_files_destinations += $(_dest))))
79
80# Dump a list of overriden (and ignored PRODUCT_COPY_FILES entries)
81pcf_ignored_file := $(PRODUCT_OUT)/product_copy_files_ignored.txt
82$(pcf_ignored_file): PRIVATE_IGNORED := $(sort $(product_copy_files_ignored))
83$(pcf_ignored_file):
84	echo "$(PRIVATE_IGNORED)" | tr " " "\n" >$@
85
86$(call dist-for-goals,droidcore-unbundled,$(pcf_ignored_file):logs/$(notdir $(pcf_ignored_file)))
87
88pcf_ignored_file :=
89product_copy_files_ignored :=
90unique_product_copy_files_pairs :=
91unique_product_copy_files_destinations :=
92
93# -----------------------------------------------------------------
94# Returns the max allowed size for an image suitable for hash verification
95# (e.g., boot.img, recovery.img, etc).
96# The value 69632 derives from MAX_VBMETA_SIZE + MAX_FOOTER_SIZE in $(AVBTOOL).
97# $(1): partition size to flash the image
98define get-hash-image-max-size
99$(if $(1), \
100  $(if $(filter true,$(BOARD_AVB_ENABLE)), \
101    $(eval _hash_meta_size := 69632), \
102    $(eval _hash_meta_size := 0)) \
103  $(1)-$(_hash_meta_size))
104endef
105
106# -----------------------------------------------------------------
107# Define rules to copy headers defined in copy_headers.mk
108# If more than one makefile declared a header, print a warning,
109# then copy the last one defined. This matches the previous make
110# behavior.
111has_dup_copy_headers :=
112$(foreach dest,$(ALL_COPIED_HEADERS), \
113    $(eval _srcs := $(ALL_COPIED_HEADERS.$(dest).SRC)) \
114    $(eval _src := $(lastword $(_srcs))) \
115    $(if $(call streq,$(_src),$(_srcs)),, \
116        $(warning Duplicate header copy: $(dest)) \
117        $(warning _ Using $(_src)) \
118        $(warning __ from $(lastword $(ALL_COPIED_HEADERS.$(dest).MAKEFILE))) \
119        $(eval _makefiles := $$(wordlist 1,$(call int_subtract,$(words $(ALL_COPIED_HEADERS.$(dest).MAKEFILE)),1),$$(ALL_COPIED_HEADERS.$$(dest).MAKEFILE))) \
120        $(foreach src,$(wordlist 1,$(call int_subtract,$(words $(_srcs)),1),$(_srcs)), \
121            $(warning _ Ignoring $(src)) \
122            $(warning __ from $(firstword $(_makefiles))) \
123            $(eval _makefiles := $$(wordlist 2,9999,$$(_makefiles)))) \
124        $(eval has_dup_copy_headers := true)) \
125    $(eval $(call copy-one-header,$(_src),$(dest))))
126all_copied_headers: $(ALL_COPIED_HEADERS)
127
128ifdef has_dup_copy_headers
129  has_dup_copy_headers :=
130  $(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)
131endif
132
133$(file >$(PRODUCT_OUT)/.copied_headers_list,$(TARGET_OUT_HEADERS) $(ALL_COPIED_HEADERS))
134
135# -----------------------------------------------------------------
136# docs/index.html
137ifeq (,$(TARGET_BUILD_UNBUNDLED))
138gen := $(OUT_DOCS)/index.html
139ALL_DOCS += $(gen)
140$(gen): frameworks/base/docs/docs-redirect-index.html
141	@mkdir -p $(dir $@)
142	@cp -f $< $@
143endif
144
145ndk_doxygen_out := $(OUT_NDK_DOCS)
146ndk_headers := $(SOONG_OUT_DIR)/ndk/sysroot/usr/include
147ndk_docs_src_dir := frameworks/native/docs
148ndk_doxyfile := $(ndk_docs_src_dir)/Doxyfile
149ifneq ($(wildcard $(ndk_docs_src_dir)),)
150ndk_docs_srcs := $(addprefix $(ndk_docs_src_dir)/,\
151    $(call find-files-in-subdirs,$(ndk_docs_src_dir),"*",.))
152$(ndk_doxygen_out)/index.html: $(ndk_docs_srcs) $(SOONG_OUT_DIR)/ndk.timestamp
153	@mkdir -p $(ndk_doxygen_out)
154	@echo "Generating NDK docs to $(ndk_doxygen_out)"
155	@( cat $(ndk_doxyfile); \
156	    echo "INPUT=$(ndk_headers)"; \
157	    echo "HTML_OUTPUT=$(ndk_doxygen_out)" \
158	) | doxygen -
159
160# Note: Not a part of the docs target because we don't have doxygen available.
161# You can run this target locally if you have doxygen installed.
162ndk-docs: $(ndk_doxygen_out)/index.html
163.PHONY: ndk-docs
164endif
165
166$(call dist-for-goals,sdk,$(API_FINGERPRINT))
167
168INSTALLED_RECOVERYIMAGE_TARGET :=
169# Build recovery image if
170# BUILDING_RECOVERY_IMAGE && !BOARD_USES_RECOVERY_AS_BOOT && !BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT.
171# If BOARD_USES_RECOVERY_AS_BOOT is true, leave empty because INSTALLED_BOOTIMAGE_TARGET is built
172#   with recovery resources.
173# If BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT is true, leave empty to build recovery resources
174#   but not the final recovery image.
175ifdef BUILDING_RECOVERY_IMAGE
176ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
177ifneq ($(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT),true)
178INSTALLED_RECOVERYIMAGE_TARGET := $(PRODUCT_OUT)/recovery.img
179endif
180endif
181endif
182
183include $(BUILD_SYSTEM)/sysprop.mk
184
185# ----------------------------------------------------------------
186
187# -----------------------------------------------------------------
188# sdk-build.prop
189#
190# There are certain things in build.prop that we don't want to
191# ship with the sdk; remove them.
192
193# This must be a list of entire property keys followed by
194# "=" characters, without any internal spaces.
195sdk_build_prop_remove := \
196	ro.build.user= \
197	ro.build.host= \
198	ro.product.brand= \
199	ro.product.manufacturer= \
200	ro.product.device=
201# TODO: Remove this soon-to-be obsolete property
202sdk_build_prop_remove += ro.build.product=
203INSTALLED_SDK_BUILD_PROP_TARGET := $(PRODUCT_OUT)/sdk/sdk-build.prop
204$(INSTALLED_SDK_BUILD_PROP_TARGET): $(INSTALLED_BUILD_PROP_TARGET)
205	@echo SDK buildinfo: $@
206	@mkdir -p $(dir $@)
207	$(hide) grep -v "$(subst $(space),\|,$(strip \
208	            $(sdk_build_prop_remove)))" $< > $@.tmp
209	$(hide) for x in $(sdk_build_prop_remove); do \
210	            echo "$$x"generic >> $@.tmp; done
211	$(hide) mv $@.tmp $@
212
213# -----------------------------------------------------------------
214# declare recovery ramdisk files
215ifeq ($(BUILDING_RECOVERY_IMAGE),true)
216INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP := $(call intermediates-dir-for,PACKAGING,recovery)/ramdisk_files-timestamp
217endif
218
219# -----------------------------------------------------------------
220# Declare vendor ramdisk fragments
221INTERNAL_VENDOR_RAMDISK_FRAGMENTS :=
222
223ifeq (true,$(BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT))
224  ifneq (,$(filter recovery,$(BOARD_VENDOR_RAMDISK_FRAGMENTS)))
225    $(error BOARD_VENDOR_RAMDISK_FRAGMENTS must not contain "recovery" if \
226      BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT is set)
227  endif
228  INTERNAL_VENDOR_RAMDISK_FRAGMENTS += recovery
229  VENDOR_RAMDISK_FRAGMENT.recovery.STAGING_DIR := $(TARGET_RECOVERY_ROOT_OUT)
230  VENDOR_RAMDISK_FRAGMENT.recovery.FILES := $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
231  BOARD_VENDOR_RAMDISK_FRAGMENT.recovery.MKBOOTIMG_ARGS += --ramdisk_type RECOVERY
232  .KATI_READONLY := VENDOR_RAMDISK_FRAGMENT.recovery.STAGING_DIR
233endif
234
235# Validation check and assign default --ramdisk_type.
236$(foreach vendor_ramdisk_fragment,$(BOARD_VENDOR_RAMDISK_FRAGMENTS), \
237  $(if $(and $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).KERNEL_MODULE_DIRS), \
238             $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).PREBUILT)), \
239    $(error Must not specify KERNEL_MODULE_DIRS for prebuilt vendor ramdisk fragment "$(vendor_ramdisk_fragment)": $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).KERNEL_MODULE_DIRS))) \
240  $(eval VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).STAGING_DIR := $(call intermediates-dir-for,PACKAGING,vendor_ramdisk_fragment-stage-$(vendor_ramdisk_fragment))) \
241  $(eval VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).FILES :=) \
242  $(if $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).KERNEL_MODULE_DIRS), \
243    $(if $(filter --ramdisk_type,$(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS)),, \
244      $(eval BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS += --ramdisk_type DLKM))) \
245)
246
247# Create the "kernel module directory" to "vendor ramdisk fragment" inverse mapping.
248$(foreach vendor_ramdisk_fragment,$(BOARD_VENDOR_RAMDISK_FRAGMENTS), \
249  $(foreach kmd,$(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).KERNEL_MODULE_DIRS), \
250    $(eval kmd_vrf := KERNEL_MODULE_DIR_VENDOR_RAMDISK_FRAGMENT_$(kmd)) \
251    $(if $($(kmd_vrf)),$(error Kernel module directory "$(kmd)" belongs to multiple vendor ramdisk fragments: "$($(kmd_vrf))" "$(vendor_ramdisk_fragment)", each kernel module directory should belong to exactly one or none vendor ramdisk fragment)) \
252    $(eval $(kmd_vrf) := $(vendor_ramdisk_fragment)) \
253  ) \
254)
255INTERNAL_VENDOR_RAMDISK_FRAGMENTS += $(BOARD_VENDOR_RAMDISK_FRAGMENTS)
256
257# Strip the list in case of any whitespace.
258INTERNAL_VENDOR_RAMDISK_FRAGMENTS := \
259  $(strip $(INTERNAL_VENDOR_RAMDISK_FRAGMENTS))
260
261# Assign --ramdisk_name for each vendor ramdisk fragment.
262$(foreach vendor_ramdisk_fragment,$(INTERNAL_VENDOR_RAMDISK_FRAGMENTS), \
263  $(if $(filter --ramdisk_name,$(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS)), \
264    $(error Must not specify --ramdisk_name for vendor ramdisk fragment: $(vendor_ramdisk_fragment))) \
265  $(eval BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS += --ramdisk_name $(vendor_ramdisk_fragment)) \
266  $(eval .KATI_READONLY := BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS) \
267)
268
269# -----------------------------------------------------------------
270# kernel modules
271
272# Depmod requires a well-formed kernel version so 0.0 is used as a placeholder.
273DEPMOD_STAGING_SUBDIR :=$= lib/modules/0.0
274
275define copy-and-strip-kernel-module
276$(2): $(1)
277	$(LLVM_STRIP) -o $(2) --strip-debug $(1)
278endef
279
280# $(1): modules list
281# $(2): output dir
282# $(3): mount point
283# $(4): staging dir
284# $(5): module load list
285# $(6): module load list filename
286# $(7): module archive
287# $(8): staging dir for stripped modules
288# $(9): module directory name
289# Returns a list of src:dest pairs to install the modules using copy-many-files.
290define build-image-kernel-modules
291  $(if $(9), \
292    $(eval _dir := $(9)/), \
293    $(eval _dir :=)) \
294  $(foreach module,$(1), \
295    $(eval _src := $(module)) \
296    $(if $(8), \
297      $(eval _src := $(8)/$(notdir $(module))) \
298      $(eval $(call copy-and-strip-kernel-module,$(module),$(_src)))) \
299    $(_src):$(2)/lib/modules/$(_dir)$(notdir $(module))) \
300  $(eval $(call build-image-kernel-modules-depmod,$(1),$(3),$(4),$(5),$(6),$(7),$(2),$(9))) \
301  $(4)/$(DEPMOD_STAGING_SUBDIR)/modules.dep:$(2)/lib/modules/$(_dir)modules.dep \
302  $(4)/$(DEPMOD_STAGING_SUBDIR)/modules.alias:$(2)/lib/modules/$(_dir)modules.alias \
303  $(4)/$(DEPMOD_STAGING_SUBDIR)/modules.softdep:$(2)/lib/modules/$(_dir)modules.softdep \
304  $(4)/$(DEPMOD_STAGING_SUBDIR)/$(6):$(2)/lib/modules/$(_dir)$(6)
305endef
306
307# $(1): modules list
308# $(2): mount point
309# $(3): staging dir
310# $(4): module load list
311# $(5): module load list filename
312# $(6): module archive
313# $(7): output dir
314# $(8): module directory name
315# TODO(b/144844424): If a module archive is being used, this step (which
316# generates obj/PACKAGING/.../modules.dep) also unzips the module archive into
317# the output directory. This should be moved to a module with a
318# LOCAL_POST_INSTALL_CMD so that if modules.dep is removed from the output dir,
319# the archive modules are restored along with modules.dep.
320define build-image-kernel-modules-depmod
321$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: .KATI_IMPLICIT_OUTPUTS := $(3)/$(DEPMOD_STAGING_SUBDIR)/modules.alias $(3)/$(DEPMOD_STAGING_SUBDIR)/modules.softdep $(3)/$(DEPMOD_STAGING_SUBDIR)/$(5)
322$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: $(DEPMOD)
323$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_MODULES := $(1)
324$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_MOUNT_POINT := $(2)
325$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_MODULE_DIR := $(3)/$(DEPMOD_STAGING_SUBDIR)/$(2)/lib/modules/$(8)
326$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_STAGING_DIR := $(3)
327$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_LOAD_MODULES := $(4)
328$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_LOAD_FILE := $(3)/$(DEPMOD_STAGING_SUBDIR)/$(5)
329$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_MODULE_ARCHIVE := $(6)
330$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_OUTPUT_DIR := $(7)
331$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: $(1) $(6)
332	@echo depmod $$(PRIVATE_STAGING_DIR)
333	rm -rf $$(PRIVATE_STAGING_DIR)
334	mkdir -p $$(PRIVATE_MODULE_DIR)
335	$(if $(6),\
336	  unzip -qoDD -d $$(PRIVATE_MODULE_DIR) $$(PRIVATE_MODULE_ARCHIVE); \
337	  mkdir -p $$(PRIVATE_OUTPUT_DIR)/lib; \
338	  cp -r  $(3)/$(DEPMOD_STAGING_SUBDIR)/$(2)/lib/modules $$(PRIVATE_OUTPUT_DIR)/lib/; \
339	  find $$(PRIVATE_MODULE_DIR) -type f -name *.ko | xargs basename -a > $$(PRIVATE_LOAD_FILE); \
340	)
341	$(if $(1),\
342	  cp $$(PRIVATE_MODULES) $$(PRIVATE_MODULE_DIR)/; \
343	  for MODULE in $$(PRIVATE_LOAD_MODULES); do \
344	    basename $$$$MODULE >> $$(PRIVATE_LOAD_FILE); \
345	  done; \
346	)
347	$(DEPMOD) -b $$(PRIVATE_STAGING_DIR) 0.0
348	# Turn paths in modules.dep into absolute paths
349	sed -i.tmp -e 's|\([^: ]*lib/modules/[^: ]*\)|/\1|g' $$(PRIVATE_STAGING_DIR)/$$(DEPMOD_STAGING_SUBDIR)/modules.dep
350	touch $$(PRIVATE_LOAD_FILE)
351endef
352
353# $(1): staging dir
354# $(2): modules list
355# $(3): module load list
356# $(4): module load list filename
357# $(5): output dir
358define module-load-list-copy-paths
359  $(eval $(call build-image-module-load-list,$(1),$(2),$(3),$(4))) \
360  $(1)/$(DEPMOD_STAGING_SUBDIR)/$(4):$(5)/lib/modules/$(4)
361endef
362
363# $(1): staging dir
364# $(2): modules list
365# $(3): module load list
366# $(4): module load list filename
367define build-image-module-load-list
368$(1)/$(DEPMOD_STAGING_SUBDIR)/$(4): PRIVATE_LOAD_MODULES := $(3)
369$(1)/$(DEPMOD_STAGING_SUBDIR)/$(4): $(2)
370	@echo load-list $$(@)
371	@echo '$$(strip $$(notdir $$(PRIVATE_LOAD_MODULES)))' | tr ' ' '\n' > $$(@)
372endef
373
374# $(1): source options file
375# $(2): destination pathname
376# Returns a build rule that checks the syntax of and installs a kernel modules
377# options file. Strip and squeeze any extra space and blank lines.
378# For use via $(eval).
379define build-image-kernel-modules-options-file
380$(2): $(1)
381	@echo "libmodprobe options $$(@)"
382	$(hide) mkdir -p "$$(dir $$@)"
383	$(hide) rm -f "$$@"
384	$(hide) awk <"$$<" >"$$@" \
385	  '/^#/ { print; next } \
386	   NF == 0 { next } \
387	   NF < 2 || $$$$1 != "options" \
388	     { print "Invalid options line " FNR ": " $$$$0 >"/dev/stderr"; \
389	       exit_status = 1; next } \
390	   { $$$$1 = $$$$1; print } \
391	   END { exit exit_status }'
392endef
393
394# $(1): source blocklist file
395# $(2): destination pathname
396# Returns a build rule that checks the syntax of and installs a kernel modules
397# blocklist file. Strip and squeeze any extra space and blank lines.
398# For use via $(eval).
399define build-image-kernel-modules-blocklist-file
400$(2): $(1)
401	@echo "libmodprobe blocklist $$(@)"
402	$(hide) mkdir -p "$$(dir $$@)"
403	$(hide) rm -f "$$@"
404	$(hide) awk <"$$<" >"$$@" \
405	  '/^#/ { print; next } \
406	   NF == 0 { next } \
407	   NF != 2 || $$$$1 != "blocklist" \
408	     { print "Invalid blocklist line " FNR ": " $$$$0 >"/dev/stderr"; \
409	       exit_status = 1; next } \
410	   { $$$$1 = $$$$1; print } \
411	   END { exit exit_status }'
412endef
413
414# $(1): image name
415# $(2): build output directory (TARGET_OUT_VENDOR, TARGET_RECOVERY_ROOT_OUT, etc)
416# $(3): mount point
417# $(4): module load filename
418# $(5): stripped staging directory
419# $(6): kernel module directory name (top is an out of band value for no directory)
420define build-image-kernel-modules-dir
421$(if $(filter top,$(6)),\
422  $(eval _kver :=)$(eval _sep :=),\
423  $(eval _kver := $(6))$(eval _sep :=_))\
424$(if $(5),\
425  $(eval _stripped_staging_dir := $(5)$(_sep)$(_kver)),\
426  $(eval _stripped_staging_dir :=))\
427$(if $(strip $(BOARD_$(1)_KERNEL_MODULES$(_sep)$(_kver))$(BOARD_$(1)_KERNEL_MODULES_ARCHIVE$(_sep)$(_kver))),\
428  $(if $(BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver)),,\
429    $(eval BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver) := $(BOARD_$(1)_KERNEL_MODULES$(_sep)$(_kver)))) \
430  $(call copy-many-files,$(call build-image-kernel-modules,$(BOARD_$(1)_KERNEL_MODULES$(_sep)$(_kver)),$(2),$(3),$(call intermediates-dir-for,PACKAGING,depmod_$(1)$(_sep)$(_kver)),$(BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver)),$(4),$(BOARD_$(1)_KERNEL_MODULES_ARCHIVE$(_sep)$(_kver)),$(_stripped_staging_dir),$(_kver)))) \
431$(if $(_kver), \
432  $(eval _dir := $(_kver)/), \
433  $(eval _dir :=)) \
434$(if $(BOARD_$(1)_KERNEL_MODULES_OPTIONS_FILE$(_sep)$(_kver)), \
435  $(eval $(call build-image-kernel-modules-options-file, \
436    $(BOARD_$(1)_KERNEL_MODULES_OPTIONS_FILE$(_sep)$(_kver)), \
437    $(2)/lib/modules/$(_dir)modules.options)) \
438  $(2)/lib/modules/$(_dir)modules.options) \
439$(if $(BOARD_$(1)_KERNEL_MODULES_BLOCKLIST_FILE$(_sep)$(_kver)), \
440  $(eval $(call build-image-kernel-modules-blocklist-file, \
441    $(BOARD_$(1)_KERNEL_MODULES_BLOCKLIST_FILE$(_sep)$(_kver)), \
442    $(2)/lib/modules/$(_dir)modules.blocklist)) \
443  $(2)/lib/modules/$(_dir)modules.blocklist)
444endef
445
446# $(1): kernel module directory name (top is an out of band value for no directory)
447define build-recovery-as-boot-load
448$(if $(filter top,$(1)),\
449  $(eval _kver :=)$(eval _sep :=),\
450  $(eval _kver := $(1))$(eval _sep :=_))\
451  $(if $(BOARD_GENERIC_RAMDISK_KERNEL_MODULES_LOAD$(_sep)$(_kver)),\
452    $(call copy-many-files,$(call module-load-list-copy-paths,$(call intermediates-dir-for,PACKAGING,ramdisk_module_list$(_sep)$(_kver)),$(BOARD_GENERIC_RAMDISK_KERNEL_MODULES$(_sep)$(_kver)),$(BOARD_GENERIC_RAMDISK_KERNEL_MODULES_LOAD$(_sep)$(_kver)),modules.load,$(TARGET_RECOVERY_ROOT_OUT))))
453endef
454
455# $(1): kernel module directory name (top is an out of band value for no directory)
456define build-vendor-ramdisk-recovery-load
457$(if $(filter top,$(1)),\
458  $(eval _kver :=)$(eval _sep :=),\
459  $(eval _kver := $(1))$(eval _sep :=_))\
460  $(if $(BOARD_VENDOR_RAMDISK_RECOVERY_KERNEL_MODULES_LOAD$(_sep)$(_kver)),\
461    $(call copy-many-files,$(call module-load-list-copy-paths,$(call intermediates-dir-for,PACKAGING,vendor_ramdisk_recovery_module_list$(_sep)$(_kver)),$(BOARD_VENDOR_RAMDISK_KERNEL_MODULES$(_sep)$(_kver)),$(BOARD_VENDOR_RAMDISK_RECOVERY_KERNEL_MODULES_LOAD$(_sep)$(_kver)),modules.load.recovery,$(TARGET_VENDOR_RAMDISK_OUT))))
462endef
463
464# $(1): kernel module directory name (top is an out of band value for no directory)
465define build-vendor-charger-load
466$(if $(filter top,$(1)),\
467  $(eval _kver :=)$(eval _sep :=),\
468  $(eval _kver := $(1))$(eval _sep :=_))\
469  $(if $(BOARD_VENDOR_CHARGER_KERNEL_MODULES_LOAD$(_sep)$(_kver)),\
470    $(call copy-many-files,$(call module-load-list-copy-paths,$(call intermediates-dir-for,PACKAGING,vendor_charger_module_list$(_sep)$(_kver)),$(BOARD_VENDOR_CHARGER_KERNEL_MODULES$(_sep)$(_kver)),$(BOARD_VENDOR_CHARGER_KERNEL_MODULES_LOAD$(_sep)$(_kver)),modules.load.charger,$(TARGET_OUT_VENDOR))))
471endef
472
473ifneq ($(BUILDING_VENDOR_BOOT_IMAGE),true)
474  # If there is no vendor boot partition, store vendor ramdisk kernel modules in the
475  # boot ramdisk.
476  BOARD_GENERIC_RAMDISK_KERNEL_MODULES += $(BOARD_VENDOR_RAMDISK_KERNEL_MODULES)
477  BOARD_GENERIC_RAMDISK_KERNEL_MODULES_LOAD += $(BOARD_VENDOR_RAMDISK_KERNEL_MODULES_LOAD)
478endif
479
480ifeq ($(BOARD_GENERIC_RAMDISK_KERNEL_MODULES_LOAD),)
481  BOARD_GENERIC_RAMDISK_KERNEL_MODULES_LOAD := $(BOARD_GENERIC_RAMDISK_KERNEL_MODULES)
482endif
483
484ifneq ($(strip $(BOARD_GENERIC_RAMDISK_KERNEL_MODULES)),)
485  ifeq ($(BOARD_USES_RECOVERY_AS_BOOT), true)
486    BOARD_RECOVERY_KERNEL_MODULES += $(BOARD_GENERIC_RAMDISK_KERNEL_MODULES)
487  endif
488endif
489
490ifneq ($(BOARD_DO_NOT_STRIP_VENDOR_MODULES),true)
491	VENDOR_STRIPPED_MODULE_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_vendor_stripped)
492else
493	VENDOR_STRIPPED_MODULE_STAGING_DIR :=
494endif
495
496ifneq ($(BOARD_DO_NOT_STRIP_VENDOR_RAMDISK_MODULES),true)
497  VENDOR_RAMDISK_STRIPPED_MODULE_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_vendor_ramdisk_stripped)
498else
499  VENDOR_RAMDISK_STRIPPED_MODULE_STAGING_DIR :=
500endif
501
502BOARD_KERNEL_MODULE_DIRS += top
503$(foreach kmd,$(BOARD_KERNEL_MODULE_DIRS), \
504  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-image-kernel-modules-dir,RECOVERY,$(TARGET_RECOVERY_ROOT_OUT),,modules.load.recovery,,$(kmd))) \
505  $(eval vendor_ramdisk_fragment := $(KERNEL_MODULE_DIR_VENDOR_RAMDISK_FRAGMENT_$(kmd))) \
506  $(if $(vendor_ramdisk_fragment), \
507    $(eval output_dir := $(VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).STAGING_DIR)) \
508    $(eval result_var := VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).FILES) \
509    $(eval ### else ###), \
510    $(eval output_dir := $(TARGET_VENDOR_RAMDISK_OUT)) \
511    $(eval result_var := ALL_DEFAULT_INSTALLED_MODULES)) \
512  $(eval $(result_var) += $(call build-image-kernel-modules-dir,VENDOR_RAMDISK,$(output_dir),,modules.load,$(VENDOR_RAMDISK_STRIPPED_MODULE_STAGING_DIR),$(kmd))) \
513  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-vendor-ramdisk-recovery-load,$(kmd))) \
514  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-image-kernel-modules-dir,VENDOR,$(if $(filter true,$(BOARD_USES_VENDOR_DLKMIMAGE)),$(TARGET_OUT_VENDOR_DLKM),$(TARGET_OUT_VENDOR)),vendor,modules.load,$(VENDOR_STRIPPED_MODULE_STAGING_DIR),$(kmd))) \
515  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-vendor-charger-load,$(kmd))) \
516  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-image-kernel-modules-dir,ODM,$(if $(filter true,$(BOARD_USES_ODM_DLKMIMAGE)),$(TARGET_OUT_ODM_DLKM),$(TARGET_OUT_ODM)),odm,modules.load,,$(kmd))) \
517  $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
518    $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-recovery-as-boot-load,$(kmd))),\
519    $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-image-kernel-modules-dir,GENERIC_RAMDISK,$(TARGET_RAMDISK_OUT),,modules.load,,$(kmd)))))
520
521# -----------------------------------------------------------------
522# Cert-to-package mapping.  Used by the post-build signing tools.
523# Use a macro to add newline to each echo command
524# $1 stem name of the package
525# $2 certificate
526# $3 private key
527# $4 compressed
528# $5 partition tag
529# $6 output file
530define _apkcerts_write_line
531$(hide) echo -n 'name="$(1).apk" certificate="$2" private_key="$3"' >> $6
532$(if $(4), $(hide) echo -n ' compressed="$4"' >> $6)
533$(if $(5), $(hide) echo -n ' partition="$5"' >> $6)
534$(hide) echo '' >> $6
535
536endef
537
538# -----------------------------------------------------------------
539# Merge an individual apkcerts output into the final apkcerts.txt output.
540# Use a macro to make it compatible with _apkcerts_write_line
541# $1 apkcerts file to be merged
542# $2 output file
543define _apkcerts_merge
544$(hide) cat $1 >> $2
545
546endef
547
548name := $(TARGET_PRODUCT)
549ifeq ($(TARGET_BUILD_TYPE),debug)
550  name := $(name)_debug
551endif
552name := $(name)-apkcerts-$(FILE_NAME_TAG)
553intermediates := \
554	$(call intermediates-dir-for,PACKAGING,apkcerts)
555APKCERTS_FILE := $(intermediates)/$(name).txt
556all_apkcerts_files := $(sort $(foreach p,$(PACKAGES),$(PACKAGES.$(p).APKCERTS_FILE)))
557$(APKCERTS_FILE): $(all_apkcerts_files)
558# We don't need to really build all the modules.
559# TODO: rebuild APKCERTS_FILE if any app change its cert.
560$(APKCERTS_FILE):
561	@echo APK certs list: $@
562	@mkdir -p $(dir $@)
563	@rm -f $@
564	$(foreach p,$(sort $(PACKAGES)),\
565	  $(if $(PACKAGES.$(p).APKCERTS_FILE),\
566	    $(call _apkcerts_merge,$(PACKAGES.$(p).APKCERTS_FILE), $@),\
567	    $(if $(PACKAGES.$(p).EXTERNAL_KEY),\
568	      $(call _apkcerts_write_line,$(PACKAGES.$(p).STEM),EXTERNAL,,$(PACKAGES.$(p).COMPRESSED),$(PACKAGES.$(p).PARTITION),$@),\
569	      $(call _apkcerts_write_line,$(PACKAGES.$(p).STEM),$(PACKAGES.$(p).CERTIFICATE),$(PACKAGES.$(p).PRIVATE_KEY),$(PACKAGES.$(p).COMPRESSED),$(PACKAGES.$(p).PARTITION),$@))))
570	# In case value of PACKAGES is empty.
571	$(hide) touch $@
572
573.PHONY: apkcerts-list
574apkcerts-list: $(APKCERTS_FILE)
575
576ifneq (,$(TARGET_BUILD_APPS))
577  $(call dist-for-goals, apps_only, $(APKCERTS_FILE):apkcerts.txt)
578  $(call dist-for-goals, apps_only, $(SOONG_APEX_KEYS_FILE):apexkeys.txt)
579endif
580
581
582# -----------------------------------------------------------------
583# build system stats
584BUILD_SYSTEM_STATS := $(PRODUCT_OUT)/build_system_stats.txt
585$(BUILD_SYSTEM_STATS):
586	@rm -f $@
587	@$(foreach s,$(STATS.MODULE_TYPE),echo "modules_type_make,$(s),$(words $(STATS.MODULE_TYPE.$(s)))" >>$@;)
588	@$(foreach s,$(STATS.SOONG_MODULE_TYPE),echo "modules_type_soong,$(s),$(STATS.SOONG_MODULE_TYPE.$(s))" >>$@;)
589$(call dist-for-goals,droidcore-unbundled,$(BUILD_SYSTEM_STATS))
590
591# -----------------------------------------------------------------
592# build /product/etc/security/avb/system_other.avbpubkey if needed
593ifdef BUILDING_SYSTEM_OTHER_IMAGE
594ifeq ($(BOARD_AVB_ENABLE),true)
595INSTALLED_PRODUCT_SYSTEM_OTHER_AVBKEY_TARGET := $(TARGET_OUT_PRODUCT_ETC)/security/avb/system_other.avbpubkey
596ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_PRODUCT_SYSTEM_OTHER_AVBKEY_TARGET)
597endif # BOARD_AVB_ENABLE
598endif # BUILDING_SYSTEM_OTHER_IMAGE
599
600# -----------------------------------------------------------------
601# Modules ready to be converted to Soong, ordered by how many
602# modules depend on them.
603SOONG_CONV := $(sort $(SOONG_CONV))
604SOONG_CONV_DATA := $(call intermediates-dir-for,PACKAGING,soong_conversion)/soong_conv_data
605$(SOONG_CONV_DATA):
606	@rm -f $@
607	@$(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))),$(sort $(SOONG_CONV.$(s).MAKEFILES)),$(sort $(SOONG_CONV.$(s).INSTALLED))" >>$@;)
608
609SOONG_TO_CONVERT_SCRIPT := build/make/tools/soong_to_convert.py
610SOONG_TO_CONVERT := $(PRODUCT_OUT)/soong_to_convert.txt
611$(SOONG_TO_CONVERT): $(SOONG_CONV_DATA) $(SOONG_TO_CONVERT_SCRIPT)
612	@rm -f $@
613	$(hide) $(SOONG_TO_CONVERT_SCRIPT) $< >$@
614$(call dist-for-goals,droidcore-unbundled,$(SOONG_TO_CONVERT))
615
616MK2BP_CATALOG_SCRIPT := build/make/tools/mk2bp_catalog.py
617MK2BP_REMAINING_HTML := $(PRODUCT_OUT)/mk2bp_remaining.html
618$(MK2BP_REMAINING_HTML): PRIVATE_CODE_SEARCH_BASE_URL := "https://cs.android.com/android/platform/superproject/+/master:"
619$(MK2BP_REMAINING_HTML): $(SOONG_CONV_DATA) $(MK2BP_CATALOG_SCRIPT)
620	@rm -f $@
621	$(hide) $(MK2BP_CATALOG_SCRIPT) \
622		--device=$(TARGET_DEVICE) \
623		--title="Remaining Android.mk files for $(TARGET_DEVICE)-$(TARGET_BUILD_VARIANT)" \
624		--codesearch=$(PRIVATE_CODE_SEARCH_BASE_URL) \
625		--out_dir="$(OUT_DIR)" \
626		--mode=html \
627		> $@
628$(call dist-for-goals,droidcore-unbundled,$(MK2BP_REMAINING_HTML))
629
630MK2BP_REMAINING_CSV := $(PRODUCT_OUT)/mk2bp_remaining.csv
631$(MK2BP_REMAINING_CSV): $(SOONG_CONV_DATA) $(MK2BP_CATALOG_SCRIPT)
632	@rm -f $@
633	$(hide) $(MK2BP_CATALOG_SCRIPT) \
634		--device=$(TARGET_DEVICE) \
635		--out_dir="$(OUT_DIR)" \
636		--mode=csv \
637		> $@
638$(call dist-for-goals,droidcore-unbundled,$(MK2BP_REMAINING_CSV))
639
640# -----------------------------------------------------------------
641# Modules use -Wno-error, or added default -Wall -Werror
642WALL_WERROR := $(PRODUCT_OUT)/wall_werror.txt
643$(WALL_WERROR):
644	@rm -f $@
645	echo "# Modules using -Wno-error" >> $@
646	for m in $(sort $(SOONG_MODULES_USING_WNO_ERROR) $(MODULES_USING_WNO_ERROR)); do echo $$m >> $@; done
647	echo "# Modules added default -Wall" >> $@
648	for m in $(sort $(SOONG_MODULES_ADDED_WALL) $(MODULES_ADDED_WALL)); do echo $$m >> $@; done
649
650$(call dist-for-goals,droidcore-unbundled,$(WALL_WERROR))
651
652# -----------------------------------------------------------------
653# C/C++ flag information for modules
654$(call dist-for-goals,droidcore-unbundled,$(SOONG_MODULES_CFLAG_ARTIFACTS))
655
656# -----------------------------------------------------------------
657# Modules missing profile files
658PGO_PROFILE_MISSING := $(PRODUCT_OUT)/pgo_profile_file_missing.txt
659$(PGO_PROFILE_MISSING):
660	@rm -f $@
661	echo "# Modules missing PGO profile files" >> $@
662	for m in $(SOONG_MODULES_MISSING_PGO_PROFILE_FILE); do echo $$m >> $@; done
663
664$(call dist-for-goals,droidcore,$(PGO_PROFILE_MISSING))
665
666CERTIFICATE_VIOLATION_MODULES_FILENAME := $(PRODUCT_OUT)/certificate_violation_modules.txt
667$(CERTIFICATE_VIOLATION_MODULES_FILENAME):
668	rm -f $@
669	$(foreach m,$(sort $(CERTIFICATE_VIOLATION_MODULES)), echo $(m) >> $@;)
670$(call dist-for-goals,droidcore,$(CERTIFICATE_VIOLATION_MODULES_FILENAME))
671
672# -----------------------------------------------------------------
673# The dev key is used to sign this package, and as the key required
674# for future OTA packages installed by this system.  Actual product
675# deliverables will be re-signed by hand.  We expect this file to
676# exist with the suffixes ".x509.pem" and ".pk8".
677DEFAULT_KEY_CERT_PAIR := $(strip $(DEFAULT_SYSTEM_DEV_CERTIFICATE))
678
679
680# Rules that need to be present for the all targets, even
681# if they don't do anything.
682.PHONY: systemimage
683systemimage:
684
685# -----------------------------------------------------------------
686
687.PHONY: event-log-tags
688
689# Produce an event logs tag file for everything we know about, in order
690# to properly allocate numbers.  Then produce a file that's filtered
691# for what's going to be installed.
692
693all_event_log_tags_file := $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
694
695event_log_tags_file := $(TARGET_OUT)/etc/event-log-tags
696
697# Include tags from all packages that we know about
698all_event_log_tags_src := \
699    $(sort $(foreach m, $(ALL_MODULES), $(ALL_MODULES.$(m).EVENT_LOG_TAGS)))
700
701$(all_event_log_tags_file): PRIVATE_SRC_FILES := $(all_event_log_tags_src)
702$(all_event_log_tags_file): $(all_event_log_tags_src) $(MERGETAGS) build/make/tools/event_log_tags.py
703	$(hide) mkdir -p $(dir $@)
704	$(hide) $(MERGETAGS) -o $@ $(PRIVATE_SRC_FILES)
705
706# Include tags from all packages included in this product, plus all
707# tags that are part of the system (ie, not in a vendor/ or device/
708# directory).
709event_log_tags_src := \
710    $(sort $(foreach m,\
711      $(call resolve-bitness-for-modules,TARGET,$(PRODUCT_PACKAGES)) \
712      $(call module-names-for-tag-list,user), \
713      $(ALL_MODULES.$(m).EVENT_LOG_TAGS)) \
714      $(filter-out vendor/% device/% out/%,$(all_event_log_tags_src)))
715
716$(event_log_tags_file): PRIVATE_SRC_FILES := $(event_log_tags_src)
717$(event_log_tags_file): PRIVATE_MERGED_FILE := $(all_event_log_tags_file)
718$(event_log_tags_file): $(event_log_tags_src) $(all_event_log_tags_file) $(MERGETAGS) build/make/tools/event_log_tags.py
719	$(hide) mkdir -p $(dir $@)
720	$(hide) $(MERGETAGS) -o $@ -m $(PRIVATE_MERGED_FILE) $(PRIVATE_SRC_FILES)
721
722event-log-tags: $(event_log_tags_file)
723
724ALL_DEFAULT_INSTALLED_MODULES += $(event_log_tags_file)
725
726
727# #################################################################
728# Targets for boot/OS images
729# #################################################################
730ifneq ($(strip $(TARGET_NO_BOOTLOADER)),true)
731  INSTALLED_BOOTLOADER_MODULE := $(PRODUCT_OUT)/bootloader
732  ifdef BOARD_PREBUILT_BOOTLOADER
733    $(eval $(call copy-one-file,$(BOARD_PREBUILT_BOOTLOADER),$(INSTALLED_BOOTLOADER_MODULE)))
734    $(call dist-for-goals,dist_files,$(INSTALLED_BOOTLOADER_MODULE))
735  endif # BOARD_PREBUILT_BOOTLOADER
736  ifeq ($(strip $(TARGET_BOOTLOADER_IS_2ND)),true)
737    INSTALLED_2NDBOOTLOADER_TARGET := $(PRODUCT_OUT)/2ndbootloader
738  else
739    INSTALLED_2NDBOOTLOADER_TARGET :=
740  endif
741else
742  INSTALLED_BOOTLOADER_MODULE :=
743  INSTALLED_2NDBOOTLOADER_TARGET :=
744endif # TARGET_NO_BOOTLOADER
745ifneq ($(strip $(TARGET_NO_KERNEL)),true)
746  ifneq ($(strip $(BOARD_KERNEL_BINARIES)),)
747    INSTALLED_KERNEL_TARGET := $(foreach k,$(BOARD_KERNEL_BINARIES), \
748      $(PRODUCT_OUT)/$(k))
749  else
750    INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
751  endif
752else
753  INSTALLED_KERNEL_TARGET :=
754endif
755
756# -----------------------------------------------------------------
757# the root dir
758INTERNAL_ROOT_FILES := $(filter $(TARGET_ROOT_OUT)/%, \
759	$(ALL_GENERATED_SOURCES) \
760	$(ALL_DEFAULT_INSTALLED_MODULES))
761
762INSTALLED_FILES_FILE_ROOT := $(PRODUCT_OUT)/installed-files-root.txt
763INSTALLED_FILES_JSON_ROOT := $(INSTALLED_FILES_FILE_ROOT:.txt=.json)
764$(INSTALLED_FILES_FILE_ROOT): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_ROOT)
765$(INSTALLED_FILES_FILE_ROOT) : $(INTERNAL_ROOT_FILES) $(FILESLIST) $(FILESLIST_UTIL)
766	@echo Installed file list: $@
767	mkdir -p $(dir $@)
768	rm -f $@
769	$(FILESLIST) $(TARGET_ROOT_OUT) > $(@:.txt=.json)
770	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
771
772$(call dist-for-goals, sdk win_sdk sdk_addon, $(INSTALLED_FILES_FILE_ROOT))
773
774#------------------------------------------------------------------
775# dtb
776ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
777INSTALLED_DTBIMAGE_TARGET := $(PRODUCT_OUT)/dtb.img
778ifdef BOARD_PREBUILT_DTBIMAGE_DIR
779$(INSTALLED_DTBIMAGE_TARGET) : $(sort $(wildcard $(BOARD_PREBUILT_DTBIMAGE_DIR)/*.dtb))
780	cat $^ > $@
781endif
782endif
783
784# -----------------------------------------------------------------
785# the ramdisk
786ifdef BUILDING_RAMDISK_IMAGE
787INTERNAL_RAMDISK_FILES := $(filter $(TARGET_RAMDISK_OUT)/%, \
788	$(ALL_GENERATED_SOURCES) \
789	$(ALL_DEFAULT_INSTALLED_MODULES))
790
791INSTALLED_FILES_FILE_RAMDISK := $(PRODUCT_OUT)/installed-files-ramdisk.txt
792INSTALLED_FILES_JSON_RAMDISK := $(INSTALLED_FILES_FILE_RAMDISK:.txt=.json)
793$(INSTALLED_FILES_FILE_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_RAMDISK)
794$(INSTALLED_FILES_FILE_RAMDISK) : $(INTERNAL_RAMDISK_FILES) $(FILESLIST) $(FILESLIST_UTIL)
795	@echo Installed file list: $@
796	mkdir -p $(TARGET_RAMDISK_OUT)
797	mkdir -p $(dir $@)
798	rm -f $@
799	$(FILESLIST) $(TARGET_RAMDISK_OUT) > $(@:.txt=.json)
800	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
801
802$(call dist-for-goals, sdk win_sdk sdk_addon, $(INSTALLED_FILES_FILE_RAMDISK))
803BUILT_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img
804
805ifeq ($(BOARD_RAMDISK_USE_LZ4),true)
806# -l enables the legacy format used by the Linux kernel
807COMPRESSION_COMMAND_DEPS := $(LZ4)
808COMPRESSION_COMMAND := $(LZ4) -l -12 --favor-decSpeed
809RAMDISK_EXT := .lz4
810else
811COMPRESSION_COMMAND_DEPS := $(MINIGZIP)
812COMPRESSION_COMMAND := $(MINIGZIP)
813RAMDISK_EXT := .gz
814endif
815
816# We just build this directly to the install location.
817INSTALLED_RAMDISK_TARGET := $(BUILT_RAMDISK_TARGET)
818$(INSTALLED_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_RAMDISK_FILES) $(INSTALLED_FILES_FILE_RAMDISK) | $(COMPRESSION_COMMAND_DEPS)
819	$(call pretty,"Target ramdisk: $@")
820	$(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RAMDISK_OUT) | $(COMPRESSION_COMMAND) > $@
821
822.PHONY: ramdisk-nodeps
823ramdisk-nodeps: $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
824	@echo "make $@: ignoring dependencies"
825	$(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RAMDISK_OUT) | $(COMPRESSION_COMMAND) > $(INSTALLED_RAMDISK_TARGET)
826
827endif # BUILDING_RAMDISK_IMAGE
828
829# -----------------------------------------------------------------
830# the boot image, which is a collection of other images.
831
832# This is defined here since we may be building recovery as boot
833# below and only want to define this once
834ifneq ($(strip $(BOARD_KERNEL_BINARIES)),)
835  BUILT_BOOTIMAGE_TARGET := $(foreach k,$(subst kernel,boot,$(BOARD_KERNEL_BINARIES)), $(PRODUCT_OUT)/$(k).img)
836else
837  BUILT_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
838endif
839
840INTERNAL_PREBUILT_BOOTIMAGE :=
841
842my_installed_prebuilt_gki_apex := $(strip $(foreach package,$(PRODUCT_PACKAGES),$(if $(ALL_MODULES.$(package).EXTRACTED_BOOT_IMAGE),$(package))))
843ifdef my_installed_prebuilt_gki_apex
844  ifneq (1,$(words $(my_installed_prebuilt_gki_apex))) # len(my_installed_prebuilt_gki_apex) > 1
845    $(error More than one prebuilt GKI APEXes are installed: $(my_installed_prebuilt_gki_apex))
846  endif # len(my_installed_prebuilt_gki_apex) > 1
847
848  ifdef BOARD_PREBUILT_BOOTIMAGE
849    $(error Must not define BOARD_PREBUILT_BOOTIMAGE because a prebuilt GKI APEX is installed: $(my_installed_prebuilt_gki_apex))
850  endif # BOARD_PREBUILT_BOOTIMAGE defined
851
852  my_apex_extracted_boot_image := $(ALL_MODULES.$(my_installed_prebuilt_gki_apex).EXTRACTED_BOOT_IMAGE)
853  INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
854  $(eval $(call copy-one-file,$(my_apex_extracted_boot_image),$(INSTALLED_BOOTIMAGE_TARGET)))
855
856  INTERNAL_PREBUILT_BOOTIMAGE := $(my_apex_extracted_boot_image)
857
858else # my_installed_prebuilt_gki_apex not defined
859
860# $1: boot image target
861# returns the kernel used to make the bootimage
862define bootimage-to-kernel
863  $(if $(BOARD_KERNEL_BINARIES),\
864    $(PRODUCT_OUT)/$(subst .img,,$(subst boot,kernel,$(notdir $(1)))),\
865    $(INSTALLED_KERNEL_TARGET))
866endef
867
868ifdef BOARD_BOOTIMAGE_PARTITION_SIZE
869  BOARD_KERNEL_BOOTIMAGE_PARTITION_SIZE := $(BOARD_BOOTIMAGE_PARTITION_SIZE)
870endif
871
872# $1: boot image file name
873# $2: boot image variant (boot, boot-debug, boot-test-harness)
874define get-bootimage-partition-size
875  $(BOARD_$(call to-upper,$(subst .img,,$(subst $(2),kernel,$(notdir $(1)))))_BOOTIMAGE_PARTITION_SIZE)
876endef
877
878ifneq ($(strip $(TARGET_NO_KERNEL)),true)
879INTERNAL_BOOTIMAGE_ARGS := \
880	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET))
881
882ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
883INTERNAL_BOOTIMAGE_ARGS += --ramdisk $(INSTALLED_RAMDISK_TARGET)
884endif
885
886ifndef BUILDING_VENDOR_BOOT_IMAGE
887ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
888  INTERNAL_BOOTIMAGE_ARGS += --dtb $(INSTALLED_DTBIMAGE_TARGET)
889endif
890endif
891
892INTERNAL_BOOTIMAGE_FILES := $(filter-out --%,$(INTERNAL_BOOTIMAGE_ARGS))
893
894ifeq ($(PRODUCT_SUPPORTS_VERITY),true)
895ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
896VERITY_KEYID := veritykeyid=id:`openssl x509 -in $(PRODUCT_VERITY_SIGNING_KEY).x509.pem -text \
897                | grep keyid | sed 's/://g' | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]' | sed 's/keyid//g'`
898endif
899endif
900
901INTERNAL_KERNEL_CMDLINE := $(strip $(INTERNAL_KERNEL_CMDLINE) buildvariant=$(TARGET_BUILD_VARIANT) $(VERITY_KEYID))
902
903# kernel cmdline/base/pagesize in boot.
904# - If using GKI, use GENERIC_KERNEL_CMDLINE. Remove kernel base and pagesize because they are
905#   device-specific.
906# - If not using GKI:
907#   - If building vendor_boot, INTERNAL_KERNEL_CMDLINE, base and pagesize goes in vendor_boot.
908#   - Otherwise, put them in boot.
909ifeq (true,$(BOARD_USES_GENERIC_KERNEL_IMAGE))
910  ifdef GENERIC_KERNEL_CMDLINE
911    INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(GENERIC_KERNEL_CMDLINE)"
912  endif
913else ifndef BUILDING_VENDOR_BOOT_IMAGE # && BOARD_USES_GENERIC_KERNEL_IMAGE != true
914  ifdef INTERNAL_KERNEL_CMDLINE
915    INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)"
916  endif
917  ifdef BOARD_KERNEL_BASE
918    INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
919  endif
920  ifdef BOARD_KERNEL_PAGESIZE
921    INTERNAL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
922  endif
923endif # BUILDING_VENDOR_BOOT_IMAGE == "" && BOARD_USES_GENERIC_KERNEL_IMAGE != true
924
925INTERNAL_MKBOOTIMG_VERSION_ARGS := \
926    --os_version $(PLATFORM_VERSION_LAST_STABLE) \
927    --os_patch_level $(PLATFORM_SECURITY_PATCH)
928
929ifdef BOARD_GKI_SIGNING_KEY_PATH
930ifndef BOARD_GKI_SIGNING_ALGORITHM
931$(error BOARD_GKI_SIGNING_ALGORITHM should be defined with BOARD_GKI_SIGNING_KEY_PATH)
932endif
933INTERNAL_MKBOOTIMG_GKI_SINGING_ARGS := \
934    --gki_signing_key $(BOARD_GKI_SIGNING_KEY_PATH) \
935    --gki_signing_algorithm $(BOARD_GKI_SIGNING_ALGORITHM) \
936    --gki_signing_avbtool_path $(AVBTOOL)
937endif
938
939# Using double quote to pass BOARD_GKI_SIGNING_SIGNATURE_ARGS as a single string
940# to MKBOOTIMG, although it may contain multiple args.
941ifdef BOARD_GKI_SIGNING_SIGNATURE_ARGS
942INTERNAL_MKBOOTIMG_GKI_SINGING_ARGS += \
943    --gki_signing_signature_args "$(BOARD_GKI_SIGNING_SIGNATURE_ARGS)"
944endif
945
946# Define these only if we are building boot
947ifdef BUILDING_BOOT_IMAGE
948INSTALLED_BOOTIMAGE_TARGET := $(BUILT_BOOTIMAGE_TARGET)
949
950ifeq ($(TARGET_BOOTIMAGE_USE_EXT2),true)
951$(error TARGET_BOOTIMAGE_USE_EXT2 is not supported anymore)
952endif # TARGET_BOOTIMAGE_USE_EXT2
953
954$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET), $(eval $(call add-dependency,$(b),$(call bootimage-to-kernel,$(b)))))
955
956ifeq (true,$(BOARD_AVB_ENABLE))
957
958# $1: boot image target
959define build_boot_board_avb_enabled
960  $(MKBOOTIMG) --kernel $(call bootimage-to-kernel,$(1)) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) \
961               $(INTERNAL_MKBOOTIMG_GKI_SINGING_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1)
962  $(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(call get-bootimage-partition-size,$(1),boot)))
963  $(AVBTOOL) add_hash_footer \
964          --image $(1) \
965          --partition_size $(call get-bootimage-partition-size,$(1),boot) \
966          --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) \
967          $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)
968endef
969
970$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(AVBTOOL) $(INTERNAL_BOOTIMAGE_FILES) $(BOARD_AVB_BOOT_KEY_PATH) $(BOARD_GKI_SIGNING_KEY_PATH)
971	$(call pretty,"Target boot image: $@")
972	$(call build_boot_board_avb_enabled,$@)
973
974.PHONY: bootimage-nodeps
975bootimage-nodeps: $(MKBOOTIMG) $(AVBTOOL) $(BOARD_AVB_BOOT_KEY_PATH) $(BOARD_GKI_SIGNING_KEY_PATH)
976	@echo "make $@: ignoring dependencies"
977	$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(call build_boot_board_avb_enabled,$(b)))
978
979else ifeq (true,$(PRODUCT_SUPPORTS_BOOT_SIGNER)) # BOARD_AVB_ENABLE != true
980
981# $1: boot image target
982define build_boot_supports_boot_signer
983  $(MKBOOTIMG) --kernel $(call bootimage-to-kernel,$(1)) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1)
984  $(BOOT_SIGNER) /boot $@ $(PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1)
985  $(call assert-max-image-size,$(1),$(call get-bootimage-partition-size,$(1),boot))
986endef
987
988$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(BOOT_SIGNER)
989	$(call pretty,"Target boot image: $@")
990	$(call build_boot_supports_boot_signer,$@)
991
992.PHONY: bootimage-nodeps
993bootimage-nodeps: $(MKBOOTIMG) $(BOOT_SIGNER)
994	@echo "make $@: ignoring dependencies"
995	$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(call build_boot_supports_boot_signer,$(b)))
996
997else ifeq (true,$(PRODUCT_SUPPORTS_VBOOT)) # PRODUCT_SUPPORTS_BOOT_SIGNER != true
998
999# $1: boot image target
1000define build_boot_supports_vboot
1001  $(MKBOOTIMG) --kernel $(call bootimage-to-kernel,$(1)) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1).unsigned
1002  $(VBOOT_SIGNER) $(FUTILITY) $(1).unsigned $(PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(1).keyblock $(1)
1003  $(call assert-max-image-size,$(1),$(call get-bootimage-partition-size,$(1),boot))
1004endef
1005
1006$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(VBOOT_SIGNER) $(FUTILITY)
1007	$(call pretty,"Target boot image: $@")
1008	$(call build_boot_supports_vboot,$@)
1009
1010.PHONY: bootimage-nodeps
1011bootimage-nodeps: $(MKBOOTIMG) $(VBOOT_SIGNER) $(FUTILITY)
1012	@echo "make $@: ignoring dependencies"
1013	$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(call build_boot_supports_vboot,$(b)))
1014
1015else # PRODUCT_SUPPORTS_VBOOT != true
1016
1017# $1: boot image target
1018define build_boot_novboot
1019  $(MKBOOTIMG) --kernel $(call bootimage-to-kernel,$(1)) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1)
1020  $(call assert-max-image-size,$1,$(call get-bootimage-partition-size,$(1),boot))
1021endef
1022
1023$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES)
1024	$(call pretty,"Target boot image: $@")
1025	$(call build_boot_novboot,$@)
1026
1027.PHONY: bootimage-nodeps
1028bootimage-nodeps: $(MKBOOTIMG)
1029	@echo "make $@: ignoring dependencies"
1030	$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(call build_boot_novboot,$(b)))
1031
1032endif # BOARD_AVB_ENABLE
1033endif # BUILDING_BOOT_IMAGE
1034
1035else # TARGET_NO_KERNEL == "true"
1036ifdef BOARD_PREBUILT_BOOTIMAGE
1037INTERNAL_PREBUILT_BOOTIMAGE := $(BOARD_PREBUILT_BOOTIMAGE)
1038INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
1039
1040ifeq ($(BOARD_AVB_ENABLE),true)
1041$(INSTALLED_BOOTIMAGE_TARGET): $(INTERNAL_PREBUILT_BOOTIMAGE) $(AVBTOOL) $(BOARD_AVB_BOOT_KEY_PATH)
1042	cp $(INTERNAL_PREBUILT_BOOTIMAGE) $@
1043	$(AVBTOOL) add_hash_footer \
1044	    --image $@ \
1045	    --partition_size $(BOARD_BOOTIMAGE_PARTITION_SIZE) \
1046	    --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) \
1047	    $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)
1048else
1049$(INSTALLED_BOOTIMAGE_TARGET): $(INTERNAL_PREBUILT_BOOTIMAGE)
1050	cp $(INTERNAL_PREBUILT_BOOTIMAGE) $@
1051endif # BOARD_AVB_ENABLE
1052
1053else # BOARD_PREBUILT_BOOTIMAGE not defined
1054INSTALLED_BOOTIMAGE_TARGET :=
1055endif # BOARD_PREBUILT_BOOTIMAGE
1056endif # TARGET_NO_KERNEL
1057endif # my_installed_prebuilt_gki_apex not defined
1058
1059my_apex_extracted_boot_image :=
1060my_installed_prebuilt_gki_apex :=
1061
1062# -----------------------------------------------------------------
1063# vendor boot image
1064ifeq ($(BUILDING_VENDOR_BOOT_IMAGE),true)
1065
1066ifeq ($(PRODUCT_SUPPORTS_VERITY),true)
1067  $(error vboot 1.0 does not support vendor_boot partition)
1068endif
1069
1070INTERNAL_VENDOR_RAMDISK_FILES := $(filter $(TARGET_VENDOR_RAMDISK_OUT)/%, \
1071    $(ALL_GENERATED_SOURCES) \
1072    $(ALL_DEFAULT_INSTALLED_MODULES))
1073
1074INTERNAL_VENDOR_RAMDISK_TARGET := $(call intermediates-dir-for,PACKAGING,vendor_boot)/vendor_ramdisk.cpio$(RAMDISK_EXT)
1075
1076# Exclude recovery files in the default vendor ramdisk if including a standalone
1077# recovery ramdisk in vendor_boot.
1078ifeq (true,$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT))
1079ifneq (true,$(BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT))
1080$(INTERNAL_VENDOR_RAMDISK_TARGET): $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
1081$(INTERNAL_VENDOR_RAMDISK_TARGET): PRIVATE_ADDITIONAL_DIR := $(TARGET_RECOVERY_ROOT_OUT)
1082endif
1083endif
1084
1085$(INTERNAL_VENDOR_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_VENDOR_RAMDISK_FILES) | $(COMPRESSION_COMMAND_DEPS)
1086	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_VENDOR_RAMDISK_OUT) $(PRIVATE_ADDITIONAL_DIR) | $(COMPRESSION_COMMAND) > $@
1087
1088ifeq (true,$(BOARD_BUILD_VENDOR_RAMDISK_IMAGE))
1089INSTALLED_VENDOR_RAMDISK_TARGET := $(PRODUCT_OUT)/vendor_ramdisk.img
1090$(INSTALLED_VENDOR_RAMDISK_TARGET): $(INTERNAL_VENDOR_RAMDISK_TARGET)
1091	$(call pretty,"Target vendor ramdisk: $@")
1092	$(copy-file-to-target)
1093endif
1094
1095INSTALLED_FILES_FILE_VENDOR_RAMDISK := $(PRODUCT_OUT)/installed-files-vendor-ramdisk.txt
1096INSTALLED_FILES_JSON_VENDOR_RAMDISK := $(INSTALLED_FILES_FILE_VENDOR_RAMDISK:.txt=.json)
1097$(INSTALLED_FILES_FILE_VENDOR_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_VENDOR_RAMDISK)
1098$(INSTALLED_FILES_FILE_VENDOR_RAMDISK): $(INTERNAL_VENDOR_RAMDISK_TARGET)
1099$(INSTALLED_FILES_FILE_VENDOR_RAMDISK): $(INTERNAL_VENDOR_RAMDISK_FILES) $(FILESLIST) $(FILESLIST_UTIL)
1100	@echo Installed file list: $@
1101	mkdir -p $(dir $@)
1102	rm -f $@
1103	$(FILESLIST) $(TARGET_VENDOR_RAMDISK_OUT) > $(@:.txt=.json)
1104	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
1105
1106ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
1107  INTERNAL_VENDOR_BOOTIMAGE_ARGS += --dtb $(INSTALLED_DTBIMAGE_TARGET)
1108endif
1109ifdef BOARD_KERNEL_BASE
1110  INTERNAL_VENDOR_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
1111endif
1112ifdef BOARD_KERNEL_PAGESIZE
1113  INTERNAL_VENDOR_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
1114endif
1115ifdef INTERNAL_KERNEL_CMDLINE
1116  INTERNAL_VENDOR_BOOTIMAGE_ARGS += --vendor_cmdline "$(INTERNAL_KERNEL_CMDLINE)"
1117endif
1118
1119ifdef INTERNAL_BOOTCONFIG
1120  INTERNAL_VENDOR_BOOTCONFIG_TARGET := $(PRODUCT_OUT)/vendor-bootconfig.img
1121  $(INTERNAL_VENDOR_BOOTCONFIG_TARGET):
1122	rm -f $@
1123	$(foreach param,$(INTERNAL_BOOTCONFIG), \
1124	 printf "%s\n" $(param) >> $@;)
1125  INTERNAL_VENDOR_BOOTIMAGE_ARGS += --vendor_bootconfig $(INTERNAL_VENDOR_BOOTCONFIG_TARGET)
1126endif
1127
1128# $(1): Build target name
1129# $(2): Staging dir to be compressed
1130# $(3): Build dependencies
1131define build-vendor-ramdisk-fragment-target
1132$(1): $(3) $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
1133	$(MKBOOTFS) -d $(TARGET_OUT) $(2) | $(COMPRESSION_COMMAND) > $$@
1134endef
1135
1136# $(1): Ramdisk name
1137define build-vendor-ramdisk-fragment
1138$(strip \
1139  $(eval build_target := $(call intermediates-dir-for,PACKAGING,vendor_ramdisk_fragments)/$(1).cpio$(RAMDISK_EXT)) \
1140  $(eval $(call build-vendor-ramdisk-fragment-target,$(build_target),$(VENDOR_RAMDISK_FRAGMENT.$(1).STAGING_DIR),$(VENDOR_RAMDISK_FRAGMENT.$(1).FILES))) \
1141  $(build_target) \
1142)
1143endef
1144
1145# $(1): Ramdisk name
1146# $(2): Prebuilt file path
1147define build-prebuilt-vendor-ramdisk-fragment
1148$(strip \
1149  $(eval build_target := $(call intermediates-dir-for,PACKAGING,prebuilt_vendor_ramdisk_fragments)/$(1)) \
1150  $(eval $(call copy-one-file,$(2),$(build_target))) \
1151  $(build_target) \
1152)
1153endef
1154
1155INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS :=
1156INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS :=
1157
1158$(foreach vendor_ramdisk_fragment,$(INTERNAL_VENDOR_RAMDISK_FRAGMENTS), \
1159  $(eval prebuilt_vendor_ramdisk_fragment_file := $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).PREBUILT)) \
1160  $(if $(prebuilt_vendor_ramdisk_fragment_file), \
1161    $(eval vendor_ramdisk_fragment_target := $(call build-prebuilt-vendor-ramdisk-fragment,$(vendor_ramdisk_fragment),$(prebuilt_vendor_ramdisk_fragment_file))) \
1162    $(eval ### else ###), \
1163    $(eval vendor_ramdisk_fragment_target := $(call build-vendor-ramdisk-fragment,$(vendor_ramdisk_fragment)))) \
1164  $(eval INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS += $(vendor_ramdisk_fragment_target)) \
1165  $(eval INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS += $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS) --vendor_ramdisk_fragment $(vendor_ramdisk_fragment_target)) \
1166)
1167
1168INSTALLED_VENDOR_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/vendor_boot.img
1169$(INSTALLED_VENDOR_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INSTALLED_DTBIMAGE_TARGET)
1170$(INSTALLED_VENDOR_BOOTIMAGE_TARGET): $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS) $(INTERNAL_VENDOR_BOOTCONFIG_TARGET)
1171ifeq ($(BOARD_AVB_ENABLE),true)
1172$(INSTALLED_VENDOR_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_VENDOR_BOOTIMAGE_KEY_PATH)
1173	$(call pretty,"Target vendor_boot image: $@")
1174	$(MKBOOTIMG) $(INTERNAL_VENDOR_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --vendor_ramdisk $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS) --vendor_boot $@
1175	$(call assert-max-image-size,$@,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE))
1176	$(AVBTOOL) add_hash_footer \
1177           --image $@ \
1178	   --partition_size $(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE) \
1179	   --partition_name vendor_boot $(INTERNAL_AVB_VENDOR_BOOT_SIGNING_ARGS) \
1180	   $(BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS)
1181else
1182$(INSTALLED_VENDOR_BOOTIMAGE_TARGET):
1183	$(call pretty,"Target vendor_boot image: $@")
1184	$(MKBOOTIMG) $(INTERNAL_VENDOR_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --vendor_ramdisk $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS) --vendor_boot $@
1185	$(call assert-max-image-size,$@,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE))
1186endif
1187endif # BUILDING_VENDOR_BOOT_IMAGE
1188
1189# -----------------------------------------------------------------
1190# NOTICE files
1191#
1192# We are required to publish the licenses for all code under BSD, GPL and
1193# Apache licenses (and possibly other more exotic ones as well). We err on the
1194# side of caution, so the licenses for other third-party code are included here
1195# too.
1196#
1197# This needs to be before the systemimage rules, because it adds to
1198# ALL_DEFAULT_INSTALLED_MODULES, which those use to pick which files
1199# go into the systemimage.
1200
1201.PHONY: notice_files
1202
1203# Create the rule to combine the files into text and html/xml forms
1204# $(1) - xml_excluded_system_product_odm_vendor_dlkm_odm_dlkm|
1205#        xml_excluded_vendor_product_odm_vendor_dlkm_odm_dlkm|
1206#        xml_product|xml_odm|xml_system_ext|xml_system|xml_vendor_dlkm|
1207#        xml_odm_dlkm|html
1208# $(2) - Plain text output file
1209# $(3) - HTML/XML output file
1210# $(4) - File title
1211# $(5) - Directory to use.  Notice files are all $(5)/src.  Other
1212#		 directories in there will be used for scratch
1213# $(6) - Dependencies for the output files
1214# $(7) - Directories to exclude
1215#
1216# The algorithm here is that we go collect a hash for each of the notice
1217# files and write the names of the files that match that hash.  Then
1218# to generate the real files, we go print out all of the files and their
1219# hashes.
1220#
1221# These rules are fairly complex, so they depend on this makefile so if
1222# it changes, they'll run again.
1223#
1224# TODO: We could clean this up so that we just record the locations of the
1225# original notice files instead of making rules to copy them somwehere.
1226# Then we could traverse that without quite as much bash drama.
1227define combine-notice-files
1228$(2): PRIVATE_MESSAGE := $(4)
1229$(2): PRIVATE_DIR := $(5)
1230$(2): .KATI_IMPLICIT_OUTPUTS := $(3)
1231$(2): $(6) $(BUILD_SYSTEM)/Makefile build/make/tools/generate-notice-files.py
1232	build/make/tools/generate-notice-files.py --text-output $(2) $(foreach xdir, $(7), -e $(xdir) )\
1233	    $(if $(filter $(1),xml_excluded_vendor_product_odm_vendor_dlkm_odm_dlkm),-e vendor -e product -e system_ext -e odm -e vendor_dlkm -e odm_dlkm --xml-output, \
1234	      $(if $(filter $(1),xml_excluded_system_product_odm_vendor_dlkm_odm_dlkm),-e system -e product -e system_ext -e odm -e vendor_dlkm -e odm_dlkm --xml-output, \
1235	        $(if $(filter $(1),xml_product),-i product --xml-output, \
1236	          $(if $(filter $(1),xml_system_ext),-i system_ext --xml-output, \
1237	            $(if $(filter $(1),xml_system),-i system --xml-output, \
1238	              $(if $(filter $(1),xml_odm),-i odm --xml-output, \
1239	                $(if $(filter $(1),xml_vendor_dlkm),-i vendor_dlkm --xml-output, \
1240	                  $(if $(filter $(1),xml_odm_dlkm),-i odm_dlkm --xml-output, \
1241	                    --html-output)))))))) $(3) \
1242	    -t $$(PRIVATE_MESSAGE) $$(foreach dir,$$(sort $$(PRIVATE_DIR)), -s $$(dir)/src)
1243notice_files: $(2) $(3)
1244endef
1245
1246# Notice file logic isn't relevant for TARGET_BUILD_APPS
1247ifndef TARGET_BUILD_APPS
1248
1249# TODO These intermediate NOTICE.txt/NOTICE.html files should go into
1250# TARGET_OUT_NOTICE_FILES now that the notice files are gathered from
1251# the src subdirectory.
1252target_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE.txt
1253tools_notice_file_txt := $(HOST_OUT_INTERMEDIATES)/NOTICE.txt
1254tools_notice_file_html := $(HOST_OUT_INTERMEDIATES)/NOTICE.html
1255kernel_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/kernel.txt
1256winpthreads_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/winpthreads.txt
1257
1258# Some targets get included under $(PRODUCT_OUT) for debug symbols or other
1259# reasons--not to be flashed onto any device. Targets under these directories
1260# need no associated notice file on the device UI.
1261exclude_target_dirs := apex
1262
1263# TODO(b/69865032): Make PRODUCT_NOTICE_SPLIT the default behavior.
1264ifneq ($(PRODUCT_NOTICE_SPLIT),true)
1265target_notice_file_html := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html
1266target_notice_file_html_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html.gz
1267installed_notice_html_or_xml_gz := $(TARGET_OUT)/etc/NOTICE.html.gz
1268$(eval $(call combine-notice-files, html, \
1269	        $(target_notice_file_txt), \
1270	        $(target_notice_file_html), \
1271	        "Notices for files contained in the filesystem images in this directory:", \
1272	        $(TARGET_OUT_NOTICE_FILES), \
1273	        $(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file), \
1274	        $(exclude_target_dirs)))
1275$(target_notice_file_html_gz): $(target_notice_file_html) | $(MINIGZIP)
1276	$(hide) $(MINIGZIP) -9 < $< > $@
1277$(installed_notice_html_or_xml_gz): $(target_notice_file_html_gz)
1278	$(copy-file-to-target)
1279else
1280target_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE.xml
1281target_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.xml.gz
1282installed_notice_html_or_xml_gz := $(TARGET_OUT)/etc/NOTICE.xml.gz
1283
1284target_vendor_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.txt
1285target_vendor_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.xml
1286target_vendor_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.xml.gz
1287installed_vendor_notice_xml_gz := $(TARGET_OUT_VENDOR)/etc/NOTICE.xml.gz
1288
1289target_product_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT.txt
1290target_product_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT.xml
1291target_product_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT.xml.gz
1292installed_product_notice_xml_gz := $(TARGET_OUT_PRODUCT)/etc/NOTICE.xml.gz
1293
1294target_system_ext_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_SYSTEM_EXT.txt
1295target_system_ext_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE_SYSTEM_EXT.xml
1296target_system_ext_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_SYSTEM_EXT.xml.gz
1297installed_system_ext_notice_xml_gz := $(TARGET_OUT_SYSTEM_EXT)/etc/NOTICE.xml.gz
1298
1299target_odm_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_ODM.txt
1300target_odm_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE_ODM.xml
1301target_odm_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_ODM.xml.gz
1302installed_odm_notice_xml_gz := $(TARGET_OUT_ODM)/etc/NOTICE.xml.gz
1303
1304target_vendor_dlkm_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR_DLKM.txt
1305target_vendor_dlkm_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR_DLKM.xml
1306target_vendor_dlkm_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR_DLKM.xml.gz
1307installed_vendor_dlkm_notice_xml_gz := $(TARGET_OUT_VENDOR_DLKM)/etc/NOTICE.xml.gz
1308
1309target_odm_dlkm_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_ODM_DLKM.txt
1310target_odm_dlkm_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE_ODM_DLKM.xml
1311target_odm_dlkm_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_ODM_DLKM.xml.gz
1312installed_odm_dlkm_notice_xml_gz := $(TARGET_OUT_ODM_DLKM)/etc/NOTICE.xml.gz
1313
1314# Notice files are copied to TARGET_OUT_NOTICE_FILES as a side-effect of their module
1315# being built. A notice xml file must depend on all modules that could potentially
1316# install a license file relevant to it.
1317license_modules := $(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file)
1318# Only files copied to a system image need system image notices.
1319license_modules := $(filter $(PRODUCT_OUT)/%,$(license_modules))
1320# Phonys/fakes don't have notice files (though their deps might)
1321license_modules := $(filter-out $(TARGET_OUT_FAKE)/%,$(license_modules))
1322# testcases are not relevant to the system image.
1323license_modules := $(filter-out $(TARGET_OUT_TESTCASES)/%,$(license_modules))
1324# filesystem images: system, vendor, product, system_ext, odm, vendor_dlkm, and odm_dlkm
1325license_modules_system := $(filter $(TARGET_OUT)/%,$(license_modules))
1326# system_other is relevant to system partition.
1327license_modules_system += $(filter $(TARGET_OUT_SYSTEM_OTHER)/%,$(license_modules))
1328license_modules_vendor := $(filter $(TARGET_OUT_VENDOR)/%,$(license_modules))
1329license_modules_product := $(filter $(TARGET_OUT_PRODUCT)/%,$(license_modules))
1330license_modules_system_ext := $(filter $(TARGET_OUT_SYSTEM_EXT)/%,$(license_modules))
1331license_modules_odm := $(filter $(TARGET_OUT_ODM)/%,$(license_modules))
1332license_modules_vendor_dlkm := $(filter $(TARGET_OUT_VENDOR_DLKM)/%,$(license_modules))
1333license_modules_odm_dlkm := $(filter $(TARGET_OUT_ODM_DLKM)/%,$(license_modules))
1334license_modules_agg := $(license_modules_system) \
1335                       $(license_modules_vendor) \
1336                       $(license_modules_product) \
1337                       $(license_modules_system_ext) \
1338                       $(license_modules_odm) \
1339                       $(license_modules_vendor_dlkm) \
1340                       $(license_modules_odm_dlkm)
1341# targets used for debug symbols only and do not get copied to the device
1342license_modules_symbols_only := $(filter $(PRODUCT_OUT)/apex/%,$(license_modules))
1343
1344license_modules_rest := $(filter-out $(license_modules_agg),$(license_modules))
1345license_modules_rest := $(filter-out $(license_modules_symbols_only),$(license_modules_rest))
1346
1347# Identify the other targets we expect to have notices for:
1348# targets copied to the device but are not readable by the UI (e.g. must boot
1349# into a different partition to read or don't have an associated /etc
1350# directory) must have their notices built somewhere readable.
1351license_modules_rehomed := $(filter-out $(PRODUCT_OUT)/%/%,$(license_modules_rest))  # files in root have no /etc
1352license_modules_rehomed += $(filter $(PRODUCT_OUT)/recovery/%,$(license_modules_rest))
1353license_modules_rehomed += $(filter $(PRODUCT_OUT)/root/%,$(license_modules_rest))
1354license_modules_rehomed += $(filter $(PRODUCT_OUT)/data/%,$(license_modules_rest))
1355license_modules_rehomed += $(filter $(PRODUCT_OUT)/ramdisk/%,$(license_modules_rest))
1356license_modules_rehomed += $(filter $(PRODUCT_OUT)/debug_ramdisk/%,$(license_modules_rest))
1357license_modules_rehomed += $(filter $(PRODUCT_OUT)/vendor_ramdisk/%,$(license_modules_rest))
1358license_modules_rehomed += $(filter $(PRODUCT_OUT)/persist/%,$(license_modules_rest))
1359license_modules_rehomed += $(filter $(PRODUCT_OUT)/persist.img,$(license_modules_rest))
1360license_modules_rehomed += $(filter $(PRODUCT_OUT)/system_other/%,$(license_modules_rest))
1361license_modules_rehomed += $(filter $(PRODUCT_OUT)/kernel%,$(license_modules_rest))
1362license_modules_rehomed += $(filter $(PRODUCT_OUT)/%.img,$(license_modules_rest))
1363license_modules_rehomed += $(filter $(PRODUCT_OUT)/%.bin,$(license_modules_rest))
1364
1365# after removing targets in system images, targets reported in system images, and
1366# targets used for debug symbols that do not need notices, nothing must remain.
1367license_modules_rest := $(filter-out $(license_modules_rehomed),$(license_modules_rest))
1368$(call maybe-print-list-and-error, $(license_modules_rest), \
1369        "Targets added under $(PRODUCT_OUT)/ unaccounted for notice handling.")
1370
1371# If we are building in a configuration that includes a prebuilt vendor.img, we can't
1372# update its notice file, so include those notices in the system partition instead
1373ifdef BOARD_PREBUILT_VENDORIMAGE
1374license_modules_system += $(license_modules_rehomed)
1375system_xml_directories := xml_excluded_vendor_product_odm_vendor_dlkm_odm_dlkm
1376system_notice_file_message := "Notices for files contained in all filesystem images except vendor/system_ext/product/odm/vendor_dlkm/odm_dlkm in this directory:"
1377else
1378license_modules_vendor += $(license_modules_rehomed)
1379system_xml_directories := xml_system
1380system_notice_file_message := "Notices for files contained in the system filesystem image in this directory:"
1381endif
1382
1383$(eval $(call combine-notice-files, $(system_xml_directories), \
1384	        $(target_notice_file_txt), \
1385	        $(target_notice_file_xml), \
1386	        $(system_notice_file_message), \
1387	        $(TARGET_OUT_NOTICE_FILES), \
1388	        $(license_modules_system), \
1389	        $(exclude_target_dirs)))
1390$(eval $(call combine-notice-files, xml_excluded_system_product_odm_vendor_dlkm_odm_dlkm, \
1391	        $(target_vendor_notice_file_txt), \
1392	        $(target_vendor_notice_file_xml), \
1393	        "Notices for files contained in all filesystem images except system/system_ext/product/odm/vendor_dlkm/odm_dlkm in this directory:", \
1394	        $(TARGET_OUT_NOTICE_FILES), \
1395	        $(license_modules_vendor), \
1396	        $(exclude_target_dirs)))
1397$(eval $(call combine-notice-files, xml_product, \
1398	        $(target_product_notice_file_txt), \
1399	        $(target_product_notice_file_xml), \
1400	        "Notices for files contained in the product filesystem image in this directory:", \
1401	        $(TARGET_OUT_NOTICE_FILES), \
1402	        $(license_modules_product), \
1403	        $(exclude_target_dirs)))
1404$(eval $(call combine-notice-files, xml_system_ext, \
1405	        $(target_system_ext_notice_file_txt), \
1406	        $(target_system_ext_notice_file_xml), \
1407	        "Notices for files contained in the system_ext filesystem image in this directory:", \
1408	        $(TARGET_OUT_NOTICE_FILES), \
1409	        $(license_modules_system_ext), \
1410	        $(exclude_target_dirs)))
1411$(eval $(call combine-notice-files, xml_odm, \
1412	        $(target_odm_notice_file_txt), \
1413	        $(target_odm_notice_file_xml), \
1414	        "Notices for files contained in the odm filesystem image in this directory:", \
1415	        $(TARGET_OUT_NOTICE_FILES), \
1416	        $(license_modules_odm), \
1417	        $(exclude_target_dirs)))
1418$(eval $(call combine-notice-files, xml_vendor_dlkm, \
1419	        $(target_vendor_dlkm_notice_file_txt), \
1420	        $(target_vendor_dlkm_notice_file_xml), \
1421	        "Notices for files contained in the vendor_dlkm filesystem image in this directory:", \
1422	        $(TARGET_OUT_NOTICE_FILES), \
1423	        $(license_modules_vendor_dlkm), \
1424	        $(exclude_target_dirs)))
1425$(eval $(call combine-notice-files, xml_odm_dlkm, \
1426	        $(target_odm_dlkm_notice_file_txt), \
1427	        $(target_odm_dlkm_notice_file_xml), \
1428	        "Notices for files contained in the odm_dlkm filesystem image in this directory:", \
1429	        $(TARGET_OUT_NOTICE_FILES), \
1430	        $(license_modules_odm_dlkm), \
1431	        $(exclude_target_dirs)))
1432
1433$(target_notice_file_xml_gz): $(target_notice_file_xml) | $(MINIGZIP)
1434	$(hide) $(MINIGZIP) -9 < $< > $@
1435$(target_vendor_notice_file_xml_gz): $(target_vendor_notice_file_xml) | $(MINIGZIP)
1436	$(hide) $(MINIGZIP) -9 < $< > $@
1437$(target_product_notice_file_xml_gz): $(target_product_notice_file_xml) | $(MINIGZIP)
1438	$(hide) $(MINIGZIP) -9 < $< > $@
1439$(target_system_ext_notice_file_xml_gz): $(target_system_ext_notice_file_xml) | $(MINIGZIP)
1440	$(hide) $(MINIGZIP) -9 < $< > $@
1441$(target_odm_notice_file_xml_gz): $(target_odm_notice_file_xml) | $(MINIGZIP)
1442	$(hide) $(MINIGZIP) -9 < $< > $@
1443$(target_vendor_dlkm_notice_file_xml_gz): $(target_vendor_dlkm_notice_file_xml) | $(MINIGZIP)
1444	$(hide) $(MINIGZIP) -9 < $< > $@
1445$(target_odm_dlkm_notice_file_xml_gz): $(target_odm_dlkm_notice_file_xml) | $(MINIGZIP)
1446	$(hide) $(MINIGZIP) -9 < $< > $@
1447$(installed_notice_html_or_xml_gz): $(target_notice_file_xml_gz)
1448	$(copy-file-to-target)
1449$(installed_vendor_notice_xml_gz): $(target_vendor_notice_file_xml_gz)
1450	$(copy-file-to-target)
1451$(installed_product_notice_xml_gz): $(target_product_notice_file_xml_gz)
1452	$(copy-file-to-target)
1453$(installed_system_ext_notice_xml_gz): $(target_system_ext_notice_file_xml_gz)
1454	$(copy-file-to-target)
1455$(installed_odm_notice_xml_gz): $(target_odm_notice_file_xml_gz)
1456	$(copy-file-to-target)
1457$(installed_vendor_dlkm_notice_xml_gz): $(target_vendor_dlkm_notice_file_xml_gz)
1458	$(copy-file-to-target)
1459$(installed_odm_dlkm_notice_xml_gz): $(target_odm_dlkm_notice_file_xml_gz)
1460	$(copy-file-to-target)
1461
1462ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_or_xml_gz)
1463ALL_DEFAULT_INSTALLED_MODULES += $(installed_vendor_notice_xml_gz)
1464ALL_DEFAULT_INSTALLED_MODULES += $(installed_product_notice_xml_gz)
1465ALL_DEFAULT_INSTALLED_MODULES += $(installed_system_ext_notice_xml_gz)
1466ALL_DEFAULT_INSTALLED_MODULES += $(installed_odm_notice_xml_gz)
1467ALL_DEFAULT_INSTALLED_MODULES += $(installed_vendor_dlkm_notice_xml_gz)
1468ALL_DEFAULT_INSTALLED_MODULES += $(installed_odm_dlkm_notice_xml_gz)
1469endif # PRODUCT_NOTICE_SPLIT
1470
1471ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_or_xml_gz)
1472
1473$(eval $(call combine-notice-files, html, \
1474	        $(tools_notice_file_txt), \
1475	        $(tools_notice_file_html), \
1476	        "Notices for files contained in the tools directory:", \
1477	        $(HOST_OUT_NOTICE_FILES), \
1478	        $(ALL_DEFAULT_INSTALLED_MODULES) \
1479	        $(winpthreads_notice_file), \
1480	        $(exclude_target_dirs)))
1481
1482endif  # TARGET_BUILD_APPS
1483
1484# The kernel isn't really a module, so to get its module file in there, we
1485# make the target NOTICE files depend on this particular file too, which will
1486# then be in the right directory for the find in combine-notice-files to work.
1487$(eval $(call copy-one-file,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,$(kernel_notice_file)))
1488
1489$(eval $(call copy-one-file,$(BUILD_SYSTEM)/WINPTHREADS_COPYING,$(winpthreads_notice_file)))
1490
1491
1492# #################################################################
1493# Targets for user images
1494# #################################################################
1495
1496INTERNAL_USERIMAGES_EXT_VARIANT :=
1497ifeq ($(TARGET_USERIMAGES_USE_EXT2),true)
1498INTERNAL_USERIMAGES_EXT_VARIANT := ext2
1499else
1500ifeq ($(TARGET_USERIMAGES_USE_EXT3),true)
1501INTERNAL_USERIMAGES_EXT_VARIANT := ext3
1502else
1503ifeq ($(TARGET_USERIMAGES_USE_EXT4),true)
1504INTERNAL_USERIMAGES_EXT_VARIANT := ext4
1505endif
1506endif
1507endif
1508
1509# These options tell the recovery updater/installer how to mount the partitions writebale.
1510# <fstype>=<fstype_opts>[|<fstype_opts>]...
1511# fstype_opts := <opt>[,<opt>]...
1512#         opt := <name>[=<value>]
1513# The following worked on Nexus devices with Kernel 3.1, 3.4, 3.10
1514DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS := ext4=max_batch_time=0,commit=1,data=ordered,barrier=1,errors=panic,nodelalloc
1515
1516ifneq (true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED))
1517  INTERNAL_USERIMAGES_SPARSE_EXT_FLAG := -s
1518endif
1519ifneq (true,$(TARGET_USERIMAGES_SPARSE_EROFS_DISABLED))
1520  INTERNAL_USERIMAGES_SPARSE_EROFS_FLAG := -s
1521endif
1522ifneq (true,$(TARGET_USERIMAGES_SPARSE_SQUASHFS_DISABLED))
1523  INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG := -s
1524endif
1525ifneq (true,$(TARGET_USERIMAGES_SPARSE_F2FS_DISABLED))
1526  INTERNAL_USERIMAGES_SPARSE_F2FS_FLAG := -S
1527endif
1528
1529INTERNAL_USERIMAGES_DEPS := \
1530    $(BUILD_IMAGE) \
1531    $(MKE2FS_CONF) \
1532    $(MKEXTUSERIMG)
1533
1534ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
1535INTERNAL_USERIMAGES_DEPS += $(MKF2FSUSERIMG)
1536endif
1537
1538ifneq ($(filter \
1539    $(BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE) \
1540    $(BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE) \
1541    $(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE) \
1542    $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE) \
1543    $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE) \
1544    $(BOARD_VENDOR_DLKMIMAGE_FILE_SYSTEM_TYPE) \
1545    $(BOARD_ODM_DLKMIMAGE_FILE_SYSTEM_TYPE) \
1546  ,erofs),)
1547INTERNAL_USERIMAGES_DEPS += $(MKEROFSUSERIMG)
1548endif
1549
1550ifneq ($(filter \
1551    $(BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE) \
1552    $(BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE) \
1553    $(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE) \
1554    $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE) \
1555    $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE) \
1556    $(BOARD_VENDOR_DLKMIMAGE_FILE_SYSTEM_TYPE) \
1557    $(BOARD_ODM_DLKMIMAGE_FILE_SYSTEM_TYPE) \
1558  ,squashfs),)
1559INTERNAL_USERIMAGES_DEPS += $(MKSQUASHFSUSERIMG)
1560endif
1561
1562ifeq (true,$(PRODUCT_SUPPORTS_VERITY))
1563INTERNAL_USERIMAGES_DEPS += $(BUILD_VERITY_METADATA) $(BUILD_VERITY_TREE) $(APPEND2SIMG) $(VERITY_SIGNER)
1564ifeq (true,$(PRODUCT_SUPPORTS_VERITY_FEC))
1565INTERNAL_USERIMAGES_DEPS += $(FEC)
1566endif
1567endif
1568
1569ifeq ($(BOARD_AVB_ENABLE),true)
1570INTERNAL_USERIMAGES_DEPS += $(AVBTOOL)
1571endif
1572
1573# Get a colon-separated list of search paths.
1574INTERNAL_USERIMAGES_BINARY_PATHS := $(subst $(space),:,$(sort $(dir $(INTERNAL_USERIMAGES_DEPS))))
1575
1576# Collects file_contexts files from modules to be installed
1577$(call merge-fc-files, \
1578  $(sort $(foreach m,$(product_MODULES),$(ALL_MODULES.$(m).FILE_CONTEXTS))),\
1579  $(call intermediates-dir-for,ETC,file_contexts.bin)/file_contexts.modules.tmp)
1580
1581SELINUX_FC := $(call intermediates-dir-for,ETC,file_contexts.bin)/file_contexts.bin
1582
1583INTERNAL_USERIMAGES_DEPS += $(SELINUX_FC)
1584
1585ifeq (true,$(PRODUCT_USE_DYNAMIC_PARTITIONS))
1586
1587ifeq ($(PRODUCT_SUPPORTS_VERITY),true)
1588  $(error vboot 1.0 doesn't support logical partition)
1589endif
1590
1591endif # PRODUCT_USE_DYNAMIC_PARTITIONS
1592
1593# $(1): the path of the output dictionary file
1594# $(2): a subset of "system vendor cache userdata product system_ext oem odm vendor_dlkm odm_dlkm"
1595# $(3): additional "key=value" pairs to append to the dictionary file.
1596define generate-image-prop-dictionary
1597$(if $(filter $(2),system),\
1598    $(if $(BOARD_SYSTEMIMAGE_PARTITION_SIZE),$(hide) echo "system_size=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE)" >> $(1))
1599    $(if $(INTERNAL_SYSTEM_OTHER_PARTITION_SIZE),$(hide) echo "system_other_size=$(INTERNAL_SYSTEM_OTHER_PARTITION_SIZE)" >> $(1))
1600    $(if $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "system_fs_type=$(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1601    $(if $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_COMPRESS),$(hide) echo "system_f2fs_compress=$(BOARD_SYSTEMIMAGE_FILE_SYSTEM_COMPRESS)" >> $(1))
1602    $(if $(BOARD_SYSTEMIMAGE_F2FS_SLOAD_COMPRESS_FLAGS),$(hide) echo "system_f2fs_sldc_flags=$(BOARD_SYSTEMIMAGE_F2FS_SLOAD_COMPRESS_FLAGS)" >> $(1))
1603    $(if $(BOARD_SYSTEMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "system_extfs_inode_count=$(BOARD_SYSTEMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1604    $(if $(BOARD_SYSTEMIMAGE_EXTFS_RSV_PCT),$(hide) echo "system_extfs_rsv_pct=$(BOARD_SYSTEMIMAGE_EXTFS_RSV_PCT)" >> $(1))
1605    $(if $(BOARD_SYSTEMIMAGE_JOURNAL_SIZE),$(hide) echo "system_journal_size=$(BOARD_SYSTEMIMAGE_JOURNAL_SIZE)" >> $(1))
1606    $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "system_squashfs_compressor=$(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1607    $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "system_squashfs_compressor_opt=$(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1608    $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "system_squashfs_block_size=$(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1609    $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "system_squashfs_disable_4k_align=$(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1610    $(if $(PRODUCT_SYSTEM_BASE_FS_PATH),$(hide) echo "system_base_fs_file=$(PRODUCT_SYSTEM_BASE_FS_PATH)" >> $(1))
1611    $(if $(PRODUCT_SYSTEM_HEADROOM),$(hide) echo "system_headroom=$(PRODUCT_SYSTEM_HEADROOM)" >> $(1))
1612    $(if $(BOARD_SYSTEMIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "system_reserved_size=$(BOARD_SYSTEMIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1613    $(hide) echo "system_selinux_fc=$(SELINUX_FC)" >> $(1)
1614    $(hide) echo "building_system_image=$(BUILDING_SYSTEM_IMAGE)" >> $(1)
1615)
1616$(if $(filter $(2),system_other),\
1617    $(hide) echo "building_system_other_image=$(BUILDING_SYSTEM_OTHER_IMAGE)" >> $(1)
1618)
1619$(if $(filter $(2),userdata),\
1620    $(if $(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "userdata_fs_type=$(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1621    $(if $(BOARD_USERDATAIMAGE_PARTITION_SIZE),$(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(1))
1622    $(if $(PRODUCT_FS_CASEFOLD),$(hide) echo "needs_casefold=$(PRODUCT_FS_CASEFOLD)" >> $(1))
1623    $(if $(PRODUCT_QUOTA_PROJID),$(hide) echo "needs_projid=$(PRODUCT_QUOTA_PROJID)" >> $(1))
1624    $(if $(PRODUCT_FS_COMPRESSION),$(hide) echo "needs_compress=$(PRODUCT_FS_COMPRESSION)" >> $(1))
1625    $(hide) echo "userdata_selinux_fc=$(SELINUX_FC)" >> $(1)
1626    $(hide) echo "building_userdata_image=$(BUILDING_USERDATA_IMAGE)" >> $(1)
1627)
1628$(if $(filter $(2),cache),\
1629    $(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1630    $(if $(BOARD_CACHEIMAGE_PARTITION_SIZE),$(hide) echo "cache_size=$(BOARD_CACHEIMAGE_PARTITION_SIZE)" >> $(1))
1631    $(hide) echo "cache_selinux_fc=$(SELINUX_FC)" >> $(1)
1632    $(hide) echo "building_cache_image=$(BUILDING_CACHE_IMAGE)" >> $(1)
1633)
1634$(if $(filter $(2),vendor),\
1635    $(if $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "vendor_fs_type=$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1636    $(if $(BOARD_VENDORIMAGE_FILE_SYSTEM_COMPRESS),$(hide) echo "vendor_f2fs_compress=$(BOARD_VENDORIMAGE_FILE_SYSTEM_COMPRESS)" >> $(1))
1637    $(if $(BOARD_VENDORIMAGE_F2FS_SLOAD_COMPRESS_FLAGS),$(hide) echo "vendor_f2fs_sldc_flags=$(BOARD_VENDORIMAGE_F2FS_SLOAD_COMPRESS_FLAGS)" >> $(1))
1638    $(if $(BOARD_VENDORIMAGE_EXTFS_INODE_COUNT),$(hide) echo "vendor_extfs_inode_count=$(BOARD_VENDORIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1639    $(if $(BOARD_VENDORIMAGE_EXTFS_RSV_PCT),$(hide) echo "vendor_extfs_rsv_pct=$(BOARD_VENDORIMAGE_EXTFS_RSV_PCT)" >> $(1))
1640    $(if $(BOARD_VENDORIMAGE_PARTITION_SIZE),$(hide) echo "vendor_size=$(BOARD_VENDORIMAGE_PARTITION_SIZE)" >> $(1))
1641    $(if $(BOARD_VENDORIMAGE_JOURNAL_SIZE),$(hide) echo "vendor_journal_size=$(BOARD_VENDORIMAGE_JOURNAL_SIZE)" >> $(1))
1642    $(if $(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "vendor_squashfs_compressor=$(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1643    $(if $(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "vendor_squashfs_compressor_opt=$(BOARD_VENDORIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1644    $(if $(BOARD_VENDORIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "vendor_squashfs_block_size=$(BOARD_VENDORIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1645    $(if $(BOARD_VENDORIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "vendor_squashfs_disable_4k_align=$(BOARD_VENDORIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1646    $(if $(PRODUCT_VENDOR_BASE_FS_PATH),$(hide) echo "vendor_base_fs_file=$(PRODUCT_VENDOR_BASE_FS_PATH)" >> $(1))
1647    $(if $(BOARD_VENDORIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "vendor_reserved_size=$(BOARD_VENDORIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1648    $(hide) echo "vendor_selinux_fc=$(SELINUX_FC)" >> $(1)
1649    $(hide) echo "building_vendor_image=$(BUILDING_VENDOR_IMAGE)" >> $(1)
1650)
1651$(if $(filter $(2),product),\
1652    $(if $(BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "product_fs_type=$(BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1653    $(if $(BOARD_PRODUCTIMAGE_FILE_SYSTEM_COMPRESS),$(hide) echo "product_f2fs_compress=$(BOARD_PRODUCTIMAGE_FILE_SYSTEM_COMPRESS)" >> $(1))
1654    $(if $(BOARD_PRODUCTIMAGE_F2FS_SLOAD_COMPRESS_FLAGS),$(hide) echo "product_f2fs_sldc_flags=$(BOARD_PRODUCTIMAGE_F2FS_SLOAD_COMPRESS_FLAGS)" >> $(1))
1655    $(if $(BOARD_PRODUCTIMAGE_EXTFS_INODE_COUNT),$(hide) echo "product_extfs_inode_count=$(BOARD_PRODUCTIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1656    $(if $(BOARD_PRODUCTIMAGE_EXTFS_RSV_PCT),$(hide) echo "product_extfs_rsv_pct=$(BOARD_PRODUCTIMAGE_EXTFS_RSV_PCT)" >> $(1))
1657    $(if $(BOARD_PRODUCTIMAGE_PARTITION_SIZE),$(hide) echo "product_size=$(BOARD_PRODUCTIMAGE_PARTITION_SIZE)" >> $(1))
1658    $(if $(BOARD_PRODUCTIMAGE_JOURNAL_SIZE),$(hide) echo "product_journal_size=$(BOARD_PRODUCTIMAGE_JOURNAL_SIZE)" >> $(1))
1659    $(if $(BOARD_PRODUCTIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "product_squashfs_compressor=$(BOARD_PRODUCTIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1660    $(if $(BOARD_PRODUCTIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "product_squashfs_compressor_opt=$(BOARD_PRODUCTIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1661    $(if $(BOARD_PRODUCTIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "product_squashfs_block_size=$(BOARD_PRODUCTIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1662    $(if $(BOARD_PRODUCTIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "product_squashfs_disable_4k_align=$(BOARD_PRODUCTIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1663    $(if $(PRODUCT_PRODUCT_BASE_FS_PATH),$(hide) echo "product_base_fs_file=$(PRODUCT_PRODUCT_BASE_FS_PATH)" >> $(1))
1664    $(if $(BOARD_PRODUCTIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "product_reserved_size=$(BOARD_PRODUCTIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1665    $(hide) echo "product_selinux_fc=$(SELINUX_FC)" >> $(1)
1666    $(hide) echo "building_product_image=$(BUILDING_PRODUCT_IMAGE)" >> $(1)
1667)
1668$(if $(filter $(2),system_ext),\
1669    $(if $(BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "system_ext_fs_type=$(BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1670    $(if $(BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_COMPRESS),$(hide) echo "system_ext_f2fs_compress=$(BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_COMPRESS)" >> $(1))
1671    $(if $(BOARD_SYSTEM_EXTIMAGE_F2FS_SLOAD_COMPRESS_FLAGS),$(hide) echo "system_ext_f2fs_sldc_flags=$(BOARD_SYSTEM_EXTIMAGE_F2FS_SLOAD_COMPRESS_FLAGS)" >> $(1))
1672    $(if $(BOARD_SYSTEM_EXTIMAGE_EXTFS_INODE_COUNT),$(hide) echo "system_ext_extfs_inode_count=$(BOARD_SYSTEM_EXTIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1673    $(if $(BOARD_SYSTEM_EXTIMAGE_EXTFS_RSV_PCT),$(hide) echo "system_ext_extfs_rsv_pct=$(BOARD_SYSTEM_EXTIMAGE_EXTFS_RSV_PCT)" >> $(1))
1674    $(if $(BOARD_SYSTEM_EXTIMAGE_PARTITION_SIZE),$(hide) echo "system_ext_size=$(BOARD_SYSTEM_EXTIMAGE_PARTITION_SIZE)" >> $(1))
1675    $(if $(BOARD_SYSTEM_EXTIMAGE_JOURNAL_SIZE),$(hide) echo "system_ext_journal_size=$(BOARD_SYSTEM_EXTIMAGE_JOURNAL_SIZE)" >> $(1))
1676    $(if $(BOARD_SYSTEM_EXTIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "system_ext_squashfs_compressor=$(BOARD_SYSTEM_EXTIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1677    $(if $(BOARD_SYSTEM_EXTIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "system_ext_squashfs_compressor_opt=$(BOARD_SYSTEM_EXTIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1678    $(if $(BOARD_SYSTEM_EXTIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "system_ext_squashfs_block_size=$(BOARD_SYSTEM_EXTIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1679    $(if $(BOARD_SYSTEM_EXTIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "system_ext_squashfs_disable_4k_align=$(BOARD_SYSTEM_EXTIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1680    $(if $(BOARD_SYSTEM_EXTIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "system_ext_reserved_size=$(BOARD_SYSTEM_EXTIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1681    $(hide) echo "system_ext_selinux_fc=$(SELINUX_FC)" >> $(1)
1682    $(hide) echo "building_system_ext_image=$(BUILDING_SYSTEM_EXT_IMAGE)" >> $(1)
1683)
1684$(if $(filter $(2),odm),\
1685    $(if $(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "odm_fs_type=$(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1686    $(if $(BOARD_ODMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "odm_extfs_inode_count=$(BOARD_ODMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1687    $(if $(BOARD_ODMIMAGE_EXTFS_RSV_PCT),$(hide) echo "odm_extfs_rsv_pct=$(BOARD_ODMIMAGE_EXTFS_RSV_PCT)" >> $(1))
1688    $(if $(BOARD_ODMIMAGE_PARTITION_SIZE),$(hide) echo "odm_size=$(BOARD_ODMIMAGE_PARTITION_SIZE)" >> $(1))
1689    $(if $(BOARD_ODMIMAGE_JOURNAL_SIZE),$(hide) echo "odm_journal_size=$(BOARD_ODMIMAGE_JOURNAL_SIZE)" >> $(1))
1690    $(if $(BOARD_ODMIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "odm_squashfs_compressor=$(BOARD_ODMIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1691    $(if $(BOARD_ODMIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "odm_squashfs_compressor_opt=$(BOARD_ODMIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1692    $(if $(BOARD_ODMIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "odm_squashfs_block_size=$(BOARD_ODMIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1693    $(if $(BOARD_ODMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "odm_squashfs_disable_4k_align=$(BOARD_ODMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1694    $(if $(PRODUCT_ODM_BASE_FS_PATH),$(hide) echo "odm_base_fs_file=$(PRODUCT_ODM_BASE_FS_PATH)" >> $(1))
1695    $(if $(BOARD_ODMIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "odm_reserved_size=$(BOARD_ODMIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1696    $(hide) echo "odm_selinux_fc=$(SELINUX_FC)" >> $(1)
1697    $(hide) echo "building_odm_image=$(BUILDING_ODM_IMAGE)" >> $(1)
1698)
1699$(if $(filter $(2),vendor_dlkm),\
1700    $(if $(BOARD_VENDOR_DLKMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "vendor_dlkm_fs_type=$(BOARD_VENDOR_DLKMIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1701    $(if $(BOARD_VENDOR_DLKMIMAGE_FILE_SYSTEM_COMPRESS),$(hide) echo "vendor_dlkm_f2fs_compress=$(BOARD_VENDOR_DLKMIMAGE_FILE_SYSTEM_COMPRESS)" >> $(1))
1702    $(if $(BOARD_VENDOR_DLKMIMAGE_F2FS_SLOAD_COMPRESS_FLAGS),$(hide) echo "vendor_dlkm_f2fs_sldc_flags=$(BOARD_VENDOR_DLKMIMAGE_F2FS_SLOAD_COMPRESS_FLAGS)" >> $(1))
1703    $(if $(BOARD_VENDOR_DLKMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "vendor_dlkm_extfs_inode_count=$(BOARD_VENDOR_DLKMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1704    $(if $(BOARD_VENDOR_DLKMIMAGE_EXTFS_RSV_PCT),$(hide) echo "vendor_dlkm_extfs_rsv_pct=$(BOARD_VENDOR_DLKMIMAGE_EXTFS_RSV_PCT)" >> $(1))
1705    $(if $(BOARD_VENDOR_DLKMIMAGE_PARTITION_SIZE),$(hide) echo "vendor_dlkm_size=$(BOARD_VENDOR_DLKMIMAGE_PARTITION_SIZE)" >> $(1))
1706    $(if $(BOARD_VENDOR_DLKMIMAGE_JOURNAL_SIZE),$(hide) echo "vendor_dlkm_journal_size=$(BOARD_VENDOR_DLKMIMAGE_JOURNAL_SIZE)" >> $(1))
1707    $(if $(BOARD_VENDOR_DLKMIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "vendor_dlkm_squashfs_compressor=$(BOARD_VENDOR_DLKMIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1708    $(if $(BOARD_VENDOR_DLKMIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "vendor_dlkm_squashfs_compressor_opt=$(BOARD_VENDOR_DLKMIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1709    $(if $(BOARD_VENDOR_DLKMIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "vendor_dlkm_squashfs_block_size=$(BOARD_VENDOR_DLKMIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1710    $(if $(BOARD_VENDOR_DLKMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "vendor_dlkm_squashfs_disable_4k_align=$(BOARD_VENDOR_DLKMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1711    $(if $(BOARD_VENDOR_DLKMIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "vendor_dlkm_reserved_size=$(BOARD_VENDOR_DLKMIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1712    $(hide) echo "vendor_dlkm_selinux_fc=$(SELINUX_FC)" >> $(1)
1713    $(hide) echo "building_vendor_dlkm_image=$(BUILDING_VENDOR_DLKM_IMAGE)" >> $(1)
1714)
1715$(if $(filter $(2),odm_dlkm),\
1716    $(if $(BOARD_ODM_DLKMIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "odm_dlkm_fs_type=$(BOARD_ODM_DLKMIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
1717    $(if $(BOARD_ODM_DLKMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "odm_dlkm_extfs_inode_count=$(BOARD_ODM_DLKMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1718    $(if $(BOARD_ODM_DLKMIMAGE_EXTFS_RSV_PCT),$(hide) echo "odm_dlkm_extfs_rsv_pct=$(BOARD_ODM_DLKMIMAGE_EXTFS_RSV_PCT)" >> $(1))
1719    $(if $(BOARD_ODM_DLKMIMAGE_PARTITION_SIZE),$(hide) echo "odm_dlkm_size=$(BOARD_ODM_DLKMIMAGE_PARTITION_SIZE)" >> $(1))
1720    $(if $(BOARD_ODM_DLKMIMAGE_JOURNAL_SIZE),$(hide) echo "odm_dlkm_journal_size=$(BOARD_ODM_DLKMIMAGE_JOURNAL_SIZE)" >> $(1))
1721    $(if $(BOARD_ODM_DLKMIMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "odm_dlkm_squashfs_compressor=$(BOARD_ODM_DLKMIMAGE_SQUASHFS_COMPRESSOR)" >> $(1))
1722    $(if $(BOARD_ODM_DLKMIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "odm_dlkm_squashfs_compressor_opt=$(BOARD_ODM_DLKMIMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(1))
1723    $(if $(BOARD_ODM_DLKMIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "odm_dlkm_squashfs_block_size=$(BOARD_ODM_DLKMIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
1724    $(if $(BOARD_ODM_DLKMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "odm_dlkm_squashfs_disable_4k_align=$(BOARD_ODM_DLKMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
1725    $(if $(BOARD_ODM_DLKMIMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "odm_dlkm_reserved_size=$(BOARD_ODM_DLKMIMAGE_PARTITION_RESERVED_SIZE)" >> $(1))
1726    $(hide) echo "odm_dlkm_selinux_fc=$(SELINUX_FC)" >> $(1)
1727    $(hide) echo "building_odm_dlkm_image=$(BUILDING_ODM_DLKM_IMAGE)" >> $(1)
1728)
1729$(if $(filter $(2),oem),\
1730    $(if $(BOARD_OEMIMAGE_PARTITION_SIZE),$(hide) echo "oem_size=$(BOARD_OEMIMAGE_PARTITION_SIZE)" >> $(1))
1731    $(if $(BOARD_OEMIMAGE_JOURNAL_SIZE),$(hide) echo "oem_journal_size=$(BOARD_OEMIMAGE_JOURNAL_SIZE)" >> $(1))
1732    $(if $(BOARD_OEMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "oem_extfs_inode_count=$(BOARD_OEMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
1733    $(if $(BOARD_OEMIMAGE_EXTFS_RSV_PCT),$(hide) echo "oem_extfs_rsv_pct=$(BOARD_OEMIMAGE_EXTFS_RSV_PCT)" >> $(1))
1734    $(hide) echo "oem_selinux_fc=$(SELINUX_FC)" >> $(1)
1735)
1736$(hide) echo "ext_mkuserimg=$(notdir $(MKEXTUSERIMG))" >> $(1)
1737
1738$(if $(INTERNAL_USERIMAGES_EXT_VARIANT),$(hide) echo "fs_type=$(INTERNAL_USERIMAGES_EXT_VARIANT)" >> $(1))
1739$(if $(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG),$(hide) echo "extfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_EXT_FLAG)" >> $(1))
1740$(if $(INTERNAL_USERIMAGES_SPARSE_EROFS_FLAG),$(hide) echo "erofs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_EROFS_FLAG)" >> $(1))
1741$(if $(INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG),$(hide) echo "squashfs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_SQUASHFS_FLAG)" >> $(1))
1742$(if $(INTERNAL_USERIMAGES_SPARSE_F2FS_FLAG),$(hide) echo "f2fs_sparse_flag=$(INTERNAL_USERIMAGES_SPARSE_F2FS_FLAG)" >> $(1))
1743$(if $(BOARD_EXT4_SHARE_DUP_BLOCKS),$(hide) echo "ext4_share_dup_blocks=$(BOARD_EXT4_SHARE_DUP_BLOCKS)" >> $(1))
1744$(if $(BOARD_FLASH_LOGICAL_BLOCK_SIZE), $(hide) echo "flash_logical_block_size=$(BOARD_FLASH_LOGICAL_BLOCK_SIZE)" >> $(1))
1745$(if $(BOARD_FLASH_ERASE_BLOCK_SIZE), $(hide) echo "flash_erase_block_size=$(BOARD_FLASH_ERASE_BLOCK_SIZE)" >> $(1))
1746$(if $(PRODUCT_SUPPORTS_BOOT_SIGNER),$(hide) echo "boot_signer=$(PRODUCT_SUPPORTS_BOOT_SIGNER)" >> $(1))
1747$(if $(PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity=$(PRODUCT_SUPPORTS_VERITY)" >> $(1))
1748$(if $(PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_key=$(PRODUCT_VERITY_SIGNING_KEY)" >> $(1))
1749$(if $(PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_signer_cmd=$(notdir $(VERITY_SIGNER))" >> $(1))
1750$(if $(PRODUCT_SUPPORTS_VERITY_FEC),$(hide) echo "verity_fec=$(PRODUCT_SUPPORTS_VERITY_FEC)" >> $(1))
1751$(if $(filter eng, $(TARGET_BUILD_VARIANT)),$(hide) echo "verity_disable=true" >> $(1))
1752$(if $(PRODUCT_SYSTEM_VERITY_PARTITION),$(hide) echo "system_verity_block_device=$(PRODUCT_SYSTEM_VERITY_PARTITION)" >> $(1))
1753$(if $(PRODUCT_VENDOR_VERITY_PARTITION),$(hide) echo "vendor_verity_block_device=$(PRODUCT_VENDOR_VERITY_PARTITION)" >> $(1))
1754$(if $(PRODUCT_PRODUCT_VERITY_PARTITION),$(hide) echo "product_verity_block_device=$(PRODUCT_PRODUCT_VERITY_PARTITION)" >> $(1))
1755$(if $(PRODUCT_SYSTEM_EXT_VERITY_PARTITION),$(hide) echo "system_ext_verity_block_device=$(PRODUCT_SYSTEM_EXT_VERITY_PARTITION)" >> $(1))
1756$(if $(PRODUCT_VENDOR_DLKM_VERITY_PARTITION),$(hide) echo "vendor_dlkm_verity_block_device=$(PRODUCT_VENDOR_DLKM_VERITY_PARTITION)" >> $(1))
1757$(if $(PRODUCT_ODM_DLKM_VERITY_PARTITION),$(hide) echo "odm_dlkm_verity_block_device=$(PRODUCT_ODM_DLKM_VERITY_PARTITION)" >> $(1))
1758$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot=$(PRODUCT_SUPPORTS_VBOOT)" >> $(1))
1759$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_key=$(PRODUCT_VBOOT_SIGNING_KEY)" >> $(1))
1760$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_subkey=$(PRODUCT_VBOOT_SIGNING_SUBKEY)" >> $(1))
1761$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "futility=$(notdir $(FUTILITY))" >> $(1))
1762$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_signer_cmd=$(VBOOT_SIGNER)" >> $(1))
1763$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_avbtool=$(notdir $(AVBTOOL))" >> $(1))
1764$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1765$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_add_hashtree_footer_args=$(BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1766$(if $(BOARD_AVB_ENABLE),\
1767    $(if $(BOARD_AVB_SYSTEM_KEY_PATH),\
1768        $(hide) echo "avb_system_key_path=$(BOARD_AVB_SYSTEM_KEY_PATH)" >> $(1)
1769        $(hide) echo "avb_system_algorithm=$(BOARD_AVB_SYSTEM_ALGORITHM)" >> $(1)
1770        $(hide) echo "avb_system_rollback_index_location=$(BOARD_AVB_SYSTEM_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1771$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_other_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1772$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_other_add_hashtree_footer_args=$(BOARD_AVB_SYSTEM_OTHER_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1773$(if $(BOARD_AVB_ENABLE),\
1774    $(if $(BOARD_AVB_SYSTEM_OTHER_KEY_PATH),\
1775        $(hide) echo "avb_system_other_key_path=$(BOARD_AVB_SYSTEM_OTHER_KEY_PATH)" >> $(1)
1776        $(hide) echo "avb_system_other_algorithm=$(BOARD_AVB_SYSTEM_OTHER_ALGORITHM)" >> $(1)))
1777$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_vendor_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1778$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_vendor_add_hashtree_footer_args=$(BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1779$(if $(BOARD_AVB_ENABLE),\
1780    $(if $(BOARD_AVB_VENDOR_KEY_PATH),\
1781        $(hide) echo "avb_vendor_key_path=$(BOARD_AVB_VENDOR_KEY_PATH)" >> $(1)
1782        $(hide) echo "avb_vendor_algorithm=$(BOARD_AVB_VENDOR_ALGORITHM)" >> $(1)
1783        $(hide) echo "avb_vendor_rollback_index_location=$(BOARD_AVB_VENDOR_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1784$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_product_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1785$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_product_add_hashtree_footer_args=$(BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1786$(if $(BOARD_AVB_ENABLE),\
1787    $(if $(BOARD_AVB_PRODUCT_KEY_PATH),\
1788        $(hide) echo "avb_product_key_path=$(BOARD_AVB_PRODUCT_KEY_PATH)" >> $(1)
1789        $(hide) echo "avb_product_algorithm=$(BOARD_AVB_PRODUCT_ALGORITHM)" >> $(1)
1790        $(hide) echo "avb_product_rollback_index_location=$(BOARD_AVB_PRODUCT_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1791$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_system_ext_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1792$(if $(BOARD_AVB_ENABLE),\
1793    $(hide) echo "avb_system_ext_add_hashtree_footer_args=$(BOARD_AVB_SYSTEM_EXT_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1794$(if $(BOARD_AVB_ENABLE),\
1795    $(if $(BOARD_AVB_SYSTEM_EXT_KEY_PATH),\
1796        $(hide) echo "avb_system_ext_key_path=$(BOARD_AVB_SYSTEM_EXT_KEY_PATH)" >> $(1)
1797        $(hide) echo "avb_system_ext_algorithm=$(BOARD_AVB_SYSTEM_EXT_ALGORITHM)" >> $(1)
1798        $(hide) echo "avb_system_ext_rollback_index_location=$(BOARD_AVB_SYSTEM_EXT_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1799$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_odm_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1800$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_odm_add_hashtree_footer_args=$(BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1801$(if $(BOARD_AVB_ENABLE),\
1802    $(if $(BOARD_AVB_ODM_KEY_PATH),\
1803        $(hide) echo "avb_odm_key_path=$(BOARD_AVB_ODM_KEY_PATH)" >> $(1)
1804        $(hide) echo "avb_odm_algorithm=$(BOARD_AVB_ODM_ALGORITHM)" >> $(1)
1805        $(hide) echo "avb_odm_rollback_index_location=$(BOARD_AVB_ODM_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1806$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_vendor_dlkm_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1807$(if $(BOARD_AVB_ENABLE),\
1808    $(hide) echo "avb_vendor_dlkm_add_hashtree_footer_args=$(BOARD_AVB_VENDOR_DLKM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1809$(if $(BOARD_AVB_ENABLE),\
1810    $(if $(BOARD_AVB_VENDOR_DLKM_KEY_PATH),\
1811        $(hide) echo "avb_vendor_dlkm_key_path=$(BOARD_AVB_VENDOR_DLKM_KEY_PATH)" >> $(1)
1812        $(hide) echo "avb_vendor_dlkm_algorithm=$(BOARD_AVB_VENDOR_DLKM_ALGORITHM)" >> $(1)
1813        $(hide) echo "avb_vendor_dlkm_rollback_index_location=$(BOARD_AVB_VENDOR_DLKM_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1814$(if $(BOARD_AVB_ENABLE),$(hide) echo "avb_odm_dlkm_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1))
1815$(if $(BOARD_AVB_ENABLE),\
1816    $(hide) echo "avb_odm_dlkm_add_hashtree_footer_args=$(BOARD_AVB_ODM_DLKM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1))
1817$(if $(BOARD_AVB_ENABLE),\
1818    $(if $(BOARD_AVB_ODM_DLKM_KEY_PATH),\
1819        $(hide) echo "avb_odm_dlkm_key_path=$(BOARD_AVB_ODM_DLKM_KEY_PATH)" >> $(1)
1820        $(hide) echo "avb_odm_dlkm_algorithm=$(BOARD_AVB_ODM_DLKM_ALGORITHM)" >> $(1)
1821        $(hide) echo "avb_odm_dlkm_rollback_index_location=$(BOARD_AVB_ODM_DLKM_ROLLBACK_INDEX_LOCATION)" >> $(1)))
1822$(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
1823    $(hide) echo "recovery_as_boot=true" >> $(1))
1824$(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)),\
1825    $(hide) echo "system_root_image=true" >> $(1))
1826$(hide) echo "root_dir=$(TARGET_ROOT_OUT)" >> $(1)
1827$(if $(filter true,$(PRODUCT_USE_DYNAMIC_PARTITION_SIZE)),\
1828    $(hide) echo "use_dynamic_partition_size=true" >> $(1))
1829$(if $(3),$(hide) $(foreach kv,$(3),echo "$(kv)" >> $(1);))
1830endef
1831
1832# $(1): the path of the output dictionary file
1833# $(2): additional "key=value" pairs to append to the dictionary file.
1834PROP_DICTIONARY_IMAGES := oem
1835ifdef BUILDING_CACHE_IMAGE
1836  PROP_DICTIONARY_IMAGES += cache
1837endif
1838ifdef BUILDING_SYSTEM_IMAGE
1839  PROP_DICTIONARY_IMAGES += system
1840endif
1841ifdef BUILDING_SYSTEM_OTHER_IMAGE
1842  PROP_DICTIONARY_IMAGES += system_other
1843endif
1844ifdef BUILDING_USERDATA_IMAGE
1845  PROP_DICTIONARY_IMAGES += userdata
1846endif
1847ifdef BUILDING_VENDOR_IMAGE
1848  PROP_DICTIONARY_IMAGES += vendor
1849endif
1850ifdef BUILDING_PRODUCT_IMAGE
1851  PROP_DICTIONARY_IMAGES += product
1852endif
1853ifdef BUILDING_SYSTEM_EXT_IMAGE
1854  PROP_DICTIONARY_IMAGES += system_ext
1855endif
1856ifdef BUILDING_ODM_IMAGE
1857  PROP_DICTIONARY_IMAGES += odm
1858endif
1859ifdef BUILDING_VENDOR_DLKM_IMAGE
1860  PROP_DICTIONARY_IMAGES += vendor_dlkm
1861endif
1862ifdef BUILDING_ODM_DLKM_IMAGE
1863  PROP_DICTIONARY_IMAGES += odm_dlkm
1864endif
1865define generate-userimage-prop-dictionary
1866  $(call generate-image-prop-dictionary,$(1),$(PROP_DICTIONARY_IMAGES),$(2))
1867endef
1868
1869# $(1): the path of the input dictionary file, where each line has the format key=value
1870# $(2): the key to look up
1871define read-image-prop-dictionary
1872$$(grep '$(2)=' $(1) | cut -f2- -d'=')
1873endef
1874
1875# -----------------------------------------------------------------
1876# Recovery image
1877
1878# Recovery image exists if we are building recovery, or building recovery as boot.
1879ifdef BUILDING_RECOVERY_IMAGE
1880
1881INTERNAL_RECOVERYIMAGE_FILES := $(filter $(TARGET_RECOVERY_OUT)/%, \
1882    $(ALL_DEFAULT_INSTALLED_MODULES))
1883
1884INSTALLED_FILES_FILE_RECOVERY := $(PRODUCT_OUT)/installed-files-recovery.txt
1885INSTALLED_FILES_JSON_RECOVERY := $(INSTALLED_FILES_FILE_RECOVERY:.txt=.json)
1886
1887ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
1888INSTALLED_BOOTIMAGE_TARGET := $(BUILT_BOOTIMAGE_TARGET)
1889endif
1890
1891# TODO(b/30414428): Can't depend on INTERNAL_RECOVERYIMAGE_FILES alone like other
1892# INSTALLED_FILES_FILE_* rules. Because currently there're cp/rsync/rm commands in
1893# build-recoveryimage-target, which would touch the files under TARGET_RECOVERY_OUT and race with
1894# the call to FILELIST.
1895$(INSTALLED_FILES_FILE_RECOVERY): $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
1896
1897$(INSTALLED_FILES_FILE_RECOVERY): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_RECOVERY)
1898$(INSTALLED_FILES_FILE_RECOVERY): $(INTERNAL_RECOVERYIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
1899	@echo Installed file list: $@
1900	mkdir -p $(dir $@)
1901	rm -f $@
1902	$(FILESLIST) $(TARGET_RECOVERY_ROOT_OUT) > $(@:.txt=.json)
1903	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
1904
1905recovery_sepolicy := \
1906    $(TARGET_RECOVERY_ROOT_OUT)/sepolicy \
1907    $(TARGET_RECOVERY_ROOT_OUT)/plat_file_contexts \
1908    $(TARGET_RECOVERY_ROOT_OUT)/plat_property_contexts \
1909    $(TARGET_RECOVERY_ROOT_OUT)/system_ext_file_contexts \
1910    $(TARGET_RECOVERY_ROOT_OUT)/system_ext_property_contexts \
1911    $(TARGET_RECOVERY_ROOT_OUT)/vendor_file_contexts \
1912    $(TARGET_RECOVERY_ROOT_OUT)/vendor_property_contexts \
1913    $(TARGET_RECOVERY_ROOT_OUT)/odm_file_contexts \
1914    $(TARGET_RECOVERY_ROOT_OUT)/odm_property_contexts \
1915    $(TARGET_RECOVERY_ROOT_OUT)/product_file_contexts \
1916    $(TARGET_RECOVERY_ROOT_OUT)/product_property_contexts
1917
1918# Passed into rsync from non-recovery root to recovery root, to avoid overwriting recovery-specific
1919# SELinux files
1920IGNORE_RECOVERY_SEPOLICY := $(patsubst $(TARGET_RECOVERY_OUT)/%,--exclude=/%,$(recovery_sepolicy))
1921
1922# if building multiple boot images from multiple kernels, use the first kernel listed
1923# for the recovery image
1924recovery_kernel := $(firstword $(INSTALLED_KERNEL_TARGET))
1925recovery_ramdisk := $(PRODUCT_OUT)/ramdisk-recovery.img
1926recovery_resources_common := bootable/recovery/res
1927
1928# Set recovery_density to a density bucket based on TARGET_SCREEN_DENSITY, PRODUCT_AAPT_PREF_CONFIG,
1929# or mdpi, in order of preference. We support both specific buckets (e.g. xdpi) and numbers,
1930# which get remapped to a bucket.
1931recovery_density := $(or $(TARGET_SCREEN_DENSITY),$(PRODUCT_AAPT_PREF_CONFIG),mdpi)
1932ifeq (,$(filter xxxhdpi xxhdpi xhdpi hdpi mdpi,$(recovery_density)))
1933recovery_density_value := $(patsubst %dpi,%,$(recovery_density))
1934# We roughly use the medium point between the primary densities to split buckets.
1935# ------160------240------320----------480------------640------
1936#       mdpi     hdpi    xhdpi        xxhdpi        xxxhdpi
1937recovery_density := $(strip \
1938  $(or $(if $(filter $(shell echo $$(($(recovery_density_value) >= 560))),1),xxxhdpi),\
1939       $(if $(filter $(shell echo $$(($(recovery_density_value) >= 400))),1),xxhdpi),\
1940       $(if $(filter $(shell echo $$(($(recovery_density_value) >= 280))),1),xhdpi),\
1941       $(if $(filter $(shell echo $$(($(recovery_density_value) >= 200))),1),hdpi,mdpi)))
1942endif
1943
1944ifneq (,$(wildcard $(recovery_resources_common)-$(recovery_density)))
1945recovery_resources_common := $(recovery_resources_common)-$(recovery_density)
1946else
1947recovery_resources_common := $(recovery_resources_common)-xhdpi
1948endif
1949
1950# Select the 18x32 font on high-density devices (xhdpi and up); and the 12x22 font on other devices.
1951# Note that the font selected here can be overridden for a particular device by putting a font.png
1952# in its private recovery resources.
1953ifneq (,$(filter xxxhdpi xxhdpi xhdpi,$(recovery_density)))
1954recovery_font := bootable/recovery/fonts/18x32.png
1955else
1956recovery_font := bootable/recovery/fonts/12x22.png
1957endif
1958
1959
1960# We will only generate the recovery background text images if the variable
1961# TARGET_RECOVERY_UI_SCREEN_WIDTH is defined. For devices with xxxhdpi and xxhdpi, we set the
1962# variable to the commonly used values here, if it hasn't been intialized elsewhere. While for
1963# devices with lower density, they must have TARGET_RECOVERY_UI_SCREEN_WIDTH defined in their
1964# BoardConfig in order to use this feature.
1965ifeq ($(recovery_density),xxxhdpi)
1966TARGET_RECOVERY_UI_SCREEN_WIDTH ?= 1440
1967else ifeq ($(recovery_density),xxhdpi)
1968TARGET_RECOVERY_UI_SCREEN_WIDTH ?= 1080
1969endif
1970
1971ifneq ($(TARGET_RECOVERY_UI_SCREEN_WIDTH),)
1972# Subtracts the margin width and menu indent from the screen width; it's safe to be conservative.
1973ifeq ($(TARGET_RECOVERY_UI_MARGIN_WIDTH),)
1974  recovery_image_width := $$(($(TARGET_RECOVERY_UI_SCREEN_WIDTH) - 10))
1975else
1976  recovery_image_width := $$(($(TARGET_RECOVERY_UI_SCREEN_WIDTH) - $(TARGET_RECOVERY_UI_MARGIN_WIDTH) - 10))
1977endif
1978
1979
1980RECOVERY_INSTALLING_TEXT_FILE := $(call intermediates-dir-for,ETC,recovery_text_res)/installing_text.png
1981RECOVERY_INSTALLING_SECURITY_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/installing_security_text.png
1982RECOVERY_ERASING_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/erasing_text.png
1983RECOVERY_ERROR_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/error_text.png
1984RECOVERY_NO_COMMAND_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/no_command_text.png
1985
1986RECOVERY_CANCEL_WIPE_DATA_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/cancel_wipe_data_text.png
1987RECOVERY_FACTORY_DATA_RESET_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/factory_data_reset_text.png
1988RECOVERY_TRY_AGAIN_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/try_again_text.png
1989RECOVERY_WIPE_DATA_CONFIRMATION_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/wipe_data_confirmation_text.png
1990RECOVERY_WIPE_DATA_MENU_HEADER_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/wipe_data_menu_header_text.png
1991
1992generated_recovery_text_files := \
1993  $(RECOVERY_INSTALLING_TEXT_FILE) \
1994  $(RECOVERY_INSTALLING_SECURITY_TEXT_FILE) \
1995  $(RECOVERY_ERASING_TEXT_FILE) \
1996  $(RECOVERY_ERROR_TEXT_FILE) \
1997  $(RECOVERY_NO_COMMAND_TEXT_FILE) \
1998  $(RECOVERY_CANCEL_WIPE_DATA_TEXT_FILE) \
1999  $(RECOVERY_FACTORY_DATA_RESET_TEXT_FILE) \
2000  $(RECOVERY_TRY_AGAIN_TEXT_FILE) \
2001  $(RECOVERY_WIPE_DATA_CONFIRMATION_TEXT_FILE) \
2002  $(RECOVERY_WIPE_DATA_MENU_HEADER_TEXT_FILE)
2003
2004resource_dir := bootable/recovery/tools/recovery_l10n/res/
2005resource_dir_deps := $(sort $(shell find $(resource_dir) -name *.xml -not -name .*))
2006image_generator_jar := $(HOST_OUT_JAVA_LIBRARIES)/RecoveryImageGenerator.jar
2007zopflipng := $(HOST_OUT_EXECUTABLES)/zopflipng
2008$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_SOURCE_FONTS := $(recovery_noto-fonts_dep) $(recovery_roboto-fonts_dep)
2009$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_FONT_FILES_DIR := $(call intermediates-dir-for,ETC,recovery_font_files)
2010$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RESOURCE_DIR := $(resource_dir)
2011$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_IMAGE_GENERATOR_JAR := $(image_generator_jar)
2012$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_ZOPFLIPNG := $(zopflipng)
2013$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_IMAGE_WIDTH := $(recovery_image_width)
2014$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_BACKGROUND_TEXT_LIST := \
2015  recovery_installing \
2016  recovery_installing_security \
2017  recovery_erasing \
2018  recovery_error \
2019  recovery_no_command
2020$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_WIPE_DATA_TEXT_LIST := \
2021  recovery_cancel_wipe_data \
2022  recovery_factory_data_reset \
2023  recovery_try_again \
2024  recovery_wipe_data_menu_header \
2025  recovery_wipe_data_confirmation
2026$(RECOVERY_INSTALLING_TEXT_FILE): .KATI_IMPLICIT_OUTPUTS := $(filter-out $(RECOVERY_INSTALLING_TEXT_FILE),$(generated_recovery_text_files))
2027$(RECOVERY_INSTALLING_TEXT_FILE): $(image_generator_jar) $(resource_dir_deps) $(recovery_noto-fonts_dep) $(recovery_roboto-fonts_dep) $(zopflipng)
2028	# Prepares the font directory.
2029	@rm -rf $(PRIVATE_RECOVERY_FONT_FILES_DIR)
2030	@mkdir -p $(PRIVATE_RECOVERY_FONT_FILES_DIR)
2031	$(foreach filename,$(PRIVATE_SOURCE_FONTS), cp $(filename) $(PRIVATE_RECOVERY_FONT_FILES_DIR) &&) true
2032	@rm -rf $(dir $@)
2033	@mkdir -p $(dir $@)
2034	$(foreach text_name,$(PRIVATE_RECOVERY_BACKGROUND_TEXT_LIST) $(PRIVATE_RECOVERY_WIPE_DATA_TEXT_LIST), \
2035	  $(eval output_file := $(dir $@)/$(patsubst recovery_%,%_text.png,$(text_name))) \
2036	  $(eval center_alignment := $(if $(filter $(text_name),$(PRIVATE_RECOVERY_BACKGROUND_TEXT_LIST)), --center_alignment)) \
2037	  java -jar $(PRIVATE_IMAGE_GENERATOR_JAR) \
2038	    --image_width $(PRIVATE_RECOVERY_IMAGE_WIDTH) \
2039	    --text_name $(text_name) \
2040	    --font_dir $(PRIVATE_RECOVERY_FONT_FILES_DIR) \
2041	    --resource_dir $(PRIVATE_RESOURCE_DIR) \
2042	    --output_file $(output_file) $(center_alignment) && \
2043	  $(PRIVATE_ZOPFLIPNG) -y --iterations=1 --filters=0 $(output_file) $(output_file) > /dev/null &&) true
2044else
2045RECOVERY_INSTALLING_TEXT_FILE :=
2046RECOVERY_INSTALLING_SECURITY_TEXT_FILE :=
2047RECOVERY_ERASING_TEXT_FILE :=
2048RECOVERY_ERROR_TEXT_FILE :=
2049RECOVERY_NO_COMMAND_TEXT_FILE :=
2050RECOVERY_CANCEL_WIPE_DATA_TEXT_FILE :=
2051RECOVERY_FACTORY_DATA_RESET_TEXT_FILE :=
2052RECOVERY_TRY_AGAIN_TEXT_FILE :=
2053RECOVERY_WIPE_DATA_CONFIRMATION_TEXT_FILE :=
2054RECOVERY_WIPE_DATA_MENU_HEADER_TEXT_FILE :=
2055endif # TARGET_RECOVERY_UI_SCREEN_WIDTH
2056
2057ifndef TARGET_PRIVATE_RES_DIRS
2058TARGET_PRIVATE_RES_DIRS := $(wildcard $(TARGET_DEVICE_DIR)/recovery/res)
2059endif
2060recovery_resource_deps := $(shell find $(recovery_resources_common) \
2061  $(TARGET_PRIVATE_RES_DIRS) -type f)
2062recovery_resource_deps += $(generated_recovery_text_files)
2063
2064
2065ifdef TARGET_RECOVERY_FSTAB
2066recovery_fstab := $(TARGET_RECOVERY_FSTAB)
2067else
2068recovery_fstab := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery.fstab))
2069endif
2070ifdef TARGET_RECOVERY_WIPE
2071recovery_wipe := $(TARGET_RECOVERY_WIPE)
2072else
2073recovery_wipe :=
2074endif
2075
2076# Traditionally with non-A/B OTA we have:
2077#   boot.img + recovery-from-boot.p + recovery-resource.dat = recovery.img.
2078# recovery-resource.dat is needed only if we carry an imgdiff patch of the boot and recovery images
2079# and invoke install-recovery.sh on the first boot post an OTA update.
2080#
2081# We no longer need that if one of the following conditions holds:
2082#   a) We carry a full copy of the recovery image - no patching needed
2083#      (BOARD_USES_FULL_RECOVERY_IMAGE = true);
2084#   b) We build a single image that contains boot and recovery both - no recovery image to install
2085#      (BOARD_USES_RECOVERY_AS_BOOT = true);
2086#   c) We mount the system image as / and therefore do not have a ramdisk in boot.img
2087#      (BOARD_BUILD_SYSTEM_ROOT_IMAGE = true).
2088#   d) We include the recovery DTBO image within recovery - not needing the resource file as we
2089#      do bsdiff because boot and recovery will contain different number of entries
2090#      (BOARD_INCLUDE_RECOVERY_DTBO = true).
2091#   e) We include the recovery ACPIO image within recovery - not needing the resource file as we
2092#      do bsdiff because boot and recovery will contain different number of entries
2093#      (BOARD_INCLUDE_RECOVERY_ACPIO = true).
2094#   f) We build a single image that contains vendor_boot and recovery both - no recovery image to
2095#      install
2096#      (BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT = true).
2097
2098ifeq (,$(filter true, $(BOARD_USES_FULL_RECOVERY_IMAGE) $(BOARD_USES_RECOVERY_AS_BOOT) \
2099  $(BOARD_BUILD_SYSTEM_ROOT_IMAGE) $(BOARD_INCLUDE_RECOVERY_DTBO) $(BOARD_INCLUDE_RECOVERY_ACPIO) \
2100  $(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT)))
2101# Named '.dat' so we don't attempt to use imgdiff for patching it.
2102RECOVERY_RESOURCE_ZIP := $(TARGET_OUT_VENDOR)/etc/recovery-resource.dat
2103ALL_DEFAULT_INSTALLED_MODULES += $(RECOVERY_RESOURCE_ZIP)
2104else
2105RECOVERY_RESOURCE_ZIP :=
2106endif
2107
2108INSTALLED_RECOVERY_BUILD_PROP_TARGET := $(TARGET_RECOVERY_ROOT_OUT)/prop.default
2109
2110$(INSTALLED_RECOVERY_BUILD_PROP_TARGET): PRIVATE_RECOVERY_UI_PROPERTIES := \
2111    TARGET_RECOVERY_UI_ANIMATION_FPS:animation_fps \
2112    TARGET_RECOVERY_UI_MARGIN_HEIGHT:margin_height \
2113    TARGET_RECOVERY_UI_MARGIN_WIDTH:margin_width \
2114    TARGET_RECOVERY_UI_MENU_UNUSABLE_ROWS:menu_unusable_rows \
2115    TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE:progress_bar_baseline \
2116    TARGET_RECOVERY_UI_TOUCH_LOW_THRESHOLD:touch_low_threshold \
2117    TARGET_RECOVERY_UI_TOUCH_HIGH_THRESHOLD:touch_high_threshold \
2118    TARGET_RECOVERY_UI_VR_STEREO_OFFSET:vr_stereo_offset
2119
2120# Parses the given list of build variables and writes their values as build properties if defined.
2121# For example, if a target defines `TARGET_RECOVERY_UI_MARGIN_HEIGHT := 100`,
2122# `ro.recovery.ui.margin_height=100` will be appended to the given output file.
2123# $(1): Map from the build variable names to property names
2124# $(2): Output file
2125define append-recovery-ui-properties
2126echo "#" >> $(2)
2127echo "# RECOVERY UI BUILD PROPERTIES" >> $(2)
2128echo "#" >> $(2)
2129$(foreach prop,$(1), \
2130    $(eval _varname := $(call word-colon,1,$(prop))) \
2131    $(eval _propname := $(call word-colon,2,$(prop))) \
2132    $(eval _value := $($(_varname))) \
2133    $(if $(_value), \
2134        echo ro.recovery.ui.$(_propname)=$(_value) >> $(2) &&)) true
2135endef
2136
2137$(INSTALLED_RECOVERY_BUILD_PROP_TARGET): \
2138	    $(INSTALLED_BUILD_PROP_TARGET) \
2139	    $(INSTALLED_VENDOR_BUILD_PROP_TARGET) \
2140	    $(INSTALLED_ODM_BUILD_PROP_TARGET) \
2141	    $(INSTALLED_PRODUCT_BUILD_PROP_TARGET) \
2142	    $(INSTALLED_SYSTEM_EXT_BUILD_PROP_TARGET)
2143	@echo "Target recovery buildinfo: $@"
2144	$(hide) mkdir -p $(dir $@)
2145	$(hide) rm -f $@
2146	$(hide) cat $(INSTALLED_BUILD_PROP_TARGET) >> $@
2147	$(hide) cat $(INSTALLED_VENDOR_BUILD_PROP_TARGET) >> $@
2148	$(hide) cat $(INSTALLED_ODM_BUILD_PROP_TARGET) >> $@
2149	$(hide) cat $(INSTALLED_PRODUCT_BUILD_PROP_TARGET) >> $@
2150	$(hide) cat $(INSTALLED_SYSTEM_EXT_BUILD_PROP_TARGET) >> $@
2151	$(call append-recovery-ui-properties,$(PRIVATE_RECOVERY_UI_PROPERTIES),$@)
2152
2153# Only install boot/etc/build.prop to recovery image on recovery_as_boot.
2154# On device with dedicated recovery partition, the file should come from the boot
2155# ramdisk.
2156ifeq (true,$(BOARD_USES_RECOVERY_AS_BOOT))
2157INSTALLED_RECOVERY_RAMDISK_BUILD_PROP_TARGET := $(TARGET_RECOVERY_ROOT_OUT)/$(RAMDISK_BUILD_PROP_REL_PATH)
2158$(INSTALLED_RECOVERY_RAMDISK_BUILD_PROP_TARGET): $(INSTALLED_RAMDISK_BUILD_PROP_TARGET)
2159	$(copy-file-to-target)
2160endif
2161
2162INTERNAL_RECOVERYIMAGE_ARGS := --ramdisk $(recovery_ramdisk)
2163
2164ifneq (truetrue,$(strip $(BUILDING_VENDOR_BOOT_IMAGE))$(strip $(BOARD_USES_RECOVERY_AS_BOOT)))
2165INTERNAL_RECOVERYIMAGE_ARGS += $(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET))
2166# Assumes this has already been stripped
2167ifneq (true,$(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE))
2168ifdef INTERNAL_KERNEL_CMDLINE
2169  INTERNAL_RECOVERYIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)"
2170endif # INTERNAL_KERNEL_CMDLINE != ""
2171endif # BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE != true
2172ifdef BOARD_KERNEL_BASE
2173  INTERNAL_RECOVERYIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
2174endif
2175ifdef BOARD_KERNEL_PAGESIZE
2176  INTERNAL_RECOVERYIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
2177endif
2178ifdef BOARD_INCLUDE_RECOVERY_DTBO
2179ifdef BOARD_PREBUILT_RECOVERY_DTBOIMAGE
2180  INTERNAL_RECOVERYIMAGE_ARGS += --recovery_dtbo $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE)
2181else
2182  INTERNAL_RECOVERYIMAGE_ARGS += --recovery_dtbo $(BOARD_PREBUILT_DTBOIMAGE)
2183endif
2184endif # BOARD_INCLUDE_RECOVERY_DTBO
2185ifdef BOARD_INCLUDE_RECOVERY_ACPIO
2186  INTERNAL_RECOVERYIMAGE_ARGS += --recovery_acpio $(BOARD_RECOVERY_ACPIO)
2187endif
2188ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
2189  INTERNAL_RECOVERYIMAGE_ARGS += --dtb $(INSTALLED_DTBIMAGE_TARGET)
2190endif
2191endif # (BUILDING_VENDOR_BOOT_IMAGE and BOARD_USES_RECOVERY_AS_BOOT)
2192ifndef BOARD_RECOVERY_MKBOOTIMG_ARGS
2193  BOARD_RECOVERY_MKBOOTIMG_ARGS := $(BOARD_MKBOOTIMG_ARGS)
2194endif
2195
2196$(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP): $(MKBOOTFS) $(COMPRESSION_COMMAND_DEPS) \
2197	    $(INTERNAL_ROOT_FILES) \
2198	    $(INSTALLED_RAMDISK_TARGET) \
2199	    $(INTERNAL_RECOVERYIMAGE_FILES) \
2200	    $(recovery_sepolicy) \
2201	    $(INSTALLED_2NDBOOTLOADER_TARGET) \
2202	    $(INSTALLED_RECOVERY_BUILD_PROP_TARGET) \
2203	    $(INSTALLED_RECOVERY_RAMDISK_BUILD_PROP_TARGET) \
2204	    $(recovery_resource_deps) \
2205	    $(recovery_fstab)
2206	# Making recovery image
2207	mkdir -p $(TARGET_RECOVERY_OUT)
2208	mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/sdcard $(TARGET_RECOVERY_ROOT_OUT)/tmp
2209	# Copying baseline ramdisk...
2210	# Use rsync because "cp -Rf" fails to overwrite broken symlinks on Mac.
2211	rsync -a --exclude=sdcard $(IGNORE_RECOVERY_SEPOLICY) $(IGNORE_CACHE_LINK) $(TARGET_ROOT_OUT) $(TARGET_RECOVERY_OUT)
2212	# Modifying ramdisk contents...
2213	$(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)),, \
2214	  ln -sf /system/bin/init $(TARGET_RECOVERY_ROOT_OUT)/init)
2215	# Removes $(TARGET_RECOVERY_ROOT_OUT)/init*.rc EXCEPT init.recovery*.rc.
2216	find $(TARGET_RECOVERY_ROOT_OUT) -maxdepth 1 -name 'init*.rc' -type f -not -name "init.recovery.*.rc" | xargs rm -f
2217	cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/ 2> /dev/null || true # Ignore error when the src file doesn't exist.
2218	mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/res
2219	rm -rf $(TARGET_RECOVERY_ROOT_OUT)/res/*
2220	cp -rf $(recovery_resources_common)/* $(TARGET_RECOVERY_ROOT_OUT)/res
2221	$(foreach recovery_text_file,$(generated_recovery_text_files), \
2222	  cp -rf $(recovery_text_file) $(TARGET_RECOVERY_ROOT_OUT)/res/images/ &&) true
2223	cp -f $(recovery_font) $(TARGET_RECOVERY_ROOT_OUT)/res/images/font.png
2224	$(foreach item,$(TARGET_PRIVATE_RES_DIRS), \
2225	  cp -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/$(newline))
2226	$(foreach item,$(recovery_fstab), \
2227	  cp -f $(item) $(TARGET_RECOVERY_ROOT_OUT)/system/etc/recovery.fstab)
2228	$(if $(strip $(recovery_wipe)), \
2229	  cp -f $(recovery_wipe) $(TARGET_RECOVERY_ROOT_OUT)/system/etc/recovery.wipe)
2230	ln -sf prop.default $(TARGET_RECOVERY_ROOT_OUT)/default.prop
2231	$(BOARD_RECOVERY_IMAGE_PREPARE)
2232	$(hide) touch $@
2233
2234$(recovery_ramdisk): $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
2235	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RECOVERY_ROOT_OUT) | $(COMPRESSION_COMMAND) > $(recovery_ramdisk)
2236
2237# $(1): output file
2238# $(2): optional kernel file
2239define build-recoveryimage-target
2240  $(if $(filter true,$(PRODUCT_SUPPORTS_VBOOT)), \
2241    $(MKBOOTIMG) $(if $(strip $(2)),--kernel $(strip $(2))) $(INTERNAL_RECOVERYIMAGE_ARGS) \
2242                 $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_RECOVERY_MKBOOTIMG_ARGS) \
2243                 --output $(1).unsigned, \
2244    $(MKBOOTIMG) $(if $(strip $(2)),--kernel $(strip $(2))) $(INTERNAL_RECOVERYIMAGE_ARGS) \
2245                 $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(INTERNAL_MKBOOTIMG_GKI_SINGING_ARGS) \
2246                 $(BOARD_RECOVERY_MKBOOTIMG_ARGS) --output $(1))
2247  $(if $(filter true,$(PRODUCT_SUPPORTS_BOOT_SIGNER)),\
2248    $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
2249      $(BOOT_SIGNER) /boot $(1) $(PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1),\
2250      $(BOOT_SIGNER) /recovery $(1) $(PRODUCT_VERITY_SIGNING_KEY).pk8 $(PRODUCT_VERITY_SIGNING_KEY).x509.pem $(1)\
2251    )\
2252  )
2253  $(if $(filter true,$(PRODUCT_SUPPORTS_VBOOT)), \
2254    $(VBOOT_SIGNER) $(FUTILITY) $(1).unsigned $(PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(1).keyblock $(1))
2255  $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)), \
2256    $(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(call get-bootimage-partition-size,$(1),boot))), \
2257    $(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(BOARD_RECOVERYIMAGE_PARTITION_SIZE))))
2258  $(if $(filter true,$(BOARD_AVB_ENABLE)), \
2259    $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)), \
2260      $(AVBTOOL) add_hash_footer --image $(1) --partition_size $(call get-bootimage-partition-size,$(1),boot) --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS),\
2261      $(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)))
2262endef
2263
2264recoveryimage-deps := $(MKBOOTIMG) $(recovery_ramdisk) $(recovery_kernel)
2265ifeq (true,$(PRODUCT_SUPPORTS_BOOT_SIGNER))
2266  recoveryimage-deps += $(BOOT_SIGNER)
2267endif
2268ifeq (true,$(PRODUCT_SUPPORTS_VBOOT))
2269  recoveryimage-deps += $(VBOOT_SIGNER)
2270endif
2271ifeq (true,$(BOARD_AVB_ENABLE))
2272  recoveryimage-deps += $(AVBTOOL) $(BOARD_AVB_BOOT_KEY_PATH)
2273endif
2274ifdef BOARD_GKI_SIGNING_KEY_PATH
2275  recoveryimage-deps += $(BOARD_GKI_SIGNING_KEY_PATH) $(AVBTOOL)
2276endif
2277ifdef BOARD_INCLUDE_RECOVERY_DTBO
2278  ifdef BOARD_PREBUILT_RECOVERY_DTBOIMAGE
2279    recoveryimage-deps += $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE)
2280  else
2281    recoveryimage-deps += $(BOARD_PREBUILT_DTBOIMAGE)
2282  endif
2283endif
2284ifdef BOARD_INCLUDE_RECOVERY_ACPIO
2285  recoveryimage-deps += $(BOARD_RECOVERY_ACPIO)
2286endif
2287ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
2288  recoveryimage-deps += $(INSTALLED_DTBIMAGE_TARGET)
2289endif
2290
2291ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2292$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET), $(eval $(call add-dependency,$(b),$(call bootimage-to-kernel,$(b)))))
2293$(INSTALLED_BOOTIMAGE_TARGET): $(recoveryimage-deps)
2294	$(call pretty,"Target boot image from recovery: $@")
2295	$(call build-recoveryimage-target, $@, $(PRODUCT_OUT)/$(subst .img,,$(subst boot,kernel,$(notdir $@))))
2296endif # BOARD_USES_RECOVERY_AS_BOOT
2297
2298$(INSTALLED_RECOVERYIMAGE_TARGET): $(recoveryimage-deps)
2299	$(call build-recoveryimage-target, $@, \
2300	  $(if $(filter true, $(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE)),, $(recovery_kernel)))
2301
2302ifdef RECOVERY_RESOURCE_ZIP
2303$(RECOVERY_RESOURCE_ZIP): $(INSTALLED_RECOVERYIMAGE_TARGET) | $(ZIPTIME)
2304	$(hide) mkdir -p $(dir $@)
2305	$(hide) find $(TARGET_RECOVERY_ROOT_OUT)/res -type f | sort | zip -0qrjX $@ -@
2306	$(remove-timestamps-from-package)
2307endif
2308
2309.PHONY: recoveryimage-nodeps
2310recoveryimage-nodeps:
2311	@echo "make $@: ignoring dependencies"
2312	$(call build-recoveryimage-target, $(INSTALLED_RECOVERYIMAGE_TARGET), \
2313	  $(if $(filter true, $(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE)),, $(recovery_kernel)))
2314
2315else # BUILDING_RECOVERY_IMAGE
2316RECOVERY_RESOURCE_ZIP :=
2317endif # BUILDING_RECOVERY_IMAGE
2318
2319.PHONY: recoveryimage
2320recoveryimage: $(INSTALLED_RECOVERYIMAGE_TARGET) $(RECOVERY_RESOURCE_ZIP)
2321
2322ifneq ($(BOARD_NAND_PAGE_SIZE),)
2323$(error MTD device is no longer supported and thus BOARD_NAND_PAGE_SIZE is deprecated.)
2324endif
2325
2326ifneq ($(BOARD_NAND_SPARE_SIZE),)
2327$(error MTD device is no longer supported and thus BOARD_NAND_SPARE_SIZE is deprecated.)
2328endif
2329
2330
2331# -----------------------------------------------------------------
2332# the debug ramdisk, which is the original ramdisk plus additional
2333# files: force_debuggable, adb_debug.prop and userdebug sepolicy.
2334# When /force_debuggable is present, /init will load userdebug sepolicy
2335# and property files to allow adb root, if the device is unlocked.
2336ifneq ($(BUILDING_DEBUG_BOOT_IMAGE)$(BUILDING_DEBUG_VENDOR_BOOT_IMAGE),)
2337
2338BUILT_DEBUG_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk-debug.img
2339INSTALLED_DEBUG_RAMDISK_TARGET := $(BUILT_DEBUG_RAMDISK_TARGET)
2340
2341INTERNAL_DEBUG_RAMDISK_FILES := $(filter $(TARGET_DEBUG_RAMDISK_OUT)/%, \
2342    $(ALL_GENERATED_SOURCES) \
2343    $(ALL_DEFAULT_INSTALLED_MODULES))
2344
2345INSTALLED_FILES_FILE_DEBUG_RAMDISK := $(PRODUCT_OUT)/installed-files-ramdisk-debug.txt
2346INSTALLED_FILES_JSON_DEBUG_RAMDISK := $(INSTALLED_FILES_FILE_DEBUG_RAMDISK:.txt=.json)
2347$(INSTALLED_FILES_FILE_DEBUG_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_DEBUG_RAMDISK)
2348
2349# ramdisk-debug.img will merge the content from either ramdisk.img or
2350# ramdisk-recovery.img, depending on whether BOARD_USES_RECOVERY_AS_BOOT
2351# is set or not.
2352ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2353  $(INSTALLED_FILES_FILE_DEBUG_RAMDISK): PRIVATE_ADDITIONAL_DIR := $(TARGET_RECOVERY_ROOT_OUT)
2354  $(INSTALLED_FILES_FILE_DEBUG_RAMDISK): $(recovery_ramdisk)
2355else
2356  $(INSTALLED_FILES_FILE_DEBUG_RAMDISK): PRIVATE_ADDITIONAL_DIR := $(TARGET_RAMDISK_OUT)
2357  $(INSTALLED_FILES_FILE_DEBUG_RAMDISK): $(INSTALLED_RAMDISK_TARGET)
2358endif # BOARD_USES_RECOVERY_AS_BOOT
2359
2360$(INSTALLED_FILES_FILE_DEBUG_RAMDISK) : $(INTERNAL_DEBUG_RAMDISK_FILES) $(FILESLIST) $(FILESLIST_UTIL)
2361	@echo Installed file list: $@
2362	mkdir -p $(dir $@)
2363	rm -f $@
2364	$(FILESLIST) $(TARGET_DEBUG_RAMDISK_OUT) $(PRIVATE_ADDITIONAL_DIR) > $(@:.txt=.json)
2365	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
2366
2367ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2368  $(INSTALLED_DEBUG_RAMDISK_TARGET): PRIVATE_ADDITIONAL_DIR := $(TARGET_RECOVERY_ROOT_OUT)
2369  $(INSTALLED_DEBUG_RAMDISK_TARGET): $(recovery_ramdisk)
2370else
2371  $(INSTALLED_DEBUG_RAMDISK_TARGET): PRIVATE_ADDITIONAL_DIR := $(TARGET_RAMDISK_OUT)
2372  $(INSTALLED_DEBUG_RAMDISK_TARGET): $(INSTALLED_RAMDISK_TARGET)
2373endif # BOARD_USES_RECOVERY_AS_BOOT
2374
2375$(INSTALLED_DEBUG_RAMDISK_TARGET): $(INSTALLED_FILES_FILE_DEBUG_RAMDISK)
2376$(INSTALLED_DEBUG_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_DEBUG_RAMDISK_FILES) | $(COMPRESSION_COMMAND_DEPS)
2377	$(call pretty,"Target debug ramdisk: $@")
2378	mkdir -p $(TARGET_DEBUG_RAMDISK_OUT)
2379	touch $(TARGET_DEBUG_RAMDISK_OUT)/force_debuggable
2380	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_DEBUG_RAMDISK_OUT) $(PRIVATE_ADDITIONAL_DIR) | $(COMPRESSION_COMMAND) > $@
2381
2382.PHONY: ramdisk_debug-nodeps
2383ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2384  ramdisk_debug-nodeps: PRIVATE_ADDITIONAL_DIR := $(TARGET_RECOVERY_ROOT_OUT)
2385else
2386  ramdisk_debug-nodeps: PRIVATE_ADDITIONAL_DIR := $(TARGET_RAMDISK_OUT)
2387endif # BOARD_USES_RECOVERY_AS_BOOT
2388ramdisk_debug-nodeps: $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
2389	echo "make $@: ignoring dependencies"
2390	mkdir -p $(TARGET_DEBUG_RAMDISK_OUT)
2391	touch $(TARGET_DEBUG_RAMDISK_OUT)/force_debuggable
2392	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_DEBUG_RAMDISK_OUT) $(PRIVATE_ADDITIONAL_DIR) | $(COMPRESSION_COMMAND) > $(INSTALLED_DEBUG_RAMDISK_TARGET)
2393
2394endif # BUILDING_DEBUG_BOOT_IMAGE || BUILDING_DEBUG_VENDOR_BOOT_IMAGE
2395
2396# -----------------------------------------------------------------
2397# the boot-debug.img, which is the kernel plus ramdisk-debug.img
2398#
2399# Note: it's intentional to skip signing for boot-debug.img, because it
2400# can only be used if the device is unlocked with verification error.
2401ifdef BUILDING_DEBUG_BOOT_IMAGE
2402
2403ifneq ($(strip $(BOARD_KERNEL_BINARIES)),)
2404  INSTALLED_DEBUG_BOOTIMAGE_TARGET := $(foreach k,$(subst kernel,boot-debug,$(BOARD_KERNEL_BINARIES)), \
2405         $(PRODUCT_OUT)/$(k).img)
2406else
2407  INSTALLED_DEBUG_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot-debug.img
2408endif
2409
2410# Replace ramdisk.img in $(MKBOOTIMG) ARGS with ramdisk-debug.img to build boot-debug.img
2411ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2412  INTERNAL_DEBUG_BOOTIMAGE_ARGS := $(subst $(recovery_ramdisk),$(INSTALLED_DEBUG_RAMDISK_TARGET), $(INTERNAL_RECOVERYIMAGE_ARGS))
2413else
2414  INTERNAL_DEBUG_BOOTIMAGE_ARGS := $(subst $(INSTALLED_RAMDISK_TARGET),$(INSTALLED_DEBUG_RAMDISK_TARGET), $(INTERNAL_BOOTIMAGE_ARGS))
2415endif
2416
2417# If boot.img is chained but boot-debug.img is not signed, libavb in bootloader
2418# will fail to find valid AVB metadata from the end of /boot, thus stop booting.
2419# Using a test key to sign boot-debug.img to continue booting with the mismatched
2420# public key, if the device is unlocked.
2421ifneq ($(BOARD_AVB_BOOT_KEY_PATH),)
2422$(INSTALLED_DEBUG_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_BOOT_TEST_KEY_PATH)
2423endif
2424
2425BOARD_AVB_BOOT_TEST_KEY_PATH := external/avb/test/data/testkey_rsa2048.pem
2426INTERNAL_AVB_BOOT_TEST_SIGNING_ARGS := --algorithm SHA256_RSA2048 --key $(BOARD_AVB_BOOT_TEST_KEY_PATH)
2427# $(1): the bootimage to sign
2428# $(2): boot image variant (boot, boot-debug, boot-test-harness)
2429define test-key-sign-bootimage
2430$(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(call get-bootimage-partition-size,$(1),$(2))))
2431$(AVBTOOL) add_hash_footer \
2432  --image $(1) \
2433  --partition_size $(call get-bootimage-partition-size,$(1),$(2))\
2434  --partition_name boot $(INTERNAL_AVB_BOOT_TEST_SIGNING_ARGS) \
2435  $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)
2436$(call assert-max-image-size,$(1),$(call get-bootimage-partition-size,$(1),$(2)))
2437endef
2438
2439# $(1): output file
2440define build-debug-bootimage-target
2441  $(MKBOOTIMG) --kernel $(PRODUCT_OUT)/$(subst .img,,$(subst boot-debug,kernel,$(notdir $(1)))) \
2442    $(INTERNAL_DEBUG_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) \
2443    $(INTERNAL_MKBOOTIMG_GKI_SINGING_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $1
2444  $(if $(BOARD_AVB_BOOT_KEY_PATH),$(call test-key-sign-bootimage,$1,boot-debug))
2445endef
2446
2447# Depends on original boot.img and ramdisk-debug.img, to build the new boot-debug.img
2448$(INSTALLED_DEBUG_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_BOOTIMAGE_TARGET) $(INSTALLED_DEBUG_RAMDISK_TARGET) $(BOARD_GKI_SIGNING_KEY_PATH) $(AVBTOOL)
2449	$(call pretty,"Target boot debug image: $@")
2450	$(call build-debug-bootimage-target, $@)
2451
2452.PHONY: bootimage_debug-nodeps
2453bootimage_debug-nodeps: $(MKBOOTIMG) $(BOARD_GKI_SIGNING_KEY_PATH) $(AVBTOOL)
2454	echo "make $@: ignoring dependencies"
2455	$(foreach b,$(INSTALLED_DEBUG_BOOTIMAGE_TARGET),$(call build-debug-bootimage-target,$b))
2456
2457endif # BUILDING_DEBUG_BOOT_IMAGE
2458
2459# -----------------------------------------------------------------
2460# vendor debug ramdisk
2461# Combines vendor ramdisk files and debug ramdisk files to build the vendor debug ramdisk.
2462ifdef BUILDING_DEBUG_VENDOR_BOOT_IMAGE
2463
2464INTERNAL_VENDOR_DEBUG_RAMDISK_FILES := $(filter $(TARGET_VENDOR_DEBUG_RAMDISK_OUT)/%, \
2465    $(ALL_GENERATED_SOURCES) \
2466    $(ALL_DEFAULT_INSTALLED_MODULES))
2467
2468INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK := $(PRODUCT_OUT)/installed-files-vendor-ramdisk-debug.txt
2469INSTALLED_FILES_JSON_VENDOR_DEBUG_RAMDISK := $(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK:.txt=.json)
2470$(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_VENDOR_DEBUG_RAMDISK)
2471$(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK): $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INSTALLED_DEBUG_RAMDISK_TARGET)
2472$(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK): $(INTERNAL_VENDOR_DEBUG_RAMDISK_FILES) $(FILESLIST) $(FILESLIST_UTIL)
2473	@echo Installed file list: $@
2474	mkdir -p $(dir $@)
2475	rm -f $@
2476	mkdir -p $(TARGET_VENDOR_DEBUG_RAMDISK_OUT) # The dir might not be created if no modules are installed here.
2477	$(FILESLIST) $(TARGET_VENDOR_RAMDISK_OUT) $(TARGET_DEBUG_RAMDISK_OUT) $(TARGET_VENDOR_DEBUG_RAMDISK_OUT) > $(@:.txt=.json)
2478	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
2479
2480INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET := $(call intermediates-dir-for,PACKAGING,vendor_boot-debug)/vendor_ramdisk-debug.cpio$(RAMDISK_EXT)
2481
2482# Exclude recovery files in the default vendor ramdisk if including a standalone
2483# recovery ramdisk in vendor_boot.
2484ifeq (true,$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT))
2485ifneq (true,$(BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT))
2486$(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET): $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
2487$(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET): PRIVATE_ADDITIONAL_DIR := $(TARGET_RECOVERY_ROOT_OUT)
2488endif
2489endif
2490
2491# The vendor debug ramdisk combines vendor ramdisk and debug ramdisk.
2492$(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET): $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INSTALLED_DEBUG_RAMDISK_TARGET)
2493$(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET): $(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK)
2494$(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_VENDOR_DEBUG_RAMDISK_FILES) | $(COMPRESSION_COMMAND_DEPS)
2495	mkdir -p $(TARGET_VENDOR_DEBUG_RAMDISK_OUT)
2496	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_VENDOR_RAMDISK_OUT) $(TARGET_DEBUG_RAMDISK_OUT) $(TARGET_VENDOR_DEBUG_RAMDISK_OUT) $(PRIVATE_ADDITIONAL_DIR) | $(COMPRESSION_COMMAND) > $@
2497
2498ifeq (true,$(BOARD_BUILD_VENDOR_RAMDISK_IMAGE))
2499INSTALLED_VENDOR_DEBUG_RAMDISK_TARGET := $(PRODUCT_OUT)/vendor_ramdisk-debug.img
2500$(INSTALLED_VENDOR_DEBUG_RAMDISK_TARGET): $(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET)
2501	$(call pretty,"Target vendor debug ramdisk: $@")
2502	$(copy-file-to-target)
2503endif
2504
2505# -----------------------------------------------------------------
2506# vendor_boot-debug.img.
2507INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/vendor_boot-debug.img
2508
2509# The util to sign vendor_boot-debug.img with a test key.
2510BOARD_AVB_VENDOR_BOOT_TEST_KEY_PATH := external/avb/test/data/testkey_rsa2048.pem
2511INTERNAL_AVB_VENDOR_BOOT_TEST_SIGNING_ARGS := --algorithm SHA256_RSA2048 --key $(BOARD_AVB_VENDOR_BOOT_TEST_KEY_PATH)
2512# $(1): the vendor bootimage to sign
2513define test-key-sign-vendor-bootimage
2514$(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE)))
2515$(AVBTOOL) add_hash_footer \
2516  --image $(1) \
2517  --partition_size $(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE) \
2518  --partition_name vendor_boot $(INTERNAL_AVB_VENDOR_BOOT_TEST_SIGNING_ARGS) \
2519  $(BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS)
2520$(call assert-max-image-size,$(1),$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE))
2521endef
2522
2523ifneq ($(BOARD_AVB_VENDOR_BOOT_KEY_PATH),)
2524$(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_VENDOR_BOOT_TEST_KEY_PATH)
2525endif
2526
2527# Depends on vendor_boot.img and vendor-ramdisk-debug.cpio.gz to build the new vendor_boot-debug.img
2528$(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_VENDOR_BOOTIMAGE_TARGET) $(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET)
2529$(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET): $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS)
2530	$(call pretty,"Target vendor_boot debug image: $@")
2531	$(MKBOOTIMG) $(INTERNAL_VENDOR_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --vendor_ramdisk $(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET) $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS) --vendor_boot $@
2532	$(call assert-max-image-size,$@,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE))
2533	$(if $(BOARD_AVB_VENDOR_BOOT_KEY_PATH),$(call test-key-sign-vendor-bootimage,$@))
2534
2535endif # BUILDING_DEBUG_VENDOR_BOOT_IMAGE
2536
2537# -----------------------------------------------------------------
2538# The test harness ramdisk, which is based off debug_ramdisk, plus a
2539# few additional test-harness-specific properties in adb_debug.prop.
2540ifneq ($(BUILDING_DEBUG_BOOT_IMAGE)$(BUILDING_DEBUG_VENDOR_BOOT_IMAGE),)
2541
2542BUILT_TEST_HARNESS_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk-test-harness.img
2543INSTALLED_TEST_HARNESS_RAMDISK_TARGET := $(BUILT_TEST_HARNESS_RAMDISK_TARGET)
2544
2545# Appends a few test harness specific properties into the adb_debug.prop.
2546TEST_HARNESS_PROP_TARGET := $(TARGET_TEST_HARNESS_RAMDISK_OUT)/adb_debug.prop
2547ADDITIONAL_TEST_HARNESS_PROPERTIES := ro.audio.silent=1
2548ADDITIONAL_TEST_HARNESS_PROPERTIES += ro.test_harness=1
2549
2550# $(1): a list of key=value pairs for additional property assignments
2551# $(2): the target .prop file to append the properties from $(1)
2552define append-test-harness-props
2553  echo "#" >> $(2); \
2554  echo "# ADDITIONAL TEST HARNESS_PROPERTIES" >> $(2); \
2555  echo "#" >> $(2);
2556  $(foreach line,$(1), echo "$(line)" >> $(2);)
2557endef
2558
2559INTERNAL_TEST_HARNESS_RAMDISK_FILES := $(filter $(TARGET_TEST_HARNESS_RAMDISK_OUT)/%, \
2560    $(ALL_GENERATED_SOURCES) \
2561    $(ALL_DEFAULT_INSTALLED_MODULES))
2562
2563# ramdisk-test-harness.img will merge the content from either ramdisk.img or
2564# ramdisk-recovery.img, depending on whether BOARD_USES_RECOVERY_AS_BOOT is set
2565# or not.
2566ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2567  $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET): PRIVATE_ADDITIONAL_DIR := $(TARGET_RECOVERY_ROOT_OUT)
2568  $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET): $(recovery_ramdisk)
2569else
2570  $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET): PRIVATE_ADDITIONAL_DIR := $(TARGET_RAMDISK_OUT)
2571  $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET): $(INSTALLED_RAMDISK_TARGET)
2572endif # BOARD_USES_RECOVERY_AS_BOOT
2573
2574# The test harness ramdisk will rsync the files from the debug ramdisk, then appends some props.
2575$(INSTALLED_TEST_HARNESS_RAMDISK_TARGET): $(INSTALLED_DEBUG_RAMDISK_TARGET)
2576$(INSTALLED_TEST_HARNESS_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_TEST_HARNESS_RAMDISK_FILES) | $(COMPRESSION_COMMAND_DEPS)
2577	$(call pretty,"Target test harness ramdisk: $@")
2578	rsync --chmod=u+w -a $(TARGET_DEBUG_RAMDISK_OUT)/ $(TARGET_TEST_HARNESS_RAMDISK_OUT)
2579	$(call append-test-harness-props,$(ADDITIONAL_TEST_HARNESS_PROPERTIES),$(TEST_HARNESS_PROP_TARGET))
2580	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_TEST_HARNESS_RAMDISK_OUT) $(PRIVATE_ADDITIONAL_DIR) | $(COMPRESSION_COMMAND) > $@
2581
2582.PHONY: ramdisk_test_harness-nodeps
2583ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2584  ramdisk_test_harness-nodeps: PRIVATE_ADDITIONAL_DIR := $(TARGET_RECOVERY_ROOT_OUT)
2585else
2586  ramdisk_test_harness-nodeps: PRIVATE_ADDITIONAL_DIR := $(TARGET_RAMDISK_OUT)
2587endif # BOARD_USES_RECOVERY_AS_BOOT
2588ramdisk_test_harness-nodeps: $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
2589	echo "make $@: ignoring dependencies"
2590	rsync --chmod=u+w -a $(TARGET_DEBUG_RAMDISK_OUT)/ $(TARGET_TEST_HARNESS_RAMDISK_OUT)
2591	$(call append-test-harness-props,$(ADDITIONAL_TEST_HARNESS_PROPERTIES),$(TEST_HARNESS_PROP_TARGET))
2592	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_TEST_HARNESS_RAMDISK_OUT) $(PRIVATE_ADDITIONAL_DIR) | $(COMPRESSION_COMMAND) > $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET)
2593
2594endif # BUILDING_DEBUG_BOOT_IMAGE || BUILDING_DEBUG_VENDOR_BOOT_IMAGE
2595
2596# -----------------------------------------------------------------
2597# the boot-test-harness.img, which is the kernel plus ramdisk-test-harness.img
2598#
2599# Note: it's intentional to skip signing for boot-test-harness.img, because it
2600# can only be used if the device is unlocked with verification error.
2601ifdef BUILDING_DEBUG_BOOT_IMAGE
2602
2603ifneq ($(strip $(BOARD_KERNEL_BINARIES)),)
2604  INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET := $(foreach k,$(subst kernel,boot-test-harness,$(BOARD_KERNEL_BINARIES)), \
2605    $(PRODUCT_OUT)/$(k).img)
2606else
2607  INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot-test-harness.img
2608endif
2609
2610# Replace ramdisk-debug.img in $(MKBOOTIMG) ARGS with ramdisk-test-harness.img to build boot-test-harness.img
2611INTERNAL_TEST_HARNESS_BOOTIMAGE_ARGS := $(subst $(INSTALLED_DEBUG_RAMDISK_TARGET),$(INSTALLED_TEST_HARNESS_RAMDISK_TARGET),$(INTERNAL_DEBUG_BOOTIMAGE_ARGS))
2612
2613# If boot.img is chained but boot-test-harness.img is not signed, libavb in bootloader
2614# will fail to find valid AVB metadata from the end of /boot, thus stop booting.
2615# Using a test key to sign boot-test-harness.img to continue booting with the mismatched
2616# public key, if the device is unlocked.
2617ifneq ($(BOARD_AVB_BOOT_KEY_PATH),)
2618$(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_BOOT_TEST_KEY_PATH)
2619endif
2620
2621# $(1): output file
2622define build-boot-test-harness-target
2623  $(MKBOOTIMG) --kernel $(PRODUCT_OUT)/$(subst .img,,$(subst boot-test-harness,kernel,$(notdir $(1)))) \
2624    $(INTERNAL_TEST_HARNESS_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) \
2625    $(INTERNAL_MKBOOTIMG_GKI_SINGING_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
2626  $(if $(BOARD_AVB_BOOT_KEY_PATH),$(call test-key-sign-bootimage,$@,boot-test-harness))
2627endef
2628
2629# Build the new boot-test-harness.img, based on boot-debug.img and ramdisk-test-harness.img.
2630$(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_DEBUG_BOOTIMAGE_TARGET) $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET) \
2631$(BOARD_GKI_SIGNING_KEY_PATH) $(AVBTOOL)
2632	$(call pretty,"Target boot test harness image: $@")
2633	$(call build-boot-test-harness-target,$@)
2634
2635.PHONY: bootimage_test_harness-nodeps
2636bootimage_test_harness-nodeps: $(MKBOOTIMG) $(BOARD_GKI_SIGNING_KEY_PATH) $(AVBTOOL)
2637	echo "make $@: ignoring dependencies"
2638	$(foreach b,$(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET),$(call build-boot-test-harness-target,$b))
2639
2640endif # BUILDING_DEBUG_BOOT_IMAGE
2641
2642# -----------------------------------------------------------------
2643# vendor test harness ramdisk, which is a vendor ramdisk combined with
2644# a test harness ramdisk.
2645ifdef BUILDING_DEBUG_VENDOR_BOOT_IMAGE
2646
2647INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET := $(call intermediates-dir-for,PACKAGING,vendor_boot-test-harness)/vendor_ramdisk-test-harness.cpio$(RAMDISK_EXT)
2648
2649# Exclude recovery files in the default vendor ramdisk if including a standalone
2650# recovery ramdisk in vendor_boot.
2651ifeq (true,$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT))
2652ifneq (true,$(BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT))
2653$(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET): $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
2654$(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET): PRIVATE_ADDITIONAL_DIR := $(TARGET_RECOVERY_ROOT_OUT)
2655endif
2656endif
2657
2658# The vendor test harness ramdisk combines vendor ramdisk and test harness ramdisk.
2659$(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET): $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET)
2660$(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET): $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
2661	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_VENDOR_RAMDISK_OUT) $(TARGET_TEST_HARNESS_RAMDISK_OUT) $(PRIVATE_ADDITIONAL_DIR) | $(COMPRESSION_COMMAND) > $@
2662
2663# -----------------------------------------------------------------
2664# vendor_boot-test-harness.img.
2665INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/vendor_boot-test-harness.img
2666
2667ifneq ($(BOARD_AVB_VENDOR_BOOT_KEY_PATH),)
2668$(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_VENDOR_BOOT_TEST_KEY_PATH)
2669endif
2670
2671# Depends on vendor_boot.img and vendor_ramdisk-test-harness.cpio$(RAMDISK_EXT) to build the new vendor_boot-test-harness.img
2672$(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_VENDOR_BOOTIMAGE_TARGET)
2673$(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET): $(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET)
2674$(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET): $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS)
2675	$(call pretty,"Target vendor_boot test harness image: $@")
2676	$(MKBOOTIMG) $(INTERNAL_VENDOR_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --vendor_ramdisk $(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET) $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS) --vendor_boot $@
2677	$(call assert-max-image-size,$@,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE))
2678	$(if $(BOARD_AVB_VENDOR_BOOT_KEY_PATH),$(call test-key-sign-vendor-bootimage,$@))
2679
2680endif # BUILDING_DEBUG_VENDOR_BOOT_IMAGE
2681
2682
2683# Creates a compatibility symlink between two partitions, e.g. /system/vendor to /vendor
2684# $1: from location (e.g $(TARGET_OUT)/vendor)
2685# $2: destination location (e.g. /vendor)
2686# $3: partition image name (e.g. vendor.img)
2687define create-partition-compat-symlink
2688$(eval \
2689$1:
2690	@echo Symlink $(patsubst $(PRODUCT_OUT)/%,%,$1) to $2
2691	mkdir -p $(dir $1)
2692	if [ -d $1 ] && [ ! -h $1 ]; then \
2693	  echo 'Non-symlink $1 detected!' 1>&2; \
2694	  echo 'You cannot install files to $1 while building a separate $3!' 1>&2; \
2695	  exit 1; \
2696	fi
2697	ln -sfn $2 $1
2698$1: .KATI_SYMLINK_OUTPUTS := $1
2699)
2700$1
2701endef
2702
2703
2704# -----------------------------------------------------------------
2705# system image
2706
2707INTERNAL_SYSTEMIMAGE_FILES := $(sort $(filter $(TARGET_OUT)/%, \
2708    $(ALL_GENERATED_SOURCES) \
2709    $(ALL_DEFAULT_INSTALLED_MODULES)))
2710
2711# Create symlink /system/vendor to /vendor if necessary.
2712ifdef BOARD_USES_VENDORIMAGE
2713  INTERNAL_SYSTEMIMAGE_FILES += $(call create-partition-compat-symlink,$(TARGET_OUT)/vendor,/vendor,vendor.img)
2714endif
2715
2716# Create symlink /system/product to /product if necessary.
2717ifdef BOARD_USES_PRODUCTIMAGE
2718  INTERNAL_SYSTEMIMAGE_FILES += $(call create-partition-compat-symlink,$(TARGET_OUT)/product,/product,product.img)
2719endif
2720
2721# Create symlink /system/system_ext to /system_ext if necessary.
2722ifdef BOARD_USES_SYSTEM_EXTIMAGE
2723  INTERNAL_SYSTEMIMAGE_FILES += $(call create-partition-compat-symlink,$(TARGET_OUT)/system_ext,/system_ext,system_ext.img)
2724endif
2725
2726FULL_SYSTEMIMAGE_DEPS := $(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_USERIMAGES_DEPS)
2727
2728# ASAN libraries in the system image - add dependency.
2729ASAN_IN_SYSTEM_INSTALLED := $(TARGET_OUT)/asan.tar.bz2
2730ifneq (,$(filter address, $(SANITIZE_TARGET)))
2731  ifeq (true,$(SANITIZE_TARGET_SYSTEM))
2732    FULL_SYSTEMIMAGE_DEPS += $(ASAN_IN_SYSTEM_INSTALLED)
2733  endif
2734endif
2735
2736FULL_SYSTEMIMAGE_DEPS += $(INTERNAL_ROOT_FILES) $(INSTALLED_FILES_FILE_ROOT)
2737
2738# -----------------------------------------------------------------
2739ifdef BUILDING_SYSTEM_IMAGE
2740
2741# Install system linker configuration
2742# Collect all available stub libraries installed in system and install with predefined linker configuration
2743SYSTEM_LINKER_CONFIG := $(TARGET_OUT)/etc/linker.config.pb
2744$(SYSTEM_LINKER_CONFIG) : $(INTERNAL_SYSTEMIMAGE_FILES) $(LINKER_CONFIG_PATH_system_linker_config) | conv_linker_config
2745	$(HOST_OUT_EXECUTABLES)/conv_linker_config systemprovide --source $(LINKER_CONFIG_PATH_system_linker_config)\
2746	  --output $@ --value "$(STUB_LIBRARIES)" --system "$(TARGET_OUT)"
2747
2748FULL_SYSTEMIMAGE_DEPS += $(SYSTEM_LINKER_CONFIG)
2749
2750# installed file list
2751# Depending on anything that $(BUILT_SYSTEMIMAGE) depends on.
2752# We put installed-files.txt ahead of image itself in the dependency graph
2753# so that we can get the size stat even if the build fails due to too large
2754# system image.
2755INSTALLED_FILES_FILE := $(PRODUCT_OUT)/installed-files.txt
2756INSTALLED_FILES_JSON := $(INSTALLED_FILES_FILE:.txt=.json)
2757$(INSTALLED_FILES_FILE): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON)
2758$(INSTALLED_FILES_FILE): $(FULL_SYSTEMIMAGE_DEPS) $(FILESLIST) $(FILESLIST_UTIL)
2759	@echo Installed file list: $@
2760	mkdir -p $(dir $@)
2761	rm -f $@
2762	$(FILESLIST) $(TARGET_OUT) > $(@:.txt=.json)
2763	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
2764
2765.PHONY: installed-file-list
2766installed-file-list: $(INSTALLED_FILES_FILE)
2767
2768$(call dist-for-goals, sdk win_sdk sdk_addon, $(INSTALLED_FILES_FILE))
2769
2770systemimage_intermediates := \
2771    $(call intermediates-dir-for,PACKAGING,systemimage)
2772BUILT_SYSTEMIMAGE := $(systemimage_intermediates)/system.img
2773
2774# $(1): output file
2775define build-systemimage-target
2776  @echo "Target system fs image: $(1)"
2777  @mkdir -p $(dir $(1)) $(systemimage_intermediates) && rm -rf $(systemimage_intermediates)/system_image_info.txt
2778  $(call generate-image-prop-dictionary, $(systemimage_intermediates)/system_image_info.txt,system, \
2779      skip_fsck=true)
2780  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
2781      $(BUILD_IMAGE) \
2782          $(TARGET_OUT) $(systemimage_intermediates)/system_image_info.txt $(1) $(TARGET_OUT) \
2783          || ( mkdir -p $${DIST_DIR}; \
2784               cp $(INSTALLED_FILES_FILE) $${DIST_DIR}/installed-files-rescued.txt; \
2785               exit 1 )
2786endef
2787
2788ifeq ($(BOARD_AVB_ENABLE),true)
2789$(BUILT_SYSTEMIMAGE): $(BOARD_AVB_SYSTEM_KEY_PATH)
2790endif
2791$(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE)
2792	$(call build-systemimage-target,$@)
2793
2794INSTALLED_SYSTEMIMAGE_TARGET := $(PRODUCT_OUT)/system.img
2795SYSTEMIMAGE_SOURCE_DIR := $(TARGET_OUT)
2796
2797# INSTALLED_SYSTEMIMAGE_TARGET used to be named INSTALLED_SYSTEMIMAGE. Create an alias for backward
2798# compatibility, in case device-specific Makefiles still refer to the old name.
2799INSTALLED_SYSTEMIMAGE := $(INSTALLED_SYSTEMIMAGE_TARGET)
2800
2801# The system partition needs room for the recovery image as well.  We
2802# now store the recovery image as a binary patch using the boot image
2803# as the source (since they are very similar).  Generate the patch so
2804# we can see how big it's going to be, and include that in the system
2805# image size check calculation.
2806ifneq ($(INSTALLED_BOOTIMAGE_TARGET),)
2807ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
2808ifneq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
2809ifneq (,$(filter true, $(BOARD_BUILD_SYSTEM_ROOT_IMAGE) $(BOARD_INCLUDE_RECOVERY_DTBO) $(BOARD_INCLUDE_RECOVERY_ACPIO)))
2810diff_tool := $(HOST_OUT_EXECUTABLES)/bsdiff
2811else
2812diff_tool := $(HOST_OUT_EXECUTABLES)/imgdiff
2813endif
2814intermediates := $(call intermediates-dir-for,PACKAGING,recovery_patch)
2815RECOVERY_FROM_BOOT_PATCH := $(intermediates)/recovery_from_boot.p
2816$(RECOVERY_FROM_BOOT_PATCH): PRIVATE_DIFF_TOOL := $(diff_tool)
2817$(RECOVERY_FROM_BOOT_PATCH): \
2818	    $(INSTALLED_RECOVERYIMAGE_TARGET) \
2819	    $(firstword $(INSTALLED_BOOTIMAGE_TARGET)) \
2820	    $(diff_tool)
2821	@echo "Construct recovery from boot"
2822	mkdir -p $(dir $@)
2823	$(PRIVATE_DIFF_TOOL) $(firstword $(INSTALLED_BOOTIMAGE_TARGET)) $(INSTALLED_RECOVERYIMAGE_TARGET) $@
2824else # $(BOARD_USES_FULL_RECOVERY_IMAGE) == true
2825RECOVERY_FROM_BOOT_PATCH := $(INSTALLED_RECOVERYIMAGE_TARGET)
2826endif # BOARD_USES_FULL_RECOVERY_IMAGE
2827endif # INSTALLED_RECOVERYIMAGE_TARGET
2828endif # INSTALLED_BOOTIMAGE_TARGET
2829
2830$(INSTALLED_SYSTEMIMAGE_TARGET): $(BUILT_SYSTEMIMAGE)
2831	@echo "Install system fs image: $@"
2832	$(copy-file-to-target)
2833	$(hide) $(call assert-max-image-size,$@,$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
2834
2835systemimage: $(INSTALLED_SYSTEMIMAGE_TARGET)
2836
2837.PHONY: systemimage-nodeps snod
2838systemimage-nodeps snod: $(filter-out systemimage-nodeps snod,$(MAKECMDGOALS)) \
2839	            | $(INTERNAL_USERIMAGES_DEPS)
2840	@echo "make $@: ignoring dependencies"
2841	$(call build-systemimage-target,$(INSTALLED_SYSTEMIMAGE_TARGET))
2842	$(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMIMAGE_TARGET),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
2843ifeq (true,$(WITH_DEXPREOPT))
2844	$(warning Warning: with dexpreopt enabled, you may need a full rebuild.)
2845endif
2846
2847endif # BUILDING_SYSTEM_IMAGE
2848
2849.PHONY: sync syncsys
2850sync syncsys: $(INTERNAL_SYSTEMIMAGE_FILES)
2851
2852# -----------------------------------------------------------------
2853# Old PDK fusion targets
2854.PHONY: platform
2855platform:
2856	echo "Warning: 'platform' is obsolete"
2857
2858.PHONY: platform-java
2859platform-java:
2860	echo "Warning: 'platform-java' is obsolete"
2861
2862# -----------------------------------------------------------------
2863# data partition image
2864INTERNAL_USERDATAIMAGE_FILES := \
2865    $(filter $(TARGET_OUT_DATA)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
2866
2867ifdef BUILDING_USERDATA_IMAGE
2868userdataimage_intermediates := \
2869    $(call intermediates-dir-for,PACKAGING,userdata)
2870BUILT_USERDATAIMAGE_TARGET := $(PRODUCT_OUT)/userdata.img
2871
2872define build-userdataimage-target
2873  $(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
2874  @mkdir -p $(TARGET_OUT_DATA)
2875  @mkdir -p $(userdataimage_intermediates) && rm -rf $(userdataimage_intermediates)/userdata_image_info.txt
2876  $(call generate-image-prop-dictionary, $(userdataimage_intermediates)/userdata_image_info.txt,userdata,skip_fsck=true)
2877  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
2878      $(BUILD_IMAGE) \
2879          $(TARGET_OUT_DATA) $(userdataimage_intermediates)/userdata_image_info.txt \
2880          $(INSTALLED_USERDATAIMAGE_TARGET) $(TARGET_OUT)
2881  $(call assert-max-image-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_PARTITION_SIZE))
2882endef
2883
2884# We just build this directly to the install location.
2885INSTALLED_USERDATAIMAGE_TARGET := $(BUILT_USERDATAIMAGE_TARGET)
2886INSTALLED_USERDATAIMAGE_TARGET_DEPS := \
2887    $(INTERNAL_USERIMAGES_DEPS) \
2888    $(INTERNAL_USERDATAIMAGE_FILES)
2889$(INSTALLED_USERDATAIMAGE_TARGET): $(INSTALLED_USERDATAIMAGE_TARGET_DEPS)
2890	$(build-userdataimage-target)
2891
2892.PHONY: userdataimage-nodeps
2893userdataimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
2894	$(build-userdataimage-target)
2895
2896endif # BUILDING_USERDATA_IMAGE
2897
2898# ASAN libraries in the system image - build rule.
2899ASAN_OUT_DIRS_FOR_SYSTEM_INSTALL := $(sort $(patsubst $(PRODUCT_OUT)/%,%,\
2900  $(TARGET_OUT_SHARED_LIBRARIES) \
2901  $(2ND_TARGET_OUT_SHARED_LIBRARIES) \
2902  $(TARGET_OUT_VENDOR_SHARED_LIBRARIES) \
2903  $(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)))
2904# Extra options: Enforce the system user for the files to avoid having to change ownership.
2905ASAN_SYSTEM_INSTALL_OPTIONS := --owner=1000 --group=1000
2906# Note: experimentally, it seems not worth it to try to get "best" compression. We don't save
2907#       enough space.
2908$(ASAN_IN_SYSTEM_INSTALLED): $(INSTALLED_USERDATAIMAGE_TARGET_DEPS)
2909	tar cfj $(ASAN_IN_SYSTEM_INSTALLED) $(ASAN_SYSTEM_INSTALL_OPTIONS) -C $(TARGET_OUT_DATA)/.. $(ASAN_OUT_DIRS_FOR_SYSTEM_INSTALL) >/dev/null
2910
2911# -----------------------------------------------------------------
2912# partition table image
2913ifdef BOARD_BPT_INPUT_FILES
2914
2915BUILT_BPTIMAGE_TARGET := $(PRODUCT_OUT)/partition-table.img
2916BUILT_BPTJSON_TARGET := $(PRODUCT_OUT)/partition-table.bpt
2917
2918INTERNAL_BVBTOOL_MAKE_TABLE_ARGS := \
2919	--output_gpt $(BUILT_BPTIMAGE_TARGET) \
2920	--output_json $(BUILT_BPTJSON_TARGET) \
2921	$(foreach file, $(BOARD_BPT_INPUT_FILES), --input $(file))
2922
2923ifdef BOARD_BPT_DISK_SIZE
2924INTERNAL_BVBTOOL_MAKE_TABLE_ARGS += --disk_size $(BOARD_BPT_DISK_SIZE)
2925endif
2926
2927define build-bptimage-target
2928  $(call pretty,"Target partition table image: $(INSTALLED_BPTIMAGE_TARGET)")
2929  $(hide) $(BPTTOOL) make_table $(INTERNAL_BVBTOOL_MAKE_TABLE_ARGS) $(BOARD_BPT_MAKE_TABLE_ARGS)
2930endef
2931
2932INSTALLED_BPTIMAGE_TARGET := $(BUILT_BPTIMAGE_TARGET)
2933$(BUILT_BPTJSON_TARGET): $(INSTALLED_BPTIMAGE_TARGET)
2934	$(hide) touch -c $(BUILT_BPTJSON_TARGET)
2935
2936$(INSTALLED_BPTIMAGE_TARGET): $(BPTTOOL) $(BOARD_BPT_INPUT_FILES)
2937	$(build-bptimage-target)
2938
2939.PHONY: bptimage-nodeps
2940bptimage-nodeps:
2941	$(build-bptimage-target)
2942
2943endif # BOARD_BPT_INPUT_FILES
2944
2945# -----------------------------------------------------------------
2946# cache partition image
2947ifdef BUILDING_CACHE_IMAGE
2948INTERNAL_CACHEIMAGE_FILES := \
2949    $(filter $(TARGET_OUT_CACHE)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
2950
2951cacheimage_intermediates := \
2952    $(call intermediates-dir-for,PACKAGING,cache)
2953BUILT_CACHEIMAGE_TARGET := $(PRODUCT_OUT)/cache.img
2954
2955define build-cacheimage-target
2956  $(call pretty,"Target cache fs image: $(INSTALLED_CACHEIMAGE_TARGET)")
2957  @mkdir -p $(TARGET_OUT_CACHE)
2958  @mkdir -p $(cacheimage_intermediates) && rm -rf $(cacheimage_intermediates)/cache_image_info.txt
2959  $(call generate-image-prop-dictionary, $(cacheimage_intermediates)/cache_image_info.txt,cache,skip_fsck=true)
2960  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
2961      $(BUILD_IMAGE) \
2962          $(TARGET_OUT_CACHE) $(cacheimage_intermediates)/cache_image_info.txt \
2963          $(INSTALLED_CACHEIMAGE_TARGET) $(TARGET_OUT)
2964  $(call assert-max-image-size,$(INSTALLED_CACHEIMAGE_TARGET),$(BOARD_CACHEIMAGE_PARTITION_SIZE))
2965endef
2966
2967# We just build this directly to the install location.
2968INSTALLED_CACHEIMAGE_TARGET := $(BUILT_CACHEIMAGE_TARGET)
2969$(INSTALLED_CACHEIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_CACHEIMAGE_FILES)
2970	$(build-cacheimage-target)
2971
2972.PHONY: cacheimage-nodeps
2973cacheimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
2974	$(build-cacheimage-target)
2975
2976else # BUILDING_CACHE_IMAGE
2977# we need to ignore the broken cache link when doing the rsync
2978IGNORE_CACHE_LINK := --exclude=cache
2979endif # BUILDING_CACHE_IMAGE
2980
2981# -----------------------------------------------------------------
2982# system_other partition image
2983ifdef BUILDING_SYSTEM_OTHER_IMAGE
2984ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
2985# Marker file to identify that odex files are installed
2986INSTALLED_SYSTEM_OTHER_ODEX_MARKER := $(TARGET_OUT_SYSTEM_OTHER)/system-other-odex-marker
2987ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_SYSTEM_OTHER_ODEX_MARKER)
2988$(INSTALLED_SYSTEM_OTHER_ODEX_MARKER):
2989	$(hide) touch $@
2990endif
2991
2992INTERNAL_SYSTEMOTHERIMAGE_FILES := \
2993    $(filter $(TARGET_OUT_SYSTEM_OTHER)/%,\
2994      $(ALL_DEFAULT_INSTALLED_MODULES))
2995
2996# system_other dex files are installed as a side-effect of installing system image files
2997INTERNAL_SYSTEMOTHERIMAGE_FILES += $(INTERNAL_SYSTEMIMAGE_FILES)
2998
2999INSTALLED_FILES_FILE_SYSTEMOTHER := $(PRODUCT_OUT)/installed-files-system-other.txt
3000INSTALLED_FILES_JSON_SYSTEMOTHER := $(INSTALLED_FILES_FILE_SYSTEMOTHER:.txt=.json)
3001$(INSTALLED_FILES_FILE_SYSTEMOTHER): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_SYSTEMOTHER)
3002$(INSTALLED_FILES_FILE_SYSTEMOTHER) : $(INTERNAL_SYSTEMOTHERIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3003	@echo Installed file list: $@
3004	mkdir -p $(dir $@)
3005	rm -f $@
3006	$(FILESLIST) $(TARGET_OUT_SYSTEM_OTHER) > $(@:.txt=.json)
3007	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3008
3009# Determines partition size for system_other.img.
3010ifeq ($(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS),true)
3011ifneq ($(filter system,$(BOARD_SUPER_PARTITION_BLOCK_DEVICES)),)
3012INTERNAL_SYSTEM_OTHER_PARTITION_SIZE := $(BOARD_SUPER_PARTITION_SYSTEM_DEVICE_SIZE)
3013endif
3014endif
3015
3016ifndef INTERNAL_SYSTEM_OTHER_PARTITION_SIZE
3017INTERNAL_SYSTEM_OTHER_PARTITION_SIZE:= $(BOARD_SYSTEMIMAGE_PARTITION_SIZE)
3018endif
3019
3020systemotherimage_intermediates := \
3021    $(call intermediates-dir-for,PACKAGING,system_other)
3022BUILT_SYSTEMOTHERIMAGE_TARGET := $(PRODUCT_OUT)/system_other.img
3023
3024# Note that we assert the size is SYSTEMIMAGE_PARTITION_SIZE since this is the 'b' system image.
3025define build-systemotherimage-target
3026  $(call pretty,"Target system_other fs image: $(INSTALLED_SYSTEMOTHERIMAGE_TARGET)")
3027  @mkdir -p $(TARGET_OUT_SYSTEM_OTHER)
3028  @mkdir -p $(systemotherimage_intermediates) && rm -rf $(systemotherimage_intermediates)/system_other_image_info.txt
3029  $(call generate-image-prop-dictionary, $(systemotherimage_intermediates)/system_other_image_info.txt,system,skip_fsck=true)
3030  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3031      $(BUILD_IMAGE) \
3032          $(TARGET_OUT_SYSTEM_OTHER) $(systemotherimage_intermediates)/system_other_image_info.txt \
3033          $(INSTALLED_SYSTEMOTHERIMAGE_TARGET) $(TARGET_OUT)
3034  $(call assert-max-image-size,$(INSTALLED_SYSTEMOTHERIMAGE_TARGET),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
3035endef
3036
3037# We just build this directly to the install location.
3038INSTALLED_SYSTEMOTHERIMAGE_TARGET := $(BUILT_SYSTEMOTHERIMAGE_TARGET)
3039ifneq (true,$(SANITIZE_LITE))
3040# Only create system_other when not building the second stage of a SANITIZE_LITE build.
3041$(INSTALLED_SYSTEMOTHERIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_SYSTEMOTHERIMAGE_FILES) $(INSTALLED_FILES_FILE_SYSTEMOTHER)
3042	$(build-systemotherimage-target)
3043endif
3044
3045.PHONY: systemotherimage-nodeps
3046systemotherimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS)
3047	$(build-systemotherimage-target)
3048
3049endif # BUILDING_SYSTEM_OTHER_IMAGE
3050
3051
3052# -----------------------------------------------------------------
3053# vendor partition image
3054ifdef BUILDING_VENDOR_IMAGE
3055INTERNAL_VENDORIMAGE_FILES := \
3056    $(filter $(TARGET_OUT_VENDOR)/%,\
3057      $(ALL_DEFAULT_INSTALLED_MODULES))
3058
3059
3060# Create symlink /vendor/odm to /odm if necessary.
3061ifdef BOARD_USES_ODMIMAGE
3062  INTERNAL_VENDORIMAGE_FILES += $(call create-partition-compat-symlink,$(TARGET_OUT_VENDOR)/odm,/odm,odm.img)
3063endif
3064
3065# Create symlinks for vendor_dlkm on devices with a vendor_dlkm partition:
3066# /vendor/lib/modules -> /vendor_dlkm/lib/modules
3067#
3068# On devices with a vendor_dlkm partition,
3069# - /vendor/lib/modules is a symlink to a directory that stores vendor DLKMs.
3070# - /vendor_dlkm/{etc,...} store other vendor_dlkm files directly. The vendor_dlkm partition is
3071#   mounted at /vendor_dlkm at runtime and the symlinks created in system/core/rootdir/Android.mk
3072#   are hidden.
3073# On devices without a vendor_dlkm partition,
3074# - /vendor/lib/modules stores vendor DLKMs directly.
3075# - /vendor_dlkm/{etc,...} are symlinks to directories that store other vendor_dlkm files.
3076#   See system/core/rootdir/Android.mk for a list of created symlinks.
3077# The vendor DLKMs and other vendor_dlkm files must not be accessed using other paths because they
3078# are not guaranteed to exist on all devices.
3079ifdef BOARD_USES_VENDOR_DLKMIMAGE
3080  INTERNAL_VENDORIMAGE_FILES += $(call create-partition-compat-symlink,$(TARGET_OUT_VENDOR)/lib/modules,/vendor_dlkm/lib/modules,vendor_dlkm.img)
3081endif
3082
3083INSTALLED_FILES_FILE_VENDOR := $(PRODUCT_OUT)/installed-files-vendor.txt
3084INSTALLED_FILES_JSON_VENDOR := $(INSTALLED_FILES_FILE_VENDOR:.txt=.json)
3085$(INSTALLED_FILES_FILE_VENDOR): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_VENDOR)
3086$(INSTALLED_FILES_FILE_VENDOR) : $(INTERNAL_VENDORIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3087	@echo Installed file list: $@
3088	mkdir -p $(dir $@)
3089	rm -f $@
3090	$(FILESLIST) $(TARGET_OUT_VENDOR) > $(@:.txt=.json)
3091	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3092
3093vendorimage_intermediates := \
3094    $(call intermediates-dir-for,PACKAGING,vendor)
3095BUILT_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
3096define build-vendorimage-target
3097  $(call pretty,"Target vendor fs image: $(INSTALLED_VENDORIMAGE_TARGET)")
3098  @mkdir -p $(TARGET_OUT_VENDOR)
3099  @mkdir -p $(vendorimage_intermediates) && rm -rf $(vendorimage_intermediates)/vendor_image_info.txt
3100  $(call generate-image-prop-dictionary, $(vendorimage_intermediates)/vendor_image_info.txt,vendor,skip_fsck=true)
3101  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3102      $(BUILD_IMAGE) \
3103          $(TARGET_OUT_VENDOR) $(vendorimage_intermediates)/vendor_image_info.txt \
3104          $(INSTALLED_VENDORIMAGE_TARGET) $(TARGET_OUT)
3105  $(call assert-max-image-size,$(INSTALLED_VENDORIMAGE_TARGET) $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_VENDORIMAGE_PARTITION_SIZE))
3106endef
3107
3108# We just build this directly to the install location.
3109INSTALLED_VENDORIMAGE_TARGET := $(BUILT_VENDORIMAGE_TARGET)
3110$(INSTALLED_VENDORIMAGE_TARGET): \
3111    $(INTERNAL_USERIMAGES_DEPS) \
3112    $(INTERNAL_VENDORIMAGE_FILES) \
3113    $(INSTALLED_FILES_FILE_VENDOR) \
3114    $(RECOVERY_FROM_BOOT_PATCH)
3115	$(build-vendorimage-target)
3116
3117.PHONY: vendorimage-nodeps vnod
3118vendorimage-nodeps vnod: | $(INTERNAL_USERIMAGES_DEPS)
3119	$(build-vendorimage-target)
3120
3121sync: $(INTERNAL_VENDORIMAGE_FILES)
3122
3123else ifdef BOARD_PREBUILT_VENDORIMAGE
3124INSTALLED_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
3125$(eval $(call copy-one-file,$(BOARD_PREBUILT_VENDORIMAGE),$(INSTALLED_VENDORIMAGE_TARGET)))
3126endif
3127
3128# -----------------------------------------------------------------
3129# product partition image
3130ifdef BUILDING_PRODUCT_IMAGE
3131INTERNAL_PRODUCTIMAGE_FILES := \
3132    $(filter $(TARGET_OUT_PRODUCT)/%,\
3133      $(ALL_DEFAULT_INSTALLED_MODULES))
3134
3135INSTALLED_FILES_FILE_PRODUCT := $(PRODUCT_OUT)/installed-files-product.txt
3136INSTALLED_FILES_JSON_PRODUCT := $(INSTALLED_FILES_FILE_PRODUCT:.txt=.json)
3137$(INSTALLED_FILES_FILE_PRODUCT): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_PRODUCT)
3138$(INSTALLED_FILES_FILE_PRODUCT) : $(INTERNAL_PRODUCTIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3139	@echo Installed file list: $@
3140	mkdir -p $(dir $@)
3141	rm -f $@
3142	$(FILESLIST) $(TARGET_OUT_PRODUCT) > $(@:.txt=.json)
3143	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3144
3145productimage_intermediates := \
3146    $(call intermediates-dir-for,PACKAGING,product)
3147BUILT_PRODUCTIMAGE_TARGET := $(PRODUCT_OUT)/product.img
3148define build-productimage-target
3149  $(call pretty,"Target product fs image: $(INSTALLED_PRODUCTIMAGE_TARGET)")
3150  @mkdir -p $(TARGET_OUT_PRODUCT)
3151  @mkdir -p $(productimage_intermediates) && rm -rf $(productimage_intermediates)/product_image_info.txt
3152  $(call generate-image-prop-dictionary, $(productimage_intermediates)/product_image_info.txt,product,skip_fsck=true)
3153  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3154      $(BUILD_IMAGE) \
3155          $(TARGET_OUT_PRODUCT) $(productimage_intermediates)/product_image_info.txt \
3156          $(INSTALLED_PRODUCTIMAGE_TARGET) $(TARGET_OUT)
3157  $(call assert-max-image-size,$(INSTALLED_PRODUCTIMAGE_TARGET),$(BOARD_PRODUCTIMAGE_PARTITION_SIZE))
3158endef
3159
3160# We just build this directly to the install location.
3161INSTALLED_PRODUCTIMAGE_TARGET := $(BUILT_PRODUCTIMAGE_TARGET)
3162$(INSTALLED_PRODUCTIMAGE_TARGET): \
3163    $(INTERNAL_USERIMAGES_DEPS) \
3164    $(INTERNAL_PRODUCTIMAGE_FILES) \
3165    $(INSTALLED_FILES_FILE_PRODUCT)
3166	$(build-productimage-target)
3167
3168.PHONY: productimage-nodeps pnod
3169productimage-nodeps pnod: | $(INTERNAL_USERIMAGES_DEPS)
3170	$(build-productimage-target)
3171
3172sync: $(INTERNAL_PRODUCTIMAGE_FILES)
3173
3174else ifdef BOARD_PREBUILT_PRODUCTIMAGE
3175INSTALLED_PRODUCTIMAGE_TARGET := $(PRODUCT_OUT)/product.img
3176$(eval $(call copy-one-file,$(BOARD_PREBUILT_PRODUCTIMAGE),$(INSTALLED_PRODUCTIMAGE_TARGET)))
3177endif
3178
3179# -----------------------------------------------------------------
3180# system_ext partition image
3181ifdef BUILDING_SYSTEM_EXT_IMAGE
3182INTERNAL_SYSTEM_EXTIMAGE_FILES := \
3183    $(filter $(TARGET_OUT_SYSTEM_EXT)/%,\
3184      $(ALL_DEFAULT_INSTALLED_MODULES))
3185
3186INSTALLED_FILES_FILE_SYSTEM_EXT := $(PRODUCT_OUT)/installed-files-system_ext.txt
3187INSTALLED_FILES_JSON_SYSTEM_EXT := $(INSTALLED_FILES_FILE_SYSTEM_EXT:.txt=.json)
3188$(INSTALLED_FILES_FILE_SYSTEM_EXT): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_SYSTEM_EXT)
3189$(INSTALLED_FILES_FILE_SYSTEM_EXT) : $(INTERNAL_SYSTEM_EXTIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3190	@echo Installed file list: $@
3191	mkdir -p $(dir $@)
3192	rm -f $@
3193	$(FILESLIST) $(TARGET_OUT_SYSTEM_EXT) > $(@:.txt=.json)
3194	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3195
3196system_extimage_intermediates := \
3197    $(call intermediates-dir-for,PACKAGING,system_ext)
3198BUILT_SYSTEM_EXTIMAGE_TARGET := $(PRODUCT_OUT)/system_ext.img
3199define build-system_extimage-target
3200  $(call pretty,"Target system_ext fs image: $(INSTALLED_SYSTEM_EXTIMAGE_TARGET)")
3201  @mkdir -p $(TARGET_OUT_SYSTEM_EXT)
3202  @mkdir -p $(system_extimage_intermediates) && rm -rf $(system_extimage_intermediates)/system_ext_image_info.txt
3203  $(call generate-image-prop-dictionary, $(system_extimage_intermediates)/system_ext_image_info.txt,system_ext, skip_fsck=true)
3204  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3205      $(BUILD_IMAGE) \
3206          $(TARGET_OUT_SYSTEM_EXT) \
3207          $(system_extimage_intermediates)/system_ext_image_info.txt \
3208          $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) \
3209          $(TARGET_OUT)
3210  $(call assert-max-image-size,$(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET),$(BOARD_PRODUCT_SERVICESIMAGE_PARTITION_SIZE))
3211endef
3212
3213# We just build this directly to the install location.
3214INSTALLED_SYSTEM_EXTIMAGE_TARGET := $(BUILT_SYSTEM_EXTIMAGE_TARGET)
3215$(INSTALLED_SYSTEM_EXTIMAGE_TARGET): \
3216    $(INTERNAL_USERIMAGES_DEPS) \
3217    $(INTERNAL_SYSTEM_EXTIMAGE_FILES) \
3218    $(INSTALLED_FILES_FILE_SYSTEM_EXT)
3219	$(build-system_extimage-target)
3220
3221.PHONY: systemextimage-nodeps senod
3222systemextimage-nodeps senod: | $(INTERNAL_USERIMAGES_DEPS)
3223	$(build-system_extimage-target)
3224
3225sync: $(INTERNAL_SYSTEM_EXTIMAGE_FILES)
3226
3227else ifdef BOARD_PREBUILT_SYSTEM_EXTIMAGE
3228INSTALLED_SYSTEM_EXTIMAGE_TARGET := $(PRODUCT_OUT)/system_ext.img
3229$(eval $(call copy-one-file,$(BOARD_PREBUILT_SYSTEM_EXTIMAGE),$(INSTALLED_SYSTEM_EXTIMAGE_TARGET)))
3230endif
3231
3232# -----------------------------------------------------------------
3233# odm partition image
3234ifdef BUILDING_ODM_IMAGE
3235INTERNAL_ODMIMAGE_FILES := \
3236    $(filter $(TARGET_OUT_ODM)/%,\
3237      $(ALL_DEFAULT_INSTALLED_MODULES))
3238
3239# Create symlinks for odm_dlkm on devices with a odm_dlkm partition:
3240# /odm/lib/modules -> /odm_dlkm/lib/modules
3241#
3242# On devices with a odm_dlkm partition,
3243# - /odm/lib/modules is a symlink to a directory that stores odm DLKMs.
3244# - /odm_dlkm/{etc,...} store other odm_dlkm files directly. The odm_dlkm partition is
3245#   mounted at /odm_dlkm at runtime and the symlinks created in system/core/rootdir/Android.mk
3246#   are hidden.
3247# On devices without a odm_dlkm partition,
3248# - /odm/lib/modules stores odm DLKMs directly.
3249# - /odm_dlkm/{etc,...} are symlinks to directories that store other odm_dlkm files.
3250#   See system/core/rootdir/Android.mk for a list of created symlinks.
3251# The odm DLKMs and other odm_dlkm files must not be accessed using other paths because they
3252# are not guaranteed to exist on all devices.
3253ifdef BOARD_USES_ODM_DLKMIMAGE
3254  INTERNAL_ODMIMAGE_FILES += $(call create-partition-compat-symlink,$(TARGET_OUT_ODM)/lib/modules,/odm_dlkm/lib/modules,odm_dlkm.img)
3255endif
3256
3257INSTALLED_FILES_FILE_ODM := $(PRODUCT_OUT)/installed-files-odm.txt
3258INSTALLED_FILES_JSON_ODM := $(INSTALLED_FILES_FILE_ODM:.txt=.json)
3259$(INSTALLED_FILES_FILE_ODM): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_ODM)
3260$(INSTALLED_FILES_FILE_ODM) : $(INTERNAL_ODMIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3261	@echo Installed file list: $@
3262	mkdir -p $(dir $@)
3263	rm -f $@
3264	$(FILESLIST) $(TARGET_OUT_ODM) > $(@:.txt=.json)
3265	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3266
3267odmimage_intermediates := \
3268    $(call intermediates-dir-for,PACKAGING,odm)
3269BUILT_ODMIMAGE_TARGET := $(PRODUCT_OUT)/odm.img
3270define build-odmimage-target
3271  $(call pretty,"Target odm fs image: $(INSTALLED_ODMIMAGE_TARGET)")
3272  @mkdir -p $(TARGET_OUT_ODM)
3273  @mkdir -p $(odmimage_intermediates) && rm -rf $(odmimage_intermediates)/odm_image_info.txt
3274  $(call generate-userimage-prop-dictionary, $(odmimage_intermediates)/odm_image_info.txt, skip_fsck=true)
3275  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3276      $(BUILD_IMAGE) \
3277          $(TARGET_OUT_ODM) $(odmimage_intermediates)/odm_image_info.txt \
3278          $(INSTALLED_ODMIMAGE_TARGET) $(TARGET_OUT)
3279  $(call assert-max-image-size,$(INSTALLED_ODMIMAGE_TARGET),$(BOARD_ODMIMAGE_PARTITION_SIZE))
3280endef
3281
3282# We just build this directly to the install location.
3283INSTALLED_ODMIMAGE_TARGET := $(BUILT_ODMIMAGE_TARGET)
3284$(INSTALLED_ODMIMAGE_TARGET): \
3285    $(INTERNAL_USERIMAGES_DEPS) \
3286    $(INTERNAL_ODMIMAGE_FILES) \
3287    $(INSTALLED_FILES_FILE_ODM)
3288	$(build-odmimage-target)
3289
3290.PHONY: odmimage-nodeps onod
3291odmimage-nodeps onod: | $(INTERNAL_USERIMAGES_DEPS)
3292	$(build-odmimage-target)
3293
3294sync: $(INTERNAL_ODMIMAGE_FILES)
3295
3296else ifdef BOARD_PREBUILT_ODMIMAGE
3297INSTALLED_ODMIMAGE_TARGET := $(PRODUCT_OUT)/odm.img
3298$(eval $(call copy-one-file,$(BOARD_PREBUILT_ODMIMAGE),$(INSTALLED_ODMIMAGE_TARGET)))
3299endif
3300
3301# -----------------------------------------------------------------
3302# vendor_dlkm partition image
3303ifdef BUILDING_VENDOR_DLKM_IMAGE
3304INTERNAL_VENDOR_DLKMIMAGE_FILES := \
3305    $(filter $(TARGET_OUT_VENDOR_DLKM)/%,\
3306      $(ALL_DEFAULT_INSTALLED_MODULES))
3307
3308INSTALLED_FILES_FILE_VENDOR_DLKM := $(PRODUCT_OUT)/installed-files-vendor_dlkm.txt
3309INSTALLED_FILES_JSON_VENDOR_DLKM := $(INSTALLED_FILES_FILE_VENDOR_DLKM:.txt=.json)
3310$(INSTALLED_FILES_FILE_VENDOR_DLKM): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_VENDOR_DLKM)
3311$(INSTALLED_FILES_FILE_VENDOR_DLKM) : $(INTERNAL_VENDOR_DLKMIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3312	@echo Installed file list: $@
3313	mkdir -p $(dir $@)
3314	rm -f $@
3315	$(FILESLIST) $(TARGET_OUT_VENDOR_DLKM) > $(@:.txt=.json)
3316	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3317
3318vendor_dlkmimage_intermediates := \
3319    $(call intermediates-dir-for,PACKAGING,vendor_dlkm)
3320BUILT_VENDOR_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/vendor_dlkm.img
3321define build-vendor_dlkmimage-target
3322  $(call pretty,"Target vendor_dlkm fs image: $(INSTALLED_VENDOR_DLKMIMAGE_TARGET)")
3323  @mkdir -p $(TARGET_OUT_VENDOR_DLKM)
3324  @mkdir -p $(vendor_dlkmimage_intermediates) && rm -rf $(vendor_dlkmimage_intermediates)/vendor_dlkm_image_info.txt
3325  $(call generate-userimage-prop-dictionary, $(vendor_dlkmimage_intermediates)/vendor_dlkm_image_info.txt, skip_fsck=true)
3326  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3327      $(BUILD_IMAGE) \
3328          $(TARGET_OUT_VENDOR_DLKM) $(vendor_dlkmimage_intermediates)/vendor_dlkm_image_info.txt \
3329          $(INSTALLED_VENDOR_DLKMIMAGE_TARGET) $(TARGET_OUT)
3330  $(call assert-max-image-size,$(INSTALLED_VENDOR_DLKMIMAGE_TARGET),$(BOARD_VENDOR_DLKMIMAGE_PARTITION_SIZE))
3331endef
3332
3333# We just build this directly to the install location.
3334INSTALLED_VENDOR_DLKMIMAGE_TARGET := $(BUILT_VENDOR_DLKMIMAGE_TARGET)
3335$(INSTALLED_VENDOR_DLKMIMAGE_TARGET): \
3336    $(INTERNAL_USERIMAGES_DEPS) \
3337    $(INTERNAL_VENDOR_DLKMIMAGE_FILES) \
3338    $(INSTALLED_FILES_FILE_VENDOR_DLKM)
3339	$(build-vendor_dlkmimage-target)
3340
3341.PHONY: vendor_dlkmimage-nodeps vdnod
3342vendor_dlkmimage-nodeps vdnod: | $(INTERNAL_USERIMAGES_DEPS)
3343	$(build-vendor_dlkmimage-target)
3344
3345sync: $(INTERNAL_VENDOR_DLKMIMAGE_FILES)
3346
3347else ifdef BOARD_PREBUILT_VENDOR_DLKMIMAGE
3348INSTALLED_VENDOR_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/vendor_dlkm.img
3349$(eval $(call copy-one-file,$(BOARD_PREBUILT_VENDOR_DLKMIMAGE),$(INSTALLED_VENDOR_DLKMIMAGE_TARGET)))
3350endif
3351
3352# -----------------------------------------------------------------
3353# odm_dlkm partition image
3354ifdef BUILDING_ODM_DLKM_IMAGE
3355INTERNAL_ODM_DLKMIMAGE_FILES := \
3356    $(filter $(TARGET_OUT_ODM_DLKM)/%,\
3357      $(ALL_DEFAULT_INSTALLED_MODULES))
3358
3359INSTALLED_FILES_FILE_ODM_DLKM := $(PRODUCT_OUT)/installed-files-odm_dlkm.txt
3360INSTALLED_FILES_JSON_ODM_DLKM := $(INSTALLED_FILES_FILE_ODM_DLKM:.txt=.json)
3361$(INSTALLED_FILES_FILE_ODM_DLKM): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_ODM_DLKM)
3362$(INSTALLED_FILES_FILE_ODM_DLKM) : $(INTERNAL_ODM_DLKMIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3363	@echo Installed file list: $@
3364	mkdir -p $(dir $@)
3365	rm -f $@
3366	$(FILESLIST) $(TARGET_OUT_ODM_DLKM) > $(@:.txt=.json)
3367	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3368
3369odm_dlkmimage_intermediates := \
3370    $(call intermediates-dir-for,PACKAGING,odm_dlkm)
3371BUILT_ODM_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/odm_dlkm.img
3372define build-odm_dlkmimage-target
3373  $(call pretty,"Target odm_dlkm fs image: $(INSTALLED_ODM_DLKMIMAGE_TARGET)")
3374  @mkdir -p $(TARGET_OUT_ODM_DLKM)
3375  @mkdir -p $(odm_dlkmimage_intermediates) && rm -rf $(odm_dlkmimage_intermediates)/odm_dlkm_image_info.txt
3376  $(call generate-userimage-prop-dictionary, $(odm_dlkmimage_intermediates)/odm_dlkm_image_info.txt, skip_fsck=true)
3377  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3378      $(BUILD_IMAGE) \
3379          $(TARGET_OUT_ODM_DLKM) $(odm_dlkmimage_intermediates)/odm_dlkm_image_info.txt \
3380          $(INSTALLED_ODM_DLKMIMAGE_TARGET) $(TARGET_OUT)
3381  $(call assert-max-image-size,$(INSTALLED_ODM_DLKMIMAGE_TARGET),$(BOARD_ODM_DLKMIMAGE_PARTITION_SIZE))
3382endef
3383
3384# We just build this directly to the install location.
3385INSTALLED_ODM_DLKMIMAGE_TARGET := $(BUILT_ODM_DLKMIMAGE_TARGET)
3386$(INSTALLED_ODM_DLKMIMAGE_TARGET): \
3387    $(INTERNAL_USERIMAGES_DEPS) \
3388    $(INTERNAL_ODM_DLKMIMAGE_FILES) \
3389    $(INSTALLED_FILES_FILE_ODM_DLKM)
3390	$(build-odm_dlkmimage-target)
3391
3392.PHONY: odm_dlkmimage-nodeps odnod
3393odm_dlkmimage-nodeps odnod: | $(INTERNAL_USERIMAGES_DEPS)
3394	$(build-odm_dlkmimage-target)
3395
3396sync: $(INTERNAL_ODM_DLKMIMAGE_FILES)
3397
3398else ifdef BOARD_PREBUILT_ODM_DLKMIMAGE
3399INSTALLED_ODM_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/odm_dlkm.img
3400$(eval $(call copy-one-file,$(BOARD_PREBUILT_ODM_DLKMIMAGE),$(INSTALLED_ODM_DLKMIMAGE_TARGET)))
3401endif
3402
3403
3404# -----------------------------------------------------------------
3405# dtbo image
3406ifdef BOARD_PREBUILT_DTBOIMAGE
3407INSTALLED_DTBOIMAGE_TARGET := $(PRODUCT_OUT)/dtbo.img
3408
3409ifeq ($(BOARD_AVB_ENABLE),true)
3410$(INSTALLED_DTBOIMAGE_TARGET): $(BOARD_PREBUILT_DTBOIMAGE) $(AVBTOOL) $(BOARD_AVB_DTBO_KEY_PATH)
3411	cp $(BOARD_PREBUILT_DTBOIMAGE) $@
3412	$(AVBTOOL) add_hash_footer \
3413	    --image $@ \
3414	    --partition_size $(BOARD_DTBOIMG_PARTITION_SIZE) \
3415	    --partition_name dtbo $(INTERNAL_AVB_DTBO_SIGNING_ARGS) \
3416	    $(BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS)
3417else
3418$(INSTALLED_DTBOIMAGE_TARGET): $(BOARD_PREBUILT_DTBOIMAGE)
3419	cp $(BOARD_PREBUILT_DTBOIMAGE) $@
3420endif
3421
3422endif # BOARD_PREBUILT_DTBOIMAGE
3423
3424# -----------------------------------------------------------------
3425# Protected VM firmware image
3426ifdef BOARD_PREBUILT_PVMFWIMAGE
3427INSTALLED_PVMFWIMAGE_TARGET := $(PRODUCT_OUT)/pvmfw.img
3428
3429ifeq ($(BOARD_AVB_ENABLE),true)
3430$(INSTALLED_PVMFWIMAGE_TARGET): $(BOARD_PREBUILT_PVMFWIMAGE) $(AVBTOOL) $(BOARD_AVB_PVMFW_KEY_PATH)
3431	cp $(BOARD_PREBUILT_PVMFWIMAGE) $@
3432	$(AVBTOOL) add_hash_footer \
3433	    --image $@ \
3434	    --partition_size $(BOARD_PVMFWIMG_PARTITION_SIZE) \
3435	    --partition_name pvmfw $(INTERNAL_AVB_PVMFW_SIGNING_ARGS) \
3436	    $(BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS)
3437else
3438$(INSTALLED_PVMFWIMAGE_TARGET): $(BOARD_PREBUILT_PVMFWIMAGE)
3439	cp $(BOARD_PREBUILT_PVMFWIMAGE) $@
3440endif
3441
3442endif # BOARD_PREBUILT_PVMFWIMAGE
3443
3444# Returns a list of image targets corresponding to the given list of partitions. For example, it
3445# returns "$(INSTALLED_PRODUCTIMAGE_TARGET)" for "product", or "$(INSTALLED_SYSTEMIMAGE_TARGET)
3446# $(INSTALLED_VENDORIMAGE_TARGET)" for "system vendor".
3447# (1): list of partitions like "system", "vendor" or "system product system_ext".
3448define images-for-partitions
3449$(strip $(foreach item,$(1),$(if $(filter $(item),system_other),$(INSTALLED_SYSTEMOTHERIMAGE_TARGET),$(INSTALLED_$(call to-upper,$(item))IMAGE_TARGET))))
3450endef
3451
3452# -----------------------------------------------------------------
3453# custom images
3454INSTALLED_CUSTOMIMAGES_TARGET :=
3455
3456ifneq ($(strip $(BOARD_CUSTOMIMAGES_PARTITION_LIST)),)
3457INTERNAL_AVB_CUSTOMIMAGES_SIGNING_ARGS :=
3458
3459# Sign custom image.
3460# $(1): the prebuilt custom image.
3461# $(2): the mount point of the prebuilt custom image.
3462# $(3): the signed custom image target.
3463define sign_custom_image
3464$(3): $(1) $(INTERNAL_USERIMAGES_DEPS)
3465	@echo Target custom image: $(3)
3466	mkdir -p $(dir $(3))
3467	cp $(1) $(3)
3468ifeq ($(BOARD_AVB_ENABLE),true)
3469	PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$$$PATH \
3470          $(AVBTOOL) add_hashtree_footer \
3471          --image $(3) \
3472          --key $(BOARD_AVB_$(call to-upper,$(2))_KEY_PATH) \
3473          --algorithm $(BOARD_AVB_$(call to-upper,$(2))_ALGORITHM) \
3474          --partition_size $(BOARD_AVB_$(call to-upper,$(2))_PARTITION_SIZE) \
3475          --partition_name $(2) \
3476          $(INTERNAL_AVB_CUSTOMIMAGES_SIGNING_ARGS) \
3477          $(BOARD_AVB_$(call to-upper,$(2))_ADD_HASHTREE_FOOTER_ARGS)
3478endif
3479INSTALLED_CUSTOMIMAGES_TARGET += $(3)
3480endef
3481
3482$(foreach partition,$(BOARD_CUSTOMIMAGES_PARTITION_LIST), \
3483  $(foreach image,$(BOARD_AVB_$(call to-upper,$(partition))_IMAGE_LIST), \
3484     $(eval $(call sign_custom_image,$(image),$(partition),$(PRODUCT_OUT)/$(notdir $(image))))))
3485endif
3486
3487# -----------------------------------------------------------------
3488# vbmeta image
3489ifeq ($(BOARD_AVB_ENABLE),true)
3490
3491BUILT_VBMETAIMAGE_TARGET := $(PRODUCT_OUT)/vbmeta.img
3492AVB_CHAIN_KEY_DIR := $(TARGET_OUT_INTERMEDIATES)/avb_chain_keys
3493
3494ifdef BOARD_AVB_KEY_PATH
3495$(if $(BOARD_AVB_ALGORITHM),,$(error BOARD_AVB_ALGORITHM is not defined))
3496else
3497# If key path isn't specified, use the 4096-bit test key.
3498BOARD_AVB_ALGORITHM := SHA256_RSA4096
3499BOARD_AVB_KEY_PATH := external/avb/test/data/testkey_rsa4096.pem
3500endif
3501
3502# AVB signing for system_other.img.
3503ifdef BUILDING_SYSTEM_OTHER_IMAGE
3504ifdef BOARD_AVB_SYSTEM_OTHER_KEY_PATH
3505$(if $(BOARD_AVB_SYSTEM_OTHER_ALGORITHM),,$(error BOARD_AVB_SYSTEM_OTHER_ALGORITHM is not defined))
3506else
3507# If key path isn't specified, use the same key as BOARD_AVB_KEY_PATH.
3508BOARD_AVB_SYSTEM_OTHER_KEY_PATH := $(BOARD_AVB_KEY_PATH)
3509BOARD_AVB_SYSTEM_OTHER_ALGORITHM := $(BOARD_AVB_ALGORITHM)
3510endif
3511
3512$(INSTALLED_PRODUCT_SYSTEM_OTHER_AVBKEY_TARGET): $(AVBTOOL) $(BOARD_AVB_SYSTEM_OTHER_KEY_PATH)
3513	@echo Extracting system_other avb key: $@
3514	@rm -f $@
3515	@mkdir -p $(dir $@)
3516	$(AVBTOOL) extract_public_key --key $(BOARD_AVB_SYSTEM_OTHER_KEY_PATH) --output $@
3517
3518ifndef BOARD_AVB_SYSTEM_OTHER_ROLLBACK_INDEX
3519BOARD_AVB_SYSTEM_OTHER_ROLLBACK_INDEX := $(PLATFORM_SECURITY_PATCH_TIMESTAMP)
3520endif
3521
3522BOARD_AVB_SYSTEM_OTHER_ADD_HASHTREE_FOOTER_ARGS += --rollback_index $(BOARD_AVB_SYSTEM_OTHER_ROLLBACK_INDEX)
3523endif # end of AVB for BUILDING_SYSTEM_OTHER_IMAGE
3524
3525INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES := \
3526    $(BOARD_AVB_VBMETA_SYSTEM) \
3527    $(BOARD_AVB_VBMETA_VENDOR)
3528
3529# Not allowing the same partition to appear in multiple groups.
3530ifneq ($(words $(sort $(INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES))),$(words $(INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES)))
3531  $(error BOARD_AVB_VBMETA_SYSTEM and BOARD_AVB_VBMETA_VENDOR cannot have duplicates)
3532endif
3533
3534# When building a standalone recovery image for non-A/B devices, recovery image must be self-signed
3535# to be verified independently, and cannot be chained into vbmeta.img. See the link below for
3536# details.
3537ifeq ($(TARGET_OTA_ALLOW_NON_AB),true)
3538ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
3539$(if $(BOARD_AVB_RECOVERY_KEY_PATH),,\
3540    $(error BOARD_AVB_RECOVERY_KEY_PATH must be defined for if non-A/B is supported. \
3541            See https://android.googlesource.com/platform/external/avb/+/master/README.md#booting-into-recovery))
3542endif
3543endif
3544
3545# Appends os version and security patch level as a AVB property descriptor
3546
3547BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS += \
3548    --prop com.android.build.system.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
3549    --prop com.android.build.system.os_version:$(PLATFORM_VERSION_LAST_STABLE) \
3550    --prop com.android.build.system.security_patch:$(PLATFORM_SECURITY_PATCH)
3551
3552BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS += \
3553    --prop com.android.build.product.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
3554    --prop com.android.build.product.os_version:$(PLATFORM_VERSION_LAST_STABLE) \
3555    --prop com.android.build.product.security_patch:$(PLATFORM_SECURITY_PATCH)
3556
3557BOARD_AVB_SYSTEM_EXT_ADD_HASHTREE_FOOTER_ARGS += \
3558    --prop com.android.build.system_ext.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
3559    --prop com.android.build.system_ext.os_version:$(PLATFORM_VERSION_LAST_STABLE) \
3560    --prop com.android.build.system_ext.security_patch:$(PLATFORM_SECURITY_PATCH)
3561
3562BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS += \
3563    --prop com.android.build.boot.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
3564    --prop com.android.build.boot.os_version:$(PLATFORM_VERSION_LAST_STABLE)
3565
3566BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS += \
3567    --prop com.android.build.vendor_boot.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
3568
3569BOARD_AVB_RECOVERY_ADD_HASH_FOOTER_ARGS += \
3570    --prop com.android.build.recovery.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
3571
3572BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS += \
3573    --prop com.android.build.vendor.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
3574    --prop com.android.build.vendor.os_version:$(PLATFORM_VERSION_LAST_STABLE)
3575
3576BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS += \
3577    --prop com.android.build.odm.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
3578    --prop com.android.build.odm.os_version:$(PLATFORM_VERSION_LAST_STABLE)
3579
3580BOARD_AVB_VENDOR_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
3581    --prop com.android.build.vendor_dlkm.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
3582    --prop com.android.build.vendor_dlkm.os_version:$(PLATFORM_VERSION_LAST_STABLE)
3583
3584BOARD_AVB_ODM_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
3585    --prop com.android.build.odm_dlkm.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
3586    --prop com.android.build.odm_dlkm.os_version:$(PLATFORM_VERSION_LAST_STABLE)
3587
3588BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS += \
3589    --prop com.android.build.dtbo.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
3590
3591BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS += \
3592    --prop com.android.build.pvmfw.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
3593
3594# The following vendor- and odm-specific images needs explicit SPL set per board.
3595ifdef BOOT_SECURITY_PATCH
3596BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS += \
3597    --prop com.android.build.boot.security_patch:$(BOOT_SECURITY_PATCH)
3598endif
3599
3600ifdef VENDOR_SECURITY_PATCH
3601BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS += \
3602    --prop com.android.build.vendor.security_patch:$(VENDOR_SECURITY_PATCH)
3603endif
3604
3605ifdef ODM_SECURITY_PATCH
3606BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS += \
3607    --prop com.android.build.odm.security_patch:$(ODM_SECURITY_PATCH)
3608endif
3609
3610ifdef VENDOR_DLKM_SECURITY_PATCH
3611BOARD_AVB_VENDOR_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
3612    --prop com.android.build.vendor_dlkm.security_patch:$(VENDOR_DLKM_SECURITY_PATCH)
3613endif
3614
3615ifdef ODM_DLKM_SECURITY_PATCH
3616BOARD_AVB_ODM_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
3617    --prop com.android.build.odm_dlkm.security_patch:$(ODM_DLKM_SECURITY_PATCH)
3618endif
3619
3620ifdef PVMFW_SECURITY_PATCH
3621BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS += \
3622    --prop com.android.build.pvmfw.security_patch:$(PVMFW_SECURITY_PATCH)
3623endif
3624
3625BOOT_FOOTER_ARGS := BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS
3626VENDOR_BOOT_FOOTER_ARGS := BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS
3627DTBO_FOOTER_ARGS := BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS
3628PVMFW_FOOTER_ARGS := BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS
3629SYSTEM_FOOTER_ARGS := BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS
3630VENDOR_FOOTER_ARGS := BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS
3631RECOVERY_FOOTER_ARGS := BOARD_AVB_RECOVERY_ADD_HASH_FOOTER_ARGS
3632PRODUCT_FOOTER_ARGS := BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS
3633SYSTEM_EXT_FOOTER_ARGS := BOARD_AVB_SYSTEM_EXT_ADD_HASHTREE_FOOTER_ARGS
3634ODM_FOOTER_ARGS := BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS
3635VENDOR_DLKM_FOOTER_ARGS := BOARD_AVB_VENDOR_DLKM_ADD_HASHTREE_FOOTER_ARGS
3636ODM_DLKM_FOOTER_ARGS := BOARD_AVB_ODM_DLKM_ADD_HASHTREE_FOOTER_ARGS
3637
3638# Helper function that checks and sets required build variables for an AVB chained partition.
3639# $(1): the partition to enable AVB chain, e.g., boot or system or vbmeta_system.
3640define _check-and-set-avb-chain-args
3641$(eval part := $(1))
3642$(eval PART=$(call to-upper,$(part)))
3643
3644$(eval _key_path := BOARD_AVB_$(PART)_KEY_PATH)
3645$(eval _signing_algorithm := BOARD_AVB_$(PART)_ALGORITHM)
3646$(eval _rollback_index := BOARD_AVB_$(PART)_ROLLBACK_INDEX)
3647$(eval _rollback_index_location := BOARD_AVB_$(PART)_ROLLBACK_INDEX_LOCATION)
3648$(if $($(_key_path)),,$(error $(_key_path) is not defined))
3649$(if $($(_signing_algorithm)),,$(error $(_signing_algorithm) is not defined))
3650$(if $($(_rollback_index)),,$(error $(_rollback_index) is not defined))
3651$(if $($(_rollback_index_location)),,$(error $(_rollback_index_location) is not defined))
3652
3653# Set INTERNAL_AVB_(PART)_SIGNING_ARGS
3654$(eval _signing_args := INTERNAL_AVB_$(PART)_SIGNING_ARGS)
3655$(eval $(_signing_args) := \
3656    --algorithm $($(_signing_algorithm)) --key $($(_key_path)))
3657
3658# The recovery partition in non-A/B devices should be verified separately. Skip adding the chain
3659# partition descriptor for recovery partition into vbmeta.img.
3660$(if $(or $(filter-out true,$(TARGET_OTA_ALLOW_NON_AB)),$(filter-out recovery,$(part))),\
3661    $(eval INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
3662        --chain_partition $(part):$($(_rollback_index_location)):$(AVB_CHAIN_KEY_DIR)/$(part).avbpubkey))
3663
3664# Set rollback_index via footer args for non-chained vbmeta image. Chained vbmeta image will pick up
3665# the index via a separate flag (e.g. BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX).
3666$(if $(filter $(part),$(part:vbmeta_%=%)),\
3667    $(eval _footer_args := $(PART)_FOOTER_ARGS) \
3668    $(eval $($(_footer_args)) += --rollback_index $($(_rollback_index))))
3669endef
3670
3671# Checks and sets the required build variables for an AVB partition. The partition will be
3672# configured as a chained partition, if BOARD_AVB_<partition>_KEY_PATH is defined. Otherwise the
3673# image descriptor will be included into vbmeta.img, unless it has been already added to any chained
3674# VBMeta image.
3675# Multiple boot images can be generated based on BOARD_KERNEL_BINARIES
3676# but vbmeta would capture the image descriptor of only the first boot
3677# image specified in BUILT_BOOTIMAGE_TARGET.
3678# $(1): Partition name, e.g. boot or system.
3679define check-and-set-avb-args
3680$(eval _in_chained_vbmeta := $(filter $(1),$(INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES)))
3681$(if $(BOARD_AVB_$(call to-upper,$(1))_KEY_PATH),\
3682    $(if $(_in_chained_vbmeta),\
3683        $(error Chaining partition "$(1)" in chained VBMeta image is not supported)) \
3684    $(call _check-and-set-avb-chain-args,$(1)),\
3685    $(if $(_in_chained_vbmeta),,\
3686        $(if $(filter boot,$(1)),\
3687            $(eval INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
3688                --include_descriptors_from_image $(firstword $(call images-for-partitions,$(1)))),\
3689            $(eval INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
3690                --include_descriptors_from_image $(call images-for-partitions,$(1))))))
3691endef
3692
3693# Checks and sets build variables for a custom chained partition to include it into vbmeta.img.
3694# $(1): the custom partition to enable AVB chain.
3695define check-and-set-custom-avb-chain-args
3696$(eval part := $(1))
3697$(eval PART=$(call to-upper,$(part)))
3698$(eval _rollback_index_location := BOARD_AVB_$(PART)_ROLLBACK_INDEX_LOCATION)
3699$(if $($(_rollback_index_location)),,$(error $(_rollback_index_location) is not defined))
3700
3701INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
3702    --chain_partition $(part):$($(_rollback_index_location)):$(AVB_CHAIN_KEY_DIR)/$(part).avbpubkey
3703endef
3704
3705ifdef INSTALLED_BOOTIMAGE_TARGET
3706$(eval $(call check-and-set-avb-args,boot))
3707endif
3708
3709ifdef INSTALLED_VENDOR_BOOTIMAGE_TARGET
3710$(eval $(call check-and-set-avb-args,vendor_boot))
3711endif
3712
3713$(eval $(call check-and-set-avb-args,system))
3714
3715ifdef INSTALLED_VENDORIMAGE_TARGET
3716$(eval $(call check-and-set-avb-args,vendor))
3717endif
3718
3719ifdef INSTALLED_PRODUCTIMAGE_TARGET
3720$(eval $(call check-and-set-avb-args,product))
3721endif
3722
3723ifdef INSTALLED_SYSTEM_EXTIMAGE_TARGET
3724$(eval $(call check-and-set-avb-args,system_ext))
3725endif
3726
3727ifdef INSTALLED_ODMIMAGE_TARGET
3728$(eval $(call check-and-set-avb-args,odm))
3729endif
3730
3731ifdef INSTALLED_VENDOR_DLKMIMAGE_TARGET
3732$(eval $(call check-and-set-avb-args,vendor_dlkm))
3733endif
3734
3735ifdef INSTALLED_ODM_DLKMIMAGE_TARGET
3736$(eval $(call check-and-set-avb-args,odm_dlkm))
3737endif
3738
3739ifdef INSTALLED_DTBOIMAGE_TARGET
3740$(eval $(call check-and-set-avb-args,dtbo))
3741endif
3742
3743ifdef INSTALLED_PVMFWIMAGE_TARGET
3744$(eval $(call check-and-set-avb-args,pvmfw))
3745endif
3746
3747ifdef INSTALLED_RECOVERYIMAGE_TARGET
3748$(eval $(call check-and-set-avb-args,recovery))
3749endif
3750
3751# Not using INSTALLED_VBMETA_SYSTEMIMAGE_TARGET as it won't be set yet.
3752ifdef BOARD_AVB_VBMETA_SYSTEM
3753$(eval $(call check-and-set-avb-args,vbmeta_system))
3754endif
3755
3756ifdef BOARD_AVB_VBMETA_VENDOR
3757$(eval $(call check-and-set-avb-args,vbmeta_vendor))
3758endif
3759
3760ifneq ($(strip $(BOARD_CUSTOMIMAGES_PARTITION_LIST)),)
3761$(foreach partition,$(BOARD_CUSTOMIMAGES_PARTITION_LIST), \
3762    $(eval $(call check-and-set-custom-avb-chain-args,$(partition))))
3763endif
3764
3765# Add kernel cmdline descriptor for kernel to mount system.img as root with
3766# dm-verity. This works when system.img is either chained or not-chained:
3767# - chained: The --setup_as_rootfs_from_kernel option will add dm-verity kernel
3768#   cmdline descriptor to system.img
3769# - not-chained: The --include_descriptors_from_image option for make_vbmeta_image
3770#   will include the kernel cmdline descriptor from system.img into vbmeta.img
3771ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
3772ifeq ($(filter system, $(BOARD_SUPER_PARTITION_PARTITION_LIST)),)
3773BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS += --setup_as_rootfs_from_kernel
3774endif
3775endif
3776
3777BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --padding_size 4096
3778BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS += --padding_size 4096
3779BOARD_AVB_MAKE_VBMETA_VENDOR_IMAGE_ARGS += --padding_size 4096
3780
3781ifeq (eng,$(filter eng, $(TARGET_BUILD_VARIANT)))
3782# We only need the flag in top-level vbmeta.img.
3783BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --set_hashtree_disabled_flag
3784endif
3785
3786ifdef BOARD_AVB_ROLLBACK_INDEX
3787BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --rollback_index $(BOARD_AVB_ROLLBACK_INDEX)
3788endif
3789
3790ifdef BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX
3791BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS += \
3792    --rollback_index $(BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX)
3793endif
3794
3795ifdef BOARD_AVB_VBMETA_VENDOR_ROLLBACK_INDEX
3796BOARD_AVB_MAKE_VBMETA_VENDOR_IMAGE_ARGS += \
3797    --rollback_index $(BOARD_AVB_VBMETA_VENDOR_ROLLBACK_INDEX)
3798endif
3799
3800# $(1): the directory to extract public keys to
3801define extract-avb-chain-public-keys
3802  $(if $(BOARD_AVB_BOOT_KEY_PATH),\
3803    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_BOOT_KEY_PATH) \
3804      --output $(1)/boot.avbpubkey)
3805  $(if $(BOARD_AVB_VENDOR_BOOT_KEY_PATH),\
3806    $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VENDOR_BOOT_KEY_PATH) \
3807      --output $(1)/vendor_boot.avbpubkey)
3808  $(if $(BOARD_AVB_SYSTEM_KEY_PATH),\
3809    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_SYSTEM_KEY_PATH) \
3810      --output $(1)/system.avbpubkey)
3811  $(if $(BOARD_AVB_VENDOR_KEY_PATH),\
3812    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VENDOR_KEY_PATH) \
3813      --output $(1)/vendor.avbpubkey)
3814  $(if $(BOARD_AVB_PRODUCT_KEY_PATH),\
3815    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_PRODUCT_KEY_PATH) \
3816      --output $(1)/product.avbpubkey)
3817  $(if $(BOARD_AVB_SYSTEM_EXT_KEY_PATH),\
3818    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_SYSTEM_EXT_KEY_PATH) \
3819      --output $(1)/system_ext.avbpubkey)
3820  $(if $(BOARD_AVB_ODM_KEY_PATH),\
3821    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_ODM_KEY_PATH) \
3822      --output $(1)/odm.avbpubkey)
3823  $(if $(BOARD_AVB_VENDOR_DLKM_KEY_PATH),\
3824    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VENDOR_DLKM_KEY_PATH) \
3825      --output $(1)/vendor_dlkm.avbpubkey)
3826  $(if $(BOARD_AVB_ODM_DLKM_KEY_PATH),\
3827    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_ODM_DLKM_KEY_PATH) \
3828      --output $(1)/odm_dlkm.avbpubkey)
3829  $(if $(BOARD_AVB_DTBO_KEY_PATH),\
3830    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_DTBO_KEY_PATH) \
3831      --output $(1)/dtbo.avbpubkey)
3832  $(if $(BOARD_AVB_PVMFW_KEY_PATH),\
3833    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_PVMFW_KEY_PATH) \
3834      --output $(1)/pvmfw.avbpubkey)
3835  $(if $(BOARD_AVB_RECOVERY_KEY_PATH),\
3836    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_RECOVERY_KEY_PATH) \
3837      --output $(1)/recovery.avbpubkey)
3838  $(if $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH),\
3839    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH) \
3840        --output $(1)/vbmeta_system.avbpubkey)
3841  $(if $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH),\
3842    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH) \
3843        --output $(1)/vbmeta_vendor.avbpubkey)
3844  $(if $(BOARD_CUSTOMIMAGES_PARTITION_LIST),\
3845    $(hide) $(foreach partition,$(BOARD_CUSTOMIMAGES_PARTITION_LIST), \
3846        $(AVBTOOL) extract_public_key --key $(BOARD_AVB_$(call to-upper,$(partition))_KEY_PATH) \
3847            --output $(1)/$(partition).avbpubkey;))
3848endef
3849
3850# Builds a chained VBMeta image. This VBMeta image will contain the descriptors for the partitions
3851# specified in BOARD_AVB_VBMETA_<NAME>. The built VBMeta image will be included into the top-level
3852# vbmeta image as a chained partition. For example, if a target defines `BOARD_AVB_VBMETA_SYSTEM
3853# := system system_ext`, `vbmeta_system.img` will be created that includes the descriptors for
3854# `system.img` and `system_ext.img`. `vbmeta_system.img` itself will be included into
3855# `vbmeta.img` as a chained partition.
3856# $(1): VBMeta image name, such as "vbmeta_system", "vbmeta_vendor" etc.
3857# $(2): Output filename.
3858define build-chained-vbmeta-image
3859  $(call pretty,"Target chained vbmeta image: $@")
3860  $(hide) $(AVBTOOL) make_vbmeta_image \
3861      $(INTERNAL_AVB_$(call to-upper,$(1))_SIGNING_ARGS) \
3862      $(BOARD_AVB_MAKE_$(call to-upper,$(1))_IMAGE_ARGS) \
3863      $(foreach image,$(BOARD_AVB_$(call to-upper,$(1))), \
3864          --include_descriptors_from_image $(call images-for-partitions,$(image))) \
3865      --output $@
3866endef
3867
3868ifdef BUILDING_SYSTEM_IMAGE
3869ifdef BOARD_AVB_VBMETA_SYSTEM
3870INSTALLED_VBMETA_SYSTEMIMAGE_TARGET := $(PRODUCT_OUT)/vbmeta_system.img
3871$(INSTALLED_VBMETA_SYSTEMIMAGE_TARGET): \
3872	    $(AVBTOOL) \
3873	    $(call images-for-partitions,$(BOARD_AVB_VBMETA_SYSTEM)) \
3874	    $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH)
3875	$(call build-chained-vbmeta-image,vbmeta_system)
3876endif
3877endif # BUILDING_SYSTEM_IMAGE
3878
3879ifdef BOARD_AVB_VBMETA_VENDOR
3880INSTALLED_VBMETA_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vbmeta_vendor.img
3881$(INSTALLED_VBMETA_VENDORIMAGE_TARGET): \
3882	    $(AVBTOOL) \
3883	    $(call images-for-partitions,$(BOARD_AVB_VBMETA_VENDOR)) \
3884	    $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH)
3885	$(call build-chained-vbmeta-image,vbmeta_vendor)
3886endif
3887
3888define build-vbmetaimage-target
3889  $(call pretty,"Target vbmeta image: $(INSTALLED_VBMETAIMAGE_TARGET)")
3890  $(hide) mkdir -p $(AVB_CHAIN_KEY_DIR)
3891  $(call extract-avb-chain-public-keys, $(AVB_CHAIN_KEY_DIR))
3892  $(hide) $(AVBTOOL) make_vbmeta_image \
3893    $(INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS) \
3894    $(PRIVATE_AVB_VBMETA_SIGNING_ARGS) \
3895    $(BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS) \
3896    --output $@
3897  $(hide) rm -rf $(AVB_CHAIN_KEY_DIR)
3898endef
3899
3900ifdef BUILDING_VBMETA_IMAGE
3901INSTALLED_VBMETAIMAGE_TARGET := $(BUILT_VBMETAIMAGE_TARGET)
3902$(INSTALLED_VBMETAIMAGE_TARGET): PRIVATE_AVB_VBMETA_SIGNING_ARGS := \
3903    --algorithm $(BOARD_AVB_ALGORITHM) --key $(BOARD_AVB_KEY_PATH)
3904
3905$(INSTALLED_VBMETAIMAGE_TARGET): \
3906	    $(AVBTOOL) \
3907	    $(INSTALLED_BOOTIMAGE_TARGET) \
3908	    $(INSTALLED_VENDOR_BOOTIMAGE_TARGET) \
3909	    $(INSTALLED_SYSTEMIMAGE_TARGET) \
3910	    $(INSTALLED_VENDORIMAGE_TARGET) \
3911	    $(INSTALLED_PRODUCTIMAGE_TARGET) \
3912	    $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) \
3913	    $(INSTALLED_ODMIMAGE_TARGET) \
3914	    $(INSTALLED_VENDOR_DLKMIMAGE_TARGET) \
3915	    $(INSTALLED_ODM_DLKMIMAGE_TARGET) \
3916	    $(INSTALLED_DTBOIMAGE_TARGET) \
3917	    $(INSTALLED_PVMFWIMAGE_TARGET) \
3918	    $(INSTALLED_CUSTOMIMAGES_TARGET) \
3919	    $(INSTALLED_RECOVERYIMAGE_TARGET) \
3920	    $(INSTALLED_VBMETA_SYSTEMIMAGE_TARGET) \
3921	    $(INSTALLED_VBMETA_VENDORIMAGE_TARGET) \
3922	    $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH) \
3923	    $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH) \
3924	    $(BOARD_AVB_KEY_PATH)
3925	$(build-vbmetaimage-target)
3926
3927.PHONY: vbmetaimage-nodeps
3928vbmetaimage-nodeps: PRIVATE_AVB_VBMETA_SIGNING_ARGS := \
3929    --algorithm $(BOARD_AVB_ALGORITHM) --key $(BOARD_AVB_KEY_PATH)
3930vbmetaimage-nodeps:
3931	$(build-vbmetaimage-target)
3932endif # BUILDING_VBMETA_IMAGE
3933
3934endif # BOARD_AVB_ENABLE
3935
3936# List of files from all images
3937INTERNAL_ALLIMAGES_FILES := \
3938    $(FULL_SYSTEMIMAGE_DEPS) \
3939    $(INTERNAL_RAMDISK_FILES) \
3940    $(INTERNAL_USERDATAIMAGE_FILES) \
3941    $(INTERNAL_VENDORIMAGE_FILES) \
3942    $(INTERNAL_PRODUCTIMAGE_FILES) \
3943    $(INTERNAL_SYSTEM_EXTIMAGE_FILES) \
3944    $(INTERNAL_ODMIMAGE_FILES) \
3945    $(INTERNAL_VENDOR_DLKMIMAGE_FILES) \
3946    $(INTERNAL_ODM_DLKMIMAGE_FILES) \
3947
3948# -----------------------------------------------------------------
3949# Check VINTF of build
3950
3951# Note: vendor_dlkm and odm_dlkm does not have VINTF files.
3952ifeq (,$(TARGET_BUILD_UNBUNDLED))
3953
3954intermediates := $(call intermediates-dir-for,PACKAGING,check_vintf_all)
3955check_vintf_all_deps :=
3956
3957# The build system only writes VINTF metadata to */etc/vintf paths. Legacy paths aren't needed here
3958# because they are only used for prebuilt images.
3959check_vintf_common_srcs_patterns := \
3960  $(TARGET_OUT)/etc/vintf/% \
3961  $(TARGET_OUT_VENDOR)/etc/vintf/% \
3962  $(TARGET_OUT_ODM)/etc/vintf/% \
3963  $(TARGET_OUT_PRODUCT)/etc/vintf/% \
3964  $(TARGET_OUT_SYSTEM_EXT)/etc/vintf/% \
3965
3966check_vintf_common_srcs := $(sort $(filter $(check_vintf_common_srcs_patterns),$(INTERNAL_ALLIMAGES_FILES)))
3967check_vintf_common_srcs_patterns :=
3968
3969check_vintf_has_system :=
3970check_vintf_has_vendor :=
3971
3972ifneq (,$(filter EMPTY_ODM_SKU_PLACEHOLDER,$(ODM_MANIFEST_SKUS)))
3973$(error EMPTY_ODM_SKU_PLACEHOLDER is an internal variable and cannot be used for ODM_MANIFEST_SKUS)
3974endif
3975ifneq (,$(filter EMPTY_VENDOR_SKU_PLACEHOLDER,$(DEVICE_MANIFEST_SKUS)))
3976$(error EMPTY_VENDOR_SKU_PLACEHOLDER is an internal variable and cannot be used for DEIVCE_MANIFEST_SKUS)
3977endif
3978
3979# -- Check system manifest / matrix including fragments (excluding other framework manifests / matrices, e.g. product);
3980check_vintf_system_deps := $(filter $(TARGET_OUT)/etc/vintf/%, $(check_vintf_common_srcs))
3981ifneq ($(check_vintf_system_deps),)
3982check_vintf_has_system := true
3983
3984check_vintf_system_log := $(intermediates)/check_vintf_system.log
3985check_vintf_all_deps += $(check_vintf_system_log)
3986$(check_vintf_system_log): $(HOST_OUT_EXECUTABLES)/checkvintf $(check_vintf_system_deps)
3987	@( $< --check-one --dirmap /system:$(TARGET_OUT) > $@ 2>&1 ) || ( cat $@ && exit 1 )
3988check_vintf_system_log :=
3989
3990vintffm_log := $(intermediates)/vintffm.log
3991check_vintf_all_deps += $(vintffm_log)
3992$(vintffm_log): $(HOST_OUT_EXECUTABLES)/vintffm $(check_vintf_system_deps)
3993	@( $< --check --dirmap /system:$(TARGET_OUT) \
3994	  $(VINTF_FRAMEWORK_MANIFEST_FROZEN_DIR) > $@ 2>&1 ) || ( cat $@ && exit 1 )
3995
3996endif # check_vintf_system_deps
3997check_vintf_system_deps :=
3998
3999# -- Check vendor manifest / matrix including fragments (excluding other device manifests / matrices)
4000check_vintf_vendor_deps := $(filter $(TARGET_OUT_VENDOR)/etc/vintf/%, $(check_vintf_common_srcs))
4001ifneq ($(check_vintf_vendor_deps),)
4002check_vintf_has_vendor := true
4003check_vintf_vendor_log := $(intermediates)/check_vintf_vendor.log
4004check_vintf_all_deps += $(check_vintf_vendor_log)
4005# Check vendor SKU=(empty) case when:
4006# - DEVICE_MANIFEST_FILE is not empty; OR
4007# - DEVICE_MANIFEST_FILE is empty AND DEVICE_MANIFEST_SKUS is empty (only vendor manifest fragments are used)
4008$(check_vintf_vendor_log): PRIVATE_VENDOR_SKUS := \
4009  $(if $(DEVICE_MANIFEST_FILE),EMPTY_VENDOR_SKU_PLACEHOLDER,\
4010    $(if $(DEVICE_MANIFEST_SKUS),,EMPTY_VENDOR_SKU_PLACEHOLDER)) \
4011  $(DEVICE_MANIFEST_SKUS)
4012$(check_vintf_vendor_log): $(HOST_OUT_EXECUTABLES)/checkvintf $(check_vintf_vendor_deps)
4013	$(foreach vendor_sku,$(PRIVATE_VENDOR_SKUS), \
4014	  ( $< --check-one --dirmap /vendor:$(TARGET_OUT_VENDOR) \
4015	       --property ro.boot.product.vendor.sku=$(filter-out EMPTY_VENDOR_SKU_PLACEHOLDER,$(vendor_sku)) \
4016	       > $@ 2>&1 ) || ( cat $@ && exit 1 ); )
4017check_vintf_vendor_log :=
4018endif # check_vintf_vendor_deps
4019check_vintf_vendor_deps :=
4020
4021# -- Kernel version and configurations.
4022ifeq ($(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS),true)
4023
4024BUILT_KERNEL_CONFIGS_FILE := $(intermediates)/kernel_configs.txt
4025BUILT_KERNEL_VERSION_FILE := $(intermediates)/kernel_version.txt
4026
4027my_board_extracted_kernel :=
4028
4029# BOARD_KERNEL_CONFIG_FILE and BOARD_KERNEL_VERSION can be used to override the values extracted
4030# from INSTALLED_KERNEL_TARGET.
4031ifdef BOARD_KERNEL_CONFIG_FILE
4032ifdef BOARD_KERNEL_VERSION
4033$(BUILT_KERNEL_CONFIGS_FILE): $(BOARD_KERNEL_CONFIG_FILE)
4034	cp $< $@
4035$(BUILT_KERNEL_VERSION_FILE):
4036	echo $(BOARD_KERNEL_VERSION) > $@
4037
4038my_board_extracted_kernel := true
4039endif # BOARD_KERNEL_VERSION
4040endif # BOARD_KERNEL_CONFIG_FILE
4041
4042ifneq ($(my_board_extracted_kernel),true)
4043# Tools for decompression that is not in PATH.
4044# Check $(EXTRACT_KERNEL) for decompression algorithms supported by the script.
4045# Algorithms that are in the script but not in this list will be found in PATH.
4046my_decompress_tools := \
4047    lz4:$(HOST_OUT_EXECUTABLES)/lz4 \
4048
4049endif # my_board_extracted_kernel
4050
4051ifneq ($(my_board_extracted_kernel),true)
4052ifdef INSTALLED_KERNEL_TARGET
4053$(BUILT_KERNEL_CONFIGS_FILE): .KATI_IMPLICIT_OUTPUTS := $(BUILT_KERNEL_VERSION_FILE)
4054$(BUILT_KERNEL_CONFIGS_FILE): PRIVATE_DECOMPRESS_TOOLS := $(my_decompress_tools)
4055$(BUILT_KERNEL_CONFIGS_FILE): $(foreach pair,$(my_decompress_tools),$(call word-colon,2,$(pair)))
4056$(BUILT_KERNEL_CONFIGS_FILE): $(EXTRACT_KERNEL) $(firstword $(INSTALLED_KERNEL_TARGET))
4057	$< --tools $(PRIVATE_DECOMPRESS_TOOLS) --input $(firstword $(INSTALLED_KERNEL_TARGET)) \
4058	  --output-configs $@ \
4059	  --output-release $(BUILT_KERNEL_VERSION_FILE)
4060
4061my_board_extracted_kernel := true
4062endif # INSTALLED_KERNEL_TARGET
4063endif # my_board_extracted_kernel
4064
4065ifneq ($(my_board_extracted_kernel),true)
4066ifdef INSTALLED_BOOTIMAGE_TARGET
4067$(BUILT_KERNEL_CONFIGS_FILE): .KATI_IMPLICIT_OUTPUTS := $(BUILT_KERNEL_VERSION_FILE)
4068$(BUILT_KERNEL_CONFIGS_FILE): PRIVATE_DECOMPRESS_TOOLS := $(my_decompress_tools)
4069$(BUILT_KERNEL_CONFIGS_FILE): $(foreach pair,$(my_decompress_tools),$(call word-colon,2,$(pair)))
4070$(BUILT_KERNEL_CONFIGS_FILE): PRIVATE_UNPACKED_BOOTIMG := $(intermediates)/unpacked_bootimage
4071$(BUILT_KERNEL_CONFIGS_FILE): \
4072        $(HOST_OUT_EXECUTABLES)/unpack_bootimg \
4073        $(EXTRACT_KERNEL) \
4074        $(INSTALLED_BOOTIMAGE_TARGET)
4075	$(HOST_OUT_EXECUTABLES)/unpack_bootimg --boot_img $(INSTALLED_BOOTIMAGE_TARGET) --out $(PRIVATE_UNPACKED_BOOTIMG)
4076	$(EXTRACT_KERNEL) --tools $(PRIVATE_DECOMPRESS_TOOLS) --input $(PRIVATE_UNPACKED_BOOTIMG)/kernel \
4077	  --output-configs $@ \
4078	  --output-release $(BUILT_KERNEL_VERSION_FILE)
4079
4080my_board_extracted_kernel := true
4081endif # INSTALLED_BOOTIMAGE_TARGET
4082endif # my_board_extracted_kernel
4083
4084ifneq ($(my_board_extracted_kernel),true)
4085$(warning Neither INSTALLED_KERNEL_TARGET nor INSTALLED_BOOTIMAGE_TARGET is defined when \
4086    PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS  is true. Information about the updated kernel \
4087    cannot be built into OTA update package. You can fix this by: \
4088    (1) setting TARGET_NO_KERNEL to false and installing the built kernel to $(PRODUCT_OUT)/kernel,\
4089        so that kernel information will be extracted from the built kernel; or \
4090    (2) Add a prebuilt boot image and specify it in BOARD_PREBUILT_BOOTIMAGE; or \
4091    (3) extracting kernel configuration and defining BOARD_KERNEL_CONFIG_FILE and \
4092        BOARD_KERNEL_VERSION manually; or \
4093    (4) unsetting PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS manually.)
4094# Clear their values to indicate that these two files does not exist.
4095BUILT_KERNEL_CONFIGS_FILE :=
4096BUILT_KERNEL_VERSION_FILE :=
4097endif
4098
4099my_decompress_tools :=
4100my_board_extracted_kernel :=
4101
4102endif # PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS
4103
4104# -- Check VINTF compatibility of build.
4105# Skip partial builds; only check full builds. Only check if:
4106# - PRODUCT_ENFORCE_VINTF_MANIFEST is true
4107# - system / vendor VINTF metadata exists
4108# - Building product / system_ext / odm images if board has product / system_ext / odm images
4109ifeq ($(PRODUCT_ENFORCE_VINTF_MANIFEST),true)
4110ifeq ($(check_vintf_has_system),true)
4111ifeq ($(check_vintf_has_vendor),true)
4112ifeq ($(filter true,$(BUILDING_ODM_IMAGE)),$(filter true,$(BOARD_USES_ODMIMAGE)))
4113ifeq ($(filter true,$(BUILDING_PRODUCT_IMAGE)),$(filter true,$(BOARD_USES_PRODUCTIMAGE)))
4114ifeq ($(filter true,$(BUILDING_SYSTEM_EXT_IMAGE)),$(filter true,$(BOARD_USES_SYSTEM_EXTIMAGE)))
4115
4116check_vintf_compatible_log := $(intermediates)/check_vintf_compatible.log
4117check_vintf_all_deps += $(check_vintf_compatible_log)
4118
4119check_vintf_compatible_args :=
4120check_vintf_compatible_deps := $(check_vintf_common_srcs)
4121
4122ifeq ($(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS),true)
4123ifneq (,$(BUILT_KERNEL_VERSION_FILE)$(BUILT_KERNEL_CONFIGS_FILE))
4124check_vintf_compatible_args += --kernel $(BUILT_KERNEL_VERSION_FILE):$(BUILT_KERNEL_CONFIGS_FILE)
4125check_vintf_compatible_deps += $(BUILT_KERNEL_CONFIGS_FILE) $(BUILT_KERNEL_VERSION_FILE)
4126endif # BUILT_KERNEL_VERSION_FILE != "" || BUILT_KERNEL_CONFIGS_FILE != ""
4127endif # PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS
4128
4129check_vintf_compatible_args += \
4130  --dirmap /system:$(TARGET_OUT) \
4131  --dirmap /vendor:$(TARGET_OUT_VENDOR) \
4132  --dirmap /odm:$(TARGET_OUT_ODM) \
4133  --dirmap /product:$(TARGET_OUT_PRODUCT) \
4134  --dirmap /system_ext:$(TARGET_OUT_SYSTEM_EXT) \
4135
4136ifdef PRODUCT_SHIPPING_API_LEVEL
4137check_vintf_compatible_args += --property ro.product.first_api_level=$(PRODUCT_SHIPPING_API_LEVEL)
4138endif # PRODUCT_SHIPPING_API_LEVEL
4139
4140$(check_vintf_compatible_log): PRIVATE_CHECK_VINTF_ARGS := $(check_vintf_compatible_args)
4141$(check_vintf_compatible_log): PRIVATE_CHECK_VINTF_DEPS := $(check_vintf_compatible_deps)
4142# Check ODM SKU=(empty) case when:
4143# - ODM_MANIFEST_FILES is not empty; OR
4144# - ODM_MANIFEST_FILES is empty AND ODM_MANIFEST_SKUS is empty (only ODM manifest fragments are used)
4145$(check_vintf_compatible_log): PRIVATE_ODM_SKUS := \
4146  $(if $(ODM_MANIFEST_FILES),EMPTY_ODM_SKU_PLACEHOLDER,\
4147    $(if $(ODM_MANIFEST_SKUS),,EMPTY_ODM_SKU_PLACEHOLDER)) \
4148  $(ODM_MANIFEST_SKUS)
4149# Check vendor SKU=(empty) case when:
4150# - DEVICE_MANIFEST_FILE is not empty; OR
4151# - DEVICE_MANIFEST_FILE is empty AND DEVICE_MANIFEST_SKUS is empty (only vendor manifest fragments are used)
4152$(check_vintf_compatible_log): PRIVATE_VENDOR_SKUS := \
4153  $(if $(DEVICE_MANIFEST_FILE),EMPTY_VENDOR_SKU_PLACEHOLDER,\
4154    $(if $(DEVICE_MANIFEST_SKUS),,EMPTY_VENDOR_SKU_PLACEHOLDER)) \
4155  $(DEVICE_MANIFEST_SKUS)
4156$(check_vintf_compatible_log): $(HOST_OUT_EXECUTABLES)/checkvintf $(check_vintf_compatible_deps)
4157	@echo "PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS=$(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS)" > $@
4158	@echo -n -e 'Deps: \n  ' >> $@
4159	@sed 's/ /\n  /g' <<< "$(PRIVATE_CHECK_VINTF_DEPS)" >> $@
4160	@echo -n -e 'Args: \n  ' >> $@
4161	@cat <<< "$(PRIVATE_CHECK_VINTF_ARGS)" >> $@
4162	$(foreach odm_sku,$(PRIVATE_ODM_SKUS), $(foreach vendor_sku,$(PRIVATE_VENDOR_SKUS), \
4163	  echo "For ODM SKU = $(odm_sku), vendor SKU = $(vendor_sku)" >> $@; \
4164	  ( $< --check-compat $(PRIVATE_CHECK_VINTF_ARGS) \
4165	       --property ro.boot.product.hardware.sku=$(filter-out EMPTY_ODM_SKU_PLACEHOLDER,$(odm_sku)) \
4166	       --property ro.boot.product.vendor.sku=$(filter-out EMPTY_VENDOR_SKU_PLACEHOLDER,$(vendor_sku)) \
4167	       >> $@ 2>&1 ) || (cat $@ && exit 1); ))
4168
4169check_vintf_compatible_log :=
4170check_vintf_compatible_args :=
4171check_vintf_compatible_deps :=
4172
4173endif # BUILDING_SYSTEM_EXT_IMAGE equals BOARD_USES_SYSTEM_EXTIMAGE
4174endif # BUILDING_PRODUCT_IMAGE equals BOARD_USES_PRODUCTIMAGE
4175endif # BUILDING_ODM_IMAGE equals BOARD_USES_ODMIMAGE
4176endif # check_vintf_has_vendor
4177endif # check_vintf_has_system
4178endif # PRODUCT_ENFORCE_VINTF_MANIFEST
4179
4180# Add all logs of VINTF checks to dist builds
4181droid_targets: $(check_vintf_all_deps)
4182$(call dist-for-goals, droid_targets, $(check_vintf_all_deps))
4183
4184# Helper alias to check all VINTF of current build.
4185.PHONY: check-vintf-all
4186check-vintf-all: $(check_vintf_all_deps)
4187	$(foreach file,$^,echo "$(file)"; cat "$(file)"; echo;)
4188
4189check_vintf_has_vendor :=
4190check_vintf_has_system :=
4191check_vintf_common_srcs :=
4192check_vintf_all_deps :=
4193intermediates :=
4194endif # !TARGET_BUILD_UNBUNDLED
4195
4196# -----------------------------------------------------------------
4197# Check image sizes <= size of super partition
4198
4199ifeq (,$(TARGET_BUILD_UNBUNDLED))
4200
4201ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
4202
4203PARTITIONS_AND_OTHER_IN_SUPER := $(BOARD_SUPER_PARTITION_PARTITION_LIST)
4204
4205# Add the system other image to the misc_info. Because factory ota may install system_other to the super partition.
4206ifdef BUILDING_SYSTEM_OTHER_IMAGE
4207PARTITIONS_AND_OTHER_IN_SUPER += system_other
4208endif # BUILDING_SYSTEM_OTHER_IMAGE
4209
4210# $(1): misc_info.txt
4211# #(2): optional log file
4212define check-all-partition-sizes-target
4213  mkdir -p $(dir $(1))
4214  rm -f $(1)
4215  $(call dump-super-image-info, $(1))
4216  $(foreach partition,$(PARTITIONS_AND_OTHER_IN_SUPER), \
4217    echo "$(partition)_image="$(call images-for-partitions,$(partition)) >> $(1);)
4218  $(CHECK_PARTITION_SIZES) $(if $(2),--logfile $(2),-v) $(1)
4219endef
4220
4221check_all_partition_sizes_log := $(call intermediates-dir-for,PACKAGING,check-all-partition-sizes)/check_all_partition_sizes.log
4222droid_targets: $(check_all_partition_sizes_log)
4223$(call dist-for-goals, droid_targets, $(check_all_partition_sizes_log))
4224
4225$(check_all_partition_sizes_log): \
4226    $(CHECK_PARTITION_SIZES) \
4227    $(call images-for-partitions,$(PARTITIONS_AND_OTHER_IN_SUPER))
4228	$(call check-all-partition-sizes-target, \
4229	  $(call intermediates-dir-for,PACKAGING,check-all-partition-sizes)/misc_info.txt, \
4230	  $@)
4231
4232.PHONY: check-all-partition-sizes
4233check-all-partition-sizes: $(check_all_partition_sizes_log)
4234
4235.PHONY: check-all-partition-sizes-nodeps
4236check-all-partition-sizes-nodeps:
4237	$(call check-all-partition-sizes-target, \
4238	  $(call intermediates-dir-for,PACKAGING,check-all-partition-sizes-nodeps)/misc_info.txt)
4239
4240endif # PRODUCT_BUILD_SUPER_PARTITION
4241
4242endif # !TARGET_BUILD_UNBUNDLED
4243
4244# -----------------------------------------------------------------
4245# bring in the installer image generation defines if necessary
4246ifeq ($(TARGET_USE_DISKINSTALLER),true)
4247include bootable/diskinstaller/config.mk
4248endif
4249
4250# -----------------------------------------------------------------
4251# host tools needed to build dist and OTA packages
4252
4253ifeq ($(BUILD_OS),darwin)
4254  build_ota_package := false
4255  build_otatools_package := false
4256else
4257  # Set build_ota_package, and allow opt-out below.
4258  build_ota_package := true
4259  ifeq ($(TARGET_SKIP_OTA_PACKAGE),true)
4260    build_ota_package := false
4261  endif
4262  ifneq (,$(filter address, $(SANITIZE_TARGET)))
4263    build_ota_package := false
4264  endif
4265  ifeq ($(TARGET_PRODUCT),sdk)
4266    build_ota_package := false
4267  endif
4268  # A target without a kernel may be one of the following:
4269  # - A generic target. In this case, the OTA package usually isn't built.
4270  #   PRODUCT_BUILD_GENERIC_OTA_PACKAGE may be set to true to force OTA package
4271  #   generation.
4272  # - A real device target, with TARGET_NO_KERNEL set to true and
4273  #   BOARD_PREBUILT_BOOTIMAGE set. In this case, it is valid to generate
4274  #   an OTA package.
4275  ifneq ($(PRODUCT_BUILD_GENERIC_OTA_PACKAGE),true)
4276    ifneq ($(filter generic%,$(TARGET_DEVICE)),)
4277      build_ota_package := false
4278    endif
4279    ifeq ($(INSTALLED_BOOTIMAGE_TARGET),)
4280      ifeq ($(TARGET_NO_KERNEL),true)
4281        build_ota_package := false
4282      endif
4283    endif # INSTALLED_BOOTIMAGE_TARGET == ""
4284    ifeq ($(recovery_fstab),)
4285      build_ota_package := false
4286    endif
4287  endif # PRODUCT_BUILD_GENERIC_OTA_PACKAGE
4288
4289  # Set build_otatools_package, and allow opt-out below.
4290  build_otatools_package := true
4291  ifeq ($(TARGET_SKIP_OTATOOLS_PACKAGE),true)
4292    build_otatools_package := false
4293  endif
4294endif
4295
4296ifeq ($(build_otatools_package),true)
4297
4298INTERNAL_OTATOOLS_MODULES := \
4299  aapt2 \
4300  add_img_to_target_files \
4301  aftltool \
4302  apksigner \
4303  append2simg \
4304  avbtool \
4305  blk_alloc_to_base_fs \
4306  boot_signer \
4307  brillo_update_payload \
4308  brotli \
4309  bsdiff \
4310  build_image \
4311  build_super_image \
4312  build_verity_metadata \
4313  build_verity_tree \
4314  care_map_generator \
4315  check_ota_package_signature \
4316  check_target_files_signatures \
4317  check_target_files_vintf \
4318  checkvintf \
4319  delta_generator \
4320  e2fsck \
4321  e2fsdroid \
4322  fc_sort \
4323  fec \
4324  fsck.f2fs \
4325  fs_config \
4326  generate_verity_key \
4327  host_init_verifier \
4328  img2simg \
4329  img_from_target_files \
4330  imgdiff \
4331  libconscrypt_openjdk_jni \
4332  lpmake \
4333  lpunpack \
4334  lz4 \
4335  make_f2fs \
4336  make_f2fs_casefold \
4337  merge_target_files \
4338  minigzip \
4339  mk_combined_img \
4340  mkbootfs \
4341  mkbootimg \
4342  mke2fs \
4343  mke2fs.conf \
4344  mkfs.erofs \
4345  mkerofsimage.sh \
4346  mkf2fsuserimg.sh \
4347  mksquashfs \
4348  mksquashfsimage.sh \
4349  mkuserimg_mke2fs \
4350  ota_from_target_files \
4351  repack_bootimg \
4352  secilc \
4353  sefcontext_compile \
4354  sgdisk \
4355  shflags \
4356  sign_apex \
4357  sign_target_files_apks \
4358  signapk \
4359  simg2img \
4360  sload_f2fs \
4361  toybox \
4362  tune2fs \
4363  unpack_bootimg \
4364  update_host_simulator \
4365  validate_target_files \
4366  verity_signer \
4367  verity_verifier \
4368  zipalign \
4369
4370# Additional tools to unpack and repack the apex file.
4371INTERNAL_OTATOOLS_MODULES += \
4372  apexer \
4373  apex_compression_tool \
4374  deapexer \
4375  debugfs_static \
4376  merge_zips \
4377  resize2fs \
4378  soong_zip \
4379
4380ifeq (true,$(PRODUCT_SUPPORTS_VBOOT))
4381INTERNAL_OTATOOLS_MODULES += \
4382  futility \
4383  vboot_signer
4384endif
4385
4386INTERNAL_OTATOOLS_FILES := \
4387  $(filter $(HOST_OUT)/%,$(call module-installed-files,$(INTERNAL_OTATOOLS_MODULES)))
4388
4389.PHONY: otatools
4390otatools: $(INTERNAL_OTATOOLS_FILES)
4391
4392# For each module, recursively resolve its host shared library dependencies. Then we have a full
4393# list of modules whose installed files need to be packed.
4394INTERNAL_OTATOOLS_MODULES_WITH_DEPS := \
4395  $(sort $(INTERNAL_OTATOOLS_MODULES) \
4396      $(foreach m,$(INTERNAL_OTATOOLS_MODULES),$(call get-all-shared-libs-deps,$(m))))
4397
4398INTERNAL_OTATOOLS_PACKAGE_FILES := \
4399  $(filter $(HOST_OUT)/%,$(call module-installed-files,$(INTERNAL_OTATOOLS_MODULES_WITH_DEPS)))
4400
4401INTERNAL_OTATOOLS_PACKAGE_FILES += \
4402  $(sort $(shell find build/make/target/product/security -type f -name "*.x509.pem" -o \
4403      -name "*.pk8" -o -name verity_key))
4404
4405ifneq (,$(wildcard device))
4406INTERNAL_OTATOOLS_PACKAGE_FILES += \
4407  $(sort $(shell find device $(wildcard vendor) -type f -name "*.pk8" -o -name "verifiedboot*" -o \
4408      -name "*.pem" -o -name "oem*.prop" -o -name "*.avbpubkey"))
4409endif
4410ifneq (,$(wildcard external/avb))
4411INTERNAL_OTATOOLS_PACKAGE_FILES += \
4412  $(sort $(shell find external/avb/test/data -type f -name "testkey_*.pem" -o \
4413      -name "atx_metadata.bin"))
4414endif
4415ifeq (true,$(PRODUCT_SUPPORTS_VBOOT))
4416INTERNAL_OTATOOLS_PACKAGE_FILES += \
4417  $(sort $(shell find external/vboot_reference/tests/devkeys -type f))
4418endif
4419
4420INTERNAL_OTATOOLS_RELEASETOOLS := \
4421  $(sort $(shell find build/make/tools/releasetools -name "*.pyc" -prune -o \
4422      \( -type f -o -type l \) -print))
4423
4424BUILT_OTATOOLS_PACKAGE := $(PRODUCT_OUT)/otatools.zip
4425$(BUILT_OTATOOLS_PACKAGE): PRIVATE_ZIP_ROOT := $(call intermediates-dir-for,PACKAGING,otatools)/otatools
4426$(BUILT_OTATOOLS_PACKAGE): PRIVATE_OTATOOLS_PACKAGE_FILES := $(INTERNAL_OTATOOLS_PACKAGE_FILES)
4427$(BUILT_OTATOOLS_PACKAGE): PRIVATE_OTATOOLS_RELEASETOOLS := $(INTERNAL_OTATOOLS_RELEASETOOLS)
4428$(BUILT_OTATOOLS_PACKAGE): $(INTERNAL_OTATOOLS_PACKAGE_FILES) $(INTERNAL_OTATOOLS_RELEASETOOLS)
4429$(BUILT_OTATOOLS_PACKAGE): $(SOONG_ZIP) $(ZIP2ZIP)
4430	@echo "Package OTA tools: $@"
4431	rm -rf $@ $(PRIVATE_ZIP_ROOT)
4432	mkdir -p $(dir $@)
4433	$(call copy-files-with-structure,$(PRIVATE_OTATOOLS_PACKAGE_FILES),$(HOST_OUT)/,$(PRIVATE_ZIP_ROOT))
4434	$(call copy-files-with-structure,$(PRIVATE_OTATOOLS_RELEASETOOLS),build/make/tools/,$(PRIVATE_ZIP_ROOT))
4435	cp $(SOONG_ZIP) $(ZIP2ZIP) $(MERGE_ZIPS) $(PRIVATE_ZIP_ROOT)/bin/
4436	$(SOONG_ZIP) -o $@ -C $(PRIVATE_ZIP_ROOT) -D $(PRIVATE_ZIP_ROOT)
4437
4438.PHONY: otatools-package
4439otatools-package: $(BUILT_OTATOOLS_PACKAGE)
4440
4441endif # build_otatools_package
4442
4443# -----------------------------------------------------------------
4444#  misc_info.txt
4445
4446INSTALLED_MISC_INFO_TARGET := $(PRODUCT_OUT)/misc_info.txt
4447
4448ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
4449# default to common dir for device vendor
4450tool_extensions := $(TARGET_DEVICE_DIR)/../common
4451else
4452tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
4453endif
4454.KATI_READONLY := tool_extensions
4455
4456# $1: boot image file name
4457define misc_boot_size
4458$(subst .img,_size,$(1))=$(BOARD_KERNEL$(call to-upper,$(subst boot,,$(subst .img,,$(1))))_BOOTIMAGE_PARTITION_SIZE)
4459endef
4460
4461$(INSTALLED_MISC_INFO_TARGET):
4462	rm -f $@
4463	$(call pretty,"Target misc_info.txt: $@")
4464	$(hide) echo "recovery_api_version=$(RECOVERY_API_VERSION)" >> $@
4465	$(hide) echo "fstab_version=$(RECOVERY_FSTAB_VERSION)" >> $@
4466ifdef BOARD_FLASH_BLOCK_SIZE
4467	$(hide) echo "blocksize=$(BOARD_FLASH_BLOCK_SIZE)" >> $@
4468endif
4469ifneq ($(strip $(BOARD_BOOTIMAGE_PARTITION_SIZE))$(strip $(BOARD_KERNEL_BINARIES)),)
4470	$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),\
4471		echo "$(call misc_boot_size,$(notdir $(b)))" >> $@;)
4472endif
4473ifeq ($(INSTALLED_BOOTIMAGE_TARGET),)
4474	$(hide) echo "no_boot=true" >> $@
4475else
4476	echo "boot_images=$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(notdir $(b)))" >> $@
4477endif
4478ifeq ($(BOARD_RAMDISK_USE_LZ4),true)
4479	echo "lz4_ramdisks=true" >> $@
4480endif
4481ifneq ($(INSTALLED_VENDOR_BOOTIMAGE_TARGET),)
4482	echo "vendor_boot=true" >> $@
4483	echo "vendor_boot_size=$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE)" >> $@
4484endif
4485ifeq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
4486	$(hide) echo "no_recovery=true" >> $@
4487endif
4488ifdef BOARD_INCLUDE_RECOVERY_DTBO
4489	$(hide) echo "include_recovery_dtbo=true" >> $@
4490endif
4491ifdef BOARD_INCLUDE_RECOVERY_ACPIO
4492	$(hide) echo "include_recovery_acpio=true" >> $@
4493endif
4494ifdef BOARD_RECOVERYIMAGE_PARTITION_SIZE
4495	$(hide) echo "recovery_size=$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)" >> $@
4496endif
4497ifdef TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS
4498	@# TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS can be empty to indicate that nothing but defaults should be used.
4499	$(hide) echo "recovery_mount_options=$(TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $@
4500else
4501	$(hide) echo "recovery_mount_options=$(DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $@
4502endif
4503	$(hide) echo "tool_extensions=$(tool_extensions)" >> $@
4504	$(hide) echo "default_system_dev_certificate=$(DEFAULT_SYSTEM_DEV_CERTIFICATE)" >> $@
4505ifdef PRODUCT_EXTRA_RECOVERY_KEYS
4506	$(hide) echo "extra_recovery_keys=$(PRODUCT_EXTRA_RECOVERY_KEYS)" >> $@
4507endif
4508	$(hide) echo 'mkbootimg_args=$(BOARD_MKBOOTIMG_ARGS)' >> $@
4509	$(hide) echo 'recovery_mkbootimg_args=$(BOARD_RECOVERY_MKBOOTIMG_ARGS)' >> $@
4510	$(hide) echo 'mkbootimg_version_args=$(INTERNAL_MKBOOTIMG_VERSION_ARGS)' >> $@
4511ifdef BOARD_GKI_SIGNING_KEY_PATH
4512	$(hide) echo 'gki_signing_key_path=$(BOARD_GKI_SIGNING_KEY_PATH)' >> $@
4513	$(hide) echo 'gki_signing_algorithm=$(BOARD_GKI_SIGNING_ALGORITHM)' >> $@
4514endif
4515ifdef BOARD_GKI_SIGNING_SIGNATURE_ARGS
4516	$(hide) echo 'gki_signing_signature_args=$(BOARD_GKI_SIGNING_SIGNATURE_ARGS)' >> $@
4517endif
4518	$(hide) echo "multistage_support=1" >> $@
4519	$(hide) echo "blockimgdiff_versions=3,4" >> $@
4520ifeq ($(PRODUCT_BUILD_GENERIC_OTA_PACKAGE),true)
4521	$(hide) echo "build_generic_ota_package=true" >> $@
4522endif
4523ifneq ($(OEM_THUMBPRINT_PROPERTIES),)
4524	# OTA scripts are only interested in fingerprint related properties
4525	$(hide) echo "oem_fingerprint_properties=$(OEM_THUMBPRINT_PROPERTIES)" >> $@
4526endif
4527ifneq (,$(filter address, $(SANITIZE_TARGET)))
4528	# We need to create userdata.img with real data because the instrumented libraries are in userdata.img.
4529	$(hide) echo "userdata_img_with_data=true" >> $@
4530endif
4531ifeq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
4532	$(hide) echo "full_recovery_image=true" >> $@
4533endif
4534ifdef BOARD_USES_VENDORIMAGE
4535	$(hide) echo "board_uses_vendorimage=true" >> $@
4536endif
4537ifeq ($(BOARD_AVB_ENABLE),true)
4538ifeq ($(BUILDING_VBMETA_IMAGE),true)
4539	$(hide) echo "avb_building_vbmeta_image=true" >> $@
4540endif # BUILDING_VBMETA_IMAGE
4541	$(hide) echo "avb_enable=true" >> $@
4542	$(hide) echo "avb_vbmeta_key_path=$(BOARD_AVB_KEY_PATH)" >> $@
4543	$(hide) echo "avb_vbmeta_algorithm=$(BOARD_AVB_ALGORITHM)" >> $@
4544	$(hide) echo "avb_vbmeta_args=$(BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS)" >> $@
4545	$(hide) echo "avb_boot_add_hash_footer_args=$(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)" >> $@
4546ifdef BOARD_AVB_BOOT_KEY_PATH
4547	$(hide) echo "avb_boot_key_path=$(BOARD_AVB_BOOT_KEY_PATH)" >> $@
4548	$(hide) echo "avb_boot_algorithm=$(BOARD_AVB_BOOT_ALGORITHM)" >> $@
4549	$(hide) echo "avb_boot_rollback_index_location=$(BOARD_AVB_BOOT_ROLLBACK_INDEX_LOCATION)" >> $@
4550endif # BOARD_AVB_BOOT_KEY_PATH
4551	echo "avb_vendor_boot_add_hash_footer_args=$(BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS)" >> $@
4552ifdef BOARD_AVB_VENDOR_BOOT_KEY_PATH
4553	echo "avb_vendor_boot_key_path=$(BOARD_AVB_VENDOR_BOOT_KEY_PATH)" >> $@
4554	echo "avb_vendor_boot_algorithm=$(BOARD_AVB_VENDOR_BOOT_ALGORITHM)" >> $@
4555	echo "avb_vendor_boot_rollback_index_location=$(BOARD_AVB_VENDOR_BOOT_ROLLBACK_INDEX_LOCATION)" >> $@
4556endif # BOARD_AVB_VENDOR_BOOT_KEY_PATH
4557	$(hide) echo "avb_recovery_add_hash_footer_args=$(BOARD_AVB_RECOVERY_ADD_HASH_FOOTER_ARGS)" >> $@
4558ifdef BOARD_AVB_RECOVERY_KEY_PATH
4559	$(hide) echo "avb_recovery_key_path=$(BOARD_AVB_RECOVERY_KEY_PATH)" >> $@
4560	$(hide) echo "avb_recovery_algorithm=$(BOARD_AVB_RECOVERY_ALGORITHM)" >> $@
4561	$(hide) echo "avb_recovery_rollback_index_location=$(BOARD_AVB_RECOVERY_ROLLBACK_INDEX_LOCATION)" >> $@
4562endif # BOARD_AVB_RECOVERY_KEY_PATH
4563ifneq (,$(strip $(BOARD_CUSTOMIMAGES_PARTITION_LIST)))
4564	$(hide) echo "avb_custom_images_partition_list=$(BOARD_CUSTOMIMAGES_PARTITION_LIST)" >> $@
4565	$(hide) $(foreach partition,$(BOARD_CUSTOMIMAGES_PARTITION_LIST), \
4566	    echo "avb_$(partition)_key_path=$(BOARD_AVB_$(call to-upper,$(partition))_KEY_PATH)"  >> $@; \
4567	    echo "avb_$(partition)_algorithm=$(BOARD_AVB_$(call to-upper,$(partition))_ALGORITHM)"  >> $@; \
4568	    echo "avb_$(partition)_add_hashtree_footer_args=$(BOARD_AVB_$(call to-upper,$(partition))_ADD_HASHTREE_FOOTER_ARGS)"  >> $@; \
4569	    echo "avb_$(partition)_rollback_index_location=$(BOARD_AVB_$(call to-upper,$(partition))_ROLLBACK_INDEX_LOCATION)"  >> $@; \
4570	    echo "avb_$(partition)_partition_size=$(BOARD_AVB_$(call to-upper,$(partition))_PARTITION_SIZE)"  >> $@; \
4571	    echo "avb_$(partition)_image_list=$(foreach image,$(BOARD_AVB_$(call to-upper,$(partition))_IMAGE_LIST),$(notdir $(image)))" >> $@;)
4572endif # BOARD_CUSTOMIMAGES_PARTITION_LIST
4573ifneq (,$(strip $(BOARD_AVB_VBMETA_SYSTEM)))
4574	$(hide) echo "avb_vbmeta_system=$(BOARD_AVB_VBMETA_SYSTEM)" >> $@
4575	$(hide) echo "avb_vbmeta_system_args=$(BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS)" >> $@
4576	$(hide) echo "avb_vbmeta_system_key_path=$(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH)" >> $@
4577	$(hide) echo "avb_vbmeta_system_algorithm=$(BOARD_AVB_VBMETA_SYSTEM_ALGORITHM)" >> $@
4578	$(hide) echo "avb_vbmeta_system_rollback_index_location=$(BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX_LOCATION)" >> $@
4579endif # BOARD_AVB_VBMETA_SYSTEM
4580ifneq (,$(strip $(BOARD_AVB_VBMETA_VENDOR)))
4581	$(hide) echo "avb_vbmeta_vendor=$(BOARD_AVB_VBMETA_VENDOR)" >> $@
4582	$(hide) echo "avb_vbmeta_vendor_args=$(BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS)" >> $@
4583	$(hide) echo "avb_vbmeta_vendor_key_path=$(BOARD_AVB_VBMETA_VENDOR_KEY_PATH)" >> $@
4584	$(hide) echo "avb_vbmeta_vendor_algorithm=$(BOARD_AVB_VBMETA_VENDOR_ALGORITHM)" >> $@
4585	$(hide) echo "avb_vbmeta_vendor_rollback_index_location=$(BOARD_AVB_VBMETA_VENDOR_ROLLBACK_INDEX_LOCATION)" >> $@
4586endif # BOARD_AVB_VBMETA_VENDOR_KEY_PATH
4587endif # BOARD_AVB_ENABLE
4588ifdef BOARD_BPT_INPUT_FILES
4589	$(hide) echo "board_bpt_enable=true" >> $@
4590	$(hide) echo "board_bpt_make_table_args=$(BOARD_BPT_MAKE_TABLE_ARGS)" >> $@
4591	$(hide) echo "board_bpt_input_files=$(BOARD_BPT_INPUT_FILES)" >> $@
4592endif
4593ifdef BOARD_BPT_DISK_SIZE
4594	$(hide) echo "board_bpt_disk_size=$(BOARD_BPT_DISK_SIZE)" >> $@
4595endif
4596	$(call generate-userimage-prop-dictionary, $@)
4597ifeq ($(AB_OTA_UPDATER),true)
4598	@# Include the build type in META/misc_info.txt so the server can easily differentiate production builds.
4599	$(hide) echo "build_type=$(TARGET_BUILD_VARIANT)" >> $@
4600	$(hide) echo "ab_update=true" >> $@
4601endif
4602ifeq ($(TARGET_OTA_ALLOW_NON_AB),true)
4603	$(hide) echo "allow_non_ab=true" >> $@
4604endif
4605ifdef BOARD_PREBUILT_DTBOIMAGE
4606	$(hide) echo "has_dtbo=true" >> $@
4607ifeq ($(BOARD_AVB_ENABLE),true)
4608	$(hide) echo "dtbo_size=$(BOARD_DTBOIMG_PARTITION_SIZE)" >> $@
4609	$(hide) echo "avb_dtbo_add_hash_footer_args=$(BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS)" >> $@
4610ifdef BOARD_AVB_DTBO_KEY_PATH
4611	$(hide) echo "avb_dtbo_key_path=$(BOARD_AVB_DTBO_KEY_PATH)" >> $@
4612	$(hide) echo "avb_dtbo_algorithm=$(BOARD_AVB_DTBO_ALGORITHM)" >> $@
4613	$(hide) echo "avb_dtbo_rollback_index_location=$(BOARD_AVB_DTBO_ROLLBACK_INDEX_LOCATION)" >> $@
4614endif # BOARD_AVB_DTBO_KEY_PATH
4615endif # BOARD_AVB_ENABLE
4616endif # BOARD_PREBUILT_DTBOIMAGE
4617ifdef BOARD_PREBUILT_PVMFWIMAGE
4618	$(hide) echo "has_pvmfw=true" >> $@
4619ifeq ($(BOARD_AVB_ENABLE),true)
4620	$(hide) echo "pvmfw_size=$(BOARD_PVMFWIMG_PARTITION_SIZE)" >> $@
4621	$(hide) echo "avb_pvmfw_add_hash_footer_args=$(BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS)" >> $@
4622ifdef BOARD_AVB_PVMFW_KEY_PATH
4623	$(hide) echo "avb_pvmfw_key_path=$(BOARD_AVB_PVMFW_KEY_PATH)" >> $@
4624	$(hide) echo "avb_pvmfw_algorithm=$(BOARD_AVB_PVMFW_ALGORITHM)" >> $@
4625	$(hide) echo "avb_pvmfw_rollback_index_location=$(BOARD_AVB_PVMFW_ROLLBACK_INDEX_LOCATION)" >> $@
4626endif # BOARD_AVB_PVMFW_KEY_PATH
4627endif # BOARD_AVB_ENABLE
4628endif # BOARD_PREBUILT_PVMFWIMAGE
4629	$(call dump-dynamic-partitions-info,$@)
4630	@# VINTF checks
4631ifeq ($(PRODUCT_ENFORCE_VINTF_MANIFEST),true)
4632	$(hide) echo "vintf_enforce=true" >> $@
4633endif
4634ifdef ODM_MANIFEST_SKUS
4635	$(hide) echo "vintf_odm_manifest_skus=$(ODM_MANIFEST_SKUS)" >> $@
4636endif
4637ifdef ODM_MANIFEST_FILES
4638	$(hide) echo "vintf_include_empty_odm_sku=true" >> $@
4639endif
4640ifdef DEVICE_MANIFEST_SKUS
4641	$(hide) echo "vintf_vendor_manifest_skus=$(DEVICE_MANIFEST_SKUS)" >> $@
4642endif
4643ifdef DEVICE_MANIFEST_FILE
4644	$(hide) echo "vintf_include_empty_vendor_sku=true" >> $@
4645endif
4646ifeq ($(BOARD_BOOTLOADER_IN_UPDATE_PACKAGE),true)
4647	$(hide) echo "bootloader_in_update_package=true" >> $@
4648endif
4649ifeq ($(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE),true)
4650	$(hide) echo "exclude_kernel_from_recovery_image=true" >> $@
4651endif
4652ifneq ($(BOARD_PARTIAL_OTA_UPDATE_PARTITIONS_LIST),)
4653	$(hide) echo "partial_ota_update_partitions_list=$(BOARD_PARTIAL_OTA_UPDATE_PARTITIONS_LIST)" >> $@
4654endif
4655
4656.PHONY: misc_info
4657misc_info: $(INSTALLED_MISC_INFO_TARGET)
4658
4659droidcore-unbundled: $(INSTALLED_MISC_INFO_TARGET)
4660
4661# -----------------------------------------------------------------
4662# A zip of the directories that map to the target filesystem.
4663# This zip can be used to create an OTA package or filesystem image
4664# as a post-build step.
4665#
4666name := $(TARGET_PRODUCT)
4667ifeq ($(TARGET_BUILD_TYPE),debug)
4668  name := $(name)_debug
4669endif
4670name := $(name)-target_files-$(FILE_NAME_TAG)
4671
4672intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
4673BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
4674$(BUILT_TARGET_FILES_PACKAGE): intermediates := $(intermediates)
4675$(BUILT_TARGET_FILES_PACKAGE): \
4676	    zip_root := $(intermediates)/$(name)
4677
4678# $(1): Directory to copy
4679# $(2): Location to copy it to
4680# The "ls -A" is to prevent "acp s/* d" from failing if s is empty.
4681define package_files-copy-root
4682  if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
4683    mkdir -p $(2) && \
4684    $(ACP) -rd $(strip $(1))/* $(2); \
4685  fi
4686endef
4687
4688built_ota_tools :=
4689
4690# We can't build static executables when SANITIZE_TARGET=address
4691ifeq (,$(filter address, $(SANITIZE_TARGET)))
4692built_ota_tools += \
4693    $(call intermediates-dir-for,EXECUTABLES,updater)/updater
4694endif
4695
4696$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_OTA_TOOLS := $(built_ota_tools)
4697
4698tool_extension := $(wildcard $(tool_extensions)/releasetools.py)
4699$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_TOOL_EXTENSION := $(tool_extension)
4700
4701ifeq ($(AB_OTA_UPDATER),true)
4702updater_dep := system/update_engine/update_engine.conf
4703endif
4704
4705# Build OTA tools if non-A/B is allowed
4706ifeq ($(TARGET_OTA_ALLOW_NON_AB),true)
4707updater_dep := $(built_ota_tools)
4708endif
4709
4710$(BUILT_TARGET_FILES_PACKAGE): $(updater_dep)
4711
4712# If we are using recovery as boot, output recovery files to BOOT/.
4713# If we are moving recovery resources to vendor_boot, output recovery files to VENDOR_BOOT/.
4714ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
4715$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := BOOT
4716else ifeq ($(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT),true)
4717$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := VENDOR_BOOT
4718else
4719$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_OUT := RECOVERY
4720endif
4721
4722ifeq ($(AB_OTA_UPDATER),true)
4723  ifdef OSRELEASED_DIRECTORY
4724    $(BUILT_TARGET_FILES_PACKAGE): $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_id
4725    $(BUILT_TARGET_FILES_PACKAGE): $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_version
4726    $(BUILT_TARGET_FILES_PACKAGE): $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/system_version
4727  endif
4728
4729  # Not checking in board_config.mk, since AB_OTA_PARTITIONS may be updated in Android.mk (e.g. to
4730  # additionally include radio or bootloader partitions).
4731  ifeq ($(AB_OTA_PARTITIONS),)
4732    $(error AB_OTA_PARTITIONS must be defined when using AB_OTA_UPDATER)
4733  endif
4734endif
4735
4736ifneq ($(AB_OTA_PARTITIONS),)
4737  ifneq ($(AB_OTA_UPDATER),true)
4738    $(error AB_OTA_UPDATER must be true when defining AB_OTA_PARTITIONS)
4739  endif
4740endif
4741
4742# Run fs_config while creating the target files package
4743# $1: root directory
4744# $2: add prefix
4745define fs_config
4746(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)"
4747endef
4748
4749define filter-out-missing-vendor
4750$(if $(INSTALLED_VENDORIMAGE_TARGET),$(1),$(filter-out vendor,$(1)))
4751endef
4752define filter-out-missing-vendor_dlkm
4753$(if $(INSTALLED_VENDOR_DLKMIMAGE_TARGET),$(1),$(filter-out vendor_dlkm,$(1)))
4754endef
4755define filter-out-missing-odm
4756$(if $(INSTALLED_ODMIMAGE_TARGET),$(1),$(filter-out odm,$(1)))
4757endef
4758define filter-out-missing-odm_dlkm
4759$(if $(INSTALLED_ODM_DLKMIMAGE_TARGET),$(1),$(filter-out odm_dlkm,$(1)))
4760endef
4761# Filter out vendor,vendor_dlkm,odm,odm_dlkm from the list for AOSP targets.
4762# $(1): list
4763define filter-out-missing-partitions
4764$(call filter-out-missing-vendor,\
4765  $(call filter-out-missing-vendor_dlkm,\
4766    $(call filter-out-missing-odm,\
4767      $(call filter-out-missing-odm_dlkm,$(1)))))
4768endef
4769
4770# Information related to dynamic partitions and virtual A/B. This information
4771# is needed for building the super image (see dump-super-image-info) and
4772# building OTA packages.
4773# $(1): file
4774define dump-dynamic-partitions-info
4775  $(if $(filter true,$(PRODUCT_USE_DYNAMIC_PARTITIONS)), \
4776    echo "use_dynamic_partitions=true" >> $(1))
4777  $(if $(filter true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)), \
4778    echo "dynamic_partition_retrofit=true" >> $(1))
4779  echo "lpmake=$(notdir $(LPMAKE))" >> $(1)
4780  $(if $(filter true,$(PRODUCT_BUILD_SUPER_PARTITION)), $(if $(BOARD_SUPER_PARTITION_SIZE), \
4781    echo "build_super_partition=true" >> $(1)))
4782  $(if $(BUILDING_SUPER_EMPTY_IMAGE), \
4783    echo "build_super_empty_partition=true" >> $(1))
4784  $(if $(filter true,$(BOARD_BUILD_RETROFIT_DYNAMIC_PARTITIONS_OTA_PACKAGE)), \
4785    echo "build_retrofit_dynamic_partitions_ota_package=true" >> $(1))
4786  echo "super_metadata_device=$(BOARD_SUPER_PARTITION_METADATA_DEVICE)" >> $(1)
4787  $(if $(BOARD_SUPER_PARTITION_BLOCK_DEVICES), \
4788    echo "super_block_devices=$(BOARD_SUPER_PARTITION_BLOCK_DEVICES)" >> $(1))
4789  $(foreach device,$(BOARD_SUPER_PARTITION_BLOCK_DEVICES), \
4790    echo "super_$(device)_device_size=$(BOARD_SUPER_PARTITION_$(call to-upper,$(device))_DEVICE_SIZE)" >> $(1);)
4791  $(if $(BOARD_SUPER_PARTITION_PARTITION_LIST), \
4792    echo "dynamic_partition_list=$(call filter-out-missing-partitions,$(BOARD_SUPER_PARTITION_PARTITION_LIST))" >> $(1))
4793  $(if $(BOARD_SUPER_PARTITION_GROUPS),
4794    echo "super_partition_groups=$(BOARD_SUPER_PARTITION_GROUPS)" >> $(1))
4795  $(foreach group,$(BOARD_SUPER_PARTITION_GROUPS), \
4796    echo "super_$(group)_group_size=$(BOARD_$(call to-upper,$(group))_SIZE)" >> $(1); \
4797    $(if $(BOARD_$(call to-upper,$(group))_PARTITION_LIST), \
4798      echo "super_$(group)_partition_list=$(call filter-out-missing-partitions,$(BOARD_$(call to-upper,$(group))_PARTITION_LIST))" >> $(1);))
4799  $(if $(filter true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED)), \
4800    echo "build_non_sparse_super_partition=true" >> $(1))
4801  $(if $(filter true,$(TARGET_USERIMAGES_SPARSE_F2FS_DISABLED)), \
4802    echo "build_non_sparse_super_partition=true" >> $(1))
4803  $(if $(filter true,$(BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE)), \
4804    echo "super_image_in_update_package=true" >> $(1))
4805  $(if $(BOARD_SUPER_PARTITION_SIZE), \
4806    echo "super_partition_size=$(BOARD_SUPER_PARTITION_SIZE)" >> $(1))
4807  $(if $(BOARD_SUPER_PARTITION_ALIGNMENT), \
4808    echo "super_partition_alignment=$(BOARD_SUPER_PARTITION_ALIGNMENT)" >> $(1))
4809  $(if $(BOARD_SUPER_PARTITION_WARN_LIMIT), \
4810    echo "super_partition_warn_limit=$(BOARD_SUPER_PARTITION_WARN_LIMIT)" >> $(1))
4811  $(if $(BOARD_SUPER_PARTITION_ERROR_LIMIT), \
4812    echo "super_partition_error_limit=$(BOARD_SUPER_PARTITION_ERROR_LIMIT)" >> $(1))
4813  $(if $(filter true,$(PRODUCT_VIRTUAL_AB_OTA)), \
4814    echo "virtual_ab=true" >> $(1))
4815  $(if $(filter true,$(PRODUCT_VIRTUAL_AB_COMPRESSION)), \
4816    echo "virtual_ab_compression=true" >> $(1))
4817  $(if $(filter true,$(PRODUCT_VIRTUAL_AB_OTA_RETROFIT)), \
4818    echo "virtual_ab_retrofit=true" >> $(1))
4819endef
4820
4821# By conditionally including the dependency of the target files package on the
4822# full system image deps, we speed up builds that do not build the system
4823# image.
4824ifdef BUILDING_SYSTEM_IMAGE
4825  $(BUILT_TARGET_FILES_PACKAGE): $(FULL_SYSTEMIMAGE_DEPS)
4826endif
4827
4828ifdef BUILDING_USERDATA_IMAGE
4829  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_USERDATAIMAGE_FILES)
4830endif
4831
4832ifdef BUILDING_SYSTEM_OTHER_IMAGE
4833  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_SYSTEMOTHERIMAGE_FILES)
4834endif
4835
4836ifdef BUILDING_VENDOR_BOOT_IMAGE
4837  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_VENDOR_RAMDISK_FILES)
4838  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS)
4839  # The vendor ramdisk may be built from the recovery ramdisk.
4840  ifeq (true,$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT))
4841    $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
4842  endif
4843endif
4844
4845ifdef BUILDING_RECOVERY_IMAGE
4846  # TODO(b/30414428): Can't depend on INTERNAL_RECOVERYIMAGE_FILES alone like other
4847  # BUILT_TARGET_FILES_PACKAGE dependencies because currently there're cp/rsync/rm
4848  # commands in build-recoveryimage-target, which would touch the files under
4849  # TARGET_RECOVERY_OUT and race with packaging target-files.zip.
4850  ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
4851    $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_BOOTIMAGE_TARGET)
4852  else
4853    $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_RECOVERYIMAGE_TARGET)
4854  endif
4855  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_RECOVERYIMAGE_FILES)
4856endif
4857
4858# Conditionally depend on the image files if the image is being built so the
4859# target-files.zip rule doesn't wait on the image creation rule, or the image
4860# if it is coming from a prebuilt.
4861
4862ifdef BUILDING_VENDOR_IMAGE
4863  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_VENDORIMAGE_FILES)
4864else ifdef BOARD_PREBUILT_VENDORIMAGE
4865  $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_VENDORIMAGE_TARGET)
4866endif
4867
4868ifdef BUILDING_PRODUCT_IMAGE
4869  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_PRODUCTIMAGE_FILES)
4870else ifdef BOARD_PREBUILT_PRODUCTIMAGE
4871  $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_PRODUCTIMAGE_TARGET)
4872endif
4873
4874ifdef BUILDING_SYSTEM_EXT_IMAGE
4875  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_SYSTEM_EXTIMAGE_FILES)
4876else ifdef BOARD_PREBUILT_SYSTEM_EXTIMAGE
4877  $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_SYSTEM_EXTIMAGE_TARGET)
4878endif
4879
4880ifdef BUILDING_BOOT_IMAGE
4881  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_RAMDISK_FILES)
4882endif
4883ifneq (,$(INTERNAL_PREBUILT_BOOTIMAGE) $(filter true,$(BOARD_COPY_BOOT_IMAGE_TO_TARGET_FILES)))
4884  $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_BOOTIMAGE_TARGET)
4885endif
4886
4887ifdef BUILDING_ODM_IMAGE
4888  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_ODMIMAGE_FILES)
4889else ifdef BOARD_PREBUILT_ODMIMAGE
4890  $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_ODMIMAGE_TARGET)
4891endif
4892
4893ifdef BUILDING_VENDOR_DLKM_IMAGE
4894  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_VENDOR_DLKMIMAGE_FILES)
4895else ifdef BOARD_PREBUILT_VENDOR_DLKMIMAGE
4896  $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_VENDOR_DLKMIMAGE_TARGET)
4897endif
4898
4899ifdef BUILDING_ODM_DLKM_IMAGE
4900  $(BUILT_TARGET_FILES_PACKAGE): $(INTERNAL_ODM_DLKMIMAGE_FILES)
4901else ifdef BOARD_PREBUILT_ODM_DLKMIMAGE
4902  $(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_ODM_DLKMIMAGE_TARGET)
4903endif
4904
4905ifeq ($(BUILD_QEMU_IMAGES),true)
4906  MK_VBMETA_BOOT_KERNEL_CMDLINE_SH := device/generic/goldfish/tools/mk_vbmeta_boot_params.sh
4907  $(BUILT_TARGET_FILES_PACKAGE): $(MK_VBMETA_BOOT_KERNEL_CMDLINE_SH)
4908endif
4909
4910ifdef BOARD_PREBUILT_BOOTLOADER
4911$(BUILT_TARGET_FILES_PACKAGE): $(INSTALLED_BOOTLOADER_MODULE)
4912droidcore-unbundled: $(INSTALLED_BOOTLOADER_MODULE)
4913endif
4914
4915# Depending on the various images guarantees that the underlying
4916# directories are up-to-date.
4917$(BUILT_TARGET_FILES_PACKAGE): \
4918	    $(INSTALLED_RADIOIMAGE_TARGET) \
4919	    $(INSTALLED_RECOVERYIMAGE_TARGET) \
4920	    $(INSTALLED_CACHEIMAGE_TARGET) \
4921	    $(INSTALLED_DTBOIMAGE_TARGET) \
4922	    $(INSTALLED_PVMFWIMAGE_TARGET) \
4923	    $(INSTALLED_CUSTOMIMAGES_TARGET) \
4924	    $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
4925	    $(INSTALLED_KERNEL_TARGET) \
4926	    $(INSTALLED_RAMDISK_TARGET) \
4927	    $(INSTALLED_DTBIMAGE_TARGET) \
4928	    $(INSTALLED_2NDBOOTLOADER_TARGET) \
4929	    $(BOARD_PREBUILT_DTBOIMAGE) \
4930	    $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE) \
4931	    $(BOARD_RECOVERY_ACPIO) \
4932	    $(PRODUCT_SYSTEM_BASE_FS_PATH) \
4933	    $(PRODUCT_VENDOR_BASE_FS_PATH) \
4934	    $(PRODUCT_PRODUCT_BASE_FS_PATH) \
4935	    $(PRODUCT_SYSTEM_EXT_BASE_FS_PATH) \
4936	    $(PRODUCT_ODM_BASE_FS_PATH) \
4937	    $(PRODUCT_VENDOR_DLKM_BASE_FS_PATH) \
4938	    $(PRODUCT_ODM_DLKM_BASE_FS_PATH) \
4939	    $(LPMAKE) \
4940	    $(SELINUX_FC) \
4941	    $(INSTALLED_MISC_INFO_TARGET) \
4942	    $(APKCERTS_FILE) \
4943	    $(SOONG_APEX_KEYS_FILE) \
4944	    $(SOONG_ZIP) \
4945	    $(HOST_OUT_EXECUTABLES)/fs_config \
4946	    $(ADD_IMG_TO_TARGET_FILES) \
4947	    $(MAKE_RECOVERY_PATCH) \
4948	    $(BUILT_KERNEL_CONFIGS_FILE) \
4949	    $(BUILT_KERNEL_VERSION_FILE) \
4950	    | $(ACP)
4951	@echo "Package target files: $@"
4952	$(hide) rm -rf $@ $@.list $(zip_root)
4953	$(hide) mkdir -p $(dir $@) $(zip_root)
4954ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT))$(filter true,$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT)))
4955	@# Components of the recovery image
4956	$(hide) mkdir -p $(zip_root)/$(PRIVATE_RECOVERY_OUT)
4957# Exclude recovery files in the default vendor ramdisk if including a standalone
4958# recovery ramdisk in vendor_boot.
4959ifneq (true,$(BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT))
4960	$(hide) $(call package_files-copy-root, \
4961	    $(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/$(PRIVATE_RECOVERY_OUT)/RAMDISK)
4962endif
4963ifdef INSTALLED_KERNEL_TARGET
4964ifneq (,$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)))
4965	cp $(INSTALLED_KERNEL_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/
4966else ifneq (true,$(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE))
4967	cp $(firstword $(INSTALLED_KERNEL_TARGET)) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/kernel
4968endif
4969endif
4970ifneq (truetrue,$(strip $(BUILDING_VENDOR_BOOT_IMAGE))$(strip $(BOARD_USES_RECOVERY_AS_BOOT)))
4971ifdef INSTALLED_2NDBOOTLOADER_TARGET
4972	cp $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/second
4973endif
4974ifdef BOARD_INCLUDE_RECOVERY_DTBO
4975ifdef BOARD_PREBUILT_RECOVERY_DTBOIMAGE
4976	cp $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/recovery_dtbo
4977else
4978	cp $(BOARD_PREBUILT_DTBOIMAGE) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/recovery_dtbo
4979endif
4980endif # BOARD_INCLUDE_RECOVERY_DTBO
4981ifdef BOARD_INCLUDE_RECOVERY_ACPIO
4982	cp $(BOARD_RECOVERY_ACPIO) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/recovery_acpio
4983endif
4984ifdef INSTALLED_DTBIMAGE_TARGET
4985	cp $(INSTALLED_DTBIMAGE_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/dtb
4986endif
4987ifneq (true,$(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE))
4988ifdef INTERNAL_KERNEL_CMDLINE
4989	echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/cmdline
4990endif # INTERNAL_KERNEL_CMDLINE != ""
4991endif # BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE != true
4992ifdef BOARD_KERNEL_BASE
4993	echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/base
4994endif
4995ifdef BOARD_KERNEL_PAGESIZE
4996	echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/pagesize
4997endif
4998endif # not (BUILDING_VENDOR_BOOT_IMAGE and BOARD_USES_RECOVERY_AS_BOOT)
4999endif # INSTALLED_RECOVERYIMAGE_TARGET defined or BOARD_USES_RECOVERY_AS_BOOT is true
5000	@# Components of the boot image
5001	$(hide) mkdir -p $(zip_root)/BOOT
5002	$(hide) mkdir -p $(zip_root)/ROOT
5003	$(hide) $(call package_files-copy-root, \
5004	    $(TARGET_ROOT_OUT),$(zip_root)/ROOT)
5005	@# If we are using recovery as boot, this is already done when processing recovery.
5006ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
5007ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
5008	$(hide) $(call package_files-copy-root, \
5009	    $(TARGET_RAMDISK_OUT),$(zip_root)/BOOT/RAMDISK)
5010endif
5011ifdef INSTALLED_KERNEL_TARGET
5012	$(hide) cp $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/
5013endif
5014ifeq (true,$(BOARD_USES_GENERIC_KERNEL_IMAGE))
5015	echo "$(GENERIC_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
5016else ifndef INSTALLED_VENDOR_BOOTIMAGE_TARGET # && BOARD_USES_GENERIC_KERNEL_IMAGE != true
5017	echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
5018ifdef INSTALLED_2NDBOOTLOADER_TARGET
5019	cp $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second
5020endif
5021ifdef INSTALLED_DTBIMAGE_TARGET
5022	cp $(INSTALLED_DTBIMAGE_TARGET) $(zip_root)/BOOT/dtb
5023endif
5024ifdef BOARD_KERNEL_BASE
5025	echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base
5026endif
5027ifdef BOARD_KERNEL_PAGESIZE
5028	echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesize
5029endif
5030endif # INSTALLED_VENDOR_BOOTIMAGE_TARGET == "" && BOARD_USES_GENERIC_KERNEL_IMAGE != true
5031endif # BOARD_USES_RECOVERY_AS_BOOT not true
5032	$(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\
5033	            mkdir -p $(zip_root)/RADIO; \
5034	            cp $(t) $(zip_root)/RADIO/$(notdir $(t));)
5035ifdef INSTALLED_VENDOR_BOOTIMAGE_TARGET
5036	mkdir -p $(zip_root)/VENDOR_BOOT
5037	$(call package_files-copy-root, \
5038	    $(TARGET_VENDOR_RAMDISK_OUT),$(zip_root)/VENDOR_BOOT/RAMDISK)
5039ifdef INSTALLED_DTBIMAGE_TARGET
5040	cp $(INSTALLED_DTBIMAGE_TARGET) $(zip_root)/VENDOR_BOOT/dtb
5041endif
5042ifdef INTERNAL_VENDOR_BOOTCONFIG_TARGET
5043	cp $(INTERNAL_VENDOR_BOOTCONFIG_TARGET) $(zip_root)/VENDOR_BOOT/vendor_bootconfig
5044endif
5045ifdef BOARD_KERNEL_BASE
5046	echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/VENDOR_BOOT/base
5047endif
5048ifdef BOARD_KERNEL_PAGESIZE
5049	echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/VENDOR_BOOT/pagesize
5050endif
5051	echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/VENDOR_BOOT/vendor_cmdline
5052ifdef INTERNAL_VENDOR_RAMDISK_FRAGMENTS
5053	echo "$(INTERNAL_VENDOR_RAMDISK_FRAGMENTS)" > "$(zip_root)/VENDOR_BOOT/vendor_ramdisk_fragments"
5054	$(foreach vendor_ramdisk_fragment,$(INTERNAL_VENDOR_RAMDISK_FRAGMENTS), \
5055	  mkdir -p $(zip_root)/VENDOR_BOOT/RAMDISK_FRAGMENTS/$(vendor_ramdisk_fragment); \
5056	  echo "$(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS)" > "$(zip_root)/VENDOR_BOOT/RAMDISK_FRAGMENTS/$(vendor_ramdisk_fragment)/mkbootimg_args"; \
5057	  $(eval prebuilt_ramdisk := $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).PREBUILT)) \
5058	  $(if $(prebuilt_ramdisk), \
5059	    cp "$(prebuilt_ramdisk)" "$(zip_root)/VENDOR_BOOT/RAMDISK_FRAGMENTS/$(vendor_ramdisk_fragment)/prebuilt_ramdisk";, \
5060	    $(call package_files-copy-root, \
5061	      $(VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).STAGING_DIR), \
5062	      $(zip_root)/VENDOR_BOOT/RAMDISK_FRAGMENTS/$(vendor_ramdisk_fragment)/RAMDISK); \
5063	  ))
5064endif # INTERNAL_VENDOR_RAMDISK_FRAGMENTS != ""
5065endif # INSTALLED_VENDOR_BOOTIMAGE_TARGET
5066ifdef BUILDING_SYSTEM_IMAGE
5067	@# Contents of the system image
5068	$(hide) $(call package_files-copy-root, \
5069	    $(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
5070endif
5071ifdef BUILDING_USERDATA_IMAGE
5072	@# Contents of the data image
5073	$(hide) $(call package_files-copy-root, \
5074	    $(TARGET_OUT_DATA),$(zip_root)/DATA)
5075endif
5076ifdef BUILDING_VENDOR_IMAGE
5077	@# Contents of the vendor image
5078	$(hide) $(call package_files-copy-root, \
5079	    $(TARGET_OUT_VENDOR),$(zip_root)/VENDOR)
5080endif
5081ifdef BUILDING_PRODUCT_IMAGE
5082	@# Contents of the product image
5083	$(hide) $(call package_files-copy-root, \
5084	    $(TARGET_OUT_PRODUCT),$(zip_root)/PRODUCT)
5085endif
5086ifdef BUILDING_SYSTEM_EXT_IMAGE
5087	@# Contents of the system_ext image
5088	$(hide) $(call package_files-copy-root, \
5089	    $(TARGET_OUT_SYSTEM_EXT),$(zip_root)/SYSTEM_EXT)
5090endif
5091ifdef BUILDING_ODM_IMAGE
5092	@# Contents of the odm image
5093	$(hide) $(call package_files-copy-root, \
5094	    $(TARGET_OUT_ODM),$(zip_root)/ODM)
5095endif
5096ifdef BUILDING_VENDOR_DLKM_IMAGE
5097	@# Contents of the vendor_dlkm image
5098	$(hide) $(call package_files-copy-root, \
5099	    $(TARGET_OUT_VENDOR_DLKM),$(zip_root)/VENDOR_DLKM)
5100endif
5101ifdef BUILDING_ODM_DLKM_IMAGE
5102	@# Contents of the odm_dlkm image
5103	$(hide) $(call package_files-copy-root, \
5104	    $(TARGET_OUT_ODM_DLKM),$(zip_root)/ODM_DLKM)
5105endif
5106ifdef BUILDING_SYSTEM_OTHER_IMAGE
5107	@# Contents of the system_other image
5108	$(hide) $(call package_files-copy-root, \
5109	    $(TARGET_OUT_SYSTEM_OTHER),$(zip_root)/SYSTEM_OTHER)
5110endif
5111	@# Extra contents of the OTA package
5112	$(hide) mkdir -p $(zip_root)/OTA
5113	$(hide) cp $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/
5114ifdef BUILDING_RAMDISK_IMAGE
5115ifeq (true,$(BOARD_IMG_USE_RAMDISK))
5116	@# Contents of the ramdisk image
5117	$(hide) mkdir -p $(zip_root)/IMAGES
5118	$(hide) cp $(INSTALLED_RAMDISK_TARGET) $(zip_root)/IMAGES/
5119endif
5120endif
5121ifeq ($(TARGET_OTA_ALLOW_NON_AB),true)
5122ifneq ($(built_ota_tools),)
5123	$(hide) mkdir -p $(zip_root)/OTA/bin
5124	$(hide) cp $(PRIVATE_OTA_TOOLS) $(zip_root)/OTA/bin/
5125endif
5126endif
5127	@# Files that do not end up in any images, but are necessary to
5128	@# build them.
5129	$(hide) mkdir -p $(zip_root)/META
5130	$(hide) cp $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
5131	$(hide) cp $(SOONG_APEX_KEYS_FILE) $(zip_root)/META/apexkeys.txt
5132ifneq ($(tool_extension),)
5133	$(hide) cp $(PRIVATE_TOOL_EXTENSION) $(zip_root)/META/
5134endif
5135	$(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
5136	$(hide) cp $(SELINUX_FC) $(zip_root)/META/file_contexts.bin
5137	$(hide) cp $(INSTALLED_MISC_INFO_TARGET) $(zip_root)/META/misc_info.txt
5138ifneq ($(PRODUCT_SYSTEM_BASE_FS_PATH),)
5139	$(hide) cp $(PRODUCT_SYSTEM_BASE_FS_PATH) \
5140	  $(zip_root)/META/$(notdir $(PRODUCT_SYSTEM_BASE_FS_PATH))
5141endif
5142ifneq ($(PRODUCT_VENDOR_BASE_FS_PATH),)
5143	$(hide) cp $(PRODUCT_VENDOR_BASE_FS_PATH) \
5144	  $(zip_root)/META/$(notdir $(PRODUCT_VENDOR_BASE_FS_PATH))
5145endif
5146ifneq ($(PRODUCT_PRODUCT_BASE_FS_PATH),)
5147	$(hide) cp $(PRODUCT_PRODUCT_BASE_FS_PATH) \
5148	  $(zip_root)/META/$(notdir $(PRODUCT_PRODUCT_BASE_FS_PATH))
5149endif
5150ifneq ($(PRODUCT_SYSTEM_EXT_BASE_FS_PATH),)
5151	$(hide) cp $(PRODUCT_SYSTEM_EXT_BASE_FS_PATH) \
5152	  $(zip_root)/META/$(notdir $(PRODUCT_SYSTEM_EXT_BASE_FS_PATH))
5153endif
5154ifneq ($(PRODUCT_ODM_BASE_FS_PATH),)
5155	$(hide) cp $(PRODUCT_ODM_BASE_FS_PATH) \
5156	  $(zip_root)/META/$(notdir $(PRODUCT_ODM_BASE_FS_PATH))
5157endif
5158ifneq ($(PRODUCT_VENDOR_DLKM_BASE_FS_PATH),)
5159	$(hide) cp $(PRODUCT_VENDOR_DLKM_BASE_FS_PATH) \
5160	  $(zip_root)/META/$(notdir $(PRODUCT_VENDOR_DLKM_BASE_FS_PATH))
5161endif
5162ifneq ($(PRODUCT_ODM_DLKM_BASE_FS_PATH),)
5163	$(hide) cp $(PRODUCT_ODM_DLKM_BASE_FS_PATH) \
5164	  $(zip_root)/META/$(notdir $(PRODUCT_ODM_DLKM_BASE_FS_PATH))
5165endif
5166ifeq ($(TARGET_OTA_ALLOW_NON_AB),true)
5167ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
5168	$(hide) PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH MKBOOTIMG=$(MKBOOTIMG) \
5169	    $(MAKE_RECOVERY_PATCH) $(zip_root) $(zip_root)
5170endif
5171endif
5172ifeq ($(AB_OTA_UPDATER),true)
5173	@# When using the A/B updater, include the updater config files in the zip.
5174	$(hide) cp $(TOPDIR)system/update_engine/update_engine.conf $(zip_root)/META/update_engine_config.txt
5175	$(hide) for part in $(AB_OTA_PARTITIONS); do \
5176	  echo "$${part}" >> $(zip_root)/META/ab_partitions.txt; \
5177	done
5178	$(hide) for conf in $(AB_OTA_POSTINSTALL_CONFIG); do \
5179	  echo "$${conf}" >> $(zip_root)/META/postinstall_config.txt; \
5180	done
5181ifdef OSRELEASED_DIRECTORY
5182	$(hide) cp $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_id $(zip_root)/META/product_id.txt
5183	$(hide) cp $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_version $(zip_root)/META/product_version.txt
5184	$(hide) cp $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/system_version $(zip_root)/META/system_version.txt
5185endif
5186endif
5187ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
5188	@# If breakpad symbols have been generated, add them to the zip.
5189	$(hide) cp -R $(TARGET_OUT_BREAKPAD) $(zip_root)/BREAKPAD
5190endif
5191ifdef BOARD_PREBUILT_VENDORIMAGE
5192	$(hide) mkdir -p $(zip_root)/IMAGES
5193	$(hide) cp $(INSTALLED_VENDORIMAGE_TARGET) $(zip_root)/IMAGES/
5194endif
5195ifdef BOARD_PREBUILT_PRODUCTIMAGE
5196	$(hide) mkdir -p $(zip_root)/IMAGES
5197	$(hide) cp $(INSTALLED_PRODUCTIMAGE_TARGET) $(zip_root)/IMAGES/
5198endif
5199ifdef BOARD_PREBUILT_SYSTEM_EXTIMAGE
5200	$(hide) mkdir -p $(zip_root)/IMAGES
5201	$(hide) cp $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) $(zip_root)/IMAGES/
5202endif
5203ifndef BOARD_PREBUILT_BOOTIMAGE
5204ifneq (,$(INTERNAL_PREBUILT_BOOTIMAGE) $(filter true,$(BOARD_COPY_BOOT_IMAGE_TO_TARGET_FILES)))
5205ifdef INSTALLED_BOOTIMAGE_TARGET
5206	$(hide) mkdir -p $(zip_root)/IMAGES
5207	$(hide) cp $(INSTALLED_BOOTIMAGE_TARGET) $(zip_root)/IMAGES/
5208endif # INSTALLED_BOOTIMAGE_TARGET
5209endif # INTERNAL_PREBUILT_BOOTIMAGE != "" || BOARD_COPY_BOOT_IMAGE_TO_TARGET_FILES == true
5210else # BOARD_PREBUILT_BOOTIMAGE is defined
5211	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
5212	$(hide) cp $(INSTALLED_BOOTIMAGE_TARGET) $(zip_root)/PREBUILT_IMAGES/
5213endif # BOARD_PREBUILT_BOOTIMAGE
5214ifdef BOARD_PREBUILT_ODMIMAGE
5215	$(hide) mkdir -p $(zip_root)/IMAGES
5216	$(hide) cp $(INSTALLED_ODMIMAGE_TARGET) $(zip_root)/IMAGES/
5217endif
5218ifdef BOARD_PREBUILT_VENDOR_DLKMIMAGE
5219	$(hide) mkdir -p $(zip_root)/IMAGES
5220	$(hide) cp $(INSTALLED_VENDOR_DLKMIMAGE_TARGET) $(zip_root)/IMAGES/
5221endif
5222ifdef BOARD_PREBUILT_ODM_DLKMIMAGE
5223	$(hide) mkdir -p $(zip_root)/IMAGES
5224	$(hide) cp $(INSTALLED_ODM_DLKMIMAGE_TARGET) $(zip_root)/IMAGES/
5225endif
5226ifdef BOARD_PREBUILT_DTBOIMAGE
5227	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
5228	$(hide) cp $(INSTALLED_DTBOIMAGE_TARGET) $(zip_root)/PREBUILT_IMAGES/
5229endif # BOARD_PREBUILT_DTBOIMAGE
5230ifdef BOARD_PREBUILT_PVMFWIMAGE
5231	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
5232	$(hide) cp $(INSTALLED_PVMFWIMAGE_TARGET) $(zip_root)/PREBUILT_IMAGES/
5233endif # BOARD_PREBUILT_PVMFWIMAGE
5234ifdef BOARD_PREBUILT_BOOTLOADER
5235	$(hide) mkdir -p $(zip_root)/IMAGES
5236	$(hide) cp $(INSTALLED_BOOTLOADER_MODULE) $(zip_root)/IMAGES/
5237endif
5238ifneq ($(strip $(BOARD_CUSTOMIMAGES_PARTITION_LIST)),)
5239	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
5240	$(hide) $(foreach partition,$(BOARD_CUSTOMIMAGES_PARTITION_LIST), \
5241	    $(foreach image,$(BOARD_AVB_$(call to-upper,$(partition))_IMAGE_LIST),cp $(image) $(zip_root)/PREBUILT_IMAGES/;))
5242endif # BOARD_CUSTOMIMAGES_PARTITION_LIST
5243	@# The radio images in BOARD_PACK_RADIOIMAGES will be additionally copied from RADIO/ into
5244	@# IMAGES/, which then will be added into <product>-img.zip. Such images must be listed in
5245	@# INSTALLED_RADIOIMAGE_TARGET.
5246	$(hide) $(foreach part,$(BOARD_PACK_RADIOIMAGES), \
5247	    echo $(part) >> $(zip_root)/META/pack_radioimages.txt;)
5248	@# Run fs_config on all the system, vendor, boot ramdisk,
5249	@# and recovery ramdisk files in the zip, and save the output
5250ifdef BUILDING_SYSTEM_IMAGE
5251	$(hide) $(call fs_config,$(zip_root)/SYSTEM,system/) > $(zip_root)/META/filesystem_config.txt
5252endif
5253ifdef BUILDING_VENDOR_IMAGE
5254	$(hide) $(call fs_config,$(zip_root)/VENDOR,vendor/) > $(zip_root)/META/vendor_filesystem_config.txt
5255endif
5256ifdef BUILDING_PRODUCT_IMAGE
5257	$(hide) $(call fs_config,$(zip_root)/PRODUCT,product/) > $(zip_root)/META/product_filesystem_config.txt
5258endif
5259ifdef BUILDING_SYSTEM_EXT_IMAGE
5260	$(hide) $(call fs_config,$(zip_root)/SYSTEM_EXT,system_ext/) > $(zip_root)/META/system_ext_filesystem_config.txt
5261endif
5262ifdef BUILDING_ODM_IMAGE
5263	$(hide) $(call fs_config,$(zip_root)/ODM,odm/) > $(zip_root)/META/odm_filesystem_config.txt
5264endif
5265ifdef BUILDING_VENDOR_DLKM_IMAGE
5266	$(hide) $(call fs_config,$(zip_root)/VENDOR_DLKM,vendor_dlkm/) > $(zip_root)/META/vendor_dlkm_filesystem_config.txt
5267endif
5268ifdef BUILDING_ODM_DLKM_IMAGE
5269	$(hide) $(call fs_config,$(zip_root)/ODM_DLKM,odm_dlkm/) > $(zip_root)/META/odm_dlkm_filesystem_config.txt
5270endif
5271	@# ROOT always contains the files for the root under normal boot.
5272	$(hide) $(call fs_config,$(zip_root)/ROOT,) > $(zip_root)/META/root_filesystem_config.txt
5273ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
5274	@# BOOT/RAMDISK exists and contains the ramdisk for recovery if using BOARD_USES_RECOVERY_AS_BOOT.
5275	$(hide) $(call fs_config,$(zip_root)/BOOT/RAMDISK,) > $(zip_root)/META/boot_filesystem_config.txt
5276endif
5277ifneq ($(INSTALLED_VENDOR_BOOTIMAGE_TARGET),)
5278	$(call fs_config,$(zip_root)/VENDOR_BOOT/RAMDISK,) > $(zip_root)/META/vendor_boot_filesystem_config.txt
5279endif
5280ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
5281	@# BOOT/RAMDISK also exists and contains the first stage ramdisk if not using BOARD_BUILD_SYSTEM_ROOT_IMAGE.
5282	$(hide) $(call fs_config,$(zip_root)/BOOT/RAMDISK,) > $(zip_root)/META/boot_filesystem_config.txt
5283endif
5284ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
5285	$(hide) $(call fs_config,$(zip_root)/RECOVERY/RAMDISK,) > $(zip_root)/META/recovery_filesystem_config.txt
5286endif
5287ifdef BUILDING_SYSTEM_OTHER_IMAGE
5288	$(hide) $(call fs_config,$(zip_root)/SYSTEM_OTHER,system/) > $(zip_root)/META/system_other_filesystem_config.txt
5289endif
5290	@# Metadata for compatibility verification.
5291ifdef BUILT_KERNEL_CONFIGS_FILE
5292	$(hide) cp $(BUILT_KERNEL_CONFIGS_FILE) $(zip_root)/META/kernel_configs.txt
5293endif
5294ifdef BUILT_KERNEL_VERSION_FILE
5295	$(hide) cp $(BUILT_KERNEL_VERSION_FILE) $(zip_root)/META/kernel_version.txt
5296endif
5297	rm -rf $(zip_root)/META/dynamic_partitions_info.txt
5298ifeq (true,$(PRODUCT_USE_DYNAMIC_PARTITIONS))
5299	$(call dump-dynamic-partitions-info, $(zip_root)/META/dynamic_partitions_info.txt)
5300endif
5301	PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH MKBOOTIMG=$(MKBOOTIMG) \
5302	    $(ADD_IMG_TO_TARGET_FILES) -a -v -p $(HOST_OUT) $(zip_root)
5303ifeq ($(BUILD_QEMU_IMAGES),true)
5304	$(hide) AVBTOOL=$(AVBTOOL) $(MK_VBMETA_BOOT_KERNEL_CMDLINE_SH) $(zip_root)/IMAGES/vbmeta.img \
5305	    $(zip_root)/IMAGES/system.img $(zip_root)/IMAGES/VerifiedBootParams.textproto
5306endif
5307	@# Zip everything up, preserving symlinks and placing META/ files first to
5308	@# help early validation of the .zip file while uploading it.
5309	$(hide) find $(zip_root)/META | sort >$@.list
5310	$(hide) find $(zip_root) -path $(zip_root)/META -prune -o -print | sort >>$@.list
5311	$(hide) $(SOONG_ZIP) -d -o $@ -C $(zip_root) -r $@.list
5312
5313.PHONY: target-files-package
5314target-files-package: $(BUILT_TARGET_FILES_PACKAGE)
5315
5316$(call dist-for-goals, target-files-package, $(BUILT_TARGET_FILES_PACKAGE))
5317
5318# -----------------------------------------------------------------
5319# NDK Sysroot Package
5320NDK_SYSROOT_TARGET := $(PRODUCT_OUT)/ndk_sysroot.tar.bz2
5321$(NDK_SYSROOT_TARGET): $(SOONG_OUT_DIR)/ndk.timestamp
5322	@echo Package NDK sysroot...
5323	$(hide) tar cjf $@ -C $(SOONG_OUT_DIR) ndk
5324
5325$(call dist-for-goals,sdk,$(NDK_SYSROOT_TARGET))
5326
5327ifeq ($(build_ota_package),true)
5328# -----------------------------------------------------------------
5329# OTA update package
5330
5331# $(1): output file
5332# $(2): additional args
5333define build-ota-package-target
5334PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$(dir $(ZIP2ZIP)):$$PATH \
5335    $(OTA_FROM_TARGET_FILES) \
5336        --verbose \
5337        --extracted_input_target_files $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE)) \
5338        --path $(HOST_OUT) \
5339        $(if $(OEM_OTA_CONFIG), --oem_settings $(OEM_OTA_CONFIG)) \
5340        $(2) \
5341        $(BUILT_TARGET_FILES_PACKAGE) $(1)
5342endef
5343
5344product_name := $(TARGET_PRODUCT)
5345ifeq ($(TARGET_BUILD_TYPE),debug)
5346  product_name := $(product_name)_debug
5347endif
5348name := $(product_name)-ota-$(FILE_NAME_TAG)
5349
5350INTERNAL_OTA_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
5351INTERNAL_OTA_METADATA := $(PRODUCT_OUT)/ota_metadata
5352
5353$(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
5354$(INTERNAL_OTA_PACKAGE_TARGET): .KATI_IMPLICIT_OUTPUTS := $(INTERNAL_OTA_METADATA)
5355$(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(OTA_FROM_TARGET_FILES) $(INTERNAL_OTATOOLS_FILES)
5356	@echo "Package OTA: $@"
5357	$(call build-ota-package-target,$@,-k $(KEY_CERT_PAIR) --output_metadata_path $(INTERNAL_OTA_METADATA))
5358
5359.PHONY: otapackage
5360otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)
5361
5362ifeq ($(BOARD_BUILD_RETROFIT_DYNAMIC_PARTITIONS_OTA_PACKAGE),true)
5363name := $(product_name)-ota-retrofit-$(FILE_NAME_TAG)
5364
5365INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
5366$(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
5367$(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET): \
5368    $(BUILT_TARGET_FILES_PACKAGE) \
5369    $(OTA_FROM_TARGET_FILES) \
5370    $(INTERNAL_OTATOOLS_FILES)
5371	@echo "Package OTA (retrofit dynamic partitions): $@"
5372	$(call build-ota-package-target,$@,-k $(KEY_CERT_PAIR) --retrofit_dynamic_partitions)
5373
5374.PHONY: otardppackage
5375
5376otapackage otardppackage: $(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET)
5377
5378endif # BOARD_BUILD_RETROFIT_DYNAMIC_PARTITIONS_OTA_PACKAGE
5379
5380ifneq ($(BOARD_PARTIAL_OTA_UPDATE_PARTITIONS_LIST),)
5381name := $(product_name)-partial-ota-$(FILE_NAME_TAG)
5382
5383INTERNAL_OTA_PARTIAL_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
5384$(INTERNAL_OTA_PARTIAL_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
5385$(INTERNAL_OTA_PARTIAL_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(OTA_FROM_TARGET_FILES) $(INTERNAL_OTATOOLS_FILES)
5386	@echo "Package partial OTA: $@"
5387	$(call build-ota-package-target,$@,-k $(KEY_CERT_PAIR) --partial "$(BOARD_PARTIAL_OTA_UPDATE_PARTITIONS_LIST)")
5388
5389.PHONY: partialotapackage
5390partialotapackage: $(INTERNAL_OTA_PARTIAL_PACKAGE_TARGET)
5391
5392endif # BOARD_PARTIAL_OTA_UPDATE_PARTITIONS_LIST
5393
5394endif    # build_ota_package
5395
5396# -----------------------------------------------------------------
5397# A zip of the appcompat directory containing logs
5398APPCOMPAT_ZIP := $(PRODUCT_OUT)/appcompat.zip
5399# For apps_only build we'll establish the dependency later in build/make/core/main.mk.
5400ifeq (,$(TARGET_BUILD_UNBUNDLED))
5401$(APPCOMPAT_ZIP): $(FULL_SYSTEMIMAGE_DEPS) \
5402	    $(INTERNAL_RAMDISK_FILES) \
5403	    $(INTERNAL_USERDATAIMAGE_FILES) \
5404	    $(INTERNAL_VENDORIMAGE_FILES) \
5405	    $(INTERNAL_PRODUCTIMAGE_FILES) \
5406	    $(INTERNAL_SYSTEM_EXTIMAGE_FILES)
5407endif
5408$(APPCOMPAT_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,appcompat)/filelist
5409$(APPCOMPAT_ZIP): $(SOONG_ZIP)
5410	@echo "appcompat logs: $@"
5411	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
5412	$(hide) mkdir -p $(dir $@) $(PRODUCT_OUT)/appcompat $(dir $(PRIVATE_LIST_FILE))
5413	$(hide) find $(PRODUCT_OUT)/appcompat | sort >$(PRIVATE_LIST_FILE)
5414	$(hide) $(SOONG_ZIP) -d -o $@ -C $(PRODUCT_OUT)/appcompat -l $(PRIVATE_LIST_FILE)
5415
5416# The mac build doesn't build dex2oat, so create the zip file only if the build OS is linux.
5417ifeq ($(BUILD_OS),linux)
5418ifneq ($(DEX2OAT),)
5419dexpreopt_tools_deps := $(DEXPREOPT_GEN_DEPS) $(DEXPREOPT_GEN) $(AAPT2)
5420DEXPREOPT_TOOLS_ZIP := $(PRODUCT_OUT)/dexpreopt_tools.zip
5421$(DEXPREOPT_TOOLS_ZIP): $(dexpreopt_tools_deps)
5422$(DEXPREOPT_TOOLS_ZIP): PRIVATE_DEXPREOPT_TOOLS_DEPS := $(dexpreopt_tools_deps)
5423$(DEXPREOPT_TOOLS_ZIP): $(SOONG_ZIP)
5424	$(hide) mkdir -p $(dir $@)
5425	$(hide) $(SOONG_ZIP) -d -o $@ -j $(addprefix -f ,$(PRIVATE_DEXPREOPT_TOOLS_DEPS)) -f $$(realpath $(DEX2OAT))
5426endif # DEX2OAT is set
5427endif # BUILD_OS == linux
5428
5429DEXPREOPT_CONFIG_ZIP := $(PRODUCT_OUT)/dexpreopt_config.zip
5430$(DEXPREOPT_CONFIG_ZIP): $(FULL_SYSTEMIMAGE_DEPS) \
5431	    $(INTERNAL_RAMDISK_FILES) \
5432	    $(INTERNAL_USERDATAIMAGE_FILES) \
5433	    $(INTERNAL_VENDORIMAGE_FILES) \
5434	    $(INTERNAL_PRODUCTIMAGE_FILES) \
5435	    $(INTERNAL_SYSTEM_EXTIMAGE_FILES) \
5436	    $(DEX_PREOPT_CONFIG_FOR_MAKE) \
5437	    $(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE)
5438
5439$(DEXPREOPT_CONFIG_ZIP): $(SOONG_ZIP)
5440	$(hide) mkdir -p $(dir $@) $(PRODUCT_OUT)/dexpreopt_config
5441ifneq (,$(DEX_PREOPT_CONFIG_FOR_MAKE))
5442	$(hide) cp $(DEX_PREOPT_CONFIG_FOR_MAKE) $(PRODUCT_OUT)/dexpreopt_config
5443endif
5444ifneq (,$(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE))
5445	$(hide) cp $(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE) $(PRODUCT_OUT)/dexpreopt_config
5446endif
5447	$(hide) $(SOONG_ZIP) -d -o $@ -C $(PRODUCT_OUT)/dexpreopt_config -D $(PRODUCT_OUT)/dexpreopt_config
5448
5449# -----------------------------------------------------------------
5450# A zip of the symbols directory.  Keep the full paths to make it
5451# more obvious where these files came from.
5452#
5453name := $(TARGET_PRODUCT)
5454ifeq ($(TARGET_BUILD_TYPE),debug)
5455  name := $(name)_debug
5456endif
5457name := $(name)-symbols-$(FILE_NAME_TAG)
5458
5459SYMBOLS_ZIP := $(PRODUCT_OUT)/$(name).zip
5460# For apps_only build we'll establish the dependency later in build/make/core/main.mk.
5461ifeq (,$(TARGET_BUILD_UNBUNDLED))
5462$(SYMBOLS_ZIP): $(INTERNAL_ALLIMAGES_FILES) $(updater_dep)
5463endif
5464$(SYMBOLS_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,symbols)/filelist
5465$(SYMBOLS_ZIP): $(SOONG_ZIP)
5466	@echo "Package symbols: $@"
5467	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
5468	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_UNSTRIPPED) $(dir $(PRIVATE_LIST_FILE))
5469	$(hide) find -L $(TARGET_OUT_UNSTRIPPED) -type f | sort >$(PRIVATE_LIST_FILE)
5470	$(hide) $(SOONG_ZIP) --ignore_missing_files -d -o $@ -C $(OUT_DIR)/.. -l $(PRIVATE_LIST_FILE)
5471# -----------------------------------------------------------------
5472# A zip of the coverage directory.
5473#
5474name := gcov-report-files-all
5475ifeq ($(TARGET_BUILD_TYPE),debug)
5476name := $(name)_debug
5477endif
5478COVERAGE_ZIP := $(PRODUCT_OUT)/$(name).zip
5479ifeq (,$(TARGET_BUILD_UNBUNDLED))
5480$(COVERAGE_ZIP): $(INTERNAL_ALLIMAGES_FILES)
5481endif
5482$(COVERAGE_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,coverage)/filelist
5483$(COVERAGE_ZIP): $(SOONG_ZIP)
5484	@echo "Package coverage: $@"
5485	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
5486	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_COVERAGE) $(dir $(PRIVATE_LIST_FILE))
5487	$(hide) find $(TARGET_OUT_COVERAGE) | sort >$(PRIVATE_LIST_FILE)
5488	$(hide) $(SOONG_ZIP) -d -o $@ -C $(TARGET_OUT_COVERAGE) -l $(PRIVATE_LIST_FILE)
5489
5490#------------------------------------------------------------------
5491# Export the LLVM profile data tool and dependencies for Clang coverage processing
5492#
5493ifeq (true,$(CLANG_COVERAGE))
5494  LLVM_PROFDATA := $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/bin/llvm-profdata
5495  LIBCXX := $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/lib64/libc++.so.1
5496  PROFDATA_ZIP := $(PRODUCT_OUT)/llvm-profdata.zip
5497  $(PROFDATA_ZIP): $(SOONG_ZIP)
5498	$(hide) $(SOONG_ZIP) -d -o $@ -C $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION) -f $(LLVM_PROFDATA) -f $(LIBCXX)
5499
5500  $(call dist-for-goals,droidcore-unbundled apps_only,$(PROFDATA_ZIP))
5501endif
5502
5503# -----------------------------------------------------------------
5504# A zip of the Android Apps. Not keeping full path so that we don't
5505# include product names when distributing
5506#
5507name := $(TARGET_PRODUCT)
5508ifeq ($(TARGET_BUILD_TYPE),debug)
5509  name := $(name)_debug
5510endif
5511name := $(name)-apps-$(FILE_NAME_TAG)
5512
5513APPS_ZIP := $(PRODUCT_OUT)/$(name).zip
5514$(APPS_ZIP): $(FULL_SYSTEMIMAGE_DEPS)
5515	@echo "Package apps: $@"
5516	$(hide) rm -rf $@
5517	$(hide) mkdir -p $(dir $@)
5518	$(hide) apps_to_zip=`find $(TARGET_OUT_APPS) $(TARGET_OUT_APPS_PRIVILEGED) -mindepth 2 -maxdepth 3 -name "*.apk"`; \
5519	if [ -z "$$apps_to_zip" ]; then \
5520	    echo "No apps to zip up. Generating empty apps archive." ; \
5521	    a=$$(mktemp /tmp/XXXXXXX) && touch $$a && zip $@ $$a && zip -d $@ $$a; \
5522	else \
5523	    zip -qjX $@ $$apps_to_zip; \
5524	fi
5525
5526ifeq (true,$(EMMA_INSTRUMENT))
5527#------------------------------------------------------------------
5528# An archive of classes for use in generating code-coverage reports
5529# These are the uninstrumented versions of any classes that were
5530# to be instrumented.
5531# Any dependencies are set up later in build/make/core/main.mk.
5532
5533JACOCO_REPORT_CLASSES_ALL := $(PRODUCT_OUT)/jacoco-report-classes-all.jar
5534$(JACOCO_REPORT_CLASSES_ALL): PRIVATE_TARGET_JACOCO_DIR := $(call intermediates-dir-for,PACKAGING,jacoco)
5535$(JACOCO_REPORT_CLASSES_ALL): PRIVATE_HOST_JACOCO_DIR := $(call intermediates-dir-for,PACKAGING,jacoco,HOST)
5536$(JACOCO_REPORT_CLASSES_ALL): PRIVATE_TARGET_PROGUARD_USAGE_DIR := $(call intermediates-dir-for,PACKAGING,proguard_usage)
5537$(JACOCO_REPORT_CLASSES_ALL): PRIVATE_HOST_PROGUARD_USAGE_DIR := $(call intermediates-dir-for,PACKAGING,proguard_usage,HOST)
5538$(JACOCO_REPORT_CLASSES_ALL) :
5539	@echo "Collecting uninstrumented classes"
5540	mkdir -p $(PRIVATE_TARGET_JACOCO_DIR) $(PRIVATE_HOST_JACOCO_DIR) $(PRIVATE_TARGET_PROGUARD_USAGE_DIR) $(PRIVATE_HOST_PROGUARD_USAGE_DIR)
5541	$(SOONG_ZIP) -o $@ -L 0 \
5542	  -C $(PRIVATE_TARGET_JACOCO_DIR) -P out/target/common/obj -D $(PRIVATE_TARGET_JACOCO_DIR) \
5543	  -C $(PRIVATE_HOST_JACOCO_DIR) -P out/target/common/obj -D $(PRIVATE_HOST_JACOCO_DIR) \
5544	  -C $(PRIVATE_TARGET_PROGUARD_USAGE_DIR) -P out/target/common/obj -D $(PRIVATE_TARGET_PROGUARD_USAGE_DIR) \
5545	  -C $(PRIVATE_HOST_PROGUARD_USAGE_DIR) -P out/target/common/obj -D $(PRIVATE_HOST_PROGUARD_USAGE_DIR)
5546
5547ifeq (,$(TARGET_BUILD_UNBUNDLED))
5548  $(JACOCO_REPORT_CLASSES_ALL): $(INTERNAL_ALLIMAGES_FILES)
5549endif
5550endif # EMMA_INSTRUMENT=true
5551
5552
5553#------------------------------------------------------------------
5554# A zip of Proguard obfuscation dictionary files.
5555#
5556PROGUARD_DICT_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-$(FILE_NAME_TAG).zip
5557# For apps_only build we'll establish the dependency later in build/make/core/main.mk.
5558ifeq (,$(TARGET_BUILD_UNBUNDLED))
5559$(PROGUARD_DICT_ZIP): $(INTERNAL_ALLIMAGES_FILES) $(updater_dep)
5560endif
5561$(PROGUARD_DICT_ZIP): PRIVATE_PACKAGING_DIR := $(call intermediates-dir-for,PACKAGING,proguard_dictionary)
5562$(PROGUARD_DICT_ZIP): $(SOONG_ZIP)
5563	@echo "Packaging Proguard obfuscation dictionary files."
5564	mkdir -p $(dir $@) $(PRIVATE_PACKAGING_DIR)
5565	$(SOONG_ZIP) --ignore_missing_files -d -o $@ -C $(PRIVATE_PACKAGING_DIR) -P out/target/common/obj -D $(PRIVATE_PACKAGING_DIR)
5566
5567#------------------------------------------------------------------
5568# A zip of Proguard usage files.
5569#
5570PROGUARD_USAGE_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-usage-$(FILE_NAME_TAG).zip
5571# For apps_only build we'll establish the dependency later in build/make/core/main.mk.
5572ifeq (,$(TARGET_BUILD_UNBUNDLED))
5573$(PROGUARD_USAGE_ZIP): \
5574    $(INSTALLED_SYSTEMIMAGE_TARGET) \
5575    $(INSTALLED_RAMDISK_TARGET) \
5576    $(INSTALLED_BOOTIMAGE_TARGET) \
5577    $(INSTALLED_USERDATAIMAGE_TARGET) \
5578    $(INSTALLED_VENDORIMAGE_TARGET) \
5579    $(INSTALLED_PRODUCTIMAGE_TARGET) \
5580    $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) \
5581    $(INSTALLED_ODMIMAGE_TARGET) \
5582    $(INSTALLED_VENDOR_DLKMIMAGE_TARGET) \
5583    $(INSTALLED_ODM_DLKMIMAGE_TARGET) \
5584    $(updater_dep)
5585endif
5586$(PROGUARD_USAGE_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,proguard_usage.zip)/filelist
5587$(PROGUARD_USAGE_ZIP): PRIVATE_PACKAGING_DIR := $(call intermediates-dir-for,PACKAGING,proguard_usage)
5588$(PROGUARD_USAGE_ZIP): $(MERGE_ZIPS)
5589	@echo "Packaging Proguard usage files."
5590	mkdir -p $(dir $@) $(PRIVATE_PACKAGING_DIR) $(dir $(PRIVATE_LIST_FILE))
5591	find $(PRIVATE_PACKAGING_DIR) -name proguard_usage.zip > $(PRIVATE_LIST_FILE)
5592	$(MERGE_ZIPS) $@ @$(PRIVATE_LIST_FILE)
5593
5594ifeq (true,$(PRODUCT_USE_DYNAMIC_PARTITIONS))
5595
5596# Dump variables used by build_super_image.py (for building super.img and super_empty.img).
5597# $(1): output file
5598define dump-super-image-info
5599  $(call dump-dynamic-partitions-info,$(1))
5600  $(if $(filter true,$(AB_OTA_UPDATER)), \
5601    echo "ab_update=true" >> $(1))
5602endef
5603
5604endif # PRODUCT_USE_DYNAMIC_PARTITIONS
5605
5606# -----------------------------------------------------------------
5607# super partition image (dist)
5608
5609ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
5610
5611# BOARD_SUPER_PARTITION_SIZE must be defined to build super image.
5612ifneq ($(BOARD_SUPER_PARTITION_SIZE),)
5613
5614ifneq (true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS))
5615
5616# For real devices and for dist builds, build super image from target files to an intermediate directory.
5617INTERNAL_SUPERIMAGE_DIST_TARGET := $(call intermediates-dir-for,PACKAGING,super.img)/super.img
5618$(INTERNAL_SUPERIMAGE_DIST_TARGET): extracted_input_target_files := $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE))
5619$(INTERNAL_SUPERIMAGE_DIST_TARGET): $(LPMAKE) $(BUILT_TARGET_FILES_PACKAGE) $(BUILD_SUPER_IMAGE)
5620	$(call pretty,"Target super fs image from target files: $@")
5621	PATH=$(dir $(LPMAKE)):$$PATH \
5622	    $(BUILD_SUPER_IMAGE) -v $(extracted_input_target_files) $@
5623
5624# Skip packing it in dist package because it is in update package.
5625ifneq (true,$(BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE))
5626$(call dist-for-goals,dist_files,$(INTERNAL_SUPERIMAGE_DIST_TARGET))
5627endif
5628
5629.PHONY: superimage_dist
5630superimage_dist: $(INTERNAL_SUPERIMAGE_DIST_TARGET)
5631
5632endif # PRODUCT_RETROFIT_DYNAMIC_PARTITIONS != "true"
5633endif # BOARD_SUPER_PARTITION_SIZE != ""
5634endif # PRODUCT_BUILD_SUPER_PARTITION == "true"
5635
5636# -----------------------------------------------------------------
5637# super partition image for development
5638
5639ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
5640ifneq ($(BOARD_SUPER_PARTITION_SIZE),)
5641ifneq (true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS))
5642
5643# Build super.img by using $(INSTALLED_*IMAGE_TARGET) to $(1)
5644# $(1): built image path
5645# $(2): misc_info.txt path; its contents should match expectation of build_super_image.py
5646define build-superimage-target
5647  mkdir -p $(dir $(2))
5648  rm -rf $(2)
5649  $(call dump-super-image-info,$(2))
5650  $(foreach p,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
5651    echo "$(p)_image=$(INSTALLED_$(call to-upper,$(p))IMAGE_TARGET)" >> $(2);)
5652  $(if $(BUILDING_SYSTEM_OTHER_IMAGE), $(if $(filter system,$(BOARD_SUPER_PARTITION_PARTITION_LIST)), \
5653    echo "system_other_image=$(INSTALLED_SYSTEMOTHERIMAGE_TARGET)" >> $(2);))
5654  mkdir -p $(dir $(1))
5655  PATH=$(dir $(LPMAKE)):$$PATH \
5656    $(BUILD_SUPER_IMAGE) -v $(2) $(1)
5657endef
5658
5659INSTALLED_SUPERIMAGE_TARGET := $(PRODUCT_OUT)/super.img
5660INSTALLED_SUPERIMAGE_DEPENDENCIES := $(LPMAKE) $(BUILD_SUPER_IMAGE) \
5661    $(foreach p, $(BOARD_SUPER_PARTITION_PARTITION_LIST), $(INSTALLED_$(call to-upper,$(p))IMAGE_TARGET))
5662
5663ifdef BUILDING_SYSTEM_OTHER_IMAGE
5664ifneq ($(filter system,$(BOARD_SUPER_PARTITION_PARTITION_LIST)),)
5665INSTALLED_SUPERIMAGE_DEPENDENCIES += $(INSTALLED_SYSTEMOTHERIMAGE_TARGET)
5666endif
5667endif
5668
5669# If BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT is set, super.img is built from images in the
5670# $(PRODUCT_OUT) directory, and is built to $(PRODUCT_OUT)/super.img. Also, it will
5671# be built for non-dist builds. This is useful for devices that uses super.img directly, e.g.
5672# virtual devices.
5673ifeq (true,$(BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT))
5674$(INSTALLED_SUPERIMAGE_TARGET): $(INSTALLED_SUPERIMAGE_DEPENDENCIES)
5675	$(call pretty,"Target super fs image for debug: $@")
5676	$(call build-superimage-target,$(INSTALLED_SUPERIMAGE_TARGET),\
5677          $(call intermediates-dir-for,PACKAGING,superimage_debug)/misc_info.txt)
5678
5679droidcore-unbundled: $(INSTALLED_SUPERIMAGE_TARGET)
5680
5681# For devices that uses super image directly, the superimage target points to the file in $(PRODUCT_OUT).
5682.PHONY: superimage
5683superimage: $(INSTALLED_SUPERIMAGE_TARGET)
5684
5685$(call dist-for-goals,dist_files,$(INSTALLED_MISC_INFO_TARGET):super_misc_info.txt)
5686endif # BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT
5687
5688# Build $(PRODUCT_OUT)/super.img without dependencies.
5689.PHONY: superimage-nodeps supernod
5690superimage-nodeps supernod: intermediates :=
5691superimage-nodeps supernod: | $(INSTALLED_SUPERIMAGE_DEPENDENCIES)
5692	$(call pretty,"make $(INSTALLED_SUPERIMAGE_TARGET): ignoring dependencies")
5693	$(call build-superimage-target,$(INSTALLED_SUPERIMAGE_TARGET),\
5694	  $(call intermediates-dir-for,PACKAGING,superimage-nodeps)/misc_info.txt)
5695
5696endif # PRODUCT_RETROFIT_DYNAMIC_PARTITIONS != "true"
5697endif # BOARD_SUPER_PARTITION_SIZE != ""
5698endif # PRODUCT_BUILD_SUPER_PARTITION == "true"
5699
5700# -----------------------------------------------------------------
5701# super empty image
5702ifdef BUILDING_SUPER_EMPTY_IMAGE
5703
5704INSTALLED_SUPERIMAGE_EMPTY_TARGET := $(PRODUCT_OUT)/super_empty.img
5705$(INSTALLED_SUPERIMAGE_EMPTY_TARGET): intermediates := $(call intermediates-dir-for,PACKAGING,super_empty)
5706$(INSTALLED_SUPERIMAGE_EMPTY_TARGET): $(LPMAKE) $(BUILD_SUPER_IMAGE)
5707	$(call pretty,"Target empty super fs image: $@")
5708	mkdir -p $(intermediates)
5709	rm -rf $(intermediates)/misc_info.txt
5710	$(call dump-super-image-info,$(intermediates)/misc_info.txt)
5711	PATH=$(dir $(LPMAKE)):$$PATH \
5712	    $(BUILD_SUPER_IMAGE) -v $(intermediates)/misc_info.txt $@
5713
5714$(call dist-for-goals,dist_files,$(INSTALLED_SUPERIMAGE_EMPTY_TARGET))
5715
5716endif # BUILDING_SUPER_EMPTY_IMAGE
5717
5718
5719# -----------------------------------------------------------------
5720# The update package
5721
5722name := $(TARGET_PRODUCT)
5723ifeq ($(TARGET_BUILD_TYPE),debug)
5724  name := $(name)_debug
5725endif
5726name := $(name)-img-$(FILE_NAME_TAG)
5727
5728INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
5729
5730$(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(IMG_FROM_TARGET_FILES)
5731	$(call pretty,"Package: $@")
5732	PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$(dir $(ZIP2ZIP)):$$PATH \
5733	    $(IMG_FROM_TARGET_FILES) \
5734	        --additional IMAGES/VerifiedBootParams.textproto:VerifiedBootParams.textproto \
5735	        $(BUILT_TARGET_FILES_PACKAGE) $@
5736
5737.PHONY: updatepackage
5738updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
5739$(call dist-for-goals,updatepackage,$(INTERNAL_UPDATE_PACKAGE_TARGET))
5740
5741
5742# -----------------------------------------------------------------
5743# dalvik something
5744.PHONY: dalvikfiles
5745dalvikfiles: $(INTERNAL_DALVIK_MODULES)
5746
5747ifeq ($(BUILD_QEMU_IMAGES),true)
5748MK_QEMU_IMAGE_SH := device/generic/goldfish/tools/mk_qemu_image.sh
5749MK_COMBINE_QEMU_IMAGE := $(HOST_OUT_EXECUTABLES)/mk_combined_img
5750SGDISK_HOST := $(HOST_OUT_EXECUTABLES)/sgdisk
5751
5752ifdef INSTALLED_SYSTEMIMAGE_TARGET
5753INSTALLED_QEMU_SYSTEMIMAGE := $(PRODUCT_OUT)/system-qemu.img
5754INSTALLED_SYSTEM_QEMU_CONFIG := $(PRODUCT_OUT)/system-qemu-config.txt
5755$(INSTALLED_SYSTEM_QEMU_CONFIG): $(INSTALLED_SUPERIMAGE_TARGET) $(INSTALLED_VBMETAIMAGE_TARGET)
5756	@echo "$(PRODUCT_OUT)/vbmeta.img vbmeta 1" > $@
5757	@echo "$(INSTALLED_SUPERIMAGE_TARGET) super 2" >> $@
5758$(INSTALLED_QEMU_SYSTEMIMAGE): $(INSTALLED_VBMETAIMAGE_TARGET) $(MK_COMBINE_QEMU_IMAGE) $(SGDISK_HOST) $(SIMG2IMG) \
5759    $(INSTALLED_SUPERIMAGE_TARGET) $(INSTALLED_SYSTEM_QEMU_CONFIG)
5760	@echo Create system-qemu.img now
5761	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); \
5762     $(MK_COMBINE_QEMU_IMAGE) -i $(INSTALLED_SYSTEM_QEMU_CONFIG) -o $@)
5763
5764systemimage: $(INSTALLED_QEMU_SYSTEMIMAGE)
5765droidcore-unbundled: $(INSTALLED_QEMU_SYSTEMIMAGE)
5766endif
5767ifdef INSTALLED_VENDORIMAGE_TARGET
5768INSTALLED_QEMU_VENDORIMAGE := $(PRODUCT_OUT)/vendor-qemu.img
5769$(INSTALLED_QEMU_VENDORIMAGE): $(INSTALLED_VENDORIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST) $(SIMG2IMG)
5770	@echo Create vendor-qemu.img
5771	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); $(MK_QEMU_IMAGE_SH) $(INSTALLED_VENDORIMAGE_TARGET))
5772
5773vendorimage: $(INSTALLED_QEMU_VENDORIMAGE)
5774droidcore-unbundled: $(INSTALLED_QEMU_VENDORIMAGE)
5775endif
5776
5777ifdef INSTALLED_RAMDISK_TARGET
5778ifdef INSTALLED_VENDOR_BOOTIMAGE_TARGET
5779ifdef INTERNAL_VENDOR_RAMDISK_TARGET
5780INSTALLED_QEMU_RAMDISKIMAGE := $(PRODUCT_OUT)/ramdisk-qemu.img
5781$(INSTALLED_QEMU_RAMDISKIMAGE): $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INSTALLED_RAMDISK_TARGET)
5782	@echo Create ramdisk-qemu.img
5783	(cat $(INSTALLED_RAMDISK_TARGET) $(INTERNAL_VENDOR_RAMDISK_TARGET) > $(INSTALLED_QEMU_RAMDISKIMAGE))
5784
5785droidcore-unbundled: $(INSTALLED_QEMU_RAMDISKIMAGE)
5786endif
5787endif
5788endif
5789
5790ifdef INSTALLED_PRODUCTIMAGE_TARGET
5791INSTALLED_QEMU_PRODUCTIMAGE := $(PRODUCT_OUT)/product-qemu.img
5792$(INSTALLED_QEMU_PRODUCTIMAGE): $(INSTALLED_PRODUCTIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST) $(SIMG2IMG)
5793	@echo Create product-qemu.img
5794	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); $(MK_QEMU_IMAGE_SH) $(INSTALLED_PRODUCTIMAGE_TARGET))
5795
5796productimage: $(INSTALLED_QEMU_PRODUCTIMAGE)
5797droidcore-unbundled: $(INSTALLED_QEMU_PRODUCTIMAGE)
5798endif
5799ifdef INSTALLED_SYSTEM_EXTIMAGE_TARGET
5800INSTALLED_QEMU_SYSTEM_EXTIMAGE := $(PRODUCT_OUT)/system_ext-qemu.img
5801$(INSTALLED_QEMU_SYSTEM_EXTIMAGE): $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST) $(SIMG2IMG)
5802	@echo Create system_ext-qemu.img
5803	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); $(MK_QEMU_IMAGE_SH) $(INSTALLED_SYSTEM_EXTIMAGE_TARGET))
5804
5805systemextimage: $(INSTALLED_QEMU_SYSTEM_EXTIMAGE)
5806droidcore-unbundled: $(INSTALLED_QEMU_SYSTEM_EXTIMAGE)
5807endif
5808ifdef INSTALLED_ODMIMAGE_TARGET
5809INSTALLED_QEMU_ODMIMAGE := $(PRODUCT_OUT)/odm-qemu.img
5810$(INSTALLED_QEMU_ODMIMAGE): $(INSTALLED_ODMIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST)
5811	@echo Create odm-qemu.img
5812	(export SGDISK=$(SGDISK_HOST); $(MK_QEMU_IMAGE_SH) $(INSTALLED_ODMIMAGE_TARGET))
5813
5814odmimage: $(INSTALLED_QEMU_ODMIMAGE)
5815droidcore-unbundled: $(INSTALLED_QEMU_ODMIMAGE)
5816endif
5817
5818ifdef INSTALLED_VENDOR_DLKMIMAGE_TARGET
5819INSTALLED_QEMU_VENDOR_DLKMIMAGE := $(PRODUCT_OUT)/vendor_dlkm-qemu.img
5820$(INSTALLED_QEMU_VENDOR_DLKMIMAGE): $(INSTALLED_VENDOR_DLKMIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST)
5821	@echo Create vendor_dlkm-qemu.img
5822	(export SGDISK=$(SGDISK_HOST); $(MK_QEMU_IMAGE_SH) $(INSTALLED_VENDOR_DLKMIMAGE_TARGET))
5823
5824vendor_dlkmimage: $(INSTALLED_QEMU_VENDOR_DLKMIMAGE)
5825droidcore-unbundled: $(INSTALLED_QEMU_VENDOR_DLKMIMAGE)
5826endif
5827
5828ifdef INSTALLED_ODM_DLKMIMAGE_TARGET
5829INSTALLED_QEMU_ODM_DLKMIMAGE := $(PRODUCT_OUT)/odm_dlkm-qemu.img
5830$(INSTALLED_QEMU_ODM_DLKMIMAGE): $(INSTALLED_ODM_DLKMIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST)
5831	@echo Create odm_dlkm-qemu.img
5832	(export SGDISK=$(SGDISK_HOST); $(MK_QEMU_IMAGE_SH) $(INSTALLED_ODM_DLKMIMAGE_TARGET))
5833
5834odm_dlkmimage: $(INSTALLED_QEMU_ODM_DLKMIMAGE)
5835droidcore-unbundled: $(INSTALLED_QEMU_ODM_DLKMIMAGE)
5836endif
5837
5838QEMU_VERIFIED_BOOT_PARAMS := $(PRODUCT_OUT)/VerifiedBootParams.textproto
5839$(QEMU_VERIFIED_BOOT_PARAMS): $(INSTALLED_VBMETAIMAGE_TARGET) $(INSTALLED_SYSTEMIMAGE_TARGET) \
5840    $(MK_VBMETA_BOOT_KERNEL_CMDLINE_SH) $(AVBTOOL)
5841	@echo Creating $@
5842	(export AVBTOOL=$(AVBTOOL); $(MK_VBMETA_BOOT_KERNEL_CMDLINE_SH) $(INSTALLED_VBMETAIMAGE_TARGET) \
5843    $(INSTALLED_SYSTEMIMAGE_TARGET) $(QEMU_VERIFIED_BOOT_PARAMS))
5844
5845systemimage: $(QEMU_VERIFIED_BOOT_PARAMS)
5846droidcore-unbundled: $(QEMU_VERIFIED_BOOT_PARAMS)
5847
5848endif
5849# -----------------------------------------------------------------
5850# The emulator package
5851ifeq ($(BUILD_EMULATOR),true)
5852INTERNAL_EMULATOR_PACKAGE_FILES += \
5853        $(HOST_OUT_EXECUTABLES)/emulator$(HOST_EXECUTABLE_SUFFIX) \
5854        prebuilts/qemu-kernel/$(TARGET_ARCH)/kernel-qemu \
5855        $(INSTALLED_RAMDISK_TARGET) \
5856        $(INSTALLED_SYSTEMIMAGE_TARGET) \
5857        $(INSTALLED_USERDATAIMAGE_TARGET)
5858
5859name := $(TARGET_PRODUCT)-emulator-$(FILE_NAME_TAG)
5860
5861INTERNAL_EMULATOR_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
5862
5863$(INTERNAL_EMULATOR_PACKAGE_TARGET): $(INTERNAL_EMULATOR_PACKAGE_FILES)
5864	@echo "Package: $@"
5865	$(hide) zip -qjX $@ $(INTERNAL_EMULATOR_PACKAGE_FILES)
5866
5867endif
5868
5869
5870# -----------------------------------------------------------------
5871# The SDK
5872
5873# The SDK includes host-specific components, so it belongs under HOST_OUT.
5874sdk_dir := $(HOST_OUT)/sdk/$(TARGET_PRODUCT)
5875
5876# Build a name that looks like:
5877#
5878#     linux-x86   --> android-sdk_12345_linux-x86
5879#     darwin-x86  --> android-sdk_12345_mac-x86
5880#     windows-x86 --> android-sdk_12345_windows
5881#
5882sdk_name := android-sdk_$(FILE_NAME_TAG)
5883ifeq ($(HOST_OS),darwin)
5884  INTERNAL_SDK_HOST_OS_NAME := mac
5885else
5886  INTERNAL_SDK_HOST_OS_NAME := $(HOST_OS)
5887endif
5888ifneq ($(HOST_OS),windows)
5889  INTERNAL_SDK_HOST_OS_NAME := $(INTERNAL_SDK_HOST_OS_NAME)-$(SDK_HOST_ARCH)
5890endif
5891sdk_name := $(sdk_name)_$(INTERNAL_SDK_HOST_OS_NAME)
5892
5893sdk_dep_file := $(sdk_dir)/sdk_deps.mk
5894
5895ATREE_FILES :=
5896-include $(sdk_dep_file)
5897
5898# if we don't have a real list, then use "everything"
5899ifeq ($(strip $(ATREE_FILES)),)
5900ATREE_FILES := \
5901	$(ALL_DEFAULT_INSTALLED_MODULES) \
5902	$(INSTALLED_RAMDISK_TARGET) \
5903	$(ALL_DOCS) \
5904	$(ALL_SDK_FILES)
5905endif
5906
5907atree_dir := development/build
5908
5909
5910sdk_atree_files := \
5911	$(atree_dir)/sdk.exclude.atree \
5912	$(atree_dir)/sdk-$(HOST_OS)-$(SDK_HOST_ARCH).atree
5913
5914# development/build/sdk-android-<abi>.atree is used to differentiate
5915# between architecture models (e.g. ARMv5TE versus ARMv7) when copying
5916# files like the kernel image. We use TARGET_CPU_ABI because we don't
5917# have a better way to distinguish between CPU models.
5918ifneq (,$(strip $(wildcard $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree)))
5919  sdk_atree_files += $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree
5920endif
5921
5922ifneq ($(PRODUCT_SDK_ATREE_FILES),)
5923sdk_atree_files += $(PRODUCT_SDK_ATREE_FILES)
5924else
5925sdk_atree_files += $(atree_dir)/sdk.atree
5926endif
5927
5928include $(BUILD_SYSTEM)/sdk_font.mk
5929
5930deps := \
5931	$(target_notice_file_txt) \
5932	$(tools_notice_file_txt) \
5933	$(OUT_DOCS)/offline-sdk-timestamp \
5934	$(SDK_METADATA_FILES) \
5935	$(SYMBOLS_ZIP) \
5936	$(COVERAGE_ZIP) \
5937	$(APPCOMPAT_ZIP) \
5938	$(INSTALLED_SYSTEMIMAGE_TARGET) \
5939	$(INSTALLED_QEMU_SYSTEMIMAGE) \
5940	$(INSTALLED_QEMU_RAMDISKIMAGE) \
5941	$(INSTALLED_QEMU_VENDORIMAGE) \
5942	$(QEMU_VERIFIED_BOOT_PARAMS) \
5943	$(INSTALLED_USERDATAIMAGE_TARGET) \
5944	$(INSTALLED_RAMDISK_TARGET) \
5945	$(INSTALLED_SDK_BUILD_PROP_TARGET) \
5946	$(INSTALLED_BUILD_PROP_TARGET) \
5947	$(ATREE_FILES) \
5948	$(sdk_atree_files) \
5949	$(HOST_OUT_EXECUTABLES)/atree \
5950	$(HOST_OUT_EXECUTABLES)/line_endings \
5951	$(SDK_FONT_DEPS)
5952
5953INTERNAL_SDK_TARGET := $(sdk_dir)/$(sdk_name).zip
5954$(INTERNAL_SDK_TARGET): PRIVATE_NAME := $(sdk_name)
5955$(INTERNAL_SDK_TARGET): PRIVATE_DIR := $(sdk_dir)/$(sdk_name)
5956$(INTERNAL_SDK_TARGET): PRIVATE_DEP_FILE := $(sdk_dep_file)
5957$(INTERNAL_SDK_TARGET): PRIVATE_INPUT_FILES := $(sdk_atree_files)
5958
5959# Set SDK_GNU_ERROR to non-empty to fail when a GNU target is built.
5960#
5961#SDK_GNU_ERROR := true
5962
5963$(INTERNAL_SDK_TARGET): $(deps)
5964	@echo "Package SDK: $@"
5965	$(hide) rm -rf $(PRIVATE_DIR) $@
5966	$(hide) for f in $(target_gnu_MODULES); do \
5967	  if [ -f $$f ]; then \
5968	    echo SDK: $(if $(SDK_GNU_ERROR),ERROR:,warning:) \
5969	        including GNU target $$f >&2; \
5970	    FAIL=$(SDK_GNU_ERROR); \
5971	  fi; \
5972	done; \
5973	if [ $$FAIL ]; then exit 1; fi
5974	$(hide) echo $(notdir $(SDK_FONT_DEPS)) | tr " " "\n"  > $(SDK_FONT_TEMP)/fontsInSdk.txt
5975	$(hide) ( \
5976	    ATREE_STRIP="$(HOST_STRIP) -x" \
5977	    $(HOST_OUT_EXECUTABLES)/atree \
5978	    $(addprefix -f ,$(PRIVATE_INPUT_FILES)) \
5979	        -m $(PRIVATE_DEP_FILE) \
5980	        -I . \
5981	        -I $(PRODUCT_OUT) \
5982	        -I $(HOST_OUT) \
5983	        -I $(TARGET_COMMON_OUT_ROOT) \
5984	        -v "PLATFORM_NAME=android-$(PLATFORM_VERSION)" \
5985	        -v "OUT_DIR=$(OUT_DIR)" \
5986	        -v "HOST_OUT=$(HOST_OUT)" \
5987	        -v "TARGET_ARCH=$(TARGET_ARCH)" \
5988	        -v "TARGET_CPU_ABI=$(TARGET_CPU_ABI)" \
5989	        -v "DLL_EXTENSION=$(HOST_SHLIB_SUFFIX)" \
5990	        -v "FONT_OUT=$(SDK_FONT_TEMP)" \
5991	        -o $(PRIVATE_DIR) && \
5992	    cp -f $(target_notice_file_txt) \
5993	            $(PRIVATE_DIR)/system-images/android-$(PLATFORM_VERSION)/$(TARGET_CPU_ABI)/NOTICE.txt && \
5994	    cp -f $(tools_notice_file_txt) $(PRIVATE_DIR)/platform-tools/NOTICE.txt && \
5995	    HOST_OUT_EXECUTABLES=$(HOST_OUT_EXECUTABLES) HOST_OS=$(HOST_OS) \
5996	        development/build/tools/sdk_clean.sh $(PRIVATE_DIR) && \
5997	    chmod -R ug+rwX $(PRIVATE_DIR) && \
5998	    cd $(dir $@) && zip -rqX $(notdir $@) $(PRIVATE_NAME) \
5999	) || ( rm -rf $(PRIVATE_DIR) $@ && exit 44 )
6000
6001
6002# Is a Windows SDK requested? If so, we need some definitions from here
6003# in order to find the Linux SDK used to create the Windows one.
6004MAIN_SDK_NAME := $(sdk_name)
6005MAIN_SDK_DIR  := $(sdk_dir)
6006MAIN_SDK_ZIP  := $(INTERNAL_SDK_TARGET)
6007ifneq ($(filter win_sdk winsdk-tools,$(MAKECMDGOALS)),)
6008include $(TOPDIR)development/build/tools/windows_sdk.mk
6009endif
6010
6011# -----------------------------------------------------------------
6012# Findbugs
6013INTERNAL_FINDBUGS_XML_TARGET := $(PRODUCT_OUT)/findbugs.xml
6014INTERNAL_FINDBUGS_HTML_TARGET := $(PRODUCT_OUT)/findbugs.html
6015$(INTERNAL_FINDBUGS_XML_TARGET): $(ALL_FINDBUGS_FILES)
6016	@echo UnionBugs: $@
6017	$(hide) $(FINDBUGS_DIR)/unionBugs $(ALL_FINDBUGS_FILES) \
6018	> $@
6019$(INTERNAL_FINDBUGS_HTML_TARGET): $(INTERNAL_FINDBUGS_XML_TARGET)
6020	@echo ConvertXmlToText: $@
6021	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl \
6022	$(INTERNAL_FINDBUGS_XML_TARGET) > $@
6023
6024# -----------------------------------------------------------------
6025# Findbugs
6026
6027# -----------------------------------------------------------------
6028# These are some additional build tasks that need to be run.
6029ifneq ($(dont_bother),true)
6030include $(sort $(wildcard $(BUILD_SYSTEM)/tasks/*.mk))
6031-include $(sort $(wildcard vendor/*/build/tasks/*.mk))
6032-include $(sort $(wildcard device/*/build/tasks/*.mk))
6033-include $(sort $(wildcard product/*/build/tasks/*.mk))
6034# Also the project-specific tasks
6035-include $(sort $(wildcard vendor/*/*/build/tasks/*.mk))
6036-include $(sort $(wildcard device/*/*/build/tasks/*.mk))
6037-include $(sort $(wildcard product/*/*/build/tasks/*.mk))
6038# Also add test specifc tasks
6039include $(sort $(wildcard platform_testing/build/tasks/*.mk))
6040include $(sort $(wildcard test/vts/tools/build/tasks/*.mk))
6041endif
6042
6043include $(BUILD_SYSTEM)/product-graph.mk
6044
6045# -----------------------------------------------------------------
6046# Create SDK repository packages. Must be done after tasks/* since
6047# we need the addon rules defined.
6048ifneq ($(sdk_repo_goal),)
6049include $(TOPDIR)development/build/tools/sdk_repo.mk
6050endif
6051
6052# -----------------------------------------------------------------
6053# Soong generates the list of all shared libraries that are depended on by fuzz
6054# targets. It saves this list as a source:destination pair to
6055# FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS, where the source is the path to the
6056# build of the unstripped shared library, and the destination is the
6057# /data/fuzz/$ARCH/lib (for device) or /fuzz/$ARCH/lib (for host) directory
6058# where fuzz target shared libraries are to be "reinstalled". The
6059# copy-many-files below generates the rules to copy the unstripped shared
6060# libraries to the device or host "reinstallation" directory. These rules are
6061# depended on by each module in soong_cc_prebuilt.mk, where the module will have
6062# a dependency on each shared library that it needs to be "reinstalled".
6063FUZZ_SHARED_DEPS := $(call copy-many-files,$(strip $(FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS)))
6064
6065# -----------------------------------------------------------------
6066# The rule to build all fuzz targets for C++ and Rust, and package them.
6067# Note: The packages are created in Soong, and in a perfect world,
6068# we'd be able to create the phony rule there. But, if we want to
6069# have dist goals for the fuzz target, we need to have the PHONY
6070# target defined in make. MakeVarsContext.DistForGoal doesn't take
6071# into account that a PHONY rule create by Soong won't be available
6072# during make, and such will fail with `writing to readonly
6073# directory`, because kati will see 'haiku' as being a file, not a
6074# phony target.
6075.PHONY: haiku
6076haiku: $(SOONG_FUZZ_PACKAGING_ARCH_MODULES) $(ALL_FUZZ_TARGETS)
6077$(call dist-for-goals,haiku,$(SOONG_FUZZ_PACKAGING_ARCH_MODULES))
6078
6079.PHONY: haiku-rust
6080haiku-rust: $(SOONG_RUST_FUZZ_PACKAGING_ARCH_MODULES) $(ALL_RUST_FUZZ_TARGETS)
6081$(call dist-for-goals,haiku-rust,$(SOONG_RUST_FUZZ_PACKAGING_ARCH_MODULES))
6082