mirror of
https://git.codelinaro.org/clo/qsdk/oss/boot/u-boot-2016.git
synced 2025-12-10 07:44:53 +01:00
tools: add python3 compatible support on pack scripts
This patch updates the pack & pack-v2 scripts with python3 compatible support Change-Id: I2bf9a1cb2dedbdae94355aed4078d9f792fc7ba9 Signed-off-by: Ram Kumar D <quic_ramd@quicinc.com>
This commit is contained in:
parent
18f7f37a94
commit
94c5a1490b
2 changed files with 629 additions and 589 deletions
234
tools/pack.py
234
tools/pack.py
|
|
@ -110,9 +110,9 @@ except ImportError:
|
||||||
try:
|
try:
|
||||||
from ordereddict import OrderedDict
|
from ordereddict import OrderedDict
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "error: this script requires the 'ordereddict' class."
|
print("error: this script requires the 'ordereddict' class.")
|
||||||
print "Try 'pip install --user ordereddict'"
|
print("Try 'pip install --user ordereddict'")
|
||||||
print "Or 'easy_install --user ordereddict'"
|
print("Or 'easy_install --user ordereddict'")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def error(msg, ex=None):
|
def error(msg, ex=None):
|
||||||
|
|
@ -136,6 +136,20 @@ def roundup(value, roundto):
|
||||||
|
|
||||||
return ((value + roundto - 1) // roundto) * roundto
|
return ((value + roundto - 1) // roundto) * roundto
|
||||||
|
|
||||||
|
def hdrobj_byte2str(gpthdr):
|
||||||
|
temp_tuple = tuple(gpthdr)
|
||||||
|
gpthdr=[]
|
||||||
|
for x in temp_tuple:
|
||||||
|
if isinstance(x, bytes):
|
||||||
|
try:
|
||||||
|
x = x.decode("utf-8")
|
||||||
|
except:
|
||||||
|
x = 0
|
||||||
|
gpthdr.append(x)
|
||||||
|
|
||||||
|
gpthdr = tuple(gpthdr)
|
||||||
|
return gpthdr
|
||||||
|
|
||||||
class GPT(object):
|
class GPT(object):
|
||||||
GPTheader = namedtuple("GPTheader", "signature revision header_size"
|
GPTheader = namedtuple("GPTheader", "signature revision header_size"
|
||||||
" crc32 current_lba backup_lba first_usable_lba"
|
" crc32 current_lba backup_lba first_usable_lba"
|
||||||
|
|
@ -162,6 +176,7 @@ class GPT(object):
|
||||||
part_fp.seek(self.blocksize, os.SEEK_SET)
|
part_fp.seek(self.blocksize, os.SEEK_SET)
|
||||||
gptheader_str = part_fp.read(struct.calcsize(GPT.GPT_HEADER_FMT))
|
gptheader_str = part_fp.read(struct.calcsize(GPT.GPT_HEADER_FMT))
|
||||||
gptheader = struct.unpack(GPT.GPT_HEADER_FMT, gptheader_str)
|
gptheader = struct.unpack(GPT.GPT_HEADER_FMT, gptheader_str)
|
||||||
|
gptheader = hdrobj_byte2str(gptheader)
|
||||||
gptheader = GPT.GPTheader._make(gptheader)
|
gptheader = GPT.GPTheader._make(gptheader)
|
||||||
|
|
||||||
if gptheader.signature != GPT.GPT_SIGNATURE:
|
if gptheader.signature != GPT.GPT_SIGNATURE:
|
||||||
|
|
@ -190,6 +205,7 @@ class GPT(object):
|
||||||
for i in range(gptheader.num_part_entry):
|
for i in range(gptheader.num_part_entry):
|
||||||
gpt_table_str = part_fp.read(struct.calcsize(GPT.GPT_TABLE_FMT))
|
gpt_table_str = part_fp.read(struct.calcsize(GPT.GPT_TABLE_FMT))
|
||||||
gpt_table = struct.unpack(GPT.GPT_TABLE_FMT, gpt_table_str)
|
gpt_table = struct.unpack(GPT.GPT_TABLE_FMT, gpt_table_str)
|
||||||
|
gpt_table = hdrobj_byte2str(gpt_table)
|
||||||
gpt_table = GPT.GPTtable._make(gpt_table)
|
gpt_table = GPT.GPTtable._make(gpt_table)
|
||||||
|
|
||||||
block_start = gpt_table.first_lba
|
block_start = gpt_table.first_lba
|
||||||
|
|
@ -214,9 +230,9 @@ class GPT(object):
|
||||||
"""Returns a list of partitions present in the GPT."""
|
"""Returns a list of partitions present in the GPT."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(self.filename, "r") as part_fp:
|
with open(self.filename, "rb") as part_fp:
|
||||||
self.__validate_and_read_parts(part_fp)
|
self.__validate_and_read_parts(part_fp)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
error("error opening %s" % self.filename, e)
|
error("error opening %s" % self.filename, e)
|
||||||
|
|
||||||
return self.__partitions
|
return self.__partitions
|
||||||
|
|
@ -254,6 +270,7 @@ class MIBIB(object):
|
||||||
|
|
||||||
mheader_str = part_fp.read(struct.calcsize(MIBIB.HEADER_FMT))
|
mheader_str = part_fp.read(struct.calcsize(MIBIB.HEADER_FMT))
|
||||||
mheader = struct.unpack(MIBIB.HEADER_FMT, mheader_str)
|
mheader = struct.unpack(MIBIB.HEADER_FMT, mheader_str)
|
||||||
|
mheader = hdrobj_byte2str(mheader)
|
||||||
mheader = MIBIB.Header._make(mheader)
|
mheader = MIBIB.Header._make(mheader)
|
||||||
|
|
||||||
if (mheader.magic1 != MIBIB.HEADER_MAGIC1
|
if (mheader.magic1 != MIBIB.HEADER_MAGIC1
|
||||||
|
|
@ -271,6 +288,7 @@ class MIBIB(object):
|
||||||
part_fp.seek(self.pagesize, os.SEEK_SET)
|
part_fp.seek(self.pagesize, os.SEEK_SET)
|
||||||
mtable_str = part_fp.read(struct.calcsize(MIBIB.TABLE_FMT))
|
mtable_str = part_fp.read(struct.calcsize(MIBIB.TABLE_FMT))
|
||||||
mtable = struct.unpack(MIBIB.TABLE_FMT, mtable_str)
|
mtable = struct.unpack(MIBIB.TABLE_FMT, mtable_str)
|
||||||
|
mtable = hdrobj_byte2str(mtable)
|
||||||
mtable = MIBIB.Table._make(mtable)
|
mtable = MIBIB.Table._make(mtable)
|
||||||
|
|
||||||
if (mtable.magic1 != MIBIB.TABLE_MAGIC1
|
if (mtable.magic1 != MIBIB.TABLE_MAGIC1
|
||||||
|
|
@ -288,6 +306,7 @@ class MIBIB(object):
|
||||||
for i in range(mtable.numparts):
|
for i in range(mtable.numparts):
|
||||||
mentry_str = part_fp.read(struct.calcsize(MIBIB.ENTRY_FMT))
|
mentry_str = part_fp.read(struct.calcsize(MIBIB.ENTRY_FMT))
|
||||||
mentry = struct.unpack(MIBIB.ENTRY_FMT, mentry_str)
|
mentry = struct.unpack(MIBIB.ENTRY_FMT, mentry_str)
|
||||||
|
mentry = hdrobj_byte2str(mentry)
|
||||||
mentry = MIBIB.Entry._make(mentry)
|
mentry = MIBIB.Entry._make(mentry)
|
||||||
self.flash_flag = self.blocksize
|
self.flash_flag = self.blocksize
|
||||||
self.chip_flag = self.chipsize
|
self.chip_flag = self.chipsize
|
||||||
|
|
@ -311,10 +330,10 @@ class MIBIB(object):
|
||||||
"""Returns a list of partitions present in the MIBIB. CE """
|
"""Returns a list of partitions present in the MIBIB. CE """
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(self.filename, "r") as part_fp:
|
with open(self.filename, "rb") as part_fp:
|
||||||
self.__validate(part_fp)
|
self.__validate(part_fp)
|
||||||
self.__read_parts(part_fp)
|
self.__read_parts(part_fp)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
error("error opening %s" % self.filename, e)
|
error("error opening %s" % self.filename, e)
|
||||||
|
|
||||||
return self.__partitions
|
return self.__partitions
|
||||||
|
|
@ -517,7 +536,7 @@ class Flash_Script(FlashScript):
|
||||||
elif self.flash_type == "emmc":
|
elif self.flash_type == "emmc":
|
||||||
if size > 0:
|
if size > 0:
|
||||||
size = roundup(size, self.blocksize)
|
size = roundup(size, self.blocksize)
|
||||||
blk_cnt = size / self.blocksize
|
blk_cnt = int(size / self.blocksize)
|
||||||
self.append("mmc write $fileaddr 0x%08x %x" % (offset, blk_cnt))
|
self.append("mmc write $fileaddr 0x%08x %x" % (offset, blk_cnt))
|
||||||
|
|
||||||
def probe(self):
|
def probe(self):
|
||||||
|
|
@ -563,7 +582,7 @@ def sha1(message):
|
||||||
"""Returns SHA1 digest in hex format of the message."""
|
"""Returns SHA1 digest in hex format of the message."""
|
||||||
|
|
||||||
m = hashlib.sha1()
|
m = hashlib.sha1()
|
||||||
m.update(message)
|
m.update(message.encode('utf-8'))
|
||||||
return m.hexdigest()
|
return m.hexdigest()
|
||||||
|
|
||||||
class Pack(object):
|
class Pack(object):
|
||||||
|
|
@ -597,7 +616,7 @@ class Pack(object):
|
||||||
try:
|
try:
|
||||||
machid = int(section.find("./machid").text, 0)
|
machid = int(section.find("./machid").text, 0)
|
||||||
machid = "%x" % machid
|
machid = "%x" % machid
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
error("invalid value for machid, should be integer")
|
error("invalid value for machid, should be integer")
|
||||||
|
|
||||||
return machid
|
return machid
|
||||||
|
|
@ -612,7 +631,7 @@ class Pack(object):
|
||||||
return 0
|
return 0
|
||||||
try:
|
try:
|
||||||
return getsize(os.path.join(self.images_dname, filename))
|
return getsize(os.path.join(self.images_dname, filename))
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
error("error getting image size '%s'" % filename, e)
|
error("error getting image size '%s'" % filename, e)
|
||||||
|
|
||||||
def __get_part_info(self, partition):
|
def __get_part_info(self, partition):
|
||||||
|
|
@ -622,7 +641,7 @@ class Pack(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return self.partitions[partition]
|
return self.partitions[partition]
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __gen_flash_script_bootconfig(self, entries, partition, flinfo, script, part_section):
|
def __gen_flash_script_bootconfig(self, entries, partition, flinfo, script, part_section):
|
||||||
|
|
@ -706,20 +725,20 @@ class Pack(object):
|
||||||
if count > 2:
|
if count > 2:
|
||||||
error("More than 2 NAND images for NOR+NAND is not allowed")
|
error("More than 2 NAND images for NOR+NAND is not allowed")
|
||||||
elif img_size > part_info.length:
|
elif img_size > part_info.length:
|
||||||
print "img size is larger than part. len in '%s'" % section_conf
|
print("img size is larger than part. len in '%s'" % section_conf)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
if (skip_size_check == "" or wifi_fw_type < skip_size_check):
|
if (skip_size_check == "" or wifi_fw_type < skip_size_check):
|
||||||
if part_info != None:
|
if part_info != None:
|
||||||
if (img_size > 0):
|
if (img_size > 0):
|
||||||
if img_size > (part_info.length * self.flinfo.blocksize):
|
if img_size > (part_info.length * self.flinfo.blocksize):
|
||||||
print "img size is larger than part. len in '%s'" % section_conf
|
print("img size is larger than part. len in '%s'" % section_conf)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
print "EMMC: size check skipped for '%s'" % filename
|
print("EMMC: size check skipped for '%s'" % filename)
|
||||||
|
|
||||||
if part_info == None and self.flinfo.type != 'norplusnand':
|
if part_info == None and self.flinfo.type != 'norplusnand':
|
||||||
print "Flash type is norplusemmc"
|
print("Flash type is norplusemmc")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
script.start_if_or("machid", machid_list)
|
script.start_if_or("machid", machid_list)
|
||||||
|
|
@ -762,7 +781,7 @@ class Pack(object):
|
||||||
if ARCH_NAME != "ipq806x":
|
if ARCH_NAME != "ipq806x":
|
||||||
try:
|
try:
|
||||||
memory = section.find(".//memory").text
|
memory = section.find(".//memory").text
|
||||||
except AttributeError, e:
|
except AttributeError as e:
|
||||||
memory = "128M16"
|
memory = "128M16"
|
||||||
if memory_size != "default":
|
if memory_size != "default":
|
||||||
filename = "cdt-" + board + "_" + memory + "_LM" + memory_size + ".bin"
|
filename = "cdt-" + board + "_" + memory + "_LM" + memory_size + ".bin"
|
||||||
|
|
@ -810,17 +829,17 @@ class Pack(object):
|
||||||
if count > 2:
|
if count > 2:
|
||||||
error("More than 2 NAND images for NOR+NAND is not allowed")
|
error("More than 2 NAND images for NOR+NAND is not allowed")
|
||||||
elif img_size > part_info.length:
|
elif img_size > part_info.length:
|
||||||
print "img size is larger than part. len in '%s'" % section_conf
|
print("img size is larger than part. len in '%s'" % section_conf)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
if part_info != None:
|
if part_info != None:
|
||||||
if (img_size > 0):
|
if (img_size > 0):
|
||||||
if img_size > (part_info.length * self.flinfo.blocksize):
|
if img_size > (part_info.length * self.flinfo.blocksize):
|
||||||
print "img size is larger than part. len in '%s'" % section_conf
|
print("img size is larger than part. len in '%s'" % section_conf)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if part_info == None and self.flinfo.type != 'norplusnand':
|
if part_info == None and self.flinfo.type != 'norplusnand':
|
||||||
print "Flash type is norplusemmc"
|
print("Flash type is norplusemmc")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if machid:
|
if machid:
|
||||||
|
|
@ -971,20 +990,20 @@ class Pack(object):
|
||||||
if count > 2:
|
if count > 2:
|
||||||
error("More than 2 NAND images for NOR+NAND is not allowed")
|
error("More than 2 NAND images for NOR+NAND is not allowed")
|
||||||
elif img_size > part_info.length:
|
elif img_size > part_info.length:
|
||||||
print "img size is larger than part. len in '%s'" % section_conf
|
print("img size is larger than part. len in '%s'" % section_conf)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
if (skip_size_check == "" or wifi_fw_type < skip_size_check):
|
if (skip_size_check == "" or wifi_fw_type < skip_size_check):
|
||||||
if part_info != None:
|
if part_info != None:
|
||||||
if (img_size > 0):
|
if (img_size > 0):
|
||||||
if img_size > (part_info.length * self.flinfo.blocksize):
|
if img_size > (part_info.length * self.flinfo.blocksize):
|
||||||
print "img size is larger than part. len in '%s'" % section_conf
|
print("img size is larger than part. len in '%s'" % section_conf)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
print "EMMC: size check skipped for '%s'" % filename
|
print("EMMC: size check skipped for '%s'" % filename)
|
||||||
|
|
||||||
if part_info == None and self.flinfo.type != 'norplusnand':
|
if part_info == None and self.flinfo.type != 'norplusnand':
|
||||||
print "Flash type is norplusemmc"
|
print("Flash type is norplusemmc")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
script.start_if_or("machid", machid_list)
|
script.start_if_or("machid", machid_list)
|
||||||
|
|
@ -1073,17 +1092,17 @@ class Pack(object):
|
||||||
if count > 2:
|
if count > 2:
|
||||||
error("More than 2 NAND images for NOR+NAND is not allowed")
|
error("More than 2 NAND images for NOR+NAND is not allowed")
|
||||||
elif img_size > part_info.length:
|
elif img_size > part_info.length:
|
||||||
print "img size is larger than part. len in '%s'" % section_conf
|
print("img size is larger than part. len in '%s'" % section_conf)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
if part_info != None:
|
if part_info != None:
|
||||||
if (img_size > 0):
|
if (img_size > 0):
|
||||||
if img_size > (part_info.length * self.flinfo.blocksize):
|
if img_size > (part_info.length * self.flinfo.blocksize):
|
||||||
print "img size is larger than part. len in '%s'" % section_conf
|
print("img size is larger than part. len in '%s'" % section_conf)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if part_info == None and self.flinfo.type != 'norplusnand':
|
if part_info == None and self.flinfo.type != 'norplusnand':
|
||||||
print "Flash type is norplusemmc"
|
print("Flash type is norplusemmc")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if machid:
|
if machid:
|
||||||
|
|
@ -1166,17 +1185,17 @@ class Pack(object):
|
||||||
if count > 2:
|
if count > 2:
|
||||||
error("More than 2 NAND images for NOR+NAND is not allowed")
|
error("More than 2 NAND images for NOR+NAND is not allowed")
|
||||||
elif img_size > part_info.length:
|
elif img_size > part_info.length:
|
||||||
print "img size is larger than part. len in '%s'" % section_conf
|
print("img size is larger than part. len in '%s'" % section_conf)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
if part_info != None:
|
if part_info != None:
|
||||||
if (img_size > 0):
|
if (img_size > 0):
|
||||||
if img_size > (part_info.length * self.flinfo.blocksize):
|
if img_size > (part_info.length * self.flinfo.blocksize):
|
||||||
print "img size is larger than part. len in '%s'" % section_conf
|
print("img size is larger than part. len in '%s'" % section_conf)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if part_info == None and self.flinfo.type != 'norplusnand':
|
if part_info == None and self.flinfo.type != 'norplusnand':
|
||||||
print "Flash type is norplusemmc"
|
print("Flash type is norplusemmc")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if machid:
|
if machid:
|
||||||
|
|
@ -1420,27 +1439,27 @@ class Pack(object):
|
||||||
filename = section[9].text
|
filename = section[9].text
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
except AttributeError, e:
|
except AttributeError as e:
|
||||||
pass
|
pass
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
except IndexError, e:
|
except IndexError as e:
|
||||||
if index == (parts_length - 1):
|
if index == (parts_length - 1):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
partition = section[0].text
|
partition = section[0].text
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
diff_files = section.attrib['diff_files']
|
diff_files = section.attrib['diff_files']
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
try:
|
try:
|
||||||
diff_soc_ver_files = section.attrib['diff_soc_ver_files']
|
diff_soc_ver_files = section.attrib['diff_soc_ver_files']
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
if (multi_wifi_fw == "true" or tiny_16m == "true") and 'wififw_type_min' in section.attrib:
|
if (multi_wifi_fw == "true" or tiny_16m == "true") and 'wififw_type_min' in section.attrib:
|
||||||
wifi_fw_type_min = section.attrib['wififw_type_min']
|
wifi_fw_type_min = section.attrib['wififw_type_min']
|
||||||
wifi_fw_type_max = section.attrib['wififw_type_max']
|
wifi_fw_type_max = section.attrib['wififw_type_max']
|
||||||
|
|
@ -1455,8 +1474,8 @@ class Pack(object):
|
||||||
partition = section.attrib['label']
|
partition = section.attrib['label']
|
||||||
if lk == "true" and "u-boot" in filename:
|
if lk == "true" and "u-boot" in filename:
|
||||||
filename = filename.replace("u-boot", "lkboot")
|
filename = filename.replace("u-boot", "lkboot")
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
print "Skipping partition '%s'" % section.attrib['label']
|
print("Skipping partition '%s'" % section.attrib['label'])
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if diff_files == "true":
|
if diff_files == "true":
|
||||||
|
|
@ -1471,8 +1490,8 @@ class Pack(object):
|
||||||
partition = section.attrib['label']
|
partition = section.attrib['label']
|
||||||
if filename == "":
|
if filename == "":
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
print "Skipping partition '%s'" % section.attrib['label']
|
print("Skipping partition '%s'" % section.attrib['label'])
|
||||||
pass
|
pass
|
||||||
diff_files = "" # Clear for next iteration
|
diff_files = "" # Clear for next iteration
|
||||||
|
|
||||||
|
|
@ -1481,7 +1500,7 @@ class Pack(object):
|
||||||
ret = self.__gen_flash_script_bootconfig(entries, partition, flinfo, script, section)
|
ret = self.__gen_flash_script_bootconfig(entries, partition, flinfo, script, section)
|
||||||
if ret == 1:
|
if ret == 1:
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get machID
|
# Get machID
|
||||||
|
|
@ -1494,7 +1513,7 @@ class Pack(object):
|
||||||
if ret == 0:
|
if ret == 0:
|
||||||
return 0
|
return 0
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if partition == "0:BOOTLDR1":
|
if partition == "0:BOOTLDR1":
|
||||||
|
|
@ -1531,7 +1550,7 @@ class Pack(object):
|
||||||
return 0
|
return 0
|
||||||
wifi_fw_type = ""
|
wifi_fw_type = ""
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if img != None and 'soc_version' in img.attrib:
|
if img != None and 'soc_version' in img.attrib:
|
||||||
|
|
@ -1550,7 +1569,7 @@ class Pack(object):
|
||||||
|
|
||||||
soc_version = 0 # Clear soc_version for next iteration
|
soc_version = 0 # Clear soc_version for next iteration
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
imgs = section.findall('img_name')
|
imgs = section.findall('img_name')
|
||||||
|
|
@ -1606,8 +1625,8 @@ class Pack(object):
|
||||||
file_exists = 1
|
file_exists = 1
|
||||||
diff_soc_ver_files = 0 # Clear diff_soc_ver_files for next iteration
|
diff_soc_ver_files = 0 # Clear diff_soc_ver_files for next iteration
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
print "Skipping partition '%s'" % section.attrib['label']
|
print("Skipping partition '%s'" % section.attrib['label'])
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if section != None and filename != "" and section.get('filename_mem' + memory_size) != None:
|
if section != None and filename != "" and section.get('filename_mem' + memory_size) != None:
|
||||||
|
|
@ -1695,7 +1714,7 @@ class Pack(object):
|
||||||
if ARCH_NAME != "ipq806x":
|
if ARCH_NAME != "ipq806x":
|
||||||
try:
|
try:
|
||||||
memory = section.find(".//memory").text
|
memory = section.find(".//memory").text
|
||||||
except AttributeError, e:
|
except AttributeError as e:
|
||||||
memory = "128M16"
|
memory = "128M16"
|
||||||
|
|
||||||
if memory_size != "default":
|
if memory_size != "default":
|
||||||
|
|
@ -1744,7 +1763,7 @@ class Pack(object):
|
||||||
if ARCH_NAME != "ipq806x":
|
if ARCH_NAME != "ipq806x":
|
||||||
try:
|
try:
|
||||||
memory = section.find(".//memory").text
|
memory = section.find(".//memory").text
|
||||||
except AttributeError, e:
|
except AttributeError as e:
|
||||||
memory = "128M16"
|
memory = "128M16"
|
||||||
|
|
||||||
if memory_size != "default":
|
if memory_size != "default":
|
||||||
|
|
@ -1803,7 +1822,7 @@ class Pack(object):
|
||||||
if lk == "true":
|
if lk == "true":
|
||||||
section_conf = "lkboot"
|
section_conf = "lkboot"
|
||||||
else:
|
else:
|
||||||
print " Using u-boot..."
|
print(" Using u-boot...")
|
||||||
section_conf = "u-boot"
|
section_conf = "u-boot"
|
||||||
elif section_conf == "rootfs" and self.flash_type in ["nand", "nand-4k", "nand-audio", "nand-audio-4k", "norplusnand", "norplusnand-4k"]:
|
elif section_conf == "rootfs" and self.flash_type in ["nand", "nand-4k", "nand-audio", "nand-audio-4k", "norplusnand", "norplusnand-4k"]:
|
||||||
section_conf = "ubi"
|
section_conf = "ubi"
|
||||||
|
|
@ -1930,27 +1949,27 @@ class Pack(object):
|
||||||
try:
|
try:
|
||||||
if section[8].attrib['mode'] != MODE:
|
if section[8].attrib['mode'] != MODE:
|
||||||
filename = section[9].text
|
filename = section[9].text
|
||||||
except AttributeError, e:
|
except AttributeError as e:
|
||||||
pass
|
pass
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
pass
|
pass
|
||||||
except IndexError, e:
|
except IndexError as e:
|
||||||
if index == (parts_length - 1):
|
if index == (parts_length - 1):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
partition = section[0].text
|
partition = section[0].text
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
diff_files = section.attrib['diff_files']
|
diff_files = section.attrib['diff_files']
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
try:
|
try:
|
||||||
diff_soc_ver_files = section.attrib['diff_soc_ver_files']
|
diff_soc_ver_files = section.attrib['diff_soc_ver_files']
|
||||||
partition = section.attrib['label']
|
partition = section.attrib['label']
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
if (multi_wifi_fw == "true" or tiny_16m == "true") and 'wififw_type_min' in section.attrib:
|
if (multi_wifi_fw == "true" or tiny_16m == "true") and 'wififw_type_min' in section.attrib:
|
||||||
wifi_fw_type_min = section.attrib['wififw_type_min']
|
wifi_fw_type_min = section.attrib['wififw_type_min']
|
||||||
wifi_fw_type_max = section.attrib['wififw_type_max']
|
wifi_fw_type_max = section.attrib['wififw_type_max']
|
||||||
|
|
@ -1966,8 +1985,8 @@ class Pack(object):
|
||||||
partition = section.attrib['label']
|
partition = section.attrib['label']
|
||||||
if lk == "true" and "u-boot" in filename:
|
if lk == "true" and "u-boot" in filename:
|
||||||
filename = filename.replace("u-boot", "lkboot")
|
filename = filename.replace("u-boot", "lkboot")
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
print "Skipping partition '%s'" % section.attrib['label']
|
print("Skipping partition '%s'" % section.attrib['label'])
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if diff_files == "true":
|
if diff_files == "true":
|
||||||
|
|
@ -1982,9 +2001,8 @@ class Pack(object):
|
||||||
partition = section.attrib['label']
|
partition = section.attrib['label']
|
||||||
if filename == "":
|
if filename == "":
|
||||||
continue
|
continue
|
||||||
|
except KeyError as e:
|
||||||
except KeyError, e:
|
print("Skipping partition '%s'" % section.attrib['label'])
|
||||||
print "Skipping partition '%s'" % section.attrib['label']
|
|
||||||
pass
|
pass
|
||||||
diff_files = "" # Clear for next iteration
|
diff_files = "" # Clear for next iteration
|
||||||
|
|
||||||
|
|
@ -2012,7 +2030,7 @@ class Pack(object):
|
||||||
if image_type == "all" or section[8].attrib['image_type'] == image_type:
|
if image_type == "all" or section[8].attrib['image_type'] == image_type:
|
||||||
self.__gen_script_cdt(images, flinfo, root, section_conf, partition)
|
self.__gen_script_cdt(images, flinfo, root, section_conf, partition)
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if section_conf == "bootldr1":
|
if section_conf == "bootldr1":
|
||||||
|
|
@ -2020,7 +2038,7 @@ class Pack(object):
|
||||||
if image_type == "all" or section[8].attrib['image_type'] == image_type:
|
if image_type == "all" or section[8].attrib['image_type'] == image_type:
|
||||||
self.__gen_script_bootldr(images, flinfo, root, section_conf, partition)
|
self.__gen_script_bootldr(images, flinfo, root, section_conf, partition)
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if section_conf == "gpt" and QCN9224:
|
if section_conf == "gpt" and QCN9224:
|
||||||
|
|
@ -2055,7 +2073,7 @@ class Pack(object):
|
||||||
self.__gen_script_append_images(filename, soc_version, wifi_fw_type, images, flinfo, root, section_conf, partition)
|
self.__gen_script_append_images(filename, soc_version, wifi_fw_type, images, flinfo, root, section_conf, partition)
|
||||||
wififw_type = ""
|
wififw_type = ""
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if img != None and 'soc_version' in img.attrib:
|
if img != None and 'soc_version' in img.attrib:
|
||||||
|
|
@ -2079,7 +2097,7 @@ class Pack(object):
|
||||||
file_exists = 1
|
file_exists = 1
|
||||||
soc_version = 0 # Clear soc_version for next iteration
|
soc_version = 0 # Clear soc_version for next iteration
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
imgs = section.findall('img_name')
|
imgs = section.findall('img_name')
|
||||||
|
|
@ -2143,8 +2161,8 @@ class Pack(object):
|
||||||
|
|
||||||
diff_soc_ver_files = 0 # Clear diff_soc_ver_files for next iteration
|
diff_soc_ver_files = 0 # Clear diff_soc_ver_files for next iteration
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
print "Skipping partition '%s'" % section.attrib['label']
|
print("Skipping partition '%s'" % section.attrib['label'])
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if section != None and filename != "" and section.get('filename_mem' + memory_size) != None:
|
if section != None and filename != "" and section.get('filename_mem' + memory_size) != None:
|
||||||
|
|
@ -2169,7 +2187,7 @@ class Pack(object):
|
||||||
return 0
|
return 0
|
||||||
wifi_fw_type = ""
|
wifi_fw_type = ""
|
||||||
continue
|
continue
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -2181,7 +2199,7 @@ class Pack(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
its_fp = open(self.its_fname, "wb")
|
its_fp = open(self.its_fname, "wb")
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
error("error opening its file '%s'" % self.its_fname, e)
|
error("error opening its file '%s'" % self.its_fname, e)
|
||||||
|
|
||||||
desc = "Flashing %s %x %x"
|
desc = "Flashing %s %x %x"
|
||||||
|
|
@ -2197,6 +2215,8 @@ class Pack(object):
|
||||||
image_data = "".join(image_data)
|
image_data = "".join(image_data)
|
||||||
its_data = its_tmpl.substitute(desc=desc, images=image_data)
|
its_data = its_tmpl.substitute(desc=desc, images=image_data)
|
||||||
|
|
||||||
|
if sys.version_info.major >= 3:
|
||||||
|
its_data = bytes(its_data, 'utf-8')
|
||||||
its_fp.write(its_data)
|
its_fp.write(its_data)
|
||||||
its_fp.close()
|
its_fp.close()
|
||||||
|
|
||||||
|
|
@ -2204,9 +2224,9 @@ class Pack(object):
|
||||||
cmd = [SRC_DIR + "/mkimage", "-f", self.its_fname, self.img_fname]
|
cmd = [SRC_DIR + "/mkimage", "-f", self.its_fname, self.img_fname]
|
||||||
ret = subprocess.call(cmd)
|
ret = subprocess.call(cmd)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
print ret
|
print(ret)
|
||||||
error("failed to create u-boot image from script")
|
error("failed to create u-boot image from script")
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
error("error executing mkimage", e)
|
error("error executing mkimage", e)
|
||||||
|
|
||||||
def __create_fnames(self):
|
def __create_fnames(self):
|
||||||
|
|
@ -2338,7 +2358,7 @@ class Pack(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
script_fp.write(script.dumps())
|
script_fp.write(script.dumps())
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
error("error writing to script '%s'" % script_fp.name, e)
|
error("error writing to script '%s'" % script_fp.name, e)
|
||||||
|
|
||||||
script_fp.close()
|
script_fp.close()
|
||||||
|
|
@ -2374,7 +2394,7 @@ class Pack(object):
|
||||||
if ftype.lower() == "norplusemmc":
|
if ftype.lower() == "norplusemmc":
|
||||||
ftype = "emmc"
|
ftype = "emmc"
|
||||||
|
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
error("invalid flash info in section '%s'" % board_section.find('machid').text, e)
|
error("invalid flash info in section '%s'" % board_section.find('machid').text, e)
|
||||||
|
|
||||||
flinfo = FlashInfo(ftype, pagesize, blocksize, chipsize)
|
flinfo = FlashInfo(ftype, pagesize, blocksize, chipsize)
|
||||||
|
|
@ -2478,7 +2498,7 @@ class Pack(object):
|
||||||
if ftype in ["nand-4k", "nand-audio", "nand-audio-4k"]:
|
if ftype in ["nand-4k", "nand-audio", "nand-audio-4k"]:
|
||||||
ftype = "nand"
|
ftype = "nand"
|
||||||
|
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
error("invalid flash info in section '%s'" % board_section.find('machid').text, e)
|
error("invalid flash info in section '%s'" % board_section.find('machid').text, e)
|
||||||
|
|
||||||
blocksize = pages_per_block * pagesize
|
blocksize = pages_per_block * pagesize
|
||||||
|
|
@ -2506,7 +2526,7 @@ class Pack(object):
|
||||||
if ret:
|
if ret:
|
||||||
ret = self.__process_board_flash_emmc("norplusemmc", images, root)
|
ret = self.__process_board_flash_emmc("norplusemmc", images, root)
|
||||||
return ret
|
return ret
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
error("error getting board info in section '%s'" % board_section.find('machid').text, e)
|
error("error getting board info in section '%s'" % board_section.find('machid').text, e)
|
||||||
|
|
||||||
def main_bconf(self, flash_type, images_dname, out_fname, root):
|
def main_bconf(self, flash_type, images_dname, out_fname, root):
|
||||||
|
|
@ -2523,7 +2543,7 @@ class Pack(object):
|
||||||
self.__create_fnames()
|
self.__create_fnames()
|
||||||
try:
|
try:
|
||||||
os.unlink(self.scr_fname)
|
os.unlink(self.scr_fname)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
images = []
|
images = []
|
||||||
|
|
@ -2571,7 +2591,7 @@ class ArgParser(object):
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
try:
|
try:
|
||||||
opts, args = getopt(sys.argv[1:], "", ["arch=", "fltype=", "srcPath=", "inImage=", "outImage=", "image_type=", "memory=", "lk", "skip_4k_nand", "atf", "qcn6122", "multi_wifi_fw"])
|
opts, args = getopt(sys.argv[1:], "", ["arch=", "fltype=", "srcPath=", "inImage=", "outImage=", "image_type=", "memory=", "lk", "skip_4k_nand", "atf", "qcn6122", "multi_wifi_fw"])
|
||||||
except GetoptError, e:
|
except GetoptError as e:
|
||||||
raise UsageError(e.msg)
|
raise UsageError(e.msg)
|
||||||
|
|
||||||
for option, value in opts:
|
for option, value in opts:
|
||||||
|
|
@ -2653,32 +2673,32 @@ class ArgParser(object):
|
||||||
|
|
||||||
msg -- string, the error message
|
msg -- string, the error message
|
||||||
"""
|
"""
|
||||||
print "pack: %s" % msg
|
print("pack: %s" % msg)
|
||||||
print
|
print()
|
||||||
print "Usage:"
|
print("Usage:")
|
||||||
print "python pack_hk.py [options] [Value] ..."
|
print("python pack_hk.py [options] [Value] ...")
|
||||||
print
|
print()
|
||||||
print "options:"
|
print("options:")
|
||||||
print " --arch \tARCH_TYPE [ipq40xx/ipq806x/ipq807x/ipq807x_64/ipq6018/ipq6018_64/ipq5018/ipq5018_64/ipq9574/ipq9574_64/ipq5332/ipq5332_64]"
|
print(" --arch \tARCH_TYPE [ipq40xx/ipq806x/ipq807x/ipq807x_64/ipq6018/ipq6018_64/ipq5018/ipq5018_64/ipq9574/ipq9574_64/ipq5332/ipq5332_64]")
|
||||||
print
|
print()
|
||||||
print " --fltype \tFlash Type [nor/tiny-nor/nand/emmc/norplusnand/norplusemmc/tiny-nor-debug]"
|
print(" --fltype \tFlash Type [nor/tiny-nor/nand/emmc/norplusnand/norplusemmc/tiny-nor-debug]")
|
||||||
print " \t\tMultiple flashtypes can be passed by a comma separated string"
|
print(" \t\tMultiple flashtypes can be passed by a comma separated string")
|
||||||
print " \t\tDefault is all. i.e If \"--fltype\" is not passed image for all the flash-type will be created.\n"
|
print(" \t\tDefault is all. i.e If \"--fltype\" is not passed image for all the flash-type will be created.\n")
|
||||||
print " --srcPath \tPath to the directory containg the meta scripts and configs"
|
print(" --srcPath \tPath to the directory containg the meta scripts and configs")
|
||||||
print
|
print()
|
||||||
print " --inImage \tPath to the direcory containg binaries and images needed for singleimage"
|
print(" --inImage \tPath to the direcory containg binaries and images needed for singleimage")
|
||||||
print
|
print()
|
||||||
print " --outImage \tPath to the directory where single image will be generated"
|
print(" --outImage \tPath to the directory where single image will be generated")
|
||||||
print
|
print()
|
||||||
print " --memory \tMemory size for low memory profile"
|
print(" --memory \tMemory size for low memory profile")
|
||||||
print " \t\tIf it is not specified CDTs with default memory size are taken for single-image packing.\n"
|
print(" \t\tIf it is not specified CDTs with default memory size are taken for single-image packing.\n")
|
||||||
print " \t\tIf specified, CDTs created with specified memory size will be used for single-image.\n"
|
print(" \t\tIf specified, CDTs created with specified memory size will be used for single-image.\n")
|
||||||
print
|
print()
|
||||||
print " --lk \t\tReplace u-boot with lkboot for appsbl"
|
print(" --lk \t\tReplace u-boot with lkboot for appsbl")
|
||||||
print " --atf \t\tReplace tz with atf for QSEE partition"
|
print(" --atf \t\tReplace tz with atf for QSEE partition")
|
||||||
print " --skip_4k_nand \tskip generating 4k nand images"
|
print(" --skip_4k_nand \tskip generating 4k nand images")
|
||||||
print " \t\tThis Argument does not take any value"
|
print(" \t\tThis Argument does not take any value")
|
||||||
print "Pack Version: %s" % version
|
print("Pack Version: %s" % version)
|
||||||
|
|
||||||
def gen_kernelboot_img(parser):
|
def gen_kernelboot_img(parser):
|
||||||
"""Generate kernelboot.img needed by LK bootloader"""
|
"""Generate kernelboot.img needed by LK bootloader"""
|
||||||
|
|
@ -2731,13 +2751,13 @@ def gen_kernelboot_img(parser):
|
||||||
cmd = [SKALES_DIR + "/dtbTool -o " + TMP_DIR + "/qcom-" + BOARD_NAME + "-dt.img " + TMP_DIR]
|
cmd = [SKALES_DIR + "/dtbTool -o " + TMP_DIR + "/qcom-" + BOARD_NAME + "-dt.img " + TMP_DIR]
|
||||||
ret = subprocess.call(cmd, shell=True)
|
ret = subprocess.call(cmd, shell=True)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
print ret
|
print(ret)
|
||||||
error("Error executing dtbTools")
|
error("Error executing dtbTools")
|
||||||
|
|
||||||
cmd = ["gzip -9 " + TMP_DIR + "/Image"]
|
cmd = ["gzip -9 " + TMP_DIR + "/Image"]
|
||||||
ret = subprocess.call(cmd, shell=True)
|
ret = subprocess.call(cmd, shell=True)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
print ret
|
print(ret)
|
||||||
error("Error executing gzip")
|
error("Error executing gzip")
|
||||||
|
|
||||||
cmd = [SKALES_DIR + "/mkbootimg",
|
cmd = [SKALES_DIR + "/mkbootimg",
|
||||||
|
|
@ -2748,11 +2768,11 @@ def gen_kernelboot_img(parser):
|
||||||
"--base=" + BASE_ADDR]
|
"--base=" + BASE_ADDR]
|
||||||
ret = subprocess.call(cmd)
|
ret = subprocess.call(cmd)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
print ret
|
print(ret)
|
||||||
error("Error executing mkbootimg")
|
error("Error executing mkbootimg")
|
||||||
|
|
||||||
rmtree(TMP_DIR)
|
rmtree(TMP_DIR)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
error("error generating kernelboot.img", e)
|
error("error generating kernelboot.img", e)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
@ -2765,7 +2785,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
parser = ArgParser()
|
parser = ArgParser()
|
||||||
parser.parse(sys.argv)
|
parser.parse(sys.argv)
|
||||||
except UsageError, e:
|
except UsageError as e:
|
||||||
parser.usage(e.args[0])
|
parser.usage(e.args[0])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
||||||
984
tools/pack_v2.py
984
tools/pack_v2.py
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue