wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
wdenk | b00ec16 | 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 | d79de1d | 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 | b00ec16 | 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 | b00ec16 | 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 | b00ec16 | 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 | b00ec16 | 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 | b00ec16 | 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 | b00ec16 | 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); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 33 | } |
| 34 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 35 | count++; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 36 | } |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 37 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 38 | copy_filename (BootFile, fn, sizeof (BootFile)); |
| 39 | load_addr = addr; |
| 40 | NetBootFileXferSize = 0; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 41 | |
Simon Glass | d6c5f55 | 2011-10-24 18:00:02 +0000 | [diff] [blame] | 42 | if (NetLoop(TFTPGET) == 0) { |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 43 | printf ("tftp transfer of file '%s' failed\n", fn); |
| 44 | return (0); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
wdenk | b00ec16 | 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 | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 52 | fp = (uchar *)load_addr; |
| 53 | efp = fp + NetBootFileXferSize; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 54 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 55 | do { |
| 56 | uchar *name, *value; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 57 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 58 | if (*fp == '#' || *fp == '\n') { |
| 59 | /* skip this line */ |
| 60 | while (fp < efp && *fp++ != '\n') |
| 61 | ; |
| 62 | continue; |
| 63 | } |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 64 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 65 | name = fp; |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 66 | |
wdenk | b00ec16 | 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 | b00ec16 | 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 | b00ec16 | 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 | b00ec16 | 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 | b00ec16 | 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 | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 90 | return (1); |
wdenk | 5d65f3a | 2002-08-19 08:10:25 +0000 | [diff] [blame] | 91 | } |