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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <net.h> |
| 10 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 11 | /* imports from input.c */ |
| 12 | extern int hymod_get_ethaddr (void); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 13 | |
| 14 | int |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 15 | fetch_and_parse (char *fn, ulong addr, int (*cback)(uchar *, uchar *)) |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 16 | { |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 17 | char *ethaddr; |
| 18 | uchar *fp, *efp; |
| 19 | int rc, count = 0; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 20 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 21 | while ((ethaddr = getenv ("ethaddr")) == NULL || *ethaddr == '\0') { |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 22 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 23 | printf ("*** Ethernet address is%s not set\n", |
| 24 | count == 0 ? "" : " STILL"); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 25 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 26 | if ((rc = hymod_get_ethaddr ()) < 0) { |
| 27 | if (rc == -1) |
| 28 | puts ("\n*** interrupted!"); |
| 29 | else |
| 30 | puts ("\n*** timeout!"); |
| 31 | printf (" - fetch of '%s' aborted\n", fn); |
| 32 | return (0); |
| 33 | } |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 34 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 35 | count++; |
| 36 | } |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 37 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 38 | copy_filename (BootFile, fn, sizeof (BootFile)); |
| 39 | load_addr = addr; |
| 40 | NetBootFileXferSize = 0; |
| 41 | |
Simon Glass | e4bf0c5 | 2011-10-24 18:00:02 +0000 | [diff] [blame] | 42 | if (NetLoop(TFTPGET) == 0) { |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 43 | printf ("tftp transfer of file '%s' failed\n", fn); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 44 | return (0); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 47 | if (NetBootFileXferSize == 0) { |
| 48 | printf ("can't determine size of file '%s'\n", fn); |
| 49 | return (0); |
| 50 | } |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 51 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 52 | fp = (uchar *)load_addr; |
| 53 | efp = fp + NetBootFileXferSize; |
| 54 | |
| 55 | do { |
| 56 | uchar *name, *value; |
| 57 | |
| 58 | if (*fp == '#' || *fp == '\n') { |
| 59 | /* skip this line */ |
| 60 | while (fp < efp && *fp++ != '\n') |
| 61 | ; |
| 62 | continue; |
| 63 | } |
| 64 | |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 65 | name = fp; |
| 66 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 67 | while (fp < efp && *fp != '=' && *fp != '\n') |
| 68 | fp++; |
| 69 | if (fp >= efp) |
| 70 | break; |
| 71 | if (*fp == '\n') { |
| 72 | fp++; |
| 73 | continue; |
| 74 | } |
| 75 | *fp++ = '\0'; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 76 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 77 | value = fp; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 78 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 79 | while (fp < efp && *fp != '\n') |
| 80 | fp++; |
| 81 | if (fp[-1] == '\r') |
| 82 | fp[-1] = '\0'; |
| 83 | *fp++ = '\0'; /* ok if we go off the end here */ |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 84 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 85 | if ((*cback)(name, value) == 0) |
| 86 | return (0); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 87 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 88 | } while (fp < efp); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 89 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 90 | return (1); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 91 | } |