From 94c5a1490bffbd073f2edf497af9929d9f50d0fb Mon Sep 17 00:00:00 2001 From: Ram Kumar D Date: Wed, 2 Aug 2023 14:43:43 +0530 Subject: [PATCH] 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 --- tools/pack.py | 234 +++++------ tools/pack_v2.py | 984 ++++++++++++++++++++++++----------------------- 2 files changed, 629 insertions(+), 589 deletions(-) diff --git a/tools/pack.py b/tools/pack.py index bfd4fb435a..aa9f727625 100644 --- a/tools/pack.py +++ b/tools/pack.py @@ -110,9 +110,9 @@ except ImportError: try: from ordereddict import OrderedDict except ImportError: - print "error: this script requires the 'ordereddict' class." - print "Try 'pip install --user ordereddict'" - print "Or 'easy_install --user ordereddict'" + print("error: this script requires the 'ordereddict' class.") + print("Try 'pip install --user ordereddict'") + print("Or 'easy_install --user ordereddict'") sys.exit(1) def error(msg, ex=None): @@ -136,6 +136,20 @@ def roundup(value, 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): GPTheader = namedtuple("GPTheader", "signature revision header_size" " crc32 current_lba backup_lba first_usable_lba" @@ -162,6 +176,7 @@ class GPT(object): part_fp.seek(self.blocksize, os.SEEK_SET) gptheader_str = part_fp.read(struct.calcsize(GPT.GPT_HEADER_FMT)) gptheader = struct.unpack(GPT.GPT_HEADER_FMT, gptheader_str) + gptheader = hdrobj_byte2str(gptheader) gptheader = GPT.GPTheader._make(gptheader) if gptheader.signature != GPT.GPT_SIGNATURE: @@ -190,6 +205,7 @@ class GPT(object): for i in range(gptheader.num_part_entry): 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 = hdrobj_byte2str(gpt_table) gpt_table = GPT.GPTtable._make(gpt_table) block_start = gpt_table.first_lba @@ -214,9 +230,9 @@ class GPT(object): """Returns a list of partitions present in the GPT.""" try: - with open(self.filename, "r") as part_fp: + with open(self.filename, "rb") as part_fp: self.__validate_and_read_parts(part_fp) - except IOError, e: + except IOError as e: error("error opening %s" % self.filename, e) return self.__partitions @@ -254,6 +270,7 @@ class MIBIB(object): mheader_str = part_fp.read(struct.calcsize(MIBIB.HEADER_FMT)) mheader = struct.unpack(MIBIB.HEADER_FMT, mheader_str) + mheader = hdrobj_byte2str(mheader) mheader = MIBIB.Header._make(mheader) if (mheader.magic1 != MIBIB.HEADER_MAGIC1 @@ -271,6 +288,7 @@ class MIBIB(object): part_fp.seek(self.pagesize, os.SEEK_SET) mtable_str = part_fp.read(struct.calcsize(MIBIB.TABLE_FMT)) mtable = struct.unpack(MIBIB.TABLE_FMT, mtable_str) + mtable = hdrobj_byte2str(mtable) mtable = MIBIB.Table._make(mtable) if (mtable.magic1 != MIBIB.TABLE_MAGIC1 @@ -288,6 +306,7 @@ class MIBIB(object): for i in range(mtable.numparts): mentry_str = part_fp.read(struct.calcsize(MIBIB.ENTRY_FMT)) mentry = struct.unpack(MIBIB.ENTRY_FMT, mentry_str) + mentry = hdrobj_byte2str(mentry) mentry = MIBIB.Entry._make(mentry) self.flash_flag = self.blocksize self.chip_flag = self.chipsize @@ -311,10 +330,10 @@ class MIBIB(object): """Returns a list of partitions present in the MIBIB. CE """ try: - with open(self.filename, "r") as part_fp: + with open(self.filename, "rb") as part_fp: self.__validate(part_fp) self.__read_parts(part_fp) - except IOError, e: + except IOError as e: error("error opening %s" % self.filename, e) return self.__partitions @@ -517,7 +536,7 @@ class Flash_Script(FlashScript): elif self.flash_type == "emmc": if size > 0: 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)) def probe(self): @@ -563,7 +582,7 @@ def sha1(message): """Returns SHA1 digest in hex format of the message.""" m = hashlib.sha1() - m.update(message) + m.update(message.encode('utf-8')) return m.hexdigest() class Pack(object): @@ -597,7 +616,7 @@ class Pack(object): try: machid = int(section.find("./machid").text, 0) machid = "%x" % machid - except ValueError, e: + except ValueError as e: error("invalid value for machid, should be integer") return machid @@ -612,7 +631,7 @@ class Pack(object): return 0 try: return getsize(os.path.join(self.images_dname, filename)) - except OSError, e: + except OSError as e: error("error getting image size '%s'" % filename, e) def __get_part_info(self, partition): @@ -622,7 +641,7 @@ class Pack(object): """ try: return self.partitions[partition] - except KeyError, e: + except KeyError as e: return None def __gen_flash_script_bootconfig(self, entries, partition, flinfo, script, part_section): @@ -706,20 +725,20 @@ class Pack(object): if count > 2: error("More than 2 NAND images for NOR+NAND is not allowed") 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 else: if (skip_size_check == "" or wifi_fw_type < skip_size_check): if part_info != None: if (img_size > 0): 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 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': - print "Flash type is norplusemmc" + print("Flash type is norplusemmc") return 1 script.start_if_or("machid", machid_list) @@ -762,7 +781,7 @@ class Pack(object): if ARCH_NAME != "ipq806x": try: memory = section.find(".//memory").text - except AttributeError, e: + except AttributeError as e: memory = "128M16" if memory_size != "default": filename = "cdt-" + board + "_" + memory + "_LM" + memory_size + ".bin" @@ -810,17 +829,17 @@ class Pack(object): if count > 2: error("More than 2 NAND images for NOR+NAND is not allowed") 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 else: if part_info != None: if (img_size > 0): 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 if part_info == None and self.flinfo.type != 'norplusnand': - print "Flash type is norplusemmc" + print("Flash type is norplusemmc") continue if machid: @@ -971,20 +990,20 @@ class Pack(object): if count > 2: error("More than 2 NAND images for NOR+NAND is not allowed") 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 else: if (skip_size_check == "" or wifi_fw_type < skip_size_check): if part_info != None: if (img_size > 0): 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 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': - print "Flash type is norplusemmc" + print("Flash type is norplusemmc") return 1 script.start_if_or("machid", machid_list) @@ -1073,17 +1092,17 @@ class Pack(object): if count > 2: error("More than 2 NAND images for NOR+NAND is not allowed") 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 else: if part_info != None: if (img_size > 0): 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 if part_info == None and self.flinfo.type != 'norplusnand': - print "Flash type is norplusemmc" + print("Flash type is norplusemmc") continue if machid: @@ -1166,17 +1185,17 @@ class Pack(object): if count > 2: error("More than 2 NAND images for NOR+NAND is not allowed") 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 else: if part_info != None: if (img_size > 0): 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 if part_info == None and self.flinfo.type != 'norplusnand': - print "Flash type is norplusemmc" + print("Flash type is norplusemmc") return 1 if machid: @@ -1420,27 +1439,27 @@ class Pack(object): filename = section[9].text else: pass - except AttributeError, e: + except AttributeError as e: pass - except KeyError, e: + except KeyError as e: pass else: continue - except IndexError, e: + except IndexError as e: if index == (parts_length - 1): return else: continue - except KeyError, e: + except KeyError as e: continue partition = section[0].text else: try: diff_files = section.attrib['diff_files'] - except KeyError, e: + except KeyError as e: try: 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: wifi_fw_type_min = section.attrib['wififw_type_min'] wifi_fw_type_max = section.attrib['wififw_type_max'] @@ -1455,8 +1474,8 @@ class Pack(object): partition = section.attrib['label'] if lk == "true" and "u-boot" in filename: filename = filename.replace("u-boot", "lkboot") - except KeyError, e: - print "Skipping partition '%s'" % section.attrib['label'] + except KeyError as e: + print("Skipping partition '%s'" % section.attrib['label']) pass if diff_files == "true": @@ -1471,8 +1490,8 @@ class Pack(object): partition = section.attrib['label'] if filename == "": continue - except KeyError, e: - print "Skipping partition '%s'" % section.attrib['label'] + except KeyError as e: + print("Skipping partition '%s'" % section.attrib['label']) pass diff_files = "" # Clear for next iteration @@ -1481,7 +1500,7 @@ class Pack(object): ret = self.__gen_flash_script_bootconfig(entries, partition, flinfo, script, section) if ret == 1: continue - except KeyError, e: + except KeyError as e: continue # Get machID @@ -1494,7 +1513,7 @@ class Pack(object): if ret == 0: return 0 continue - except KeyError, e: + except KeyError as e: continue if partition == "0:BOOTLDR1": @@ -1531,7 +1550,7 @@ class Pack(object): return 0 wifi_fw_type = "" continue - except KeyError, e: + except KeyError as e: continue 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 continue - except KeyError, e: + except KeyError as e: continue imgs = section.findall('img_name') @@ -1606,8 +1625,8 @@ class Pack(object): file_exists = 1 diff_soc_ver_files = 0 # Clear diff_soc_ver_files for next iteration continue - except KeyError, e: - print "Skipping partition '%s'" % section.attrib['label'] + except KeyError as e: + print("Skipping partition '%s'" % section.attrib['label']) pass if section != None and filename != "" and section.get('filename_mem' + memory_size) != None: @@ -1695,7 +1714,7 @@ class Pack(object): if ARCH_NAME != "ipq806x": try: memory = section.find(".//memory").text - except AttributeError, e: + except AttributeError as e: memory = "128M16" if memory_size != "default": @@ -1744,7 +1763,7 @@ class Pack(object): if ARCH_NAME != "ipq806x": try: memory = section.find(".//memory").text - except AttributeError, e: + except AttributeError as e: memory = "128M16" if memory_size != "default": @@ -1803,7 +1822,7 @@ class Pack(object): if lk == "true": section_conf = "lkboot" else: - print " Using u-boot..." + print(" Using 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"]: section_conf = "ubi" @@ -1930,27 +1949,27 @@ class Pack(object): try: if section[8].attrib['mode'] != MODE: filename = section[9].text - except AttributeError, e: + except AttributeError as e: pass - except KeyError, e: + except KeyError as e: pass - except IndexError, e: + except IndexError as e: if index == (parts_length - 1): return else: continue - except KeyError, e: + except KeyError as e: continue partition = section[0].text else: try: diff_files = section.attrib['diff_files'] - except KeyError, e: + except KeyError as e: try: diff_soc_ver_files = section.attrib['diff_soc_ver_files'] 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: wifi_fw_type_min = section.attrib['wififw_type_min'] wifi_fw_type_max = section.attrib['wififw_type_max'] @@ -1966,8 +1985,8 @@ class Pack(object): partition = section.attrib['label'] if lk == "true" and "u-boot" in filename: filename = filename.replace("u-boot", "lkboot") - except KeyError, e: - print "Skipping partition '%s'" % section.attrib['label'] + except KeyError as e: + print("Skipping partition '%s'" % section.attrib['label']) pass if diff_files == "true": @@ -1982,9 +2001,8 @@ class Pack(object): partition = section.attrib['label'] if filename == "": continue - - except KeyError, e: - print "Skipping partition '%s'" % section.attrib['label'] + except KeyError as e: + print("Skipping partition '%s'" % section.attrib['label']) pass 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: self.__gen_script_cdt(images, flinfo, root, section_conf, partition) continue - except KeyError, e: + except KeyError as e: continue if section_conf == "bootldr1": @@ -2020,7 +2038,7 @@ class Pack(object): if image_type == "all" or section[8].attrib['image_type'] == image_type: self.__gen_script_bootldr(images, flinfo, root, section_conf, partition) continue - except KeyError, e: + except KeyError as e: continue 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) wififw_type = "" continue - except KeyError, e: + except KeyError as e: continue if img != None and 'soc_version' in img.attrib: @@ -2079,7 +2097,7 @@ class Pack(object): file_exists = 1 soc_version = 0 # Clear soc_version for next iteration continue - except KeyError, e: + except KeyError as e: continue 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 continue - except KeyError, e: - print "Skipping partition '%s'" % section.attrib['label'] + except KeyError as e: + print("Skipping partition '%s'" % section.attrib['label']) pass if section != None and filename != "" and section.get('filename_mem' + memory_size) != None: @@ -2169,7 +2187,7 @@ class Pack(object): return 0 wifi_fw_type = "" continue - except KeyError, e: + except KeyError as e: continue return 1 @@ -2181,7 +2199,7 @@ class Pack(object): """ try: its_fp = open(self.its_fname, "wb") - except IOError, e: + except IOError as e: error("error opening its file '%s'" % self.its_fname, e) desc = "Flashing %s %x %x" @@ -2197,6 +2215,8 @@ class Pack(object): image_data = "".join(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.close() @@ -2204,9 +2224,9 @@ class Pack(object): cmd = [SRC_DIR + "/mkimage", "-f", self.its_fname, self.img_fname] ret = subprocess.call(cmd) if ret != 0: - print ret + print(ret) error("failed to create u-boot image from script") - except OSError, e: + except OSError as e: error("error executing mkimage", e) def __create_fnames(self): @@ -2338,7 +2358,7 @@ class Pack(object): try: script_fp.write(script.dumps()) - except IOError, e: + except IOError as e: error("error writing to script '%s'" % script_fp.name, e) script_fp.close() @@ -2374,7 +2394,7 @@ class Pack(object): if ftype.lower() == "norplusemmc": ftype = "emmc" - except ValueError, e: + except ValueError as e: error("invalid flash info in section '%s'" % board_section.find('machid').text, e) flinfo = FlashInfo(ftype, pagesize, blocksize, chipsize) @@ -2478,7 +2498,7 @@ class Pack(object): if ftype in ["nand-4k", "nand-audio", "nand-audio-4k"]: ftype = "nand" - except ValueError, e: + except ValueError as e: error("invalid flash info in section '%s'" % board_section.find('machid').text, e) blocksize = pages_per_block * pagesize @@ -2506,7 +2526,7 @@ class Pack(object): if ret: ret = self.__process_board_flash_emmc("norplusemmc", images, root) return ret - except ValueError, e: + except ValueError as 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): @@ -2523,7 +2543,7 @@ class Pack(object): self.__create_fnames() try: os.unlink(self.scr_fname) - except OSError, e: + except OSError as e: pass images = [] @@ -2571,7 +2591,7 @@ class ArgParser(object): if len(sys.argv) > 1: try: 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) for option, value in opts: @@ -2653,32 +2673,32 @@ class ArgParser(object): msg -- string, the error message """ - print "pack: %s" % msg - print - print "Usage:" - print "python pack_hk.py [options] [Value] ..." - print - print "options:" - print " --arch \tARCH_TYPE [ipq40xx/ipq806x/ipq807x/ipq807x_64/ipq6018/ipq6018_64/ipq5018/ipq5018_64/ipq9574/ipq9574_64/ipq5332/ipq5332_64]" - print - 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\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 - print " --inImage \tPath to the direcory containg binaries and images needed for singleimage" - print - print " --outImage \tPath to the directory where single image will be generated" - print - 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 specified, CDTs created with specified memory size will be used for single-image.\n" - print - print " --lk \t\tReplace u-boot with lkboot for appsbl" - print " --atf \t\tReplace tz with atf for QSEE partition" - print " --skip_4k_nand \tskip generating 4k nand images" - print " \t\tThis Argument does not take any value" - print "Pack Version: %s" % version + print("pack: %s" % msg) + print() + print("Usage:") + print("python pack_hk.py [options] [Value] ...") + print() + print("options:") + print(" --arch \tARCH_TYPE [ipq40xx/ipq806x/ipq807x/ipq807x_64/ipq6018/ipq6018_64/ipq5018/ipq5018_64/ipq9574/ipq9574_64/ipq5332/ipq5332_64]") + print() + 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\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() + print(" --inImage \tPath to the direcory containg binaries and images needed for singleimage") + print() + print(" --outImage \tPath to the directory where single image will be generated") + print() + 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 specified, CDTs created with specified memory size will be used for single-image.\n") + print() + print(" --lk \t\tReplace u-boot with lkboot for appsbl") + print(" --atf \t\tReplace tz with atf for QSEE partition") + print(" --skip_4k_nand \tskip generating 4k nand images") + print(" \t\tThis Argument does not take any value") + print("Pack Version: %s" % version) def gen_kernelboot_img(parser): """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] ret = subprocess.call(cmd, shell=True) if ret != 0: - print ret + print(ret) error("Error executing dtbTools") cmd = ["gzip -9 " + TMP_DIR + "/Image"] ret = subprocess.call(cmd, shell=True) if ret != 0: - print ret + print(ret) error("Error executing gzip") cmd = [SKALES_DIR + "/mkbootimg", @@ -2748,11 +2768,11 @@ def gen_kernelboot_img(parser): "--base=" + BASE_ADDR] ret = subprocess.call(cmd) if ret != 0: - print ret + print(ret) error("Error executing mkbootimg") rmtree(TMP_DIR) - except OSError, e: + except OSError as e: error("error generating kernelboot.img", e) def main(): @@ -2765,7 +2785,7 @@ def main(): try: parser = ArgParser() parser.parse(sys.argv) - except UsageError, e: + except UsageError as e: parser.usage(e.args[0]) sys.exit(1) diff --git a/tools/pack_v2.py b/tools/pack_v2.py index ccd9497004..6a91cd23e2 100644 --- a/tools/pack_v2.py +++ b/tools/pack_v2.py @@ -106,9 +106,9 @@ except ImportError: try: from ordereddict import OrderedDict except ImportError: - print "error: this script requires the 'ordereddict' class." - print "Try 'pip install --user ordereddict'" - print "Or 'easy_install --user ordereddict'" + print("error: this script requires the 'ordereddict' class.") + print("Try 'pip install --user ordereddict'") + print("Or 'easy_install --user ordereddict'") sys.exit(1) def error(msg, ex=None): @@ -127,6 +127,20 @@ FlashInfo = namedtuple("FlashInfo", "type pagesize blocksize chipsize") ImageInfo = namedtuple("ProgInfo", "name filename type") PartInfo = namedtuple("PartInfo", "name offset length which_flash") +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): GPTheader = namedtuple("GPTheader", "signature revision header_size" " crc32 current_lba backup_lba first_usable_lba" @@ -153,6 +167,7 @@ class GPT(object): part_fp.seek(self.blocksize, os.SEEK_SET) gptheader_str = part_fp.read(struct.calcsize(GPT.GPT_HEADER_FMT)) gptheader = struct.unpack(GPT.GPT_HEADER_FMT, gptheader_str) + gptheader = hdrobj_byte2str(gptheader) gptheader = GPT.GPTheader._make(gptheader) if gptheader.signature != GPT.GPT_SIGNATURE: @@ -181,6 +196,7 @@ class GPT(object): for i in range(gptheader.num_part_entry): 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 = hdrobj_byte2str(gpt_table) gpt_table = GPT.GPTtable._make(gpt_table) block_start = gpt_table.first_lba @@ -205,9 +221,9 @@ class GPT(object): """Returns a list of partitions present in the GPT.""" try: - with open(self.filename, "r") as part_fp: + with open(self.filename, "rb") as part_fp: self.__validate_and_read_parts(part_fp) - except IOError, e: + except IOError as e: error("error opening %s" % self.filename, e) return self.__partitions @@ -240,27 +256,29 @@ class MIBIB(object): self.__partitions = OrderedDict() def __validate(self, part_fp): - """Validate the MIBIB by checking for magic bytes.""" + """Validate the MIBIB by checking for magic bytes.""" - mheader_str = part_fp.read(struct.calcsize(MIBIB.HEADER_FMT)) - mheader = struct.unpack(MIBIB.HEADER_FMT, mheader_str) - mheader = MIBIB.Header._make(mheader) + mheader_str = part_fp.read(struct.calcsize(MIBIB.HEADER_FMT)) + mheader = struct.unpack(MIBIB.HEADER_FMT, mheader_str) + mheader = hdrobj_byte2str(mheader) + mheader = MIBIB.Header._make(mheader) - if (mheader.magic1 != MIBIB.HEADER_MAGIC1 - or mheader.magic2 != MIBIB.HEADER_MAGIC2): - """ mheader.magic1 = MIBIB.HEADER_MAGIC1 - mheader.magic2 = MIBIB.HEADER_MAGIC2 """ - error("invalid partition table, magic byte not present") + if (mheader.magic1 != MIBIB.HEADER_MAGIC1 + or mheader.magic2 != MIBIB.HEADER_MAGIC2): + """ mheader.magic1 = MIBIB.HEADER_MAGIC1 + mheader.magic2 = MIBIB.HEADER_MAGIC2 """ + error("invalid partition table, magic byte not present") - if mheader.version != MIBIB.HEADER_VERSION: - error("unsupport mibib version") + if mheader.version != MIBIB.HEADER_VERSION: + error("unsupport mibib version") def __read_parts(self, part_fp): """Read the partitions from the MIBIB.""" - global ARCH_NAME + global ARCH_NAME part_fp.seek(self.pagesize, os.SEEK_SET) mtable_str = part_fp.read(struct.calcsize(MIBIB.TABLE_FMT)) mtable = struct.unpack(MIBIB.TABLE_FMT, mtable_str) + mtable = hdrobj_byte2str(mtable) mtable = MIBIB.Table._make(mtable) if (mtable.magic1 != MIBIB.TABLE_MAGIC1 @@ -275,6 +293,7 @@ class MIBIB(object): for i in range(mtable.numparts): mentry_str = part_fp.read(struct.calcsize(MIBIB.ENTRY_FMT)) mentry = struct.unpack(MIBIB.ENTRY_FMT, mentry_str) + mentry = hdrobj_byte2str(mentry) mentry = MIBIB.Entry._make(mentry) self.flash_flag = self.blocksize self.chip_flag = self.chipsize @@ -286,9 +305,9 @@ class MIBIB(object): byte_offset = mentry.offset * self.flash_flag if mentry.length == 0xFFFFFFFF: - byte_length = self.chip_flag - byte_offset + byte_length = self.chip_flag - byte_offset else: - byte_length = mentry.length * self.flash_flag + byte_length = mentry.length * self.flash_flag part_name = mentry.name.strip(chr(0)) part_info = PartInfo(part_name, byte_offset, byte_length, mentry.which_flash) @@ -298,10 +317,10 @@ class MIBIB(object): """Returns a list of partitions present in the MIBIB. CE """ try: - with open(self.filename, "r") as part_fp: + with open(self.filename, "rb") as part_fp: self.__validate(part_fp) self.__read_parts(part_fp) - except IOError, e: + except IOError as e: error("error opening %s" % self.filename, e) return self.__partitions @@ -392,17 +411,17 @@ class FlashScript(object): value -- string, the list of values to compare with """ - n_val = len(val_list) - item = 1 - cmd_str = "if " - for val in val_list: - cmd_str = cmd_str + str('test "$%s" = "%s"' % (var, val)) - #cmd_str = cmd_str + "\"$" + var + "\"" + "=" + "\"" + val + "\"" - if item <= (n_val - 1): - cmd_str = cmd_str + " || " - item = item + 1 + n_val = len(val_list) + item = 1 + cmd_str = "if " + for val in val_list: + cmd_str = cmd_str + str('test "$%s" = "%s"' % (var, val)) + #cmd_str = cmd_str + "\"$" + var + "\"" + "=" + "\"" + val + "\"" + if item <= (n_val - 1): + cmd_str = cmd_str + " || " + item = item + 1 - self.append('%s; then\n' % cmd_str, fatal=False) + self.append('%s; then\n' % cmd_str, fatal=False) def end_if(self): """Generate code, to end if statement.""" @@ -435,7 +454,7 @@ def sha1(message): """Returns SHA1 digest in hex format of the message.""" m = hashlib.sha1() - m.update(message) + m.update(message.encode('utf-8')) return m.hexdigest() class Pack(object): @@ -466,7 +485,7 @@ class Pack(object): try: machid = int(section.find(".//machid").text, 0) machid = "%x" % machid - except ValueError, e: + except ValueError as e: error("invalid value for machid, should be integer") return machid @@ -481,7 +500,7 @@ class Pack(object): return 0 try: return getsize(os.path.join(self.images_dname, filename)) - except OSError, e: + except OSError as e: error("error getting image size '%s'" % filename, e) def __get_part_info(self, partition): @@ -491,18 +510,18 @@ class Pack(object): """ try: return self.partitions[partition] - except KeyError, e: + except KeyError as e: return None def __gen_flash_script_cdt(self, entries, partition, flinfo, script): - global ARCH_NAME + global ARCH_NAME for section in entries: machid = self.__get_machid(section) board = section.find(".//board").text try: memory = section.find(".//memory").text - except AttributeError, e: + except AttributeError as e: memory = "128M16" if memory_size != "default": filename = "cdt-" + board + "_" + memory + "_LM" + memory_size + ".bin" @@ -521,22 +540,22 @@ class Pack(object): section_conf = section_conf.lower() if self.flinfo.type != "emmc": - if part_info == None: - if self.flinfo.type == 'norplusnand': - if count > 2: - error("More than 2 NAND images for NOR+NAND is not allowed") - elif img_size > part_info.length: - print "img size is larger than part. len in '%s'" % section_conf - return 0 + if part_info == None: + if self.flinfo.type == 'norplusnand': + if count > 2: + error("More than 2 NAND images for NOR+NAND is not allowed") + elif img_size > part_info.length: + print("img size is larger than part. len in '%s'" % section_conf) + return 0 else: if part_info != None: if (img_size > 0): 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 if part_info == None and self.flinfo.type != 'norplusnand': - print "Flash type is norplusemmc" + print("Flash type is norplusemmc") continue if machid: @@ -554,63 +573,63 @@ class Pack(object): if multi_fw_check != None: script.append(multi_fw_check[0], fatal=False) - script.imxtract_n_flash(fw_filename[:-13] + "-" + sha1(fw_filename), "wifi_fw") + script.imxtract_n_flash(fw_filename[:-13] + "-" + sha1(fw_filename), "wifi_fw") if multi_fw_check != None: for i in range(multi_fw_check[1]): - script.end_if() + script.end_if() - return 1 + return 1 def __gen_flash_script_for_non_ubi_wififw(self, partition, filename, flinfo, script, multi_fw_check): - img_size = self.__get_img_size(filename) - part_info = self.__get_part_info(partition) + img_size = self.__get_img_size(filename) + part_info = self.__get_part_info(partition) - section_label = partition.split(":") + section_label = partition.split(":") if len(section_label) != 1: - section_conf = section_label[1] - else: - section_conf = section_label[0] - section_conf = section_conf.lower() + section_conf = section_label[1] + else: + section_conf = section_label[0] + section_conf = section_conf.lower() - if self.flinfo.type != "emmc": - if part_info == None: - if self.flinfo.type == 'norplusnand': - if count > 2: - error("More than 2 NAND images for NOR+NAND is not allowed") - elif img_size > part_info.length: - print "img size is larger than part. len in '%s'" % section_conf - return 0 - else: - if part_info != None: - if (img_size > 0): - if img_size > (part_info.length * self.flinfo.blocksize): - print "img size is larger than part. len in '%s'" % section_conf - return 0 + if self.flinfo.type != "emmc": + if part_info == None: + if self.flinfo.type == 'norplusnand': + if count > 2: + error("More than 2 NAND images for NOR+NAND is not allowed") + elif img_size > part_info.length: + print("img size is larger than part. len in '%s'" % section_conf) + return 0 + else: + if part_info != None: + if (img_size > 0): + if img_size > (part_info.length * self.flinfo.blocksize): + print("img size is larger than part. len in '%s'" % section_conf) + return 0 - if part_info == None and self.flinfo.type != 'norplusnand': - print "Flash type is norplusemmc" - return 1 + if part_info == None and self.flinfo.type != 'norplusnand': + print("Flash type is norplusemmc") + return 1 if multi_fw_check != None: script.append(multi_fw_check[0], fatal=False) - if img_size > 0: - script.imxtract_n_flash(filename[:-13] + "-" + sha1(filename), part_info.name) + if img_size > 0: + script.imxtract_n_flash(filename[:-13] + "-" + sha1(filename), part_info.name) if multi_fw_check != None: for i in range(multi_fw_check[1]): - script.end_if() + script.end_if() return 1 def __gen_flash_script_update_for_wififw(self, partition, filename, flinfo, script, machid_list): - script.start_if_or("machid", machid_list) + script.start_if_or("machid", machid_list) if ver_check == True: combs = self.__find_wifi_fw_ver_combinations(filename) - for k, v in combs.iteritems(): + for k, v in combs.items(): if flinfo.type != "emmc": self.__gen_flash_script_for_ubi_wififw(k, script, v) else: @@ -619,25 +638,25 @@ class Pack(object): if flinfo.type != "emmc": self.__gen_flash_script_for_ubi_wififw(filename, script, None) else: - self.__gen_flash_script_for_non_ubi_wififw(partition, filename, flinfo, script, None) + self.__gen_flash_script_for_non_ubi_wififw(partition, filename, flinfo, script, None) script.end_if() def __gen_flash_script_wififw(self, entries, partition, filename, wifi_fw_type, flinfo, script): machid_list = [] - for section in entries: + for section in entries: - wififw_type = section.find('.//wififw_name') - if wififw_type == None: - continue - wififw_type = str(section.find(".//wififw_name").text) + wififw_type = section.find('.//wififw_name') + if wififw_type == None: + continue + wififw_type = str(section.find(".//wififw_name").text) - if str(wifi_fw_type) != str(wififw_type): - continue + if str(wifi_fw_type) != str(wififw_type): + continue - machid = int(section.find(".//machid").text, 0) - machid = "%x" % machid - if self.flash_type == "nor": + machid = int(section.find(".//machid").text, 0) + machid = "%x" % machid + if self.flash_type == "nor": is_nor_flash = section.find(".//spi_nor") if is_nor_flash == None: continue @@ -661,9 +680,9 @@ class Pack(object): if tiny_image == None: continue - if memory_size != "default": + if memory_size != "default": filename = "bootldr1_" + board + "_" + memory + "_LM" + memory_size + ".mbn" - else: + else: filename = "bootldr1_" + board + "_" + memory + ".mbn" img_size = self.__get_img_size(filename) @@ -678,22 +697,22 @@ class Pack(object): section_conf = section_conf.lower() if self.flinfo.type != "emmc": - if part_info == None: - if self.flinfo.type == 'norplusnand': - if count > 2: - error("More than 2 NAND images for NOR+NAND is not allowed") - elif img_size > part_info.length: - print "img size is larger than part. len in '%s'" % section_conf - return 0 + if part_info == None: + if self.flinfo.type == 'norplusnand': + if count > 2: + error("More than 2 NAND images for NOR+NAND is not allowed") + elif img_size > part_info.length: + print("img size is larger than part. len in '%s'" % section_conf) + return 0 else: if part_info != None: if (img_size > 0): 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 if part_info == None and self.flinfo.type != 'norplusnand': - print "Flash type is norplusemmc" + print("Flash type is norplusemmc") continue if machid: @@ -710,15 +729,15 @@ class Pack(object): def __gen_script_mibib(self, script, flinfo, parts, parts_length, cmd): for index in range(parts_length): - partition = parts[index] - pnames = partition.findall('name') - if pnames[0].text == "0:MIBIB": - imgs = partition.findall('img_name') - filename = imgs[0].text - if cmd == "mibib_reload": - self.mibib_reload(filename, pnames[0].text, flinfo, script) - if cmd == "xtract_n_flash": - script.imxtract_n_flash("mibib-" + sha1(filename), "0:MIBIB") + partition = parts[index] + pnames = partition.findall('name') + if pnames[0].text == "0:MIBIB": + imgs = partition.findall('img_name') + filename = imgs[0].text + if cmd == "mibib_reload": + self.mibib_reload(filename, pnames[0].text, flinfo, script) + if cmd == "xtract_n_flash": + script.imxtract_n_flash("mibib-" + sha1(filename), "0:MIBIB") def mibib_reload(self, filename, partition, flinfo, script): @@ -744,82 +763,82 @@ class Pack(object): def __gen_flash_script_image(self, parts, parts_length, filename, soc_version, file_exists, machid, partition, flinfo, script): - img_size = 0 - if file_exists == 1: - img_size = self.__get_img_size(filename) - part_info = self.__get_part_info(partition) + img_size = 0 + if file_exists == 1: + img_size = self.__get_img_size(filename) + part_info = self.__get_part_info(partition) - section_label = partition.split(":") - if len(section_label) != 1: - section_conf = section_label[1] - else: - section_conf = section_label[0] + section_label = partition.split(":") + if len(section_label) != 1: + section_conf = section_label[1] + else: + section_conf = section_label[0] - section_conf = section_conf.lower() + section_conf = section_conf.lower() - if self.flinfo.type != "emmc": - if part_info == None: - if self.flinfo.type == 'norplusnand': - if count > 2: - error("More than 2 NAND images for NOR+NAND is not allowed") - elif img_size > part_info.length: - print "img size is larger than part. len in '%s'" % section_conf - return 0 - else: - if part_info != None: - if (img_size > 0): - if img_size > (part_info.length * self.flinfo.blocksize): - print "img size is larger than part. len in '%s'" % section_conf - return 0 - - if part_info == None and self.flinfo.type != 'norplusnand': - print "Flash type is norplusemmc" - return 1 - - if machid: - script.start_if("machid", machid) - - if section_conf == "qsee": - section_conf = "tz" - elif section_conf == "appsbl": - section_conf = "u-boot" - elif section_conf == "rootfs" and self.flash_type in ["nand", "nand-4k", "norplusnand", "norplusnand-4k"]: - section_conf = "ubi" - elif section_conf == "wififw" and self.flash_type in ["nand", "nand-4k", "norplusnand", "norplusnand-4k"]: - section_conf = "wififw_ubi" - - if file_exists == 0: - script.append('setenv stdout serial && echo "error: binary image not found" && exit 1', fatal=False) - return 1 - - if img_size > 0: - if section_conf == "mibib": - self.__gen_script_mibib(script, flinfo, parts, parts_length, "xtract_n_flash") - else: - script.imxtract_n_flash(section_conf + "-" + sha1(filename), part_info.name) - - if machid: - script.end_if() + if self.flinfo.type != "emmc": + if part_info == None: + if self.flinfo.type == 'norplusnand': + if count > 2: + error("More than 2 NAND images for NOR+NAND is not allowed") + elif img_size > part_info.length: + print("img size is larger than part. len in '%s'" % section_conf) + return 0 + else: + if part_info != None: + if (img_size > 0): + if img_size > (part_info.length * self.flinfo.blocksize): + print("img size is larger than part. len in '%s'" % section_conf) + return 0 + if part_info == None and self.flinfo.type != 'norplusnand': + print("Flash type is norplusemmc") return 1 + if machid: + script.start_if("machid", machid) + + if section_conf == "qsee": + section_conf = "tz" + elif section_conf == "appsbl": + section_conf = "u-boot" + elif section_conf == "rootfs" and self.flash_type in ["nand", "nand-4k", "norplusnand", "norplusnand-4k"]: + section_conf = "ubi" + elif section_conf == "wififw" and self.flash_type in ["nand", "nand-4k", "norplusnand", "norplusnand-4k"]: + section_conf = "wififw_ubi" + + if file_exists == 0: + script.append('setenv stdout serial && echo "error: binary image not found" && exit 1', fatal=False) + return 1 + + if img_size > 0: + if section_conf == "mibib": + self.__gen_script_mibib(script, flinfo, parts, parts_length, "xtract_n_flash") + else: + script.imxtract_n_flash(section_conf + "-" + sha1(filename), part_info.name) + + if machid: + script.end_if() + + return 1 + def __gen_flash_script(self, script, flinfo, root, testmachid=False): """Generate the script to flash the images. info -- ConfigParser object, containing image flashing info script -- Script object, to append commands to """ - global MODE - global SRC_DIR - global ARCH_NAME - global flash_size + global MODE + global SRC_DIR + global ARCH_NAME + global flash_size - diff_files = "" + diff_files = "" count = 0 - soc_version = 0 - diff_soc_ver_files = 0 - file_exists = 1 - wifi_fw_type = "" + soc_version = 0 + diff_soc_ver_files = 0 + file_exists = 1 + wifi_fw_type = "" if self.flash_type == "norplusemmc" and flinfo.type == "emmc": srcDir_part = SRC_DIR + "/" + ARCH_NAME + "/flash_partition/" + flinfo.type + "-partition"+ flash_size +".xml" @@ -846,7 +865,7 @@ class Pack(object): for segment in entries: wififw_type = segment.find('.//wififw_name') if wififw_type == None: - machid = int(segment.find(".//machid").text, 0) + machid = int(segment.find(".//machid").text, 0) machid = "%x" % machid no_fw_mach_ids.append(machid) @@ -877,22 +896,22 @@ class Pack(object): script.script.append('echo \'soc_hw_version : unknown, skipping validation\'\n') script.script.append('fi\n') - if testmachid: - machid_count = 0 - for section in entries: + if testmachid: + machid_count = 0 + for section in entries: machid = self.__get_machid(section) - machid_count = machid_count + 1 - if machid_count == 1: - script.script.append('if test "$machid" = "%s" ' % machid) - else: - script.script.append('|| test "$machid" = "%s" ' % machid) - if machid_count >= 1: - script.script.append('; then\n') - script.script.append('echo \'machid : Validation success\'\n') - script.script.append('else\n') - script.script.append('echo \'machid : unknown, aborting upgrade\'\n') - script.script.append('exit 1\n') - script.script.append('fi\n') + machid_count = machid_count + 1 + if machid_count == 1: + script.script.append('if test "$machid" = "%s" ' % machid) + else: + script.script.append('|| test "$machid" = "%s" ' % machid) + if machid_count >= 1: + script.script.append('; then\n') + script.script.append('echo \'machid : Validation success\'\n') + script.script.append('else\n') + script.script.append('echo \'machid : unknown, aborting upgrade\'\n') + script.script.append('exit 1\n') + script.script.append('fi\n') first = False section = None part_index = 0 @@ -937,124 +956,124 @@ class Pack(object): part_index += 1 if flinfo.type != "emmc": try: - if image_type == "all" or section[8].attrib['image_type'] == image_type: + if image_type == "all" or section[8].attrib['image_type'] == image_type: filename = section[8].text - try: - if section[8].attrib['mode'] != MODE: - filename = section[9].text - else: - pass - except AttributeError, e: - pass - except KeyError, e: - pass - else: - continue - except IndexError, e: + try: + if section[8].attrib['mode'] != MODE: + filename = section[9].text + else: + pass + except AttributeError as e: + pass + except KeyError as e: + pass + else: + continue + except IndexError as e: if index == (parts_length - 1): return else: continue - except KeyError, e: - continue + except KeyError as e: + continue partition = section[0].text else: - try: - diff_files = section.attrib['diff_files'] - except KeyError, e: + try: + diff_files = section.attrib['diff_files'] + except KeyError as e: if tiny_16m == "true": pass - else: - try: - partition = section.attrib['label'] + else: + try: + partition = section.attrib['label'] if image_type == "all" or section.attrib['image_type'] == image_type: filename = section.attrib['filename'] if filename == "": continue - except KeyError, e: - print "Skipping partition '%s'" % section.attrib['label'] - pass + except KeyError as e: + print("Skipping partition '%s'" % section.attrib['label']) + pass - if diff_files == "true": - try: - if image_type == "all" or section.attrib['image_type'] == image_type: - filename = section.attrib['filename_' + MODE] - partition = section.attrib['label'] - if filename == "": - continue - except KeyError, e: - print "Skipping partition '%s'" % section.attrib['label'] - pass - diff_files = "" # Clear for next iteration + if diff_files == "true": + try: + if image_type == "all" or section.attrib['image_type'] == image_type: + filename = section.attrib['filename_' + MODE] + partition = section.attrib['label'] + if filename == "": + continue + except KeyError as e: + print("Skipping partition '%s'" % section.attrib['label']) + pass + diff_files = "" # Clear for next iteration # Get machID if partition != "0:CDT" and partition != "0:DDRCONFIG": machid = None else: - try: - if image_type == "all" or section.attrib['image_type'] == image_type: - ret = self.__gen_flash_script_cdt(entries, partition, flinfo, script) - if ret == 0: - return 0 - continue - except KeyError, e: - continue - - if partition == "0:BOOTLDR1": - if image_type == "all" or section.attrib['image_type'] == image_type: - ret = self.__gen_flash_script_bootldr(entries, partition, flinfo, script) + try: + if image_type == "all" or section.attrib['image_type'] == image_type: + ret = self.__gen_flash_script_cdt(entries, partition, flinfo, script) if ret == 0: return 0 continue + except KeyError as e: + continue + + if partition == "0:BOOTLDR1": + if image_type == "all" or section.attrib['image_type'] == image_type: + ret = self.__gen_flash_script_bootldr(entries, partition, flinfo, script) + if ret == 0: + return 0 + continue if flinfo.type != "emmc" and flinfo.type != "nor": - imgs = section.findall('img_name') - for img in imgs: - memory_attr = img.get('memory') - if memory_attr != None and memory_attr == memory_size: - filename = img.text; + imgs = section.findall('img_name') + for img in imgs: + memory_attr = img.get('memory') + if memory_attr != None and memory_attr == memory_size: + filename = img.text; - atf_image = img.get('atf') - if atf_image != None and atf == "true": - filename = img.text; + atf_image = img.get('atf') + if atf_image != None and atf == "true": + filename = img.text; - else: - if partition == "0:WIFIFW": + else: + if partition == "0:WIFIFW": - if ver_check == True: - script.append("qcn_detect", fatal=False) + if ver_check == True: + script.append("qcn_detect", fatal=False) - if no_fw_mach_ids and filename != "": - self.__gen_flash_script_update_for_wififw(partition, filename, flinfo, script, no_fw_mach_ids) + if no_fw_mach_ids and filename != "": + self.__gen_flash_script_update_for_wififw(partition, filename, flinfo, script, no_fw_mach_ids) - if image_type == "all" or section.attrib['image_type'] == image_type: - for wifi_fw_type in wifi_fw_list: - fw_name = wifi_fw_type - if fw_name == "": - continue - ret = self.__gen_flash_script_wififw(entries, partition, fw_name, wifi_fw_type, flinfo, script) - if ret == 0: - return 0 - fw_name = "" - wifi_fw_type = "" + if image_type == "all" or section.attrib['image_type'] == image_type: + for wifi_fw_type in wifi_fw_list: + fw_name = wifi_fw_type + if fw_name == "": + continue + ret = self.__gen_flash_script_wififw(entries, partition, fw_name, wifi_fw_type, flinfo, script) + if ret == 0: + return 0 + fw_name = "" + wifi_fw_type = "" - if filename != "": - wifi_fw_list.append(filename) - filename = "" - continue + if filename != "": + wifi_fw_list.append(filename) + filename = "" + continue - if section != None and filename != "" and section.get('filename_mem' + memory_size) != None: - filename = section.get('filename_mem' + memory_size) + if section != None and filename != "" and section.get('filename_mem' + memory_size) != None: + filename = section.get('filename_mem' + memory_size) - if section != None and atf == "true" and section.get('filename_atf') != None: - filename = section.get('filename_atf') + if section != None and atf == "true" and section.get('filename_atf') != None: + filename = section.get('filename_atf') if filename != "": ret = self.__gen_flash_script_image(parts, parts_length, filename, soc_version, file_exists, machid, partition, flinfo, script) if ret == 0: return 0 - if self.flash_type in [ "nand", "nand-4k", "norplusnand", "norplusnand-4k" ] and partition == "rootfs": + if self.flash_type in [ "nand", "nand-4k", "norplusnand", "norplusnand-4k" ] and partition == "rootfs": if ver_check == True: script.append("qcn_detect", fatal=False) @@ -1086,7 +1105,7 @@ class Pack(object): board = section.find(".//board").text try: memory = section.find(".//memory").text - except AttributeError, e: + except AttributeError as e: memory = "128M16" if memory_size != "default": @@ -1104,7 +1123,7 @@ class Pack(object): filename, "firmware") if filename.lower() != "none": if image_info not in images: - images.append(image_info) + images.append(image_info) def __gen_script_bootldr(self, images, flinfo, root, section_conf, partition): global ARCH_NAME @@ -1121,7 +1140,7 @@ class Pack(object): try: memory = section.find(".//memory").text - except AttributeError, e: + except AttributeError as e: memory = "128M16" if memory_size != "default": @@ -1139,7 +1158,7 @@ class Pack(object): filename, "firmware") if filename.lower() != "none": if image_info not in images: - images.append(image_info) + images.append(image_info) def __find_wifi_fw_ver_combinations(self, filename): global wifi_fws_avail @@ -1198,34 +1217,34 @@ class Pack(object): def __gen_script_append_images(self, filename, soc_version, wifi_fw_type, images, flinfo, root, section_conf, partition): - part_info = self.__get_part_info(partition) - if part_info == None and self.flinfo.type != 'norplusnand': - return + part_info = self.__get_part_info(partition) + if part_info == None and self.flinfo.type != 'norplusnand': + return - if section_conf == "qsee": - section_conf = "tz" - elif section_conf == "appsbl": - print " Using u-boot..." - section_conf = "u-boot" - elif section_conf == "rootfs" and self.flash_type in ["nand", "nand-4k", "norplusnand", "norplusnand-4k"]: - section_conf = "ubi" - elif section_conf == "wififw" and self.flash_type in ["nand", "nand-4k", "norplusnand", "norplusnand-4k"]: - section_conf = "wififw_ubi" - elif section_conf == "wififw" and wifi_fw_type: - section_conf = filename[:-13] + if section_conf == "qsee": + section_conf = "tz" + elif section_conf == "appsbl": + print(" Using u-boot...") + section_conf = "u-boot" + elif section_conf == "rootfs" and self.flash_type in ["nand", "nand-4k", "norplusnand", "norplusnand-4k"]: + section_conf = "ubi" + elif section_conf == "wififw" and self.flash_type in ["nand", "nand-4k", "norplusnand", "norplusnand-4k"]: + section_conf = "wififw_ubi" + elif section_conf == "wififw" and wifi_fw_type: + section_conf = filename[:-13] - image_info = ImageInfo(section_conf + "-" + sha1(filename), filename, "firmware") + image_info = ImageInfo(section_conf + "-" + sha1(filename), filename, "firmware") if filename.lower() != "none": if image_info not in images: images.append(image_info) def __gen_script_append_images_wififw_ubi_volume(self, fw_filename, wifi_fw_type, images): - image_info = ImageInfo(fw_filename[:-13] + "-" + sha1(fw_filename), - fw_filename, "firmware") - if fw_filename.lower() != "none": - if image_info not in images: - images.append(image_info) + image_info = ImageInfo(fw_filename[:-13] + "-" + sha1(fw_filename), + fw_filename, "firmware") + if fw_filename.lower() != "none": + if image_info not in images: + images.append(image_info) def __gen_script(self, script_fp, script, images, flinfo, root): """Generate the script to flash the multi-image blob. @@ -1235,15 +1254,15 @@ class Pack(object): script -- Script object, to append the commands to images -- list of ImageInfo, appended to, based on images in config """ - global MODE - global SRC_DIR - global flash_size + global MODE + global SRC_DIR + global flash_size - soc_version = 0 - diff_soc_ver_files = 0 - wifi_fw_type = "" - diff_files = "" - file_exists = 1 + soc_version = 0 + diff_soc_ver_files = 0 + wifi_fw_type = "" + diff_files = "" + file_exists = 1 ret = self.__gen_flash_script(script, flinfo, root, True) if ret == 0: @@ -1303,59 +1322,59 @@ class Pack(object): part_index += 1 if flinfo.type != "emmc": try: - if image_type == "all" or section[8].attrib['image_type'] == image_type: + if image_type == "all" or section[8].attrib['image_type'] == image_type: filename = section[8].text - try: - if section[8].attrib['mode'] != MODE: - filename = section[9].text - except AttributeError, e: - pass - except KeyError, e: - pass - except IndexError, e: + try: + if section[8].attrib['mode'] != MODE: + filename = section[9].text + except AttributeError as e: + pass + except KeyError as e: + pass + except IndexError as e: if index == (parts_length - 1): return else: continue - except KeyError, e: - continue + except KeyError as e: + continue partition = section[0].text else: - try: - diff_files = section.attrib['diff_files'] - except KeyError, e: - try: - diff_soc_ver_files = section.attrib['diff_soc_ver_files'] - partition = section.attrib['label'] - except KeyError, e: + try: + diff_files = section.attrib['diff_files'] + except KeyError as e: + try: + diff_soc_ver_files = section.attrib['diff_soc_ver_files'] + partition = section.attrib['label'] + except KeyError as e: if tiny_16m == "true": pass - else: - try: - partition = section.attrib['label'] + else: + try: + partition = section.attrib['label'] if partition != "0:WIFIFW": - if image_type == "all" or section.attrib['image_type'] == image_type: - filename = section.attrib['filename'] - if filename == "": - continue - except KeyError, e: - partition = "" - print "Skipping partition '%s'" % section.attrib['label'] - pass + if image_type == "all" or section.attrib['image_type'] == image_type: + filename = section.attrib['filename'] + if filename == "": + continue + except KeyError as e: + partition = "" + print("Skipping partition '%s'" % section.attrib['label']) + pass - if diff_files == "true": - try: - if image_type == "all" or section.attrib['image_type'] == image_type: - filename = section.attrib['filename_' + MODE] - partition = section.attrib['label'] - if filename == "": - continue + if diff_files == "true": + try: + if image_type == "all" or section.attrib['image_type'] == image_type: + filename = section.attrib['filename_' + MODE] + partition = section.attrib['label'] + if filename == "": + continue - except KeyError, e: - print "Skipping partition '%s'" % section.attrib['label'] - pass - diff_files = "" # Clear for next iteration + except KeyError as e: + print("Skipping partition '%s'" % section.attrib['label']) + pass + diff_files = "" # Clear for next iteration part_info = self.__get_part_info(partition) @@ -1368,70 +1387,70 @@ class Pack(object): section_conf = section_conf.lower() if section_conf == "cdt" or section_conf == "ddrconfig": - try: - if image_type == "all" or section[8].attrib['image_type'] == image_type: - self.__gen_script_cdt(images, flinfo, root, section_conf, partition) - continue - except KeyError, e: + try: + if image_type == "all" or section[8].attrib['image_type'] == image_type: + self.__gen_script_cdt(images, flinfo, root, section_conf, partition) + continue + except KeyError as e: continue if section_conf == "bootldr1": - try: - if image_type == "all" or section[8].attrib['image_type'] == image_type: - self.__gen_script_bootldr(images, flinfo, root, section_conf, partition) - continue - except KeyError, e: + try: + if image_type == "all" or section[8].attrib['image_type'] == image_type: + self.__gen_script_bootldr(images, flinfo, root, section_conf, partition) + continue + except KeyError as e: continue if flinfo.type != "emmc": - imgs = section.findall('img_name') - for img in imgs: - memory_attr = img.get('memory') - if memory_attr != None and memory_attr == memory_size: - filename = img.text; + imgs = section.findall('img_name') + for img in imgs: + memory_attr = img.get('memory') + if memory_attr != None and memory_attr == memory_size: + filename = img.text; - atf_image = img.get('atf') - if atf_image != None and atf == "true": - filename = img.text; + atf_image = img.get('atf') + if atf_image != None and atf == "true": + filename = img.text; else: - # wififw images specific for RDP based on machid - if section_conf == "wififw": + # wififw images specific for RDP based on machid + if section_conf == "wififw": if ver_check: - for k, v in wifi_fws_avail.iteritems(): - self.__gen_script_append_images(k, soc_version, 1, images, flinfo, root, section_conf, partition) + for k, v in wifi_fws_avail.items(): + self.__gen_script_append_images(k, soc_version, 1, images, flinfo, root, section_conf, partition) else: for wifi_fw_type in wifi_fw_list: fw_name = wifi_fw_type if fw_name == "": - continue - if not os.path.exists(os.path.join(self.images_dname, fw_name)): + continue + if not os.path.exists(os.path.join(self.images_dname, fw_name)): return 0 - self.__gen_script_append_images(fw_name, soc_version, wifi_fw_type, images, flinfo, root, section_conf, partition) - wifi_fw_type = "" + self.__gen_script_append_images(fw_name, soc_version, wifi_fw_type, images, flinfo, root, section_conf, partition) + wifi_fw_type = "" fw_name = "" - continue + continue - if section != None and filename != "" and section.get('filename_mem' + memory_size) != None: - filename = section.get('filename_mem' + memory_size) + if section != None and filename != "" and section.get('filename_mem' + memory_size) != None: + filename = section.get('filename_mem' + memory_size) - if section != None and atf == "true" and section.get('filename_atf') != None: - filename = section.get('filename_atf') + if section != None and atf == "true" and section.get('filename_atf') != None: + filename = section.get('filename_atf') if filename != "": self.__gen_script_append_images(filename, soc_version, wifi_fw_type, images, flinfo, root, section_conf, partition) - if self.flash_type in [ "nand", "nand-4k", "norplusnand", "norplusnand-4k" ] and section_conf == "rootfs": + if self.flash_type in [ "nand", "nand-4k", "norplusnand", "norplusnand-4k" ] and section_conf == "rootfs": if ver_check: - for k, v in wifi_fws_avail.iteritems(): - self.__gen_script_append_images_wififw_ubi_volume(k, wifi_fw_type, images) + for k, v in wifi_fws_avail.items(): + self.__gen_script_append_images_wififw_ubi_volume(k, wifi_fw_type, images) else: for wifi_fw_type in wifi_fw_list: filename = wifi_fw_type if filename == "": continue - ret = self.__gen_script_append_images_wififw_ubi_volume(filename, wifi_fw_type, images) + ret = self.__gen_script_append_images_wififw_ubi_volume(filename, wifi_fw_type, images) if ret == 0: return 0 filename = "" @@ -1448,7 +1467,7 @@ class Pack(object): """ try: its_fp = open(self.its_fname, "wb") - except IOError, e: + except IOError as e: error("error opening its file '%s'" % self.its_fname, e) desc = "Flashing %s %x %x" @@ -1464,6 +1483,7 @@ class Pack(object): image_data = "".join(image_data) its_data = its_tmpl.substitute(desc=desc, images=image_data) + its_data = bytes(its_data, 'utf-8') its_fp.write(its_data) its_fp.close() @@ -1471,9 +1491,9 @@ class Pack(object): cmd = [SRC_DIR + "/mkimage", "-f", self.its_fname, self.img_fname] ret = subprocess.call(cmd) if ret != 0: - print ret + print(ret) error("failed to create u-boot image from script") - except OSError, e: + except OSError as e: error("error executing mkimage", e) def __create_fnames(self): @@ -1483,9 +1503,9 @@ class Pack(object): self.its_fname = os.path.join(self.images_dname, "flash.its") def __gen_board_script(self, flinfo, part_fname, images, root): - global SRC_DIR - global ARCH_NAME - global flash_size + global SRC_DIR + global ARCH_NAME + global flash_size """Generate the flashing script for one board. @@ -1526,12 +1546,12 @@ class Pack(object): self.partitions = gpt.get_parts() ret = self.__gen_script(script_fp, script, images, flinfo, root) - if ret == 0: - return 0 + if ret == 0: + return 0 try: script_fp.write(script.dumps()) - except IOError, e: + except IOError as e: error("error writing to script '%s'" % script_fp.name, e) script_fp.close() @@ -1563,22 +1583,22 @@ class Pack(object): if ftype.lower() == "norplusemmc": ftype = "emmc" - except ValueError, e: + except ValueError as e: error("invalid flash info in section '%s'" % board_section.find('machid').text, e) flinfo = FlashInfo(ftype, pagesize, blocksize, chipsize) ret = self.__gen_board_script(flinfo, part_fname, images, root) - if ret == 0: + if ret == 0: return 0 return 1 def __process_board_flash(self, ftype, images, root): - global SRC_DIR - global ARCH_NAME - global MODE - global flash_size + global SRC_DIR + global ARCH_NAME + global MODE + global flash_size try: if ftype == "tiny-nor" or ftype == "tiny-nor-debug": @@ -1611,37 +1631,37 @@ class Pack(object): part_file = SRC_DIR + "/" + ARCH_NAME + "/flash_partition/" + ftype + "-partition"+ flash_size +".xml" parts = ET.parse(part_file).findall('.//partitions/partition') for index in range(len(parts)): - section = parts[index] - if section[0].text == "rootfs": - rootfs_pos = 9 if MODE == "64" else 8 - UBI_IMG_NAME = section[rootfs_pos].text + section = parts[index] + if section[0].text == "rootfs": + rootfs_pos = 9 if MODE == "64" else 8 + UBI_IMG_NAME = section[rootfs_pos].text if ftype in ["nand-4k", "norplusnand-4k"]: cmd = '%s -m 4096 -p 256KiB -o root.ubi %s' % ((SRC_DIR + "/ubinize") ,UBINIZE_CFG_NAME) ret = subprocess.call(cmd, shell=True) if ret != 0: - error("ubinization got failed") + error("ubinization got failed") cmd = 'dd if=root.ubi of=%s bs=4k conv=sync' % (SRC_DIR + "/" + UBI_IMG_NAME) ret = subprocess.call(cmd, shell=True) if ret != 0: - error("ubi image copy operation failed") + error("ubi image copy operation failed") elif ftype in ["nand", "norplusnand"]: cmd = '%s -m 2048 -p 128KiB -o root.ubi %s' % ((SRC_DIR + "/ubinize") ,UBINIZE_CFG_NAME) ret = subprocess.call(cmd, shell=True) if ret != 0: - error("ubinization got failed") + error("ubinization got failed") cmd = 'dd if=root.ubi of=%s bs=2k conv=sync' % (SRC_DIR + "/" + UBI_IMG_NAME) ret = subprocess.call(cmd, shell=True) if ret != 0: - error("ubi image copy operation failed") + error("ubi image copy operation failed") part_file = SRC_DIR + "/" + ARCH_NAME + "/flash_partition/" + ftype + "-partition"+ flash_size +".xml" part_xml = ET.parse(part_file) - if (part_xml.find(".//partitions/partition[name='0:MIBIB']")): - partition = part_xml.find(".//partitions/partition[name='0:MIBIB']") - else: - partition = part_xml.find(".//partitions/partition[2]") + if (part_xml.find(".//partitions/partition[name='0:MIBIB']")): + partition = part_xml.find(".//partitions/partition[name='0:MIBIB']") + else: + partition = part_xml.find(".//partitions/partition[2]") part_fname = partition[8].text part_fname = os.path.join(self.images_dname, part_fname) pagesize = int(part_info.find(".//page_size").text) @@ -1653,7 +1673,7 @@ class Pack(object): if ftype in ["nand-4k"]: ftype = "nand" - except ValueError, e: + except ValueError as e: error("invalid flash info in section '%s'" % board_section.find('machid').text, e) blocksize = pages_per_block * pagesize @@ -1662,7 +1682,7 @@ class Pack(object): flinfo = FlashInfo(ftype, pagesize, blocksize, chipsize) ret = self.__gen_board_script(flinfo, part_fname, images, root) - return ret + return ret def __process_board(self, images, root): @@ -1673,10 +1693,10 @@ class Pack(object): ret = self.__process_board_flash_emmc(self.flash_type, images, root) elif self.flash_type == "norplusemmc": ret = self.__process_board_flash("norplusemmc", images, root) - if ret: + if ret: ret = self.__process_board_flash_emmc("norplusemmc", images, root) return ret - except ValueError, e: + except ValueError as 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): @@ -1693,7 +1713,7 @@ class Pack(object): self.__create_fnames() try: os.unlink(self.scr_fname) - except OSError, e: + except OSError as e: pass images = [] @@ -1702,7 +1722,7 @@ class Pack(object): images.insert(0, ImageInfo("script", "flash.scr", "script")) self.__mkimage(images) else: - fail_img = out_fname.split("/") + fail_img = out_fname.split("/") error("Failed to pack %s" % fail_img[-1]) class UsageError(Exception): @@ -1722,46 +1742,46 @@ class ArgParser(object): self.its_fname = None def parse(self, argv): - global MODE - global SRC_DIR - global ARCH_NAME - global image_type - global memory_size + global MODE + global SRC_DIR + global ARCH_NAME + global image_type + global memory_size global atf global skip_4k_nand - global flash_size - flash_size = "" + global flash_size + flash_size = "" """Start the parsing process, and populate members with parsed value. argv -- list of string, the command line arguments """ - cdir = os.path.abspath(os.path.dirname("")) + cdir = os.path.abspath(os.path.dirname("")) if len(sys.argv) > 1: try: opts, args = getopt(sys.argv[1:], "", ["arch=", "fltype=", "srcPath=", "inImage=", "outImage=", "image_type=", "memory=", "flash_size=", "skip_4k_nand", "atf"]) - except GetoptError, e: - raise UsageError(e.msg) + except GetoptError as e: + raise UsageError(e.msg) - for option, value in opts: - if option == "--arch": - ARCH_NAME = value + for option, value in opts: + if option == "--arch": + ARCH_NAME = value - elif option == "--fltype": - self.flash_type = value + elif option == "--fltype": + self.flash_type = value - elif option == "--srcPath": - SRC_DIR = os.path.abspath(value) + elif option == "--srcPath": + SRC_DIR = os.path.abspath(value) - elif option == "--inImage": - self.images_dname = os.path.join(cdir, value) + elif option == "--inImage": + self.images_dname = os.path.join(cdir, value) - elif option == "--outImage": - self.out_dname = os.path.join(cdir, value) + elif option == "--outImage": + self.out_dname = os.path.join(cdir, value) - elif option == "--image_type": - image_type = value + elif option == "--image_type": + image_type = value elif option == "--memory": memory_size = value @@ -1778,63 +1798,63 @@ class ArgParser(object): #Verify Arguments passed by user # Verify arch type - if ARCH_NAME not in supported_arch: - raise UsageError("Invalid arch type '%s'" % arch) + if ARCH_NAME not in supported_arch: + raise UsageError("Invalid arch type '%s'" % arch) - MODE = "32" - if ARCH_NAME[-3:] == "_64": - MODE = "64" + MODE = "32" + if ARCH_NAME[-3:] == "_64": + MODE = "64" ARCH_NAME = ARCH_NAME[:-3] # Set flash type to default type (nand) if not given by user - if self.flash_type == None: + if self.flash_type == None: self.flash_type = ArgParser.DEFAULT_TYPE - for flash_type in self.flash_type.split(","): + for flash_type in self.flash_type.split(","): if flash_type not in [ "nand", "nor", "tiny-nor", "emmc", "norplusnand", "norplusemmc", "tiny-nor-debug" ]: raise UsageError("invalid flash type '%s'" % flash_type) # Verify src Path - if SRC_DIR == "": - raise UsageError("Source Path is not provided") + if SRC_DIR == "": + raise UsageError("Source Path is not provided") #Verify input image path - if self.images_dname == None: - raise UsageError("input images' Path is not provided") + if self.images_dname == None: + raise UsageError("input images' Path is not provided") #Verify Output image path - if self.out_dname == None: - raise UsageError("Output Path is not provided") + if self.out_dname == None: + raise UsageError("Output Path is not provided") def usage(self, msg): """Print error message and command usage information. msg -- string, the error message """ - print "pack: %s" % msg - print - print "Usage:" - print "python pack_v2.py [options] [Value] ..." - print - print "options:" - print " --arch \tARCH_TYPE [" + '/'.join(supported_arch) + "]" - 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\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 - print " --inImage \tPath to the direcory containg binaries and images needed for singleimage" - print - print " --outImage \tPath to the directory where single image will be generated" - print - 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 specified, CDTs created with specified memory size will be used for single-image.\n" - print " --flash_size \tFlash size" - print - print " --atf \t\tReplace tz with atf for QSEE partition" - print " --skip_4k_nand \tskip generating 4k nand images" - print " \t\tThis Argument does not take any value" - print "Pack Version: %s" % version + print("pack: %s" % msg) + print() + print("Usage:") + print("python pack_v2.py [options] [Value] ...") + print() + print("options:") + print(" --arch \tARCH_TYPE [" + '/'.join(supported_arch) + "]") + 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\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() + print(" --inImage \tPath to the direcory containg binaries and images needed for singleimage") + print() + print(" --outImage \tPath to the directory where single image will be generated") + print() + 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 specified, CDTs created with specified memory size will be used for single-image.\n") + print(" --flash_size \tFlash size") + print() + print(" --atf \t\tReplace tz with atf for QSEE partition") + print(" --skip_4k_nand \tskip generating 4k nand images") + print(" \t\tThis Argument does not take any value") + print("Pack Version: %s" % version) def main(): """Main script entry point. @@ -1847,14 +1867,14 @@ def main(): try: parser = ArgParser() parser.parse(sys.argv) - except UsageError, e: + except UsageError as e: parser.usage(e.args[0]) sys.exit(1) pack = Pack() if not os.path.exists(parser.out_dname): - os.makedirs(parser.out_dname) + os.makedirs(parser.out_dname) config = SRC_DIR + "/" + ARCH_NAME + "/config.xml" root = ET.parse(config) @@ -1867,7 +1887,7 @@ def main(): global def_ver_list global possible_fw_vers global wifi_fws_avail - global flash_size + global flash_size wifi_fws_avail = dict() ver_check = True @@ -1876,7 +1896,7 @@ def main(): def_ver_list = list(map(int, def_ver_list)) if len(soc_ver_list) != len(def_ver_list): - print "Invalid VERSION_PARAMETER!!! Please check " + config + " file." + print("Invalid VERSION_PARAMETER!!! Please check " + config + " file.") sys.exit(1) possible_fw_vers = [] @@ -1898,22 +1918,22 @@ def main(): possible_fw_vers.append(temp) if skip_4k_nand != "true": - # Add nand-4k flash type, if nand flash type is specified - if "nand" in parser.flash_type.split(",") and flash_size == "": + # Add nand-4k flash type, if nand flash type is specified + if "nand" in parser.flash_type.split(",") and flash_size == "": if root.find(".//data[@type='NAND_PARAMETER']/entry") != None: - parser.flash_type = parser.flash_type + ",nand-4k" + parser.flash_type = parser.flash_type + ",nand-4k" - # Add norplusnand-4k flash type, if norplusnand flash type is specified - if "norplusnand" in parser.flash_type.split(","): + # Add norplusnand-4k flash type, if norplusnand flash type is specified + if "norplusnand" in parser.flash_type.split(","): if root.find(".//data[@type='NAND_PARAMETER']/entry") != None: - parser.flash_type = parser.flash_type + ",norplusnand-4k" + parser.flash_type = parser.flash_type + ",norplusnand-4k" # Format the output image name from Arch, flash type and mode for flash_type in parser.flash_type.split(","): - if (flash_type == "tiny-nor" or flash_type == "tiny-nor-debug"): - tiny_16m = "true" - else: - tiny_16m = "false" + if (flash_type == "tiny-nor" or flash_type == "tiny-nor-debug"): + tiny_16m = "true" + else: + tiny_16m = "false" MODE_APPEND = "_64" if MODE == "64" else "" if image_type == "hlos":