From: Yoshinori Sato <ysato@users.sourceforge.jp>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] xyzModem.c Packet buffer dynamic allocate
Date: Fri, 01 Oct 2010 14:56:36 +0900 [thread overview]
Message-ID: <87sk0q1mnf.wl%ysato@users.sourceforge.jp> (raw)
Hello.
It changes reduce bss usage.
Ymodem receive buffer dinamic allocation.
Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
---
common/cmd_load.c | 1 +
common/xyzModem.c | 17 ++++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/common/cmd_load.c b/common/cmd_load.c
index dad0303..f144bf4 100644
--- a/common/cmd_load.c
+++ b/common/cmd_load.c
@@ -992,6 +992,7 @@ static ulong load_serial_ymodem (ulong offset)
store_addr, res);
if (rc != 0) {
flash_perror (rc);
+ xyzModem_stream_close (&err);
return (~0);
}
} else
diff --git a/common/xyzModem.c b/common/xyzModem.c
index 7a46805..5af995d 100644
--- a/common/xyzModem.c
+++ b/common/xyzModem.c
@@ -58,6 +58,7 @@
#include <xyzModem.h>
#include <stdarg.h>
#include <crc.h>
+#include <malloc.h>
/* Assumption - run xyzModem protocol over the console port */
@@ -81,7 +82,7 @@ static struct
#else
int *__chan;
#endif
- unsigned char pkt[1024], *bufp;
+ unsigned char *pkt, *bufp;
unsigned char blk, cblk, crc1, crc2;
unsigned char next_blk; /* Expected block */
int len, mode, total_retries;
@@ -353,6 +354,7 @@ xyzModem_get_hdr (void)
bool hdr_found = false;
int i, can_total, hdr_chars;
unsigned short cksum;
+ char *pktp;
ZM_DEBUG (zm_new ());
/* Find the start of a header */
@@ -433,13 +435,14 @@ xyzModem_get_hdr (void)
}
xyz.len = (c == SOH) ? 128 : 1024;
xyz.bufp = xyz.pkt;
+ pktp = xyz.pkt;
for (i = 0; i < xyz.len; i++)
{
res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c);
ZM_DEBUG (zm_save (c));
if (res)
{
- xyz.pkt[i] = c;
+ *pktp++ = c;
}
else
{
@@ -489,9 +492,10 @@ xyzModem_get_hdr (void)
else
{
cksum = 0;
+ pktp = xyz.pkt;
for (i = 0; i < xyz.len; i++)
{
- cksum += xyz.pkt[i];
+ cksum += *pktp++;
}
if (xyz.crc1 != (cksum & 0xFF))
{
@@ -560,6 +564,11 @@ xyzModem_stream_open (connection_info_t * info, int *err)
xyz.read_length = 0;
xyz.file_length = 0;
#endif
+ if (xyz.pkt == NULL) {
+ xyz.pkt = malloc(1024);
+ if (xyz.pkt == NULL)
+ return -1;
+ }
CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
@@ -743,6 +752,8 @@ xyzModem_stream_close (int *err)
xyz.crc_mode ? "CRC" : "Cksum", xyz.total_SOH, xyz.total_STX,
xyz.total_CAN, xyz.total_retries);
ZM_DEBUG (zm_flush ());
+ free(xyz.pkt);
+ xyz.pkt = NULL;
}
/* Need to be able to clean out the input buffer, so have to take the */
--
1.7.1
next reply other threads:[~2010-10-01 5:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-01 5:56 Yoshinori Sato [this message]
2010-10-01 7:57 ` [U-Boot] [PATCH] xyzModem.c Packet buffer dynamic allocate Wolfgang Denk
2010-10-01 15:02 ` Yoshinori Sato
2010-10-01 19:39 ` Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sk0q1mnf.wl%ysato@users.sourceforge.jp \
--to=ysato@users.sourceforge.jp \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.