aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMarek BehĂșn <marek.behun@nic.cz>2021-09-24 23:06:52 +0200
committerStefan Roese <sr@denx.de>2021-10-01 11:07:13 +0200
commit12df7b790f2836580621271709ffba3c1339d929 (patch)
treee606c1b465e8bd71ffc4c0b24d32399083e8f3cc /tools
parent2e81b3ab0eb46c8214d11d49cb65d9a5f13ee268 (diff)
downloadu-boot-12df7b790f2836580621271709ffba3c1339d929.zip
u-boot-12df7b790f2836580621271709ffba3c1339d929.tar.gz
u-boot-12df7b790f2836580621271709ffba3c1339d929.tar.bz2
tools: kwboot: Allow greater timeout when executing header code
When executing header code (which contains U-Boot SPL in most cases), wait 10s after every non-xmodem character received (i.e. printed by U-Boot SPL) before timing out. Sometimes DDR training, which runs in SPL, may be slow. Signed-off-by: Marek BehĂșn <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'tools')
-rw-r--r--tools/kwboot.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c
index 2f4c61b..cf6e32c 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -24,6 +24,7 @@
#include <unistd.h>
#include <stdint.h>
#include <termios.h>
+#include <time.h>
#include <sys/mman.h>
#include <sys/stat.h>
@@ -68,6 +69,7 @@ struct kwboot_block {
} __packed;
#define KWBOOT_BLK_RSP_TIMEO 1000 /* ms */
+#define KWBOOT_HDR_RSP_TIMEO 10000 /* ms */
static int kwboot_verbose;
@@ -375,6 +377,26 @@ kwboot_xm_makeblock(struct kwboot_block *block, const void *data,
return n;
}
+static uint64_t
+_now(void)
+{
+ struct timespec ts;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ts)) {
+ static int err_print;
+
+ if (!err_print) {
+ perror("clock_gettime() does not work");
+ err_print = 1;
+ }
+
+ /* this will just make the timeout not work */
+ return -1ULL;
+ }
+
+ return ts.tv_sec * 1000ULL + (ts.tv_nsec + 500000) / 1000000;
+}
+
static int
_is_xm_reply(char c)
{
@@ -384,16 +406,21 @@ _is_xm_reply(char c)
static int
kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print)
{
+ int timeout = allow_non_xm ? KWBOOT_HDR_RSP_TIMEO : blk_rsp_timeo;
+ uint64_t recv_until = 0;
int rc;
*non_xm_print = 0;
while (1) {
- rc = kwboot_tty_recv(fd, c, 1, blk_rsp_timeo);
+ rc = kwboot_tty_recv(fd, c, 1, timeout);
if (rc) {
if (errno != ETIMEDOUT)
return rc;
- *c = NAK;
+ else if (recv_until && recv_until < _now())
+ return -1;
+ else
+ *c = NAK;
}
/* If received xmodem reply, end. */
@@ -402,9 +429,10 @@ kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print)
/*
* If printing non-xmodem text output is allowed and such a byte
- * was received, print it.
+ * was received, print it and increase receiving time.
*/
if (allow_non_xm) {
+ recv_until = _now() + timeout;
putchar(*c);
fflush(stdout);
*non_xm_print = 1;