Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (C) 2014 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 | """ |
| 18 | Given a target-files zipfile that does not contain images (ie, does |
| 19 | not have an IMAGES/ top-level subdirectory), produce the images and |
| 20 | add them to the zipfile. |
| 21 | |
| 22 | Usage: add_img_to_target_files target_files |
| 23 | """ |
| 24 | |
| 25 | import sys |
| 26 | |
| 27 | if sys.hexversion < 0x02070000: |
| 28 | print >> sys.stderr, "Python 2.7 or newer is required." |
| 29 | sys.exit(1) |
| 30 | |
Tao Bao | 822f584 | 2015-09-30 16:01:14 -0700 | [diff] [blame] | 31 | import datetime |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 32 | import errno |
| 33 | import os |
Ying Wang | 2a04839 | 2015-06-25 13:56:53 -0700 | [diff] [blame] | 34 | import shutil |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 35 | import tempfile |
| 36 | import zipfile |
| 37 | |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 38 | import build_image |
| 39 | import common |
| 40 | |
| 41 | OPTIONS = common.OPTIONS |
| 42 | |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 43 | OPTIONS.add_missing = False |
| 44 | OPTIONS.rebuild_recovery = False |
Baligh Uddin | 59f4ff1 | 2015-09-16 21:20:30 -0700 | [diff] [blame] | 45 | OPTIONS.replace_verity_public_key = False |
| 46 | OPTIONS.replace_verity_private_key = False |
| 47 | OPTIONS.verity_signer_path = None |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 48 | |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 49 | def AddSystem(output_zip, prefix="IMAGES/", recovery_img=None, boot_img=None): |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 50 | """Turn the contents of SYSTEM into a system image and store it in |
| 51 | output_zip.""" |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 52 | |
| 53 | prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "system.img") |
| 54 | if os.path.exists(prebuilt_path): |
| 55 | print "system.img already exists in %s, no need to rebuild..." % (prefix,) |
| 56 | return |
| 57 | |
| 58 | def output_sink(fn, data): |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 59 | ofile = open(os.path.join(OPTIONS.input_tmp, "SYSTEM", fn), "w") |
| 60 | ofile.write(data) |
| 61 | ofile.close() |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 62 | |
| 63 | if OPTIONS.rebuild_recovery: |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 64 | print "Building new recovery patch" |
| 65 | common.MakeRecoveryPatch(OPTIONS.input_tmp, output_sink, recovery_img, |
| 66 | boot_img, info_dict=OPTIONS.info_dict) |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 67 | |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 68 | block_list = common.MakeTempFile(prefix="system-blocklist-", suffix=".map") |
| 69 | imgname = BuildSystem(OPTIONS.input_tmp, OPTIONS.info_dict, |
| 70 | block_list=block_list) |
Dan Albert | 8e0178d | 2015-01-27 15:53:15 -0800 | [diff] [blame] | 71 | common.ZipWrite(output_zip, imgname, prefix + "system.img") |
| 72 | common.ZipWrite(output_zip, block_list, prefix + "system.map") |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 73 | |
| 74 | |
| 75 | def BuildSystem(input_dir, info_dict, block_list=None): |
| 76 | """Build the (sparse) system image and return the name of a temp |
| 77 | file containing it.""" |
| 78 | return CreateImage(input_dir, info_dict, "system", block_list=block_list) |
| 79 | |
| 80 | |
| 81 | def AddVendor(output_zip, prefix="IMAGES/"): |
| 82 | """Turn the contents of VENDOR into a vendor image and store in it |
| 83 | output_zip.""" |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 84 | |
| 85 | prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "vendor.img") |
| 86 | if os.path.exists(prebuilt_path): |
| 87 | print "vendor.img already exists in %s, no need to rebuild..." % (prefix,) |
| 88 | return |
| 89 | |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 90 | block_list = common.MakeTempFile(prefix="vendor-blocklist-", suffix=".map") |
| 91 | imgname = BuildVendor(OPTIONS.input_tmp, OPTIONS.info_dict, |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 92 | block_list=block_list) |
Dan Albert | 8e0178d | 2015-01-27 15:53:15 -0800 | [diff] [blame] | 93 | common.ZipWrite(output_zip, imgname, prefix + "vendor.img") |
| 94 | common.ZipWrite(output_zip, block_list, prefix + "vendor.map") |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 95 | |
| 96 | |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 97 | def BuildVendor(input_dir, info_dict, block_list=None): |
| 98 | """Build the (sparse) vendor image and return the name of a temp |
| 99 | file containing it.""" |
| 100 | return CreateImage(input_dir, info_dict, "vendor", block_list=block_list) |
| 101 | |
| 102 | |
| 103 | def CreateImage(input_dir, info_dict, what, block_list=None): |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 104 | print "creating " + what + ".img..." |
| 105 | |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 106 | img = common.MakeTempFile(prefix=what + "-", suffix=".img") |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 107 | |
| 108 | # The name of the directory it is making an image out of matters to |
| 109 | # mkyaffs2image. It wants "system" but we have a directory named |
| 110 | # "SYSTEM", so create a symlink. |
| 111 | try: |
| 112 | os.symlink(os.path.join(input_dir, what.upper()), |
| 113 | os.path.join(input_dir, what)) |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 114 | except OSError as e: |
| 115 | # bogus error on my mac version? |
| 116 | # File "./build/tools/releasetools/img_from_target_files" |
| 117 | # os.path.join(OPTIONS.input_tmp, "system")) |
| 118 | # OSError: [Errno 17] File exists |
| 119 | if e.errno == errno.EEXIST: |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 120 | pass |
| 121 | |
| 122 | image_props = build_image.ImagePropFromGlobalDict(info_dict, what) |
| 123 | fstab = info_dict["fstab"] |
| 124 | if fstab: |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 125 | image_props["fs_type"] = fstab["/" + what].fs_type |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 126 | |
Tao Bao | 822f584 | 2015-09-30 16:01:14 -0700 | [diff] [blame] | 127 | # Use a fixed timestamp (01/01/2009) when packaging the image. |
| 128 | # Bug: 24377993 |
| 129 | epoch = datetime.datetime.fromtimestamp(0) |
| 130 | timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds() |
| 131 | image_props["timestamp"] = int(timestamp) |
| 132 | |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 133 | if what == "system": |
| 134 | fs_config_prefix = "" |
| 135 | else: |
| 136 | fs_config_prefix = what + "_" |
| 137 | |
| 138 | fs_config = os.path.join( |
| 139 | input_dir, "META/" + fs_config_prefix + "filesystem_config.txt") |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 140 | if not os.path.exists(fs_config): |
| 141 | fs_config = None |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 142 | |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 143 | # Override values loaded from info_dict. |
| 144 | if fs_config: |
| 145 | image_props["fs_config"] = fs_config |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 146 | if block_list: |
| 147 | image_props["block_list"] = block_list |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 148 | |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 149 | succ = build_image.BuildImage(os.path.join(input_dir, what), |
Ying Wang | a2292c9 | 2015-03-24 19:07:40 -0700 | [diff] [blame] | 150 | image_props, img) |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 151 | assert succ, "build " + what + ".img image failed" |
| 152 | |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 153 | return img |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 154 | |
| 155 | |
| 156 | def AddUserdata(output_zip, prefix="IMAGES/"): |
Ying Wang | 2a04839 | 2015-06-25 13:56:53 -0700 | [diff] [blame] | 157 | """Create a userdata image and store it in output_zip. |
| 158 | |
| 159 | In most case we just create and store an empty userdata.img; |
| 160 | But the invoker can also request to create userdata.img with real |
| 161 | data from the target files, by setting "userdata_img_with_data=true" |
| 162 | in OPTIONS.info_dict. |
| 163 | """ |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 164 | |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 165 | prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "userdata.img") |
| 166 | if os.path.exists(prebuilt_path): |
| 167 | print "userdata.img already exists in %s, no need to rebuild..." % (prefix,) |
| 168 | return |
| 169 | |
Tao Bao | 2c15d9e | 2015-07-09 11:51:16 -0700 | [diff] [blame] | 170 | image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict, "data") |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 171 | # We only allow yaffs to have a 0/missing partition_size. |
| 172 | # Extfs, f2fs must have a size. Skip userdata.img if no size. |
| 173 | if (not image_props.get("fs_type", "").startswith("yaffs") and |
| 174 | not image_props.get("partition_size")): |
| 175 | return |
| 176 | |
| 177 | print "creating userdata.img..." |
| 178 | |
Tao Bao | 822f584 | 2015-09-30 16:01:14 -0700 | [diff] [blame] | 179 | # Use a fixed timestamp (01/01/2009) when packaging the image. |
| 180 | # Bug: 24377993 |
| 181 | epoch = datetime.datetime.fromtimestamp(0) |
| 182 | timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds() |
| 183 | image_props["timestamp"] = int(timestamp) |
| 184 | |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 185 | # The name of the directory it is making an image out of matters to |
| 186 | # mkyaffs2image. So we create a temp dir, and within it we create an |
Ying Wang | 2a04839 | 2015-06-25 13:56:53 -0700 | [diff] [blame] | 187 | # empty dir named "data", or a symlink to the DATA dir, |
| 188 | # and build the image from that. |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 189 | temp_dir = tempfile.mkdtemp() |
| 190 | user_dir = os.path.join(temp_dir, "data") |
Ying Wang | 2a04839 | 2015-06-25 13:56:53 -0700 | [diff] [blame] | 191 | empty = (OPTIONS.info_dict.get("userdata_img_with_data") != "true") |
| 192 | if empty: |
| 193 | # Create an empty dir. |
| 194 | os.mkdir(user_dir) |
| 195 | else: |
| 196 | # Symlink to the DATA dir. |
| 197 | os.symlink(os.path.join(OPTIONS.input_tmp, "DATA"), |
| 198 | user_dir) |
| 199 | |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 200 | img = tempfile.NamedTemporaryFile() |
| 201 | |
| 202 | fstab = OPTIONS.info_dict["fstab"] |
| 203 | if fstab: |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 204 | image_props["fs_type"] = fstab["/data"].fs_type |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 205 | succ = build_image.BuildImage(user_dir, image_props, img.name) |
| 206 | assert succ, "build userdata.img image failed" |
| 207 | |
| 208 | common.CheckSize(img.name, "userdata.img", OPTIONS.info_dict) |
Tao Bao | 2ed665a | 2015-04-01 11:21:55 -0700 | [diff] [blame] | 209 | common.ZipWrite(output_zip, img.name, prefix + "userdata.img") |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 210 | img.close() |
Ying Wang | 2a04839 | 2015-06-25 13:56:53 -0700 | [diff] [blame] | 211 | shutil.rmtree(temp_dir) |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 212 | |
| 213 | |
| 214 | def AddCache(output_zip, prefix="IMAGES/"): |
| 215 | """Create an empty cache image and store it in output_zip.""" |
| 216 | |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 217 | prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "cache.img") |
| 218 | if os.path.exists(prebuilt_path): |
| 219 | print "cache.img already exists in %s, no need to rebuild..." % (prefix,) |
| 220 | return |
| 221 | |
Tao Bao | 2c15d9e | 2015-07-09 11:51:16 -0700 | [diff] [blame] | 222 | image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict, "cache") |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 223 | # The build system has to explicitly request for cache.img. |
| 224 | if "fs_type" not in image_props: |
| 225 | return |
| 226 | |
| 227 | print "creating cache.img..." |
| 228 | |
Tao Bao | 822f584 | 2015-09-30 16:01:14 -0700 | [diff] [blame] | 229 | # Use a fixed timestamp (01/01/2009) when packaging the image. |
| 230 | # Bug: 24377993 |
| 231 | epoch = datetime.datetime.fromtimestamp(0) |
| 232 | timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds() |
| 233 | image_props["timestamp"] = int(timestamp) |
| 234 | |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 235 | # The name of the directory it is making an image out of matters to |
| 236 | # mkyaffs2image. So we create a temp dir, and within it we create an |
| 237 | # empty dir named "cache", and build the image from that. |
| 238 | temp_dir = tempfile.mkdtemp() |
| 239 | user_dir = os.path.join(temp_dir, "cache") |
| 240 | os.mkdir(user_dir) |
| 241 | img = tempfile.NamedTemporaryFile() |
| 242 | |
| 243 | fstab = OPTIONS.info_dict["fstab"] |
| 244 | if fstab: |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 245 | image_props["fs_type"] = fstab["/cache"].fs_type |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 246 | succ = build_image.BuildImage(user_dir, image_props, img.name) |
| 247 | assert succ, "build cache.img image failed" |
| 248 | |
| 249 | common.CheckSize(img.name, "cache.img", OPTIONS.info_dict) |
Tao Bao | 2ed665a | 2015-04-01 11:21:55 -0700 | [diff] [blame] | 250 | common.ZipWrite(output_zip, img.name, prefix + "cache.img") |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 251 | img.close() |
| 252 | os.rmdir(user_dir) |
| 253 | os.rmdir(temp_dir) |
| 254 | |
| 255 | |
| 256 | def AddImagesToTargetFiles(filename): |
| 257 | OPTIONS.input_tmp, input_zip = common.UnzipTemp(filename) |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 258 | |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 259 | if not OPTIONS.add_missing: |
| 260 | for n in input_zip.namelist(): |
| 261 | if n.startswith("IMAGES/"): |
| 262 | print "target_files appears to already contain images." |
| 263 | sys.exit(1) |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 264 | |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 265 | try: |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 266 | input_zip.getinfo("VENDOR/") |
| 267 | has_vendor = True |
| 268 | except KeyError: |
| 269 | has_vendor = False |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 270 | |
Tao Bao | 2c15d9e | 2015-07-09 11:51:16 -0700 | [diff] [blame] | 271 | OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.input_tmp) |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 272 | |
Tao Bao | 2ed665a | 2015-04-01 11:21:55 -0700 | [diff] [blame] | 273 | common.ZipClose(input_zip) |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 274 | output_zip = zipfile.ZipFile(filename, "a", |
| 275 | compression=zipfile.ZIP_DEFLATED) |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 276 | |
Tao Bao | db45efa | 2015-10-27 19:25:18 -0700 | [diff] [blame] | 277 | has_recovery = (OPTIONS.info_dict.get("no_recovery") != "true") |
| 278 | |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 279 | def banner(s): |
| 280 | print "\n\n++++ " + s + " ++++\n\n" |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 281 | |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 282 | banner("boot") |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 283 | prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", "boot.img") |
| 284 | boot_image = None |
| 285 | if os.path.exists(prebuilt_path): |
| 286 | print "boot.img already exists in IMAGES/, no need to rebuild..." |
| 287 | if OPTIONS.rebuild_recovery: |
| 288 | boot_image = common.GetBootableImage( |
| 289 | "IMAGES/boot.img", "boot.img", OPTIONS.input_tmp, "BOOT") |
| 290 | else: |
| 291 | boot_image = common.GetBootableImage( |
| 292 | "IMAGES/boot.img", "boot.img", OPTIONS.input_tmp, "BOOT") |
| 293 | if boot_image: |
| 294 | boot_image.AddToZip(output_zip) |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 295 | |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 296 | recovery_image = None |
Tao Bao | db45efa | 2015-10-27 19:25:18 -0700 | [diff] [blame] | 297 | if has_recovery: |
| 298 | banner("recovery") |
| 299 | prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", "recovery.img") |
| 300 | if os.path.exists(prebuilt_path): |
| 301 | print "recovery.img already exists in IMAGES/, no need to rebuild..." |
| 302 | if OPTIONS.rebuild_recovery: |
| 303 | recovery_image = common.GetBootableImage( |
| 304 | "IMAGES/recovery.img", "recovery.img", OPTIONS.input_tmp, |
| 305 | "RECOVERY") |
| 306 | else: |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 307 | recovery_image = common.GetBootableImage( |
| 308 | "IMAGES/recovery.img", "recovery.img", OPTIONS.input_tmp, "RECOVERY") |
Tao Bao | db45efa | 2015-10-27 19:25:18 -0700 | [diff] [blame] | 309 | if recovery_image: |
| 310 | recovery_image.AddToZip(output_zip) |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 311 | |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 312 | banner("system") |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 313 | AddSystem(output_zip, recovery_img=recovery_image, boot_img=boot_image) |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 314 | if has_vendor: |
| 315 | banner("vendor") |
| 316 | AddVendor(output_zip) |
| 317 | banner("userdata") |
| 318 | AddUserdata(output_zip) |
| 319 | banner("cache") |
| 320 | AddCache(output_zip) |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 321 | |
Tao Bao | a0421cd | 2015-11-16 16:32:27 -0800 | [diff] [blame^] | 322 | # For devices using A/B update, copy over images from RADIO/ to IMAGES/ and |
| 323 | # make sure we have all the needed images ready under IMAGES/. |
| 324 | ab_partitions = os.path.join(OPTIONS.input_tmp, "META", "ab_partitions.txt") |
| 325 | if os.path.exists(ab_partitions): |
| 326 | with open(ab_partitions, 'r') as f: |
| 327 | lines = f.readlines() |
| 328 | for line in lines: |
| 329 | img_name = line.strip() + ".img" |
| 330 | img_radio_path = os.path.join(OPTIONS.input_tmp, "RADIO", img_name) |
| 331 | if os.path.exists(img_radio_path): |
| 332 | common.ZipWrite(output_zip, img_radio_path, |
| 333 | os.path.join("IMAGES", img_name)) |
| 334 | |
| 335 | # Zip spec says: All slashes MUST be forward slashes. |
| 336 | img_path = 'IMAGES/' + img_name |
| 337 | assert img_path in output_zip.namelist(), "cannot find " + img_name |
| 338 | |
Tao Bao | 2ed665a | 2015-04-01 11:21:55 -0700 | [diff] [blame] | 339 | common.ZipClose(output_zip) |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 340 | |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 341 | def main(argv): |
Baligh Uddin | 59f4ff1 | 2015-09-16 21:20:30 -0700 | [diff] [blame] | 342 | def option_handler(o, a): |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 343 | if o in ("-a", "--add_missing"): |
| 344 | OPTIONS.add_missing = True |
| 345 | elif o in ("-r", "--rebuild_recovery",): |
| 346 | OPTIONS.rebuild_recovery = True |
Baligh Uddin | 59f4ff1 | 2015-09-16 21:20:30 -0700 | [diff] [blame] | 347 | elif o == "--replace_verity_private_key": |
| 348 | OPTIONS.replace_verity_private_key = (True, a) |
| 349 | elif o == "--replace_verity_public_key": |
| 350 | OPTIONS.replace_verity_public_key = (True, a) |
| 351 | elif o == "--verity_signer_path": |
| 352 | OPTIONS.verity_signer_path = a |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 353 | else: |
| 354 | return False |
| 355 | return True |
| 356 | |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 357 | args = common.ParseOptions( |
| 358 | argv, __doc__, extra_opts="ar", |
Baligh Uddin | 59f4ff1 | 2015-09-16 21:20:30 -0700 | [diff] [blame] | 359 | extra_long_opts=["add_missing", "rebuild_recovery", |
| 360 | "replace_verity_public_key=", |
| 361 | "replace_verity_private_key=", |
| 362 | "verity_signer_path="], |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 363 | extra_option_handler=option_handler) |
Michael Runge | 2e0d8fc | 2014-11-13 21:41:08 -0800 | [diff] [blame] | 364 | |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 365 | |
| 366 | if len(args) != 1: |
| 367 | common.Usage(__doc__) |
| 368 | sys.exit(1) |
| 369 | |
| 370 | AddImagesToTargetFiles(args[0]) |
| 371 | print "done." |
| 372 | |
| 373 | if __name__ == '__main__': |
| 374 | try: |
| 375 | common.CloseInheritedPipes() |
| 376 | main(sys.argv[1:]) |
Dan Albert | 8b72aef | 2015-03-23 19:13:21 -0700 | [diff] [blame] | 377 | except common.ExternalError as e: |
Doug Zongker | 3c84f56 | 2014-07-31 11:06:30 -0700 | [diff] [blame] | 378 | print |
| 379 | print " ERROR: %s" % (e,) |
| 380 | print |
| 381 | sys.exit(1) |
Doug Zongker | fc44a51 | 2014-08-26 13:10:25 -0700 | [diff] [blame] | 382 | finally: |
| 383 | common.Cleanup() |