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 <pa...@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;
> +     }
> +
[...]
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to