Skip to contentSkip to conversation

fastboot: Implement fetching uboot env variables via fastboot getvar

RFC PATCH New Priit Laes 1 participant 1 message Mar 7, 2019

lore
Share & tools
lore

Priit Laes

author
#0 lore raw

RFC PATCH 1/1 fastboot: Implement fetching uboot env variables via fastboot getvar

From: Priit Laes <[email protected]>

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.

---
 drivers/fastboot/fb_getvar.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/fastboot/fb_getvar.c +14 -0
index 4d264c985d..37bb8c7220 100644
@@ -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);
Signature · 1 line
2.11.0