def cli(): resets = ResetSeqFactory("rumboot.resetseq") formats = ImageFormatDb("rumboot.images") chips = ChipDb("rumboot.chips") parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="rumboot-daemon {} - Collaborative board access daemon\n". format(rumboot.__version__) + rumboot.__copyright__) helper = arghelper() helper.add_terminal_opts(parser) helper.add_file_handling_opts(parser) helper.add_resetseq_options(parser, resets) parser.add_argument( "-L", "--listen", help="Specify address:port to listen (default 0.0.0.0:10000)", nargs=1, metavar=('listen'), default=["0.0.0.0:10000"], required=False) opts = parser.parse_args() c = helper.detect_chip_type(opts, chips, formats) if c == None: c = chips["basis"] return 1 print("Detected chip: %s (%s)" % (c.name, c.part)) if c == None: print("ERROR: Failed to auto-detect chip type") return 1 if opts.baud == None: opts.baud = [c.baudrate] reset = resets[opts.reset[0]](opts) if opts.log: term.logstream = opts.log print("Reset method: %s" % (reset.name)) print("Baudrate: %d bps" % int(opts.baud[0])) print("Serial Port: %s" % opts.port[0]) print("Listen address: %s" % opts.listen) term = terminal(opts.port[0], opts.baud[0]) srv = server(term, opts.listen[0]) srv.set_reset_seq(reset) if "file" in opts: srv.preload_binaries(opts.file) return srv.loop()
def __init__(self, target_chip=None, transport="xmodem", args=None): resets = ResetSeqFactory("rumboot.resetseq") formats = ImageFormatDb("rumboot.images") chips = ChipDb("rumboot.chips") c = chips[target_chip] parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description= "Rumboot Scripting Engine script, using rumboot-tools {}\n".format( rumboot.__version__) + rumboot.__copyright__) helper = arghelper() helper.add_terminal_opts(parser) helper.add_resetseq_options(parser, resets) opts = parser.parse_args() dump_path = os.path.dirname(__file__) + "/romdumps/" helper.detect_terminal_options(opts, c) print("Target Chip: %s (%s)" % (c.name, c.part)) if c == None: raise Exception("ERROR: Failed to auto-detect chip type") if opts.baud == None: opts.baud = [c.baudrate] reset = resets[opts.reset[0]](opts) term = terminal(opts.port[0], opts.baud[0]) term.set_chip(c) try: romdump = open(dump_path + c.romdump, "r") term.add_dumps({'rom': romdump}) except: pass if opts.log: term.logstream = opts.log print("Reset method: %s" % (reset.name)) print("Baudrate: %d bps" % int(opts.baud[0])) print("Port: %s" % opts.port[0]) if opts.edcl and c.edcl != None: term.xfer.selectTransport("edcl") print("Preferred data transport: %s" % term.xfer.how) print("--- --- --- --- --- --- --- --- --- ") self.terminal = term self.xfer = term.xfer
def intialize_testing(target_chip=None): resets = ResetSeqFactory("rumboot.resetseq") formats = ImageFormatDb("rumboot.images") chips = ChipDb("rumboot.chips") c = chips[target_chip] parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="rumboot-factorytest {} - RumBoot Board Testing Framework\n" .format(rumboot.__version__) + rumboot.__copyright__) helper = arghelper() helper.add_terminal_opts(parser) helper.add_resetseq_options(parser, resets) opts = parser.parse_args() dump_path = os.path.dirname(__file__) + "/romdumps/" helper.detect_terminal_options(opts, c) print("Detected chip: %s (%s)" % (c.name, c.part)) if c == None: print("ERROR: Failed to auto-detect chip type") return 1 if opts.baud == None: opts.baud = [c.baudrate] reset = resets[opts.reset[0]](opts) term = terminal(opts.port[0], opts.baud[0]) term.set_chip(c) try: romdump = open(dump_path + c.romdump, "r") term.add_dumps({'rom': romdump}) except: pass if opts.log: term.logstream = opts.log print("Reset method: %s" % (reset.name)) print("Baudrate: %d bps" % int(opts.baud[0])) print("Port: %s" % opts.port[0]) if opts.edcl and c.edcl != None: term.xfer.selectTransport("edcl") print("Preferred data transport: %s" % term.xfer.how) print("--- --- --- --- --- --- ") return term, reset
def _test_execution_in_thread(self, test_desc): params_for_xfers = { "default": self._test_context.env["connection"]["transport"], "force_static_arp": self._test_context.env["connection"]["force_static_arp"], "edcl_timeout": self._test_context.env["connection"]["edcl_timeout"] } if self._test_context.env["connection"]["edcl_ip"]: params_for_xfers["edcl_ip"] = self._test_context.env["connection"][ "edcl_ip"] if self._test_context.env["connection"]["edcl_mac"]: params_for_xfers["edcl_mac"] = self._test_context.env[ "connection"]["edcl_mac"] term = terminal(self._test_context.env["connection"]["port"], self._test_context.env["connection"]["baud"], xferparams=params_for_xfers) term.set_chip(self._test_context.chip) term.xfer.selectTransport( self._test_context.env["connection"]["transport"]) reset = self._test_context.resets[ self._test_context.env["reset"]["name"]]( term, self._test_context.env["reset"]) try: test = test_desc.test_class(test_desc.name, test_desc.full_name, term, reset, self._test_context.env, test_desc.params, self._user_interaction) if test.run(): test_desc.status = TEST_STATUS_PASSED except Exception: print(traceback.format_exc()) # ??? for term deleting (must be fixed in the terminal class) term.xfer.xfers = None term.xfer.how = None term.xfer.xfer = None term.xfer = None term.opf.objects = None term.opf = None term.ser.write = None term.ser = None
def create_core_stuff_from_options(self, opts): resets = ResetSeqFactory("rumboot.resetseq") formats = ImageFormatDb("rumboot.images") chips = ChipDb("rumboot.chips") c = self.detect_chip_type(opts, chips, formats) if not c: return None, None, None print("Detected chip: %s (%s)" % (c.name, c.part)) if c == None: raise Exception("ERROR: Failed to auto-detect chip type") if opts.baud == None: opts.baud = c.baudrate params_for_xfers = { "force_static_arp": opts.force_static_arp, "default": "xmodem" } if opts.edcl: params_for_xfers["default"] = "edcl" if opts.edcl_ip: params_for_xfers["edcl_ip"] = opts.edcl_ip if opts.edcl_mac: params_for_xfers["edcl_mac"] = opts.edcl_mac if opts.edcl_timeout: params_for_xfers["edcl_timeout"] = opts.edcl_timeout term = terminal(opts.port, opts.baud, xferparams=params_for_xfers) reset = resets[opts.reset[0]](term, vars(opts)) term.set_chip(c) reset.set_chip(c) print("Reset method: %s" % (reset.name)) print("Baudrate: %d bps" % int(opts.baud)) print("Port: %s" % opts.port) print("Preferred data transport: %s" % params_for_xfers["default"]) return c, term, reset
def cli(): resets = ResetSeqFactory("rumboot.resetseq") formats = ImageFormatDb("rumboot.images") chips = ChipDb("rumboot.chips") parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="rumboot-gdb {} - Debugger launcher tool\n".format( rumboot.__version__) + rumboot.__copyright__) helper = arghelper() helper.add_terminal_opts(parser) parser.add_argument( "-v", "--verbose", action='store_true', default=False, help="Print serial debug messages during preload phase"), parser.add_argument("-z", "--spl-path", help="Path for SPL writers (Debug only)", type=str, required=False) parser.add_argument("-L", "--load", help="Load binary on start", action='store_true', default=False, required=False) parser.add_argument("-f", "--file", help="Application ELF file to debug", type=str, required=False) parser.add_argument( "-x", "--exec", help="Execute supplied binary on start (Implies --load)", action='store_true', default=False, required=False) parser.add_argument("-R", "--rebuild", help="Attempt to rebuild binary", action='store_true', default=False, required=False) parser.add_argument("--debug-remote", help="Send 'set debug remote 1' to gdb for debugging", action='store_true', default=False, required=False) parser.add_argument("--debug-serial", help="Send 'set debug serial 1' to gdb for debugging", action='store_true', default=False, required=False) parser.add_argument("-g", "--gdb-path", help="Path to flashrom binary", type=str, required=False) parser.add_argument("-G", "--gdb-gui", help="Start GDB gui", action='store_true', default=False, required=False) parser.add_argument("-c", "--chip_id", help="Chip Id (numeric or name)", required=True) parser.add_argument('remaining', nargs=argparse.REMAINDER, default=[], help="Extra gdb arguments (e.g. filename)") helper.add_resetseq_options(parser, resets) opts = parser.parse_args() if opts.remaining and opts.remaining[0] == "--": opts.remaining = opts.remaining[1:] gdb_args = " ".join(opts.remaining) c = chips[opts.chip_id] if (c == None): return 1 helper.detect_terminal_options(opts, c) print("Detected chip: %s (%s)" % (c.name, c.part)) if c.warning != None: print(" --- WARNING ---") print(c.warning) print(" --- WARNING ---") print("") spl_path = os.path.dirname(__file__) + "/tools/" if opts.baud == None: opts.baud = [c.baudrate] reset = resets[opts.reset[0]](opts) term = terminal(opts.port[0], opts.baud[0]) term.verbose = opts.verbose term.set_chip(c) if opts.log: term.logstream = opts.log try: spl = c.stub except: print("ERROR: Target chip (%s) doesn't have a gdb stub" % (c.name)) return 1 if opts.spl_path != None: spl_path = opts.spl_path print("SPL %s" % (spl_path + c.stub)) spl = spl_path + c.stub if opts.gdb_path: gdb = opts.gdb_path else: gdb = c.gdb print(opts.rebuild, opts.file) if opts.rebuild and opts.file != None: if 0 != os.system("cmake --build . --target " + opts.file): os.exit(1) print("Reset method: %s" % (reset.name)) print("Baudrate: %d bps" % int(opts.baud[0])) print("Port: %s" % opts.port[0]) print("GDB: %s" % gdb) if opts.edcl and c.edcl != None: term.xfer.selectTransport("edcl") reset.resetToHost() term.add_binaries(spl) term.loop(break_after_uploads=True) while True: s = term.ser.readline() if opts.verbose: print(s) if s.decode("utf-8", errors="replace").find("STUB READY!") != -1: break print("gdb-stub is ready for operations, starting gdb..") # If we're here, we'll need to setup socket redirector port = 20000 while True: try: print("Trying port %d" % port) server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(("127.0.0.1", port)) server.listen() break except: port = port + 1 if port > 30000: print("Weird shit going on, breaking") break #Fire up flashrom in background if opts.gdb_gui: flr = ipgdbgui() else: flr = ipgdb() if opts.debug_remote: flr.add_command("set debug remote 1") if opts.debug_serial: flr.add_command("set debug serial 1") if opts.file != None: gdb_args = gdb_args + opts.file flr.configure(gdb, port, gdb_args) if opts.load or opts.exec: flr.add_command("load") if opts.exec: flr.add_command("continue") flr.start() #Accept connection connection, client_address = server.accept() connection.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) rd = redirector() rd.configure(term.ser, connection) rd.start() return flr.join()
def cli(): resets = ResetSeqFactory("rumboot.resetseq") formats = ImageFormatDb("rumboot.images") chips = ChipDb("rumboot.chips") parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description="rumboot-xrun {} - RumBoot X-Modem execution tool\n".format(rumboot.__version__) + rumboot.__copyright__) helper = arghelper() helper.add_file_handling_opts(parser, True) helper.add_terminal_opts(parser) helper.add_resetseq_options(parser, resets) plus = parser.add_argument_group("Plusargs parser options", """ rumboot-xrun can parse plusargs (similar to verilog simulator) and use them for runtime file uploads. This option is intended to be used for """) plus.add_argument('-A', '--plusargs', nargs='*') parser.add_argument("-R", "--rebuild", help="Attempt to rebuild/update target before uploading", action="store_true", default=False, required=False) parser.add_argument("-I", '--stdin', help="Use stdin redirection to tty", action="store_true", default=False, required=False) parser.add_argument('--replay-no-exit', help="Do not exit on panics/rom returns when replaying logs (for batch analysis)", action="store_true", default=False, required=False) if len(sys.argv) == 1: sys.argv = sys.argv + ["--help"] opts = parser.parse_args() #Open files, rebuild if needed opts.file[0], dumps = helper.process_files(opts.file[0], opts.rebuild) dump_path = os.path.dirname(__file__) + "/romdumps/" plusargs = {} if opts.plusargs: for a in opts.plusargs: ret = parse("+{}={}", a) if ret: plusargs[ret[0]] = ret[1] continue ret = parse("+{}", a) if ret: plusargs[ret[0]] = True c = helper.detect_chip_type(opts, chips, formats) if c == None: return 1 print("Detected chip: %s (%s)" % (c.name, c.part)) if c == None: print("ERROR: Failed to auto-detect chip type") return 1 if opts.baud == None: opts.baud = [ c.baudrate ] reset = resets[opts.reset[0]](opts) term = terminal(opts.port[0], opts.baud[0]) term.set_chip(c) term.plusargs = plusargs term.xfer.xfers["edcl"].force_static_arp = opts.force_static_arp try: romdump = open(dump_path + c.romdump, "r") term.add_dumps({'rom' : romdump}) except: pass if opts.log: term.logstream = opts.log print("Reset method: %s" % (reset.name)) print("Baudrate: %d bps" % int(opts.baud[0])) print("Port: %s" % opts.port[0]) reset.resetToHost() term.add_binaries(opts.file) term.add_dumps(dumps) term.replay_till_the_end = opts.replay_no_exit if opts.edcl and c.edcl != None: term.xfer.selectTransport("edcl") print("Preferred data transport: %s" % term.xfer.how) return term.loop(opts.stdin)
def cli(): resets = ResetSeqFactory("rumboot.resetseq") formats = ImageFormatDb("rumboot.images") chips = ChipDb("rumboot.chips") parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="rumboot-flashrom {} - flashrom wrapper tool\n".format( rumboot.__version__) + rumboot.__copyright__) helper = arghelper() helper.add_terminal_opts(parser) parser.add_argument( "-v", "--verbose", action='store_true', default=False, help="Print serial debug messages during preload phase"), parser.add_argument( "-m", "--memory", help="SPI bus to use. Names match '-m help' of rumboot-xflash", nargs=1, metavar=('memory'), default="help", required=True) parser.add_argument("-z", "--spl-path", help="Path for SPL writers (Debug only)", type=str, required=False) parser.add_argument("-f", "--flashrom-path", help="Path to flashrom binary", type=str, required=False) parser.add_argument("-c", "--chip_id", help="Chip Id (numeric or name)", required=True) parser.add_argument('remaining', nargs=argparse.REMAINDER, default=[], help="Flashrom arguments") # parser.add_argument('-F', '--flashrom-args', nargs='*', default=[], ) helper.add_resetseq_options(parser, resets) opts = parser.parse_args() if opts.remaining and opts.remaining[0] == "--": opts.remaining = opts.remaining[1:] flashrom_args = " ".join(opts.remaining) c = chips[opts.chip_id] if (c == None): return 1 helper.detect_terminal_options(opts, c) print("Detected chip: %s (%s)" % (c.name, c.part)) if c.warning != None: print(" --- WARNING ---") print(c.warning) print(" --- WARNING ---") print("") spl_path = os.path.dirname(__file__) + "/tools/" if opts.baud == None: opts.baud = [c.baudrate] reset = resets[opts.reset[0]](opts) term = terminal(opts.port[0], opts.baud[0]) term.verbose = opts.verbose term.set_chip(c) if opts.log: term.logstream = opts.log mem = opts.memory[0] if not mem: return 1 if mem == "help": for mem, spl in c.flashrom.items(): print("Memory %16s: %s" % (mem, spl)) return 1 try: spl = c.flashrom[mem] except: print( "ERROR: Target chip (%s) doesn't have bus '%s'. Run with -m help for a list" % (c.name, mem)) return 1 if opts.spl_path != None: spl_path = opts.spl_path print("SPL %s" % (spl_path + c.flashrom[mem])) spl = spl_path + c.flashrom[mem] print("Reset method: %s" % (reset.name)) print("Baudrate: %d bps" % int(opts.baud[0])) print("Port: %s" % opts.port[0]) flashrom = None flashrom_paths = [ "/usr/local/sbin/flashrom", "/sbin/flashrom", "/usr/sbin/flashrom", "C:\\flashrom\\flashrom.exe" ] if opts.flashrom_path and os.path.exists(opts.flashrom_path): flashrom = opts.flashrom_path elif opts.flashrom_path: print("[W] Specified flashrom path (%s) is invalid, trying to guess" % opts.flashrom_path) for f in flashrom_paths: if os.path.exists(f): flashrom = f if flashrom == None: print( "FATAL: Failed to find working flashrom. Please download and install from https://flashrom.org/" ) return 1 print("FlashRom: %s" % flashrom) print("FlashRom args: %s" % flashrom_args) reset.resetToHost() term.add_binaries(spl) term.loop(break_after_uploads=True) while True: s = term.ser.readline() if s.decode("utf-8", errors="replace").find("SERPROG READY!") != -1: break print("Serprog stub ready!") if opts.port[0].find("socket://") == -1: #Use flashrom directly ret = os.system(flashrom + " -p serprog:dev=" + opts.port[0] + ":" + opts.baud[0]) reset.resetToNormal return ret # If we're here, we'll need to setup socket redirector port = 20000 while True: try: print("Trying port %d" % port) server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(("127.0.0.1", port)) server.listen() break except: port = port + 1 if port > 30000: print("Weird shit going on, breaking") break #Fire up flashrom in background flr = ipflashrom() flr.configure(flashrom, port, flashrom_args) flr.start() #Accept connection connection, client_address = server.accept() connection.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) rd = redirector() rd.configure(term.ser, connection) rd.start() return flr.join()
def cli(): resets = ResetSeqFactory("rumboot.resetseq") formats = ImageFormatDb("rumboot.images") chips = ChipDb("rumboot.chips") parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="rumboot-xflash {} - RumBoot X-Modem firmware update tool\n" .format(rumboot.__version__) + rumboot.__copyright__) helper = arghelper() helper.add_file_handling_opts(parser, True) helper.add_terminal_opts(parser) parser.add_argument("-v", "--verbose", action='store_true', help="Print serial debug messages during update"), parser.add_argument("-m", "--memory", help="Memory program. Help for a list of memories", nargs=1, metavar=('memory'), default="help", required=True) parser.add_argument("-z", "--spl-path", help="Path for SPL writers (Debug only)", type=str, required=False) helper.add_resetseq_options(parser, resets) opts = parser.parse_args() c = helper.detect_chip_type(opts, chips, formats) if (c == None): return 1 mem = opts.memory[0] if not mem: return 1 if mem == "help": for mem, spl in c.memories.items(): print("Memory %16s: %s" % (mem, spl)) return 1 #Open files, rebuild if needed opts.file[0], dumps = helper.process_files(opts.file[0], False) print("Detected chip: %s (%s)" % (c.name, c.part)) if c.warning != None: print(" --- WARNING ---") print(c.warning) print(" --- WARNING ---") print("") spl_path = os.path.dirname(__file__) + "/spl-tools/" if opts.baud == None: opts.baud = [c.baudrate] reset = resets[opts.reset[0]](opts) term = terminal(opts.port[0], opts.baud[0]) term.set_chip(c) if opts.log: term.logstream = opts.log term.verbose = opts.verbose term.xfer.xfers["edcl"].force_static_arp = opts.force_static_arp try: spl = c.memories[mem] except: print( "ERROR: Target chip (%s) doesn't have memory '%s'. Run with -m help for a list" % (c.name, mem)) return 1 if opts.spl_path != None: spl_path = opts.spl_path print("SPL %s" % (spl_path + c.memories[mem])) spl = spl_path + c.memories[mem] print("Reset method: %s" % (reset.name)) print("Baudrate: %d bps" % int(opts.baud[0])) print("Port: %s" % opts.port[0]) reset.resetToHost() term.add_binaries(spl) term.add_binaries(opts.file[0][0]) if opts.edcl and c.edcl != None: term.xfer.selectTransport("edcl") print("Preferred data transport: %s" % term.xfer.how) reset.resetToHost() term.loop()