summaryrefslogtreecommitdiff
path: root/tools/kwboot.c
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2022-02-03 17:45:20 +0100
committerStefan Roese <sr@denx.de>2022-02-10 07:12:16 +0100
commitde7514046ea5e66ecdfcffc59031e0561d5b3aa6 (patch)
tree02b153c6d81f358d2658284ed4bbcb9ce4af4f8a /tools/kwboot.c
parentf99a169c19149fd005783c37c815518fb5ac9bdf (diff)
downloadu-boot-socfpga-de7514046ea5e66ecdfcffc59031e0561d5b3aa6.tar.gz
tools: kwboot: Fix detection of quit esc sequence
Quit esc sequence may be also in the middle of the read buffer. Fix the detection for that case. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'tools/kwboot.c')
-rw-r--r--tools/kwboot.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c
index 2684f0e75a..7737188f0d 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1183,10 +1183,10 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate)
static int
kwboot_term_pipe(int in, int out, const char *quit, int *s)
{
+ char buf[128];
ssize_t nin;
- char _buf[128], *buf = _buf;
- nin = read(in, buf, sizeof(_buf));
+ nin = read(in, buf, sizeof(buf));
if (nin <= 0)
return -1;
@@ -1194,18 +1194,21 @@ kwboot_term_pipe(int in, int out, const char *quit, int *s)
int i;
for (i = 0; i < nin; i++) {
- if (*buf == quit[*s]) {
+ if (buf[i] == quit[*s]) {
(*s)++;
- if (!quit[*s])
- return 0;
- buf++;
- nin--;
+ if (!quit[*s]) {
+ nin = i - *s;
+ break;
+ }
} else {
- if (kwboot_write(out, quit, *s) < 0)
+ if (*s > i && kwboot_write(out, quit, *s - i) < 0)
return -1;
*s = 0;
}
}
+
+ if (i == nin)
+ nin -= *s;
}
if (kwboot_write(out, buf, nin) < 0)