[PATCH 3/4] fastboot: Fix usage of ubiformat for UBI image transfers

Markus Pargmann mpa at pengutronix.de
Wed Feb 17 01:33:27 PST 2016


Hi,

On Wednesday, February 17, 2016 08:29:14 AM Sascha Hauer wrote:
> On Tue, Feb 16, 2016 at 07:54:47PM +0100, Markus Pargmann wrote:
> > Currently all fastboot flash commands with UBI images are handled by a
> > final call to 'ubiformat'. This only makes sense for flash commands
> > where the target file is a mtd device. If we just want to transfer a UBI
> > image we would expect a simple copy to the correct location.
> > 
> > This patch checks if the destination file is a MTD device by opening it
> > and calling an ioctl MEMGETINFO. Only for MTD devices, ubiformat is
> > called.
> > 
> > Signed-off-by: Markus Pargmann <mpa at pengutronix.de>
> > ---
> >  drivers/usb/gadget/f_fastboot.c | 17 ++++++++++++++++-
> >  1 file changed, 16 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
> > index bf28f7c22aaa..192c0d6eb7f4 100644
> > --- a/drivers/usb/gadget/f_fastboot.c
> > +++ b/drivers/usb/gadget/f_fastboot.c
> > @@ -686,7 +686,21 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd
> >  	}
> >  
> >  	if (filetype == filetype_ubi) {
> > -		char *cmd = asprintf("ubiformat -y -f %s %s", FASTBOOT_TMPFILE, filename);
> > +		char *cmd;
> > +		int fd;
> > +		struct mtd_info_user meminfo;
> > +
> > +		fd = open(filename, O_RDONLY);
> > +		if (!fd)
> > +			goto copy;
> 
> 0 is a valid file descriptor, though one that will never be returned by
> open(). You want to check for fd < 0 here.

Right, thanks, will fix that.

> 
> > +
> > +		ret = ioctl(fd, MEMGETINFO, &meminfo);
> > +		close(fd);
> > +		/* Not a MTD device, ubiformat is not a valid operation */
> > +		if (ret)
> > +			goto copy;
> > +
> > +		cmd = asprintf("ubiformat -y -f %s %s", FASTBOOT_TMPFILE, filename);
> 
> Hm, ubiformat should get a C api.

Yes, probably.

Best Regards,

Markus

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20160217/2668f9d1/attachment-0001.sig>


More information about the barebox mailing list