system.img镜像转换为system.new.dat + system.transfer.list

android 8.1上面验证,支持所有的android版本,直接放到sdk中执行即可。
 
img2sdat.py
#!/usr/bin/env python
#coding=utf-8
 
import sys
 
if sys.hexversion < 0x02070000:
  print >> sys.stderr, "Python 2.7 or newer is required."
  sys.exit(1)
 
from hashlib import sha1 as sha1
 
import common
import sparse_img
 
OPTIONS = common.OPTIONS
 
try:
    PARTITION_NAME = str(sys.argv[1])
    SYSTEM_IMG = str(sys.argv[2])
    OUTPUT_DIR = str(sys.argv[3])
    OPTIONS.outpath = OUTPUT_DIR
except IndexError:
    print('\nUsage: img2sdat.py <partiton_name> <system_img> <system_new_dir>\n')
    print('  eg:   img2sdat.py system system.img system_new\n')
    print('        <partiton_name>: input partition name')
    print('        <img_name>: input image name')
    print('        <new_dir>: image new dat dir')
    print('        Visit xda thread for more information.\n')
    try:
       input = raw_input
    except NameError: pass
    input('Press ENTER to exit...')
    sys.exit()
 
 
def main(argv):  
  system_tgt = sparse_img.SparseImage(SYSTEM_IMG);
  system_tgt.ResetFileMap()
  system_diff = common.BlockDifference(PARTITION_NAME, system_tgt, src=None, check_first_block=False, version=4)
 
 
if __name__ == '__main__':  
  main(sys.argv[1:])  
目前transfer.list已经最新的支持version=4, system.transfer.list版本进化,这里针对不同的android版本,传入不同的version=1/2/3/4即可
 
对common.py打patch
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 22d95a9..4b981e3 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -1406,6 +1406,12 @@ class BlockDifference(object):
     b = blockimgdiff.BlockImageDiff(tgt, src, threads=OPTIONS.worker_threads,
                                     version=self.version,
                                     disable_imgdiff=self.disable_imgdiff)
+
+    self.path = os.path.join(OPTIONS.outpath, partition)
+    print (self.path)
+    return
+
     tmpdir = tempfile.mkdtemp()
     OPTIONS.tempfiles.append(tmpdir)
     self.path = os.path.join(tmpdir, partition)
 
然后即可在android的根目录下面执行如下命令:
./build/tools/releasetools/img2sdat.py  system out/target/product/xxxx/system.img out/target/product/xxxx/sdat/
Total of 475136 4096-byte output blocks in 2302 input chunks.
Finding transfers...
Generating digraph...
Finding vertex sequence...
Reversing backward edges...
  0/0 dependencies (0.00%) were violated; 0 source blocks stashed.
Improving vertex order...
Reticulating splines...
940847104  940847104 (100.00%)     new __DATA 0-32765 32768-32769 32889-32890 65536-65537 66033-98301 98304-98305 98425-98426 98922-131070 131072-131073 131569-151714 163840-163841 163961-163962 164458-196605 196608-196609 229376-229377 229497-229498 229994-262141 262144-262145 294912-294913 295033-295034 295530-327677 327680-327681 360448-360449 393216-393217 425984-425985 458752-458753 459249-475135
max stashed blocks: 0  (0 bytes), limit: <unknown>
 
即可在目录out/target/product/xxxx/sdat看到有system.new.dat与system.transfer.list文件生成。
命令格式: img2sdat.py 分区名  img路径   new.dat路径

eg:img2sdat.py  system  system.img  system_out_dir

posted @ 2019-01-30 17:45  leo21sun  阅读(1917)  评论(0编辑  收藏  举报