From 7f0f22f9a7c6b2ebda0b5bd5306450fe7a12488d Mon Sep 17 00:00:00 2001 From: Giovanni Giacobbi Date: Sat, 14 Nov 2020 16:29:02 +0000 Subject: [PATCH] stm32flash: Added patch to lock serial device Patch backported from upstream master Signed-off-by: Giovanni Giacobbi --- utils/stm32flash/Makefile | 2 +- ...ck-if-tty-is-already-opened-by-anoth.patch | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 utils/stm32flash/patches/0001-Serial-POSIX-Check-if-tty-is-already-opened-by-anoth.patch diff --git a/utils/stm32flash/Makefile b/utils/stm32flash/Makefile index 1136acb83e..6bd44794b6 100644 --- a/utils/stm32flash/Makefile +++ b/utils/stm32flash/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=stm32flash PKG_VERSION:=0.4 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://sourceforge.net/projects/stm32flash/files diff --git a/utils/stm32flash/patches/0001-Serial-POSIX-Check-if-tty-is-already-opened-by-anoth.patch b/utils/stm32flash/patches/0001-Serial-POSIX-Check-if-tty-is-already-opened-by-anoth.patch new file mode 100644 index 0000000000..d0692ca876 --- /dev/null +++ b/utils/stm32flash/patches/0001-Serial-POSIX-Check-if-tty-is-already-opened-by-anoth.patch @@ -0,0 +1,47 @@ +From 1f10b4e3364de54f108bc42e4f789893afd44c9a Mon Sep 17 00:00:00 2001 +From: Mickael GARDET +Date: Thu, 1 Sep 2016 17:12:03 +0200 +Subject: [PATCH] Serial POSIX: Check if tty is already opened by another + stm32flash + +--- + serial_posix.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/serial_posix.c b/serial_posix.c +index 46b8a94..020e796 100644 +--- a/serial_posix.c ++++ b/serial_posix.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + #include "serial.h" + #include "port.h" +@@ -45,6 +46,13 @@ static serial_t *serial_open(const char *device) + free(h); + return NULL; + } ++ ++ if(lockf(h->fd,F_TLOCK,0) != 0) ++ { ++ fprintf(stderr, "Error: %s is already open\n", device); ++ free(h); ++ return NULL; ++ } + fcntl(h->fd, F_SETFL, 0); + + tcgetattr(h->fd, &h->oldtio); +@@ -62,6 +70,7 @@ static void serial_close(serial_t *h) + { + serial_flush(h); + tcsetattr(h->fd, TCSANOW, &h->oldtio); ++ lockf(h->fd, F_ULOCK, 0); + close(h->fd); + free(h); + } +-- +2.17.1 +