def _power_on_do_openocd_start(self): self.log.action = "openocd start" kws = {} if self.serial != None: kws["serial_string"] = self.serial else: kws["serial_string"] = "MISCONFIGURATION? SERIAL-NUMBER NOT SPECIFIED" # Well, reusing the TCP port range is creating plenty of # problems, as when we kill it and try to restart it, the # sockets are lingering and it fails to reopen it... #tcp_port_base = ttbl.tcp_port_assigner(2 + self.max_target) # Schew it, let's go random -- if it fails, it'll be restarted # with another one tcp_port_base = commonl.tcp_port_assigner(2 + self.max_target, ttbl.config.tcp_port_range) self.log.debug("port base %d" % tcp_port_base) self.tt.fsdb.set("openocd.port", "%d" % tcp_port_base) self.log.debug("port base read: %s" % self.tt.fsdb.get("openocd.port")) args = [ self.openocd_path, "-c", 'tcl_port %d' % (tcp_port_base + 1), "-c", 'telnet_port %d' % tcp_port_base, "--log_output", self.log_name, "-c", 'gdb_port %d' % (tcp_port_base + 2) ] if self.debug: args.append("-d") if self.openocd_scripts: args += ["-s", self.openocd_scripts] if 'interface' in self.board and self.board['interface'] != None: args += ["-f", self.board['interface']] if 'board' in self.board and self.board['board'] != None: if self.openocd_scripts == None: self.openocd_scripts = "" args += [ "-f", os.path.join(self.openocd_scripts, "board", self.board['board'] + ".cfg") ] if self.board['config']: with open(os.path.join(self.tt.state_dir, "openocd.cfg"), "w") \ as cfgf: cfgf.write(self.board['config'] % kws) args += ["-f", cfgf.name] self.log.info("OpenOCD command line %s" % " ".join(args)) self.tt.fsdb.set("openocd.path", commonl.which(self.openocd_path)) p = subprocess.Popen(args, shell=False, cwd=self.tt.state_dir, close_fds=True) # loop for a while until we can connect to it, to prove it's # done initializing self.pid = p.pid self.pid_s = "%d" % p.pid ttbl.daemon_pid_add(self.pid) # FIXME: race condition if it died? # Write a pidfile, as openocd can't do it himself :/ [daemon 101] self.tt.fsdb.set("openocd.pid", self.pid_s)
def _power_on_do_openocd_start(self): self.log.action = "openocd start" kws = {} if self.serial != None: kws["serial_string"] = self.serial else: kws["serial_string"] = "MISCONFIGURATION? SERIAL-NUMBER NOT SPECIFIED" # Well, reusing the TCP port range is creating plenty of # problems, as when we kill it and try to restart it, the # sockets are lingering and it fails to reopen it... #tcp_port_base = ttbl.tcp_port_assigner(2 + self.max_target) # Schew it, let's go random -- if it fails, it'll be restarted # with another one tcp_port_base = commonl.tcp_port_assigner(2 + self.max_target, ttbl.config.tcp_port_range) self.log.debug("port base %d" % tcp_port_base) self.tt.fsdb.set("openocd.port", "%d" % tcp_port_base) self.log.debug("port base read: %s" % self.tt.fsdb.get("openocd.port")) args = [ self.openocd_path, "-c", 'tcl_port %d' % (tcp_port_base + 1), "-c", 'telnet_port %d' % tcp_port_base, "--log_output", self.log_name, "-c", 'gdb_port %d' % (tcp_port_base + 2) ] if self.debug: args.append("-d") if self.openocd_scripts: args += [ "-s", self.openocd_scripts ] if 'interface' in self.board and self.board['interface'] != None: args += [ "-f", self.board['interface'] ] if 'board' in self.board and self.board['board'] != None: if self.openocd_scripts == None: self.openocd_scripts = "" args += [ "-f", os.path.join(self.openocd_scripts, "board", self.board['board'] + ".cfg")] if self.board['config']: with open(os.path.join(self.tt.state_dir, "openocd.cfg"), "w") \ as cfgf: cfgf.write(self.board['config'] % kws) args += [ "-f", cfgf.name ] self.log.info("OpenOCD command line %s" % " ".join(args)) self.tt.fsdb.set("openocd.path", commonl.which(self.openocd_path)) p = subprocess.Popen(args, shell = False, cwd = self.tt.state_dir, close_fds = True) # loop for a while until we can connect to it, to prove it's # done initializing self.pid = p.pid self.pid_s = "%d" % p.pid ttbl.daemon_pid_add(self.pid) # FIXME: race condition if it died? # Write a pidfile, as openocd can't do it himself :/ [daemon 101] self.tt.fsdb.set("openocd.pid", self.pid_s)