store user-visible image sizes in target-files
Do the yaffs-specific adjustments to image sizes in common.CheckSize,
instead of baking it into the image size stored in the target-files
package. Remove the special fs_type flag and fold it into the
"info_dict" we have for saving key-value pairs from the build system.
Change-Id: I6e63f3330f6277d9a946b22e66cadeb51203ba14
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 2a81133..8b163c0 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -41,6 +41,7 @@
OPTIONS.device_specific = None
OPTIONS.extras = {}
OPTIONS.mkyaffs2_extra_flags = None
+OPTIONS.info_dict = None
# Values for "certificate" in apkcerts that mean special things.
@@ -85,7 +86,7 @@
def LoadMaxSizes(info):
"""Load the maximum allowable images sizes from the input
target_files. Uses the imagesizes.txt file if it's available
- (pre-honeycomb target_files), or the more general info dict (which
+ (pre-gingerbread target_files), or the more general info dict (which
must be passed in) if not."""
OPTIONS.max_image_size = {}
try:
@@ -98,7 +99,7 @@
except IOError, e:
if e.errno == errno.ENOENT:
def copy(x, y):
- if x in info: OPTIONS.max_image_size[x+".img"] = int(info[x+y])
+ if x+y in info: OPTIONS.max_image_size[x+".img"] = int(info[x+y])
copy("blocksize", "")
copy("boot", "_size")
copy("recovery", "_size")
@@ -297,9 +298,18 @@
"""Check the data string passed against the max size limit, if
any, for the given target. Raise exception if the data is too big.
Print a warning if the data is nearing the maximum size."""
+
+ fs_type = OPTIONS.info_dict.get("fs_type", None)
+ if not fs_type: return
+
limit = OPTIONS.max_image_size.get(target, None)
if limit is None: return
+ if fs_type == "yaffs2":
+ # image size should be increased by 1/64th to account for the
+ # spare area (64 bytes per 2k page)
+ limit = limit / 2048 * (2048+64)
+
size = len(data)
pct = float(size) * 100.0 / limit
msg = "%s size (%d) is %.2f%% of limit (%d)" % (target, size, pct, limit)
diff --git a/tools/releasetools/img_from_target_files b/tools/releasetools/img_from_target_files
index 46ac754..a74ef89 100755
--- a/tools/releasetools/img_from_target_files
+++ b/tools/releasetools/img_from_target_files
@@ -23,11 +23,6 @@
-b (--board_config) <file>
Deprecated.
- -f (--fs_type) <value>
- The file system type of the user image files to be created.
- It can be ext fs variants, such as ext2, ext3, ext4, etc.
- efault is yaffs.
-
"""
import sys
@@ -52,10 +47,6 @@
OPTIONS = common.OPTIONS
-class UserImageOptions(object): pass
-USERIMAGE_OPTIONS = UserImageOptions()
-USERIMAGE_OPTIONS.fs_type = None
-
def AddUserdata(output_zip):
"""Create an empty userdata image and store it in output_zip."""
@@ -70,9 +61,9 @@
img = tempfile.NamedTemporaryFile()
build_command = []
- if USERIMAGE_OPTIONS.fs_type is not None and USERIMAGE_OPTIONS.fs_type.startswith("ext"):
+ if OPTIONS.info_dict.get("fs_type", "").startswith("ext"):
build_command = ["mkuserimg.sh",
- user_dir, img.name, USERIMAGE_OPTIONS.fs_type, "userdata"]
+ user_dir, img.name, OPTIONS.info_dict["fs_type"], "userdata"]
if "userdata.img" in OPTIONS.max_image_size:
build_command.append(str(OPTIONS.max_image_size["userdata.img"]))
else:
@@ -86,8 +77,7 @@
p.communicate()
assert p.returncode == 0, "build userdata.img image failed"
- if USERIMAGE_OPTIONS.fs_type is None or not USERIMAGE_OPTIONS.fs_type.startswith("ext"):
- common.CheckSize(img.name, "userdata.img")
+ common.CheckSize(img.name, "userdata.img")
output_zip.write(img.name, "userdata.img")
img.close()
os.rmdir(user_dir)
@@ -117,10 +107,10 @@
pass
build_command = []
- if USERIMAGE_OPTIONS.fs_type is not None and USERIMAGE_OPTIONS.fs_type.startswith("ext"):
+ if OPTIONS.info_dict.get("fs_type", "").startswith("ext"):
build_command = ["mkuserimg.sh",
os.path.join(OPTIONS.input_tmp, "system"), img.name,
- USERIMAGE_OPTIONS.fs_type, "system"]
+ OPTIONS.info_dict["fs_type"], "system"]
if "system.img" in OPTIONS.max_image_size:
build_command.append(str(OPTIONS.max_image_size["system.img"]))
else:
@@ -138,8 +128,7 @@
data = img.read()
img.close()
- if USERIMAGE_OPTIONS.fs_type is None or not USERIMAGE_OPTIONS.fs_type.startswith("ext"):
- common.CheckSize(data, "system.img")
+ common.CheckSize(data, "system.img")
common.ZipWriteStr(output_zip, "system.img", data)
@@ -154,15 +143,13 @@
def option_handler(o, a):
if o in ("-b", "--board_config"):
pass # deprecated
- elif o in ("-f", "--fs_type"):
- USERIMAGE_OPTIONS.fs_type = a
else:
return False
return True
args = common.ParseOptions(argv, __doc__,
- extra_opts="b:f:",
- extra_long_opts=["board_config=", "fs_type="],
+ extra_opts="b:",
+ extra_long_opts=["board_config="],
extra_option_handler=option_handler)
if len(args) != 2:
@@ -171,8 +158,8 @@
OPTIONS.input_tmp = common.UnzipTemp(args[0])
- info = common.LoadInfoDict()
- common.LoadMaxSizes(info)
+ OPTIONS.info_dict = common.LoadInfoDict()
+ common.LoadMaxSizes(OPTIONS.info_dict)
if not OPTIONS.max_image_size:
print
print " WARNING: Failed to load max image sizes; will not enforce"
diff --git a/tools/releasetools/ota_from_target_files b/tools/releasetools/ota_from_target_files
index 02f2508..89caa5c 100755
--- a/tools/releasetools/ota_from_target_files
+++ b/tools/releasetools/ota_from_target_files
@@ -334,11 +334,11 @@
return Item.Get("system/etc/install-recovery.sh", dir=False)
-def WriteFullOTAPackage(input_zip, output_zip, info):
+def WriteFullOTAPackage(input_zip, output_zip):
# TODO: how to determine this? We don't know what version it will
# be installed on top of. For now, we expect the API just won't
# change very often.
- script = edify_generator.EdifyGenerator(3, info)
+ script = edify_generator.EdifyGenerator(3, OPTIONS.info_dict)
metadata = {"post-build": GetBuildProp("ro.build.fingerprint", input_zip),
"pre-device": GetBuildProp("ro.product.device", input_zip),
@@ -448,14 +448,14 @@
return 0
-def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip, info):
+def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):
source_version = GetRecoveryAPIVersion(source_zip)
target_version = GetRecoveryAPIVersion(target_zip)
if source_version == 0:
print ("WARNING: generating edify script for a source that "
"can't install it.")
- script = edify_generator.EdifyGenerator(source_version, info)
+ script = edify_generator.EdifyGenerator(source_version, OPTIONS.info_dict)
metadata = {"pre-device": GetBuildProp("ro.product.device", source_zip),
"post-timestamp": GetBuildProp("ro.build.date.utc", target_zip),
@@ -755,8 +755,8 @@
else:
raise
- info = common.LoadInfoDict()
- common.LoadMaxSizes(info)
+ OPTIONS.info_dict = common.LoadInfoDict()
+ common.LoadMaxSizes(OPTIONS.info_dict)
if not OPTIONS.max_image_size:
print
print " WARNING: Failed to load max image sizes; will not enforce"
@@ -774,12 +774,12 @@
compression=zipfile.ZIP_DEFLATED)
if OPTIONS.incremental_source is None:
- WriteFullOTAPackage(input_zip, output_zip, info)
+ WriteFullOTAPackage(input_zip, output_zip)
else:
print "unzipping source target-files..."
OPTIONS.source_tmp = common.UnzipTemp(OPTIONS.incremental_source)
source_zip = zipfile.ZipFile(OPTIONS.incremental_source, "r")
- WriteIncrementalOTAPackage(input_zip, source_zip, output_zip, info)
+ WriteIncrementalOTAPackage(input_zip, source_zip, output_zip)
output_zip.close()
if OPTIONS.package_key: