1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <net.h>
26
27
28extern int hymod_get_ethaddr (void);
29
30int
31fetch_and_parse (char *fn, ulong addr, int (*cback)(uchar *, uchar *))
32{
33 char *ethaddr;
34 uchar *fp, *efp;
35 int rc, count = 0;
36
37 while ((ethaddr = getenv ("ethaddr")) == NULL || *ethaddr == '\0') {
38
39 printf ("*** Ethernet address is%s not set\n",
40 count == 0 ? "" : " STILL");
41
42 if ((rc = hymod_get_ethaddr ()) < 0) {
43 if (rc == -1)
44 puts ("\n*** interrupted!");
45 else
46 puts ("\n*** timeout!");
47 printf (" - fetch of '%s' aborted\n", fn);
48 return (0);
49 }
50
51 count++;
52 }
53
54 copy_filename (BootFile, fn, sizeof (BootFile));
55 load_addr = addr;
56 NetBootFileXferSize = 0;
57
58 if (NetLoop(TFTPGET) == 0) {
59 printf ("tftp transfer of file '%s' failed\n", fn);
60 return (0);
61 }
62
63 if (NetBootFileXferSize == 0) {
64 printf ("can't determine size of file '%s'\n", fn);
65 return (0);
66 }
67
68 fp = (uchar *)load_addr;
69 efp = fp + NetBootFileXferSize;
70
71 do {
72 uchar *name, *value;
73
74 if (*fp == '#' || *fp == '\n') {
75
76 while (fp < efp && *fp++ != '\n')
77 ;
78 continue;
79 }
80
81 name = fp;
82
83 while (fp < efp && *fp != '=' && *fp != '\n')
84 fp++;
85 if (fp >= efp)
86 break;
87 if (*fp == '\n') {
88 fp++;
89 continue;
90 }
91 *fp++ = '\0';
92
93 value = fp;
94
95 while (fp < efp && *fp != '\n')
96 fp++;
97 if (fp[-1] == '\r')
98 fp[-1] = '\0';
99 *fp++ = '\0';
100
101 if ((*cback)(name, value) == 0)
102 return (0);
103
104 } while (fp < efp);
105
106 return (1);
107}
108