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