[U-Boot] [RFC PATCH] fastboot: Implement fetching uboot env variables via fastboot getvar

Priit Laes plaes at plaes.org
Thu Mar 7 08:57:53 UTC 2019


From: Priit Laes <priit.laes at paf.com>

Add u-boot specific getvar "extension" to fetch u-boot environment
variables via `fastboot getvar uboot:var`. This makes it possible
to gather certain data (like mac addresses) in an automated way
during initial fastboot flashing for inventory purposes:

$ fastboot getvar uboot:ethaddr
uboot:ethaddr: 12:23:45:56:78:90

Output is currently truncated at 64 bytes, but this is good enough
for my own requirements.

Signed-off-by: Priit Laes <priit.laes at paf.com>
---
 drivers/fastboot/fb_getvar.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c
index 4d264c985d..37bb8c7220 100644
--- a/drivers/fastboot/fb_getvar.c
+++ b/drivers/fastboot/fb_getvar.c
@@ -20,6 +20,7 @@ static void getvar_product(char *var_parameter, char *response);
 static void getvar_current_slot(char *var_parameter, char *response);
 static void getvar_slot_suffixes(char *var_parameter, char *response);
 static void getvar_has_slot(char *var_parameter, char *response);
+static void getvar_ubootenv(char *var_parameter, char *response);
 #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
 static void getvar_partition_type(char *part_name, char *response);
 #endif
@@ -64,6 +65,9 @@ static const struct {
 	}, {
 		.variable = "has_slot",
 		.dispatch = getvar_has_slot
+	}, {
+		.variable = "uboot",
+		.dispatch = getvar_ubootenv
 #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
 	}, {
 		.variable = "partition-type",
@@ -82,6 +86,16 @@ static void getvar_version(char *var_parameter, char *response)
 	fastboot_okay(FASTBOOT_VERSION, response);
 }
 
+static void getvar_ubootenv(char *var_parameter, char *response)
+{
+	const char *value = env_get(var_parameter);
+
+	if (value)
+		fastboot_okay(value, response);
+	else
+		fastboot_fail("Variable is not set", response);
+}
+
 static void getvar_bootloader_version(char *var_parameter, char *response)
 {
 	fastboot_okay(U_BOOT_VERSION, response);
-- 
2.11.0



More information about the U-Boot mailing list