Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (C) 2011 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | """ |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 18 | Builds output_image from the given input_directory, properties_file, |
| 19 | and writes the image to target_output_directory. |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 20 | |
Tao Bao | 2bbb07c | 2019-05-07 13:12:21 -0700 | [diff] [blame] | 21 | Usage: build_image input_directory properties_file output_image \\ |
Yifan Hong | 8c3dce0 | 2019-04-09 17:03:57 +0000 | [diff] [blame] | 22 | target_output_directory |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 23 | """ |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 24 | |
| 25 | from __future__ import print_function |
| 26 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 27 | import logging |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 28 | import os |
Ying Wang | 69e9b4d | 2012-11-26 18:10:23 -0800 | [diff] [blame] | 29 | import os.path |
Tao Bao | c7a6f1e | 2015-06-23 11:16:05 -0700 | [diff] [blame] | 30 | import re |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 31 | import shutil |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 32 | import sys |
| 33 | |
| 34 | import common |
Tao Bao | 7119751 | 2018-10-11 14:08:45 -0700 | [diff] [blame] | 35 | import verity_utils |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 36 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 37 | logger = logging.getLogger(__name__) |
| 38 | |
Baligh Uddin | 601ddea | 2015-06-09 15:48:14 -0700 | [diff] [blame] | 39 | OPTIONS = common.OPTIONS |
Tao Bao | 7119751 | 2018-10-11 14:08:45 -0700 | [diff] [blame] | 40 | BLOCK_SIZE = common.BLOCK_SIZE |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 41 | BYTES_IN_MB = 1024 * 1024 |
Geremy Condra | e8e982a | 2014-05-16 19:14:30 -0700 | [diff] [blame] | 42 | |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 43 | |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 44 | class BuildImageError(Exception): |
| 45 | """An Exception raised during image building.""" |
| 46 | |
| 47 | def __init__(self, message): |
| 48 | Exception.__init__(self, message) |
| 49 | |
| 50 | |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 51 | def GetDiskUsage(path): |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 52 | """Returns the number of bytes that "path" occupies on host. |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 53 | |
| 54 | Args: |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 55 | path: The directory or file to calculate size on. |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 56 | |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 57 | Returns: |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 58 | The number of bytes based on a 1K block_size. |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 59 | """ |
Chirayu Desai | 96a913e | 2020-03-27 03:49:31 +0530 | [diff] [blame] | 60 | cmd = ["du", "-b", "-k", "-s", path] |
Tao Bao | f3fc62c | 2018-10-25 12:23:12 -0700 | [diff] [blame] | 61 | output = common.RunAndCheckOutput(cmd, verbose=False) |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 62 | return int(output.split()[0]) * 1024 |
| 63 | |
| 64 | |
| 65 | def GetInodeUsage(path): |
| 66 | """Returns the number of inodes that "path" occupies on host. |
| 67 | |
| 68 | Args: |
| 69 | path: The directory or file to calculate inode number on. |
| 70 | |
| 71 | Returns: |
| 72 | The number of inodes used. |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 73 | """ |
| 74 | cmd = ["find", path, "-print"] |
Tao Bao | f3fc62c | 2018-10-25 12:23:12 -0700 | [diff] [blame] | 75 | output = common.RunAndCheckOutput(cmd, verbose=False) |
David Anderson | 203057c | 2021-03-31 20:01:41 -0700 | [diff] [blame] | 76 | # increase by > 6% as number of files and directories is not whole picture. |
Mark Salyzyn | c25b2bf | 2019-01-16 08:03:10 -0800 | [diff] [blame] | 77 | inodes = output.count('\n') |
David Anderson | 203057c | 2021-03-31 20:01:41 -0700 | [diff] [blame] | 78 | spare_inodes = inodes * 6 // 100 |
Mark Salyzyn | 60fa99d | 2019-01-16 08:03:10 -0800 | [diff] [blame] | 79 | min_spare_inodes = 12 |
Mark Salyzyn | c25b2bf | 2019-01-16 08:03:10 -0800 | [diff] [blame] | 80 | if spare_inodes < min_spare_inodes: |
| 81 | spare_inodes = min_spare_inodes |
| 82 | return inodes + spare_inodes |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 83 | |
| 84 | |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 85 | def GetFilesystemCharacteristics(fs_type, image_path, sparse_image=True): |
Mark Salyzyn | 6541d0a | 2019-01-10 14:30:51 -0800 | [diff] [blame] | 86 | """Returns various filesystem characteristics of "image_path". |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 87 | |
| 88 | Args: |
Mark Salyzyn | 6541d0a | 2019-01-10 14:30:51 -0800 | [diff] [blame] | 89 | image_path: The file to analyze. |
| 90 | sparse_image: Image is sparse |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 91 | |
| 92 | Returns: |
| 93 | The characteristics dictionary. |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 94 | """ |
Mark Salyzyn | 6541d0a | 2019-01-10 14:30:51 -0800 | [diff] [blame] | 95 | unsparse_image_path = image_path |
| 96 | if sparse_image: |
| 97 | unsparse_image_path = UnsparseImage(image_path, replace=False) |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 98 | |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 99 | if fs_type.startswith("ext"): |
| 100 | cmd = ["tune2fs", "-l", unsparse_image_path] |
| 101 | elif fs_type.startswith("f2fs"): |
| 102 | cmd = ["fsck.f2fs", "-l", unsparse_image_path] |
| 103 | |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 104 | try: |
| 105 | output = common.RunAndCheckOutput(cmd, verbose=False) |
Tao Bao | f3fc62c | 2018-10-25 12:23:12 -0700 | [diff] [blame] | 106 | finally: |
Mark Salyzyn | 6541d0a | 2019-01-10 14:30:51 -0800 | [diff] [blame] | 107 | if sparse_image: |
| 108 | os.remove(unsparse_image_path) |
Tao Bao | f3fc62c | 2018-10-25 12:23:12 -0700 | [diff] [blame] | 109 | fs_dict = {} |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 110 | for line in output.splitlines(): |
| 111 | fields = line.split(":") |
| 112 | if len(fields) == 2: |
| 113 | fs_dict[fields[0].strip()] = fields[1].strip() |
| 114 | return fs_dict |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 115 | |
| 116 | |
Geremy Condra | 6e8f53c | 2013-12-05 17:09:18 -0800 | [diff] [blame] | 117 | def UnsparseImage(sparse_image_path, replace=True): |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 118 | img_dir = os.path.dirname(sparse_image_path) |
| 119 | unsparse_image_path = "unsparse_" + os.path.basename(sparse_image_path) |
| 120 | unsparse_image_path = os.path.join(img_dir, unsparse_image_path) |
| 121 | if os.path.exists(unsparse_image_path): |
Geremy Condra | 6e8f53c | 2013-12-05 17:09:18 -0800 | [diff] [blame] | 122 | if replace: |
| 123 | os.unlink(unsparse_image_path) |
| 124 | else: |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 125 | return unsparse_image_path |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 126 | inflate_command = ["simg2img", sparse_image_path, unsparse_image_path] |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 127 | try: |
| 128 | common.RunAndCheckOutput(inflate_command) |
| 129 | except: |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 130 | os.remove(unsparse_image_path) |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 131 | raise |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 132 | return unsparse_image_path |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 133 | |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 134 | |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 135 | def ConvertBlockMapToBaseFs(block_map_file): |
Tao Bao | 1c830bf | 2017-12-25 10:43:47 -0800 | [diff] [blame] | 136 | base_fs_file = common.MakeTempFile(prefix="script_gen_", suffix=".base_fs") |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 137 | convert_command = ["blk_alloc_to_base_fs", block_map_file, base_fs_file] |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 138 | common.RunAndCheckOutput(convert_command) |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 139 | return base_fs_file |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 140 | |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 141 | |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 142 | def SetUpInDirAndFsConfig(origin_in, prop_dict): |
| 143 | """Returns the in_dir and fs_config that should be used for image building. |
| 144 | |
Tom Cherry | d14b895 | 2018-08-09 14:26:00 -0700 | [diff] [blame] | 145 | When building system.img for all targets, it creates and returns a staged dir |
| 146 | that combines the contents of /system (i.e. in the given in_dir) and root. |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 147 | |
| 148 | Args: |
| 149 | origin_in: Path to the input directory. |
| 150 | prop_dict: A property dict that contains info like partition size. Values |
| 151 | may be updated. |
| 152 | |
| 153 | Returns: |
| 154 | A tuple of in_dir and fs_config that should be used to build the image. |
| 155 | """ |
| 156 | fs_config = prop_dict.get("fs_config") |
Tom Cherry | d14b895 | 2018-08-09 14:26:00 -0700 | [diff] [blame] | 157 | |
| 158 | if prop_dict["mount_point"] == "system_other": |
| 159 | prop_dict["mount_point"] = "system" |
| 160 | return origin_in, fs_config |
| 161 | |
| 162 | if prop_dict["mount_point"] != "system": |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 163 | return origin_in, fs_config |
| 164 | |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 165 | if "first_pass" in prop_dict: |
| 166 | prop_dict["mount_point"] = "/" |
| 167 | return prop_dict["first_pass"] |
| 168 | |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 169 | # Construct a staging directory of the root file system. |
| 170 | in_dir = common.MakeTempDir() |
| 171 | root_dir = prop_dict.get("root_dir") |
| 172 | if root_dir: |
| 173 | shutil.rmtree(in_dir) |
| 174 | shutil.copytree(root_dir, in_dir, symlinks=True) |
| 175 | in_dir_system = os.path.join(in_dir, "system") |
| 176 | shutil.rmtree(in_dir_system, ignore_errors=True) |
| 177 | shutil.copytree(origin_in, in_dir_system, symlinks=True) |
| 178 | |
| 179 | # Change the mount point to "/". |
| 180 | prop_dict["mount_point"] = "/" |
| 181 | if fs_config: |
| 182 | # We need to merge the fs_config files of system and root. |
| 183 | merged_fs_config = common.MakeTempFile( |
| 184 | prefix="merged_fs_config", suffix=".txt") |
| 185 | with open(merged_fs_config, "w") as fw: |
| 186 | if "root_fs_config" in prop_dict: |
| 187 | with open(prop_dict["root_fs_config"]) as fr: |
| 188 | fw.writelines(fr.readlines()) |
| 189 | with open(fs_config) as fr: |
| 190 | fw.writelines(fr.readlines()) |
| 191 | fs_config = merged_fs_config |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 192 | prop_dict["first_pass"] = (in_dir, fs_config) |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 193 | return in_dir, fs_config |
| 194 | |
| 195 | |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 196 | def CheckHeadroom(ext4fs_output, prop_dict): |
| 197 | """Checks if there's enough headroom space available. |
| 198 | |
| 199 | Headroom is the reserved space on system image (via PRODUCT_SYSTEM_HEADROOM), |
| 200 | which is useful for devices with low disk space that have system image |
| 201 | variation between builds. The 'partition_headroom' in prop_dict is the size |
| 202 | in bytes, while the numbers in 'ext4fs_output' are for 4K-blocks. |
| 203 | |
| 204 | Args: |
| 205 | ext4fs_output: The output string from mke2fs command. |
| 206 | prop_dict: The property dict. |
| 207 | |
Tao Bao | d8a953d | 2018-01-02 21:19:27 -0800 | [diff] [blame] | 208 | Raises: |
| 209 | AssertionError: On invalid input. |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 210 | BuildImageError: On check failure. |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 211 | """ |
Tao Bao | d8a953d | 2018-01-02 21:19:27 -0800 | [diff] [blame] | 212 | assert ext4fs_output is not None |
| 213 | assert prop_dict.get('fs_type', '').startswith('ext4') |
| 214 | assert 'partition_headroom' in prop_dict |
| 215 | assert 'mount_point' in prop_dict |
| 216 | |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 217 | ext4fs_stats = re.compile( |
| 218 | r'Created filesystem with .* (?P<used_blocks>[0-9]+)/' |
| 219 | r'(?P<total_blocks>[0-9]+) blocks') |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 220 | last_line = ext4fs_output.strip().split('\n')[-1] |
| 221 | m = ext4fs_stats.match(last_line) |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 222 | used_blocks = int(m.groupdict().get('used_blocks')) |
| 223 | total_blocks = int(m.groupdict().get('total_blocks')) |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 224 | headroom_blocks = int(prop_dict['partition_headroom']) // BLOCK_SIZE |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 225 | adjusted_blocks = total_blocks - headroom_blocks |
| 226 | if used_blocks > adjusted_blocks: |
Tao Bao | d8a953d | 2018-01-02 21:19:27 -0800 | [diff] [blame] | 227 | mount_point = prop_dict["mount_point"] |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 228 | raise BuildImageError( |
| 229 | "Error: Not enough room on {} (total: {} blocks, used: {} blocks, " |
| 230 | "headroom: {} blocks, available: {} blocks)".format( |
| 231 | mount_point, total_blocks, used_blocks, headroom_blocks, |
| 232 | adjusted_blocks)) |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 233 | |
Huang Jianan | 6552727 | 2021-09-08 18:28:32 +0800 | [diff] [blame] | 234 | def CalculateSizeAndReserved(prop_dict, size): |
| 235 | fs_type = prop_dict.get("fs_type", "") |
| 236 | partition_headroom = int(prop_dict.get("partition_headroom", 0)) |
| 237 | # If not specified, give us 16MB margin for GetDiskUsage error ... |
| 238 | reserved_size = int(prop_dict.get("partition_reserved_size", BYTES_IN_MB * 16)) |
| 239 | |
| 240 | if fs_type == "erofs": |
| 241 | reserved_size = int(prop_dict.get("partition_reserved_size", 0)) |
| 242 | if reserved_size == 0: |
| 243 | # give .3% margin or a minimum size for AVB footer |
| 244 | return max(size * 1003 // 1000, 256 * 1024) |
| 245 | |
| 246 | if fs_type.startswith("ext4") and partition_headroom > reserved_size: |
| 247 | reserved_size = partition_headroom |
| 248 | |
| 249 | return size + reserved_size |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 250 | |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 251 | def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config): |
| 252 | """Builds a pure image for the files under in_dir and writes it to out_file. |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 253 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 254 | Args: |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 255 | in_dir: Path to input directory. |
| 256 | prop_dict: A property dict that contains info like partition size. Values |
| 257 | will be updated with computed values. |
| 258 | out_file: The output image file. |
| 259 | target_out: Path to the TARGET_OUT directory as in Makefile. It actually |
| 260 | points to the /system directory under PRODUCT_OUT. fs_config (the one |
| 261 | under system/core/libcutils) reads device specific FS config files from |
| 262 | there. |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 263 | fs_config: The fs_config file that drives the prototype |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 264 | |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 265 | Raises: |
| 266 | BuildImageError: On build image failures. |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 267 | """ |
| 268 | build_command = [] |
| 269 | fs_type = prop_dict.get("fs_type", "") |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 270 | run_e2fsck = False |
Daniel Rosenberg | 6cc2c81 | 2019-12-17 17:36:31 -0800 | [diff] [blame] | 271 | needs_projid = prop_dict.get("needs_projid", 0) |
| 272 | needs_casefold = prop_dict.get("needs_casefold", 0) |
Jaegeuk Kim | ed754fb | 2020-10-12 19:50:05 -0700 | [diff] [blame] | 273 | needs_compress = prop_dict.get("needs_compress", 0) |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 274 | |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 275 | disable_sparse = "disable_sparse" in prop_dict |
| 276 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 277 | if fs_type.startswith("ext"): |
Adrien Schildknecht | 9a072cc | 2016-11-18 17:06:29 -0800 | [diff] [blame] | 278 | build_command = [prop_dict["ext_mkuserimg"]] |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 279 | if "extfs_sparse_flag" in prop_dict and not disable_sparse: |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 280 | build_command.append(prop_dict["extfs_sparse_flag"]) |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 281 | run_e2fsck = True |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 282 | build_command.extend([in_dir, out_file, fs_type, |
| 283 | prop_dict["mount_point"]]) |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 284 | build_command.append(prop_dict["image_size"]) |
Ying Wang | f3b8635 | 2014-11-18 18:03:13 -0800 | [diff] [blame] | 285 | if "journal_size" in prop_dict: |
| 286 | build_command.extend(["-j", prop_dict["journal_size"]]) |
Doug Zongker | 850b807 | 2013-12-05 15:54:55 -0800 | [diff] [blame] | 287 | if "timestamp" in prop_dict: |
| 288 | build_command.extend(["-T", str(prop_dict["timestamp"])]) |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 289 | if fs_config: |
Doug Zongker | 8282282 | 2014-06-16 09:10:55 -0700 | [diff] [blame] | 290 | build_command.extend(["-C", fs_config]) |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 291 | if target_out: |
| 292 | build_command.extend(["-D", target_out]) |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 293 | if "block_list" in prop_dict: |
| 294 | build_command.extend(["-B", prop_dict["block_list"]]) |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 295 | if "base_fs_file" in prop_dict: |
| 296 | base_fs_file = ConvertBlockMapToBaseFs(prop_dict["base_fs_file"]) |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 297 | build_command.extend(["-d", base_fs_file]) |
Christoffer Dall | 8ed01f3 | 2014-12-17 21:34:12 +0100 | [diff] [blame] | 298 | build_command.extend(["-L", prop_dict["mount_point"]]) |
Patrick Tjin | a190084 | 2016-10-20 10:58:12 -0700 | [diff] [blame] | 299 | if "extfs_inode_count" in prop_dict: |
| 300 | build_command.extend(["-i", prop_dict["extfs_inode_count"]]) |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 301 | if "extfs_rsv_pct" in prop_dict: |
| 302 | build_command.extend(["-M", prop_dict["extfs_rsv_pct"]]) |
Connor O'Brien | 20f08c3 | 2017-01-05 16:48:14 -0800 | [diff] [blame] | 303 | if "flash_erase_block_size" in prop_dict: |
| 304 | build_command.extend(["-e", prop_dict["flash_erase_block_size"]]) |
| 305 | if "flash_logical_block_size" in prop_dict: |
| 306 | build_command.extend(["-o", prop_dict["flash_logical_block_size"]]) |
Tao Bao | d86e311 | 2017-09-22 15:45:33 -0700 | [diff] [blame] | 307 | # Specify UUID and hash_seed if using mke2fs. |
HÃ¥kan Kvist | 2e1f527 | 2021-05-11 11:14:48 +0200 | [diff] [blame] | 308 | if os.path.basename(prop_dict["ext_mkuserimg"]) == "mkuserimg_mke2fs": |
Tao Bao | d86e311 | 2017-09-22 15:45:33 -0700 | [diff] [blame] | 309 | if "uuid" in prop_dict: |
| 310 | build_command.extend(["-U", prop_dict["uuid"]]) |
| 311 | if "hash_seed" in prop_dict: |
| 312 | build_command.extend(["-S", prop_dict["hash_seed"]]) |
Tamas Petz | c0a8c63 | 2020-02-03 15:41:02 +0100 | [diff] [blame] | 313 | if prop_dict.get("ext4_share_dup_blocks") == "true": |
Jin Qian | fde9f79 | 2018-01-22 13:15:46 -0800 | [diff] [blame] | 314 | build_command.append("-c") |
Daniel Rosenberg | 6cc2c81 | 2019-12-17 17:36:31 -0800 | [diff] [blame] | 315 | if (needs_projid): |
| 316 | build_command.extend(["--inode_size", "512"]) |
| 317 | else: |
| 318 | build_command.extend(["--inode_size", "256"]) |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 319 | if "selinux_fc" in prop_dict: |
Kenny Root | f32dc71 | 2012-04-08 10:42:34 -0700 | [diff] [blame] | 320 | build_command.append(prop_dict["selinux_fc"]) |
Gao Xiang | 961041a | 2020-06-17 13:59:16 +0800 | [diff] [blame] | 321 | elif fs_type.startswith("erofs"): |
| 322 | build_command = ["mkerofsimage.sh"] |
| 323 | build_command.extend([in_dir, out_file]) |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 324 | if "erofs_sparse_flag" in prop_dict and not disable_sparse: |
Gao Xiang | 961041a | 2020-06-17 13:59:16 +0800 | [diff] [blame] | 325 | build_command.extend([prop_dict["erofs_sparse_flag"]]) |
| 326 | build_command.extend(["-m", prop_dict["mount_point"]]) |
| 327 | if target_out: |
| 328 | build_command.extend(["-d", target_out]) |
| 329 | if fs_config: |
| 330 | build_command.extend(["-C", fs_config]) |
| 331 | if "selinux_fc" in prop_dict: |
| 332 | build_command.extend(["-c", prop_dict["selinux_fc"]]) |
Huang Jianan | 1ed889b | 2021-02-19 16:48:31 +0800 | [diff] [blame] | 333 | if "timestamp" in prop_dict: |
| 334 | build_command.extend(["-T", str(prop_dict["timestamp"])]) |
| 335 | if "uuid" in prop_dict: |
| 336 | build_command.extend(["-U", prop_dict["uuid"]]) |
David Anderson | 40a821f | 2021-09-22 18:02:01 -0700 | [diff] [blame] | 337 | compressor = None |
| 338 | if "erofs_default_compressor" in prop_dict: |
| 339 | compressor = prop_dict["erofs_default_compressor"] |
| 340 | if "erofs_compressor" in prop_dict: |
| 341 | compressor = prop_dict["erofs_compressor"] |
| 342 | if compressor: |
| 343 | build_command.extend(["-z", compressor]) |
Mohamad Ayyash | b97746e | 2015-03-03 12:30:37 -0800 | [diff] [blame] | 344 | elif fs_type.startswith("squash"): |
| 345 | build_command = ["mksquashfsimage.sh"] |
| 346 | build_command.extend([in_dir, out_file]) |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 347 | if "squashfs_sparse_flag" in prop_dict and not disable_sparse: |
Todd Poynor | b2a555e | 2015-12-15 18:00:14 -0800 | [diff] [blame] | 348 | build_command.extend([prop_dict["squashfs_sparse_flag"]]) |
Mohamad Ayyash | b97746e | 2015-03-03 12:30:37 -0800 | [diff] [blame] | 349 | build_command.extend(["-m", prop_dict["mount_point"]]) |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 350 | if target_out: |
| 351 | build_command.extend(["-d", target_out]) |
Mohamad Ayyash | 8837882 | 2016-04-07 22:10:51 -0700 | [diff] [blame] | 352 | if fs_config: |
| 353 | build_command.extend(["-C", fs_config]) |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 354 | if "selinux_fc" in prop_dict: |
Mohamad Ayyash | b97746e | 2015-03-03 12:30:37 -0800 | [diff] [blame] | 355 | build_command.extend(["-c", prop_dict["selinux_fc"]]) |
Mohamad Ayyash | c3484f7 | 2016-06-13 09:46:58 -0700 | [diff] [blame] | 356 | if "block_list" in prop_dict: |
| 357 | build_command.extend(["-B", prop_dict["block_list"]]) |
Ng Zhi An | 9446c1d | 2018-01-19 15:51:46 -0800 | [diff] [blame] | 358 | if "squashfs_block_size" in prop_dict: |
| 359 | build_command.extend(["-b", prop_dict["squashfs_block_size"]]) |
Simon Wilson | f86e7ee | 2015-06-17 12:35:15 -0700 | [diff] [blame] | 360 | if "squashfs_compressor" in prop_dict: |
| 361 | build_command.extend(["-z", prop_dict["squashfs_compressor"]]) |
| 362 | if "squashfs_compressor_opt" in prop_dict: |
| 363 | build_command.extend(["-zo", prop_dict["squashfs_compressor_opt"]]) |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 364 | if prop_dict.get("squashfs_disable_4k_align") == "true": |
Mohamad Ayyash | 1b6d348 | 2016-06-15 15:53:07 -0700 | [diff] [blame] | 365 | build_command.extend(["-a"]) |
JP Abgrall | 5bfed5a | 2014-06-16 14:17:40 -0700 | [diff] [blame] | 366 | elif fs_type.startswith("f2fs"): |
| 367 | build_command = ["mkf2fsuserimg.sh"] |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 368 | build_command.extend([out_file, prop_dict["image_size"]]) |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 369 | if "f2fs_sparse_flag" in prop_dict and not disable_sparse: |
Alistair Delva | 91238cc | 2019-10-16 10:53:41 -0700 | [diff] [blame] | 370 | build_command.extend([prop_dict["f2fs_sparse_flag"]]) |
Jaegeuk Kim | 2ea1eba | 2017-11-28 19:21:28 -0800 | [diff] [blame] | 371 | if fs_config: |
| 372 | build_command.extend(["-C", fs_config]) |
| 373 | build_command.extend(["-f", in_dir]) |
| 374 | if target_out: |
| 375 | build_command.extend(["-D", target_out]) |
| 376 | if "selinux_fc" in prop_dict: |
| 377 | build_command.extend(["-s", prop_dict["selinux_fc"]]) |
| 378 | build_command.extend(["-t", prop_dict["mount_point"]]) |
| 379 | if "timestamp" in prop_dict: |
| 380 | build_command.extend(["-T", str(prop_dict["timestamp"])]) |
Jaegeuk Kim | 3dc4728 | 2021-06-13 08:54:01 -0700 | [diff] [blame] | 381 | if "block_list" in prop_dict: |
| 382 | build_command.extend(["-B", prop_dict["block_list"]]) |
Jaegeuk Kim | 2ea1eba | 2017-11-28 19:21:28 -0800 | [diff] [blame] | 383 | build_command.extend(["-L", prop_dict["mount_point"]]) |
Daniel Rosenberg | 6cc2c81 | 2019-12-17 17:36:31 -0800 | [diff] [blame] | 384 | if (needs_projid): |
| 385 | build_command.append("--prjquota") |
| 386 | if (needs_casefold): |
| 387 | build_command.append("--casefold") |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 388 | if (needs_compress or prop_dict.get("f2fs_compress") == "true"): |
Jaegeuk Kim | ed754fb | 2020-10-12 19:50:05 -0700 | [diff] [blame] | 389 | build_command.append("--compression") |
Jaegeuk Kim | 3dc4728 | 2021-06-13 08:54:01 -0700 | [diff] [blame] | 390 | if (prop_dict.get("mount_point") != "data"): |
Jaegeuk Kim | 46e0ea2 | 2021-05-20 23:13:59 -0700 | [diff] [blame] | 391 | build_command.append("--readonly") |
Jaegeuk Kim | 3dc4728 | 2021-06-13 08:54:01 -0700 | [diff] [blame] | 392 | if (prop_dict.get("f2fs_compress") == "true"): |
Robin Hsu | 3e51f42 | 2020-11-04 09:29:09 +0800 | [diff] [blame] | 393 | build_command.append("--sldc") |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 394 | if (prop_dict.get("f2fs_sldc_flags") == None): |
Robin Hsu | 3e51f42 | 2020-11-04 09:29:09 +0800 | [diff] [blame] | 395 | build_command.append(str(0)) |
| 396 | else: |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 397 | sldc_flags_str = prop_dict.get("f2fs_sldc_flags") |
Robin Hsu | 3e51f42 | 2020-11-04 09:29:09 +0800 | [diff] [blame] | 398 | sldc_flags = sldc_flags_str.split() |
| 399 | build_command.append(str(len(sldc_flags))) |
| 400 | build_command.extend(sldc_flags) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 401 | else: |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 402 | raise BuildImageError( |
| 403 | "Error: unknown filesystem type: {}".format(fs_type)) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 404 | |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 405 | try: |
| 406 | mkfs_output = common.RunAndCheckOutput(build_command) |
| 407 | except: |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 408 | try: |
| 409 | du = GetDiskUsage(in_dir) |
| 410 | du_str = "{} bytes ({} MB)".format(du, du // BYTES_IN_MB) |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 411 | # Suppress any errors from GetDiskUsage() to avoid hiding the real errors |
| 412 | # from common.RunAndCheckOutput(). |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 413 | except Exception: # pylint: disable=broad-except |
| 414 | logger.exception("Failed to compute disk usage with du") |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 415 | du_str = "unknown" |
Tao Bao | 4251fe9 | 2018-07-23 13:05:00 -0700 | [diff] [blame] | 416 | print( |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 417 | "Out of space? Out of inodes? The tree size of {} is {}, " |
| 418 | "with reserved space of {} bytes ({} MB).".format( |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 419 | in_dir, du_str, |
Tao Bao | 4251fe9 | 2018-07-23 13:05:00 -0700 | [diff] [blame] | 420 | int(prop_dict.get("partition_reserved_size", 0)), |
| 421 | int(prop_dict.get("partition_reserved_size", 0)) // BYTES_IN_MB)) |
Huang Jianan | f63abb1 | 2021-04-29 15:24:50 +0800 | [diff] [blame] | 422 | if ("image_size" in prop_dict and "partition_size" in prop_dict): |
| 423 | print( |
| 424 | "The max image size for filesystem files is {} bytes ({} MB), " |
| 425 | "out of a total partition size of {} bytes ({} MB).".format( |
| 426 | int(prop_dict["image_size"]), |
| 427 | int(prop_dict["image_size"]) // BYTES_IN_MB, |
| 428 | int(prop_dict["partition_size"]), |
| 429 | int(prop_dict["partition_size"]) // BYTES_IN_MB)) |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 430 | raise |
Ying Wang | 69e9b4d | 2012-11-26 18:10:23 -0800 | [diff] [blame] | 431 | |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 432 | if run_e2fsck and prop_dict.get("skip_fsck") != "true": |
| 433 | unsparse_image = UnsparseImage(out_file, replace=False) |
| 434 | |
| 435 | # Run e2fsck on the inflated image file |
| 436 | e2fsck_command = ["e2fsck", "-f", "-n", unsparse_image] |
| 437 | try: |
| 438 | common.RunAndCheckOutput(e2fsck_command) |
| 439 | finally: |
| 440 | os.remove(unsparse_image) |
| 441 | |
| 442 | return mkfs_output |
| 443 | |
| 444 | |
| 445 | def BuildImage(in_dir, prop_dict, out_file, target_out=None): |
| 446 | """Builds an image for the files under in_dir and writes it to out_file. |
| 447 | |
| 448 | Args: |
| 449 | in_dir: Path to input directory. |
| 450 | prop_dict: A property dict that contains info like partition size. Values |
| 451 | will be updated with computed values. |
| 452 | out_file: The output image file. |
| 453 | target_out: Path to the TARGET_OUT directory as in Makefile. It actually |
| 454 | points to the /system directory under PRODUCT_OUT. fs_config (the one |
| 455 | under system/core/libcutils) reads device specific FS config files from |
| 456 | there. |
| 457 | |
| 458 | Raises: |
| 459 | BuildImageError: On build image failures. |
| 460 | """ |
| 461 | in_dir, fs_config = SetUpInDirAndFsConfig(in_dir, prop_dict) |
| 462 | |
| 463 | build_command = [] |
| 464 | fs_type = prop_dict.get("fs_type", "") |
| 465 | |
| 466 | fs_spans_partition = True |
Huang Jianan | 62d926e | 2020-12-04 16:53:06 +0800 | [diff] [blame] | 467 | if fs_type.startswith("squash") or fs_type.startswith("erofs"): |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 468 | fs_spans_partition = False |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 469 | elif fs_type.startswith("f2fs") and prop_dict.get("f2fs_compress") == "true": |
| 470 | fs_spans_partition = False |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 471 | |
| 472 | # Get a builder for creating an image that's to be verified by Verified Boot, |
| 473 | # or None if not applicable. |
| 474 | verity_image_builder = verity_utils.CreateVerityImageBuilder(prop_dict) |
| 475 | |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 476 | disable_sparse = "disable_sparse" in prop_dict |
Huang Jianan | ffa1d57 | 2021-09-08 18:11:22 +0800 | [diff] [blame] | 477 | mkfs_output = None |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 478 | if (prop_dict.get("use_dynamic_partition_size") == "true" and |
| 479 | "partition_size" not in prop_dict): |
| 480 | # If partition_size is not defined, use output of `du' + reserved_size. |
Huang Jianan | 35f015e | 2020-12-04 16:58:24 +0800 | [diff] [blame] | 481 | # For compressed file system, it's better to use the compressed size to avoid wasting space. |
| 482 | if fs_type.startswith("erofs"): |
Huang Jianan | ffa1d57 | 2021-09-08 18:11:22 +0800 | [diff] [blame] | 483 | mkfs_output = BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config) |
| 484 | if "erofs_sparse_flag" in prop_dict and not disable_sparse: |
| 485 | image_path = UnsparseImage(out_file, replace=False) |
| 486 | size = GetDiskUsage(image_path) |
| 487 | os.remove(image_path) |
| 488 | else: |
| 489 | size = GetDiskUsage(out_file) |
Huang Jianan | 35f015e | 2020-12-04 16:58:24 +0800 | [diff] [blame] | 490 | else: |
| 491 | size = GetDiskUsage(in_dir) |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 492 | logger.info( |
| 493 | "The tree size of %s is %d MB.", in_dir, size // BYTES_IN_MB) |
Huang Jianan | 6552727 | 2021-09-08 18:28:32 +0800 | [diff] [blame] | 494 | size = CalculateSizeAndReserved(prop_dict, size) |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 495 | # Round this up to a multiple of 4K so that avbtool works |
| 496 | size = common.RoundUpTo4K(size) |
| 497 | if fs_type.startswith("ext"): |
| 498 | prop_dict["partition_size"] = str(size) |
| 499 | prop_dict["image_size"] = str(size) |
| 500 | if "extfs_inode_count" not in prop_dict: |
| 501 | prop_dict["extfs_inode_count"] = str(GetInodeUsage(in_dir)) |
| 502 | logger.info( |
| 503 | "First Pass based on estimates of %d MB and %s inodes.", |
| 504 | size // BYTES_IN_MB, prop_dict["extfs_inode_count"]) |
| 505 | BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config) |
Mark Salyzyn | 6541d0a | 2019-01-10 14:30:51 -0800 | [diff] [blame] | 506 | sparse_image = False |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 507 | if "extfs_sparse_flag" in prop_dict and not disable_sparse: |
Mark Salyzyn | 6541d0a | 2019-01-10 14:30:51 -0800 | [diff] [blame] | 508 | sparse_image = True |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 509 | fs_dict = GetFilesystemCharacteristics(fs_type, out_file, sparse_image) |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 510 | os.remove(out_file) |
| 511 | block_size = int(fs_dict.get("Block size", "4096")) |
| 512 | free_size = int(fs_dict.get("Free blocks", "0")) * block_size |
| 513 | reserved_size = int(prop_dict.get("partition_reserved_size", 0)) |
| 514 | partition_headroom = int(fs_dict.get("partition_headroom", 0)) |
| 515 | if fs_type.startswith("ext4") and partition_headroom > reserved_size: |
| 516 | reserved_size = partition_headroom |
| 517 | if free_size <= reserved_size: |
| 518 | logger.info( |
| 519 | "Not worth reducing image %d <= %d.", free_size, reserved_size) |
| 520 | else: |
| 521 | size -= free_size |
| 522 | size += reserved_size |
Mark Salyzyn | 60a716f | 2019-01-10 08:36:34 -0800 | [diff] [blame] | 523 | if reserved_size == 0: |
Mark Salyzyn | c25b2bf | 2019-01-16 08:03:10 -0800 | [diff] [blame] | 524 | # add .3% margin |
| 525 | size = size * 1003 // 1000 |
Mark Salyzyn | 60a716f | 2019-01-10 08:36:34 -0800 | [diff] [blame] | 526 | # Use a minimum size, otherwise we will fail to calculate an AVB footer |
| 527 | # or fail to construct an ext4 image. |
| 528 | size = max(size, 256 * 1024) |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 529 | if block_size <= 4096: |
| 530 | size = common.RoundUpTo4K(size) |
| 531 | else: |
| 532 | size = ((size + block_size - 1) // block_size) * block_size |
| 533 | extfs_inode_count = prop_dict["extfs_inode_count"] |
| 534 | inodes = int(fs_dict.get("Inode count", extfs_inode_count)) |
| 535 | inodes -= int(fs_dict.get("Free inodes", "0")) |
Mark Salyzyn | c25b2bf | 2019-01-16 08:03:10 -0800 | [diff] [blame] | 536 | # add .2% margin or 1 inode, whichever is greater |
| 537 | spare_inodes = inodes * 2 // 1000 |
| 538 | min_spare_inodes = 1 |
| 539 | if spare_inodes < min_spare_inodes: |
| 540 | spare_inodes = min_spare_inodes |
| 541 | inodes += spare_inodes |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 542 | prop_dict["extfs_inode_count"] = str(inodes) |
| 543 | prop_dict["partition_size"] = str(size) |
| 544 | logger.info( |
| 545 | "Allocating %d Inodes for %s.", inodes, out_file) |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 546 | elif fs_type.startswith("f2fs") and prop_dict.get("f2fs_compress") == "true": |
| 547 | prop_dict["partition_size"] = str(size) |
| 548 | prop_dict["image_size"] = str(size) |
| 549 | BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config) |
| 550 | sparse_image = False |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 551 | if "f2fs_sparse_flag" in prop_dict and not disable_sparse: |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 552 | sparse_image = True |
| 553 | fs_dict = GetFilesystemCharacteristics(fs_type, out_file, sparse_image) |
| 554 | os.remove(out_file) |
| 555 | block_count = int(fs_dict.get("block_count", "0")) |
| 556 | log_blocksize = int(fs_dict.get("log_blocksize", "12")) |
| 557 | size = block_count << log_blocksize |
| 558 | prop_dict["partition_size"] = str(size) |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 559 | if verity_image_builder: |
| 560 | size = verity_image_builder.CalculateDynamicPartitionSize(size) |
| 561 | prop_dict["partition_size"] = str(size) |
| 562 | logger.info( |
| 563 | "Allocating %d MB for %s.", size // BYTES_IN_MB, out_file) |
| 564 | |
| 565 | prop_dict["image_size"] = prop_dict["partition_size"] |
| 566 | |
| 567 | # Adjust the image size to make room for the hashes if this is to be verified. |
| 568 | if verity_image_builder: |
| 569 | max_image_size = verity_image_builder.CalculateMaxImageSize() |
| 570 | prop_dict["image_size"] = str(max_image_size) |
| 571 | |
Huang Jianan | ffa1d57 | 2021-09-08 18:11:22 +0800 | [diff] [blame] | 572 | if not mkfs_output: |
| 573 | mkfs_output = BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config) |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 574 | |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 575 | # Check if there's enough headroom space available for ext4 image. |
Tao Bao | 79d52f8 | 2017-12-07 14:07:44 -0800 | [diff] [blame] | 576 | if "partition_headroom" in prop_dict and fs_type.startswith("ext4"): |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 577 | CheckHeadroom(mkfs_output, prop_dict) |
Tao Bao | c7a6f1e | 2015-06-23 11:16:05 -0700 | [diff] [blame] | 578 | |
Tao Bao | 7549e5e | 2018-10-03 14:23:59 -0700 | [diff] [blame] | 579 | if not fs_spans_partition and verity_image_builder: |
| 580 | verity_image_builder.PadSparseImage(out_file) |
Mohamad Ayyash | dd06352 | 2015-03-24 12:42:03 -0700 | [diff] [blame] | 581 | |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 582 | # Create the verified image if this is to be verified. |
Tao Bao | 7549e5e | 2018-10-03 14:23:59 -0700 | [diff] [blame] | 583 | if verity_image_builder: |
| 584 | verity_image_builder.Build(out_file) |
David Zeuthen | 4014a9d | 2016-09-30 17:29:22 -0400 | [diff] [blame] | 585 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 586 | |
| 587 | def ImagePropFromGlobalDict(glob_dict, mount_point): |
| 588 | """Build an image property dictionary from the global dictionary. |
| 589 | |
| 590 | Args: |
| 591 | glob_dict: the global dictionary from the build system. |
| 592 | mount_point: such as "system", "data" etc. |
| 593 | """ |
Doug Zongker | 1ad7ade | 2013-12-06 11:53:27 -0800 | [diff] [blame] | 594 | d = {} |
Tao Bao | 052ae35 | 2015-09-28 13:44:13 -0700 | [diff] [blame] | 595 | |
Tao Bao | 822f584 | 2015-09-30 16:01:14 -0700 | [diff] [blame] | 596 | if "build.prop" in glob_dict: |
Tianjie Xu | 0fde41e | 2020-05-09 05:24:18 +0000 | [diff] [blame] | 597 | timestamp = glob_dict["build.prop"].GetProp("ro.build.date.utc") |
| 598 | if timestamp: |
| 599 | d["timestamp"] = timestamp |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 600 | |
| 601 | def copy_prop(src_p, dest_p): |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 602 | """Copy a property from the global dictionary. |
| 603 | |
| 604 | Args: |
| 605 | src_p: The source property in the global dictionary. |
| 606 | dest_p: The destination property. |
| 607 | Returns: |
| 608 | True if property was found and copied, False otherwise. |
| 609 | """ |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 610 | if src_p in glob_dict: |
| 611 | d[dest_p] = str(glob_dict[src_p]) |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 612 | return True |
| 613 | return False |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 614 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 615 | common_props = ( |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 616 | "extfs_sparse_flag", |
David Anderson | 40a821f | 2021-09-22 18:02:01 -0700 | [diff] [blame] | 617 | "erofs_default_compressor", |
Gao Xiang | 961041a | 2020-06-17 13:59:16 +0800 | [diff] [blame] | 618 | "erofs_sparse_flag", |
Todd Poynor | b2a555e | 2015-12-15 18:00:14 -0800 | [diff] [blame] | 619 | "squashfs_sparse_flag", |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 620 | "system_f2fs_compress", |
Robin Hsu | 3e51f42 | 2020-11-04 09:29:09 +0800 | [diff] [blame] | 621 | "system_f2fs_sldc_flags", |
Alistair Delva | 91238cc | 2019-10-16 10:53:41 -0700 | [diff] [blame] | 622 | "f2fs_sparse_flag", |
Ying Wang | 6a42a25 | 2013-02-27 13:54:02 -0800 | [diff] [blame] | 623 | "skip_fsck", |
Adrien Schildknecht | 9a072cc | 2016-11-18 17:06:29 -0800 | [diff] [blame] | 624 | "ext_mkuserimg", |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 625 | "verity", |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 626 | "verity_key", |
Sami Tolvanen | f99b531 | 2015-05-20 07:30:57 +0100 | [diff] [blame] | 627 | "verity_signer_cmd", |
David Zeuthen | 4014a9d | 2016-09-30 17:29:22 -0400 | [diff] [blame] | 628 | "verity_fec", |
Bowgo Tsai | 6ceeb1a | 2017-10-11 16:21:48 +0800 | [diff] [blame] | 629 | "verity_disable", |
Bowgo Tsai | 3e599ea | 2017-05-26 18:30:04 +0800 | [diff] [blame] | 630 | "avb_enable", |
Tao Bao | 2b6dfd6 | 2017-09-27 17:17:43 -0700 | [diff] [blame] | 631 | "avb_avbtool", |
Yifan Hong | 2dae572 | 2018-07-31 12:47:27 -0700 | [diff] [blame] | 632 | "use_dynamic_partition_size", |
Tao Bao | 2b6dfd6 | 2017-09-27 17:17:43 -0700 | [diff] [blame] | 633 | ) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 634 | for p in common_props: |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 635 | copy_prop(p, p) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 636 | |
David Anderson | 40a821f | 2021-09-22 18:02:01 -0700 | [diff] [blame] | 637 | suffixed_props = ( |
| 638 | "erofs_compressor", |
| 639 | ) |
| 640 | for p in suffixed_props: |
| 641 | copy_prop("{}_{}".format(mount_point, p), p) |
| 642 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 643 | d["mount_point"] = mount_point |
| 644 | if mount_point == "system": |
Bowgo Tsai | 3e599ea | 2017-05-26 18:30:04 +0800 | [diff] [blame] | 645 | copy_prop("avb_system_hashtree_enable", "avb_hashtree_enable") |
| 646 | copy_prop("avb_system_add_hashtree_footer_args", |
| 647 | "avb_add_hashtree_footer_args") |
| 648 | copy_prop("avb_system_key_path", "avb_key_path") |
| 649 | copy_prop("avb_system_algorithm", "avb_algorithm") |
Daniel Norman | d5fe862 | 2020-01-08 17:01:11 -0800 | [diff] [blame] | 650 | copy_prop("avb_system_salt", "avb_salt") |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 651 | copy_prop("fs_type", "fs_type") |
Julius D'souza | 001c676 | 2017-05-03 13:43:27 -0700 | [diff] [blame] | 652 | # Copy the generic system fs type first, override with specific one if |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 653 | # available. |
Mohamad Ayyash | b97746e | 2015-03-03 12:30:37 -0800 | [diff] [blame] | 654 | copy_prop("system_fs_type", "fs_type") |
Julius D'souza | 001c676 | 2017-05-03 13:43:27 -0700 | [diff] [blame] | 655 | copy_prop("system_headroom", "partition_headroom") |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 656 | copy_prop("system_size", "partition_size") |
Tao Bao | 332a96b | 2018-03-31 10:27:35 -0700 | [diff] [blame] | 657 | if not copy_prop("system_journal_size", "journal_size"): |
| 658 | d["journal_size"] = "0" |
Daniel Rosenberg | f4eabc3 | 2014-07-10 15:42:38 -0700 | [diff] [blame] | 659 | copy_prop("system_verity_block_device", "verity_block_device") |
Tao Bao | f3282b4 | 2015-04-01 11:21:55 -0700 | [diff] [blame] | 660 | copy_prop("system_root_image", "system_root_image") |
Tao Bao | 8bfd3c7 | 2018-07-20 15:20:28 -0700 | [diff] [blame] | 661 | copy_prop("root_dir", "root_dir") |
| 662 | copy_prop("root_fs_config", "root_fs_config") |
Jin Qian | fde9f79 | 2018-01-22 13:15:46 -0800 | [diff] [blame] | 663 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 664 | copy_prop("system_f2fs_compress", "f2fs_compress") |
| 665 | copy_prop("system_f2fs_sldc_flags", "f2fs_sldc_flags") |
Simon Wilson | f86e7ee | 2015-06-17 12:35:15 -0700 | [diff] [blame] | 666 | copy_prop("system_squashfs_compressor", "squashfs_compressor") |
| 667 | copy_prop("system_squashfs_compressor_opt", "squashfs_compressor_opt") |
Mohamad Ayyash | dfec815 | 2016-05-24 12:59:30 -0700 | [diff] [blame] | 668 | copy_prop("system_squashfs_block_size", "squashfs_block_size") |
Mohamad Ayyash | 1b6d348 | 2016-06-15 15:53:07 -0700 | [diff] [blame] | 669 | copy_prop("system_squashfs_disable_4k_align", "squashfs_disable_4k_align") |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 670 | copy_prop("system_base_fs_file", "base_fs_file") |
Patrick Tjin | a190084 | 2016-10-20 10:58:12 -0700 | [diff] [blame] | 671 | copy_prop("system_extfs_inode_count", "extfs_inode_count") |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 672 | if not copy_prop("system_extfs_rsv_pct", "extfs_rsv_pct"): |
| 673 | d["extfs_rsv_pct"] = "0" |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 674 | copy_prop("system_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 675 | copy_prop("system_selinux_fc", "selinux_fc") |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 676 | copy_prop("system_disable_sparse", "disable_sparse") |
Alex Light | 4e358ab | 2016-06-16 14:47:10 -0700 | [diff] [blame] | 677 | elif mount_point == "system_other": |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 678 | # We inherit the selinux policies of /system since we contain some of its |
| 679 | # files. |
Bowgo Tsai | 1e04bf7 | 2019-01-23 22:19:19 +0800 | [diff] [blame] | 680 | copy_prop("avb_system_other_hashtree_enable", "avb_hashtree_enable") |
| 681 | copy_prop("avb_system_other_add_hashtree_footer_args", |
Bowgo Tsai | 3e599ea | 2017-05-26 18:30:04 +0800 | [diff] [blame] | 682 | "avb_add_hashtree_footer_args") |
Bowgo Tsai | 1e04bf7 | 2019-01-23 22:19:19 +0800 | [diff] [blame] | 683 | copy_prop("avb_system_other_key_path", "avb_key_path") |
| 684 | copy_prop("avb_system_other_algorithm", "avb_algorithm") |
Daniel Norman | d5fe862 | 2020-01-08 17:01:11 -0800 | [diff] [blame] | 685 | copy_prop("avb_system_other_salt", "avb_salt") |
Alex Light | 4e358ab | 2016-06-16 14:47:10 -0700 | [diff] [blame] | 686 | copy_prop("fs_type", "fs_type") |
| 687 | copy_prop("system_fs_type", "fs_type") |
Bowgo Tsai | 867ab66 | 2019-01-29 13:30:18 +0800 | [diff] [blame] | 688 | copy_prop("system_other_size", "partition_size") |
Tao Bao | 332a96b | 2018-03-31 10:27:35 -0700 | [diff] [blame] | 689 | if not copy_prop("system_journal_size", "journal_size"): |
| 690 | d["journal_size"] = "0" |
Alex Light | 4e358ab | 2016-06-16 14:47:10 -0700 | [diff] [blame] | 691 | copy_prop("system_verity_block_device", "verity_block_device") |
Mark Salyzyn | f0cef8d | 2018-10-29 10:55:06 -0700 | [diff] [blame] | 692 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 693 | copy_prop("system_f2fs_compress", "f2fs_compress") |
| 694 | copy_prop("system_f2fs_sldc_flags", "f2fs_sldc_flags") |
Alex Light | 4e358ab | 2016-06-16 14:47:10 -0700 | [diff] [blame] | 695 | copy_prop("system_squashfs_compressor", "squashfs_compressor") |
| 696 | copy_prop("system_squashfs_compressor_opt", "squashfs_compressor_opt") |
| 697 | copy_prop("system_squashfs_block_size", "squashfs_block_size") |
Patrick Tjin | a190084 | 2016-10-20 10:58:12 -0700 | [diff] [blame] | 698 | copy_prop("system_extfs_inode_count", "extfs_inode_count") |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 699 | if not copy_prop("system_extfs_rsv_pct", "extfs_rsv_pct"): |
| 700 | d["extfs_rsv_pct"] = "0" |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 701 | copy_prop("system_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 702 | copy_prop("system_selinux_fc", "selinux_fc") |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 703 | copy_prop("system_disable_sparse", "disable_sparse") |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 704 | elif mount_point == "data": |
JP Abgrall | 5bfed5a | 2014-06-16 14:17:40 -0700 | [diff] [blame] | 705 | # Copy the generic fs type first, override with specific one if available. |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 706 | copy_prop("fs_type", "fs_type") |
JP Abgrall | 5bfed5a | 2014-06-16 14:17:40 -0700 | [diff] [blame] | 707 | copy_prop("userdata_fs_type", "fs_type") |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 708 | copy_prop("userdata_size", "partition_size") |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 709 | copy_prop("flash_logical_block_size", "flash_logical_block_size") |
Connor O'Brien | 20f08c3 | 2017-01-05 16:48:14 -0800 | [diff] [blame] | 710 | copy_prop("flash_erase_block_size", "flash_erase_block_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 711 | copy_prop("userdata_selinux_fc", "selinux_fc") |
Daniel Rosenberg | 6cc2c81 | 2019-12-17 17:36:31 -0800 | [diff] [blame] | 712 | copy_prop("needs_casefold", "needs_casefold") |
| 713 | copy_prop("needs_projid", "needs_projid") |
Jaegeuk Kim | ed754fb | 2020-10-12 19:50:05 -0700 | [diff] [blame] | 714 | copy_prop("needs_compress", "needs_compress") |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 715 | elif mount_point == "cache": |
| 716 | copy_prop("cache_fs_type", "fs_type") |
| 717 | copy_prop("cache_size", "partition_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 718 | copy_prop("cache_selinux_fc", "selinux_fc") |
Ying Wang | a0febe5 | 2013-03-20 11:02:05 -0700 | [diff] [blame] | 719 | elif mount_point == "vendor": |
Bowgo Tsai | 3e599ea | 2017-05-26 18:30:04 +0800 | [diff] [blame] | 720 | copy_prop("avb_vendor_hashtree_enable", "avb_hashtree_enable") |
| 721 | copy_prop("avb_vendor_add_hashtree_footer_args", |
| 722 | "avb_add_hashtree_footer_args") |
| 723 | copy_prop("avb_vendor_key_path", "avb_key_path") |
| 724 | copy_prop("avb_vendor_algorithm", "avb_algorithm") |
Daniel Norman | d5fe862 | 2020-01-08 17:01:11 -0800 | [diff] [blame] | 725 | copy_prop("avb_vendor_salt", "avb_salt") |
Ying Wang | a0febe5 | 2013-03-20 11:02:05 -0700 | [diff] [blame] | 726 | copy_prop("vendor_fs_type", "fs_type") |
| 727 | copy_prop("vendor_size", "partition_size") |
Tao Bao | 332a96b | 2018-03-31 10:27:35 -0700 | [diff] [blame] | 728 | if not copy_prop("vendor_journal_size", "journal_size"): |
| 729 | d["journal_size"] = "0" |
Daniel Rosenberg | f4eabc3 | 2014-07-10 15:42:38 -0700 | [diff] [blame] | 730 | copy_prop("vendor_verity_block_device", "verity_block_device") |
Jin Qian | fde9f79 | 2018-01-22 13:15:46 -0800 | [diff] [blame] | 731 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 732 | copy_prop("vendor_f2fs_compress", "f2fs_compress") |
| 733 | copy_prop("vendor_f2fs_sldc_flags", "f2fs_sldc_flags") |
Patrick Tjin | e11aa50 | 2016-02-09 15:40:38 -0800 | [diff] [blame] | 734 | copy_prop("vendor_squashfs_compressor", "squashfs_compressor") |
| 735 | copy_prop("vendor_squashfs_compressor_opt", "squashfs_compressor_opt") |
Mohamad Ayyash | dfec815 | 2016-05-24 12:59:30 -0700 | [diff] [blame] | 736 | copy_prop("vendor_squashfs_block_size", "squashfs_block_size") |
Mohamad Ayyash | 1b6d348 | 2016-06-15 15:53:07 -0700 | [diff] [blame] | 737 | copy_prop("vendor_squashfs_disable_4k_align", "squashfs_disable_4k_align") |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 738 | copy_prop("vendor_base_fs_file", "base_fs_file") |
Patrick Tjin | a190084 | 2016-10-20 10:58:12 -0700 | [diff] [blame] | 739 | copy_prop("vendor_extfs_inode_count", "extfs_inode_count") |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 740 | if not copy_prop("vendor_extfs_rsv_pct", "extfs_rsv_pct"): |
| 741 | d["extfs_rsv_pct"] = "0" |
Yifan Hong | 749062d | 2018-06-19 16:23:16 -0700 | [diff] [blame] | 742 | copy_prop("vendor_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 743 | copy_prop("vendor_selinux_fc", "selinux_fc") |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 744 | copy_prop("vendor_disable_sparse", "disable_sparse") |
Jaekyun Seok | b7735d8 | 2017-11-27 17:04:47 +0900 | [diff] [blame] | 745 | elif mount_point == "product": |
| 746 | copy_prop("avb_product_hashtree_enable", "avb_hashtree_enable") |
| 747 | copy_prop("avb_product_add_hashtree_footer_args", |
| 748 | "avb_add_hashtree_footer_args") |
| 749 | copy_prop("avb_product_key_path", "avb_key_path") |
| 750 | copy_prop("avb_product_algorithm", "avb_algorithm") |
Daniel Norman | d5fe862 | 2020-01-08 17:01:11 -0800 | [diff] [blame] | 751 | copy_prop("avb_product_salt", "avb_salt") |
Jaekyun Seok | b7735d8 | 2017-11-27 17:04:47 +0900 | [diff] [blame] | 752 | copy_prop("product_fs_type", "fs_type") |
| 753 | copy_prop("product_size", "partition_size") |
Tao Bao | 332a96b | 2018-03-31 10:27:35 -0700 | [diff] [blame] | 754 | if not copy_prop("product_journal_size", "journal_size"): |
| 755 | d["journal_size"] = "0" |
Jaekyun Seok | b7735d8 | 2017-11-27 17:04:47 +0900 | [diff] [blame] | 756 | copy_prop("product_verity_block_device", "verity_block_device") |
Mark Salyzyn | f0cef8d | 2018-10-29 10:55:06 -0700 | [diff] [blame] | 757 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 758 | copy_prop("product_f2fs_compress", "f2fs_compress") |
| 759 | copy_prop("product_f2fs_sldc_flags", "f2fs_sldc_flags") |
Jaekyun Seok | b7735d8 | 2017-11-27 17:04:47 +0900 | [diff] [blame] | 760 | copy_prop("product_squashfs_compressor", "squashfs_compressor") |
| 761 | copy_prop("product_squashfs_compressor_opt", "squashfs_compressor_opt") |
| 762 | copy_prop("product_squashfs_block_size", "squashfs_block_size") |
| 763 | copy_prop("product_squashfs_disable_4k_align", "squashfs_disable_4k_align") |
| 764 | copy_prop("product_base_fs_file", "base_fs_file") |
| 765 | copy_prop("product_extfs_inode_count", "extfs_inode_count") |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 766 | if not copy_prop("product_extfs_rsv_pct", "extfs_rsv_pct"): |
| 767 | d["extfs_rsv_pct"] = "0" |
Yifan Hong | 56a6c3b | 2018-07-20 15:19:34 -0700 | [diff] [blame] | 768 | copy_prop("product_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 769 | copy_prop("product_selinux_fc", "selinux_fc") |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 770 | copy_prop("product_disable_sparse", "disable_sparse") |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 771 | elif mount_point == "system_ext": |
| 772 | copy_prop("avb_system_ext_hashtree_enable", "avb_hashtree_enable") |
| 773 | copy_prop("avb_system_ext_add_hashtree_footer_args", |
Dario Freni | 5f681e1 | 2018-05-29 13:09:01 +0100 | [diff] [blame] | 774 | "avb_add_hashtree_footer_args") |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 775 | copy_prop("avb_system_ext_key_path", "avb_key_path") |
| 776 | copy_prop("avb_system_ext_algorithm", "avb_algorithm") |
Daniel Norman | d5fe862 | 2020-01-08 17:01:11 -0800 | [diff] [blame] | 777 | copy_prop("avb_system_ext_salt", "avb_salt") |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 778 | copy_prop("system_ext_fs_type", "fs_type") |
| 779 | copy_prop("system_ext_size", "partition_size") |
| 780 | if not copy_prop("system_ext_journal_size", "journal_size"): |
Dario Freni | 5f681e1 | 2018-05-29 13:09:01 +0100 | [diff] [blame] | 781 | d["journal_size"] = "0" |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 782 | copy_prop("system_ext_verity_block_device", "verity_block_device") |
Mark Salyzyn | f0cef8d | 2018-10-29 10:55:06 -0700 | [diff] [blame] | 783 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 784 | copy_prop("system_ext_f2fs_compress", "f2fs_compress") |
| 785 | copy_prop("system_ext_f2fs_sldc_flags", "f2fs_sldc_flags") |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 786 | copy_prop("system_ext_squashfs_compressor", "squashfs_compressor") |
| 787 | copy_prop("system_ext_squashfs_compressor_opt", |
Dario Freni | 5f681e1 | 2018-05-29 13:09:01 +0100 | [diff] [blame] | 788 | "squashfs_compressor_opt") |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 789 | copy_prop("system_ext_squashfs_block_size", "squashfs_block_size") |
| 790 | copy_prop("system_ext_squashfs_disable_4k_align", |
Dario Freni | 5f681e1 | 2018-05-29 13:09:01 +0100 | [diff] [blame] | 791 | "squashfs_disable_4k_align") |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 792 | copy_prop("system_ext_base_fs_file", "base_fs_file") |
| 793 | copy_prop("system_ext_extfs_inode_count", "extfs_inode_count") |
| 794 | if not copy_prop("system_ext_extfs_rsv_pct", "extfs_rsv_pct"): |
Dario Freni | 5f681e1 | 2018-05-29 13:09:01 +0100 | [diff] [blame] | 795 | d["extfs_rsv_pct"] = "0" |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 796 | copy_prop("system_ext_reserved_size", "partition_reserved_size") |
| 797 | copy_prop("system_ext_selinux_fc", "selinux_fc") |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 798 | copy_prop("system_ext_disable_sparse", "disable_sparse") |
Bowgo Tsai | d624fa6 | 2017-11-14 23:42:30 +0800 | [diff] [blame] | 799 | elif mount_point == "odm": |
| 800 | copy_prop("avb_odm_hashtree_enable", "avb_hashtree_enable") |
| 801 | copy_prop("avb_odm_add_hashtree_footer_args", |
| 802 | "avb_add_hashtree_footer_args") |
| 803 | copy_prop("avb_odm_key_path", "avb_key_path") |
| 804 | copy_prop("avb_odm_algorithm", "avb_algorithm") |
Daniel Norman | d5fe862 | 2020-01-08 17:01:11 -0800 | [diff] [blame] | 805 | copy_prop("avb_odm_salt", "avb_salt") |
Bowgo Tsai | d624fa6 | 2017-11-14 23:42:30 +0800 | [diff] [blame] | 806 | copy_prop("odm_fs_type", "fs_type") |
| 807 | copy_prop("odm_size", "partition_size") |
| 808 | if not copy_prop("odm_journal_size", "journal_size"): |
| 809 | d["journal_size"] = "0" |
| 810 | copy_prop("odm_verity_block_device", "verity_block_device") |
Mark Salyzyn | f0cef8d | 2018-10-29 10:55:06 -0700 | [diff] [blame] | 811 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Bowgo Tsai | d624fa6 | 2017-11-14 23:42:30 +0800 | [diff] [blame] | 812 | copy_prop("odm_squashfs_compressor", "squashfs_compressor") |
| 813 | copy_prop("odm_squashfs_compressor_opt", "squashfs_compressor_opt") |
| 814 | copy_prop("odm_squashfs_block_size", "squashfs_block_size") |
| 815 | copy_prop("odm_squashfs_disable_4k_align", "squashfs_disable_4k_align") |
| 816 | copy_prop("odm_base_fs_file", "base_fs_file") |
| 817 | copy_prop("odm_extfs_inode_count", "extfs_inode_count") |
| 818 | if not copy_prop("odm_extfs_rsv_pct", "extfs_rsv_pct"): |
| 819 | d["extfs_rsv_pct"] = "0" |
| 820 | copy_prop("odm_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 821 | copy_prop("odm_selinux_fc", "selinux_fc") |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 822 | copy_prop("odm_disable_sparse", "disable_sparse") |
Yifan Hong | cfb917a | 2020-05-07 14:58:20 -0700 | [diff] [blame] | 823 | elif mount_point == "vendor_dlkm": |
| 824 | copy_prop("avb_vendor_dlkm_hashtree_enable", "avb_hashtree_enable") |
| 825 | copy_prop("avb_vendor_dlkm_add_hashtree_footer_args", |
| 826 | "avb_add_hashtree_footer_args") |
| 827 | copy_prop("avb_vendor_dlkm_key_path", "avb_key_path") |
| 828 | copy_prop("avb_vendor_dlkm_algorithm", "avb_algorithm") |
| 829 | copy_prop("avb_vendor_dlkm_salt", "avb_salt") |
| 830 | copy_prop("vendor_dlkm_fs_type", "fs_type") |
| 831 | copy_prop("vendor_dlkm_size", "partition_size") |
Jaegeuk Kim | 1369654 | 2021-05-22 09:47:48 -0700 | [diff] [blame] | 832 | copy_prop("vendor_dlkm_f2fs_compress", "f2fs_compress") |
| 833 | copy_prop("vendor_dlkm_f2fs_sldc_flags", "f2fs_sldc_flags") |
Yifan Hong | cfb917a | 2020-05-07 14:58:20 -0700 | [diff] [blame] | 834 | if not copy_prop("vendor_dlkm_journal_size", "journal_size"): |
| 835 | d["journal_size"] = "0" |
| 836 | copy_prop("vendor_dlkm_verity_block_device", "verity_block_device") |
| 837 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
| 838 | copy_prop("vendor_dlkm_squashfs_compressor", "squashfs_compressor") |
| 839 | copy_prop("vendor_dlkm_squashfs_compressor_opt", "squashfs_compressor_opt") |
| 840 | copy_prop("vendor_dlkm_squashfs_block_size", "squashfs_block_size") |
| 841 | copy_prop("vendor_dlkm_squashfs_disable_4k_align", "squashfs_disable_4k_align") |
| 842 | copy_prop("vendor_dlkm_base_fs_file", "base_fs_file") |
| 843 | copy_prop("vendor_dlkm_extfs_inode_count", "extfs_inode_count") |
| 844 | if not copy_prop("vendor_dlkm_extfs_rsv_pct", "extfs_rsv_pct"): |
| 845 | d["extfs_rsv_pct"] = "0" |
| 846 | copy_prop("vendor_dlkm_reserved_size", "partition_reserved_size") |
| 847 | copy_prop("vendor_dlkm_selinux_fc", "selinux_fc") |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 848 | copy_prop("vendor_dlkm_disable_sparse", "disable_sparse") |
Yifan Hong | f496f1b | 2020-07-15 16:52:59 -0700 | [diff] [blame] | 849 | elif mount_point == "odm_dlkm": |
| 850 | copy_prop("avb_odm_dlkm_hashtree_enable", "avb_hashtree_enable") |
| 851 | copy_prop("avb_odm_dlkm_add_hashtree_footer_args", |
| 852 | "avb_add_hashtree_footer_args") |
| 853 | copy_prop("avb_odm_dlkm_key_path", "avb_key_path") |
| 854 | copy_prop("avb_odm_dlkm_algorithm", "avb_algorithm") |
| 855 | copy_prop("avb_odm_dlkm_salt", "avb_salt") |
| 856 | copy_prop("odm_dlkm_fs_type", "fs_type") |
| 857 | copy_prop("odm_dlkm_size", "partition_size") |
| 858 | if not copy_prop("odm_dlkm_journal_size", "journal_size"): |
| 859 | d["journal_size"] = "0" |
| 860 | copy_prop("odm_dlkm_verity_block_device", "verity_block_device") |
| 861 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
| 862 | copy_prop("odm_dlkm_squashfs_compressor", "squashfs_compressor") |
| 863 | copy_prop("odm_dlkm_squashfs_compressor_opt", "squashfs_compressor_opt") |
| 864 | copy_prop("odm_dlkm_squashfs_block_size", "squashfs_block_size") |
| 865 | copy_prop("odm_dlkm_squashfs_disable_4k_align", "squashfs_disable_4k_align") |
| 866 | copy_prop("odm_dlkm_base_fs_file", "base_fs_file") |
| 867 | copy_prop("odm_dlkm_extfs_inode_count", "extfs_inode_count") |
| 868 | if not copy_prop("odm_dlkm_extfs_rsv_pct", "extfs_rsv_pct"): |
| 869 | d["extfs_rsv_pct"] = "0" |
| 870 | copy_prop("odm_dlkm_reserved_size", "partition_reserved_size") |
| 871 | copy_prop("odm_dlkm_selinux_fc", "selinux_fc") |
David Anderson | 9e95a02 | 2021-08-31 21:32:45 -0700 | [diff] [blame] | 872 | copy_prop("odm_dlkm_disable_sparse", "disable_sparse") |
Ying Wang | b888843 | 2014-03-11 17:13:27 -0700 | [diff] [blame] | 873 | elif mount_point == "oem": |
| 874 | copy_prop("fs_type", "fs_type") |
| 875 | copy_prop("oem_size", "partition_size") |
Tao Bao | 332a96b | 2018-03-31 10:27:35 -0700 | [diff] [blame] | 876 | if not copy_prop("oem_journal_size", "journal_size"): |
| 877 | d["journal_size"] = "0" |
Patrick Tjin | a190084 | 2016-10-20 10:58:12 -0700 | [diff] [blame] | 878 | copy_prop("oem_extfs_inode_count", "extfs_inode_count") |
Mark Salyzyn | f0cef8d | 2018-10-29 10:55:06 -0700 | [diff] [blame] | 879 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 880 | if not copy_prop("oem_extfs_rsv_pct", "extfs_rsv_pct"): |
| 881 | d["extfs_rsv_pct"] = "0" |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 882 | copy_prop("oem_selinux_fc", "selinux_fc") |
David Zeuthen | 4014a9d | 2016-09-30 17:29:22 -0400 | [diff] [blame] | 883 | d["partition_name"] = mount_point |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 884 | return d |
| 885 | |
| 886 | |
| 887 | def LoadGlobalDict(filename): |
| 888 | """Load "name=value" pairs from filename""" |
| 889 | d = {} |
| 890 | f = open(filename) |
| 891 | for line in f: |
| 892 | line = line.strip() |
| 893 | if not line or line.startswith("#"): |
| 894 | continue |
| 895 | k, v = line.split("=", 1) |
| 896 | d[k] = v |
| 897 | f.close() |
| 898 | return d |
| 899 | |
| 900 | |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 901 | def GlobalDictFromImageProp(image_prop, mount_point): |
| 902 | d = {} |
| 903 | def copy_prop(src_p, dest_p): |
| 904 | if src_p in image_prop: |
| 905 | d[dest_p] = image_prop[src_p] |
| 906 | return True |
| 907 | return False |
Tao Bao | 4251fe9 | 2018-07-23 13:05:00 -0700 | [diff] [blame] | 908 | |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 909 | if mount_point == "system": |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 910 | copy_prop("partition_size", "system_size") |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 911 | elif mount_point == "system_other": |
Bowgo Tsai | 867ab66 | 2019-01-29 13:30:18 +0800 | [diff] [blame] | 912 | copy_prop("partition_size", "system_other_size") |
Yifan Hong | 749062d | 2018-06-19 16:23:16 -0700 | [diff] [blame] | 913 | elif mount_point == "vendor": |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 914 | copy_prop("partition_size", "vendor_size") |
Bowgo Tsai | d624fa6 | 2017-11-14 23:42:30 +0800 | [diff] [blame] | 915 | elif mount_point == "odm": |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 916 | copy_prop("partition_size", "odm_size") |
Yifan Hong | cfb917a | 2020-05-07 14:58:20 -0700 | [diff] [blame] | 917 | elif mount_point == "vendor_dlkm": |
| 918 | copy_prop("partition_size", "vendor_dlkm_size") |
Yifan Hong | f496f1b | 2020-07-15 16:52:59 -0700 | [diff] [blame] | 919 | elif mount_point == "odm_dlkm": |
| 920 | copy_prop("partition_size", "odm_dlkm_size") |
Yifan Hong | 56a6c3b | 2018-07-20 15:19:34 -0700 | [diff] [blame] | 921 | elif mount_point == "product": |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 922 | copy_prop("partition_size", "product_size") |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 923 | elif mount_point == "system_ext": |
| 924 | copy_prop("partition_size", "system_ext_size") |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 925 | return d |
| 926 | |
| 927 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 928 | def main(argv): |
Yifan Hong | 8c3dce0 | 2019-04-09 17:03:57 +0000 | [diff] [blame] | 929 | if len(argv) != 4: |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 930 | print(__doc__) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 931 | sys.exit(1) |
| 932 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 933 | common.InitLogging() |
| 934 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 935 | in_dir = argv[0] |
| 936 | glob_dict_file = argv[1] |
| 937 | out_file = argv[2] |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 938 | target_out = argv[3] |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 939 | |
| 940 | glob_dict = LoadGlobalDict(glob_dict_file) |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 941 | if "mount_point" in glob_dict: |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 942 | # The caller knows the mount point and provides a dictionary needed by |
Tao Bao | c7a6f1e | 2015-06-23 11:16:05 -0700 | [diff] [blame] | 943 | # BuildImage(). |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 944 | image_properties = glob_dict |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 945 | else: |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 946 | image_filename = os.path.basename(out_file) |
| 947 | mount_point = "" |
| 948 | if image_filename == "system.img": |
| 949 | mount_point = "system" |
Alex Light | 4e358ab | 2016-06-16 14:47:10 -0700 | [diff] [blame] | 950 | elif image_filename == "system_other.img": |
| 951 | mount_point = "system_other" |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 952 | elif image_filename == "userdata.img": |
| 953 | mount_point = "data" |
| 954 | elif image_filename == "cache.img": |
| 955 | mount_point = "cache" |
| 956 | elif image_filename == "vendor.img": |
| 957 | mount_point = "vendor" |
Bowgo Tsai | d624fa6 | 2017-11-14 23:42:30 +0800 | [diff] [blame] | 958 | elif image_filename == "odm.img": |
| 959 | mount_point = "odm" |
Yifan Hong | cfb917a | 2020-05-07 14:58:20 -0700 | [diff] [blame] | 960 | elif image_filename == "vendor_dlkm.img": |
| 961 | mount_point = "vendor_dlkm" |
Yifan Hong | f496f1b | 2020-07-15 16:52:59 -0700 | [diff] [blame] | 962 | elif image_filename == "odm_dlkm.img": |
| 963 | mount_point = "odm_dlkm" |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 964 | elif image_filename == "oem.img": |
| 965 | mount_point = "oem" |
Jaekyun Seok | b7735d8 | 2017-11-27 17:04:47 +0900 | [diff] [blame] | 966 | elif image_filename == "product.img": |
| 967 | mount_point = "product" |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 968 | elif image_filename == "system_ext.img": |
| 969 | mount_point = "system_ext" |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 970 | else: |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 971 | logger.error("Unknown image file name %s", image_filename) |
Tao Bao | 1c830bf | 2017-12-25 10:43:47 -0800 | [diff] [blame] | 972 | sys.exit(1) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 973 | |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 974 | image_properties = ImagePropFromGlobalDict(glob_dict, mount_point) |
| 975 | |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 976 | try: |
| 977 | BuildImage(in_dir, image_properties, out_file, target_out) |
| 978 | except: |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 979 | logger.error("Failed to build %s from %s", out_file, in_dir) |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 980 | raise |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 981 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 982 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 983 | if __name__ == '__main__': |
Tao Bao | 1c830bf | 2017-12-25 10:43:47 -0800 | [diff] [blame] | 984 | try: |
| 985 | main(sys.argv[1:]) |
| 986 | finally: |
| 987 | common.Cleanup() |