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

转载于:https://www.cnblogs.com/codeking100/p/10339162.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值