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 | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 21 | Usage: build_image.py 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 | """ |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 60 | cmd = ["du", "-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) |
Mark Salyzyn | 9f23b89 | 2019-01-08 08:17:46 -0800 | [diff] [blame] | 76 | # increase by > 4% 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') |
| 78 | spare_inodes = inodes * 4 // 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 | |
Mark Salyzyn | 6541d0a | 2019-01-10 14:30:51 -0800 | [diff] [blame] | 85 | def GetFilesystemCharacteristics(image_path, sparse_image=True): |
| 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 | |
| 99 | cmd = ["tune2fs", "-l", unsparse_image_path] |
| 100 | try: |
| 101 | output = common.RunAndCheckOutput(cmd, verbose=False) |
Tao Bao | f3fc62c | 2018-10-25 12:23:12 -0700 | [diff] [blame] | 102 | finally: |
Mark Salyzyn | 6541d0a | 2019-01-10 14:30:51 -0800 | [diff] [blame] | 103 | if sparse_image: |
| 104 | os.remove(unsparse_image_path) |
Tao Bao | f3fc62c | 2018-10-25 12:23:12 -0700 | [diff] [blame] | 105 | fs_dict = {} |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 106 | for line in output.splitlines(): |
| 107 | fields = line.split(":") |
| 108 | if len(fields) == 2: |
| 109 | fs_dict[fields[0].strip()] = fields[1].strip() |
| 110 | return fs_dict |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 111 | |
| 112 | |
Geremy Condra | 6e8f53c | 2013-12-05 17:09:18 -0800 | [diff] [blame] | 113 | def UnsparseImage(sparse_image_path, replace=True): |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 114 | img_dir = os.path.dirname(sparse_image_path) |
| 115 | unsparse_image_path = "unsparse_" + os.path.basename(sparse_image_path) |
| 116 | unsparse_image_path = os.path.join(img_dir, unsparse_image_path) |
| 117 | if os.path.exists(unsparse_image_path): |
Geremy Condra | 6e8f53c | 2013-12-05 17:09:18 -0800 | [diff] [blame] | 118 | if replace: |
| 119 | os.unlink(unsparse_image_path) |
| 120 | else: |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 121 | return unsparse_image_path |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 122 | inflate_command = ["simg2img", sparse_image_path, unsparse_image_path] |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 123 | try: |
| 124 | common.RunAndCheckOutput(inflate_command) |
| 125 | except: |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 126 | os.remove(unsparse_image_path) |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 127 | raise |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 128 | return unsparse_image_path |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 129 | |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 130 | |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 131 | def ConvertBlockMapToBaseFs(block_map_file): |
Tao Bao | 1c830bf | 2017-12-25 10:43:47 -0800 | [diff] [blame] | 132 | base_fs_file = common.MakeTempFile(prefix="script_gen_", suffix=".base_fs") |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 133 | 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] | 134 | common.RunAndCheckOutput(convert_command) |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 135 | return base_fs_file |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 136 | |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 137 | |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 138 | def SetUpInDirAndFsConfig(origin_in, prop_dict): |
| 139 | """Returns the in_dir and fs_config that should be used for image building. |
| 140 | |
Tom Cherry | d14b895 | 2018-08-09 14:26:00 -0700 | [diff] [blame] | 141 | When building system.img for all targets, it creates and returns a staged dir |
| 142 | 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] | 143 | |
| 144 | Args: |
| 145 | origin_in: Path to the input directory. |
| 146 | prop_dict: A property dict that contains info like partition size. Values |
| 147 | may be updated. |
| 148 | |
| 149 | Returns: |
| 150 | A tuple of in_dir and fs_config that should be used to build the image. |
| 151 | """ |
| 152 | fs_config = prop_dict.get("fs_config") |
Tom Cherry | d14b895 | 2018-08-09 14:26:00 -0700 | [diff] [blame] | 153 | |
| 154 | if prop_dict["mount_point"] == "system_other": |
| 155 | prop_dict["mount_point"] = "system" |
| 156 | return origin_in, fs_config |
| 157 | |
| 158 | if prop_dict["mount_point"] != "system": |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 159 | return origin_in, fs_config |
| 160 | |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 161 | if "first_pass" in prop_dict: |
| 162 | prop_dict["mount_point"] = "/" |
| 163 | return prop_dict["first_pass"] |
| 164 | |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 165 | # Construct a staging directory of the root file system. |
| 166 | in_dir = common.MakeTempDir() |
| 167 | root_dir = prop_dict.get("root_dir") |
| 168 | if root_dir: |
| 169 | shutil.rmtree(in_dir) |
| 170 | shutil.copytree(root_dir, in_dir, symlinks=True) |
| 171 | in_dir_system = os.path.join(in_dir, "system") |
| 172 | shutil.rmtree(in_dir_system, ignore_errors=True) |
| 173 | shutil.copytree(origin_in, in_dir_system, symlinks=True) |
| 174 | |
| 175 | # Change the mount point to "/". |
| 176 | prop_dict["mount_point"] = "/" |
| 177 | if fs_config: |
| 178 | # We need to merge the fs_config files of system and root. |
| 179 | merged_fs_config = common.MakeTempFile( |
| 180 | prefix="merged_fs_config", suffix=".txt") |
| 181 | with open(merged_fs_config, "w") as fw: |
| 182 | if "root_fs_config" in prop_dict: |
| 183 | with open(prop_dict["root_fs_config"]) as fr: |
| 184 | fw.writelines(fr.readlines()) |
| 185 | with open(fs_config) as fr: |
| 186 | fw.writelines(fr.readlines()) |
| 187 | fs_config = merged_fs_config |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 188 | prop_dict["first_pass"] = (in_dir, fs_config) |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 189 | return in_dir, fs_config |
| 190 | |
| 191 | |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 192 | def CheckHeadroom(ext4fs_output, prop_dict): |
| 193 | """Checks if there's enough headroom space available. |
| 194 | |
| 195 | Headroom is the reserved space on system image (via PRODUCT_SYSTEM_HEADROOM), |
| 196 | which is useful for devices with low disk space that have system image |
| 197 | variation between builds. The 'partition_headroom' in prop_dict is the size |
| 198 | in bytes, while the numbers in 'ext4fs_output' are for 4K-blocks. |
| 199 | |
| 200 | Args: |
| 201 | ext4fs_output: The output string from mke2fs command. |
| 202 | prop_dict: The property dict. |
| 203 | |
Tao Bao | d8a953d | 2018-01-02 21:19:27 -0800 | [diff] [blame] | 204 | Raises: |
| 205 | AssertionError: On invalid input. |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 206 | BuildImageError: On check failure. |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 207 | """ |
Tao Bao | d8a953d | 2018-01-02 21:19:27 -0800 | [diff] [blame] | 208 | assert ext4fs_output is not None |
| 209 | assert prop_dict.get('fs_type', '').startswith('ext4') |
| 210 | assert 'partition_headroom' in prop_dict |
| 211 | assert 'mount_point' in prop_dict |
| 212 | |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 213 | ext4fs_stats = re.compile( |
| 214 | r'Created filesystem with .* (?P<used_blocks>[0-9]+)/' |
| 215 | r'(?P<total_blocks>[0-9]+) blocks') |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 216 | last_line = ext4fs_output.strip().split('\n')[-1] |
| 217 | m = ext4fs_stats.match(last_line) |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 218 | used_blocks = int(m.groupdict().get('used_blocks')) |
| 219 | total_blocks = int(m.groupdict().get('total_blocks')) |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 220 | headroom_blocks = int(prop_dict['partition_headroom']) // BLOCK_SIZE |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 221 | adjusted_blocks = total_blocks - headroom_blocks |
| 222 | if used_blocks > adjusted_blocks: |
Tao Bao | d8a953d | 2018-01-02 21:19:27 -0800 | [diff] [blame] | 223 | mount_point = prop_dict["mount_point"] |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 224 | raise BuildImageError( |
| 225 | "Error: Not enough room on {} (total: {} blocks, used: {} blocks, " |
| 226 | "headroom: {} blocks, available: {} blocks)".format( |
| 227 | mount_point, total_blocks, used_blocks, headroom_blocks, |
| 228 | adjusted_blocks)) |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 229 | |
| 230 | |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 231 | def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config): |
| 232 | """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] | 233 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 234 | Args: |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 235 | in_dir: Path to input directory. |
| 236 | prop_dict: A property dict that contains info like partition size. Values |
| 237 | will be updated with computed values. |
| 238 | out_file: The output image file. |
| 239 | target_out: Path to the TARGET_OUT directory as in Makefile. It actually |
| 240 | points to the /system directory under PRODUCT_OUT. fs_config (the one |
| 241 | under system/core/libcutils) reads device specific FS config files from |
| 242 | there. |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 243 | fs_config: The fs_config file that drives the prototype |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 244 | |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 245 | Raises: |
| 246 | BuildImageError: On build image failures. |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 247 | """ |
| 248 | build_command = [] |
| 249 | fs_type = prop_dict.get("fs_type", "") |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 250 | run_e2fsck = False |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 251 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 252 | if fs_type.startswith("ext"): |
Adrien Schildknecht | 9a072cc | 2016-11-18 17:06:29 -0800 | [diff] [blame] | 253 | build_command = [prop_dict["ext_mkuserimg"]] |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 254 | if "extfs_sparse_flag" in prop_dict: |
| 255 | build_command.append(prop_dict["extfs_sparse_flag"]) |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 256 | run_e2fsck = True |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 257 | build_command.extend([in_dir, out_file, fs_type, |
| 258 | prop_dict["mount_point"]]) |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 259 | build_command.append(prop_dict["image_size"]) |
Ying Wang | f3b8635 | 2014-11-18 18:03:13 -0800 | [diff] [blame] | 260 | if "journal_size" in prop_dict: |
| 261 | build_command.extend(["-j", prop_dict["journal_size"]]) |
Doug Zongker | 850b807 | 2013-12-05 15:54:55 -0800 | [diff] [blame] | 262 | if "timestamp" in prop_dict: |
| 263 | build_command.extend(["-T", str(prop_dict["timestamp"])]) |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 264 | if fs_config: |
Doug Zongker | 8282282 | 2014-06-16 09:10:55 -0700 | [diff] [blame] | 265 | build_command.extend(["-C", fs_config]) |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 266 | if target_out: |
| 267 | build_command.extend(["-D", target_out]) |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 268 | if "block_list" in prop_dict: |
| 269 | build_command.extend(["-B", prop_dict["block_list"]]) |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 270 | if "base_fs_file" in prop_dict: |
| 271 | base_fs_file = ConvertBlockMapToBaseFs(prop_dict["base_fs_file"]) |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 272 | build_command.extend(["-d", base_fs_file]) |
Christoffer Dall | 8ed01f3 | 2014-12-17 21:34:12 +0100 | [diff] [blame] | 273 | build_command.extend(["-L", prop_dict["mount_point"]]) |
Patrick Tjin | a190084 | 2016-10-20 10:58:12 -0700 | [diff] [blame] | 274 | if "extfs_inode_count" in prop_dict: |
| 275 | build_command.extend(["-i", prop_dict["extfs_inode_count"]]) |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 276 | if "extfs_rsv_pct" in prop_dict: |
| 277 | build_command.extend(["-M", prop_dict["extfs_rsv_pct"]]) |
Connor O'Brien | 20f08c3 | 2017-01-05 16:48:14 -0800 | [diff] [blame] | 278 | if "flash_erase_block_size" in prop_dict: |
| 279 | build_command.extend(["-e", prop_dict["flash_erase_block_size"]]) |
| 280 | if "flash_logical_block_size" in prop_dict: |
| 281 | build_command.extend(["-o", prop_dict["flash_logical_block_size"]]) |
Tao Bao | d86e311 | 2017-09-22 15:45:33 -0700 | [diff] [blame] | 282 | # Specify UUID and hash_seed if using mke2fs. |
Tianjie Xu | 5733222 | 2018-08-15 16:16:21 -0700 | [diff] [blame] | 283 | if prop_dict["ext_mkuserimg"] == "mkuserimg_mke2fs": |
Tao Bao | d86e311 | 2017-09-22 15:45:33 -0700 | [diff] [blame] | 284 | if "uuid" in prop_dict: |
| 285 | build_command.extend(["-U", prop_dict["uuid"]]) |
| 286 | if "hash_seed" in prop_dict: |
| 287 | build_command.extend(["-S", prop_dict["hash_seed"]]) |
Jin Qian | fde9f79 | 2018-01-22 13:15:46 -0800 | [diff] [blame] | 288 | if "ext4_share_dup_blocks" in prop_dict: |
| 289 | build_command.append("-c") |
Mark Salyzyn | c777eaa | 2019-01-08 10:08:04 -0800 | [diff] [blame] | 290 | build_command.extend(["--inode_size", "256"]) |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 291 | if "selinux_fc" in prop_dict: |
Kenny Root | f32dc71 | 2012-04-08 10:42:34 -0700 | [diff] [blame] | 292 | build_command.append(prop_dict["selinux_fc"]) |
Mohamad Ayyash | b97746e | 2015-03-03 12:30:37 -0800 | [diff] [blame] | 293 | elif fs_type.startswith("squash"): |
| 294 | build_command = ["mksquashfsimage.sh"] |
| 295 | build_command.extend([in_dir, out_file]) |
Todd Poynor | b2a555e | 2015-12-15 18:00:14 -0800 | [diff] [blame] | 296 | if "squashfs_sparse_flag" in prop_dict: |
| 297 | build_command.extend([prop_dict["squashfs_sparse_flag"]]) |
Mohamad Ayyash | b97746e | 2015-03-03 12:30:37 -0800 | [diff] [blame] | 298 | build_command.extend(["-m", prop_dict["mount_point"]]) |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 299 | if target_out: |
| 300 | build_command.extend(["-d", target_out]) |
Mohamad Ayyash | 8837882 | 2016-04-07 22:10:51 -0700 | [diff] [blame] | 301 | if fs_config: |
| 302 | build_command.extend(["-C", fs_config]) |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 303 | if "selinux_fc" in prop_dict: |
Mohamad Ayyash | b97746e | 2015-03-03 12:30:37 -0800 | [diff] [blame] | 304 | build_command.extend(["-c", prop_dict["selinux_fc"]]) |
Mohamad Ayyash | c3484f7 | 2016-06-13 09:46:58 -0700 | [diff] [blame] | 305 | if "block_list" in prop_dict: |
| 306 | build_command.extend(["-B", prop_dict["block_list"]]) |
Ng Zhi An | 9446c1d | 2018-01-19 15:51:46 -0800 | [diff] [blame] | 307 | if "squashfs_block_size" in prop_dict: |
| 308 | build_command.extend(["-b", prop_dict["squashfs_block_size"]]) |
Simon Wilson | f86e7ee | 2015-06-17 12:35:15 -0700 | [diff] [blame] | 309 | if "squashfs_compressor" in prop_dict: |
| 310 | build_command.extend(["-z", prop_dict["squashfs_compressor"]]) |
| 311 | if "squashfs_compressor_opt" in prop_dict: |
| 312 | build_command.extend(["-zo", prop_dict["squashfs_compressor_opt"]]) |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 313 | if prop_dict.get("squashfs_disable_4k_align") == "true": |
Mohamad Ayyash | 1b6d348 | 2016-06-15 15:53:07 -0700 | [diff] [blame] | 314 | build_command.extend(["-a"]) |
JP Abgrall | 5bfed5a | 2014-06-16 14:17:40 -0700 | [diff] [blame] | 315 | elif fs_type.startswith("f2fs"): |
| 316 | build_command = ["mkf2fsuserimg.sh"] |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 317 | build_command.extend([out_file, prop_dict["image_size"]]) |
Jaegeuk Kim | 2ea1eba | 2017-11-28 19:21:28 -0800 | [diff] [blame] | 318 | if fs_config: |
| 319 | build_command.extend(["-C", fs_config]) |
| 320 | build_command.extend(["-f", in_dir]) |
| 321 | if target_out: |
| 322 | build_command.extend(["-D", target_out]) |
| 323 | if "selinux_fc" in prop_dict: |
| 324 | build_command.extend(["-s", prop_dict["selinux_fc"]]) |
| 325 | build_command.extend(["-t", prop_dict["mount_point"]]) |
| 326 | if "timestamp" in prop_dict: |
| 327 | build_command.extend(["-T", str(prop_dict["timestamp"])]) |
| 328 | build_command.extend(["-L", prop_dict["mount_point"]]) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 329 | else: |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 330 | raise BuildImageError( |
| 331 | "Error: unknown filesystem type: {}".format(fs_type)) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 332 | |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 333 | try: |
| 334 | mkfs_output = common.RunAndCheckOutput(build_command) |
| 335 | except: |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 336 | try: |
| 337 | du = GetDiskUsage(in_dir) |
| 338 | du_str = "{} bytes ({} MB)".format(du, du // BYTES_IN_MB) |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 339 | # Suppress any errors from GetDiskUsage() to avoid hiding the real errors |
| 340 | # from common.RunAndCheckOutput(). |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 341 | except Exception: # pylint: disable=broad-except |
| 342 | logger.exception("Failed to compute disk usage with du") |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 343 | du_str = "unknown" |
Tao Bao | 4251fe9 | 2018-07-23 13:05:00 -0700 | [diff] [blame] | 344 | print( |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 345 | "Out of space? Out of inodes? The tree size of {} is {}, " |
| 346 | "with reserved space of {} bytes ({} MB).".format( |
Tao Bao | c2606eb | 2018-07-20 14:44:46 -0700 | [diff] [blame] | 347 | in_dir, du_str, |
Tao Bao | 4251fe9 | 2018-07-23 13:05:00 -0700 | [diff] [blame] | 348 | int(prop_dict.get("partition_reserved_size", 0)), |
| 349 | int(prop_dict.get("partition_reserved_size", 0)) // BYTES_IN_MB)) |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 350 | print( |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 351 | "The max image size for filesystem files is {} bytes ({} MB), out of a " |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 352 | "total partition size of {} bytes ({} MB).".format( |
| 353 | int(prop_dict["image_size"]), |
| 354 | int(prop_dict["image_size"]) // BYTES_IN_MB, |
| 355 | int(prop_dict["partition_size"]), |
| 356 | int(prop_dict["partition_size"]) // BYTES_IN_MB)) |
Tao Bao | 986ee86 | 2018-10-04 15:46:16 -0700 | [diff] [blame] | 357 | raise |
Ying Wang | 69e9b4d | 2012-11-26 18:10:23 -0800 | [diff] [blame] | 358 | |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 359 | if run_e2fsck and prop_dict.get("skip_fsck") != "true": |
| 360 | unsparse_image = UnsparseImage(out_file, replace=False) |
| 361 | |
| 362 | # Run e2fsck on the inflated image file |
| 363 | e2fsck_command = ["e2fsck", "-f", "-n", unsparse_image] |
| 364 | try: |
| 365 | common.RunAndCheckOutput(e2fsck_command) |
| 366 | finally: |
| 367 | os.remove(unsparse_image) |
| 368 | |
| 369 | return mkfs_output |
| 370 | |
| 371 | |
| 372 | def BuildImage(in_dir, prop_dict, out_file, target_out=None): |
| 373 | """Builds an image for the files under in_dir and writes it to out_file. |
| 374 | |
| 375 | Args: |
| 376 | in_dir: Path to input directory. |
| 377 | prop_dict: A property dict that contains info like partition size. Values |
| 378 | will be updated with computed values. |
| 379 | out_file: The output image file. |
| 380 | target_out: Path to the TARGET_OUT directory as in Makefile. It actually |
| 381 | points to the /system directory under PRODUCT_OUT. fs_config (the one |
| 382 | under system/core/libcutils) reads device specific FS config files from |
| 383 | there. |
| 384 | |
| 385 | Raises: |
| 386 | BuildImageError: On build image failures. |
| 387 | """ |
| 388 | in_dir, fs_config = SetUpInDirAndFsConfig(in_dir, prop_dict) |
| 389 | |
| 390 | build_command = [] |
| 391 | fs_type = prop_dict.get("fs_type", "") |
| 392 | |
| 393 | fs_spans_partition = True |
| 394 | if fs_type.startswith("squash"): |
| 395 | fs_spans_partition = False |
| 396 | |
| 397 | # Get a builder for creating an image that's to be verified by Verified Boot, |
| 398 | # or None if not applicable. |
| 399 | verity_image_builder = verity_utils.CreateVerityImageBuilder(prop_dict) |
| 400 | |
| 401 | if (prop_dict.get("use_dynamic_partition_size") == "true" and |
| 402 | "partition_size" not in prop_dict): |
| 403 | # If partition_size is not defined, use output of `du' + reserved_size. |
| 404 | size = GetDiskUsage(in_dir) |
| 405 | logger.info( |
| 406 | "The tree size of %s is %d MB.", in_dir, size // BYTES_IN_MB) |
| 407 | # If not specified, give us 16MB margin for GetDiskUsage error ... |
| 408 | reserved_size = int(prop_dict.get("partition_reserved_size", BYTES_IN_MB * 16)) |
| 409 | partition_headroom = int(prop_dict.get("partition_headroom", 0)) |
| 410 | if fs_type.startswith("ext4") and partition_headroom > reserved_size: |
| 411 | reserved_size = partition_headroom |
| 412 | size += reserved_size |
| 413 | # Round this up to a multiple of 4K so that avbtool works |
| 414 | size = common.RoundUpTo4K(size) |
| 415 | if fs_type.startswith("ext"): |
| 416 | prop_dict["partition_size"] = str(size) |
| 417 | prop_dict["image_size"] = str(size) |
| 418 | if "extfs_inode_count" not in prop_dict: |
| 419 | prop_dict["extfs_inode_count"] = str(GetInodeUsage(in_dir)) |
| 420 | logger.info( |
| 421 | "First Pass based on estimates of %d MB and %s inodes.", |
| 422 | size // BYTES_IN_MB, prop_dict["extfs_inode_count"]) |
| 423 | BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config) |
Mark Salyzyn | 6541d0a | 2019-01-10 14:30:51 -0800 | [diff] [blame] | 424 | sparse_image = False |
| 425 | if "extfs_sparse_flag" in prop_dict: |
| 426 | sparse_image = True |
| 427 | fs_dict = GetFilesystemCharacteristics(out_file, sparse_image) |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 428 | os.remove(out_file) |
| 429 | block_size = int(fs_dict.get("Block size", "4096")) |
| 430 | free_size = int(fs_dict.get("Free blocks", "0")) * block_size |
| 431 | reserved_size = int(prop_dict.get("partition_reserved_size", 0)) |
| 432 | partition_headroom = int(fs_dict.get("partition_headroom", 0)) |
| 433 | if fs_type.startswith("ext4") and partition_headroom > reserved_size: |
| 434 | reserved_size = partition_headroom |
| 435 | if free_size <= reserved_size: |
| 436 | logger.info( |
| 437 | "Not worth reducing image %d <= %d.", free_size, reserved_size) |
| 438 | else: |
| 439 | size -= free_size |
| 440 | size += reserved_size |
Mark Salyzyn | 60a716f | 2019-01-10 08:36:34 -0800 | [diff] [blame] | 441 | if reserved_size == 0: |
Mark Salyzyn | c25b2bf | 2019-01-16 08:03:10 -0800 | [diff] [blame] | 442 | # add .3% margin |
| 443 | size = size * 1003 // 1000 |
Mark Salyzyn | 60a716f | 2019-01-10 08:36:34 -0800 | [diff] [blame] | 444 | # Use a minimum size, otherwise we will fail to calculate an AVB footer |
| 445 | # or fail to construct an ext4 image. |
| 446 | size = max(size, 256 * 1024) |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 447 | if block_size <= 4096: |
| 448 | size = common.RoundUpTo4K(size) |
| 449 | else: |
| 450 | size = ((size + block_size - 1) // block_size) * block_size |
| 451 | extfs_inode_count = prop_dict["extfs_inode_count"] |
| 452 | inodes = int(fs_dict.get("Inode count", extfs_inode_count)) |
| 453 | inodes -= int(fs_dict.get("Free inodes", "0")) |
Mark Salyzyn | c25b2bf | 2019-01-16 08:03:10 -0800 | [diff] [blame] | 454 | # add .2% margin or 1 inode, whichever is greater |
| 455 | spare_inodes = inodes * 2 // 1000 |
| 456 | min_spare_inodes = 1 |
| 457 | if spare_inodes < min_spare_inodes: |
| 458 | spare_inodes = min_spare_inodes |
| 459 | inodes += spare_inodes |
Mark Salyzyn | 3cd2460 | 2018-11-07 07:40:31 -0800 | [diff] [blame] | 460 | prop_dict["extfs_inode_count"] = str(inodes) |
| 461 | prop_dict["partition_size"] = str(size) |
| 462 | logger.info( |
| 463 | "Allocating %d Inodes for %s.", inodes, out_file) |
| 464 | if verity_image_builder: |
| 465 | size = verity_image_builder.CalculateDynamicPartitionSize(size) |
| 466 | prop_dict["partition_size"] = str(size) |
| 467 | logger.info( |
| 468 | "Allocating %d MB for %s.", size // BYTES_IN_MB, out_file) |
| 469 | |
| 470 | prop_dict["image_size"] = prop_dict["partition_size"] |
| 471 | |
| 472 | # Adjust the image size to make room for the hashes if this is to be verified. |
| 473 | if verity_image_builder: |
| 474 | max_image_size = verity_image_builder.CalculateMaxImageSize() |
| 475 | prop_dict["image_size"] = str(max_image_size) |
| 476 | |
| 477 | mkfs_output = BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config) |
| 478 | |
Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame] | 479 | # Check if there's enough headroom space available for ext4 image. |
Tao Bao | 79d52f8 | 2017-12-07 14:07:44 -0800 | [diff] [blame] | 480 | if "partition_headroom" in prop_dict and fs_type.startswith("ext4"): |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 481 | CheckHeadroom(mkfs_output, prop_dict) |
Tao Bao | c7a6f1e | 2015-06-23 11:16:05 -0700 | [diff] [blame] | 482 | |
Tao Bao | 7549e5e | 2018-10-03 14:23:59 -0700 | [diff] [blame] | 483 | if not fs_spans_partition and verity_image_builder: |
| 484 | verity_image_builder.PadSparseImage(out_file) |
Mohamad Ayyash | dd06352 | 2015-03-24 12:42:03 -0700 | [diff] [blame] | 485 | |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 486 | # Create the verified image if this is to be verified. |
Tao Bao | 7549e5e | 2018-10-03 14:23:59 -0700 | [diff] [blame] | 487 | if verity_image_builder: |
| 488 | verity_image_builder.Build(out_file) |
David Zeuthen | 4014a9d | 2016-09-30 17:29:22 -0400 | [diff] [blame] | 489 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 490 | |
| 491 | def ImagePropFromGlobalDict(glob_dict, mount_point): |
| 492 | """Build an image property dictionary from the global dictionary. |
| 493 | |
| 494 | Args: |
| 495 | glob_dict: the global dictionary from the build system. |
| 496 | mount_point: such as "system", "data" etc. |
| 497 | """ |
Doug Zongker | 1ad7ade | 2013-12-06 11:53:27 -0800 | [diff] [blame] | 498 | d = {} |
Tao Bao | 052ae35 | 2015-09-28 13:44:13 -0700 | [diff] [blame] | 499 | |
Tao Bao | 822f584 | 2015-09-30 16:01:14 -0700 | [diff] [blame] | 500 | if "build.prop" in glob_dict: |
| 501 | bp = glob_dict["build.prop"] |
| 502 | if "ro.build.date.utc" in bp: |
| 503 | d["timestamp"] = bp["ro.build.date.utc"] |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 504 | |
| 505 | def copy_prop(src_p, dest_p): |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 506 | """Copy a property from the global dictionary. |
| 507 | |
| 508 | Args: |
| 509 | src_p: The source property in the global dictionary. |
| 510 | dest_p: The destination property. |
| 511 | Returns: |
| 512 | True if property was found and copied, False otherwise. |
| 513 | """ |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 514 | if src_p in glob_dict: |
| 515 | d[dest_p] = str(glob_dict[src_p]) |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 516 | return True |
| 517 | return False |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 518 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 519 | common_props = ( |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 520 | "extfs_sparse_flag", |
Todd Poynor | b2a555e | 2015-12-15 18:00:14 -0800 | [diff] [blame] | 521 | "squashfs_sparse_flag", |
Ying Wang | 6a42a25 | 2013-02-27 13:54:02 -0800 | [diff] [blame] | 522 | "skip_fsck", |
Adrien Schildknecht | 9a072cc | 2016-11-18 17:06:29 -0800 | [diff] [blame] | 523 | "ext_mkuserimg", |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 524 | "verity", |
Geremy Condra | fd6f751 | 2013-06-16 17:26:08 -0700 | [diff] [blame] | 525 | "verity_key", |
Sami Tolvanen | f99b531 | 2015-05-20 07:30:57 +0100 | [diff] [blame] | 526 | "verity_signer_cmd", |
David Zeuthen | 4014a9d | 2016-09-30 17:29:22 -0400 | [diff] [blame] | 527 | "verity_fec", |
Bowgo Tsai | 6ceeb1a | 2017-10-11 16:21:48 +0800 | [diff] [blame] | 528 | "verity_disable", |
Bowgo Tsai | 3e599ea | 2017-05-26 18:30:04 +0800 | [diff] [blame] | 529 | "avb_enable", |
Tao Bao | 2b6dfd6 | 2017-09-27 17:17:43 -0700 | [diff] [blame] | 530 | "avb_avbtool", |
| 531 | "avb_salt", |
Yifan Hong | 2dae572 | 2018-07-31 12:47:27 -0700 | [diff] [blame] | 532 | "use_dynamic_partition_size", |
Tao Bao | 2b6dfd6 | 2017-09-27 17:17:43 -0700 | [diff] [blame] | 533 | ) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 534 | for p in common_props: |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 535 | copy_prop(p, p) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 536 | |
| 537 | d["mount_point"] = mount_point |
| 538 | if mount_point == "system": |
Bowgo Tsai | 3e599ea | 2017-05-26 18:30:04 +0800 | [diff] [blame] | 539 | copy_prop("avb_system_hashtree_enable", "avb_hashtree_enable") |
| 540 | copy_prop("avb_system_add_hashtree_footer_args", |
| 541 | "avb_add_hashtree_footer_args") |
| 542 | copy_prop("avb_system_key_path", "avb_key_path") |
| 543 | copy_prop("avb_system_algorithm", "avb_algorithm") |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 544 | copy_prop("fs_type", "fs_type") |
Julius D'souza | 001c676 | 2017-05-03 13:43:27 -0700 | [diff] [blame] | 545 | # Copy the generic system fs type first, override with specific one if |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 546 | # available. |
Mohamad Ayyash | b97746e | 2015-03-03 12:30:37 -0800 | [diff] [blame] | 547 | copy_prop("system_fs_type", "fs_type") |
Julius D'souza | 001c676 | 2017-05-03 13:43:27 -0700 | [diff] [blame] | 548 | copy_prop("system_headroom", "partition_headroom") |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 549 | copy_prop("system_size", "partition_size") |
Tao Bao | 332a96b | 2018-03-31 10:27:35 -0700 | [diff] [blame] | 550 | if not copy_prop("system_journal_size", "journal_size"): |
| 551 | d["journal_size"] = "0" |
Daniel Rosenberg | f4eabc3 | 2014-07-10 15:42:38 -0700 | [diff] [blame] | 552 | copy_prop("system_verity_block_device", "verity_block_device") |
Tao Bao | f3282b4 | 2015-04-01 11:21:55 -0700 | [diff] [blame] | 553 | copy_prop("system_root_image", "system_root_image") |
Tao Bao | 8bfd3c7 | 2018-07-20 15:20:28 -0700 | [diff] [blame] | 554 | copy_prop("root_dir", "root_dir") |
| 555 | copy_prop("root_fs_config", "root_fs_config") |
Jin Qian | fde9f79 | 2018-01-22 13:15:46 -0800 | [diff] [blame] | 556 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Simon Wilson | f86e7ee | 2015-06-17 12:35:15 -0700 | [diff] [blame] | 557 | copy_prop("system_squashfs_compressor", "squashfs_compressor") |
| 558 | copy_prop("system_squashfs_compressor_opt", "squashfs_compressor_opt") |
Mohamad Ayyash | dfec815 | 2016-05-24 12:59:30 -0700 | [diff] [blame] | 559 | copy_prop("system_squashfs_block_size", "squashfs_block_size") |
Mohamad Ayyash | 1b6d348 | 2016-06-15 15:53:07 -0700 | [diff] [blame] | 560 | copy_prop("system_squashfs_disable_4k_align", "squashfs_disable_4k_align") |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 561 | copy_prop("system_base_fs_file", "base_fs_file") |
Patrick Tjin | a190084 | 2016-10-20 10:58:12 -0700 | [diff] [blame] | 562 | copy_prop("system_extfs_inode_count", "extfs_inode_count") |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 563 | if not copy_prop("system_extfs_rsv_pct", "extfs_rsv_pct"): |
| 564 | d["extfs_rsv_pct"] = "0" |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 565 | copy_prop("system_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 566 | copy_prop("system_selinux_fc", "selinux_fc") |
Alex Light | 4e358ab | 2016-06-16 14:47:10 -0700 | [diff] [blame] | 567 | elif mount_point == "system_other": |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 568 | # We inherit the selinux policies of /system since we contain some of its |
| 569 | # files. |
Bowgo Tsai | 1e04bf7 | 2019-01-23 22:19:19 +0800 | [diff] [blame] | 570 | copy_prop("avb_system_other_hashtree_enable", "avb_hashtree_enable") |
| 571 | copy_prop("avb_system_other_add_hashtree_footer_args", |
Bowgo Tsai | 3e599ea | 2017-05-26 18:30:04 +0800 | [diff] [blame] | 572 | "avb_add_hashtree_footer_args") |
Bowgo Tsai | 1e04bf7 | 2019-01-23 22:19:19 +0800 | [diff] [blame] | 573 | copy_prop("avb_system_other_key_path", "avb_key_path") |
| 574 | copy_prop("avb_system_other_algorithm", "avb_algorithm") |
Alex Light | 4e358ab | 2016-06-16 14:47:10 -0700 | [diff] [blame] | 575 | copy_prop("fs_type", "fs_type") |
| 576 | copy_prop("system_fs_type", "fs_type") |
Bowgo Tsai | 867ab66 | 2019-01-29 13:30:18 +0800 | [diff] [blame] | 577 | copy_prop("system_other_size", "partition_size") |
Tao Bao | 332a96b | 2018-03-31 10:27:35 -0700 | [diff] [blame] | 578 | if not copy_prop("system_journal_size", "journal_size"): |
| 579 | d["journal_size"] = "0" |
Alex Light | 4e358ab | 2016-06-16 14:47:10 -0700 | [diff] [blame] | 580 | copy_prop("system_verity_block_device", "verity_block_device") |
Mark Salyzyn | f0cef8d | 2018-10-29 10:55:06 -0700 | [diff] [blame] | 581 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Alex Light | 4e358ab | 2016-06-16 14:47:10 -0700 | [diff] [blame] | 582 | copy_prop("system_squashfs_compressor", "squashfs_compressor") |
| 583 | copy_prop("system_squashfs_compressor_opt", "squashfs_compressor_opt") |
| 584 | copy_prop("system_squashfs_block_size", "squashfs_block_size") |
| 585 | copy_prop("system_base_fs_file", "base_fs_file") |
Patrick Tjin | a190084 | 2016-10-20 10:58:12 -0700 | [diff] [blame] | 586 | copy_prop("system_extfs_inode_count", "extfs_inode_count") |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 587 | if not copy_prop("system_extfs_rsv_pct", "extfs_rsv_pct"): |
| 588 | d["extfs_rsv_pct"] = "0" |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 589 | copy_prop("system_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 590 | copy_prop("system_selinux_fc", "selinux_fc") |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 591 | elif mount_point == "data": |
JP Abgrall | 5bfed5a | 2014-06-16 14:17:40 -0700 | [diff] [blame] | 592 | # Copy the generic fs type first, override with specific one if available. |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 593 | copy_prop("fs_type", "fs_type") |
JP Abgrall | 5bfed5a | 2014-06-16 14:17:40 -0700 | [diff] [blame] | 594 | copy_prop("userdata_fs_type", "fs_type") |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 595 | copy_prop("userdata_size", "partition_size") |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 596 | copy_prop("flash_logical_block_size", "flash_logical_block_size") |
Connor O'Brien | 20f08c3 | 2017-01-05 16:48:14 -0800 | [diff] [blame] | 597 | copy_prop("flash_erase_block_size", "flash_erase_block_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 598 | copy_prop("userdata_selinux_fc", "selinux_fc") |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 599 | elif mount_point == "cache": |
| 600 | copy_prop("cache_fs_type", "fs_type") |
| 601 | copy_prop("cache_size", "partition_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 602 | copy_prop("cache_selinux_fc", "selinux_fc") |
Ying Wang | a0febe5 | 2013-03-20 11:02:05 -0700 | [diff] [blame] | 603 | elif mount_point == "vendor": |
Bowgo Tsai | 3e599ea | 2017-05-26 18:30:04 +0800 | [diff] [blame] | 604 | copy_prop("avb_vendor_hashtree_enable", "avb_hashtree_enable") |
| 605 | copy_prop("avb_vendor_add_hashtree_footer_args", |
| 606 | "avb_add_hashtree_footer_args") |
| 607 | copy_prop("avb_vendor_key_path", "avb_key_path") |
| 608 | copy_prop("avb_vendor_algorithm", "avb_algorithm") |
Ying Wang | a0febe5 | 2013-03-20 11:02:05 -0700 | [diff] [blame] | 609 | copy_prop("vendor_fs_type", "fs_type") |
| 610 | copy_prop("vendor_size", "partition_size") |
Tao Bao | 332a96b | 2018-03-31 10:27:35 -0700 | [diff] [blame] | 611 | if not copy_prop("vendor_journal_size", "journal_size"): |
| 612 | d["journal_size"] = "0" |
Daniel Rosenberg | f4eabc3 | 2014-07-10 15:42:38 -0700 | [diff] [blame] | 613 | copy_prop("vendor_verity_block_device", "verity_block_device") |
Jin Qian | fde9f79 | 2018-01-22 13:15:46 -0800 | [diff] [blame] | 614 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Patrick Tjin | e11aa50 | 2016-02-09 15:40:38 -0800 | [diff] [blame] | 615 | copy_prop("vendor_squashfs_compressor", "squashfs_compressor") |
| 616 | copy_prop("vendor_squashfs_compressor_opt", "squashfs_compressor_opt") |
Mohamad Ayyash | dfec815 | 2016-05-24 12:59:30 -0700 | [diff] [blame] | 617 | copy_prop("vendor_squashfs_block_size", "squashfs_block_size") |
Mohamad Ayyash | 1b6d348 | 2016-06-15 15:53:07 -0700 | [diff] [blame] | 618 | copy_prop("vendor_squashfs_disable_4k_align", "squashfs_disable_4k_align") |
Mohamad Ayyash | f876555 | 2016-03-02 21:07:23 -0800 | [diff] [blame] | 619 | copy_prop("vendor_base_fs_file", "base_fs_file") |
Patrick Tjin | a190084 | 2016-10-20 10:58:12 -0700 | [diff] [blame] | 620 | copy_prop("vendor_extfs_inode_count", "extfs_inode_count") |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 621 | if not copy_prop("vendor_extfs_rsv_pct", "extfs_rsv_pct"): |
| 622 | d["extfs_rsv_pct"] = "0" |
Yifan Hong | 749062d | 2018-06-19 16:23:16 -0700 | [diff] [blame] | 623 | copy_prop("vendor_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 624 | copy_prop("vendor_selinux_fc", "selinux_fc") |
Jaekyun Seok | b7735d8 | 2017-11-27 17:04:47 +0900 | [diff] [blame] | 625 | elif mount_point == "product": |
| 626 | copy_prop("avb_product_hashtree_enable", "avb_hashtree_enable") |
| 627 | copy_prop("avb_product_add_hashtree_footer_args", |
| 628 | "avb_add_hashtree_footer_args") |
| 629 | copy_prop("avb_product_key_path", "avb_key_path") |
| 630 | copy_prop("avb_product_algorithm", "avb_algorithm") |
| 631 | copy_prop("product_fs_type", "fs_type") |
| 632 | copy_prop("product_size", "partition_size") |
Tao Bao | 332a96b | 2018-03-31 10:27:35 -0700 | [diff] [blame] | 633 | if not copy_prop("product_journal_size", "journal_size"): |
| 634 | d["journal_size"] = "0" |
Jaekyun Seok | b7735d8 | 2017-11-27 17:04:47 +0900 | [diff] [blame] | 635 | copy_prop("product_verity_block_device", "verity_block_device") |
Mark Salyzyn | f0cef8d | 2018-10-29 10:55:06 -0700 | [diff] [blame] | 636 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Jaekyun Seok | b7735d8 | 2017-11-27 17:04:47 +0900 | [diff] [blame] | 637 | copy_prop("product_squashfs_compressor", "squashfs_compressor") |
| 638 | copy_prop("product_squashfs_compressor_opt", "squashfs_compressor_opt") |
| 639 | copy_prop("product_squashfs_block_size", "squashfs_block_size") |
| 640 | copy_prop("product_squashfs_disable_4k_align", "squashfs_disable_4k_align") |
| 641 | copy_prop("product_base_fs_file", "base_fs_file") |
| 642 | copy_prop("product_extfs_inode_count", "extfs_inode_count") |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 643 | if not copy_prop("product_extfs_rsv_pct", "extfs_rsv_pct"): |
| 644 | d["extfs_rsv_pct"] = "0" |
Yifan Hong | 56a6c3b | 2018-07-20 15:19:34 -0700 | [diff] [blame] | 645 | copy_prop("product_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 646 | copy_prop("product_selinux_fc", "selinux_fc") |
Dario Freni | 924af7d | 2018-08-17 00:56:14 +0100 | [diff] [blame] | 647 | elif mount_point == "product_services": |
Yifan Hong | ebc041a | 2018-07-26 16:02:52 -0700 | [diff] [blame] | 648 | copy_prop("avb_product_services_hashtree_enable", "avb_hashtree_enable") |
| 649 | copy_prop("avb_product_services_add_hashtree_footer_args", |
Dario Freni | 5f681e1 | 2018-05-29 13:09:01 +0100 | [diff] [blame] | 650 | "avb_add_hashtree_footer_args") |
Yifan Hong | ebc041a | 2018-07-26 16:02:52 -0700 | [diff] [blame] | 651 | copy_prop("avb_product_services_key_path", "avb_key_path") |
| 652 | copy_prop("avb_product_services_algorithm", "avb_algorithm") |
| 653 | copy_prop("product_services_fs_type", "fs_type") |
| 654 | copy_prop("product_services_size", "partition_size") |
| 655 | if not copy_prop("product_services_journal_size", "journal_size"): |
Dario Freni | 5f681e1 | 2018-05-29 13:09:01 +0100 | [diff] [blame] | 656 | d["journal_size"] = "0" |
Yifan Hong | ebc041a | 2018-07-26 16:02:52 -0700 | [diff] [blame] | 657 | copy_prop("product_services_verity_block_device", "verity_block_device") |
Mark Salyzyn | f0cef8d | 2018-10-29 10:55:06 -0700 | [diff] [blame] | 658 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Yifan Hong | ebc041a | 2018-07-26 16:02:52 -0700 | [diff] [blame] | 659 | copy_prop("product_services_squashfs_compressor", "squashfs_compressor") |
| 660 | copy_prop("product_services_squashfs_compressor_opt", |
Dario Freni | 5f681e1 | 2018-05-29 13:09:01 +0100 | [diff] [blame] | 661 | "squashfs_compressor_opt") |
Yifan Hong | ebc041a | 2018-07-26 16:02:52 -0700 | [diff] [blame] | 662 | copy_prop("product_services_squashfs_block_size", "squashfs_block_size") |
| 663 | copy_prop("product_services_squashfs_disable_4k_align", |
Dario Freni | 5f681e1 | 2018-05-29 13:09:01 +0100 | [diff] [blame] | 664 | "squashfs_disable_4k_align") |
Yifan Hong | ebc041a | 2018-07-26 16:02:52 -0700 | [diff] [blame] | 665 | copy_prop("product_services_base_fs_file", "base_fs_file") |
| 666 | copy_prop("product_services_extfs_inode_count", "extfs_inode_count") |
| 667 | if not copy_prop("product_services_extfs_rsv_pct", "extfs_rsv_pct"): |
Dario Freni | 5f681e1 | 2018-05-29 13:09:01 +0100 | [diff] [blame] | 668 | d["extfs_rsv_pct"] = "0" |
Yifan Hong | ebc041a | 2018-07-26 16:02:52 -0700 | [diff] [blame] | 669 | copy_prop("product_services_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 670 | copy_prop("product_services_selinux_fc", "selinux_fc") |
Bowgo Tsai | d624fa6 | 2017-11-14 23:42:30 +0800 | [diff] [blame] | 671 | elif mount_point == "odm": |
| 672 | copy_prop("avb_odm_hashtree_enable", "avb_hashtree_enable") |
| 673 | copy_prop("avb_odm_add_hashtree_footer_args", |
| 674 | "avb_add_hashtree_footer_args") |
| 675 | copy_prop("avb_odm_key_path", "avb_key_path") |
| 676 | copy_prop("avb_odm_algorithm", "avb_algorithm") |
| 677 | copy_prop("odm_fs_type", "fs_type") |
| 678 | copy_prop("odm_size", "partition_size") |
| 679 | if not copy_prop("odm_journal_size", "journal_size"): |
| 680 | d["journal_size"] = "0" |
| 681 | copy_prop("odm_verity_block_device", "verity_block_device") |
Mark Salyzyn | f0cef8d | 2018-10-29 10:55:06 -0700 | [diff] [blame] | 682 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Bowgo Tsai | d624fa6 | 2017-11-14 23:42:30 +0800 | [diff] [blame] | 683 | copy_prop("odm_squashfs_compressor", "squashfs_compressor") |
| 684 | copy_prop("odm_squashfs_compressor_opt", "squashfs_compressor_opt") |
| 685 | copy_prop("odm_squashfs_block_size", "squashfs_block_size") |
| 686 | copy_prop("odm_squashfs_disable_4k_align", "squashfs_disable_4k_align") |
| 687 | copy_prop("odm_base_fs_file", "base_fs_file") |
| 688 | copy_prop("odm_extfs_inode_count", "extfs_inode_count") |
| 689 | if not copy_prop("odm_extfs_rsv_pct", "extfs_rsv_pct"): |
| 690 | d["extfs_rsv_pct"] = "0" |
| 691 | copy_prop("odm_reserved_size", "partition_reserved_size") |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 692 | copy_prop("odm_selinux_fc", "selinux_fc") |
Ying Wang | b888843 | 2014-03-11 17:13:27 -0700 | [diff] [blame] | 693 | elif mount_point == "oem": |
| 694 | copy_prop("fs_type", "fs_type") |
| 695 | copy_prop("oem_size", "partition_size") |
Tao Bao | 332a96b | 2018-03-31 10:27:35 -0700 | [diff] [blame] | 696 | if not copy_prop("oem_journal_size", "journal_size"): |
| 697 | d["journal_size"] = "0" |
Patrick Tjin | a190084 | 2016-10-20 10:58:12 -0700 | [diff] [blame] | 698 | copy_prop("oem_extfs_inode_count", "extfs_inode_count") |
Mark Salyzyn | f0cef8d | 2018-10-29 10:55:06 -0700 | [diff] [blame] | 699 | copy_prop("ext4_share_dup_blocks", "ext4_share_dup_blocks") |
Patrick Tjin | 3f5f993 | 2018-03-23 11:36:43 -0700 | [diff] [blame] | 700 | if not copy_prop("oem_extfs_rsv_pct", "extfs_rsv_pct"): |
| 701 | d["extfs_rsv_pct"] = "0" |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 702 | copy_prop("oem_selinux_fc", "selinux_fc") |
David Zeuthen | 4014a9d | 2016-09-30 17:29:22 -0400 | [diff] [blame] | 703 | d["partition_name"] = mount_point |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 704 | return d |
| 705 | |
| 706 | |
| 707 | def LoadGlobalDict(filename): |
| 708 | """Load "name=value" pairs from filename""" |
| 709 | d = {} |
| 710 | f = open(filename) |
| 711 | for line in f: |
| 712 | line = line.strip() |
| 713 | if not line or line.startswith("#"): |
| 714 | continue |
| 715 | k, v = line.split("=", 1) |
| 716 | d[k] = v |
| 717 | f.close() |
| 718 | return d |
| 719 | |
| 720 | |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 721 | def GlobalDictFromImageProp(image_prop, mount_point): |
| 722 | d = {} |
| 723 | def copy_prop(src_p, dest_p): |
| 724 | if src_p in image_prop: |
| 725 | d[dest_p] = image_prop[src_p] |
| 726 | return True |
| 727 | return False |
Tao Bao | 4251fe9 | 2018-07-23 13:05:00 -0700 | [diff] [blame] | 728 | |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 729 | if mount_point == "system": |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 730 | copy_prop("partition_size", "system_size") |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 731 | elif mount_point == "system_other": |
Bowgo Tsai | 867ab66 | 2019-01-29 13:30:18 +0800 | [diff] [blame] | 732 | copy_prop("partition_size", "system_other_size") |
Yifan Hong | 749062d | 2018-06-19 16:23:16 -0700 | [diff] [blame] | 733 | elif mount_point == "vendor": |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 734 | copy_prop("partition_size", "vendor_size") |
Bowgo Tsai | d624fa6 | 2017-11-14 23:42:30 +0800 | [diff] [blame] | 735 | elif mount_point == "odm": |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 736 | copy_prop("partition_size", "odm_size") |
Yifan Hong | 56a6c3b | 2018-07-20 15:19:34 -0700 | [diff] [blame] | 737 | elif mount_point == "product": |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 738 | copy_prop("partition_size", "product_size") |
Dario Freni | 924af7d | 2018-08-17 00:56:14 +0100 | [diff] [blame] | 739 | elif mount_point == "product_services": |
Tao Bao | 35f4ebc | 2018-09-27 15:31:11 -0700 | [diff] [blame] | 740 | copy_prop("partition_size", "product_services_size") |
Yifan Hong | bbcba1e | 2018-06-18 16:32:35 -0700 | [diff] [blame] | 741 | return d |
| 742 | |
| 743 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 744 | def main(argv): |
Yifan Hong | 8c3dce0 | 2019-04-09 17:03:57 +0000 | [diff] [blame] | 745 | if len(argv) != 4: |
Tao Bao | c72727a | 2017-12-07 10:33:00 -0800 | [diff] [blame] | 746 | print(__doc__) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 747 | sys.exit(1) |
| 748 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 749 | common.InitLogging() |
| 750 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 751 | in_dir = argv[0] |
| 752 | glob_dict_file = argv[1] |
| 753 | out_file = argv[2] |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 754 | target_out = argv[3] |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 755 | |
| 756 | glob_dict = LoadGlobalDict(glob_dict_file) |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 757 | if "mount_point" in glob_dict: |
Mark Salyzyn | 780f595 | 2018-10-19 13:44:36 -0700 | [diff] [blame] | 758 | # The caller knows the mount point and provides a dictionary needed by |
Tao Bao | c7a6f1e | 2015-06-23 11:16:05 -0700 | [diff] [blame] | 759 | # BuildImage(). |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 760 | image_properties = glob_dict |
Ying Wang | 9f8e8db | 2011-11-04 11:37:01 -0700 | [diff] [blame] | 761 | else: |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 762 | image_filename = os.path.basename(out_file) |
| 763 | mount_point = "" |
| 764 | if image_filename == "system.img": |
| 765 | mount_point = "system" |
Alex Light | 4e358ab | 2016-06-16 14:47:10 -0700 | [diff] [blame] | 766 | elif image_filename == "system_other.img": |
| 767 | mount_point = "system_other" |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 768 | elif image_filename == "userdata.img": |
| 769 | mount_point = "data" |
| 770 | elif image_filename == "cache.img": |
| 771 | mount_point = "cache" |
| 772 | elif image_filename == "vendor.img": |
| 773 | mount_point = "vendor" |
Bowgo Tsai | d624fa6 | 2017-11-14 23:42:30 +0800 | [diff] [blame] | 774 | elif image_filename == "odm.img": |
| 775 | mount_point = "odm" |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 776 | elif image_filename == "oem.img": |
| 777 | mount_point = "oem" |
Jaekyun Seok | b7735d8 | 2017-11-27 17:04:47 +0900 | [diff] [blame] | 778 | elif image_filename == "product.img": |
| 779 | mount_point = "product" |
Dario Freni | 924af7d | 2018-08-17 00:56:14 +0100 | [diff] [blame] | 780 | elif image_filename == "product_services.img": |
| 781 | mount_point = "product_services" |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 782 | else: |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 783 | logger.error("Unknown image file name %s", image_filename) |
Tao Bao | 1c830bf | 2017-12-25 10:43:47 -0800 | [diff] [blame] | 784 | sys.exit(1) |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 785 | |
Ying Wang | ae61f50 | 2015-03-12 18:30:39 -0700 | [diff] [blame] | 786 | image_properties = ImagePropFromGlobalDict(glob_dict, mount_point) |
| 787 | |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 788 | try: |
| 789 | BuildImage(in_dir, image_properties, out_file, target_out) |
| 790 | except: |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 791 | logger.error("Failed to build %s from %s", out_file, in_dir) |
Tao Bao | c6bd70a | 2018-09-27 16:58:00 -0700 | [diff] [blame] | 792 | raise |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 793 | |
Tao Bao | 32fcdab | 2018-10-12 10:30:39 -0700 | [diff] [blame] | 794 | |
Ying Wang | bd93d42 | 2011-10-28 17:02:30 -0700 | [diff] [blame] | 795 | if __name__ == '__main__': |
Tao Bao | 1c830bf | 2017-12-25 10:43:47 -0800 | [diff] [blame] | 796 | try: |
| 797 | main(sys.argv[1:]) |
| 798 | finally: |
| 799 | common.Cleanup() |