2018-01-11 22:20:33 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# pylint: disable=C0111,C0326,C0103
|
|
|
|
|
2018-02-03 21:25:26 +00:00
|
|
|
"""Download a given firmware file."""
|
|
|
|
|
2018-01-11 22:20:33 +00:00
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import sys
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2018-01-11 22:20:33 +00:00
|
|
|
import tcllib
|
2018-02-02 02:33:53 +00:00
|
|
|
import tcllib.argparser
|
2018-02-05 12:20:15 +00:00
|
|
|
from tcllib.xmltools import pretty_xml
|
2018-01-11 22:20:33 +00:00
|
|
|
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2018-01-11 22:20:33 +00:00
|
|
|
fc = tcllib.FotaCheck()
|
|
|
|
fc.serid = "3531510"
|
2018-02-03 20:24:36 +00:00
|
|
|
#fc.osvs = "7.1.1"
|
2018-01-11 22:20:33 +00:00
|
|
|
|
2018-01-30 17:31:05 +00:00
|
|
|
dpdesc = """
|
2018-01-11 22:20:33 +00:00
|
|
|
Downloads the given firmware file.
|
|
|
|
"""
|
2018-02-02 02:33:53 +00:00
|
|
|
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
|
2018-01-11 22:20:33 +00:00
|
|
|
dp.add_argument("prd", nargs=1, help="CU Reference #, e.g. PRD-63117-011")
|
|
|
|
dp.add_argument("targetversion", nargs=1, help="Firmware version to download, e.g. AAN990")
|
|
|
|
dp.add_argument("fwid", nargs=1, help="Numeric firmware file id, e.g. 268932")
|
|
|
|
dp.add_argument("-o", "--ota", metavar="FROMVERSION", help="download OTA from specified version (switches mode to OTA)", type=str)
|
|
|
|
dp.add_argument("-i", "--imei", help="use specified IMEI instead of default", type=str)
|
|
|
|
dp.add_argument("-t", "--type", help="download device (default to desktop)", default="desktop", type=str, choices=["desktop", "mobile"])
|
2018-01-30 17:31:05 +00:00
|
|
|
dp.add_argument("--rawmode", help="override --mode with raw value (2=OTA, 4=FULL)", metavar="MODE")
|
|
|
|
dp.add_argument("--rawcltp", help="override --type with raw value (10=MOBILE, 2010=DESKTOP)", metavar="CLTP")
|
2018-01-11 22:20:33 +00:00
|
|
|
args = dp.parse_args(sys.argv[1:])
|
|
|
|
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2018-01-11 22:20:33 +00:00
|
|
|
def sel_mode(defaultmode, rawval):
|
2018-02-03 21:25:26 +00:00
|
|
|
"""Handle custom mode."""
|
2018-01-11 22:20:33 +00:00
|
|
|
if rawval:
|
|
|
|
enum = tcllib.default_enum("MODE", {"RAW": rawval})
|
|
|
|
return enum.RAW
|
|
|
|
return defaultmode
|
|
|
|
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2018-01-11 22:20:33 +00:00
|
|
|
def sel_cltp(txtmode, rawval):
|
2018-02-03 21:25:26 +00:00
|
|
|
"""Handle custom CLTP."""
|
2018-01-11 22:20:33 +00:00
|
|
|
if rawval:
|
|
|
|
enum = tcllib.default_enum("CLTP", {"RAW": rawval})
|
|
|
|
return enum.RAW
|
|
|
|
if txtmode == "mobile":
|
|
|
|
return fc.CLTP.MOBILE
|
|
|
|
return fc.CLTP.DESKTOP
|
|
|
|
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2018-01-11 22:20:33 +00:00
|
|
|
if args.imei:
|
|
|
|
print("Use specified IMEI: {}".format(args.imei))
|
|
|
|
fc.serid = args.imei
|
|
|
|
|
|
|
|
fc.curef = args.prd[0]
|
|
|
|
if args.ota:
|
2018-02-03 20:24:36 +00:00
|
|
|
fc.fv = args.ota[0]
|
2018-01-11 22:20:33 +00:00
|
|
|
fc.mode = sel_mode(fc.MODE.OTA, args.rawmode)
|
|
|
|
else:
|
2018-02-03 20:24:36 +00:00
|
|
|
fc.fv = args.targetversion[0]
|
2018-01-11 22:20:33 +00:00
|
|
|
fc.mode = sel_mode(fc.MODE.FULL, args.rawmode)
|
|
|
|
fc.cltp = sel_cltp(args.type, args.rawcltp)
|
|
|
|
|
|
|
|
print("Mode: {}".format(fc.mode.value))
|
|
|
|
print("CLTP: {}".format(fc.cltp.value))
|
|
|
|
|
|
|
|
fv = fc.fv
|
|
|
|
tv = args.targetversion[0]
|
|
|
|
fw_id = args.fwid[0]
|
|
|
|
req_xml = fc.do_request(fc.curef, fv, tv, fw_id)
|
2018-02-05 12:20:15 +00:00
|
|
|
print(pretty_xml(req_xml))
|
2018-01-11 23:31:39 +00:00
|
|
|
fileid, fileurl, slaves, encslaves, s3_fileurl, s3_slaves = fc.parse_request(req_xml)
|
2018-01-11 22:20:33 +00:00
|
|
|
|
|
|
|
for s in slaves:
|
|
|
|
print("http://{}{}".format(s, fileurl))
|
|
|
|
|
2018-01-11 23:31:39 +00:00
|
|
|
for s in s3_slaves:
|
|
|
|
print("http://{}{}".format(s, s3_fileurl))
|
|
|
|
|
2018-01-11 22:20:33 +00:00
|
|
|
if fc.mode == fc.MODE.FULL:
|
|
|
|
header = fc.do_encrypt_header(random.choice(encslaves), fileurl)
|
|
|
|
headname = "header_{}.bin".format(tv)
|
|
|
|
headdir = "headers"
|
|
|
|
if not os.path.exists(headdir):
|
|
|
|
os.makedirs(headdir)
|
|
|
|
if len(header) == 4194320:
|
|
|
|
print("Header length check passed. Writing to {}.".format(headname))
|
|
|
|
with open(os.path.join(headdir, headname), "wb") as f:
|
|
|
|
f.write(header)
|
|
|
|
else:
|
|
|
|
print("Header length invalid ({}).".format(len(header)))
|
|
|
|
|
|
|
|
tcllib.FotaCheck.write_info_if_dumps_found()
|