diff --git a/commands/state.c b/commands/state.c index 59d1eb8..4b51759 100644 --- a/commands/state.c +++ b/commands/state.c @@ -21,26 +21,20 @@ { int opt, ret = 0; struct state *state = NULL; - int do_save = 0, do_load = 0; + int do_save = 0; const char *statename = "state"; - while ((opt = getopt(argc, argv, "sl")) > 0) { + while ((opt = getopt(argc, argv, "s")) > 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) { + if (!do_save) { state_info(); return 0; } @@ -56,8 +50,6 @@ if (do_save) ret = state_save(state); - else if (do_load) - ret = state_load(state); return ret; } @@ -67,13 +59,12 @@ BAREBOX_CMD_HELP_TEXT("") BAREBOX_CMD_HELP_TEXT("options:") BAREBOX_CMD_HELP_OPT ("-s", "save state") -BAREBOX_CMD_HELP_OPT ("-l", "load state") BAREBOX_CMD_HELP_END BAREBOX_CMD_START(state) .cmd = do_state, - BAREBOX_CMD_DESC("load and save state information") - BAREBOX_CMD_OPTS("[-sl] [STATENAME]") + BAREBOX_CMD_DESC("save state information") + BAREBOX_CMD_OPTS("[-s] [STATENAME]") BAREBOX_CMD_GROUP(CMD_GRP_MISC) BAREBOX_CMD_HELP(cmd_state_help) BAREBOX_CMD_END diff --git a/common/state.c b/common/state.c index 117a686..fdb5564 100644 --- a/common/state.c +++ b/common/state.c @@ -51,7 +51,6 @@ }; struct state_backend { - int (*load)(struct state_backend *backend, struct state *state); int (*save)(struct state_backend *backend, struct state *state); const char *name; const char *of_path; @@ -1049,30 +1048,6 @@ } /* - * state_load - load a state from the backing store - * - * @state The state instance to load - */ -int state_load(struct state *state) -{ - int ret; - - if (!state->backend) - return -ENOSYS; - - ret = state->backend->load(state->backend, state); - if (ret) { - dev_warn(&state->dev, "load failed\n"); - state->dirty = 1; - } else { - dev_info(&state->dev, "load successful\n"); - state->dirty = 0; - } - - return ret; -} - -/* * state_save - save a state to the backing store * * @state The state instance to save @@ -1226,7 +1201,6 @@ backend_dtb = xzalloc(sizeof(*backend_dtb)); backend = &backend_dtb->backend; - backend->load = state_backend_dtb_load; backend->save = state_backend_dtb_save; backend->of_path = xstrdup(of_path); backend->path = xstrdup(path); @@ -1238,6 +1212,15 @@ if (!ret && !(meminfo.flags & MTD_NO_ERASE)) backend_dtb->need_erase = true; + ret = state_backend_dtb_load(backend, state); + if (ret) { + dev_warn(&state->dev, "load failed - using defaults\n"); + } else { + dev_info(&state->dev, "load successful\n"); + state->dirty = 0; + } + + /* ignore return value of load() */ return 0; } @@ -1548,7 +1531,6 @@ backend_raw = xzalloc(sizeof(*backend_raw)); backend = &backend_raw->backend; - backend->load = state_backend_raw_load; backend->save = state_backend_raw_save; backend->of_path = xstrdup(of_path); backend->path = xstrdup(path); @@ -1583,6 +1565,15 @@ goto err; } + ret = state_backend_raw_load(backend, state); + if (ret) { + dev_warn(&state->dev, "load failed - using defaults\n"); + } else { + dev_info(&state->dev, "load successful\n"); + state->dirty = 0; + } + + /* ignore return value of load() */ return 0; err: free(backend_raw); diff --git a/drivers/misc/state.c b/drivers/misc/state.c index d46d5b9..73356b4 100644 --- a/drivers/misc/state.c +++ b/drivers/misc/state.c @@ -86,7 +86,6 @@ dev_info(dev, "backend: %s, path: %s, of_path: %s\n", backend_type, path, of_path); free(path); - state_load(state); return 0; out_free: diff --git a/include/state.h b/include/state.h index 08c4e86..b3966fd 100644 --- a/include/state.h +++ b/include/state.h @@ -17,7 +17,6 @@ struct state *state_by_node(const struct device_node *node); int state_get_name(const struct state *state, char const **name); -int state_load(struct state *state); int state_save(struct state *state); void state_info(void);