From: Priit Laes Date: Thu, 7 Mar 2019 10:57:53 +0200 Subject: [U-Boot] [RFC PATCH] fastboot: Implement fetching uboot env variables via fastboot getvar Message-ID: <20190307085753.12508-1-plaes@plaes.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Priit Laes 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 --- 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