fetch.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * (C) Copyright 2001
  3. * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
  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. #include <common.h>
  24. #include <net.h>
  25. /* imports from input.c */
  26. extern int hymod_get_ethaddr (void);
  27. int
  28. fetch_and_parse (char *fn, ulong addr, int (*cback)(uchar *, uchar *))
  29. {
  30. char *ethaddr;
  31. uchar *fp, *efp;
  32. int rc, count = 0;
  33. while ((ethaddr = getenv ("ethaddr")) == NULL || *ethaddr == '\0') {
  34. printf ("*** Ethernet address is%s not set\n",
  35. count == 0 ? "" : " STILL");
  36. if ((rc = hymod_get_ethaddr ()) < 0) {
  37. if (rc == -1)
  38. puts ("\n*** interrupted!");
  39. else
  40. puts ("\n*** timeout!");
  41. printf (" - fetch of '%s' aborted\n", fn);
  42. return (0);
  43. }
  44. count++;
  45. }
  46. copy_filename (BootFile, fn, sizeof (BootFile));
  47. load_addr = addr;
  48. NetBootFileXferSize = 0;
  49. if (NetLoop (TFTP) == 0) {
  50. printf ("tftp transfer of file '%s' failed\n", fn);
  51. return (0);
  52. }
  53. if (NetBootFileXferSize == 0) {
  54. printf ("can't determine size of file '%s'\n", fn);
  55. return (0);
  56. }
  57. fp = (uchar *)load_addr;
  58. efp = fp + NetBootFileXferSize;
  59. do {
  60. uchar *name, *value;
  61. if (*fp == '#' || *fp == '\n') {
  62. /* skip this line */
  63. while (fp < efp && *fp++ != '\n')
  64. ;
  65. continue;
  66. }
  67. name = fp;
  68. while (fp < efp && *fp != '=' && *fp != '\n')
  69. fp++;
  70. if (fp >= efp)
  71. break;
  72. if (*fp == '\n') {
  73. fp++;
  74. continue;
  75. }
  76. *fp++ = '\0';
  77. value = fp;
  78. while (fp < efp && *fp != '\n')
  79. fp++;
  80. if (fp[-1] == '\r')
  81. fp[-1] = '\0';
  82. *fp++ = '\0'; /* ok if we go off the end here */
  83. if ((*cback)(name, value) == 0)
  84. return (0);
  85. } while (fp < efp);
  86. return (1);
  87. }