From 418b43b0fafcaaaa2c62fdb712829599fe74bb31 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sat, 15 Mar 2025 16:37:50 -0400 Subject: [PATCH] flashtool: usb bootloader request fix Open the usb device with the O_NOCTTY flag. This prevents a SIGHUP signal from killing the flashtool process if the bootloader request results in a hangup event. Signed-off-by: Eric Callahan --- scripts/flashtool.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/flashtool.py b/scripts/flashtool.py index 590f45a..4ab9f8e 100755 --- a/scripts/flashtool.py +++ b/scripts/flashtool.py @@ -959,16 +959,13 @@ class SerialSocket(BaseSocket): start_usb_id = usb_info["usb_id"] fd: Optional[int] = None with contextlib.suppress(OSError): - fd = os.open(str(device), os.O_RDWR) - fcntl.ioctl( - fd, termios.TIOCMBIS, struct.pack('I', termios.TIOCM_DTR) - ) + fd = os.open(str(device), os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) + dtr_data = struct.pack('I', termios.TIOCM_DTR) + fcntl.ioctl(fd, termios.TIOCMBIS, dtr_data) t = termios.tcgetattr(fd) t[4] = t[5] = termios.B1200 termios.tcsetattr(fd, termios.TCSANOW, t) - fcntl.ioctl( - fd, termios.TIOCMBIC, struct.pack('I', termios.TIOCM_DTR) - ) + fcntl.ioctl(fd, termios.TIOCMBIC, dtr_data) if fd is not None: os.close(fd) output("Waiting for USB Reconnect.")