[U-Boot] [PATCH 05/14] dfu: allow read with 0 data for EOF indication

Patrick DELAUNAY patrick.delaunay at st.com
Wed Sep 18 11:45:27 UTC 2019


Hi Lukasz,

> From: Lukasz Majewski <lukma at denx.de>
> Sent: mardi 17 septembre 2019 12:29
> 
> Hi Patrick,
> 
> > This patch allows into the DFU backend to indicate that there is no
> > remaining data (for EOF for example). That allows users to read a
> > buffer greater than the device size; the dfu stack stops the read
> > request when the backend return a length=0 without error.
> >
> > Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
> > ---
> >
> >  drivers/dfu/dfu.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index
> > 8bd5216017..50919fcae9 100644
> > --- a/drivers/dfu/dfu.c
> > +++ b/drivers/dfu/dfu.c
> > @@ -396,6 +396,8 @@ static int dfu_read_buffer_fill(struct dfu_entity
> > *dfu, void *buf, int size) debug("%s: Read error!\n", __func__);
> >  				return ret;
> >  			}
> > +			if (dfu->b_left == 0)
> > +				break;
> 
> I guess that this is the use case for sending commands?

Yes,

The use-case is for virtual partition, also used for "command".

Command is requested by updload in the associated alternate 
And result is done by reading on the same alternate.

During enumeration I set the size of the alternate at the maximum size of the answer....
This test allow to read, without error, until the backend / callback read at the requested offset with a offset = 0.


> Could you provide a more descriptive use case for this change (the description in
> the above commit message is not enough for me to get it).

Yes, I will update the comment in V2.

The issue is the DFU read size is limited by get_medium_size = r_left and the stack expectes that read is allowed up to this size.

Today the DFU backend can't indicate to the DFU stack when the end of available data to read is reached, without and raising error.
Because in dfu_read_buffer_fill the loop is infinite until
- read_medium raised a error
- size = 0
- no more to read in DFU buffer (r_left = 0)

This patch allow the backend to indicate that that it can't provide no more data to fill the DFU buffer, by setting b_left =0 even is the available size id is lower of the total size indicated by get_medium_size.

For USB DFU stack point of view, it is acceptable (read lenght < requested size in DFU_UPLOAD and the transaction is stopped).

It is never a issue for flash device (where chunk are always completely read, b_left will be never 0) but it is usefulll for virtual partition when we only know the max size of this alternate.

Without this patch, I have a infinite loop, when for on backend the result of read_medium  is 0 (OK) but dfu->b_left = 0
=> r_left is not decreased and size is not updated
I try an other solution: raised a error when no more date is available but in this case the data read is not correctly managed in the loop.

PS: It is used in my example for stm32mp1

=> board/st/stm32mp1/stm32mp1.c

I force size to size = 1KB for all virtual partition , in dfu_get_medium_size_virt.

But in fucntio called dfu_read_medium_virt, I limit the size the each virtual partition in dfu_otp_read...

=> only 8 bytes for pmic  (in dfu_pmic_read, the second read at offset 8, misc_read return -EACCES)


dfu-util -d 0483:5720 -a 26 -U pmic.bin
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Opening DFU capable USB device...
ID 0483:df11
Run-time device DFU version 0110
Claiming USB DFU Interface...
Setting Alternate Setting #26 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 0110
Device returned transfer size 4096
Copying data from DFU device to PC
Upload	[=========================] 100%            8 bytes
Upload done.

===> but 1KB for otp

dfu-util -d 0483:5720 -a 25 -U otp.bin
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Opening DFU capable USB device...
ID 0483:df11
Run-time device DFU version 0110
Claiming USB DFU Interface...
Setting Alternate Setting #25 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 0110
Device returned transfer size 4096
Copying data from DFU device to PC
Upload	[=========================] 100%         1024 bytes
Upload done.


> 
> >  			dfu->offset += dfu->b_left;
> >  			dfu->r_left -= dfu->b_left;
> >
> 
> 
> 
> Best regards,
> 
> Lukasz Majewski
> 

Best regards

Patrick Delaunay


More information about the U-Boot mailing list