OSDN Git Service

store user-visible image sizes in target-files
authorDoug Zongker <dougz@android.com>
Thu, 16 Sep 2010 18:28:43 +0000 (11:28 -0700)
committerDoug Zongker <dougz@android.com>
Thu, 16 Sep 2010 19:29:17 +0000 (12:29 -0700)
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

core/Makefile
tools/releasetools/common.py
tools/releasetools/img_from_target_files
tools/releasetools/ota_from_target_files

index 8d1399a..2f20817 100644 (file)
@@ -1011,8 +1011,8 @@ endif
 ifdef BOARD_USERDATAIMAGE_PARTITION_SIZE
        $(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
 endif
-ifeq ($(TARGET_USERIMAGES_USE_EXT4), true)
-       $(hide) echo "fs_type=ext4" >> $(zip_root)/META/misc_info.txt
+ifneq (,$(INTERNAL_USERIMAGES_EXT_VARIANT))
+       $(hide) echo "fs_type=$(INTERNAL_USERIMAGES_EXT_VARIANT)" >> $(zip_root)/META/misc_info.txt
        $(hide) echo "partition_type=EMMC" >> $(zip_root)/META/misc_info.txt
        @# TODO: where is the right place to get this path from?  BoardConfig.mk?
        $(hide) echo "partition_path=/dev/block/platform/sdhci-tegra.3/by-name/" >> $(zip_root)/META/misc_info.txt
@@ -1213,7 +1213,6 @@ $(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(OTATOOLS)
        $(hide) ./build/tools/releasetools/img_from_target_files -v \
           -s $(extensions) \
           -p $(HOST_OUT) \
-          $(addprefix --fs_type ,$(INTERNAL_USERIMAGES_EXT_VARIANT)) \
           $(BUILT_TARGET_FILES_PACKAGE) $@
 
 .PHONY: updatepackage
index 2a81133..8b163c0 100644 (file)
@@ -41,6 +41,7 @@ OPTIONS.tempfiles = []
 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 LoadInfoDict():
 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 @@ def LoadMaxSizes(info):
   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 @@ def CheckSize(data, target):
   """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)
index 46ac754..a74ef89 100755 (executable)
@@ -23,11 +23,6 @@ Usage:  img_from_target_files [flags] input_target_files output_image_zip
   -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 @@ import common
 
 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 @@ def AddUserdata(output_zip):
   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 @@ def AddUserdata(output_zip):
   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 @@ def AddSystem(output_zip):
       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 @@ def AddSystem(output_zip):
   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 main(argv):
   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 @@ def main(argv):
 
   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"
index 02f2508..89caa5c 100755 (executable)
@@ -334,11 +334,11 @@ fi
   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 @@ def GetRecoveryAPIVersion(zip):
       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 @@ def main(argv):
       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 @@ def main(argv):
                                  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: