def gen_bct(bootloader, bct): bct_config = generated() + "bct.cfg" #./bct_dump ./ac100.bct.orig > bct.cfg res = execute(bct_dump() + " " + bct + " > " + bct_config) if res != 0: return res, None # Add bootloader at the end of bct.cfg res = execute("echo 'BootLoader = " + bootloader + ",0x00108000,0x00108000,Complete;' >> " + bct_config) if res != 0: return res, None new_bct = generated() + "ac100.bct" #./cbootimage -d ./bct.cfg ac100.bct.new res = execute(cbootimage() + " -d " + bct_config + " " + new_bct) if res != 0: return res, None res = execute("truncate " + new_bct + " -s 4080") if res != 0: return res, None return 0, new_bct
def repart_vendor(self, bootloader, config): print "AC100 repartition for vendor scheme" self.bootloader = binaries() + bootloader self.config = configs() + config self.bct = ac100_bct_dump() if not self.check_files(): return 2 (res, self.bct) = gen_bct(self.bootloader, self.bct) if res != 0: return res res = self.repart() if res != 0: return res part_table = generated() + "partitiontable.txt" res = backup_partitiontable(part_table) if res != 0: return res res, gens = generate_new_partitions(part_table) if res != 0: return res #TODO: generate_new_partitions shoud return file names and IDs for g in gens: push_part(g[0], g[1]) return 0
def write_boot_record(partitions, base_name, base_partitions, result): if len(partitions) == 0: print "No partitions for", base_name return None file_name = "%s%s.gen" % (generated(), base_name) print "Forming", file_name base = get_partition_by_name(partitions, base_name) if base == None: print "Can't find", base_name return None f = "" try: f = open(file_name, "wb") except: print "Can't open file", file_name, "for writing" return None br = [0] * int(base[SIZE]) * 2048 br[510:512] = [0x55, 0xaa] for part in base_partitions: put_partition_record(br, part) f.write(bytearray(br)) result.append([int(base[ID]), file_name]) return result
def init_externals(): if not os.path.isdir(generated()): os.makedirs(generated()) if os.path.isfile(bct_dump()) and \ os.path.isfile(cbootimage()) and \ os.path.isfile(externals() + "nvflash/nvflash") and \ os.path.isfile(externals() + "gpt_surgeon.py") and \ os.path.isfile(externals() + "uboot-sos.img"): return None print "Initialize externals..." res = execute("./init-externals.sh \"%s\"" % log_file()) if res != 0: print "Failed with code %d.\nLog file is ./generated/init.log" % res quit() print
def prepare_bootloader(self): try: new_bl = generated() + "bootloader.bin" print "Copy %s to %s" % (self.bootloader, new_bl) shutil.copyfile(self.bootloader, new_bl) self.bootloader = new_bl except shutil.Error as e: print e return False except IOError as e: print "I/O error({0}): {$1}".format(e.errno, e.strerror) return False except: print "Error: %s" % (sys.exc_info()[1]) return False return True
def repart(self): print "AC100 repartition:" print " bl: %s" % self.bootloader print " bct: %s" % self.bct print " cfg: %s" % self.config if not self.check_files(): return 2 if not self.prepare_bootloader(): print "Error: can't prepare bootloader for config" return 3 # chdir to ./generated, otherwise nvflash will not find bootloader.bin os.chdir(generated()) res = repart(self.bct, self.config) if res != 0: print "Error: failed to repart using nvflash" return res return 0