diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/releasetools/build_image.py | 128 | ||||
-rwxr-xr-x | tools/releasetools/img_from_target_files | 55 | ||||
-rw-r--r-- | tools/zipalign/ZipEntry.cpp | 24 | ||||
-rw-r--r-- | tools/zipalign/ZipFile.cpp | 12 |
4 files changed, 160 insertions, 59 deletions
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py new file mode 100755 index 0000000..b5140a9 --- /dev/null +++ b/tools/releasetools/build_image.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python +# +# Copyright (C) 2011 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. + +""" +Build image output_image_file from input_directory and properties_file. + +Usage: build_image input_directory properties_file output_image_file + +""" +import os +import subprocess +import sys + + +def BuildImage(in_dir, prop_dict, out_file): + """Build an image to out_file from in_dir with property prop_dict. + + Args: + in_dir: path of input directory. + prop_dict: property dictionary. + out_file: path of the output image file. + + Returns: + True iff the image is built successfully. + """ + build_command = [] + fs_type = prop_dict.get("fs_type", "") + if fs_type.startswith("ext"): + build_command = ["mkuserimg.sh"] + if "extfs_sparse_flag" in prop_dict: + build_command.append(prop_dict["extfs_sparse_flag"]) + build_command.extend([in_dir, out_file, fs_type, + prop_dict["mount_point"]]) + if "partition_size" in prop_dict: + build_command.append(prop_dict["partition_size"]) + else: + build_command = ["mkyaffs2image", "-f"] + if prop_dict.get("mkyaffs2_extra_flags", None): + build_command.extend(prop_dict["mkyaffs2_extra_flags"].split()) + build_command.append(in_dir) + build_command.append(out_file) + + print "Running: ", " ".join(build_command) + p = subprocess.Popen(build_command); + p.communicate() + return p.returncode == 0 + + +def ImagePropFromGlobalDict(glob_dict, mount_point): + """Build an image property dictionary from the global dictionary. + + Args: + glob_dict: the global dictionary from the build system. + mount_point: such as "system", "data" etc. + """ + d = {} + common_props = ( + "fs_type", + "extfs_sparse_flag", + "mkyaffs2_extra_flags", + ) + for p in common_props: + if p in glob_dict: + d[p] = glob_dict[p] + + d["mount_point"] = mount_point + if mount_point == "system": + if "system_size" in glob_dict: + d["partition_size"] = str(glob_dict["system_size"]) + elif mount_point == "data": + if "userdata_size" in glob_dict: + d["partition_size"] = str(glob_dict["userdata_size"]) + + return d + + +def LoadGlobalDict(filename): + """Load "name=value" pairs from filename""" + d = {} + f = open(filename) + for line in f: + line = line.strip() + if not line or line.startswith("#"): + continue + k, v = line.split("=", 1) + d[k] = v + f.close() + return d + + +def main(argv): + if len(argv) != 3: + print __doc__ + sys.exit(1) + + in_dir = argv[0] + glob_dict_file = argv[1] + out_file = argv[2] + + glob_dict = LoadGlobalDict(glob_dict_file) + image_filename = os.path.basename(out_file) + mount_point = "" + if image_filename == "system.img": + mount_point = "system" + elif image_filename == "userdata.img": + mount_point = "data" + + image_properties = ImagePropFromGlobalDict(glob_dict, mount_point) + if not BuildImage(in_dir, image_properties, out_file): + print >> sys.stderr, "error: failed to build %s from %s" % (out_file, in_dir) + exit(1) + + +if __name__ == '__main__': + main(sys.argv[1:]) diff --git a/tools/releasetools/img_from_target_files b/tools/releasetools/img_from_target_files index c5b9886..4388f69 100755 --- a/tools/releasetools/img_from_target_files +++ b/tools/releasetools/img_from_target_files @@ -47,6 +47,7 @@ import zipfile if not hasattr(os, "SEEK_SET"): os.SEEK_SET = 0 +import build_image import common OPTIONS = common.OPTIONS @@ -64,27 +65,13 @@ def AddUserdata(output_zip): os.mkdir(user_dir) img = tempfile.NamedTemporaryFile() - build_command = [] + image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict, + "data") fstab = OPTIONS.info_dict["fstab"] - if fstab and fstab["/data"].fs_type.startswith("ext"): - build_command = ["mkuserimg.sh"] - if "extfs_sparse_flag" in OPTIONS.info_dict: - build_command.append(OPTIONS.info_dict["extfs_sparse_flag"]) - build_command.extend([user_dir, img.name, - 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" + if fstab: + image_props["fs_type" ] = fstab["/data"].fs_type + succ = build_image.BuildImage(user_dir, image_props, img.name) + assert succ, "build userdata.img image failed" common.CheckSize(img.name, "userdata.img", OPTIONS.info_dict) output_zip.write(img.name, "userdata.img") @@ -115,28 +102,14 @@ def AddSystem(output_zip): if (e.errno == errno.EEXIST): pass - build_command = [] + image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict, + "system") fstab = OPTIONS.info_dict["fstab"] - if fstab and fstab["/system"].fs_type.startswith("ext"): - - build_command = ["mkuserimg.sh"] - if "extfs_sparse_flag" in OPTIONS.info_dict: - build_command.append(OPTIONS.info_dict["extfs_sparse_flag"]) - build_command.extend([os.path.join(OPTIONS.input_tmp, "system"), img.name, - 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" + if fstab: + image_props["fs_type" ] = fstab["/system"].fs_type + succ = build_image.BuildImage(os.path.join(OPTIONS.input_tmp, "system"), + image_props, img.name) + assert succ, "build system.img image failed" img.seek(os.SEEK_SET, 0) data = img.read() diff --git a/tools/zipalign/ZipEntry.cpp b/tools/zipalign/ZipEntry.cpp index bed0333..cd9e332 100644 --- a/tools/zipalign/ZipEntry.cpp +++ b/tools/zipalign/ZipEntry.cpp @@ -42,7 +42,7 @@ status_t ZipEntry::initFromCDE(FILE* fp) long posn; bool hasDD; - //LOGV("initFromCDE ---\n"); + //ALOGV("initFromCDE ---\n"); /* read the CDE */ result = mCDE.read(fp); @@ -280,50 +280,50 @@ void ZipEntry::setDataInfo(long uncompLen, long compLen, unsigned long crc32, bool ZipEntry::compareHeaders(void) const { if (mCDE.mVersionToExtract != mLFH.mVersionToExtract) { - LOGV("cmp: VersionToExtract\n"); + ALOGV("cmp: VersionToExtract\n"); return false; } if (mCDE.mGPBitFlag != mLFH.mGPBitFlag) { - LOGV("cmp: GPBitFlag\n"); + ALOGV("cmp: GPBitFlag\n"); return false; } if (mCDE.mCompressionMethod != mLFH.mCompressionMethod) { - LOGV("cmp: CompressionMethod\n"); + ALOGV("cmp: CompressionMethod\n"); return false; } if (mCDE.mLastModFileTime != mLFH.mLastModFileTime) { - LOGV("cmp: LastModFileTime\n"); + ALOGV("cmp: LastModFileTime\n"); return false; } if (mCDE.mLastModFileDate != mLFH.mLastModFileDate) { - LOGV("cmp: LastModFileDate\n"); + ALOGV("cmp: LastModFileDate\n"); return false; } if (mCDE.mCRC32 != mLFH.mCRC32) { - LOGV("cmp: CRC32\n"); + ALOGV("cmp: CRC32\n"); return false; } if (mCDE.mCompressedSize != mLFH.mCompressedSize) { - LOGV("cmp: CompressedSize\n"); + ALOGV("cmp: CompressedSize\n"); return false; } if (mCDE.mUncompressedSize != mLFH.mUncompressedSize) { - LOGV("cmp: UncompressedSize\n"); + ALOGV("cmp: UncompressedSize\n"); return false; } if (mCDE.mFileNameLength != mLFH.mFileNameLength) { - LOGV("cmp: FileNameLength\n"); + ALOGV("cmp: FileNameLength\n"); return false; } #if 0 // this seems to be used for padding, not real data if (mCDE.mExtraFieldLength != mLFH.mExtraFieldLength) { - LOGV("cmp: ExtraFieldLength\n"); + ALOGV("cmp: ExtraFieldLength\n"); return false; } #endif if (mCDE.mFileName != NULL) { if (strcmp((char*) mCDE.mFileName, (char*) mLFH.mFileName) != 0) { - LOGV("cmp: FileName\n"); + ALOGV("cmp: FileName\n"); return false; } } diff --git a/tools/zipalign/ZipFile.cpp b/tools/zipalign/ZipFile.cpp index 62c9383..9e5ee42 100644 --- a/tools/zipalign/ZipFile.cpp +++ b/tools/zipalign/ZipFile.cpp @@ -253,7 +253,7 @@ status_t ZipFile::readCentralDir(void) if (buf[i] == 0x50 && ZipEntry::getLongLE(&buf[i]) == EndOfCentralDir::kSignature) { - LOGV("+++ Found EOCD at buf+%d\n", i); + ALOGV("+++ Found EOCD at buf+%d\n", i); break; } } @@ -303,7 +303,7 @@ status_t ZipFile::readCentralDir(void) /* * Loop through and read the central dir entries. */ - LOGV("Scanning %d entries...\n", mEOCD.mTotalNumEntries); + ALOGV("Scanning %d entries...\n", mEOCD.mTotalNumEntries); int entry; for (entry = 0; entry < mEOCD.mTotalNumEntries; entry++) { ZipEntry* pEntry = new ZipEntry; @@ -334,7 +334,7 @@ status_t ZipFile::readCentralDir(void) result = UNKNOWN_ERROR; goto bail; } - LOGV("+++ EOCD read check passed\n"); + ALOGV("+++ EOCD read check passed\n"); } bail: @@ -799,7 +799,7 @@ status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp, /* only read if the input buffer is empty */ if (zstream.avail_in == 0 && !atEof) { - LOGV("+++ reading %d bytes\n", (int)kBufSize); + ALOGV("+++ reading %d bytes\n", (int)kBufSize); if (data) { getSize = size > kBufSize ? kBufSize : size; memcpy(inBuf, data, getSize); @@ -813,7 +813,7 @@ status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp, } } if (getSize < kBufSize) { - LOGV("+++ got %d bytes, EOF reached\n", + ALOGV("+++ got %d bytes, EOF reached\n", (int)getSize); atEof = true; } @@ -840,7 +840,7 @@ status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp, if (zstream.avail_out == 0 || (zerr == Z_STREAM_END && zstream.avail_out != (uInt) kBufSize)) { - LOGV("+++ writing %d bytes\n", (int) (zstream.next_out - outBuf)); + ALOGV("+++ writing %d bytes\n", (int) (zstream.next_out - outBuf)); if (fwrite(outBuf, 1, zstream.next_out - outBuf, dstFp) != (size_t)(zstream.next_out - outBuf)) { |