/src/barebox/commands/saveenv.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0-only |
2 | | // SPDX-FileCopyrightText: © 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix |
3 | | |
4 | | #include <common.h> |
5 | | #include <command.h> |
6 | | #include <errno.h> |
7 | | #include <getopt.h> |
8 | | #include <fs.h> |
9 | | #include <fcntl.h> |
10 | | #include <envfs.h> |
11 | | |
12 | | static int do_saveenv(int argc, char *argv[]) |
13 | 0 | { |
14 | 0 | int ret, opt; |
15 | 0 | unsigned envfs_flags = 0; |
16 | 0 | const char *filename = NULL, *dirname = NULL; |
17 | |
|
18 | 0 | while ((opt = getopt(argc, argv, "z")) > 0) { |
19 | 0 | switch (opt) { |
20 | 0 | case 'z': |
21 | 0 | envfs_flags |= ENVFS_FLAGS_FORCE_BUILT_IN; |
22 | 0 | break; |
23 | 0 | default: |
24 | 0 | return COMMAND_ERROR_USAGE; |
25 | 0 | } |
26 | 0 | } |
27 | | |
28 | | /* destination and source are given? */ |
29 | 0 | if (argc - optind > 1) |
30 | 0 | dirname = argv[optind + 1]; |
31 | | |
32 | | /* destination only given? */ |
33 | 0 | if (argc - optind > 0) |
34 | 0 | filename = argv[optind]; |
35 | 0 | if (!filename) |
36 | 0 | filename = default_environment_path_get(); |
37 | |
|
38 | 0 | printf("saving environment to %s\n", filename); |
39 | |
|
40 | 0 | ret = envfs_save(filename, dirname, envfs_flags); |
41 | |
|
42 | 0 | return ret; |
43 | 0 | } |
44 | | |
45 | | BAREBOX_CMD_HELP_START(saveenv) |
46 | | BAREBOX_CMD_HELP_TEXT("Save the files in DIRECTORY to the persistent storage device ENVFS.") |
47 | | BAREBOX_CMD_HELP_TEXT("") |
48 | | BAREBOX_CMD_HELP_TEXT("ENVFS is usually a block in flash but can be any other file. If") |
49 | | BAREBOX_CMD_HELP_TEXT("omitted, DIRECTORY defaults to /env and ENVFS defaults to") |
50 | | BAREBOX_CMD_HELP_TEXT("/dev/env0.") |
51 | | BAREBOX_CMD_HELP_OPT ("-z", "force the built-in default environment at startup") |
52 | | |
53 | | BAREBOX_CMD_HELP_END |
54 | | |
55 | | BAREBOX_CMD_START(saveenv) |
56 | | .cmd = do_saveenv, |
57 | | BAREBOX_CMD_DESC("save environment to persistent storage") |
58 | | BAREBOX_CMD_OPTS("[-z] [ENVFS [DIRECTORY]]") |
59 | | BAREBOX_CMD_GROUP(CMD_GRP_ENV) |
60 | | BAREBOX_CMD_HELP(cmd_saveenv_help) |
61 | | BAREBOX_CMD_END |