mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Johannes Zink <j.zink@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Johannes Zink <j.zink@pengutronix.de>
Subject: [PATCH v2] USB: gadget: fastboot: introduce optional flag for fastboot partitions
Date: Thu, 22 Sep 2022 15:24:10 +0200	[thread overview]
Message-ID: <20220922132410.2653284-1-j.zink@pengutronix.de> (raw)

On some boards, some partitions exposed to fastboot may become
unavailable under certain circumstances, e.g. if an SD-Card exposed to
fastboot is removed.

Previously, this lead to an error and the fastboot gadget did not
initialize the remaining partitions exposed via fastboot, e.g. an
eMMC which usually is permanently soldered on the board.

This patch allows to append an optional flag 'o' to the description of a
fastboot partition. If this partition is unavailable at the
initialization of the fastboot gadget, said partition is skipped, while
the remaining available partitions are still exposed.

Signed-off-by: Johannes Zink <j.zink@pengutronix.de>
---
Changes since v1:
 - moved check for FILE_LIST_OPTIONAL flag to fastboot_add_partition_variables().
   This allows for cleaner error checking on error conditions (Thanks Sascha)
 - reworded info message to indicate intended condition on skipping optional
   partitions rather than indicating an error condition (Thanks Ahmad)
 - added FILE_LIST_OPTIONAL flag to flags_to_str() (Thanks Ahmad

 Documentation/user/usb.rst | 1 +
 common/fastboot.c          | 8 ++++++++
 common/file-list.c         | 7 ++++++-
 include/file-list.h        | 1 +
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/Documentation/user/usb.rst b/Documentation/user/usb.rst
index 2479efe9d6..f2f57ead98 100644
--- a/Documentation/user/usb.rst
+++ b/Documentation/user/usb.rst
@@ -65,6 +65,7 @@ Several **flags** are supported, each denoted by a single character:
 * ``r`` Readback. The partition is allowed to be read back (DFU specific)
 * ``c`` The file shall be created if it doesn't exist. Needed when a regular file is exported.
 * ``u`` The partition is a MTD device and shall be flashed with a UBI image.
+* ``o`` The partition is optional, i.e. if it is not available at initialization time, it is skipped instead of aborting the initialization
 
 Example:
 
diff --git a/common/fastboot.c b/common/fastboot.c
index 330a06f5a3..249e953ad6 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -95,6 +95,14 @@ static int fastboot_add_partition_variables(struct fastboot *fb,
 	}
 
 	if (ret) {
+		if (fentry->flags & FILE_LIST_FLAG_OPTIONAL) {
+			pr_info("skipping unavailable optional partition %s for fastboot gadget\n",
+				fentry->filename);
+			ret = 0;
+			type = "unavailable";
+			goto out;
+		}
+
 		if (fentry->flags & FILE_LIST_FLAG_CREATE) {
 			ret = 0;
 			type = "file";
diff --git a/common/file-list.c b/common/file-list.c
index 407b312833..3bb3b39d05 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -88,6 +88,9 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
 			case 'u':
 				flags |= FILE_LIST_FLAG_UBI;
 				break;
+			case 'o':
+				flags |= FILE_LIST_FLAG_OPTIONAL;
+				break;
 			default:
 				pr_err("Unknown flag '%c'\n", *partstr);
 				return -EINVAL;
@@ -113,7 +116,7 @@ static int file_list_parse_one(struct file_list *files, const char *partstr, con
 
 static const char *flags_to_str(int flags)
 {
-	static char str[sizeof "srcu"];
+	static char str[sizeof "srcuo"];
 	char *s = str;;
 
 	if (flags & FILE_LIST_FLAG_SAFE)
@@ -124,6 +127,8 @@ static const char *flags_to_str(int flags)
 		*s++ = 'c';
 	if (flags & FILE_LIST_FLAG_UBI)
 		*s++ = 'u';
+	if (flags & FILE_LIST_FLAG_OPTIONAL)
+		*s++ = 'o';
 
 	*s = '\0';
 
diff --git a/include/file-list.h b/include/file-list.h
index 5090313739..bcb06979c8 100644
--- a/include/file-list.h
+++ b/include/file-list.h
@@ -8,6 +8,7 @@
 #define FILE_LIST_FLAG_READBACK	(1 << 1)
 #define FILE_LIST_FLAG_CREATE	(1 << 2)
 #define FILE_LIST_FLAG_UBI	(1 << 3)
+#define FILE_LIST_FLAG_OPTIONAL (1 << 4)
 
 struct file_list_entry {
 	char *name;
-- 
2.30.2




             reply	other threads:[~2022-09-22 13:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-22 13:24 Johannes Zink [this message]
2022-09-26  8:22 ` 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=20220922132410.2653284-1-j.zink@pengutronix.de \
    --to=j.zink@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