summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/releasetools/common.py56
-rw-r--r--tools/releasetools/edify_generator.py99
-rwxr-xr-xtools/releasetools/img_from_target_files9
-rwxr-xr-xtools/releasetools/ota_from_target_files12
4 files changed, 127 insertions, 49 deletions
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 31e86a1..be8333b 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -72,9 +72,6 @@ def LoadInfoDict(zip):
# ok if misc_info.txt doesn't exist
pass
- if "fs_type" not in d: d["fs_type"] = "yaffs2"
- if "partition_type" not in d: d["partition_type"] = "MTD"
-
# backwards compatibility: These values used to be in their own
# files. Look for them, in case we're processing an old
# target_files zip.
@@ -123,8 +120,45 @@ def LoadInfoDict(zip):
makeint("recovery_size")
makeint("boot_size")
+ d["fstab"] = LoadRecoveryFSTab(zip)
+ if not d["fstab"]:
+ if "fs_type" not in d: d["fs_type"] = "yaffs2"
+ if "partition_type" not in d: d["partition_type"] = "MTD"
+
return d
+def LoadRecoveryFSTab(zip):
+ class Partition(object):
+ pass
+
+ try:
+ data = zip.read("RECOVERY/RAMDISK/etc/recovery.fstab")
+ except KeyError:
+ # older target-files that doesn't have a recovery.fstab; fall back
+ # to the fs_type and partition_type keys.
+ return
+
+ d = {}
+ for line in data.split("\n"):
+ line = line.strip()
+ if not line or line.startswith("#"): continue
+ pieces = line.split()
+ if not (3 <= len(pieces) <= 4):
+ raise ValueError("malformed recovery.fstab line: \"%s\"" % (line,))
+
+ p = Partition()
+ p.mount_point = pieces[0]
+ p.fs_type = pieces[1]
+ p.device = pieces[2]
+ if len(pieces) == 4:
+ p.device2 = pieces[3]
+ else:
+ p.device2 = None
+
+ d[p.mount_point] = p
+ return d
+
+
def DumpInfoDict(d):
for k, v in sorted(d.items()):
print "%-25s = (%s) %s" % (k, type(v).__name__, v)
@@ -308,12 +342,18 @@ def CheckSize(data, target, info_dict):
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 = info_dict.get("fs_type", None)
- if not fs_type: return
-
if target.endswith(".img"): target = target[:-4]
- limit = info_dict.get(target + "_size", None)
- if limit is None: return
+ mount_point = "/" + target
+
+ if info_dict["fstab"]:
+ if mount_point == "/userdata": mount_point = "/data"
+ p = info_dict["fstab"][mount_point]
+ fs_type = p.fs_type
+ limit = info_dict.get(p.device + "_size", None)
+ else:
+ fs_type = info_dict.get("fs_type", None)
+ limit = info_dict.get(target + "_size", None)
+ if not fs_type or not limit: return
if fs_type == "yaffs2":
# image size should be increased by 1/64th to account for the
diff --git a/tools/releasetools/edify_generator.py b/tools/releasetools/edify_generator.py
index 390bd4b..012c06a 100644
--- a/tools/releasetools/edify_generator.py
+++ b/tools/releasetools/edify_generator.py
@@ -21,6 +21,9 @@ class EdifyGenerator(object):
"""Class to generate scripts in the 'edify' recovery script language
used from donut onwards."""
+ # map recovery.fstab's fs_types to mount/format "partition types"
+ PARTITION_TYPES = { "yaffs2": "MTD", "mtd": "MTD", "ext4": "EMMC" }
+
def __init__(self, version, info):
self.script = []
self.mounts = set()
@@ -131,15 +134,22 @@ class EdifyGenerator(object):
available on /cache."""
self.script.append("assert(apply_patch_space(%d));" % (amount,))
- def Mount(self, what, mount_point):
- """Mount the given 'what' at the given path. 'what' should be a
- partition name for an MTD partition, or a block device for
- anything else."""
- what = self.info.get("partition_path", "") + what
- self.script.append('mount("%s", "%s", "%s", "%s");' %
- (self.info["fs_type"], self.info["partition_type"],
- what, mount_point))
- self.mounts.add(mount_point)
+ def Mount(self, mount_point):
+ """Mount the partition with the given mount_point."""
+ fstab = self.info.get("fstab", None)
+ if fstab:
+ p = fstab[mount_point]
+ self.script.append('mount("%s", "%s", "%s", "%s");' %
+ (p.fs_type, self.PARTITION_TYPES[p.fs_type],
+ p.device, p.mount_point))
+ self.mounts.add(p.mount_point)
+ else:
+ what = mount_point.lstrip("/")
+ what = self.info.get("partition_path", "") + what
+ self.script.append('mount("%s", "%s", "%s", "%s");' %
+ (self.info["fs_type"], self.info["partition_type"],
+ what, mount_point))
+ self.mounts.add(mount_point)
def UnpackPackageDir(self, src, dst):
"""Unpack a given directory from the OTA package into the given
@@ -158,11 +168,20 @@ class EdifyGenerator(object):
self.script.append('ui_print("%s");' % (message,))
def FormatPartition(self, partition):
- """Format the given partition."""
- partition = self.info.get("partition_path", "") + partition
- self.script.append('format("%s", "%s", "%s");' %
- (self.info["fs_type"], self.info["partition_type"],
- partition))
+ """Format the given partition, specified by its mount point (eg,
+ "/system")."""
+
+ fstab = self.info.get("fstab", None)
+ if fstab:
+ p = fstab[partition]
+ self.script.append('format("%s", "%s", "%s");' %
+ (p.fs_type, self.PARTITION_TYPES[p.fs_type], p.device))
+ else:
+ # older target-files without per-partition types
+ partition = self.info.get("partition_path", "") + partition
+ self.script.append('format("%s", "%s", "%s");' %
+ (self.info["fs_type"], self.info["partition_type"],
+ partition))
def DeleteFiles(self, file_list):
"""Delete all files in file_list."""
@@ -196,24 +215,42 @@ class EdifyGenerator(object):
self.script.append(
'write_firmware_image("PACKAGE:%s", "%s");' % (fn, kind))
- def WriteRawImage(self, partition, fn):
- """Write the given package file into the given partition."""
-
- if self.info["partition_type"] == "MTD":
- self.script.append(
- ('assert(package_extract_file("%(fn)s", "/tmp/%(partition)s.img"),\n'
- ' write_raw_image("/tmp/%(partition)s.img", "%(partition)s"),\n'
- ' delete("/tmp/%(partition)s.img"));')
- % {'partition': partition, 'fn': fn})
- elif self.info["partition_type"] == "EMMC":
- self.script.append(
- ('package_extract_file("%(fn)s", "%(dir)s%(partition)s");')
- % {'partition': partition, 'fn': fn,
- 'dir': self.info.get("partition_path", ""),
- })
+ def WriteRawImage(self, mount_point, fn):
+ """Write the given package file into the partition for the given
+ mount point."""
+
+ fstab = self.info["fstab"]
+ if fstab:
+ p = fstab[mount_point]
+ partition_type = self.PARTITION_TYPES[p.fs_type]
+ args = {'device': p.device, 'fn': fn}
+ if partition_type == "MTD":
+ self.script.append(
+ ('assert(package_extract_file("%(fn)s", "/tmp/%(device)s.img"),\n'
+ ' write_raw_image("/tmp/%(device)s.img", "%(device)s"),\n'
+ ' delete("/tmp/%(device)s.img"));') % args)
+ elif partition_type == "EMMC":
+ self.script.append(
+ 'package_extract_file("%(fn)s", "%(device)s");' % args)
+ else:
+ raise ValueError("don't know how to write \"%s\" partitions" % (p.fs_type,))
else:
- raise ValueError("don't know how to write \"%s\" partitions" %
- (self.info["partition_type"],))
+ # backward compatibility with older target-files that lack recovery.fstab
+ if self.info["partition_type"] == "MTD":
+ self.script.append(
+ ('assert(package_extract_file("%(fn)s", "/tmp/%(partition)s.img"),\n'
+ ' write_raw_image("/tmp/%(partition)s.img", "%(partition)s"),\n'
+ ' delete("/tmp/%(partition)s.img"));')
+ % {'partition': partition, 'fn': fn})
+ elif self.info["partition_type"] == "EMMC":
+ self.script.append(
+ ('package_extract_file("%(fn)s", "%(dir)s%(partition)s");')
+ % {'partition': partition, 'fn': fn,
+ 'dir': self.info.get("partition_path", ""),
+ })
+ else:
+ raise ValueError("don't know how to write \"%s\" partitions" %
+ (self.info["partition_type"],))
def SetPermissions(self, fn, uid, gid, mode):
"""Set file ownership and permissions."""
diff --git a/tools/releasetools/img_from_target_files b/tools/releasetools/img_from_target_files
index d734ad0..2a0e4cc 100755
--- a/tools/releasetools/img_from_target_files
+++ b/tools/releasetools/img_from_target_files
@@ -61,9 +61,10 @@ def AddUserdata(output_zip):
img = tempfile.NamedTemporaryFile()
build_command = []
- if OPTIONS.info_dict.get("fs_type", "").startswith("ext"):
+ if OPTIONS.info_dict["fstab"]["/data"].fs_type.startswith("ext"):
build_command = ["mkuserimg.sh",
- user_dir, img.name, OPTIONS.info_dict["fs_type"], "userdata"]
+ user_dir, img.name,
+ OPTIONS.info_dict["fstab"]["/data"].fs_type, "userdata"]
if "userdata_size" in OPTIONS.info_dict:
build_command.append(str(OPTIONS.info_dict["userdata_size"]))
else:
@@ -108,10 +109,10 @@ def AddSystem(output_zip):
pass
build_command = []
- if OPTIONS.info_dict.get("fs_type", "").startswith("ext"):
+ if OPTIONS.info_dict["fstab"]["/system"].fs_type.startswith("ext"):
build_command = ["mkuserimg.sh",
os.path.join(OPTIONS.input_tmp, "system"), img.name,
- OPTIONS.info_dict["fs_type"], "system"]
+ OPTIONS.info_dict["fstab"]["/system"].fs_type, "system"]
if "system_img" in OPTIONS.info_dict:
build_command.append(str(OPTIONS.info_dict["system_size"]))
else:
diff --git a/tools/releasetools/ota_from_target_files b/tools/releasetools/ota_from_target_files
index 37715bc..320c6fc 100755
--- a/tools/releasetools/ota_from_target_files
+++ b/tools/releasetools/ota_from_target_files
@@ -363,10 +363,10 @@ def WriteFullOTAPackage(input_zip, output_zip):
script.ShowProgress(0.5, 0)
if OPTIONS.wipe_user_data:
- script.FormatPartition("userdata")
+ script.FormatPartition("/data")
- script.FormatPartition("system")
- script.Mount("system", "/system")
+ script.FormatPartition("/system")
+ script.Mount("/system")
script.UnpackPackageDir("recovery", "/system")
script.UnpackPackageDir("system", "/system")
@@ -387,7 +387,7 @@ def WriteFullOTAPackage(input_zip, output_zip):
script.ShowProgress(0.2, 0)
script.ShowProgress(0.2, 10)
- script.WriteRawImage("boot", "boot.img")
+ script.WriteRawImage("/boot", "boot.img")
script.ShowProgress(0.1, 0)
device_specific.FullOTA_InstallEnd()
@@ -500,7 +500,7 @@ def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):
metadata["pre-build"] = source_fp
metadata["post-build"] = target_fp
- script.Mount("system", "/system")
+ script.Mount("/system")
script.AssertSomeFingerprint(source_fp, target_fp)
source_boot = common.File("/tmp/boot.img",
@@ -564,7 +564,7 @@ def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):
if OPTIONS.wipe_user_data:
script.Print("Erasing user data...")
- script.FormatPartition("userdata")
+ script.FormatPartition("/data")
script.Print("Removing unneeded files...")
script.DeleteFiles(["/"+i[0] for i in verbatim_targets] +