mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* usbgadget: fastboot: Allow to automatically export bbu handlers
@ 2017-09-27 12:08 Sascha Hauer
  2017-09-27 12:08 ` [PATCH 01/12] file_list: Add function to add an entry to the list Sascha Hauer
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:08 UTC (permalink / raw)
  To: Barebox List

This series allows to automatically export the registered bbu handlers
to fastboot. This way barebox can be updated via fastboot without much
preparation. Setting the following variables will be enough:

nv usbgadget.fastboot_function=""
nv usbgadget.autostart=1
nv usbgadget.fastboot_bbu=1

The exported partitions are then named bbu-<bbuname>.

example:

# fastboot -i 0x1d6b getvar all
< waiting for any device >
(bootloader) version: 0.4
(bootloader) bootloader-version: barebox-2017.09.0-00121-g9fde4fe832-dir
(bootloader) partition-size:bbu-mmc: 000c0000
(bootloader) partition-type:bbu-mmc: basic
all: 
finished. total time: 0.001s

# fastboot -i 0x1d6b flash bbu-mmc build/images/barebox-nxp-imx6ull-evk.img
target didn't report max-download-size
sending 'bbu-mmc' (515 KB)...
(bootloader) Downloading 527984 bytes...
(bootloader) Downloading 527984 bytes finished
OKAY [  0.027s]
writing 'bbu-mmc'...
(bootloader) Copying file to bbu-mmc...
(bootloader) This is a barebox image...
OKAY [  0.124s]
finished. total time: 0.151s

----------------------------------------------------------------
Sascha Hauer (12):
      file_list: Add function to add an entry to the list
      file_list: Add function to get entry by its name
      file_list: Allow only unique names on list
      file_list: Fix memory leak in failure path
      file_list: Add GPL header to file
      file_list: Add error messages
      usbgadget: fastboot: Use function to find file_list entry by name
      bbu: Add function to iterate over registered handlers
      usbgadget command: catch errors when parsing the file list
      usbgadget: fastboot: Allow to automatically export the bbu handlers
      fastboot command: Add -b option to export bbu handlers
      usbgadget autostart: add usbgadget.fastboot_bbu to automatically export bbu handlers

 commands/usbgadget.c            | 20 ++++++++++--
 common/bbu.c                    | 15 +++++++++
 common/file-list.c              | 72 +++++++++++++++++++++++++++++++++--------
 drivers/usb/gadget/autostart.c  |  7 ++++
 drivers/usb/gadget/f_fastboot.c | 29 +++++++++++++----
 drivers/usb/gadget/multi.c      |  1 +
 include/bbu.h                   |  2 ++
 include/file-list.h             |  5 +++
 include/usb/fastboot.h          |  7 ++++
 9 files changed, 135 insertions(+), 23 deletions(-)

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 01/12] file_list: Add function to add an entry to the list
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
@ 2017-09-27 12:08 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 02/12] file_list: Add function to get entry by its name Sascha Hauer
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:08 UTC (permalink / raw)
  To: Barebox List

Add file_list_add_entry() to add a single entry to a file_list. Then
use it in file_list_parse_one() instead of open coding adding a new
entry.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/file-list.c  | 28 +++++++++++++++++++---------
 include/file-list.h |  3 +++
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/common/file-list.c b/common/file-list.c
index 90c0f429c5..010f8f0617 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -8,12 +8,26 @@
 #define PARSE_NAME	1
 #define PARSE_FLAGS	2
 
+int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
+			unsigned long flags)
+{
+	struct file_list_entry *entry = xzalloc(sizeof(*entry));
+
+	entry->name = xstrdup(name);
+	entry->filename = xstrdup(filename);
+	entry->flags = flags;
+
+	list_add_tail(&entry->list, &files->list);
+
+	return 0;
+}
+
 static int file_list_parse_one(struct file_list *files, const char *partstr, const char **endstr)
 {
 	int i = 0, state = PARSE_DEVICE;
 	char filename[PATH_MAX];
 	char name[PATH_MAX];
-	struct file_list_entry *entry = xzalloc(sizeof(*entry));
+	unsigned long flags = 0;
 
 	memset(filename, 0, sizeof(filename));
 	memset(name, 0, sizeof(name));
@@ -39,13 +53,13 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
 		case PARSE_FLAGS:
 			switch (*partstr) {
 			case 's':
-				entry->flags |= FILE_LIST_FLAG_SAFE;
+				flags |= FILE_LIST_FLAG_SAFE;
 				break;
 			case 'r':
-				entry->flags |= FILE_LIST_FLAG_READBACK;
+				flags |= FILE_LIST_FLAG_READBACK;
 				break;
 			case 'c':
-				entry->flags |= FILE_LIST_FLAG_CREATE;
+				flags |= FILE_LIST_FLAG_CREATE;
 				break;
 			default:
 				return -EINVAL;
@@ -60,15 +74,11 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
 	if (state != PARSE_FLAGS)
 		return -EINVAL;
 
-	entry->name = xstrdup(name);
-	entry->filename = xstrdup(filename);
 	if (*partstr == ',')
 		partstr++;
 	*endstr = partstr;
 
-	list_add_tail(&entry->list, &files->list);
-
-	return 0;
+	return file_list_add_entry(files, name, filename, flags);
 }
 
 struct file_list *file_list_parse(const char *str)
diff --git a/include/file-list.h b/include/file-list.h
index 608181ff8d..ccdc2b5efd 100644
--- a/include/file-list.h
+++ b/include/file-list.h
@@ -20,6 +20,9 @@ struct file_list {
 struct file_list *file_list_parse(const char *str);
 void file_list_free(struct file_list *);
 
+int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
+			unsigned long flags);
+
 #define file_list_for_each_entry(files, entry) \
 	list_for_each_entry(entry, &files->list, list)
 
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 02/12] file_list: Add function to get entry by its name
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
  2017-09-27 12:08 ` [PATCH 01/12] file_list: Add function to add an entry to the list Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 03/12] file_list: Allow only unique names on list Sascha Hauer
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/file-list.c  | 12 ++++++++++++
 include/file-list.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/common/file-list.c b/common/file-list.c
