blob: da9373ffb0f4281dc53f6d4d1d86c964f2ddce53 [file] [log] [blame]
wdenk5d65f3a2002-08-19 08:10:25 +00001/*
2 * (C) Copyright 2001
wdenk6dd652f2003-06-19 23:40:20 +00003 * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
wdenk5d65f3a2002-08-19 08:10:25 +00004 *
Wolfgang Denk1a459662013-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
wdenk6dd652f2003-06-19 23:40:20 +000011/* imports from input.c */
12extern int hymod_get_ethaddr (void);
wdenk5d65f3a2002-08-19 08:10:25 +000013
14int
wdenk6dd652f2003-06-19 23:40:20 +000015fetch_and_parse (char *fn, ulong addr, int (*cback)(uchar *, uchar *))
wdenk5d65f3a2002-08-19 08:10:25 +000016{
wdenk6dd652f2003-06-19 23:40:20 +000017 char *ethaddr;
18 uchar *fp, *efp;
19 int rc, count = 0;
wdenk5d65f3a2002-08-19 08:10:25 +000020
wdenk6dd652f2003-06-19 23:40:20 +000021 while ((ethaddr = getenv ("ethaddr")) == NULL || *ethaddr == '\0') {
wdenk5d65f3a2002-08-19 08:10:25 +000022
wdenk6dd652f2003-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
wdenk6dd652f2003-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);
33 }
wdenk5d65f3a2002-08-19 08:10:25 +000034
wdenk6dd652f2003-06-19 23:40:20 +000035 count++;
36 }
wdenk5d65f3a2002-08-19 08:10:25 +000037
wdenk6dd652f2003-06-19 23:40:20 +000038 copy_filename (BootFile, fn, sizeof (BootFile));
39 load_addr = addr;
40 NetBootFileXferSize = 0;
41
Simon Glasse4bf0c52011-10-24 18:00:02 +000042 if (NetLoop(TFTPGET) == 0) {
wdenk6dd652f2003-06-19 23:40:20 +000043 printf ("tftp transfer of file '%s' failed\n", fn);
wdenk5d65f3a2002-08-19 08:10:25 +000044 return (0);
wdenk5d65f3a2002-08-19 08:10:25 +000045 }
46
wdenk6dd652f2003-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
wdenk6dd652f2003-06-19 23:40:20 +000052 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
wdenk5d65f3a2002-08-19 08:10:25 +000065 name = fp;
66
wdenk6dd652f2003-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
wdenk6dd652f2003-06-19 23:40:20 +000077 value = fp;
wdenk5d65f3a2002-08-19 08:10:25 +000078
wdenk6dd652f2003-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
wdenk6dd652f2003-06-19 23:40:20 +000085 if ((*cback)(name, value) == 0)
86 return (0);
wdenk5d65f3a2002-08-19 08:10:25 +000087
wdenk6dd652f2003-06-19 23:40:20 +000088 } while (fp < efp);
wdenk5d65f3a2002-08-19 08:10:25 +000089
wdenk6dd652f2003-06-19 23:40:20 +000090 return (1);
wdenk5d65f3a2002-08-19 08:10:25 +000091}