aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMark Salyzyn2018-11-08 13:26:50 -0600
committerMark Salyzyn2018-11-08 13:26:50 -0600
commit533558ec9613aed95f4b2fa3b53d3b4b5d381f19 (patch)
treea13495786da378a509efbd3b8f340d720e5b72bb /tools
parent2b72b7f01e446c2f270f24b840f484bd7c339165 (diff)
downloadplatform-build-533558ec9613aed95f4b2fa3b53d3b4b5d381f19.tar.gz
platform-build-533558ec9613aed95f4b2fa3b53d3b4b5d381f19.tar.xz
platform-build-533558ec9613aed95f4b2fa3b53d3b4b5d381f19.zip
Revert "build: Split out mkfs in BuildImageMkfs"
This reverts commit 2b72b7f01e446c2f270f24b840f484bd7c339165. out/target/product/generic_x86/installed-files.txt \${DIST_DIR}/installed-files-rescued.txt; exit 1 ) )" 2018-11-08 19:12:28 - build_image.py - ERROR : Failed to build out/target/product/generic_x86/obj/PACKAGING/systemimage_intermediates/system.img from out/target/product/generic_x86/system Traceback (most recent call last): File "build/make/tools/releasetools/build_image.py", line 767, in <module> main(sys.argv[1:]) File "build/make/tools/releasetools/build_image.py", line 755, in main BuildImage(in_dir, image_properties, out_file, target_out) File "build/make/tools/releasetools/build_image.py", line 449, in BuildImage CheckHeadroom(mkfs_output, prop_dict) NameError: global name 'mkfs_output' is not defined Bug: 111302946 Reason for revert: Build problem Change-Id: I786f232e07af653a7207509055df5a07a6d8bb9e
Diffstat (limited to 'tools')
-rwxr-xr-xtools/releasetools/build_image.py182
1 files changed, 81 insertions, 101 deletions
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index c5f28014c..7611a4d43 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -221,8 +221,8 @@ def CheckHeadroom(ext4fs_output, prop_dict):
221 adjusted_blocks)) 221 adjusted_blocks))
222 222
223 223
224def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config): 224def BuildImage(in_dir, prop_dict, out_file, target_out=None):
225 """Builds a pure image for the files under in_dir and writes it to out_file. 225 """Builds an image for the files under in_dir and writes it to out_file.
226 226
227 Args: 227 Args:
228 in_dir: Path to input directory. 228 in_dir: Path to input directory.
@@ -233,15 +233,81 @@ def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config):
233 points to the /system directory under PRODUCT_OUT. fs_config (the one 233 points to the /system directory under PRODUCT_OUT. fs_config (the one
234 under system/core/libcutils) reads device specific FS config files from 234 under system/core/libcutils) reads device specific FS config files from
235 there. 235 there.
236 fs_config: The fs_config file that drives the prototype
237 236
238 Raises: 237 Raises:
239 BuildImageError: On build image failures. 238 BuildImageError: On build image failures.
240 """ 239 """
240 original_mount_point = prop_dict["mount_point"]
241 in_dir, fs_config = SetUpInDirAndFsConfig(in_dir, prop_dict)
242
241 build_command = [] 243 build_command = []
242 fs_type = prop_dict.get("fs_type", "") 244 fs_type = prop_dict.get("fs_type", "")
243 run_e2fsck = False 245 run_e2fsck = False
244 246
247 fs_spans_partition = True
248 if fs_type.startswith("squash"):
249 fs_spans_partition = False
250
251 # Get a builder for creating an image that's to be verified by Verified Boot,
252 # or None if not applicable.
253 verity_image_builder = verity_utils.CreateVerityImageBuilder(prop_dict)
254
255 if (prop_dict.get("use_dynamic_partition_size") == "true" and
256 "partition_size" not in prop_dict):
257 # If partition_size is not defined, use output of `du' + reserved_size.
258 size = GetDiskUsage(in_dir)
259 logger.info(
260 "The tree size of %s is %d MB.", in_dir, size // BYTES_IN_MB)
261 # If not specified, give us 16MB margin for GetDiskUsage error ...
262 size += int(prop_dict.get("partition_reserved_size", BYTES_IN_MB * 16))
263 # Round this up to a multiple of 4K so that avbtool works
264 size = common.RoundUpTo4K(size)
265 if fs_type.startswith("ext"):
266 if verity_image_builder:
267 size = verity_image_builder.CalculateDynamicPartitionSize(size)
268 prop_dict["partition_size"] = str(size)
269 if "extfs_inode_count" not in prop_dict:
270 prop_dict["extfs_inode_count"] = str(GetInodeUsage(in_dir))
271 logger.info(
272 "First Pass based on estimates of %d MB and %s inodes.",
273 size // BYTES_IN_MB, prop_dict["extfs_inode_count"])
274 prop_dict["mount_point"] = original_mount_point
275 BuildImage(in_dir, prop_dict, out_file, target_out)
276 fs_dict = GetFilesystemCharacteristics(out_file)
277 os.remove(out_file)
278 block_size = int(fs_dict.get("Block size", "4096"))
279 free_size = int(fs_dict.get("Free blocks", "0")) * block_size
280 reserved_size = int(prop_dict.get("partition_reserved_size", 0))
281 if free_size <= reserved_size:
282 logger.info(
283 "Not worth reducing image %d <= %d.", free_size, reserved_size)
284 else:
285 size -= free_size
286 size += reserved_size
287 if block_size <= 4096:
288 size = common.RoundUpTo4K(size)
289 else:
290 size = ((size + block_size - 1) // block_size) * block_size
291 extfs_inode_count = prop_dict["extfs_inode_count"]
292 inodes = int(fs_dict.get("Inode count", extfs_inode_count))
293 inodes -= int(fs_dict.get("Free inodes", "0"))
294 prop_dict["extfs_inode_count"] = str(inodes)
295 prop_dict["partition_size"] = str(size)
296 logger.info(
297 "Allocating %d Inodes for %s.", inodes, out_file)
298 if verity_image_builder:
299 size = verity_image_builder.CalculateDynamicPartitionSize(size)
300 prop_dict["partition_size"] = str(size)
301 logger.info(
302 "Allocating %d MB for %s.", size // BYTES_IN_MB, out_file)
303
304 prop_dict["image_size"] = prop_dict["partition_size"]
305
306 # Adjust the image size to make room for the hashes if this is to be verified.
307 if verity_image_builder:
308 max_image_size = verity_image_builder.CalculateMaxImageSize()
309 prop_dict["image_size"] = str(max_image_size)
310
245 if fs_type.startswith("ext"): 311 if fs_type.startswith("ext"):
246 build_command = [prop_dict["ext_mkuserimg"]] 312 build_command = [prop_dict["ext_mkuserimg"]]
247 if "extfs_sparse_flag" in prop_dict: 313 if "extfs_sparse_flag" in prop_dict:
@@ -334,8 +400,8 @@ def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config):
334 logger.exception("Failed to compute disk usage with du") 400 logger.exception("Failed to compute disk usage with du")
335 du_str = "unknown" 401 du_str = "unknown"
336 print( 402 print(
337 "Out of space? Out of inodes? The tree size of {} is {}, " 403 "Out of space? The tree size of {} is {}, with reserved space of {} "
338 "with reserved space of {} bytes ({} MB).".format( 404 "bytes ({} MB).".format(
339 in_dir, du_str, 405 in_dir, du_str,
340 int(prop_dict.get("partition_reserved_size", 0)), 406 int(prop_dict.get("partition_reserved_size", 0)),
341 int(prop_dict.get("partition_reserved_size", 0)) // BYTES_IN_MB)) 407 int(prop_dict.get("partition_reserved_size", 0)) // BYTES_IN_MB))
@@ -348,102 +414,6 @@ def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config):
348 int(prop_dict["partition_size"]) // BYTES_IN_MB)) 414 int(prop_dict["partition_size"]) // BYTES_IN_MB))
349 raise 415 raise
350 416
351 if run_e2fsck and prop_dict.get("skip_fsck") != "true":
352 unsparse_image = UnsparseImage(out_file, replace=False)
353
354 # Run e2fsck on the inflated image file
355 e2fsck_command = ["e2fsck", "-f", "-n", unsparse_image]
356 try:
357 common.RunAndCheckOutput(e2fsck_command)
358 finally:
359 os.remove(unsparse_image)
360
361
362def BuildImage(in_dir, prop_dict, out_file, target_out=None):
363 """Builds an image for the files under in_dir and writes it to out_file.
364
365 Args:
366 in_dir: Path to input directory.
367 prop_dict: A property dict that contains info like partition size. Values
368 will be updated with computed values.
369 out_file: The output image file.
370 target_out: Path to the TARGET_OUT directory as in Makefile. It actually
371 points to the /system directory under PRODUCT_OUT. fs_config (the one
372 under system/core/libcutils) reads device specific FS config files from
373 there.
374
375 Raises:
376 BuildImageError: On build image failures.
377 """
378 in_dir, fs_config = SetUpInDirAndFsConfig(in_dir, prop_dict)
379
380 build_command = []
381 fs_type = prop_dict.get("fs_type", "")
382
383 fs_spans_partition = True
384 if fs_type.startswith("squash"):
385 fs_spans_partition = False
386
387 # Get a builder for creating an image that's to be verified by Verified Boot,
388 # or None if not applicable.
389 verity_image_builder = verity_utils.CreateVerityImageBuilder(prop_dict)
390
391 if (prop_dict.get("use_dynamic_partition_size") == "true" and
392 "partition_size" not in prop_dict):
393 # If partition_size is not defined, use output of `du' + reserved_size.
394 size = GetDiskUsage(in_dir)
395 logger.info(
396 "The tree size of %s is %d MB.", in_dir, size // BYTES_IN_MB)
397 # If not specified, give us 16MB margin for GetDiskUsage error ...
398 size += int(prop_dict.get("partition_reserved_size", BYTES_IN_MB * 16))
399 # Round this up to a multiple of 4K so that avbtool works
400 size = common.RoundUpTo4K(size)
401 if fs_type.startswith("ext"):
402 prop_dict["partition_size"] = str(size)
403 prop_dict["image_size"] = str(size)
404 if "extfs_inode_count" not in prop_dict:
405 prop_dict["extfs_inode_count"] = str(GetInodeUsage(in_dir))
406 logger.info(
407 "First Pass based on estimates of %d MB and %s inodes.",
408 size // BYTES_IN_MB, prop_dict["extfs_inode_count"])
409 BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config)
410 fs_dict = GetFilesystemCharacteristics(out_file)
411 os.remove(out_file)
412 block_size = int(fs_dict.get("Block size", "4096"))
413 free_size = int(fs_dict.get("Free blocks", "0")) * block_size
414 reserved_size = int(prop_dict.get("partition_reserved_size", 0))
415 if free_size <= reserved_size:
416 logger.info(
417 "Not worth reducing image %d <= %d.", free_size, reserved_size)
418 else:
419 size -= free_size
420 size += reserved_size
421 if block_size <= 4096:
422 size = common.RoundUpTo4K(size)
423 else:
424 size = ((size + block_size - 1) // block_size) * block_size
425 extfs_inode_count = prop_dict["extfs_inode_count"]
426 inodes = int(fs_dict.get("Inode count", extfs_inode_count))
427 inodes -= int(fs_dict.get("Free inodes", "0"))
428 prop_dict["extfs_inode_count"] = str(inodes)
429 prop_dict["partition_size"] = str(size)
430 logger.info(
431 "Allocating %d Inodes for %s.", inodes, out_file)
432 if verity_image_builder:
433 size = verity_image_builder.CalculateDynamicPartitionSize(size)
434 prop_dict["partition_size"] = str(size)
435 logger.info(
436 "Allocating %d MB for %s.", size // BYTES_IN_MB, out_file)
437
438 prop_dict["image_size"] = prop_dict["partition_size"]
439
440 # Adjust the image size to make room for the hashes if this is to be verified.
441 if verity_image_builder:
442 max_image_size = verity_image_builder.CalculateMaxImageSize()
443 prop_dict["image_size"] = str(max_image_size)
444
445 BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config)
446
447 # Check if there's enough headroom space available for ext4 image. 417 # Check if there's enough headroom space available for ext4 image.
448 if "partition_headroom" in prop_dict and fs_type.startswith("ext4"): 418 if "partition_headroom" in prop_dict and fs_type.startswith("ext4"):
449 CheckHeadroom(mkfs_output, prop_dict) 419 CheckHeadroom(mkfs_output, prop_dict)
@@ -455,6 +425,16 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
455 if verity_image_builder: 425 if verity_image_builder:
456 verity_image_builder.Build(out_file) 426 verity_image_builder.Build(out_file)
457 427
428 if run_e2fsck and prop_dict.get("skip_fsck") != "true":
429 unsparse_image = UnsparseImage(out_file, replace=False)
430
431 # Run e2fsck on the inflated image file
432 e2fsck_command = ["e2fsck", "-f", "-n", unsparse_image]
433 try:
434 common.RunAndCheckOutput(e2fsck_command)
435 finally:
436 os.remove(unsparse_image)
437
458 438
459def ImagePropFromGlobalDict(glob_dict, mount_point): 439def ImagePropFromGlobalDict(glob_dict, mount_point):
460 """Build an image property dictionary from the global dictionary. 440 """Build an image property dictionary from the global dictionary.