]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/hymod/env.c
3 * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include <linux/ctype.h>
27 DECLARE_GLOBAL_DATA_PTR
;
29 /* imports from fetch.c */
30 extern int fetch_and_parse (char *, ulong
, int (*)(uchar
*, uchar
*));
32 /* this is relative to the root of the server's tftp directory */
33 static char *def_global_env_path
= "/hymod/global_env";
36 env_callback (uchar
*name
, uchar
*value
)
38 hymod_conf_t
*cp
= &gd
->bd
->bi_hymod_conf
;
39 char ov
[CONFIG_SYS_CBSIZE
], nv
[CONFIG_SYS_CBSIZE
], *p
, *q
, *nn
, c
, *curver
, *newver
;
40 int override
= 1, append
= 0, remove
= 0, nnl
, ovl
, nvl
;
52 if ((nnl
= strlen (nn
)) == 0) {
53 printf ("Empty name in global env file\n");
57 if ((c
= nn
[nnl
- 1]) == '+' || c
== '-') {
65 while (nnl
> 0 && isblank(nn
[nnl
- 1]))
68 printf ("Empty name in global env file\n");
79 while (nvl
> 0 && isblank(p
[nvl
- 1]))
82 while ((*q
= *p
++) != '\0') {
86 case '\0': /* whoops - back up */
90 case '%': /* a single percent character */
94 case 's': /* main board serial number as string */
95 q
+= sprintf (q
, "%010lu",
96 cp
->main
.eeprom
.serno
);
99 case 'S': /* main board serial number as number */
100 q
+= sprintf (q
, "%lu", cp
->main
.eeprom
.serno
);
103 default: /* ignore any others */
111 if ((nvl
= q
- nv
) == 0) {
116 if ((curver
= getenv ("global_env_version")) == NULL
)
119 if ((newver
= getenv ("new_genv_version")) == NULL
|| \
120 strcmp (curver
, newver
) == 0) {
121 if (strcmp (nn
, "version") == 0)
122 setenv ("new_genv_version", nv
);
126 if ((p
= getenv (nn
)) != NULL
) {
133 if (strstr (ov
, nv
) == NULL
) {
135 printf ("Appending '%s' to env var '%s'\n",
139 nv
[ovl
+ 1 + nvl
] = nv
[nvl
];
156 if (strstr (ov
, nv
) != NULL
) {
158 printf ("Removing '%s' from env var '%s'\n",
161 while ((p
= strstr (ov
, nv
)) != NULL
) {
174 if (!override
|| strcmp (ov
, nv
) == 0)
177 printf ("Re-setting env cmd '%s' from '%s' to '%s'\n",
181 printf ("Setting env cmd '%s' to '%s'\n", nn
, nv
);
188 hymod_check_env (void)
190 char *p
, *path
, *curver
, *newver
;
191 int firsttime
= 0, needsave
= 0;
193 if (getenv ("global_env_loaded") == NULL
) {
194 puts ("*** global environment has never been loaded\n");
195 puts ("*** fetching from server");
198 else if ((p
= getenv ("always_check_env")) != NULL
&&
199 strcmp (p
, "yes") == 0)
200 puts ("*** checking for updated global environment");
204 puts (" (Control-C to Abort)\n");
206 if ((path
= getenv ("global_env_path")) == NULL
|| *path
== '\0')
207 path
= def_global_env_path
;
209 if (fetch_and_parse (path
, CONFIG_SYS_LOAD_ADDR
, env_callback
) == 0) {
210 puts ("*** Fetch of global environment failed!\n");
214 if ((newver
= getenv ("new_genv_version")) == NULL
) {
215 puts ("*** Version number not set - contents ignored!\n");
219 if ((curver
= getenv ("global_env_version")) == NULL
|| \
220 strcmp (curver
, newver
) != 0) {
221 setenv ("global_env_version", newver
);
225 printf ("*** Global environment up-to-date (ver %s)\n", curver
);
227 setenv ("new_genv_version", NULL
);
230 setenv ("global_env_loaded", "yes");
235 puts ("\n*** Remember to run the 'saveenv' "
236 "command to save the changes\n\n");