blob: 9444c036453a946b7e232f4d3c89140f624f9b7b [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
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
24#include <common.h>
25#include <command.h>
26#include <net.h>
wdenkf602aa02004-03-13 23:29:43 +000027#include "nfs.h"
wdenkaffae2b2002-08-17 09:36:01 +000028#include "bootp.h"
29#include "rarp.h"
30#include "tftp.h"
31
Bartlomiej Sieka56668462008-10-01 15:26:28 +020032#define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
wdenkaffae2b2002-08-17 09:36:01 +000033#ifndef CONFIG_NET_RETRY_COUNT
34# define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
35#else
36# define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
37#endif
38
39
40int RarpTry;
41
42/*
43 * Handle a RARP received packet.
44 */
45static void
46RarpHandler(uchar * dummi0, unsigned dummi1, unsigned dummi2, unsigned dummi3)
47{
wdenkf602aa02004-03-13 23:29:43 +000048 char *s;
Robin Getz9e0a4d62009-07-23 03:01:03 -040049 debug("Got good RARP\n");
wdenk00fe1612004-03-14 00:07:33 +000050 if ((s = getenv("autoload")) != NULL) {
51 if (*s == 'n') {
52 /*
53 * Just use RARP to configure system;
54 * Do not use TFTP/NFS to to load the bootfile.
55 */
56 NetState = NETLOOP_SUCCESS;
57 return;
Jon Loeliger54f35c22007-07-09 17:45:14 -050058#if defined(CONFIG_CMD_NFS)
wdenk00fe1612004-03-14 00:07:33 +000059 } else if ((s != NULL) && !strcmp(s, "NFS")) {
60 NfsStart();
61 return;
62#endif
63 }
wdenkf602aa02004-03-13 23:29:43 +000064 }
wdenkaffae2b2002-08-17 09:36:01 +000065 TftpStart ();
66}
67
68
69/*
70 * Timeout on BOOTP request.
71 */
72static void
73RarpTimeout(void)
74{
75 if (RarpTry >= TIMEOUT_COUNT) {
76 puts ("\nRetry count exceeded; starting again\n");
77 NetStartAgain ();
78 } else {
Bartlomiej Sieka56668462008-10-01 15:26:28 +020079 NetSetTimeout (TIMEOUT, RarpTimeout);
wdenkaffae2b2002-08-17 09:36:01 +000080 RarpRequest ();
81 }
82}
83
84
85void
86RarpRequest (void)
87{
88 int i;
89 volatile uchar *pkt;
90 ARP_t * rarp;
91
92 printf("RARP broadcast %d\n", ++RarpTry);
93 pkt = NetTxPacket;
94
wdenk145d2c12004-04-15 21:48:45 +000095 pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP);
wdenkaffae2b2002-08-17 09:36:01 +000096
97 rarp = (ARP_t *)pkt;
98
wdenkabda5ca2003-05-31 18:35:21 +000099 rarp->ar_hrd = htons (ARP_ETHER);
100 rarp->ar_pro = htons (PROT_IP);
wdenkaffae2b2002-08-17 09:36:01 +0000101 rarp->ar_hln = 6;
102 rarp->ar_pln = 4;
wdenkabda5ca2003-05-31 18:35:21 +0000103 rarp->ar_op = htons (RARPOP_REQUEST);
wdenkaffae2b2002-08-17 09:36:01 +0000104 memcpy (&rarp->ar_data[0], NetOurEther, 6); /* source ET addr */
105 memcpy (&rarp->ar_data[6], &NetOurIP, 4); /* source IP addr */
106 memcpy (&rarp->ar_data[10], NetOurEther, 6); /* dest ET addr = source ET addr ??*/
107 /* dest. IP addr set to broadcast */
108 for (i = 0; i <= 3; i++) {
109 rarp->ar_data[16 + i] = 0xff;
110 }
111
wdenk145d2c12004-04-15 21:48:45 +0000112 NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
wdenkaffae2b2002-08-17 09:36:01 +0000113
Bartlomiej Sieka56668462008-10-01 15:26:28 +0200114 NetSetTimeout(TIMEOUT, RarpTimeout);
wdenkaffae2b2002-08-17 09:36:01 +0000115 NetSetHandler(RarpHandler);
116}