mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] USB: gadget: fastboot: introduce optional flag for fastboot partitions
@ 2022-09-22  7:27 Johannes Zink
  2022-09-22  8:13 ` Ahmad Fatoum
  2022-09-22  8:35 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Johannes Zink @ 2022-09-22  7:27 UTC (permalink / raw)
  To: barebox; +Cc: Johannes Zink

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>
---
 Documentation/user/usb.rst | 1 +
 common/fastboot.c          | 6 +++++-
 common/file-list.c         | 3 +++
 include/file-list.h        | 1 +
 4 files changed, 10 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..6bd1191325 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -177,7 +177,11 @@ int fastboot_generic_init(struct fastboot *fb, bool export_bbu)
 	file_list_for_each_entry(fb->files, fentry) {
 		ret = fastboot_add_partition_variables(fb, fentry);
 		if (ret)
-			return ret;
+			if((fentry->flags & FILE_LIST_FLAG_OPTIONAL))
+				pr_info("failed to add optional partition %s to fastboot gadget\n",
+					fentry->filename);
+			else
+				return ret;
 	}
 
 	return 0;
diff --git a/common/file-list.c b/common/file-list.c
index 407b312833..68a7768696 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;
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




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

* Re: [PATCH] USB: gadget: fastboot: introduce optional flag for fastboot partitions
  2022-09-22  7:27 [PATCH] USB: gadget: fastboot: introduce optional flag for fastboot partitions Johannes Zink
@ 2022-09-22  8:13 ` Ahmad Fatoum
  2022-09-22  8:35 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-09-22  8:13 UTC (permalink / raw)
  To: Johannes Zink, barebox

Hi,

On 22.09.22 08:27, Johannes Zink wrote:
> 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>
> ---
>  Documentation/user/usb.rst | 1 +
>  common/fastboot.c          | 6 +++++-
>  common/file-list.c         | 3 +++
>  include/file-list.h        | 1 +
>  4 files changed, 10 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..6bd1191325 100644
> --- a/common/fastboot.c
> +++ b/common/fastboot.c
> @@ -177,7 +177,11 @@ int fastboot_generic_init(struct fastboot *fb, bool export_bbu)
>  	file_list_for_each_entry(fb->files, fentry) {
>  		ret = fastboot_add_partition_variables(fb, fentry);
>  		if (ret)
> -			return ret;
> +			if((fentry->flags & FILE_LIST_FLAG_OPTIONAL))
> +				pr_info("failed to add optional partition %s to fastboot gadget\n",

s/failed to add/skipping unavailable/

to make this more in line with the chosen log level.

> +					fentry->filename);
> +			else
> +				return ret;

Please avoid dangling else here, either with braces or by having an 
if (ret && fentry->flags & FILE_LIST_FLAG_OPTIONAL)) as first condition.

>  	}
>  
>  	return 0;
> diff --git a/common/file-list.c b/common/file-list.c
> index 407b312833..68a7768696 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;

When adding new flags, search for all instances of a similar flag and add
your new flag there as well. You're missing flags_to_str().

> 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;

Cheers,

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* Re: [PATCH] USB: gadget: fastboot: introduce optional flag for fastboot partitions
  2022-09-22  7:27 [PATCH] USB: gadget: fastboot: introduce optional flag for fastboot partitions Johannes Zink
  2022-09-22  8:13 ` Ahmad Fatoum
@ 2022-09-22  8:35 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-09-22  8:35 UTC (permalink / raw)
  To: Johannes Zink; +Cc: barebox

On Thu, Sep 22, 2022 at 09:27:23AM +0200, Johannes Zink wrote:
> 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>
> ---
>  Documentation/user/usb.rst | 1 +
>  common/fastboot.c          | 6 +++++-
>  common/file-list.c         | 3 +++
>  include/file-list.h        | 1 +
>  4 files changed, 10 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..6bd1191325 100644
> --- a/common/fastboot.c
> +++ b/common/fastboot.c
> @@ -177,7 +177,11 @@ int fastboot_generic_init(struct fastboot *fb, bool export_bbu)
>  	file_list_for_each_entry(fb->files, fentry) {
>  		ret = fastboot_add_partition_variables(fb, fentry);
>  		if (ret)
> -			return ret;
> +			if((fentry->flags & FILE_LIST_FLAG_OPTIONAL))
> +				pr_info("failed to add optional partition %s to fastboot gadget\n",
> +					fentry->filename);
> +			else
> +				return ret;

I would prefer to check the FILE_LIST_FLAG_OPTIONAL flag in
fastboot_add_partition_variables(). That gives us the possibility to
explicitly check for the right conditions rather than generalising
all possible errors from fastboot_add_partition_variables().

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

end of thread, other threads:[~2022-09-22  8:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22  7:27 [PATCH] USB: gadget: fastboot: introduce optional flag for fastboot partitions Johannes Zink
2022-09-22  8:13 ` Ahmad Fatoum
2022-09-22  8:35 ` Sascha Hauer

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