forked from openkylin/platform_build
Run e2fsck on built sparse images.
Bug: 7591683 Change-Id: Id1cba79f7840aab1f0327cb741eda655b45d1b46
This commit is contained in:
parent
5c0f9e996a
commit
6a6c11215b
|
@ -556,7 +556,7 @@ ifneq (true,$(TARGET_USERIMAGES_SPARSE_EXT_DISABLED))
|
|||
endif
|
||||
|
||||
ifeq ($(INTERNAL_USERIMAGES_USE_EXT),true)
|
||||
INTERNAL_USERIMAGES_DEPS := $(MKEXTUSERIMG) $(MAKE_EXT4FS)
|
||||
INTERNAL_USERIMAGES_DEPS := $(MKEXTUSERIMG) $(MAKE_EXT4FS) $(SIMG2IMG) $(E2FSCK)
|
||||
else
|
||||
INTERNAL_USERIMAGES_DEPS := $(MKYAFFS2)
|
||||
endif
|
||||
|
|
|
@ -293,6 +293,8 @@ MKEXT2IMG := $(HOST_OUT_EXECUTABLES)/genext2fs$(HOST_EXECUTABLE_SUFFIX)
|
|||
MAKE_EXT4FS := $(HOST_OUT_EXECUTABLES)/make_ext4fs$(HOST_EXECUTABLE_SUFFIX)
|
||||
MKEXTUSERIMG := $(HOST_OUT_EXECUTABLES)/mkuserimg.sh
|
||||
MKEXT2BOOTIMG := external/genext2fs/mkbootimg_ext2.sh
|
||||
SIMG2IMG := $(HOST_OUT_EXECUTABLES)/simg2img$(HOST_EXECUTABLE_SUFFIX)
|
||||
E2FSCK := $(HOST_OUT_EXECUTABLES)/e2fsck$(HOST_EXECUTABLE_SUFFIX)
|
||||
MKTARBALL := build/tools/mktarball.sh
|
||||
TUNE2FS := $(HOST_OUT_EXECUTABLES)/tune2fs$(HOST_EXECUTABLE_SUFFIX)
|
||||
E2FSCK := $(HOST_OUT_EXECUTABLES)/e2fsck$(HOST_EXECUTABLE_SUFFIX)
|
||||
|
|
|
@ -21,9 +21,22 @@ Usage: build_image input_directory properties_file output_image_file
|
|||
|
||||
"""
|
||||
import os
|
||||
import os.path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def RunCommand(cmd):
|
||||
""" Echo and run the given command
|
||||
|
||||
Args:
|
||||
cmd: the command represented as a list of strings.
|
||||
Returns:
|
||||
The exit code.
|
||||
"""
|
||||
print "Running: ", " ".join(cmd)
|
||||
p = subprocess.Popen(cmd)
|
||||
p.communicate()
|
||||
return p.returncode
|
||||
|
||||
def BuildImage(in_dir, prop_dict, out_file):
|
||||
"""Build an image to out_file from in_dir with property prop_dict.
|
||||
|
@ -38,10 +51,12 @@ def BuildImage(in_dir, prop_dict, out_file):
|
|||
"""
|
||||
build_command = []
|
||||
fs_type = prop_dict.get("fs_type", "")
|
||||
run_fsck = False
|
||||
if fs_type.startswith("ext"):
|
||||
build_command = ["mkuserimg.sh"]
|
||||
if "extfs_sparse_flag" in prop_dict:
|
||||
build_command.append(prop_dict["extfs_sparse_flag"])
|
||||
run_fsck = True
|
||||
build_command.extend([in_dir, out_file, fs_type,
|
||||
prop_dict["mount_point"]])
|
||||
if "partition_size" in prop_dict:
|
||||
|
@ -58,10 +73,27 @@ def BuildImage(in_dir, prop_dict, out_file):
|
|||
build_command.append(prop_dict["selinux_fc"])
|
||||
build_command.append(prop_dict["mount_point"])
|
||||
|
||||
print "Running: ", " ".join(build_command)
|
||||
p = subprocess.Popen(build_command);
|
||||
p.communicate()
|
||||
return p.returncode == 0
|
||||
exit_code = RunCommand(build_command)
|
||||
if exit_code != 0:
|
||||
return False
|
||||
|
||||
if run_fsck:
|
||||
# Inflate the sparse image
|
||||
unsparse_image = os.path.join(
|
||||
os.path.dirname(out_file), "unsparse_" + os.path.basename(out_file))
|
||||
inflate_command = ["simg2img", out_file, unsparse_image]
|
||||
exit_code = RunCommand(inflate_command)
|
||||
if exit_code != 0:
|
||||
os.remove(unsparse_image)
|
||||
return False
|
||||
|
||||
# Run e2fsck on the inflated image file
|
||||
e2fsck_command = ["e2fsck", "-f", "-n", unsparse_image]
|
||||
exit_code = RunCommand(e2fsck_command)
|
||||
|
||||
os.remove(unsparse_image)
|
||||
|
||||
return exit_code == 0
|
||||
|
||||
|
||||
def ImagePropFromGlobalDict(glob_dict, mount_point):
|
||||
|
|
Loading…
Reference in New Issue