[PATCH] common: fastboot: send FAIL if variable does not exist

Sascha Hauer s.hauer at pengutronix.de
Thu Jun 12 01:08:20 PDT 2025


Hi Andrei,

On Wed, Jun 11, 2025 at 07:56:45PM +0200, Andrei Lalaev wrote:
> According to doc [1], new implementations should send FAIL if the
> variable specified in the getvar command does not exist.
> 
> [1]: https://android.googlesource.com/platform/system/core/+show/refs/heads/main/fastboot/README.md#121
> 
> Signed-off-by: Andrei Lalaev <andrey.lalaev at gmail.com>
> ---
>  common/fastboot.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/fastboot.c b/common/fastboot.c
> index 56bc4e82c4..3df3c227a3 100644
> --- a/common/fastboot.c
> +++ b/common/fastboot.c
> @@ -372,7 +372,7 @@ static void cb_getvar(struct fastboot *fb, const char *cmd)
>  		goto out;
>  
>  skip_partitions:
> -	fastboot_tx_print(fb, FASTBOOT_MSG_OKAY, "");
> +	fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, "");

With this a "fastboot getvar all" fails.

I fixed this up as below.

Sascha

----------------------8<-------------------------------

>From dd377c937f8bd14842e8e1c119bd3323f85570f8 Mon Sep 17 00:00:00 2001
From: Andrei Lalaev <andrey.lalaev at gmail.com>
Date: Wed, 11 Jun 2025 19:56:45 +0200
Subject: [PATCH] common: fastboot: send FAIL if variable does not exist

According to doc [1], new implementations should send FAIL if the
variable specified in the getvar command does not exist.

[1]: https://android.googlesource.com/platform/system/core/+show/refs/heads/main/fastboot/README.md#121

Signed-off-by: Andrei Lalaev <andrey.lalaev at gmail.com>
Link: https://lore.barebox.org/20250611175645.144025-1-andrey.lalaev@gmail.com
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/fastboot.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/common/fastboot.c b/common/fastboot.c
index 7227149dfb..f678fe8ccb 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -348,8 +348,10 @@ static void cb_getvar(struct fastboot *fb, const char *cmd)
 	if (fastboot_tx_print_var(fb, &fb->variables, cmd))
 		goto out;
 
-	if (!all && !partition)
-		goto skip_partitions;
+	if (!all && !partition) {
+		fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, "no such variable: %s", cmd);
+		goto out;
+	}
 
 	file_list_for_each_entry(fb->files, fentry) {
 		int ret;
@@ -371,8 +373,11 @@ static void cb_getvar(struct fastboot *fb, const char *cmd)
 	if (fastboot_tx_print_var(fb, &partition_list, cmd))
 		goto out;
 
-skip_partitions:
-	fastboot_tx_print(fb, FASTBOOT_MSG_OKAY, "");
+	if (all)
+		fastboot_tx_print(fb, FASTBOOT_MSG_OKAY, "");
+	else
+		fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, "no such variable: %s", cmd);
+
 out:
 	fastboot_free_variables(&partition_list);
 }
-- 
2.39.5


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



More information about the barebox mailing list