summaryrefslogtreecommitdiffstats
path: root/commands/state.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-03-10 15:54:26 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-03-12 08:28:31 +0100
commit1487e6b9ad2ec0fafb0a2a35c921a33fb6c37fec (patch)
tree22ae6baae5a65993b9ad46b39bdbc1e7f210b79e /commands/state.c
parentdcc4a70a3c279669d21a90764cda29854244c237 (diff)
downloadbarebox-1487e6b9ad2ec0fafb0a2a35c921a33fb6c37fec.tar.gz
barebox-1487e6b9ad2ec0fafb0a2a35c921a33fb6c37fec.tar.xz
state: add framework for persistent state handling
This patch adds a framework to describe, access, store and restore a set of variables. A state variable set can be fully described in a devicetree node. This node could be part of the regular devicetree blob or it could be an extra devicetree solely for the state. The state variable set contains variables of different types and a place to store the variable set. For more information see: Documentation/devicetree/bindings/barebox/barebox,state.rst Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Jan Luebbe <jlu@pengutronix.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/state.c')
-rw-r--r--commands/state.c77
1 files changed, 77 insertions, 0 deletions
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