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
7SYSTEM_NOTICE_DEPS :=
8VENDOR_NOTICE_DEPS :=
9UNMOUNTED_NOTICE_DEPS :=
10UNMOUNTED_NOTICE_VENDOR_DEPS :=
11ODM_NOTICE_DEPS :=
12OEM_NOTICE_DEPS :=
13PRODUCT_NOTICE_DEPS :=
14SYSTEM_EXT_NOTICE_DEPS :=
15VENDOR_DLKM_NOTICE_DEPS :=
16ODM_DLKM_NOTICE_DEPS :=
17SYSTEM_DLKM_NOTICE_DEPS :=
18
19
20# IMAGES_TO_BUILD is a list of the partition .img files that will be created.
21IMAGES_TO_BUILD:=
22ifneq ($(BUILDING_BOOT_IMAGE),)
23  IMAGES_TO_BUILD += boot
24endif
25ifneq ($(BUILDING_CACHE_IMAGE),)
26  IMAGES_TO_BUILD += cache
27endif
28ifneq ($(BUILDING_DEBUG_BOOT_IMAGE),)
29  IMAGES_TO_BUILD += debug_boot
30endif
31ifneq ($(BUILDING_DEBUG_VENDOR_BOOT_IMAGE),)
32  IMAGES_TO_BUILD += debug_vendor_boot
33endif
34ifneq ($(BUILDING_INIT_BOOT_IMAGE),)
35  IMAGES_TO_BUILD += init_boot
36endif
37ifneq ($(BUILDING_ODM_DLKM_IMAGE),)
38  IMAGES_TO_BUILD += odm_dlkm
39endif
40ifneq ($(BUILDING_ODM_IMAGE),)
41  IMAGES_TO_BUILD += odm
42endif
43ifneq ($(BUILDING_PRODUCT_IMAGE),)
44  IMAGES_TO_BUILD += product
45endif
46ifneq ($(BUILDING_RAMDISK_IMAGE),)
47  IMAGES_TO_BUILD += ramdisk
48endif
49ifneq ($(BUILDING_RECOVERY_IMAGE),)
50  IMAGES_TO_BUILD += recovery
51endif
52ifneq ($(BUILDING_SUPER_EMPTY_IMAGE),)
53  IMAGES_TO_BUILD += super_empty
54endif
55ifneq ($(BUILDING_SYSTEM_DLKM_IMAGE),)
56  IMAGES_TO_BUILD += system_dlkm
57endif
58ifneq ($(BUILDING_SYSTEM_EXT_IMAGE),)
59  IMAGES_TO_BUILD += system_ext
60endif
61ifneq ($(BUILDING_SYSTEM_IMAGE),)
62  IMAGES_TO_BUILD += system
63endif
64ifneq ($(BUILDING_SYSTEM_OTHER_IMAGE),)
65  IMAGES_TO_BUILD += system_other
66endif
67ifneq ($(BUILDING_USERDATA_IMAGE),)
68  IMAGES_TO_BUILD += userdata
69endif
70ifneq ($(BUILDING_VBMETA_IMAGE),)
71  IMAGES_TO_BUILD += vbmeta
72endif
73ifneq ($(BUILDING_VENDOR_BOOT_IMAGE),)
74  IMAGES_TO_BUILD += vendor_boot
75endif
76ifneq ($(BUILDING_VENDOR_DLKM_IMAGE),)
77  IMAGES_TO_BUILD += vendor_dlkm
78endif
79ifneq ($(BUILDING_VENDOR_IMAGE),)
80  IMAGES_TO_BUILD += vendor
81endif
82ifneq ($(BUILDING_VENDOR_KERNEL_BOOT_IMAGE),)
83  IMAGES_TO_BUILD += vendor_kernel_boot
84endif
85
86
87###########################################################
88# Get the module names suitable for ALL_MODULES.* variables that are installed
89# for a given partition
90#
91# $(1): Partition
92###########################################################
93define register-names-for-partition
94$(sort $(foreach m,$(product_MODULES),\
95	$(if $(filter $(PRODUCT_OUT)/$(strip $(1))/%, $(ALL_MODULES.$(m).INSTALLED)), \
96		$(m)
97	) \
98))
99endef
100
101
102# Release & Aconfig Flags
103# -----------------------------------------------------------------
104include $(BUILD_SYSTEM)/packaging/flags.mk
105
106
107# -----------------------------------------------------------------
108# Define rules to copy PRODUCT_COPY_FILES defined by the product.
109# PRODUCT_COPY_FILES contains words like <source file>:<dest file>[:<owner>].
110# <dest file> is relative to $(PRODUCT_OUT), so it should look like,
111# e.g., "system/etc/file.xml".
112# The filter part means "only eval the copy-one-file rule if this
113# src:dest pair is the first one to match the same dest"
114#$(1): the src:dest pair
115#$(2): the dest
116define check-product-copy-files
117$(if $(filter-out $(TARGET_COPY_OUT_SYSTEM_OTHER)/%,$(2)), \
118  $(if $(filter %.apk, $(2)),$(error \
119     Prebuilt apk found in PRODUCT_COPY_FILES: $(1), use BUILD_PREBUILT instead!))) \
120$(if $(filter true,$(BUILD_BROKEN_VINTF_PRODUCT_COPY_FILES)),, \
121  $(if $(filter $(TARGET_COPY_OUT_SYSTEM)/etc/vintf/% \
122                $(TARGET_COPY_OUT_SYSTEM)/manifest.xml \
123                $(TARGET_COPY_OUT_SYSTEM)/compatibility_matrix.xml,$(2)), \
124    $(error VINTF metadata found in PRODUCT_COPY_FILES: $(1), use vintf_fragments instead!)) \
125  $(if $(filter $(TARGET_COPY_OUT_PRODUCT)/etc/vintf/%,$(2)), \
126    $(error VINTF metadata found in PRODUCT_COPY_FILES: $(1), \
127      use PRODUCT_MANIFEST_FILES / DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE / vintf_compatibility_matrix / vintf_fragments instead!)) \
128  $(if $(filter $(TARGET_COPY_OUT_SYSTEM_EXT)/etc/vintf/%,$(2)), \
129    $(error VINTF metadata found in PRODUCT_COPY_FILES: $(1), \
130      use vintf_compatibility_matrix / vintf_fragments instead!)) \
131  $(if $(filter $(TARGET_COPY_OUT_VENDOR)/etc/vintf/% \
132                $(TARGET_COPY_OUT_VENDOR)/manifest.xml \
133                $(TARGET_COPY_OUT_VENDOR)/compatibility_matrix.xml,$(2)), \
134    $(error VINTF metadata found in PRODUCT_COPY_FILES: $(1), \
135      use DEVICE_MANIFEST_FILE / DEVICE_MATRIX_FILE / vintf_compatibility_matrix / vintf_fragments instead!)) \
136  $(if $(filter $(TARGET_COPY_OUT_ODM)/etc/vintf/% \
137                $(TARGET_COPY_OUT_ODM)/etc/manifest%,$(2)), \
138    $(error VINTF metadata found in PRODUCT_COPY_FILES: $(1), \
139      use ODM_MANIFEST_FILES / vintf_fragments instead!)) \
140)
141endef
142
143# Phony target to check PRODUCT_COPY_FILES copy pairs don't contain ELF files
144.PHONY: check-elf-prebuilt-product-copy-files
145check-elf-prebuilt-product-copy-files:
146
147check_elf_prebuilt_product_copy_files := true
148ifneq (,$(filter true,$(BUILD_BROKEN_ELF_PREBUILT_PRODUCT_COPY_FILES)))
149check_elf_prebuilt_product_copy_files :=
150endif
151check_elf_prebuilt_product_copy_files_hint := \
152    found ELF prebuilt in PRODUCT_COPY_FILES, use cc_prebuilt_binary / cc_prebuilt_library_shared instead.
153
154# filter out the duplicate <source file>:<dest file> pairs.
155unique_product_copy_files_pairs :=
156$(foreach cf,$(PRODUCT_COPY_FILES), \
157    $(if $(filter $(unique_product_copy_files_pairs),$(cf)),,\
158        $(eval unique_product_copy_files_pairs += $(cf))))
159unique_product_copy_files_destinations :=
160product_copy_files_ignored :=
161$(foreach cf,$(unique_product_copy_files_pairs), \
162    $(eval _src := $(call word-colon,1,$(cf))) \
163    $(eval _dest := $(call word-colon,2,$(cf))) \
164    $(call check-product-copy-files,$(cf),$(_dest)) \
165    $(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \
166        $(eval product_copy_files_ignored += $(cf)), \
167        $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
168        $(if $(filter %.xml,$(_dest)),\
169            $(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\
170            $(if $(and $(filter %.jar,$(_dest)),$(filter $(basename $(notdir $(_dest))),$(PRODUCT_LOADED_BY_PRIVILEGED_MODULES))),\
171                $(eval $(call copy-and-uncompress-dexs,$(_src),$(_fulldest))), \
172                $(if $(filter init%rc,$(notdir $(_dest)))$(filter %/etc/init,$(dir $(_dest))),\
173                    $(eval $(call copy-init-script-file-checked,$(_src),$(_fulldest))),\
174                    $(if $(and $(filter true,$(check_elf_prebuilt_product_copy_files)), \
175                               $(filter bin lib lib64,$(subst /,$(space),$(_dest)))), \
176                        $(eval $(call copy-non-elf-file-checked,$(_src),$(_fulldest),$(check_elf_prebuilt_product_copy_files_hint))), \
177                        $(eval $(call copy-one-file,$(_src),$(_fulldest))))))) \
178        $(eval unique_product_copy_files_destinations += $(_dest))))
179
180# Dump a list of overriden (and ignored PRODUCT_COPY_FILES entries)
181pcf_ignored_file := $(PRODUCT_OUT)/product_copy_files_ignored.txt
182$(pcf_ignored_file): PRIVATE_IGNORED := $(sort $(product_copy_files_ignored))
183$(pcf_ignored_file):
184	echo "$(PRIVATE_IGNORED)" | tr " " "\n" >$@
185
186$(call declare-0p-target,$(pcf_ignored_file))
187
188$(call dist-for-goals,droidcore-unbundled,$(pcf_ignored_file):logs/$(notdir $(pcf_ignored_file)))
189
190pcf_ignored_file :=
191product_copy_files_ignored :=
192unique_product_copy_files_pairs :=
193unique_product_copy_files_destinations :=
194
195# -----------------------------------------------------------------
196# Returns the max allowed size for an image suitable for hash verification
197# (e.g., boot.img, recovery.img, etc).
198# The value 69632 derives from MAX_VBMETA_SIZE + MAX_FOOTER_SIZE in $(AVBTOOL).
199# $(1): partition size to flash the image
200define get-hash-image-max-size
201$(if $(1), \
202  $(if $(filter true,$(BOARD_AVB_ENABLE)), \
203    $(eval _hash_meta_size := 69632), \
204    $(eval _hash_meta_size := 0)) \
205  $(1)-$(_hash_meta_size))
206endef
207
208# -----------------------------------------------------------------
209# Define rules to copy headers defined in copy_headers.mk
210# If more than one makefile declared a header, print a warning,
211# then copy the last one defined. This matches the previous make
212# behavior.
213has_dup_copy_headers :=
214$(foreach dest,$(ALL_COPIED_HEADERS), \
215    $(eval _srcs := $(ALL_COPIED_HEADERS.$(dest).SRC)) \
216    $(eval _src := $(lastword $(_srcs))) \
217    $(if $(call streq,$(_src),$(_srcs)),, \
218        $(warning Duplicate header copy: $(dest)) \
219        $(warning _ Using $(_src)) \
220        $(warning __ from $(lastword $(ALL_COPIED_HEADERS.$(dest).MAKEFILE))) \
221        $(eval _makefiles := $$(wordlist 1,$(call int_subtract,$(words $(ALL_COPIED_HEADERS.$(dest).MAKEFILE)),1),$$(ALL_COPIED_HEADERS.$$(dest).MAKEFILE))) \
222        $(foreach src,$(wordlist 1,$(call int_subtract,$(words $(_srcs)),1),$(_srcs)), \
223            $(warning _ Ignoring $(src)) \
224            $(warning __ from $(firstword $(_makefiles))) \
225            $(eval _makefiles := $$(wordlist 2,9999,$$(_makefiles)))) \
226        $(eval has_dup_copy_headers := true)) \
227    $(eval $(call copy-one-header,$(_src),$(dest))))
228all_copied_headers: $(ALL_COPIED_HEADERS)
229
230ifdef has_dup_copy_headers
231  has_dup_copy_headers :=
232  $(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)
233endif
234
235$(file >$(PRODUCT_OUT)/.copied_headers_list,$(TARGET_OUT_HEADERS) $(ALL_COPIED_HEADERS))
236
237# -----------------------------------------------------------------
238# docs/index.html
239ifeq (,$(TARGET_BUILD_UNBUNDLED))
240gen := $(OUT_DOCS)/index.html
241ALL_DOCS += $(gen)
242$(gen): frameworks/base/docs/docs-redirect-index.html
243	@mkdir -p $(dir $@)
244	@cp -f $< $@
245endif
246
247ndk_doxygen_out := $(OUT_NDK_DOCS)
248ndk_headers := $(SOONG_OUT_DIR)/ndk/sysroot/usr/include
249ndk_docs_src_dir := frameworks/native/docs
250ndk_doxyfile := $(ndk_docs_src_dir)/Doxyfile
251ifneq ($(wildcard $(ndk_docs_src_dir)),)
252ndk_docs_srcs := $(addprefix $(ndk_docs_src_dir)/,\
253    $(call find-files-in-subdirs,$(ndk_docs_src_dir),"*",.))
254$(ndk_doxygen_out)/index.html: $(ndk_docs_srcs) $(SOONG_OUT_DIR)/ndk.timestamp
255	@mkdir -p $(ndk_doxygen_out)
256	@echo "Generating NDK docs to $(ndk_doxygen_out)"
257	@( cat $(ndk_doxyfile); \
258	    echo "INPUT=$(ndk_headers)"; \
259	    echo "HTML_OUTPUT=$(ndk_doxygen_out)" \
260	) | doxygen -
261
262$(call declare-1p-target,$(ndk_doxygen_out)/index.html,)
263
264# Note: Not a part of the docs target because we don't have doxygen available.
265# You can run this target locally if you have doxygen installed.
266ndk-docs: $(ndk_doxygen_out)/index.html
267.PHONY: ndk-docs
268endif
269
270ifeq ($(HOST_OS),linux)
271$(call dist-for-goals,sdk,$(API_FINGERPRINT))
272$(call dist-for-goals,droidcore,$(API_FINGERPRINT))
273endif
274
275INSTALLED_RECOVERYIMAGE_TARGET :=
276# Build recovery image if
277# BUILDING_RECOVERY_IMAGE && !BOARD_USES_RECOVERY_AS_BOOT && !BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT.
278# If BOARD_USES_RECOVERY_AS_BOOT is true, leave empty because INSTALLED_BOOTIMAGE_TARGET is built
279#   with recovery resources.
280# If BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT is true, leave empty to build recovery resources
281#   but not the final recovery image.
282ifdef BUILDING_RECOVERY_IMAGE
283ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
284ifneq ($(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT),true)
285INSTALLED_RECOVERYIMAGE_TARGET := $(PRODUCT_OUT)/recovery.img
286endif
287endif
288endif
289
290# Do this early because sysprop.mk depends on BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC.
291ifeq (default,$(ENABLE_UFFD_GC))
292BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC := $(OUT_DIR)/soong/dexpreopt/kernel_version_for_uffd_gc.txt
293endif # ENABLE_UFFD_GC
294
295include $(BUILD_SYSTEM)/sysprop.mk
296
297# ----------------------------------------------------------------
298
299# -----------------------------------------------------------------
300# sdk-build.prop
301#
302# There are certain things in build.prop that we don't want to
303# ship with the sdk; remove them.
304
305# This must be a list of entire property keys followed by
306# "=" characters, without any internal spaces.
307sdk_build_prop_remove := \
308	ro.build.user= \
309	ro.build.host= \
310	ro.product.brand= \
311	ro.product.manufacturer= \
312	ro.product.device=
313# TODO: Remove this soon-to-be obsolete property
314sdk_build_prop_remove += ro.build.product=
315INSTALLED_SDK_BUILD_PROP_TARGET := $(PRODUCT_OUT)/sdk/sdk-build.prop
316$(INSTALLED_SDK_BUILD_PROP_TARGET): $(INSTALLED_BUILD_PROP_TARGET)
317	@echo SDK buildinfo: $@
318	@mkdir -p $(dir $@)
319	$(hide) grep -v "$(subst $(space),\|,$(strip \
320	            $(sdk_build_prop_remove)))" $< > $@.tmp
321	$(hide) for x in $(strip $(sdk_build_prop_remove)); do \
322	            echo "$$x"generic >> $@.tmp; done
323	$(hide) mv $@.tmp $@
324
325$(call declare-0p-target,$(INSTALLED_SDK_BUILD_PROP_TARGET))
326
327# -----------------------------------------------------------------
328# declare recovery ramdisk files
329ifeq ($(BUILDING_RECOVERY_IMAGE),true)
330INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP := $(call intermediates-dir-for,PACKAGING,recovery)/ramdisk_files-timestamp
331endif
332
333# -----------------------------------------------------------------
334# Declare vendor ramdisk fragments
335INTERNAL_VENDOR_RAMDISK_FRAGMENTS :=
336
337ifeq (true,$(BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT))
338  ifneq (,$(filter recovery,$(BOARD_VENDOR_RAMDISK_FRAGMENTS)))
339    $(error BOARD_VENDOR_RAMDISK_FRAGMENTS must not contain "recovery" if \
340      BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT is set)
341  endif
342  INTERNAL_VENDOR_RAMDISK_FRAGMENTS += recovery
343  VENDOR_RAMDISK_FRAGMENT.recovery.STAGING_DIR := $(TARGET_RECOVERY_ROOT_OUT)
344  VENDOR_RAMDISK_FRAGMENT.recovery.FILES := $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
345  BOARD_VENDOR_RAMDISK_FRAGMENT.recovery.MKBOOTIMG_ARGS += --ramdisk_type RECOVERY
346  .KATI_READONLY := VENDOR_RAMDISK_FRAGMENT.recovery.STAGING_DIR
347endif
348
349# Validation check and assign default --ramdisk_type.
350$(foreach vendor_ramdisk_fragment,$(BOARD_VENDOR_RAMDISK_FRAGMENTS), \
351  $(if $(and $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).KERNEL_MODULE_DIRS), \
352             $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).PREBUILT)), \
353    $(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))) \
354  $(eval VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).STAGING_DIR := $(call intermediates-dir-for,PACKAGING,vendor_ramdisk_fragment-stage-$(vendor_ramdisk_fragment))) \
355  $(eval VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).FILES :=) \
356  $(if $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).KERNEL_MODULE_DIRS), \
357    $(if $(filter --ramdisk_type,$(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS)),, \
358      $(eval BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS += --ramdisk_type DLKM))) \
359)
360
361# Create the "kernel module directory" to "vendor ramdisk fragment" inverse mapping.
362$(foreach vendor_ramdisk_fragment,$(BOARD_VENDOR_RAMDISK_FRAGMENTS), \
363  $(foreach kmd,$(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).KERNEL_MODULE_DIRS), \
364    $(eval kmd_vrf := KERNEL_MODULE_DIR_VENDOR_RAMDISK_FRAGMENT_$(kmd)) \
365    $(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)) \
366    $(eval $(kmd_vrf) := $(vendor_ramdisk_fragment)) \
367  ) \
368)
369INTERNAL_VENDOR_RAMDISK_FRAGMENTS += $(BOARD_VENDOR_RAMDISK_FRAGMENTS)
370
371ifneq ($(BOARD_KERNEL_MODULES_16K),)
372INTERNAL_VENDOR_RAMDISK_FRAGMENTS += 16K
373endif
374
375# Strip the list in case of any whitespace.
376INTERNAL_VENDOR_RAMDISK_FRAGMENTS := \
377  $(strip $(INTERNAL_VENDOR_RAMDISK_FRAGMENTS))
378
379# Assign --ramdisk_name for each vendor ramdisk fragment.
380$(foreach vendor_ramdisk_fragment,$(INTERNAL_VENDOR_RAMDISK_FRAGMENTS), \
381  $(if $(filter --ramdisk_name,$(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS)), \
382    $(error Must not specify --ramdisk_name for vendor ramdisk fragment: $(vendor_ramdisk_fragment))) \
383  $(eval BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS += --ramdisk_name $(vendor_ramdisk_fragment)) \
384  $(eval .KATI_READONLY := BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS) \
385)
386
387# -----------------------------------------------------------------
388# kernel modules
389
390# Depmod requires a well-formed kernel version so 0.0 is used as a placeholder.
391DEPMOD_STAGING_SUBDIR :=$= lib/modules/0.0
392
393define copy-and-strip-kernel-module
394$(2): $(1)
395	$(LLVM_STRIP) -o $(2) --strip-debug $(1)
396endef
397
398# $(1): modules list
399# $(2): output dir
400# $(3): mount point
401# $(4): staging dir
402# $(5): module load list
403# $(6): module load list filename
404# $(7): module archive
405# $(8): staging dir for stripped modules
406# $(9): module directory name
407# $(10): extra modules that might be dependency of modules in this partition, but should not be copied to output dir
408# $(11): mount point for extra modules
409# Returns a list of src:dest pairs to install the modules using copy-many-files.
410define build-image-kernel-modules
411  $(if $(9), \
412    $(eval _dir := $(9)/), \
413    $(eval _dir :=)) \
414  $(foreach module,$(1), \
415    $(eval _src := $(module)) \
416    $(if $(8), \
417      $(eval _src := $(8)/$(notdir $(module))) \
418      $(eval $(call copy-and-strip-kernel-module,$(module),$(_src)))) \
419    $(_src):$(2)/lib/modules/$(_dir)$(notdir $(module))) \
420  $(eval $(call build-image-kernel-modules-depmod,$(1),$(3),$(4),$(5),$(6),$(7),$(2),$(9),$(10),$(11))) \
421  $(4)/$(DEPMOD_STAGING_SUBDIR)/modules.dep:$(2)/lib/modules/$(_dir)modules.dep \
422  $(4)/$(DEPMOD_STAGING_SUBDIR)/modules.alias:$(2)/lib/modules/$(_dir)modules.alias \
423  $(4)/$(DEPMOD_STAGING_SUBDIR)/modules.softdep:$(2)/lib/modules/$(_dir)modules.softdep \
424  $(4)/$(DEPMOD_STAGING_SUBDIR)/$(6):$(2)/lib/modules/$(_dir)$(6)
425endef
426
427# $(1): modules list
428# $(2): mount point
429# $(3): staging dir
430# $(4): module load list
431# $(5): module load list filename
432# $(6): module archive
433# $(7): output dir
434# $(8): module directory name
435# $(9): extra modules which should not be copied to output dir, but might be dependency of modules in this partition
436# $(10): mount point for extra modules
437# TODO(b/144844424): If a module archive is being used, this step (which
438# generates obj/PACKAGING/.../modules.dep) also unzips the module archive into
439# the output directory. This should be moved to a module with a
440# LOCAL_POST_INSTALL_CMD so that if modules.dep is removed from the output dir,
441# the archive modules are restored along with modules.dep.
442define build-image-kernel-modules-depmod
443$(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)
444$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: $(DEPMOD)
445$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_MODULES := $(strip $(1))
446$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_EXTRA_MODULES := $(strip $(9))
447$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_MOUNT_POINT := $(2)
448$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_EXTRA_MOUNT_POINT := $(10)
449$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_MODULE_DIR := $(3)/$(DEPMOD_STAGING_SUBDIR)/$(2)/lib/modules/$(8)
450$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_EXTRA_MODULE_DIR := $(3)/$(DEPMOD_STAGING_SUBDIR)/$(10)/lib/modules/$(8)
451$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_STAGING_DIR := $(3)
452$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_LOAD_MODULES := $(strip $(4))
453$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_LOAD_FILE := $(3)/$(DEPMOD_STAGING_SUBDIR)/$(5)
454$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_MODULE_ARCHIVE := $(6)
455$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: PRIVATE_OUTPUT_DIR := $(7)
456$(3)/$(DEPMOD_STAGING_SUBDIR)/modules.dep: $(1) $(6)
457	@echo depmod $$(PRIVATE_STAGING_DIR)
458	rm -rf $$(PRIVATE_STAGING_DIR)
459	mkdir -p $$(PRIVATE_MODULE_DIR)
460	$(if $(6),\
461	  unzip -qoDD -d $$(PRIVATE_MODULE_DIR) $$(PRIVATE_MODULE_ARCHIVE); \
462	  mkdir -p $$(PRIVATE_OUTPUT_DIR)/lib; \
463	  cp -r  $(3)/$(DEPMOD_STAGING_SUBDIR)/$(2)/lib/modules $$(PRIVATE_OUTPUT_DIR)/lib/; \
464	  find $$(PRIVATE_MODULE_DIR) -type f -name '*.ko' | xargs basename -a > $$(PRIVATE_LOAD_FILE); \
465	)
466	$(if $(1),\
467	  cp $$(PRIVATE_MODULES) $$(PRIVATE_MODULE_DIR)/; \
468	  if [ -n "$$(PRIVATE_LOAD_MODULES)" ]; then basename -a $$(PRIVATE_LOAD_MODULES); fi > $$(PRIVATE_LOAD_FILE); \
469	)
470	# The ln -sf + find -delete sequence is to remove any modules in
471	# PRIVATE_EXTRA_MODULES which have same basename as MODULES in PRIVATE_MODULES
472	# Basically, it computes a set difference. When there is a duplicate module
473	# present in both directories, we want modules in PRIVATE_MODULES to take
474	# precedence. Since depmod does not provide any guarantee about ordering of
475	# dependency resolution, we achieve this by maually removing any duplicate
476	# modules with lower priority.
477	$(if $(9),\
478	  mkdir -p $$(PRIVATE_EXTRA_MODULE_DIR); \
479	  find $$(PRIVATE_EXTRA_MODULE_DIR) -maxdepth 1 -type f -name "*.ko" -delete; \
480	  cp $$(PRIVATE_EXTRA_MODULES) $$(PRIVATE_EXTRA_MODULE_DIR); \
481	  ln -sf $$(PRIVATE_MODULE_DIR)/*.ko $$(PRIVATE_EXTRA_MODULE_DIR); \
482	  find $$(PRIVATE_EXTRA_MODULE_DIR) -type l -delete; \
483	)
484	$(DEPMOD) -b $$(PRIVATE_STAGING_DIR) 0.0
485	# Turn paths in modules.dep into absolute paths
486	sed -i.tmp -e 's|\([^: ]*lib/modules/[^: ]*\)|/\1|g' $$(PRIVATE_STAGING_DIR)/$$(DEPMOD_STAGING_SUBDIR)/modules.dep
487	touch $$(PRIVATE_LOAD_FILE)
488endef
489
490# $(1): staging dir
491# $(2): modules list
492# $(3): module load list
493# $(4): module load list filename
494# $(5): output dir
495define module-load-list-copy-paths
496  $(eval $(call build-image-module-load-list,$(1),$(2),$(3),$(4))) \
497  $(1)/$(DEPMOD_STAGING_SUBDIR)/$(4):$(5)/lib/modules/$(4)
498endef
499
500# $(1): staging dir
501# $(2): modules list
502# $(3): module load list
503# $(4): module load list filename
504define build-image-module-load-list
505$(1)/$(DEPMOD_STAGING_SUBDIR)/$(4): PRIVATE_LOAD_MODULES := $(3)
506$(1)/$(DEPMOD_STAGING_SUBDIR)/$(4): $(2)
507	@echo load-list $$(@)
508	@echo '$$(strip $$(notdir $$(PRIVATE_LOAD_MODULES)))' | tr ' ' '\n' > $$(@)
509endef
510
511# $(1): source options file
512# $(2): destination pathname
513# Returns a build rule that checks the syntax of and installs a kernel modules
514# options file. Strip and squeeze any extra space and blank lines.
515# For use via $(eval).
516define build-image-kernel-modules-options-file
517$(2): $(1)
518	@echo "libmodprobe options $$(@)"
519	$(hide) mkdir -p "$$(dir $$@)"
520	$(hide) rm -f "$$@"
521	$(hide) awk <"$$<" >"$$@" \
522	  '/^#/ { print; next } \
523	   NF == 0 { next } \
524	   NF < 2 || $$$$1 != "options" \
525	     { print "Invalid options line " FNR ": " $$$$0 >"/dev/stderr"; \
526	       exit_status = 1; next } \
527	   { $$$$1 = $$$$1; print } \
528	   END { exit exit_status }'
529endef
530
531# $(1): source blocklist file
532# $(2): destination pathname
533# Returns a build rule that checks the syntax of and installs a kernel modules
534# blocklist file. Strip and squeeze any extra space and blank lines.
535# For use via $(eval).
536define build-image-kernel-modules-blocklist-file
537$(2): $(1)
538	@echo "libmodprobe blocklist $$(@)"
539	$(hide) mkdir -p "$$(dir $$@)"
540	$(hide) rm -f "$$@"
541	$(hide) awk <"$$<" >"$$@" \
542	  '/^#/ { print; next } \
543	   NF == 0 { next } \
544	   NF != 2 || $$$$1 != "blocklist" \
545	     { print "Invalid blocklist line " FNR ": " $$$$0 >"/dev/stderr"; \
546	       exit_status = 1; next } \
547	   { $$$$1 = $$$$1; print } \
548	   END { exit exit_status }'
549endef
550
551# $(1): image name
552# $(2): build output directory (TARGET_OUT_VENDOR, TARGET_RECOVERY_ROOT_OUT, etc)
553# $(3): mount point
554# $(4): module load filename
555# $(5): stripped staging directory
556# $(6): kernel module directory name (top is an out of band value for no directory)
557# $(7): list of extra modules that might be dependency of modules in this partition
558# $(8): mount point for extra modules. e.g. system
559
560define build-image-kernel-modules-dir
561$(if $(filter top,$(6)),\
562  $(eval _kver :=)$(eval _sep :=),\
563  $(eval _kver := $(6))$(eval _sep :=_))\
564$(if $(5),\
565  $(eval _stripped_staging_dir := $(5)$(_sep)$(_kver)),\
566  $(eval _stripped_staging_dir :=))\
567$(if $(strip $(BOARD_$(1)_KERNEL_MODULES$(_sep)$(_kver))$(BOARD_$(1)_KERNEL_MODULES_ARCHIVE$(_sep)$(_kver))),\
568  $(if $(BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver)),,\
569    $(eval BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver) := $(BOARD_$(1)_KERNEL_MODULES$(_sep)$(_kver)))) \
570  $(if $(filter false,$(BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver))),\
571    $(eval BOARD_$(1)_KERNEL_MODULES_LOAD$(_sep)$(_kver) :=),) \
572  $(eval _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),$(7),$(8))) \
573  $(call copy-many-files,$(_files)) \
574  $(eval _modules := $(BOARD_$(1)_KERNEL_MODULES$(_sep)$(_kver)) ANDROID-GEN ANDROID-GEN ANDROID-GEN ANDROID-GEN) \
575  $(eval KERNEL_MODULE_COPY_FILES += $(join $(addsuffix :,$(_modules)),$(_files)))) \
576$(if $(_kver), \
577  $(eval _dir := $(_kver)/), \
578  $(eval _dir :=)) \
579$(if $(BOARD_$(1)_KERNEL_MODULES_OPTIONS_FILE$(_sep)$(_kver)), \
580  $(eval $(call build-image-kernel-modules-options-file, \
581    $(BOARD_$(1)_KERNEL_MODULES_OPTIONS_FILE$(_sep)$(_kver)), \
582    $(2)/lib/modules/$(_dir)modules.options)) \
583  $(2)/lib/modules/$(_dir)modules.options) \
584$(if $(BOARD_$(1)_KERNEL_MODULES_BLOCKLIST_FILE$(_sep)$(_kver)), \
585  $(eval $(call build-image-kernel-modules-blocklist-file, \
586    $(BOARD_$(1)_KERNEL_MODULES_BLOCKLIST_FILE$(_sep)$(_kver)), \
587    $(2)/lib/modules/$(_dir)modules.blocklist)) \
588  $(eval ALL_KERNEL_MODULES_BLOCKLIST += $(2)/lib/modules/$(_dir)modules.blocklist) \
589  $(2)/lib/modules/$(_dir)modules.blocklist)
590endef
591
592# $(1): kernel module directory name (top is an out of band value for no directory)
593define build-recovery-as-boot-load
594$(if $(filter top,$(1)),\
595  $(eval _kver :=)$(eval _sep :=),\
596  $(eval _kver := $(1))$(eval _sep :=_))\
597  $(if $(BOARD_GENERIC_RAMDISK_KERNEL_MODULES_LOAD$(_sep)$(_kver)),\
598    $(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))))
599endef
600
601# $(1): kernel module directory name (top is an out of band value for no directory)
602define build-vendor-ramdisk-recovery-load
603$(if $(filter top,$(1)),\
604  $(eval _kver :=)$(eval _sep :=),\
605  $(eval _kver := $(1))$(eval _sep :=_))\
606  $(if $(BOARD_VENDOR_RAMDISK_RECOVERY_KERNEL_MODULES_LOAD$(_sep)$(_kver)),\
607    $(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))))
608endef
609
610# $(1): kernel module directory name (top is an out of band value for no directory)
611define build-vendor-kernel-ramdisk-recovery-load
612$(if $(filter top,$(1)),\
613  $(eval _kver :=)$(eval _sep :=),\
614  $(eval _kver := $(1))$(eval _sep :=_))\
615  $(if $(BOARD_VENDOR_KERNEL_RAMDISK_RECOVERY_KERNEL_MODULES_LOAD$(_sep)$(_kver)),\
616    $(call copy-many-files,$(call module-load-list-copy-paths,$(call intermediates-dir-for,PACKAGING,vendor_kernel_ramdisk_recovery_module_list$(_sep)$(_kver)),$(BOARD_VENDOR_KERNEL_RAMDISK_KERNEL_MODULES$(_sep)$(_kver)),$(BOARD_VENDOR_KERNEL_RAMDISK_RECOVERY_KERNEL_MODULES_LOAD$(_sep)$(_kver)),modules.load.recovery,$(TARGET_VENDOR_KERNEL_RAMDISK_OUT))))
617endef
618
619# $(1): kernel module directory name (top is an out of band value for no directory)
620define build-vendor-charger-load
621$(if $(filter top,$(1)),\
622  $(eval _kver :=)$(eval _sep :=),\
623  $(eval _kver := $(1))$(eval _sep :=_))\
624  $(if $(BOARD_VENDOR_CHARGER_KERNEL_MODULES_LOAD$(_sep)$(_kver)),\
625    $(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))))
626endef
627
628# $(1): kernel module directory name (top is an out of band value for no directory)
629define build-vendor-ramdisk-charger-load
630$(if $(filter top,$(1)),\
631  $(eval _kver :=)$(eval _sep :=),\
632  $(eval _kver := $(1))$(eval _sep :=_))\
633  $(if $(BOARD_VENDOR_RAMDISK_CHARGER_KERNEL_MODULES_LOAD$(_sep)$(_kver)),\
634    $(call copy-many-files,$(call module-load-list-copy-paths,$(call intermediates-dir-for,PACKAGING,vendor_ramdisk_charger_module_list$(_sep)$(_kver)),$(BOARD_VENDOR_RAMDISK_KERNEL_MODULES$(_sep)$(_kver)),$(BOARD_VENDOR_RAMDISK_CHARGER_KERNEL_MODULES_LOAD$(_sep)$(_kver)),modules.load.charger,$(TARGET_VENDOR_RAMDISK_OUT))))
635endef
636
637# $(1): kernel module directory name (top is an out of band value for no directory)
638define build-vendor-kernel-ramdisk-charger-load
639$(if $(filter top,$(1)),\
640  $(eval _kver :=)$(eval _sep :=),\
641  $(eval _kver := $(1))$(eval _sep :=_))\
642  $(if $(BOARD_VENDOR_KERNEL_RAMDISK_CHARGER_KERNEL_MODULES_LOAD$(_sep)$(_kver)),\
643    $(call copy-many-files,$(call module-load-list-copy-paths,$(call intermediates-dir-for,PACKAGING,vendor_kernel_ramdisk_charger_module_list$(_sep)$(_kver)),$(BOARD_VENDOR_KERNEL_RAMDISK_KERNEL_MODULES$(_sep)$(_kver)),$(BOARD_VENDOR_KERNEL_RAMDISK_CHARGER_KERNEL_MODULES_LOAD$(_sep)$(_kver)),modules.load.charger,$(TARGET_VENDOR_KERNEL_RAMDISK_OUT))))
644endef
645
646ifneq ($(BUILDING_VENDOR_BOOT_IMAGE),true)
647  # If there is no vendor boot partition, store vendor ramdisk kernel modules in the
648  # boot ramdisk.
649  BOARD_GENERIC_RAMDISK_KERNEL_MODULES += $(BOARD_VENDOR_RAMDISK_KERNEL_MODULES)
650  BOARD_GENERIC_RAMDISK_KERNEL_MODULES_LOAD += $(BOARD_VENDOR_RAMDISK_KERNEL_MODULES_LOAD)
651endif
652
653ifeq ($(BOARD_GENERIC_RAMDISK_KERNEL_MODULES_LOAD),)
654  BOARD_GENERIC_RAMDISK_KERNEL_MODULES_LOAD := $(BOARD_GENERIC_RAMDISK_KERNEL_MODULES)
655endif
656
657ifneq ($(strip $(BOARD_GENERIC_RAMDISK_KERNEL_MODULES)),)
658  ifeq ($(BOARD_USES_RECOVERY_AS_BOOT), true)
659    BOARD_RECOVERY_KERNEL_MODULES += $(BOARD_GENERIC_RAMDISK_KERNEL_MODULES)
660  endif
661endif
662
663ifneq ($(BOARD_DO_NOT_STRIP_GENERIC_RAMDISK_MODULES),true)
664  GENERIC_RAMDISK_STRIPPED_MODULE_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_generic_ramdisk_kernel_stripped)
665else
666  GENERIC_RAMDISK_STRIPPED_MODULE_STAGING_DIR :=
667endif
668
669ifneq ($(BOARD_DO_NOT_STRIP_RECOVERY_MODULES),true)
670	RECOVERY_STRIPPED_MODULE_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_recovery_stripped)
671else
672	RECOVERY_STRIPPED_MODULE_STAGING_DIR :=
673endif
674
675ifneq ($(BOARD_DO_NOT_STRIP_VENDOR_MODULES),true)
676	VENDOR_STRIPPED_MODULE_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_vendor_stripped)
677else
678	VENDOR_STRIPPED_MODULE_STAGING_DIR :=
679endif
680
681ifneq ($(BOARD_DO_NOT_STRIP_VENDOR_RAMDISK_MODULES),true)
682  VENDOR_RAMDISK_STRIPPED_MODULE_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_vendor_ramdisk_stripped)
683else
684  VENDOR_RAMDISK_STRIPPED_MODULE_STAGING_DIR :=
685endif
686
687ifneq ($(BOARD_DO_NOT_STRIP_VENDOR_KERNEL_RAMDISK_MODULES),true)
688  VENDOR_KERNEL_RAMDISK_STRIPPED_MODULE_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_vendor_kernel_ramdisk_stripped)
689else
690  VENDOR_KERNEL_RAMDISK_STRIPPED_MODULE_STAGING_DIR :=
691endif
692
693BOARD_KERNEL_MODULE_DIRS += top
694
695# Default to not generating modules.dep for kernel modules on system
696# side. We should only load these modules if they are depended by vendor
697# side modules.
698ifeq ($(BOARD_SYSTEM_KERNEL_MODULES_LOAD),)
699  BOARD_SYSTEM_KERNEL_MODULES_LOAD := false
700endif
701
702$(foreach kmd,$(BOARD_KERNEL_MODULE_DIRS), \
703  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-image-kernel-modules-dir,RECOVERY,$(TARGET_RECOVERY_ROOT_OUT),,modules.load.recovery,$(RECOVERY_STRIPPED_MODULE_STAGING_DIR),$(kmd))) \
704  $(eval vendor_ramdisk_fragment := $(KERNEL_MODULE_DIR_VENDOR_RAMDISK_FRAGMENT_$(kmd))) \
705  $(if $(vendor_ramdisk_fragment), \
706    $(eval output_dir := $(VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).STAGING_DIR)) \
707    $(eval result_var := VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).FILES) \
708    $(eval ### else ###), \
709    $(eval output_dir := $(TARGET_VENDOR_RAMDISK_OUT)) \
710    $(eval result_var := ALL_DEFAULT_INSTALLED_MODULES)) \
711  $(eval $(result_var) += $(call build-image-kernel-modules-dir,VENDOR_RAMDISK,$(output_dir),,modules.load,$(VENDOR_RAMDISK_STRIPPED_MODULE_STAGING_DIR),$(kmd))) \
712  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-image-kernel-modules-dir,VENDOR_KERNEL_RAMDISK,$(TARGET_VENDOR_KERNEL_RAMDISK_OUT),,modules.load,$(VENDOR_KERNEL_RAMDISK_STRIPPED_MODULE_STAGING_DIR),$(kmd))) \
713  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-vendor-ramdisk-recovery-load,$(kmd))) \
714  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-vendor-kernel-ramdisk-recovery-load,$(kmd))) \
715  $(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),$(BOARD_SYSTEM_KERNEL_MODULES),system)) \
716  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-vendor-charger-load,$(kmd))) \
717  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-vendor-ramdisk-charger-load,$(kmd))) \
718  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-vendor-kernel-ramdisk-charger-load,$(kmd))) \
719  $(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))) \
720  $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-image-kernel-modules-dir,SYSTEM,$(if $(filter true,$(BOARD_USES_SYSTEM_DLKMIMAGE)),$(TARGET_OUT_SYSTEM_DLKM),$(TARGET_OUT_SYSTEM)),system,modules.load,,$(kmd))) \
721  $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
722    $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-recovery-as-boot-load,$(kmd))),\
723    $(eval ALL_DEFAULT_INSTALLED_MODULES += $(call build-image-kernel-modules-dir,GENERIC_RAMDISK,$(TARGET_RAMDISK_OUT),,modules.load,$(GENERIC_RAMDISK_STRIPPED_MODULE_STAGING_DIR),$(kmd)))))
724
725ifeq ($(BOARD_SYSTEM_KERNEL_MODULES),)
726ifneq ($(BOARD_SYSTEM_DLKM_SRC),)
727ifneq ($(wildcard $(BOARD_SYSTEM_DLKM_SRC)/*),)
728  SYSTEM_KERNEL_MODULES := $(shell find $(BOARD_SYSTEM_DLKM_SRC) -type f)
729  SRC_SYSTEM_KERNEL_MODULES := $(SYSTEM_KERNEL_MODULES)
730  DST_SYSTEM_KERNEL_MODULES := $(patsubst $(BOARD_SYSTEM_DLKM_SRC)/%,:$(TARGET_OUT_SYSTEM_DLKM)/%,$(SRC_SYSTEM_KERNEL_MODULES))
731  SYSTEM_KERNEL_MODULE_COPY_PAIRS := $(join $(SRC_SYSTEM_KERNEL_MODULES),$(DST_SYSTEM_KERNEL_MODULES))
732  ALL_DEFAULT_INSTALLED_MODULES += $(call copy-many-files,$(SYSTEM_KERNEL_MODULE_COPY_PAIRS))
733endif
734endif
735endif
736
737
738# -----------------------------------------------------------------
739# Cert-to-package mapping.  Used by the post-build signing tools.
740# Use a macro to add newline to each echo command
741# $1 stem name of the package
742# $2 certificate
743# $3 private key
744# $4 compressed
745# $5 partition tag
746# $6 output file
747define _apkcerts_write_line
748$(hide) echo -n 'name="$(1).apk" certificate="$2" private_key="$3"' >> $6
749$(if $(4), $(hide) echo -n ' compressed="$4"' >> $6)
750$(if $(5), $(hide) echo -n ' partition="$5"' >> $6)
751$(hide) echo '' >> $6
752
753endef
754
755# -----------------------------------------------------------------
756# Merge an individual apkcerts output into the final apkcerts.txt output.
757# Use a macro to make it compatible with _apkcerts_write_line
758# $1 apkcerts file to be merged
759# $2 output file
760define _apkcerts_merge
761$(hide) cat $1 >> $2
762
763endef
764
765name := $(TARGET_PRODUCT)
766ifeq ($(TARGET_BUILD_TYPE),debug)
767  name := $(name)_debug
768endif
769name := $(name)-apkcerts
770intermediates := \
771	$(call intermediates-dir-for,PACKAGING,apkcerts)
772APKCERTS_FILE := $(intermediates)/$(name).txt
773all_apkcerts_files := $(sort $(foreach p,$(PACKAGES),$(PACKAGES.$(p).APKCERTS_FILE)))
774$(APKCERTS_FILE): $(all_apkcerts_files)
775# We don't need to really build all the modules.
776# TODO: rebuild APKCERTS_FILE if any app change its cert.
777$(APKCERTS_FILE):
778	@echo APK certs list: $@
779	@mkdir -p $(dir $@)
780	@rm -f $@
781	$(foreach p,$(sort $(PACKAGES)),\
782	  $(if $(PACKAGES.$(p).APKCERTS_FILE),\
783	    $(call _apkcerts_merge,$(PACKAGES.$(p).APKCERTS_FILE), $@),\
784	    $(if $(PACKAGES.$(p).EXTERNAL_KEY),\
785	      $(call _apkcerts_write_line,$(PACKAGES.$(p).STEM),EXTERNAL,,$(PACKAGES.$(p).COMPRESSED),$(PACKAGES.$(p).PARTITION),$@),\
786	      $(call _apkcerts_write_line,$(PACKAGES.$(p).STEM),$(PACKAGES.$(p).CERTIFICATE),$(PACKAGES.$(p).PRIVATE_KEY),$(PACKAGES.$(p).COMPRESSED),$(PACKAGES.$(p).PARTITION),$@))))
787	$(if $(filter true,$(PRODUCT_FSVERITY_GENERATE_METADATA)),\
788	  $(call _apkcerts_write_line,BuildManifest,$(FSVERITY_APK_KEY_PATH).x509.pem,$(FSVERITY_APK_KEY_PATH).pk8,,system,$@) \
789	  $(if $(filter true,$(BUILDING_SYSTEM_EXT_IMAGE)),\
790            $(call _apkcerts_write_line,BuildManifestSystemExt,$(FSVERITY_APK_KEY_PATH).x509.pem,$(FSVERITY_APK_KEY_PATH).pk8,,system_ext,$@)))
791	# In case value of PACKAGES is empty.
792	$(hide) touch $@
793
794$(call declare-0p-target,$(APKCERTS_FILE))
795
796.PHONY: apkcerts-list
797apkcerts-list: $(APKCERTS_FILE)
798
799intermediates := $(call intermediates-dir-for,PACKAGING,apexkeys)
800APEX_KEYS_FILE := $(intermediates)/apexkeys.txt
801
802all_apex_keys_files := $(sort $(foreach m,$(call product-installed-modules,$(INTERNAL_PRODUCT)),$(ALL_MODULES.$(m).APEX_KEYS_FILE)))
803$(APEX_KEYS_FILE): $(all_apex_keys_files)
804	@mkdir -p $(dir $@)
805	@rm -f $@
806	$(hide) touch $@
807	$(hide) $(foreach file,$^,cat $(file) >> $@ $(newline))
808all_apex_keys_files :=
809
810$(call declare-0p-target,$(APEX_KEYS_FILE))
811
812.PHONY: apexkeys.txt
813apexkeys.txt: $(APEX_KEYS_FILE)
814
815ifneq (,$(TARGET_BUILD_APPS))
816  $(call dist-for-goals, apps_only, $(APKCERTS_FILE):apkcerts.txt)
817  $(call dist-for-goals, apps_only, $(APEX_KEYS_FILE):apexkeys.txt)
818endif
819
820
821# -----------------------------------------------------------------
822# build system stats
823BUILD_SYSTEM_STATS := $(PRODUCT_OUT)/build_system_stats.txt
824$(BUILD_SYSTEM_STATS):
825	@rm -f $@
826	@$(foreach s,$(STATS.MODULE_TYPE),echo "modules_type_make,$(s),$(words $(STATS.MODULE_TYPE.$(s)))" >>$@;)
827	@$(foreach s,$(STATS.SOONG_MODULE_TYPE),echo "modules_type_soong,$(s),$(STATS.SOONG_MODULE_TYPE.$(s))" >>$@;)
828$(call declare-1p-target,$(BUILD_SYSTEM_STATS),build)
829$(call dist-for-goals,droidcore-unbundled,$(BUILD_SYSTEM_STATS))
830
831# -----------------------------------------------------------------
832# build /product/etc/security/avb/system_other.avbpubkey if needed
833ifdef BUILDING_SYSTEM_OTHER_IMAGE
834ifeq ($(BOARD_AVB_ENABLE),true)
835INSTALLED_PRODUCT_SYSTEM_OTHER_AVBKEY_TARGET := $(TARGET_OUT_PRODUCT_ETC)/security/avb/system_other.avbpubkey
836ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_PRODUCT_SYSTEM_OTHER_AVBKEY_TARGET)
837endif # BOARD_AVB_ENABLE
838endif # BUILDING_SYSTEM_OTHER_IMAGE
839
840# -----------------------------------------------------------------
841# Modules ready to be converted to Soong, ordered by how many
842# modules depend on them.
843SOONG_CONV := $(sort $(SOONG_CONV))
844SOONG_CONV_DATA := $(call intermediates-dir-for,PACKAGING,soong_conversion)/soong_conv_data
845$(SOONG_CONV_DATA):
846	@rm -f $@
847	@$(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))" >>$@;)
848
849$(call declare-1p-target,$(SOONG_CONV_DATA),build)
850
851SOONG_TO_CONVERT_SCRIPT := build/make/tools/soong_to_convert.py
852SOONG_TO_CONVERT := $(PRODUCT_OUT)/soong_to_convert.txt
853$(SOONG_TO_CONVERT): $(SOONG_CONV_DATA) $(SOONG_TO_CONVERT_SCRIPT)
854	@rm -f $@
855	$(hide) $(SOONG_TO_CONVERT_SCRIPT) $< >$@
856$(call declare-1p-target,$(SOONG_TO_CONVERT),build)
857$(call dist-for-goals,droidcore-unbundled,$(SOONG_TO_CONVERT))
858
859$(PRODUCT_OUT)/product_packages.txt:
860	@rm -f $@
861	echo "" > $@
862	$(foreach x,$(PRODUCT_PACKAGES),echo $(x) >> $@$(newline))
863
864MK2BP_CATALOG_SCRIPT := build/make/tools/mk2bp_catalog.py
865PRODUCT_PACKAGES_TXT := $(PRODUCT_OUT)/product_packages.txt
866MK2BP_REMAINING_HTML := $(PRODUCT_OUT)/mk2bp_remaining.html
867$(MK2BP_REMAINING_HTML): PRIVATE_CODE_SEARCH_BASE_URL := "https://cs.android.com/android/platform/superproject/+/master:"
868$(MK2BP_REMAINING_HTML): $(SOONG_CONV_DATA) $(MK2BP_CATALOG_SCRIPT) $(PRODUCT_PACKAGES_TXT)
869	@rm -f $@
870	$(hide) $(MK2BP_CATALOG_SCRIPT) \
871		--device=$(TARGET_DEVICE) \
872		--product-packages=$(PRODUCT_PACKAGES_TXT) \
873		--title="Remaining Android.mk files for $(TARGET_DEVICE)-$(TARGET_BUILD_VARIANT)" \
874		--codesearch=$(PRIVATE_CODE_SEARCH_BASE_URL) \
875		--out-dir="$(OUT_DIR)" \
876		--mode=html \
877		> $@
878$(call declare-1p-target,$(MK2BP_REMAINING_HTML),build)
879$(call dist-for-goals,droidcore-unbundled,$(MK2BP_REMAINING_HTML))
880
881MK2BP_REMAINING_CSV := $(PRODUCT_OUT)/mk2bp_remaining.csv
882$(MK2BP_REMAINING_CSV): $(SOONG_CONV_DATA) $(MK2BP_CATALOG_SCRIPT) $(PRODUCT_PACKAGES_TXT)
883	@rm -f $@
884	$(hide) $(MK2BP_CATALOG_SCRIPT) \
885		--device=$(TARGET_DEVICE) \
886		--product-packages=$(PRODUCT_PACKAGES_TXT) \
887		--out-dir="$(OUT_DIR)" \
888		--mode=csv \
889		> $@
890$(call declare-1p-target,$(MK2BP_REMAINING_CSV))
891$(call dist-for-goals,droidcore-unbundled,$(MK2BP_REMAINING_CSV))
892
893.PHONY: mk2bp_remaining
894mk2bp_remaining: $(MK2BP_REMAINING_HTML) $(MK2BP_REMAINING_CSV)
895
896# -----------------------------------------------------------------
897# Modules use -Wno-error, or added default -Wall -Werror
898WALL_WERROR := $(PRODUCT_OUT)/wall_werror.txt
899$(WALL_WERROR):
900	@rm -f $@
901	echo "# Modules using -Wno-error" >> $@
902	for m in $(sort $(SOONG_MODULES_USING_WNO_ERROR) $(MODULES_USING_WNO_ERROR)); do echo $$m >> $@; done
903	echo "# Modules that allow warnings" >> $@
904	for m in $(sort $(SOONG_MODULES_WARNINGS_ALLOWED) $(MODULES_WARNINGS_ALLOWED)); do echo $$m >> $@; done
905
906$(call declare-0p-target,$(WALL_WERROR))
907
908$(call dist-for-goals,droidcore-unbundled,$(WALL_WERROR))
909
910# -----------------------------------------------------------------
911# Modules missing profile files
912PGO_PROFILE_MISSING := $(PRODUCT_OUT)/pgo_profile_file_missing.txt
913$(PGO_PROFILE_MISSING):
914	@rm -f $@
915	echo "# Modules missing PGO profile files" >> $@
916	for m in $(SOONG_MODULES_MISSING_PGO_PROFILE_FILE); do echo $$m >> $@; done
917
918$(call declare-0p-target,$(PGO_PROFILE_MISSING))
919
920$(call dist-for-goals,droidcore,$(PGO_PROFILE_MISSING))
921
922CERTIFICATE_VIOLATION_MODULES_FILENAME := $(PRODUCT_OUT)/certificate_violation_modules.txt
923$(CERTIFICATE_VIOLATION_MODULES_FILENAME):
924	rm -f $@
925	$(foreach m,$(sort $(CERTIFICATE_VIOLATION_MODULES)), echo $(m) >> $@;)
926$(call declare-0p-target,$(CERTIFICATE_VIOLATION_MODULES_FILENAME))
927$(call dist-for-goals,droidcore,$(CERTIFICATE_VIOLATION_MODULES_FILENAME))
928
929# -----------------------------------------------------------------
930# The dev key is used to sign this package, and as the key required
931# for future OTA packages installed by this system.  Actual product
932# deliverables will be re-signed by hand.  We expect this file to
933# exist with the suffixes ".x509.pem" and ".pk8".
934DEFAULT_KEY_CERT_PAIR := $(strip $(DEFAULT_SYSTEM_DEV_CERTIFICATE))
935
936
937# Rules that need to be present for the all targets, even
938# if they don't do anything.
939.PHONY: systemimage
940systemimage:
941
942# -----------------------------------------------------------------
943
944.PHONY: event-log-tags
945
946# Produce an event logs tag file for everything we know about, in order
947# to properly allocate numbers.  Then produce a file that's filtered
948# for what's going to be installed.
949
950all_event_log_tags_file := $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
951
952event_log_tags_file := $(TARGET_OUT)/etc/event-log-tags
953
954# Include tags from all packages that we know about
955all_event_log_tags_src := \
956    $(sort $(foreach m, $(ALL_MODULES), $(ALL_MODULES.$(m).EVENT_LOG_TAGS)))
957
958$(all_event_log_tags_file): PRIVATE_SRC_FILES := $(all_event_log_tags_src)
959$(all_event_log_tags_file): $(all_event_log_tags_src) $(MERGETAGS) build/make/tools/event_log_tags.py
960	$(hide) mkdir -p $(dir $@)
961	$(hide) $(MERGETAGS) -o $@ $(PRIVATE_SRC_FILES)
962
963$(call declare-0p-target,$(all_event_log_tags_file))
964
965# Include tags from all packages included in this product, plus all
966# tags that are part of the system (ie, not in a vendor/ or device/
967# directory).
968event_log_tags_src := \
969    $(sort $(foreach m,\
970      $(call resolve-bitness-for-modules,TARGET,$(PRODUCT_PACKAGES)) \
971      $(call module-names-for-tag-list,user), \
972      $(ALL_MODULES.$(m).EVENT_LOG_TAGS)) \
973      $(filter-out vendor/% device/% out/%,$(all_event_log_tags_src)))
974
975$(event_log_tags_file): PRIVATE_SRC_FILES := $(event_log_tags_src)
976$(event_log_tags_file): PRIVATE_MERGED_FILE := $(all_event_log_tags_file)
977$(event_log_tags_file): $(event_log_tags_src) $(all_event_log_tags_file) $(MERGETAGS) build/make/tools/event_log_tags.py
978	$(hide) mkdir -p $(dir $@)
979	$(hide) $(MERGETAGS) -o $@ -m $(PRIVATE_MERGED_FILE) $(PRIVATE_SRC_FILES)
980
981$(eval $(call declare-0p-target,$(event_log_tags_file)))
982
983event-log-tags: $(event_log_tags_file)
984
985ALL_DEFAULT_INSTALLED_MODULES += $(event_log_tags_file)
986
987# Initialize INSTALLED_FILES_OUTSIDE_IMAGES with the list of all device files,
988# files installed in images will be filtered out later.
989INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out \
990  $(PRODUCT_OUT)/apex/% \
991  $(PRODUCT_OUT)/fake_packages/% \
992  $(PRODUCT_OUT)/testcases/%, \
993  $(filter $(PRODUCT_OUT)/%,$(ALL_DEFAULT_INSTALLED_MODULES)))
994
995# #################################################################
996# Targets for boot/OS images
997# #################################################################
998ifneq ($(strip $(TARGET_NO_BOOTLOADER)),true)
999  INSTALLED_BOOTLOADER_MODULE := $(PRODUCT_OUT)/bootloader
1000  ifdef BOARD_PREBUILT_BOOTLOADER
1001    $(eval $(call copy-one-file,$(BOARD_PREBUILT_BOOTLOADER),$(INSTALLED_BOOTLOADER_MODULE)))
1002    $(call dist-for-goals,dist_files,$(INSTALLED_BOOTLOADER_MODULE))
1003  endif # BOARD_PREBUILT_BOOTLOADER
1004  ifeq ($(strip $(TARGET_BOOTLOADER_IS_2ND)),true)
1005    INSTALLED_2NDBOOTLOADER_TARGET := $(PRODUCT_OUT)/2ndbootloader
1006  else
1007    INSTALLED_2NDBOOTLOADER_TARGET :=
1008  endif
1009else
1010  INSTALLED_BOOTLOADER_MODULE :=
1011  INSTALLED_2NDBOOTLOADER_TARGET :=
1012endif # TARGET_NO_BOOTLOADER
1013ifneq ($(strip $(TARGET_NO_KERNEL)),true)
1014  ifneq ($(strip $(BOARD_KERNEL_BINARIES)),)
1015    INSTALLED_KERNEL_TARGET := $(foreach k,$(BOARD_KERNEL_BINARIES), \
1016      $(PRODUCT_OUT)/$(k))
1017  else
1018    INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
1019  endif
1020else
1021  INSTALLED_KERNEL_TARGET :=
1022endif
1023
1024# -----------------------------------------------------------------
1025# the root dir
1026INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_ROOT_OUT)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
1027INTERNAL_ROOT_FILES := $(filter $(TARGET_ROOT_OUT)/%, \
1028	$(ALL_DEFAULT_INSTALLED_MODULES))
1029
1030
1031INSTALLED_FILES_FILE_ROOT := $(PRODUCT_OUT)/installed-files-root.txt
1032INSTALLED_FILES_JSON_ROOT := $(INSTALLED_FILES_FILE_ROOT:.txt=.json)
1033$(INSTALLED_FILES_FILE_ROOT): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_ROOT)
1034$(INSTALLED_FILES_FILE_ROOT) : $(INTERNAL_ROOT_FILES) $(FILESLIST) $(FILESLIST_UTIL)
1035	@echo Installed file list: $@
1036	mkdir -p $(TARGET_ROOT_OUT)
1037	mkdir -p $(dir $@)
1038	rm -f $@
1039	$(FILESLIST) $(TARGET_ROOT_OUT) > $(@:.txt=.json)
1040	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
1041
1042$(call declare-0p-target,$(INSTALLED_FILES_FILE_ROOT))
1043$(call declare-0p-target,$(INSTALLED_FILES_JSON_ROOT))
1044
1045#------------------------------------------------------------------
1046# dtb
1047ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
1048INSTALLED_DTBIMAGE_TARGET := $(PRODUCT_OUT)/dtb.img
1049ifdef BOARD_PREBUILT_DTBIMAGE_DIR
1050$(INSTALLED_DTBIMAGE_TARGET) : $(sort $(wildcard $(BOARD_PREBUILT_DTBIMAGE_DIR)/*.dtb))
1051	cat $^ > $@
1052endif
1053endif
1054
1055# -----------------------------------------------------------------
1056# the ramdisk
1057INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_RAMDISK_OUT)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
1058ifdef BUILDING_RAMDISK_IMAGE
1059INTERNAL_RAMDISK_FILES := $(filter $(TARGET_RAMDISK_OUT)/%, \
1060	$(ALL_DEFAULT_INSTALLED_MODULES))
1061
1062INSTALLED_FILES_FILE_RAMDISK := $(PRODUCT_OUT)/installed-files-ramdisk.txt
1063INSTALLED_FILES_JSON_RAMDISK := $(INSTALLED_FILES_FILE_RAMDISK:.txt=.json)
1064$(INSTALLED_FILES_FILE_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_RAMDISK)
1065$(INSTALLED_FILES_FILE_RAMDISK) : $(INTERNAL_RAMDISK_FILES) $(FILESLIST) $(FILESLIST_UTIL)
1066	@echo Installed file list: $@
1067	mkdir -p $(TARGET_RAMDISK_OUT)
1068	mkdir -p $(dir $@)
1069	rm -f $@
1070	$(FILESLIST) $(TARGET_RAMDISK_OUT) > $(@:.txt=.json)
1071	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
1072
1073$(eval $(call declare-0p-target,$(INSTALLED_FILES_FILE_RAMDISK)))
1074$(eval $(call declare-0p-target,$(INSTALLED_FILES_JSON_RAMDISK)))
1075
1076BUILT_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img
1077
1078
1079ifneq ($(BOARD_KERNEL_MODULES_16K),)
1080
1081TARGET_OUT_RAMDISK_16K := $(PRODUCT_OUT)/ramdisk_16k
1082BUILT_RAMDISK_16K_TARGET := $(PRODUCT_OUT)/ramdisk_16k.img
1083RAMDISK_16K_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_ramdisk_16k)
1084
1085ifneq ($(BOARD_SYSTEM_KERNEL_MODULES),)
1086SYSTEM_DLKM_MODULE_PATTERNS := $(foreach path,$(BOARD_SYSTEM_KERNEL_MODULES),%/$(notdir $(path)))
1087
1088endif
1089
1090# BOARD_KERNEL_MODULES_16K might contain duplicate modules under different path.
1091# for example, foo/bar/wifi.ko and foo/wifi.ko . To avoid build issues, de-dup
1092# module list on basename first.
1093BOARD_KERNEL_MODULES_16K := $(foreach \
1094  pattern,\
1095  $(sort $(foreach \
1096    path,\
1097    $(BOARD_KERNEL_MODULES_16K),\
1098    %/$(notdir $(path)))\
1099  ),\
1100  $(firstword $(filter $(pattern),$(BOARD_KERNEL_MODULES_16K))) \
1101)
1102# For non-GKI modules, strip them before install. As debug symbols take up
1103# significant space.
1104$(foreach \
1105  file,\
1106  $(filter-out $(SYSTEM_DLKM_MODULE_PATTERNS),$(BOARD_KERNEL_MODULES_16K)),\
1107  $(eval \
1108    $(call copy-and-strip-kernel-module,\
1109      $(file),\
1110      $(RAMDISK_16K_STAGING_DIR)/lib/modules/0.0/$(notdir $(file)) \
1111    ) \
1112  ) \
1113)
1114
1115# For GKI modules, copy as-is without stripping, because stripping would
1116# remove the signature of kernel modules, and GKI modules must be signed
1117# for kernel to load them.
1118$(foreach \
1119  file,\
1120  $(filter $(SYSTEM_DLKM_MODULE_PATTERNS),$(BOARD_KERNEL_MODULES_16K)),\
1121  $(eval \
1122    $(call copy-one-file,\
1123      $(file),\
1124      $(RAMDISK_16K_STAGING_DIR)/lib/modules/0.0/$(notdir $(file)) \
1125    ) \
1126  ) \
1127)
1128
1129BOARD_VENDOR_RAMDISK_FRAGMENT.16K.PREBUILT := $(BUILT_RAMDISK_16K_TARGET)
1130
1131ifndef BOARD_KERNEL_MODULES_LOAD_16K
1132  BOARD_KERNEL_MODULES_LOAD_16K := $(BOARD_KERNEL_MODULES_16K)
1133endif
1134
1135$(BUILT_RAMDISK_16K_TARGET): $(DEPMOD) $(MKBOOTFS) $(EXTRACT_KERNEL) $(COMPRESSION_COMMAND_DEPS)
1136$(BUILT_RAMDISK_16K_TARGET): $(foreach file,$(BOARD_KERNEL_MODULES_16K),$(RAMDISK_16K_STAGING_DIR)/lib/modules/0.0/$(notdir $(file)))
1137	$(DEPMOD) -b $(RAMDISK_16K_STAGING_DIR) 0.0
1138	rm -f $(RAMDISK_16K_STAGING_DIR)/lib/modules/0.0/modules.load
1139	for MODULE in $(BOARD_KERNEL_MODULES_LOAD_16K); do \
1140		basename $$MODULE >> $(RAMDISK_16K_STAGING_DIR)/lib/modules/0.0/modules.load ; \
1141	done;
1142	rm -rf $(TARGET_OUT_RAMDISK_16K)/lib/modules
1143	mkdir -p $(TARGET_OUT_RAMDISK_16K)/lib/modules
1144	KERNEL_RELEASE=`$(EXTRACT_KERNEL) --tools lz4:$(LZ4) --input $(BOARD_KERNEL_PATH_16K) --output-release` ;\
1145	IS_16K_KERNEL=`$(EXTRACT_KERNEL) --tools lz4:$(LZ4) --input $(BOARD_KERNEL_PATH_16K) --output-config` ;\
1146	if [[ "$$IS_16K_KERNEL" == *"CONFIG_ARM64_16K_PAGES=y"* ]]; then SUFFIX=_16k; fi ;\
1147	cp -r $(RAMDISK_16K_STAGING_DIR)/lib/modules/0.0 $(TARGET_OUT_RAMDISK_16K)/lib/modules/$$KERNEL_RELEASE$$SUFFIX
1148	$(MKBOOTFS) $(TARGET_OUT_RAMDISK_16K) | $(COMPRESSION_COMMAND) > $@
1149
1150# Builds a ramdisk using modules defined in BOARD_KERNEL_MODULES_16K
1151ramdisk_16k: $(BUILT_RAMDISK_16K_TARGET)
1152.PHONY: ramdisk_16k
1153
1154endif
1155
1156ifneq ($(BOARD_KERNEL_PATH_16K),)
1157BUILT_KERNEL_16K_TARGET := $(PRODUCT_OUT)/kernel_16k
1158
1159$(eval $(call copy-one-file,$(BOARD_KERNEL_PATH_16K),$(BUILT_KERNEL_16K_TARGET)))
1160
1161# Copies BOARD_KERNEL_PATH_16K to output directory as is
1162kernel_16k: $(BUILT_KERNEL_16K_TARGET)
1163.PHONY: kernel_16k
1164
1165BUILT_BOOTIMAGE_16K_TARGET := $(PRODUCT_OUT)/boot_16k.img
1166
1167BOARD_KERNEL_16K_BOOTIMAGE_PARTITION_SIZE := $(BOARD_BOOTIMAGE_PARTITION_SIZE)
1168
1169$(BUILT_BOOTIMAGE_16K_TARGET): $(MKBOOTIMG) $(AVBTOOL) $(INTERNAL_BOOTIMAGE_FILES) $(BOARD_AVB_BOOT_KEY_PATH) $(BUILT_KERNEL_16K_TARGET)
1170	$(call pretty,"Target boot 16k image: $@")
1171	$(call build_boot_from_kernel_avb_enabled,$@,$(BUILT_KERNEL_16K_TARGET))
1172
1173
1174bootimage_16k: $(BUILT_BOOTIMAGE_16K_TARGET)
1175.PHONY: bootimage_16k
1176
1177BUILT_BOOT_OTA_PACKAGE_16K := $(PRODUCT_OUT)/boot_ota_16k.zip
1178$(BUILT_BOOT_OTA_PACKAGE_16K): $(OTA_FROM_RAW_IMG) $(BUILT_BOOTIMAGE_16K_TARGET) $(INSTALLED_BOOTIMAGE_TARGET) $(DEFAULT_SYSTEM_DEV_CERTIFICATE).pk8
1179	$(OTA_FROM_RAW_IMG) --package_key $(DEFAULT_SYSTEM_DEV_CERTIFICATE) \
1180                      --max_timestamp `cat $(BUILD_DATETIME_FILE)` \
1181                      --path $(HOST_OUT) \
1182                      --partition_name boot \
1183                      --output $@ \
1184                      $(if $(BOARD_16K_OTA_USE_INCREMENTAL),\
1185                        $(INSTALLED_BOOTIMAGE_TARGET):$(BUILT_BOOTIMAGE_16K_TARGET),\
1186                        $(BUILT_BOOTIMAGE_16K_TARGET)\
1187                      )
1188
1189boototapackage_16k: $(BUILT_BOOT_OTA_PACKAGE_16K)
1190.PHONY: boototapackage_16k
1191
1192endif
1193
1194
1195ifeq ($(BOARD_RAMDISK_USE_LZ4),true)
1196# -l enables the legacy format used by the Linux kernel
1197COMPRESSION_COMMAND_DEPS := $(LZ4)
1198COMPRESSION_COMMAND := $(LZ4) -l -12 --favor-decSpeed
1199RAMDISK_EXT := .lz4
1200else
1201COMPRESSION_COMMAND_DEPS := $(GZIP)
1202COMPRESSION_COMMAND := $(GZIP)
1203RAMDISK_EXT := .gz
1204endif
1205
1206# This file contains /dev nodes description added to the generic ramdisk
1207RAMDISK_NODE_LIST := $(PRODUCT_OUT)/ramdisk_node_list
1208
1209# We just build this directly to the install location.
1210INSTALLED_RAMDISK_TARGET := $(BUILT_RAMDISK_TARGET)
1211$(INSTALLED_RAMDISK_TARGET): PRIVATE_DIRS := debug_ramdisk dev metadata mnt proc second_stage_resources sys
1212$(INSTALLED_RAMDISK_TARGET): $(MKBOOTFS) $(RAMDISK_NODE_LIST) $(INTERNAL_RAMDISK_FILES) $(INSTALLED_FILES_FILE_RAMDISK) | $(COMPRESSION_COMMAND_DEPS)
1213	$(call pretty,"Target ramdisk: $@")
1214	$(hide) mkdir -p $(addprefix $(TARGET_RAMDISK_OUT)/,$(PRIVATE_DIRS))
1215ifeq (true,$(BOARD_USES_GENERIC_KERNEL_IMAGE))
1216	$(hide) mkdir -p $(addprefix $(TARGET_RAMDISK_OUT)/first_stage_ramdisk/,$(PRIVATE_DIRS))
1217endif
1218	$(hide) $(MKBOOTFS) -n $(RAMDISK_NODE_LIST) -d $(TARGET_OUT) $(TARGET_RAMDISK_OUT) | $(COMPRESSION_COMMAND) > $@
1219
1220$(call declare-1p-container,$(INSTALLED_RAMDISK_TARGET),)
1221$(call declare-container-license-deps,$(INSTALLED_RAMDISK_TARGET),$(INTERNAL_RAMDISK_FILE),$(PRODUCT_OUT)/:/)
1222
1223UNMOUNTED_NOTICE_VENDOR_DEPS += $(INSTALLED_RAMDISK_TARGET)
1224
1225.PHONY: ramdisk-nodeps
1226ramdisk-nodeps: $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
1227	@echo "make $@: ignoring dependencies"
1228	$(hide) $(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RAMDISK_OUT) | $(COMPRESSION_COMMAND) > $(INSTALLED_RAMDISK_TARGET)
1229
1230endif # BUILDING_RAMDISK_IMAGE
1231
1232# -----------------------------------------------------------------
1233# the boot image, which is a collection of other images.
1234
1235# This is defined here since we may be building recovery as boot
1236# below and only want to define this once
1237ifneq ($(strip $(BOARD_KERNEL_BINARIES)),)
1238  BUILT_BOOTIMAGE_TARGET := $(foreach k,$(subst kernel,boot,$(BOARD_KERNEL_BINARIES)), $(PRODUCT_OUT)/$(k).img)
1239else
1240  BUILT_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
1241endif
1242
1243INTERNAL_PREBUILT_BOOTIMAGE :=
1244
1245my_installed_prebuilt_gki_apex := $(strip $(foreach package,$(PRODUCT_PACKAGES),$(if $(ALL_MODULES.$(package).EXTRACTED_BOOT_IMAGE),$(package))))
1246ifdef my_installed_prebuilt_gki_apex
1247  ifneq (1,$(words $(my_installed_prebuilt_gki_apex))) # len(my_installed_prebuilt_gki_apex) > 1
1248    $(error More than one prebuilt GKI APEXes are installed: $(my_installed_prebuilt_gki_apex))
1249  endif # len(my_installed_prebuilt_gki_apex) > 1
1250
1251  ifdef BOARD_PREBUILT_BOOTIMAGE
1252    $(error Must not define BOARD_PREBUILT_BOOTIMAGE because a prebuilt GKI APEX is installed: $(my_installed_prebuilt_gki_apex))
1253  endif # BOARD_PREBUILT_BOOTIMAGE defined
1254
1255  my_apex_extracted_boot_image := $(ALL_MODULES.$(my_installed_prebuilt_gki_apex).EXTRACTED_BOOT_IMAGE)
1256  INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
1257  $(eval $(call copy-one-file,$(my_apex_extracted_boot_image),$(INSTALLED_BOOTIMAGE_TARGET)))
1258  $(call declare-container-license-metadata,$(INSTALLED_BOOTIMAGE_TARGET),SPDX-license-identifier-GPL-2.0-only SPDX-license-identifier-Apache-2.0,restricted notice,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING build/soong/licenses/LICENSE,"Boot Image",boot)
1259
1260  INTERNAL_PREBUILT_BOOTIMAGE := $(my_apex_extracted_boot_image)
1261
1262else # my_installed_prebuilt_gki_apex not defined
1263
1264# $1: boot image target
1265# returns the kernel used to make the bootimage
1266define bootimage-to-kernel
1267  $(if $(BOARD_KERNEL_BINARIES),\
1268    $(PRODUCT_OUT)/$(subst .img,,$(subst boot,kernel,$(notdir $(1)))),\
1269    $(INSTALLED_KERNEL_TARGET))
1270endef
1271
1272ifdef BOARD_BOOTIMAGE_PARTITION_SIZE
1273  BOARD_KERNEL_BOOTIMAGE_PARTITION_SIZE := $(BOARD_BOOTIMAGE_PARTITION_SIZE)
1274endif
1275
1276# $1: boot image file name
1277# $2: boot image variant (boot, boot-debug, boot-test-harness)
1278define get-bootimage-partition-size
1279$(BOARD_$(call to-upper,$(subst .img,,$(subst $(2),kernel,$(notdir $(1)))))_BOOTIMAGE_PARTITION_SIZE)
1280endef
1281
1282# $1: partition size
1283define get-partition-size-argument
1284  $(if $(1),--partition_size $(1),--dynamic_partition_size)
1285endef
1286
1287# $1: output boot image target
1288# $2: input path to kernel binary
1289define build_boot_from_kernel_avb_enabled
1290  $(eval kernel := $(2))
1291  $(MKBOOTIMG) --kernel $(kernel) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1)
1292  $(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(call get-bootimage-partition-size,$(1),boot)))
1293  $(AVBTOOL) add_hash_footer \
1294          --image $(1) \
1295          $(call get-partition-size-argument,$(call get-bootimage-partition-size,$(1),boot)) \
1296          --salt `sha256sum "$(kernel)" | cut -d " " -f 1` \
1297          --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) \
1298          $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)
1299endef
1300
1301
1302ifndef BOARD_PREBUILT_BOOTIMAGE
1303
1304ifneq ($(strip $(TARGET_NO_KERNEL)),true)
1305INTERNAL_BOOTIMAGE_ARGS := \
1306	$(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET))
1307
1308ifneq ($(BUILDING_INIT_BOOT_IMAGE),true)
1309  INTERNAL_BOOTIMAGE_ARGS += --ramdisk $(INSTALLED_RAMDISK_TARGET)
1310endif
1311
1312ifndef BUILDING_VENDOR_BOOT_IMAGE
1313ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
1314  INTERNAL_BOOTIMAGE_ARGS += --dtb $(INSTALLED_DTBIMAGE_TARGET)
1315endif
1316endif
1317
1318INTERNAL_BOOTIMAGE_FILES := $(filter-out --%,$(INTERNAL_BOOTIMAGE_ARGS))
1319
1320# kernel cmdline/base/pagesize in boot.
1321# - If using GKI, use GENERIC_KERNEL_CMDLINE. Remove kernel base and pagesize because they are
1322#   device-specific.
1323# - If not using GKI:
1324#   - If building vendor_boot, INTERNAL_KERNEL_CMDLINE, base and pagesize goes in vendor_boot.
1325#   - Otherwise, put them in boot.
1326ifeq (true,$(BOARD_USES_GENERIC_KERNEL_IMAGE))
1327  ifdef GENERIC_KERNEL_CMDLINE
1328    INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(GENERIC_KERNEL_CMDLINE)"
1329  endif
1330else ifndef BUILDING_VENDOR_BOOT_IMAGE # && BOARD_USES_GENERIC_KERNEL_IMAGE != true
1331  ifdef INTERNAL_KERNEL_CMDLINE
1332    INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)"
1333  endif
1334  ifdef BOARD_KERNEL_BASE
1335    INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
1336  endif
1337  ifdef BOARD_KERNEL_PAGESIZE
1338    INTERNAL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
1339  endif
1340endif # BUILDING_VENDOR_BOOT_IMAGE == "" && BOARD_USES_GENERIC_KERNEL_IMAGE != true
1341
1342INTERNAL_MKBOOTIMG_VERSION_ARGS := \
1343  --os_version $(PLATFORM_VERSION_LAST_STABLE) \
1344  --os_patch_level $(PLATFORM_SECURITY_PATCH)
1345
1346# Define these only if we are building boot
1347ifdef BUILDING_BOOT_IMAGE
1348INSTALLED_BOOTIMAGE_TARGET := $(BUILT_BOOTIMAGE_TARGET)
1349
1350ifeq ($(TARGET_BOOTIMAGE_USE_EXT2),true)
1351$(error TARGET_BOOTIMAGE_USE_EXT2 is not supported anymore)
1352endif # TARGET_BOOTIMAGE_USE_EXT2
1353
1354$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET), $(eval $(call add-dependency,$(b),$(call bootimage-to-kernel,$(b)))))
1355
1356ifeq (true,$(BOARD_AVB_ENABLE))
1357
1358# $1: boot image target
1359define build_boot_board_avb_enabled
1360  $(eval kernel := $(call bootimage-to-kernel,$(1)))
1361  $(call build_boot_from_kernel_avb_enabled,$(1),$(kernel))
1362endef
1363
1364$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(AVBTOOL) $(INTERNAL_BOOTIMAGE_FILES) $(BOARD_AVB_BOOT_KEY_PATH)
1365	$(call pretty,"Target boot image: $@")
1366	$(call build_boot_board_avb_enabled,$@)
1367
1368$(call declare-container-license-metadata,$(INSTALLED_BOOTIMAGE_TARGET),SPDX-license-identifier-GPL-2.0-only SPDX-license-identifier-Apache-2.0,restricted notice,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING build/soong/licenses/LICENSE,"Boot Image",boot)
1369$(call declare-container-license-deps,$(INSTALLED_BOOTIMAGE_TARGET),$(INTERNAL_BOOTIMAGE_FILES),$(PRODUCT_OUT)/:/)
1370
1371UNMOUNTED_NOTICE_VENDOR_DEPS += $(INSTALLED_BOOTIMAGE_TARGET)
1372
1373.PHONY: bootimage-nodeps
1374bootimage-nodeps: $(MKBOOTIMG) $(AVBTOOL) $(BOARD_AVB_BOOT_KEY_PATH)
1375	@echo "make $@: ignoring dependencies"
1376	$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(call build_boot_board_avb_enabled,$(b)))
1377
1378else ifeq (true,$(PRODUCT_SUPPORTS_VBOOT)) # BOARD_AVB_ENABLE != true
1379
1380# $1: boot image target
1381define build_boot_supports_vboot
1382  $(MKBOOTIMG) --kernel $(call bootimage-to-kernel,$(1)) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1).unsigned
1383  $(VBOOT_SIGNER) $(FUTILITY) $(1).unsigned $(PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(1).keyblock $(1)
1384  $(call assert-max-image-size,$(1),$(call get-bootimage-partition-size,$(1),boot))
1385endef
1386
1387$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES) $(VBOOT_SIGNER) $(FUTILITY)
1388	$(call pretty,"Target boot image: $@")
1389	$(call build_boot_supports_vboot,$@)
1390
1391$(call declare-container-license-metadata,$(INSTALLED_BOOTIMAGE_TARGET),SPDX-license-identifier-GPL-2.0-only SPDX-license-identifier-Apache-2.0,restricted notice,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING build/soong/licenses/LICENSE,"Boot Image",boot)
1392$(call declare-container-license-deps,$(INSTALLED_BOOTIMAGE_TARGET),$(INTERNAL_BOOTIMAGE_FILES),$(PRODUCT_OUT)/:/)
1393
1394UNMOUNTED_NOTICE_VENDOR_DEPS += $(INSTALLED_BOOTIMAGE_TARGET)
1395
1396.PHONY: bootimage-nodeps
1397bootimage-nodeps: $(MKBOOTIMG) $(VBOOT_SIGNER) $(FUTILITY)
1398	@echo "make $@: ignoring dependencies"
1399	$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(call build_boot_supports_vboot,$(b)))
1400
1401else # PRODUCT_SUPPORTS_VBOOT != true
1402
1403# $1: boot image target
1404define build_boot_novboot
1405  $(MKBOOTIMG) --kernel $(call bootimage-to-kernel,$(1)) $(INTERNAL_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $(1)
1406  $(call assert-max-image-size,$1,$(call get-bootimage-partition-size,$(1),boot))
1407endef
1408
1409$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES)
1410	$(call pretty,"Target boot image: $@")
1411	$(call build_boot_novboot,$@)
1412
1413$(call declare-container-license-metadata,$(INSTALLED_BOOTIMAGE_TARGET),SPDX-license-identifier-GPL-2.0-only SPDX-license-identifier-Apache-2.0,restricted notice,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING build/soong/licenses/LICENSE,"Boot Image",boot)
1414$(call declare-container-license-deps,$(INSTALLED_BOOTIMAGE_TARGET),$(INTERNAL_BOOTIMAGE_FILES),$(PRODUCT_OUT)/:/)
1415
1416UNMOUNTED_NOTICE_VENDOR_DEPS += $(INSTALLED_BOOTIMAGE_TARGET)
1417
1418.PHONY: bootimage-nodeps
1419bootimage-nodeps: $(MKBOOTIMG)
1420	@echo "make $@: ignoring dependencies"
1421	$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(call build_boot_novboot,$(b)))
1422
1423endif # BOARD_AVB_ENABLE
1424endif # BUILDING_BOOT_IMAGE
1425
1426else # TARGET_NO_KERNEL == "true"
1427INSTALLED_BOOTIMAGE_TARGET :=
1428endif # TARGET_NO_KERNEL
1429
1430else # BOARD_PREBUILT_BOOTIMAGE defined
1431INTERNAL_PREBUILT_BOOTIMAGE := $(BOARD_PREBUILT_BOOTIMAGE)
1432INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
1433
1434ifeq ($(BOARD_AVB_ENABLE),true)
1435$(INSTALLED_BOOTIMAGE_TARGET): PRIVATE_WORKING_DIR := $(call intermediates-dir-for,PACKAGING,prebuilt_bootimg)
1436$(INSTALLED_BOOTIMAGE_TARGET): $(INTERNAL_PREBUILT_BOOTIMAGE) $(AVBTOOL) $(BOARD_AVB_BOOT_KEY_PATH) $(UNPACK_BOOTIMG)
1437	cp $(INTERNAL_PREBUILT_BOOTIMAGE) $@
1438	$(UNPACK_BOOTIMG) --boot_img $(INTERNAL_PREBUILT_BOOTIMAGE) --out $(PRIVATE_WORKING_DIR)
1439	chmod +w $@
1440	$(AVBTOOL) add_hash_footer \
1441	    --image $@ \
1442	    --salt `sha256sum $(PRIVATE_WORKING_DIR)/kernel | cut -d " " -f 1` \
1443	    $(call get-partition-size-argument,$(BOARD_BOOTIMAGE_PARTITION_SIZE)) \
1444	    --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) \
1445	    $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)
1446
1447
1448$(call declare-container-license-metadata,$(INSTALLED_BOOTIMAGE_TARGET),SPDX-license-identifier-GPL-2.0-only SPDX-license-identifier-Apache-2.0,restricted notice,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING build/soong/licenses/LICENSE,"Boot Image",bool)
1449$(call declare-container-license-deps,$(INSTALLED_BOOTIMAGE_TARGET),$(INTERNAL_PREBUILT_BOOTIMAGE),$(PRODUCT_OUT)/:/)
1450
1451UNMOUNTED_NOTICE_VENDOR_DEPS += $(INSTALLED_BOOTIMAGE_TARGET)
1452else
1453$(INSTALLED_BOOTIMAGE_TARGET): $(INTERNAL_PREBUILT_BOOTIMAGE)
1454	cp $(INTERNAL_PREBUILT_BOOTIMAGE) $@
1455endif # BOARD_AVB_ENABLE
1456
1457endif # BOARD_PREBUILT_BOOTIMAGE
1458
1459endif # my_installed_prebuilt_gki_apex not defined
1460
1461ifneq ($(BOARD_KERNEL_PATH_16K),)
1462BUILT_BOOT_OTA_PACKAGE_4K := $(PRODUCT_OUT)/boot_ota_4k.zip
1463$(BUILT_BOOT_OTA_PACKAGE_4K): $(OTA_FROM_RAW_IMG) $(INSTALLED_BOOTIMAGE_TARGET) $(BUILT_BOOTIMAGE_16K_TARGET) $(DEFAULT_SYSTEM_DEV_CERTIFICATE).pk8
1464	$(OTA_FROM_RAW_IMG) --package_key $(DEFAULT_SYSTEM_DEV_CERTIFICATE) \
1465                      --max_timestamp `cat $(BUILD_DATETIME_FILE)` \
1466                      --path $(HOST_OUT) \
1467                      --partition_name boot \
1468                      --output $@ \
1469                      $(if $(BOARD_16K_OTA_USE_INCREMENTAL),\
1470                        $(BUILT_BOOTIMAGE_16K_TARGET):$(INSTALLED_BOOTIMAGE_TARGET),\
1471                        $(INSTALLED_BOOTIMAGE_TARGET)\
1472                      )
1473
1474boototapackage_4k: $(BUILT_BOOT_OTA_PACKAGE_4K)
1475.PHONY: boototapackage_4k
1476
1477ifeq ($(BOARD_16K_OTA_MOVE_VENDOR),true)
1478$(eval $(call copy-one-file,$(BUILT_BOOT_OTA_PACKAGE_4K),$(TARGET_OUT_VENDOR)/boot_otas/boot_ota_4k.zip))
1479$(eval $(call copy-one-file,$(BUILT_BOOT_OTA_PACKAGE_16K),$(TARGET_OUT_VENDOR)/boot_otas/boot_ota_16k.zip))
1480ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_VENDOR)/boot_otas/boot_ota_4k.zip
1481ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_VENDOR)/boot_otas/boot_ota_16k.zip
1482else
1483$(eval $(call copy-one-file,$(BUILT_BOOT_OTA_PACKAGE_4K),$(TARGET_OUT)/boot_otas/boot_ota_4k.zip))
1484$(eval $(call copy-one-file,$(BUILT_BOOT_OTA_PACKAGE_16K),$(TARGET_OUT)/boot_otas/boot_ota_16k.zip))
1485ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT)/boot_otas/boot_ota_4k.zip
1486ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT)/boot_otas/boot_ota_16k.zip
1487endif # BOARD_16K_OTA_MOVE_VENDOR == true
1488
1489
1490endif
1491
1492my_apex_extracted_boot_image :=
1493my_installed_prebuilt_gki_apex :=
1494
1495# -----------------------------------------------------------------
1496#  init boot image
1497ifeq ($(BUILDING_INIT_BOOT_IMAGE),true)
1498
1499INSTALLED_INIT_BOOT_IMAGE_TARGET := $(PRODUCT_OUT)/init_boot.img
1500$(INSTALLED_INIT_BOOT_IMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_RAMDISK_TARGET)
1501
1502INTERNAL_INIT_BOOT_IMAGE_ARGS := --ramdisk $(INSTALLED_RAMDISK_TARGET)
1503
1504ifdef BOARD_KERNEL_PAGESIZE
1505  INTERNAL_INIT_BOOT_IMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
1506endif
1507
1508ifeq ($(BOARD_AVB_ENABLE),true)
1509$(INSTALLED_INIT_BOOT_IMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_INIT_BOOT_KEY_PATH)
1510	$(call pretty,"Target init_boot image: $@")
1511	$(MKBOOTIMG) $(INTERNAL_INIT_BOOT_IMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_INIT_ARGS) --output "$@"
1512	$(call assert-max-image-size,$@,$(BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE))
1513	$(AVBTOOL) add_hash_footer \
1514           --image $@ \
1515	   $(call get-partition-size-argument,$(BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE)) \
1516	   --partition_name init_boot $(INTERNAL_AVB_INIT_BOOT_SIGNING_ARGS) \
1517	   $(BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS)
1518
1519$(call declare-1p-container,$(INSTALLED_INIT_BOOT_IMAGE_TARGET),)
1520$(call declare-container-license-deps,$(INSTALLED_INIT_BOOT_IMAGE_TARGET),$(INTERNAL_GENERIC_RAMDISK_BOOT_SIGNATURE),$(PRODUCT_OUT)/:/)
1521else
1522$(INSTALLED_INIT_BOOT_IMAGE_TARGET):
1523	$(call pretty,"Target init_boot image: $@")
1524	$(MKBOOTIMG) $(INTERNAL_INIT_BOOT_IMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_MKBOOTIMG_INIT_ARGS) --output $@
1525	$(call assert-max-image-size,$@,$(BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE))
1526
1527$(call declare-1p-target,$(INSTALLED_INIT_BOOT_IMAGE_TARGET),)
1528endif
1529
1530UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_INIT_BOOT_IMAGE_TARGET)
1531
1532else # BUILDING_INIT_BOOT_IMAGE is not true
1533
1534ifdef BOARD_PREBUILT_INIT_BOOT_IMAGE
1535INTERNAL_PREBUILT_INIT_BOOT_IMAGE := $(BOARD_PREBUILT_INIT_BOOT_IMAGE)
1536INSTALLED_INIT_BOOT_IMAGE_TARGET := $(PRODUCT_OUT)/init_boot.img
1537
1538ifeq ($(BOARD_AVB_ENABLE),true)
1539$(INSTALLED_INIT_BOOT_IMAGE_TARGET): $(INTERNAL_PREBUILT_INIT_BOOT_IMAGE) $(AVBTOOL) $(BOARD_AVB_INIT_BOOT_KEY_PATH)
1540	cp $(INTERNAL_PREBUILT_INIT_BOOT_IMAGE) $@
1541	chmod +w $@
1542	$(AVBTOOL) add_hash_footer \
1543	    --image $@ \
1544	    $(call get-partition-size-argument,$(BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE)) \
1545	    --partition_name init_boot $(INTERNAL_AVB_INIT_BOOT_SIGNING_ARGS) \
1546	    $(BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS)
1547
1548$(call declare-1p-container,$(INSTALLED_INIT_BOOT_IMAGE_TARGET),)
1549$(call declare-container-license-deps,$(INSTALLED_INIT_BOOT_IMAGE_TARGET),$(INTERNAL_PREBUILT_INIT_BOOT_IMAGE),$(PRODUCT_OUT)/:/)
1550else
1551$(INSTALLED_INIT_BOOT_IMAGE_TARGET): $(INTERNAL_PREBUILT_INIT_BOOT_IMAGE)
1552	cp $(INTERNAL_PREBUILT_INIT_BOOT_IMAGE) $@
1553
1554$(call declare-1p-target,$(INSTALLED_INIT_BOOT_IMAGE_TARGET),)
1555endif # BOARD_AVB_ENABLE
1556
1557UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_INIT_BOOT_IMAGE_TARGET)
1558
1559else # BOARD_PREBUILT_INIT_BOOT_IMAGE not defined
1560INSTALLED_INIT_BOOT_IMAGE_TARGET :=
1561endif # BOARD_PREBUILT_INIT_BOOT_IMAGE
1562
1563endif # BUILDING_INIT_BOOT_IMAGE is not true
1564
1565# -----------------------------------------------------------------
1566# vendor boot image
1567INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_VENDOR_RAMDISK_OUT)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
1568ifeq ($(BUILDING_VENDOR_BOOT_IMAGE),true)
1569
1570INTERNAL_VENDOR_RAMDISK_FILES := $(filter $(TARGET_VENDOR_RAMDISK_OUT)/%, \
1571    $(ALL_DEFAULT_INSTALLED_MODULES))
1572
1573INTERNAL_VENDOR_RAMDISK_TARGET := $(call intermediates-dir-for,PACKAGING,vendor_boot)/vendor_ramdisk.cpio$(RAMDISK_EXT)
1574
1575# Exclude recovery files in the default vendor ramdisk if including a standalone
1576# recovery ramdisk in vendor_boot.
1577ifeq (true,$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT))
1578ifneq (true,$(BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT))
1579$(INTERNAL_VENDOR_RAMDISK_TARGET): $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
1580$(INTERNAL_VENDOR_RAMDISK_TARGET): PRIVATE_ADDITIONAL_DIR := $(TARGET_RECOVERY_ROOT_OUT)
1581endif
1582endif
1583
1584$(INTERNAL_VENDOR_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_VENDOR_RAMDISK_FILES) | $(COMPRESSION_COMMAND_DEPS)
1585	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_VENDOR_RAMDISK_OUT) $(PRIVATE_ADDITIONAL_DIR) | $(COMPRESSION_COMMAND) > $@
1586
1587INSTALLED_VENDOR_RAMDISK_TARGET := $(PRODUCT_OUT)/vendor_ramdisk.img
1588$(INSTALLED_VENDOR_RAMDISK_TARGET): $(INTERNAL_VENDOR_RAMDISK_TARGET)
1589	@echo "Target vendor ramdisk: $@"
1590	$(copy-file-to-target)
1591
1592$(call declare-1p-container,$(INSTALLED_VENDOR_RAMDISK_TARGET),)
1593$(call declare-container-license-deps,$(INSTALLED_VENDOR_RAMDISK_TARGET),$(INTERNAL_VENDOR_RAMDISK_TARGET),$(PRODUCT_OUT)/:/)
1594
1595VENDOR_NOTICE_DEPS += $(INSTALLED_VENDOR_RAMDISK_TARGET)
1596
1597INSTALLED_FILES_FILE_VENDOR_RAMDISK := $(PRODUCT_OUT)/installed-files-vendor-ramdisk.txt
1598INSTALLED_FILES_JSON_VENDOR_RAMDISK := $(INSTALLED_FILES_FILE_VENDOR_RAMDISK:.txt=.json)
1599$(INSTALLED_FILES_FILE_VENDOR_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_VENDOR_RAMDISK)
1600$(INSTALLED_FILES_FILE_VENDOR_RAMDISK): $(INTERNAL_VENDOR_RAMDISK_TARGET)
1601$(INSTALLED_FILES_FILE_VENDOR_RAMDISK): $(INTERNAL_VENDOR_RAMDISK_FILES) $(FILESLIST) $(FILESLIST_UTIL)
1602	@echo Installed file list: $@
1603	mkdir -p $(dir $@)
1604	rm -f $@
1605	$(FILESLIST) $(TARGET_VENDOR_RAMDISK_OUT) > $(@:.txt=.json)
1606	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
1607
1608$(eval $(call declare-0p-target,$(INSTALLED_FILES_FILE_VENDOR_RAMDISK)))
1609$(eval $(call declare-0p-target,$(INSTALLED_FILES_JSON_VENDOR_RAMDISK)))
1610
1611ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
1612  ifneq ($(BUILDING_VENDOR_KERNEL_BOOT_IMAGE),true)
1613    # If we have vendor_kernel_boot partition, we migrate dtb image to that image
1614    # and allow dtb in vendor_boot to be empty.
1615    INTERNAL_VENDOR_BOOTIMAGE_ARGS += --dtb $(INSTALLED_DTBIMAGE_TARGET)
1616  endif
1617endif
1618ifdef BOARD_KERNEL_BASE
1619  INTERNAL_VENDOR_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
1620endif
1621ifdef BOARD_KERNEL_PAGESIZE
1622  INTERNAL_VENDOR_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
1623endif
1624ifdef INTERNAL_KERNEL_CMDLINE
1625  INTERNAL_VENDOR_BOOTIMAGE_ARGS += --vendor_cmdline "$(INTERNAL_KERNEL_CMDLINE)"
1626endif
1627
1628ifdef INTERNAL_BOOTCONFIG
1629  INTERNAL_VENDOR_BOOTCONFIG_TARGET := $(PRODUCT_OUT)/vendor-bootconfig.img
1630  $(INTERNAL_VENDOR_BOOTCONFIG_TARGET):
1631	rm -f $@
1632	$(foreach param,$(INTERNAL_BOOTCONFIG), \
1633	 printf "%s\n" $(param) >> $@;)
1634  INTERNAL_VENDOR_BOOTIMAGE_ARGS += --vendor_bootconfig $(INTERNAL_VENDOR_BOOTCONFIG_TARGET)
1635endif
1636
1637# $(1): Build target name
1638# $(2): Staging dir to be compressed
1639# $(3): Build dependencies
1640define build-vendor-ramdisk-fragment-target
1641$(1): $(3) $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
1642	$(MKBOOTFS) -d $(TARGET_OUT) $(2) | $(COMPRESSION_COMMAND) > $$@
1643endef
1644
1645# $(1): Ramdisk name
1646define build-vendor-ramdisk-fragment
1647$(strip \
1648  $(eval build_target := $(call intermediates-dir-for,PACKAGING,vendor_ramdisk_fragments)/$(1).cpio$(RAMDISK_EXT)) \
1649  $(eval $(call build-vendor-ramdisk-fragment-target,$(build_target),$(VENDOR_RAMDISK_FRAGMENT.$(1).STAGING_DIR),$(VENDOR_RAMDISK_FRAGMENT.$(1).FILES))) \
1650  $(build_target) \
1651)
1652endef
1653
1654# $(1): Ramdisk name
1655# $(2): Prebuilt file path
1656define build-prebuilt-vendor-ramdisk-fragment
1657$(strip \
1658  $(eval build_target := $(call intermediates-dir-for,PACKAGING,prebuilt_vendor_ramdisk_fragments)/$(1)) \
1659  $(eval $(call copy-one-file,$(2),$(build_target))) \
1660  $(build_target) \
1661)
1662endef
1663
1664INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS :=
1665INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS :=
1666
1667$(foreach vendor_ramdisk_fragment,$(INTERNAL_VENDOR_RAMDISK_FRAGMENTS), \
1668  $(eval prebuilt_vendor_ramdisk_fragment_file := $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).PREBUILT)) \
1669  $(if $(prebuilt_vendor_ramdisk_fragment_file), \
1670    $(eval vendor_ramdisk_fragment_target := $(call build-prebuilt-vendor-ramdisk-fragment,$(vendor_ramdisk_fragment),$(prebuilt_vendor_ramdisk_fragment_file))) \
1671    $(eval ### else ###), \
1672    $(eval vendor_ramdisk_fragment_target := $(call build-vendor-ramdisk-fragment,$(vendor_ramdisk_fragment)))) \
1673  $(eval INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS += $(vendor_ramdisk_fragment_target)) \
1674  $(eval INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS += $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS) --vendor_ramdisk_fragment $(vendor_ramdisk_fragment_target)) \
1675)
1676
1677INSTALLED_VENDOR_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/vendor_boot.img
1678$(INSTALLED_VENDOR_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INSTALLED_DTBIMAGE_TARGET)
1679$(INSTALLED_VENDOR_BOOTIMAGE_TARGET): $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS) $(INTERNAL_VENDOR_BOOTCONFIG_TARGET)
1680ifeq ($(BOARD_AVB_ENABLE),true)
1681$(INSTALLED_VENDOR_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_VENDOR_BOOTIMAGE_KEY_PATH)
1682	$(call pretty,"Target vendor_boot image: $@")
1683	$(MKBOOTIMG) $(INTERNAL_VENDOR_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --vendor_ramdisk $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS) --vendor_boot $@
1684	$(call assert-max-image-size,$@,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE))
1685	$(AVBTOOL) add_hash_footer \
1686           --image $@ \
1687	   $(call get-partition-size-argument,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE)) \
1688	   --partition_name vendor_boot $(INTERNAL_AVB_VENDOR_BOOT_SIGNING_ARGS) \
1689	   $(BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS)
1690else
1691$(INSTALLED_VENDOR_BOOTIMAGE_TARGET):
1692	$(call pretty,"Target vendor_boot image: $@")
1693	$(MKBOOTIMG) $(INTERNAL_VENDOR_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --vendor_ramdisk $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS) --vendor_boot $@
1694	$(call assert-max-image-size,$@,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE))
1695endif
1696
1697$(call declare-1p-container,$(INSTALLED_VENDOR_BOOTIMAGE_TARGET),)
1698$(call declare-container-license-deps,$(INSTALLED_VENDOR_BOOTIMAGE_TARGET),$(INTERNAL_VENDOR_RAMDISK_TARGET) $(INSTALLED_DTB_IMAGE_TARGET) $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS) $(INTERNAL_VENDOR_BOOTCONDIG_TARGET),$(PRODUCT_OUT)/:/)
1699VENDOR_NOTICE_DEPS += $(INSTALLED_VENDOR_BOOTIMAGE_TARGET)
1700endif # BUILDING_VENDOR_BOOT_IMAGE
1701
1702# -----------------------------------------------------------------
1703# vendor kernel boot image
1704ifeq ($(BUILDING_VENDOR_KERNEL_BOOT_IMAGE),true)
1705
1706INTERNAL_VENDOR_KERNEL_RAMDISK_FILES := $(filter $(TARGET_VENDOR_KERNEL_RAMDISK_OUT)/%, \
1707    $(ALL_DEFAULT_INSTALLED_MODULES))
1708
1709INTERNAL_VENDOR_KERNEL_RAMDISK_TARGET := $(call intermediates-dir-for,PACKAGING,vendor_kernel_boot)/vendor_kernel_ramdisk.cpio$(RAMDISK_EXT)
1710
1711$(INTERNAL_VENDOR_KERNEL_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_VENDOR_KERNEL_RAMDISK_FILES) | $(COMPRESSION_COMMAND_DEPS)
1712	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_VENDOR_KERNEL_RAMDISK_OUT) | $(COMPRESSION_COMMAND) > $@
1713
1714INSTALLED_VENDOR_KERNEL_RAMDISK_TARGET := $(PRODUCT_OUT)/vendor_kernel_ramdisk.img
1715$(INSTALLED_VENDOR_KERNEL_RAMDISK_TARGET): $(INTERNAL_VENDOR_KERNEL_RAMDISK_TARGET)
1716	@echo "Target vendor kernel ramdisk: $@"
1717	$(copy-file-to-target)
1718
1719INSTALLED_FILES_FILE_VENDOR_KERNEL_RAMDISK := $(PRODUCT_OUT)/installed-files-vendor-kernel-ramdisk.txt
1720INSTALLED_FILES_JSON_VENDOR_KERNEL_RAMDISK := $(INSTALLED_FILES_FILE_VENDOR_KERNEL_RAMDISK:.txt=.json)
1721$(INSTALLED_FILES_FILE_VENDOR_KERNEL_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_VENDOR_KERNEL_RAMDISK)
1722$(INSTALLED_FILES_FILE_VENDOR_KERNEL_RAMDISK): $(INTERNAL_VENDOR_KERNEL_RAMDISK_TARGET)
1723$(INSTALLED_FILES_FILE_VENDOR_KERNEL_RAMDISK): $(INTERNAL_VENDOR_KERNEL_RAMDISK_FILES) $(FILESLIST) $(FILESLIST_UTIL)
1724	@echo Installed file list: $@
1725	mkdir -p $(dir $@)
1726	rm -f $@
1727	$(FILESLIST) $(TARGET_VENDOR_KERNEL_RAMDISK_OUT) > $(@:.txt=.json)
1728	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
1729
1730$(call declare-0p-target,$(INSTALLED_FILES_FILE_VENDOR_KERNEL_RAMDISK))
1731$(call declare-0p-target,$(INSTALLED_FILES_JSON_VENDOR_KERNEL_RAMDISK))
1732
1733INTERNAL_VENDOR_KERNEL_BOOTIMAGE_ARGS := --vendor_ramdisk $(INTERNAL_VENDOR_KERNEL_RAMDISK_TARGET)
1734INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/vendor_kernel_boot.img
1735$(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_VENDOR_KERNEL_RAMDISK_TARGET)
1736
1737ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
1738  INTERNAL_VENDOR_KERNEL_BOOTIMAGE_ARGS += --dtb $(INSTALLED_DTBIMAGE_TARGET)
1739  $(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET): $(INSTALLED_DTBIMAGE_TARGET)
1740endif
1741ifdef BOARD_KERNEL_PAGESIZE
1742  INTERNAL_VENDOR_KERNEL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
1743endif
1744
1745
1746ifeq ($(BOARD_AVB_ENABLE),true)
1747$(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_VENDOR_KERNEL_BOOTIMAGE_KEY_PATH)
1748	$(call pretty,"Target vendor_kernel_boot image: $@")
1749	$(MKBOOTIMG) $(INTERNAL_VENDOR_KERNEL_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --vendor_boot $@
1750	$(call assert-max-image-size,$@,$(BOARD_VENDOR_KERNEL_BOOTIMAGE_PARTITION_SIZE))
1751	$(AVBTOOL) add_hash_footer \
1752	    --image $@ \
1753	   $(call get-partition-size-argument,$(BOARD_VENDOR_KERNEL_BOOTIMAGE_PARTITION_SIZE)) \
1754	   --partition_name vendor_kernel_boot $(INTERNAL_AVB_VENDOR_KERNEL_BOOT_SIGNING_ARGS) \
1755	   $(BOARD_AVB_VENDOR_KERNEL_BOOT_ADD_HASH_FOOTER_ARGS)
1756else
1757$(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET):
1758	$(call pretty,"Target vendor_kernel_boot image: $@")
1759	$(MKBOOTIMG) $(INTERNAL_VENDOR_KERNEL_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --vendor_boot $@
1760	$(call assert-max-image-size,$@,$(BOARD_VENDOR_KERNEL_BOOTIMAGE_PARTITION_SIZE))
1761endif
1762$(call declare-1p-container,$(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET),)
1763ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
1764$(call declare-container-license-deps,$(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET),\
1765    $(INTERNAL_VENDOR_KERNEL_RAMDISK_TARGET) $(INSTALLED_DTBIMAGE_TARGET),\
1766    $(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET):)
1767else
1768$(call declare-container-license-deps,$(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET),$(INTERNAL_VENDOR_KERNEL_RAMDISK_TARGET),$(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET):)
1769endif
1770endif # BUILDING_VENDOR_KERNEL_BOOT_IMAGE
1771
1772# -----------------------------------------------------------------
1773# NOTICE files
1774#
1775# We are required to publish the licenses for all code under BSD, GPL and
1776# Apache licenses (and possibly other more exotic ones as well). We err on the
1777# side of caution, so the licenses for other third-party code are included here
1778# too.
1779#
1780# This needs to be before the systemimage rules, because it adds to
1781# ALL_DEFAULT_INSTALLED_MODULES, which those use to pick which files
1782# go into the systemimage.
1783
1784.PHONY: notice_files
1785
1786# Convert license metadata into xml notice file.
1787# $(1) - Output target notice filename
1788# $(2) - Product name
1789# $(3) - File title
1790# $(4) - License metadata file roots
1791# $(5) - Prefixes to strip
1792#
1793define xml-notice-rule
1794$(1): PRIVATE_PRODUCT := $(2)
1795$(1): PRIVATE_MESSAGE := $(3)
1796$(1): PRIVATE_DEPS := $(call corresponding-license-metadata,$(4))
1797$(1): $(call corresponding-license-metadata,$(4)) $(XMLNOTICE) $(BUILD_SYSTEM)/Makefile
1798	OUT_DIR=$(OUT_DIR) $(XMLNOTICE) -o $$@ -product=$$(PRIVATE_PRODUCT) -title=$$(PRIVATE_MESSAGE) $(foreach prefix, $(5), -strip_prefix=$(prefix)) $$(PRIVATE_DEPS)
1799
1800notice_files: $(1)
1801endef
1802
1803# Convert license metadata into text notice file.
1804# $(1) - Output target notice filename
1805# $(2) - Product name
1806# $(3) - File title
1807# $(4) - License metadata file roots
1808# $(5) - Prefixes to strip
1809#
1810define text-notice-rule
1811$(1): PRIVATE_PRODUCT := $(2)
1812$(1): PRIVATE_MESSAGE := $(3)
1813$(1): $(call corresponding-license-metadata,$(4)) $(TEXTNOTICE) $(BUILD_SYSTEM)/Makefile
1814	OUT_DIR=$(OUT_DIR) $(TEXTNOTICE) -o $$@ -product=$$(PRIVATE_PRODUCT) -title=$$(PRIVATE_MESSAGE) $(foreach prefix, $(5), -strip_prefix=$(prefix)) $(call corresponding-license-metadata,$(4))
1815
1816notice_files: $(1)
1817endef
1818
1819# Conversion license metadata into html notice file.
1820# $(1) - Output target notice filename
1821# $(2) - Product name
1822# $(3) - File title
1823# $(4) - License metadata file roots
1824# $(5) - Prefixes to strip
1825#
1826define html-notice-rule
1827$(1): PRIVATE_PRODUCT := $(2)
1828$(1): PRIVATE_MESSAGE := $(3)
1829$(1): $(call corresponding-license-metadata,$(4)) $(HTMLNOTICE) $(BUILD_SYSTEM)/Makefile
1830	OUT_DIR=$(OUT_DIR) $(HTMLNOTICE) -o $$@ -product=$$(PRIVATE_PRODUCT) -title=$$(PRIVATE_MESSAGE) $(foreach prefix, $(5), -strip_prefix=$(prefix)) $(call corresponding-license-metadata,$(4))
1831
1832notice_files: $(1)
1833endef
1834
1835$(KATI_obsolete_var combine-notice-files, To create notice files use xml-notice-rule, html-notice-rule, or text-notice-rule.)
1836
1837# Notice file logic isn't relevant for TARGET_BUILD_APPS
1838ifndef TARGET_BUILD_APPS
1839
1840# TODO These intermediate NOTICE.txt/NOTICE.html files should go into
1841# TARGET_OUT_NOTICE_FILES now that the notice files are gathered from
1842# the src subdirectory.
1843kernel_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/kernel.txt
1844
1845# Some targets get included under $(PRODUCT_OUT) for debug symbols or other
1846# reasons--not to be flashed onto any device. Targets under these directories
1847# need no associated notice file on the device UI.
1848exclude_target_dirs := apex
1849
1850# TODO(b/69865032): Make PRODUCT_NOTICE_SPLIT the default behavior.
1851ifneq ($(PRODUCT_NOTICE_SPLIT),true)
1852#target_notice_file_html := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html
1853target_notice_file_html_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html.gz
1854installed_notice_html_or_xml_gz := $(TARGET_OUT)/etc/NOTICE.html.gz
1855
1856$(call declare-0p-target,$(target_notice_file_html_gz))
1857$(call declare-0p-target,$(installed_notice_html_or_xml_gz))
1858else
1859# target_notice_file_xml := $(TARGET_OUT_INTERMEDIATES)/NOTICE.xml
1860target_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.xml.gz
1861installed_notice_html_or_xml_gz := $(TARGET_OUT)/etc/NOTICE.xml.gz
1862
1863target_vendor_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.txt
1864target_vendor_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR.xml.gz
1865installed_vendor_notice_xml_gz := $(TARGET_OUT_VENDOR)/etc/NOTICE.xml.gz
1866
1867target_product_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT.txt
1868target_product_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_PRODUCT.xml.gz
1869installed_product_notice_xml_gz := $(TARGET_OUT_PRODUCT)/etc/NOTICE.xml.gz
1870
1871target_system_ext_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_SYSTEM_EXT.txt
1872target_system_ext_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_SYSTEM_EXT.xml.gz
1873installed_system_ext_notice_xml_gz := $(TARGET_OUT_SYSTEM_EXT)/etc/NOTICE.xml.gz
1874
1875target_odm_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_ODM.txt
1876target_odm_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_ODM.xml.gz
1877installed_odm_notice_xml_gz := $(TARGET_OUT_ODM)/etc/NOTICE.xml.gz
1878
1879target_vendor_dlkm_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR_DLKM.txt
1880target_vendor_dlkm_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_VENDOR_DLKM.xml.gz
1881installed_vendor_dlkm_notice_xml_gz := $(TARGET_OUT_VENDOR_DLKM)/etc/NOTICE.xml.gz
1882
1883target_odm_dlkm_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_ODM_DLKM.txt
1884target_odm_dlkm_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_ODM_DLKM.xml.gz
1885installed_odm_dlkm_notice_xml_gz := $(TARGET_OUT_ODM_DLKM)/etc/NOTICE.xml.gz
1886
1887target_system_dlkm_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE_SYSTEM_DLKM.txt
1888target_system_dlkm_notice_file_xml_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE_SYSTEM_DLKM.xml.gz
1889installed_system_dlkm_notice_xml_gz := $(TARGET_OUT_SYSTEM_DLKM)/etc/NOTICE.xml.gz
1890
1891ALL_INSTALLED_NOTICE_FILES := \
1892  $(installed_notice_html_or_xml_gz) \
1893  $(installed_vendor_notice_xml_gz) \
1894  $(installed_product_notice_xml_gz) \
1895  $(installed_system_ext_notice_xml_gz) \
1896  $(installed_odm_notice_xml_gz) \
1897  $(installed_vendor_dlkm_notice_xml_gz) \
1898  $(installed_odm_dlkm_notice_xml_gz) \
1899  $(installed_system_dlkm_notice_xml_gz) \
1900
1901# $1 installed file path, e.g. out/target/product/vsoc_x86_64/system_ext/etc/NOTICE.xml.gz
1902define is-notice-file
1903$(if $(findstring $1,$(ALL_INSTALLED_NOTICE_FILES)),Y)
1904endef
1905
1906# Notice files are copied to TARGET_OUT_NOTICE_FILES as a side-effect of their module
1907# being built. A notice xml file must depend on all modules that could potentially
1908# install a license file relevant to it.
1909license_modules := $(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file)
1910# Only files copied to a system image need system image notices.
1911license_modules := $(filter $(PRODUCT_OUT)/%,$(license_modules))
1912# Phonys/fakes don't have notice files (though their deps might)
1913license_modules := $(filter-out $(TARGET_OUT_FAKE)/%,$(license_modules))
1914# testcases are not relevant to the system image.
1915license_modules := $(filter-out $(TARGET_OUT_TESTCASES)/%,$(license_modules))
1916# filesystem images: system, vendor, product, system_ext, odm, vendor_dlkm, and odm_dlkm
1917license_modules_system := $(filter $(TARGET_OUT)/%,$(license_modules))
1918# system_other is relevant to system partition.
1919license_modules_system += $(filter $(TARGET_OUT_SYSTEM_OTHER)/%,$(license_modules))
1920license_modules_vendor := $(filter $(TARGET_OUT_VENDOR)/%,$(license_modules))
1921license_modules_product := $(filter $(TARGET_OUT_PRODUCT)/%,$(license_modules))
1922license_modules_system_ext := $(filter $(TARGET_OUT_SYSTEM_EXT)/%,$(license_modules))
1923license_modules_odm := $(filter $(TARGET_OUT_ODM)/%,$(license_modules))
1924license_modules_vendor_dlkm := $(filter $(TARGET_OUT_VENDOR_DLKM)/%,$(license_modules))
1925license_modules_odm_dlkm := $(filter $(TARGET_OUT_ODM_DLKM)/%,$(license_modules))
1926license_modules_odm_dlkm := $(filter $(TARGET_OUT_SYSTEM_DLKM)/%,$(license_modules))
1927license_modules_agg := $(license_modules_system) \
1928                       $(license_modules_vendor) \
1929                       $(license_modules_product) \
1930                       $(license_modules_system_ext) \
1931                       $(license_modules_odm) \
1932                       $(license_modules_vendor_dlkm) \
1933                       $(license_modules_odm_dlkm) \
1934                       $(license_modules_system_dlkm)
1935# targets used for debug symbols only and do not get copied to the device
1936license_modules_symbols_only := $(filter $(PRODUCT_OUT)/apex/%,$(license_modules))
1937
1938license_modules_rest := $(filter-out $(license_modules_agg),$(license_modules))
1939license_modules_rest := $(filter-out $(license_modules_symbols_only),$(license_modules_rest))
1940
1941# Identify the other targets we expect to have notices for:
1942# targets copied to the device but are not readable by the UI (e.g. must boot
1943# into a different partition to read or don't have an associated /etc
1944# directory) must have their notices built somewhere readable.
1945license_modules_rehomed := $(filter-out $(PRODUCT_OUT)/%/%,$(license_modules_rest))  # files in root have no /etc
1946license_modules_rehomed += $(filter $(PRODUCT_OUT)/recovery/%,$(license_modules_rest))
1947license_modules_rehomed += $(filter $(PRODUCT_OUT)/root/%,$(license_modules_rest))
1948license_modules_rehomed += $(filter $(PRODUCT_OUT)/data/%,$(license_modules_rest))
1949license_modules_rehomed += $(filter $(PRODUCT_OUT)/ramdisk/%,$(license_modules_rest))
1950license_modules_rehomed += $(filter $(PRODUCT_OUT)/debug_ramdisk/%,$(license_modules_rest))
1951license_modules_rehomed += $(filter $(PRODUCT_OUT)/vendor_ramdisk/%,$(license_modules_rest))
1952license_modules_rehomed += $(filter $(PRODUCT_OUT)/persist/%,$(license_modules_rest))
1953license_modules_rehomed += $(filter $(PRODUCT_OUT)/persist.img,$(license_modules_rest))
1954license_modules_rehomed += $(filter $(PRODUCT_OUT)/system_other/%,$(license_modules_rest))
1955license_modules_rehomed += $(filter $(PRODUCT_OUT)/kernel%,$(license_modules_rest))
1956license_modules_rehomed += $(filter $(PRODUCT_OUT)/%.img,$(license_modules_rest))
1957license_modules_rehomed += $(filter $(PRODUCT_OUT)/%.bin,$(license_modules_rest))
1958
1959# after removing targets in system images, targets reported in system images, and
1960# targets used for debug symbols that do not need notices, nothing must remain.
1961license_modules_rest := $(filter-out $(license_modules_rehomed),$(license_modules_rest))
1962$(call maybe-print-list-and-error, $(license_modules_rest), \
1963        "Targets added under $(PRODUCT_OUT)/ unaccounted for notice handling.")
1964
1965# If we are building in a configuration that includes a prebuilt vendor.img, we can't
1966# update its notice file, so include those notices in the system partition instead
1967ifdef BOARD_PREBUILT_VENDORIMAGE
1968license_modules_system += $(license_modules_rehomed)
1969system_xml_directories := xml_excluded_vendor_product_odm_vendor_dlkm_odm_dlkm
1970system_notice_file_message := "Notices for files contained in all filesystem images except vendor/system_ext/product/odm/vendor_dlkm/odm_dlkm in this directory:"
1971else
1972license_modules_vendor += $(license_modules_rehomed)
1973system_xml_directories := xml_system
1974system_notice_file_message := "Notices for files contained in the system filesystem image in this directory:"
1975endif
1976
1977endif # PRODUCT_NOTICE_SPLIT
1978
1979ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_or_xml_gz)
1980
1981need_vendor_notice:=false
1982ifeq ($(BUILDING_VENDOR_BOOT_IMAGE),true)
1983   need_vendor_notice:=true
1984endif
1985
1986ifdef BUILDING_DEBUG_VENDOR_BOOT_IMAGE
1987   need_vendor_notice:=true
1988endif
1989
1990ifdef BUILDING_VENDOR_IMAGE
1991   need_vendor_notice:=true
1992endif
1993
1994ifeq (true,$(need_vendor_notice))
1995ifneq (,$(installed_vendor_notice_xml_gz))
1996ALL_DEFAULT_INSTALLED_MODULES += $(installed_vendor_notice_xml_gz)
1997endif
1998endif
1999
2000need_vendor_notice:=
2001
2002ifdef BUILDING_ODM_IMAGE
2003ifneq (,$(installed_odm_notice_xml_gz))
2004ALL_DEFAULT_INSTALLED_MODULES += $(installed_odm_notice_xml_gz)
2005endif
2006endif
2007
2008ifdef BUILDING_PRODUCT_IMAGE
2009ifneq (,$(installed_product_notice_xml_gz))
2010ALL_DEFAULT_INSTALLED_MODULES += $(installed_product_notice_xml_gz)
2011endif
2012endif
2013
2014ifdef BUILDING_SYSTEM_EXT_IMAGE
2015ifneq (,$(installed_system_ext_notice_xml_gz))
2016ALL_DEFAULT_INSTALLED_MODULES += $(installed_system_ext_notice_xml_gz)
2017endif
2018endif
2019
2020ifdef BUILDING_VENDOR_DLKM_IMAGE
2021ifneq (,$(installed_vendor_dlkm_notice_xml_gz)
2022ALL_DEFAULT_INSTALLED_MODULES += $(installed_vendor_dlkm_notice_xml_gz)
2023endif
2024endif
2025
2026ifdef BUILDING_ODM_DLKM_IMAGE
2027ifneq (,$(installed_odm_dlkm_notice_xml_gz))
2028ALL_DEFAULT_INSTALLED_MODULES += $(installed_odm_dlkm_notice_xml_gz)
2029endif
2030endif
2031
2032ifdef BUILDING_SYSTEM_DLKM_IMAGE
2033ifneq (,$(installed_system_dlkm_notice_xml_gz))
2034ALL_DEFAULT_INSTALLED_MODULES += $(installed_system_dlkm_notice_xml_gz)
2035endif
2036endif
2037
2038endif  # TARGET_BUILD_APPS
2039
2040# Presently none of the prebuilts etc. comply with policy to have a license text. Fake one here.
2041$(eval $(call copy-one-file,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,$(kernel_notice_file)))
2042
2043ifneq (,$(strip $(INSTALLED_KERNEL_TARGET)))
2044$(call declare-license-metadata,$(INSTALLED_KERNEL_TARGET),SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,"Kernel",kernel)
2045endif
2046
2047# No matter where it gets copied from, a copied linux kernel is licensed under "GPL 2.0 only"
2048$(eval $(call declare-copy-files-license-metadata,,:kernel,SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,kernel))
2049
2050
2051# #################################################################
2052# Targets for user images
2053# #################################################################
2054
2055# These options tell the recovery updater/installer how to mount the partitions writebale.
2056# <fstype>=<fstype_opts>[|<fstype_opts>]...
2057# fstype_opts := <opt>[,<opt>]...
2058#         opt := <name>[=<value>]
2059# The following worked on Nexus devices with Kernel 3.1, 3.4, 3.10
2060DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS := ext4=max_batch_time=0,commit=1,data=ordered,barrier=1,errors=panic,nodelalloc
2061
2062INTERNAL_USERIMAGES_DEPS := \
2063    $(BUILD_IMAGE) \
2064    $(MKE2FS_CONF) \
2065    $(MKEXTUSERIMG)
2066
2067$(call declare-1p-target,$(MKE2FS_CONF),system/extras)
2068
2069ifeq ($(TARGET_USERIMAGES_USE_F2FS),true)
2070INTERNAL_USERIMAGES_DEPS += $(MKF2FSUSERIMG)
2071endif
2072
2073ifneq ($(filter \
2074    $(BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE) \
2075    $(BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE) \
2076    $(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE) \
2077    $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE) \
2078    $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE) \
2079    $(BOARD_VENDOR_DLKMIMAGE_FILE_SYSTEM_TYPE) \
2080    $(BOARD_ODM_DLKMIMAGE_FILE_SYSTEM_TYPE) \
2081    $(BOARD_SYSTEM_DLKMIMAGE_FILE_SYSTEM_TYPE) \
2082  ,erofs),)
2083INTERNAL_USERIMAGES_DEPS += $(MKEROFS)
2084ifeq ($(BOARD_EROFS_USE_LEGACY_COMPRESSION),true)
2085BOARD_EROFS_COMPRESSOR ?= "lz4"
2086else
2087BOARD_EROFS_COMPRESSOR ?= "lz4hc,9"
2088endif
2089endif
2090
2091ifneq ($(filter \
2092    $(BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE) \
2093    $(BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE) \
2094    $(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE) \
2095    $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE) \
2096    $(BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE) \
2097    $(BOARD_VENDOR_DLKMIMAGE_FILE_SYSTEM_TYPE) \
2098    $(BOARD_ODM_DLKMIMAGE_FILE_SYSTEM_TYPE) \
2099    $(BOARD_SYSTEM_DLKMIMAGE_FILE_SYSTEM_TYPE) \
2100  ,squashfs),)
2101INTERNAL_USERIMAGES_DEPS += $(MKSQUASHFSUSERIMG)
2102endif
2103
2104ifeq ($(BOARD_AVB_ENABLE),true)
2105INTERNAL_USERIMAGES_DEPS += $(AVBTOOL)
2106endif
2107
2108# Get a colon-separated list of search paths.
2109INTERNAL_USERIMAGES_BINARY_PATHS := $(subst $(space),:,$(sort $(dir $(INTERNAL_USERIMAGES_DEPS))))
2110
2111SELINUX_FC := $(call intermediates-dir-for,ETC,file_contexts.bin)/file_contexts.bin
2112
2113INTERNAL_USERIMAGES_DEPS += $(SELINUX_FC)
2114
2115# $(1) the partition name (eg system)
2116# $(2) the image prop file
2117define add-common-flags-to-image-props
2118$(eval _var := $(call to-upper,$(1)))
2119$(hide) echo "$(1)_selinux_fc=$(SELINUX_FC)" >> $(2)
2120$(hide) echo "building_$(1)_image=$(BUILDING_$(_var)_IMAGE)" >> $(2)
2121endef
2122
2123# $(1) the partition name (eg system)
2124# $(2) the image prop file
2125define add-common-ro-flags-to-image-props
2126$(eval _var := $(call to-upper,$(1)))
2127$(if $(BOARD_$(_var)IMAGE_EROFS_COMPRESSOR),$(hide) echo "$(1)_erofs_compressor=$(BOARD_$(_var)IMAGE_EROFS_COMPRESSOR)" >> $(2))
2128$(if $(BOARD_$(_var)IMAGE_EROFS_COMPRESS_HINTS),$(hide) echo "$(1)_erofs_compress_hints=$(BOARD_$(_var)IMAGE_EROFS_COMPRESS_HINTS)" >> $(2))
2129$(if $(BOARD_$(_var)IMAGE_EROFS_PCLUSTER_SIZE),$(hide) echo "$(1)_erofs_pcluster_size=$(BOARD_$(_var)IMAGE_EROFS_PCLUSTER_SIZE)" >> $(2))
2130$(if $(BOARD_$(_var)IMAGE_EROFS_BLOCKSIZE),$(hide) echo "$(1)_erofs_blocksize=$(BOARD_$(_var)IMAGE_EROFS_BLOCKSIZE)" >> $(2))
2131$(if $(BOARD_$(_var)IMAGE_EXTFS_INODE_COUNT),$(hide) echo "$(1)_extfs_inode_count=$(BOARD_$(_var)IMAGE_EXTFS_INODE_COUNT)" >> $(2))
2132$(if $(BOARD_$(_var)IMAGE_EXTFS_RSV_PCT),$(hide) echo "$(1)_extfs_rsv_pct=$(BOARD_$(_var)IMAGE_EXTFS_RSV_PCT)" >> $(2))
2133$(if $(BOARD_$(_var)IMAGE_F2FS_SLOAD_COMPRESS_FLAGS),$(hide) echo "$(1)_f2fs_sldc_flags=$(BOARD_$(_var)IMAGE_F2FS_SLOAD_COMPRESS_FLAGS)" >> $(2))
2134$(if $(BOARD_$(_var)IMAGE_F2FS_BLOCKSIZE),$(hide) echo "$(1)_f2fs_blocksize=$(BOARD_$(_var)IMAGE_F2FS_BLOCKSIZE)" >> $(2))
2135$(if $(BOARD_$(_var)IMAGE_FILE_SYSTEM_COMPRESS),$(hide) echo "$(1)_f2fs_compress=$(BOARD_$(_var)IMAGE_FILE_SYSTEM_COMPRESS)" >> $(2))
2136$(if $(BOARD_$(_var)IMAGE_FILE_SYSTEM_TYPE),$(hide) echo "$(1)_fs_type=$(BOARD_$(_var)IMAGE_FILE_SYSTEM_TYPE)" >> $(2))
2137$(if $(BOARD_$(_var)IMAGE_JOURNAL_SIZE),$(hide) echo "$(1)_journal_size=$(BOARD_$(_var)IMAGE_JOURNAL_SIZE)" >> $(2))
2138$(if $(BOARD_$(_var)IMAGE_PARTITION_RESERVED_SIZE),$(hide) echo "$(1)_reserved_size=$(BOARD_$(_var)IMAGE_PARTITION_RESERVED_SIZE)" >> $(2))
2139$(if $(BOARD_$(_var)IMAGE_PARTITION_SIZE),$(hide) echo "$(1)_size=$(BOARD_$(_var)IMAGE_PARTITION_SIZE)" >> $(2))
2140$(if $(BOARD_$(_var)IMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "$(1)_squashfs_block_size=$(BOARD_$(_var)IMAGE_SQUASHFS_BLOCK_SIZE)" >> $(2))
2141$(if $(BOARD_$(_var)IMAGE_SQUASHFS_COMPRESSOR),$(hide) echo "$(1)_squashfs_compressor=$(BOARD_$(_var)IMAGE_SQUASHFS_COMPRESSOR)" >> $(2))
2142$(if $(BOARD_$(_var)IMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "$(1)_squashfs_compressor_opt=$(BOARD_$(_var)IMAGE_SQUASHFS_COMPRESSOR_OPT)" >> $(2))
2143$(if $(BOARD_$(_var)IMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "$(1)_squashfs_disable_4k_align=$(BOARD_$(_var)IMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(2))
2144$(if $(PRODUCT_$(_var)_BASE_FS_PATH),$(hide) echo "$(1)_base_fs_file=$(PRODUCT_$(_var)_BASE_FS_PATH)" >> $(2))
2145$(eval _size := $(BOARD_$(_var)IMAGE_PARTITION_SIZE))
2146$(eval _reserved := $(BOARD_$(_var)IMAGE_PARTITION_RESERVED_SIZE))
2147$(eval _headroom := $(PRODUCT_$(_var)_HEADROOM))
2148$(if $(or $(_size), $(_reserved), $(_headroom)),,
2149    $(hide) echo "$(1)_disable_sparse=true" >> $(2))
2150$(call add-common-flags-to-image-props,$(1),$(2))
2151endef
2152
2153# $(1): the path of the output dictionary file
2154# $(2): a subset of "system vendor cache userdata product system_ext oem odm vendor_dlkm odm_dlkm system_dlkm"
2155# $(3): additional "key=value" pairs to append to the dictionary file.
2156define generate-image-prop-dictionary
2157$(if $(filter $(2),system),\
2158    $(if $(INTERNAL_SYSTEM_OTHER_PARTITION_SIZE),$(hide) echo "system_other_size=$(INTERNAL_SYSTEM_OTHER_PARTITION_SIZE)" >> $(1))
2159    $(if $(PRODUCT_SYSTEM_HEADROOM),$(hide) echo "system_headroom=$(PRODUCT_SYSTEM_HEADROOM)" >> $(1))
2160    $(call add-common-ro-flags-to-image-props,system,$(1))
2161)
2162$(if $(filter $(2),system_other),\
2163    $(hide) echo "building_system_other_image=$(BUILDING_SYSTEM_OTHER_IMAGE)" >> $(1)
2164    $(if $(INTERNAL_SYSTEM_OTHER_PARTITION_SIZE),,
2165        $(hide) echo "system_other_disable_sparse=true" >> $(1))
2166)
2167$(if $(filter $(2),userdata),\
2168    $(if $(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "userdata_fs_type=$(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
2169    $(if $(BOARD_USERDATAIMAGE_PARTITION_SIZE),$(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(1))
2170    $(if $(PRODUCT_FS_CASEFOLD),$(hide) echo "needs_casefold=$(PRODUCT_FS_CASEFOLD)" >> $(1))
2171    $(if $(PRODUCT_QUOTA_PROJID),$(hide) echo "needs_projid=$(PRODUCT_QUOTA_PROJID)" >> $(1))
2172    $(if $(PRODUCT_FS_COMPRESSION),$(hide) echo "needs_compress=$(PRODUCT_FS_COMPRESSION)" >> $(1))
2173    $(call add-common-flags-to-image-props,userdata,$(1))
2174)
2175$(if $(filter $(2),cache),\
2176    $(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
2177    $(if $(BOARD_CACHEIMAGE_PARTITION_SIZE),$(hide) echo "cache_size=$(BOARD_CACHEIMAGE_PARTITION_SIZE)" >> $(1))
2178    $(call add-common-flags-to-image-props,cache,$(1))
2179)
2180$(if $(filter $(2),vendor),\
2181    $(call add-common-ro-flags-to-image-props,vendor,$(1))
2182)
2183$(if $(filter $(2),product),\
2184    $(call add-common-ro-flags-to-image-props,product,$(1))
2185)
2186$(if $(filter $(2),system_ext),\
2187    $(call add-common-ro-flags-to-image-props,system_ext,$(1))
2188)
2189$(if $(filter $(2),odm),\
2190    $(call add-common-ro-flags-to-image-props,odm,$(1))
2191)
2192$(if $(filter $(2),vendor_dlkm),\
2193    $(call add-common-ro-flags-to-image-props,vendor_dlkm,$(1))
2194)
2195$(if $(filter $(2),odm_dlkm),\
2196    $(call add-common-ro-flags-to-image-props,odm_dlkm,$(1))
2197)
2198$(if $(filter $(2),system_dlkm),\
2199    $(call add-common-ro-flags-to-image-props,system_dlkm,$(1))
2200)
2201$(if $(filter $(2),oem),\
2202    $(if $(BOARD_OEMIMAGE_PARTITION_SIZE),$(hide) echo "oem_size=$(BOARD_OEMIMAGE_PARTITION_SIZE)" >> $(1))
2203    $(if $(BOARD_OEMIMAGE_JOURNAL_SIZE),$(hide) echo "oem_journal_size=$(BOARD_OEMIMAGE_JOURNAL_SIZE)" >> $(1))
2204    $(if $(BOARD_OEMIMAGE_EXTFS_INODE_COUNT),$(hide) echo "oem_extfs_inode_count=$(BOARD_OEMIMAGE_EXTFS_INODE_COUNT)" >> $(1))
2205    $(if $(BOARD_OEMIMAGE_EXTFS_RSV_PCT),$(hide) echo "oem_extfs_rsv_pct=$(BOARD_OEMIMAGE_EXTFS_RSV_PCT)" >> $(1))
2206    $(call add-common-flags-to-image-props,oem,$(1))
2207)
2208$(hide) echo "ext_mkuserimg=$(notdir $(MKEXTUSERIMG))" >> $(1)
2209
2210$(if $(filter true,$(TARGET_USERIMAGES_USE_EXT2)),$(hide) echo "fs_type=ext2" >> $(1),
2211  $(if $(filter true,$(TARGET_USERIMAGES_USE_EXT3)),$(hide) echo "fs_type=ext3" >> $(1),
2212    $(if $(filter true,$(TARGET_USERIMAGES_USE_EXT4)),$(hide) echo "fs_type=ext4" >> $(1))))
2213
2214$(if $(filter true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED)),,$(hide) echo "extfs_sparse_flag=-s" >> $(1))
2215$(if $(filter true,$(TARGET_USERIMAGES_SPARSE_EROFS_DISABLED)),,$(hide) echo "erofs_sparse_flag=-s" >> $(1))
2216$(if $(filter true,$(TARGET_USERIMAGES_SPARSE_SQUASHFS_DISABLED)),,$(hide) echo "squashfs_sparse_flag=-s" >> $(1))
2217$(if $(filter true,$(TARGET_USERIMAGES_SPARSE_F2FS_DISABLED)),,$(hide) echo "f2fs_sparse_flag=-S" >> $(1))
2218$(if $(BOARD_EROFS_COMPRESSOR),$(hide) echo "erofs_default_compressor=$(BOARD_EROFS_COMPRESSOR)" >> $(1))
2219$(if $(BOARD_EROFS_COMPRESS_HINTS),$(hide) echo "erofs_default_compress_hints=$(BOARD_EROFS_COMPRESS_HINTS)" >> $(1))
2220$(if $(BOARD_EROFS_PCLUSTER_SIZE),$(hide) echo "erofs_pcluster_size=$(BOARD_EROFS_PCLUSTER_SIZE)" >> $(1))
2221$(if $(BOARD_EROFS_BLOCKSIZE),$(hide) echo "erofs_blocksize=$(BOARD_EROFS_BLOCKSIZE)" >> $(1))
2222$(if $(BOARD_EROFS_SHARE_DUP_BLOCKS),$(hide) echo "erofs_share_dup_blocks=$(BOARD_EROFS_SHARE_DUP_BLOCKS)" >> $(1))
2223$(if $(BOARD_EROFS_USE_LEGACY_COMPRESSION),$(hide) echo "erofs_use_legacy_compression=$(BOARD_EROFS_USE_LEGACY_COMPRESSION)" >> $(1))
2224$(if $(BOARD_EXT4_SHARE_DUP_BLOCKS),$(hide) echo "ext4_share_dup_blocks=$(BOARD_EXT4_SHARE_DUP_BLOCKS)" >> $(1))
2225$(if $(BOARD_F2FS_BLOCKSIZE),$(hide) echo "f2fs_blocksize=$(BOARD_F2FS_BLOCKSIZE)" >> $(1))
2226$(if $(BOARD_FLASH_LOGICAL_BLOCK_SIZE), $(hide) echo "flash_logical_block_size=$(BOARD_FLASH_LOGICAL_BLOCK_SIZE)" >> $(1))
2227$(if $(BOARD_FLASH_ERASE_BLOCK_SIZE), $(hide) echo "flash_erase_block_size=$(BOARD_FLASH_ERASE_BLOCK_SIZE)" >> $(1))
2228$(if $(filter eng, $(TARGET_BUILD_VARIANT)),$(hide) echo "verity_disable=true" >> $(1))
2229$(if $(PRODUCT_SYSTEM_VERITY_PARTITION),$(hide) echo "system_verity_block_device=$(PRODUCT_SYSTEM_VERITY_PARTITION)" >> $(1))
2230$(if $(PRODUCT_VENDOR_VERITY_PARTITION),$(hide) echo "vendor_verity_block_device=$(PRODUCT_VENDOR_VERITY_PARTITION)" >> $(1))
2231$(if $(PRODUCT_PRODUCT_VERITY_PARTITION),$(hide) echo "product_verity_block_device=$(PRODUCT_PRODUCT_VERITY_PARTITION)" >> $(1))
2232$(if $(PRODUCT_SYSTEM_EXT_VERITY_PARTITION),$(hide) echo "system_ext_verity_block_device=$(PRODUCT_SYSTEM_EXT_VERITY_PARTITION)" >> $(1))
2233$(if $(PRODUCT_VENDOR_DLKM_VERITY_PARTITION),$(hide) echo "vendor_dlkm_verity_block_device=$(PRODUCT_VENDOR_DLKM_VERITY_PARTITION)" >> $(1))
2234$(if $(PRODUCT_ODM_DLKM_VERITY_PARTITION),$(hide) echo "odm_dlkm_verity_block_device=$(PRODUCT_ODM_DLKM_VERITY_PARTITION)" >> $(1))
2235$(if $(PRODUCT_SYSTEM_DLKM_VERITY_PARTITION),$(hide) echo "system_dlkm_verity_block_device=$(PRODUCT_SYSTEM_DLKM_VERITY_PARTITION)" >> $(1))
2236$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot=$(PRODUCT_SUPPORTS_VBOOT)" >> $(1))
2237$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_key=$(PRODUCT_VBOOT_SIGNING_KEY)" >> $(1))
2238$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_subkey=$(PRODUCT_VBOOT_SIGNING_SUBKEY)" >> $(1))
2239$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "futility=$(notdir $(FUTILITY))" >> $(1))
2240$(if $(PRODUCT_SUPPORTS_VBOOT),$(hide) echo "vboot_signer_cmd=$(VBOOT_SIGNER)" >> $(1))
2241$(if $(BOARD_AVB_ENABLE), \
2242  $(hide) echo "avb_avbtool=$(notdir $(AVBTOOL))" >> $(1)$(newline) \
2243  $(if $(filter $(2),system), \
2244    $(hide) echo "avb_system_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1)$(newline) \
2245    $(hide) echo "avb_system_add_hashtree_footer_args=$(BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1)$(newline) \
2246    $(if $(BOARD_AVB_SYSTEM_KEY_PATH), \
2247      $(hide) echo "avb_system_key_path=$(BOARD_AVB_SYSTEM_KEY_PATH)" >> $(1)$(newline) \
2248      $(hide) echo "avb_system_algorithm=$(BOARD_AVB_SYSTEM_ALGORITHM)" >> $(1)$(newline) \
2249      $(hide) echo "avb_system_rollback_index_location=$(BOARD_AVB_SYSTEM_ROLLBACK_INDEX_LOCATION)" >> $(1)$(newline))) \
2250  $(if $(filter $(2),system_other), \
2251    $(hide) echo "avb_system_other_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1)$(newline) \
2252    $(hide) echo "avb_system_other_add_hashtree_footer_args=$(BOARD_AVB_SYSTEM_OTHER_ADD_HASHTREE_FOOTER_ARGS)" >> $(1)$(newline) \
2253    $(if $(BOARD_AVB_SYSTEM_OTHER_KEY_PATH),\
2254      $(hide) echo "avb_system_other_key_path=$(BOARD_AVB_SYSTEM_OTHER_KEY_PATH)" >> $(1)$(newline) \
2255      $(hide) echo "avb_system_other_algorithm=$(BOARD_AVB_SYSTEM_OTHER_ALGORITHM)" >> $(1)$(newline))) \
2256  $(if $(filter $(2),vendor), \
2257    $(hide) echo "avb_vendor_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1)$(newline) \
2258    $(hide) echo "avb_vendor_add_hashtree_footer_args=$(BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS)" >> $(1)$(newline) \
2259    $(if $(BOARD_AVB_VENDOR_KEY_PATH),\
2260      $(hide) echo "avb_vendor_key_path=$(BOARD_AVB_VENDOR_KEY_PATH)" >> $(1)$(newline) \
2261      $(hide) echo "avb_vendor_algorithm=$(BOARD_AVB_VENDOR_ALGORITHM)" >> $(1)$(newline) \
2262      $(hide) echo "avb_vendor_rollback_index_location=$(BOARD_AVB_VENDOR_ROLLBACK_INDEX_LOCATION)" >> $(1)$(newline))) \
2263  $(if $(filter $(2),product), \
2264    $(hide) echo "avb_product_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1)$(newline) \
2265    $(hide) echo "avb_product_add_hashtree_footer_args=$(BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS)" >> $(1)$(newline) \
2266    $(if $(BOARD_AVB_PRODUCT_KEY_PATH),\
2267      $(hide) echo "avb_product_key_path=$(BOARD_AVB_PRODUCT_KEY_PATH)" >> $(1)$(newline) \
2268      $(hide) echo "avb_product_algorithm=$(BOARD_AVB_PRODUCT_ALGORITHM)" >> $(1)$(newline) \
2269      $(hide) echo "avb_product_rollback_index_location=$(BOARD_AVB_PRODUCT_ROLLBACK_INDEX_LOCATION)" >> $(1)$(newline))) \
2270  $(if $(filter $(2),system_ext), \
2271    $(hide) echo "avb_system_ext_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1)$(newline) \
2272    $(hide) echo "avb_system_ext_add_hashtree_footer_args=$(BOARD_AVB_SYSTEM_EXT_ADD_HASHTREE_FOOTER_ARGS)" >> $(1)$(newline) \
2273    $(if $(BOARD_AVB_SYSTEM_EXT_KEY_PATH),\
2274      $(hide) echo "avb_system_ext_key_path=$(BOARD_AVB_SYSTEM_EXT_KEY_PATH)" >> $(1)$(newline) \
2275      $(hide) echo "avb_system_ext_algorithm=$(BOARD_AVB_SYSTEM_EXT_ALGORITHM)" >> $(1)$(newline) \
2276      $(hide) echo "avb_system_ext_rollback_index_location=$(BOARD_AVB_SYSTEM_EXT_ROLLBACK_INDEX_LOCATION)" >> $(1)$(newline))) \
2277  $(if $(filter $(2),odm), \
2278    $(hide) echo "avb_odm_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1)$(newline) \
2279    $(hide) echo "avb_odm_add_hashtree_footer_args=$(BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1)$(newline) \
2280    $(if $(BOARD_AVB_ODM_KEY_PATH),\
2281      $(hide) echo "avb_odm_key_path=$(BOARD_AVB_ODM_KEY_PATH)" >> $(1)$(newline) \
2282      $(hide) echo "avb_odm_algorithm=$(BOARD_AVB_ODM_ALGORITHM)" >> $(1)$(newline) \
2283      $(hide) echo "avb_odm_rollback_index_location=$(BOARD_AVB_ODM_ROLLBACK_INDEX_LOCATION)" >> $(1)$(newline))) \
2284  $(if $(filter $(2),vendor_dlkm), \
2285    $(hide) echo "avb_vendor_dlkm_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1)$(newline) \
2286    $(hide) echo "avb_vendor_dlkm_add_hashtree_footer_args=$(BOARD_AVB_VENDOR_DLKM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1)$(newline) \
2287    $(if $(BOARD_AVB_VENDOR_DLKM_KEY_PATH),\
2288      $(hide) echo "avb_vendor_dlkm_key_path=$(BOARD_AVB_VENDOR_DLKM_KEY_PATH)" >> $(1)$(newline) \
2289      $(hide) echo "avb_vendor_dlkm_algorithm=$(BOARD_AVB_VENDOR_DLKM_ALGORITHM)" >> $(1)$(newline) \
2290      $(hide) echo "avb_vendor_dlkm_rollback_index_location=$(BOARD_AVB_VENDOR_DLKM_ROLLBACK_INDEX_LOCATION)" >> $(1)$(newline))) \
2291  $(if $(filter $(2),odm_dlkm), \
2292    $(hide) echo "avb_odm_dlkm_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1)$(newline) \
2293    $(hide) echo "avb_odm_dlkm_add_hashtree_footer_args=$(BOARD_AVB_ODM_DLKM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1)$(newline) \
2294    $(if $(BOARD_AVB_ODM_DLKM_KEY_PATH),\
2295      $(hide) echo "avb_odm_dlkm_key_path=$(BOARD_AVB_ODM_DLKM_KEY_PATH)" >> $(1)$(newline) \
2296      $(hide) echo "avb_odm_dlkm_algorithm=$(BOARD_AVB_ODM_DLKM_ALGORITHM)" >> $(1)$(newline) \
2297      $(hide) echo "avb_odm_dlkm_rollback_index_location=$(BOARD_AVB_ODM_DLKM_ROLLBACK_INDEX_LOCATION)" >> $(1)$(newline))) \
2298  $(if $(filter $(2),system_dlkm), \
2299    $(hide) echo "avb_system_dlkm_hashtree_enable=$(BOARD_AVB_ENABLE)" >> $(1)$(newline) \
2300    $(hide) echo "avb_system_dlkm_add_hashtree_footer_args=$(BOARD_AVB_SYSTEM_DLKM_ADD_HASHTREE_FOOTER_ARGS)" >> $(1)$(newline) \
2301    $(if $(BOARD_AVB_SYSTEM_DLKM_KEY_PATH),\
2302      $(hide) echo "avb_system_dlkm_key_path=$(BOARD_AVB_SYSTEM_DLKM_KEY_PATH)" >> $(1)$(newline) \
2303      $(hide) echo "avb_system_dlkm_algorithm=$(BOARD_AVB_SYSTEM_DLKM_ALGORITHM)" >> $(1)$(newline) \
2304      $(hide) echo "avb_system_dlkm_rollback_index_location=$(BOARD_SYSTEM_SYSTEM_DLKM_ROLLBACK_INDEX_LOCATION)" >> $(1)$(newline))) \
2305)
2306$(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)),\
2307    $(hide) echo "recovery_as_boot=true" >> $(1))
2308$(hide) echo "root_dir=$(TARGET_ROOT_OUT)" >> $(1)
2309$(if $(filter true,$(PRODUCT_USE_DYNAMIC_PARTITION_SIZE)),\
2310    $(hide) echo "use_dynamic_partition_size=true" >> $(1))
2311$(if $(COPY_IMAGES_FOR_TARGET_FILES_ZIP),\
2312    $(hide) echo "use_fixed_timestamp=true" >> $(1))
2313$(if $(3),$(hide) $(foreach kv,$(3),echo "$(kv)" >> $(1);))
2314$(hide) sort -o $(1) $(1)
2315endef
2316
2317# $(1): the path of the output dictionary file
2318# $(2): additional "key=value" pairs to append to the dictionary file.
2319PROP_DICTIONARY_IMAGES := oem
2320ifdef BUILDING_CACHE_IMAGE
2321  PROP_DICTIONARY_IMAGES += cache
2322endif
2323ifdef BUILDING_SYSTEM_IMAGE
2324  PROP_DICTIONARY_IMAGES += system
2325endif
2326ifdef BUILDING_SYSTEM_OTHER_IMAGE
2327  PROP_DICTIONARY_IMAGES += system_other
2328endif
2329ifdef BUILDING_USERDATA_IMAGE
2330  PROP_DICTIONARY_IMAGES += userdata
2331endif
2332ifdef BUILDING_VENDOR_IMAGE
2333  PROP_DICTIONARY_IMAGES += vendor
2334endif
2335ifdef BUILDING_PRODUCT_IMAGE
2336  PROP_DICTIONARY_IMAGES += product
2337endif
2338ifdef BUILDING_SYSTEM_EXT_IMAGE
2339  PROP_DICTIONARY_IMAGES += system_ext
2340endif
2341ifdef BUILDING_ODM_IMAGE
2342  PROP_DICTIONARY_IMAGES += odm
2343endif
2344ifdef BUILDING_VENDOR_DLKM_IMAGE
2345  PROP_DICTIONARY_IMAGES += vendor_dlkm
2346endif
2347ifdef BUILDING_ODM_DLKM_IMAGE
2348  PROP_DICTIONARY_IMAGES += odm_dlkm
2349endif
2350ifdef BUILDING_SYSTEM_DLKM_IMAGE
2351  PROP_DICTIONARY_IMAGES += system_dlkm
2352endif
2353define generate-userimage-prop-dictionary
2354  $(call generate-image-prop-dictionary,$(1),$(PROP_DICTIONARY_IMAGES),$(2))
2355endef
2356
2357# $(1): the path of the input dictionary file, where each line has the format key=value
2358# $(2): the key to look up
2359define read-image-prop-dictionary
2360$$(grep '$(2)=' $(1) | cut -f2- -d'=')
2361endef
2362
2363# -----------------------------------------------------------------
2364# Recovery image
2365
2366# Recovery image exists if we are building recovery, or building recovery as boot.
2367INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_RECOVERY_OUT)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
2368ifdef BUILDING_RECOVERY_IMAGE
2369
2370INTERNAL_RECOVERYIMAGE_FILES := $(filter $(TARGET_RECOVERY_OUT)/%, \
2371    $(ALL_DEFAULT_INSTALLED_MODULES))
2372
2373INSTALLED_FILES_FILE_RECOVERY := $(PRODUCT_OUT)/installed-files-recovery.txt
2374INSTALLED_FILES_JSON_RECOVERY := $(INSTALLED_FILES_FILE_RECOVERY:.txt=.json)
2375
2376ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2377INSTALLED_BOOTIMAGE_TARGET := $(BUILT_BOOTIMAGE_TARGET)
2378endif
2379
2380# TODO(b/30414428): Can't depend on INTERNAL_RECOVERYIMAGE_FILES alone like other
2381# INSTALLED_FILES_FILE_* rules. Because currently there're cp/rsync/rm commands in
2382# build-recoveryimage-target, which would touch the files under TARGET_RECOVERY_OUT and race with
2383# the call to FILELIST.
2384$(INSTALLED_FILES_FILE_RECOVERY): $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
2385
2386$(INSTALLED_FILES_FILE_RECOVERY): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_RECOVERY)
2387$(INSTALLED_FILES_FILE_RECOVERY): $(INTERNAL_RECOVERYIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
2388	@echo Installed file list: $@
2389	mkdir -p $(dir $@)
2390	rm -f $@
2391	$(FILESLIST) $(TARGET_RECOVERY_ROOT_OUT) > $(@:.txt=.json)
2392	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
2393
2394$(eval $(call declare-0p-target,$(INSTALLED_FILES_FILE_RECOVERY)))
2395$(eval $(call declare-0p-target,$(INSTALLED_FILES_JSON_RECOVERY)))
2396
2397recovery_sepolicy := \
2398    $(TARGET_RECOVERY_ROOT_OUT)/sepolicy \
2399    $(TARGET_RECOVERY_ROOT_OUT)/plat_file_contexts \
2400    $(TARGET_RECOVERY_ROOT_OUT)/plat_service_contexts \
2401    $(TARGET_RECOVERY_ROOT_OUT)/plat_property_contexts \
2402    $(TARGET_RECOVERY_ROOT_OUT)/system_ext_file_contexts \
2403    $(TARGET_RECOVERY_ROOT_OUT)/system_ext_service_contexts \
2404    $(TARGET_RECOVERY_ROOT_OUT)/system_ext_property_contexts \
2405    $(TARGET_RECOVERY_ROOT_OUT)/vendor_file_contexts \
2406    $(TARGET_RECOVERY_ROOT_OUT)/vendor_service_contexts \
2407    $(TARGET_RECOVERY_ROOT_OUT)/vendor_property_contexts \
2408    $(TARGET_RECOVERY_ROOT_OUT)/odm_file_contexts \
2409    $(TARGET_RECOVERY_ROOT_OUT)/odm_property_contexts \
2410    $(TARGET_RECOVERY_ROOT_OUT)/product_file_contexts \
2411    $(TARGET_RECOVERY_ROOT_OUT)/product_service_contexts \
2412    $(TARGET_RECOVERY_ROOT_OUT)/product_property_contexts
2413
2414# Passed into rsync from non-recovery root to recovery root, to avoid overwriting recovery-specific
2415# SELinux files
2416IGNORE_RECOVERY_SEPOLICY := $(patsubst $(TARGET_RECOVERY_OUT)/%,--exclude=/%,$(recovery_sepolicy))
2417
2418# if building multiple boot images from multiple kernels, use the first kernel listed
2419# for the recovery image
2420recovery_kernel := $(firstword $(INSTALLED_KERNEL_TARGET))
2421recovery_ramdisk := $(PRODUCT_OUT)/ramdisk-recovery.img
2422recovery_resources_common := bootable/recovery/res
2423
2424# Set recovery_density to a density bucket based on TARGET_SCREEN_DENSITY, PRODUCT_AAPT_PREF_CONFIG,
2425# or mdpi, in order of preference. We support both specific buckets (e.g. xdpi) and numbers,
2426# which get remapped to a bucket.
2427recovery_density := $(or $(TARGET_SCREEN_DENSITY),$(PRODUCT_AAPT_PREF_CONFIG),mdpi)
2428ifeq (,$(filter xxxhdpi xxhdpi xhdpi hdpi mdpi,$(recovery_density)))
2429recovery_density_value := $(patsubst %dpi,%,$(recovery_density))
2430# We roughly use the medium point between the primary densities to split buckets.
2431# ------160------240------320----------480------------640------
2432#       mdpi     hdpi    xhdpi        xxhdpi        xxxhdpi
2433recovery_density := $(strip \
2434  $(or $(if $(filter $(shell echo $$(($(recovery_density_value) >= 560))),1),xxxhdpi),\
2435       $(if $(filter $(shell echo $$(($(recovery_density_value) >= 400))),1),xxhdpi),\
2436       $(if $(filter $(shell echo $$(($(recovery_density_value) >= 280))),1),xhdpi),\
2437       $(if $(filter $(shell echo $$(($(recovery_density_value) >= 200))),1),hdpi,mdpi)))
2438endif
2439
2440ifneq (,$(wildcard $(recovery_resources_common)-$(recovery_density)))
2441recovery_resources_common := $(recovery_resources_common)-$(recovery_density)
2442else
2443recovery_resources_common := $(recovery_resources_common)-xhdpi
2444endif
2445
2446# Select the 18x32 font on high-density devices (xhdpi and up); and the 12x22 font on other devices.
2447# Note that the font selected here can be overridden for a particular device by putting a font.png
2448# in its private recovery resources.
2449ifneq (,$(filter xxxhdpi xxhdpi xhdpi,$(recovery_density)))
2450recovery_font := bootable/recovery/fonts/18x32.png
2451else
2452recovery_font := bootable/recovery/fonts/12x22.png
2453endif
2454
2455
2456# We will only generate the recovery background text images if the variable
2457# TARGET_RECOVERY_UI_SCREEN_WIDTH is defined. For devices with xxxhdpi and xxhdpi, we set the
2458# variable to the commonly used values here, if it hasn't been intialized elsewhere. While for
2459# devices with lower density, they must have TARGET_RECOVERY_UI_SCREEN_WIDTH defined in their
2460# BoardConfig in order to use this feature.
2461ifeq ($(recovery_density),xxxhdpi)
2462TARGET_RECOVERY_UI_SCREEN_WIDTH ?= 1440
2463else ifeq ($(recovery_density),xxhdpi)
2464TARGET_RECOVERY_UI_SCREEN_WIDTH ?= 1080
2465endif
2466
2467ifneq ($(TARGET_RECOVERY_UI_SCREEN_WIDTH),)
2468# Subtracts the margin width and menu indent from the screen width; it's safe to be conservative.
2469ifeq ($(TARGET_RECOVERY_UI_MARGIN_WIDTH),)
2470  recovery_image_width := $$(($(TARGET_RECOVERY_UI_SCREEN_WIDTH) - 10))
2471else
2472  recovery_image_width := $$(($(TARGET_RECOVERY_UI_SCREEN_WIDTH) - $(TARGET_RECOVERY_UI_MARGIN_WIDTH) - 10))
2473endif
2474
2475
2476RECOVERY_INSTALLING_TEXT_FILE := $(call intermediates-dir-for,ETC,recovery_text_res)/installing_text.png
2477RECOVERY_INSTALLING_SECURITY_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/installing_security_text.png
2478RECOVERY_ERASING_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/erasing_text.png
2479RECOVERY_ERROR_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/error_text.png
2480RECOVERY_NO_COMMAND_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/no_command_text.png
2481
2482RECOVERY_CANCEL_WIPE_DATA_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/cancel_wipe_data_text.png
2483RECOVERY_FACTORY_DATA_RESET_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/factory_data_reset_text.png
2484RECOVERY_TRY_AGAIN_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/try_again_text.png
2485RECOVERY_WIPE_DATA_CONFIRMATION_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/wipe_data_confirmation_text.png
2486RECOVERY_WIPE_DATA_MENU_HEADER_TEXT_FILE := $(dir $(RECOVERY_INSTALLING_TEXT_FILE))/wipe_data_menu_header_text.png
2487
2488generated_recovery_text_files := \
2489  $(RECOVERY_INSTALLING_TEXT_FILE) \
2490  $(RECOVERY_INSTALLING_SECURITY_TEXT_FILE) \
2491  $(RECOVERY_ERASING_TEXT_FILE) \
2492  $(RECOVERY_ERROR_TEXT_FILE) \
2493  $(RECOVERY_NO_COMMAND_TEXT_FILE) \
2494  $(RECOVERY_CANCEL_WIPE_DATA_TEXT_FILE) \
2495  $(RECOVERY_FACTORY_DATA_RESET_TEXT_FILE) \
2496  $(RECOVERY_TRY_AGAIN_TEXT_FILE) \
2497  $(RECOVERY_WIPE_DATA_CONFIRMATION_TEXT_FILE) \
2498  $(RECOVERY_WIPE_DATA_MENU_HEADER_TEXT_FILE)
2499
2500resource_dir := bootable/recovery/tools/recovery_l10n/res/
2501resource_dir_deps := $(sort $(shell find $(resource_dir) -name *.xml -not -name .*))
2502image_generator_jar := $(HOST_OUT_JAVA_LIBRARIES)/RecoveryImageGenerator.jar
2503zopflipng := $(HOST_OUT_EXECUTABLES)/zopflipng
2504$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_SOURCE_FONTS := $(recovery_noto-fonts_dep) $(recovery_roboto-fonts_dep)
2505$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_FONT_FILES_DIR := $(call intermediates-dir-for,ETC,recovery_font_files)
2506$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RESOURCE_DIR := $(resource_dir)
2507$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_IMAGE_GENERATOR_JAR := $(image_generator_jar)
2508$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_ZOPFLIPNG := $(zopflipng)
2509$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_IMAGE_WIDTH := $(recovery_image_width)
2510$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_BACKGROUND_TEXT_LIST := \
2511  recovery_installing \
2512  recovery_installing_security \
2513  recovery_erasing \
2514  recovery_error \
2515  recovery_no_command
2516$(RECOVERY_INSTALLING_TEXT_FILE): PRIVATE_RECOVERY_WIPE_DATA_TEXT_LIST := \
2517  recovery_cancel_wipe_data \
2518  recovery_factory_data_reset \
2519  recovery_try_again \
2520  recovery_wipe_data_menu_header \
2521  recovery_wipe_data_confirmation
2522$(RECOVERY_INSTALLING_TEXT_FILE): .KATI_IMPLICIT_OUTPUTS := $(filter-out $(RECOVERY_INSTALLING_TEXT_FILE),$(generated_recovery_text_files))
2523$(RECOVERY_INSTALLING_TEXT_FILE): $(image_generator_jar) $(resource_dir_deps) $(recovery_noto-fonts_dep) $(recovery_roboto-fonts_dep) $(zopflipng)
2524	# Prepares the font directory.
2525	@rm -rf $(PRIVATE_RECOVERY_FONT_FILES_DIR)
2526	@mkdir -p $(PRIVATE_RECOVERY_FONT_FILES_DIR)
2527	$(foreach filename,$(PRIVATE_SOURCE_FONTS), cp $(filename) $(PRIVATE_RECOVERY_FONT_FILES_DIR) &&) true
2528	@rm -rf $(dir $@)
2529	@mkdir -p $(dir $@)
2530	$(foreach text_name,$(PRIVATE_RECOVERY_BACKGROUND_TEXT_LIST) $(PRIVATE_RECOVERY_WIPE_DATA_TEXT_LIST), \
2531	  $(eval output_file := $(dir $@)/$(patsubst recovery_%,%_text.png,$(text_name))) \
2532	  $(eval center_alignment := $(if $(filter $(text_name),$(PRIVATE_RECOVERY_BACKGROUND_TEXT_LIST)), --center_alignment)) \
2533	  java -jar $(PRIVATE_IMAGE_GENERATOR_JAR) \
2534	    --image_width $(PRIVATE_RECOVERY_IMAGE_WIDTH) \
2535	    --text_name $(text_name) \
2536	    --font_dir $(PRIVATE_RECOVERY_FONT_FILES_DIR) \
2537	    --resource_dir $(PRIVATE_RESOURCE_DIR) \
2538	    --output_file $(output_file) $(center_alignment) && \
2539	  $(PRIVATE_ZOPFLIPNG) -y --iterations=1 --filters=0 $(output_file) $(output_file) > /dev/null &&) true
2540else
2541RECOVERY_INSTALLING_TEXT_FILE :=
2542RECOVERY_INSTALLING_SECURITY_TEXT_FILE :=
2543RECOVERY_ERASING_TEXT_FILE :=
2544RECOVERY_ERROR_TEXT_FILE :=
2545RECOVERY_NO_COMMAND_TEXT_FILE :=
2546RECOVERY_CANCEL_WIPE_DATA_TEXT_FILE :=
2547RECOVERY_FACTORY_DATA_RESET_TEXT_FILE :=
2548RECOVERY_TRY_AGAIN_TEXT_FILE :=
2549RECOVERY_WIPE_DATA_CONFIRMATION_TEXT_FILE :=
2550RECOVERY_WIPE_DATA_MENU_HEADER_TEXT_FILE :=
2551endif # TARGET_RECOVERY_UI_SCREEN_WIDTH
2552
2553ifndef TARGET_PRIVATE_RES_DIRS
2554TARGET_PRIVATE_RES_DIRS := $(wildcard $(TARGET_DEVICE_DIR)/recovery/res)
2555endif
2556recovery_resource_deps := $(shell find $(recovery_resources_common) \
2557  $(TARGET_PRIVATE_RES_DIRS) -type f)
2558recovery_resource_deps += $(generated_recovery_text_files)
2559
2560
2561ifdef TARGET_RECOVERY_FSTAB
2562recovery_fstab := $(TARGET_RECOVERY_FSTAB)
2563else ifdef TARGET_RECOVERY_FSTAB_GENRULE
2564# Specifies a soong genrule module that generates an fstab.
2565recovery_fstab := $(call intermediates-dir-for,ETC,$(TARGET_RECOVERY_FSTAB_GENRULE))/$(TARGET_RECOVERY_FSTAB_GENRULE)
2566else
2567recovery_fstab := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery.fstab))
2568endif
2569ifdef TARGET_RECOVERY_WIPE
2570recovery_wipe := $(TARGET_RECOVERY_WIPE)
2571else
2572recovery_wipe :=
2573endif
2574
2575# Traditionally with non-A/B OTA we have:
2576#   boot.img + recovery-from-boot.p + recovery-resource.dat = recovery.img.
2577# recovery-resource.dat is needed only if we carry an imgdiff patch of the boot and recovery images
2578# and invoke install-recovery.sh on the first boot post an OTA update.
2579#
2580# We no longer need that if one of the following conditions holds:
2581#   a) We carry a full copy of the recovery image - no patching needed
2582#      (BOARD_USES_FULL_RECOVERY_IMAGE = true);
2583#   b) We build a single image that contains boot and recovery both - no recovery image to install
2584#      (BOARD_USES_RECOVERY_AS_BOOT = true);
2585#   c) We include the recovery DTBO image within recovery - not needing the resource file as we
2586#      do bsdiff because boot and recovery will contain different number of entries
2587#      (BOARD_INCLUDE_RECOVERY_DTBO = true).
2588#   d) We include the recovery ACPIO image within recovery - not needing the resource file as we
2589#      do bsdiff because boot and recovery will contain different number of entries
2590#      (BOARD_INCLUDE_RECOVERY_ACPIO = true).
2591#   e) We build a single image that contains vendor_boot and recovery both - no recovery image to
2592#      install
2593#      (BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT = true).
2594
2595ifeq (,$(filter true, $(BOARD_USES_FULL_RECOVERY_IMAGE) $(BOARD_USES_RECOVERY_AS_BOOT) \
2596  $(BOARD_INCLUDE_RECOVERY_DTBO) $(BOARD_INCLUDE_RECOVERY_ACPIO) \
2597  $(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT)))
2598# Named '.dat' so we don't attempt to use imgdiff for patching it.
2599RECOVERY_RESOURCE_ZIP := $(TARGET_OUT_VENDOR)/etc/recovery-resource.dat
2600ALL_DEFAULT_INSTALLED_MODULES += $(RECOVERY_RESOURCE_ZIP)
2601else
2602RECOVERY_RESOURCE_ZIP :=
2603endif
2604
2605INSTALLED_RECOVERY_BUILD_PROP_TARGET := $(TARGET_RECOVERY_ROOT_OUT)/prop.default
2606
2607$(INSTALLED_RECOVERY_BUILD_PROP_TARGET): PRIVATE_RECOVERY_UI_PROPERTIES := \
2608    TARGET_RECOVERY_UI_ANIMATION_FPS:animation_fps \
2609    TARGET_RECOVERY_UI_MARGIN_HEIGHT:margin_height \
2610    TARGET_RECOVERY_UI_MARGIN_WIDTH:margin_width \
2611    TARGET_RECOVERY_UI_MENU_UNUSABLE_ROWS:menu_unusable_rows \
2612    TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE:progress_bar_baseline \
2613    TARGET_RECOVERY_UI_TOUCH_LOW_THRESHOLD:touch_low_threshold \
2614    TARGET_RECOVERY_UI_TOUCH_HIGH_THRESHOLD:touch_high_threshold \
2615    TARGET_RECOVERY_UI_VR_STEREO_OFFSET:vr_stereo_offset \
2616    TARGET_RECOVERY_UI_BRIGHTNESS_FILE:brightness_file \
2617    TARGET_RECOVERY_UI_MAX_BRIGHTNESS_FILE:max_brightness_file \
2618    TARGET_RECOVERY_UI_BRIGHTNESS_NORMAL:brightness_normal_percent \
2619    TARGET_RECOVERY_UI_BRIGHTNESS_DIMMED:brightness_dimmed_percent
2620
2621# Parses the given list of build variables and writes their values as build properties if defined.
2622# For example, if a target defines `TARGET_RECOVERY_UI_MARGIN_HEIGHT := 100`,
2623# `ro.recovery.ui.margin_height=100` will be appended to the given output file.
2624# $(1): Map from the build variable names to property names
2625# $(2): Output file
2626define append-recovery-ui-properties
2627echo "#" >> $(2)
2628echo "# RECOVERY UI BUILD PROPERTIES" >> $(2)
2629echo "#" >> $(2)
2630$(foreach prop,$(1), \
2631    $(eval _varname := $(call word-colon,1,$(prop))) \
2632    $(eval _propname := $(call word-colon,2,$(prop))) \
2633    $(eval _value := $($(_varname))) \
2634    $(if $(_value), \
2635        echo ro.recovery.ui.$(_propname)=$(_value) >> $(2) &&)) true
2636endef
2637
2638$(INSTALLED_RECOVERY_BUILD_PROP_TARGET): \
2639	    $(INSTALLED_BUILD_PROP_TARGET) \
2640	    $(INSTALLED_VENDOR_BUILD_PROP_TARGET) \
2641	    $(INSTALLED_ODM_BUILD_PROP_TARGET) \
2642	    $(INSTALLED_PRODUCT_BUILD_PROP_TARGET) \
2643	    $(INSTALLED_SYSTEM_EXT_BUILD_PROP_TARGET)
2644	@echo "Target recovery buildinfo: $@"
2645	$(hide) mkdir -p $(dir $@)
2646	$(hide) rm -f $@
2647	$(hide) cat $(INSTALLED_BUILD_PROP_TARGET) >> $@
2648	$(hide) cat $(INSTALLED_VENDOR_BUILD_PROP_TARGET) >> $@
2649	$(hide) cat $(INSTALLED_ODM_BUILD_PROP_TARGET) >> $@
2650	$(hide) cat $(INSTALLED_PRODUCT_BUILD_PROP_TARGET) >> $@
2651	$(hide) cat $(INSTALLED_SYSTEM_EXT_BUILD_PROP_TARGET) >> $@
2652	$(call append-recovery-ui-properties,$(PRIVATE_RECOVERY_UI_PROPERTIES),$@)
2653
2654$(call declare-1p-target,$(INSTALLED_RECOVERY_BUILD_PROP_TARGET),build)
2655$(call declare-license-deps,$(INSTALLED_RECOVERY_BUILD_PROP_TARGET),\
2656    $(INSTALLED_BUILD_PROP_TARGET) $(INSTALLED_VENDOR_BUILD_PROP_TARGET) $(INSTALLED_ODM_BUILD_PROP_TARGET) \
2657    $(INSTALLED_PRODUCT_BUILD_PROP_TARGET) $(INSTALLED_SYSTEM_EXT_BUILD_PROP_TARGET))
2658
2659# Only install boot/etc/build.prop to recovery image on recovery_as_boot.
2660# On device with dedicated recovery partition, the file should come from the boot
2661# ramdisk.
2662ifeq (true,$(BOARD_USES_RECOVERY_AS_BOOT))
2663INSTALLED_RECOVERY_RAMDISK_BUILD_PROP_TARGET := $(TARGET_RECOVERY_ROOT_OUT)/$(RAMDISK_BUILD_PROP_REL_PATH)
2664$(INSTALLED_RECOVERY_RAMDISK_BUILD_PROP_TARGET): $(INSTALLED_RAMDISK_BUILD_PROP_TARGET)
2665	$(copy-file-to-target)
2666
2667$(call declare-1p-target,$(INSTALLED_RECOVERY_RAMDISK_BUILD_PROP_TARGET),build)
2668$(call declare-license-deps,$(INSTALLED_RECOVERY_RAMDISK_BUILD_PROP_TARGET),$(INSTALLED_RAMDISK_BUILD_PROP_TARGET))
2669endif
2670
2671INTERNAL_RECOVERYIMAGE_ARGS := --ramdisk $(recovery_ramdisk)
2672
2673ifneq (truetrue,$(strip $(BUILDING_VENDOR_BOOT_IMAGE))$(strip $(BOARD_USES_RECOVERY_AS_BOOT)))
2674INTERNAL_RECOVERYIMAGE_ARGS += $(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET))
2675# Assumes this has already been stripped
2676ifneq (true,$(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE))
2677ifdef INTERNAL_KERNEL_CMDLINE
2678  INTERNAL_RECOVERYIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)"
2679endif # INTERNAL_KERNEL_CMDLINE != ""
2680endif # BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE != true
2681ifdef BOARD_KERNEL_BASE
2682  INTERNAL_RECOVERYIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
2683endif
2684ifdef BOARD_KERNEL_PAGESIZE
2685  INTERNAL_RECOVERYIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE)
2686endif
2687ifdef BOARD_INCLUDE_RECOVERY_DTBO
2688ifdef BOARD_PREBUILT_RECOVERY_DTBOIMAGE
2689  INTERNAL_RECOVERYIMAGE_ARGS += --recovery_dtbo $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE)
2690else
2691  INTERNAL_RECOVERYIMAGE_ARGS += --recovery_dtbo $(BOARD_PREBUILT_DTBOIMAGE)
2692endif
2693endif # BOARD_INCLUDE_RECOVERY_DTBO
2694ifdef BOARD_INCLUDE_RECOVERY_ACPIO
2695  INTERNAL_RECOVERYIMAGE_ARGS += --recovery_acpio $(BOARD_RECOVERY_ACPIO)
2696endif
2697ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
2698  INTERNAL_RECOVERYIMAGE_ARGS += --dtb $(INSTALLED_DTBIMAGE_TARGET)
2699endif
2700endif # (BUILDING_VENDOR_BOOT_IMAGE and BOARD_USES_RECOVERY_AS_BOOT)
2701ifndef BOARD_RECOVERY_MKBOOTIMG_ARGS
2702  BOARD_RECOVERY_MKBOOTIMG_ARGS := $(BOARD_MKBOOTIMG_ARGS)
2703endif
2704
2705$(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP): $(MKBOOTFS) $(COMPRESSION_COMMAND_DEPS) \
2706	    $(INTERNAL_ROOT_FILES) \
2707	    $(INSTALLED_RAMDISK_TARGET) \
2708	    $(INTERNAL_RECOVERYIMAGE_FILES) \
2709	    $(recovery_sepolicy) \
2710	    $(INSTALLED_2NDBOOTLOADER_TARGET) \
2711	    $(INSTALLED_RECOVERY_BUILD_PROP_TARGET) \
2712	    $(INSTALLED_RECOVERY_RAMDISK_BUILD_PROP_TARGET) \
2713	    $(recovery_resource_deps) \
2714	    $(recovery_fstab)
2715	# Making recovery image
2716	mkdir -p $(TARGET_RECOVERY_OUT)
2717	mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/sdcard $(TARGET_RECOVERY_ROOT_OUT)/tmp
2718	# Copying baseline ramdisk...
2719	# Use rsync because "cp -Rf" fails to overwrite broken symlinks on Mac.
2720	rsync -a --exclude=sdcard $(IGNORE_RECOVERY_SEPOLICY) $(IGNORE_CACHE_LINK) $(TARGET_ROOT_OUT) $(TARGET_RECOVERY_OUT)
2721	# Modifying ramdisk contents...
2722	ln -sf /system/bin/init $(TARGET_RECOVERY_ROOT_OUT)/init
2723	# Removes $(TARGET_RECOVERY_ROOT_OUT)/init*.rc EXCEPT init.recovery*.rc.
2724	find $(TARGET_RECOVERY_ROOT_OUT) -maxdepth 1 -name 'init*.rc' -type f -not -name "init.recovery.*.rc" | xargs rm -f
2725	cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/ 2> /dev/null || true # Ignore error when the src file doesn't exist.
2726	mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/res
2727	rm -rf $(TARGET_RECOVERY_ROOT_OUT)/res/*
2728	cp -rf $(recovery_resources_common)/* $(TARGET_RECOVERY_ROOT_OUT)/res
2729	$(foreach recovery_text_file,$(generated_recovery_text_files), \
2730	  cp -rf $(recovery_text_file) $(TARGET_RECOVERY_ROOT_OUT)/res/images/ &&) true
2731	cp -f $(recovery_font) $(TARGET_RECOVERY_ROOT_OUT)/res/images/font.png
2732	$(foreach item,$(TARGET_PRIVATE_RES_DIRS), \
2733	  cp -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/$(newline))
2734	$(foreach item,$(recovery_fstab), \
2735	  cp -f $(item) $(TARGET_RECOVERY_ROOT_OUT)/system/etc/recovery.fstab)
2736	$(if $(strip $(recovery_wipe)), \
2737	  cp -f $(recovery_wipe) $(TARGET_RECOVERY_ROOT_OUT)/system/etc/recovery.wipe)
2738	ln -sf prop.default $(TARGET_RECOVERY_ROOT_OUT)/default.prop
2739	# Silence warnings in first_stage_console.
2740	touch $(TARGET_RECOVERY_ROOT_OUT)/linkerconfig/ld.config.txt
2741	$(BOARD_RECOVERY_IMAGE_PREPARE)
2742	$(hide) touch $@
2743
2744$(recovery_ramdisk): $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
2745	$(MKBOOTFS) -d $(TARGET_OUT) $(TARGET_RECOVERY_ROOT_OUT) | $(COMPRESSION_COMMAND) > $(recovery_ramdisk)
2746
2747# $(1): output file
2748# $(2): optional kernel file
2749define build-recoveryimage-target
2750  $(if $(filter true,$(PRODUCT_SUPPORTS_VBOOT)), \
2751    $(MKBOOTIMG) $(if $(strip $(2)),--kernel $(strip $(2))) $(INTERNAL_RECOVERYIMAGE_ARGS) \
2752                 $(INTERNAL_MKBOOTIMG_VERSION_ARGS) $(BOARD_RECOVERY_MKBOOTIMG_ARGS) \
2753                 --output $(1).unsigned, \
2754    $(MKBOOTIMG) $(if $(strip $(2)),--kernel $(strip $(2))) $(INTERNAL_RECOVERYIMAGE_ARGS) \
2755                 $(INTERNAL_MKBOOTIMG_VERSION_ARGS) \
2756                 $(BOARD_RECOVERY_MKBOOTIMG_ARGS) --output $(1))
2757  $(if $(filter true,$(PRODUCT_SUPPORTS_VBOOT)), \
2758    $(VBOOT_SIGNER) $(FUTILITY) $(1).unsigned $(PRODUCT_VBOOT_SIGNING_KEY).vbpubk $(PRODUCT_VBOOT_SIGNING_KEY).vbprivk $(PRODUCT_VBOOT_SIGNING_SUBKEY).vbprivk $(1).keyblock $(1))
2759  $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)), \
2760    $(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(call get-bootimage-partition-size,$(1),boot))), \
2761    $(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(BOARD_RECOVERYIMAGE_PARTITION_SIZE))))
2762  $(if $(filter true,$(BOARD_AVB_ENABLE)), \
2763    $(if $(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)), \
2764      $(AVBTOOL) add_hash_footer --image $(1) $(call get-partition-size-argument,$(call get-bootimage-partition-size,$(1),boot)) --partition_name boot $(INTERNAL_AVB_BOOT_SIGNING_ARGS) $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS),\
2765      $(AVBTOOL) add_hash_footer --image $(1) $(call get-partition-size-argument,$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)) --partition_name recovery $(INTERNAL_AVB_RECOVERY_SIGNING_ARGS) $(BOARD_AVB_RECOVERY_ADD_HASH_FOOTER_ARGS)))
2766endef
2767
2768recoveryimage-deps := $(MKBOOTIMG) $(recovery_ramdisk) $(recovery_kernel)
2769ifeq (true,$(PRODUCT_SUPPORTS_VBOOT))
2770  recoveryimage-deps += $(VBOOT_SIGNER)
2771endif
2772ifeq (true,$(BOARD_AVB_ENABLE))
2773  recoveryimage-deps += $(AVBTOOL) $(BOARD_AVB_BOOT_KEY_PATH)
2774endif
2775ifdef BOARD_INCLUDE_RECOVERY_DTBO
2776  ifdef BOARD_PREBUILT_RECOVERY_DTBOIMAGE
2777    recoveryimage-deps += $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE)
2778  else
2779    recoveryimage-deps += $(BOARD_PREBUILT_DTBOIMAGE)
2780  endif
2781endif
2782ifdef BOARD_INCLUDE_RECOVERY_ACPIO
2783  recoveryimage-deps += $(BOARD_RECOVERY_ACPIO)
2784endif
2785ifdef BOARD_INCLUDE_DTB_IN_BOOTIMG
2786  recoveryimage-deps += $(INSTALLED_DTBIMAGE_TARGET)
2787endif
2788
2789ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2790$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET), $(eval $(call add-dependency,$(b),$(call bootimage-to-kernel,$(b)))))
2791$(INSTALLED_BOOTIMAGE_TARGET): $(recoveryimage-deps)
2792	$(call pretty,"Target boot image from recovery: $@")
2793	$(call build-recoveryimage-target, $@, $(PRODUCT_OUT)/$(subst .img,,$(subst boot,kernel,$(notdir $@))))
2794
2795$(call declare-container-license-metadata,$(INSTALLED_BOOTIMAGE_TARGET),SPDX-license-identifier-GPL-2.0-only SPDX-license-identifier-Apache-2.0,restricted notice,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING build/soong/licenses/LICENSE,"Boot Image",bool)
2796$(call declare-container-license-deps,$(INSTALLED_BOOTIMAGE_TARGET),$(recoveryimage-deps),$(PRODUCT_OUT)/:/)
2797
2798UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_BOOTIMAGE_TARGET)
2799endif # BOARD_USES_RECOVERY_AS_BOOT
2800
2801$(INSTALLED_RECOVERYIMAGE_TARGET): $(recoveryimage-deps)
2802	$(call build-recoveryimage-target, $@, \
2803	  $(if $(filter true, $(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE)),, $(recovery_kernel)))
2804
2805ifdef RECOVERY_RESOURCE_ZIP
2806$(RECOVERY_RESOURCE_ZIP): $(INSTALLED_RECOVERYIMAGE_TARGET) | $(ZIPTIME)
2807	$(hide) mkdir -p $(dir $@)
2808	$(hide) find $(TARGET_RECOVERY_ROOT_OUT)/res -type f | sort | zip -0qrjX $@ -@
2809	$(remove-timestamps-from-package)
2810endif
2811
2812
2813$(call declare-1p-container,$(INSTALLED_RECOVERYIMAGE_TARGET),)
2814$(call declare-container-license-deps,$(INSTALLED_RECOVERYIMAGE_TARGET),$(recoveryimage-deps),$(PRODUCT_OUT)/:/)
2815
2816UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_RECOVERYIMAGE_TARGET)
2817
2818.PHONY: recoveryimage-nodeps
2819recoveryimage-nodeps:
2820	@echo "make $@: ignoring dependencies"
2821	$(call build-recoveryimage-target, $(INSTALLED_RECOVERYIMAGE_TARGET), \
2822	  $(if $(filter true, $(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE)),, $(recovery_kernel)))
2823
2824else # BUILDING_RECOVERY_IMAGE
2825RECOVERY_RESOURCE_ZIP :=
2826endif # BUILDING_RECOVERY_IMAGE
2827
2828.PHONY: recoveryimage
2829recoveryimage: $(INSTALLED_RECOVERYIMAGE_TARGET) $(RECOVERY_RESOURCE_ZIP)
2830
2831ifneq ($(BOARD_NAND_PAGE_SIZE),)
2832$(error MTD device is no longer supported and thus BOARD_NAND_PAGE_SIZE is deprecated.)
2833endif
2834
2835ifneq ($(BOARD_NAND_SPARE_SIZE),)
2836$(error MTD device is no longer supported and thus BOARD_NAND_SPARE_SIZE is deprecated.)
2837endif
2838
2839
2840# -----------------------------------------------------------------
2841# Build debug ramdisk and debug boot image.
2842INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_DEBUG_RAMDISK_OUT)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
2843ifneq ($(BUILDING_DEBUG_BOOT_IMAGE)$(BUILDING_DEBUG_VENDOR_BOOT_IMAGE),)
2844
2845INTERNAL_DEBUG_RAMDISK_FILES := $(filter $(TARGET_DEBUG_RAMDISK_OUT)/%, \
2846    $(ALL_DEFAULT_INSTALLED_MODULES))
2847
2848# Directories to be picked into the debug ramdisk.
2849# As these directories are all merged into one single cpio archive, the order
2850# matters. If there are multiple files with the same pathname, then the last one
2851# wins.
2852#
2853# ramdisk-debug.img will merge the content from either ramdisk.img or
2854# ramdisk-recovery.img, depending on whether BOARD_USES_RECOVERY_AS_BOOT
2855# is set or not.
2856ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2857  INTERNAL_DEBUG_RAMDISK_SRC_DIRS := $(TARGET_RECOVERY_ROOT_OUT)
2858  INTERNAL_DEBUG_RAMDISK_SRC_RAMDISK_TARGET := $(recovery_ramdisk)
2859else  # BOARD_USES_RECOVERY_AS_BOOT == true
2860  INTERNAL_DEBUG_RAMDISK_SRC_DIRS := $(TARGET_RAMDISK_OUT)
2861  INTERNAL_DEBUG_RAMDISK_SRC_RAMDISK_TARGET := $(INSTALLED_RAMDISK_TARGET)
2862endif # BOARD_USES_RECOVERY_AS_BOOT != true
2863
2864INTERNAL_DEBUG_RAMDISK_SRC_DIRS += $(TARGET_DEBUG_RAMDISK_OUT)
2865INTERNAL_DEBUG_RAMDISK_SRC_DEPS := $(INTERNAL_DEBUG_RAMDISK_SRC_RAMDISK_TARGET) $(INTERNAL_DEBUG_RAMDISK_FILES)
2866
2867# INSTALLED_FILES_FILE_DEBUG_RAMDISK would ensure TARGET_DEBUG_RAMDISK_OUT is created.
2868INSTALLED_FILES_FILE_DEBUG_RAMDISK := $(PRODUCT_OUT)/installed-files-ramdisk-debug.txt
2869INSTALLED_FILES_JSON_DEBUG_RAMDISK := $(INSTALLED_FILES_FILE_DEBUG_RAMDISK:.txt=.json)
2870$(INSTALLED_FILES_FILE_DEBUG_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_DEBUG_RAMDISK)
2871$(INSTALLED_FILES_FILE_DEBUG_RAMDISK): $(INTERNAL_DEBUG_RAMDISK_SRC_DEPS)
2872$(INSTALLED_FILES_FILE_DEBUG_RAMDISK): $(FILESLIST) $(FILESLIST_UTIL)
2873	@echo "Installed file list: $@"
2874	$(hide) rm -f $@
2875	$(hide) mkdir -p $(dir $@) $(TARGET_DEBUG_RAMDISK_OUT)
2876	touch $(TARGET_DEBUG_RAMDISK_OUT)/force_debuggable
2877	$(FILESLIST) $(INTERNAL_DEBUG_RAMDISK_SRC_DIRS) > $(@:.txt=.json)
2878	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
2879
2880$(eval $(call declare-0p-target,$(INSTALLED_FILES_FILE_DEBUG_RAMDISK)))
2881$(eval $(call declare-0p-target,$(INSTALLED_FILES_JSON_DEBUG_RAMDISK)))
2882
2883ifdef BUILDING_DEBUG_BOOT_IMAGE
2884
2885# -----------------------------------------------------------------
2886# the debug ramdisk, which is the original ramdisk plus additional
2887# files: force_debuggable, adb_debug.prop and userdebug sepolicy.
2888# When /force_debuggable is present, /init will load userdebug sepolicy
2889# and property files to allow adb root, if the device is unlocked.
2890INSTALLED_DEBUG_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk-debug.img
2891
2892$(INSTALLED_DEBUG_RAMDISK_TARGET): $(INSTALLED_FILES_FILE_DEBUG_RAMDISK)
2893$(INSTALLED_DEBUG_RAMDISK_TARGET): $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
2894	@echo "Target debug ramdisk: $@"
2895	$(hide) rm -f $@
2896	$(hide) mkdir -p $(dir $@)
2897	$(MKBOOTFS) -d $(TARGET_OUT) $(INTERNAL_DEBUG_RAMDISK_SRC_DIRS) | $(COMPRESSION_COMMAND) > $@
2898
2899$(call declare-1p-container,$(INSTALLED_DEBUG_RAMDISK_TARGET),)
2900$(call declare-container-license-deps,$(INSTALLED_DEBUG_RAMDISK_TARGET),$(INSTALLED_RAMDISK_TARGET),$(PRODUCT_OUT)/:/)
2901
2902UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_DEBUG_RAMDISK_TARGET)
2903
2904.PHONY: ramdisk_debug-nodeps
2905ramdisk_debug-nodeps: $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
2906	@echo "make $@: ignoring dependencies"
2907	$(hide) rm -f $(INSTALLED_DEBUG_RAMDISK_TARGET)
2908	$(hide) mkdir -p $(dir $(INSTALLED_DEBUG_RAMDISK_TARGET)) $(INTERNAL_DEBUG_RAMDISK_SRC_DIRS)
2909	$(MKBOOTFS) -d $(TARGET_OUT) $(INTERNAL_DEBUG_RAMDISK_SRC_DIRS) | $(COMPRESSION_COMMAND) > $(INSTALLED_DEBUG_RAMDISK_TARGET)
2910
2911# -----------------------------------------------------------------
2912# the boot-debug.img, which is the kernel plus ramdisk-debug.img
2913#
2914# Note: it's intentional to skip signing for boot-debug.img, because it
2915# can only be used if the device is unlocked with verification error.
2916ifneq ($(strip $(BOARD_KERNEL_BINARIES)),)
2917  INSTALLED_DEBUG_BOOTIMAGE_TARGET := $(foreach k,$(subst kernel,boot-debug,$(BOARD_KERNEL_BINARIES)), \
2918         $(PRODUCT_OUT)/$(k).img)
2919else
2920  INSTALLED_DEBUG_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot-debug.img
2921endif
2922
2923# Replace ramdisk.img in $(MKBOOTIMG) ARGS with ramdisk-debug.img to build boot-debug.img
2924$(INSTALLED_DEBUG_BOOTIMAGE_TARGET): $(INSTALLED_DEBUG_RAMDISK_TARGET)
2925ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
2926  INTERNAL_DEBUG_BOOTIMAGE_ARGS := $(subst $(INTERNAL_DEBUG_RAMDISK_SRC_RAMDISK_TARGET),$(INSTALLED_DEBUG_RAMDISK_TARGET),$(INTERNAL_RECOVERYIMAGE_ARGS))
2927else
2928  INTERNAL_DEBUG_BOOTIMAGE_ARGS := $(subst $(INTERNAL_DEBUG_RAMDISK_SRC_RAMDISK_TARGET),$(INSTALLED_DEBUG_RAMDISK_TARGET),$(INTERNAL_BOOTIMAGE_ARGS))
2929endif
2930
2931# If boot.img is chained but boot-debug.img is not signed, libavb in bootloader
2932# will fail to find valid AVB metadata from the end of /boot, thus stop booting.
2933# Using a test key to sign boot-debug.img to continue booting with the mismatched
2934# public key, if the device is unlocked.
2935ifneq ($(BOARD_AVB_BOOT_KEY_PATH),)
2936$(INSTALLED_DEBUG_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_BOOT_TEST_KEY_PATH)
2937endif
2938
2939BOARD_AVB_BOOT_TEST_KEY_PATH := external/avb/test/data/testkey_rsa2048.pem
2940INTERNAL_AVB_BOOT_TEST_SIGNING_ARGS := --algorithm SHA256_RSA2048 --key $(BOARD_AVB_BOOT_TEST_KEY_PATH)
2941# $(1): the bootimage to sign
2942# $(2): boot image variant (boot, boot-debug, boot-test-harness)
2943define test-key-sign-bootimage
2944$(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(call get-bootimage-partition-size,$(1),$(2))))
2945$(AVBTOOL) add_hash_footer \
2946  --image $(1) \
2947  $(call get-partition-size-argument,$(call get-bootimage-partition-size,$(1),$(2)))\
2948  --partition_name boot $(INTERNAL_AVB_BOOT_TEST_SIGNING_ARGS) \
2949  $(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)
2950$(call assert-max-image-size,$(1),$(call get-bootimage-partition-size,$(1),$(2)))
2951endef
2952
2953# $(1): output file
2954define build-debug-bootimage-target
2955  $(MKBOOTIMG) --kernel $(PRODUCT_OUT)/$(subst .img,,$(subst boot-debug,kernel,$(notdir $(1)))) \
2956    $(INTERNAL_DEBUG_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) \
2957    $(BOARD_MKBOOTIMG_ARGS) --output $1
2958  $(if $(BOARD_AVB_BOOT_KEY_PATH),$(call test-key-sign-bootimage,$1,boot-debug))
2959endef
2960
2961# Depends on original boot.img and ramdisk-debug.img, to build the new boot-debug.img
2962$(INSTALLED_DEBUG_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_BOOTIMAGE_TARGET) $(AVBTOOL)
2963	$(call pretty,"Target boot debug image: $@")
2964	$(call build-debug-bootimage-target, $@)
2965
2966$(call declare-container-license-metadata,$(INSTALLED_DEBUG_BOOTIMAGE_TARGET),SPDX-license-identifier-GPL-2.0-only SPDX-license-identifier-Apache-2.0,restricted notice,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING build/soong/licenses/LICENSE,"Boot Image",boot)
2967$(call declare-container-license-deps,$(INSTALLED_DEBUG_BOOTIMAGE_TARGET),$(INSTALLED_BOOTIMAGE_TARGET),$(PRODUCT_OUT)/:/)
2968
2969UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_DEBUG_BOOTIMAGE_TARGET)
2970
2971.PHONY: bootimage_debug-nodeps
2972bootimage_debug-nodeps: $(MKBOOTIMG) $(AVBTOOL)
2973	echo "make $@: ignoring dependencies"
2974	$(foreach b,$(INSTALLED_DEBUG_BOOTIMAGE_TARGET),$(call build-debug-bootimage-target,$b))
2975
2976endif # BUILDING_DEBUG_BOOT_IMAGE
2977
2978# -----------------------------------------------------------------
2979# vendor debug ramdisk
2980# Combines vendor ramdisk files and debug ramdisk files to build the vendor debug ramdisk.
2981INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_VENDOR_DEBUG_RAMDISK_OUT)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
2982ifdef BUILDING_DEBUG_VENDOR_BOOT_IMAGE
2983
2984INTERNAL_VENDOR_DEBUG_RAMDISK_FILES := $(filter $(TARGET_VENDOR_DEBUG_RAMDISK_OUT)/%, \
2985    $(ALL_DEFAULT_INSTALLED_MODULES))
2986
2987# The debug vendor ramdisk combines vendor ramdisk and debug ramdisk.
2988INTERNAL_DEBUG_VENDOR_RAMDISK_SRC_DIRS := $(TARGET_VENDOR_RAMDISK_OUT)
2989INTERNAL_DEBUG_VENDOR_RAMDISK_SRC_DEPS := $(INTERNAL_VENDOR_RAMDISK_TARGET)
2990
2991# Exclude recovery files in the default vendor ramdisk if including a standalone
2992# recovery ramdisk in vendor_boot.
2993ifeq (true,$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT))
2994  ifneq (true,$(BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT))
2995    INTERNAL_DEBUG_VENDOR_RAMDISK_SRC_DIRS += $(TARGET_RECOVERY_ROOT_OUT)
2996    INTERNAL_DEBUG_VENDOR_RAMDISK_SRC_DEPS += $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
2997  endif # BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT != true
2998endif # BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT == true
2999
3000INTERNAL_DEBUG_VENDOR_RAMDISK_SRC_DIRS += $(TARGET_VENDOR_DEBUG_RAMDISK_OUT) $(TARGET_DEBUG_RAMDISK_OUT)
3001INTERNAL_DEBUG_VENDOR_RAMDISK_SRC_DEPS += $(INTERNAL_VENDOR_DEBUG_RAMDISK_FILES) $(INSTALLED_FILES_FILE_DEBUG_RAMDISK)
3002
3003# INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK would ensure TARGET_VENDOR_DEBUG_RAMDISK_OUT is created.
3004INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK := $(PRODUCT_OUT)/installed-files-vendor-ramdisk-debug.txt
3005INSTALLED_FILES_JSON_VENDOR_DEBUG_RAMDISK := $(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK:.txt=.json)
3006$(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_VENDOR_DEBUG_RAMDISK)
3007$(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK): $(INTERNAL_DEBUG_VENDOR_RAMDISK_SRC_DEPS)
3008$(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK): $(FILESLIST) $(FILESLIST_UTIL)
3009	@echo "Installed file list: $@"
3010	$(hide) rm -f $@
3011	$(hide) mkdir -p $(dir $@) $(TARGET_VENDOR_DEBUG_RAMDISK_OUT)
3012	$(FILESLIST) $(INTERNAL_DEBUG_VENDOR_RAMDISK_SRC_DIRS) > $(@:.txt=.json)
3013	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3014
3015$(call declare-0p-target,$(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK))
3016$(call declare-0p-target,$(INSTALLED_FILES_JSON_VENDOR_DEBUG_RAMDISK))
3017
3018INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET := $(call intermediates-dir-for,PACKAGING,vendor_boot-debug)/vendor_ramdisk-debug.cpio$(RAMDISK_EXT)
3019
3020$(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET): $(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK)
3021$(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET): $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
3022	$(hide) rm -f $@
3023	$(hide) mkdir -p $(dir $@)
3024	$(MKBOOTFS) -d $(TARGET_OUT) $(INTERNAL_DEBUG_VENDOR_RAMDISK_SRC_DIRS) | $(COMPRESSION_COMMAND) > $@
3025
3026INSTALLED_VENDOR_DEBUG_RAMDISK_TARGET := $(PRODUCT_OUT)/vendor_ramdisk-debug.img
3027$(INSTALLED_VENDOR_DEBUG_RAMDISK_TARGET): $(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET)
3028	@echo "Target debug vendor ramdisk: $@"
3029	$(copy-file-to-target)
3030
3031$(call declare-1p-container,$(INSTALLED_VENDOR_DEBUG_RAMDISK_TARGET),)
3032$(call declare-container-license-deps,$(INSTALLED_VENDOR_DEBUG_RAMDISK_TARGET),$(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET),$(PRODUCT_OUT)/:/)
3033
3034VENDOR_NOTICE_DEPS += $(INSTALLED_VENDOR_DEBUG_RAMDISK_TARGET)
3035
3036# -----------------------------------------------------------------
3037# vendor_boot-debug.img.
3038INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/vendor_boot-debug.img
3039
3040# The util to sign vendor_boot-debug.img with a test key.
3041BOARD_AVB_VENDOR_BOOT_TEST_KEY_PATH := external/avb/test/data/testkey_rsa2048.pem
3042INTERNAL_AVB_VENDOR_BOOT_TEST_SIGNING_ARGS := --algorithm SHA256_RSA2048 --key $(BOARD_AVB_VENDOR_BOOT_TEST_KEY_PATH)
3043# $(1): the vendor bootimage to sign
3044define test-key-sign-vendor-bootimage
3045$(call assert-max-image-size,$(1),$(call get-hash-image-max-size,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE)))
3046$(AVBTOOL) add_hash_footer \
3047  --image $(1) \
3048  $(call get-partition-size-argument,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE)) \
3049  --partition_name vendor_boot $(INTERNAL_AVB_VENDOR_BOOT_TEST_SIGNING_ARGS) \
3050  $(BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS)
3051$(call assert-max-image-size,$(1),$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE))
3052endef
3053
3054ifneq ($(BOARD_AVB_VENDOR_BOOT_KEY_PATH),)
3055$(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_VENDOR_BOOT_TEST_KEY_PATH)
3056endif
3057
3058# Depends on vendor_boot.img and vendor-ramdisk-debug.cpio.gz to build the new vendor_boot-debug.img
3059$(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_VENDOR_BOOTIMAGE_TARGET) $(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET)
3060$(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET): $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS)
3061	$(call pretty,"Target vendor_boot debug image: $@")
3062	$(MKBOOTIMG) $(INTERNAL_VENDOR_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --vendor_ramdisk $(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET) $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS) --vendor_boot $@
3063	$(call assert-max-image-size,$@,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE))
3064	$(if $(BOARD_AVB_VENDOR_BOOT_KEY_PATH),$(call test-key-sign-vendor-bootimage,$@))
3065
3066$(call declare-1p-container,$(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET),)
3067$(call declare-container-license-deps,$(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET),$(INTERNAL_VENDOR_DEBUG_RAMDISK_TARGET),$(PRODUCT_OUT)/:/)
3068
3069VENDOR_NOTICE_DEPS += $(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET)
3070
3071endif # BUILDING_DEBUG_VENDOR_BOOT_IMAGE
3072
3073# Appends a few test harness specific properties into the adb_debug.prop.
3074ADDITIONAL_TEST_HARNESS_PROPERTIES := ro.audio.silent=1
3075ADDITIONAL_TEST_HARNESS_PROPERTIES += ro.test_harness=1
3076
3077INTERNAL_DEBUG_RAMDISK_ADB_DEBUG_PROP_TARGET := $(strip $(filter $(TARGET_DEBUG_RAMDISK_OUT)/adb_debug.prop,$(INTERNAL_DEBUG_RAMDISK_FILES)))
3078INTERNAL_TEST_HARNESS_RAMDISK_ADB_DEBUG_PROP_TARGET := $(TARGET_TEST_HARNESS_RAMDISK_OUT)/adb_debug.prop
3079$(INTERNAL_TEST_HARNESS_RAMDISK_ADB_DEBUG_PROP_TARGET): $(INTERNAL_DEBUG_RAMDISK_ADB_DEBUG_PROP_TARGET)
3080	$(hide) rm -f $@
3081	$(hide) mkdir -p $(dir $@)
3082ifdef INTERNAL_DEBUG_RAMDISK_ADB_DEBUG_PROP_TARGET
3083	$(hide) cp $(INTERNAL_DEBUG_RAMDISK_ADB_DEBUG_PROP_TARGET) $@
3084endif
3085	$(hide) echo "" >> $@
3086	$(hide) echo "#" >> $@
3087	$(hide) echo "# ADDITIONAL TEST HARNESS PROPERTIES" >> $@
3088	$(hide) echo "#" >> $@
3089	$(hide) $(foreach line,$(ADDITIONAL_TEST_HARNESS_PROPERTIES), \
3090	          echo "$(line)" >> $@;)
3091
3092$(call declare-1p-target,$(INTERNAL_TEST_HARNESS_RAMDISK_ADB_DEBUG_PROP_TARGET))
3093
3094INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_TEST_HARNESS_RAMDISK_OUT)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
3095INTERNAL_TEST_HARNESS_RAMDISK_FILES := $(filter $(TARGET_TEST_HARNESS_RAMDISK_OUT)/%, \
3096    $(INTERNAL_TEST_HARNESS_RAMDISK_ADB_DEBUG_PROP_TARGET) \
3097    $(ALL_DEFAULT_INSTALLED_MODULES))
3098
3099# The order is important here. The test harness ramdisk staging directory has to
3100# come last so that it can override the adb_debug.prop in the debug ramdisk
3101# staging directory.
3102INTERNAL_TEST_HARNESS_RAMDISK_SRC_DIRS := $(INTERNAL_DEBUG_RAMDISK_SRC_DIRS) $(TARGET_TEST_HARNESS_RAMDISK_OUT)
3103INTERNAL_TEST_HARNESS_RAMDISK_SRC_DEPS := $(INSTALLED_FILES_FILE_DEBUG_RAMDISK) $(INTERNAL_TEST_HARNESS_RAMDISK_FILES)
3104
3105ifdef BUILDING_DEBUG_BOOT_IMAGE
3106
3107# -----------------------------------------------------------------
3108# The test harness ramdisk, which is based off debug_ramdisk, plus a
3109# few additional test-harness-specific properties in adb_debug.prop.
3110INSTALLED_TEST_HARNESS_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk-test-harness.img
3111
3112$(INSTALLED_TEST_HARNESS_RAMDISK_TARGET): $(INTERNAL_TEST_HARNESS_RAMDISK_SRC_DEPS)
3113$(INSTALLED_TEST_HARNESS_RAMDISK_TARGET): $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
3114	@echo "Target test harness ramdisk: $@"
3115	$(hide) rm -f $@
3116	$(hide) mkdir -p $(dir $@)
3117	$(MKBOOTFS) -d $(TARGET_OUT) $(INTERNAL_TEST_HARNESS_RAMDISK_SRC_DIRS) | $(COMPRESSION_COMMAND) > $@
3118
3119$(call declare-1p-container,$(INSTALLED_TEST_HARNESS_RAMDISK_TARGET),)
3120$(call declare-container-license-deps,$(INSTALLED_TEST_HARNESS_RAMDISK_TARGET),$(INTERNAL_TEST_HARNESS_RAMDISK_SRC_DEPS),$(PRODUCT_OUT)/:/)
3121
3122UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET)
3123
3124.PHONY: ramdisk_test_harness-nodeps
3125ramdisk_test_harness-nodeps: $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
3126	@echo "make $@: ignoring dependencies"
3127	$(hide) rm -f $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET)
3128	$(hide) mkdir -p $(dir $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET)) $(INTERNAL_TEST_HARNESS_RAMDISK_SRC_DIRS)
3129	$(MKBOOTFS) -d $(TARGET_OUT) $(INTERNAL_TEST_HARNESS_RAMDISK_SRC_DIRS) | $(COMPRESSION_COMMAND) > $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET)
3130
3131# -----------------------------------------------------------------
3132# the boot-test-harness.img, which is the kernel plus ramdisk-test-harness.img
3133#
3134# Note: it's intentional to skip signing for boot-test-harness.img, because it
3135# can only be used if the device is unlocked with verification error.
3136ifneq ($(strip $(BOARD_KERNEL_BINARIES)),)
3137  INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET := $(foreach k,$(subst kernel,boot-test-harness,$(BOARD_KERNEL_BINARIES)), \
3138    $(PRODUCT_OUT)/$(k).img)
3139else
3140  INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot-test-harness.img
3141endif
3142
3143# Replace ramdisk-debug.img in $(MKBOOTIMG) ARGS with ramdisk-test-harness.img to build boot-test-harness.img
3144$(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET): $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET)
3145INTERNAL_TEST_HARNESS_BOOTIMAGE_ARGS := $(subst $(INSTALLED_DEBUG_RAMDISK_TARGET),$(INSTALLED_TEST_HARNESS_RAMDISK_TARGET),$(INTERNAL_DEBUG_BOOTIMAGE_ARGS))
3146
3147# If boot.img is chained but boot-test-harness.img is not signed, libavb in bootloader
3148# will fail to find valid AVB metadata from the end of /boot, thus stop booting.
3149# Using a test key to sign boot-test-harness.img to continue booting with the mismatched
3150# public key, if the device is unlocked.
3151ifneq ($(BOARD_AVB_BOOT_KEY_PATH),)
3152$(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_BOOT_TEST_KEY_PATH)
3153endif
3154
3155# $(1): output file
3156define build-boot-test-harness-target
3157  $(MKBOOTIMG) --kernel $(PRODUCT_OUT)/$(subst .img,,$(subst boot-test-harness,kernel,$(notdir $(1)))) \
3158    $(INTERNAL_TEST_HARNESS_BOOTIMAGE_ARGS) $(INTERNAL_MKBOOTIMG_VERSION_ARGS) \
3159    $(BOARD_MKBOOTIMG_ARGS) --output $@
3160  $(if $(BOARD_AVB_BOOT_KEY_PATH),$(call test-key-sign-bootimage,$@,boot-test-harness))
3161endef
3162
3163# Build the new boot-test-harness.img, based on boot-debug.img and ramdisk-test-harness.img.
3164$(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_DEBUG_BOOTIMAGE_TARGET) $(AVBTOOL)
3165	$(call pretty,"Target boot test harness image: $@")
3166	$(call build-boot-test-harness-target,$@)
3167
3168$(call declare-1p-container,$(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET),)
3169$(call declare-container-license-deps,$(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET),$(INSTALLED_DEBUG_BOOTIMAGE_TARGET),$(PRODUCT_OUT)/:/)
3170
3171UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET)
3172
3173.PHONY: bootimage_test_harness-nodeps
3174bootimage_test_harness-nodeps: $(MKBOOTIMG) $(AVBTOOL)
3175	echo "make $@: ignoring dependencies"
3176	$(foreach b,$(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET),$(call build-boot-test-harness-target,$b))
3177
3178endif # BUILDING_DEBUG_BOOT_IMAGE
3179
3180# -----------------------------------------------------------------
3181# vendor test harness ramdisk, which is a vendor ramdisk combined with
3182# a test harness ramdisk.
3183ifdef BUILDING_DEBUG_VENDOR_BOOT_IMAGE
3184
3185INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET := $(call intermediates-dir-for,PACKAGING,vendor_boot-test-harness)/vendor_ramdisk-test-harness.cpio$(RAMDISK_EXT)
3186
3187# The order is important here. The test harness ramdisk staging directory has to
3188# come last so that it can override the adb_debug.prop in the debug ramdisk
3189# staging directory.
3190INTERNAL_TEST_HARNESS_VENDOR_RAMDISK_SRC_DIRS := $(INTERNAL_DEBUG_VENDOR_RAMDISK_SRC_DIRS) $(TARGET_TEST_HARNESS_RAMDISK_OUT)
3191INTERNAL_TEST_HARNESS_VENDOR_RAMDISK_SRC_DEPS := $(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK) $(INTERNAL_TEST_HARNESS_RAMDISK_FILES)
3192
3193$(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET): $(INTERNAL_TEST_HARNESS_VENDOR_RAMDISK_SRC_DEPS)
3194$(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET): $(MKBOOTFS) | $(COMPRESSION_COMMAND_DEPS)
3195	$(hide) rm -f $@
3196	$(hide) mkdir -p $(dir $@)
3197	$(MKBOOTFS) -d $(TARGET_OUT) $(INTERNAL_TEST_HARNESS_VENDOR_RAMDISK_SRC_DIRS) | $(COMPRESSION_COMMAND) > $@
3198
3199INSTALLED_VENDOR_TEST_HARNESS_RAMDISK_TARGET := $(PRODUCT_OUT)/vendor_ramdisk-test-harness.img
3200$(INSTALLED_VENDOR_TEST_HARNESS_RAMDISK_TARGET): $(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET)
3201	@echo "Target test harness vendor ramdisk: $@"
3202	$(copy-file-to-target)
3203
3204$(call declare-1p-container,$(INSTALLED_VENDOR_TEST_HARNESS_RAMDISK_TARGET),)
3205$(call declare-container-license-deps,$(INSTALLED_VENDOR_TEST_HARNESS_RAMDISK_TARGET),$(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET),$(PRODUCT_OUT)/:/)
3206
3207VENDOR_NOTICE_DEPS += $(INSTALLED_VENDOR_TEST_HARNESS_RAMDISK_TARGET)
3208
3209# -----------------------------------------------------------------
3210# vendor_boot-test-harness.img.
3211INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/vendor_boot-test-harness.img
3212
3213ifneq ($(BOARD_AVB_VENDOR_BOOT_KEY_PATH),)
3214$(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET): $(AVBTOOL) $(BOARD_AVB_VENDOR_BOOT_TEST_KEY_PATH)
3215endif
3216
3217# Depends on vendor_boot.img and vendor_ramdisk-test-harness.cpio$(RAMDISK_EXT) to build the new vendor_boot-test-harness.img
3218$(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INSTALLED_VENDOR_BOOTIMAGE_TARGET)
3219$(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET): $(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET)
3220$(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET): $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS)
3221	$(call pretty,"Target vendor_boot test harness image: $@")
3222	$(MKBOOTIMG) $(INTERNAL_VENDOR_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --vendor_ramdisk $(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET) $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_ARGS) --vendor_boot $@
3223	$(call assert-max-image-size,$@,$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE))
3224	$(if $(BOARD_AVB_VENDOR_BOOT_KEY_PATH),$(call test-key-sign-vendor-bootimage,$@))
3225
3226$(call declare-1p-container,$(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET),)
3227$(call declare-container-license-deps,$(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET),$(INTERNAL_VENDOR_TEST_HARNESS_RAMDISK_TARGET),$(PRODUCT_OUT)/:/)
3228
3229VENDOR_NOTICE_DEPS += $(INSTALLED_VENDOR_TEST_HARNESS_BOOTIMAGE_TARGET)
3230
3231endif # BUILDING_DEBUG_VENDOR_BOOT_IMAGE
3232
3233endif # BUILDING_DEBUG_BOOT_IMAGE || BUILDING_DEBUG_VENDOR_BOOT_IMAGE
3234
3235PARTITION_COMPAT_SYMLINKS :=
3236# Creates a compatibility symlink between two partitions, e.g. /system/vendor to /vendor
3237# $1: from location (e.g $(TARGET_OUT)/vendor)
3238# $2: destination location (e.g. /vendor)
3239# $3: partition image name (e.g. vendor.img)
3240define create-partition-compat-symlink
3241$(eval \
3242$1:
3243	@echo Symlink $(patsubst $(PRODUCT_OUT)/%,%,$1) to $2
3244	mkdir -p $(dir $1)
3245	if [ -d $1 ] && [ ! -h $1 ]; then \
3246	  echo 'Non-symlink $1 detected!' 1>&2; \
3247	  echo 'You cannot install files to $1 while building a separate $3!' 1>&2; \
3248	  exit 1; \
3249	fi
3250	ln -sfn $2 $1
3251)
3252$(eval PARTITION_COMPAT_SYMLINKS += $1)
3253$1
3254endef
3255
3256
3257# FSVerity metadata generation
3258# Generate fsverity metadata files (.fsv_meta) and build manifest
3259# (<partition>/etc/security/fsverity/BuildManifest<suffix>.apk) BEFORE filtering systemimage,
3260# vendorimage, odmimage, productimage files below.
3261ifeq ($(PRODUCT_FSVERITY_GENERATE_METADATA),true)
3262
3263fsverity-metadata-targets-patterns := \
3264  $(TARGET_OUT)/framework/% \
3265  $(TARGET_OUT)/etc/boot-image.prof \
3266  $(TARGET_OUT)/etc/dirty-image-objects \
3267  $(TARGET_OUT)/etc/preloaded-classes \
3268  $(TARGET_OUT)/etc/classpaths/%.pb \
3269
3270ifdef BUILDING_SYSTEM_EXT_IMAGE
3271fsverity-metadata-targets-patterns += $(TARGET_OUT_SYSTEM_EXT)/framework/%
3272endif
3273
3274# Generate fsv_meta
3275fsverity-metadata-targets := $(sort $(filter \
3276  $(fsverity-metadata-targets-patterns), \
3277  $(ALL_DEFAULT_INSTALLED_MODULES)))
3278
3279define fsverity-generate-metadata
3280$(call declare-0p-target,$(1).fsv_meta)
3281
3282$(1).fsv_meta: PRIVATE_SRC := $(1)
3283$(1).fsv_meta: PRIVATE_FSVERITY := $(HOST_OUT_EXECUTABLES)/fsverity
3284$(1).fsv_meta: $(HOST_OUT_EXECUTABLES)/fsverity_metadata_generator $(HOST_OUT_EXECUTABLES)/fsverity $(1)
3285	$$< --fsverity-path $$(PRIVATE_FSVERITY) --signature none \
3286	    --hash-alg sha256 --output $$@ $$(PRIVATE_SRC)
3287endef
3288
3289$(foreach f,$(fsverity-metadata-targets),$(eval $(call fsverity-generate-metadata,$(f))))
3290ALL_DEFAULT_INSTALLED_MODULES += $(addsuffix .fsv_meta,$(fsverity-metadata-targets))
3291
3292FSVERITY_APK_KEY_PATH := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
3293FSVERITY_APK_MANIFEST_TEMPLATE_PATH := system/security/fsverity/AndroidManifest.xml
3294
3295# Generate and install BuildManifest<suffix>.apk for the given partition
3296# $(1): path of the output APK
3297# $(2): partition name
3298define fsverity-generate-and-install-manifest-apk
3299fsverity-metadata-targets-$(2) := $(filter $(PRODUCT_OUT)/$(2)/%,\
3300      $(fsverity-metadata-targets))
3301$(1): PRIVATE_FSVERITY := $(HOST_OUT_EXECUTABLES)/fsverity
3302$(1): PRIVATE_AAPT2 := $(HOST_OUT_EXECUTABLES)/aapt2
3303$(1): PRIVATE_MIN_SDK_VERSION := $(DEFAULT_APP_TARGET_SDK)
3304$(1): PRIVATE_VERSION_CODE := $(PLATFORM_SDK_VERSION)
3305$(1): PRIVATE_VERSION_NAME := $(APPS_DEFAULT_VERSION_NAME)
3306$(1): PRIVATE_APKSIGNER := $(HOST_OUT_EXECUTABLES)/apksigner
3307$(1): PRIVATE_MANIFEST := $(FSVERITY_APK_MANIFEST_TEMPLATE_PATH)
3308$(1): PRIVATE_FRAMEWORK_RES := $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
3309$(1): PRIVATE_KEY := $(FSVERITY_APK_KEY_PATH)
3310$(1): PRIVATE_INPUTS := $$(fsverity-metadata-targets-$(2))
3311$(1): PRIVATE_ASSETS := $(call intermediates-dir-for,ETC,build_manifest-$(2))/assets
3312$(1): $(HOST_OUT_EXECUTABLES)/fsverity_manifest_generator \
3313    $(HOST_OUT_EXECUTABLES)/fsverity $(HOST_OUT_EXECUTABLES)/aapt2 \
3314    $(HOST_OUT_EXECUTABLES)/apksigner $(FSVERITY_APK_MANIFEST_TEMPLATE_PATH) \
3315    $(FSVERITY_APK_KEY_PATH).x509.pem $(FSVERITY_APK_KEY_PATH).pk8 \
3316    $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk \
3317    $$(fsverity-metadata-targets-$(2))
3318	rm -rf $$(PRIVATE_ASSETS)
3319	mkdir -p $$(PRIVATE_ASSETS)
3320	$$< --fsverity-path $$(PRIVATE_FSVERITY) \
3321	    --base-dir $$(PRODUCT_OUT) \
3322	    --output $$(PRIVATE_ASSETS)/build_manifest.pb \
3323	    $$(PRIVATE_INPUTS)
3324	$$(PRIVATE_AAPT2) link -o $$@ \
3325	    -A $$(PRIVATE_ASSETS) \
3326	    -I $$(PRIVATE_FRAMEWORK_RES) \
3327	    --min-sdk-version $$(PRIVATE_MIN_SDK_VERSION) \
3328	    --version-code $$(PRIVATE_VERSION_CODE) \
3329	    --version-name $$(PRIVATE_VERSION_NAME) \
3330	    --manifest $$(PRIVATE_MANIFEST) \
3331            --rename-manifest-package com.android.security.fsverity_metadata.$(2)
3332	$$(PRIVATE_APKSIGNER) sign --in $$@ \
3333	    --cert $$(PRIVATE_KEY).x509.pem \
3334	    --key $$(PRIVATE_KEY).pk8
3335
3336$(1).idsig: $(1)
3337
3338ALL_DEFAULT_INSTALLED_MODULES += $(1) $(1).idsig
3339
3340endef  # fsverity-generate-and-install-manifest-apk
3341
3342$(eval $(call fsverity-generate-and-install-manifest-apk, \
3343  $(TARGET_OUT)/etc/security/fsverity/BuildManifest.apk,system))
3344ALL_FSVERITY_BUILD_MANIFEST_APK += $(TARGET_OUT)/etc/security/fsverity/BuildManifest.apk $(TARGET_OUT)/etc/security/fsverity/BuildManifest.apk.idsig
3345ifdef BUILDING_SYSTEM_EXT_IMAGE
3346  $(eval $(call fsverity-generate-and-install-manifest-apk, \
3347    $(TARGET_OUT_SYSTEM_EXT)/etc/security/fsverity/BuildManifestSystemExt.apk,system_ext))
3348  ALL_FSVERITY_BUILD_MANIFEST_APK += $(TARGET_OUT_SYSTEM_EXT)/etc/security/fsverity/BuildManifestSystemExt.apk $(TARGET_OUT_SYSTEM_EXT)/etc/security/fsverity/BuildManifestSystemExt.apk.idsig
3349endif
3350
3351endif  # PRODUCT_FSVERITY_GENERATE_METADATA
3352
3353
3354# -----------------------------------------------------------------
3355# system image
3356
3357INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
3358INTERNAL_SYSTEMIMAGE_FILES := $(sort $(filter $(TARGET_OUT)/%, \
3359    $(ALL_DEFAULT_INSTALLED_MODULES)))
3360
3361# Create symlink /system/vendor to /vendor if necessary.
3362ifdef BOARD_USES_VENDORIMAGE
3363  _vendor_symlink := $(call create-partition-compat-symlink,$(TARGET_OUT)/vendor,/vendor,vendor.img)
3364  INTERNAL_SYSTEMIMAGE_FILES += $(_vendor_symlink)
3365  ALL_DEFAULT_INSTALLED_MODULES += $(_vendor_symlink)
3366endif
3367
3368# Create symlink /system/product to /product if necessary.
3369ifdef BOARD_USES_PRODUCTIMAGE
3370  _product_symlink := $(call create-partition-compat-symlink,$(TARGET_OUT)/product,/product,product.img)
3371  INTERNAL_SYSTEMIMAGE_FILES += $(_product_symlink)
3372  ALL_DEFAULT_INSTALLED_MODULES += $(_product_symlink)
3373endif
3374
3375# Create symlink /system/system_ext to /system_ext if necessary.
3376ifdef BOARD_USES_SYSTEM_EXTIMAGE
3377  _systemext_symlink := $(call create-partition-compat-symlink,$(TARGET_OUT)/system_ext,/system_ext,system_ext.img)
3378  INTERNAL_SYSTEMIMAGE_FILES += $(_systemext_symlink)
3379  ALL_DEFAULT_INSTALLED_MODULES += $(_systemext_symlink)
3380endif
3381
3382# -----------------------------------------------------------------
3383# system_dlkm partition image
3384
3385# Create symlinks for system_dlkm on devices with a system_dlkm partition:
3386# /system/lib/modules -> /system_dlkm/lib/modules
3387#
3388# On devices with a system_dlkm partition,
3389# - /system/lib/modules is a symlink to a directory that stores system DLKMs.
3390# - The system_dlkm partition is mounted at /system_dlkm at runtime.
3391ifdef BOARD_USES_SYSTEM_DLKMIMAGE
3392  _system_dlkm_lib_modules_symlink := $(call create-partition-compat-symlink,$(TARGET_OUT)/lib/modules,/system_dlkm/lib/modules,system_dlkm.img)
3393  INTERNAL_SYSTEMIMAGE_FILES += $(_system_dlkm_lib_modules_symlink)
3394  ALL_DEFAULT_INSTALLED_MODULES += $(_system_dlkm_lib_modules_symlink)
3395endif
3396
3397FULL_SYSTEMIMAGE_DEPS := $(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_USERIMAGES_DEPS)
3398
3399# ASAN libraries in the system image - add dependency.
3400ASAN_IN_SYSTEM_INSTALLED := $(TARGET_OUT)/asan.tar.bz2
3401ifneq (,$(filter address, $(SANITIZE_TARGET)))
3402  ifeq (true,$(SANITIZE_TARGET_SYSTEM))
3403    FULL_SYSTEMIMAGE_DEPS += $(ASAN_IN_SYSTEM_INSTALLED)
3404  endif
3405endif
3406
3407FULL_SYSTEMIMAGE_DEPS += $(INTERNAL_ROOT_FILES) $(INSTALLED_FILES_FILE_ROOT)
3408
3409# Returns a list of EXTRA_INSTALL_ZIPS trios whose primary file is contained within $(1)
3410# The trios will contain the primary installed file : the directory to unzip the zip to : the zip
3411define relevant-extra-install-zips
3412$(strip $(foreach p,$(EXTRA_INSTALL_ZIPS), \
3413  $(if $(filter $(call word-colon,1,$(p)),$(1)), \
3414    $(p))))
3415endef
3416
3417# Writes a text file that contains all of the files that will be inside a partition.
3418# All the file paths will be relative to the partition's staging directory.
3419# It will also take into account files inside zips listed in EXTRA_INSTALL_ZIPS.
3420#
3421# Arguments:
3422#   $(1): Output file
3423#   $(2): The partition's staging directory
3424#   $(3): Files to include in the partition
3425define write-partition-file-list
3426$(1): $$(HOST_OUT_EXECUTABLES)/extra_install_zips_file_list $(foreach p,$(call relevant-extra-install-zips,$(filter $(2)/%,$(3))),$(call word-colon,3,$(p)))
3427	@echo Writing $$@
3428	rm -f $$@
3429	echo -n > $$@
3430	$$(foreach f,$(subst $(2)/,,$(filter $(2)/%,$(3))),echo "$$(f)" >> $$@$$(newline))
3431	$$(HOST_OUT_EXECUTABLES)/extra_install_zips_file_list $(2) $(call relevant-extra-install-zips,$(filter $(2)/%,$(3))) >> $$@
3432endef
3433
3434# -----------------------------------------------------------------
3435ifdef BUILDING_SYSTEM_IMAGE
3436
3437# Install system linker configuration
3438# Collect all available stub libraries installed in system and install with predefined linker configuration
3439# Also append LLNDK libraries in the APEX as required libs
3440SYSTEM_LINKER_CONFIG := $(TARGET_OUT)/etc/linker.config.pb
3441SYSTEM_LINKER_CONFIG_SOURCE := $(call intermediates-dir-for,ETC,system_linker_config)/system_linker_config
3442$(SYSTEM_LINKER_CONFIG): PRIVATE_SYSTEM_LINKER_CONFIG_SOURCE := $(SYSTEM_LINKER_CONFIG_SOURCE)
3443$(SYSTEM_LINKER_CONFIG): $(INTERNAL_SYSTEMIMAGE_FILES) $(SYSTEM_LINKER_CONFIG_SOURCE) | conv_linker_config
3444	@echo Creating linker config: $@
3445	@mkdir -p $(dir $@)
3446	@rm -f $@
3447	$(HOST_OUT_EXECUTABLES)/conv_linker_config systemprovide --source $(PRIVATE_SYSTEM_LINKER_CONFIG_SOURCE) \
3448		--output $@ --value "$(STUB_LIBRARIES)" --system "$(TARGET_OUT)"
3449	$(HOST_OUT_EXECUTABLES)/conv_linker_config append --source $@ --output $@ --key requireLibs \
3450		--value "$(foreach lib,$(LLNDK_MOVED_TO_APEX_LIBRARIES), $(lib).so)"
3451
3452$(call declare-1p-target,$(SYSTEM_LINKER_CONFIG),)
3453$(call declare-license-deps,$(SYSTEM_LINKER_CONFIG),$(INTERNAL_SYSTEMIMAGE_FILES) $(SYSTEM_LINKER_CONFIG_SOURCE))
3454
3455FULL_SYSTEMIMAGE_DEPS += $(SYSTEM_LINKER_CONFIG)
3456ALL_DEFAULT_INSTALLED_MODULES += $(SYSTEM_LINKER_CONFIG)
3457
3458# installed file list
3459# Depending on anything that $(BUILT_SYSTEMIMAGE) depends on.
3460# We put installed-files.txt ahead of image itself in the dependency graph
3461# so that we can get the size stat even if the build fails due to too large
3462# system image.
3463INSTALLED_FILES_FILE := $(PRODUCT_OUT)/installed-files.txt
3464INSTALLED_FILES_JSON := $(INSTALLED_FILES_FILE:.txt=.json)
3465$(INSTALLED_FILES_FILE): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON)
3466$(INSTALLED_FILES_FILE): $(FULL_SYSTEMIMAGE_DEPS) $(FILESLIST) $(FILESLIST_UTIL)
3467	@echo Installed file list: $@
3468	mkdir -p $(dir $@)
3469	rm -f $@
3470	$(FILESLIST) $(TARGET_OUT) > $(@:.txt=.json)
3471	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3472
3473$(eval $(call declare-0p-target,$(INSTALLED_FILES_FILE)))
3474$(eval $(call declare-0p-target,$(INSTALLED_FILES_JSON)))
3475
3476.PHONY: installed-file-list
3477installed-file-list: $(INSTALLED_FILES_FILE)
3478
3479systemimage_intermediates :=$= $(call intermediates-dir-for,PACKAGING,system)
3480BUILT_SYSTEMIMAGE :=$= $(systemimage_intermediates)/system.img
3481
3482# $(1): output file
3483define build-systemimage-target
3484  @echo "Target system fs image: $(1)"
3485  @mkdir -p $(dir $(1)) $(systemimage_intermediates) && rm -rf $(systemimage_intermediates)/system_image_info.txt
3486  $(call generate-image-prop-dictionary, $(systemimage_intermediates)/system_image_info.txt,system, \
3487      skip_fsck=true)
3488  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3489      $(BUILD_IMAGE) \
3490          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(systemimage_intermediates)/file_list.txt) \
3491          $(TARGET_OUT) $(systemimage_intermediates)/system_image_info.txt $(1) $(TARGET_OUT) \
3492          || ( mkdir -p $${DIST_DIR}; \
3493               cp $(INSTALLED_FILES_FILE) $${DIST_DIR}/installed-files-rescued.txt; \
3494               exit 1 )
3495endef
3496
3497$(eval $(call write-partition-file-list,$(systemimage_intermediates)/file_list.txt,$(TARGET_OUT),$(FULL_SYSTEMIMAGE_DEPS)))
3498# Used by soong sandwich to request the staging dir be built
3499$(systemimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT)/%,$(FULL_SYSTEMIMAGE_DEPS))
3500	touch $@
3501
3502ifeq ($(BOARD_AVB_ENABLE),true)
3503$(BUILT_SYSTEMIMAGE): $(BOARD_AVB_SYSTEM_KEY_PATH)
3504endif
3505$(BUILT_SYSTEMIMAGE): $(FULL_SYSTEMIMAGE_DEPS) $(INSTALLED_FILES_FILE) $(systemimage_intermediates)/file_list.txt
3506	$(call build-systemimage-target,$@)
3507
3508$(call declare-1p-container,$(BUILT_SYSTEMIMAGE),system/extras)
3509$(call declare-container-license-deps,$(BUILT_SYSTEMIMAGE),$(FULL_SYSTEMIMAGE_DEPS),$(PRODUCT_OUT)/:/)
3510
3511INSTALLED_SYSTEMIMAGE_TARGET := $(PRODUCT_OUT)/system.img
3512SYSTEMIMAGE_SOURCE_DIR := $(TARGET_OUT)
3513
3514# INSTALLED_SYSTEMIMAGE_TARGET used to be named INSTALLED_SYSTEMIMAGE. Create an alias for backward
3515# compatibility, in case device-specific Makefiles still refer to the old name.
3516INSTALLED_SYSTEMIMAGE := $(INSTALLED_SYSTEMIMAGE_TARGET)
3517
3518# The system partition needs room for the recovery image as well.  We
3519# now store the recovery image as a binary patch using the boot image
3520# as the source (since they are very similar).  Generate the patch so
3521# we can see how big it's going to be, and include that in the system
3522# image size check calculation.
3523ifneq ($(INSTALLED_BOOTIMAGE_TARGET),)
3524ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
3525ifneq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
3526ifneq (,$(filter true,$(BOARD_INCLUDE_RECOVERY_DTBO) $(BOARD_INCLUDE_RECOVERY_ACPIO)))
3527diff_tool := $(HOST_OUT_EXECUTABLES)/bsdiff
3528else
3529diff_tool := $(HOST_OUT_EXECUTABLES)/imgdiff
3530endif
3531intermediates := $(call intermediates-dir-for,PACKAGING,recovery_patch)
3532RECOVERY_FROM_BOOT_PATCH := $(intermediates)/recovery_from_boot.p
3533$(RECOVERY_FROM_BOOT_PATCH): PRIVATE_DIFF_TOOL := $(diff_tool)
3534$(RECOVERY_FROM_BOOT_PATCH): \
3535	    $(INSTALLED_RECOVERYIMAGE_TARGET) \
3536	    $(firstword $(INSTALLED_BOOTIMAGE_TARGET)) \
3537	    $(diff_tool)
3538	@echo "Construct recovery from boot"
3539	mkdir -p $(dir $@)
3540	$(PRIVATE_DIFF_TOOL) $(firstword $(INSTALLED_BOOTIMAGE_TARGET)) $(INSTALLED_RECOVERYIMAGE_TARGET) $@
3541else # $(BOARD_USES_FULL_RECOVERY_IMAGE) == true
3542RECOVERY_FROM_BOOT_PATCH := $(INSTALLED_RECOVERYIMAGE_TARGET)
3543endif # BOARD_USES_FULL_RECOVERY_IMAGE
3544endif # INSTALLED_RECOVERYIMAGE_TARGET
3545endif # INSTALLED_BOOTIMAGE_TARGET
3546
3547$(INSTALLED_SYSTEMIMAGE_TARGET): $(BUILT_SYSTEMIMAGE)
3548	@echo "Install system fs image: $@"
3549	$(copy-file-to-target)
3550	$(hide) $(call assert-max-image-size,$@,$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
3551
3552$(call declare-1p-container,$(INSTALLED_SYSTEMIMAGE_TARGET),)
3553$(call declare-container-license-deps,$(INSTALLED_SYSTEMIMAGE_TARGET),$(BUILT_SYSTEMIMAGE),$(BUILT_SYSTEMIMAGE):/)
3554
3555systemimage: $(INSTALLED_SYSTEMIMAGE_TARGET)
3556
3557SYSTEM_NOTICE_DEPS += $(INSTALLED_SYSTEMIMAGE_TARGET)
3558
3559.PHONY: systemimage-nodeps snod
3560systemimage-nodeps snod: $(filter-out systemimage-nodeps snod,$(MAKECMDGOALS)) \
3561	            | $(INTERNAL_USERIMAGES_DEPS) $(systemimage_intermediates)/file_list.txt
3562	@echo "make $@: ignoring dependencies"
3563	$(call build-systemimage-target,$(INSTALLED_SYSTEMIMAGE_TARGET))
3564	$(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMIMAGE_TARGET),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
3565ifeq (true,$(WITH_DEXPREOPT))
3566	$(warning Warning: with dexpreopt enabled, you may need a full rebuild.)
3567endif
3568
3569endif # BUILDING_SYSTEM_IMAGE
3570
3571.PHONY: sync syncsys sync_system
3572sync syncsys sync_system: $(INTERNAL_SYSTEMIMAGE_FILES)
3573
3574# -----------------------------------------------------------------
3575# Old PDK fusion targets
3576.PHONY: platform
3577platform:
3578	echo "Warning: 'platform' is obsolete"
3579
3580.PHONY: platform-java
3581platform-java:
3582	echo "Warning: 'platform-java' is obsolete"
3583
3584# -----------------------------------------------------------------
3585# data partition image
3586INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT_DATA)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
3587INTERNAL_USERDATAIMAGE_FILES := \
3588    $(filter $(TARGET_OUT_DATA)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
3589
3590ifdef BUILDING_USERDATA_IMAGE
3591userdataimage_intermediates := \
3592    $(call intermediates-dir-for,PACKAGING,userdata)
3593BUILT_USERDATAIMAGE_TARGET := $(PRODUCT_OUT)/userdata.img
3594
3595define build-userdataimage-target
3596  $(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
3597  @mkdir -p $(TARGET_OUT_DATA)
3598  @mkdir -p $(userdataimage_intermediates) && rm -rf $(userdataimage_intermediates)/userdata_image_info.txt
3599  $(call generate-image-prop-dictionary, $(userdataimage_intermediates)/userdata_image_info.txt,userdata,skip_fsck=true)
3600  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3601      $(BUILD_IMAGE) \
3602          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(userdataimage_intermediates)/file_list.txt) \
3603          $(TARGET_OUT_DATA) $(userdataimage_intermediates)/userdata_image_info.txt \
3604          $(INSTALLED_USERDATAIMAGE_TARGET) $(TARGET_OUT)
3605  $(call assert-max-image-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_PARTITION_SIZE))
3606endef
3607
3608# We just build this directly to the install location.
3609INSTALLED_USERDATAIMAGE_TARGET := $(BUILT_USERDATAIMAGE_TARGET)
3610INSTALLED_USERDATAIMAGE_TARGET_DEPS := \
3611    $(INTERNAL_USERIMAGES_DEPS) \
3612    $(INTERNAL_USERDATAIMAGE_FILES)
3613
3614$(eval $(call write-partition-file-list,$(userdataimage_intermediates)/file_list.txt,$(TARGET_OUT_DATA),$(INSTALLED_USERDATAIMAGE_TARGET_DEPS)))
3615# Used by soong sandwich to request the staging dir be built
3616$(userdataimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT_DATA)/%,$(INSTALLED_USERDATAIMAGE_TARGET_DEPS))
3617	touch $@
3618
3619$(INSTALLED_USERDATAIMAGE_TARGET): $(INSTALLED_USERDATAIMAGE_TARGET_DEPS) $(userdataimage_intermediates)/file_list.txt
3620	$(build-userdataimage-target)
3621
3622$(call declare-1p-container,$(INSTALLED_USERDATAIMAGE_TARGET),)
3623$(call declare-container-license-deps,$(INSTALLED_USERDATAIMAGE_TARGET),$(INSTALLED_USERDATAIMAGE_TARGET_DEPS),$(PRODUCT_OUT)/:/)
3624
3625UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_USERDATAIMAGE_TARGET)
3626
3627.PHONY: userdataimage-nodeps
3628userdataimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS) $(userdataimage_intermediates)/file_list.txt
3629	$(build-userdataimage-target)
3630
3631endif # BUILDING_USERDATA_IMAGE
3632
3633# ASAN libraries in the system image - build rule.
3634ASAN_OUT_DIRS_FOR_SYSTEM_INSTALL := $(sort $(patsubst $(PRODUCT_OUT)/%,%,\
3635  $(TARGET_OUT_SHARED_LIBRARIES) \
3636  $(2ND_TARGET_OUT_SHARED_LIBRARIES) \
3637  $(TARGET_OUT_VENDOR_SHARED_LIBRARIES) \
3638  $(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES)))
3639# Extra options: Enforce the system user for the files to avoid having to change ownership.
3640ASAN_SYSTEM_INSTALL_OPTIONS := --owner=1000 --group=1000
3641# Note: experimentally, it seems not worth it to try to get "best" compression. We don't save
3642#       enough space.
3643$(ASAN_IN_SYSTEM_INSTALLED): $(INSTALLED_USERDATAIMAGE_TARGET_DEPS)
3644	tar cfj $(ASAN_IN_SYSTEM_INSTALLED) $(ASAN_SYSTEM_INSTALL_OPTIONS) -C $(TARGET_OUT_DATA)/.. $(ASAN_OUT_DIRS_FOR_SYSTEM_INSTALL) >/dev/null
3645
3646# -----------------------------------------------------------------
3647# cache partition image
3648INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT_CACHE)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
3649ifdef BUILDING_CACHE_IMAGE
3650INTERNAL_CACHEIMAGE_FILES := \
3651    $(filter $(TARGET_OUT_CACHE)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
3652
3653cacheimage_intermediates := \
3654    $(call intermediates-dir-for,PACKAGING,cache)
3655BUILT_CACHEIMAGE_TARGET := $(PRODUCT_OUT)/cache.img
3656
3657define build-cacheimage-target
3658  $(call pretty,"Target cache fs image: $(INSTALLED_CACHEIMAGE_TARGET)")
3659  @mkdir -p $(TARGET_OUT_CACHE)
3660  @mkdir -p $(cacheimage_intermediates) && rm -rf $(cacheimage_intermediates)/cache_image_info.txt
3661  $(call generate-image-prop-dictionary, $(cacheimage_intermediates)/cache_image_info.txt,cache,skip_fsck=true)
3662  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3663      $(BUILD_IMAGE) \
3664          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(cacheimage_intermediates)/file_list.txt) \
3665          $(TARGET_OUT_CACHE) $(cacheimage_intermediates)/cache_image_info.txt \
3666          $(INSTALLED_CACHEIMAGE_TARGET) $(TARGET_OUT)
3667  $(call assert-max-image-size,$(INSTALLED_CACHEIMAGE_TARGET),$(BOARD_CACHEIMAGE_PARTITION_SIZE))
3668endef
3669
3670$(eval $(call write-partition-file-list,$(cacheimage_intermediates)/file_list.txt,$(TARGET_OUT_CACHE),$(INTERNAL_CACHEIMAGE_FILES)))
3671# Used by soong sandwich to request the staging dir be built
3672$(cacheimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT_CACHE)/%,$(INTERNAL_CACHEIMAGE_FILES))
3673	touch $@
3674
3675# We just build this directly to the install location.
3676INSTALLED_CACHEIMAGE_TARGET := $(BUILT_CACHEIMAGE_TARGET)
3677$(INSTALLED_CACHEIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_CACHEIMAGE_FILES) $(cacheimage_intermediates)/file_list.txt
3678	$(build-cacheimage-target)
3679
3680$(call declare-1p-container,$(INSTALLED_CACHEIMAGE_TARGET),)
3681$(call declare-container-license-deps,$(INSTALLED_CACHEIMAGE_TARGET),$(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_CACHEIMAGE_FILES),$(PRODUCT_OUT)/:/)
3682
3683UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_CACHEIMAGE_TARGET)
3684
3685.PHONY: cacheimage-nodeps
3686cacheimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS) $(cacheimage_intermediates)/file_list.txt
3687	$(build-cacheimage-target)
3688
3689else # BUILDING_CACHE_IMAGE
3690# we need to ignore the broken cache link when doing the rsync
3691IGNORE_CACHE_LINK := --exclude=cache
3692endif # BUILDING_CACHE_IMAGE
3693
3694# -----------------------------------------------------------------
3695# system_other partition image
3696INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT_SYSTEM_OTHER)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
3697ifdef BUILDING_SYSTEM_OTHER_IMAGE
3698ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
3699# Marker file to identify that odex files are installed
3700INSTALLED_SYSTEM_OTHER_ODEX_MARKER := $(TARGET_OUT_SYSTEM_OTHER)/system-other-odex-marker
3701ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_SYSTEM_OTHER_ODEX_MARKER)
3702$(INSTALLED_SYSTEM_OTHER_ODEX_MARKER):
3703	$(hide) touch $@
3704
3705$(call declare-0p-target,$(INSTALLED_SYSTEM_OTHER_ODEX_MARKER))
3706endif
3707
3708INTERNAL_SYSTEMOTHERIMAGE_FILES := \
3709    $(filter $(TARGET_OUT_SYSTEM_OTHER)/%,\
3710      $(ALL_DEFAULT_INSTALLED_MODULES))
3711
3712# system_other dex files are installed as a side-effect of installing system image files
3713INTERNAL_SYSTEMOTHERIMAGE_FILES += $(INTERNAL_SYSTEMIMAGE_FILES)
3714
3715INSTALLED_FILES_FILE_SYSTEMOTHER := $(PRODUCT_OUT)/installed-files-system-other.txt
3716INSTALLED_FILES_JSON_SYSTEMOTHER := $(INSTALLED_FILES_FILE_SYSTEMOTHER:.txt=.json)
3717$(INSTALLED_FILES_FILE_SYSTEMOTHER): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_SYSTEMOTHER)
3718$(INSTALLED_FILES_FILE_SYSTEMOTHER) : $(INTERNAL_SYSTEMOTHERIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3719	@echo Installed file list: $@
3720	mkdir -p $(dir $@)
3721	rm -f $@
3722	$(FILESLIST) $(TARGET_OUT_SYSTEM_OTHER) > $(@:.txt=.json)
3723	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3724
3725$(eval $(call declare-0p-target,$(INSTALLED_FILES_FILE_SYSTEMOTHER)))
3726$(eval $(call declare-0p-target,$(INSTALLED_FILES_JSON_SYSTEMOTHER)))
3727
3728# Determines partition size for system_other.img.
3729ifeq ($(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS),true)
3730ifneq ($(filter system,$(BOARD_SUPER_PARTITION_BLOCK_DEVICES)),)
3731INTERNAL_SYSTEM_OTHER_PARTITION_SIZE := $(BOARD_SUPER_PARTITION_SYSTEM_DEVICE_SIZE)
3732endif
3733endif
3734
3735ifndef INTERNAL_SYSTEM_OTHER_PARTITION_SIZE
3736INTERNAL_SYSTEM_OTHER_PARTITION_SIZE:= $(BOARD_SYSTEMIMAGE_PARTITION_SIZE)
3737endif
3738
3739systemotherimage_intermediates := \
3740    $(call intermediates-dir-for,PACKAGING,system_other)
3741BUILT_SYSTEMOTHERIMAGE_TARGET := $(PRODUCT_OUT)/system_other.img
3742
3743# Note that we assert the size is SYSTEMIMAGE_PARTITION_SIZE since this is the 'b' system image.
3744define build-systemotherimage-target
3745  $(call pretty,"Target system_other fs image: $(INSTALLED_SYSTEMOTHERIMAGE_TARGET)")
3746  @mkdir -p $(TARGET_OUT_SYSTEM_OTHER)
3747  @mkdir -p $(systemotherimage_intermediates) && rm -rf $(systemotherimage_intermediates)/system_other_image_info.txt
3748  $(call generate-image-prop-dictionary, $(systemotherimage_intermediates)/system_other_image_info.txt,system,skip_fsck=true)
3749  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3750      $(BUILD_IMAGE) \
3751          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(systemotherimage_intermediates)/file_list.txt) \
3752          $(TARGET_OUT_SYSTEM_OTHER) $(systemotherimage_intermediates)/system_other_image_info.txt \
3753          $(INSTALLED_SYSTEMOTHERIMAGE_TARGET) $(TARGET_OUT)
3754  $(call assert-max-image-size,$(INSTALLED_SYSTEMOTHERIMAGE_TARGET),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))
3755endef
3756
3757$(eval $(call write-partition-file-list,$(systemotherimage_intermediates)/file_list.txt,$(TARGET_OUT_SYSTEM_OTHER),$(INTERNAL_SYSTEMOTHERIMAGE_FILES)))
3758# Used by soong sandwich to request the staging dir be built
3759$(systemotherimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT_SYSTEM_OTHER)/%,$(INTERNAL_SYSTEMOTHERIMAGE_FILES))
3760	touch $@
3761
3762# We just build this directly to the install location.
3763INSTALLED_SYSTEMOTHERIMAGE_TARGET := $(BUILT_SYSTEMOTHERIMAGE_TARGET)
3764ifneq (true,$(SANITIZE_LITE))
3765# Only create system_other when not building the second stage of a SANITIZE_LITE build.
3766$(INSTALLED_SYSTEMOTHERIMAGE_TARGET): $(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_SYSTEMOTHERIMAGE_FILES) $(INSTALLED_FILES_FILE_SYSTEMOTHER) $(systemotherimage_intermediates)/file_list.txt
3767	$(build-systemotherimage-target)
3768
3769$(call declare-1p-container,$(INSTALLED_SYSTEMOTHERIMAGE_TARGET),)
3770$(call declare-container-license-deps,$(INSTALLED_SYSTEMOTHERIMAGE_TARGET),$(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_SYSTEMOTHERIMAGE_FILES),$(PRODUCT_OUT)/:/)
3771
3772UNMOUNTED_NOTICE_DEPS += $(INSTALLED_SYSTEMOTHERIMAGE_TARGET)
3773endif
3774
3775.PHONY: systemotherimage-nodeps
3776systemotherimage-nodeps: | $(INTERNAL_USERIMAGES_DEPS) $(systemotherimage_intermediates)/file_list.txt
3777	$(build-systemotherimage-target)
3778
3779endif # BUILDING_SYSTEM_OTHER_IMAGE
3780
3781
3782# -----------------------------------------------------------------
3783# vendor partition image
3784INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT_VENDOR)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
3785ifdef BUILDING_VENDOR_IMAGE
3786INTERNAL_VENDORIMAGE_FILES := \
3787    $(filter $(TARGET_OUT_VENDOR)/%,\
3788      $(ALL_DEFAULT_INSTALLED_MODULES))
3789
3790
3791# Create symlink /vendor/odm to /odm if necessary.
3792ifdef BOARD_USES_ODMIMAGE
3793  _odm_symlink := $(call create-partition-compat-symlink,$(TARGET_OUT_VENDOR)/odm,/odm,odm.img)
3794  INTERNAL_VENDORIMAGE_FILES += $(_odm_symlink)
3795  ALL_DEFAULT_INSTALLED_MODULES += $(_odm_symlink)
3796endif
3797
3798# Create symlinks for vendor_dlkm on devices with a vendor_dlkm partition:
3799# /vendor/lib/modules -> /vendor_dlkm/lib/modules
3800#
3801# On devices with a vendor_dlkm partition,
3802# - /vendor/lib/modules is a symlink to a directory that stores vendor DLKMs.
3803# - /vendor_dlkm/{etc,...} store other vendor_dlkm files directly. The vendor_dlkm partition is
3804#   mounted at /vendor_dlkm at runtime and the symlinks created in system/core/rootdir/Android.mk
3805#   are hidden.
3806# On devices without a vendor_dlkm partition,
3807# - /vendor/lib/modules stores vendor DLKMs directly.
3808# - /vendor_dlkm/{etc,...} are symlinks to directories that store other vendor_dlkm files.
3809#   See system/core/rootdir/Android.mk for a list of created symlinks.
3810# The vendor DLKMs and other vendor_dlkm files must not be accessed using other paths because they
3811# are not guaranteed to exist on all devices.
3812ifdef BOARD_USES_VENDOR_DLKMIMAGE
3813  _vendor_dlkm_lib_modules_symlink := $(call create-partition-compat-symlink,$(TARGET_OUT_VENDOR)/lib/modules,/vendor_dlkm/lib/modules,vendor_dlkm.img)
3814  INTERNAL_VENDORIMAGE_FILES += $(_vendor_dlkm_lib_modules_symlink)
3815  ALL_DEFAULT_INSTALLED_MODULES += $(_vendor_dlkm_lib_modules_symlink)
3816endif
3817
3818# Install vendor/etc/linker.config.pb with PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS and SOONG_STUB_VENDOR_LIBRARIES
3819vendor_linker_config_file := $(TARGET_OUT_VENDOR)/etc/linker.config.pb
3820$(vendor_linker_config_file): private_linker_config_fragments := $(PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS)
3821$(vendor_linker_config_file): $(INTERNAL_VENDORIMAGE_FILES) $(PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS) | $(HOST_OUT_EXECUTABLES)/conv_linker_config
3822	@echo Creating linker config: $@
3823	@mkdir -p $(dir $@)
3824	@rm -f $@
3825	$(HOST_OUT_EXECUTABLES)/conv_linker_config proto \
3826		--source $(call normalize-path-list,$(private_linker_config_fragments)) \
3827		--output $@
3828	$(HOST_OUT_EXECUTABLES)/conv_linker_config systemprovide --source $@ \
3829		--output $@ --value "$(SOONG_STUB_VENDOR_LIBRARIES)" --system "$(TARGET_OUT_VENDOR)"
3830$(call define declare-0p-target,$(vendor_linker_config_file),)
3831INTERNAL_VENDORIMAGE_FILES += $(vendor_linker_config_file)
3832ALL_DEFAULT_INSTALLED_MODULES += $(vendor_linker_config_file)
3833
3834INSTALLED_FILES_FILE_VENDOR := $(PRODUCT_OUT)/installed-files-vendor.txt
3835INSTALLED_FILES_JSON_VENDOR := $(INSTALLED_FILES_FILE_VENDOR:.txt=.json)
3836$(INSTALLED_FILES_FILE_VENDOR): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_VENDOR)
3837$(INSTALLED_FILES_FILE_VENDOR) : $(INTERNAL_VENDORIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3838	@echo Installed file list: $@
3839	mkdir -p $(dir $@)
3840	rm -f $@
3841	$(FILESLIST) $(TARGET_OUT_VENDOR) > $(@:.txt=.json)
3842	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3843
3844$(call declare-0p-target,$(INSTALLED_FILES_FILE_VENDOR))
3845$(call declare-0p-target,$(INSTALLED_FILES_JSON_VENDOR))
3846
3847vendorimage_intermediates := \
3848    $(call intermediates-dir-for,PACKAGING,vendor)
3849BUILT_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
3850define build-vendorimage-target
3851  $(call pretty,"Target vendor fs image: $(INSTALLED_VENDORIMAGE_TARGET)")
3852  @mkdir -p $(TARGET_OUT_VENDOR)
3853  @mkdir -p $(vendorimage_intermediates) && rm -rf $(vendorimage_intermediates)/vendor_image_info.txt
3854  $(call generate-image-prop-dictionary, $(vendorimage_intermediates)/vendor_image_info.txt,vendor,skip_fsck=true)
3855  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3856      $(BUILD_IMAGE) \
3857          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(vendorimage_intermediates)/file_list.txt) \
3858          $(TARGET_OUT_VENDOR) $(vendorimage_intermediates)/vendor_image_info.txt \
3859          $(INSTALLED_VENDORIMAGE_TARGET) $(TARGET_OUT)
3860  $(call assert-max-image-size,$(INSTALLED_VENDORIMAGE_TARGET) $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_VENDORIMAGE_PARTITION_SIZE))
3861endef
3862
3863$(eval $(call write-partition-file-list,$(vendorimage_intermediates)/file_list.txt,$(TARGET_OUT_VENDOR),$(INTERNAL_VENDORIMAGE_FILES)))
3864# Used by soong sandwich to request the staging dir be built
3865$(vendorimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT_VENDOR)/%,$(INTERNAL_VENDORIMAGE_FILES))
3866	touch $@
3867
3868# We just build this directly to the install location.
3869INSTALLED_VENDORIMAGE_TARGET := $(BUILT_VENDORIMAGE_TARGET)
3870$(INSTALLED_VENDORIMAGE_TARGET): \
3871    $(INTERNAL_USERIMAGES_DEPS) \
3872    $(INTERNAL_VENDORIMAGE_FILES) \
3873    $(INSTALLED_FILES_FILE_VENDOR) \
3874    $(RECOVERY_FROM_BOOT_PATCH) \
3875    $(vendorimage_intermediates)/file_list.txt
3876	$(build-vendorimage-target)
3877
3878VENDOR_NOTICE_DEPS += $(INSTALLED_VENDORIMAGE_TARGET)
3879
3880$(call declare-container-license-metadata,$(INSTALLED_VENDORIMAGE_TARGET),legacy_proprietary,proprietary,,"Vendor Image",vendor)
3881$(call declare-container-license-deps,$(INSTALLED_VENDORIMAGE_TARGET),$(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_VENDORIMAGE_FILES) $(RECOVERY_FROM_BOOT_PATH),$(PRODUCT_OUT)/:/)
3882
3883.PHONY: vendorimage-nodeps vnod
3884vendorimage-nodeps vnod: | $(INTERNAL_USERIMAGES_DEPS) $(vendorimage_intermediates)/file_list.txt
3885	$(build-vendorimage-target)
3886
3887.PHONY: sync_vendor
3888sync sync_vendor: $(INTERNAL_VENDORIMAGE_FILES)
3889
3890else ifdef BOARD_PREBUILT_VENDORIMAGE
3891INSTALLED_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
3892$(eval $(call copy-one-file,$(BOARD_PREBUILT_VENDORIMAGE),$(INSTALLED_VENDORIMAGE_TARGET)))
3893$(if $(strip $(ALL_TARGETS.$(INSTALLED_VENDORIMAGE_TARGET).META_LIC)),,\
3894    $(if $(strip $(ALL_TARGETS.$(BOARD_PREBUILT_VENDORIMAGE).META_LIC)),\
3895        $(call declare-copy-target-license-metadata,$(INSTALLED_VENDORIMAGE_TARGET),$(BOARD_PREBUILT_VENDORIMAGE)),\
3896        $(call declare-license-metadata,$(INSTALLED_VENDORIMAGE_TARGET),legacy_proprietary,proprietary,,"Vendor Image",vendor)))
3897endif
3898
3899# -----------------------------------------------------------------
3900# product partition image
3901INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT_PRODUCT)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
3902ifdef BUILDING_PRODUCT_IMAGE
3903INTERNAL_PRODUCTIMAGE_FILES := \
3904    $(filter $(TARGET_OUT_PRODUCT)/%,\
3905      $(ALL_DEFAULT_INSTALLED_MODULES))
3906
3907INSTALLED_FILES_FILE_PRODUCT := $(PRODUCT_OUT)/installed-files-product.txt
3908INSTALLED_FILES_JSON_PRODUCT := $(INSTALLED_FILES_FILE_PRODUCT:.txt=.json)
3909$(INSTALLED_FILES_FILE_PRODUCT): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_PRODUCT)
3910$(INSTALLED_FILES_FILE_PRODUCT) : $(INTERNAL_PRODUCTIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3911	@echo Installed file list: $@
3912	mkdir -p $(dir $@)
3913	rm -f $@
3914	$(FILESLIST) $(TARGET_OUT_PRODUCT) > $(@:.txt=.json)
3915	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3916
3917$(call declare-0p-target,$(INSTALLED_FILES_FILE_PRODUCT))
3918$(call declare-0p-target,$(INSTALLED_FILES_JSON_PRODUCT))
3919
3920productimage_intermediates := \
3921    $(call intermediates-dir-for,PACKAGING,product)
3922BUILT_PRODUCTIMAGE_TARGET := $(PRODUCT_OUT)/product.img
3923define build-productimage-target
3924  $(call pretty,"Target product fs image: $(INSTALLED_PRODUCTIMAGE_TARGET)")
3925  @mkdir -p $(TARGET_OUT_PRODUCT)
3926  @mkdir -p $(productimage_intermediates) && rm -rf $(productimage_intermediates)/product_image_info.txt
3927  $(call generate-image-prop-dictionary, $(productimage_intermediates)/product_image_info.txt,product,skip_fsck=true)
3928  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3929      $(BUILD_IMAGE) \
3930          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(productimage_intermediates)/file_list.txt) \
3931          $(TARGET_OUT_PRODUCT) $(productimage_intermediates)/product_image_info.txt \
3932          $(INSTALLED_PRODUCTIMAGE_TARGET) $(TARGET_OUT)
3933  $(call assert-max-image-size,$(INSTALLED_PRODUCTIMAGE_TARGET),$(BOARD_PRODUCTIMAGE_PARTITION_SIZE))
3934endef
3935
3936$(eval $(call write-partition-file-list,$(productimage_intermediates)/file_list.txt,$(TARGET_OUT_PRODUCT),$(INTERNAL_PRODUCTIMAGE_FILES)))
3937# Used by soong sandwich to request the staging dir be built
3938$(productimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT_PRODUCT)/%,$(INTERNAL_PRODUCTIMAGE_FILES))
3939	touch $@
3940
3941# We just build this directly to the install location.
3942INSTALLED_PRODUCTIMAGE_TARGET := $(BUILT_PRODUCTIMAGE_TARGET)
3943$(INSTALLED_PRODUCTIMAGE_TARGET): \
3944    $(INTERNAL_USERIMAGES_DEPS) \
3945    $(INTERNAL_PRODUCTIMAGE_FILES) \
3946    $(INSTALLED_FILES_FILE_PRODUCT) \
3947    $(productimage_intermediates)/file_list.txt
3948	$(build-productimage-target)
3949
3950PRODUCT_NOTICE_DEPS += $(INSTALLED_PRODUCTIMAGE_TARGET)
3951
3952$(call declare-1p-container,$(INSTALLED_PRODUCTIMAGE_TARGET),)
3953$(call declare-container-license-deps,$(INSTALLED_PRODUCTIMAGE_TARGET),$(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_PRODUCTIMAGE_FILES) $(INSTALLED_FILES_FILE_PRODUCT),$(PRODUCT_OUT)/:/)
3954
3955.PHONY: productimage-nodeps pnod
3956productimage-nodeps pnod: | $(INTERNAL_USERIMAGES_DEPS) $(productimage_intermediates)/file_list.txt
3957	$(build-productimage-target)
3958
3959.PHONY: sync_product
3960sync sync_product: $(INTERNAL_PRODUCTIMAGE_FILES)
3961
3962else ifdef BOARD_PREBUILT_PRODUCTIMAGE
3963INSTALLED_PRODUCTIMAGE_TARGET := $(PRODUCT_OUT)/product.img
3964$(eval $(call copy-one-file,$(BOARD_PREBUILT_PRODUCTIMAGE),$(INSTALLED_PRODUCTIMAGE_TARGET)))
3965endif
3966
3967# -----------------------------------------------------------------
3968# system_ext partition image
3969INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT_SYSTEM_EXT)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
3970ifdef BUILDING_SYSTEM_EXT_IMAGE
3971INTERNAL_SYSTEM_EXTIMAGE_FILES := \
3972    $(filter $(TARGET_OUT_SYSTEM_EXT)/%,\
3973      $(ALL_DEFAULT_INSTALLED_MODULES))
3974
3975INSTALLED_FILES_FILE_SYSTEM_EXT := $(PRODUCT_OUT)/installed-files-system_ext.txt
3976INSTALLED_FILES_JSON_SYSTEM_EXT := $(INSTALLED_FILES_FILE_SYSTEM_EXT:.txt=.json)
3977$(INSTALLED_FILES_FILE_SYSTEM_EXT): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_SYSTEM_EXT)
3978$(INSTALLED_FILES_FILE_SYSTEM_EXT) : $(INTERNAL_SYSTEM_EXTIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
3979	@echo Installed file list: $@
3980	mkdir -p $(dir $@)
3981	rm -f $@
3982	$(FILESLIST) $(TARGET_OUT_SYSTEM_EXT) > $(@:.txt=.json)
3983	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
3984
3985$(call declare-0p-target,$(INSTALLED_FILES_FILE_SYSTEM_EXT))
3986$(call declare-0p-target,$(INSTALLED_FILES_JSON_SYSTEM_EXT))
3987
3988system_extimage_intermediates := \
3989    $(call intermediates-dir-for,PACKAGING,system_ext)
3990BUILT_SYSTEM_EXTIMAGE_TARGET := $(PRODUCT_OUT)/system_ext.img
3991define build-system_extimage-target
3992  $(call pretty,"Target system_ext fs image: $(INSTALLED_SYSTEM_EXTIMAGE_TARGET)")
3993  @mkdir -p $(TARGET_OUT_SYSTEM_EXT)
3994  @mkdir -p $(system_extimage_intermediates) && rm -rf $(system_extimage_intermediates)/system_ext_image_info.txt
3995  $(call generate-image-prop-dictionary, $(system_extimage_intermediates)/system_ext_image_info.txt,system_ext, skip_fsck=true)
3996  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
3997      $(BUILD_IMAGE) \
3998          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(system_extimage_intermediates)/file_list.txt) \
3999          $(TARGET_OUT_SYSTEM_EXT) \
4000          $(system_extimage_intermediates)/system_ext_image_info.txt \
4001          $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) \
4002          $(TARGET_OUT)
4003  $(call assert-max-image-size,$(INSTALLED_PRODUCT_SERVICESIMAGE_TARGET),$(BOARD_PRODUCT_SERVICESIMAGE_PARTITION_SIZE))
4004endef
4005
4006$(eval $(call write-partition-file-list,$(system_extimage_intermediates)/file_list.txt,$(TARGET_OUT_SYSTEM_EXT),$(INTERNAL_SYSTEM_EXTIMAGE_FILES)))
4007# Used by soong sandwich to request the staging dir be built
4008$(system_extimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT_SYSTEM_EXT)/%,$(INTERNAL_SYSTEM_EXTIMAGE_FILES))
4009	touch $@
4010
4011# We just build this directly to the install location.
4012INSTALLED_SYSTEM_EXTIMAGE_TARGET := $(BUILT_SYSTEM_EXTIMAGE_TARGET)
4013$(INSTALLED_SYSTEM_EXTIMAGE_TARGET): \
4014    $(INTERNAL_USERIMAGES_DEPS) \
4015    $(INTERNAL_SYSTEM_EXTIMAGE_FILES) \
4016    $(INSTALLED_FILES_FILE_SYSTEM_EXT) \
4017    $(system_extimage_intermediates)/file_list.txt
4018	$(build-system_extimage-target)
4019
4020SYSTEM_EXT_NOTICE_DEPS += $(INSTALLED_SYSTEM_EXTIMAGE_TARGET)
4021
4022$(call declare-1p-container,$(INSTALLED_SYSTEM_EXTIMAGE_TARGET),)
4023$(call declare-container-license-deps,$(INSTALLED_SYSTEM_EXTIMAGE_TARGET),$(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_SYSTEM_EXTIMAGE_FILES) $(INSTALLED_FILES_FILE_SYSTEM_EXT),$(PRODUCT_OUT)/:/)
4024
4025.PHONY: systemextimage-nodeps senod
4026systemextimage-nodeps senod: | $(INTERNAL_USERIMAGES_DEPS) $(system_extimage_intermediates)/file_list.txt
4027	$(build-system_extimage-target)
4028
4029.PHONY: sync_system_ext
4030sync sync_system_ext: $(INTERNAL_SYSTEM_EXTIMAGE_FILES)
4031
4032else ifdef BOARD_PREBUILT_SYSTEM_EXTIMAGE
4033INSTALLED_SYSTEM_EXTIMAGE_TARGET := $(PRODUCT_OUT)/system_ext.img
4034$(eval $(call copy-one-file,$(BOARD_PREBUILT_SYSTEM_EXTIMAGE),$(INSTALLED_SYSTEM_EXTIMAGE_TARGET)))
4035endif
4036
4037# -----------------------------------------------------------------
4038# odm partition image
4039INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT_ODM)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
4040ifdef BUILDING_ODM_IMAGE
4041INTERNAL_ODMIMAGE_FILES := \
4042    $(filter $(TARGET_OUT_ODM)/%,\
4043      $(ALL_DEFAULT_INSTALLED_MODULES))
4044
4045# Create symlinks for odm_dlkm on devices with a odm_dlkm partition:
4046# /odm/lib/modules -> /odm_dlkm/lib/modules
4047#
4048# On devices with a odm_dlkm partition,
4049# - /odm/lib/modules is a symlink to a directory that stores odm DLKMs.
4050# - /odm_dlkm/{etc,...} store other odm_dlkm files directly. The odm_dlkm partition is
4051#   mounted at /odm_dlkm at runtime and the symlinks created in system/core/rootdir/Android.mk
4052#   are hidden.
4053# On devices without a odm_dlkm partition,
4054# - /odm/lib/modules stores odm DLKMs directly.
4055# - /odm_dlkm/{etc,...} are symlinks to directories that store other odm_dlkm files.
4056#   See system/core/rootdir/Android.mk for a list of created symlinks.
4057# The odm DLKMs and other odm_dlkm files must not be accessed using other paths because they
4058# are not guaranteed to exist on all devices.
4059ifdef BOARD_USES_ODM_DLKMIMAGE
4060  _odm_dlkm_lib_modules_symlink := $(call create-partition-compat-symlink,$(TARGET_OUT_ODM)/lib/modules,/odm_dlkm/lib/modules,odm_dlkm.img)
4061  INTERNAL_ODMIMAGE_FILES += $(_odm_dlkm_lib_modules_symlink)
4062  ALL_DEFAULT_INSTALLED_MODULES += $(_odm_dlkm_lib_modules_symlink)
4063endif
4064
4065INSTALLED_FILES_FILE_ODM := $(PRODUCT_OUT)/installed-files-odm.txt
4066INSTALLED_FILES_JSON_ODM := $(INSTALLED_FILES_FILE_ODM:.txt=.json)
4067$(INSTALLED_FILES_FILE_ODM): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_ODM)
4068$(INSTALLED_FILES_FILE_ODM) : $(INTERNAL_ODMIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
4069	@echo Installed file list: $@
4070	mkdir -p $(dir $@)
4071	rm -f $@
4072	$(FILESLIST) $(TARGET_OUT_ODM) > $(@:.txt=.json)
4073	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
4074
4075$(call declare-0p-target,$(INSTALLED_FILES_FILE_ODM))
4076$(call declare-0p-target,$(INSTALLED_FILES_JSON_ODM))
4077
4078odmimage_intermediates := \
4079    $(call intermediates-dir-for,PACKAGING,odm)
4080BUILT_ODMIMAGE_TARGET := $(PRODUCT_OUT)/odm.img
4081define build-odmimage-target
4082  $(call pretty,"Target odm fs image: $(INSTALLED_ODMIMAGE_TARGET)")
4083  @mkdir -p $(TARGET_OUT_ODM)
4084  @mkdir -p $(odmimage_intermediates) && rm -rf $(odmimage_intermediates)/odm_image_info.txt
4085  $(call generate-image-prop-dictionary, $(odmimage_intermediates)/odm_image_info.txt, odm, \
4086	  skip_fsck=true)
4087  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
4088      $(BUILD_IMAGE) \
4089          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(odmimage_intermediates)/file_list.txt) \
4090          $(TARGET_OUT_ODM) $(odmimage_intermediates)/odm_image_info.txt \
4091          $(INSTALLED_ODMIMAGE_TARGET) $(TARGET_OUT)
4092  $(call assert-max-image-size,$(INSTALLED_ODMIMAGE_TARGET),$(BOARD_ODMIMAGE_PARTITION_SIZE))
4093endef
4094
4095$(eval $(call write-partition-file-list,$(odmimage_intermediates)/file_list.txt,$(TARGET_OUT_ODM),$(INTERNAL_ODMIMAGE_FILES)))
4096# Used by soong sandwich to request the staging dir be built
4097$(odmimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT_ODM)/%,$(INTERNAL_ODMIMAGE_FILES))
4098	touch $@
4099
4100# We just build this directly to the install location.
4101INSTALLED_ODMIMAGE_TARGET := $(BUILT_ODMIMAGE_TARGET)
4102$(INSTALLED_ODMIMAGE_TARGET): \
4103    $(INTERNAL_USERIMAGES_DEPS) \
4104    $(INTERNAL_ODMIMAGE_FILES) \
4105    $(INSTALLED_FILES_FILE_ODM) \
4106    $(odmimage_intermediates)/file_list.txt
4107	$(build-odmimage-target)
4108
4109ODM_NOTICE_DEPS += $(INSTALLED_ODMIMAGE_TARGET)
4110
4111$(call declare-1p-container,$(INSTALLED_ODMIMAGE_TARGET),)
4112$(call declare-container-license-deps,$(INSTALLED_ODMIMAGE_TARGET),$(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_ODMIMAGE_FILES) $(INSTALLED_FILES_FILE_ODM),$(PRODUCT_OUT)/:/)
4113
4114.PHONY: odmimage-nodeps onod
4115odmimage-nodeps onod: | $(INTERNAL_USERIMAGES_DEPS) $(odmimage_intermediates)/file_list.txt
4116	$(build-odmimage-target)
4117
4118.PHONY: sync_odm
4119sync sync_odm: $(INTERNAL_ODMIMAGE_FILES)
4120
4121else ifdef BOARD_PREBUILT_ODMIMAGE
4122INSTALLED_ODMIMAGE_TARGET := $(PRODUCT_OUT)/odm.img
4123$(eval $(call copy-one-file,$(BOARD_PREBUILT_ODMIMAGE),$(INSTALLED_ODMIMAGE_TARGET)))
4124endif
4125
4126# -----------------------------------------------------------------
4127# vendor_dlkm partition image
4128INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT_VENDOR_DLKM)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
4129ifdef BUILDING_VENDOR_DLKM_IMAGE
4130INTERNAL_VENDOR_DLKMIMAGE_FILES := \
4131    $(filter $(TARGET_OUT_VENDOR_DLKM)/%,\
4132      $(ALL_DEFAULT_INSTALLED_MODULES))
4133
4134INSTALLED_FILES_FILE_VENDOR_DLKM := $(PRODUCT_OUT)/installed-files-vendor_dlkm.txt
4135INSTALLED_FILES_JSON_VENDOR_DLKM := $(INSTALLED_FILES_FILE_VENDOR_DLKM:.txt=.json)
4136$(INSTALLED_FILES_FILE_VENDOR_DLKM): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_VENDOR_DLKM)
4137$(INSTALLED_FILES_FILE_VENDOR_DLKM) : $(INTERNAL_VENDOR_DLKMIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
4138	@echo Installed file list: $@
4139	mkdir -p $(dir $@)
4140	rm -f $@
4141	$(FILESLIST) $(TARGET_OUT_VENDOR_DLKM) > $(@:.txt=.json)
4142	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
4143
4144$(call declare-0p-target,$(INSTALLED_FILES_FILE_VENDOR_DLKM))
4145$(call declare-0p-target,$(INSTALLED_FILES_JSON_VENDOR_DLKM))
4146
4147vendor_dlkmimage_intermediates := \
4148    $(call intermediates-dir-for,PACKAGING,vendor_dlkm)
4149BUILT_VENDOR_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/vendor_dlkm.img
4150define build-vendor_dlkmimage-target
4151  $(call pretty,"Target vendor_dlkm fs image: $(INSTALLED_VENDOR_DLKMIMAGE_TARGET)")
4152  @mkdir -p $(TARGET_OUT_VENDOR_DLKM)
4153  @mkdir -p $(vendor_dlkmimage_intermediates) && rm -rf $(vendor_dlkmimage_intermediates)/vendor_dlkm_image_info.txt
4154  $(call generate-image-prop-dictionary, $(vendor_dlkmimage_intermediates)/vendor_dlkm_image_info.txt, \
4155	  vendor_dlkm, skip_fsck=true)
4156  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
4157      $(BUILD_IMAGE) \
4158          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(vendor_dlkmimage_intermediates)/file_list.txt) \
4159          $(TARGET_OUT_VENDOR_DLKM) $(vendor_dlkmimage_intermediates)/vendor_dlkm_image_info.txt \
4160          $(INSTALLED_VENDOR_DLKMIMAGE_TARGET) $(TARGET_OUT)
4161  $(call assert-max-image-size,$(INSTALLED_VENDOR_DLKMIMAGE_TARGET),$(BOARD_VENDOR_DLKMIMAGE_PARTITION_SIZE))
4162endef
4163
4164$(eval $(call write-partition-file-list,$(vendor_dlkmimage_intermediates)/file_list.txt,$(TARGET_OUT_VENDOR_DLKM),$(INTERNAL_VENDOR_DLKMIMAGE_FILES)))
4165# Used by soong sandwich to request the staging dir be built
4166$(vendor_dlkmimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT_VENDOR_DLKM)/%,$(INTERNAL_VENDOR_DLKMIMAGE_FILES))
4167	touch $@
4168
4169# We just build this directly to the install location.
4170INSTALLED_VENDOR_DLKMIMAGE_TARGET := $(BUILT_VENDOR_DLKMIMAGE_TARGET)
4171$(INSTALLED_VENDOR_DLKMIMAGE_TARGET): \
4172    $(INTERNAL_USERIMAGES_DEPS) \
4173    $(INTERNAL_VENDOR_DLKMIMAGE_FILES) \
4174    $(INSTALLED_FILES_FILE_VENDOR_DLKM) \
4175    $(vendor_dlkmimage_intermediates)/file_list.txt
4176	$(build-vendor_dlkmimage-target)
4177
4178VENDOR_DLKM_NOTICE_DEPS += $(INSTALLED_VENDOR_DLKMIMAGE_TARGET)
4179
4180$(call declare-1p-container,$(INSTALLED_VENDOR_DLKMIMAGE_TARGET),)
4181$(call declare-container-license-deps,$(INSTALLED_VENDOR_DLKMIMAGE_TARGET),$(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_VENDOR_DLKMIMAGE_FILES) $(INSTALLED_FILES_FILE_VENDOR_DLKM),$(PRODUCT_OUT)/:/)
4182
4183.PHONY: vendor_dlkmimage-nodeps vdnod
4184vendor_dlkmimage-nodeps vdnod: | $(INTERNAL_USERIMAGES_DEPS) $(vendor_dlkmimage_intermediates)/file_list.txt
4185	$(build-vendor_dlkmimage-target)
4186
4187.PHONY: sync_vendor_dlkm
4188sync sync_vendor_dlkm: $(INTERNAL_VENDOR_DLKMIMAGE_FILES)
4189
4190else ifdef BOARD_PREBUILT_VENDOR_DLKMIMAGE
4191INSTALLED_VENDOR_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/vendor_dlkm.img
4192$(eval $(call copy-one-file,$(BOARD_PREBUILT_VENDOR_DLKMIMAGE),$(INSTALLED_VENDOR_DLKMIMAGE_TARGET)))
4193endif
4194
4195# -----------------------------------------------------------------
4196# odm_dlkm partition image
4197INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT_ODM_DLKM)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
4198ifdef BUILDING_ODM_DLKM_IMAGE
4199INTERNAL_ODM_DLKMIMAGE_FILES := \
4200    $(filter $(TARGET_OUT_ODM_DLKM)/%,\
4201      $(ALL_DEFAULT_INSTALLED_MODULES))
4202
4203INSTALLED_FILES_FILE_ODM_DLKM := $(PRODUCT_OUT)/installed-files-odm_dlkm.txt
4204INSTALLED_FILES_JSON_ODM_DLKM := $(INSTALLED_FILES_FILE_ODM_DLKM:.txt=.json)
4205$(INSTALLED_FILES_FILE_ODM_DLKM): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_ODM_DLKM)
4206$(INSTALLED_FILES_FILE_ODM_DLKM) : $(INTERNAL_ODM_DLKMIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
4207	@echo Installed file list: $@
4208	mkdir -p $(dir $@)
4209	rm -f $@
4210	$(FILESLIST) $(TARGET_OUT_ODM_DLKM) > $(@:.txt=.json)
4211	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
4212
4213$(call declare-0p-target,$(INSTALLED_FILES_FILE_ODM_DLKM))
4214$(call declare-0p-target,$(INSTALLED_FILES_JSON_ODM_DLKM))
4215
4216odm_dlkmimage_intermediates := \
4217    $(call intermediates-dir-for,PACKAGING,odm_dlkm)
4218BUILT_ODM_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/odm_dlkm.img
4219define build-odm_dlkmimage-target
4220  $(call pretty,"Target odm_dlkm fs image: $(INSTALLED_ODM_DLKMIMAGE_TARGET)")
4221  @mkdir -p $(TARGET_OUT_ODM_DLKM)
4222  @mkdir -p $(odm_dlkmimage_intermediates) && rm -rf $(odm_dlkmimage_intermediates)/odm_dlkm_image_info.txt
4223  $(call generate-image-prop-dictionary, $(odm_dlkmimage_intermediates)/odm_dlkm_image_info.txt, \
4224	  odm_dlkm, skip_fsck=true)
4225  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
4226      $(BUILD_IMAGE) \
4227          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(odm_dlkmimage_intermediates)/file_list.txt) \
4228          $(TARGET_OUT_ODM_DLKM) $(odm_dlkmimage_intermediates)/odm_dlkm_image_info.txt \
4229          $(INSTALLED_ODM_DLKMIMAGE_TARGET) $(TARGET_OUT)
4230  $(call assert-max-image-size,$(INSTALLED_ODM_DLKMIMAGE_TARGET),$(BOARD_ODM_DLKMIMAGE_PARTITION_SIZE))
4231endef
4232
4233$(eval $(call write-partition-file-list,$(odm_dlkmimage_intermediates)/file_list.txt,$(TARGET_OUT_ODM_DLKM),$(INTERNAL_ODM_DLKMIMAGE_FILES)))
4234# Used by soong sandwich to request the staging dir be built
4235$(odm_dlkmimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT_ODM_DLKM)/%,$(INTERNAL_ODM_DLKMIMAGE_FILES))
4236	touch $@
4237
4238# We just build this directly to the install location.
4239INSTALLED_ODM_DLKMIMAGE_TARGET := $(BUILT_ODM_DLKMIMAGE_TARGET)
4240$(INSTALLED_ODM_DLKMIMAGE_TARGET): \
4241    $(INTERNAL_USERIMAGES_DEPS) \
4242    $(INTERNAL_ODM_DLKMIMAGE_FILES) \
4243    $(INSTALLED_FILES_FILE_ODM_DLKM) \
4244    $(odm_dlkmimage_intermediates)/file_list.txt
4245	$(build-odm_dlkmimage-target)
4246
4247ODM_DLKM_NOTICE_DEPS += $(INSTALLED_ODM_DLKMIMAGE_TARGET)
4248
4249$(call declare-1p-container,$(INSTALLED_ODM_DLKMIMAGE_TARGET),)
4250$(call declare-container-license-deps,$(INSTALLED_ODM_DLKMIMAGE_TARGET),$(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_ODM_DLKMIMAGE_FILES) $(INSTALLED_FILES_FILE_ODM_DLKM),$(PRODUCT_OUT)/:/)
4251
4252.PHONY: odm_dlkmimage-nodeps odnod
4253odm_dlkmimage-nodeps odnod: | $(INTERNAL_USERIMAGES_DEPS) $(odm_dlkmimage_intermediates)/file_list.txt
4254	$(build-odm_dlkmimage-target)
4255
4256.PHONY: sync_odm_dlkm
4257sync sync_odm_dlkm: $(INTERNAL_ODM_DLKMIMAGE_FILES)
4258
4259else ifdef BOARD_PREBUILT_ODM_DLKMIMAGE
4260INSTALLED_ODM_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/odm_dlkm.img
4261$(eval $(call copy-one-file,$(BOARD_PREBUILT_ODM_DLKMIMAGE),$(INSTALLED_ODM_DLKMIMAGE_TARGET)))
4262endif
4263
4264# -----------------------------------------------------------------
4265# system_dlkm partition image
4266
4267INSTALLED_FILES_OUTSIDE_IMAGES := $(filter-out $(TARGET_OUT_SYSTEM_DLKM)/%, $(INSTALLED_FILES_OUTSIDE_IMAGES))
4268ifdef BUILDING_SYSTEM_DLKM_IMAGE
4269
4270INTERNAL_SYSTEM_DLKMIMAGE_FILES := \
4271    $(filter $(TARGET_OUT_SYSTEM_DLKM)/%,\
4272      $(ALL_DEFAULT_INSTALLED_MODULES))
4273
4274INSTALLED_FILES_FILE_SYSTEM_DLKM := $(PRODUCT_OUT)/installed-files-system_dlkm.txt
4275INSTALLED_FILES_JSON_SYSTEM_DLKM := $(INSTALLED_FILES_FILE_SYSTEM_DLKM:.txt=.json)
4276$(INSTALLED_FILES_FILE_SYSTEM_DLKM): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_SYSTEM_DLKM)
4277$(INSTALLED_FILES_FILE_SYSTEM_DLKM): $(INTERNAL_SYSTEM_DLKMIMAGE_FILES) $(FILESLIST) $(FILESLIST_UTIL)
4278	@echo Installed file list: $@
4279	mkdir -p $(dir $@)
4280	rm -f $@
4281	$(FILESLIST) $(TARGET_OUT_SYSTEM_DLKM) > $(@:.txt=.json)
4282	$(FILESLIST_UTIL) -c $(@:.txt=.json) > $@
4283
4284$(call declare-0p-target,$(INSTALLED_FILES_FILE_SYSTEM_DLKM))
4285$(call declare-0p-target,$(INSTALLED_FILES_JSON_SYSTEM_DLKM))
4286
4287system_dlkmimage_intermediates := \
4288    $(call intermediates-dir-for,PACKAGING,system_dlkm)
4289BUILT_SYSTEM_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/system_dlkm.img
4290define build-system_dlkmimage-target
4291  $(call pretty,"Target system_dlkm fs image: $(INSTALLED_SYSTEM_DLKMIMAGE_TARGET)")
4292  @mkdir -p $(TARGET_OUT_SYSTEM_DLKM)
4293  @mkdir -p $(system_dlkmimage_intermediates) && rm -rf $(system_dlkmimage_intermediates)/system_dlkm_image_info.txt
4294  $(call generate-image-prop-dictionary, $(system_dlkmimage_intermediates)/system_dlkm_image_info.txt, \
4295	  system_dlkm, skip_fsck=true)
4296  PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH \
4297      $(BUILD_IMAGE) \
4298          $(if $(BUILD_BROKEN_INCORRECT_PARTITION_IMAGES),,--input-directory-filter-file $(system_dlkmimage_intermediates)/file_list.txt) \
4299          $(TARGET_OUT_SYSTEM_DLKM) $(system_dlkmimage_intermediates)/system_dlkm_image_info.txt \
4300          $(INSTALLED_SYSTEM_DLKMIMAGE_TARGET) $(TARGET_OUT)
4301  $(call assert-max-image-size,$(INSTALLED_SYSTEM_DLKMIMAGE_TARGET),$(BOARD_SYSTEM_DLKMIMAGE_PARTITION_SIZE))
4302endef
4303
4304$(eval $(call write-partition-file-list,$(system_dlkmimage_intermediates)/file_list.txt,$(TARGET_OUT_SYSTEM_DLKM),$(INTERNAL_SYSTEM_DLKMIMAGE_FILES)))
4305# Used by soong sandwich to request the staging dir be built
4306$(system_dlkmimage_intermediates)/staging_dir.stamp: $(filter $(TARGET_OUT_SYSTEM_DLKM)/%,$(INTERNAL_SYSTEM_DLKMIMAGE_FILES))
4307	touch $@
4308
4309# We just build this directly to the install location.
4310INSTALLED_SYSTEM_DLKMIMAGE_TARGET := $(BUILT_SYSTEM_DLKMIMAGE_TARGET)
4311$(INSTALLED_SYSTEM_DLKMIMAGE_TARGET): \
4312    $(INTERNAL_USERIMAGES_DEPS) \
4313    $(INTERNAL_SYSTEM_DLKMIMAGE_FILES) \
4314    $(INSTALLED_FILES_FILE_SYSTEM_DLKM) \
4315    $(system_dlkmimage_intermediates)/file_list.txt
4316	$(build-system_dlkmimage-target)
4317
4318SYSTEM_DLKM_NOTICE_DEPS += $(INSTALLED_SYSTEM_DLKMIMAGE_TARGET)
4319
4320$(call declare-1p-container,$(INSTALLED_SYSTEM_DLKMIMAGE_TARGET),)
4321$(call declare-container-license-deps,$(INSTALLED_SYSTEM_DLKMIMAGE_TARGET),$(INTERNAL_USERIMAGES_DEPS) $(INTERNAL_SYSTEM_DLKMIMAGE_FILES) $(INSTALLED_FILES_FILE_SYSTEM_DLKM),$(PRODUCT_OUT)/:/)
4322
4323.PHONY: system_dlkmimage-nodeps sdnod
4324system_dlkmimage-nodeps sdnod: | $(INTERNAL_USERIMAGES_DEPS) $(system_dlkmimage_intermediates)/file_list.txt
4325	$(build-system_dlkmimage-target)
4326
4327.PHONY: sync_system_dlkm
4328sync sync_system_dlkm: $(INTERNAL_SYSTEM_DLKMIMAGE_FILES)
4329
4330else ifdef BOARD_PREBUILT_SYSTEM_DLKMIMAGE
4331INSTALLED_SYSTEM_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/system_dlkm.img
4332$(eval $(call copy-one-file,$(BOARD_PREBUILT_SYSTEM_DLKMIMAGE),$(INSTALLED_SYSTEM_DLKMIMAGE_TARGET)))
4333endif
4334
4335# -----------------------------------------------------------------
4336# dtbo image
4337ifdef BOARD_PREBUILT_DTBOIMAGE
4338INSTALLED_DTBOIMAGE_TARGET := $(PRODUCT_OUT)/dtbo.img
4339
4340ifeq ($(BOARD_AVB_ENABLE),true)
4341$(INSTALLED_DTBOIMAGE_TARGET): $(BOARD_PREBUILT_DTBOIMAGE) $(AVBTOOL) $(BOARD_AVB_DTBO_KEY_PATH)
4342	cp $(BOARD_PREBUILT_DTBOIMAGE) $@
4343	chmod +w $@
4344	$(AVBTOOL) add_hash_footer \
4345	    --image $@ \
4346	    $(call get-partition-size-argument,$(BOARD_DTBOIMG_PARTITION_SIZE)) \
4347	    --partition_name dtbo $(INTERNAL_AVB_DTBO_SIGNING_ARGS) \
4348	    $(BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS)
4349
4350$(call declare-1p-container,$(INSTALLED_DTBOIMAGE_TARGET),)
4351$(call declare-container-license-deps,$(INSTALLED_DTBOIMAGE_TARGET),$(BOARD_PREBUILT_DTBOIMAGE),$(PRODUCT_OUT)/:/)
4352
4353UNMOUNTED_NOTICE_VENDOR_DEPS+= $(INSTALLED_DTBOIMAGE_TARGET)
4354else
4355$(INSTALLED_DTBOIMAGE_TARGET): $(BOARD_PREBUILT_DTBOIMAGE)
4356	cp $(BOARD_PREBUILT_DTBOIMAGE) $@
4357endif
4358
4359endif # BOARD_PREBUILT_DTBOIMAGE
4360
4361# -----------------------------------------------------------------
4362# Protected VM firmware image
4363ifeq ($(BOARD_USES_PVMFWIMAGE),true)
4364
4365.PHONY: pvmfwimage
4366pvmfwimage: $(INSTALLED_PVMFWIMAGE_TARGET)
4367
4368INSTALLED_PVMFWIMAGE_TARGET := $(PRODUCT_OUT)/pvmfw.img
4369INSTALLED_PVMFW_EMBEDDED_AVBKEY_TARGET := $(PRODUCT_OUT)/pvmfw_embedded.avbpubkey
4370INSTALLED_PVMFW_BINARY_TARGET := $(call module-target-built-files,pvmfw_bin)
4371INTERNAL_PVMFWIMAGE_FILES := $(call module-target-built-files,pvmfw_img)
4372INTERNAL_PVMFW_EMBEDDED_AVBKEY := $(call module-target-built-files,pvmfw_embedded_key_pub_bin)
4373INTERNAL_PVMFW_SYMBOL := $(TARGET_OUT_EXECUTABLES_UNSTRIPPED)/pvmfw
4374
4375$(call declare-1p-container,$(INSTALLED_PVMFWIMAGE_TARGET),)
4376$(call declare-container-license-deps,$(INSTALLED_PVMFWIMAGE_TARGET),$(INTERNAL_PVMFWIMAGE_FILES),$(PRODUCT_OUT)/:/)
4377
4378UNMOUNTED_NOTICE_VENDOR_DEPS += $(INSTALLED_PVMFWIMAGE_TARGET)
4379
4380# Place the unstripped pvmfw image to the symbols directory
4381$(INTERNAL_PVMFWIMAGE_FILES): |$(INTERNAL_PVMFW_SYMBOL)
4382
4383$(eval $(call copy-one-file,$(INTERNAL_PVMFWIMAGE_FILES),$(INSTALLED_PVMFWIMAGE_TARGET)))
4384
4385$(INSTALLED_PVMFWIMAGE_TARGET): $(INSTALLED_PVMFW_EMBEDDED_AVBKEY_TARGET)
4386
4387$(eval $(call copy-one-file,$(INTERNAL_PVMFW_EMBEDDED_AVBKEY),$(INSTALLED_PVMFW_EMBEDDED_AVBKEY_TARGET)))
4388
4389endif # BOARD_USES_PVMFWIMAGE
4390
4391# Returns a list of image targets corresponding to the given list of partitions. For example, it
4392# returns "$(INSTALLED_PRODUCTIMAGE_TARGET)" for "product", or "$(INSTALLED_SYSTEMIMAGE_TARGET)
4393# $(INSTALLED_VENDORIMAGE_TARGET)" for "system vendor".
4394# (1): list of partitions like "system", "vendor" or "system product system_ext".
4395define images-for-partitions
4396$(strip $(foreach item,$(1),\
4397  $(if $(filter $(item),system_other),$(INSTALLED_SYSTEMOTHERIMAGE_TARGET),\
4398    $(if $(filter $(item),init_boot),$(INSTALLED_INIT_BOOT_IMAGE_TARGET),\
4399      $(INSTALLED_$(call to-upper,$(item))IMAGE_TARGET)))))
4400endef
4401
4402# -----------------------------------------------------------------
4403# custom images
4404INSTALLED_CUSTOMIMAGES_TARGET :=
4405
4406ifneq ($(strip $(BOARD_CUSTOMIMAGES_PARTITION_LIST)),)
4407INTERNAL_AVB_CUSTOMIMAGES_SIGNING_ARGS :=
4408BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST :=
4409# If BOARD_AVB_$(call to-upper,$(partition))_KEY_PATH is set, the image will be included in
4410# BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST, otherwise the image won't be AVB signed.
4411$(foreach partition,$(BOARD_CUSTOMIMAGES_PARTITION_LIST), \
4412	$(if $(BOARD_AVB_$(call to-upper,$(partition))_KEY_PATH), \
4413	$(eval BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST += $(partition)) \
4414	$(eval BOARD_$(call to-upper,$(partition))_IMAGE_LIST := $(BOARD_AVB_$(call to-upper,$(partition))_IMAGE_LIST))))
4415
4416# Sign custom image.
4417# $(1): the prebuilt custom image.
4418# $(2): the mount point of the prebuilt custom image.
4419# $(3): the signed custom image target.
4420define sign_custom_image
4421$(3): $(1) $(INTERNAL_USERIMAGES_DEPS)
4422	@echo Target custom image: $(3)
4423	mkdir -p $(dir $(3))
4424	cp $(1) $(3)
4425ifeq ($(BOARD_AVB_ENABLE),true)
4426	PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$$$PATH \
4427          $(AVBTOOL) add_hashtree_footer \
4428          --image $(3) \
4429          --key $(BOARD_AVB_$(call to-upper,$(2))_KEY_PATH) \
4430          --algorithm $(BOARD_AVB_$(call to-upper,$(2))_ALGORITHM) \
4431          $(call get-partition-size-argument,$(BOARD_AVB_$(call to-upper,$(2))_PARTITION_SIZE)) \
4432          --partition_name $(2) \
4433          $(INTERNAL_AVB_CUSTOMIMAGES_SIGNING_ARGS) \
4434          $(BOARD_AVB_$(call to-upper,$(2))_ADD_HASHTREE_FOOTER_ARGS)
4435endif
4436INSTALLED_CUSTOMIMAGES_TARGET += $(3)
4437endef
4438
4439# Copy unsigned custom image.
4440# $(1): the prebuilt custom image.
4441# $(2): the signed custom image target.
4442define copy_custom_image
4443$(2): $(1) $(INTERNAL_USERIMAGES_DEPS)
4444	@echo Target custom image: $(2)
4445	mkdir -p $(dir $(2))
4446	cp $(1) $(2)
4447INSTALLED_CUSTOMIMAGES_TARGET += $(2)
4448endef
4449
4450# Add AVB custom image to droid target
4451$(foreach partition,$(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST), \
4452  $(foreach image,$(BOARD_AVB_$(call to-upper,$(partition))_IMAGE_LIST), \
4453     $(eval $(call sign_custom_image,$(image),$(partition),$(PRODUCT_OUT)/$(notdir $(image))))))
4454
4455# Add unsigned custom image to droid target
4456$(foreach partition,$(filter-out $(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST), $(BOARD_CUSTOMIMAGES_PARTITION_LIST)), \
4457  $(foreach image,$(BOARD_$(call to-upper,$(partition))_IMAGE_LIST), \
4458     $(eval $(call copy_custom_image,$(image),$(PRODUCT_OUT)/$(notdir $(image))))))
4459endif
4460
4461# -----------------------------------------------------------------
4462# vbmeta image
4463ifeq ($(BOARD_AVB_ENABLE),true)
4464
4465BUILT_VBMETAIMAGE_TARGET := $(PRODUCT_OUT)/vbmeta.img
4466AVB_CHAIN_KEY_DIR := $(TARGET_OUT_INTERMEDIATES)/avb_chain_keys
4467
4468ifdef BOARD_AVB_KEY_PATH
4469$(if $(BOARD_AVB_ALGORITHM),,$(error BOARD_AVB_ALGORITHM is not defined))
4470else
4471# If key path isn't specified, use the 4096-bit test key.
4472BOARD_AVB_ALGORITHM := SHA256_RSA4096
4473BOARD_AVB_KEY_PATH := external/avb/test/data/testkey_rsa4096.pem
4474endif
4475
4476# AVB signing for system_other.img.
4477ifdef BUILDING_SYSTEM_OTHER_IMAGE
4478ifdef BOARD_AVB_SYSTEM_OTHER_KEY_PATH
4479$(if $(BOARD_AVB_SYSTEM_OTHER_ALGORITHM),,$(error BOARD_AVB_SYSTEM_OTHER_ALGORITHM is not defined))
4480else
4481# If key path isn't specified, use the same key as BOARD_AVB_KEY_PATH.
4482BOARD_AVB_SYSTEM_OTHER_KEY_PATH := $(BOARD_AVB_KEY_PATH)
4483BOARD_AVB_SYSTEM_OTHER_ALGORITHM := $(BOARD_AVB_ALGORITHM)
4484endif
4485
4486$(INSTALLED_PRODUCT_SYSTEM_OTHER_AVBKEY_TARGET): $(AVBTOOL) $(BOARD_AVB_SYSTEM_OTHER_KEY_PATH)
4487	@echo Extracting system_other avb key: $@
4488	@rm -f $@
4489	@mkdir -p $(dir $@)
4490	$(AVBTOOL) extract_public_key --key $(BOARD_AVB_SYSTEM_OTHER_KEY_PATH) --output $@
4491
4492$(eval $(call declare-0p-target,$(INSTALLED_PRODUCT_SYSTEM_OTHER_AVBKEY_TARGET),))
4493
4494ifndef BOARD_AVB_SYSTEM_OTHER_ROLLBACK_INDEX
4495BOARD_AVB_SYSTEM_OTHER_ROLLBACK_INDEX := $(PLATFORM_SECURITY_PATCH_TIMESTAMP)
4496endif
4497
4498BOARD_AVB_SYSTEM_OTHER_ADD_HASHTREE_FOOTER_ARGS += --rollback_index $(BOARD_AVB_SYSTEM_OTHER_ROLLBACK_INDEX)
4499endif # end of AVB for BUILDING_SYSTEM_OTHER_IMAGE
4500
4501INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES := \
4502    $(BOARD_AVB_VBMETA_SYSTEM) \
4503    $(BOARD_AVB_VBMETA_VENDOR) \
4504    $(foreach partition,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS),$(BOARD_AVB_VBMETA_$(call to-upper,$(partition))))
4505
4506# Not allowing the same partition to appear in multiple groups.
4507ifneq ($(words $(sort $(INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES))),$(words $(INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES)))
4508  $(error BOARD_AVB_VBMETA_SYSTEM and BOARD_AVB_VBMETA_VENDOR cannot have duplicates)
4509endif
4510
4511# When building a standalone recovery image for non-A/B devices, recovery image must be self-signed
4512# to be verified independently, and cannot be chained into vbmeta.img. See the link below for
4513# details.
4514ifeq ($(TARGET_OTA_ALLOW_NON_AB),true)
4515ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
4516$(if $(BOARD_AVB_RECOVERY_KEY_PATH),,\
4517    $(error BOARD_AVB_RECOVERY_KEY_PATH must be defined for if non-A/B is supported. \
4518            See https://android.googlesource.com/platform/external/avb/+/master/README.md#booting-into-recovery))
4519endif
4520endif
4521
4522# Appends os version as a AVB property descriptor.
4523SYSTEM_OS_VERSION ?= $(PLATFORM_VERSION_LAST_STABLE)
4524BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS += \
4525    --prop com.android.build.system.os_version:$(SYSTEM_OS_VERSION)
4526
4527PRODUCT_OS_VERSION ?= $(PLATFORM_VERSION_LAST_STABLE)
4528BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS += \
4529    --prop com.android.build.product.os_version:$(PRODUCT_OS_VERSION)
4530
4531SYSTEM_EXT_OS_VERSION ?= $(PLATFORM_VERSION_LAST_STABLE)
4532BOARD_AVB_SYSTEM_EXT_ADD_HASHTREE_FOOTER_ARGS += \
4533    --prop com.android.build.system_ext.os_version:$(SYSTEM_EXT_OS_VERSION)
4534
4535INIT_BOOT_OS_VERSION ?= $(PLATFORM_VERSION_LAST_STABLE)
4536BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS += \
4537    --prop com.android.build.init_boot.os_version:$(INIT_BOOT_OS_VERSION)
4538
4539BOOT_OS_VERSION ?= $(PLATFORM_VERSION_LAST_STABLE)
4540BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS += \
4541    --prop com.android.build.boot.os_version:$(BOOT_OS_VERSION)
4542
4543VENDOR_OS_VERSION ?= $(PLATFORM_VERSION_LAST_STABLE)
4544BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS += \
4545    --prop com.android.build.vendor.os_version:$(VENDOR_OS_VERSION)
4546
4547ODM_OS_VERSION ?= $(PLATFORM_VERSION_LAST_STABLE)
4548BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS += \
4549    --prop com.android.build.odm.os_version:$(ODM_OS_VERSION)
4550
4551VENDOR_DLKM_OS_VERSION ?= $(PLATFORM_VERSION_LAST_STABLE)
4552BOARD_AVB_VENDOR_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
4553    --prop com.android.build.vendor_dlkm.os_version:$(VENDOR_DLKM_OS_VERSION)
4554
4555ODM_DLKM_OS_VERSION ?= $(PLATFORM_VERSION_LAST_STABLE)
4556BOARD_AVB_ODM_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
4557    --prop com.android.build.odm_dlkm.os_version:$(ODM_DLKM_OS_VERSION)
4558
4559SYSTEM_DLKM_OS_VERSION ?= $(PLATFORM_VERSION_LAST_STABLE)
4560BOARD_AVB_SYSTEM_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
4561    --prop com.android.build.system_dlkm.os_version:$(SYSTEM_DLKM_OS_VERSION)
4562
4563# Appends fingerprint and security patch level as a AVB property descriptor.
4564BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS += \
4565    --prop com.android.build.system.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
4566    --prop com.android.build.system.security_patch:$(PLATFORM_SECURITY_PATCH)
4567
4568BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS += \
4569    --prop com.android.build.product.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
4570    --prop com.android.build.product.security_patch:$(PLATFORM_SECURITY_PATCH)
4571
4572BOARD_AVB_SYSTEM_EXT_ADD_HASHTREE_FOOTER_ARGS += \
4573    --prop com.android.build.system_ext.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
4574    --prop com.android.build.system_ext.security_patch:$(PLATFORM_SECURITY_PATCH)
4575
4576BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS += \
4577    --prop com.android.build.boot.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
4578
4579BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS += \
4580    --prop com.android.build.init_boot.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
4581
4582BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS += \
4583    --prop com.android.build.vendor_boot.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
4584
4585BOARD_AVB_VENDOR_KERNEL_BOOT_ADD_HASH_FOOTER_ARGS += \
4586    --prop com.android.build.vendor_kernel_boot.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE) \
4587
4588BOARD_AVB_RECOVERY_ADD_HASH_FOOTER_ARGS += \
4589    --prop com.android.build.recovery.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
4590
4591BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS += \
4592    --prop com.android.build.vendor.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
4593
4594BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS += \
4595    --prop com.android.build.odm.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
4596
4597BOARD_AVB_VENDOR_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
4598    --prop com.android.build.vendor_dlkm.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
4599
4600BOARD_AVB_ODM_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
4601    --prop com.android.build.odm_dlkm.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
4602
4603BOARD_AVB_SYSTEM_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
4604    --prop com.android.build.system_dlkm.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
4605
4606BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS += \
4607    --prop com.android.build.dtbo.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
4608
4609BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS += \
4610    --prop com.android.build.pvmfw.fingerprint:$(BUILD_FINGERPRINT_FROM_FILE)
4611
4612# The following vendor- and odm-specific images needs explicit SPL set per board.
4613# TODO(b/210875415) Is this security_patch property used? Should it be removed from
4614# boot.img when there is no platform ramdisk included in it?
4615ifdef BOOT_SECURITY_PATCH
4616BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS += \
4617    --prop com.android.build.boot.security_patch:$(BOOT_SECURITY_PATCH)
4618endif
4619
4620ifdef INIT_BOOT_SECURITY_PATCH
4621BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS += \
4622    --prop com.android.build.init_boot.security_patch:$(INIT_BOOT_SECURITY_PATCH)
4623else ifdef BOOT_SECURITY_PATCH
4624BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS += \
4625    --prop com.android.build.init_boot.security_patch:$(BOOT_SECURITY_PATCH)
4626endif
4627
4628ifdef VENDOR_SECURITY_PATCH
4629BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS += \
4630    --prop com.android.build.vendor.security_patch:$(VENDOR_SECURITY_PATCH)
4631endif
4632
4633ifdef ODM_SECURITY_PATCH
4634BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS += \
4635    --prop com.android.build.odm.security_patch:$(ODM_SECURITY_PATCH)
4636endif
4637
4638ifdef VENDOR_DLKM_SECURITY_PATCH
4639BOARD_AVB_VENDOR_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
4640    --prop com.android.build.vendor_dlkm.security_patch:$(VENDOR_DLKM_SECURITY_PATCH)
4641endif
4642
4643ifdef ODM_DLKM_SECURITY_PATCH
4644BOARD_AVB_ODM_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
4645    --prop com.android.build.odm_dlkm.security_patch:$(ODM_DLKM_SECURITY_PATCH)
4646endif
4647
4648ifdef SYSTEM_DLKM_SECURITY_PATCH
4649BOARD_AVB_SYSTEM_DLKM_ADD_HASHTREE_FOOTER_ARGS += \
4650    --prop com.android.build.system_dlkm.security_patch:$(SYSTEM_DLKM_SECURITY_PATCH)
4651endif
4652
4653ifdef PVMFW_SECURITY_PATCH
4654BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS += \
4655    --prop com.android.build.pvmfw.security_patch:$(PVMFW_SECURITY_PATCH)
4656endif
4657
4658# Append root digest of microdroid-vendor partition's hashtree descriptor into vendor partition.
4659ifdef MICRODROID_VENDOR_IMAGE_MODULE
4660MICRODROID_VENDOR_IMAGE := \
4661    $(call intermediates-dir-for,ETC,$(MICRODROID_VENDOR_IMAGE_MODULE))/$(MICRODROID_VENDOR_IMAGE_MODULE)
4662MICRODROID_VENDOR_ROOT_DIGEST := $(PRODUCT_OUT)/microdroid_vendor_root_digest
4663BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS += \
4664    --prop_from_file com.android.build.microdroid-vendor.root_digest:$(MICRODROID_VENDOR_ROOT_DIGEST)
4665$(MICRODROID_VENDOR_ROOT_DIGEST): $(AVBTOOL) $(MICRODROID_VENDOR_IMAGE)
4666	$(AVBTOOL) print_partition_digests \
4667      --image $(MICRODROID_VENDOR_IMAGE) \
4668      | tr -d '\n' | sed -E 's/.*: //g' > $@
4669$(INSTALLED_VENDORIMAGE_TARGET): $(MICRODROID_VENDOR_ROOT_DIGEST)
4670endif
4671
4672BOOT_FOOTER_ARGS := BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS
4673INIT_BOOT_FOOTER_ARGS := BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS
4674VENDOR_BOOT_FOOTER_ARGS := BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS
4675VENDOR_KERNEL_BOOT_FOOTER_ARGS := BOARD_AVB_VENDOR_KERNEL_BOOT_ADD_HASH_FOOTER_ARGS
4676DTBO_FOOTER_ARGS := BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS
4677PVMFW_FOOTER_ARGS := BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS
4678SYSTEM_FOOTER_ARGS := BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS
4679VENDOR_FOOTER_ARGS := BOARD_AVB_VENDOR_ADD_HASHTREE_FOOTER_ARGS
4680RECOVERY_FOOTER_ARGS := BOARD_AVB_RECOVERY_ADD_HASH_FOOTER_ARGS
4681PRODUCT_FOOTER_ARGS := BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS
4682SYSTEM_EXT_FOOTER_ARGS := BOARD_AVB_SYSTEM_EXT_ADD_HASHTREE_FOOTER_ARGS
4683ODM_FOOTER_ARGS := BOARD_AVB_ODM_ADD_HASHTREE_FOOTER_ARGS
4684VENDOR_DLKM_FOOTER_ARGS := BOARD_AVB_VENDOR_DLKM_ADD_HASHTREE_FOOTER_ARGS
4685ODM_DLKM_FOOTER_ARGS := BOARD_AVB_ODM_DLKM_ADD_HASHTREE_FOOTER_ARGS
4686SYSTEM_DLKM_FOOTER_ARGS := BOARD_AVB_SYSTEM_DLKM_ADD_HASHTREE_FOOTER_ARGS
4687
4688# Helper function that checks and sets required build variables for an AVB chained partition.
4689# $(1): the partition to enable AVB chain, e.g., boot or system or vbmeta_system.
4690define _check-and-set-avb-chain-args
4691$(eval part := $(1))
4692$(eval PART=$(call to-upper,$(part)))
4693
4694$(eval _key_path := BOARD_AVB_$(PART)_KEY_PATH)
4695$(eval _signing_algorithm := BOARD_AVB_$(PART)_ALGORITHM)
4696$(eval _rollback_index := BOARD_AVB_$(PART)_ROLLBACK_INDEX)
4697$(eval _rollback_index_location := BOARD_AVB_$(PART)_ROLLBACK_INDEX_LOCATION)
4698$(if $($(_key_path)),,$(error $(_key_path) is not defined))
4699$(if $($(_signing_algorithm)),,$(error $(_signing_algorithm) is not defined))
4700$(if $($(_rollback_index)),,$(error $(_rollback_index) is not defined))
4701$(if $($(_rollback_index_location)),,$(error $(_rollback_index_location) is not defined))
4702
4703# Set INTERNAL_AVB_(PART)_SIGNING_ARGS
4704$(eval _signing_args := INTERNAL_AVB_$(PART)_SIGNING_ARGS)
4705$(eval $(_signing_args) := \
4706    --algorithm $($(_signing_algorithm)) --key $($(_key_path)))
4707
4708# The recovery partition in non-A/B devices should be verified separately. Skip adding the chain
4709# partition descriptor for recovery partition into vbmeta.img.
4710$(if $(or $(filter-out true,$(TARGET_OTA_ALLOW_NON_AB)),$(filter-out recovery,$(part))),\
4711    $(eval INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
4712        --chain_partition $(part):$($(_rollback_index_location)):$(AVB_CHAIN_KEY_DIR)/$(part).avbpubkey))
4713
4714# Set rollback_index via footer args for non-chained vbmeta image. Chained vbmeta image will pick up
4715# the index via a separate flag (e.g. BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX).
4716$(if $(filter $(part),$(part:vbmeta_%=%)),\
4717    $(eval _footer_args := $(PART)_FOOTER_ARGS) \
4718    $(eval $($(_footer_args)) += --rollback_index $($(_rollback_index))))
4719endef
4720
4721# Checks and sets the required build variables for an AVB partition. The partition will be
4722# configured as a chained partition, if BOARD_AVB_<partition>_KEY_PATH is defined. Otherwise the
4723# image descriptor will be included into vbmeta.img, unless it has been already added to any chained
4724# VBMeta image.
4725# Multiple boot images can be generated based on BOARD_KERNEL_BINARIES
4726# but vbmeta would capture the image descriptor of only the first boot
4727# image specified in BUILT_BOOTIMAGE_TARGET.
4728# $(1): Partition name, e.g. boot or system.
4729define check-and-set-avb-args
4730$(eval _in_chained_vbmeta := $(filter $(1),$(INTERNAL_AVB_PARTITIONS_IN_CHAINED_VBMETA_IMAGES)))
4731$(if $(BOARD_AVB_$(call to-upper,$(1))_KEY_PATH),\
4732    $(if $(_in_chained_vbmeta),\
4733        $(error Chaining partition "$(1)" in chained VBMeta image is not supported)) \
4734    $(call _check-and-set-avb-chain-args,$(1)),\
4735    $(if $(_in_chained_vbmeta),,\
4736        $(if $(filter boot,$(1)),\
4737            $(eval INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
4738                --include_descriptors_from_image $(firstword $(call images-for-partitions,$(1)))),\
4739            $(eval INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
4740                --include_descriptors_from_image $(call images-for-partitions,$(1))))))
4741endef
4742
4743# Checks and sets build variables for a custom chained partition to include it into vbmeta.img.
4744# $(1): the custom partition to enable AVB chain.
4745define check-and-set-custom-avb-chain-args
4746$(eval part := $(1))
4747$(eval PART=$(call to-upper,$(part)))
4748$(eval _rollback_index_location := BOARD_AVB_$(PART)_ROLLBACK_INDEX_LOCATION)
4749$(eval _key_path := BOARD_AVB_$(PART)_KEY_PATH)
4750$(if $($(_rollback_index_location)),,$(error $(_rollback_index_location) is not defined))
4751$(if $($(_key_path)),,$(error $(_key_path) is not defined))
4752
4753INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS += \
4754    --chain_partition $(part):$($(_rollback_index_location)):$(AVB_CHAIN_KEY_DIR)/$(part).avbpubkey
4755endef
4756
4757ifdef INSTALLED_BOOTIMAGE_TARGET
4758$(eval $(call check-and-set-avb-args,boot))
4759endif
4760
4761ifdef INSTALLED_INIT_BOOT_IMAGE_TARGET
4762$(eval $(call check-and-set-avb-args,init_boot))
4763endif
4764
4765ifdef INSTALLED_VENDOR_BOOTIMAGE_TARGET
4766$(eval $(call check-and-set-avb-args,vendor_boot))
4767endif
4768
4769ifdef INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET
4770$(eval $(call check-and-set-avb-args,vendor_kernel_boot))
4771endif
4772
4773ifdef INSTALLED_SYSTEMIMAGE_TARGET
4774$(eval $(call check-and-set-avb-args,system))
4775endif
4776
4777ifdef INSTALLED_VENDORIMAGE_TARGET
4778$(eval $(call check-and-set-avb-args,vendor))
4779endif
4780
4781ifdef INSTALLED_PRODUCTIMAGE_TARGET
4782$(eval $(call check-and-set-avb-args,product))
4783endif
4784
4785ifdef INSTALLED_SYSTEM_EXTIMAGE_TARGET
4786$(eval $(call check-and-set-avb-args,system_ext))
4787endif
4788
4789ifdef INSTALLED_ODMIMAGE_TARGET
4790$(eval $(call check-and-set-avb-args,odm))
4791endif
4792
4793ifdef INSTALLED_VENDOR_DLKMIMAGE_TARGET
4794$(eval $(call check-and-set-avb-args,vendor_dlkm))
4795endif
4796
4797ifdef INSTALLED_ODM_DLKMIMAGE_TARGET
4798$(eval $(call check-and-set-avb-args,odm_dlkm))
4799endif
4800
4801ifdef INSTALLED_SYSTEM_DLKMIMAGE_TARGET
4802$(eval $(call check-and-set-avb-args,system_dlkm))
4803endif
4804
4805ifdef INSTALLED_DTBOIMAGE_TARGET
4806$(eval $(call check-and-set-avb-args,dtbo))
4807endif
4808
4809ifdef INSTALLED_PVMFWIMAGE_TARGET
4810$(eval $(call check-and-set-avb-args,pvmfw))
4811endif
4812
4813ifdef INSTALLED_RECOVERYIMAGE_TARGET
4814$(eval $(call check-and-set-avb-args,recovery))
4815endif
4816
4817# Not using INSTALLED_VBMETA_SYSTEMIMAGE_TARGET as it won't be set yet.
4818ifdef BOARD_AVB_VBMETA_SYSTEM
4819$(eval $(call check-and-set-avb-args,vbmeta_system))
4820endif
4821
4822ifdef BOARD_AVB_VBMETA_VENDOR
4823$(eval $(call check-and-set-avb-args,vbmeta_vendor))
4824endif
4825
4826ifdef BOARD_AVB_VBMETA_CUSTOM_PARTITIONS
4827$(foreach partition,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS),$(eval $(call check-and-set-avb-args,vbmeta_$(partition))))
4828$(foreach partition,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS),$(eval BOARD_AVB_MAKE_VBMETA_$(call to-upper,$(partition))_IMAGE_ARGS += --padding_size 4096))
4829endif
4830
4831ifneq ($(strip $(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST)),)
4832$(foreach partition,$(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST), \
4833    $(eval $(call check-and-set-custom-avb-chain-args,$(partition))))
4834endif
4835
4836BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --padding_size 4096
4837BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS += --padding_size 4096
4838BOARD_AVB_MAKE_VBMETA_VENDOR_IMAGE_ARGS += --padding_size 4096
4839
4840ifeq (eng,$(filter eng, $(TARGET_BUILD_VARIANT)))
4841# We only need the flag in top-level vbmeta.img.
4842BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --set_hashtree_disabled_flag
4843endif
4844
4845ifdef BOARD_AVB_ROLLBACK_INDEX
4846BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --rollback_index $(BOARD_AVB_ROLLBACK_INDEX)
4847endif
4848
4849ifdef BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX
4850BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS += \
4851    --rollback_index $(BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX)
4852endif
4853
4854ifdef BOARD_AVB_VBMETA_VENDOR_ROLLBACK_INDEX
4855BOARD_AVB_MAKE_VBMETA_VENDOR_IMAGE_ARGS += \
4856    --rollback_index $(BOARD_AVB_VBMETA_VENDOR_ROLLBACK_INDEX)
4857endif
4858
4859ifdef BOARD_AVB_VBMETA_CUSTOM_PARTITIONS
4860  $(foreach partition,$(call to-upper,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS)), \
4861      $(if $(BOARD_AVB_VBMETA_$(partition)_ROLLBACK_INDEX),$(eval \
4862        BOARD_AVB_MAKE_VBMETA_$(partition)_IMAGE_ARGS += \
4863          --rollback_index $(BOARD_AVB_VBMETA_$(partition)_ROLLBACK_INDEX))))
4864endif
4865
4866# $(1): the directory to extract public keys to
4867define extract-avb-chain-public-keys
4868  $(if $(BOARD_AVB_BOOT_KEY_PATH),\
4869    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_BOOT_KEY_PATH) \
4870      --output $(1)/boot.avbpubkey)
4871  $(if $(BOARD_AVB_INIT_BOOT_KEY_PATH),\
4872    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_INIT_BOOT_KEY_PATH) \
4873      --output $(1)/init_boot.avbpubkey)
4874  $(if $(BOARD_AVB_VENDOR_BOOT_KEY_PATH),\
4875    $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VENDOR_BOOT_KEY_PATH) \
4876      --output $(1)/vendor_boot.avbpubkey)
4877  $(if $(BOARD_AVB_VENDOR_KERNEL_BOOT_KEY_PATH),\
4878    $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VENDOR_KERNEL_BOOT_KEY_PATH) \
4879      --output $(1)/vendor_kernel_boot.avbpubkey)
4880  $(if $(BOARD_AVB_SYSTEM_KEY_PATH),\
4881    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_SYSTEM_KEY_PATH) \
4882      --output $(1)/system.avbpubkey)
4883  $(if $(BOARD_AVB_VENDOR_KEY_PATH),\
4884    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VENDOR_KEY_PATH) \
4885      --output $(1)/vendor.avbpubkey)
4886  $(if $(BOARD_AVB_PRODUCT_KEY_PATH),\
4887    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_PRODUCT_KEY_PATH) \
4888      --output $(1)/product.avbpubkey)
4889  $(if $(BOARD_AVB_SYSTEM_EXT_KEY_PATH),\
4890    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_SYSTEM_EXT_KEY_PATH) \
4891      --output $(1)/system_ext.avbpubkey)
4892  $(if $(BOARD_AVB_ODM_KEY_PATH),\
4893    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_ODM_KEY_PATH) \
4894      --output $(1)/odm.avbpubkey)
4895  $(if $(BOARD_AVB_VENDOR_DLKM_KEY_PATH),\
4896    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VENDOR_DLKM_KEY_PATH) \
4897      --output $(1)/vendor_dlkm.avbpubkey)
4898  $(if $(BOARD_AVB_ODM_DLKM_KEY_PATH),\
4899    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_ODM_DLKM_KEY_PATH) \
4900      --output $(1)/odm_dlkm.avbpubkey)
4901  $(if $(BOARD_AVB_SYSTEM_DLKM_KEY_PATH),\
4902    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_SYSTEM_DLKM_KEY_PATH) \
4903      --output $(1)/system_dlkm.avbpubkey)
4904  $(if $(BOARD_AVB_DTBO_KEY_PATH),\
4905    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_DTBO_KEY_PATH) \
4906      --output $(1)/dtbo.avbpubkey)
4907  $(if $(BOARD_AVB_PVMFW_KEY_PATH),\
4908    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_PVMFW_KEY_PATH) \
4909      --output $(1)/pvmfw.avbpubkey)
4910  $(if $(BOARD_AVB_RECOVERY_KEY_PATH),\
4911    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_RECOVERY_KEY_PATH) \
4912      --output $(1)/recovery.avbpubkey)
4913  $(if $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH),\
4914    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH) \
4915        --output $(1)/vbmeta_system.avbpubkey)
4916  $(if $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH),\
4917    $(hide) $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH) \
4918        --output $(1)/vbmeta_vendor.avbpubkey)
4919  $(if $(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST),\
4920    $(hide) $(foreach partition,$(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST), \
4921        $(AVBTOOL) extract_public_key --key $(BOARD_AVB_$(call to-upper,$(partition))_KEY_PATH) \
4922            --output $(1)/$(partition).avbpubkey;))
4923  $(if $(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS),\
4924    $(hide) $(foreach partition,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS), \
4925        $(AVBTOOL) extract_public_key --key $(BOARD_AVB_VBMETA_$(call to-upper,$(partition))_KEY_PATH) \
4926            --output $(1)/vbmeta_$(partition).avbpubkey;))
4927endef
4928
4929# Builds a chained VBMeta image. This VBMeta image will contain the descriptors for the partitions
4930# specified in BOARD_AVB_VBMETA_<NAME>. The built VBMeta image will be included into the top-level
4931# vbmeta image as a chained partition. For example, if a target defines `BOARD_AVB_VBMETA_SYSTEM
4932# := system system_ext`, `vbmeta_system.img` will be created that includes the descriptors for
4933# `system.img` and `system_ext.img`. `vbmeta_system.img` itself will be included into
4934# `vbmeta.img` as a chained partition.
4935# $(1): VBMeta image name, such as "vbmeta_system", "vbmeta_vendor" etc.
4936# $(2): Output filename.
4937define build-chained-vbmeta-image
4938	$(call pretty,"Target chained vbmeta image: $@")
4939	$(hide) $(AVBTOOL) make_vbmeta_image \
4940	    $(INTERNAL_AVB_$(call to-upper,$(1))_SIGNING_ARGS) \
4941	    $(BOARD_AVB_MAKE_$(call to-upper,$(1))_IMAGE_ARGS) \
4942	    $(foreach image,$(BOARD_AVB_$(call to-upper,$(1))), \
4943	        --include_descriptors_from_image $(call images-for-partitions,$(image))) \
4944	    --output $@
4945endef
4946
4947ifdef BUILDING_SYSTEM_IMAGE
4948ifdef BOARD_AVB_VBMETA_SYSTEM
4949INSTALLED_VBMETA_SYSTEMIMAGE_TARGET := $(PRODUCT_OUT)/vbmeta_system.img
4950$(INSTALLED_VBMETA_SYSTEMIMAGE_TARGET): \
4951	    $(AVBTOOL) \
4952	    $(call images-for-partitions,$(BOARD_AVB_VBMETA_SYSTEM)) \
4953	    $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH)
4954	$(call build-chained-vbmeta-image,vbmeta_system)
4955
4956$(call declare-1p-container,$(INSTALLED_VBMETA_SYSTEMIMAGE_TARGET),)
4957
4958SYSTEM_NOTICE_DEPS += $(INSTALLED_VBMETA_SYSTEMIMAGE_TARGET)
4959endif
4960endif # BUILDING_SYSTEM_IMAGE
4961
4962ifdef BOARD_AVB_VBMETA_VENDOR
4963INSTALLED_VBMETA_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vbmeta_vendor.img
4964$(INSTALLED_VBMETA_VENDORIMAGE_TARGET): \
4965	    $(AVBTOOL) \
4966	    $(call images-for-partitions,$(BOARD_AVB_VBMETA_VENDOR)) \
4967	    $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH)
4968	$(call build-chained-vbmeta-image,vbmeta_vendor)
4969
4970$(call declare-1p-container,$(INSTALLED_VBMETA_VENDORIMAGE_TARGET),)
4971
4972UNMOUNTED_NOTICE_VENDOR_DEPS += $(INSTALLED_VBMETA_VENDORIMAGE_TARGET)
4973endif
4974
4975ifdef BOARD_AVB_VBMETA_CUSTOM_PARTITIONS
4976define declare-custom-vbmeta-target
4977INSTALLED_VBMETA_$(call to-upper,$(1))IMAGE_TARGET := $(PRODUCT_OUT)/vbmeta_$(call to-lower,$(1)).img
4978$$(INSTALLED_VBMETA_$(call to-upper,$(1))IMAGE_TARGET): \
4979	    $(AVBTOOL) \
4980	    $(call images-for-partitions,$(BOARD_AVB_VBMETA_$(call to-upper,$(1)))) \
4981	    $(BOARD_AVB_VBMETA_$(call to-upper,$(1))_KEY_PATH)
4982	$$(call build-chained-vbmeta-image,vbmeta_$(call to-lower,$(1)))
4983
4984$(call declare-1p-container,$(INSTALLED_VBMETA_$(call to-upper,$(1))IMAGE_TARGET),)
4985
4986UNMOUNTED_NOTICE_VENDOR_DEPS += $(INSTALLED_VBMETA_$(call to-upper,$(1))IMAGE_TARGET)
4987endef
4988
4989$(foreach partition,\
4990          $(call to-upper,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS)),\
4991          $(eval $(call declare-custom-vbmeta-target,$(partition))))
4992endif
4993
4994define build-vbmetaimage-target
4995  $(call pretty,"Target vbmeta image: $(INSTALLED_VBMETAIMAGE_TARGET)")
4996  $(hide) mkdir -p $(AVB_CHAIN_KEY_DIR)
4997  $(call extract-avb-chain-public-keys, $(AVB_CHAIN_KEY_DIR))
4998  $(hide) $(AVBTOOL) make_vbmeta_image \
4999    $(INTERNAL_AVB_MAKE_VBMETA_IMAGE_ARGS) \
5000    $(PRIVATE_AVB_VBMETA_SIGNING_ARGS) \
5001    $(BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS) \
5002    --output $@
5003  $(hide) rm -rf $(AVB_CHAIN_KEY_DIR)
5004endef
5005
5006ifdef BUILDING_VBMETA_IMAGE
5007INSTALLED_VBMETAIMAGE_TARGET := $(BUILT_VBMETAIMAGE_TARGET)
5008$(INSTALLED_VBMETAIMAGE_TARGET): PRIVATE_AVB_VBMETA_SIGNING_ARGS := \
5009    --algorithm $(BOARD_AVB_ALGORITHM) --key $(BOARD_AVB_KEY_PATH)
5010
5011
5012$(INSTALLED_VBMETAIMAGE_TARGET): \
5013	    $(AVBTOOL) \
5014	    $(INSTALLED_BOOTIMAGE_TARGET) \
5015	    $(INSTALLED_INIT_BOOT_IMAGE_TARGET) \
5016	    $(INSTALLED_VENDOR_BOOTIMAGE_TARGET) \
5017	    $(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET) \
5018	    $(INSTALLED_SYSTEMIMAGE_TARGET) \
5019	    $(INSTALLED_VENDORIMAGE_TARGET) \
5020	    $(INSTALLED_PRODUCTIMAGE_TARGET) \
5021	    $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) \
5022	    $(INSTALLED_ODMIMAGE_TARGET) \
5023	    $(INSTALLED_VENDOR_DLKMIMAGE_TARGET) \
5024	    $(INSTALLED_ODM_DLKMIMAGE_TARGET) \
5025	    $(INSTALLED_SYSTEM_DLKMIMAGE_TARGET) \
5026	    $(INSTALLED_DTBOIMAGE_TARGET) \
5027	    $(INSTALLED_PVMFWIMAGE_TARGET) \
5028	    $(INSTALLED_CUSTOMIMAGES_TARGET) \
5029	    $(INSTALLED_RECOVERYIMAGE_TARGET) \
5030	    $(INSTALLED_VBMETA_SYSTEMIMAGE_TARGET) \
5031	    $(INSTALLED_VBMETA_VENDORIMAGE_TARGET) \
5032      $(foreach partition,$(call to-upper,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS)),$(INSTALLED_VBMETA_$(partition)IMAGE_TARGET)) \
5033	    $(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH) \
5034	    $(BOARD_AVB_VBMETA_VENDOR_KEY_PATH) \
5035      $(foreach partition,$(call to-upper,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS)),$(BOARD_AVB_VBMETA_$(partition)_KEY_PATH)) \
5036	    $(BOARD_AVB_KEY_PATH)
5037	$(build-vbmetaimage-target)
5038
5039$(call declare-1p-container,$(INSTALLED_VBMETAIMAGE_TARGET),)
5040
5041UNMOUNTED_NOTICE_DEPS += $(INSTALLED_VBMETAIMAGE_TARGET)
5042
5043.PHONY: vbmetaimage-nodeps
5044vbmetaimage-nodeps: PRIVATE_AVB_VBMETA_SIGNING_ARGS := \
5045    --algorithm $(BOARD_AVB_ALGORITHM) --key $(BOARD_AVB_KEY_PATH)
5046vbmetaimage-nodeps:
5047	$(build-vbmetaimage-target)
5048endif # BUILDING_VBMETA_IMAGE
5049
5050endif # BOARD_AVB_ENABLE
5051
5052# List of files from all images
5053INTERNAL_ALLIMAGES_FILES := \
5054    $(FULL_SYSTEMIMAGE_DEPS) \
5055    $(INTERNAL_RAMDISK_FILES) \
5056    $(INTERNAL_USERDATAIMAGE_FILES) \
5057    $(INTERNAL_VENDORIMAGE_FILES) \
5058    $(INTERNAL_PRODUCTIMAGE_FILES) \
5059    $(INTERNAL_SYSTEM_EXTIMAGE_FILES) \
5060    $(INTERNAL_ODMIMAGE_FILES) \
5061    $(INTERNAL_VENDOR_DLKMIMAGE_FILES) \
5062    $(INTERNAL_ODM_DLKMIMAGE_FILES) \
5063    $(INTERNAL_SYSTEM_DLKMIMAGE_FILES) \
5064    $(INTERNAL_PVMFWIMAGE_FILES) \
5065
5066# -----------------------------------------------------------------
5067# Run apex_sepolicy_tests for all installed APEXes
5068
5069ifeq (,$(TARGET_BUILD_UNBUNDLED))
5070intermediate := $(call intermediates-dir-for,PACKAGING,apex_sepolicy_tests)
5071apex_dirs := \
5072  $(TARGET_OUT)/apex/% \
5073  $(TARGET_OUT_SYSTEM_EXT)/apex/% \
5074  $(TARGET_OUT_VENDOR)/apex/% \
5075  $(TARGET_OUT_PRODUCT)/apex/% \
5076
5077apex_files := $(sort $(filter $(apex_dirs), $(INTERNAL_ALLIMAGES_FILES)))
5078apex_dirs :=
5079
5080# $1: apex file
5081# $2: output file
5082define _run_apex_sepolicy_tests
5083$2: $1 \
5084    $(HOST_OUT_EXECUTABLES)/apex_sepolicy_tests \
5085    $(HOST_OUT_EXECUTABLES)/deapexer \
5086    $(HOST_OUT_EXECUTABLES)/debugfs_static
5087	@rm -rf $$@
5088	@mkdir -p $(dir $$@)
5089	$(HOST_OUT_EXECUTABLES)/apex_sepolicy_tests --all -f <($(HOST_OUT_EXECUTABLES)/deapexer --debugfs_path $(HOST_OUT_EXECUTABLES)/debugfs_static list -Z $$<)
5090	@touch $$@
5091endef
5092
5093# $1: apex file list
5094define run_apex_sepolicy_tests
5095$(foreach apex_file,$1, \
5096  $(eval passfile := $(patsubst $(PRODUCT_OUT)/%,$(intermediate)/%.pass,$(apex_file))) \
5097  $(eval $(call _run_apex_sepolicy_tests,$(apex_file),$(passfile))) \
5098  $(passfile))
5099endef
5100
5101.PHONY: run_apex_sepolicy_tests
5102run_apex_sepolicy_tests: $(call run_apex_sepolicy_tests,$(apex_files))
5103
5104droid_targets: run_apex_sepolicy_tests
5105
5106apex_files :=
5107intermediate :=
5108endif # TARGET_BUILD_UNBUNDLED
5109
5110# -----------------------------------------------------------------
5111# Check VINTF of build
5112
5113# Note: vendor_dlkm, odm_dlkm, and system_dlkm does not have VINTF files.
5114ifeq (,$(TARGET_BUILD_UNBUNDLED))
5115
5116intermediates := $(call intermediates-dir-for,PACKAGING,check_vintf_all)
5117check_vintf_all_deps :=
5118
5119# -----------------------------------------------------------------
5120# Activate APEXes for checkvintf
5121
5122apex_dirs := \
5123  $(TARGET_OUT)/apex/% \
5124  $(TARGET_OUT_PRODUCT)/apex/% \
5125  $(TARGET_OUT_SYSTEM_EXT)/apex/% \
5126  $(TARGET_OUT_VENDOR)/apex/% \
5127
5128apex_files := $(sort $(filter $(apex_dirs), $(INTERNAL_ALLIMAGES_FILES)))
5129
5130APEX_OUT := $(intermediates)/apex
5131APEX_INFO_FILE := $(APEX_OUT)/apex-info-list.xml
5132
5133# apexd_host scans/activates APEX files and writes /apex/apex-info-list.xml
5134# Note that `@echo $(PRIVATE_APEX_FILES)` line is added to trigger the rule when the APEX list is changed.
5135$(APEX_INFO_FILE): PRIVATE_APEX_FILES := $(apex_files)
5136$(APEX_INFO_FILE): $(HOST_OUT_EXECUTABLES)/apexd_host $(apex_files)
5137	@echo "Extracting apexes..."
5138	@echo $(PRIVATE_APEX_FILES) > /dev/null
5139	@rm -rf $(APEX_OUT)
5140	@mkdir -p $(APEX_OUT)
5141	$< --system_path $(TARGET_OUT) \
5142	   --system_ext_path $(TARGET_OUT_SYSTEM_EXT) \
5143	   --product_path $(TARGET_OUT_PRODUCT) \
5144	   --vendor_path $(TARGET_OUT_VENDOR) \
5145	   --apex_path $(APEX_OUT)
5146
5147apex_files :=
5148apex_dirs :=
5149
5150# The build system only writes VINTF metadata to */etc/vintf paths. Legacy paths aren't needed here
5151# because they are only used for prebuilt images.
5152# APEX files in /$partition/apex can have VINTF fragments as well.
5153check_vintf_common_srcs_patterns := \
5154  $(TARGET_OUT)/etc/vintf/% \
5155  $(TARGET_OUT_VENDOR)/etc/vintf/% \
5156  $(TARGET_OUT_ODM)/etc/vintf/% \
5157  $(TARGET_OUT_PRODUCT)/etc/vintf/% \
5158  $(TARGET_OUT_SYSTEM_EXT)/etc/vintf/% \
5159  $(apex_dirs)
5160
5161check_vintf_common_srcs := $(sort $(filter $(check_vintf_common_srcs_patterns),$(INTERNAL_ALLIMAGES_FILES)))
5162check_vintf_common_srcs_patterns :=
5163
5164check_vintf_has_system :=
5165check_vintf_has_vendor :=
5166
5167ifneq (,$(filter EMPTY_ODM_SKU_PLACEHOLDER,$(ODM_MANIFEST_SKUS)))
5168$(error EMPTY_ODM_SKU_PLACEHOLDER is an internal variable and cannot be used for ODM_MANIFEST_SKUS)
5169endif
5170ifneq (,$(filter EMPTY_VENDOR_SKU_PLACEHOLDER,$(DEVICE_MANIFEST_SKUS)))
5171$(error EMPTY_VENDOR_SKU_PLACEHOLDER is an internal variable and cannot be used for DEIVCE_MANIFEST_SKUS)
5172endif
5173
5174# -- Check system and system_ext manifests / matrices including fragments (excluding other framework manifests / matrices, e.g. product);
5175ifdef BUILDING_SYSTEM_IMAGE
5176check_vintf_system_deps := $(filter $(TARGET_OUT)/etc/vintf/% \
5177                                    $(TARGET_OUT_SYSTEM_EXT)/etc/vintf/% \
5178                                    $(TARGET_OUT)/apex/% \
5179                                    $(TARGET_OUT_SYSTEM_EXT)/apex/%, \
5180                                    $(check_vintf_common_srcs))
5181ifneq ($(check_vintf_system_deps),)
5182check_vintf_has_system := true
5183
5184check_vintf_system_log := $(intermediates)/check_vintf_system.log
5185check_vintf_all_deps += $(check_vintf_system_log)
5186$(check_vintf_system_log): $(HOST_OUT_EXECUTABLES)/checkvintf $(check_vintf_system_deps) $(APEX_INFO_FILE)
5187	@( $< --check-one --dirmap /system:$(TARGET_OUT) --dirmap /apex:$(APEX_OUT) > $@ 2>&1 ) || ( cat $@ && exit 1 )
5188$(call declare-1p-target,$(check_vintf_system_log))
5189check_vintf_system_log :=
5190
5191# -- Check framework manifest against frozen manifests for GSI targets. They need to be compatible.
5192ifneq (true, $(BUILDING_VENDOR_IMAGE))
5193    vintffm_log := $(intermediates)/vintffm.log
5194endif
5195check_vintf_all_deps += $(vintffm_log)
5196$(vintffm_log): $(HOST_OUT_EXECUTABLES)/vintffm $(check_vintf_system_deps) $(APEX_INFO_FILE)
5197	@( $< --check --dirmap /system:$(TARGET_OUT) \
5198	  --dirmap /system_ext:$(TARGET_OUT_SYSTEM_EXT) \
5199	  --dirmap /product:$(TARGET_OUT_PRODUCT) \
5200	  --dirmap /apex:$(APEX_OUT) \
5201	  $(VINTF_FRAMEWORK_MANIFEST_FROZEN_DIR) > $@ 2>&1 ) || ( cat $@ && exit 1 )
5202
5203$(call declare-1p-target,$(vintffm_log))
5204
5205endif # check_vintf_system_deps
5206check_vintf_system_deps :=
5207
5208endif # BUILDING_SYSTEM_IMAGE
5209
5210# -- Check vendor manifest / matrix including fragments (excluding other device manifests / matrices)
5211check_vintf_vendor_deps := $(filter $(TARGET_OUT_VENDOR)/etc/vintf/% \
5212                                    $(TARGET_OUT_VENDOR)/apex/%, \
5213                                    $(check_vintf_common_srcs))
5214ifneq ($(strip $(check_vintf_vendor_deps)),)
5215check_vintf_has_vendor := true
5216check_vintf_vendor_log := $(intermediates)/check_vintf_vendor.log
5217check_vintf_all_deps += $(check_vintf_vendor_log)
5218# Check vendor SKU=(empty) case when:
5219# - DEVICE_MANIFEST_FILE is not empty; OR
5220# - DEVICE_MANIFEST_FILE is empty AND DEVICE_MANIFEST_SKUS is empty (only vendor manifest fragments are used)
5221$(check_vintf_vendor_log): PRIVATE_VENDOR_SKUS := \
5222  $(if $(DEVICE_MANIFEST_FILE),EMPTY_VENDOR_SKU_PLACEHOLDER,\
5223    $(if $(DEVICE_MANIFEST_SKUS),,EMPTY_VENDOR_SKU_PLACEHOLDER)) \
5224  $(DEVICE_MANIFEST_SKUS)
5225$(check_vintf_vendor_log): $(HOST_OUT_EXECUTABLES)/checkvintf $(check_vintf_vendor_deps) $(APEX_INFO_FILE)
5226	$(foreach vendor_sku,$(PRIVATE_VENDOR_SKUS), \
5227	  ( $< --check-one --dirmap /vendor:$(TARGET_OUT_VENDOR) --dirmap /apex:$(APEX_OUT) \
5228	       --property ro.boot.product.vendor.sku=$(filter-out EMPTY_VENDOR_SKU_PLACEHOLDER,$(vendor_sku)) \
5229	       > $@ 2>&1 ) || ( cat $@ && exit 1 ); )
5230$(call declare-1p-target,$(check_vintf_vendor_log))
5231check_vintf_vendor_log :=
5232endif # check_vintf_vendor_deps
5233check_vintf_vendor_deps :=
5234
5235# -- Kernel version and configurations.
5236ifeq ($(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS),true)
5237
5238BUILT_KERNEL_CONFIGS_FILE := $(intermediates)/kernel_configs.txt
5239BUILT_KERNEL_VERSION_FILE := $(intermediates)/kernel_version.txt
5240
5241my_board_extracted_kernel :=
5242
5243# Tools for decompression that is not in PATH.
5244# Check $(EXTRACT_KERNEL) for decompression algorithms supported by the script.
5245# Algorithms that are in the script but not in this list will be found in PATH.
5246my_decompress_tools := \
5247    lz4:$(HOST_OUT_EXECUTABLES)/lz4 \
5248
5249
5250# BOARD_KERNEL_CONFIG_FILE and BOARD_KERNEL_VERSION can be used to override the values extracted
5251# from INSTALLED_KERNEL_TARGET.
5252ifdef BOARD_KERNEL_VERSION
5253$(BUILT_KERNEL_VERSION_FILE): PRIVATE_DECOMPRESS_TOOLS := $(my_decompress_tools)
5254$(BUILT_KERNEL_VERSION_FILE): $(foreach pair,$(my_decompress_tools),$(call word-colon,2,$(pair)))
5255$(BUILT_KERNEL_VERSION_FILE): $(EXTRACT_KERNEL) $(firstword $(INSTALLED_KERNEL_TARGET))
5256	KERNEL_RELEASE=`$(EXTRACT_KERNEL) --tools $(PRIVATE_DECOMPRESS_TOOLS) --input $(firstword $(INSTALLED_KERNEL_TARGET)) \
5257	  --output-release` ;\
5258  if [ "$$KERNEL_RELEASE" != '$(BOARD_KERNEL_VERSION)' ]; then \
5259    echo "Specified kernel version '$(BOARD_KERNEL_VERSION)' does not match actual kernel version '$$KERNEL_RELEASE' " ; exit 1; fi;
5260	echo '$(BOARD_KERNEL_VERSION)' > $@
5261
5262ifdef BOARD_KERNEL_CONFIG_FILE
5263$(BUILT_KERNEL_CONFIGS_FILE): $(BOARD_KERNEL_CONFIG_FILE)
5264	cp $< $@
5265
5266$(call declare-license-metadata,$(BUILT_KERNEL_CONFIGS_FILE),SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,"Kernel",kernel)
5267$(call declare-license-metadata,$(BUILT_KERNEL_VERSION_FILE),SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,"Kernel",kernel)
5268
5269my_board_extracted_kernel := true
5270endif # BOARD_KERNEL_CONFIG_FILE
5271endif # BOARD_KERNEL_VERSION
5272
5273
5274ifneq ($(my_board_extracted_kernel),true)
5275ifdef INSTALLED_KERNEL_TARGET
5276ifndef BOARD_KERNEL_VERSION
5277$(BUILT_KERNEL_CONFIGS_FILE): .KATI_IMPLICIT_OUTPUTS := $(BUILT_KERNEL_VERSION_FILE)
5278endif
5279$(BUILT_KERNEL_CONFIGS_FILE): PRIVATE_DECOMPRESS_TOOLS := $(my_decompress_tools)
5280$(BUILT_KERNEL_CONFIGS_FILE): $(foreach pair,$(my_decompress_tools),$(call word-colon,2,$(pair)))
5281$(BUILT_KERNEL_CONFIGS_FILE): $(EXTRACT_KERNEL) $(firstword $(INSTALLED_KERNEL_TARGET))
5282	$< --tools $(PRIVATE_DECOMPRESS_TOOLS) --input $(firstword $(INSTALLED_KERNEL_TARGET)) \
5283	  --output-configs $@ \
5284	  $(if $(BOARD_KERNEL_VERSION),,--output-release $(BUILT_KERNEL_VERSION_FILE))
5285
5286$(call declare-license-metadata,$(BUILT_KERNEL_CONFIGS_FILE),SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,"Kernel",kernel)
5287
5288my_board_extracted_kernel := true
5289endif # INSTALLED_KERNEL_TARGET
5290endif # my_board_extracted_kernel
5291
5292ifneq ($(my_board_extracted_kernel),true)
5293ifdef INSTALLED_BOOTIMAGE_TARGET
5294$(BUILT_KERNEL_CONFIGS_FILE): .KATI_IMPLICIT_OUTPUTS := $(BUILT_KERNEL_VERSION_FILE)
5295$(BUILT_KERNEL_CONFIGS_FILE): PRIVATE_DECOMPRESS_TOOLS := $(my_decompress_tools)
5296$(BUILT_KERNEL_CONFIGS_FILE): $(foreach pair,$(my_decompress_tools),$(call word-colon,2,$(pair)))
5297$(BUILT_KERNEL_CONFIGS_FILE): PRIVATE_UNPACKED_BOOTIMG := $(intermediates)/unpacked_bootimage
5298$(BUILT_KERNEL_CONFIGS_FILE): \
5299        $(HOST_OUT_EXECUTABLES)/unpack_bootimg \
5300        $(EXTRACT_KERNEL) \
5301        $(INSTALLED_BOOTIMAGE_TARGET)
5302	$(HOST_OUT_EXECUTABLES)/unpack_bootimg --boot_img $(INSTALLED_BOOTIMAGE_TARGET) --out $(PRIVATE_UNPACKED_BOOTIMG)
5303	$(EXTRACT_KERNEL) --tools $(PRIVATE_DECOMPRESS_TOOLS) --input $(PRIVATE_UNPACKED_BOOTIMG)/kernel \
5304	  --output-configs $@ \
5305	  --output-release $(BUILT_KERNEL_VERSION_FILE)
5306
5307$(call declare-license-metadata,$(BUILT_KERNEL_CONFIGS_FILE),SPDX-license-identifier-GPL-2.0-only,restricted,$(BUILD_SYSTEM)/LINUX_KERNEL_COPYING,"Kernel",kernel)
5308
5309my_board_extracted_kernel := true
5310endif # INSTALLED_BOOTIMAGE_TARGET
5311endif # my_board_extracted_kernel
5312
5313ifeq ($(my_board_extracted_kernel),true)
5314$(call dist-for-goals, droid_targets, $(BUILT_KERNEL_VERSION_FILE))
5315else
5316$(warning Neither INSTALLED_KERNEL_TARGET nor INSTALLED_BOOTIMAGE_TARGET is defined when \
5317    PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS  is true. Information about the updated kernel \
5318    cannot be built into OTA update package. You can fix this by: \
5319    (1) setting TARGET_NO_KERNEL to false and installing the built kernel to $(PRODUCT_OUT)/kernel,\
5320        so that kernel information will be extracted from the built kernel; or \
5321    (2) Add a prebuilt boot image and specify it in BOARD_PREBUILT_BOOTIMAGE; or \
5322    (3) extracting kernel configuration and defining BOARD_KERNEL_CONFIG_FILE and \
5323        BOARD_KERNEL_VERSION manually; or \
5324    (4) unsetting PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS manually.)
5325# Clear their values to indicate that these two files does not exist.
5326BUILT_KERNEL_CONFIGS_FILE :=
5327BUILT_KERNEL_VERSION_FILE :=
5328endif
5329
5330my_decompress_tools :=
5331my_board_extracted_kernel :=
5332
5333endif # PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS
5334
5335ifeq (default,$(ENABLE_UFFD_GC))
5336
5337ifneq (,$(BUILT_KERNEL_VERSION_FILE))
5338$(BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC): $(BUILT_KERNEL_VERSION_FILE)
5339$(BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC):
5340	cp $(BUILT_KERNEL_VERSION_FILE) $(BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC)
5341else
5342# We make this a warning rather than an error to avoid breaking too many builds. When it happens,
5343# we use a placeholder as the kernel version, which is consumed by uffd_gc_utils.py.
5344$(BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC):
5345	echo $$'\
5346Unable to determine UFFD GC flag because the kernel version is not available and\n\
5347PRODUCT_ENABLE_UFFD_GC is "default".\n\
5348You can fix this by:\n\
5349  1. [Recommended] Making the kernel version available.\n\
5350    (1). Set PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS to "true".\n\
5351    (2). If you are still getting this message after doing so, see the warning about\n\
5352         PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS in the build logs.\n\
5353  or\n\
5354  2. Explicitly setting PRODUCT_ENABLE_UFFD_GC to "true" or "false" based on the kernel version.\n\
5355    (1). Set PRODUCT_ENABLE_UFFD_GC to "true" if the kernel is a GKI kernel and is android12-5.4\n\
5356         or above, or a non-GKI kernel that supports userfaultfd(2) and MREMAP_DONTUNMAP.\n\
5357    (2). Set PRODUCT_ENABLE_UFFD_GC to "false" otherwise.'\
5358	  && echo '<unknown-kernel>' > $@
5359endif # BUILT_KERNEL_VERSION_FILE
5360
5361endif # ENABLE_UFFD_GC == "default"
5362
5363# -- Check VINTF compatibility of build.
5364# Skip partial builds; only check full builds. Only check if:
5365# - PRODUCT_ENFORCE_VINTF_MANIFEST is true
5366# - system / vendor VINTF metadata exists
5367# - Building product / system_ext / odm images if board has product / system_ext / odm images
5368ifeq ($(PRODUCT_ENFORCE_VINTF_MANIFEST),true)
5369ifeq ($(check_vintf_has_system),true)
5370ifeq ($(check_vintf_has_vendor),true)
5371ifeq ($(filter true,$(BUILDING_ODM_IMAGE)),$(filter true,$(BOARD_USES_ODMIMAGE)))
5372ifeq ($(filter true,$(BUILDING_PRODUCT_IMAGE)),$(filter true,$(BOARD_USES_PRODUCTIMAGE)))
5373ifeq ($(filter true,$(BUILDING_SYSTEM_EXT_IMAGE)),$(filter true,$(BOARD_USES_SYSTEM_EXTIMAGE)))
5374
5375check_vintf_compatible_log := $(intermediates)/check_vintf_compatible.log
5376check_vintf_all_deps += $(check_vintf_compatible_log)
5377
5378check_vintf_compatible_args :=
5379check_vintf_compatible_deps := $(check_vintf_common_srcs) $(APEX_INFO_FILE)
5380
5381ifeq ($(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS),true)
5382ifneq (,$(BUILT_KERNEL_VERSION_FILE)$(BUILT_KERNEL_CONFIGS_FILE))
5383check_vintf_compatible_args += --kernel $(BUILT_KERNEL_VERSION_FILE):$(BUILT_KERNEL_CONFIGS_FILE)
5384check_vintf_compatible_deps += $(BUILT_KERNEL_CONFIGS_FILE) $(BUILT_KERNEL_VERSION_FILE)
5385endif # BUILT_KERNEL_VERSION_FILE != "" || BUILT_KERNEL_CONFIGS_FILE != ""
5386endif # PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS
5387
5388check_vintf_compatible_args += \
5389  --dirmap /system:$(TARGET_OUT) \
5390  --dirmap /vendor:$(TARGET_OUT_VENDOR) \
5391  --dirmap /odm:$(TARGET_OUT_ODM) \
5392  --dirmap /product:$(TARGET_OUT_PRODUCT) \
5393  --dirmap /system_ext:$(TARGET_OUT_SYSTEM_EXT) \
5394  --dirmap /apex:$(APEX_OUT) \
5395
5396ifdef PRODUCT_SHIPPING_API_LEVEL
5397check_vintf_compatible_args += --property ro.product.first_api_level=$(PRODUCT_SHIPPING_API_LEVEL)
5398endif # PRODUCT_SHIPPING_API_LEVEL
5399
5400$(check_vintf_compatible_log): PRIVATE_CHECK_VINTF_ARGS := $(check_vintf_compatible_args)
5401$(check_vintf_compatible_log): PRIVATE_CHECK_VINTF_DEPS := $(check_vintf_compatible_deps)
5402# Check ODM SKU=(empty) case when:
5403# - ODM_MANIFEST_FILES is not empty; OR
5404# - ODM_MANIFEST_FILES is empty AND ODM_MANIFEST_SKUS is empty (only ODM manifest fragments are used)
5405$(check_vintf_compatible_log): PRIVATE_ODM_SKUS := \
5406  $(if $(ODM_MANIFEST_FILES),EMPTY_ODM_SKU_PLACEHOLDER,\
5407    $(if $(ODM_MANIFEST_SKUS),,EMPTY_ODM_SKU_PLACEHOLDER)) \
5408  $(ODM_MANIFEST_SKUS)
5409# Check vendor SKU=(empty) case when:
5410# - DEVICE_MANIFEST_FILE is not empty; OR
5411# - DEVICE_MANIFEST_FILE is empty AND DEVICE_MANIFEST_SKUS is empty (only vendor manifest fragments are used)
5412$(check_vintf_compatible_log): PRIVATE_VENDOR_SKUS := \
5413  $(if $(DEVICE_MANIFEST_FILE),EMPTY_VENDOR_SKU_PLACEHOLDER,\
5414    $(if $(DEVICE_MANIFEST_SKUS),,EMPTY_VENDOR_SKU_PLACEHOLDER)) \
5415  $(DEVICE_MANIFEST_SKUS)
5416$(check_vintf_compatible_log): $(HOST_OUT_EXECUTABLES)/checkvintf $(check_vintf_compatible_deps)
5417	@echo "PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS=$(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS)" > $@
5418	@echo -n -e 'Deps: \n  ' >> $@
5419	@sed 's/ /\n  /g' <<< "$(PRIVATE_CHECK_VINTF_DEPS)" >> $@
5420	@echo -n -e 'Args: \n  ' >> $@
5421	@cat <<< "$(PRIVATE_CHECK_VINTF_ARGS)" >> $@
5422	$(foreach odm_sku,$(PRIVATE_ODM_SKUS), $(foreach vendor_sku,$(PRIVATE_VENDOR_SKUS), \
5423	  echo "For ODM SKU = $(odm_sku), vendor SKU = $(vendor_sku)" >> $@; \
5424	  ( $< --check-compat $(PRIVATE_CHECK_VINTF_ARGS) \
5425	       --property ro.boot.product.hardware.sku=$(filter-out EMPTY_ODM_SKU_PLACEHOLDER,$(odm_sku)) \
5426	       --property ro.boot.product.vendor.sku=$(filter-out EMPTY_VENDOR_SKU_PLACEHOLDER,$(vendor_sku)) \
5427	       >> $@ 2>&1 ) || (cat $@ && exit 1); ))
5428
5429$(call declare-1p-target,$(check_vintf_compatible_log))
5430
5431check_vintf_compatible_log :=
5432check_vintf_compatible_args :=
5433check_vintf_compatible_deps :=
5434
5435endif # BUILDING_SYSTEM_EXT_IMAGE equals BOARD_USES_SYSTEM_EXTIMAGE
5436endif # BUILDING_PRODUCT_IMAGE equals BOARD_USES_PRODUCTIMAGE
5437endif # BUILDING_ODM_IMAGE equals BOARD_USES_ODMIMAGE
5438endif # check_vintf_has_vendor
5439endif # check_vintf_has_system
5440endif # PRODUCT_ENFORCE_VINTF_MANIFEST
5441
5442# Add all logs of VINTF checks to dist builds
5443droid_targets: $(check_vintf_all_deps)
5444$(call dist-for-goals, droid_targets, $(check_vintf_all_deps))
5445
5446# Helper alias to check all VINTF of current build.
5447.PHONY: check-vintf-all
5448check-vintf-all: $(check_vintf_all_deps)
5449	$(foreach file,$^,echo "$(file)"; cat "$(file)"; echo;)
5450
5451check_vintf_has_vendor :=
5452check_vintf_has_system :=
5453check_vintf_common_srcs :=
5454check_vintf_all_deps :=
5455intermediates :=
5456endif # !TARGET_BUILD_UNBUNDLED
5457
5458# -----------------------------------------------------------------
5459# Check image sizes <= size of super partition
5460
5461ifeq (,$(TARGET_BUILD_UNBUNDLED))
5462
5463ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
5464
5465PARTITIONS_AND_OTHER_IN_SUPER := $(BOARD_SUPER_PARTITION_PARTITION_LIST)
5466
5467# Add the system other image to the misc_info. Because factory ota may install system_other to the super partition.
5468ifdef BUILDING_SYSTEM_OTHER_IMAGE
5469PARTITIONS_AND_OTHER_IN_SUPER += system_other
5470endif # BUILDING_SYSTEM_OTHER_IMAGE
5471
5472# $(1): misc_info.txt
5473# #(2): optional log file
5474define check-all-partition-sizes-target
5475  mkdir -p $(dir $(1))
5476  rm -f $(1)
5477  $(call dump-super-image-info, $(1))
5478  $(foreach partition,$(PARTITIONS_AND_OTHER_IN_SUPER), \
5479    echo "$(partition)_image="$(call images-for-partitions,$(partition)) >> $(1);)
5480  $(CHECK_PARTITION_SIZES) $(if $(2),--logfile $(2),-v) $(1)
5481endef
5482
5483check_all_partition_sizes_log := $(call intermediates-dir-for,PACKAGING,check-all-partition-sizes)/check_all_partition_sizes.log
5484droid_targets: $(check_all_partition_sizes_log)
5485$(call dist-for-goals, droid_targets, $(check_all_partition_sizes_log))
5486
5487$(check_all_partition_sizes_log): \
5488    $(CHECK_PARTITION_SIZES) \
5489    $(call images-for-partitions,$(PARTITIONS_AND_OTHER_IN_SUPER))
5490	$(call check-all-partition-sizes-target, \
5491	  $(call intermediates-dir-for,PACKAGING,check-all-partition-sizes)/misc_info.txt, \
5492	  $@)
5493
5494$(call declare-1p-target,$(check_all_partition_sizes_log))
5495
5496.PHONY: check-all-partition-sizes
5497check-all-partition-sizes: $(check_all_partition_sizes_log)
5498
5499.PHONY: check-all-partition-sizes-nodeps
5500check-all-partition-sizes-nodeps:
5501	$(call check-all-partition-sizes-target, \
5502	  $(call intermediates-dir-for,PACKAGING,check-all-partition-sizes-nodeps)/misc_info.txt)
5503
5504endif # PRODUCT_BUILD_SUPER_PARTITION
5505
5506endif # !TARGET_BUILD_UNBUNDLED
5507
5508# -----------------------------------------------------------------
5509# bring in the installer image generation defines if necessary
5510ifeq ($(TARGET_USE_DISKINSTALLER),true)
5511include bootable/diskinstaller/config.mk
5512endif
5513
5514# -----------------------------------------------------------------
5515# host tools needed to build dist and OTA packages
5516
5517ifeq ($(BUILD_OS),darwin)
5518  build_ota_package := false
5519  build_otatools_package := false
5520else
5521  # Set build_ota_package, and allow opt-out below.
5522  build_ota_package := true
5523  ifeq ($(TARGET_SKIP_OTA_PACKAGE),true)
5524    build_ota_package := false
5525  endif
5526  ifneq (,$(filter address, $(SANITIZE_TARGET)))
5527    build_ota_package := false
5528  endif
5529  ifeq ($(TARGET_PRODUCT),sdk)
5530    build_ota_package := false
5531  endif
5532  # A target without a kernel may be one of the following:
5533  # - A generic target. In this case, the OTA package usually isn't built.
5534  #   PRODUCT_BUILD_GENERIC_OTA_PACKAGE may be set to true to force OTA package
5535  #   generation.
5536  # - A real device target, with TARGET_NO_KERNEL set to true and
5537  #   BOARD_PREBUILT_BOOTIMAGE set. In this case, it is valid to generate
5538  #   an OTA package.
5539  ifneq ($(PRODUCT_BUILD_GENERIC_OTA_PACKAGE),true)
5540    ifneq ($(filter generic%,$(TARGET_DEVICE)),)
5541      build_ota_package := false
5542    endif
5543    ifeq ($(INSTALLED_BOOTIMAGE_TARGET),)
5544      ifeq ($(TARGET_NO_KERNEL),true)
5545        build_ota_package := false
5546      endif
5547    endif # INSTALLED_BOOTIMAGE_TARGET == ""
5548    ifeq ($(recovery_fstab),)
5549      build_ota_package := false
5550    endif
5551  endif # PRODUCT_BUILD_GENERIC_OTA_PACKAGE
5552
5553  # Set build_otatools_package, and allow opt-out below.
5554  build_otatools_package := true
5555  ifeq ($(TARGET_SKIP_OTATOOLS_PACKAGE),true)
5556    build_otatools_package := false
5557  endif
5558endif
5559
5560ifeq ($(build_otatools_package),true)
5561
5562INTERNAL_OTATOOLS_MODULES := \
5563  aapt2 \
5564  add_img_to_target_files \
5565  apksigner \
5566  append2simg \
5567  avbtool \
5568  blk_alloc_to_base_fs \
5569  boot_signer \
5570  brillo_update_payload \
5571  brotli \
5572  bsdiff \
5573  build_image \
5574  build_super_image \
5575  build_verity_metadata \
5576  build_verity_tree \
5577  care_map_generator \
5578  check_ota_package_signature \
5579  check_target_files_signatures \
5580  check_target_files_vintf \
5581  checkvintf \
5582  create_brick_ota \
5583  delta_generator \
5584  e2fsck \
5585  e2fsdroid \
5586  fc_sort \
5587  fec \
5588  fsck.erofs \
5589  fsck.f2fs \
5590  fs_config \
5591  generate_verity_key \
5592  host_init_verifier \
5593  img2simg \
5594  img_from_target_files \
5595  imgdiff \
5596  initrd_bootconfig \
5597  libconscrypt_openjdk_jni \
5598  lpmake \
5599  lpunpack \
5600  lz4 \
5601  make_f2fs \
5602  make_f2fs_casefold \
5603  merge_ota \
5604  merge_target_files \
5605  mk_combined_img \
5606  mkbootfs \
5607  mkbootimg \
5608  mke2fs \
5609  mke2fs.conf \
5610  mkfs.erofs \
5611  mkf2fsuserimg \
5612  mksquashfs \
5613  mksquashfsimage \
5614  mkuserimg_mke2fs \
5615  ota_extractor \
5616  ota_from_target_files \
5617  repack_bootimg \
5618  secilc \
5619  sefcontext_compile \
5620  sgdisk \
5621  shflags \
5622  sign_apex \
5623  sign_target_files_apks \
5624  sign_virt_apex \
5625  signapk \
5626  simg2img \
5627  sload_f2fs \
5628  toybox \
5629  tune2fs \
5630  unpack_bootimg \
5631  update_device \
5632  update_host_simulator \
5633  validate_target_files \
5634  verity_signer \
5635  verity_verifier \
5636  zipalign \
5637  zucchini \
5638  zip2zip \
5639
5640
5641# Additional tools to unpack and repack the apex file.
5642INTERNAL_OTATOOLS_MODULES += \
5643  apexd_host \
5644  apexer \
5645  apex_compression_tool \
5646  deapexer \
5647  debugfs_static \
5648  fsck.erofs \
5649  make_erofs \
5650  merge_zips \
5651  resize2fs \
5652  soong_zip \
5653
5654ifeq (true,$(PRODUCT_SUPPORTS_VBOOT))
5655INTERNAL_OTATOOLS_MODULES += \
5656  futility-host \
5657  vboot_signer
5658endif
5659
5660INTERNAL_OTATOOLS_FILES := \
5661  $(filter $(HOST_OUT)/%,$(call module-installed-files,$(INTERNAL_OTATOOLS_MODULES)))
5662
5663.PHONY: otatools
5664otatools: $(INTERNAL_OTATOOLS_FILES)
5665
5666# For each module, recursively resolve its host shared library dependencies. Then we have a full
5667# list of modules whose installed files need to be packed.
5668INTERNAL_OTATOOLS_MODULES_WITH_DEPS := \
5669  $(sort $(INTERNAL_OTATOOLS_MODULES) \
5670      $(foreach m,$(INTERNAL_OTATOOLS_MODULES),$(call get-all-shared-libs-deps,$(m))))
5671
5672INTERNAL_OTATOOLS_PACKAGE_FILES := \
5673  $(filter $(HOST_OUT)/%,$(call module-installed-files,$(INTERNAL_OTATOOLS_MODULES_WITH_DEPS)))
5674
5675INTERNAL_OTATOOLS_PACKAGE_FILES += \
5676  $(sort $(shell find build/make/target/product/security -type f -name "*.x509.pem" -o \
5677      -name "*.pk8"))
5678
5679ifneq (,$(wildcard packages/modules))
5680INTERNAL_OTATOOLS_PACKAGE_FILES += \
5681  $(sort $(shell find packages/modules -type f -name "*.x509.pem" -o -name "*.pk8" -o -name \
5682      "key.pem"))
5683endif
5684
5685ifneq (,$(wildcard device))
5686INTERNAL_OTATOOLS_PACKAGE_FILES += \
5687  $(sort $(shell find device $(wildcard vendor) -type f -name "*.pk8" -o -name "verifiedboot*" -o \
5688      -name "*.pem" -o -name "oem*.prop" -o -name "*.avbpubkey"))
5689endif
5690ifneq (,$(wildcard external/avb))
5691INTERNAL_OTATOOLS_PACKAGE_FILES += \
5692  $(sort $(shell find external/avb/test/data -type f -name "testkey_*.pem" -o \
5693      -name "atx_metadata.bin"))
5694endif
5695ifeq (true,$(PRODUCT_SUPPORTS_VBOOT))
5696INTERNAL_OTATOOLS_PACKAGE_FILES += \
5697  $(sort $(shell find external/vboot_reference/tests/devkeys -type f))
5698endif
5699
5700INTERNAL_OTATOOLS_RELEASETOOLS := \
5701  $(shell find build/make/tools/releasetools -name "*.pyc" -prune -o \
5702      \( -type f -o -type l \) -print | sort)
5703
5704BUILT_OTATOOLS_PACKAGE := $(PRODUCT_OUT)/otatools.zip
5705$(BUILT_OTATOOLS_PACKAGE): PRIVATE_ZIP_ROOT := $(call intermediates-dir-for,PACKAGING,otatools)/otatools
5706$(BUILT_OTATOOLS_PACKAGE): PRIVATE_OTATOOLS_PACKAGE_FILES := $(INTERNAL_OTATOOLS_PACKAGE_FILES)
5707$(BUILT_OTATOOLS_PACKAGE): PRIVATE_OTATOOLS_RELEASETOOLS := $(INTERNAL_OTATOOLS_RELEASETOOLS)
5708$(BUILT_OTATOOLS_PACKAGE): $(INTERNAL_OTATOOLS_PACKAGE_FILES) $(INTERNAL_OTATOOLS_RELEASETOOLS)
5709$(BUILT_OTATOOLS_PACKAGE): $(SOONG_ZIP) $(ZIP2ZIP)
5710	@echo "Package OTA tools: $@"
5711	rm -rf $@ $(PRIVATE_ZIP_ROOT)
5712	mkdir -p $(dir $@)
5713	$(call copy-files-with-structure,$(PRIVATE_OTATOOLS_PACKAGE_FILES),$(HOST_OUT)/,$(PRIVATE_ZIP_ROOT))
5714	$(call copy-files-with-structure,$(PRIVATE_OTATOOLS_RELEASETOOLS),build/make/tools/,$(PRIVATE_ZIP_ROOT))
5715	cp $(SOONG_ZIP) $(ZIP2ZIP) $(MERGE_ZIPS) $(PRIVATE_ZIP_ROOT)/bin/
5716	$(SOONG_ZIP) -o $@ -C $(PRIVATE_ZIP_ROOT) -D $(PRIVATE_ZIP_ROOT)
5717
5718$(call declare-1p-container,$(BUILT_OTATOOLS_PACKAGE),build)
5719$(call declare-container-license-deps,$(INTERNAL_OTATOOLS_PACKAGE_FILES) $(INTERNAL_OTATOOLS_RELEASETOOLS),$(BUILT_OTATOOLS_PACKAGE):)
5720
5721.PHONY: otatools-package
5722otatools-package: $(BUILT_OTATOOLS_PACKAGE)
5723
5724$(call dist-for-goals, otatools-package, \
5725  $(BUILT_OTATOOLS_PACKAGE) \
5726)
5727
5728endif # build_otatools_package
5729
5730# -----------------------------------------------------------------
5731#  fastboot-info.txt
5732FASTBOOT_INFO_VERSION = 1
5733
5734INSTALLED_FASTBOOT_INFO_TARGET := $(PRODUCT_OUT)/fastboot-info.txt
5735ifdef TARGET_BOARD_FASTBOOT_INFO_FILE
5736$(INSTALLED_FASTBOOT_INFO_TARGET): $(TARGET_BOARD_FASTBOOT_INFO_FILE)
5737	rm -f $@
5738	$(call pretty,"Target fastboot-info.txt: $@")
5739	$(hide) cp $< $@
5740else
5741$(INSTALLED_FASTBOOT_INFO_TARGET):
5742	rm -f $@
5743	$(call pretty,"Target fastboot-info.txt: $@")
5744	$(hide) echo "# fastboot-info for $(TARGET_PRODUCT)" >> $@
5745	$(hide) echo "version $(FASTBOOT_INFO_VERSION)" >> $@
5746ifneq ($(INSTALLED_BOOTIMAGE_TARGET),)
5747	$(hide) echo "flash boot" >> $@
5748endif
5749ifneq ($(INSTALLED_INIT_BOOT_IMAGE_TARGET),)
5750	$(hide) echo "flash init_boot" >> $@
5751endif
5752ifdef BOARD_PREBUILT_DTBOIMAGE
5753	$(hide) echo "flash dtbo" >> $@
5754endif
5755ifneq ($(INSTALLED_DTIMAGE_TARGET),)
5756	$(hide) echo "flash dts dt.img" >> $@
5757endif
5758ifneq ($(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET),)
5759	$(hide) echo "flash vendor_kernel_boot" >> $@
5760endif
5761ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
5762	$(hide) echo "flash recovery" >> $@
5763endif
5764ifeq ($(BOARD_USES_PVMFWIMAGE),true)
5765	$(hide) echo "flash pvmfw" >> $@
5766endif
5767ifneq ($(INSTALLED_VENDOR_BOOTIMAGE_TARGET),)
5768	$(hide) echo "flash vendor_boot" >> $@
5769endif
5770ifeq ($(BOARD_AVB_ENABLE),true)
5771ifeq ($(BUILDING_VBMETA_IMAGE),true)
5772	$(hide) echo "flash --apply-vbmeta vbmeta" >> $@
5773endif
5774ifneq (,$(strip $(BOARD_AVB_VBMETA_SYSTEM)))
5775	$(hide) echo "flash vbmeta_system" >> $@
5776endif
5777ifneq (,$(strip $(BOARD_AVB_VBMETA_VENDOR)))
5778	$(hide) echo "flash vbmeta_vendor" >> $@
5779endif
5780ifneq (,$(strip $(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS)))
5781	$(hide) $(foreach partition,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS), \
5782	  echo "flash vbmeta_$(partition)" >> $@;)
5783endif
5784endif # BOARD_AVB_ENABLE
5785ifneq (,$(strip $(BOARD_CUSTOMIMAGES_PARTITION_LIST)))
5786	$(hide) $(foreach partition,$(BOARD_CUSTOMIMAGES_PARTITION_LIST), \
5787	  echo "flash $(partition)" >> $@;)
5788endif
5789	$(hide) echo "reboot fastboot" >> $@
5790	$(hide) echo "update-super" >> $@
5791	$(hide) $(foreach partition,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
5792	  echo "flash $(partition)" >> $@;)
5793ifdef BUILDING_SYSTEM_OTHER_IMAGE
5794	$(hide) echo "flash --slot-other system system_other.img" >> $@
5795endif
5796ifdef BUILDING_CACHE_IMAGE
5797	$(hide) echo "if-wipe erase cache" >> $@
5798endif
5799	$(hide) echo "if-wipe erase userdata" >> $@
5800ifeq ($(BOARD_USES_METADATA_PARTITION),true)
5801	$(hide) echo "if-wipe erase metadata" >> $@
5802endif
5803endif
5804
5805# -----------------------------------------------------------------
5806#  misc_info.txt
5807
5808INSTALLED_MISC_INFO_TARGET := $(PRODUCT_OUT)/misc_info.txt
5809
5810ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
5811# default to common dir for device vendor
5812tool_extensions := $(TARGET_DEVICE_DIR)/../common
5813else
5814tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
5815endif
5816.KATI_READONLY := tool_extensions
5817
5818# $1: boot image file name
5819define misc_boot_size
5820$(subst .img,_size,$(1))=$(BOARD_KERNEL$(call to-upper,$(subst boot,,$(subst .img,,$(1))))_BOOTIMAGE_PARTITION_SIZE)
5821endef
5822
5823$(INSTALLED_MISC_INFO_TARGET):
5824	rm -f $@
5825	$(call pretty,"Target misc_info.txt: $@")
5826	$(hide) echo "recovery_api_version=$(RECOVERY_API_VERSION)" >> $@
5827	$(hide) echo "fstab_version=$(RECOVERY_FSTAB_VERSION)" >> $@
5828ifdef BOARD_FLASH_BLOCK_SIZE
5829	$(hide) echo "blocksize=$(BOARD_FLASH_BLOCK_SIZE)" >> $@
5830endif
5831ifneq ($(strip $(BOARD_BOOTIMAGE_PARTITION_SIZE))$(strip $(BOARD_KERNEL_BINARIES)),)
5832	$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),\
5833		echo "$(call misc_boot_size,$(notdir $(b)))" >> $@;)
5834endif
5835ifeq ($(INSTALLED_BOOTIMAGE_TARGET),)
5836	$(hide) echo "no_boot=true" >> $@
5837else
5838	echo "boot_images=$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(notdir $(b)))" >> $@
5839endif
5840ifneq ($(INSTALLED_INIT_BOOT_IMAGE_TARGET),)
5841	$(hide) echo "init_boot=true" >> $@
5842	$(hide) echo "init_boot_size=$(BOARD_INIT_BOOT_IMAGE_PARTITION_SIZE)" >> $@
5843endif
5844ifeq ($(BOARD_RAMDISK_USE_LZ4),true)
5845	echo "lz4_ramdisks=true" >> $@
5846endif
5847ifneq ($(INSTALLED_VENDOR_BOOTIMAGE_TARGET),)
5848	echo "vendor_boot=true" >> $@
5849	echo "vendor_boot_size=$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE)" >> $@
5850endif
5851ifneq ($(INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET),)
5852	echo "vendor_kernel_boot=true" >> $@
5853	echo "vendor_kernel_boot_size=$(BOARD_VENDOR_KERNEL_BOOTIMAGE_PARTITION_SIZE)" >> $@
5854endif
5855ifeq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
5856	$(hide) echo "no_recovery=true" >> $@
5857endif
5858ifdef BOARD_INCLUDE_RECOVERY_DTBO
5859	$(hide) echo "include_recovery_dtbo=true" >> $@
5860endif
5861ifdef BOARD_INCLUDE_RECOVERY_ACPIO
5862	$(hide) echo "include_recovery_acpio=true" >> $@
5863endif
5864ifdef BOARD_RECOVERYIMAGE_PARTITION_SIZE
5865	$(hide) echo "recovery_size=$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)" >> $@
5866endif
5867ifdef TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS
5868	@# TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS can be empty to indicate that nothing but defaults should be used.
5869	$(hide) echo "recovery_mount_options=$(TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $@
5870else
5871	$(hide) echo "recovery_mount_options=$(DEFAULT_TARGET_RECOVERY_FSTYPE_MOUNT_OPTIONS)" >> $@
5872endif
5873	$(hide) echo "tool_extensions=$(tool_extensions)" >> $@
5874	$(hide) echo "default_system_dev_certificate=$(DEFAULT_SYSTEM_DEV_CERTIFICATE)" >> $@
5875ifdef PRODUCT_EXTRA_OTA_KEYS
5876	$(hide) echo "extra_ota_keys=$(PRODUCT_EXTRA_OTA_KEYS)" >> $@
5877endif
5878ifdef PRODUCT_EXTRA_RECOVERY_KEYS
5879	$(hide) echo "extra_recovery_keys=$(PRODUCT_EXTRA_RECOVERY_KEYS)" >> $@
5880endif
5881	$(hide) echo 'mkbootimg_args=$(BOARD_MKBOOTIMG_ARGS)' >> $@
5882	$(hide) echo 'recovery_mkbootimg_args=$(BOARD_RECOVERY_MKBOOTIMG_ARGS)' >> $@
5883	$(hide) echo 'mkbootimg_version_args=$(INTERNAL_MKBOOTIMG_VERSION_ARGS)' >> $@
5884	$(hide) echo 'mkbootimg_init_args=$(BOARD_MKBOOTIMG_INIT_ARGS)' >> $@
5885	$(hide) echo "multistage_support=1" >> $@
5886	$(hide) echo "blockimgdiff_versions=3,4" >> $@
5887ifeq ($(PRODUCT_BUILD_GENERIC_OTA_PACKAGE),true)
5888	$(hide) echo "build_generic_ota_package=true" >> $@
5889endif
5890ifneq ($(OEM_THUMBPRINT_PROPERTIES),)
5891	# OTA scripts are only interested in fingerprint related properties
5892	$(hide) echo "oem_fingerprint_properties=$(OEM_THUMBPRINT_PROPERTIES)" >> $@
5893endif
5894ifneq (,$(filter address, $(SANITIZE_TARGET)))
5895	# We need to create userdata.img with real data because the instrumented libraries are in userdata.img.
5896	$(hide) echo "userdata_img_with_data=true" >> $@
5897endif
5898ifeq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
5899	$(hide) echo "full_recovery_image=true" >> $@
5900endif
5901ifdef BOARD_USES_VENDORIMAGE
5902	$(hide) echo "board_uses_vendorimage=true" >> $@
5903endif
5904ifeq ($(BOARD_AVB_ENABLE),true)
5905ifeq ($(BUILDING_VBMETA_IMAGE),true)
5906	$(hide) echo "avb_building_vbmeta_image=true" >> $@
5907endif # BUILDING_VBMETA_IMAGE
5908	$(hide) echo "avb_enable=true" >> $@
5909	$(hide) echo "avb_vbmeta_key_path=$(BOARD_AVB_KEY_PATH)" >> $@
5910	$(hide) echo "avb_vbmeta_algorithm=$(BOARD_AVB_ALGORITHM)" >> $@
5911	$(hide) echo "avb_vbmeta_args=$(BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS)" >> $@
5912	$(hide) echo "avb_boot_add_hash_footer_args=$(BOARD_AVB_BOOT_ADD_HASH_FOOTER_ARGS)" >> $@
5913ifdef BOARD_AVB_BOOT_KEY_PATH
5914	$(hide) echo "avb_boot_key_path=$(BOARD_AVB_BOOT_KEY_PATH)" >> $@
5915	$(hide) echo "avb_boot_algorithm=$(BOARD_AVB_BOOT_ALGORITHM)" >> $@
5916	$(hide) echo "avb_boot_rollback_index_location=$(BOARD_AVB_BOOT_ROLLBACK_INDEX_LOCATION)" >> $@
5917endif # BOARD_AVB_BOOT_KEY_PATH
5918	$(hide) echo "avb_init_boot_add_hash_footer_args=$(BOARD_AVB_INIT_BOOT_ADD_HASH_FOOTER_ARGS)" >> $@
5919ifdef BOARD_AVB_INIT_BOOT_KEY_PATH
5920	$(hide) echo "avb_init_boot_key_path=$(BOARD_AVB_INIT_BOOT_KEY_PATH)" >> $@
5921	$(hide) echo "avb_init_boot_algorithm=$(BOARD_AVB_INIT_BOOT_ALGORITHM)" >> $@
5922	$(hide) echo "avb_init_boot_rollback_index_location=$(BOARD_AVB_INIT_BOOT_ROLLBACK_INDEX_LOCATION)" >> $@
5923endif # BOARD_AVB_INIT_BOOT_KEY_PATH
5924	echo "avb_vendor_boot_add_hash_footer_args=$(BOARD_AVB_VENDOR_BOOT_ADD_HASH_FOOTER_ARGS)" >> $@
5925ifdef BOARD_AVB_VENDOR_BOOT_KEY_PATH
5926	echo "avb_vendor_boot_key_path=$(BOARD_AVB_VENDOR_BOOT_KEY_PATH)" >> $@
5927	echo "avb_vendor_boot_algorithm=$(BOARD_AVB_VENDOR_BOOT_ALGORITHM)" >> $@
5928	echo "avb_vendor_boot_rollback_index_location=$(BOARD_AVB_VENDOR_BOOT_ROLLBACK_INDEX_LOCATION)" >> $@
5929endif # BOARD_AVB_VENDOR_BOOT_KEY_PATH
5930	echo "avb_vendor_kernel_boot_add_hash_footer_args=$(BOARD_AVB_VENDOR_KERNEL_BOOT_ADD_HASH_FOOTER_ARGS)" >> $@
5931ifdef BOARD_AVB_VENDOR_KERNEL_BOOT_KEY_PATH
5932	echo "avb_vendor_kernel_boot_key_path=$(BOARD_AVB_VENDOR_KERNEL_BOOT_KEY_PATH)" >> $@
5933	echo "avb_vendor_kernel_boot_algorithm=$(BOARD_AVB_VENDOR_KERNEL_BOOT_ALGORITHM)" >> $@
5934	echo "avb_vendor_kernel_boot_rollback_index_location=$(BOARD_AVB_VENDOR_KERNEL_BOOT_ROLLBACK_INDEX_LOCATION)" >> $@
5935endif # BOARD_AVB_VENDOR_KERNEL_BOOT_KEY_PATH
5936	$(hide) echo "avb_recovery_add_hash_footer_args=$(BOARD_AVB_RECOVERY_ADD_HASH_FOOTER_ARGS)" >> $@
5937ifdef BOARD_AVB_RECOVERY_KEY_PATH
5938	$(hide) echo "avb_recovery_key_path=$(BOARD_AVB_RECOVERY_KEY_PATH)" >> $@
5939	$(hide) echo "avb_recovery_algorithm=$(BOARD_AVB_RECOVERY_ALGORITHM)" >> $@
5940	$(hide) echo "avb_recovery_rollback_index_location=$(BOARD_AVB_RECOVERY_ROLLBACK_INDEX_LOCATION)" >> $@
5941endif # BOARD_AVB_RECOVERY_KEY_PATH
5942ifneq (,$(strip $(BOARD_CUSTOMIMAGES_PARTITION_LIST)))
5943	$(hide) echo "custom_images_partition_list=$(filter-out $(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST), $(BOARD_CUSTOMIMAGES_PARTITION_LIST))" >> $@
5944	$(hide) $(foreach partition,$(filter-out $(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST), $(BOARD_CUSTOMIMAGES_PARTITION_LIST)), \
5945	    echo "$(partition)_image_list=$(foreach image,$(BOARD_$(call to-upper,$(partition))_IMAGE_LIST),$(notdir $(image)))" >> $@;)
5946endif # BOARD_CUSTOMIMAGES_PARTITION_LIST
5947ifneq (,$(strip $(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST)))
5948	$(hide) echo "avb_custom_images_partition_list=$(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST)" >> $@
5949	$(hide) $(foreach partition,$(BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST), \
5950	    echo "avb_$(partition)_key_path=$(BOARD_AVB_$(call to-upper,$(partition))_KEY_PATH)"  >> $@; \
5951	    echo "avb_$(partition)_algorithm=$(BOARD_AVB_$(call to-upper,$(partition))_ALGORITHM)"  >> $@; \
5952	    echo "avb_$(partition)_add_hashtree_footer_args=$(BOARD_AVB_$(call to-upper,$(partition))_ADD_HASHTREE_FOOTER_ARGS)"  >> $@; \
5953	    echo "avb_$(partition)_rollback_index_location=$(BOARD_AVB_$(call to-upper,$(partition))_ROLLBACK_INDEX_LOCATION)"  >> $@; \
5954	    echo "avb_$(partition)_partition_size=$(BOARD_AVB_$(call to-upper,$(partition))_PARTITION_SIZE)"  >> $@; \
5955	    echo "avb_$(partition)_image_list=$(foreach image,$(BOARD_AVB_$(call to-upper,$(partition))_IMAGE_LIST),$(notdir $(image)))" >> $@;)
5956endif # BOARD_AVB_CUSTOMIMAGES_PARTITION_LIST
5957ifneq (,$(strip $(BOARD_AVB_VBMETA_SYSTEM)))
5958	$(hide) echo "avb_vbmeta_system=$(BOARD_AVB_VBMETA_SYSTEM)" >> $@
5959	$(hide) echo "avb_vbmeta_system_args=$(BOARD_AVB_MAKE_VBMETA_SYSTEM_IMAGE_ARGS)" >> $@
5960	$(hide) echo "avb_vbmeta_system_key_path=$(BOARD_AVB_VBMETA_SYSTEM_KEY_PATH)" >> $@
5961	$(hide) echo "avb_vbmeta_system_algorithm=$(BOARD_AVB_VBMETA_SYSTEM_ALGORITHM)" >> $@
5962	$(hide) echo "avb_vbmeta_system_rollback_index_location=$(BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX_LOCATION)" >> $@
5963endif # BOARD_AVB_VBMETA_SYSTEM
5964ifneq (,$(strip $(BOARD_AVB_VBMETA_VENDOR)))
5965	$(hide) echo "avb_vbmeta_vendor=$(BOARD_AVB_VBMETA_VENDOR)" >> $@
5966	$(hide) echo "avb_vbmeta_vendor_args=$(BOARD_AVB_MAKE_VBMETA_VENDOR_IMAGE_ARGS)" >> $@
5967	$(hide) echo "avb_vbmeta_vendor_key_path=$(BOARD_AVB_VBMETA_VENDOR_KEY_PATH)" >> $@
5968	$(hide) echo "avb_vbmeta_vendor_algorithm=$(BOARD_AVB_VBMETA_VENDOR_ALGORITHM)" >> $@
5969	$(hide) echo "avb_vbmeta_vendor_rollback_index_location=$(BOARD_AVB_VBMETA_VENDOR_ROLLBACK_INDEX_LOCATION)" >> $@
5970endif # BOARD_AVB_VBMETA_VENDOR_KEY_PATH
5971ifneq (,$(strip $(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS)))
5972	$(hide) echo "avb_custom_vbmeta_images_partition_list=$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS)" >> $@
5973	$(hide) $(foreach partition,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS),\
5974	echo "avb_vbmeta_$(partition)=$(BOARD_AVB_VBMETA_$(call to-upper,$(partition)))" >> $@ ;\
5975	echo "avb_vbmeta_$(partition)_args=$(BOARD_AVB_MAKE_VBMETA_$(call to-upper,$(partition))_IMAGE_ARGS)" >> $@ ;\
5976	echo "avb_vbmeta_$(partition)_key_path=$(BOARD_AVB_VBMETA_$(call to-upper,$(partition))_KEY_PATH)" >> $@ ;\
5977	echo "avb_vbmeta_$(partition)_algorithm=$(BOARD_AVB_VBMETA_$(call to-upper,$(partition))_ALGORITHM)" >> $@ ;\
5978	echo "avb_vbmeta_$(partition)_rollback_index_location=$(BOARD_AVB_VBMETA_$(call to-upper,$(partition))_ROLLBACK_INDEX_LOCATION)" >> $@ ;)
5979endif # BOARD_AVB_VBMETA_CUSTOM_PARTITIONS
5980endif # BOARD_AVB_ENABLE
5981	$(call generate-userimage-prop-dictionary, $@)
5982ifeq ($(AB_OTA_UPDATER),true)
5983	@# Include the build type in META/misc_info.txt so the server can easily differentiate production builds.
5984	$(hide) echo "build_type=$(TARGET_BUILD_VARIANT)" >> $@
5985	$(hide) echo "ab_update=true" >> $@
5986endif
5987ifeq ($(TARGET_OTA_ALLOW_NON_AB),true)
5988	$(hide) echo "allow_non_ab=true" >> $@
5989endif
5990ifeq ($(BOARD_NON_AB_OTA_DISABLE_COMPRESSION),true)
5991	$(hide) echo "board_non_ab_ota_disable_compression=true" >> $@
5992endif
5993ifdef BOARD_PREBUILT_DTBOIMAGE
5994	$(hide) echo "has_dtbo=true" >> $@
5995ifeq ($(BOARD_AVB_ENABLE),true)
5996	$(hide) echo "dtbo_size=$(BOARD_DTBOIMG_PARTITION_SIZE)" >> $@
5997	$(hide) echo "avb_dtbo_add_hash_footer_args=$(BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS)" >> $@
5998ifdef BOARD_AVB_DTBO_KEY_PATH
5999	$(hide) echo "avb_dtbo_key_path=$(BOARD_AVB_DTBO_KEY_PATH)" >> $@
6000	$(hide) echo "avb_dtbo_algorithm=$(BOARD_AVB_DTBO_ALGORITHM)" >> $@
6001	$(hide) echo "avb_dtbo_rollback_index_location=$(BOARD_AVB_DTBO_ROLLBACK_INDEX_LOCATION)" >> $@
6002endif # BOARD_AVB_DTBO_KEY_PATH
6003endif # BOARD_AVB_ENABLE
6004endif # BOARD_PREBUILT_DTBOIMAGE
6005ifeq ($(BOARD_USES_PVMFWIMAGE),true)
6006	$(hide) echo "has_pvmfw=true" >> $@
6007ifeq ($(BOARD_AVB_ENABLE),true)
6008	$(hide) echo "pvmfw_size=$(BOARD_PVMFWIMAGE_PARTITION_SIZE)" >> $@
6009	$(hide) echo "avb_pvmfw_add_hash_footer_args=$(BOARD_AVB_PVMFW_ADD_HASH_FOOTER_ARGS)" >> $@
6010ifdef BOARD_AVB_PVMFW_KEY_PATH
6011	$(hide) echo "avb_pvmfw_key_path=$(BOARD_AVB_PVMFW_KEY_PATH)" >> $@
6012	$(hide) echo "avb_pvmfw_algorithm=$(BOARD_AVB_PVMFW_ALGORITHM)" >> $@
6013	$(hide) echo "avb_pvmfw_rollback_index_location=$(BOARD_AVB_PVMFW_ROLLBACK_INDEX_LOCATION)" >> $@
6014endif # BOARD_AVB_PVMFW_KEY_PATH
6015endif # BOARD_AVB_ENABLE
6016endif # BOARD_USES_PVMFWIMAGE
6017	$(call dump-dynamic-partitions-info,$@)
6018	@# VINTF checks
6019ifeq ($(PRODUCT_ENFORCE_VINTF_MANIFEST),true)
6020	$(hide) echo "vintf_enforce=true" >> $@
6021endif
6022ifdef ODM_MANIFEST_SKUS
6023	$(hide) echo "vintf_odm_manifest_skus=$(ODM_MANIFEST_SKUS)" >> $@
6024endif
6025ifdef ODM_MANIFEST_FILES
6026	$(hide) echo "vintf_include_empty_odm_sku=true" >> $@
6027endif
6028ifdef DEVICE_MANIFEST_SKUS
6029	$(hide) echo "vintf_vendor_manifest_skus=$(DEVICE_MANIFEST_SKUS)" >> $@
6030endif
6031ifdef DEVICE_MANIFEST_FILE
6032	$(hide) echo "vintf_include_empty_vendor_sku=true" >> $@
6033endif
6034ifeq ($(BOARD_BOOTLOADER_IN_UPDATE_PACKAGE),true)
6035	$(hide) echo "bootloader_in_update_package=true" >> $@
6036endif
6037ifeq ($(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE),true)
6038	$(hide) echo "exclude_kernel_from_recovery_image=true" >> $@
6039endif
6040ifneq ($(BOARD_PARTIAL_OTA_UPDATE_PARTITIONS_LIST),)
6041	$(hide) echo "partial_ota_update_partitions_list=$(BOARD_PARTIAL_OTA_UPDATE_PARTITIONS_LIST)" >> $@
6042endif
6043ifeq ($(BUILDING_WITH_VSDK),true)
6044	$(hide) echo "building_with_vsdk=true" >> $@
6045endif
6046
6047$(call declare-0p-target,$(INSTALLED_FASTBOOT_INFO_TARGET))
6048
6049.PHONY: fastboot_info
6050fastboot_info: $(INSTALLED_FASTBOOT_INFO_TARGET)
6051
6052droidcore-unbundled: $(INSTALLED_FASTBOOT_INFO_TARGET)
6053
6054$(call declare-0p-target,$(INSTALLED_MISC_INFO_TARGET))
6055
6056.PHONY: misc_info
6057misc_info: $(INSTALLED_MISC_INFO_TARGET)
6058
6059droidcore-unbundled: $(INSTALLED_MISC_INFO_TARGET)
6060
6061# -----------------------------------------------------------------
6062# A zip of the directories that map to the target filesystem.
6063# This zip can be used to create an OTA package or filesystem image
6064# as a post-build step.
6065#
6066name := $(TARGET_PRODUCT)
6067ifeq ($(TARGET_BUILD_TYPE),debug)
6068  name := $(name)_debug
6069endif
6070name := $(name)-target_files
6071
6072intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
6073BUILT_TARGET_FILES_DIR := $(intermediates)/$(name).zip.list
6074BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
6075$(BUILT_TARGET_FILES_PACKAGE): zip_root := $(intermediates)/$(name)
6076$(BUILT_TARGET_FILES_DIR): zip_root := $(intermediates)/$(name)
6077$(BUILT_TARGET_FILES_DIR): intermediates := $(intermediates)
6078
6079
6080# $(1): Directory to copy
6081# $(2): Location to copy it to
6082# The "ls -A" is to skip if $(1) is empty.
6083define package_files-copy-root
6084  if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
6085    mkdir -p $(2) && \
6086    $(ACP) -rd $(strip $(1))/. $(strip $(2))/; \
6087  fi
6088endef
6089
6090built_ota_tools :=
6091
6092# We can't build static executables when SANITIZE_TARGET=address
6093ifeq (,$(filter address, $(SANITIZE_TARGET)))
6094built_ota_tools += \
6095    $(call intermediates-dir-for,EXECUTABLES,updater)/updater
6096endif
6097
6098$(BUILT_TARGET_FILES_DIR): PRIVATE_OTA_TOOLS := $(built_ota_tools)
6099
6100tool_extension := $(wildcard $(tool_extensions)/releasetools.py)
6101$(BUILT_TARGET_FILES_DIR): PRIVATE_TOOL_EXTENSION := $(tool_extension)
6102
6103updater_dep :=
6104ifeq ($(AB_OTA_UPDATER),true)
6105updater_dep += system/update_engine/update_engine.conf
6106$(call declare-1p-target,system/update_engine/update_engine.conf,system/update_engine)
6107updater_dep += external/zucchini/version_info.h
6108$(call declare-license-metadata,external/zucchini/version_info.h,legacy_notice,notice,external/zucchini/LICENSE,external/zucchini)
6109updater_dep += $(HOST_OUT_SHARED_LIBRARIES)/liblz4.so
6110endif
6111
6112# Build OTA tools if non-A/B is allowed
6113ifeq ($(TARGET_OTA_ALLOW_NON_AB),true)
6114updater_dep += $(built_ota_tools)
6115endif
6116
6117$(BUILT_TARGET_FILES_DIR): $(updater_dep)
6118
6119# If we are using recovery as boot, output recovery files to BOOT/.
6120# If we are moving recovery resources to vendor_boot, output recovery files to VENDOR_BOOT/.
6121ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
6122$(BUILT_TARGET_FILES_DIR): PRIVATE_RECOVERY_OUT := BOOT
6123else ifeq ($(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT),true)
6124$(BUILT_TARGET_FILES_DIR): PRIVATE_RECOVERY_OUT := VENDOR_BOOT
6125else
6126$(BUILT_TARGET_FILES_DIR): PRIVATE_RECOVERY_OUT := RECOVERY
6127endif
6128
6129ifeq ($(AB_OTA_UPDATER),true)
6130  ifdef OSRELEASED_DIRECTORY
6131    $(BUILT_TARGET_FILES_DIR): $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_id
6132    $(BUILT_TARGET_FILES_DIR): $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_version
6133    $(BUILT_TARGET_FILES_DIR): $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/system_version
6134  endif
6135
6136  # Not checking in board_config.mk, since AB_OTA_PARTITIONS may be updated in Android.mk (e.g. to
6137  # additionally include radio or bootloader partitions).
6138  ifeq ($(AB_OTA_PARTITIONS),)
6139    $(error AB_OTA_PARTITIONS must be defined when using AB_OTA_UPDATER)
6140  endif
6141endif
6142
6143ifneq ($(AB_OTA_PARTITIONS),)
6144  ifneq ($(AB_OTA_UPDATER),true)
6145    $(error AB_OTA_UPDATER must be true when defining AB_OTA_PARTITIONS)
6146  endif
6147endif
6148
6149# Run fs_config while creating the target files package
6150# $1: root directory
6151# $2: add prefix
6152define fs_config
6153(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) -R "$(2)"
6154endef
6155
6156define filter-out-missing-vendor
6157$(if $(INSTALLED_VENDORIMAGE_TARGET),$(1),$(filter-out vendor,$(1)))
6158endef
6159define filter-out-missing-vendor_dlkm
6160$(if $(INSTALLED_VENDOR_DLKMIMAGE_TARGET),$(1),$(filter-out vendor_dlkm,$(1)))
6161endef
6162define filter-out-missing-odm
6163$(if $(INSTALLED_ODMIMAGE_TARGET),$(1),$(filter-out odm,$(1)))
6164endef
6165define filter-out-missing-odm_dlkm
6166$(if $(INSTALLED_ODM_DLKMIMAGE_TARGET),$(1),$(filter-out odm_dlkm,$(1)))
6167endef
6168define filter-out-missing-system_dlkm
6169$(if $(INSTALLED_SYSTEM_DLKMIMAGE_TARGET),$(1),$(filter-out system_dlkm,$(1)))
6170endef
6171# Filter out vendor,vendor_dlkm,odm,odm_dlkm,system_dlkm from the list for AOSP targets.
6172# $(1): list
6173define filter-out-missing-partitions
6174$(call filter-out-missing-vendor,\
6175  $(call filter-out-missing-vendor_dlkm,\
6176    $(call filter-out-missing-odm,\
6177      $(call filter-out-missing-odm_dlkm,\
6178        $(call filter-out-missing-system_dlkm,$(1))))))
6179endef
6180
6181# Information related to dynamic partitions and virtual A/B. This information
6182# is needed for building the super image (see dump-super-image-info) and
6183# building OTA packages.
6184# $(1): file
6185define dump-dynamic-partitions-info
6186  $(if $(filter true,$(PRODUCT_USE_DYNAMIC_PARTITIONS)), \
6187    echo "use_dynamic_partitions=true" >> $(1))
6188  $(if $(filter true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)), \
6189    echo "dynamic_partition_retrofit=true" >> $(1))
6190  echo "lpmake=$(notdir $(LPMAKE))" >> $(1)
6191  $(if $(filter true,$(PRODUCT_BUILD_SUPER_PARTITION)), $(if $(BOARD_SUPER_PARTITION_SIZE), \
6192    echo "build_super_partition=true" >> $(1)))
6193  $(if $(BUILDING_SUPER_EMPTY_IMAGE), \
6194    echo "build_super_empty_partition=true" >> $(1))
6195  $(if $(filter true,$(BOARD_BUILD_RETROFIT_DYNAMIC_PARTITIONS_OTA_PACKAGE)), \
6196    echo "build_retrofit_dynamic_partitions_ota_package=true" >> $(1))
6197  echo "super_metadata_device=$(BOARD_SUPER_PARTITION_METADATA_DEVICE)" >> $(1)
6198  $(if $(BOARD_SUPER_PARTITION_BLOCK_DEVICES), \
6199    echo "super_block_devices=$(BOARD_SUPER_PARTITION_BLOCK_DEVICES)" >> $(1))
6200  $(foreach device,$(BOARD_SUPER_PARTITION_BLOCK_DEVICES), \
6201    echo "super_$(device)_device_size=$(BOARD_SUPER_PARTITION_$(call to-upper,$(device))_DEVICE_SIZE)" >> $(1);)
6202  $(if $(BOARD_SUPER_PARTITION_PARTITION_LIST), \
6203    echo "dynamic_partition_list=$(call filter-out-missing-partitions,$(BOARD_SUPER_PARTITION_PARTITION_LIST))" >> $(1))
6204  $(if $(BOARD_SUPER_PARTITION_GROUPS),
6205    echo "super_partition_groups=$(BOARD_SUPER_PARTITION_GROUPS)" >> $(1))
6206  $(foreach group,$(BOARD_SUPER_PARTITION_GROUPS), \
6207    echo "super_$(group)_group_size=$(BOARD_$(call to-upper,$(group))_SIZE)" >> $(1); \
6208    $(if $(BOARD_$(call to-upper,$(group))_PARTITION_LIST), \
6209      echo "super_$(group)_partition_list=$(call filter-out-missing-partitions,$(BOARD_$(call to-upper,$(group))_PARTITION_LIST))" >> $(1);))
6210  $(if $(filter true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED)), \
6211    echo "build_non_sparse_super_partition=true" >> $(1))
6212  $(if $(filter true,$(TARGET_USERIMAGES_SPARSE_F2FS_DISABLED)), \
6213    echo "build_non_sparse_super_partition=true" >> $(1))
6214  $(if $(filter true,$(BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE)), \
6215    echo "super_image_in_update_package=true" >> $(1))
6216  $(if $(BOARD_SUPER_PARTITION_SIZE), \
6217    echo "super_partition_size=$(BOARD_SUPER_PARTITION_SIZE)" >> $(1))
6218  $(if $(BOARD_SUPER_PARTITION_ALIGNMENT), \
6219    echo "super_partition_alignment=$(BOARD_SUPER_PARTITION_ALIGNMENT)" >> $(1))
6220  $(if $(BOARD_SUPER_PARTITION_WARN_LIMIT), \
6221    echo "super_partition_warn_limit=$(BOARD_SUPER_PARTITION_WARN_LIMIT)" >> $(1))
6222  $(if $(BOARD_SUPER_PARTITION_ERROR_LIMIT), \
6223    echo "super_partition_error_limit=$(BOARD_SUPER_PARTITION_ERROR_LIMIT)" >> $(1))
6224  $(if $(filter true,$(PRODUCT_VIRTUAL_AB_OTA)), \
6225    echo "virtual_ab=true" >> $(1))
6226  $(if $(filter true,$(PRODUCT_VIRTUAL_AB_COMPRESSION)), \
6227    echo "virtual_ab_compression=true" >> $(1))
6228# This value controls the compression algorithm used for VABC
6229# valid options are defined in system/core/fs_mgr/libsnapshot/cow_writer.cpp
6230# e.g. "none", "gz", "brotli"
6231  $(if $(PRODUCT_VIRTUAL_AB_COMPRESSION_METHOD), \
6232    echo "virtual_ab_compression_method=$(PRODUCT_VIRTUAL_AB_COMPRESSION_METHOD)" >> $(1))
6233  $(if $(filter true,$(PRODUCT_VIRTUAL_AB_OTA_RETROFIT)), \
6234    echo "virtual_ab_retrofit=true" >> $(1))
6235  $(if $(PRODUCT_VIRTUAL_AB_COW_VERSION), \
6236    echo "virtual_ab_cow_version=$(PRODUCT_VIRTUAL_AB_COW_VERSION)" >> $(1))
6237  $(if $(PRODUCT_VIRTUAL_AB_COMPRESSION_FACTOR), \
6238    echo "virtual_ab_compression_factor=$(PRODUCT_VIRTUAL_AB_COMPRESSION_FACTOR)" >> $(1))
6239endef
6240
6241# Copy an image file to a directory and generate a block list map file from the image,
6242# only if the map_file_generator supports the file system.
6243# Otherwise, skip generating map files as well as copying images. The image will be
6244# generated from the $(ADD_IMG_TO_TARGET_FILES) to generate the map file with it.
6245# $(1): path of the image file
6246# $(2): target out directory
6247# $(3): image name to generate a map file. skip generating map file if empty
6248define copy-image-and-generate-map
6249  $(if $(COPY_IMAGES_FOR_TARGET_FILES_ZIP), \
6250    $(eval _supported_fs_for_map_file_generator := erofs ext%) \
6251    $(eval _img := $(call to-upper,$(3))) \
6252    $(if $(3),$(eval _map_fs_type := $(BOARD_$(_img)IMAGE_FILE_SYSTEM_TYPE)),\
6253      $(eval _no_map_file := "true")) \
6254    $(if $(filter $(_supported_fs_for_map_file_generator),$(_map_fs_type))$(_no_map_file),\
6255      mkdir -p $(2); \
6256      cp $(1) $(2); \
6257      $(if $(3),$(HOST_OUT_EXECUTABLES)/map_file_generator $(1) $(2)/$(3).map)) \
6258    $(eval _img :=) \
6259    $(eval _map_fs_type :=) \
6260    $(eval _no_map_file :=) \
6261  )
6262endef
6263
6264# By conditionally including the dependency of the target files package on the
6265# full system image deps, we speed up builds that do not build the system
6266# image.
6267ifdef BUILDING_SYSTEM_IMAGE
6268  $(BUILT_TARGET_FILES_DIR): $(FULL_SYSTEMIMAGE_DEPS)
6269  ifdef COPY_IMAGES_FOR_TARGET_FILES_ZIP
6270    $(BUILT_TARGET_FILES_DIR): $(BUILT_SYSTEMIMAGE)
6271  endif
6272else
6273  # releasetools may need the system build.prop even when building a
6274  # system-image-less product.
6275  $(BUILT_TARGET_FILES_DIR): $(INSTALLED_BUILD_PROP_TARGET)
6276endif
6277
6278ifdef BUILDING_USERDATA_IMAGE
6279  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_USERDATAIMAGE_FILES)
6280endif
6281
6282ifdef BUILDING_SYSTEM_OTHER_IMAGE
6283  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_SYSTEMOTHERIMAGE_FILES)
6284  ifdef COPY_IMAGES_FOR_TARGET_FILES_ZIP
6285    $(BUILT_TARGET_FILES_DIR): $(BUILT_SYSTEMOTHERIMAGE_TARGET)
6286  endif
6287endif
6288
6289ifdef BUILDING_VENDOR_BOOT_IMAGE
6290  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_VENDOR_RAMDISK_FILES)
6291  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS)
6292  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_VENDOR_BOOTCONFIG_TARGET)
6293  # The vendor ramdisk may be built from the recovery ramdisk.
6294  ifeq (true,$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT))
6295    $(BUILT_TARGET_FILES_DIR): $(INTERNAL_RECOVERY_RAMDISK_FILES_TIMESTAMP)
6296  endif
6297endif
6298
6299ifdef BUILDING_RECOVERY_IMAGE
6300  # TODO(b/30414428): Can't depend on INTERNAL_RECOVERYIMAGE_FILES alone like other
6301  # BUILT_TARGET_FILES_PACKAGE dependencies because currently there're cp/rsync/rm
6302  # commands in build-recoveryimage-target, which would touch the files under
6303  # TARGET_RECOVERY_OUT and race with packaging target-files.zip.
6304  ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
6305    $(BUILT_TARGET_FILES_DIR): $(INSTALLED_BOOTIMAGE_TARGET)
6306  else
6307    $(BUILT_TARGET_FILES_DIR): $(INSTALLED_RECOVERYIMAGE_TARGET)
6308  endif
6309  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_RECOVERYIMAGE_FILES)
6310endif
6311
6312# Conditionally depend on the image files if the image is being built so the
6313# target-files.zip rule doesn't wait on the image creation rule, or the image
6314# if it is coming from a prebuilt.
6315
6316ifdef BUILDING_VENDOR_IMAGE
6317  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_VENDORIMAGE_FILES)
6318  ifdef COPY_IMAGES_FOR_TARGET_FILES_ZIP
6319    $(BUILT_TARGET_FILES_DIR): $(BUILT_VENDORIMAGE_TARGET)
6320  endif
6321else ifdef BOARD_PREBUILT_VENDORIMAGE
6322  $(BUILT_TARGET_FILES_DIR): $(INSTALLED_VENDORIMAGE_TARGET)
6323endif
6324
6325ifdef BUILDING_PRODUCT_IMAGE
6326  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_PRODUCTIMAGE_FILES)
6327  ifdef COPY_IMAGES_FOR_TARGET_FILES_ZIP
6328    $(BUILT_TARGET_FILES_DIR): $(BUILT_PRODUCTIMAGE_TARGET)
6329  endif
6330else ifdef BOARD_PREBUILT_PRODUCTIMAGE
6331  $(BUILT_TARGET_FILES_DIR): $(INSTALLED_PRODUCTIMAGE_TARGET)
6332endif
6333
6334ifdef BUILDING_SYSTEM_EXT_IMAGE
6335  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_SYSTEM_EXTIMAGE_FILES)
6336  ifdef COPY_IMAGES_FOR_TARGET_FILES_ZIP
6337    $(BUILT_TARGET_FILES_DIR): $(BUILT_SYSTEM_EXTIMAGE_TARGET)
6338  endif
6339else ifdef BOARD_PREBUILT_SYSTEM_EXTIMAGE
6340  $(BUILT_TARGET_FILES_DIR): $(INSTALLED_SYSTEM_EXTIMAGE_TARGET)
6341endif
6342
6343ifneq (,$(BUILDING_BOOT_IMAGE)$(BUILDING_INIT_BOOT_IMAGE))
6344  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_RAMDISK_FILES)
6345endif  # BUILDING_BOOT_IMAGE != "" || BUILDING_INIT_BOOT_IMAGE != ""
6346
6347ifneq (,$(INTERNAL_PREBUILT_BOOTIMAGE) $(filter true,$(BOARD_COPY_BOOT_IMAGE_TO_TARGET_FILES)))
6348  $(BUILT_TARGET_FILES_DIR): $(INSTALLED_BOOTIMAGE_TARGET)
6349endif
6350
6351ifdef BUILDING_ODM_IMAGE
6352  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_ODMIMAGE_FILES)
6353  ifdef COPY_IMAGES_FOR_TARGET_FILES_ZIP
6354    $(BUILT_TARGET_FILES_DIR): $(BUILT_ODMIMAGE_TARGET)
6355  endif
6356else ifdef BOARD_PREBUILT_ODMIMAGE
6357  $(BUILT_TARGET_FILES_DIR): $(INSTALLED_ODMIMAGE_TARGET)
6358endif
6359
6360ifdef BUILDING_VENDOR_DLKM_IMAGE
6361  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_VENDOR_DLKMIMAGE_FILES)
6362  ifdef COPY_IMAGES_FOR_TARGET_FILES_ZIP
6363    $(BUILT_TARGET_FILES_DIR): $(BUILT_VENDOR_DLKMIMAGE_TARGET)
6364  endif
6365else ifdef BOARD_PREBUILT_VENDOR_DLKMIMAGE
6366  $(BUILT_TARGET_FILES_DIR): $(INSTALLED_VENDOR_DLKMIMAGE_TARGET)
6367endif
6368
6369ifdef BUILDING_ODM_DLKM_IMAGE
6370  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_ODM_DLKMIMAGE_FILES)
6371  ifdef COPY_IMAGES_FOR_TARGET_FILES_ZIP
6372    $(BUILT_TARGET_FILES_DIR): $(BUILT_ODM_DLKMIMAGE_TARGET)
6373  endif
6374else ifdef BOARD_PREBUILT_ODM_DLKMIMAGE
6375  $(BUILT_TARGET_FILES_DIR): $(INSTALLED_ODM_DLKMIMAGE_TARGET)
6376endif
6377
6378ifdef BUILDING_SYSTEM_DLKM_IMAGE
6379  $(BUILT_TARGET_FILES_DIR): $(INTERNAL_SYSTEM_DLKMIMAGE_FILES)
6380  ifdef COPY_IMAGES_FOR_TARGET_FILES_ZIP
6381    $(BUILT_TARGET_FILES_DIR): $(BUILT_SYSTEM_DLKMIMAGE_TARGET)
6382  endif
6383else ifdef BOARD_PREBUILT_SYSTEM_DLKMIMAGE
6384  $(BUILT_TARGET_FILES_DIR): $(INSTALLED_SYSTEM_DLKMIMAGE_TARGET)
6385endif
6386
6387ifeq ($(BUILD_QEMU_IMAGES),true)
6388  MK_VBMETA_BOOT_KERNEL_CMDLINE_SH := device/generic/goldfish/tools/mk_vbmeta_boot_params.sh
6389  $(BUILT_TARGET_FILES_DIR): $(MK_VBMETA_BOOT_KERNEL_CMDLINE_SH)
6390endif
6391
6392ifdef BOARD_PREBUILT_BOOTLOADER
6393$(BUILT_TARGET_FILES_DIR): $(INSTALLED_BOOTLOADER_MODULE)
6394droidcore-unbundled: $(INSTALLED_BOOTLOADER_MODULE)
6395endif
6396
6397# Depending on the various images guarantees that the underlying
6398# directories are up-to-date.
6399$(BUILT_TARGET_FILES_DIR): \
6400	    $(INSTALLED_RADIOIMAGE_TARGET) \
6401	    $(INSTALLED_RECOVERYIMAGE_TARGET) \
6402	    $(INSTALLED_CACHEIMAGE_TARGET) \
6403	    $(INSTALLED_DTBOIMAGE_TARGET) \
6404	    $(INSTALLED_PVMFWIMAGE_TARGET) \
6405	    $(INSTALLED_PVMFW_BINARY_TARGET) \
6406	    $(INSTALLED_PVMFW_EMBEDDED_AVBKEY_TARGET) \
6407	    $(INSTALLED_CUSTOMIMAGES_TARGET) \
6408	    $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
6409	    $(INSTALLED_KERNEL_TARGET) \
6410	    $(INSTALLED_RAMDISK_TARGET) \
6411	    $(INSTALLED_DTBIMAGE_TARGET) \
6412	    $(INSTALLED_2NDBOOTLOADER_TARGET) \
6413	    $(BUILT_RAMDISK_16K_TARGET) \
6414	    $(BUILT_KERNEL_16K_TARGET) \
6415	    $(BOARD_PREBUILT_DTBOIMAGE) \
6416	    $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE) \
6417	    $(BOARD_RECOVERY_ACPIO) \
6418	    $(PRODUCT_SYSTEM_BASE_FS_PATH) \
6419	    $(PRODUCT_VENDOR_BASE_FS_PATH) \
6420	    $(PRODUCT_PRODUCT_BASE_FS_PATH) \
6421	    $(PRODUCT_SYSTEM_EXT_BASE_FS_PATH) \
6422	    $(PRODUCT_ODM_BASE_FS_PATH) \
6423	    $(PRODUCT_VENDOR_DLKM_BASE_FS_PATH) \
6424	    $(PRODUCT_ODM_DLKM_BASE_FS_PATH) \
6425	    $(PRODUCT_SYSTEM_DLKM_BASE_FS_PATH) \
6426	    $(LPMAKE) \
6427	    $(SELINUX_FC) \
6428	    $(INSTALLED_MISC_INFO_TARGET) \
6429	    $(INSTALLED_FASTBOOT_INFO_TARGET) \
6430	    $(APKCERTS_FILE) \
6431	    $(APEX_KEYS_FILE) \
6432	    $(SOONG_ZIP) \
6433	    $(HOST_OUT_EXECUTABLES)/fs_config \
6434	    $(HOST_OUT_EXECUTABLES)/map_file_generator \
6435	    $(ADD_IMG_TO_TARGET_FILES) \
6436	    $(MAKE_RECOVERY_PATCH) \
6437	    $(BUILT_KERNEL_CONFIGS_FILE) \
6438	    $(BUILT_KERNEL_VERSION_FILE) \
6439	    | $(ACP)
6440	@echo "Building target files: $@"
6441	$(hide) rm -rf $@ $@.list $(zip_root)
6442	$(hide) mkdir -p $(dir $@) $(zip_root)
6443ifneq (,$(INSTALLED_RECOVERYIMAGE_TARGET)$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT))$(filter true,$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT)))
6444	@# Components of the recovery image
6445	$(hide) mkdir -p $(zip_root)/$(PRIVATE_RECOVERY_OUT)
6446# Exclude recovery files in the default vendor ramdisk if including a standalone
6447# recovery ramdisk in vendor_boot.
6448ifneq (true,$(BOARD_INCLUDE_RECOVERY_RAMDISK_IN_VENDOR_BOOT))
6449	$(hide) $(call package_files-copy-root, \
6450	    $(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/$(PRIVATE_RECOVERY_OUT)/RAMDISK)
6451endif
6452ifdef INSTALLED_KERNEL_TARGET
6453ifneq (,$(filter true,$(BOARD_USES_RECOVERY_AS_BOOT)))
6454	cp $(INSTALLED_KERNEL_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/
6455else ifneq (true,$(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE))
6456	cp $(firstword $(INSTALLED_KERNEL_TARGET)) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/kernel
6457endif
6458endif
6459ifneq (truetrue,$(strip $(BUILDING_VENDOR_BOOT_IMAGE))$(strip $(BOARD_USES_RECOVERY_AS_BOOT)))
6460ifdef INSTALLED_2NDBOOTLOADER_TARGET
6461	cp $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/second
6462endif
6463ifdef BOARD_INCLUDE_RECOVERY_DTBO
6464ifdef BOARD_PREBUILT_RECOVERY_DTBOIMAGE
6465	cp $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/recovery_dtbo
6466else
6467	cp $(BOARD_PREBUILT_DTBOIMAGE) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/recovery_dtbo
6468endif
6469endif # BOARD_INCLUDE_RECOVERY_DTBO
6470ifdef BOARD_INCLUDE_RECOVERY_ACPIO
6471	cp $(BOARD_RECOVERY_ACPIO) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/recovery_acpio
6472endif
6473ifdef INSTALLED_DTBIMAGE_TARGET
6474	cp $(INSTALLED_DTBIMAGE_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/dtb
6475endif
6476ifneq (true,$(BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE))
6477ifdef INTERNAL_KERNEL_CMDLINE
6478	echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/cmdline
6479endif # INTERNAL_KERNEL_CMDLINE != ""
6480endif # BOARD_EXCLUDE_KERNEL_FROM_RECOVERY_IMAGE != true
6481ifdef BOARD_KERNEL_BASE
6482	echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/base
6483endif
6484ifdef BOARD_KERNEL_PAGESIZE
6485	echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/pagesize
6486endif
6487endif # not (BUILDING_VENDOR_BOOT_IMAGE and BOARD_USES_RECOVERY_AS_BOOT)
6488endif # INSTALLED_RECOVERYIMAGE_TARGET defined or BOARD_USES_RECOVERY_AS_BOOT is true
6489	@# Components of the boot image
6490	$(hide) mkdir -p $(zip_root)/BOOT
6491	$(hide) mkdir -p $(zip_root)/ROOT
6492	$(hide) $(call package_files-copy-root, \
6493	    $(TARGET_ROOT_OUT),$(zip_root)/ROOT)
6494	@# If we are using recovery as boot, this is already done when processing recovery.
6495ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
6496	$(hide) $(call package_files-copy-root, \
6497	    $(TARGET_RAMDISK_OUT),$(zip_root)/BOOT/RAMDISK)
6498ifdef INSTALLED_KERNEL_TARGET
6499	$(hide) cp $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/
6500endif
6501ifeq (true,$(BOARD_USES_GENERIC_KERNEL_IMAGE))
6502	echo "$(GENERIC_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
6503else ifndef INSTALLED_VENDOR_BOOTIMAGE_TARGET # && BOARD_USES_GENERIC_KERNEL_IMAGE != true
6504	echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
6505ifdef INSTALLED_2NDBOOTLOADER_TARGET
6506	cp $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second
6507endif
6508ifdef INSTALLED_DTBIMAGE_TARGET
6509	cp $(INSTALLED_DTBIMAGE_TARGET) $(zip_root)/BOOT/dtb
6510endif
6511ifdef BOARD_KERNEL_BASE
6512	echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base
6513endif
6514ifdef BOARD_KERNEL_PAGESIZE
6515	echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesize
6516endif
6517endif # INSTALLED_VENDOR_BOOTIMAGE_TARGET == "" && BOARD_USES_GENERIC_KERNEL_IMAGE != true
6518endif # BOARD_USES_RECOVERY_AS_BOOT not true
6519	$(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\
6520	            mkdir -p $(zip_root)/RADIO; \
6521	            cp $(t) $(zip_root)/RADIO/$(notdir $(t));)
6522ifdef INSTALLED_VENDOR_BOOTIMAGE_TARGET
6523	mkdir -p $(zip_root)/VENDOR_BOOT
6524	$(call package_files-copy-root, \
6525	    $(TARGET_VENDOR_RAMDISK_OUT),$(zip_root)/VENDOR_BOOT/RAMDISK)
6526ifdef INSTALLED_DTBIMAGE_TARGET
6527ifneq ($(BUILDING_VENDOR_KERNEL_BOOT_IMAGE),true)
6528	cp $(INSTALLED_DTBIMAGE_TARGET) $(zip_root)/VENDOR_BOOT/dtb
6529endif
6530endif # end of INSTALLED_DTBIMAGE_TARGET
6531ifdef INTERNAL_VENDOR_BOOTCONFIG_TARGET
6532	cp $(INTERNAL_VENDOR_BOOTCONFIG_TARGET) $(zip_root)/VENDOR_BOOT/vendor_bootconfig
6533endif
6534ifdef BOARD_KERNEL_BASE
6535	echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/VENDOR_BOOT/base
6536endif
6537ifdef BOARD_KERNEL_PAGESIZE
6538	echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/VENDOR_BOOT/pagesize
6539endif
6540	echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/VENDOR_BOOT/vendor_cmdline
6541ifdef INTERNAL_VENDOR_RAMDISK_FRAGMENTS
6542	echo "$(INTERNAL_VENDOR_RAMDISK_FRAGMENTS)" > "$(zip_root)/VENDOR_BOOT/vendor_ramdisk_fragments"
6543	$(foreach vendor_ramdisk_fragment,$(INTERNAL_VENDOR_RAMDISK_FRAGMENTS), \
6544	  mkdir -p $(zip_root)/VENDOR_BOOT/RAMDISK_FRAGMENTS/$(vendor_ramdisk_fragment); \
6545	  echo "$(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).MKBOOTIMG_ARGS)" > "$(zip_root)/VENDOR_BOOT/RAMDISK_FRAGMENTS/$(vendor_ramdisk_fragment)/mkbootimg_args"; \
6546	  $(eval prebuilt_ramdisk := $(BOARD_VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).PREBUILT)) \
6547	  $(if $(prebuilt_ramdisk), \
6548	    cp "$(prebuilt_ramdisk)" "$(zip_root)/VENDOR_BOOT/RAMDISK_FRAGMENTS/$(vendor_ramdisk_fragment)/prebuilt_ramdisk";, \
6549	    $(call package_files-copy-root, \
6550	      $(VENDOR_RAMDISK_FRAGMENT.$(vendor_ramdisk_fragment).STAGING_DIR), \
6551	      $(zip_root)/VENDOR_BOOT/RAMDISK_FRAGMENTS/$(vendor_ramdisk_fragment)/RAMDISK); \
6552	  ))
6553endif # INTERNAL_VENDOR_RAMDISK_FRAGMENTS != ""
6554endif # INSTALLED_VENDOR_BOOTIMAGE_TARGET
6555ifdef INSTALLED_VENDOR_KERNEL_BOOTIMAGE_TARGET
6556	mkdir -p $(zip_root)/VENDOR_KERNEL_BOOT
6557	$(call package_files-copy-root, \
6558	    $(TARGET_VENDOR_KERNEL_RAMDISK_OUT),$(zip_root)/VENDOR_KERNEL_BOOT/RAMDISK)
6559ifdef INSTALLED_DTBIMAGE_TARGET
6560	cp $(INSTALLED_DTBIMAGE_TARGET) $(zip_root)/VENDOR_KERNEL_BOOT/dtb
6561endif
6562ifdef BOARD_KERNEL_PAGESIZE
6563	echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/VENDOR_KERNEL_BOOT/pagesize
6564endif
6565endif # INSTALLED_VENDOR_BOOTIMAGE_TARGET
6566ifdef BUILDING_SYSTEM_IMAGE
6567	@# Contents of the system image
6568	$(hide) $(call package_files-copy-root, \
6569	    $(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
6570else ifdef INSTALLED_BUILD_PROP_TARGET
6571	@# Copy the system build.prop even if not building a system image
6572	@# because add_img_to_target_files may need it to build other partition
6573	@# images.
6574	$(hide) mkdir -p "$(zip_root)/SYSTEM"
6575	$(hide) cp "$(INSTALLED_BUILD_PROP_TARGET)" "$(patsubst $(TARGET_OUT)/%,$(zip_root)/SYSTEM/%,$(INSTALLED_BUILD_PROP_TARGET))"
6576endif
6577ifdef BUILDING_USERDATA_IMAGE
6578	@# Contents of the data image
6579	$(hide) $(call package_files-copy-root, \
6580	    $(TARGET_OUT_DATA),$(zip_root)/DATA)
6581endif
6582ifdef BUILDING_VENDOR_IMAGE
6583	@# Contents of the vendor image
6584	$(hide) $(call package_files-copy-root, \
6585	    $(TARGET_OUT_VENDOR),$(zip_root)/VENDOR)
6586endif
6587ifdef BUILDING_PRODUCT_IMAGE
6588	@# Contents of the product image
6589	$(hide) $(call package_files-copy-root, \
6590	    $(TARGET_OUT_PRODUCT),$(zip_root)/PRODUCT)
6591endif
6592ifdef BUILDING_SYSTEM_EXT_IMAGE
6593	@# Contents of the system_ext image
6594	$(hide) $(call package_files-copy-root, \
6595	    $(TARGET_OUT_SYSTEM_EXT),$(zip_root)/SYSTEM_EXT)
6596endif
6597ifdef BUILDING_ODM_IMAGE
6598	@# Contents of the odm image
6599	$(hide) $(call package_files-copy-root, \
6600	    $(TARGET_OUT_ODM),$(zip_root)/ODM)
6601endif
6602ifdef BUILDING_VENDOR_DLKM_IMAGE
6603	@# Contents of the vendor_dlkm image
6604	$(hide) $(call package_files-copy-root, \
6605	    $(TARGET_OUT_VENDOR_DLKM),$(zip_root)/VENDOR_DLKM)
6606endif
6607ifdef BUILDING_ODM_DLKM_IMAGE
6608	@# Contents of the odm_dlkm image
6609	$(hide) $(call package_files-copy-root, \
6610	    $(TARGET_OUT_ODM_DLKM),$(zip_root)/ODM_DLKM)
6611endif
6612ifdef BUILDING_SYSTEM_DLKM_IMAGE
6613	@# Contents of the system_dlkm image
6614	$(hide) $(call package_files-copy-root, \
6615	    $(TARGET_OUT_SYSTEM_DLKM),$(zip_root)/SYSTEM_DLKM)
6616endif
6617ifdef BUILDING_SYSTEM_OTHER_IMAGE
6618	@# Contents of the system_other image
6619	$(hide) $(call package_files-copy-root, \
6620	    $(TARGET_OUT_SYSTEM_OTHER),$(zip_root)/SYSTEM_OTHER)
6621endif
6622	@# Extra contents of the OTA package
6623	$(hide) mkdir -p $(zip_root)/OTA
6624	$(hide) cp $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/
6625ifdef BUILDING_RAMDISK_IMAGE
6626ifeq (true,$(BOARD_IMG_USE_RAMDISK))
6627	@# Contents of the ramdisk image
6628	$(hide) mkdir -p $(zip_root)/IMAGES
6629	$(hide) cp $(INSTALLED_RAMDISK_TARGET) $(zip_root)/IMAGES/
6630endif
6631endif
6632ifeq ($(TARGET_OTA_ALLOW_NON_AB),true)
6633ifneq ($(built_ota_tools),)
6634	$(hide) mkdir -p $(zip_root)/OTA/bin
6635	$(hide) cp $(PRIVATE_OTA_TOOLS) $(zip_root)/OTA/bin/
6636endif
6637endif
6638	@# Files that do not end up in any images, but are necessary to
6639	@# build them.
6640	$(hide) mkdir -p $(zip_root)/META
6641	$(hide) cp $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
6642	$(hide) cp $(APEX_KEYS_FILE) $(zip_root)/META/apexkeys.txt
6643ifneq ($(tool_extension),)
6644	$(hide) cp $(PRIVATE_TOOL_EXTENSION) $(zip_root)/META/
6645endif
6646	$(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
6647	$(hide) cp $(SELINUX_FC) $(zip_root)/META/file_contexts.bin
6648	$(hide) cp $(INSTALLED_MISC_INFO_TARGET) $(zip_root)/META/misc_info.txt
6649ifneq ($(INSTALLED_FASTBOOT_INFO_TARGET),)
6650	$(hide) cp $(INSTALLED_FASTBOOT_INFO_TARGET) $(zip_root)/META/fastboot-info.txt
6651endif
6652ifneq ($(PRODUCT_SYSTEM_BASE_FS_PATH),)
6653	$(hide) cp $(PRODUCT_SYSTEM_BASE_FS_PATH) \
6654	  $(zip_root)/META/$(notdir $(PRODUCT_SYSTEM_BASE_FS_PATH))
6655endif
6656ifneq ($(PRODUCT_VENDOR_BASE_FS_PATH),)
6657	$(hide) cp $(PRODUCT_VENDOR_BASE_FS_PATH) \
6658	  $(zip_root)/META/$(notdir $(PRODUCT_VENDOR_BASE_FS_PATH))
6659endif
6660ifneq ($(PRODUCT_PRODUCT_BASE_FS_PATH),)
6661	$(hide) cp $(PRODUCT_PRODUCT_BASE_FS_PATH) \
6662	  $(zip_root)/META/$(notdir $(PRODUCT_PRODUCT_BASE_FS_PATH))
6663endif
6664ifneq ($(PRODUCT_SYSTEM_EXT_BASE_FS_PATH),)
6665	$(hide) cp $(PRODUCT_SYSTEM_EXT_BASE_FS_PATH) \
6666	  $(zip_root)/META/$(notdir $(PRODUCT_SYSTEM_EXT_BASE_FS_PATH))
6667endif
6668ifneq ($(PRODUCT_ODM_BASE_FS_PATH),)
6669	$(hide) cp $(PRODUCT_ODM_BASE_FS_PATH) \
6670	  $(zip_root)/META/$(notdir $(PRODUCT_ODM_BASE_FS_PATH))
6671endif
6672ifneq ($(PRODUCT_VENDOR_DLKM_BASE_FS_PATH),)
6673	$(hide) cp $(PRODUCT_VENDOR_DLKM_BASE_FS_PATH) \
6674	  $(zip_root)/META/$(notdir $(PRODUCT_VENDOR_DLKM_BASE_FS_PATH))
6675endif
6676ifneq ($(PRODUCT_ODM_DLKM_BASE_FS_PATH),)
6677	$(hide) cp $(PRODUCT_ODM_DLKM_BASE_FS_PATH) \
6678	  $(zip_root)/META/$(notdir $(PRODUCT_ODM_DLKM_BASE_FS_PATH))
6679endif
6680ifneq ($(PRODUCT_SYSTEM_DLKM_BASE_FS_PATH),)
6681	$(hide) cp $(PRODUCT_SYSTEM_DLKM_BASE_FS_PATH) \
6682	  $(zip_root)/META/$(notdir $(PRODUCT_SYSTEM_DLKM_BASE_FS_PATH))
6683endif
6684ifeq ($(TARGET_OTA_ALLOW_NON_AB),true)
6685ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
6686	$(hide) PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH MKBOOTIMG=$(MKBOOTIMG) \
6687	    $(MAKE_RECOVERY_PATCH) $(zip_root) $(zip_root)
6688endif
6689endif
6690ifeq ($(AB_OTA_UPDATER),true)
6691	@# When using the A/B updater, include the updater config files in the zip.
6692	$(hide) cp $(TOPDIR)system/update_engine/update_engine.conf $(zip_root)/META/update_engine_config.txt
6693	$(hide) cp $(TOPDIR)external/zucchini/version_info.h $(zip_root)/META/zucchini_config.txt
6694	$(hide) cp $(HOST_OUT_SHARED_LIBRARIES)/liblz4.so $(zip_root)/META/liblz4.so
6695	$(hide) for part in $(sort $(AB_OTA_PARTITIONS)); do \
6696	  echo "$${part}" >> $(zip_root)/META/ab_partitions.txt; \
6697	done
6698	$(hide) for conf in $(strip $(AB_OTA_POSTINSTALL_CONFIG)); do \
6699	  echo "$${conf}" >> $(zip_root)/META/postinstall_config.txt; \
6700	done
6701ifdef OSRELEASED_DIRECTORY
6702	$(hide) cp $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_id $(zip_root)/META/product_id.txt
6703	$(hide) cp $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)/product_version $(zip_root)/META/product_version.txt
6704	$(hide) cp $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)/system_version $(zip_root)/META/system_version.txt
6705endif
6706endif
6707ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
6708	@# If breakpad symbols have been generated, add them to the zip.
6709	$(hide) cp -R $(TARGET_OUT_BREAKPAD) $(zip_root)/BREAKPAD
6710endif
6711ifdef BOARD_PREBUILT_VENDORIMAGE
6712	$(hide) mkdir -p $(zip_root)/IMAGES
6713	$(hide) cp $(INSTALLED_VENDORIMAGE_TARGET) $(zip_root)/IMAGES/
6714endif
6715ifdef BOARD_PREBUILT_PRODUCTIMAGE
6716	$(hide) mkdir -p $(zip_root)/IMAGES
6717	$(hide) cp $(INSTALLED_PRODUCTIMAGE_TARGET) $(zip_root)/IMAGES/
6718endif
6719ifdef BOARD_PREBUILT_SYSTEM_EXTIMAGE
6720	$(hide) mkdir -p $(zip_root)/IMAGES
6721	$(hide) cp $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) $(zip_root)/IMAGES/
6722endif
6723ifdef BOARD_PREBUILT_INIT_BOOT_IMAGE
6724	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
6725	$(hide) cp $(INSTALLED_INIT_BOOT_IMAGE_TARGET) $(zip_root)/PREBUILT_IMAGES/
6726endif
6727
6728ifndef BOARD_PREBUILT_BOOTIMAGE
6729ifneq (,$(strip $(INTERNAL_PREBUILT_BOOTIMAGE) $(filter true,$(BOARD_COPY_BOOT_IMAGE_TO_TARGET_FILES))))
6730ifdef INSTALLED_BOOTIMAGE_TARGET
6731	$(hide) mkdir -p $(zip_root)/IMAGES
6732	$(hide) cp $(INSTALLED_BOOTIMAGE_TARGET) $(zip_root)/IMAGES/
6733endif # INSTALLED_BOOTIMAGE_TARGET
6734endif # INTERNAL_PREBUILT_BOOTIMAGE != "" || BOARD_COPY_BOOT_IMAGE_TO_TARGET_FILES == true
6735else # BOARD_PREBUILT_BOOTIMAGE is defined
6736	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
6737	$(hide) cp $(INSTALLED_BOOTIMAGE_TARGET) $(zip_root)/PREBUILT_IMAGES/
6738endif # BOARD_PREBUILT_BOOTIMAGE
6739ifdef BOARD_PREBUILT_ODMIMAGE
6740	$(hide) mkdir -p $(zip_root)/IMAGES
6741	$(hide) cp $(INSTALLED_ODMIMAGE_TARGET) $(zip_root)/IMAGES/
6742endif
6743ifdef BOARD_PREBUILT_VENDOR_DLKMIMAGE
6744	$(hide) mkdir -p $(zip_root)/IMAGES
6745	$(hide) cp $(INSTALLED_VENDOR_DLKMIMAGE_TARGET) $(zip_root)/IMAGES/
6746endif
6747ifdef BOARD_PREBUILT_ODM_DLKMIMAGE
6748	$(hide) mkdir -p $(zip_root)/IMAGES
6749	$(hide) cp $(INSTALLED_ODM_DLKMIMAGE_TARGET) $(zip_root)/IMAGES/
6750endif
6751ifdef BOARD_PREBUILT_SYSTEM_DLKMIMAGE
6752	$(hide) mkdir -p $(zip_root)/IMAGES
6753	$(hide) cp $(INSTALLED_SYSTEM_DLKMIMAGE_TARGET) $(zip_root)/IMAGES/
6754endif
6755ifdef BOARD_PREBUILT_DTBOIMAGE
6756	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
6757	$(hide) cp $(INSTALLED_DTBOIMAGE_TARGET) $(zip_root)/PREBUILT_IMAGES/
6758endif # BOARD_PREBUILT_DTBOIMAGE
6759ifdef BUILT_KERNEL_16K_TARGET
6760	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
6761	$(hide) cp $(BUILT_KERNEL_16K_TARGET) $(zip_root)/PREBUILT_IMAGES/
6762endif # BUILT_KERNEL_16K_TARGET
6763ifdef BUILT_RAMDISK_16K_TARGET
6764	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
6765	$(hide) cp $(BUILT_RAMDISK_16K_TARGET) $(zip_root)/PREBUILT_IMAGES/
6766endif # BUILT_RAMDISK_16K_TARGET
6767ifeq ($(BOARD_USES_PVMFWIMAGE),true)
6768	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
6769	$(hide) cp $(INSTALLED_PVMFWIMAGE_TARGET) $(zip_root)/PREBUILT_IMAGES/
6770	$(hide) cp $(INSTALLED_PVMFW_EMBEDDED_AVBKEY_TARGET) $(zip_root)/PREBUILT_IMAGES/
6771	$(hide) mkdir -p $(zip_root)/PVMFW
6772	$(hide) cp $(INSTALLED_PVMFW_BINARY_TARGET) $(zip_root)/PVMFW/
6773endif
6774ifdef BOARD_PREBUILT_BOOTLOADER
6775	$(hide) mkdir -p $(zip_root)/IMAGES
6776	$(hide) cp $(INSTALLED_BOOTLOADER_MODULE) $(zip_root)/IMAGES/
6777endif
6778ifneq ($(strip $(BOARD_CUSTOMIMAGES_PARTITION_LIST)),)
6779	$(hide) mkdir -p $(zip_root)/PREBUILT_IMAGES
6780	$(hide) $(foreach partition,$(BOARD_CUSTOMIMAGES_PARTITION_LIST), \
6781	    $(foreach image,$(BOARD_$(call to-upper,$(partition))_IMAGE_LIST),cp $(image) $(zip_root)/PREBUILT_IMAGES/;))
6782endif # BOARD_CUSTOMIMAGES_PARTITION_LIST
6783	@# The radio images in BOARD_PACK_RADIOIMAGES will be additionally copied from RADIO/ into
6784	@# IMAGES/, which then will be added into <product>-img.zip. Such images must be listed in
6785	@# INSTALLED_RADIOIMAGE_TARGET.
6786	$(hide) $(foreach part,$(BOARD_PACK_RADIOIMAGES), \
6787	    echo $(part) >> $(zip_root)/META/pack_radioimages.txt;)
6788	@# Run fs_config on all the system, vendor, boot ramdisk,
6789	@# and recovery ramdisk files in the zip, and save the output
6790ifdef BUILDING_SYSTEM_IMAGE
6791	$(hide) $(call copy-image-and-generate-map,$(BUILT_SYSTEMIMAGE),$(zip_root)/IMAGES,system)
6792	$(hide) $(call fs_config,$(zip_root)/SYSTEM,system/) > $(zip_root)/META/filesystem_config.txt
6793endif
6794ifdef BUILDING_VENDOR_IMAGE
6795	$(hide) $(call copy-image-and-generate-map,$(BUILT_VENDORIMAGE_TARGET),$(zip_root)/IMAGES,vendor)
6796	$(hide) $(call fs_config,$(zip_root)/VENDOR,vendor/) > $(zip_root)/META/vendor_filesystem_config.txt
6797endif
6798ifdef BUILDING_PRODUCT_IMAGE
6799	$(hide) $(call copy-image-and-generate-map,$(BUILT_PRODUCTIMAGE_TARGET),$(zip_root)/IMAGES,product)
6800	$(hide) $(call fs_config,$(zip_root)/PRODUCT,product/) > $(zip_root)/META/product_filesystem_config.txt
6801endif
6802ifdef BUILDING_SYSTEM_EXT_IMAGE
6803	$(hide) $(call copy-image-and-generate-map,$(BUILT_SYSTEM_EXTIMAGE_TARGET),$(zip_root)/IMAGES,system_ext)
6804	$(hide) $(call fs_config,$(zip_root)/SYSTEM_EXT,system_ext/) > $(zip_root)/META/system_ext_filesystem_config.txt
6805endif
6806ifdef BUILDING_ODM_IMAGE
6807	$(hide) $(call copy-image-and-generate-map,$(BUILT_ODMIMAGE_TARGET),$(zip_root)/IMAGES,odm)
6808	$(hide) $(call fs_config,$(zip_root)/ODM,odm/) > $(zip_root)/META/odm_filesystem_config.txt
6809endif
6810ifdef BUILDING_VENDOR_DLKM_IMAGE
6811	$(hide)$(call copy-image-and-generate-map,$(BUILT_VENDOR_DLKMIMAGE_TARGET),$(zip_root)/IMAGES,vendor_dlkm)
6812	$(hide) $(call fs_config,$(zip_root)/VENDOR_DLKM,vendor_dlkm/) > $(zip_root)/META/vendor_dlkm_filesystem_config.txt
6813endif
6814ifdef BUILDING_ODM_DLKM_IMAGE
6815	$(hide) $(call copy-image-and-generate-map,$(BUILT_ODM_DLKMIMAGE_TARGET),$(zip_root)/IMAGES,odm_dlkm)
6816	$(hide) $(call fs_config,$(zip_root)/ODM_DLKM,odm_dlkm/) > $(zip_root)/META/odm_dlkm_filesystem_config.txt
6817endif
6818ifdef BUILDING_SYSTEM_DLKM_IMAGE
6819	$(hide) $(call copy-image-and-generate-map,$(BUILT_SYSTEM_DLKMIMAGE_TARGET),$(zip_root)/IMAGES,system_dlkm)
6820	$(hide) $(call fs_config,$(zip_root)/SYSTEM_DLKM,system_dlkm/) > $(zip_root)/META/system_dlkm_filesystem_config.txt
6821endif
6822	@# ROOT always contains the files for the root under normal boot.
6823	$(hide) $(call fs_config,$(zip_root)/ROOT,) > $(zip_root)/META/root_filesystem_config.txt
6824	@# BOOT/RAMDISK contains the first stage and recovery ramdisk.
6825	$(hide) $(call fs_config,$(zip_root)/BOOT/RAMDISK,) > $(zip_root)/META/boot_filesystem_config.txt
6826ifdef BUILDING_INIT_BOOT_IMAGE
6827	$(hide) $(call package_files-copy-root, $(TARGET_RAMDISK_OUT),$(zip_root)/INIT_BOOT/RAMDISK)
6828	$(hide) $(call fs_config,$(zip_root)/INIT_BOOT/RAMDISK,) > $(zip_root)/META/init_boot_filesystem_config.txt
6829	$(hide) cp $(RAMDISK_NODE_LIST) $(zip_root)/META/ramdisk_node_list
6830ifdef BOARD_KERNEL_PAGESIZE
6831	$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/INIT_BOOT/pagesize
6832endif # BOARD_KERNEL_PAGESIZE
6833endif # BUILDING_INIT_BOOT_IMAGE
6834ifneq ($(INSTALLED_VENDOR_BOOTIMAGE_TARGET),)
6835	$(call fs_config,$(zip_root)/VENDOR_BOOT/RAMDISK,) > $(zip_root)/META/vendor_boot_filesystem_config.txt
6836endif
6837ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
6838	$(hide) $(call fs_config,$(zip_root)/RECOVERY/RAMDISK,) > $(zip_root)/META/recovery_filesystem_config.txt
6839endif
6840ifdef BUILDING_SYSTEM_OTHER_IMAGE
6841	$(hide) $(call copy-image-and-generate-map,$(BUILT_SYSTEMOTHERIMAGE_TARGET),$(zip_root)/IMAGES)
6842	$(hide) $(call fs_config,$(zip_root)/SYSTEM_OTHER,system/) > $(zip_root)/META/system_other_filesystem_config.txt
6843endif
6844	@# Metadata for compatibility verification.
6845ifdef BUILT_KERNEL_CONFIGS_FILE
6846	$(hide) cp $(BUILT_KERNEL_CONFIGS_FILE) $(zip_root)/META/kernel_configs.txt
6847endif
6848ifdef BUILT_KERNEL_VERSION_FILE
6849	$(hide) cp $(BUILT_KERNEL_VERSION_FILE) $(zip_root)/META/kernel_version.txt
6850endif
6851	rm -rf $(zip_root)/META/dynamic_partitions_info.txt
6852ifeq (true,$(PRODUCT_USE_DYNAMIC_PARTITIONS))
6853	$(call dump-dynamic-partitions-info, $(zip_root)/META/dynamic_partitions_info.txt)
6854endif
6855	PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$$PATH MKBOOTIMG=$(MKBOOTIMG) \
6856	    $(ADD_IMG_TO_TARGET_FILES) -a -v -p $(HOST_OUT) $(zip_root)
6857ifeq ($(BUILD_QEMU_IMAGES),true)
6858	$(hide) AVBTOOL=$(AVBTOOL) $(MK_VBMETA_BOOT_KERNEL_CMDLINE_SH) $(zip_root)/IMAGES/vbmeta.img \
6859	    $(zip_root)/IMAGES/system.img $(zip_root)/IMAGES/VerifiedBootParams.textproto
6860endif
6861	@# Zip everything up, preserving symlinks and placing META/ files first to
6862	@# help early validation of the .zip file while uploading it.
6863	$(hide) find $(zip_root)/META | sort >$@
6864	$(hide) find $(zip_root) -path $(zip_root)/META -prune -o -print | sort >>$@
6865
6866$(BUILT_TARGET_FILES_PACKAGE): $(BUILT_TARGET_FILES_DIR)
6867	@echo "Packaging target files: $@"
6868	$(hide) $(SOONG_ZIP) -d -o $@ -C $(zip_root) -r $@.list -sha256
6869
6870.PHONY: target-files-package
6871target-files-package: $(BUILT_TARGET_FILES_PACKAGE)
6872
6873.PHONY: target-files-dir
6874target-files-dir: $(BUILT_TARGET_FILES_DIR)
6875
6876$(call declare-1p-container,$(BUILT_TARGET_FILES_PACKAGE),)
6877$(call declare-container-license-deps,$(BUILT_TARGET_FILES_PACKAGE), $(INSTALLED_RADIOIMAGE_TARGET) \
6878            $(INSTALLED_RECOVERYIMAGE_TARGET) \
6879            $(INSTALLED_CACHEIMAGE_TARGET) \
6880            $(INSTALLED_DTBOIMAGE_TARGET) \
6881            $(INSTALLED_PVMFWIMAGE_TARGET) \
6882            $(INSTALLED_PVMFW_EMBEDDED_AVBKEY_TARGET) \
6883            $(INSTALLED_CUSTOMIMAGES_TARGET) \
6884            $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
6885            $(INSTALLED_KERNEL_TARGET) \
6886            $(INSTALLED_RAMDISK_TARGET) \
6887            $(INSTALLED_DTBIMAGE_TARGET) \
6888            $(INSTALLED_2NDBOOTLOADER_TARGET) \
6889            $(BOARD_PREBUILT_DTBOIMAGE) \
6890            $(BOARD_PREBUILT_RECOVERY_DTBOIMAGE) \
6891            $(BOARD_RECOVERY_ACPIO) \
6892            $(PRODUCT_SYSTEM_BASE_FS_PATH) \
6893            $(PRODUCT_VENDOR_BASE_FS_PATH) \
6894            $(PRODUCT_PRODUCT_BASE_FS_PATH) \
6895            $(PRODUCT_SYSTEM_EXT_BASE_FS_PATH) \
6896            $(PRODUCT_ODM_BASE_FS_PATH) \
6897            $(PRODUCT_VENDOR_DLKM_BASE_FS_PATH) \
6898            $(PRODUCT_ODM_DLKM_BASE_FS_PATH) \
6899            $(PRODUCT_SYSTEM_DLKM_BASE_FS_PATH) \
6900            $(LPMAKE) \
6901            $(SELINUX_FC) \
6902            $(INSTALLED_MISC_INFO_TARGET) \
6903            $(INSTALLED_FASTBOOT_INFO_TARGET) \
6904            $(APKCERTS_FILE) \
6905            $(APEX_KEYS_FILE) \
6906            $(HOST_OUT_EXECUTABLES)/fs_config \
6907            $(HOST_OUT_EXECUTABLES)/map_file_generator \
6908            $(ADD_IMG_TO_TARGET_FILES) \
6909            $(MAKE_RECOVERY_PATCH) \
6910            $(BUILT_KERNEL_CONFIGS_FILE) \
6911            $(BUILT_KERNEL_VERSION_FILE),$(BUILT_TARGET_FILES_PACKAGE):)
6912
6913$(call dist-for-goals-with-filenametag, target-files-package, $(BUILT_TARGET_FILES_PACKAGE))
6914
6915# -----------------------------------------------------------------
6916# NDK Sysroot Package
6917NDK_SYSROOT_TARGET := $(PRODUCT_OUT)/ndk_sysroot.tar.bz2
6918.PHONY: ndk_sysroot
6919ndk_sysroot: $(NDK_SYSROOT_TARGET)
6920$(NDK_SYSROOT_TARGET): $(SOONG_OUT_DIR)/ndk.timestamp
6921	@echo Package NDK sysroot...
6922	$(hide) tar cjf $@ -C $(SOONG_OUT_DIR) ndk
6923
6924ifeq ($(HOST_OS),linux)
6925$(call dist-for-goals,sdk ndk_sysroot,$(NDK_SYSROOT_TARGET))
6926endif
6927
6928ifeq ($(build_ota_package),true)
6929# -----------------------------------------------------------------
6930# OTA update package
6931
6932# $(1): output file
6933# $(2): additional args
6934define build-ota-package-target
6935PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$(dir $(ZIP2ZIP)):$$PATH \
6936    $(OTA_FROM_TARGET_FILES) \
6937        --verbose \
6938        --path $(HOST_OUT) \
6939        $(if $(OEM_OTA_CONFIG), --oem_settings $(OEM_OTA_CONFIG)) \
6940        $(if $(BOOT_VAR_OTA_CONFIG), --boot_variable_file $(BOOT_VAR_OTA_CONFIG)) \
6941        $(2) \
6942        $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE)) $(1)
6943endef
6944
6945product_name := $(TARGET_PRODUCT)
6946ifeq ($(TARGET_BUILD_TYPE),debug)
6947  product_name := $(product_name)_debug
6948endif
6949name := $(product_name)-ota
6950
6951INTERNAL_OTA_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
6952INTERNAL_OTA_METADATA := $(PRODUCT_OUT)/ota_metadata
6953
6954$(call declare-0p-target,$(INTERNAL_OTA_METADATA))
6955
6956$(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
6957$(INTERNAL_OTA_PACKAGE_TARGET): .KATI_IMPLICIT_OUTPUTS := $(INTERNAL_OTA_METADATA)
6958$(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_DIR) $(OTA_FROM_TARGET_FILES) $(INTERNAL_OTATOOLS_FILES)
6959	@echo "Package OTA: $@"
6960	$(call build-ota-package-target,$@,-k $(KEY_CERT_PAIR) --output_metadata_path $(INTERNAL_OTA_METADATA))
6961
6962$(call declare-1p-container,$(INTERNAL_OTA_PACKAGE_TARGET),)
6963$(call declare-container-license-deps,$(INTERNAL_OTA_PACKAGE_TARGET),$(BUILT_TARGET_FILES_PACKAGE) $(OTA_FROM_TARGET_FILES) $(INTERNAL_OTATOOLS_FILES),$(PRODUCT_OUT)/:/)
6964
6965.PHONY: otapackage
6966otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)
6967
6968ifeq ($(BOARD_BUILD_RETROFIT_DYNAMIC_PARTITIONS_OTA_PACKAGE),true)
6969name := $(product_name)-ota-retrofit
6970
6971INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
6972$(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
6973$(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET): \
6974    $(BUILT_TARGET_FILES_PACKAGE) \
6975    $(OTA_FROM_TARGET_FILES) \
6976    $(INTERNAL_OTATOOLS_FILES)
6977	@echo "Package OTA (retrofit dynamic partitions): $@"
6978	$(call build-ota-package-target,$@,-k $(KEY_CERT_PAIR) --retrofit_dynamic_partitions)
6979
6980$(call declare-1p-container,$(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET),)
6981$(call declare-container-license-deps,$(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET),$(BUILT_TARGET_FILES_PACKAGE) $(OTA_FROM_TARGET_FILES) $(INTERNAL_OTATOOLS_FILES),$(PRODUCT_OUT)/:/)
6982
6983.PHONY: otardppackage
6984
6985otapackage otardppackage: $(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET)
6986
6987endif # BOARD_BUILD_RETROFIT_DYNAMIC_PARTITIONS_OTA_PACKAGE
6988
6989ifneq ($(BOARD_PARTIAL_OTA_UPDATE_PARTITIONS_LIST),)
6990name := $(product_name)-partial-ota
6991
6992INTERNAL_OTA_PARTIAL_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
6993$(INTERNAL_OTA_PARTIAL_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
6994$(INTERNAL_OTA_PARTIAL_PACKAGE_TARGET): $(BUILT_TARGET_FILES_DIR) $(OTA_FROM_TARGET_FILES) $(INTERNAL_OTATOOLS_FILES)
6995	@echo "Package partial OTA: $@"
6996	$(call build-ota-package-target,$@,-k $(KEY_CERT_PAIR) --partial "$(BOARD_PARTIAL_OTA_UPDATE_PARTITIONS_LIST)")
6997
6998$(call declare-1p-container,$(INTERNAL_OTA_PARTIAL_PACKAGE_TARGET),)
6999$(call declare-container-license-deps,$(INTERNAL_OTA_PARTIAL_PACKAGE_TARGET),$(BUILT_TARGET_FILES_PACKAGE) $(OTA_FROM_TARGET_FILES) $(INTERNAL_OTATOOLS_FILES),$(PRODUCT_OUT)/:/)
7000
7001
7002.PHONY: partialotapackage
7003partialotapackage: $(INTERNAL_OTA_PARTIAL_PACKAGE_TARGET)
7004
7005endif # BOARD_PARTIAL_OTA_UPDATE_PARTITIONS_LIST
7006
7007endif    # build_ota_package
7008
7009# -----------------------------------------------------------------
7010# A zip of the appcompat directory containing logs
7011APPCOMPAT_ZIP := $(PRODUCT_OUT)/appcompat.zip
7012# For apps_only build we'll establish the dependency later in build/make/core/main.mk.
7013ifeq (,$(TARGET_BUILD_UNBUNDLED))
7014$(APPCOMPAT_ZIP): $(FULL_SYSTEMIMAGE_DEPS) \
7015	    $(INTERNAL_RAMDISK_FILES) \
7016	    $(INTERNAL_USERDATAIMAGE_FILES) \
7017	    $(INTERNAL_VENDORIMAGE_FILES) \
7018	    $(INTERNAL_PRODUCTIMAGE_FILES) \
7019	    $(INTERNAL_SYSTEM_EXTIMAGE_FILES)
7020endif
7021$(APPCOMPAT_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,appcompat)/filelist
7022$(APPCOMPAT_ZIP): $(SOONG_ZIP)
7023	@echo "appcompat logs: $@"
7024	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
7025	$(hide) mkdir -p $(dir $@) $(PRODUCT_OUT)/appcompat $(dir $(PRIVATE_LIST_FILE))
7026	$(hide) find $(PRODUCT_OUT)/appcompat | sort >$(PRIVATE_LIST_FILE)
7027	$(hide) $(SOONG_ZIP) -d -o $@ -C $(PRODUCT_OUT)/appcompat -l $(PRIVATE_LIST_FILE)
7028
7029# The mac build doesn't build dex2oat, so create the zip file only if the build OS is linux.
7030ifeq ($(BUILD_OS),linux)
7031ifneq ($(DEX2OAT),)
7032dexpreopt_tools_deps := $(DEXPREOPT_GEN_DEPS) $(DEXPREOPT_GEN)
7033dexpreopt_tools_deps += $(HOST_OUT_EXECUTABLES)/dexdump
7034dexpreopt_tools_deps += $(HOST_OUT_EXECUTABLES)/oatdump
7035DEXPREOPT_TOOLS_ZIP := $(PRODUCT_OUT)/dexpreopt_tools.zip
7036$(DEXPREOPT_TOOLS_ZIP): $(dexpreopt_tools_deps)
7037$(DEXPREOPT_TOOLS_ZIP): PRIVATE_DEXPREOPT_TOOLS_DEPS := $(dexpreopt_tools_deps)
7038$(DEXPREOPT_TOOLS_ZIP): $(SOONG_ZIP)
7039	$(hide) mkdir -p $(dir $@)
7040	$(hide) $(SOONG_ZIP) -d -o $@ -j $(addprefix -f ,$(PRIVATE_DEXPREOPT_TOOLS_DEPS)) -f $$(realpath $(DEX2OAT))
7041$(call declare-1p-target,$(DEXPREOPT_TOOLS_ZIP),)
7042endif # DEX2OAT is set
7043endif # BUILD_OS == linux
7044
7045DEXPREOPT_CONFIG_ZIP := $(PRODUCT_OUT)/dexpreopt_config.zip
7046
7047$(DEXPREOPT_CONFIG_ZIP): $(INSTALLED_SYSTEMIMAGE_TARGET) \
7048    $(INSTALLED_VENDORIMAGE_TARGET) \
7049    $(INSTALLED_ODMIMAGE_TARGET) \
7050    $(INSTALLED_PRODUCTIMAGE_TARGET) \
7051
7052ifeq (,$(TARGET_BUILD_UNBUNDLED))
7053$(DEXPREOPT_CONFIG_ZIP): $(DEX_PREOPT_CONFIG_FOR_MAKE) \
7054	  $(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE) \
7055
7056endif
7057
7058$(DEXPREOPT_CONFIG_ZIP): PRIVATE_DEXPREOPT_CONFIG_ZIP_PARAMS :=
7059ifeq (,$(TARGET_BUILD_UNBUNDLED))
7060ifneq (,$(DEX_PREOPT_CONFIG_FOR_MAKE))
7061$(DEXPREOPT_CONFIG_ZIP): PRIVATE_DEXPREOPT_CONFIG_ZIP_PARAMS += -e $(notdir $(DEX_PREOPT_CONFIG_FOR_MAKE)) -f $(DEX_PREOPT_CONFIG_FOR_MAKE)
7062endif
7063ifneq (,$(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE))
7064$(DEXPREOPT_CONFIG_ZIP): PRIVATE_DEXPREOPT_CONFIG_ZIP_PARAMS += -e $(notdir $(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE)) -f $(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE)
7065endif
7066endif #!TARGET_BUILD_UNBUNDLED
7067
7068$(DEXPREOPT_CONFIG_ZIP): $(SOONG_ZIP)
7069	$(hide) mkdir -p $(dir $@) $(PRODUCT_OUT)/dexpreopt_config
7070	$(hide) $(SOONG_ZIP) -d -o $@ -C $(PRODUCT_OUT)/dexpreopt_config -D $(PRODUCT_OUT)/dexpreopt_config $(PRIVATE_DEXPREOPT_CONFIG_ZIP_PARAMS)
7071
7072.PHONY: dexpreopt_config_zip
7073dexpreopt_config_zip: $(DEXPREOPT_CONFIG_ZIP)
7074
7075$(call declare-1p-target,$(DEXPREOPT_CONFIG_ZIP),)
7076
7077# -----------------------------------------------------------------
7078# A zip of the symbols directory.  Keep the full paths to make it
7079# more obvious where these files came from.
7080# Also produces a textproto containing mappings from elf IDs to symbols
7081# filename, which will allow finding the appropriate symbols to deobfuscate
7082# a stack trace frame.
7083#
7084
7085name := $(TARGET_PRODUCT)
7086ifeq ($(TARGET_BUILD_TYPE),debug)
7087  name := $(name)_debug
7088endif
7089
7090# The path to the zip file containing binaries with symbols.
7091SYMBOLS_ZIP := $(PRODUCT_OUT)/$(name)-symbols.zip
7092# The path to a file containing mappings from elf IDs to filenames.
7093SYMBOLS_MAPPING := $(PRODUCT_OUT)/$(name)-symbols-mapping.textproto
7094.KATI_READONLY := SYMBOLS_ZIP SYMBOLS_MAPPING
7095# For apps_only build we'll establish the dependency later in build/make/core/main.mk.
7096ifeq (,$(TARGET_BUILD_UNBUNDLED))
7097$(SYMBOLS_ZIP): $(INTERNAL_ALLIMAGES_FILES) $(updater_dep)
7098endif
7099$(SYMBOLS_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,symbols)/filelist
7100$(SYMBOLS_ZIP): PRIVATE_MAPPING_PACKAGING_DIR := $(call intermediates-dir-for,PACKAGING,elf_symbol_mapping)
7101$(SYMBOLS_ZIP): $(SOONG_ZIP) $(SYMBOLS_MAP)
7102	@echo "Package symbols: $@"
7103	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
7104	$(hide) mkdir -p $(TARGET_OUT_UNSTRIPPED) $(dir $(PRIVATE_LIST_FILE)) $(PRIVATE_MAPPING_PACKAGING_DIR)
7105	# Find all of the files in the symbols directory and zip them into the symbols zip.
7106	$(hide) find -L $(TARGET_OUT_UNSTRIPPED) -type f | sort >$(PRIVATE_LIST_FILE)
7107	$(hide) $(SOONG_ZIP) --ignore_missing_files -d -o $@ -C $(OUT_DIR)/.. -l $(PRIVATE_LIST_FILE)
7108	# Find all of the files in the symbols mapping directory and merge them into the symbols mapping textproto.
7109	$(hide) find -L $(PRIVATE_MAPPING_PACKAGING_DIR) -type f | sort >$(PRIVATE_LIST_FILE)
7110	$(hide) $(SYMBOLS_MAP) -merge $(SYMBOLS_MAPPING) -ignore_missing_files @$(PRIVATE_LIST_FILE)
7111$(SYMBOLS_ZIP): .KATI_IMPLICIT_OUTPUTS := $(SYMBOLS_MAPPING)
7112
7113$(call declare-1p-container,$(SYMBOLS_ZIP),)
7114ifeq (,$(TARGET_BUILD_UNBUNDLED))
7115$(call declare-container-license-deps,$(SYMBOLS_ZIP),$(INTERNAL_ALLIMAGES_FILES) $(updater_dep),$(PRODUCT_OUT)/:/)
7116endif
7117
7118# -----------------------------------------------------------------
7119# A zip of the coverage directory.
7120#
7121name := gcov-report-files-all
7122ifeq ($(TARGET_BUILD_TYPE),debug)
7123name := $(name)_debug
7124endif
7125COVERAGE_ZIP := $(PRODUCT_OUT)/$(name).zip
7126ifeq (,$(TARGET_BUILD_UNBUNDLED))
7127$(COVERAGE_ZIP): $(INTERNAL_ALLIMAGES_FILES)
7128endif
7129$(COVERAGE_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,coverage)/filelist
7130$(COVERAGE_ZIP): $(SOONG_ZIP)
7131	@echo "Package coverage: $@"
7132	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
7133	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_COVERAGE) $(dir $(PRIVATE_LIST_FILE))
7134	$(hide) find $(TARGET_OUT_COVERAGE) | sort >$(PRIVATE_LIST_FILE)
7135	$(hide) $(SOONG_ZIP) -d -o $@ -C $(TARGET_OUT_COVERAGE) -l $(PRIVATE_LIST_FILE)
7136
7137$(call declare-1p-container,$(COVERAGE_ZIP),)
7138ifeq (,$(TARGET_BUILD_UNBUNDLED))
7139$(call declare-container-license-deps,$(COVERAGE_ZIP),$(INTERNAL_ALLIMAGE_FILES),$(PRODUCT_OUT)/:/)
7140endif
7141
7142SYSTEM_NOTICE_DEPS += $(COVERAGE_ZIP)
7143
7144#------------------------------------------------------------------
7145# Export the LLVM profile data tool and dependencies for Clang coverage processing
7146#
7147ifeq (true,$(CLANG_COVERAGE))
7148  LLVM_PROFDATA := $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/bin/llvm-profdata
7149  LLVM_COV := $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/bin/llvm-cov
7150  LIBCXX := $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/lib/x86_64-unknown-linux-gnu/libc++.so
7151  # Use llvm-profdata.zip for backwards compatibility with tradefed code.
7152  LLVM_COVERAGE_TOOLS_ZIP := $(PRODUCT_OUT)/llvm-profdata.zip
7153
7154  $(LLVM_COVERAGE_TOOLS_ZIP): $(SOONG_ZIP)
7155	$(hide) $(SOONG_ZIP) -d -o $@ -C $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION) -f $(LLVM_PROFDATA) -f $(LIBCXX) -f $(LLVM_COV)
7156
7157  $(call dist-for-goals,droidcore-unbundled apps_only,$(LLVM_COVERAGE_TOOLS_ZIP))
7158endif
7159
7160# -----------------------------------------------------------------
7161# A zip of the Android Apps. Not keeping full path so that we don't
7162# include product names when distributing
7163#
7164name := $(TARGET_PRODUCT)
7165ifeq ($(TARGET_BUILD_TYPE),debug)
7166  name := $(name)_debug
7167endif
7168name := $(name)-apps
7169
7170APPS_ZIP := $(PRODUCT_OUT)/$(name).zip
7171$(APPS_ZIP): $(FULL_SYSTEMIMAGE_DEPS)
7172	@echo "Package apps: $@"
7173	$(hide) rm -rf $@
7174	$(hide) mkdir -p $(dir $@)
7175	$(hide) apps_to_zip=`find $(TARGET_OUT_APPS) $(TARGET_OUT_APPS_PRIVILEGED) -mindepth 2 -maxdepth 3 -name "*.apk"`; \
7176	if [ -z "$$apps_to_zip" ]; then \
7177	    echo "No apps to zip up. Generating empty apps archive." ; \
7178	    a=$$(mktemp /tmp/XXXXXXX) && touch $$a && zip $@ $$a && zip -d $@ $$a; \
7179	else \
7180	    zip -qjX $@ $$apps_to_zip; \
7181	fi
7182
7183ifeq (true,$(EMMA_INSTRUMENT))
7184#------------------------------------------------------------------
7185# An archive of classes for use in generating code-coverage reports
7186# These are the uninstrumented versions of any classes that were
7187# to be instrumented.
7188# Any dependencies are set up later in build/make/core/main.mk.
7189
7190JACOCO_REPORT_CLASSES_ALL := $(PRODUCT_OUT)/jacoco-report-classes-all.jar
7191$(JACOCO_REPORT_CLASSES_ALL): PRIVATE_TARGET_JACOCO_DIR := $(call intermediates-dir-for,PACKAGING,jacoco)
7192$(JACOCO_REPORT_CLASSES_ALL): PRIVATE_HOST_JACOCO_DIR := $(call intermediates-dir-for,PACKAGING,jacoco,HOST)
7193$(JACOCO_REPORT_CLASSES_ALL): PRIVATE_TARGET_PROGUARD_USAGE_DIR := $(call intermediates-dir-for,PACKAGING,proguard_usage)
7194$(JACOCO_REPORT_CLASSES_ALL): PRIVATE_HOST_PROGUARD_USAGE_DIR := $(call intermediates-dir-for,PACKAGING,proguard_usage,HOST)
7195$(JACOCO_REPORT_CLASSES_ALL) :
7196	@echo "Collecting uninstrumented classes"
7197	mkdir -p $(PRIVATE_TARGET_JACOCO_DIR) $(PRIVATE_HOST_JACOCO_DIR) $(PRIVATE_TARGET_PROGUARD_USAGE_DIR) $(PRIVATE_HOST_PROGUARD_USAGE_DIR)
7198	$(SOONG_ZIP) -o $@ -L 0 \
7199	  -C $(PRIVATE_TARGET_JACOCO_DIR) -P out/target/common/obj -D $(PRIVATE_TARGET_JACOCO_DIR) \
7200	  -C $(PRIVATE_HOST_JACOCO_DIR) -P out/target/common/obj -D $(PRIVATE_HOST_JACOCO_DIR) \
7201	  -C $(PRIVATE_TARGET_PROGUARD_USAGE_DIR) -P out/target/common/obj -D $(PRIVATE_TARGET_PROGUARD_USAGE_DIR) \
7202	  -C $(PRIVATE_HOST_PROGUARD_USAGE_DIR) -P out/target/common/obj -D $(PRIVATE_HOST_PROGUARD_USAGE_DIR)
7203
7204ifeq (,$(TARGET_BUILD_UNBUNDLED))
7205  $(JACOCO_REPORT_CLASSES_ALL): $(INTERNAL_ALLIMAGES_FILES)
7206endif
7207
7208# This is not ideal, but it is difficult to correctly figure out the actual jacoco report
7209# jars we need to add here as dependencies, so we add the device-tests as a dependency when
7210# the env variable is set and this should guarantee thaat all the jacoco report jars are ready
7211# when we package the final report jar here.
7212ifeq ($(JACOCO_PACKAGING_INCLUDE_DEVICE_TESTS),true)
7213  $(JACOCO_REPORT_CLASSES_ALL): $(COMPATIBILITY.device-tests.FILES)
7214endif
7215endif # EMMA_INSTRUMENT=true
7216
7217
7218#------------------------------------------------------------------
7219# A zip of Proguard obfuscation dictionary files.
7220# Also produces a textproto containing mappings from the hashes of the
7221# dictionary contents (which are also stored in the dex files on the
7222# devices) to the filename of the proguard dictionary, which will allow
7223# finding the appropriate dictionary to deobfuscate a stack trace frame.
7224#
7225
7226ifeq (,$(TARGET_BUILD_UNBUNDLED))
7227  _proguard_dict_zip_modules := $(call product-installed-modules,$(INTERNAL_PRODUCT))
7228else
7229  _proguard_dict_zip_modules := $(unbundled_build_modules)
7230endif
7231
7232# The path to the zip file containing proguard dictionaries.
7233PROGUARD_DICT_ZIP :=$= $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict.zip
7234$(PROGUARD_DICT_ZIP): PRIVATE_SOONG_ZIP_ARGUMENTS := $(foreach m,$(_proguard_dict_zip_modules),$(ALL_MODULES.$(m).PROGUARD_DICTIONARY_SOONG_ZIP_ARGUMENTS))
7235$(PROGUARD_DICT_ZIP): $(SOONG_ZIP) $(foreach m,$(_proguard_dict_zip_modules),$(ALL_MODULES.$(m).PROGUARD_DICTIONARY_FILES))
7236	@echo "Packaging Proguard obfuscation dictionary files."
7237	# Zip all of the files in PROGUARD_DICTIONARY_FILES.
7238	echo -n > $@.tmparglist
7239	$(foreach arg,$(PRIVATE_SOONG_ZIP_ARGUMENTS),printf "%s\n" "$(arg)" >> $@.tmparglist$(newline))
7240	$(SOONG_ZIP) -d -o $@ @$@.tmparglist
7241	rm -f $@.tmparglist
7242
7243# The path to the zip file containing mappings from dictionary hashes to filenames.
7244PROGUARD_DICT_MAPPING :=$= $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-mapping.textproto
7245_proguard_dict_mapping_files := $(foreach m,$(_proguard_dict_zip_modules),$(ALL_MODULES.$(m).PROGUARD_DICTIONARY_MAPPING))
7246$(PROGUARD_DICT_MAPPING): PRIVATE_MAPPING_FILES := $(_proguard_dict_mapping_files)
7247$(PROGUARD_DICT_MAPPING): $(SYMBOLS_MAP) $(_proguard_dict_mapping_files)
7248	@echo "Packaging Proguard obfuscation dictionary mapping files."
7249	# Merge all the mapping files together
7250	echo -n > $@.tmparglist
7251	$(foreach mf,$(PRIVATE_MAPPING_FILES),echo "$(mf)" >> $@.tmparglist$(newline))
7252	$(SYMBOLS_MAP) -merge $(PROGUARD_DICT_MAPPING) @$@.tmparglist
7253	rm -f $@.tmparglist
7254
7255$(call declare-1p-container,$(PROGUARD_DICT_ZIP),)
7256ifeq (,$(TARGET_BUILD_UNBUNDLED))
7257$(call declare-container-license-deps,$(PROGUARD_DICT_ZIP),$(INTERNAL_ALLIMAGES_FILES) $(updater_dep),$(PRODUCT_OUT)/:/)
7258endif
7259
7260#------------------------------------------------------------------
7261# A zip of Proguard usage files.
7262#
7263PROGUARD_USAGE_ZIP :=$= $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-usage.zip
7264_proguard_usage_zips := $(foreach m,$(_proguard_dict_zip_modules),$(ALL_MODULES.$(m).PROGUARD_USAGE_ZIP))
7265$(PROGUARD_USAGE_ZIP): PRIVATE_ZIPS := $(_proguard_usage_zips)
7266$(PROGUARD_USAGE_ZIP): $(MERGE_ZIPS) $(_proguard_usage_zips)
7267	@echo "Packaging Proguard usage files."
7268	echo -n > $@.tmparglist
7269	$(foreach z,$(PRIVATE_ZIPS),echo "$(z)" >> $@.tmparglist$(newline))
7270	$(MERGE_ZIPS) $@ @$@.tmparglist
7271	rm -rf $@.tmparglist
7272
7273_proguard_dict_mapping_files :=
7274_proguard_usage_zips :=
7275_proguard_dict_zip_modules :=
7276
7277$(call declare-1p-container,$(PROGUARD_USAGE_ZIP),)
7278ifeq (,$(TARGET_BUILD_UNBUNDLED))
7279$(call declare-container-license-deps,$(PROGUARD_USAGE_ZIP),$(INSTALLED_SYSTEMIMAGE_TARGET) \
7280    $(INSTALLED_RAMDISK_TARGET) \
7281    $(INSTALLED_BOOTIMAGE_TARGET) \
7282    $(INSTALLED_INIT_BOOT_IMAGE_TARGET) \
7283    $(INSTALLED_USERDATAIMAGE_TARGET) \
7284    $(INSTALLED_VENDORIMAGE_TARGET) \
7285    $(INSTALLED_PRODUCTIMAGE_TARGET) \
7286    $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) \
7287    $(INSTALLED_ODMIMAGE_TARGET) \
7288    $(INSTALLED_VENDOR_DLKMIMAGE_TARGET) \
7289    $(INSTALLED_ODM_DLKMIMAGE_TARGET) \
7290    $(INSTALLED_SYSTEM_DLKMIMAGE_TARGET) \
7291    $(updater_dep),$(PROGUARD_USAGE_ZIP):/)
7292endif
7293
7294ifeq (true,$(PRODUCT_USE_DYNAMIC_PARTITIONS))
7295
7296# Dump variables used by build_super_image.py (for building super.img and super_empty.img).
7297# $(1): output file
7298define dump-super-image-info
7299  $(call dump-dynamic-partitions-info,$(1))
7300  $(if $(filter true,$(AB_OTA_UPDATER)), \
7301    echo "ab_update=true" >> $(1))
7302endef
7303
7304endif # PRODUCT_USE_DYNAMIC_PARTITIONS
7305
7306# -----------------------------------------------------------------
7307# super partition image (dist)
7308
7309ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
7310
7311# BOARD_SUPER_PARTITION_SIZE must be defined to build super image.
7312ifneq ($(BOARD_SUPER_PARTITION_SIZE),)
7313
7314ifneq (true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS))
7315
7316# For real devices and for dist builds, build super image from target files to an intermediate directory.
7317INTERNAL_SUPERIMAGE_DIST_TARGET := $(call intermediates-dir-for,PACKAGING,super.img)/super.img
7318$(INTERNAL_SUPERIMAGE_DIST_TARGET): extracted_input_target_files := $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE))
7319$(INTERNAL_SUPERIMAGE_DIST_TARGET): $(LPMAKE) $(BUILT_TARGET_FILES_DIR) $(BUILD_SUPER_IMAGE)
7320	$(call pretty,"Target super fs image from target files: $@")
7321	PATH=$(dir $(LPMAKE)):$$PATH \
7322	    $(BUILD_SUPER_IMAGE) -v $(extracted_input_target_files) $@
7323
7324# Skip packing it in dist package because it is in update package.
7325ifneq (true,$(BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE))
7326$(call dist-for-goals,dist_files,$(INTERNAL_SUPERIMAGE_DIST_TARGET))
7327endif
7328
7329.PHONY: superimage_dist
7330superimage_dist: $(INTERNAL_SUPERIMAGE_DIST_TARGET)
7331
7332endif # PRODUCT_RETROFIT_DYNAMIC_PARTITIONS != "true"
7333endif # BOARD_SUPER_PARTITION_SIZE != ""
7334endif # PRODUCT_BUILD_SUPER_PARTITION == "true"
7335
7336# -----------------------------------------------------------------
7337# super partition image for development
7338
7339ifeq (true,$(PRODUCT_BUILD_SUPER_PARTITION))
7340ifneq ($(BOARD_SUPER_PARTITION_SIZE),)
7341ifneq (true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS))
7342
7343# Build super.img by using $(INSTALLED_*IMAGE_TARGET) to $(1)
7344# $(1): built image path
7345# $(2): misc_info.txt path; its contents should match expectation of build_super_image.py
7346define build-superimage-target
7347  mkdir -p $(dir $(2))
7348  rm -rf $(2)
7349  $(call dump-super-image-info,$(2))
7350  $(foreach p,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
7351    echo "$(p)_image=$(INSTALLED_$(call to-upper,$(p))IMAGE_TARGET)" >> $(2);)
7352  $(if $(BUILDING_SYSTEM_OTHER_IMAGE), $(if $(filter system,$(BOARD_SUPER_PARTITION_PARTITION_LIST)), \
7353    echo "system_other_image=$(INSTALLED_SYSTEMOTHERIMAGE_TARGET)" >> $(2);))
7354  mkdir -p $(dir $(1))
7355  PATH=$(dir $(LPMAKE)):$$PATH \
7356    $(BUILD_SUPER_IMAGE) -v $(2) $(1)
7357endef
7358
7359INSTALLED_SUPERIMAGE_TARGET := $(PRODUCT_OUT)/super.img
7360INSTALLED_SUPERIMAGE_DEPENDENCIES := $(LPMAKE) $(BUILD_SUPER_IMAGE) \
7361    $(foreach p, $(BOARD_SUPER_PARTITION_PARTITION_LIST), $(INSTALLED_$(call to-upper,$(p))IMAGE_TARGET))
7362
7363ifdef BUILDING_SYSTEM_OTHER_IMAGE
7364ifneq ($(filter system,$(BOARD_SUPER_PARTITION_PARTITION_LIST)),)
7365INSTALLED_SUPERIMAGE_DEPENDENCIES += $(INSTALLED_SYSTEMOTHERIMAGE_TARGET)
7366endif
7367endif
7368
7369$(INSTALLED_SUPERIMAGE_TARGET): $(INSTALLED_SUPERIMAGE_DEPENDENCIES)
7370	$(call pretty,"Target super fs image for debug: $@")
7371	$(call build-superimage-target,$(INSTALLED_SUPERIMAGE_TARGET),\
7372          $(call intermediates-dir-for,PACKAGING,superimage_debug)/misc_info.txt)
7373
7374# For devices that uses super image directly, the superimage target points to the file in $(PRODUCT_OUT).
7375.PHONY: superimage
7376superimage: $(INSTALLED_SUPERIMAGE_TARGET)
7377
7378# If BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT is set, super.img is built from images in the
7379# $(PRODUCT_OUT) directory, and is built to $(PRODUCT_OUT)/super.img. Also, it will
7380# be built for non-dist builds. This is useful for devices that uses super.img directly, e.g.
7381# virtual devices.
7382ifeq (true,$(BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT))
7383droidcore-unbundled: $(INSTALLED_SUPERIMAGE_TARGET)
7384
7385$(call dist-for-goals,dist_files,$(INSTALLED_MISC_INFO_TARGET):super_misc_info.txt)
7386endif # BOARD_BUILD_SUPER_IMAGE_BY_DEFAULT
7387
7388# Build $(PRODUCT_OUT)/super.img without dependencies.
7389.PHONY: superimage-nodeps supernod
7390superimage-nodeps supernod: intermediates :=
7391superimage-nodeps supernod: | $(INSTALLED_SUPERIMAGE_DEPENDENCIES)
7392	$(call pretty,"make $(INSTALLED_SUPERIMAGE_TARGET): ignoring dependencies")
7393	$(call build-superimage-target,$(INSTALLED_SUPERIMAGE_TARGET),\
7394	  $(call intermediates-dir-for,PACKAGING,superimage-nodeps)/misc_info.txt)
7395
7396endif # PRODUCT_RETROFIT_DYNAMIC_PARTITIONS != "true"
7397endif # BOARD_SUPER_PARTITION_SIZE != ""
7398endif # PRODUCT_BUILD_SUPER_PARTITION == "true"
7399
7400# -----------------------------------------------------------------
7401# super empty image
7402ifdef BUILDING_SUPER_EMPTY_IMAGE
7403
7404INSTALLED_SUPERIMAGE_EMPTY_TARGET := $(PRODUCT_OUT)/super_empty.img
7405$(INSTALLED_SUPERIMAGE_EMPTY_TARGET): intermediates := $(call intermediates-dir-for,PACKAGING,super_empty)
7406$(INSTALLED_SUPERIMAGE_EMPTY_TARGET): $(LPMAKE) $(BUILD_SUPER_IMAGE)
7407	$(call pretty,"Target empty super fs image: $@")
7408	mkdir -p $(intermediates)
7409	rm -rf $(intermediates)/misc_info.txt
7410	$(call dump-super-image-info,$(intermediates)/misc_info.txt)
7411	PATH=$(dir $(LPMAKE)):$$PATH \
7412	    $(BUILD_SUPER_IMAGE) -v $(intermediates)/misc_info.txt $@
7413
7414$(call dist-for-goals,dist_files,$(INSTALLED_SUPERIMAGE_EMPTY_TARGET))
7415
7416$(call declare-0p-target,$(INSTALLED_SUPERIMAGE_EMPTY_TARGET))
7417
7418endif # BUILDING_SUPER_EMPTY_IMAGE
7419
7420
7421# -----------------------------------------------------------------
7422# The update package
7423
7424name := $(TARGET_PRODUCT)
7425ifeq ($(TARGET_BUILD_TYPE),debug)
7426  name := $(name)_debug
7427endif
7428name := $(name)-img
7429
7430INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
7431
7432$(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(IMG_FROM_TARGET_FILES)
7433	$(call pretty,"Package: $@")
7434	PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$(dir $(ZIP2ZIP)):$$PATH \
7435	    $(IMG_FROM_TARGET_FILES) \
7436	        --additional IMAGES/VerifiedBootParams.textproto:VerifiedBootParams.textproto \
7437	        --build_super_image $(BUILD_SUPER_IMAGE) \
7438	        $(BUILT_TARGET_FILES_PACKAGE) $@
7439
7440$(call declare-1p-container,$(INTERNAL_UPDATE_PACKAGE_TARGET),)
7441$(call declare-container-license-deps,$(INTERNAL_UPDATE_PACKAGE_TARGET),$(BUILT_TARGET_FILES_PACKAGE) $(IMG_FROM_TARGET_FILES),$(PRODUCT_OUT)/:/)
7442
7443.PHONY: updatepackage
7444updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
7445$(call dist-for-goals-with-filenametag,updatepackage,$(INTERNAL_UPDATE_PACKAGE_TARGET))
7446
7447
7448# -----------------------------------------------------------------
7449# dalvik something
7450.PHONY: dalvikfiles
7451dalvikfiles: $(INTERNAL_DALVIK_MODULES)
7452
7453ifeq ($(BUILD_QEMU_IMAGES),true)
7454MK_QEMU_IMAGE_SH := device/generic/goldfish/tools/mk_qemu_image.sh
7455MK_COMBINE_QEMU_IMAGE := $(HOST_OUT_EXECUTABLES)/mk_combined_img
7456SGDISK_HOST := $(HOST_OUT_EXECUTABLES)/sgdisk
7457
7458ifdef INSTALLED_SYSTEMIMAGE_TARGET
7459INSTALLED_QEMU_SYSTEMIMAGE := $(PRODUCT_OUT)/system-qemu.img
7460INSTALLED_SYSTEM_QEMU_CONFIG := $(PRODUCT_OUT)/system-qemu-config.txt
7461$(INSTALLED_SYSTEM_QEMU_CONFIG): $(INSTALLED_SUPERIMAGE_TARGET) $(INSTALLED_VBMETAIMAGE_TARGET)
7462	@echo "$(PRODUCT_OUT)/vbmeta.img vbmeta 1" > $@
7463	@echo "$(INSTALLED_SUPERIMAGE_TARGET) super 2" >> $@
7464$(INSTALLED_QEMU_SYSTEMIMAGE): $(INSTALLED_VBMETAIMAGE_TARGET) $(MK_COMBINE_QEMU_IMAGE) $(SGDISK_HOST) $(SIMG2IMG) \
7465    $(INSTALLED_SUPERIMAGE_TARGET) $(INSTALLED_SYSTEM_QEMU_CONFIG)
7466	@echo Create system-qemu.img now
7467	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); \
7468     $(MK_COMBINE_QEMU_IMAGE) -i $(INSTALLED_SYSTEM_QEMU_CONFIG) -o $@)
7469
7470systemimage: $(INSTALLED_QEMU_SYSTEMIMAGE)
7471droidcore-unbundled: $(INSTALLED_QEMU_SYSTEMIMAGE)
7472endif
7473ifdef INSTALLED_VENDORIMAGE_TARGET
7474INSTALLED_QEMU_VENDORIMAGE := $(PRODUCT_OUT)/vendor-qemu.img
7475$(INSTALLED_QEMU_VENDORIMAGE): $(INSTALLED_VENDORIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST) $(SIMG2IMG)
7476	@echo Create vendor-qemu.img
7477	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); $(MK_QEMU_IMAGE_SH) $(INSTALLED_VENDORIMAGE_TARGET))
7478
7479vendorimage: $(INSTALLED_QEMU_VENDORIMAGE)
7480droidcore-unbundled: $(INSTALLED_QEMU_VENDORIMAGE)
7481endif
7482
7483ifdef INSTALLED_RAMDISK_TARGET
7484ifdef INSTALLED_VENDOR_BOOTIMAGE_TARGET
7485ifdef INTERNAL_VENDOR_RAMDISK_TARGET
7486INSTALLED_QEMU_RAMDISKIMAGE := $(PRODUCT_OUT)/ramdisk-qemu.img
7487$(INSTALLED_QEMU_RAMDISKIMAGE): $(INTERNAL_VENDOR_RAMDISK_TARGET) $(INSTALLED_RAMDISK_TARGET)
7488	@echo Create ramdisk-qemu.img
7489	(cat $(INSTALLED_RAMDISK_TARGET) $(INTERNAL_VENDOR_RAMDISK_TARGET) > $(INSTALLED_QEMU_RAMDISKIMAGE))
7490
7491droidcore-unbundled: $(INSTALLED_QEMU_RAMDISKIMAGE)
7492endif
7493endif
7494endif
7495
7496ifdef INSTALLED_PRODUCTIMAGE_TARGET
7497INSTALLED_QEMU_PRODUCTIMAGE := $(PRODUCT_OUT)/product-qemu.img
7498$(INSTALLED_QEMU_PRODUCTIMAGE): $(INSTALLED_PRODUCTIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST) $(SIMG2IMG)
7499	@echo Create product-qemu.img
7500	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); $(MK_QEMU_IMAGE_SH) $(INSTALLED_PRODUCTIMAGE_TARGET))
7501
7502productimage: $(INSTALLED_QEMU_PRODUCTIMAGE)
7503droidcore-unbundled: $(INSTALLED_QEMU_PRODUCTIMAGE)
7504endif
7505ifdef INSTALLED_SYSTEM_EXTIMAGE_TARGET
7506INSTALLED_QEMU_SYSTEM_EXTIMAGE := $(PRODUCT_OUT)/system_ext-qemu.img
7507$(INSTALLED_QEMU_SYSTEM_EXTIMAGE): $(INSTALLED_SYSTEM_EXTIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST) $(SIMG2IMG)
7508	@echo Create system_ext-qemu.img
7509	(export SGDISK=$(SGDISK_HOST) SIMG2IMG=$(SIMG2IMG); $(MK_QEMU_IMAGE_SH) $(INSTALLED_SYSTEM_EXTIMAGE_TARGET))
7510
7511systemextimage: $(INSTALLED_QEMU_SYSTEM_EXTIMAGE)
7512droidcore-unbundled: $(INSTALLED_QEMU_SYSTEM_EXTIMAGE)
7513endif
7514ifdef INSTALLED_ODMIMAGE_TARGET
7515INSTALLED_QEMU_ODMIMAGE := $(PRODUCT_OUT)/odm-qemu.img
7516$(INSTALLED_QEMU_ODMIMAGE): $(INSTALLED_ODMIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST)
7517	@echo Create odm-qemu.img
7518	(export SGDISK=$(SGDISK_HOST); $(MK_QEMU_IMAGE_SH) $(INSTALLED_ODMIMAGE_TARGET))
7519
7520odmimage: $(INSTALLED_QEMU_ODMIMAGE)
7521droidcore-unbundled: $(INSTALLED_QEMU_ODMIMAGE)
7522endif
7523
7524ifdef INSTALLED_VENDOR_DLKMIMAGE_TARGET
7525INSTALLED_QEMU_VENDOR_DLKMIMAGE := $(PRODUCT_OUT)/vendor_dlkm-qemu.img
7526$(INSTALLED_QEMU_VENDOR_DLKMIMAGE): $(INSTALLED_VENDOR_DLKMIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST)
7527	@echo Create vendor_dlkm-qemu.img
7528	(export SGDISK=$(SGDISK_HOST); $(MK_QEMU_IMAGE_SH) $(INSTALLED_VENDOR_DLKMIMAGE_TARGET))
7529
7530vendor_dlkmimage: $(INSTALLED_QEMU_VENDOR_DLKMIMAGE)
7531droidcore-unbundled: $(INSTALLED_QEMU_VENDOR_DLKMIMAGE)
7532endif
7533
7534ifdef INSTALLED_ODM_DLKMIMAGE_TARGET
7535INSTALLED_QEMU_ODM_DLKMIMAGE := $(PRODUCT_OUT)/odm_dlkm-qemu.img
7536$(INSTALLED_QEMU_ODM_DLKMIMAGE): $(INSTALLED_ODM_DLKMIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST)
7537	@echo Create odm_dlkm-qemu.img
7538	(export SGDISK=$(SGDISK_HOST); $(MK_QEMU_IMAGE_SH) $(INSTALLED_ODM_DLKMIMAGE_TARGET))
7539
7540odm_dlkmimage: $(INSTALLED_QEMU_ODM_DLKMIMAGE)
7541droidcore-unbundled: $(INSTALLED_QEMU_ODM_DLKMIMAGE)
7542endif
7543
7544ifdef INSTALLED_SYSTEM_DLKMIMAGE_TARGET
7545INSTALLED_QEMU_SYSTEM_DLKMIMAGE := $(PRODUCT_OUT)/system_dlkm-qemu.img
7546$(INSTALLED_QEMU_SYSTEM_DLKMIMAGE): $(INSTALLED_SYSTEM_DLKMIMAGE_TARGET) $(MK_QEMU_IMAGE_SH) $(SGDISK_HOST)
7547	@echo Create system_dlkm-qemu.img
7548	(export SGDISK=$(SGDISK_HOST); $(MK_QEMU_IMAGE_SH) $(INSTALLED_SYSTEM_DLKMIMAGE_TARGET))
7549
7550system_dlkmimage: $(INSTALLED_QEMU_SYSTEM_DLKMIMAGE)
7551droidcore-unbundled: $(INSTALLED_QEMU_SYSTEM_DLKMIMAGE)
7552endif
7553
7554QEMU_VERIFIED_BOOT_PARAMS := $(PRODUCT_OUT)/VerifiedBootParams.textproto
7555$(QEMU_VERIFIED_BOOT_PARAMS): $(INSTALLED_VBMETAIMAGE_TARGET) $(INSTALLED_SYSTEMIMAGE_TARGET) \
7556    $(MK_VBMETA_BOOT_KERNEL_CMDLINE_SH) $(AVBTOOL)
7557	@echo Creating $@
7558	(export AVBTOOL=$(AVBTOOL); $(MK_VBMETA_BOOT_KERNEL_CMDLINE_SH) $(INSTALLED_VBMETAIMAGE_TARGET) \
7559    $(INSTALLED_SYSTEMIMAGE_TARGET) $(QEMU_VERIFIED_BOOT_PARAMS))
7560
7561systemimage: $(QEMU_VERIFIED_BOOT_PARAMS)
7562droidcore-unbundled: $(QEMU_VERIFIED_BOOT_PARAMS)
7563
7564endif
7565
7566# Preprocess files for emulator and sdk.
7567-include development/build/tools/sdk-preprocess-files.mk
7568
7569# -----------------------------------------------------------------
7570# The emulator package
7571ifeq ($(BUILD_EMULATOR),true)
7572INTERNAL_EMULATOR_PACKAGE_FILES += \
7573        $(HOST_OUT_EXECUTABLES)/emulator$(HOST_EXECUTABLE_SUFFIX) \
7574        $(INSTALLED_RAMDISK_TARGET) \
7575        $(INSTALLED_SYSTEMIMAGE_TARGET) \
7576        $(INSTALLED_USERDATAIMAGE_TARGET)
7577
7578name := $(TARGET_PRODUCT)-emulator
7579
7580INTERNAL_EMULATOR_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
7581
7582$(INTERNAL_EMULATOR_PACKAGE_TARGET): $(INTERNAL_EMULATOR_PACKAGE_FILES)
7583	@echo "Package: $@"
7584	$(hide) zip -qjX $@ $(INTERNAL_EMULATOR_PACKAGE_FILES)
7585
7586endif
7587
7588
7589# -----------------------------------------------------------------
7590# The SDK
7591
7592ifneq ($(filter sdk,$(MAKECMDGOALS)),)
7593
7594# The SDK includes host-specific components, so it belongs under HOST_OUT.
7595sdk_dir := $(HOST_OUT)/sdk/$(TARGET_PRODUCT)
7596
7597# Build a name that looks like:
7598#
7599#     linux-x86   --> android-sdk_12345_linux-x86
7600#     darwin-x86  --> android-sdk_12345_mac-x86
7601#     windows-x86 --> android-sdk_12345_windows
7602#
7603ifneq ($(HOST_OS),linux)
7604  $(error Building the monolithic SDK is only supported on Linux)
7605endif
7606sdk_name := android-sdk
7607INTERNAL_SDK_HOST_OS_NAME := linux-$(SDK_HOST_ARCH)
7608sdk_name := $(sdk_name)_$(INTERNAL_SDK_HOST_OS_NAME)
7609
7610sdk_dep_file := $(sdk_dir)/sdk_deps.mk
7611
7612ATREE_FILES :=
7613-include $(sdk_dep_file)
7614
7615# if we don't have a real list, then use "everything"
7616ifeq ($(strip $(ATREE_FILES)),)
7617ATREE_FILES := \
7618	$(ALL_DOCS) \
7619	$(ALL_SDK_FILES)
7620endif
7621
7622atree_dir := development/build
7623
7624
7625sdk_atree_files := $(atree_dir)/sdk.exclude.atree
7626
7627# development/build/sdk-android-<abi>.atree is used to differentiate
7628# between architecture models (e.g. ARMv5TE versus ARMv7) when copying
7629# files like the kernel image. We use TARGET_CPU_ABI because we don't
7630# have a better way to distinguish between CPU models.
7631ifneq (,$(strip $(wildcard $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree)))
7632  sdk_atree_files += $(atree_dir)/sdk-android-$(TARGET_CPU_ABI).atree
7633endif
7634
7635ifneq ($(PRODUCT_SDK_ATREE_FILES),)
7636sdk_atree_files += $(PRODUCT_SDK_ATREE_FILES)
7637else
7638sdk_atree_files += $(atree_dir)/sdk.atree
7639endif
7640
7641SDK_METADATA_DIR :=$= $(call intermediates-dir-for,PACKAGING,framework-doc-stubs-metadata,,COMMON)
7642SDK_METADATA_FILES :=$= $(addprefix $(SDK_METADATA_DIR)/,\
7643    activity_actions.txt \
7644    broadcast_actions.txt \
7645    categories.txt \
7646    features.txt \
7647    service_actions.txt \
7648    widgets.txt)
7649SDK_METADATA :=$= $(firstword $(SDK_METADATA_FILES))
7650$(SDK_METADATA): .KATI_IMPLICIT_OUTPUTS := $(filter-out $(SDK_METADATA),$(SDK_METADATA_FILES))
7651$(SDK_METADATA): $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/framework-doc-stubs-metadata.zip
7652	rm -rf $(SDK_METADATA_DIR)
7653	mkdir -p $(SDK_METADATA_DIR)
7654	unzip -DDqo $< -d $(SDK_METADATA_DIR)
7655
7656.PHONY: framework-doc-stubs
7657framework-doc-stubs: $(SDK_METADATA)
7658
7659deps := \
7660	$(OUT_DOCS)/offline-sdk-timestamp \
7661	$(SDK_METADATA_FILES) \
7662  $(INSTALLED_SDK_BUILD_PROP_TARGET) \
7663	$(ATREE_FILES) \
7664	$(sdk_atree_files) \
7665	$(HOST_OUT_EXECUTABLES)/atree \
7666	$(HOST_OUT_EXECUTABLES)/line_endings
7667
7668# The name of the subdir within the platforms dir of the sdk. One of:
7669# - android-<SDK_INT> (stable base dessert SDKs)
7670# - android-<CODENAME> (stable extension SDKs)
7671# - android-<SDK_INT>-ext<EXT_INT> (codename SDKs)
7672sdk_platform_dir_name := $(strip \
7673  $(if $(filter REL,$(PLATFORM_VERSION_CODENAME)), \
7674    $(if $(filter $(PLATFORM_SDK_EXTENSION_VERSION),$(PLATFORM_BASE_SDK_EXTENSION_VERSION)), \
7675      android-$(PLATFORM_SDK_VERSION), \
7676      android-$(PLATFORM_SDK_VERSION)-ext$(PLATFORM_SDK_EXTENSION_VERSION) \
7677    ), \
7678    android-$(PLATFORM_VERSION_CODENAME) \
7679  ) \
7680)
7681
7682INTERNAL_SDK_TARGET := $(sdk_dir)/$(sdk_name).zip
7683$(INTERNAL_SDK_TARGET): PRIVATE_NAME := $(sdk_name)
7684$(INTERNAL_SDK_TARGET): PRIVATE_DIR := $(sdk_dir)/$(sdk_name)
7685$(INTERNAL_SDK_TARGET): PRIVATE_DEP_FILE := $(sdk_dep_file)
7686$(INTERNAL_SDK_TARGET): PRIVATE_INPUT_FILES := $(sdk_atree_files)
7687$(INTERNAL_SDK_TARGET): PRIVATE_PLATFORM_NAME := $(sdk_platform_dir_name)
7688# Set SDK_GNU_ERROR to non-empty to fail when a GNU target is built.
7689#
7690#SDK_GNU_ERROR := true
7691
7692$(INTERNAL_SDK_TARGET): $(deps)
7693	@echo "Package SDK: $@"
7694	$(hide) rm -rf $(PRIVATE_DIR) $@
7695	$(hide) for f in $(strip $(target_gnu_MODULES)); do \
7696	  if [ -f $$f ]; then \
7697	    echo SDK: $(if $(SDK_GNU_ERROR),ERROR:,warning:) \
7698	        including GNU target $$f >&2; \
7699	    FAIL=$(SDK_GNU_ERROR); \
7700	  fi; \
7701	done; \
7702	if [ $$FAIL ]; then exit 1; fi
7703	$(hide) ( \
7704	    ATREE_STRIP="$(HOST_STRIP) -x" \
7705	    $(HOST_OUT_EXECUTABLES)/atree \
7706	    $(addprefix -f ,$(PRIVATE_INPUT_FILES)) \
7707	        -m $(PRIVATE_DEP_FILE) \
7708	        -I . \
7709	        -I $(PRODUCT_OUT) \
7710	        -I $(HOST_OUT) \
7711	        -I $(TARGET_COMMON_OUT_ROOT) \
7712	        -v "PLATFORM_NAME=$(PRIVATE_PLATFORM_NAME)" \
7713	        -v "OUT_DIR=$(OUT_DIR)" \
7714	        -v "HOST_OUT=$(HOST_OUT)" \
7715	        -v "TARGET_ARCH=$(TARGET_ARCH)" \
7716	        -v "TARGET_CPU_ABI=$(TARGET_CPU_ABI)" \
7717	        -v "DLL_EXTENSION=$(HOST_SHLIB_SUFFIX)" \
7718	        -o $(PRIVATE_DIR) && \
7719	    HOST_OUT_EXECUTABLES=$(HOST_OUT_EXECUTABLES) HOST_OS=$(HOST_OS) \
7720	        development/build/tools/sdk_clean.sh $(PRIVATE_DIR) && \
7721	    chmod -R ug+rwX $(PRIVATE_DIR) && \
7722	    cd $(dir $@) && zip -rqX $(notdir $@) $(PRIVATE_NAME) \
7723	) || ( rm -rf $(PRIVATE_DIR) $@ && exit 44 )
7724
7725MAIN_SDK_DIR  := $(sdk_dir)
7726MAIN_SDK_ZIP  := $(INTERNAL_SDK_TARGET)
7727
7728endif # sdk in MAKECMDGOALS
7729
7730# -----------------------------------------------------------------
7731# Findbugs
7732INTERNAL_FINDBUGS_XML_TARGET := $(PRODUCT_OUT)/findbugs.xml
7733INTERNAL_FINDBUGS_HTML_TARGET := $(PRODUCT_OUT)/findbugs.html
7734$(INTERNAL_FINDBUGS_XML_TARGET): $(ALL_FINDBUGS_FILES)
7735	@echo UnionBugs: $@
7736	$(hide) $(FINDBUGS_DIR)/unionBugs $(ALL_FINDBUGS_FILES) \
7737	> $@
7738$(INTERNAL_FINDBUGS_HTML_TARGET): $(INTERNAL_FINDBUGS_XML_TARGET)
7739	@echo ConvertXmlToText: $@
7740	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl \
7741	$(INTERNAL_FINDBUGS_XML_TARGET) > $@
7742
7743# -----------------------------------------------------------------
7744# Findbugs
7745
7746# -----------------------------------------------------------------
7747# These are some additional build tasks that need to be run.
7748ifneq ($(dont_bother),true)
7749include $(sort $(wildcard $(BUILD_SYSTEM)/tasks/*.mk))
7750-include $(sort $(wildcard vendor/*/build/tasks/*.mk))
7751-include $(sort $(wildcard device/*/build/tasks/*.mk))
7752-include $(sort $(wildcard product/*/build/tasks/*.mk))
7753# Also the project-specific tasks
7754-include $(sort $(wildcard vendor/*/*/build/tasks/*.mk))
7755-include $(sort $(wildcard device/*/*/build/tasks/*.mk))
7756-include $(sort $(wildcard product/*/*/build/tasks/*.mk))
7757# Also add test specifc tasks
7758include $(sort $(wildcard platform_testing/build/tasks/*.mk))
7759include $(sort $(wildcard test/vts/tools/build/tasks/*.mk))
7760endif
7761
7762include $(BUILD_SYSTEM)/product-graph.mk
7763
7764# -----------------------------------------------------------------
7765# Create SDK repository packages. Must be done after tasks/* since
7766# we need the addon rules defined.
7767ifneq ($(sdk_repo_goal),)
7768include $(TOPDIR)development/build/tools/sdk_repo.mk
7769endif
7770
7771# -----------------------------------------------------------------
7772# Soong generates the list of all shared libraries that are depended on by fuzz
7773# targets. It saves this list as a source:destination pair to
7774# FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS, where the source is the path to the
7775# build of the unstripped shared library, and the destination is the
7776# /data/fuzz/$ARCH/lib (for device) or /fuzz/$ARCH/lib (for host) directory
7777# where fuzz target shared libraries are to be "reinstalled". The
7778# copy-many-files below generates the rules to copy the unstripped shared
7779# libraries to the device or host "reinstallation" directory. These rules are
7780# depended on by each module in soong_cc_prebuilt.mk, where the module will have
7781# a dependency on each shared library that it needs to be "reinstalled".
7782FUZZ_SHARED_DEPS := $(call copy-many-files,$(strip $(FUZZ_TARGET_SHARED_DEPS_INSTALL_PAIRS)))
7783
7784# -----------------------------------------------------------------
7785# The rule to build all fuzz targets for C++ and Rust, and package them.
7786# Note: The packages are created in Soong, and in a perfect world,
7787# we'd be able to create the phony rule there. But, if we want to
7788# have dist goals for the fuzz target, we need to have the PHONY
7789# target defined in make. MakeVarsContext.DistForGoal doesn't take
7790# into account that a PHONY rule create by Soong won't be available
7791# during make, and such will fail with `writing to readonly
7792# directory`, because kati will see 'haiku' as being a file, not a
7793# phony target.
7794.PHONY: haiku
7795haiku: $(SOONG_FUZZ_PACKAGING_ARCH_MODULES) $(ALL_FUZZ_TARGETS)
7796$(call dist-for-goals,haiku,$(SOONG_FUZZ_PACKAGING_ARCH_MODULES))
7797$(call dist-for-goals,haiku,$(PRODUCT_OUT)/module-info.json)
7798.PHONY: haiku-java
7799haiku-java: $(SOONG_JAVA_FUZZ_PACKAGING_ARCH_MODULES) $(ALL_JAVA_FUZZ_TARGETS)
7800$(call dist-for-goals,haiku-java,$(SOONG_JAVA_FUZZ_PACKAGING_ARCH_MODULES))
7801.PHONY: haiku-rust
7802haiku-rust: $(SOONG_RUST_FUZZ_PACKAGING_ARCH_MODULES) $(ALL_RUST_FUZZ_TARGETS)
7803$(call dist-for-goals,haiku-rust,$(SOONG_RUST_FUZZ_PACKAGING_ARCH_MODULES))
7804$(call dist-for-goals,haiku-rust,$(PRODUCT_OUT)/module-info.json)
7805.PHONY: haiku-presubmit
7806haiku-presubmit: $(SOONG_PRESUBMIT_FUZZ_PACKAGING_ARCH_MODULES) $(ALL_PRESUBMIT_FUZZ_TARGETS)
7807$(call dist-for-goals,haiku-presubmit,$(SOONG_PRESUBMIT_FUZZ_PACKAGING_ARCH_MODULES))
7808
7809# -----------------------------------------------------------------
7810# Extract platform fonts used in Layoutlib
7811include $(BUILD_SYSTEM)/layoutlib_data.mk
7812
7813
7814# -----------------------------------------------------------------
7815# OS Licensing
7816
7817include $(BUILD_SYSTEM)/os_licensing.mk
7818
7819# When appending new code to this file, please insert above OS Licensing
7820