]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/hymod/fetch.c
1511b085820a6014164272bfdfceb2603f54eb50
[karo-tx-uboot.git] / board / hymod / fetch.c
1 /*
2  * (C) Copyright 2001
3  * Murray Jensen, CSIRO Manufacturing Science and Technology,
4  * <Murray.Jensen@cmst.csiro.au>
5  *
6  * See file CREDITS for list of people who contributed to this
7  * project.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  */
24
25 #include <common.h>
26 #include <net.h>
27
28 /* imports from common/main.c */
29 extern char console_buffer[CFG_CBSIZE];
30
31 int
32 fetch_and_parse(bd_t *bd, char *fn, ulong addr, int (*cback)(uchar *, uchar *))
33 {
34     char *ethaddr;
35     uchar *fp, *efp;
36
37     while ((ethaddr = getenv("ethaddr")) == NULL || *ethaddr == '\0') {
38
39         puts("*** Ethernet address is not set\n");
40
41         for (;;) {
42             int n;
43
44             n = readline("Enter board ethernet address: ");
45
46             if (n < 0) {
47                 puts("\n");
48                 return (0);
49             }
50
51             if (n == 0)
52                 continue;
53
54             if (n == 17) {
55                 int i;
56                 char *p, *q;
57                 uchar ea[6];
58
59                 /* see if it looks like an ethernet address */
60
61                 p = console_buffer;
62
63                 for (i = 0; i < 6; i++) {
64                     char term = (i == 5 ? '\0' : ':');
65
66                     ea[i] = simple_strtol(p, &q, 16);
67
68                     if ((q - p) != 2 || *q++ != term)
69                         break;
70
71                     p = q;
72                 }
73
74                 if (i == 6) {
75                     /* it looks ok - set it */
76                     printf("Setting ethernet address to %s\n", console_buffer);
77                     setenv("ethaddr", console_buffer);
78
79                     puts("Remember to do a 'saveenv' to make it permanent\n");
80                     break;
81                 }
82             }
83
84             printf("Invalid ethernet address (%s) - please re-enter\n",
85                 console_buffer);
86         }
87     }
88
89     copy_filename(BootFile, fn, sizeof (BootFile));
90     load_addr = addr;
91
92     if (NetLoop(TFTP) == 0) {
93         printf("tftp transfer of file '%s' failed\n", fn);
94         return (0);
95     }
96
97     if (NetBootFileXferSize == 0) {
98         printf("can't determine size of file '%s'\n", fn);
99         return (0);
100     }
101
102     fp = (uchar *)load_addr;
103     efp = fp + NetBootFileXferSize;
104
105     do {
106         uchar *name, *value;
107
108         if (*fp == '#' || *fp == '\n') {
109             while (fp < efp && *fp++ != '\n')
110                 ;
111             continue;
112         }
113
114         name = fp;
115
116         while (fp < efp && *fp != '=')
117             if (*fp++ == '\n')
118                 name = fp;
119
120         if (fp >= efp)
121             break;
122
123         *fp++ = '\0';
124
125         value = fp;
126
127         while (fp < efp && *fp != '\n')
128             fp++;
129
130         /* ok if we go off the end here */
131
132         if (fp[-1] == '\r')
133             fp[-1] = '\0';
134         *fp++ = '\0';
135
136         if ((*cback)(name, value) == 0)
137             return (0);
138
139     } while (fp < efp);
140
141     return (1);
142 }