summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2010-07-23 16:51:49 -0400
committerMike Frysinger <vapier@gentoo.org>2010-07-25 15:17:34 -0400
commitb990c7bda4d8f4501b3383be9ed44327de24f36f (patch)
treeba0837445a7568f003d6ff124d466d21e9d2d5b5 /arch
parent4fff5ac2f89140361e373818aa3c8c6c7dbd20e9 (diff)
Blackfin: jtag-console: handle newline stuffing
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>
Diffstat (limited to 'arch')
-rw-r--r--arch/blackfin/cpu/jtag-console.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/arch/blackfin/cpu/jtag-console.c b/arch/blackfin/cpu/jtag-console.c
index bde8beeca54..e0f2975603b 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)
{