[U-Boot] [PATCH 1/4] Blackfin: jtagconsole: disable output processing

Avoid extra carriage returns in the output by disabling output processing. Otherwise, whenever the remote sends a \r\n, we end up with \r\r\n.
Reported-by: Vivi Li vivi.li@analog.com Signed-off-by: Mike Frysinger vapier@gentoo.org --- tools/jtagconsole | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/jtagconsole b/tools/jtagconsole index 24198c8..d404fac 100755 --- a/tools/jtagconsole +++ b/tools/jtagconsole @@ -31,9 +31,9 @@ if [ -z "${ip}" ] || [ -n "$3" ] ; then usage "Invalid number of arguments" fi
-trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15 +trap "stty icanon echo opost intr ^C" 0 2 3 5 10 13 15 echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
-stty -icanon -echo intr ^T +stty -icanon -echo -opost intr ^T nc ${ip} ${port} exit 0

If the other side isn't listening, we should reset the state to ignore the whole message and not just the part we missed. This makes it easier to connect at any time to the jtag console without worrying about the two sides getting out of sync and thus sending garbage back and forth.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- arch/blackfin/cpu/jtag-console.c | 40 ++++++++++++++++++++++++++++++------- 1 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/arch/blackfin/cpu/jtag-console.c b/arch/blackfin/cpu/jtag-console.c index 1cd619f..46b30a0 100644 --- a/arch/blackfin/cpu/jtag-console.c +++ b/arch/blackfin/cpu/jtag-console.c @@ -1,7 +1,7 @@ /* * jtag-console.c - console driver over Blackfin JTAG * - * Copyright (c) 2008 Analog Devices Inc. + * Copyright (c) 2008-2010 Analog Devices Inc. * * Licensed under the GPL-2 or later. */ @@ -10,23 +10,37 @@ #include <stdio_dev.h> #include <asm/blackfin.h>
+static inline uint32_t bfin_write_emudat(uint32_t emudat) +{ + __asm__ __volatile__("emudat = %0;" : : "d"(emudat)); + return emudat; +} + +static inline uint32_t bfin_read_emudat(void) +{ + uint32_t emudat; + __asm__ __volatile__("%0 = emudat;" : "=d"(emudat)); + return emudat; +} + #ifndef CONFIG_JTAG_CONSOLE_TIMEOUT # define CONFIG_JTAG_CONSOLE_TIMEOUT 500 #endif
/* The Blackfin tends to be much much faster than the JTAG hardware. */ -static void jtag_write_emudat(uint32_t emudat) +static bool jtag_write_emudat(uint32_t emudat) { static bool overflowed = false; ulong timeout = get_timer(0) + CONFIG_JTAG_CONSOLE_TIMEOUT; while (bfin_read_DBGSTAT() & 0x1) { if (overflowed) - return; + return overflowed; if (timeout < get_timer(0)) overflowed = true; } overflowed = false; - __asm__ __volatile__("emudat = %0;" : : "d"(emudat)); + bfin_write_emudat(emudat); + return overflowed; } /* Transmit a buffer. The format is: * [32bit length][actual data] @@ -39,11 +53,21 @@ static void jtag_send(const char *c, uint32_t len) return;
/* First send the length */ - jtag_write_emudat(len); + if (jtag_write_emudat(len)) + return;
/* Then send the data */ - for (i = 0; i < len; i += 4) - jtag_write_emudat((c[i] << 0) | (c[i+1] << 8) | (c[i+2] << 16) | (c[i+3] << 24)); + for (i = 0; i < len; i += 4) { + uint32_t emudat = + (c[i + 0] << 0) | + (c[i + 1] << 8) | + (c[i + 2] << 16) | + (c[i + 3] << 24); + if (jtag_write_emudat(emudat)) { + bfin_write_emudat(0); + return; + } + } } static void jtag_putc(const char c) { @@ -88,7 +112,7 @@ static int jtag_getc(void) /* wait for new data ! */ while (!jtag_tstc_dbg()) continue; - __asm__("%0 = emudat;" : "=d"(emudat)); + emudat = bfin_read_emudat();
if (inbound_len == 0) { /* grab the length */

While we're in here, add some useful debug points. We need custom debug statements because we need the output to only go to the serial port. If we used the standard debug helpers, the output would also go to the stdout (which would be the jtag console) and make it hard to figure out what is going where exactly.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- arch/blackfin/cpu/jtag-console.c | 28 +++++++++++++++++++++++++++- 1 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/arch/blackfin/cpu/jtag-console.c b/arch/blackfin/cpu/jtag-console.c index 46b30a0..bde8bee 100644 --- a/arch/blackfin/cpu/jtag-console.c +++ b/arch/blackfin/cpu/jtag-console.c @@ -10,6 +10,22 @@ #include <stdio_dev.h> #include <asm/blackfin.h>
+#ifdef DEBUG +# define dprintf(...) serial_printf(__VA_ARGS__) +#else +# define dprintf(...) do { if (0) printf(__VA_ARGS__); } while (0) +#endif + +static inline void dprintf_decode(const char *s, uint32_t len) +{ + uint32_t i; + for (i = 0; i < len; ++i) + if (s[i] < 0x20 || s[i] >= 0x7f) + dprintf("\%o", s[i]); + else + dprintf("%c", s[i]); +} + static inline uint32_t bfin_write_emudat(uint32_t emudat) { __asm__ __volatile__("emudat = %0;" : : "d"(emudat)); @@ -52,6 +68,10 @@ static void jtag_send(const char *c, uint32_t len) if (len == 0) return;
+ dprintf("%s("", __func__); + dprintf_decode(c, len); + dprintf("", %i)\n", len); + /* First send the length */ if (jtag_write_emudat(len)) return; @@ -83,7 +103,10 @@ static size_t inbound_len, leftovers_len; /* Lower layers want to know when jtag has data */ static int jtag_tstc_dbg(void) { - return (bfin_read_DBGSTAT() & 0x2); + int ret = (bfin_read_DBGSTAT() & 0x2); + if (ret) + dprintf("%s: ret:%i\n", __func__, ret); + return ret; }
/* Higher layers want to know when any data is available */ @@ -101,6 +124,9 @@ static int jtag_getc(void) int ret; uint32_t emudat;
+ dprintf("%s: inlen:%zu leftlen:%zu left:%x\n", __func__, + inbound_len, leftovers_len, leftovers); + /* see if any data is left over */ if (leftovers_len) { --leftovers_len;

Serial devices currently have to manually stuff \r after every \n found, but this is a bit more difficult with the jtag console since we process everything in chunks of 4 bit. So we have to scan & stuff the whole string rather than what most serial drivers do which is output on a byte per byte basis.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- arch/blackfin/cpu/jtag-console.c | 41 +++++++++++++++++++++++++++++-------- 1 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/arch/blackfin/cpu/jtag-console.c b/arch/blackfin/cpu/jtag-console.c index bde8bee..e0f2975 100644 --- a/arch/blackfin/cpu/jtag-console.c +++ b/arch/blackfin/cpu/jtag-console.c @@ -7,6 +7,7 @@ */
#include <common.h> +#include <malloc.h> #include <stdio_dev.h> #include <asm/blackfin.h>
@@ -61,33 +62,55 @@ static bool jtag_write_emudat(uint32_t emudat) /* Transmit a buffer. The format is: * [32bit length][actual data] */ -static void jtag_send(const char *c, uint32_t len) +static void jtag_send(const char *raw_str, uint32_t len) { - uint32_t i; + const char *cooked_str; + uint32_t i, ex;
if (len == 0) return;
+ /* Ugh, need to output \r after \n */ + ex = 0; + for (i = 0; i < len; ++i) + if (raw_str[i] == '\n') + ++ex; + if (ex) { + char *c = malloc(len + ex); + cooked_str = c; + for (i = 0; i < len; ++i) { + *c++ = raw_str[i]; + if (raw_str[i] == '\n') + *c++ = '\r'; + } + len += ex; + } else + cooked_str = raw_str; + dprintf("%s("", __func__); - dprintf_decode(c, len); + dprintf_decode(cooked_str, len); dprintf("", %i)\n", len);
/* First send the length */ if (jtag_write_emudat(len)) - return; + goto done;
/* Then send the data */ for (i = 0; i < len; i += 4) { uint32_t emudat = - (c[i + 0] << 0) | - (c[i + 1] << 8) | - (c[i + 2] << 16) | - (c[i + 3] << 24); + (cooked_str[i + 0] << 0) | + (cooked_str[i + 1] << 8) | + (cooked_str[i + 2] << 16) | + (cooked_str[i + 3] << 24); if (jtag_write_emudat(emudat)) { bfin_write_emudat(0); - return; + goto done; } } + + done: + if (cooked_str != raw_str) + free((char *)cooked_str); } static void jtag_putc(const char c) {
participants (1)
-
Mike Frysinger