wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 3 | * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au> |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <net.h> |
| 26 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 27 | /* imports from input.c */ |
| 28 | extern int hymod_get_ethaddr (void); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 29 | |
| 30 | int |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 31 | fetch_and_parse (char *fn, ulong addr, int (*cback)(uchar *, uchar *)) |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 32 | { |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 33 | char *ethaddr; |
| 34 | uchar *fp, *efp; |
| 35 | int rc, count = 0; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 36 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 37 | while ((ethaddr = getenv ("ethaddr")) == NULL || *ethaddr == '\0') { |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 38 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 39 | printf ("*** Ethernet address is%s not set\n", |
| 40 | count == 0 ? "" : " STILL"); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 41 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 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 | } |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 50 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 51 | count++; |
| 52 | } |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 53 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 54 | copy_filename (BootFile, fn, sizeof (BootFile)); |
| 55 | load_addr = addr; |
| 56 | NetBootFileXferSize = 0; |
| 57 | |
| 58 | if (NetLoop (TFTP) == 0) { |
| 59 | printf ("tftp transfer of file '%s' failed\n", fn); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 60 | return (0); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 61 | } |
| 62 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 63 | if (NetBootFileXferSize == 0) { |
| 64 | printf ("can't determine size of file '%s'\n", fn); |
| 65 | return (0); |
| 66 | } |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 67 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 68 | fp = (uchar *)load_addr; |
| 69 | efp = fp + NetBootFileXferSize; |
| 70 | |
| 71 | do { |
| 72 | uchar *name, *value; |
| 73 | |
| 74 | if (*fp == '#' || *fp == '\n') { |
| 75 | /* skip this line */ |
| 76 | while (fp < efp && *fp++ != '\n') |
| 77 | ; |
| 78 | continue; |
| 79 | } |
| 80 | |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 81 | name = fp; |
| 82 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 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'; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 92 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 93 | value = fp; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 94 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 95 | while (fp < efp && *fp != '\n') |
| 96 | fp++; |
| 97 | if (fp[-1] == '\r') |
| 98 | fp[-1] = '\0'; |
| 99 | *fp++ = '\0'; /* ok if we go off the end here */ |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 100 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 101 | if ((*cback)(name, value) == 0) |
| 102 | return (0); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 103 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 104 | } while (fp < efp); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 105 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame^] | 106 | return (1); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 107 | } |