Add build support for XZ ramdisks

Co-authored-by: Arne Coucheron <arco68@gmail.com>
Change-Id: I61530b6da06e0038970551aa4d12bce02007ae3c
This commit is contained in:
Luca Stefani 2020-06-11 13:03:18 +02:00 committed by Bartłomiej Rudecki
parent fe27b5e0ed
commit 94b75b4429
Signed by: przekichane
GPG key ID: 751F23C6F014EF76
2 changed files with 23 additions and 4 deletions

View file

@ -1197,6 +1197,10 @@ ifeq ($(BOARD_RAMDISK_USE_LZ4),true)
COMPRESSION_COMMAND_DEPS := $(LZ4)
COMPRESSION_COMMAND := $(LZ4) -l -12 --favor-decSpeed
RAMDISK_EXT := .lz4
else ifeq ($(BOARD_RAMDISK_USE_XZ),true)
COMPRESSION_COMMAND_DEPS := $(XZ)
COMPRESSION_COMMAND := $(XZ) -f -c --check=crc32 --lzma2=dict=32MiB
RAMDISK_EXT := .xz
else
COMPRESSION_COMMAND_DEPS := $(GZIP)
COMPRESSION_COMMAND := $(GZIP)
@ -2586,7 +2590,7 @@ endif
ifeq (,$(filter true, $(BOARD_USES_FULL_RECOVERY_IMAGE) $(BOARD_USES_RECOVERY_AS_BOOT) \
$(BOARD_INCLUDE_RECOVERY_DTBO) $(BOARD_INCLUDE_RECOVERY_ACPIO) \
$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT) $(BOARD_RAMDISK_USE_LZ4)))
$(BOARD_MOVE_RECOVERY_RESOURCES_TO_VENDOR_BOOT) $(BOARD_RAMDISK_USE_LZ4) $(BOARD_RAMDISK_USE_XZ)))
# Named '.dat' so we don't attempt to use imgdiff for patching it.
RECOVERY_RESOURCE_ZIP := $(TARGET_OUT_VENDOR)/etc/recovery-resource.dat
ALL_DEFAULT_INSTALLED_MODULES += $(RECOVERY_RESOURCE_ZIP)
@ -3519,7 +3523,7 @@ ifneq ($(INSTALLED_BOOTIMAGE_TARGET),)
ifneq ($(INSTALLED_RECOVERYIMAGE_TARGET),)
ifneq ($(BOARD_USES_FULL_RECOVERY_IMAGE),true)
ifneq (,$(filter true,$(BOARD_INCLUDE_RECOVERY_DTBO) $(BOARD_INCLUDE_RECOVERY_ACPIO) \
$(BOARD_RAMDISK_USE_LZ4)))
$(BOARD_RAMDISK_USE_LZ4) $(BOARD_RAMDISK_USE_XZ)))
diff_tool := $(HOST_OUT_EXECUTABLES)/bsdiff
else
diff_tool := $(HOST_OUT_EXECUTABLES)/imgdiff
@ -5840,6 +5844,9 @@ endif
ifeq ($(BOARD_RAMDISK_USE_LZ4),true)
echo "lz4_ramdisks=true" >> $@
endif
ifeq ($(BOARD_RAMDISK_USE_XZ),true)
echo "xz_ramdisks=true" >> $@
endif
ifneq ($(INSTALLED_VENDOR_BOOTIMAGE_TARGET),)
echo "vendor_boot=true" >> $@
echo "vendor_boot_size=$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE)" >> $@

View file

@ -832,11 +832,14 @@ def ExtractFromInputFile(input_file, fn):
class RamdiskFormat(object):
LZ4 = 1
GZ = 2
XZ = 3
def GetRamdiskFormat(info_dict):
if info_dict.get('lz4_ramdisks') == 'true':
ramdisk_format = RamdiskFormat.LZ4
elif info_dict.get('xz_ramdisks') == 'true':
ramdisk_format = RamdiskFormat.XZ
else:
ramdisk_format = RamdiskFormat.GZ
return ramdisk_format
@ -1674,10 +1677,13 @@ def _MakeRamdisk(sourcedir, fs_config_file=None,
if ramdisk_format == RamdiskFormat.LZ4:
p2 = Run(["lz4", "-l", "-12", "--favor-decSpeed"], stdin=p1.stdout,
stdout=ramdisk_img.file.fileno())
elif ramdisk_format == RamdiskFormat.XZ:
p2 = Run(["xz", "-f", "-c", "--check=crc32", "--lzma2=dict=32MiB"], stdin=p1.stdout,
stdout=ramdisk_img.file.fileno())
elif ramdisk_format == RamdiskFormat.GZ:
p2 = Run(["gzip"], stdin=p1.stdout, stdout=ramdisk_img.file.fileno())
else:
raise ValueError("Only support lz4 or gzip ramdisk format.")
raise ValueError("Only support lz4, xz or gzip ramdisk format.")
p2.wait()
p1.wait()
@ -4157,8 +4163,14 @@ def GetBootImageBuildProp(boot_img, ramdisk_format=RamdiskFormat.LZ4):
p2 = Run(['gzip', '-d'], stdin=input_stream.fileno(),
stdout=output_stream.fileno())
p2.wait()
elif ramdisk_format == RamdiskFormat.XZ:
with open(ramdisk, 'rb') as input_stream:
with open(uncompressed_ramdisk, 'wb') as output_stream:
p2 = Run(['xz', '-d'], stdin=input_stream.fileno(),
stdout=output_stream.fileno())
p2.wait()
else:
logger.error('Only support lz4 or gzip ramdisk format.')
logger.error('Only support lz4, xz or gzip ramdisk format.')
return None
abs_uncompressed_ramdisk = os.path.abspath(uncompressed_ramdisk)