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 SkyMinus
parent bebc2416e8
commit 80f63ee9d1
2 changed files with 34 additions and 4 deletions

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
@@ -1694,10 +1697,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()
@@ -4164,8 +4170,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)