前言
写的一个 python 脚本,封装了高通回读镜像的命令,主要用于开不了机的情况下,查哪个镜像出问题用
代码
# -*- coding: UTF-8 -*-
import os
import subprocess
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
import sys
#!/usr/bin/evn python
#coding:utf-8
"""
文件内容:
<?xml version="1.0"?>
<data>
<country name="Singapore">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Panama">
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>
输出结果:
F:\BT同步\Study\【常用工具】\Python\XML>python ETreeDemo.py ETreeDemo.xml
data --- {}
country --- {'name': 'Singapore'}
country --- {'name': 'Panama'}
**********
2011
country
**********
Singapore 4
Panama 68
"""
"""
F:\BT同步\Study\【常用工具】\Python\Qcom回读镜像\回读所有镜像除 user分区以及最后一次根据地址回读.log (58 hits)
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=fh_gpt_header_0 --start_sector=1 --lun=0 --num_sectors=1 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=fh_gpt_entries_0 --start_sector=2 --lun=0 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x20000_Len172032_DT_28_04_2018_13_43_44.bin --start_sector=131072 --lun=0 --num_sectors=172032 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x60000_Len2_DT_28_04_2018_13_43_58.bin --start_sector=393216 --lun=0 --num_sectors=2 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x60008_Len16_DT_28_04_2018_13_44_05.bin --start_sector=393224 --lun=0 --num_sectors=16 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x60018_Len1024_DT_28_04_2018_13_44_10.bin --start_sector=393240 --lun=0 --num_sectors=1024 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x60418_Len1024_DT_28_04_2018_13_44_14.bin --start_sector=394264 --lun=0 --num_sectors=1024 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x60818_Len1024_DT_28_04_2018_13_44_19.bin --start_sector=395288 --lun=0 --num_sectors=1024 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x60c18_Len1024_DT_28_04_2018_13_44_23.bin --start_sector=396312 --lun=0 --num_sectors=1024 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x61018_Len4096_DT_28_04_2018_13_44_28.bin --start_sector=397336 --lun=0 --num_sectors=4096 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x62018_Len4096_DT_28_04_2018_13_44_32.bin --start_sector=401432 --lun=0 --num_sectors=4096 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x63018_Len512_DT_28_04_2018_13_44_37.bin --start_sector=405528 --lun=0 --num_sectors=512 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x63218_Len512_DT_28_04_2018_13_44_41.bin --start_sector=406040 --lun=0 --num_sectors=512 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x63418_Len32768_DT_28_04_2018_13_44_46.bin --start_sector=406552 --lun=0 --num_sectors=32768 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x6b418_Len3072_DT_28_04_2018_13_44_55.bin --start_sector=439320 --lun=0 --num_sectors=3072 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x6c018_Len3072_DT_28_04_2018_13_45_02.bin --start_sector=442392 --lun=0 --num_sectors=3072 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x80000_Len64_DT_28_04_2018_13_45_07.bin --start_sector=524288 --lun=0 --num_sectors=64 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x80040_Len3072_DT_28_04_2018_13_45_13.bin --start_sector=524352 --lun=0 --num_sectors=3072 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x80c40_Len32_DT_28_04_2018_13_45_20.bin --start_sector=527424 --lun=0 --num_sectors=32 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xa0000_Len22528_DT_28_04_2018_13_45_25.bin --start_sector=655360 --lun=0 --num_sectors=22528 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xc0000_Len2048_DT_28_04_2018_13_45_32.bin --start_sector=786432 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xc0800_Len2048_DT_28_04_2018_13_45_38.bin --start_sector=788480 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xe1000_Len131072_DT_28_04_2018_13_45_44.bin --start_sector=921600 --lun=0 --num_sectors=131072 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x101000_Len2048_DT_28_04_2018_13_45_56.bin --start_sector=1052672 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x101800_Len6758400_DT_28_04_2018_13_46_07.bin --start_sector=1054720 --lun=0 --num_sectors=6758400 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x773800_Len1331200_DT_28_04_2018_13_51_47.bin --start_sector=7813120 --lun=0 --num_sectors=1331200 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x8c0000_Len307200_DT_28_04_2018_13_53_52.bin --start_sector=9175040 --lun=0 --num_sectors=307200 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x920000_Len16384_DT_28_04_2018_13_54_19.bin --start_sector=9568256 --lun=0 --num_sectors=16384 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x920000_Len16384_DT_28_04_2018_13_54_27.bin --start_sector=9568256 --lun=0 --num_sectors=16384 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x940000_Len65536_DT_28_04_2018_13_54_35.bin --start_sector=9699328 --lun=0 --num_sectors=65536 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x950000_Len2_DT_28_04_2018_13_54_50.bin --start_sector=9764864 --lun=0 --num_sectors=2 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x950008_Len307200_DT_28_04_2018_13_55_00.bin --start_sector=9764872 --lun=0 --num_sectors=307200 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x99b008_Len65536_DT_28_04_2018_13_55_24.bin --start_sector=10072072 --lun=0 --num_sectors=65536 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x9ab008_Len22528_DT_28_04_2018_13_55_40.bin --start_sector=10137608 --lun=0 --num_sectors=22528 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x9b0808_Len131072_DT_28_04_2018_13_55_47.bin --start_sector=10160136 --lun=0 --num_sectors=131072 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x9d0808_Len1024000_DT_28_04_2018_13_56_03.bin --start_sector=10291208 --lun=0 --num_sectors=1024000 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xaca808_Len2048_DT_28_04_2018_13_57_27.bin --start_sector=11315208 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xacb008_Len1024_DT_28_04_2018_13_57_35.bin --start_sector=11317256 --lun=0 --num_sectors=1024 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xacb408_Len64_DT_28_04_2018_13_57_44.bin --start_sector=11318280 --lun=0 --num_sectors=64 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xacb448_Len524288_DT_28_04_2018_13_58_09.bin --start_sector=11318344 --lun=0 --num_sectors=524288 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xb60000_Len64_DT_28_04_2018_13_58_48.bin --start_sector=11927552 --lun=0 --num_sectors=64 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xb80000_Len1024_DT_28_04_2018_13_59_02.bin --start_sector=12058624 --lun=0 --num_sectors=1024 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xb80400_Len2048_DT_28_04_2018_13_59_15.bin --start_sector=12059648 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xb80c00_Len65536_DT_28_04_2018_13_59_23.bin --start_sector=12061696 --lun=0 --num_sectors=65536 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xb90c00_Len1024_DT_28_04_2018_13_59_36.bin --start_sector=12127232 --lun=0 --num_sectors=1024 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xb91000_Len8192_DT_28_04_2018_13_59_51.bin --start_sector=12128256 --lun=0 --num_sectors=8192 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xba0000_Len2048_DT_28_04_2018_14_00_00.bin --start_sector=12189696 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xba0800_Len2048_DT_28_04_2018_14_00_08.bin --start_sector=12191744 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xba1000_Len2048_DT_28_04_2018_14_00_13.bin --start_sector=12193792 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xba1800_Len2048_DT_28_04_2018_14_00_22.bin --start_sector=12195840 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xba2000_Len2048_DT_28_04_2018_14_00_29.bin --start_sector=12197888 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xba2800_Len2048_DT_28_04_2018_14_00_34.bin --start_sector=12199936 --lun=0 --num_sectors=2048 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xbc0000_Len512_DT_28_04_2018_14_00_40.bin --start_sector=12320768 --lun=0 --num_sectors=512 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xbc0200_Len512_DT_28_04_2018_14_00_44.bin --start_sector=12321280 --lun=0 --num_sectors=512 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xbc0400_Len16_DT_28_04_2018_14_00_49.bin --start_sector=12321792 --lun=0 --num_sectors=16 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0xbc0410_Len131072_DT_28_04_2018_14_00_57.bin --start_sector=12321808 --lun=0 --num_sectors=131072 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x0_Len1_DT_28_04_2018_14_02_08.bin --start_sector=0 --lun=0 --num_sectors=1 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
fh_loader.exe --port=\\.\COM97 --sendxml=ResetToEDL.xml --search_path=.\ --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
正常回读镜像命令:
"C:\Program Files (x86)\Qualcomm\QPST\bin\QSaharaServer.exe" -s 13:prog_emmc_firehose_8917_ddr.mbn -p \\.\COM97
"C:\Program Files (x86)\Qualcomm\QPST\bin\fh_loader.exe" --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x20000_Len172032_DT_27_04_2018_15_54_56.bin --start_sector=131072 --lun=0 --num_sectors=172032 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
# 对应的 xml 文件项:
<program SECTOR_SIZE_IN_BYTES="512" file_sector_offset="0" filename="NON-HLOS.bin" label="modem" num_partition_sectors="172032" physical_partition_number="0" size_in_KB="86016.0" sparse="false" start_byte_hex="0x4000000" start_sector="131072"/>
"""
def main():
try:
tree = ET.parse("rawprogram0.xml") # 打开xml文档
#root = ET.fromstring(country_string) # 从字符串传递 xml
root = tree.getroot() # 获得root节点
except Exception, e:
print "Error:cannot parse file:rawprogram0.xml"
sys.exit(1)
#print root.tag, "---", root.attrib
#for child in root:
# print child.tag, "---", child.attrib
"""
###############################
# # 通过下标访问
print "*"*10
print root[0][1].text # 通过下标访问
print root[0].tag, root[0].text
print "*"*10
###############################
"""
# log 输出
readBackBAT = open("readBackBAT.bat",'w')
logFile = open("logFile.log",'w')
# 命令行: "C:\Program Files (x86)\Qualcomm\QPST\bin\QSaharaServer.exe" -s 13:prog_emmc_firehose_8917_ddr.mbn -p \\.\COM97
# 1. 下发 ddr 代理 mbn
''' 注意这句:里面的 \\ '''
downFireHoseCmD = '"C:\\Program Files (x86)\\Qualcomm\\QPST\\bin\\QSaharaServer.exe" -s 13:prog_emmc_firehose_8917_ddr.mbn -p \\\.\COM97'
print downFireHoseCmD
readBackBAT.write(downFireHoseCmD + "\r\n")
CmdProcess = subprocess.Popen(downFireHoseCmD, shell=True, stdout=logFile, stderr=subprocess.PIPE)
CmdProcess.wait()
#os._exit(0)
# 2. 回读各个分区,以分区名为各个分区命名
for program in root.findall('program'): # 找到 root 节点下的所有 program 节点
print("###################################################")
sSectorSize = program.get('SECTOR_SIZE_IN_BYTES')
#print sSectorSize
sFileSectorOffset = program.get('file_sector_offset')
#print sFileSectorOffset
sFileName = program.get('filename')
#print sFileName
sLabel = program.get('label')
print sLabel
sNumPartSector = program.get('num_partition_sectors')
#print sNumPartSector
sPhyPartNum = program.get('physical_partition_number')
#print sPhyPartNum
sSizeKB = program.get('size_in_KB')
#print sSizeKB
sSparse = program.get('sparse')
#print sSparse
sStartByte = program.get('start_byte_hex')
#print sStartByte
sStartSector = program.get('start_sector')
#print sStartSector
# 跳过读取 分区表及 userdata
#if(sLabel == "PrimaryGPT") or (sLabel == "BackupGPT") or (sLabel == "userdata"):
# print("skip label:%s"% sLabel)
# continue
print("============== ReadBack Start ==============")
# 命令行:
# "C:\Program Files (x86)\Qualcomm\QPST\bin\fh_loader.exe" --port=\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=ReadData_eMMC_Lun0_0x20000_Len172032_DT_27_04_2018_15_54_56.bin --start_sector=131072 --lun=0 --num_sectors=172032 --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc
# <program SECTOR_SIZE_IN_BYTES="512" file_sector_offset="0" filename="NON-HLOS.bin" label="modem" num_partition_sectors="172032" physical_partition_number="0" size_in_KB="86016.0" sparse="false" start_byte_hex="0x4000000" start_sector="131072"/>
''' 注意这句:里面的三 \\\ '''
readBackCmD = '"C:\\Program Files (x86)\\Qualcomm\\QPST\\bin\\fh_loader.exe" --port=\\\.\COM97 --search_path=.\ --convertprogram2read --sendimage=%s.bin --start_sector=%s --lun=0 --num_sectors=%s --noprompt --showpercentagecomplete --zlpawarehost=1 --memoryname=emmc' %(sLabel,sStartSector,sNumPartSector)
# print("The length of %s is %d" % (s,x))
print readBackCmD
readBackBAT.write(readBackCmD + "\r\n")
#print "C:\\Program Files (x86)\\Qualcomm\\QPST\\bin\\fh_loader.exe"
CmdProcess = subprocess.Popen(readBackCmD, shell=True, stdout=logFile, stderr=subprocess.PIPE)
CmdProcess.wait()
'''
if (sLabel == "modem"):
CmdProcess = subprocess.Popen(readBackCmD, shell=True, stdout=logFile, stderr=subprocess.PIPE)
CmdProcess.wait()
'''
program.set('filename',sLabel)
print("============== ReadBack End ==============")
logFile.close()
readBackBAT.close()
tree.write('rawprogram0_readback.xml')
###########################################################
# 脚本作用: 根据对应版本里的 rawprogram0.xml 分区表,
# 回读 qcom 手机的镜像
# 注:跳过了 userdata 及分区表
#
# 使用方法:
# 将以下文件放在与脚本同目录下
# rawprogram0.xml 来于手机里对应版本的分区表
# prog_emmc_firehose_8917_ddr.mbn 来于手机里对应版本
#
# 此同目录打开命令行,输入:
# python qcomreadback.py
#
# 注:注意端口,暂不支持自动检测所在端口,端口可以 QFIL 中查看
#
# 调试方法:
# readBackBAT.bat # 记录了使用的命令
# logFile.log # 记录了命令执行过程 log
#
# 后续方向:
# 一键下载,与对应目录版本比较?
# 使用 fh_loader.exe 单个下载?
# 命令 adb 单个下载?
###########################################################
if __name__ == "__main__":
main()