diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/Kconfig | 23 | ||||
-rw-r--r-- | cmd/Makefile | 1 | ||||
-rw-r--r-- | cmd/button.c | 86 | ||||
-rw-r--r-- | cmd/demo.c | 1 | ||||
-rw-r--r-- | cmd/host.c | 2 | ||||
-rw-r--r-- | cmd/mdio.c | 1 | ||||
-rw-r--r-- | cmd/mii.c | 1 | ||||
-rw-r--r-- | cmd/nvedit.c | 66 | ||||
-rw-r--r-- | cmd/w1.c | 1 |
9 files changed, 173 insertions, 9 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig index bfe6c163dc..d7136b0e79 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -601,8 +601,20 @@ config CMD_NVEDIT_INFO This command can be optionally used for evaluation in scripts: [-d] : evaluate whether default environment is used [-p] : evaluate whether environment can be persisted + [-q] : quiet output The result of multiple evaluations will be combined with AND. +config CMD_NVEDIT_LOAD + bool "env load" + help + Load all environment variables from the compiled-in persistent + storage. + +config CMD_NVEDIT_SELECT + bool "env select" + help + Select the compiled-in persistent storage of environment variables. + endmenu menu "Memory commands" @@ -1679,6 +1691,17 @@ config CMD_BLOCK_CACHE during development, but also allows the cache to be disabled when it might hurt performance (e.g. when using the ums command). +config CMD_BUTTON + bool "button" + depends on BUTTON + default y if BUTTON + help + Enable the 'button' command which allows to get the status of + buttons supported by the board. The buttonss can be listed with + 'button list' and state can be known with 'button <label>'. + Any button drivers can be controlled with this command, e.g. + button_gpio. + config CMD_CACHE bool "icache or dcache" help diff --git a/cmd/Makefile b/cmd/Makefile index 7952138dc2..6e0086ba07 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_CMD_BOOTSTAGE) += bootstage.o obj-$(CONFIG_CMD_BOOTZ) += bootz.o obj-$(CONFIG_CMD_BOOTI) += booti.o obj-$(CONFIG_CMD_BTRFS) += btrfs.o +obj-$(CONFIG_CMD_BUTTON) += button.o obj-$(CONFIG_CMD_CACHE) += cache.o obj-$(CONFIG_CMD_CBFS) += cbfs.o obj-$(CONFIG_CMD_CLK) += clk.o diff --git a/cmd/button.c b/cmd/button.c new file mode 100644 index 0000000000..84ad1653c7 --- /dev/null +++ b/cmd/button.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com> + * + * Based on led.c + */ + +#include <common.h> +#include <command.h> +#include <dm.h> +#include <button.h> +#include <dm/uclass-internal.h> + +static const char *const state_label[] = { + [BUTTON_OFF] = "off", + [BUTTON_ON] = "on", +}; + +static int show_button_state(struct udevice *dev) +{ + int ret; + + ret = button_get_state(dev); + if (ret >= BUTTON_COUNT) + ret = -EINVAL; + if (ret >= 0) + printf("%s\n", state_label[ret]); + + return ret; +} + +static int list_buttons(void) +{ + struct udevice *dev; + int ret; + + for (uclass_find_first_device(UCLASS_BUTTON, &dev); + dev; + uclass_find_next_device(&dev)) { + struct button_uc_plat *plat = dev_get_uclass_platdata(dev); + + if (!plat->label) + continue; + printf("%-15s ", plat->label); + if (device_active(dev)) { + ret = show_button_state(dev); + if (ret < 0) + printf("Error %d\n", ret); + } else { + printf("<inactive>\n"); + } + } + + return 0; +} + +int do_button(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + const char *button_label; + struct udevice *dev; + int ret; + + /* Validate arguments */ + if (argc < 2) + return CMD_RET_USAGE; + button_label = argv[1]; + if (strncmp(button_label, "list", 4) == 0) + return list_buttons(); + + ret = button_get_by_label(button_label, &dev); + if (ret) { + printf("Button '%s' not found (err=%d)\n", button_label, ret); + return CMD_RET_FAILURE; + } + + ret = show_button_state(dev); + + return 0; +} + +U_BOOT_CMD( + button, 4, 1, do_button, + "manage buttons", + "<button_label> \tGet button state\n" + "button list\t\tShow a list of buttons" +); diff --git a/cmd/demo.c b/cmd/demo.c index 9da06f5e4d..f923533f79 100644 --- a/cmd/demo.c +++ b/cmd/demo.c @@ -8,6 +8,7 @@ #include <common.h> #include <command.h> +#include <dm.h> #include <dm-demo.h> #include <mapmem.h> #include <asm/io.h> diff --git a/cmd/host.c b/cmd/host.c index cd9c9677f0..ff119da738 100644 --- a/cmd/host.c +++ b/cmd/host.c @@ -51,7 +51,7 @@ static int do_host_bind(struct cmd_tbl *cmdtp, int flag, int argc, printf("** Bad device specification %s **\n", dev_str); return CMD_RET_USAGE; } - return host_dev_bind(dev, file); + return !!host_dev_bind(dev, file); } static int do_host_info(struct cmd_tbl *cmdtp, int flag, int argc, diff --git a/cmd/mdio.c b/cmd/mdio.c index c48bb51237..cfa45ad12a 100644 --- a/cmd/mdio.c +++ b/cmd/mdio.c @@ -10,6 +10,7 @@ #include <common.h> #include <command.h> +#include <dm.h> #include <miiphy.h> #include <phy.h> @@ -10,6 +10,7 @@ #include <common.h> #include <command.h> +#include <dm.h> #include <miiphy.h> typedef struct _MII_field_desc_t { diff --git a/cmd/nvedit.c b/cmd/nvedit.c index ca0be92fc3..d188c6aa6b 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -794,6 +794,23 @@ U_BOOT_CMD( ); #endif #endif + +#if defined(CONFIG_CMD_NVEDIT_LOAD) +static int do_env_load(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + return env_reload() ? 1 : 0; +} +#endif + +#if defined(CONFIG_CMD_NVEDIT_SELECT) +static int do_env_select(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + return env_select(argv[1]) ? 1 : 0; +} +#endif + #endif /* CONFIG_SPL_BUILD */ int env_match(uchar *s1, int i2) @@ -1224,12 +1241,18 @@ static int print_env_info(void) * env info - display environment information * env info [-d] - evaluate whether default environment is used * env info [-p] - evaluate whether environment can be persisted + * Add [-q] - quiet mode, use only for command result, for test by example: + * test env info -p -d -q */ static int do_env_info(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { int eval_flags = 0; int eval_results = 0; + bool quiet = false; +#if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE) + enum env_location loc; +#endif /* display environment information */ if (argc <= 1) @@ -1247,6 +1270,9 @@ static int do_env_info(struct cmd_tbl *cmdtp, int flag, case 'p': eval_flags |= ENV_INFO_IS_PERSISTED; break; + case 'q': + quiet = true; + break; default: return CMD_RET_USAGE; } @@ -1256,20 +1282,30 @@ static int do_env_info(struct cmd_tbl *cmdtp, int flag, /* evaluate whether default environment is used */ if (eval_flags & ENV_INFO_IS_DEFAULT) { if (gd->flags & GD_FLG_ENV_DEFAULT) { - printf("Default environment is used\n"); + if (!quiet) + printf("Default environment is used\n"); eval_results |= ENV_INFO_IS_DEFAULT; } else { - printf("Environment was loaded from persistent storage\n"); + if (!quiet) + printf("Environment was loaded from persistent storage\n"); } } /* evaluate whether environment can be persisted */ if (eval_flags & ENV_INFO_IS_PERSISTED) { #if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE) - printf("Environment can be persisted\n"); - eval_results |= ENV_INFO_IS_PERSISTED; + loc = env_get_location(ENVOP_SAVE, gd->env_load_prio); + if (ENVL_NOWHERE != loc && ENVL_UNKNOWN != loc) { + if (!quiet) + printf("Environment can be persisted\n"); + eval_results |= ENV_INFO_IS_PERSISTED; + } else { + if (!quiet) + printf("Environment cannot be persisted\n"); + } #else - printf("Environment cannot be persisted\n"); + if (!quiet) + printf("Environment cannot be persisted\n"); #endif } @@ -1326,7 +1362,10 @@ static struct cmd_tbl cmd_env_sub[] = { U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""), #endif #if defined(CONFIG_CMD_NVEDIT_INFO) - U_BOOT_CMD_MKENT(info, 2, 0, do_env_info, "", ""), + U_BOOT_CMD_MKENT(info, 3, 0, do_env_info, "", ""), +#endif +#if defined(CONFIG_CMD_NVEDIT_LOAD) + U_BOOT_CMD_MKENT(load, 1, 0, do_env_load, "", ""), #endif U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""), #if defined(CONFIG_CMD_RUN) @@ -1338,6 +1377,9 @@ static struct cmd_tbl cmd_env_sub[] = { U_BOOT_CMD_MKENT(erase, 1, 0, do_env_erase, "", ""), #endif #endif +#if defined(CONFIG_CMD_NVEDIT_SELECT) + U_BOOT_CMD_MKENT(select, 2, 0, do_env_select, "", ""), +#endif U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""), #if defined(CONFIG_CMD_ENV_EXISTS) U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""), @@ -1405,8 +1447,10 @@ static char env_help_text[] = #endif #if defined(CONFIG_CMD_NVEDIT_INFO) "env info - display environment information\n" - "env info [-d] - whether default environment is used\n" - "env info [-p] - whether environment can be persisted\n" + "env info [-d] [-p] [-q] - evaluate environment information\n" + " \"-d\": default environment is used\n" + " \"-p\": environment can be persisted\n" + " \"-q\": quiet output\n" #endif "env print [-a | name ...] - print environment\n" #if defined(CONFIG_CMD_NVEDIT_EFI) @@ -1421,6 +1465,12 @@ static char env_help_text[] = "env erase - erase environment\n" #endif #endif +#if defined(CONFIG_CMD_NVEDIT_LOAD) + "env load - load environment\n" +#endif +#if defined(CONFIG_CMD_NVEDIT_SELECT) + "env select [target] - select environment target\n" +#endif #if defined(CONFIG_CMD_NVEDIT_EFI) "env set -e [-nv][-bs][-rt][-at][-a][-i addr,size][-v] name [arg ...]\n" " - set UEFI variable; unset if '-i' or 'arg' not specified\n" @@ -6,6 +6,7 @@ */ #include <common.h> #include <command.h> +#include <dm.h> #include <w1.h> #include <w1-eeprom.h> #include <dm/device-internal.h> |