summaryrefslogtreecommitdiffstats
path: root/releasetools
diff options
context:
space:
mode:
authorCaio Schnepper <caioschnepper@gmail.com>2015-07-01 18:11:33 -0300
committerCaio Schnepper <caioschnepper@gmail.com>2015-07-01 18:11:33 -0300
commit24b15d402db91a2466eeed0a27ec7653fe45ab61 (patch)
treeb64f4f9293400240dad50e5724512145d244b9d0 /releasetools
parentecc3d13410f7821659f7cc1ef806dfb9378853a3 (diff)
downloaddevice_samsung_galaxys2-common-24b15d402db91a2466eeed0a27ec7653fe45ab61.zip
device_samsung_galaxys2-common-24b15d402db91a2466eeed0a27ec7653fe45ab61.tar.gz
device_samsung_galaxys2-common-24b15d402db91a2466eeed0a27ec7653fe45ab61.tar.bz2
Update releasetools
We were using a deprecated version and with a faulty backuptool. Use CM releasetools as much as possible Change-Id: I19fbbcb21b20030f10161fbc798feb02b90a7c7c
Diffstat (limited to 'releasetools')
-rwxr-xr-xreleasetools/galaxys2_common.py31
-rwxr-xr-xreleasetools/galaxys2_edify_generator.py46
-rwxr-xr-xreleasetools/galaxys2_img_from_target_files186
-rwxr-xr-xreleasetools/galaxys2_ota_from_target_files107
4 files changed, 43 insertions, 327 deletions
diff --git a/releasetools/galaxys2_common.py b/releasetools/galaxys2_common.py
deleted file mode 100755
index 93f1b8e..0000000
--- a/releasetools/galaxys2_common.py
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import os, sys
-
-LOCAL_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
-RELEASETOOLS_DIR = os.path.abspath(os.path.join(LOCAL_DIR, '../../../build/tools/releasetools'))
-
-# Add releasetools directory to python path
-sys.path.append(RELEASETOOLS_DIR)
-
-from common import *
-
-def load_module_from_file(module_name, filename):
- import imp
- f = open(filename, 'r')
- module = imp.load_module(module_name, f, filename, ('', 'U', 1))
- f.close()
- return module
diff --git a/releasetools/galaxys2_edify_generator.py b/releasetools/galaxys2_edify_generator.py
deleted file mode 100755
index 95bdf48..0000000
--- a/releasetools/galaxys2_edify_generator.py
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import os, sys
-
-LOCAL_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
-RELEASETOOLS_DIR = os.path.abspath(os.path.join(LOCAL_DIR, '../../../build/tools/releasetools'))
-
-import edify_generator
-
-class EdifyGenerator(edify_generator.EdifyGenerator):
- def UnpackPackageFile(self, src, dst):
- """Unpack a given file from the OTA package into the given
- destination file."""
- self.script.append('package_extract_file("%s", "%s");' % (src, dst))
-
- def EMMCWriteRawImage(self, partition, image):
- """Write the given package file into the given partition."""
-
- args = {'partition': partition, 'image': image}
-
- self.script.append(
- ('assert(package_extract_file("%(image)s", "/tmp/%(image)s"),\n'
- ' write_raw_image("/tmp/%(image)s", "%(partition)s"),\n'
- ' delete("/tmp/%(image)s"));') % args)
-
- def Unmount(self, mount_point):
- """Unmount the partition with the given mount_point."""
- fstab = self.info.get("fstab", None)
- if fstab:
- p = fstab[mount_point]
- self.script.append('unmount("%s");' %
- (p.mount_point))
- self.mounts.add(p.mount_point)
diff --git a/releasetools/galaxys2_img_from_target_files b/releasetools/galaxys2_img_from_target_files
index 240de1b..e929af6 100755
--- a/releasetools/galaxys2_img_from_target_files
+++ b/releasetools/galaxys2_img_from_target_files
@@ -14,172 +14,38 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""
-Given a target-files zipfile, produces an image zipfile suitable for
-use with 'fastboot update'.
+import os, sys, imp
-Usage: img_from_target_files [flags] input_target_files output_image_zip
+LOCAL_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
+RELEASETOOLS_DIR = os.path.abspath(os.path.join(LOCAL_DIR, '../../../build/tools/releasetools'))
+TARGET_DIR = os.getenv('OUT')
- -b (--board_config) <file>
- Deprecated.
+# Add releasetools directory to python path
+sys.path.append(RELEASETOOLS_DIR)
-"""
+# Import the existing file so we just have to rewrite the modules we need.
+# This is a nasty hack as the filename doesn't end in .py, but it works
+filename = os.path.join(RELEASETOOLS_DIR, 'img_from_target_files')
+f = open(filename, 'rU')
+img_from_target_files = imp.load_module('img_from_target_files', f, filename, ('', 'U', 1))
+f.close()
-import sys
+from img_from_target_files import *
-if sys.hexversion < 0x02040000:
- print >> sys.stderr, "Python 2.4 or newer is required."
- sys.exit(1)
+__doc__ = img_from_target_files.__doc__
-import errno
-import os
-import re
-import shutil
-import subprocess
-import tempfile
-import zipfile
-
-# missing in Python 2.4 and before
-if not hasattr(os, "SEEK_SET"):
- os.SEEK_SET = 0
-
-import galaxys2_common as common
-
-OPTIONS = common.OPTIONS
-
-def AddUserdata(output_zip):
- """Create an empty userdata image and store it in output_zip."""
-
- print "creating userdata.img..."
-
- # The name of the directory it is making an image out of matters to
- # mkyaffs2image. So we create a temp dir, and within it we create an
- # empty dir named "data", and build the image from that.
- temp_dir = tempfile.mkdtemp()
- user_dir = os.path.join(temp_dir, "data")
- os.mkdir(user_dir)
- img = tempfile.NamedTemporaryFile()
-
- build_command = []
- if OPTIONS.info_dict["fstab"]["/data"].fs_type.startswith("ext"):
- build_command = ["mkuserimg.sh",
- user_dir, img.name,
- OPTIONS.info_dict["fstab"]["/data"].fs_type, "data"]
- if "userdata_size" in OPTIONS.info_dict:
- build_command.append(str(OPTIONS.info_dict["userdata_size"]))
- else:
- build_command = ["mkyaffs2image", "-f"]
- extra = OPTIONS.info_dict.get("mkyaffs2_extra_flags", None)
- if extra:
- build_command.extend(extra.split())
- build_command.append(user_dir)
- build_command.append(img.name)
-
- p = common.Run(build_command)
- p.communicate()
- assert p.returncode == 0, "build userdata.img image failed"
-
- common.CheckSize(img.name, "userdata.img", OPTIONS.info_dict)
- output_zip.write(img.name, "userdata.img")
- img.close()
- os.rmdir(user_dir)
- os.rmdir(temp_dir)
-
-
-def AddSystem(output_zip):
- """Turn the contents of SYSTEM into a system image and store it in
- output_zip."""
-
- print "creating system.img..."
-
- img = tempfile.NamedTemporaryFile()
-
- # The name of the directory it is making an image out of matters to
- # mkyaffs2image. It wants "system" but we have a directory named
- # "SYSTEM", so create a symlink.
- try:
- os.symlink(os.path.join(OPTIONS.input_tmp, "SYSTEM"),
- os.path.join(OPTIONS.input_tmp, "system"))
- except OSError, e:
- if (e.errno == errno.EEXIST):
- pass
-
- build_command = []
- 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["fstab"]["/system"].fs_type, "system"]
- if "system_size" in OPTIONS.info_dict:
- build_command.append(str(OPTIONS.info_dict["system_size"]))
- else:
- build_command = ["mkyaffs2image", "-f"]
- extra = OPTIONS.info_dict.get("mkyaffs2_extra_flags", None)
- if extra:
- build_command.extend(extra.split())
- build_command.append(os.path.join(OPTIONS.input_tmp, "system"))
- build_command.append(img.name)
-
- p = common.Run(build_command)
- p.communicate()
- assert p.returncode == 0, "build system.img image failed"
-
- img.seek(os.SEEK_SET, 0)
- data = img.read()
- img.close()
-
- common.CheckSize(data, "system.img", OPTIONS.info_dict)
- common.ZipWriteStr(output_zip, "system.img", data)
-
-
-def CopyInfo(output_zip):
- """Copy the android-info.txt file from the input to the output."""
- output_zip.write(os.path.join(OPTIONS.input_tmp, "OTA", "android-info.txt"),
- "android-info.txt")
-
-
-def main(argv):
-
- def option_handler(o, a):
- if o in ("-b", "--board_config"):
- pass # deprecated
- else:
- return False
- return True
-
- args = common.ParseOptions(argv, __doc__,
- extra_opts="b:",
- extra_long_opts=["board_config="],
- extra_option_handler=option_handler)
-
- if len(args) != 2:
- common.Usage(__doc__)
- sys.exit(1)
-
- OPTIONS.input_tmp = common.UnzipTemp(args[0])
-
- input_zip = zipfile.ZipFile(args[0], "r")
- OPTIONS.info_dict = common.LoadInfoDict(input_zip)
-
- output_zip = zipfile.ZipFile(args[1], "w", compression=zipfile.ZIP_DEFLATED)
-
- common.AddBoot(output_zip, OPTIONS.info_dict)
- common.AddRecovery(output_zip, OPTIONS.info_dict)
- AddSystem(output_zip)
- AddUserdata(output_zip)
- CopyInfo(output_zip)
-
- print "cleaning up..."
- output_zip.close()
- shutil.rmtree(OPTIONS.input_tmp)
-
- print "done."
+def GetBootableImage(name, prebuilt_name, unpack_dir, tree_subdir):
+ from common import File
+ return File.FromLocalFile(name, os.path.join(TARGET_DIR, prebuilt_name))
+common.GetBootableImage = GetBootableImage
if __name__ == '__main__':
- try:
- main(sys.argv[1:])
- except common.ExternalError, e:
- print
- print " ERROR: %s" % (e,)
- print
- sys.exit(1)
+ try:
+ common.CloseInheritedPipes()
+ main(sys.argv[1:])
+ except common.ExternalError, e:
+ print
+ print " ERROR: %s" % (e,)
+ print
+ sys.exit(1)
diff --git a/releasetools/galaxys2_ota_from_target_files b/releasetools/galaxys2_ota_from_target_files
index dbc945a..d605646 100755
--- a/releasetools/galaxys2_ota_from_target_files
+++ b/releasetools/galaxys2_ota_from_target_files
@@ -14,9 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys
-import os
-import galaxys2_common as common
+import os, sys, imp
LOCAL_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
RELEASETOOLS_DIR = os.path.abspath(os.path.join(LOCAL_DIR, '../../../build/tools/releasetools'))
@@ -27,98 +25,27 @@ sys.path.append(RELEASETOOLS_DIR)
# Import the existing file so we just have to rewrite the modules we need.
# This is a nasty hack as the filename doesn't end in .py, but it works
-filename = os.path.join(RELEASETOOLS_DIR, "ota_from_target_files")
-ota_from_target_files = common.load_module_from_file('ota_from_target_files', filename)
+filename = os.path.join(RELEASETOOLS_DIR, 'ota_from_target_files')
+f = open(filename, 'rU')
+ota_from_target_files = imp.load_module('ota_from_target_files', f, filename, ('', 'U', 1))
+f.close()
from ota_from_target_files import *
-import galaxys2_edify_generator as edify_generator
__doc__ = ota_from_target_files.__doc__
-def CopyBootFiles(input_zip, output_zip):
- output_zip.write(os.path.join(TARGET_DIR, "boot.img"),"boot.img")
+def GetBootableImage(name, prebuilt_name, unpack_dir, tree_subdir):
+ from common import File
+ return File.FromLocalFile(name, os.path.join(TARGET_DIR, prebuilt_name))
-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, OPTIONS.info_dict)
-
- metadata = {"post-build": GetBuildProp("ro.build.fingerprint",
- OPTIONS.info_dict),
- "pre-device": GetBuildProp("ro.product.device",
- OPTIONS.info_dict),
- "post-timestamp": GetBuildProp("ro.build.date.utc",
- OPTIONS.info_dict),
- }
-
- device_specific = common.DeviceSpecificParams(
- input_zip=input_zip,
- input_version=OPTIONS.info_dict["recovery_api_version"],
- output_zip=output_zip,
- script=script,
- input_tmp=OPTIONS.input_tmp,
- metadata=metadata,
- info_dict=OPTIONS.info_dict)
-
- system_items = ItemSet("system", "META/filesystem_config.txt")
- AppendAssertions(script, device_specific.info_dict)
- device_specific.FullOTA_Assertions()
- if OPTIONS.backuptool:
- script.Mount("/system")
- script.RunBackup("backup")
- script.Unmount("/system")
-
- script.ShowProgress(0.5, 0)
-
- if OPTIONS.wipe_user_data:
- script.FormatPartition("/data")
- script.Unmount("/system")
-
- script.FormatPartition("/system")
- script.Mount("/system")
- script.UnpackPackageDir("recovery", "/system")
- script.UnpackPackageDir("system", "/system")
-
- symlinks = CopyPartitionFiles(system_items, input_zip, output_zip)
- script.MakeSymlinks(symlinks)
-
- CopyBootFiles(input_zip, output_zip)
-
- system_items.GetMetadata(input_zip)
- system_items.Get("system").SetPermissions(script)
-
- script.ShowProgress(0.2, 0)
-
- if OPTIONS.backuptool:
- script.ShowProgress(0.2, 10)
- script.RunBackup("restore")
-
- script.ShowProgress(0.2, 10)
- script.WriteRawImage("/boot", "boot.img")
-
- script.ShowProgress(0.1, 0)
- device_specific.FullOTA_InstallEnd()
-
- if OPTIONS.extra_script is not None:
- script.AppendExtra(OPTIONS.extra_script)
-
- script.UnmountAll()
- script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary)
- WriteMetadata(metadata, output_zip)
-ota_from_target_files.WriteFullOTAPackage = WriteFullOTAPackage
-
-
-def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):
- print "Incremental OTA Packages are not support on the galaxys2 at this time"
- sys.exit(1)
-ota_from_target_files.WriteIncrementalOTAPackage = WriteIncrementalOTAPackage
+common.GetBootableImage = GetBootableImage
if __name__ == '__main__':
- try:
- main(sys.argv[1:])
- except common.ExternalError, e:
- print
- print " ERROR: %s" % (e,)
- print
- sys.exit(1)
+ try:
+ common.CloseInheritedPipes()
+ main(sys.argv[1:])
+ except common.ExternalError, e:
+ print
+ print " ERROR: %s" % (e,)
+ print
+ sys.exit(1)