From 98cd4cc7a3c3b2ffe7c27d3aa5cc299565a7892c Mon Sep 17 00:00:00 2001 From: "J. Avila" Date: Wed, 10 Jun 2020 20:09:10 +0000 Subject: [PATCH] Add LZ4 support to the release tools The core android build platform has changed to add support for LZ4 compression for ramdisks, but the release tools were not. Fix this. Bug: 156129966 Change-Id: I39680b91930d2d3cbd0cd565beb78e1ee699397e --- core/Makefile | 3 +++ tools/releasetools/Android.bp | 1 + tools/releasetools/common.py | 16 +++++++++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/Makefile b/core/Makefile index 561368d4b..b833648fd 100644 --- a/core/Makefile +++ b/core/Makefile @@ -3774,6 +3774,9 @@ ifeq ($(INSTALLED_BOOTIMAGE_TARGET),) else echo "boot_images=$(foreach b,$(INSTALLED_BOOTIMAGE_TARGET),$(notdir $(b)))" >> $@ endif +ifeq ($(BOARD_RAMDISK_USE_LZ4),true) + echo "lz4_ramdisks=true" >> $@ +endif ifneq ($(INSTALLED_VENDOR_BOOTIMAGE_TARGET),) echo "vendor_boot=true" >> $@ echo "vendor_boot_size=$(BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE)" >> $@ diff --git a/tools/releasetools/Android.bp b/tools/releasetools/Android.bp index b52da8733..11f92abb1 100644 --- a/tools/releasetools/Android.bp +++ b/tools/releasetools/Android.bp @@ -184,6 +184,7 @@ python_library_host { "bsdiff", "imgdiff", "minigzip", + "lz4", "mkbootfs", "signapk", ], diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index 93e14e5c1..8a59a39f1 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -1191,7 +1191,7 @@ def BuildVBMeta(image_path, partitions, name, needed_partitions): AddAftlInclusionProof(image_path) -def _MakeRamdisk(sourcedir, fs_config_file=None): +def _MakeRamdisk(sourcedir, fs_config_file=None, lz4_ramdisks=False): ramdisk_img = tempfile.NamedTemporaryFile() if fs_config_file is not None and os.access(fs_config_file, os.F_OK): @@ -1200,12 +1200,16 @@ def _MakeRamdisk(sourcedir, fs_config_file=None): else: cmd = ["mkbootfs", os.path.join(sourcedir, "RAMDISK")] p1 = Run(cmd, stdout=subprocess.PIPE) - p2 = Run(["minigzip"], stdin=p1.stdout, stdout=ramdisk_img.file.fileno()) + if lz4_ramdisks: + p2 = Run(["lz4", "-l", "-12" , "--favor-decSpeed"], stdin=p1.stdout, + stdout=ramdisk_img.file.fileno()) + else: + p2 = Run(["minigzip"], stdin=p1.stdout, stdout=ramdisk_img.file.fileno()) p2.wait() p1.wait() assert p1.returncode == 0, "mkbootfs of %s ramdisk failed" % (sourcedir,) - assert p2.returncode == 0, "minigzip of %s ramdisk failed" % (sourcedir,) + assert p2.returncode == 0, "compression of %s ramdisk failed" % (sourcedir,) return ramdisk_img @@ -1243,7 +1247,8 @@ def _BuildBootableImage(image_name, sourcedir, fs_config_file, info_dict=None, img = tempfile.NamedTemporaryFile() if has_ramdisk: - ramdisk_img = _MakeRamdisk(sourcedir, fs_config_file) + use_lz4 = info_dict.get("lz4_ramdisks") == 'true' + ramdisk_img = _MakeRamdisk(sourcedir, fs_config_file, lz4_ramdisks=use_lz4) # use MKBOOTIMG from environ, or "mkbootimg" if empty or not set mkbootimg = os.getenv('MKBOOTIMG') or "mkbootimg" @@ -1427,7 +1432,8 @@ def _BuildVendorBootImage(sourcedir, info_dict=None): img = tempfile.NamedTemporaryFile() - ramdisk_img = _MakeRamdisk(sourcedir) + use_lz4 = info_dict.get("lz4_ramdisks") == 'true' + ramdisk_img = _MakeRamdisk(sourcedir, lz4_ramdisks=use_lz4) # use MKBOOTIMG from environ, or "mkbootimg" if empty or not set mkbootimg = os.getenv('MKBOOTIMG') or "mkbootimg"