blob: da9373ffb0f4281dc53f6d4d1d86c964f2ddce53 [file] [log] [blame]
wdenk5d65f3a2002-08-19 08:10:25 +00001/*
2 * (C) Copyright 2001
wdenkb00ec162003-06-19 23:40:20 +00003 * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
wdenk5d65f3a2002-08-19 08:10:25 +00004 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk5d65f3a2002-08-19 08:10:25 +00006 */
7
8#include <common.h>
9#include <net.h>
10
wdenkb00ec162003-06-19 23:40:20 +000011/* imports from input.c */
12extern int hymod_get_ethaddr (void);
wdenk5d65f3a2002-08-19 08:10:25 +000013
14int
wdenkb00ec162003-06-19 23:40:20 +000015fetch_and_parse (char *fn, ulong addr, int (*cback)(uchar *, uchar *))
wdenk5d65f3a2002-08-19 08:10:25 +000016{
wdenkb00ec162003-06-19 23:40:20 +000017 char *ethaddr;
18 uchar *fp, *efp;
19 int rc, count = 0;
wdenk5d65f3a2002-08-19 08:10:25 +000020
wdenkb00ec162003-06-19 23:40:20 +000021 while ((ethaddr = getenv ("ethaddr")) == NULL || *ethaddr == '\0') {
wdenk5d65f3a2002-08-19 08:10:25 +000022
wdenkb00ec162003-06-19 23:40:20 +000023 printf ("*** Ethernet address is%s not set\n",
24 count == 0 ? "" : " STILL");
wdenk5d65f3a2002-08-19 08:10:25 +000025
wdenkb00ec162003-06-19 23:40:20 +000026 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);
wdenk5d65f3a2002-08-19 08:10:25 +000033 }
34
wdenkb00ec162003-06-19 23:40:20 +000035 count++;
wdenk5d65f3a2002-08-19 08:10:25 +000036 }
wdenk5d65f3a2002-08-19 08:10:25 +000037
wdenkb00ec162003-06-19 23:40:20 +000038 copy_filename (BootFile, fn, sizeof (BootFile));
39 load_addr = addr;
40 NetBootFileXferSize = 0;
wdenk5d65f3a2002-08-19 08:10:25 +000041
Simon Glassd6c5f552011-10-24 18:00:02 +000042 if (NetLoop(TFTPGET) == 0) {
wdenkb00ec162003-06-19 23:40:20 +000043 printf ("tftp transfer of file '%s' failed\n", fn);
44 return (0);
wdenk5d65f3a2002-08-19 08:10:25 +000045 }
46
wdenkb00ec162003-06-19 23:40:20 +000047 if (NetBootFileXferSize == 0) {
48 printf ("can't determine size of file '%s'\n", fn);
49 return (0);
50 }
wdenk5d65f3a2002-08-19 08:10:25 +000051
wdenkb00ec162003-06-19 23:40:20 +000052 fp = (uchar *)load_addr;
53 efp = fp + NetBootFileXferSize;
wdenk5d65f3a2002-08-19 08:10:25 +000054
wdenkb00ec162003-06-19 23:40:20 +000055 do {
56 uchar *name, *value;
wdenk5d65f3a2002-08-19 08:10:25 +000057
wdenkb00ec162003-06-19 23:40:20 +000058 if (*fp == '#' || *fp == '\n') {
59 /* skip this line */
60 while (fp < efp && *fp++ != '\n')
61 ;
62 continue;
63 }
wdenk5d65f3a2002-08-19 08:10:25 +000064
wdenkb00ec162003-06-19 23:40:20 +000065 name = fp;
wdenk5d65f3a2002-08-19 08:10:25 +000066
wdenkb00ec162003-06-19 23:40:20 +000067 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';
wdenk5d65f3a2002-08-19 08:10:25 +000076
wdenkb00ec162003-06-19 23:40:20 +000077 value = fp;
wdenk5d65f3a2002-08-19 08:10:25 +000078
wdenkb00ec162003-06-19 23:40:20 +000079 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 */
wdenk5d65f3a2002-08-19 08:10:25 +000084
wdenkb00ec162003-06-19 23:40:20 +000085 if ((*cback)(name, value) == 0)
86 return (0);
wdenk5d65f3a2002-08-19 08:10:25 +000087
wdenkb00ec162003-06-19 23:40:20 +000088 } while (fp < efp);
wdenk5d65f3a2002-08-19 08:10:25 +000089
wdenkb00ec162003-06-19 23:40:20 +000090 return (1);
wdenk5d65f3a2002-08-19 08:10:25 +000091}