1: #include "global.h"
2: #include "ub_env.h"
3:
4:
5: cfg_root_t cfg;
6: int Verbose;
7: extern char compiled[], compiledby[], compilehost[];
8:
9:
10: static void
11: Usage()
12: {
13: printf( " -= U-Boot-Env =- Tool for u-boot-env nand map management\n"
14: "=== %s === %s@%s ===\n\n"
15: " Syntax: ube [options] [set_value]\n"
16: "\n"
17: "\t-c <cfgfile>\tConfig file [default: /etc/ube.conf]\n"
18: "\t-d <descr>\tDrive description into config [default: 64K]\n"
19: "\t-g <name>\tSet parameter to value\n"
20: "\t-s <name>\tGet parameter value\n"
21: "\t-q\t\tQuiet mode\n"
22: "\t-v\t\tVerbose ...\n"
23: "\n", compiled, compiledby, compilehost);
24: }
25:
26: int
27: main(int argc, char **argv)
28: {
29: char ch, mode = 0, szName[STRSIZ] = { 0 }, szVal[STRSIZ] = { 0 },
30: szCfgName[PATH_MAX], szSec[STRSIZ];
31: const char *str;
32: int ret;
33:
34: strlcpy(szCfgName, UBE_CFGNAME, sizeof szCfgName);
35: strlcpy(szSec, UBE_SECTION, sizeof szSec);
36: while ((ch = getopt(argc, argv, "hvqg:s:c:d:")) != -1)
37: switch (ch) {
38: case 'g':
39: mode |= 1;
40: strlcpy(szName, optarg, sizeof szName);
41: break;
42: case 's':
43: mode |= 2;
44: strlcpy(szName, optarg, sizeof szName);
45: break;
46: case 'c':
47: strlcpy(szCfgName, optarg, sizeof szCfgName);
48: break;
49: case 'd':
50: strlcpy(szSec, optarg, sizeof szSec);
51: break;
52: case 'v':
53: Verbose++;
54: break;
55: case 'q':
56: mode |= 0x80;
57: break;
58: case 'h':
59: default:
60: Usage();
61: return 1;
62: }
63: argc -= optind;
64: argv += optind;
65: if ((mode & 0x7f) == 2 && argc)
66: strlcpy(szVal, *argv, sizeof szVal);
67:
68: VERB(1) printf("u-boot-env: mode=0x%hhx name=%s value=%s\n", mode, szName, szVal);
69:
70: if (cfgLoadConfig(szCfgName, &cfg)) {
71: printf("Error:: cfgLoadConfig() #%d - %s\n", cfg_GetErrno(), cfg_GetError());
72: return 1;
73: }
74:
75: if (!(mode & 0x7f)) {
76: VERB(2) printf("u-boot-env: list variables\n");
77: }
78:
79: if ((mode & 0x7f) & 1) {
80: VERB(2) printf("u-boot-env: get variable %s\n", szName);
81: str = ub_getenv(szName);
82: if (!str) {
83: printf("Error:: Variable %s not found!\n", szName);
84: cfgUnloadConfig(&cfg);
85: return 2;
86: } else if (mode & 0x80)
87: printf("%s\n", str);
88: else
89: printf("Variable %s=%s\n", szName, str);
90: }
91:
92: if ((mode & 0x7f) & 2) {
93: VERB(2) printf("u-boot-env: set variable %s\n", szName);
94: ret = ub_setenv(szName, argc ? szVal : NULL);
95: if (ret) {
96: printf("Error:: Writing variable %s!\n", szName);
97: cfgUnloadConfig(&cfg);
98: return 3;
99: }
100: if (!(mode & 0x80))
101: printf("Done\n");
102: }
103:
104: cfgUnloadConfig(&cfg);
105: return 0;
106: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>