index 010f8f0617..0b760c1aec 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -8,6 +8,18 @@
 #define PARSE_NAME	1
 #define PARSE_FLAGS	2
 
+struct file_list_entry *file_list_entry_by_name(struct file_list *files, const char *name)
+{
+	struct file_list_entry *entry;
+
+	file_list_for_each_entry(files, entry) {
+		if (!strcmp(entry->name, name))
+			return entry;
+	}
+
+	return NULL;
+}
+
 int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
 			unsigned long flags)
 {
diff --git a/include/file-list.h b/include/file-list.h
index ccdc2b5efd..1e02539d4d 100644
--- a/include/file-list.h
+++ b/include/file-list.h
@@ -23,6 +23,8 @@ void file_list_free(struct file_list *);
 int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
 			unsigned long flags);
 
+struct file_list_entry *file_list_entry_by_name(struct file_list *files, const char *name);
+
 #define file_list_for_each_entry(files, entry) \
 	list_for_each_entry(entry, &files->list, list)
 
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 03/12] file_list: Allow only unique names on list
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
  2017-09-27 12:08 ` [PATCH 01/12] file_list: Add function to add an entry to the list Sascha Hauer
  2017-09-27 12:09 ` [PATCH 02/12] file_list: Add function to get entry by its name Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 04/12] file_list: Fix memory leak in failure path Sascha Hauer
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

The key to a file_list is it's name, so ensure it's unique.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/file-list.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/file-list.c b/common/file-list.c
index 0b760c1aec..e13d5af659 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -23,7 +23,13 @@ struct file_list_entry *file_list_entry_by_name(struct file_list *files, const c
 int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
 			unsigned long flags)
 {
-	struct file_list_entry *entry = xzalloc(sizeof(*entry));
+	struct file_list_entry *entry;
+
+	entry = file_list_entry_by_name(files, name);
+	if (entry)
+		return -EEXIST;
+
+	entry = xzalloc(sizeof(*entry));
 
 	entry->name = xstrdup(name);
 	entry->filename = xstrdup(filename);
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 04/12] file_list: Fix memory leak in failure path
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
                   ` (2 preceding siblings ...)
  2017-09-27 12:09 ` [PATCH 03/12] file_list: Allow only unique names on list Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 05/12] file_list: Add GPL header to file Sascha Hauer
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

In case of a parse error not only the list header has to be freed, but
also the entries. Use file_list_free() for this purpose.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/file-list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/file-list.c b/common/file-list.c
index e13d5af659..be8f53bd89 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -122,7 +122,7 @@ struct file_list *file_list_parse(const char *str)
 
 	return files;
 out:
-	free(files);
+	file_list_free(files);
 
 	return ERR_PTR(ret);
 }
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 05/12] file_list: Add GPL header to file
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
                   ` (3 preceding siblings ...)
  2017-09-27 12:09 ` [PATCH 04/12] file_list: Fix memory leak in failure path Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 06/12] file_list: Add error messages Sascha Hauer
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/file-list.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/common/file-list.c b/common/file-list.c
index be8f53bd89..0c3cb0a4e7 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -1,3 +1,14 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
 #include <common.h>
 #include <malloc.h>
 #include <fs.h>
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 06/12] file_list: Add error messages
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
                   ` (4 preceding siblings ...)
  2017-09-27 12:09 ` [PATCH 05/12] file_list: Add GPL header to file Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 07/12] usbgadget: fastboot: Use function to find file_list entry by name Sascha Hauer
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

Add error messages when file list parsing fails. Also, forward the error
from file_list_parse_one() instead of using -EINVAL for every error.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/file-list.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/common/file-list.c b/common/file-list.c
index 0c3cb0a4e7..8d61b76cbb 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -9,6 +9,8 @@
  * General Public License for more details.
  */
 
+#define pr_fmt(fmt)	"file_list: " fmt
+
 #include <common.h>
 #include <malloc.h>
 #include <fs.h>
@@ -91,6 +93,7 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
 				flags |= FILE_LIST_FLAG_CREATE;
 				break;
 			default:
+				pr_err("Unknown flag '%c'\n", *partstr);
 				return -EINVAL;
 			}
 			break;
@@ -100,8 +103,10 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
 		partstr++;
 	}
 
-	if (state != PARSE_FLAGS)
+	if (state != PARSE_FLAGS) {
+		pr_err("Missing ')'\n");
 		return -EINVAL;
+	}
 
 	if (*partstr == ',')
 		partstr++;
@@ -121,9 +126,9 @@ struct file_list *file_list_parse(const char *str)
 	INIT_LIST_HEAD(&files->list);
 
 	while (*str) {
-		if (file_list_parse_one(files, str, &endptr)) {
-			printf("parse error\n");
-			ret = -EINVAL;
+		ret = file_list_parse_one(files, str, &endptr);
+		if (ret) {
+			pr_err("parse error\n");
 			goto out;
 		}
 		str = endptr;
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 07/12] usbgadget: fastboot: Use function to find file_list entry by name
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
                   ` (5 preceding siblings ...)
  2017-09-27 12:09 ` [PATCH 06/12] file_list: Add error messages Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 08/12] bbu: Add function to iterate over registered handlers Sascha Hauer
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

We have file_list_entry_by_name() now, so use it rather than open
coding it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/gadget/f_fastboot.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 598637619d..0f2c02ee47 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -679,18 +679,15 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd
 
 	fastboot_tx_print(f_fb, "INFOCopying file to %s...", cmd);
 
-	file_list_for_each_entry(f_fb->files, fentry) {
-		if (!strcmp(cmd, fentry->name)) {
-			filename = fentry->filename;
-			break;
-		}
-	}
+	fentry = file_list_entry_by_name(f_fb->files, cmd);
 
-	if (!filename) {
+	if (!fentry) {
 		fastboot_tx_print(f_fb, "FAILNo such partition: %s", cmd);
 		return;
 	}
 
+	filename = fentry->filename;
+
 	if (filetype == filetype_ubi) {
 		int fd;
 		struct mtd_info_user meminfo;
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 08/12] bbu: Add function to iterate over registered handlers
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
                   ` (6 preceding siblings ...)
  2017-09-27 12:09 ` [PATCH 07/12] usbgadget: fastboot: Use function to find file_list entry by name Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 09/12] usbgadget command: catch errors when parsing the file list Sascha Hauer
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bbu.c  | 15 +++++++++++++++
 include/bbu.h |  2 ++
 2 files changed, 17 insertions(+)

diff --git a/common/bbu.c b/common/bbu.c
index 031c433820..3b372263b1 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -30,6 +30,21 @@
 
 static LIST_HEAD(bbu_image_handlers);
 
+int bbu_handlers_iterate(int (*fn)(struct bbu_handler *, void *), void *ctx)
+{
+	struct bbu_handler *handler;
+
+	list_for_each_entry(handler, &bbu_image_handlers, list) {
+		int ret;
+
+		ret = fn(handler, ctx);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 int bbu_force(struct bbu_data *data, const char *fmt, ...)
 {
 	va_list args;
diff --git a/include/bbu.h b/include/bbu.h
index 9d24ffc395..54434b03e0 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -42,6 +42,8 @@ bool barebox_update_handler_exists(struct bbu_data *);
 
 void bbu_handlers_list(void);
 
+int bbu_handlers_iterate(int (*fn)(struct bbu_handler *, void *), void *);
+
 #ifdef CONFIG_BAREBOX_UPDATE
 
 int bbu_register_handler(struct bbu_handler *);
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 09/12] usbgadget command: catch errors when parsing the file list
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
                   ` (7 preceding siblings ...)
  2017-09-27 12:09 ` [PATCH 08/12] bbu: Add function to iterate over registered handlers Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 10/12] usbgadget: fastboot: Allow to automatically export the bbu handlers Sascha Hauer
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

file_list_parse() can fail. Print an error message in this case instead
of crashing.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/usbgadget.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/commands/usbgadget.c b/commands/usbgadget.c
index ba09f97847..59359098ad 100644
--- a/commands/usbgadget.c
+++ b/commands/usbgadget.c
@@ -83,10 +83,14 @@ static int do_usbgadget(int argc, char *argv[])
 
 	if (fastboot_opts) {
 		opts->fastboot_opts.files = file_list_parse(fastboot_opts);
+		if (IS_ERR(opts->fastboot_opts.files))
+			goto err_parse;
 	}
 
 	if (dfu_opts) {
 		opts->dfu_opts.files = file_list_parse(dfu_opts);
+		if (IS_ERR(opts->dfu_opts.files))
+			goto err_parse;
 	}
 
 	if (create_serial) {
@@ -98,6 +102,13 @@ static int do_usbgadget(int argc, char *argv[])
 		usb_multi_opts_release(opts);
 
 	return ret;
+
+err_parse:
+	printf("Cannot parse file list \"%s\": %s\n", fastboot_opts, strerrorp(opts->fastboot_opts.files));
+
+	free(opts);
+
+	return 1;
 }
 
 BAREBOX_CMD_HELP_START(usbgadget)
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 10/12] usbgadget: fastboot: Allow to automatically export the bbu handlers
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
                   ` (8 preceding siblings ...)
  2017-09-27 12:09 ` [PATCH 09/12] usbgadget command: catch errors when parsing the file list Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 11/12] fastboot command: Add -b option to export " Sascha Hauer
  2017-09-27 12:09 ` [PATCH 12/12] usbgadget autostart: add usbgadget.fastboot_bbu to automatically " Sascha Hauer
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

We have a list of registered handlers which take a barebox update. Do
the next step and allow to automatically export them via fastboot so
that barebox can be updated via fastboot without manually exporting
the partition. Since this may not be desirable in all cases this
behaviour is configurable.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/gadget/f_fastboot.c | 18 ++++++++++++++++++
 drivers/usb/gadget/multi.c      |  1 +
 include/usb/fastboot.h          |  7 +++++++
 3 files changed, 26 insertions(+)

diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 0f2c02ee47..85c64c05c8 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -283,6 +283,21 @@ out:
 	return ret;
 }
 
+static int fastboot_add_bbu_variables(struct bbu_handler *handler, void *ctx)
+{
+	struct f_fastboot *f_fb = ctx;
+	char *name;
+	int ret;
+
+	name = basprintf("bbu-%s", handler->name);
+
+	ret = file_list_add_entry(f_fb->files, name, handler->devicefile, 0);
+
+	free(name);
+
+	return ret;
+}
+
 static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
 {
 	struct usb_composite_dev *cdev = c->cdev;
@@ -302,6 +317,9 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
 	var = fb_addvar(f_fb, "bootloader-version");
 	fb_setvar(var, release_string);
 
+	if (IS_ENABLED(CONFIG_BAREBOX_UPDATE) && opts->export_bbu)
+		bbu_handlers_iterate(fastboot_add_bbu_variables, f_fb);
+
 	file_list_for_each_entry(f_fb->files, fentry) {
 		ret = fastboot_add_partition_variables(f_fb, fentry);
 		if (ret)
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 6eeeb4e982..44969be0c9 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -128,6 +128,7 @@ static int multi_bind_fastboot(struct usb_composite_dev *cdev)
 
 	opts = container_of(fi_fastboot, struct f_fastboot_opts, func_inst);
 	opts->files = gadget_multi_opts->fastboot_opts.files;
+	opts->export_bbu = gadget_multi_opts->fastboot_opts.export_bbu;
 
 	f_fastboot = usb_get_function(fi_fastboot);
 	if (IS_ERR(f_fastboot)) {
diff --git a/include/usb/fastboot.h b/include/usb/fastboot.h
index dab5a9a299..ced890c9ab 100644
--- a/include/usb/fastboot.h
+++ b/include/usb/fastboot.h
@@ -5,9 +5,16 @@
 #include <file-list.h>
 #include <usb/composite.h>
 
+/**
+ * struct f_fastboot_opts - options to configure the fastboot gadget
+ * @func_inst:	The USB function instance to register on
+ * @files:	A file_list containing the files (partitions) to export via fastboot
+ * @export_bbu:	Automatically include the partitions provided by barebox update (bbu)
+ */
 struct f_fastboot_opts {
 	struct usb_function_instance func_inst;
 	struct file_list *files;
+	bool export_bbu;
 };
 
 #endif /* _USB_FASTBOOT_H */
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 11/12] fastboot command: Add -b option to export bbu handlers
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
                   ` (9 preceding siblings ...)
  2017-09-27 12:09 ` [PATCH 10/12] usbgadget: fastboot: Allow to automatically export the bbu handlers Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  2017-09-27 12:09 ` [PATCH 12/12] usbgadget autostart: add usbgadget.fastboot_bbu to automatically " Sascha Hauer
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

