mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Markus Pargmann <mpa@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/4] fastboot: Fix usage of ubiformat for UBI image transfers
Date: Tue, 16 Feb 2016 19:54:47 +0100	[thread overview]
Message-ID: <1455648888-20678-3-git-send-email-mpa@pengutronix.de> (raw)
In-Reply-To: <1455648888-20678-1-git-send-email-mpa@pengutronix.de>

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@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;
+
+		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);
 
 		fastboot_tx_print(f_fb, "INFOThis is an UBI image...");
 
@@ -702,6 +716,7 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd
 		goto out;
 	}
 
+copy:
 	ret = copy_file(FASTBOOT_TMPFILE, filename, 1);
 	if (ret) {
 		fastboot_tx_print(f_fb, "FAILwrite partition: %s", strerror(-ret));
-- 
2.7.0.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-02-16 18:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-16 18:54 [PATCH 1/4] bbu: Add barebox_update search by device Markus Pargmann
2016-02-16 18:54 ` [PATCH 2/4] bbu: Add function to check if an update handler exists Markus Pargmann
2016-02-16 18:54 ` Markus Pargmann [this message]
2016-02-17  7:29   ` [PATCH 3/4] fastboot: Fix usage of ubiformat for UBI image transfers Sascha Hauer
2016-02-17  9:33     ` Markus Pargmann
2016-02-16 18:54 ` [PATCH 4/4] fastboot: Add a ARM Barebox filetype handler Markus Pargmann
2016-02-17  7:37   ` Sascha Hauer
2016-02-17 10:02     ` Markus Pargmann

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=1455648888-20678-3-git-send-email-mpa@pengutronix.de \
    --to=mpa@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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