From 523775a11c5a41fb13ae26591dbd1c5ca7b62db3 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Wed, 8 Feb 2012 17:36:28 -0800 Subject: Add simg_dump.py python script to dump sparse image information Change-Id: I97c1aec040b46c36bde82f7726a6d35b28ac6733 Signed-off-by: Scott Anderson --- ext4_utils/Android.mk | 10 +++ ext4_utils/simg_dump.py | 169 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100755 ext4_utils/simg_dump.py (limited to 'ext4_utils') diff --git a/ext4_utils/Android.mk b/ext4_utils/Android.mk index ab0f26b2..9b0dc1b5 100644 --- a/ext4_utils/Android.mk +++ b/ext4_utils/Android.mk @@ -150,3 +150,13 @@ LOCAL_BUILT_MODULE_STEM := $(notdir $(LOCAL_SRC_FILES)) LOCAL_IS_HOST_MODULE := true include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) + +LOCAL_MODULE := simg_dump.py +LOCAL_MODULE_TAGS := debug +LOCAL_SRC_FILES := simg_dump.py +LOCAL_MODULE_CLASS := EXECUTABLES +LOCAL_IS_HOST_MODULE := true + +include $(BUILD_PREBUILT) diff --git a/ext4_utils/simg_dump.py b/ext4_utils/simg_dump.py new file mode 100755 index 00000000..6ece31d0 --- /dev/null +++ b/ext4_utils/simg_dump.py @@ -0,0 +1,169 @@ +#! /usr/bin/env python + +# Copyright (C) 2012 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. + +from __future__ import print_function +import getopt, posixpath, signal, struct, sys + +def usage(argv0): + print(""" +Usage: %s [-v] sparse_image_file ... + -v verbose output +""" % ( argv0 )) + sys.exit(2) + +def main(): + + signal.signal(signal.SIGPIPE, signal.SIG_DFL) + + me = posixpath.basename(sys.argv[0]) + + # Parse the command line + verbose = 0 # -v + try: + opts, args = getopt.getopt(sys.argv[1:], + "v", + ["verbose"]) + except getopt.GetoptError, e: + print(e) + usage(me) + for o, a in opts: + if o in ("-v", "--verbose"): + verbose += 1 + else: + print("Unrecognized option \"%s\"" % (o)) + usage(me) + + if len(args) == 0: + print("No sparse_image_file specified") + usage(me) + + for path in args: + FH = open(path, 'rb') + header_bin = FH.read(28) + header = struct.unpack(" 1: + header = struct.unpack("<12B", header_bin) + print(" (%02X%02X %02X%02X %02X%02X%02X%02X %02X%02X%02X%02X)" + % (header[0], header[1], header[2], header[3], + header[4], header[5], header[6], header[7], + header[8], header[9], header[10], header[11])) + else: + print() + + offset += chunk_sz + + print(" %10u %7u End" % (FH.tell(), offset)) + + if total_blks != offset: + print("The header said we should have %u output blocks, but we saw %u" + % (total_blks, offset)) + + junk_len = len(FH.read()) + if junk_len: + print("There were %u bytes of extra data at the end of the file." + % (junk_len)) + + sys.exit(0) + +if __name__ == "__main__": + main() -- cgit v1.2.3