soc/tools/litex_term: continue cleanup
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 19 Feb 2016 16:44:25 +0000 (17:44 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 19 Feb 2016 16:44:25 +0000 (17:44 +0100)
litex/soc/tools/litex_term.py

index 06d8843c4c465c53adcb08dea816132218f95ee7..97fb0579a863380f7fe8b4adad4e0e6f9abc274b 100644 (file)
@@ -116,7 +116,7 @@ class LiteXTerm:
         self.reader_alive = False
         self.writer_alive = False
 
-        self.promp_detect_buffer = bytes(len(sfl_prompt_req))
+        self.prompt_detect_buffer = bytes(len(sfl_prompt_req))
         self.magic_detect_buffer = bytes(len(sfl_magic_req))
 
     def open(self, port, baudrate):
@@ -182,8 +182,8 @@ class LiteXTerm:
 
     def detect_prompt(self, data):
         if len(data):
-            self.promp_detect_buffer = self.promp_detect_buffer[1:] + data
-            return self.promp_detect_buffer == sfl_prompt_req
+            self.prompt_detect_buffer = self.prompt_detect_buffer[1:] + data
+            return self.prompt_detect_buffer == sfl_prompt_req
         else:
             return False
 
@@ -213,11 +213,7 @@ class LiteXTerm:
                 if c == b"\r":
                     sys.stdout.write(b"\n")
                 else:
-                    try:
-                        # TODO: cleanup
-                        sys.stdout.write(c.decode())
-                    except:
-                        pass
+                       sys.stdout.buffer.write(c)
                 sys.stdout.flush()
 
                 if self.kernel_image is not None:
@@ -243,10 +239,7 @@ class LiteXTerm:
     def writer(self):
         try:
             while self.writer_alive:
-                try:
-                    b = getkey()
-                except KeyboardInterrupt:
-                    b = b"\x03"
+                b = getkey()
                 if b == b"\x03":
                     self.stop()
                 elif b == b"\n":
@@ -296,13 +289,12 @@ def _get_args():
 def main():
     args = _get_args()
     term = LiteXTerm(args.serial_boot, args.kernel, args.kernel_adr)
-    term.open(args.port, args.speed)
-    term.start()
     try:
+        term.open(args.port, args.speed)
+        term.start()
         term.join(True)
-    except KeyboardInterrupt:
-        pass
-    term.close()
+    finally:
+        term.close()
 
 
 if __name__ == "__main__":