diff --git a/gateway.py b/gateway.py index 5ba2afa..3e98c0c 100644 --- a/gateway.py +++ b/gateway.py @@ -218,6 +218,11 @@ class Gateway(): self.config[key] = value self.save_config() + def set_timeout(self, timeout): + self.timeout = timeout + if self.use_ssh and self.ssh: + self.ssh.set_timeout(int(self.timeout * 1000)) + def get_ssh(self, verbose = 0, contimeout = None): if self.ssh: try: @@ -236,7 +241,7 @@ class Gateway(): self.ssh.handshake(self.socket) self.ssh.userauth_password('root', 'root') self.ssh.set_blocking(True) - self.ssh.set_timeout(self.timeout * 1000); + self.ssh.set_timeout(int(self.timeout * 1000)) return self.ssh except Exception as e: #print(e) @@ -293,7 +298,7 @@ class Gateway(): return False return True - def run_cmd(self, cmd, msg = None): + def run_cmd(self, cmd, msg = None, timeout = None): if self.use_ssh: ssh = self.get_ssh(self.verbose) else: @@ -308,6 +313,9 @@ class Gateway(): for idx, cmd in enumerate(cmdlist): if self.use_ssh: channel = ssh.open_session() + if timeout is not None: + saved_timeout = ssh.get_timeout() + ssh.set_timeout(int(timeout * 1000)) #channel.pty('xterm') #print("exec = '{}'".format(cmd)) channel.execute(cmd) @@ -315,6 +323,8 @@ class Gateway(): channel.wait_eof() except ssh2.exceptions.Timeout: die("SSH execute command timedout! CMD: \"{}\"".format(cmd)) + if timeout is not None: + ssh.set_timeout(saved_timeout) try: channel.close() channel.wait_closed() diff --git a/install_fw.py b/install_fw.py index 4978046..bc19500 100644 --- a/install_fw.py +++ b/install_fw.py @@ -471,14 +471,15 @@ if fw_num is not None: if not kernel.cmd or not rootfs.cmd: die("Flashing recipe unknown!") +gw.set_timeout(12) gw.upload(kernel.fn_local, kernel.fn_remote) gw.upload(rootfs.fn_local, rootfs.fn_remote) print('Writing kernel image to addr {} ...'.format("0x%08X" % kernel.addr)) print(" " + kernel.cmd) -gw.run_cmd(kernel.cmd) +gw.run_cmd(kernel.cmd, timeout = 12) print('Writing rootfs image to addr {} ...'.format("0x%08X" % rootfs.addr)) print(" " + rootfs.cmd) -gw.run_cmd(rootfs.cmd) +gw.run_cmd(rootfs.cmd, timeout = 40) print("The firmware has been successfully flashed!")