public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] dfu: Handle large transfers correctly
Date: Thu, 29 Nov 2012 07:26:51 +0100	[thread overview]
Message-ID: <201211290726.51827.marex@denx.de> (raw)
In-Reply-To: <1354142330-31130-1-git-send-email-panto@antoniou-consulting.com>

Dear Pantelis Antoniou,

> The sequence number is a 16 bit counter; make sure we
> handle rollover correctly. This fixes the wrong transfers for
> large (> 256MB) images.
> 
> Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>
> ---
>  drivers/dfu/dfu.c     | 28 +++++++++++++++++++++++-----
>  drivers/dfu/dfu_mmc.c |  3 +++
>  include/dfu.h         |  2 ++
>  3 files changed, 28 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index 1260c55..2483018 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -82,7 +82,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int
> size, int blk_seq_num) __func__, dfu->name, buf, size, blk_seq_num,
> dfu->offset, dfu->i_buf - dfu->i_buf_start);
> 
> -	if (blk_seq_num == 0) {
> +	if (dfu->do_init) {

If you were to change this to dfu->inited, I think it'd be a bit more intuitive 
;)

>  		/* initial state */
>  		dfu->crc = 0;
>  		dfu->offset = 0;
> @@ -90,6 +90,8 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int
> size, int blk_seq_num) dfu->i_buf_start = dfu_buf;
>  		dfu->i_buf_end = dfu_buf + sizeof(dfu_buf);
>  		dfu->i_buf = dfu->i_buf_start;
> +
> +		dfu->do_init = 0;
>  	}
> 
>  	if (dfu->i_blk_seq_num != blk_seq_num) {
> @@ -97,7 +99,8 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int
> size, int blk_seq_num) __func__, dfu->i_blk_seq_num, blk_seq_num);
>  		return -1;
>  	}
> -	dfu->i_blk_seq_num++;
> +	/* handle rollover */
> +	dfu->i_blk_seq_num = (dfu->i_blk_seq_num + 1) & 0xffff;
> 
>  	/* flush buffer if overflow */
>  	if ((dfu->i_buf + size) > dfu->i_buf_end) {
> @@ -106,6 +109,13 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int
> size, int blk_seq_num) ret = tret;
>  	}
> 
> +	/* we should be in buffer now (if not then size too large) */

I can't make much sense from this comment :(

> +	if ((dfu->i_buf + size) > dfu->i_buf_end) {
> +		printf("%s: Wrong size! [%d] [%d] - \n",

And you should really make this output a bit more human readable please.

> +		       __func__, dfu->i_blk_seq_num, blk_seq_num, size);
> +		return -1;
> +	}
> +
[...]

  reply	other threads:[~2012-11-29  6:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-28 22:38 [U-Boot] [PATCH] dfu: Handle large transfers correctly Pantelis Antoniou
2012-11-29  6:26 ` Marek Vasut [this message]
2012-11-29  9:06 ` Lukasz Majewski
2012-11-29  9:35   ` Pantelis Antoniou
2012-11-29 10:25 ` Lukasz Majewski

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=201211290726.51827.marex@denx.de \
    --to=marex@denx.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox