public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] common/xyzModem.c: unifdef (Remove useless #ifdefs)
@ 2017-04-04 17:42 Alexandru Gagniuc
  2017-04-04 17:42 ` [U-Boot] [PATCH 2/2] common/xyzModem.c: Do not use hard-coded address for debug buffer Alexandru Gagniuc
  2017-04-09  1:15 ` [U-Boot] [U-Boot, 1/2] common/xyzModem.c: unifdef (Remove useless #ifdefs) Tom Rini
  0 siblings, 2 replies; 4+ messages in thread
From: Alexandru Gagniuc @ 2017-04-04 17:42 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Alexandru Gagniuc <alex.g@adaptrum.com>
---
 common/xyzModem.c  | 103 -----------------------------------------------------
 include/xyzModem.h |   7 ----
 2 files changed, 110 deletions(-)

diff --git a/common/xyzModem.c b/common/xyzModem.c
index e0d87db..6ded958 100644
--- a/common/xyzModem.c
+++ b/common/xyzModem.c
@@ -39,25 +39,17 @@
 #define CAN 0x18
 #define EOF 0x1A		/* ^Z for DOS officionados */
 
-#define USE_YMODEM_LENGTH
-
 /* Data & state local to the protocol */
 static struct
 {
-#ifdef REDBOOT
-  hal_virtual_comm_table_t *__chan;
-#else
   int *__chan;
-#endif
   unsigned char pkt[1024], *bufp;
   unsigned char blk, cblk, crc1, crc2;
   unsigned char next_blk;	/* Expected block */
   int len, mode, total_retries;
   int total_SOH, total_STX, total_CAN;
   bool crc_mode, at_eof, tx_ack;
-#ifdef USE_YMODEM_LENGTH
   unsigned long file_length, read_length;
-#endif
 } xyz;
 
 #define xyzModem_CHAR_TIMEOUT            2000	/* 2 seconds */
@@ -66,7 +58,6 @@ static struct
 #define xyzModem_CAN_COUNT                3	/* Wait for 3 CAN before quitting */
 
 
-#ifndef REDBOOT			/*SB */
 typedef int cyg_int32;
 static int
 CYGACC_COMM_IF_GETC_TIMEOUT (char chan, char *c)
@@ -156,17 +147,7 @@ parse_num (char *s, unsigned long *val, char **es, char *delim)
       if (_is_hex (c) && ((digit = _from_hex (c)) < radix))
 	{
 	  /* Valid digit */
-#ifdef CYGPKG_HAL_MIPS
-	  /* FIXME: tx49 compiler generates 0x2539018 for MUL which */
-	  /* isn't any good. */
-	  if (16 == radix)
-	    result = result << 4;
-	  else
-	    result = 10 * result;
-	  result += digit;
-#else
 	  result = (result * radix) + digit;
-#endif
 	}
       else
 	{
@@ -190,41 +171,8 @@ parse_num (char *s, unsigned long *val, char **es, char *delim)
   return true;
 }
 
-#endif
 
-#define USE_SPRINTF
 #ifdef DEBUG
-#ifndef USE_SPRINTF
-/*
- * Note: this debug setup only works if the target platform has two serial ports
- * available so that the other one (currently only port 1) can be used for debug
- * messages.
- */
-static int
-zm_dprintf (char *fmt, ...)
-{
-  int cur_console;
-  va_list args;
-
-  va_start (args, fmt);
-#ifdef REDBOOT
-  cur_console =
-    CYGACC_CALL_IF_SET_CONSOLE_COMM
-    (CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
-  CYGACC_CALL_IF_SET_CONSOLE_COMM (1);
-#endif
-  diag_vprintf (fmt, args);
-#ifdef REDBOOT
-  CYGACC_CALL_IF_SET_CONSOLE_COMM (cur_console);
-#endif
-}
-
-static void
-zm_flush (void)
-{
-}
-
-#else
 /*
  * Note: this debug setup works by storing the strings in a fixed buffer
  */
@@ -253,23 +201,13 @@ zm_dprintf (char *fmt, ...)
 static void
 zm_flush (void)
 {
-#ifdef REDBOOT
-  char *p = zm_out_start;
-  while (*p)
-    mon_write_char (*p++);
-#endif
   zm_out = zm_out_start;
 }
-#endif
 
 static void
 zm_dump_buf (void *buf, int len)
 {
-#ifdef REDBOOT
-  diag_vdump_buf_with_offset (zm_dprintf, buf, len, 0);
-#else
 
-#endif
 }
 
 static unsigned char zm_buf[2048];
@@ -476,9 +414,6 @@ xyzModem_get_hdr (void)
 int
 xyzModem_stream_open (connection_info_t * info, int *err)
 {
-#ifdef REDBOOT
-  int console_chan;
-#endif
   int stat = 0;
   int retries = xyzModem_MAX_RETRIES;
   int crc_retries = xyzModem_MAX_RETRIES_WITH_CRC;
@@ -492,29 +427,9 @@ xyzModem_stream_open (connection_info_t * info, int *err)
     }
 #endif
 
-#ifdef REDBOOT
-  /* Set up the I/O channel.  Note: this allows for using a different port in the future */
-  console_chan =
-    CYGACC_CALL_IF_SET_CONSOLE_COMM
-    (CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
-  if (info->chan >= 0)
-    {
-      CYGACC_CALL_IF_SET_CONSOLE_COMM (info->chan);
-    }
-  else
-    {
-      CYGACC_CALL_IF_SET_CONSOLE_COMM (console_chan);
-    }
-  xyz.__chan = CYGACC_CALL_IF_CONSOLE_PROCS ();
-
-  CYGACC_CALL_IF_SET_CONSOLE_COMM (console_chan);
-  CYGACC_COMM_IF_CONTROL (*xyz.__chan, __COMMCTL_SET_TIMEOUT,
-			  xyzModem_CHAR_TIMEOUT);
-#else
 /* TODO: CHECK ! */
   int dummy = 0;
   xyz.__chan = &dummy;
-#endif
   xyz.len = 0;
   xyz.crc_mode = true;
   xyz.at_eof = false;
@@ -524,10 +439,8 @@ xyzModem_stream_open (connection_info_t * info, int *err)
   xyz.total_SOH = 0;
   xyz.total_STX = 0;
   xyz.total_CAN = 0;
-#ifdef USE_YMODEM_LENGTH
   xyz.read_length = 0;
   xyz.file_length = 0;
-#endif
 
   CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
 
@@ -546,12 +459,10 @@ xyzModem_stream_open (connection_info_t * info, int *err)
 	  /* Y-modem file information header */
 	  if (xyz.blk == 0)
 	    {
-#ifdef USE_YMODEM_LENGTH
 	      /* skip filename */
 	      while (*xyz.bufp++);
 	      /* get the length */
 	      parse_num ((char *) xyz.bufp, &xyz.file_length, NULL, " ");
-#endif
 	      /* The rest of the file name data block quietly discarded */
 	      xyz.tx_ack = true;
 	    }
@@ -604,13 +515,8 @@ xyzModem_stream_read (char *buf, int size, int *err)
 				("ACK block %d (%d)\n", xyz.blk, __LINE__));
 		      xyz.next_blk = (xyz.next_blk + 1) & 0xFF;
 
-#if defined(xyzModem_zmodem) || defined(USE_YMODEM_LENGTH)
 		      if (xyz.mode == xyzModem_xmodem || xyz.file_length == 0)
 			{
-#else
-		      if (1)
-			{
-#endif
 			  /* Data blocks can be padded with ^Z (EOF) characters */
 			  /* This code tries to detect and remove them */
 			  if ((xyz.bufp[xyz.len - 1] == EOF) &&
@@ -625,7 +531,6 @@ xyzModem_stream_read (char *buf, int size, int *err)
 			    }
 			}
 
-#ifdef USE_YMODEM_LENGTH
 		      /*
 		       * See if accumulated length exceeds that of the file.
 		       * If so, reduce size (i.e., cut out pad bytes)
@@ -640,7 +545,6 @@ xyzModem_stream_read (char *buf, int size, int *err)
 			      xyz.len -= (xyz.read_length - xyz.file_length);
 			    }
 			}
-#endif
 		      break;
 		    }
 		  else if (xyz.blk == ((xyz.next_blk - 1) & 0xFF))
@@ -809,10 +713,3 @@ xyzModem_error (int err)
 /*
  * RedBoot interface
  */
-#if 0				/* SB */
-GETC_IO_FUNCS (xyzModem_io, xyzModem_stream_open, xyzModem_stream_close,
-	       xyzModem_stream_terminate, xyzModem_stream_read,
-	       xyzModem_error);
-RedBoot_load (xmodem, xyzModem_io, false, false, xyzModem_xmodem);
-RedBoot_load (ymodem, xyzModem_io, false, false, xyzModem_ymodem);
-#endif
diff --git a/include/xyzModem.h b/include/xyzModem.h
index 0eddbbc..4b667f7 100644
--- a/include/xyzModem.h
+++ b/include/xyzModem.h
@@ -44,9 +44,6 @@
 #define xyzModem_abort 2
 
 
-#ifdef REDBOOT
-extern getc_io_funcs_t xyzModem_io;
-#else
 #define CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT
 #define CYGACC_CALL_IF_SET_CONSOLE_COMM(x)
 
@@ -60,12 +57,8 @@ typedef struct {
     char *filename;
     int   mode;
     int   chan;
-#ifdef CYGPKG_REDBOOT_NETWORKING
-    struct sockaddr_in *server;
-#endif
 } connection_info_t;
 
-#endif
 
 
 int   xyzModem_stream_open(connection_info_t *info, int *err);
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH 2/2] common/xyzModem.c: Do not use hard-coded address for debug buffer
  2017-04-04 17:42 [U-Boot] [PATCH 1/2] common/xyzModem.c: unifdef (Remove useless #ifdefs) Alexandru Gagniuc
@ 2017-04-04 17:42 ` Alexandru Gagniuc
  2017-04-09  1:15   ` [U-Boot] [U-Boot, " Tom Rini
  2017-04-09  1:15 ` [U-Boot] [U-Boot, 1/2] common/xyzModem.c: unifdef (Remove useless #ifdefs) Tom Rini
  1 sibling, 1 reply; 4+ messages in thread
From: Alexandru Gagniuc @ 2017-04-04 17:42 UTC (permalink / raw)
  To: u-boot

Under the plethora of #ifdefs, the xyzModem code hid this pearl:
static char *zm_out = (char *) 0x00380000;
This was only enabled when DEBUG is defined, so it's probably why it
went unnoticed for so long. No idea what platform had memory at that
exact location, but the this approach is extremely hacky.
Use a static buffer instead.

Signed-off-by: Alexandru Gagniuc <alex.g@adaptrum.com>
---
 common/xyzModem.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/common/xyzModem.c b/common/xyzModem.c
index 6ded958..a0c5dfe 100644
--- a/common/xyzModem.c
+++ b/common/xyzModem.c
@@ -176,16 +176,10 @@ parse_num (char *s, unsigned long *val, char **es, char *delim)
 /*
  * Note: this debug setup works by storing the strings in a fixed buffer
  */
-#define FINAL
-#ifdef FINAL
-static char *zm_out = (char *) 0x00380000;
-static char *zm_out_start = (char *) 0x00380000;
-#else
-static char zm_buf[8192];
-static char *zm_out = zm_buf;
-static char *zm_out_start = zm_buf;
+static char zm_debug_buf[8192];
+static char *zm_out = zm_debug_buf;
+static char *zm_out_start = zm_debug_buf;
 
-#endif
 static int
 zm_dprintf (char *fmt, ...)
 {
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [U-Boot, 1/2] common/xyzModem.c: unifdef (Remove useless #ifdefs)
  2017-04-04 17:42 [U-Boot] [PATCH 1/2] common/xyzModem.c: unifdef (Remove useless #ifdefs) Alexandru Gagniuc
  2017-04-04 17:42 ` [U-Boot] [PATCH 2/2] common/xyzModem.c: Do not use hard-coded address for debug buffer Alexandru Gagniuc
@ 2017-04-09  1:15 ` Tom Rini
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Rini @ 2017-04-09  1:15 UTC (permalink / raw)
  To: u-boot

On Tue, Apr 04, 2017 at 10:42:30AM -0700, Alexandru Gagniuc wrote:

> Signed-off-by: Alexandru Gagniuc <alex.g@adaptrum.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170408/a1f75ea1/attachment.sig>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [U-Boot, 2/2] common/xyzModem.c: Do not use hard-coded address for debug buffer
  2017-04-04 17:42 ` [U-Boot] [PATCH 2/2] common/xyzModem.c: Do not use hard-coded address for debug buffer Alexandru Gagniuc
@ 2017-04-09  1:15   ` Tom Rini
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2017-04-09  1:15 UTC (permalink / raw)
  To: u-boot

On Tue, Apr 04, 2017 at 10:42:31AM -0700, Alexandru Gagniuc wrote:

> Under the plethora of #ifdefs, the xyzModem code hid this pearl:
> static char *zm_out = (char *) 0x00380000;
> This was only enabled when DEBUG is defined, so it's probably why it
> went unnoticed for so long. No idea what platform had memory at that
> exact location, but the this approach is extremely hacky.
> Use a static buffer instead.
> 
> Signed-off-by: Alexandru Gagniuc <alex.g@adaptrum.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170408/3b2b5fc2/attachment.sig>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-09  1:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-04 17:42 [U-Boot] [PATCH 1/2] common/xyzModem.c: unifdef (Remove useless #ifdefs) Alexandru Gagniuc
2017-04-04 17:42 ` [U-Boot] [PATCH 2/2] common/xyzModem.c: Do not use hard-coded address for debug buffer Alexandru Gagniuc
2017-04-09  1:15   ` [U-Boot] [U-Boot, " Tom Rini
2017-04-09  1:15 ` [U-Boot] [U-Boot, 1/2] common/xyzModem.c: unifdef (Remove useless #ifdefs) Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox