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 = 0;
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 (ub_load(szSec)) {
76: ret = 1;
77: goto end;
78: }
79:
80: if (!(mode & 0x7f)) {
81: VERB(2) printf("u-boot-env: list variables\n");
82: }
83:
84: if ((mode & 0x7f) & 1) {
85: VERB(2) printf("u-boot-env: get variable %s\n", szName);
86: str = ub_getenv(szSec, szName);
87: if (!str) {
88: printf("Error:: Variable %s not found!\n", szName);
89: ret = 2;
90: goto end;
91: } else if (mode & 0x80)
92: printf("%s\n", str);
93: else
94: printf("%s=%s\n", szName, str);
95: }
96:
97: if ((mode & 0x7f) & 2) {
98: VERB(2) printf("u-boot-env: set variable %s\n", szName);
99: ret = ub_setenv(szSec, szName, argc ? szVal : NULL);
100: if (ret) {
101: printf("Error:: Writing variable %s!\n", szName);
102: ret = 3;
103: goto end;
104: }
105: if (!(mode & 0x80))
106: printf("Done\n");
107: }
108:
109: end:
110: ub_unload();
111: cfgUnloadConfig(&cfg);
112: return ret;
113: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>