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 v2 4/4] fastboot: Add a ARM Barebox filetype handler
Date: Wed, 17 Feb 2016 12:28:20 +0100	[thread overview]
Message-ID: <1455708500-980-4-git-send-email-mpa@pengutronix.de> (raw)
In-Reply-To: <1455708500-980-1-git-send-email-mpa@pengutronix.de>

This will automatically call barebox_update for the transfered file if
it is an ARM Barebox image and the destination file is defined by some
update handler.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 common/filetype.c               | 13 +++++++++++++
 drivers/usb/gadget/f_fastboot.c | 29 +++++++++++++++++++++++++++++
 include/filetype.h              |  2 ++
 3 files changed, 44 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 8cfae88aeb35..74baf514466a 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -369,3 +369,16 @@ err_out:
 	cdev_close(cdev);
 	return type;
 }
+
+bool filetype_is_barebox_image(enum filetype ft)
+{
+	switch (ft) {
+	case filetype_arm_barebox:
+	case filetype_mips_barebox:
+	case filetype_ch_image:
+	case filetype_ch_image_be:
+		return true;
+	default:
+		return false;
+	}
+}
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index bc06c58d8dcb..9a1058a9670b 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -23,6 +23,7 @@
 #include <clock.h>
 #include <ioctl.h>
 #include <libbb.h>
+#include <bbu.h>
 #include <boot.h>
 #include <dma.h>
 #include <fs.h>
@@ -716,6 +717,34 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd
 		goto out;
 	}
 
+	if (filetype_is_barebox_image(filetype)) {
+		struct bbu_data data = {
+			.devicefile = filename,
+			.imagefile = FASTBOOT_TMPFILE,
+			.flags = BBU_FLAG_YES,
+		};
+
+		if (!barebox_update_handler_exists(&data))
+			goto copy;
+
+		fastboot_tx_print(f_fb, "INFOThis is an ARM Barebox image...");
+
+		data.image = read_file(data.imagefile, &data.len);
+		if (!data.image) {
+			fastboot_tx_print(f_fb, "FAILreading barebox");
+			return;
+		}
+
+		ret = barebox_update(&data);
+
+		if (ret) {
+			fastboot_tx_print(f_fb, "FAILupdate barebox: %s", strerror(-ret));
+			return;
+		}
+
+		goto out;
+	}
+
 copy:
 	ret = copy_file(FASTBOOT_TMPFILE, filename, 1);
 	if (ret) {
diff --git a/include/filetype.h b/include/filetype.h
index cde543e5b061..e87ca174a89d 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -2,6 +2,7 @@
 #define __FILE_TYPE_H
 
 #include <linux/string.h>
+#include <linux/types.h>
 
 /*
  * List of file types we know
@@ -48,6 +49,7 @@ enum filetype file_name_detect_type(const char *filename);
 enum filetype cdev_detect_type(const char *name);
 enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec);
 int is_fat_boot_sector(const void *_buf);
+bool filetype_is_barebox_image(enum filetype ft);
 
 #define ARM_HEAD_SIZE			0x30
 #define ARM_HEAD_MAGICWORD_OFFSET	0x20
-- 
2.7.0


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

  parent reply	other threads:[~2016-02-17 11:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-17 11:28 [PATCH v2 1/4] bbu: Add barebox_update search by device Markus Pargmann
2016-02-17 11:28 ` [PATCH v2 2/4] bbu: Add function to check if an update handler exists Markus Pargmann
2016-02-17 11:28 ` [PATCH v2 3/4] fastboot: Fix usage of ubiformat for UBI image transfers Markus Pargmann
2016-02-17 11:28 ` Markus Pargmann [this message]
2016-02-18  8:22   ` [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler Michael Olbrich
2016-02-19  7:44     ` Sascha Hauer
2016-03-11  7:07   ` Sascha Hauer

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=1455708500-980-4-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