From patchwork Wed Dec 12 04:16:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 205360 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 060802C0093 for ; Wed, 12 Dec 2012 15:18:04 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 802384A1D5; Wed, 12 Dec 2012 05:17:58 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id u8ZY0rcFFNsd; Wed, 12 Dec 2012 05:17:58 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 906354A1A5; Wed, 12 Dec 2012 05:17:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BDEBD4A192 for ; Wed, 12 Dec 2012 05:17:29 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tAGDrTsTrEo1 for ; Wed, 12 Dec 2012 05:17:29 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from spamkiller06.natinst.com (mailserver6.natinst.com [130.164.80.6]) by theia.denx.de (Postfix) with ESMTP id 177724A1A3 for ; Wed, 12 Dec 2012 05:17:22 +0100 (CET) Received: from mailserv58-us.natinst.com (nb-hsrp-1338.natinst.com [130.164.19.133]) by spamkiller06.natinst.com (8.14.5/8.14.5) with ESMTP id qBC4HHwr022831; Tue, 11 Dec 2012 22:17:17 -0600 Received: from linux-xvxi.natinst.com ([130.164.14.197]) by mailserv58-us.natinst.com (Lotus Domino Release 8.5.3FP2 HF169) with ESMTP id 2012121122171725-310431 ; Tue, 11 Dec 2012 22:17:17 -0600 From: Joe Hershberger To: u-boot@lists.denx.de Date: Tue, 11 Dec 2012 22:16:33 -0600 Message-Id: <1355285797-27051-17-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1355285797-27051-1-git-send-email-joe.hershberger@ni.com> References: <1354672367-23747-1-git-send-email-joe.hershberger@ni.com> <1355285797-27051-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on MailServ58-US/AUS/H/NIC(Release 8.5.3FP2 HF169|September 14, 2012) at 12/11/2012 10:17:17 PM, Serialize by Router on MailServ58-US/AUS/H/NIC(Release 8.5.3FP2 HF169|September 14, 2012) at 12/11/2012 10:17:17 PM, Serialize complete at 12/11/2012 10:17:17 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.9.8327, 1.0.431, 0.0.0000 definitions=2012-12-12_01:2012-12-12, 2012-12-12, 1970-01-01 signatures=0 Cc: Tom Rini , Joe Hershberger , Gerlando Falauto Subject: [U-Boot] [PATCH v5 16/20] env: Add a command to display details about env flags X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Similar to the env callback command, this will show details about the options available, the static list, and the currently active variables. Signed-off-by: Joe Hershberger --- Changes in v5: None Changes in v4: - Add help text for env flags command Changes in v3: None Changes in v2: None README | 1 + common/cmd_nvedit.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ common/env_flags.c | 34 ++++++++++++++++++++++++++++++ include/env_flags.h | 11 ++++++++++ 4 files changed, 105 insertions(+) diff --git a/README b/README index 5705925..efce998 100644 --- a/README +++ b/README @@ -811,6 +811,7 @@ The following options need to be configured: CONFIG_CMD_EEPROM * EEPROM read/write support CONFIG_CMD_ELF * bootelf, bootvx CONFIG_CMD_ENV_CALLBACK * display details about env callbacks + CONFIG_CMD_ENV_FLAGS * display details about env flags CONFIG_CMD_EXPORTENV * export the environment CONFIG_CMD_EXT2 * ext2 command support CONFIG_CMD_EXT4 * ext4 command support diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index f645194..468b89c 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -443,6 +443,59 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif +#if defined(CONFIG_CMD_ENV_FLAGS) +static int print_static_flags(const char *var_name, const char *flags) +{ + enum env_flags_vartype type = env_flags_parse_vartype(flags); + + printf("\t%-20s %-20s\n", var_name, env_flags_get_vartype_name(type)); + + return 0; +} + +static int print_active_flags(ENTRY *entry) +{ + enum env_flags_vartype type; + + if (entry->flags == 0) + return 0; + + type = (enum env_flags_vartype) + (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK); + printf("\t%-20s %-20s\n", entry->key, env_flags_get_vartype_name(type)); + + return 0; +} + +/* + * Print the flags available and what variables have flags + */ +int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + /* Print the available variable types */ + printf("Available variable type flags (position %d):\n", + ENV_FLAGS_VARTYPE_LOC); + puts("\tFlag\tVariable Type Name\n"); + puts("\t----\t------------------\n"); + env_flags_print_vartypes(); + puts("\n"); + + /* Print the static flags that may exist */ + puts("Static flags:\n"); + printf("\t%-20s %-20s\n", "Variable Name", "Variable Type"); + printf("\t%-20s %-20s\n", "-------------", "-------------"); + env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags); + puts("\n"); + + /* walk through each variable and print the flags if non-default */ + puts("Active flags:\n"); + printf("\t%-20s %-20s\n", "Variable Name", "Variable Type"); + printf("\t%-20s %-20s\n", "-------------", "-------------"); + hwalk_r(&env_htab, print_active_flags); + return 0; +} +#endif + /* * Interactively edit an environment variable */ @@ -913,6 +966,9 @@ static cmd_tbl_t cmd_env_sub[] = { #if defined(CONFIG_CMD_ENV_CALLBACK) U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""), #endif +#if defined(CONFIG_CMD_ENV_FLAGS) + U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""), +#endif #if defined(CONFIG_CMD_EXPORTENV) U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""), #endif @@ -974,6 +1030,9 @@ static char env_help_text[] = #if defined(CONFIG_CMD_EXPORTENV) "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n" #endif +#if defined(CONFIG_CMD_ENV_FLAGS) + "env flags - print variables that have non-default flags\n" +#endif #if defined(CONFIG_CMD_GREPENV) "env grep string [...] - search environment\n" #endif diff --git a/common/env_flags.c b/common/env_flags.c index ed0857c..09f93d5 100644 --- a/common/env_flags.c +++ b/common/env_flags.c @@ -43,6 +43,40 @@ #endif static const char env_flags_vartype_rep[] = "sdxb" ENV_FLAGS_NET_VARTYPE_REPS; +#ifdef CONFIG_CMD_ENV_FLAGS +static const char * const env_flags_vartype_names[] = { + "string", + "decimal", + "hexadecimal", + "boolean", +#ifdef CONFIG_CMD_NET + "IP address", + "MAC address", +#endif +}; + +/* + * Print the whole list of available type flags. + */ +void env_flags_print_vartypes(void) +{ + enum env_flags_vartype curtype = (enum env_flags_vartype)0; + + while (curtype != env_flags_vartype_end) { + printf("\t%c -\t%s\n", env_flags_vartype_rep[curtype], + env_flags_vartype_names[curtype]); + curtype++; + } +} + +/* + * Return the name of the type. + */ +const char *env_flags_get_vartype_name(enum env_flags_vartype type) +{ + return env_flags_vartype_names[type]; +} +#endif /* CONFIG_CMD_ENV_FLAGS */ /* * Parse the flags string from a .flags attribute list into the vartype enum. diff --git a/include/env_flags.h b/include/env_flags.h index 3333446..7e72523 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -47,6 +47,17 @@ enum env_flags_vartype { #define ENV_FLAGS_LIST_STATIC \ CONFIG_ENV_FLAGS_LIST_STATIC +#ifdef CONFIG_CMD_ENV_FLAGS +/* + * Print the whole list of available type flags. + */ +void env_flags_print_vartypes(void); +/* + * Return the name of the type. + */ +const char *env_flags_get_vartype_name(enum env_flags_vartype type); +#endif + /* * Parse the flags string from a .flags attribute list into the vartype enum. */