summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bml_over_mtd.sh44
-rw-r--r--releasetools/aries_common.py31
-rw-r--r--releasetools/aries_edify_generator.py57
-rwxr-xr-xreleasetools/aries_img_from_target_files189
-rwxr-xr-xreleasetools/aries_ota_from_target_files138
-rw-r--r--updater.sh128
6 files changed, 587 insertions, 0 deletions
diff --git a/bml_over_mtd.sh b/bml_over_mtd.sh
new file mode 100644
index 0000000..be73e15
--- /dev/null
+++ b/bml_over_mtd.sh
@@ -0,0 +1,44 @@
+#!/sbin/busybox sh
+#
+# bml_over_mtd.sh
+# Take care of bad blocks while flashing kernel image to boot partition
+#
+
+PARTITION=$1
+PARTITION_START_BLOCK=$2
+RESERVOIRPARTITION=$3
+RESERVOIR_START_BLOCK=$4
+IMAGE=$5
+
+# remove old log
+rm -rf /sdcard/bml_over_mtd.log
+
+# everything is logged into /sdcard/bml_over_mtd.log
+exec >> /sdcard/bml_over_mtd.log 2>&1
+
+set -x
+export PATH=/:/sbin:/system/xbin:/system/bin:$PATH
+
+busybox cat <<EOF
+########################################################################################
+#
+# Flashing boot image with bml_over_mtd on `busybox date`
+#
+########################################################################################
+EOF
+
+# scan boot partition for bad blocks
+/tmp/bml_over_mtd scan $PARTITION
+status=$?
+
+# if exit status is 15 use bml_over_mtd, otherwise use flash_image
+if test $status -eq 15
+then
+ echo "Running bml_over_mtd..."
+ /tmp/bml_over_mtd flash $PARTITION $PARTITION_START_BLOCK $RESERVOIRPARTITION $RESERVOIR_START_BLOCK $IMAGE
+else
+ echo "Running flash_image..."
+ /sbin/flash_image $PARTITION $IMAGE
+fi
+
+exit
diff --git a/releasetools/aries_common.py b/releasetools/aries_common.py
new file mode 100644
index 0000000..93f1b8e
--- /dev/null
+++ b/releasetools/aries_common.py
@@ -0,0 +1,31 @@
+#
+# 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/aries_edify_generator.py b/releasetools/aries_edify_generator.py
new file mode 100644
index 0000000..8beb707
--- /dev/null
+++ b/releasetools/aries_edify_generator.py
@@ -0,0 +1,57 @@
+#
+# 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 RunBackup(self, command):
+ edify_generator.EdifyGenerator.RunBackup(self, command)
+ self.script.append(
+ ('package_extract_file("updater.sh", "/tmp/updater.sh");\n'
+ 'set_perm(0, 0, 0777, "/tmp/updater.sh");'))
+ self.script.append(
+ ('package_extract_file("busybox", "/tmp/busybox");\n'
+ 'set_perm(0, 0, 0777, "/tmp/busybox");'))
+ self.script.append(
+ ('package_extract_file("flash_image", "/tmp/flash_image");\n'
+ 'set_perm(0, 0, 0777, "/tmp/flash_image");'))
+ self.script.append(
+ ('package_extract_file("erase_image", "/tmp/erase_image");\n'
+ 'set_perm(0, 0, 0777, "/tmp/erase_image");'))
+ self.script.append(
+ ('package_extract_file("bml_over_mtd", "/tmp/bml_over_mtd");\n'
+ 'set_perm(0, 0, 0777, "/tmp/bml_over_mtd");'))
+ self.script.append(
+ ('package_extract_file("bml_over_mtd.sh", "/tmp/bml_over_mtd.sh");\n'
+ 'set_perm(0, 0, 0777, "/tmp/bml_over_mtd.sh");'))
+
+ self.script.append('package_extract_file("boot.img", "/tmp/boot.img");')
+ self.script.append('run_program("/tmp/updater.sh");')
+
+ def WriteBMLoverMTD(self, partition, partition_start_block, reservoirpartition, reservoir_start_block, image):
+ """Write the given package file into the given partition."""
+
+ args = {'partition': partition, 'partition_start_block': partition_start_block, 'reservoirpartition': reservoirpartition, 'reservoir_start_block': reservoir_start_block, 'image': image}
+
+ self.script.append(
+ ('assert(package_extract_file("%(image)s", "/tmp/%(partition)s.img"),\n'
+ ' run_program("/tmp/bml_over_mtd.sh", "%(partition)s", "%(partition_start_block)s", "%(reservoirpartition)s", "%(reservoir_start_block)s", "/tmp/%(partition)s.img"),\n'
+ ' delete("/tmp/%(partition)s.img"));') % args)
+
diff --git a/releasetools/aries_img_from_target_files b/releasetools/aries_img_from_target_files
new file mode 100755
index 0000000..1a6d82e
--- /dev/null
+++ b/releasetools/aries_img_from_target_files
@@ -0,0 +1,189 @@
+#!/usr/bin/env python
+#
+# 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.
+
+"""
+Given a target-files zipfile, produces an image zipfile suitable for
+use with 'fastboot update'.
+
+Usage: img_from_target_files [flags] input_target_files output_image_zip
+
+ -b (--board_config) <file>
+ Deprecated.
+
+"""
+
+import sys
+
+if sys.hexversion < 0x02040000:
+ print >> sys.stderr, "Python 2.4 or newer is required."
+ sys.exit(1)
+
+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 aries_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:
+ # bogus error on my mac version?
+ # File "./build/tools/releasetools/img_from_target_files", line 86, in AddSystem
+ # os.path.join(OPTIONS.input_tmp, "system"))
+ # OSError: [Errno 17] File exists
+ 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."
+
+
+if __name__ == '__main__':
+ try:
+ main(sys.argv[1:])
+ except common.ExternalError, e:
+ print
+ print " ERROR: %s" % (e,)
+ print
+ sys.exit(1)
diff --git a/releasetools/aries_ota_from_target_files b/releasetools/aries_ota_from_target_files
new file mode 100755
index 0000000..dd2ae66
--- /dev/null
+++ b/releasetools/aries_ota_from_target_files
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+#
+# 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 sys
+import os
+import aries_common as common
+
+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')
+UTILITIES_DIR = os.path.join(TARGET_DIR, 'utilities')
+
+# 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, "ota_from_target_files")
+ota_from_target_files = common.load_module_from_file('ota_from_target_files', filename)
+
+from ota_from_target_files import *
+import aries_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 CopyBMLoverMTD(output_zip):
+ """Copy the bml_over_mtd utility and script to the output."""
+ output_zip.write(os.path.join(UTILITIES_DIR, "make_ext4fs"),"make_ext4fs")
+ output_zip.write(os.path.join(UTILITIES_DIR, "busybox"),"busybox")
+ output_zip.write(os.path.join(UTILITIES_DIR, "flash_image"),"flash_image")
+ output_zip.write(os.path.join(UTILITIES_DIR, "erase_image"),"erase_image")
+ output_zip.write(os.path.join(UTILITIES_DIR, "bml_over_mtd"),"bml_over_mtd")
+ output_zip.write(os.path.join(LOCAL_DIR, "bml_over_mtd.sh"),"bml_over_mtd.sh")
+ output_zip.write(os.path.join(LOCAL_DIR, "updater.sh"),"updater.sh")
+
+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", input_zip),
+ "pre-device": GetBuildProp("ro.product.device", input_zip),
+ "post-timestamp": GetBuildProp("ro.build.date.utc", input_zip),
+ }
+
+ 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)
+
+# if not OPTIONS.omit_prereq:
+# ts = GetBuildProp("ro.build.date.utc", input_zip)
+# script.AssertOlderBuild(ts)
+
+ AppendAssertions(script, input_zip)
+ device_specific.FullOTA_Assertions()
+ if OPTIONS.backuptool:
+ script.RunBackup("backup")
+
+ script.ShowProgress(0.5, 0)
+
+ if OPTIONS.wipe_user_data:
+ script.FormatPartition("/data")
+
+ script.FormatPartition("/system")
+ script.Mount("/system")
+ script.UnpackPackageDir("recovery", "/system")
+ script.UnpackPackageDir("system", "/system")
+
+ symlinks = CopySystemFiles(input_zip, output_zip)
+ script.MakeSymlinks(symlinks)
+
+ Item.GetMetadata(input_zip)
+ Item.Get("system").SetPermissions(script)
+
+ script.ShowProgress(0.2, 0)
+
+ if OPTIONS.backuptool:
+ script.ShowProgress(0.2, 10)
+ script.RunBackup("restore")
+
+ script.RunModelidCfg()
+
+ script.RunVerifyCachePartitionSize()
+
+ CopyBootFiles(input_zip, output_zip)
+ CopyBMLoverMTD(output_zip)
+
+ script.ShowProgress(0.2, 10)
+ script.WriteBMLoverMTD("boot", "72", "reservoir", "2004", "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)
+ 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 Samsung Galaxy S at this time"
+ sys.exit(1)
+ota_from_target_files.WriteIncrementalOTAPackage = WriteIncrementalOTAPackage
+
+
+if __name__ == '__main__':
+ try:
+ main(sys.argv[1:])
+ except common.ExternalError, e:
+ print
+ print " ERROR: %s" % (e,)
+ print
+ sys.exit(1)
diff --git a/updater.sh b/updater.sh
new file mode 100644
index 0000000..af49b45
--- /dev/null
+++ b/updater.sh
@@ -0,0 +1,128 @@
+#!/tmp/busybox sh
+#
+# Universal Updater Script for Samsung Galaxy S Phones
+# (c) 2011 by Teamhacksung
+#
+
+set -x
+export PATH=/:/sbin:/system/xbin:/system/bin:/tmp:$PATH
+
+# check if we're running on a bml or mtd device
+if /tmp/busybox test -e /dev/block/bml7 ; then
+# we're running on a bml device
+
+ # make sure sdcard is mounted
+ if ! /tmp/busybox grep -q /mnt/sdcard /proc/mounts ; then
+ /tmp/busybox mkdir -p /mnt/sdcard
+ /tmp/busybox umount -l /dev/block/mmcblk0p1
+ if ! /tmp/busybox mount -t vfat /dev/block/mmcblk0p1 /mnt/sdcard ; then
+ /tmp/busybox echo "Cannot mount sdcard."
+ exit 1
+ fi
+ fi
+
+ # remove old log
+ rm -rf /mnt/sdcard/cyanogenmod_bml.log
+
+ # everything is logged into /sdcard/cyanogenmod.log
+ exec >> /mnt/sdcard/cyanogenmod_bml.log 2>&1
+
+ # make sure efs is mounted
+ if ! /tmp/busybox grep -q /efs /proc/mounts ; then
+ /tmp/busybox mkdir -p /efs
+ /tmp/busybox umount -l /dev/block/stl3
+ if ! /tmp/busybox mount -t rfs /dev/block/stl3 /efs ; then
+ /tmp/busybox echo "Cannot mount efs."
+ exit 1
+ fi
+ fi
+
+ # create a backup of efs
+ /tmp/busybox rm -rf /mnt/sdcard/backup/efs
+ /tmp/busybox mkdir -p /mnt/sdcard/backup/efs
+ /tmp/busybox cp -R /efs/ /mnt/sdcard/backup
+
+ # write the package path to sdcard cyanogenmod.cfg
+ if /tmp/busybox test -n "$UPDATE_PACKAGE" ; then
+ PACKAGE_LOCATION=${UPDATE_PACKAGE#/mnt}
+ /tmp/busybox echo "$PACKAGE_LOCATION" > /mnt/sdcard/cyanogenmod.cfg
+ fi
+
+ # write new kernel to boot partition
+ /tmp/flash_image /tmp/boot.img /dev/block/bml7
+
+ /sbin/reboot now
+ exit 0
+
+elif /tmp/busybox test -e /dev/block/mtdblock0 ; then
+# we're running on a mtd device
+
+ # make sure sdcard is mounted
+ /tmp/busybox mkdir -p /sdcard
+
+ if ! /tmp/busybox grep -q /sdcard /proc/mounts ; then
+ /tmp/busybox umount -l /dev/block/mmcblk0p1
+ if ! /tmp/busybox mount -t vfat /dev/block/mmcblk0p1 /sdcard ; then
+ /tmp/busybox echo "Cannot mount sdcard."
+ exit 1
+ fi
+ fi
+
+ # remove old log
+ rm -rf /sdcard/cyanogenmod_mtd.log
+
+ # everything is logged into /sdcard/cyanogenmod.log
+ exec >> /sdcard/cyanogenmod_mtd.log 2>&1
+
+ # if a cyanogenmod.cfg exists, then this is a first time install
+ # let's format the volumes and restore radio and efs
+ if ! /tmp/busybox test -e /sdcard/cyanogenmod.cfg ; then
+ exit 1
+ fi
+ # remove the cyanogenmod.cfg to prevent this from looping
+ /tmp/busybox rm -f /sdcard/cyanogenmod.cfg
+
+ # unmount, format and mount system
+ /tmp/busybox umount -l /system
+ /tmp/erase_image system
+ /tmp/busybox mount -t yaffs2 /dev/block/mtdblock2 /system
+
+ # unmount and format cache
+ /tmp/busybox umount -l /cache
+ /tmp/erase_image cache
+
+ # unmount and format data
+ tmp/make_ext4fs -b 4096 -g 32768 -i 8192 -I 256 -a /data /dev/block/mmcblk0p2
+
+ # unmount and format datadata
+ /tmp/busybox umount -l /datadata
+ /tmp/erase_image datadata
+
+ # flash radio image
+ /tmp/erase_image radio
+ /tmp/flash_image radio /tmp/modem.bin
+
+ # restore efs backup
+ if /tmp/busybox test -e /sdcard/backup/efs/nv_data.bin ; then
+ /tmp/busybox umount -l /efs
+ /tmp/erase_image efs
+ /tmp/busybox mkdir -p /efs
+
+ if ! /tmp/busybox grep -q /efs /proc/mounts ; then
+ if ! /tmp/busybox mount -t yaffs2 /dev/block/mtdblock4 /efs ; then
+ /tmp/busybox echo "Cannot mount efs."
+ exit 1
+ fi
+ fi
+
+ /tmp/busybox cp -R /sdcard/backup/efs /
+ /tmp/busybox umount -l /efs
+ else
+ /tmp/busybox echo "Cannot restore efs."
+ fi
+
+ # flash boot image
+ /tmp/bml_over_mtd.sh boot 72 reservoir 2004 /tmp/boot.img
+
+ exit 0
+fi