diff -NurbB u-boot/common/cmd_net.c u-boot-work/common/cmd_net.c --- u-boot/common/cmd_net.c 2005-03-07 16:47:57.000000000 +0100 +++ u-boot-work/common/cmd_net.c 2005-03-04 13:26:59.000000000 +0100 @@ -236,6 +236,30 @@ ); #endif /* CFG_CMD_PING */ +#if (CONFIG_COMMANDS & CFG_CMD_ETHLOOP) +int do_ethloop (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + if (argc != 1) + return -1; + + if (NetLoop(ETHLOOP) < 0) { + printf("loopback test failed\n"); + return 1; + } + + printf("loopback test successfully completed\n"); + return 0; +} + +U_BOOT_CMD( + ethloop, 1, 1, do_ethloop, + "ethloop\t- loopback test using ethernet test package\n", + "- send and receive ethernet test package\n" + "\t Ensure that EMAC/PHY loopback mode has been\n" + "\t set before or use a loopback plug\n" +); +#endif /* CFG_CMD_ETHLOOP */ + #if (CONFIG_COMMANDS & CFG_CMD_CDP) static void cdp_update_env(void) diff -NurbB u-boot/include/cmd_confdefs.h u-boot-work/include/cmd_confdefs.h --- u-boot/include/cmd_confdefs.h 2005-03-07 16:45:39.000000000 +0100 +++ u-boot-work/include/cmd_confdefs.h 2005-03-04 11:28:33.000000000 +0100 @@ -92,6 +92,7 @@ #define CFG_CMD_XIMG 0x0400000000000000ULL /* Load part of Multi Image */ #define CFG_CMD_UNIVERSE 0x0800000000000000ULL /* Tundra Universe Support */ #define CFG_CMD_EXT2 0x1000000000000000ULL /* EXT2 Support */ +#define CFG_CMD_ETHLOOP 0x2000000000000000ULL /* ETH loopback test */ #define CFG_CMD_ALL 0xFFFFFFFFFFFFFFFFULL /* ALL commands */ diff -NurbB u-boot/include/net.h u-boot-work/include/net.h --- u-boot/include/net.h 2005-03-07 16:49:17.000000000 +0100 +++ u-boot-work/include/net.h 2005-03-07 13:47:03.000000000 +0100 @@ -163,6 +163,7 @@ #define PROT_IP 0x0800 /* IP protocol */ #define PROT_ARP 0x0806 /* IP ARP protocol */ +#define PROT_TEST 0x0808 /* Ethernet loopback test */ #define PROT_RARP 0x8035 /* IP ARP protocol */ #define PROT_VLAN 0x8100 /* IEEE 802.1q protocol */ @@ -335,7 +336,7 @@ extern int NetRestartWrap; /* Tried all network devices */ #endif -typedef enum { BOOTP, RARP, ARP, TFTP, DHCP, PING, DNS, NFS, CDP, NETCONS } proto_t; +typedef enum { BOOTP, RARP, ARP, TFTP, DHCP, PING, DNS, NFS, CDP, NETCONS, ETHLOOP } proto_t; /* from net/net.c */ extern char BootFile[128]; /* Boot File name */ diff -NurbB u-boot/net/net.c u-boot-work/net/net.c --- u-boot/net/net.c 2005-03-07 16:44:08.000000000 +0100 +++ u-boot-work/net/net.c 2005-03-07 14:03:17.000000000 +0100 @@ -93,6 +93,8 @@ #define ET_DEBUG #endif +#define ETHLOOP_LEN 64 + /** BOOTP EXTENTIONS **/ IPaddr_t NetOurSubnetMask=0; /* Our subnet mask (0=unknown) */ @@ -121,6 +123,8 @@ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; uchar NetEtherNullAddr[6] = { 0, 0, 0, 0, 0, 0 }; +uchar EtherPacket[ETHLOOP_LEN]; /* buffer for loopback test frame */ + #if (CONFIG_COMMANDS & CFG_CMD_CDP) uchar NetCDPAddr[6] = /* Ethernet bcast address */ { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc }; @@ -144,6 +148,12 @@ static void PingStart(void); #endif +#if (CONFIG_COMMANDS & CFG_CMD_ETHLOOP) + + +static void EthLoopStart(void); +#endif + #if (CONFIG_COMMANDS & CFG_CMD_CDP) static void CDPStart(void); #endif @@ -313,6 +323,11 @@ #if (CONFIG_COMMANDS & CFG_CMD_PING) case PING: #endif +#if (CONFIG_COMMANDS & CFG_CMD_ETHLOOP) + case ETHLOOP: + + +#endif case NETCONS: case TFTP: NetCopyIP(&NetOurIP, &bd->bi_ip_addr); @@ -402,6 +417,12 @@ PingStart(); break; #endif +#if (CONFIG_COMMANDS & CFG_CMD_ETHLOOP) + case ETHLOOP: + + EthLoopStart(); + break; +#endif #if (CONFIG_COMMANDS & CFG_CMD_NFS) case NFS: NfsStart(); @@ -745,6 +766,55 @@ } #endif /* CFG_CMD_PING */ +#if (CONFIG_COMMANDS & CFG_CMD_ETHLOOP) +int EthLoopSend(void) +{ + int i; + uchar *pkt; + + for (i=0 ; iudp_src), ntohs(ip->udp_len) - 8); break; + case PROT_TEST: + + printf ("Got ethernet loopback frame, len=%d\n", NetRxPktLen); + + + +#if 0 + if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2)) { + puts ("checksum bad\n"); + return; + } +#endif + /* + * Ethernet header OK. Pass the packet to the current handler. + */ + (*packetHandler)((uchar *)NetRxPkt, 0, 0, NetRxPktLen); + break; } }