2023-07-26 23:33:51 +02:00
|
|
|
#!/usr/bin/env python3
|
2011-10-29 02:02:30 +02:00
|
|
|
#
|
|
|
|
# Copyright (C) 2011 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
"""
|
2017-12-07 19:33:00 +01:00
|
|
|
Builds output_image from the given input_directory, properties_file,
|
|
|
|
and writes the image to target_output_directory.
|
2011-10-29 02:02:30 +02:00
|
|
|
|
2019-05-07 22:12:21 +02:00
|
|
|
Usage: build_image input_directory properties_file output_image \\
|
2019-04-09 19:03:57 +02:00
|
|
|
target_output_directory
|
2011-10-29 02:02:30 +02:00
|
|
|
"""
|
2017-12-07 19:33:00 +01:00
|
|
|
|
2023-06-03 01:41:19 +02:00
|
|
|
import datetime
|
2017-12-07 19:33:00 +01:00
|
|
|
|
2023-07-26 23:33:51 +02:00
|
|
|
import argparse
|
2021-10-12 15:59:12 +02:00
|
|
|
import glob
|
2018-10-12 19:30:39 +02:00
|
|
|
import logging
|
2011-10-29 02:02:30 +02:00
|
|
|
import os
|
2012-11-27 03:10:23 +01:00
|
|
|
import os.path
|
2015-06-23 20:16:05 +02:00
|
|
|
import re
|
2023-06-03 01:41:19 +02:00
|
|
|
import shlex
|
2017-12-07 19:33:00 +01:00
|
|
|
import shutil
|
2011-10-29 02:02:30 +02:00
|
|
|
import sys
|
2023-06-03 01:41:19 +02:00
|
|
|
import uuid
|
2023-07-26 23:33:51 +02:00
|
|
|
import tempfile
|
2017-12-07 19:33:00 +01:00
|
|
|
|
2015-06-10 00:48:14 +02:00
|
|
|
import common
|
2018-10-11 23:08:45 +02:00
|
|
|
import verity_utils
|
2011-10-29 02:02:30 +02:00
|
|
|
|
2023-06-03 01:41:19 +02:00
|
|
|
|
2018-10-12 19:30:39 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2015-06-10 00:48:14 +02:00
|
|
|
OPTIONS = common.OPTIONS
|
2018-10-11 23:08:45 +02:00
|
|
|
BLOCK_SIZE = common.BLOCK_SIZE
|
2018-06-19 01:32:35 +02:00
|
|
|
BYTES_IN_MB = 1024 * 1024
|
2014-05-17 04:14:30 +02:00
|
|
|
|
2023-06-03 01:41:19 +02:00
|
|
|
# Use a fixed timestamp (01/01/2009 00:00:00 UTC) for files when packaging
|
|
|
|
# images. (b/24377993, b/80600931)
|
|
|
|
FIXED_FILE_TIMESTAMP = int((
|
|
|
|
datetime.datetime(2009, 1, 1, 0, 0, 0, 0, None) -
|
|
|
|
datetime.datetime.utcfromtimestamp(0)).total_seconds())
|
|
|
|
|
2017-12-07 19:33:00 +01:00
|
|
|
|
2018-09-28 01:58:00 +02:00
|
|
|
class BuildImageError(Exception):
|
|
|
|
"""An Exception raised during image building."""
|
|
|
|
|
|
|
|
def __init__(self, message):
|
|
|
|
Exception.__init__(self, message)
|
|
|
|
|
|
|
|
|
2018-06-19 01:32:35 +02:00
|
|
|
def GetDiskUsage(path):
|
2018-09-28 01:58:00 +02:00
|
|
|
"""Returns the number of bytes that "path" occupies on host.
|
2018-06-19 01:32:35 +02:00
|
|
|
|
|
|
|
Args:
|
2018-10-19 22:44:36 +02:00
|
|
|
path: The directory or file to calculate size on.
|
2018-09-28 01:58:00 +02:00
|
|
|
|
2018-06-19 01:32:35 +02:00
|
|
|
Returns:
|
2018-10-19 22:44:36 +02:00
|
|
|
The number of bytes based on a 1K block_size.
|
2018-06-19 01:32:35 +02:00
|
|
|
"""
|
2020-03-26 23:19:31 +01:00
|
|
|
cmd = ["du", "-b", "-k", "-s", path]
|
2018-10-25 21:23:12 +02:00
|
|
|
output = common.RunAndCheckOutput(cmd, verbose=False)
|
2018-10-19 22:44:36 +02:00
|
|
|
return int(output.split()[0]) * 1024
|
|
|
|
|
|
|
|
|
|
|
|
def GetInodeUsage(path):
|
|
|
|
"""Returns the number of inodes that "path" occupies on host.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
path: The directory or file to calculate inode number on.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The number of inodes used.
|
|
|
|
"""
|
|
|
|
cmd = ["find", path, "-print"]
|
2018-10-25 21:23:12 +02:00
|
|
|
output = common.RunAndCheckOutput(cmd, verbose=False)
|
2021-04-01 05:01:41 +02:00
|
|
|
# increase by > 6% as number of files and directories is not whole picture.
|
2019-01-16 17:03:10 +01:00
|
|
|
inodes = output.count('\n')
|
2021-04-01 05:01:41 +02:00
|
|
|
spare_inodes = inodes * 6 // 100
|
2019-01-16 17:03:10 +01:00
|
|
|
min_spare_inodes = 12
|
2019-01-16 17:03:10 +01:00
|
|
|
if spare_inodes < min_spare_inodes:
|
|
|
|
spare_inodes = min_spare_inodes
|
|
|
|
return inodes + spare_inodes
|
2018-10-19 22:44:36 +02:00
|
|
|
|
|
|
|
|
2021-05-22 18:47:48 +02:00
|
|
|
def GetFilesystemCharacteristics(fs_type, image_path, sparse_image=True):
|
2019-01-10 23:30:51 +01:00
|
|
|
"""Returns various filesystem characteristics of "image_path".
|
2018-10-19 22:44:36 +02:00
|
|
|
|
|
|
|
Args:
|
2019-01-10 23:30:51 +01:00
|
|
|
image_path: The file to analyze.
|
|
|
|
sparse_image: Image is sparse
|
2018-10-19 22:44:36 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
The characteristics dictionary.
|
|
|
|
"""
|
2019-01-10 23:30:51 +01:00
|
|
|
unsparse_image_path = image_path
|
|
|
|
if sparse_image:
|
|
|
|
unsparse_image_path = UnsparseImage(image_path, replace=False)
|
2018-10-19 22:44:36 +02:00
|
|
|
|
2021-05-22 18:47:48 +02:00
|
|
|
if fs_type.startswith("ext"):
|
|
|
|
cmd = ["tune2fs", "-l", unsparse_image_path]
|
|
|
|
elif fs_type.startswith("f2fs"):
|
|
|
|
cmd = ["fsck.f2fs", "-l", unsparse_image_path]
|
|
|
|
|
2018-10-19 22:44:36 +02:00
|
|
|
try:
|
|
|
|
output = common.RunAndCheckOutput(cmd, verbose=False)
|
2018-10-25 21:23:12 +02:00
|
|
|
finally:
|
2019-01-10 23:30:51 +01:00
|
|
|
if sparse_image:
|
|
|
|
os.remove(unsparse_image_path)
|
2018-10-25 21:23:12 +02:00
|
|
|
fs_dict = {}
|
2018-10-19 22:44:36 +02:00
|
|
|
for line in output.splitlines():
|
|
|
|
fields = line.split(":")
|
|
|
|
if len(fields) == 2:
|
|
|
|
fs_dict[fields[0].strip()] = fields[1].strip()
|
|
|
|
return fs_dict
|
2018-06-19 01:32:35 +02:00
|
|
|
|
|
|
|
|
2013-12-06 02:09:18 +01:00
|
|
|
def UnsparseImage(sparse_image_path, replace=True):
|
2013-06-17 02:26:08 +02:00
|
|
|
img_dir = os.path.dirname(sparse_image_path)
|
|
|
|
unsparse_image_path = "unsparse_" + os.path.basename(sparse_image_path)
|
|
|
|
unsparse_image_path = os.path.join(img_dir, unsparse_image_path)
|
|
|
|
if os.path.exists(unsparse_image_path):
|
2013-12-06 02:09:18 +01:00
|
|
|
if replace:
|
|
|
|
os.unlink(unsparse_image_path)
|
|
|
|
else:
|
2018-09-28 01:58:00 +02:00
|
|
|
return unsparse_image_path
|
2013-06-17 02:26:08 +02:00
|
|
|
inflate_command = ["simg2img", sparse_image_path, unsparse_image_path]
|
2018-10-05 00:46:16 +02:00
|
|
|
try:
|
|
|
|
common.RunAndCheckOutput(inflate_command)
|
|
|
|
except:
|
2013-06-17 02:26:08 +02:00
|
|
|
os.remove(unsparse_image_path)
|
2018-10-05 00:46:16 +02:00
|
|
|
raise
|
2018-09-28 01:58:00 +02:00
|
|
|
return unsparse_image_path
|
2013-06-17 02:26:08 +02:00
|
|
|
|
2017-12-07 19:33:00 +01:00
|
|
|
|
2016-03-03 06:07:23 +01:00
|
|
|
def ConvertBlockMapToBaseFs(block_map_file):
|
2017-12-25 19:43:47 +01:00
|
|
|
base_fs_file = common.MakeTempFile(prefix="script_gen_", suffix=".base_fs")
|
2016-03-03 06:07:23 +01:00
|
|
|
convert_command = ["blk_alloc_to_base_fs", block_map_file, base_fs_file]
|
2018-10-05 00:46:16 +02:00
|
|
|
common.RunAndCheckOutput(convert_command)
|
2018-09-28 01:58:00 +02:00
|
|
|
return base_fs_file
|
2016-03-03 06:07:23 +01:00
|
|
|
|
2017-12-08 08:01:25 +01:00
|
|
|
|
2018-07-20 23:44:46 +02:00
|
|
|
def SetUpInDirAndFsConfig(origin_in, prop_dict):
|
|
|
|
"""Returns the in_dir and fs_config that should be used for image building.
|
|
|
|
|
2018-08-09 23:26:00 +02:00
|
|
|
When building system.img for all targets, it creates and returns a staged dir
|
|
|
|
that combines the contents of /system (i.e. in the given in_dir) and root.
|
2018-07-20 23:44:46 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
origin_in: Path to the input directory.
|
|
|
|
prop_dict: A property dict that contains info like partition size. Values
|
|
|
|
may be updated.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A tuple of in_dir and fs_config that should be used to build the image.
|
|
|
|
"""
|
|
|
|
fs_config = prop_dict.get("fs_config")
|
2018-08-09 23:26:00 +02:00
|
|
|
|
|
|
|
if prop_dict["mount_point"] == "system_other":
|
|
|
|
prop_dict["mount_point"] = "system"
|
|
|
|
return origin_in, fs_config
|
|
|
|
|
|
|
|
if prop_dict["mount_point"] != "system":
|
2018-07-20 23:44:46 +02:00
|
|
|
return origin_in, fs_config
|
|
|
|
|
2018-10-19 22:44:36 +02:00
|
|
|
if "first_pass" in prop_dict:
|
|
|
|
prop_dict["mount_point"] = "/"
|
|
|
|
return prop_dict["first_pass"]
|
|
|
|
|
2018-07-20 23:44:46 +02:00
|
|
|
# Construct a staging directory of the root file system.
|
|
|
|
in_dir = common.MakeTempDir()
|
|
|
|
root_dir = prop_dict.get("root_dir")
|
|
|
|
if root_dir:
|
|
|
|
shutil.rmtree(in_dir)
|
|
|
|
shutil.copytree(root_dir, in_dir, symlinks=True)
|
|
|
|
in_dir_system = os.path.join(in_dir, "system")
|
|
|
|
shutil.rmtree(in_dir_system, ignore_errors=True)
|
|
|
|
shutil.copytree(origin_in, in_dir_system, symlinks=True)
|
|
|
|
|
|
|
|
# Change the mount point to "/".
|
|
|
|
prop_dict["mount_point"] = "/"
|
|
|
|
if fs_config:
|
|
|
|
# We need to merge the fs_config files of system and root.
|
|
|
|
merged_fs_config = common.MakeTempFile(
|
|
|
|
prefix="merged_fs_config", suffix=".txt")
|
|
|
|
with open(merged_fs_config, "w") as fw:
|
|
|
|
if "root_fs_config" in prop_dict:
|
|
|
|
with open(prop_dict["root_fs_config"]) as fr:
|
|
|
|
fw.writelines(fr.readlines())
|
|
|
|
with open(fs_config) as fr:
|
|
|
|
fw.writelines(fr.readlines())
|
|
|
|
fs_config = merged_fs_config
|
2018-10-19 22:44:36 +02:00
|
|
|
prop_dict["first_pass"] = (in_dir, fs_config)
|
2018-07-20 23:44:46 +02:00
|
|
|
return in_dir, fs_config
|
|
|
|
|
|
|
|
|
2017-12-08 08:01:25 +01:00
|
|
|
def CheckHeadroom(ext4fs_output, prop_dict):
|
|
|
|
"""Checks if there's enough headroom space available.
|
|
|
|
|
|
|
|
Headroom is the reserved space on system image (via PRODUCT_SYSTEM_HEADROOM),
|
|
|
|
which is useful for devices with low disk space that have system image
|
|
|
|
variation between builds. The 'partition_headroom' in prop_dict is the size
|
|
|
|
in bytes, while the numbers in 'ext4fs_output' are for 4K-blocks.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
ext4fs_output: The output string from mke2fs command.
|
|
|
|
prop_dict: The property dict.
|
|
|
|
|
2018-01-03 06:19:27 +01:00
|
|
|
Raises:
|
|
|
|
AssertionError: On invalid input.
|
2018-09-28 01:58:00 +02:00
|
|
|
BuildImageError: On check failure.
|
2017-12-08 08:01:25 +01:00
|
|
|
"""
|
2018-01-03 06:19:27 +01:00
|
|
|
assert ext4fs_output is not None
|
|
|
|
assert prop_dict.get('fs_type', '').startswith('ext4')
|
|
|
|
assert 'partition_headroom' in prop_dict
|
|
|
|
assert 'mount_point' in prop_dict
|
|
|
|
|
2017-12-08 08:01:25 +01:00
|
|
|
ext4fs_stats = re.compile(
|
|
|
|
r'Created filesystem with .* (?P<used_blocks>[0-9]+)/'
|
|
|
|
r'(?P<total_blocks>[0-9]+) blocks')
|
2017-12-07 19:33:00 +01:00
|
|
|
last_line = ext4fs_output.strip().split('\n')[-1]
|
|
|
|
m = ext4fs_stats.match(last_line)
|
2017-12-08 08:01:25 +01:00
|
|
|
used_blocks = int(m.groupdict().get('used_blocks'))
|
|
|
|
total_blocks = int(m.groupdict().get('total_blocks'))
|
2018-10-19 22:44:36 +02:00
|
|
|
headroom_blocks = int(prop_dict['partition_headroom']) // BLOCK_SIZE
|
2017-12-08 08:01:25 +01:00
|
|
|
adjusted_blocks = total_blocks - headroom_blocks
|
|
|
|
if used_blocks > adjusted_blocks:
|
2018-01-03 06:19:27 +01:00
|
|
|
mount_point = prop_dict["mount_point"]
|
2018-09-28 01:58:00 +02:00
|
|
|
raise BuildImageError(
|
|
|
|
"Error: Not enough room on {} (total: {} blocks, used: {} blocks, "
|
|
|
|
"headroom: {} blocks, available: {} blocks)".format(
|
|
|
|
mount_point, total_blocks, used_blocks, headroom_blocks,
|
|
|
|
adjusted_blocks))
|
2017-12-08 08:01:25 +01:00
|
|
|
|
2022-12-15 19:31:34 +01:00
|
|
|
|
2021-09-08 12:28:32 +02:00
|
|
|
def CalculateSizeAndReserved(prop_dict, size):
|
|
|
|
fs_type = prop_dict.get("fs_type", "")
|
|
|
|
partition_headroom = int(prop_dict.get("partition_headroom", 0))
|
|
|
|
# If not specified, give us 16MB margin for GetDiskUsage error ...
|
2022-12-15 19:31:34 +01:00
|
|
|
reserved_size = int(prop_dict.get(
|
|
|
|
"partition_reserved_size", BYTES_IN_MB * 16))
|
2021-09-08 12:28:32 +02:00
|
|
|
|
|
|
|
if fs_type == "erofs":
|
|
|
|
reserved_size = int(prop_dict.get("partition_reserved_size", 0))
|
|
|
|
if reserved_size == 0:
|
|
|
|
# give .3% margin or a minimum size for AVB footer
|
|
|
|
return max(size * 1003 // 1000, 256 * 1024)
|
|
|
|
|
|
|
|
if fs_type.startswith("ext4") and partition_headroom > reserved_size:
|
|
|
|
reserved_size = partition_headroom
|
|
|
|
|
2024-01-24 21:39:36 +01:00
|
|
|
return int(size * 1.1) + reserved_size
|
2017-12-08 08:01:25 +01:00
|
|
|
|
2022-12-15 19:31:34 +01:00
|
|
|
|
2018-11-07 16:40:31 +01:00
|
|
|
def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config):
|
|
|
|
"""Builds a pure image for the files under in_dir and writes it to out_file.
|
2018-07-20 23:44:46 +02:00
|
|
|
|
2011-10-29 02:02:30 +02:00
|
|
|
Args:
|
2018-07-20 23:44:46 +02:00
|
|
|
in_dir: Path to input directory.
|
|
|
|
prop_dict: A property dict that contains info like partition size. Values
|
|
|
|
will be updated with computed values.
|
|
|
|
out_file: The output image file.
|
|
|
|
target_out: Path to the TARGET_OUT directory as in Makefile. It actually
|
|
|
|
points to the /system directory under PRODUCT_OUT. fs_config (the one
|
|
|
|
under system/core/libcutils) reads device specific FS config files from
|
|
|
|
there.
|
2018-11-07 16:40:31 +01:00
|
|
|
fs_config: The fs_config file that drives the prototype
|
2011-10-29 02:02:30 +02:00
|
|
|
|
2018-09-28 01:58:00 +02:00
|
|
|
Raises:
|
|
|
|
BuildImageError: On build image failures.
|
2011-10-29 02:02:30 +02:00
|
|
|
"""
|
|
|
|
build_command = []
|
|
|
|
fs_type = prop_dict.get("fs_type", "")
|
2022-03-04 19:57:58 +01:00
|
|
|
run_fsck = None
|
2019-12-18 02:36:31 +01:00
|
|
|
needs_projid = prop_dict.get("needs_projid", 0)
|
|
|
|
needs_casefold = prop_dict.get("needs_casefold", 0)
|
2020-10-13 04:50:05 +02:00
|
|
|
needs_compress = prop_dict.get("needs_compress", 0)
|
2013-06-17 02:26:08 +02:00
|
|
|
|
2021-09-01 06:32:45 +02:00
|
|
|
disable_sparse = "disable_sparse" in prop_dict
|
2022-03-04 19:57:58 +01:00
|
|
|
manual_sparse = False
|
2021-09-01 06:32:45 +02:00
|
|
|
|
2011-10-29 02:02:30 +02:00
|
|
|
if fs_type.startswith("ext"):
|
2016-11-19 02:06:29 +01:00
|
|
|
build_command = [prop_dict["ext_mkuserimg"]]
|
2021-09-01 06:32:45 +02:00
|
|
|
if "extfs_sparse_flag" in prop_dict and not disable_sparse:
|
2011-10-29 02:02:30 +02:00
|
|
|
build_command.append(prop_dict["extfs_sparse_flag"])
|
2024-03-20 21:58:00 +01:00
|
|
|
run_fsck = RunE2fsck
|
2011-10-29 02:02:30 +02:00
|
|
|
build_command.extend([in_dir, out_file, fs_type,
|
|
|
|
prop_dict["mount_point"]])
|
2018-09-28 00:31:11 +02:00
|
|
|
build_command.append(prop_dict["image_size"])
|
2014-11-19 03:03:13 +01:00
|
|
|
if "journal_size" in prop_dict:
|
|
|
|
build_command.extend(["-j", prop_dict["journal_size"]])
|
2013-12-06 00:54:55 +01:00
|
|
|
if "timestamp" in prop_dict:
|
|
|
|
build_command.extend(["-T", str(prop_dict["timestamp"])])
|
2015-03-25 03:07:40 +01:00
|
|
|
if fs_config:
|
2014-06-16 18:10:55 +02:00
|
|
|
build_command.extend(["-C", fs_config])
|
2015-07-09 18:54:55 +02:00
|
|
|
if target_out:
|
|
|
|
build_command.extend(["-D", target_out])
|
2015-03-25 03:07:40 +01:00
|
|
|
if "block_list" in prop_dict:
|
|
|
|
build_command.extend(["-B", prop_dict["block_list"]])
|
2016-03-03 06:07:23 +01:00
|
|
|
if "base_fs_file" in prop_dict:
|
|
|
|
base_fs_file = ConvertBlockMapToBaseFs(prop_dict["base_fs_file"])
|
|
|
|
build_command.extend(["-d", base_fs_file])
|
2014-12-17 21:34:12 +01:00
|
|
|
build_command.extend(["-L", prop_dict["mount_point"]])
|
2016-10-20 19:58:12 +02:00
|
|
|
if "extfs_inode_count" in prop_dict:
|
|
|
|
build_command.extend(["-i", prop_dict["extfs_inode_count"]])
|
2018-03-23 19:36:43 +01:00
|
|
|
if "extfs_rsv_pct" in prop_dict:
|
|
|
|
build_command.extend(["-M", prop_dict["extfs_rsv_pct"]])
|
2017-01-06 01:48:14 +01:00
|
|
|
if "flash_erase_block_size" in prop_dict:
|
|
|
|
build_command.extend(["-e", prop_dict["flash_erase_block_size"]])
|
|
|
|
if "flash_logical_block_size" in prop_dict:
|
|
|
|
build_command.extend(["-o", prop_dict["flash_logical_block_size"]])
|
2017-09-23 00:45:33 +02:00
|
|
|
# Specify UUID and hash_seed if using mke2fs.
|
2021-05-11 11:14:48 +02:00
|
|
|
if os.path.basename(prop_dict["ext_mkuserimg"]) == "mkuserimg_mke2fs":
|
2017-09-23 00:45:33 +02:00
|
|
|
if "uuid" in prop_dict:
|
|
|
|
build_command.extend(["-U", prop_dict["uuid"]])
|
|
|
|
if "hash_seed" in prop_dict:
|
|
|
|
build_command.extend(["-S", prop_dict["hash_seed"]])
|
2020-02-03 15:41:02 +01:00
|
|
|
if prop_dict.get("ext4_share_dup_blocks") == "true":
|
2018-01-22 22:15:46 +01:00
|
|
|
build_command.append("-c")
|
2019-12-18 02:36:31 +01:00
|
|
|
if (needs_projid):
|
|
|
|
build_command.extend(["--inode_size", "512"])
|
|
|
|
else:
|
|
|
|
build_command.extend(["--inode_size", "256"])
|
2015-03-25 03:07:40 +01:00
|
|
|
if "selinux_fc" in prop_dict:
|
2012-04-08 19:42:34 +02:00
|
|
|
build_command.append(prop_dict["selinux_fc"])
|
2020-06-17 07:59:16 +02:00
|
|
|
elif fs_type.startswith("erofs"):
|
2022-03-04 19:57:58 +01:00
|
|
|
build_command = ["mkfs.erofs"]
|
|
|
|
|
2021-09-23 03:02:01 +02:00
|
|
|
compressor = None
|
|
|
|
if "erofs_default_compressor" in prop_dict:
|
|
|
|
compressor = prop_dict["erofs_default_compressor"]
|
|
|
|
if "erofs_compressor" in prop_dict:
|
|
|
|
compressor = prop_dict["erofs_compressor"]
|
2022-06-28 01:18:46 +02:00
|
|
|
if compressor and compressor != "none":
|
2021-09-23 03:02:01 +02:00
|
|
|
build_command.extend(["-z", compressor])
|
2022-03-04 19:57:58 +01:00
|
|
|
|
2022-05-18 01:10:37 +02:00
|
|
|
compress_hints = None
|
|
|
|
if "erofs_default_compress_hints" in prop_dict:
|
|
|
|
compress_hints = prop_dict["erofs_default_compress_hints"]
|
|
|
|
if "erofs_compress_hints" in prop_dict:
|
|
|
|
compress_hints = prop_dict["erofs_compress_hints"]
|
|
|
|
if compress_hints:
|
|
|
|
build_command.extend(["--compress-hints", compress_hints])
|
|
|
|
|
2023-09-12 07:25:53 +02:00
|
|
|
build_command.extend(["-b", prop_dict.get("erofs_blocksize", "4096")])
|
|
|
|
|
2022-03-04 19:57:58 +01:00
|
|
|
build_command.extend(["--mount-point", prop_dict["mount_point"]])
|
|
|
|
if target_out:
|
|
|
|
build_command.extend(["--product-out", target_out])
|
|
|
|
if fs_config:
|
|
|
|
build_command.extend(["--fs-config-file", fs_config])
|
|
|
|
if "selinux_fc" in prop_dict:
|
|
|
|
build_command.extend(["--file-contexts", prop_dict["selinux_fc"]])
|
2021-10-09 03:33:43 +02:00
|
|
|
if "timestamp" in prop_dict:
|
|
|
|
build_command.extend(["-T", str(prop_dict["timestamp"])])
|
|
|
|
if "uuid" in prop_dict:
|
|
|
|
build_command.extend(["-U", prop_dict["uuid"]])
|
|
|
|
if "block_list" in prop_dict:
|
2022-03-04 19:57:58 +01:00
|
|
|
build_command.extend(["--block-list-file", prop_dict["block_list"]])
|
2021-10-13 09:20:43 +02:00
|
|
|
if "erofs_pcluster_size" in prop_dict:
|
2022-03-04 19:57:58 +01:00
|
|
|
build_command.extend(["-C", prop_dict["erofs_pcluster_size"]])
|
2021-10-13 09:20:43 +02:00
|
|
|
if "erofs_share_dup_blocks" in prop_dict:
|
2022-03-04 19:57:58 +01:00
|
|
|
build_command.extend(["--chunksize", "4096"])
|
2022-03-04 23:42:18 +01:00
|
|
|
if "erofs_use_legacy_compression" in prop_dict:
|
|
|
|
build_command.extend(["-E", "legacy-compress"])
|
2022-03-04 19:57:58 +01:00
|
|
|
|
|
|
|
build_command.extend([out_file, in_dir])
|
|
|
|
if "erofs_sparse_flag" in prop_dict and not disable_sparse:
|
|
|
|
manual_sparse = True
|
|
|
|
|
|
|
|
run_fsck = RunErofsFsck
|
2015-03-03 21:30:37 +01:00
|
|
|
elif fs_type.startswith("squash"):
|
2022-09-06 03:34:56 +02:00
|
|
|
build_command = ["mksquashfsimage"]
|
2015-03-03 21:30:37 +01:00
|
|
|
build_command.extend([in_dir, out_file])
|
2021-09-01 06:32:45 +02:00
|
|
|
if "squashfs_sparse_flag" in prop_dict and not disable_sparse:
|
2015-12-16 03:00:14 +01:00
|
|
|
build_command.extend([prop_dict["squashfs_sparse_flag"]])
|
2015-03-03 21:30:37 +01:00
|
|
|
build_command.extend(["-m", prop_dict["mount_point"]])
|
2015-07-09 18:54:55 +02:00
|
|
|
if target_out:
|
|
|
|
build_command.extend(["-d", target_out])
|
2016-04-08 07:10:51 +02:00
|
|
|
if fs_config:
|
|
|
|
build_command.extend(["-C", fs_config])
|
2015-03-25 03:07:40 +01:00
|
|
|
if "selinux_fc" in prop_dict:
|
2015-03-03 21:30:37 +01:00
|
|
|
build_command.extend(["-c", prop_dict["selinux_fc"]])
|
2016-06-13 18:46:58 +02:00
|
|
|
if "block_list" in prop_dict:
|
|
|
|
build_command.extend(["-B", prop_dict["block_list"]])
|
2018-01-20 00:51:46 +01:00
|
|
|
if "squashfs_block_size" in prop_dict:
|
|
|
|
build_command.extend(["-b", prop_dict["squashfs_block_size"]])
|
2015-06-17 21:35:15 +02:00
|
|
|
if "squashfs_compressor" in prop_dict:
|
|
|
|
build_command.extend(["-z", prop_dict["squashfs_compressor"]])
|
|
|
|
if "squashfs_compressor_opt" in prop_dict:
|
|
|
|
build_command.extend(["-zo", prop_dict["squashfs_compressor_opt"]])
|
2017-12-07 19:33:00 +01:00
|
|
|
if prop_dict.get("squashfs_disable_4k_align") == "true":
|
2016-06-16 00:53:07 +02:00
|
|
|
build_command.extend(["-a"])
|
2014-06-16 23:17:40 +02:00
|
|
|
elif fs_type.startswith("f2fs"):
|
2022-09-06 03:34:56 +02:00
|
|
|
build_command = ["mkf2fsuserimg"]
|
2018-09-28 00:31:11 +02:00
|
|
|
build_command.extend([out_file, prop_dict["image_size"]])
|
2021-09-01 06:32:45 +02:00
|
|
|
if "f2fs_sparse_flag" in prop_dict and not disable_sparse:
|
2019-10-16 19:53:41 +02:00
|
|
|
build_command.extend([prop_dict["f2fs_sparse_flag"]])
|
2017-11-29 04:21:28 +01:00
|
|
|
if fs_config:
|
|
|
|
build_command.extend(["-C", fs_config])
|
|
|
|
build_command.extend(["-f", in_dir])
|
|
|
|
if target_out:
|
|
|
|
build_command.extend(["-D", target_out])
|
|
|
|
if "selinux_fc" in prop_dict:
|
|
|
|
build_command.extend(["-s", prop_dict["selinux_fc"]])
|
|
|
|
build_command.extend(["-t", prop_dict["mount_point"]])
|
|
|
|
if "timestamp" in prop_dict:
|
|
|
|
build_command.extend(["-T", str(prop_dict["timestamp"])])
|
2021-06-13 17:54:01 +02:00
|
|
|
if "block_list" in prop_dict:
|
|
|
|
build_command.extend(["-B", prop_dict["block_list"]])
|
2017-11-29 04:21:28 +01:00
|
|
|
build_command.extend(["-L", prop_dict["mount_point"]])
|
2019-12-18 02:36:31 +01:00
|
|
|
if (needs_projid):
|
|
|
|
build_command.append("--prjquota")
|
|
|
|
if (needs_casefold):
|
|
|
|
build_command.append("--casefold")
|
2021-05-22 18:47:48 +02:00
|
|
|
if (needs_compress or prop_dict.get("f2fs_compress") == "true"):
|
2020-10-13 04:50:05 +02:00
|
|
|
build_command.append("--compression")
|
2022-10-27 18:46:03 +02:00
|
|
|
if "ro_mount_point" in prop_dict:
|
2021-05-21 08:13:59 +02:00
|
|
|
build_command.append("--readonly")
|
2021-06-13 17:54:01 +02:00
|
|
|
if (prop_dict.get("f2fs_compress") == "true"):
|
2020-11-04 02:29:09 +01:00
|
|
|
build_command.append("--sldc")
|
2021-05-22 18:47:48 +02:00
|
|
|
if (prop_dict.get("f2fs_sldc_flags") == None):
|
2020-11-04 02:29:09 +01:00
|
|
|
build_command.append(str(0))
|
|
|
|
else:
|
2021-05-22 18:47:48 +02:00
|
|
|
sldc_flags_str = prop_dict.get("f2fs_sldc_flags")
|
2020-11-04 02:29:09 +01:00
|
|
|
sldc_flags = sldc_flags_str.split()
|
|
|
|
build_command.append(str(len(sldc_flags)))
|
|
|
|
build_command.extend(sldc_flags)
|
2023-10-14 02:22:44 +02:00
|
|
|
f2fs_blocksize = prop_dict.get("f2fs_blocksize", "4096")
|
|
|
|
build_command.extend(["-b", f2fs_blocksize])
|
2011-10-29 02:02:30 +02:00
|
|
|
else:
|
2018-09-28 01:58:00 +02:00
|
|
|
raise BuildImageError(
|
|
|
|
"Error: unknown filesystem type: {}".format(fs_type))
|
2011-10-29 02:02:30 +02:00
|
|
|
|
2018-10-05 00:46:16 +02:00
|
|
|
try:
|
|
|
|
mkfs_output = common.RunAndCheckOutput(build_command)
|
|
|
|
except:
|
2018-09-28 01:58:00 +02:00
|
|
|
try:
|
|
|
|
du = GetDiskUsage(in_dir)
|
|
|
|
du_str = "{} bytes ({} MB)".format(du, du // BYTES_IN_MB)
|
2018-10-05 00:46:16 +02:00
|
|
|
# Suppress any errors from GetDiskUsage() to avoid hiding the real errors
|
|
|
|
# from common.RunAndCheckOutput().
|
2018-10-12 19:30:39 +02:00
|
|
|
except Exception: # pylint: disable=broad-except
|
|
|
|
logger.exception("Failed to compute disk usage with du")
|
2018-09-28 01:58:00 +02:00
|
|
|
du_str = "unknown"
|
2018-07-23 22:05:00 +02:00
|
|
|
print(
|
2018-11-07 16:40:31 +01:00
|
|
|
"Out of space? Out of inodes? The tree size of {} is {}, "
|
|
|
|
"with reserved space of {} bytes ({} MB).".format(
|
2018-07-20 23:44:46 +02:00
|
|
|
in_dir, du_str,
|
2018-07-23 22:05:00 +02:00
|
|
|
int(prop_dict.get("partition_reserved_size", 0)),
|
|
|
|
int(prop_dict.get("partition_reserved_size", 0)) // BYTES_IN_MB))
|
2021-04-29 09:24:50 +02:00
|
|
|
if ("image_size" in prop_dict and "partition_size" in prop_dict):
|
|
|
|
print(
|
|
|
|
"The max image size for filesystem files is {} bytes ({} MB), "
|
|
|
|
"out of a total partition size of {} bytes ({} MB).".format(
|
|
|
|
int(prop_dict["image_size"]),
|
|
|
|
int(prop_dict["image_size"]) // BYTES_IN_MB,
|
|
|
|
int(prop_dict["partition_size"]),
|
|
|
|
int(prop_dict["partition_size"]) // BYTES_IN_MB))
|
2018-10-05 00:46:16 +02:00
|
|
|
raise
|
2012-11-27 03:10:23 +01:00
|
|
|
|
2022-03-04 19:57:58 +01:00
|
|
|
if run_fsck and prop_dict.get("skip_fsck") != "true":
|
|
|
|
run_fsck(out_file)
|
2018-11-07 16:40:31 +01:00
|
|
|
|
2022-03-04 19:57:58 +01:00
|
|
|
if manual_sparse:
|
|
|
|
temp_file = out_file + ".sparse"
|
|
|
|
img2simg_argv = ["img2simg", out_file, temp_file]
|
|
|
|
common.RunAndCheckOutput(img2simg_argv)
|
|
|
|
os.rename(temp_file, out_file)
|
2018-11-07 16:40:31 +01:00
|
|
|
|
|
|
|
return mkfs_output
|
|
|
|
|
2022-03-04 19:57:58 +01:00
|
|
|
|
|
|
|
def RunE2fsck(out_file):
|
|
|
|
unsparse_image = UnsparseImage(out_file, replace=False)
|
|
|
|
|
|
|
|
# Run e2fsck on the inflated image file
|
|
|
|
e2fsck_command = ["e2fsck", "-f", "-n", unsparse_image]
|
|
|
|
try:
|
|
|
|
common.RunAndCheckOutput(e2fsck_command)
|
|
|
|
finally:
|
|
|
|
os.remove(unsparse_image)
|
|
|
|
|
|
|
|
|
|
|
|
def RunErofsFsck(out_file):
|
|
|
|
fsck_command = ["fsck.erofs", "--extract", out_file]
|
|
|
|
try:
|
|
|
|
common.RunAndCheckOutput(fsck_command)
|
|
|
|
except:
|
|
|
|
print("Check failed for EROFS image {}".format(out_file))
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
2023-06-03 01:41:19 +02:00
|
|
|
def SetUUIDIfNotExist(image_props):
|
|
|
|
|
|
|
|
# Use repeatable ext4 FS UUID and hash_seed UUID (based on partition name and
|
|
|
|
# build fingerprint). Also use the legacy build id, because the vbmeta digest
|
|
|
|
# isn't available at this point.
|
|
|
|
what = image_props["mount_point"]
|
|
|
|
fingerprint = image_props.get("fingerprint", "")
|
|
|
|
uuid_seed = what + "-" + fingerprint
|
|
|
|
logger.info("Using fingerprint %s for partition %s", fingerprint, what)
|
|
|
|
image_props["uuid"] = str(uuid.uuid5(uuid.NAMESPACE_URL, uuid_seed))
|
|
|
|
hash_seed = "hash_seed-" + uuid_seed
|
|
|
|
image_props["hash_seed"] = str(uuid.uuid5(uuid.NAMESPACE_URL, hash_seed))
|
|
|
|
|
|
|
|
|
2018-11-07 16:40:31 +01:00
|
|
|
def BuildImage(in_dir, prop_dict, out_file, target_out=None):
|
|
|
|
"""Builds an image for the files under in_dir and writes it to out_file.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
in_dir: Path to input directory.
|
|
|
|
prop_dict: A property dict that contains info like partition size. Values
|
|
|
|
will be updated with computed values.
|
|
|
|
out_file: The output image file.
|
|
|
|
target_out: Path to the TARGET_OUT directory as in Makefile. It actually
|
|
|
|
points to the /system directory under PRODUCT_OUT. fs_config (the one
|
|
|
|
under system/core/libcutils) reads device specific FS config files from
|
|
|
|
there.
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
BuildImageError: On build image failures.
|
|
|
|
"""
|
|
|
|
in_dir, fs_config = SetUpInDirAndFsConfig(in_dir, prop_dict)
|
2023-06-03 01:41:19 +02:00
|
|
|
SetUUIDIfNotExist(prop_dict)
|
2018-11-07 16:40:31 +01:00
|
|
|
|
|
|
|
build_command = []
|
|
|
|
fs_type = prop_dict.get("fs_type", "")
|
|
|
|
|
|
|
|
fs_spans_partition = True
|
2020-12-04 09:53:06 +01:00
|
|
|
if fs_type.startswith("squash") or fs_type.startswith("erofs"):
|
2018-11-07 16:40:31 +01:00
|
|
|
fs_spans_partition = False
|
2021-05-22 18:47:48 +02:00
|
|
|
elif fs_type.startswith("f2fs") and prop_dict.get("f2fs_compress") == "true":
|
|
|
|
fs_spans_partition = False
|
2018-11-07 16:40:31 +01:00
|
|
|
|
|
|
|
# Get a builder for creating an image that's to be verified by Verified Boot,
|
|
|
|
# or None if not applicable.
|
|
|
|
verity_image_builder = verity_utils.CreateVerityImageBuilder(prop_dict)
|
|
|
|
|
2021-09-01 06:32:45 +02:00
|
|
|
disable_sparse = "disable_sparse" in prop_dict
|
2021-09-08 12:11:22 +02:00
|
|
|
mkfs_output = None
|
2018-11-07 16:40:31 +01:00
|
|
|
if (prop_dict.get("use_dynamic_partition_size") == "true" and
|
2022-12-15 19:31:34 +01:00
|
|
|
"partition_size" not in prop_dict):
|
2018-11-07 16:40:31 +01:00
|
|
|
# If partition_size is not defined, use output of `du' + reserved_size.
|
2020-12-04 09:58:24 +01:00
|
|
|
# For compressed file system, it's better to use the compressed size to avoid wasting space.
|
|
|
|
if fs_type.startswith("erofs"):
|
2022-12-15 19:31:34 +01:00
|
|
|
mkfs_output = BuildImageMkfs(
|
|
|
|
in_dir, prop_dict, out_file, target_out, fs_config)
|
2021-09-08 12:11:22 +02:00
|
|
|
if "erofs_sparse_flag" in prop_dict and not disable_sparse:
|
|
|
|
image_path = UnsparseImage(out_file, replace=False)
|
|
|
|
size = GetDiskUsage(image_path)
|
|
|
|
os.remove(image_path)
|
|
|
|
else:
|
|
|
|
size = GetDiskUsage(out_file)
|
2020-12-04 09:58:24 +01:00
|
|
|
else:
|
|
|
|
size = GetDiskUsage(in_dir)
|
2018-11-07 16:40:31 +01:00
|
|
|
logger.info(
|
|
|
|
"The tree size of %s is %d MB.", in_dir, size // BYTES_IN_MB)
|
2021-09-08 12:28:32 +02:00
|
|
|
size = CalculateSizeAndReserved(prop_dict, size)
|
2018-11-07 16:40:31 +01:00
|
|
|
# Round this up to a multiple of 4K so that avbtool works
|
|
|
|
size = common.RoundUpTo4K(size)
|
|
|
|
if fs_type.startswith("ext"):
|
|
|
|
prop_dict["partition_size"] = str(size)
|
|
|
|
prop_dict["image_size"] = str(size)
|
|
|
|
if "extfs_inode_count" not in prop_dict:
|
|
|
|
prop_dict["extfs_inode_count"] = str(GetInodeUsage(in_dir))
|
|
|
|
logger.info(
|
|
|
|
"First Pass based on estimates of %d MB and %s inodes.",
|
|
|
|
size // BYTES_IN_MB, prop_dict["extfs_inode_count"])
|
|
|
|
BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config)
|
2019-01-10 23:30:51 +01:00
|
|
|
sparse_image = False
|
2021-09-01 06:32:45 +02:00
|
|
|
if "extfs_sparse_flag" in prop_dict and not disable_sparse:
|
2019-01-10 23:30:51 +01:00
|
|
|
sparse_image = True
|
2021-05-22 18:47:48 +02:00
|
|
|
fs_dict = GetFilesystemCharacteristics(fs_type, out_file, sparse_image)
|
2018-11-07 16:40:31 +01:00
|
|
|
os.remove(out_file)
|
|
|
|
block_size = int(fs_dict.get("Block size", "4096"))
|
|
|
|
free_size = int(fs_dict.get("Free blocks", "0")) * block_size
|
|
|
|
reserved_size = int(prop_dict.get("partition_reserved_size", 0))
|
|
|
|
partition_headroom = int(fs_dict.get("partition_headroom", 0))
|
|
|
|
if fs_type.startswith("ext4") and partition_headroom > reserved_size:
|
|
|
|
reserved_size = partition_headroom
|
|
|
|
if free_size <= reserved_size:
|
|
|
|
logger.info(
|
|
|
|
"Not worth reducing image %d <= %d.", free_size, reserved_size)
|
|
|
|
else:
|
|
|
|
size -= free_size
|
|
|
|
size += reserved_size
|
2019-01-10 17:36:34 +01:00
|
|
|
if reserved_size == 0:
|
2019-01-16 17:03:10 +01:00
|
|
|
# add .3% margin
|
|
|
|
size = size * 1003 // 1000
|
2019-01-10 17:36:34 +01:00
|
|
|
# Use a minimum size, otherwise we will fail to calculate an AVB footer
|
|
|
|
# or fail to construct an ext4 image.
|
|
|
|
size = max(size, 256 * 1024)
|
2018-11-07 16:40:31 +01:00
|
|
|
if block_size <= 4096:
|
|
|
|
size = common.RoundUpTo4K(size)
|
|
|
|
else:
|
|
|
|
size = ((size + block_size - 1) // block_size) * block_size
|
|
|
|
extfs_inode_count = prop_dict["extfs_inode_count"]
|
|
|
|
inodes = int(fs_dict.get("Inode count", extfs_inode_count))
|
|
|
|
inodes -= int(fs_dict.get("Free inodes", "0"))
|
2019-01-16 17:03:10 +01:00
|
|
|
# add .2% margin or 1 inode, whichever is greater
|
|
|
|
spare_inodes = inodes * 2 // 1000
|
|
|
|
min_spare_inodes = 1
|
|
|
|
if spare_inodes < min_spare_inodes:
|
|
|
|
spare_inodes = min_spare_inodes
|
|
|
|
inodes += spare_inodes
|
2018-11-07 16:40:31 +01:00
|
|
|
prop_dict["extfs_inode_count"] = str(inodes)
|
|
|
|
prop_dict["partition_size"] = str(size)
|
|
|
|
logger.info(
|
|
|
|
"Allocating %d Inodes for %s.", inodes, out_file)
|
2021-05-22 18:47:48 +02:00
|
|
|
elif fs_type.startswith("f2fs") and prop_dict.get("f2fs_compress") == "true":
|
|
|
|
prop_dict["partition_size"] = str(size)
|
|
|
|
prop_dict["image_size"] = str(size)
|
|
|
|
BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config)
|
|
|
|
sparse_image = False
|
2021-09-01 06:32:45 +02:00
|
|
|
if "f2fs_sparse_flag" in prop_dict and not disable_sparse:
|
2021-05-22 18:47:48 +02:00
|
|
|
sparse_image = True
|
|
|
|
fs_dict = GetFilesystemCharacteristics(fs_type, out_file, sparse_image)
|
|
|
|
os.remove(out_file)
|
|
|
|
block_count = int(fs_dict.get("block_count", "0"))
|
|
|
|
log_blocksize = int(fs_dict.get("log_blocksize", "12"))
|
|
|
|
size = block_count << log_blocksize
|
|
|
|
prop_dict["partition_size"] = str(size)
|
2018-11-07 16:40:31 +01:00
|
|
|
if verity_image_builder:
|
|
|
|
size = verity_image_builder.CalculateDynamicPartitionSize(size)
|
|
|
|
prop_dict["partition_size"] = str(size)
|
|
|
|
logger.info(
|
2024-01-24 21:39:36 +01:00
|
|
|
"Allocating %d MB for %s", size // BYTES_IN_MB, out_file)
|
2018-11-07 16:40:31 +01:00
|
|
|
|
|
|
|
prop_dict["image_size"] = prop_dict["partition_size"]
|
|
|
|
|
|
|
|
# Adjust the image size to make room for the hashes if this is to be verified.
|
|
|
|
if verity_image_builder:
|
|
|
|
max_image_size = verity_image_builder.CalculateMaxImageSize()
|
|
|
|
prop_dict["image_size"] = str(max_image_size)
|
|
|
|
|
2021-09-08 12:11:22 +02:00
|
|
|
if not mkfs_output:
|
2022-12-15 19:31:34 +01:00
|
|
|
mkfs_output = BuildImageMkfs(
|
|
|
|
in_dir, prop_dict, out_file, target_out, fs_config)
|
2018-11-07 16:40:31 +01:00
|
|
|
|
2021-11-12 03:01:29 +01:00
|
|
|
# Update the image (eg filesystem size). This can be different eg if mkfs
|
|
|
|
# rounds the requested size down due to alignment.
|
|
|
|
prop_dict["image_size"] = common.sparse_img.GetImagePartitionSize(out_file)
|
|
|
|
|
2017-12-08 08:01:25 +01:00
|
|
|
# Check if there's enough headroom space available for ext4 image.
|
2017-12-07 23:07:44 +01:00
|
|
|
if "partition_headroom" in prop_dict and fs_type.startswith("ext4"):
|
2018-09-28 01:58:00 +02:00
|
|
|
CheckHeadroom(mkfs_output, prop_dict)
|
2015-06-23 20:16:05 +02:00
|
|
|
|
2018-10-03 23:23:59 +02:00
|
|
|
if not fs_spans_partition and verity_image_builder:
|
|
|
|
verity_image_builder.PadSparseImage(out_file)
|
2015-03-24 20:42:03 +01:00
|
|
|
|
2017-12-07 19:33:00 +01:00
|
|
|
# Create the verified image if this is to be verified.
|
2018-10-03 23:23:59 +02:00
|
|
|
if verity_image_builder:
|
|
|
|
verity_image_builder.Build(out_file)
|
2016-09-30 23:29:22 +02:00
|
|
|
|
2022-12-15 19:31:34 +01:00
|
|
|
|
2023-06-03 01:41:19 +02:00
|
|
|
def TryParseFingerprint(glob_dict: dict):
|
|
|
|
for (key, val) in glob_dict.items():
|
|
|
|
if not key.endswith("_add_hashtree_footer_args") and not key.endswith("_add_hash_footer_args"):
|
|
|
|
continue
|
|
|
|
for arg in shlex.split(val):
|
|
|
|
m = re.match(r"^com\.android\.build\.\w+\.fingerprint:", arg)
|
|
|
|
if m is None:
|
|
|
|
continue
|
|
|
|
fingerprint = arg[len(m.group()):]
|
|
|
|
glob_dict["fingerprint"] = fingerprint
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2011-10-29 02:02:30 +02:00
|
|
|
def ImagePropFromGlobalDict(glob_dict, mount_point):
|
|
|
|
"""Build an image property dictionary from the global dictionary.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
glob_dict: the global dictionary from the build system.
|
|
|
|
mount_point: such as "system", "data" etc.
|
|
|
|
"""
|
2013-12-06 20:53:27 +01:00
|
|
|
d = {}
|
2023-06-03 01:41:19 +02:00
|
|
|
TryParseFingerprint(glob_dict)
|
2015-09-28 22:44:13 +02:00
|
|
|
|
2023-07-15 08:35:07 +02:00
|
|
|
# Set fixed timestamp for building the OTA package.
|
|
|
|
if "use_fixed_timestamp" in glob_dict:
|
|
|
|
d["timestamp"] = FIXED_FILE_TIMESTAMP
|
2015-10-01 01:01:14 +02:00
|
|
|
if "build.prop" in glob_dict:
|
2020-05-09 07:24:18 +02:00
|
|
|
timestamp = glob_dict["build.prop"].GetProp("ro.build.date.utc")
|
|
|
|
if timestamp:
|
|
|
|
d["timestamp"] = timestamp
|
2011-11-04 19:37:01 +01:00
|
|
|
|
|
|
|
def copy_prop(src_p, dest_p):
|
2018-03-23 19:36:43 +01:00
|
|
|
"""Copy a property from the global dictionary.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
src_p: The source property in the global dictionary.
|
|
|
|
dest_p: The destination property.
|
|
|
|
Returns:
|
|
|
|
True if property was found and copied, False otherwise.
|
|
|
|
"""
|
2011-11-04 19:37:01 +01:00
|
|
|
if src_p in glob_dict:
|
|
|
|
d[dest_p] = str(glob_dict[src_p])
|
2018-03-23 19:36:43 +01:00
|
|
|
return True
|
|
|
|
return False
|
2011-11-04 19:37:01 +01:00
|
|
|
|
2011-10-29 02:02:30 +02:00
|
|
|
common_props = (
|
|
|
|
"extfs_sparse_flag",
|
2021-09-23 03:02:01 +02:00
|
|
|
"erofs_default_compressor",
|
2022-05-18 01:10:37 +02:00
|
|
|
"erofs_default_compress_hints",
|
2021-10-13 09:20:43 +02:00
|
|
|
"erofs_pcluster_size",
|
2023-09-12 07:25:53 +02:00
|
|
|
"erofs_blocksize",
|
2021-10-13 09:20:43 +02:00
|
|
|
"erofs_share_dup_blocks",
|
2020-06-17 07:59:16 +02:00
|
|
|
"erofs_sparse_flag",
|
2022-03-04 23:42:18 +01:00
|
|
|
"erofs_use_legacy_compression",
|
2015-12-16 03:00:14 +01:00
|
|
|
"squashfs_sparse_flag",
|
2021-05-22 18:47:48 +02:00
|
|
|
"system_f2fs_compress",
|
2020-11-04 02:29:09 +01:00
|
|
|
"system_f2fs_sldc_flags",
|
2019-10-16 19:53:41 +02:00
|
|
|
"f2fs_sparse_flag",
|
2023-10-14 02:22:44 +02:00
|
|
|
"f2fs_blocksize",
|
2013-02-27 22:54:02 +01:00
|
|
|
"skip_fsck",
|
2016-11-19 02:06:29 +01:00
|
|
|
"ext_mkuserimg",
|
2017-05-26 12:30:04 +02:00
|
|
|
"avb_enable",
|
2017-09-28 02:17:43 +02:00
|
|
|
"avb_avbtool",
|
2018-07-31 21:47:27 +02:00
|
|
|
"use_dynamic_partition_size",
|
2023-06-03 01:41:19 +02:00
|
|
|
"fingerprint",
|
2017-09-28 02:17:43 +02:00
|
|
|
)
|
2011-10-29 02:02:30 +02:00
|
|
|
for p in common_props:
|
2011-11-04 19:37:01 +01:00
|
|
|
copy_prop(p, p)
|
2011-10-29 02:02:30 +02:00
|
|
|
|
2021-10-12 02:31:26 +02:00
|
|
|
ro_mount_points = set([
|
|
|
|
"odm",
|
|
|
|
"odm_dlkm",
|
|
|
|
"oem",
|
|
|
|
"product",
|
|
|
|
"system",
|
2022-01-27 08:05:08 +01:00
|
|
|
"system_dlkm",
|
2021-10-12 02:31:26 +02:00
|
|
|
"system_ext",
|
|
|
|
"system_other",
|
|
|
|
"vendor",
|
|
|
|
"vendor_dlkm",
|
|
|
|
])
|
|
|
|
|
|
|
|
# Tuple layout: (readonly, specific prop, general prop)
|
|
|
|
fmt_props = (
|
|
|
|
# Generic first, then specific file type.
|
|
|
|
(False, "fs_type", "fs_type"),
|
|
|
|
(False, "{}_fs_type", "fs_type"),
|
|
|
|
|
|
|
|
# Ordering for these doesn't matter.
|
|
|
|
(False, "{}_selinux_fc", "selinux_fc"),
|
|
|
|
(False, "{}_size", "partition_size"),
|
|
|
|
(True, "avb_{}_add_hashtree_footer_args", "avb_add_hashtree_footer_args"),
|
|
|
|
(True, "avb_{}_algorithm", "avb_algorithm"),
|
|
|
|
(True, "avb_{}_hashtree_enable", "avb_hashtree_enable"),
|
|
|
|
(True, "avb_{}_key_path", "avb_key_path"),
|
|
|
|
(True, "avb_{}_salt", "avb_salt"),
|
2022-03-04 23:42:18 +01:00
|
|
|
(True, "erofs_use_legacy_compression", "erofs_use_legacy_compression"),
|
2021-10-12 02:31:26 +02:00
|
|
|
(True, "ext4_share_dup_blocks", "ext4_share_dup_blocks"),
|
|
|
|
(True, "{}_base_fs_file", "base_fs_file"),
|
|
|
|
(True, "{}_disable_sparse", "disable_sparse"),
|
|
|
|
(True, "{}_erofs_compressor", "erofs_compressor"),
|
2022-05-18 01:10:37 +02:00
|
|
|
(True, "{}_erofs_compress_hints", "erofs_compress_hints"),
|
2021-10-13 09:20:43 +02:00
|
|
|
(True, "{}_erofs_pcluster_size", "erofs_pcluster_size"),
|
2023-09-12 07:25:53 +02:00
|
|
|
(True, "{}_erofs_blocksize", "erofs_blocksize"),
|
2021-10-13 09:20:43 +02:00
|
|
|
(True, "{}_erofs_share_dup_blocks", "erofs_share_dup_blocks"),
|
2021-10-12 02:31:26 +02:00
|
|
|
(True, "{}_extfs_inode_count", "extfs_inode_count"),
|
|
|
|
(True, "{}_f2fs_compress", "f2fs_compress"),
|
|
|
|
(True, "{}_f2fs_sldc_flags", "f2fs_sldc_flags"),
|
2023-10-14 02:22:44 +02:00
|
|
|
(True, "{}_f2fs_blocksize", "f2fs_block_size"),
|
2021-10-12 02:31:26 +02:00
|
|
|
(True, "{}_reserved_size", "partition_reserved_size"),
|
|
|
|
(True, "{}_squashfs_block_size", "squashfs_block_size"),
|
|
|
|
(True, "{}_squashfs_compressor", "squashfs_compressor"),
|
|
|
|
(True, "{}_squashfs_compressor_opt", "squashfs_compressor_opt"),
|
|
|
|
(True, "{}_squashfs_disable_4k_align", "squashfs_disable_4k_align"),
|
|
|
|
(True, "{}_verity_block_device", "verity_block_device"),
|
2021-09-23 03:02:01 +02:00
|
|
|
)
|
|
|
|
|
2021-10-12 02:31:26 +02:00
|
|
|
# Translate prefixed properties into generic ones.
|
|
|
|
if mount_point == "data":
|
|
|
|
prefix = "userdata"
|
|
|
|
else:
|
|
|
|
prefix = mount_point
|
|
|
|
|
|
|
|
for readonly, src_prop, dest_prop in fmt_props:
|
|
|
|
if readonly and mount_point not in ro_mount_points:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if src_prop == "fs_type":
|
|
|
|
# This property is legacy and only used on a few partitions. b/202600377
|
|
|
|
allowed_partitions = set(["system", "system_other", "data", "oem"])
|
|
|
|
if mount_point not in allowed_partitions:
|
2022-12-15 19:31:34 +01:00
|
|
|
continue
|
2021-10-12 02:31:26 +02:00
|
|
|
|
2022-02-18 10:10:22 +01:00
|
|
|
if (mount_point == "system_other") and (dest_prop != "partition_size"):
|
2021-10-12 02:31:26 +02:00
|
|
|
# Propagate system properties to system_other. They'll get overridden
|
|
|
|
# after as needed.
|
|
|
|
copy_prop(src_prop.format("system"), dest_prop)
|
|
|
|
|
|
|
|
copy_prop(src_prop.format(prefix), dest_prop)
|
|
|
|
|
|
|
|
# Set prefixed properties that need a default value.
|
|
|
|
if mount_point in ro_mount_points:
|
|
|
|
prop = "{}_journal_size".format(prefix)
|
|
|
|
if not copy_prop(prop, "journal_size"):
|
|
|
|
d["journal_size"] = "0"
|
|
|
|
|
|
|
|
prop = "{}_extfs_rsv_pct".format(prefix)
|
|
|
|
if not copy_prop(prop, "extfs_rsv_pct"):
|
|
|
|
d["extfs_rsv_pct"] = "0"
|
|
|
|
|
2022-10-27 18:46:03 +02:00
|
|
|
d["ro_mount_point"] = "1"
|
|
|
|
|
2021-10-12 02:31:26 +02:00
|
|
|
# Copy partition-specific properties.
|
2011-10-29 02:02:30 +02:00
|
|
|
d["mount_point"] = mount_point
|
|
|
|
if mount_point == "system":
|
2017-05-03 22:43:27 +02:00
|
|
|
copy_prop("system_headroom", "partition_headroom")
|
2018-07-21 00:20:28 +02:00
|
|
|
copy_prop("root_dir", "root_dir")
|
|
|
|
copy_prop("root_fs_config", "root_fs_config")
|
2011-10-29 02:02:30 +02:00
|
|
|
elif mount_point == "data":
|
2014-06-16 23:17:40 +02:00
|
|
|
# Copy the generic fs type first, override with specific one if available.
|
2017-12-07 19:33:00 +01:00
|
|
|
copy_prop("flash_logical_block_size", "flash_logical_block_size")
|
2017-01-06 01:48:14 +01:00
|
|
|
copy_prop("flash_erase_block_size", "flash_erase_block_size")
|
2019-12-18 02:36:31 +01:00
|
|
|
copy_prop("needs_casefold", "needs_casefold")
|
|
|
|
copy_prop("needs_projid", "needs_projid")
|
2020-10-13 04:50:05 +02:00
|
|
|
copy_prop("needs_compress", "needs_compress")
|
2016-09-30 23:29:22 +02:00
|
|
|
d["partition_name"] = mount_point
|
2011-10-29 02:02:30 +02:00
|
|
|
return d
|
|
|
|
|
|
|
|
|
|
|
|
def LoadGlobalDict(filename):
|
|
|
|
"""Load "name=value" pairs from filename"""
|
|
|
|
d = {}
|
|
|
|
f = open(filename)
|
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
|
|
|
if not line or line.startswith("#"):
|
|
|
|
continue
|
|
|
|
k, v = line.split("=", 1)
|
|
|
|
d[k] = v
|
|
|
|
f.close()
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
2018-06-19 01:32:35 +02:00
|
|
|
def GlobalDictFromImageProp(image_prop, mount_point):
|
|
|
|
d = {}
|
2022-12-15 19:31:34 +01:00
|
|
|
|
2018-06-19 01:32:35 +02:00
|
|
|
def copy_prop(src_p, dest_p):
|
|
|
|
if src_p in image_prop:
|
|
|
|
d[dest_p] = image_prop[src_p]
|
|
|
|
return True
|
|
|
|
return False
|
2018-07-23 22:05:00 +02:00
|
|
|
|
2018-06-19 01:32:35 +02:00
|
|
|
if mount_point == "system":
|
2018-09-28 00:31:11 +02:00
|
|
|
copy_prop("partition_size", "system_size")
|
2018-06-19 01:32:35 +02:00
|
|
|
elif mount_point == "system_other":
|
2019-01-29 06:30:18 +01:00
|
|
|
copy_prop("partition_size", "system_other_size")
|
2018-06-20 01:23:16 +02:00
|
|
|
elif mount_point == "vendor":
|
2018-09-28 00:31:11 +02:00
|
|
|
copy_prop("partition_size", "vendor_size")
|
2017-11-14 16:42:30 +01:00
|
|
|
elif mount_point == "odm":
|
2018-09-28 00:31:11 +02:00
|
|
|
copy_prop("partition_size", "odm_size")
|
2020-05-07 23:58:20 +02:00
|
|
|
elif mount_point == "vendor_dlkm":
|
|
|
|
copy_prop("partition_size", "vendor_dlkm_size")
|
2020-07-16 01:52:59 +02:00
|
|
|
elif mount_point == "odm_dlkm":
|
|
|
|
copy_prop("partition_size", "odm_dlkm_size")
|
2022-01-27 08:05:08 +01:00
|
|
|
elif mount_point == "system_dlkm":
|
|
|
|
copy_prop("partition_size", "system_dlkm_size")
|
2018-07-21 00:19:34 +02:00
|
|
|
elif mount_point == "product":
|
2018-09-28 00:31:11 +02:00
|
|
|
copy_prop("partition_size", "product_size")
|
2019-06-25 08:58:13 +02:00
|
|
|
elif mount_point == "system_ext":
|
|
|
|
copy_prop("partition_size", "system_ext_size")
|
2018-06-19 01:32:35 +02:00
|
|
|
return d
|
|
|
|
|
|
|
|
|
2022-12-15 19:31:34 +01:00
|
|
|
def BuildVBMeta(in_dir, glob_dict, output_path):
|
|
|
|
"""Creates a VBMeta image.
|
|
|
|
|
|
|
|
It generates the requested VBMeta image. The requested image could be for
|
|
|
|
top-level or chained VBMeta image, which is determined based on the name.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
output_path: Path to generated vbmeta.img
|
|
|
|
partitions: A dict that's keyed by partition names with image paths as
|
|
|
|
values. Only valid partition names are accepted, as partitions listed
|
|
|
|
in common.AVB_PARTITIONS and custom partitions listed in
|
|
|
|
OPTIONS.info_dict.get("avb_custom_images_partition_list")
|
|
|
|
name: Name of the VBMeta partition, e.g. 'vbmeta', 'vbmeta_system'.
|
|
|
|
needed_partitions: Partitions whose descriptors should be included into the
|
|
|
|
generated VBMeta image.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Path to the created image.
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
AssertionError: On invalid input args.
|
|
|
|
"""
|
|
|
|
vbmeta_partitions = common.AVB_PARTITIONS[:]
|
|
|
|
name = os.path.basename(output_path).rstrip(".img")
|
|
|
|
vbmeta_system = glob_dict.get("avb_vbmeta_system", "").strip()
|
|
|
|
vbmeta_vendor = glob_dict.get("avb_vbmeta_vendor", "").strip()
|
|
|
|
if "vbmeta_system" in name:
|
|
|
|
vbmeta_partitions = vbmeta_system.split()
|
|
|
|
elif "vbmeta_vendor" in name:
|
|
|
|
vbmeta_partitions = vbmeta_vendor.split()
|
|
|
|
else:
|
|
|
|
if vbmeta_system:
|
|
|
|
vbmeta_partitions = [
|
|
|
|
item for item in vbmeta_partitions
|
|
|
|
if item not in vbmeta_system.split()]
|
|
|
|
vbmeta_partitions.append("vbmeta_system")
|
|
|
|
|
|
|
|
if vbmeta_vendor:
|
|
|
|
vbmeta_partitions = [
|
|
|
|
item for item in vbmeta_partitions
|
|
|
|
if item not in vbmeta_vendor.split()]
|
|
|
|
vbmeta_partitions.append("vbmeta_vendor")
|
|
|
|
|
|
|
|
partitions = {part: os.path.join(in_dir, part + ".img")
|
|
|
|
for part in vbmeta_partitions}
|
2023-06-03 01:41:19 +02:00
|
|
|
partitions = {part: path for (part, path) in partitions.items() if os.path.exists(path)}
|
2022-12-15 19:31:34 +01:00
|
|
|
common.BuildVBMeta(output_path, partitions, name, vbmeta_partitions)
|
|
|
|
|
|
|
|
|
2023-07-26 23:33:51 +02:00
|
|
|
def BuildImageOrVBMeta(input_directory, target_out, glob_dict, image_properties, out_file):
|
|
|
|
try:
|
|
|
|
if "vbmeta" in os.path.basename(out_file):
|
|
|
|
OPTIONS.info_dict = glob_dict
|
|
|
|
BuildVBMeta(input_directory, glob_dict, out_file)
|
|
|
|
else:
|
|
|
|
BuildImage(input_directory, image_properties, out_file, target_out)
|
|
|
|
except:
|
|
|
|
logger.error("Failed to build %s from %s", out_file, input_directory)
|
|
|
|
raise
|
2023-09-08 03:24:39 +02:00
|
|
|
|
2023-07-26 23:33:51 +02:00
|
|
|
|
2023-07-26 23:33:51 +02:00
|
|
|
def CopyInputDirectory(src, dst, filter_file):
|
|
|
|
with open(filter_file, 'r') as f:
|
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
|
|
|
if not line:
|
|
|
|
return
|
|
|
|
if line != os.path.normpath(line):
|
|
|
|
sys.exit(f"{line}: not normalized")
|
|
|
|
if line.startswith("../") or line.startswith('/'):
|
|
|
|
sys.exit(f"{line}: escapes staging directory by starting with ../ or /")
|
|
|
|
full_src = os.path.join(src, line)
|
|
|
|
full_dst = os.path.join(dst, line)
|
|
|
|
if os.path.isdir(full_src):
|
|
|
|
os.makedirs(full_dst, exist_ok=True)
|
|
|
|
else:
|
|
|
|
os.makedirs(os.path.dirname(full_dst), exist_ok=True)
|
|
|
|
os.link(full_src, full_dst, follow_symlinks=False)
|
|
|
|
|
2011-10-29 02:02:30 +02:00
|
|
|
|
2023-07-26 23:33:51 +02:00
|
|
|
def main(argv):
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Builds output_image from the given input_directory and properties_file, and "
|
|
|
|
"writes the image to target_output_directory.")
|
|
|
|
parser.add_argument("--input-directory-filter-file",
|
|
|
|
help="the path to a file that contains a list of all files in the input_directory. If this "
|
|
|
|
"option is provided, all files under the input_directory that are not listed in this file will "
|
|
|
|
"be deleted before building the image. This is to work around the fact that building a module "
|
|
|
|
"will install in by default, so there could be files in the input_directory that are not "
|
|
|
|
"actually supposed to be part of the partition. The paths in this file must be relative to "
|
|
|
|
"input_directory.")
|
|
|
|
parser.add_argument("input_directory",
|
|
|
|
help="the staging directory to be converted to an image file")
|
|
|
|
parser.add_argument("properties_file",
|
|
|
|
help="a file containing the 'global dictionary' of properties that affect how the image is "
|
|
|
|
"built")
|
|
|
|
parser.add_argument("out_file",
|
|
|
|
help="the output file to write")
|
|
|
|
parser.add_argument("target_out",
|
|
|
|
help="the path to $(TARGET_OUT). Certain tools will use this to look through multiple staging "
|
|
|
|
"directories for fs config files.")
|
2024-01-24 21:39:36 +01:00
|
|
|
parser.add_argument("-v", action="store_true",
|
|
|
|
help="Enable verbose logging", dest="verbose")
|
2023-07-26 23:33:51 +02:00
|
|
|
args = parser.parse_args()
|
2024-01-24 21:39:36 +01:00
|
|
|
if args.verbose:
|
|
|
|
OPTIONS.verbose = True
|
2023-07-26 23:33:51 +02:00
|
|
|
|
|
|
|
common.InitLogging()
|
2023-09-08 03:24:39 +02:00
|
|
|
|
2023-07-26 23:33:51 +02:00
|
|
|
glob_dict = LoadGlobalDict(args.properties_file)
|
Support to configure and build multiple custom images.
Build additional images requested by the product makefile.
This script gives the ability to build multiple additional images and
you can configure what modules/files to include in each image.
1. Define PRODUCT_CUSTOM_IMAGE_MAKEFILES in your product makefile.
PRODUCT_CUSTOM_IMAGE_MAKEFILES is a list of makefiles.
Each makefile configures an image.
For image configuration makefile foo/bar/xyz.mk, the built image
file name
will be xyz.img. So make sure they won't conflict.
2. In each image's configuration makefile, you can define variables:
- CUSTOM_IMAGE_MOUNT_POINT, the mount point, such as "oem", "odm"
etc.
- CUSTOM_IMAGE_PARTITION_SIZE
- CUSTOM_IMAGE_FILE_SYSTEM_TYPE
- CUSTOM_IMAGE_DICT_FILE, a text file defining a dictionary
accepted by BuildImage() in tools/releasetools/build_image.py.
- CUSTOM_IMAGE_MODULES, a list of module names you want to include
in the image; Not only the module itself will be installed to proper
path in the image, you can also piggyback additional files/directories
with the module's LOCAL_PICKUP_FILES.
- CUSTOM_IMAGE_COPY_FILES, a list of "<src>:<dest>" to be copied to
the image. <dest> is relativ to the root of the image.
To build all those images, run "make custom_images".
Bug: 19609718
Change-Id: Ic73587e08503a251be27797c7b00329716051927
(cherry picked from commit 5fcf1094f9cf4d57c2598237f99621f254130d71)
2015-03-13 02:30:39 +01:00
|
|
|
if "mount_point" in glob_dict:
|
2018-10-19 22:44:36 +02:00
|
|
|
# The caller knows the mount point and provides a dictionary needed by
|
2015-06-23 20:16:05 +02:00
|
|
|
# BuildImage().
|
Support to configure and build multiple custom images.
Build additional images requested by the product makefile.
This script gives the ability to build multiple additional images and
you can configure what modules/files to include in each image.
1. Define PRODUCT_CUSTOM_IMAGE_MAKEFILES in your product makefile.
PRODUCT_CUSTOM_IMAGE_MAKEFILES is a list of makefiles.
Each makefile configures an image.
For image configuration makefile foo/bar/xyz.mk, the built image
file name
will be xyz.img. So make sure they won't conflict.
2. In each image's configuration makefile, you can define variables:
- CUSTOM_IMAGE_MOUNT_POINT, the mount point, such as "oem", "odm"
etc.
- CUSTOM_IMAGE_PARTITION_SIZE
- CUSTOM_IMAGE_FILE_SYSTEM_TYPE
- CUSTOM_IMAGE_DICT_FILE, a text file defining a dictionary
accepted by BuildImage() in tools/releasetools/build_image.py.
- CUSTOM_IMAGE_MODULES, a list of module names you want to include
in the image; Not only the module itself will be installed to proper
path in the image, you can also piggyback additional files/directories
with the module's LOCAL_PICKUP_FILES.
- CUSTOM_IMAGE_COPY_FILES, a list of "<src>:<dest>" to be copied to
the image. <dest> is relativ to the root of the image.
To build all those images, run "make custom_images".
Bug: 19609718
Change-Id: Ic73587e08503a251be27797c7b00329716051927
(cherry picked from commit 5fcf1094f9cf4d57c2598237f99621f254130d71)
2015-03-13 02:30:39 +01:00
|
|
|
image_properties = glob_dict
|
2011-11-04 19:37:01 +01:00
|
|
|
else:
|
2023-07-26 23:33:51 +02:00
|
|
|
image_filename = os.path.basename(args.out_file)
|
Support to configure and build multiple custom images.
Build additional images requested by the product makefile.
This script gives the ability to build multiple additional images and
you can configure what modules/files to include in each image.
1. Define PRODUCT_CUSTOM_IMAGE_MAKEFILES in your product makefile.
PRODUCT_CUSTOM_IMAGE_MAKEFILES is a list of makefiles.
Each makefile configures an image.
For image configuration makefile foo/bar/xyz.mk, the built image
file name
will be xyz.img. So make sure they won't conflict.
2. In each image's configuration makefile, you can define variables:
- CUSTOM_IMAGE_MOUNT_POINT, the mount point, such as "oem", "odm"
etc.
- CUSTOM_IMAGE_PARTITION_SIZE
- CUSTOM_IMAGE_FILE_SYSTEM_TYPE
- CUSTOM_IMAGE_DICT_FILE, a text file defining a dictionary
accepted by BuildImage() in tools/releasetools/build_image.py.
- CUSTOM_IMAGE_MODULES, a list of module names you want to include
in the image; Not only the module itself will be installed to proper
path in the image, you can also piggyback additional files/directories
with the module's LOCAL_PICKUP_FILES.
- CUSTOM_IMAGE_COPY_FILES, a list of "<src>:<dest>" to be copied to
the image. <dest> is relativ to the root of the image.
To build all those images, run "make custom_images".
Bug: 19609718
Change-Id: Ic73587e08503a251be27797c7b00329716051927
(cherry picked from commit 5fcf1094f9cf4d57c2598237f99621f254130d71)
2015-03-13 02:30:39 +01:00
|
|
|
mount_point = ""
|
|
|
|
if image_filename == "system.img":
|
|
|
|
mount_point = "system"
|
2016-06-16 23:47:10 +02:00
|
|
|
elif image_filename == "system_other.img":
|
|
|
|
mount_point = "system_other"
|
Support to configure and build multiple custom images.
Build additional images requested by the product makefile.
This script gives the ability to build multiple additional images and
you can configure what modules/files to include in each image.
1. Define PRODUCT_CUSTOM_IMAGE_MAKEFILES in your product makefile.
PRODUCT_CUSTOM_IMAGE_MAKEFILES is a list of makefiles.
Each makefile configures an image.
For image configuration makefile foo/bar/xyz.mk, the built image
file name
will be xyz.img. So make sure they won't conflict.
2. In each image's configuration makefile, you can define variables:
- CUSTOM_IMAGE_MOUNT_POINT, the mount point, such as "oem", "odm"
etc.
- CUSTOM_IMAGE_PARTITION_SIZE
- CUSTOM_IMAGE_FILE_SYSTEM_TYPE
- CUSTOM_IMAGE_DICT_FILE, a text file defining a dictionary
accepted by BuildImage() in tools/releasetools/build_image.py.
- CUSTOM_IMAGE_MODULES, a list of module names you want to include
in the image; Not only the module itself will be installed to proper
path in the image, you can also piggyback additional files/directories
with the module's LOCAL_PICKUP_FILES.
- CUSTOM_IMAGE_COPY_FILES, a list of "<src>:<dest>" to be copied to
the image. <dest> is relativ to the root of the image.
To build all those images, run "make custom_images".
Bug: 19609718
Change-Id: Ic73587e08503a251be27797c7b00329716051927
(cherry picked from commit 5fcf1094f9cf4d57c2598237f99621f254130d71)
2015-03-13 02:30:39 +01:00
|
|
|
elif image_filename == "userdata.img":
|
|
|
|
mount_point = "data"
|
|
|
|
elif image_filename == "cache.img":
|
|
|
|
mount_point = "cache"
|
|
|
|
elif image_filename == "vendor.img":
|
|
|
|
mount_point = "vendor"
|
2017-11-14 16:42:30 +01:00
|
|
|
elif image_filename == "odm.img":
|
|
|
|
mount_point = "odm"
|
2020-05-07 23:58:20 +02:00
|
|
|
elif image_filename == "vendor_dlkm.img":
|
|
|
|
mount_point = "vendor_dlkm"
|
2020-07-16 01:52:59 +02:00
|
|
|
elif image_filename == "odm_dlkm.img":
|
|
|
|
mount_point = "odm_dlkm"
|
2022-01-27 08:05:08 +01:00
|
|
|
elif image_filename == "system_dlkm.img":
|
|
|
|
mount_point = "system_dlkm"
|
Support to configure and build multiple custom images.
Build additional images requested by the product makefile.
This script gives the ability to build multiple additional images and
you can configure what modules/files to include in each image.
1. Define PRODUCT_CUSTOM_IMAGE_MAKEFILES in your product makefile.
PRODUCT_CUSTOM_IMAGE_MAKEFILES is a list of makefiles.
Each makefile configures an image.
For image configuration makefile foo/bar/xyz.mk, the built image
file name
will be xyz.img. So make sure they won't conflict.
2. In each image's configuration makefile, you can define variables:
- CUSTOM_IMAGE_MOUNT_POINT, the mount point, such as "oem", "odm"
etc.
- CUSTOM_IMAGE_PARTITION_SIZE
- CUSTOM_IMAGE_FILE_SYSTEM_TYPE
- CUSTOM_IMAGE_DICT_FILE, a text file defining a dictionary
accepted by BuildImage() in tools/releasetools/build_image.py.
- CUSTOM_IMAGE_MODULES, a list of module names you want to include
in the image; Not only the module itself will be installed to proper
path in the image, you can also piggyback additional files/directories
with the module's LOCAL_PICKUP_FILES.
- CUSTOM_IMAGE_COPY_FILES, a list of "<src>:<dest>" to be copied to
the image. <dest> is relativ to the root of the image.
To build all those images, run "make custom_images".
Bug: 19609718
Change-Id: Ic73587e08503a251be27797c7b00329716051927
(cherry picked from commit 5fcf1094f9cf4d57c2598237f99621f254130d71)
2015-03-13 02:30:39 +01:00
|
|
|
elif image_filename == "oem.img":
|
|
|
|
mount_point = "oem"
|
2017-11-27 09:04:47 +01:00
|
|
|
elif image_filename == "product.img":
|
|
|
|
mount_point = "product"
|
2019-06-25 08:58:13 +02:00
|
|
|
elif image_filename == "system_ext.img":
|
|
|
|
mount_point = "system_ext"
|
2022-12-15 19:31:34 +01:00
|
|
|
elif "vbmeta" in image_filename:
|
|
|
|
mount_point = "vbmeta"
|
Support to configure and build multiple custom images.
Build additional images requested by the product makefile.
This script gives the ability to build multiple additional images and
you can configure what modules/files to include in each image.
1. Define PRODUCT_CUSTOM_IMAGE_MAKEFILES in your product makefile.
PRODUCT_CUSTOM_IMAGE_MAKEFILES is a list of makefiles.
Each makefile configures an image.
For image configuration makefile foo/bar/xyz.mk, the built image
file name
will be xyz.img. So make sure they won't conflict.
2. In each image's configuration makefile, you can define variables:
- CUSTOM_IMAGE_MOUNT_POINT, the mount point, such as "oem", "odm"
etc.
- CUSTOM_IMAGE_PARTITION_SIZE
- CUSTOM_IMAGE_FILE_SYSTEM_TYPE
- CUSTOM_IMAGE_DICT_FILE, a text file defining a dictionary
accepted by BuildImage() in tools/releasetools/build_image.py.
- CUSTOM_IMAGE_MODULES, a list of module names you want to include
in the image; Not only the module itself will be installed to proper
path in the image, you can also piggyback additional files/directories
with the module's LOCAL_PICKUP_FILES.
- CUSTOM_IMAGE_COPY_FILES, a list of "<src>:<dest>" to be copied to
the image. <dest> is relativ to the root of the image.
To build all those images, run "make custom_images".
Bug: 19609718
Change-Id: Ic73587e08503a251be27797c7b00329716051927
(cherry picked from commit 5fcf1094f9cf4d57c2598237f99621f254130d71)
2015-03-13 02:30:39 +01:00
|
|
|
else:
|
2018-10-12 19:30:39 +02:00
|
|
|
logger.error("Unknown image file name %s", image_filename)
|
2017-12-25 19:43:47 +01:00
|
|
|
sys.exit(1)
|
Support to configure and build multiple custom images.
Build additional images requested by the product makefile.
This script gives the ability to build multiple additional images and
you can configure what modules/files to include in each image.
1. Define PRODUCT_CUSTOM_IMAGE_MAKEFILES in your product makefile.
PRODUCT_CUSTOM_IMAGE_MAKEFILES is a list of makefiles.
Each makefile configures an image.
For image configuration makefile foo/bar/xyz.mk, the built image
file name
will be xyz.img. So make sure they won't conflict.
2. In each image's configuration makefile, you can define variables:
- CUSTOM_IMAGE_MOUNT_POINT, the mount point, such as "oem", "odm"
etc.
- CUSTOM_IMAGE_PARTITION_SIZE
- CUSTOM_IMAGE_FILE_SYSTEM_TYPE
- CUSTOM_IMAGE_DICT_FILE, a text file defining a dictionary
accepted by BuildImage() in tools/releasetools/build_image.py.
- CUSTOM_IMAGE_MODULES, a list of module names you want to include
in the image; Not only the module itself will be installed to proper
path in the image, you can also piggyback additional files/directories
with the module's LOCAL_PICKUP_FILES.
- CUSTOM_IMAGE_COPY_FILES, a list of "<src>:<dest>" to be copied to
the image. <dest> is relativ to the root of the image.
To build all those images, run "make custom_images".
Bug: 19609718
Change-Id: Ic73587e08503a251be27797c7b00329716051927
(cherry picked from commit 5fcf1094f9cf4d57c2598237f99621f254130d71)
2015-03-13 02:30:39 +01:00
|
|
|
|
2022-12-15 19:31:34 +01:00
|
|
|
if "vbmeta" != mount_point:
|
|
|
|
image_properties = ImagePropFromGlobalDict(glob_dict, mount_point)
|
2011-10-29 02:02:30 +02:00
|
|
|
|
2023-07-26 23:33:51 +02:00
|
|
|
if args.input_directory_filter_file and not os.environ.get("BUILD_BROKEN_INCORRECT_PARTITION_IMAGES"):
|
|
|
|
with tempfile.TemporaryDirectory(dir=os.path.dirname(args.input_directory)) as new_input_directory:
|
|
|
|
CopyInputDirectory(args.input_directory, new_input_directory, args.input_directory_filter_file)
|
|
|
|
BuildImageOrVBMeta(new_input_directory, args.target_out, glob_dict, image_properties, args.out_file)
|
|
|
|
else:
|
|
|
|
BuildImageOrVBMeta(args.input_directory, args.target_out, glob_dict, image_properties, args.out_file)
|
2011-10-29 02:02:30 +02:00
|
|
|
|
2018-10-12 19:30:39 +02:00
|
|
|
|
2011-10-29 02:02:30 +02:00
|
|
|
if __name__ == '__main__':
|
2017-12-25 19:43:47 +01:00
|
|
|
try:
|
|
|
|
main(sys.argv[1:])
|
|
|
|
finally:
|
|
|
|
common.Cleanup()
|