DO NOT MERGE: Add the option to reserve headroom for
partition images. This is useful for devices with low disk space with different build variants. This is a manual cherry-pick from aosp-master. Bug: 37469715 Test: Regular image builds successfully, errors occur when the headroom size is greater than available partition space. Change-Id: I048b45e4b7b68ed2e855ea852b09ee1fdc6ad35d
This commit is contained in:
parent
6be965be74
commit
af6d68e80d
|
@ -799,6 +799,7 @@ $(if $(BOARD_SYSTEMIMAGE_SQUASHFS_COMPRESSOR_OPT),$(hide) echo "system_squashfs_
|
||||||
$(if $(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "system_squashfs_block_size=$(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
|
$(if $(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE),$(hide) echo "system_squashfs_block_size=$(BOARD_SYSTEMIMAGE_SQUASHFS_BLOCK_SIZE)" >> $(1))
|
||||||
$(if $(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "system_squashfs_disable_4k_align=$(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
|
$(if $(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN),$(hide) echo "system_squashfs_disable_4k_align=$(BOARD_SYSTEMIMAGE_SQUASHFS_DISABLE_4K_ALIGN)" >> $(1))
|
||||||
$(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH),$(hide) echo "system_base_fs_file=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH)" >> $(1))
|
$(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH),$(hide) echo "system_base_fs_file=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_BASE_FS_PATH)" >> $(1))
|
||||||
|
$(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_HEADROOM),$(hide) echo "system_headroom=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_HEADROOM)" >> $(1))
|
||||||
$(if $(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "userdata_fs_type=$(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
|
$(if $(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "userdata_fs_type=$(BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
|
||||||
$(if $(BOARD_USERDATAIMAGE_PARTITION_SIZE),$(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(1))
|
$(if $(BOARD_USERDATAIMAGE_PARTITION_SIZE),$(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(1))
|
||||||
$(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
|
$(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
|
||||||
|
|
|
@ -124,6 +124,7 @@ _product_var_list := \
|
||||||
PRODUCT_SYSTEM_BASE_FS_PATH \
|
PRODUCT_SYSTEM_BASE_FS_PATH \
|
||||||
PRODUCT_VENDOR_BASE_FS_PATH \
|
PRODUCT_VENDOR_BASE_FS_PATH \
|
||||||
PRODUCT_SHIPPING_API_LEVEL \
|
PRODUCT_SHIPPING_API_LEVEL \
|
||||||
|
PRODUCT_SYSTEM_HEADROOM \
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -319,6 +319,9 @@ ifndef PRODUCT_MANUFACTURER
|
||||||
PRODUCT_MANUFACTURER := unknown
|
PRODUCT_MANUFACTURER := unknown
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Add reserved headroom to a system image.
|
||||||
|
PRODUCT_SYSTEM_HEADROOM := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_HEADROOM))
|
||||||
|
|
||||||
ifeq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_CHARACTERISTICS),)
|
ifeq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_CHARACTERISTICS),)
|
||||||
TARGET_AAPT_CHARACTERISTICS := default
|
TARGET_AAPT_CHARACTERISTICS := default
|
||||||
else
|
else
|
||||||
|
|
|
@ -449,11 +449,11 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
|
||||||
shutil.rmtree(staging_system, ignore_errors=True)
|
shutil.rmtree(staging_system, ignore_errors=True)
|
||||||
shutil.copytree(origin_in, staging_system, symlinks=True)
|
shutil.copytree(origin_in, staging_system, symlinks=True)
|
||||||
|
|
||||||
reserved_blocks = prop_dict.get("has_ext4_reserved_blocks") == "true"
|
has_reserved_blocks = prop_dict.get("has_ext4_reserved_blocks") == "true"
|
||||||
ext4fs_output = None
|
ext4fs_output = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if reserved_blocks and fs_type.startswith("ext4"):
|
if fs_type.startswith("ext4"):
|
||||||
(ext4fs_output, exit_code) = RunCommand(build_command)
|
(ext4fs_output, exit_code) = RunCommand(build_command)
|
||||||
else:
|
else:
|
||||||
(_, exit_code) = RunCommand(build_command)
|
(_, exit_code) = RunCommand(build_command)
|
||||||
|
@ -474,7 +474,9 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
|
||||||
# not writable even with root privilege. It only affects devices using
|
# not writable even with root privilege. It only affects devices using
|
||||||
# file-based OTA and a kernel version of 3.10 or greater (currently just
|
# file-based OTA and a kernel version of 3.10 or greater (currently just
|
||||||
# sprout).
|
# sprout).
|
||||||
if reserved_blocks and fs_type.startswith("ext4"):
|
# Separately, check if there's enough headroom space available. This is useful for
|
||||||
|
# devices with low disk space that have system image variation between builds.
|
||||||
|
if (has_reserved_blocks or "partition_headroom" in prop_dict) and fs_type.startswith("ext4"):
|
||||||
assert ext4fs_output is not None
|
assert ext4fs_output is not None
|
||||||
ext4fs_stats = re.compile(
|
ext4fs_stats = re.compile(
|
||||||
r'Created filesystem with .* (?P<used_blocks>[0-9]+)/'
|
r'Created filesystem with .* (?P<used_blocks>[0-9]+)/'
|
||||||
|
@ -482,14 +484,21 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
|
||||||
m = ext4fs_stats.match(ext4fs_output.strip().split('\n')[-1])
|
m = ext4fs_stats.match(ext4fs_output.strip().split('\n')[-1])
|
||||||
used_blocks = int(m.groupdict().get('used_blocks'))
|
used_blocks = int(m.groupdict().get('used_blocks'))
|
||||||
total_blocks = int(m.groupdict().get('total_blocks'))
|
total_blocks = int(m.groupdict().get('total_blocks'))
|
||||||
reserved_blocks = min(4096, int(total_blocks * 0.02))
|
reserved_blocks = 0
|
||||||
adjusted_blocks = total_blocks - reserved_blocks
|
headroom_blocks = 0
|
||||||
|
adjusted_blocks = total_blocks
|
||||||
|
if has_reserved_blocks:
|
||||||
|
reserved_blocks = min(4096, int(total_blocks * 0.02))
|
||||||
|
adjusted_blocks -= reserved_blocks
|
||||||
|
if "partition_headroom" in prop_dict:
|
||||||
|
headroom_blocks = int(prop_dict.get('partition_headroom')) / BLOCK_SIZE
|
||||||
|
adjusted_blocks -= headroom_blocks
|
||||||
if used_blocks > adjusted_blocks:
|
if used_blocks > adjusted_blocks:
|
||||||
mount_point = prop_dict.get("mount_point")
|
mount_point = prop_dict.get("mount_point")
|
||||||
print("Error: Not enough room on %s (total: %d blocks, used: %d blocks, "
|
print("Error: Not enough room on %s (total: %d blocks, used: %d blocks, "
|
||||||
"reserved: %d blocks, available: %d blocks)" % (
|
"reserved: %d blocks, headroom: %d blocks, available: %d blocks)" % (
|
||||||
mount_point, total_blocks, used_blocks, reserved_blocks,
|
mount_point, total_blocks, used_blocks, reserved_blocks,
|
||||||
adjusted_blocks))
|
headroom_blocks, adjusted_blocks))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not fs_spans_partition:
|
if not fs_spans_partition:
|
||||||
|
@ -557,9 +566,10 @@ def ImagePropFromGlobalDict(glob_dict, mount_point):
|
||||||
d["mount_point"] = mount_point
|
d["mount_point"] = mount_point
|
||||||
if mount_point == "system":
|
if mount_point == "system":
|
||||||
copy_prop("fs_type", "fs_type")
|
copy_prop("fs_type", "fs_type")
|
||||||
# Copy the generic sysetem fs type first, override with specific one if
|
# Copy the generic system fs type first, override with specific one if
|
||||||
# available.
|
# available.
|
||||||
copy_prop("system_fs_type", "fs_type")
|
copy_prop("system_fs_type", "fs_type")
|
||||||
|
copy_prop("system_headroom", "partition_headroom")
|
||||||
copy_prop("system_size", "partition_size")
|
copy_prop("system_size", "partition_size")
|
||||||
copy_prop("system_journal_size", "journal_size")
|
copy_prop("system_journal_size", "journal_size")
|
||||||
copy_prop("system_verity_block_device", "verity_block_device")
|
copy_prop("system_verity_block_device", "verity_block_device")
|
||||||
|
|
Loading…
Reference in New Issue