Add super_empty.img to target-files and the update package.

super_empty.img is needed for "fastboot update" to work, as such, it
must be included in the update package. This change adds lpmake
parameters to misc_info.txt for add_img_to_target_files.py, and ensures
that lpmake is packaged with otatools.zip.

The build-superimage-target macro is now split into two functions - one
to generate the device-specific arguments, and another to build the full
command-line for convenience. The former is used to pass arguments
directly to add_img_to_target_files.

Bug: 113524256
Test: make updatepackage builds and includes super_empty.img
      make otatools includes lpmake

Change-Id: I25091c964b036beeea2a8b8f738e2c18937c1eb4
diff --git a/core/Makefile b/core/Makefile
index 73e93fc..e11dd02 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -2835,23 +2835,29 @@
 $(INSTALLED_SUPERIMAGE_TARGET) $(INSTALLED_SUPERIMAGE_EMPTY_TARGET): PRIVATE_PARTITION_SUFFIX=_a
 endif # AB_OTA_UPDATER
 
-$(INSTALLED_SUPERIMAGE_TARGET) $(INSTALLED_SUPERIMAGE_EMPTY_TARGET): $(HOST_OUT_EXECUTABLES)/lpmake
+$(INSTALLED_SUPERIMAGE_TARGET) $(INSTALLED_SUPERIMAGE_EMPTY_TARGET): $(LPMAKE)
+
+# $(1): slot A suffix (_a or empty)
+# $(2): include images or not (true or empty)
+define build-superimage-target-args
+  $(if $(2), --sparse) \
+  --metadata-size 65536 \
+  --metadata-slots $(if $(1),2,1) \
+  --device-size $(BOARD_SUPER_PARTITION_SIZE) \
+  $(foreach name,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
+    --partition $(name)$(1):$$($(UUIDGEN) $(name)$(1)):readonly:$(if $(2),$(call read-size-of-partitions,$(name)),0) \
+    $(if $(2), --image $(name)$(1)=$(call images-for-partitions,$(name))) \
+    $(if $(1), --partition $(name)_b:$$($(UUIDGEN) $(name)_b):readonly:0) \
+  )
+endef
 
 # $(1): output image path
 # $(2): slot A suffix (_a or empty)
 # $(3): include images or not (true or empty)
 define build-superimage-target
   $(HOST_OUT_EXECUTABLES)/lpmake \
-    $(if $(3), --sparse) \
-    --metadata-size 65536 \
-    --metadata-slots $(if $(2),2,1) \
-    --device-size $(BOARD_SUPER_PARTITION_SIZE) \
-    --output $(1) \
-    $(foreach name,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
-      --partition $(name)$(2):$$($(UUIDGEN) $(name)$(2)):readonly:$(if $(3),$(call read-size-of-partitions,$(name)),0) \
-      $(if $(3), --image $(name)$(2)=$(call images-for-partitions,$(name))) \
-      $(if $(2), --partition $(name)_b:$$($(UUIDGEN) $(name)_b):readonly:0) \
-    )
+    $(call build-superimage-target-args,$(2),$(3)) \
+    --output $(1)
 endef
 
 $(INSTALLED_SUPERIMAGE_TARGET):
@@ -2974,6 +2980,7 @@
   $(HOST_OUT_EXECUTABLES)/lib/shflags/shflags \
   $(HOST_OUT_EXECUTABLES)/delta_generator \
   $(HOST_OUT_EXECUTABLES)/care_map_generator \
+  $(LPMAKE) \
   $(AVBTOOL) \
   $(BLK_ALLOC_TO_BASE_FS) \
   $(BROTLI) \
@@ -3014,7 +3021,9 @@
   $(HOST_LIBRARY_PATH)/libsparse-host$(HOST_SHLIB_SUFFIX) \
   $(HOST_LIBRARY_PATH)/libbase$(HOST_SHLIB_SUFFIX) \
   $(HOST_LIBRARY_PATH)/libpcre2$(HOST_SHLIB_SUFFIX) \
-  $(HOST_LIBRARY_PATH)/libbrotli$(HOST_SHLIB_SUFFIX)
+  $(HOST_LIBRARY_PATH)/libbrotli$(HOST_SHLIB_SUFFIX) \
+  $(HOST_LIBRARY_PATH)/liblp$(HOST_SHLIB_SUFFIX) \
+  $(HOST_LIBRARY_PATH)/libext4_utils$(HOST_SHLIB_SUFFIX)
 
 
 .PHONY: otatools
@@ -3162,6 +3171,7 @@
 		$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PRODUCT_BASE_FS_PATH) \
 		$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PRODUCT_SERVICES_BASE_FS_PATH) \
 		$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_ODM_BASE_FS_PATH) \
+		$(LPMAKE) \
 		$(SELINUX_FC) \
 		$(APKCERTS_FILE) \
 		$(SOONG_ZIP) \
@@ -3488,6 +3498,13 @@
 ifdef BUILT_VENDOR_MATRIX
 	$(hide) cp $(BUILT_VENDOR_MATRIX) $(zip_root)/META/vendor_matrix.xml
 endif
+ifdef BOARD_SUPER_PARTITION_SIZE
+	$(hide) echo "super_size=$(BOARD_SUPER_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
+	$(hide) echo "lpmake=$(notdir $(LPMAKE))" >> $(zip_root)/META/misc_info.txt
+	$(hide) echo -n "lpmake_args=" >> $(zip_root)/META/misc_info.txt
+	$(hide) echo $(call build-superimage-target-args,$(if $(filter true,$(AB_OTA_UPDATER)),_a,)) \
+	    >> $(zip_root)/META/misc_info.txt
+endif
 
 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
 	    build/make/tools/releasetools/add_img_to_target_files -a -v -p $(HOST_OUT) $(zip_root)