When -b is given the usbgadget command will automatically export the
registered bbu handlers via fastboot.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/usbgadget.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/commands/usbgadget.c b/commands/usbgadget.c
index 59359098ad..507871edd2 100644
--- a/commands/usbgadget.c
+++ b/commands/usbgadget.c
@@ -33,11 +33,11 @@
 static int do_usbgadget(int argc, char *argv[])
 {
 	int opt, ret;
-	int acm = 1, create_serial = 0, fastboot_set = 0;
+	int acm = 1, create_serial = 0, fastboot_set = 0, fastboot_export_bbu = 0;
 	const char *fastboot_opts = NULL, *dfu_opts = NULL;
 	struct f_multi_opts *opts;
 
-	while ((opt = getopt(argc, argv, "asdA::D:")) > 0) {
+	while ((opt = getopt(argc, argv, "asdA::D:b")) > 0) {
 		switch (opt) {
 		case 'a':
 			acm = 1;
@@ -54,6 +54,9 @@ static int do_usbgadget(int argc, char *argv[])
 			fastboot_opts = optarg;
 			fastboot_set = 1;
 			break;
+		case 'b':
+			fastboot_export_bbu = 1;
+			break;
 		case 'd':
 			usb_multi_unregister();
 			return 0;
@@ -85,6 +88,7 @@ static int do_usbgadget(int argc, char *argv[])
 		opts->fastboot_opts.files = file_list_parse(fastboot_opts);
 		if (IS_ERR(opts->fastboot_opts.files))
 			goto err_parse;
+		opts->fastboot_opts.export_bbu = fastboot_export_bbu;
 	}
 
 	if (dfu_opts) {
@@ -119,6 +123,7 @@ BAREBOX_CMD_HELP_OPT ("-a",   "Create CDC ACM function")
 BAREBOX_CMD_HELP_OPT ("-s",   "Create Generic Serial function")
 BAREBOX_CMD_HELP_OPT ("-A [desc]",	"Create Android Fastboot function. If 'desc' is not provided,")
 BAREBOX_CMD_HELP_OPT ("",		"trying to use 'global.usbgadget.fastboot_function' variable.")
+BAREBOX_CMD_HELP_OPT ("-b",    "include registered barebox update handlers (fastboot specific)")
 BAREBOX_CMD_HELP_OPT ("-D <desc>",   "Create DFU function")
 BAREBOX_CMD_HELP_OPT ("-d",   "Disable the currently running gadget")
 BAREBOX_CMD_HELP_END
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 12/12] usbgadget autostart: add usbgadget.fastboot_bbu to automatically export bbu handlers
  2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
                   ` (10 preceding siblings ...)
  2017-09-27 12:09 ` [PATCH 11/12] fastboot command: Add -b option to export " Sascha Hauer
@ 2017-09-27 12:09 ` Sascha Hauer
  11 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-09-27 12:09 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/gadget/autostart.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/usb/gadget/autostart.c b/drivers/usb/gadget/autostart.c
index 2ca979057e..f640a9667d 100644
--- a/drivers/usb/gadget/autostart.c
+++ b/drivers/usb/gadget/autostart.c
@@ -30,6 +30,7 @@
 static int autostart;
 static int acm;
 static char *fastboot_function;
+static int fastboot_bbu;
 
 static int usbgadget_autostart(void)
 {
@@ -49,6 +50,8 @@ static int usbgadget_autostart(void)
 			       strerrorp(opts->fastboot_opts.files));
 			opts->fastboot_opts.files = NULL;
 		}
+
+		opts->fastboot_opts.export_bbu = fastboot_bbu;
 	}
 
 	opts->create_acm = acm;
@@ -75,6 +78,7 @@ static int usbgadget_globalvars_init(void)
 	globalvar_add_simple_bool("usbgadget.acm", &acm);
 	globalvar_add_simple_string("usbgadget.fastboot_function",
 				    &fastboot_function);
+	globalvar_add_simple_bool("usbgadget.fastboot_bbu", &fastboot_bbu);
 
 	return 0;
 }
@@ -89,3 +93,6 @@ BAREBOX_MAGICVAR_NAMED(global_usbgadget_acm,
 BAREBOX_MAGICVAR_NAMED(global_usbgadget_fastboot_function,
 		       global.usbgadget.fastboot_function,
 		       "usbgadget: Create Android Fastboot function");
+BAREBOX_MAGICVAR_NAMED(global_usbgadget_fastboot_bbu,
+		       global.usbgadget.fastboot_bbu,
+		       "usbgadget: export barebox update handlers via fastboot");
-- 
2.11.0


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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-09-27 12:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-27 12:08 usbgadget: fastboot: Allow to automatically export bbu handlers Sascha Hauer
2017-09-27 12:08 ` [PATCH 01/12] file_list: Add function to add an entry to the list Sascha Hauer
2017-09-27 12:09 ` [PATCH 02/12] file_list: Add function to get entry by its name Sascha Hauer
2017-09-27 12:09 ` [PATCH 03/12] file_list: Allow only unique names on list Sascha Hauer
2017-09-27 12:09 ` [PATCH 04/12] file_list: Fix memory leak in failure path Sascha Hauer
2017-09-27 12:09 ` [PATCH 05/12] file_list: Add GPL header to file Sascha Hauer
2017-09-27 12:09 ` [PATCH 06/12] file_list: Add error messages Sascha Hauer
2017-09-27 12:09 ` [PATCH 07/12] usbgadget: fastboot: Use function to find file_list entry by name Sascha Hauer
2017-09-27 12:09 ` [PATCH 08/12] bbu: Add function to iterate over registered handlers Sascha Hauer
2017-09-27 12:09 ` [PATCH 09/12] usbgadget command: catch errors when parsing the file list Sascha Hauer
2017-09-27 12:09 ` [PATCH 10/12] usbgadget: fastboot: Allow to automatically export the bbu handlers Sascha Hauer
2017-09-27 12:09 ` [PATCH 11/12] fastboot command: Add -b option to export " Sascha Hauer
2017-09-27 12:09 ` [PATCH 12/12] usbgadget autostart: add usbgadget.fastboot_bbu to automatically " Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox