diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-04-13 12:57:14 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-04-13 12:57:14 +0200 |
commit | ee0035e5ccee0056e23b2dda2cade0c5ca756713 (patch) | |
tree | 9e02a89c11c7574bace93f2c3731c4175e0ea649 /commands | |
parent | a76a6bc8fd62bc26140d421d09e71624ee13aa47 (diff) | |
parent | 1487e6b9ad2ec0fafb0a2a35c921a33fb6c37fec (diff) | |
download | barebox-ee0035e5ccee0056e23b2dda2cade0c5ca756713.tar.gz barebox-ee0035e5ccee0056e23b2dda2cade0c5ca756713.tar.xz |
Merge branch 'for-next/state'
Diffstat (limited to 'commands')
-rw-r--r-- | commands/Kconfig | 5 | ||||
-rw-r--r-- | commands/Makefile | 1 | ||||
-rw-r--r-- | commands/state.c | 77 |
3 files changed, 83 insertions, 0 deletions
diff --git a/commands/Kconfig b/commands/Kconfig index 2618eda2f6..847ff76d1d 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -2096,6 +2096,11 @@ config CMD_TIME Note: This command depends on COMMAND being interruptible, otherwise the timer may overrun resulting in incorrect results +config CMD_STATE + tristate + depends on STATE + prompt "state" + # end Miscellaneous commands endmenu diff --git a/commands/Makefile b/commands/Makefile index d69e3f0b06..b902f58ec5 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -110,3 +110,4 @@ obj-$(CONFIG_CMD_FIRMWARELOAD) += firmwareload.o obj-$(CONFIG_CMD_CMP) += cmp.o obj-$(CONFIG_CMD_NV) += nv.o obj-$(CONFIG_CMD_DEFAULTENV) += defaultenv.o +obj-$(CONFIG_CMD_STATE) += state.o diff --git a/commands/state.c b/commands/state.c new file mode 100644 index 0000000000..82c29d00c8 --- /dev/null +++ b/commands/state.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2012 Jan Luebbe <j.luebbe@pengutronix.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <common.h> +#include <getopt.h> +#include <command.h> +#include <state.h> + +static int do_state(int argc, char *argv[]) +{ + int opt, ret = 0; + struct state *state = NULL; + int do_save = 0, do_load = 0; + const char *statename = "state"; + + while ((opt = getopt(argc, argv, "sl")) > 0) { + switch (opt) { + case 's': + do_save = 1; + break; + case 'l': + do_load = 1; + break; + default: + return COMMAND_ERROR_USAGE; + } + } + + if (do_save && do_load) + return COMMAND_ERROR_USAGE; + + if (!do_save && !do_load) { + state_info(); + return 0; + } + + if (optind < argc) + statename = argv[optind]; + + state = state_by_name(statename); + if (!state) { + printf("cannot find state %s\n", statename); + return -ENOENT; + } + + if (do_save) + ret = state_save(state); + else if (do_load) + ret = state_load(state); + + return ret; +} + +static const __maybe_unused char cmd_state_help[] = +"Usage: state [OPTIONS] [STATENAME]\n" +"\n" +"options:\n" +"-s save state\n" +"-l load state\n"; + +BAREBOX_CMD_START(state) + .cmd = do_state, + BAREBOX_CMD_DESC("handle state information") + BAREBOX_CMD_GROUP(CMD_GRP_MISC) + BAREBOX_CMD_HELP(cmd_state_help) +BAREBOX_CMD_END |