summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Pargmann <mpa@pengutronix.de>2016-02-17 12:28:20 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2016-03-11 08:06:05 +0100
commit0240fd3f8469eba3bda367b79dc221b9736baec7 (patch)
treeb6151ea4bf02df8b11d3ea3370d057a30c09a4f2
parent24ff0ab0fa0354d74c03c6a1cfddb05c52d9d113 (diff)
downloadbarebox-0240fd3f8469eba3bda367b79dc221b9736baec7.tar.gz
fastboot: Add a ARM Barebox filetype handler
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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/filetype.c13
-rw-r--r--drivers/usb/gadget/f_fastboot.c31
-rw-r--r--include/filetype.h2
3 files changed, 46 insertions, 0 deletions
diff --git a/common/filetype.c b/common/filetype.c
index 8cfae88..74baf51 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 bc06c58..0df08c9 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,36 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd
goto out;
}
+ if (IS_ENABLED(CONFIG_BAREBOX_UPDATE) && 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 a 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);
+
+ free(data.image);
+
+ 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 cde543e..e87ca17 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