def set_printk(self, CUR=1, DEF=1, MIN=1, BTDEF=7): self.sendline('echo "%d %d %d %d" > /proc/sys/kernel/printk' % (CUR, DEF, MIN, BTDEF)) self.expect(self.prompt) if not BFT_DEBUG: common.print_bold("printk set to %d %d %d %d" % (CUR, DEF, MIN, BTDEF))
def flash_rootfs(self, ROOTFS): common.print_bold("\n===== Flashing rootfs =====\n") filename = self.prepare_file(ROOTFS) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) self.spi_flash_bin("0x006b0000", size, self.uboot_ddr_addr, "0x1920000")
def flash_linux(self, KERNEL): common.print_bold("\n===== Flashing linux =====\n") filename = self.prepare_file(KERNEL) self.sendline('setenv firmwareName %s' % filename) self.expect(self.uprompt) self.sendline('run update_both_images') self.expect(self.uprompt, timeout=90)
def flash_rootfs(self, ROOTFS): '''Flash Root File System image''' common.print_bold("\n===== Flashing rootfs =====\n") filename = self.prepare_file(ROOTFS) if self.model == "ap135-nand": self.tftp_get_file_uboot("0x82060000", filename) self.sendline('nand erase 0x700000 0x1E00000') self.expect('OK') self.expect(self.uprompt) self.sendline('nand write.jffs2 0x82060000 0x700000 $filesize') self.expect('OK') self.expect(self.uprompt) # erase the overlay otherwise, things will be in a weird state self.sendline('nand erase 0x1F00000') self.expect('OK') self.expect(self.uprompt) return self.tftp_get_file_uboot("0x82060000", filename) self.sendline('erase %s +$filesize' % self.rootfs_addr) self.expect('Erased .* sectors', timeout=180) self.expect(self.uprompt) self.sendline('protect off all') self.expect(self.uprompt) self.sendline('cp.b $fileaddr %s $filesize' % self.rootfs_addr) self.expect('done', timeout=80) self.expect(self.uprompt) self.sendline('cmp.b $fileaddr %s $filesize' % self.rootfs_addr) self.expect('Total of .* bytes were the same')
def collect_stats(self, stats=[]): pp = self.get_pp_dev() self.stats = [] self.failed_stats = {} for stat in stats: if 'mpstat' in stat: for i in range(5): try: pp.sendcontrol('c') pp.sendline( "kill `ps | grep mpstat | grep -v grep | awk '{print $1}'`" ) pp.expect_exact( "kill `ps | grep mpstat | grep -v grep | awk '{print $1}'`" ) pp.expect(pp.prompt) break except: if i == 4: print_bold("FAILED TO KILL MPSTAT!") pp.sendcontrol('c') pass pp.sendline('mpstat -P ALL 5 > %s/mpstat &' % self.tmpdir) if 0 == pp.expect(['mpstat: not found'] + pp.prompt): self.failed_stats['mpstat'] = float('nan') continue elif 0 == pp.expect(['mpstat: not found', pexpect.TIMEOUT], timeout=4): self.failed_stats['mpstat'] = float('nan') continue self.stats.append(stat)
def flash_uboot(self, uboot): '''In this case it's flashing the vfat partition of the bootload. Need to have that image u-boot and serial turned on via dtoverlay for things to work after flashing''' common.print_bold("\n===== Flashing bootloader (and u-boot) =====\n") filename = self.prepare_file(uboot) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) self.sendline('mmc part') # get offset of ext (83) partition after a fat (0c) partition self.expect('\r\n\s+\d+\s+(\d+)\s+(\d+).*0c( Boot)?\r\n') start = hex(int(self.match.groups()[0])) if (int(size) != int(self.match.groups()[1]) * 512): raise Exception("Partition size does not match, refusing to flash") self.expect(self.uprompt) count = hex(int(size / 512)) self.sendline('mmc erase %s %s' % (start, count)) self.expect(self.uprompt) self.sendline('mmc write %s %s %s' % (self.uboot_ddr_addr, start, count)) self.expect(self.uprompt, timeout=120) self.reset() self.wait_for_boot() self.setup_uboot_network()
def flash_meta(self, META_BUILD): ''' A meta image contains several components wrapped up into one file. Here we flash a meta image onto the board. ''' common.print_bold("\n===== Flashing meta =====\n") filename = self.prepare_file(META_BUILD) self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) # probe SPI flash incase this is a NOR boot meta if self.model not in ("dk01", "dk04"): self.sendline('sf probe') self.expect('sf probe') self.expect(self.uprompt) self.sendline('machid=%s && imgaddr=%s && source $imgaddr:script && echo DONE' % (self.machid, self.uboot_ddr_addr)) self.expect('DONE') try: self.expect("Can't find 'script' FIT subimage", timeout=5) except: pass else: self.sendline('machid=%s && imgaddr=%s && source $imgaddr:SCRIPT && echo DONE' % (self.machid, self.uboot_ddr_addr)) self.expect('DONE') self.expect('DONE', timeout=400) self.expect(self.uprompt) # reboot incase partitions changed self.reset() self.wait_for_boot() self.setup_uboot_network()
def flash_rootfs(self, ROOTFS): '''Flash Root File System image''' common.print_bold("\n===== Flashing rootfs =====\n") filename = self.prepare_file(ROOTFS) if self.model == "ap135-nand": self.tftp_get_file_uboot("0x82060000", filename) self.sendline('nand erase 0x700000 0x1E00000') self.expect('OK') self.expect(self.uprompt) self.sendline('nand write.jffs2 0x82060000 0x700000 $filesize') self.expect('OK') self.expect(self.uprompt) # erase the overlay otherwise, things will be in a weird state self.sendline('nand erase 0x1F00000') self.expect('OK') self.expect(self.uprompt) return self.tftp_get_file_uboot("0x82060000", filename) self.sendline('erase %s +$filesize' % self.rootfs_addr) self.expect('Erased .* sectors', timeout=180) self.expect(self.uprompt) self.sendline('cp.b $fileaddr %s $filesize' % self.rootfs_addr) self.expect('done', timeout=80) self.expect(self.uprompt) self.sendline('cmp.b $fileaddr %s $filesize' % self.rootfs_addr) self.expect('Total of .* bytes were the same')
def boot_linux(self, rootfs=None, bootargs=None): common.print_bold("\n===== Booting linux for %s on %s =====" % (self.model, self.root_type)) self.switch_to_mode(MODE_DISABLED) self.sendline('npcpu start') self.sendline('bootkernel -c %kernel_cmd_line%') self.delaybetweenchar = None
def flash_meta(self, META_BUILD, wan, lan): ''' A meta image contains several components wrapped up into one file. Here we flash a meta image onto the board. ''' common.print_bold("\n===== Flashing meta =====\n") filename = self.prepare_file(META_BUILD) self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) # probe SPI flash incase this is a NOR boot meta if self.model not in ("dk01", "dk04"): self.sendline('sf probe') self.expect('sf probe') self.expect(self.uprompt) self.sendline( 'machid=%s && imgaddr=%s && source $imgaddr:script && echo DONE' % (self.machid, self.uboot_ddr_addr)) self.expect('DONE') try: self.expect("Can't find 'script' FIT subimage", timeout=5) except: pass else: self.sendline( 'machid=%s && imgaddr=%s && source $imgaddr:SCRIPT && echo DONE' % (self.machid, self.uboot_ddr_addr)) self.expect('DONE') self.expect('DONE', timeout=400) self.expect(self.uprompt) # reboot incase partitions changed self.reset() self.wait_for_boot() self.setup_uboot_network()
def flash_linux(self, KERNEL): common.print_bold("\n===== Flashing linux =====\n") filename = self.prepare_file(KERNEL) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) self.spi_flash_bin(self.kernel_addr, size, self.uboot_ddr_addr, self.kernel_size)
def flash_rootfs(self, ROOTFS): common.print_bold("\n===== Flashing rootfs =====\n") filename = self.prepare_file(ROOTFS) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) self.nand_flash_bin(self.rootfs_addr, self.rootfs_size, self.uboot_ddr_addr)
def send(self, s): if not self.in_detect_fatal_error and self.linux_booted: self.in_detect_fatal_error = True error_detect.detect_fatal_error(self) self.in_detect_fatal_error = False if BFT_DEBUG: common.print_bold("%s = sending: %s" % (error_detect.caller_file_line(3), repr(s))) return super(OpenWrtRouter, self).send(s)
def flash_linux(self, KERNEL): common.print_bold("\n===== Flashing linux =====\n") filename = self.prepare_file(KERNEL) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) self.sendline('fatwrite mmc 0 %s uImage $filesize' % self.uboot_ddr_addr) self.expect(self.uprompt)
def flash_linux(self, KERNEL): common.print_bold("\n===== Flashing linux =====\n") filename = self.prepare_file(KERNEL) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) self.kernel_file = os.path.basename(KERNEL) self.sendline('fatwrite mmc 0 %s %s $filesize' % (self.kernel_file, self.uboot_ddr_addr)) self.expect(self.uprompt)
def set_printk(self, CUR=1, DEF=1, MIN=1, BTDEF=7): '''Modifies the log level in kernel''' try: self.sendline('echo "%d %d %d %d" > /proc/sys/kernel/printk' % (CUR, DEF, MIN, BTDEF)) self.expect(self.prompt, timeout=10) if not BFT_DEBUG: print_bold("printk set to %d %d %d %d" % (CUR, DEF, MIN, BTDEF)) except: pass
def flash_uboot(self, uboot): '''Flash Universal Bootloader image.''' common.print_bold("\n===== Flashing u-boot =====\n") filename = self.prepare_file(uboot) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) self.sendline('ipq_nand sbl') self.expect(self.uprompt) self.nand_flash_bin(self.uboot_addr, self.uboot_size, self.uboot_ddr_addr) self.reset() self.wait_for_boot() self.setup_uboot_network()
def flash_uboot(self, uboot): '''Flash Universal Bootloader image.''' common.print_bold("\n===== Flashing u-boot =====\n") filename = self.prepare_file(uboot) self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) self.sendline('ipq_nand sbl') self.expect(self.uprompt) self.nand_flash_bin(self.uboot_addr, self.uboot_size, self.uboot_ddr_addr) self.reset() self.wait_for_boot() self.setup_uboot_network()
def send(self, s): if BFT_DEBUG: common.print_bold("%s = sending: %s" % (error_detect.caller_file_line(3), repr(s))) if self.delaybetweenchar is not None: ret = 0 for char in s: ret += super(BaseDevice, self).send(char) time.sleep(self.delaybetweenchar) return ret return super(BaseDevice, self).send(s)
def boot_linux(self, rootfs=None): common.print_bold("\n===== Booting linux for %s on %s =====" % (self.model, self.root_type)) if self.model == "ap135-nand": self.sendline('setenv bootcmd nboot 0x81000000 0 0x100000') self.expect(self.uprompt) else: self.sendline("setenv bootcmd 'bootm %s'" % self.kernel_addr) self.expect(self.uprompt) self.sendline("saveenv") self.expect(self.uprompt) self.sendline("print") self.expect(self.uprompt) self.sendline("boot")
def expect_helper(self, pattern, wrapper, *args, **kwargs): if not BFT_DEBUG: return wrapper(pattern, *args, **kwargs) if 'base.py: expect():' in error_detect.caller_file_line(3) or \ 'base.py: expect_exact():' in error_detect.caller_file_line(3): idx = 5 else: idx = 3 common.print_bold("%s = expecting: %s" % (error_detect.caller_file_line(idx), repr(pattern))) try: ret = wrapper(pattern, *args, **kwargs) frame = error_detect.caller_file_line(idx) if hasattr(self.match, "group"): common.print_bold("%s = matched: %s" % (frame, repr(self.match.group()))) else: common.print_bold("%s = matched: %s" % (frame, repr(pattern))) return ret except: common.print_bold("expired") raise
def boot_linux(self, rootfs=None): common.print_bold("\n===== Booting linux for %s on %s =====" % (self.model, self.root_type)) #self.sendline('setenv bootargs "8250.nr_uarts=1 bcm2708_fb.fbwidth=1824 bcm2708_fb.fbheight=984 bcm2708_fb.fbswap=1 dma.dmachans=0x7f35 bcm2709.boardrev=0xa02082 bcm2709.serial=0xc07187c2 bcm2709.uart_clock=48000000 smsc95xx.macaddr=B8:27:EB:71:87:C2 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 root=mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait"') #self.expect(self.uprompt) self.sendline("setenv bootcmd 'fatload mmc 0 ${kernel_addr_r} uImage; bootm ${kernel_addr_r} - ${fdt_addr}'") self.expect(self.uprompt) self.sendline('saveenv') self.expect(self.uprompt) self.sendline('boot') # Linux handles serial better ? self.delaybetweenchar = None
def boot_linux_ramboot(self): '''Boot Linux from initramfs''' common.print_bold("\n===== Booting linux (ramboot) for %s =====" % self.model) bootargs = 'console=ttyMSM0,115200 clk_ignore_unused norootfssplit mem=256M %s' % self.get_safe_mtdparts() if self.boot_dbg: bootargs += " dyndbg=\"module %s +p\"" % self.boot_dbg self.sendline("setenv bootargs '%s'" % bootargs) self.expect(self.uprompt) self.sendline('set fdt_high 0x85000000') self.expect(self.uprompt) self.sendline("bootm %s" % self.uboot_ddr_addr) self.expect("Loading Device Tree to") self.rambooted = True
def boot_linux(self, rootfs=None, bootargs=""): common.print_bold("\n===== Booting linux for %s on %s =====" % (self.model, self.root_type)) self.reset() self.wait_for_boot() self.sendline("set bootargs 'console=ttyMSM0,115200'") self.expect(self.uprompt) self.sendline("set fsbootargs 'rootfstype=squashfs,jffs2'") self.expect(self.uprompt) self.sendline('set bootcmd bootipq') self.expect(self.uprompt) self.sendline("saveenv") self.expect(self.uprompt) self.sendline("print") self.expect(self.uprompt) self.sendline('run bootcmd')
def boot_linux(self, rootfs=None): common.print_bold("\n===== Booting linux for %s on %s =====" % (self.model, self.root_type)) self.reset() self.wait_for_boot() self.sendline("set bootargs 'console=ttyMSM0,115200'") self.expect(self.uprompt) self.sendline("set fsbootargs 'rootfstype=squashfs,jffs2'") self.expect(self.uprompt) self.sendline('set bootcmd bootipq') self.expect(self.uprompt) self.sendline("saveenv") self.expect(self.uprompt) self.sendline("print") self.expect(self.uprompt) self.sendline('run bootcmd')
def flash_rootfs(self, ROOTFS): common.print_bold("\n===== Flashing rootfs =====\n") filename = self.prepare_file(ROOTFS) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename, timeout=220) self.sendline('mmc part') # get offset of ext (83) partition after a fat (0c) partition self.expect('0c( Boot)?\r\n\s+\d+\s+(\d+)\s+(\d+).*83\r\n') start = hex(int(self.match.groups()[-2])) sectors = int(self.match.groups()[-1]) self.expect(self.uprompt) # increase partition size if required if (int(size) > (sectors * 512)): self.sendline("mmc read %s 0 1" % self.uboot_ddr_addr) self.expect(self.uprompt) gp2_sz = int(self.uboot_ddr_addr, 16) + int("0x1da", 16) self.sendline("mm 0x%08x" % gp2_sz) self.expect("%08x: %08x ?" % (gp2_sz, sectors)) # pad 100M self.sendline('0x%08x' % int((int(size) + 104857600) / 512)) self.sendcontrol('c') self.sendcontrol('c') self.expect(self.uprompt) self.sendline('echo FOO') self.expect_exact('echo FOO') self.expect_exact('FOO') self.expect(self.uprompt) self.sendline("mmc write %s 0 1" % self.uboot_ddr_addr) self.expect(self.uprompt) self.sendline('mmc rescan') self.expect(self.uprompt) self.sendline('mmc part') self.expect(self.uprompt) count = hex(int(size / 512)) self.sendline('mmc erase %s %s' % (start, count)) self.expect(self.uprompt) self.sendline('mmc write %s %s %s' % (self.uboot_ddr_addr, start, count)) self.expect_exact('mmc write %s %s %s' % (self.uboot_ddr_addr, start, count)) self.expect(self.uprompt, timeout=480)
def send(self, s): if BFT_DEBUG: if 'pexpect/__init__.py: sendline():' in error_detect.caller_file_line( 3): idx = 4 else: idx = 3 common.print_bold("%s = sending: %s" % (error_detect.caller_file_line(idx), repr(s))) if self.delaybetweenchar is not None: ret = 0 for char in s: ret += super(BaseDevice, self).send(char) time.sleep(self.delaybetweenchar) return ret return super(BaseDevice, self).send(s)
def boot_linux(self, rootfs=None, bootargs=""): common.print_bold("\n===== Booting linux for %s on %s =====" % (self.model, self.root_type)) self.sendline('fdt addr $fdt_addr') self.expect(self.uprompt) self.sendline('fdt get value bcm_bootargs /chosen bootargs') self.expect(self.uprompt) self.sendline('setenv bootargs "$bcm_bootargs %s"' % bootargs) self.expect(self.uprompt) self.sendline("setenv bootcmd 'fatload mmc 0 ${kernel_addr_r} %s; bootm ${kernel_addr_r} - ${fdt_addr}; booti ${kernel_addr_r} - ${fdt_addr}'" % self.kernel_file) self.expect(self.uprompt) self.sendline('saveenv') self.expect(self.uprompt) self.sendline('boot') # Linux handles serial better ? self.delaybetweenchar = None
def runTest(self): wan_ip = wan.get_interface_ipaddr(wan.iface_dut) wan.sendline('iperf -s -l 1M -w 1M') wan.expect('Server listening on ') board.collect_stats(stats=['mpstat']) time = 10 cmd = "iperf -R -c %s -P %s -t 10 -N -w 1M -l 1M | grep SUM" # prime the pipes... lan.sendline(cmd % (wan_ip, 4)) lan.expect(prompt) prev_con = 0 prev_failed = 0 for con_conn in range(32, 513, 16): try: tstart = datetime.now() lan.sendline(cmd % (wan_ip, con_conn)) failed_cons = 0 while (datetime.now() - tstart).seconds < (time * 2): timeout=(time*2)-(datetime.now() - tstart).seconds if 0 == lan.expect(['write failed: Connection reset by peer'] + prompt, timeout=timeout): failed_cons += 1 else: break print_bold("For iperf with %s connections, %s failed...." % (con_conn, failed_cons)) lan.expect('.*') wan.expect('.*') board.touch() prev_conn = con_conn prev_failed = failed_cons if con_conn == 512: self.result_message = "iPerf Concurrent passed 512 connections (failed conns = %s)" % failed_cons except: self.result_message = "iPerf Concurrent Connections failed entirely at %s (failed conns = %s)" % (prev_conn, prev_failed) break print self.result_message self.recover()
def boot_linux(self, rootfs=None): common.print_bold("\n===== Booting linux for %s on %s =====" % (self.model, self.root_type)) self.reset() self.wait_for_boot() self.sendline("setenv bootcmd bootipq") self.expect(self.uprompt) self.sendline("saveenv") self.expect(self.uprompt) self.sendline("print") self.expect(self.uprompt) self.sendline('run bootcmd') # if run isn't support, we just reset u-boot and # let the bootcmd run that way try: self.expect('Unknown command', timeout=5) except: pass else: self.sendline('reset')
def flash_linux(self, KERNEL): common.print_bold("\n===== Flashing linux =====\n") filename = self.prepare_file(KERNEL) self.tftp_get_file_uboot("0x82060000", filename) if self.model == "ap135-nand": self.sendline('nand erase 0x100000 $filesize') self.expect('OK') self.expect(self.uprompt) self.sendline('nand write.jffs2 0x82060000 0x100000 $filesize') self.expect('OK') self.expect(self.uprompt) return self.sendline('erase %s +$filesize' % self.kernel_addr) self.expect('Erased .* sectors', timeout=60) self.expect(self.uprompt) self.sendline('cp.b $fileaddr %s $filesize' % self.kernel_addr) self.expect('done', timeout=60) self.sendline('cmp.b $fileaddr %s $filesize' % self.kernel_addr) self.expect('Total of .* bytes were the same') self.expect(self.uprompt)
def boot_linux(self, rootfs=None, bootargs=""): common.print_bold("\n===== Booting linux for %s on %s =====" % (self.model, self.root_type)) self.reset() self.wait_for_boot() self.sendline("setenv bootcmd bootipq") self.expect(self.uprompt) self.sendline("saveenv") self.expect(self.uprompt) self.sendline("print") self.expect(self.uprompt) self.sendline('run bootcmd') # if run isn't support, we just reset u-boot and # let the bootcmd run that way try: self.expect('Unknown command', timeout=5) except: pass else: self.sendline('reset')
def flash_rootfs(self, ROOTFS): common.print_bold("\n===== Flashing rootfs =====\n") filename = self.prepare_file(ROOTFS) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename, timeout=220) self.sendline('mmc part') # get offset of ext (83) partition after a fat (0c) partition self.expect('0c( Boot)?\r\n\s+\d+\s+(\d+)\s+(\d+).*83\r\n') start = hex(int(self.match.groups()[-2])) sectors = int(self.match.groups()[-1]) self.expect(self.uprompt) # increase partition size if required if (int(size) > (sectors * 512)): self.sendline("mmc read %s 0 1" % self.uboot_ddr_addr) self.expect(self.uprompt) gp2_sz = int(self.uboot_ddr_addr, 16) + int("0x1da", 16) self.sendline("mm 0x%08x" % gp2_sz) self.expect("%08x: %08x ?" % (gp2_sz, sectors)) # pad 100M self.sendline('0x%08x' % int((int(size) + 104857600) / 512)) self.sendcontrol('c') self.sendcontrol('c') self.expect(self.uprompt) self.sendline('echo FOO') self.expect_exact('echo FOO') self.expect_exact('FOO') self.expect(self.uprompt) self.sendline("mmc write %s 0 1" % self.uboot_ddr_addr) self.expect(self.uprompt) self.sendline('mmc rescan') self.expect(self.uprompt) self.sendline('mmc part') self.expect(self.uprompt) count = hex(int(size/512)) self.sendline('mmc erase %s %s' % (start, count)) self.expect(self.uprompt) self.sendline('mmc write %s %s %s' % (self.uboot_ddr_addr, start, count)) self.expect_exact('mmc write %s %s %s' % (self.uboot_ddr_addr, start, count)) self.expect(self.uprompt, timeout=480)
def detect_crashdump_error(console, s): if re.findall("Crashdump magic found", s): common.print_bold("Crashdump magic found, trying to save data...") console.sendcontrol('c') console.sendcontrol('c') console.sendcontrol('c') console.expect('<INTERRUPT>') console.expect(console.uprompt) console.setup_uboot_network() console.sendline("dumpipq_data") tftp_progress = "#" * 30 tftp_start = "TFTP to server" tftp_done = "Bytes transferred" tftp_expect = [tftp_progress, tftp_start, tftp_done] i = -1 try: # this waits until we get the reseting message which means # we are done while i < 3: i = console.expect(tftp_expect + ["Resetting with watch dog!"] + console.uprompt) except: common.print_bold("Crashdump upload failed") else: common.print_bold("Crashdump upload succeeded") # TODO: actually parse data too? raise Exception('Crashdump detected')
def detect_crashdump_error(console, s): if re.findall("Crashdump magic found", s): common.print_bold("Crashdump magic found, trying to save data..."); console.sendcontrol('c') console.sendcontrol('c') console.sendcontrol('c') console.expect('<INTERRUPT>') console.expect(console.uprompt) console.setup_uboot_network() console.sendline("dumpipq_data") tftp_progress = "#" * 30 tftp_start = "TFTP to server" tftp_done = "Bytes transferred" tftp_expect = [tftp_progress, tftp_start, tftp_done] i = -1 try: # this waits until we get the reseting message which means # we are done while i < 3: i = console.expect(tftp_expect + ["Resetting with watch dog!"] + console.uprompt) except: common.print_bold("Crashdump upload failed") else: common.print_bold("Crashdump upload succeeded") # TODO: actually parse data too? raise Exception('Crashdump detected')
def main(args): # load vocab vocab, vocab_inv = load_vocab(args.model_dir) vocab_source, vocab_target = vocab vocab_inv_source, vocab_inv_target = vocab_inv # load textfile source_dataset = read_data(args.source_filename, vocab_source) print_bold("data #") print("source {}".format(len(source_dataset))) # split into buckets source_buckets = make_buckets(source_dataset) if args.buckets_limit is not None: source_buckets = source_buckets[:args.buckets_limit + 1] print_bold("buckets #data (train)") for size, data in zip(bucket_sizes, source_buckets): print("{} {}".format(size, len(data))) print_bold("buckets #data (dev)") # init model = load_model(args.model_dir) assert model is not None show_source_translation(model, source_buckets, vocab_inv_source, vocab_inv_target)
def boot_linux(self, rootfs=None, bootargs=""): common.print_bold("\n===== Booting linux for %s on %s =====" % (self.model, self.root_type)) self.sendline('fdt addr $fdt_addr') self.expect(self.uprompt) self.sendline('fdt get value bcm_bootargs /chosen bootargs') self.expect(self.uprompt) self.sendline('setenv bootargs "$bcm_bootargs %s"' % bootargs) self.expect(self.uprompt) self.sendline( "setenv bootcmd 'fatload mmc 0 ${kernel_addr_r} %s; bootm ${kernel_addr_r} - ${fdt_addr}; booti ${kernel_addr_r} - ${fdt_addr}'" % self.kernel_file) self.expect(self.uprompt) self.sendline('saveenv') self.expect(self.uprompt) self.sendline('boot') # Linux handles serial better ? self.delaybetweenchar = None
def flash_uboot(self, uboot): '''In this case it's flashing the vfat partition of the bootload. Need to have that image u-boot and serial turned on via dtoverlay for things to work after flashing''' common.print_bold("\n===== Flashing bootloader (and u-boot) =====\n") filename = self.prepare_file(uboot) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) self.sendline('mmc part') # get offset of ext (83) partition after a fat (0c) partition self.expect('\r\n\s+\d+\s+(\d+)\s+(\d+).*0c( Boot)?\r\n') start = hex(int(self.match.groups()[0])) if (int(size) != int(self.match.groups()[1]) * 512): raise Exception("Partition size does not match, refusing to flash") self.expect(self.uprompt) count = hex(int(size/512)) self.sendline('mmc erase %s %s' % (start, count)) self.expect(self.uprompt) self.sendline('mmc write %s %s %s' % (self.uboot_ddr_addr, start, count)) self.expect(self.uprompt, timeout=120) self.reset() self.wait_for_boot() self.setup_uboot_network()
def expect_helper(self, pattern, wrapper, *args, **kwargs): if not BFT_DEBUG: return wrapper(pattern, *args, **kwargs) common.print_bold("%s = expecting: %s" % (error_detect.caller_file_line(2), repr(pattern))) try: ret = wrapper(pattern, *args, **kwargs) if hasattr(self.match, "group"): common.print_bold("%s = matched: %s" % (error_detect.caller_file_line(1), repr(self.match.group()))) else: common.print_bold("%s = matched: %s" % (error_detect.caller_file_line(1), repr(pattern))) return ret except: common.print_bold("expired") raise
def expect_helper(self, pattern, wrapper, *args, **kwargs): if not BFT_DEBUG: return wrapper(pattern, *args, **kwargs) common.print_bold("%s = expecting: %s" % (error_detect.caller_file_line(2), repr(pattern))) try: ret = wrapper(pattern, *args, **kwargs) if hasattr(self.match, "group"): common.print_bold("%s = matched: %s" % (error_detect.caller_file_line(2), repr(self.match.group()))) else: common.print_bold("%s = matched: %s" % (error_detect.caller_file_line(2), repr(pattern))) return ret except: common.print_bold("expired") raise
def expect(self, *args, **kwargs): if BFT_DEBUG: common.print_bold("%s = expecting: %s" % (error_detect.caller_file_line(2), repr(args[0]))) try: return super(OpenWrtRouter, self).expect(*args, **kwargs) except: if not self.in_detect_fatal_error and self.linux_booted: self.in_detect_fatal_error = True error_detect.detect_fatal_error(self) self.in_detect_fatal_error = False if BFT_DEBUG: common.print_bold("expired") raise else: if BFT_DEBUG: common.print_bold("found")
def flash_linux(self, KERNEL): common.print_bold("\n===== Flashing linux =====\n") filename = self.prepare_file(KERNEL) size = self.tftp_get_file_uboot(self.uboot_ddr_addr, filename) self.spi_flash_bin("0x0062b0000", size, self.uboot_ddr_addr, "0x400000")
def flash_linux(self, KERNEL): common.print_bold("\n===== Flashing linux =====\n") filename = self.prepare_file(KERNEL) self.sendline('tftpboot $defaultLoadAddr %s && nand erase $priKernAddr $priFwSize && nand write $defaultLoadAddr $priKernAddr $filesize' % filename) self.expect(self.uprompt)
def boot_linux(self, rootfs=None, bootargs=None): common.print_bold("\n===== Booting linux for %s on %s =====" % (self.model, self.root_type)) self.sendline('npcpu start') self.sendline('bootkernel -c %kernel_cmd_line%') self.delaybetweenchar = None
def sendcontrol(self, char): if BFT_DEBUG: common.print_bold("%s = sending: control-%s" % (error_detect.caller_file_line(3), repr(char))) return super(BaseDevice, self).sendcontrol(char)
def flash_linux(self, KERNEL): common.print_bold("\n===== Flashing linux =====\n") filename = self.prepare_file(KERNEL) raise Exception("Kernel is in UBI rootfs, not separate")