From owner-p4-projects@FreeBSD.ORG Fri Aug 4 23:12:44 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C58D516A4EA; Fri, 4 Aug 2006 23:12:44 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A3C9D16A4E8 for ; Fri, 4 Aug 2006 23:12:44 +0000 (UTC) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2FFD043D58 for ; Fri, 4 Aug 2006 23:12:44 +0000 (GMT) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k74NCicp068636 for ; Fri, 4 Aug 2006 23:12:44 GMT (envelope-from imp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k74NChHp068633 for perforce@freebsd.org; Fri, 4 Aug 2006 23:12:43 GMT (envelope-from imp@freebsd.org) Date: Fri, 4 Aug 2006 23:12:43 GMT Message-Id: <200608042312.k74NChHp068633@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to imp@freebsd.org using -f From: Warner Losh To: Perforce Change Reviews Cc: Subject: PERFORCE change 103211 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Aug 2006 23:12:45 -0000 http://perforce.freebsd.org/chv.cgi?CH=103211 Change 103211 by imp@imp_lighthouse on 2006/08/04 23:12:17 Print download stats while we're downloading: update every 64k at end for each 'NAK' that we send to jumpstart the d/l Init the GPIO lines, etc when we set the MAC address Eliminate the lame state machine for tftp download. Even adding printing the stats, we save about 200 bytes. Affected files ... .. //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac.c#20 edit .. //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac.h#5 edit Differences ... ==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac.c#20 (text+ko) ==== @@ -35,8 +35,7 @@ static unsigned char localIPAddr[4], serverIPAddr[4]; static unsigned short serverPort, localPort; static int ackBlock; - -static unsigned lastAddress, lastSize; +static unsigned lastSize; static char *dlAddress; static unsigned transmitBuffer[1024 / sizeof(unsigned)]; @@ -184,7 +183,7 @@ char *cPtr, *ePtr, *mPtr; unsigned length; - tftpHeader.opcode = SWAP16(TFTP_RRQ_OPCODE); + tftpHeader.opcode = TFTP_RRQ_OPCODE; cPtr = (char*)&(tftpHeader.block_num); @@ -214,14 +213,16 @@ p_memcpy(dlAddress, data, len); dlAddress += len; lastSize += len; + if (ackBlock % 128 == 0) + printf("tftp: %u kB\r", lastSize / 1024); } - - tftpHeader.opcode = SWAP16(TFTP_ACK_OPCODE); - tftpHeader.block_num = SWAP16(block_num); + tftpHeader.opcode = TFTP_ACK_OPCODE; + tftpHeader.block_num = SWAP16(ackBlock); Send_TFTP_Packet((char*)&tftpHeader, 4); - - if (len < 512) + if (len < 512) { ackBlock = -2; + printf("tftp: %u byte\r\n", lastSize); + } } @@ -315,7 +316,7 @@ if (udpHdr->dst_port != localPort) break; - if (tftpHdr->opcode != SWAP16(TFTP_DATA_OPCODE)) + if (tftpHdr->opcode != TFTP_DATA_OPCODE) break; if (ackBlock == -1) { @@ -329,8 +330,8 @@ break; TFTP_ACK_Data(tftpHdr->data, - SWAP16(tftpHdr->block_num), - SWAP16(udpHdr->udp_len) - 12); + SWAP16(tftpHdr->block_num), + SWAP16(udpHdr->udp_len) - 12); } } p_rxBD[process].address &= ~0x01; @@ -516,6 +517,32 @@ // low_address & 0xff000000 = next // high_address & 0x000000ff = next // high_address & 0x0000ff00 = last byte in address + + if (!MAC_init) { + AT91C_BASE_PMC->PMC_PCER = 1u << AT91C_ID_EMAC; + AT91C_BASE_PIOA->PIO_ASR = + AT91C_PA14_ERXER | AT91C_PA12_ERX0 | AT91C_PA13_ERX1 | + AT91C_PA8_ETXEN | AT91C_PA16_EMDIO | AT91C_PA9_ETX0 | + AT91C_PA10_ETX1 | AT91C_PA11_ECRS_ECRSDV | AT91C_PA15_EMDC | + AT91C_PA7_ETXCK_EREFCK; + AT91C_BASE_PIOA->PIO_PDR = + AT91C_PA14_ERXER | AT91C_PA12_ERX0 | AT91C_PA13_ERX1 | + AT91C_PA8_ETXEN | AT91C_PA16_EMDIO | AT91C_PA9_ETX0 | + AT91C_PA10_ETX1 | AT91C_PA11_ECRS_ECRSDV | AT91C_PA15_EMDC | + AT91C_PA7_ETXCK_EREFCK; +#ifdef BOOT_KB9202 /* Really !RMII */ + AT91C_BASE_PIOB->PIO_BSR = + AT91C_PB12_ETX2 | AT91C_PB13_ETX3 | AT91C_PB14_ETXER | + AT91C_PB15_ERX2 | AT91C_PB16_ERX3 | AT91C_PB17_ERXDV | + AT91C_PB18_ECOL | AT91C_PB19_ERXCK; + AT91C_BASE_PIOB->PIO_PDR = + AT91C_PB12_ETX2 | AT91C_PB13_ETX3 | AT91C_PB14_ETXER | + AT91C_PB15_ERX2 | AT91C_PB16_ERX3 | AT91C_PB17_ERXDV | + AT91C_PB18_ECOL | AT91C_PB19_ERXCK; +#endif + MAC_init = 1; + } + } @@ -573,108 +600,41 @@ TFTP_Download(unsigned address, char *filename) { ip_header_t IpHeader; - unsigned thisSeconds, running, state; - int timeout, tickUpdate; - - if (!address) { - // report last transfer information - printf("\r\n -- Last tftp transfer info --\r\n" - " address: 0x%x\r\n" - " size: 0x%x\r\n", lastAddress, lastSize); - return ; - } + unsigned thisSeconds; + int timeout; if ((!localMACSet) || (!localIPSet) || (!serverIPSet)) return ; - if (!MAC_init) { - AT91C_BASE_PMC->PMC_PCER = 1u << AT91C_ID_EMAC; - AT91C_BASE_PIOA->PIO_ASR = - AT91C_PA14_ERXER | AT91C_PA12_ERX0 | AT91C_PA13_ERX1 | - AT91C_PA8_ETXEN | AT91C_PA16_EMDIO | AT91C_PA9_ETX0 | - AT91C_PA10_ETX1 | AT91C_PA11_ECRS_ECRSDV | AT91C_PA15_EMDC | - AT91C_PA7_ETXCK_EREFCK; - AT91C_BASE_PIOA->PIO_PDR = - AT91C_PA14_ERXER | AT91C_PA12_ERX0 | AT91C_PA13_ERX1 | - AT91C_PA8_ETXEN | AT91C_PA16_EMDIO | AT91C_PA9_ETX0 | - AT91C_PA10_ETX1 | AT91C_PA11_ECRS_ECRSDV | AT91C_PA15_EMDC | - AT91C_PA7_ETXCK_EREFCK; -#ifdef BOOT_KB9202 /* Really !RMII */ - AT91C_BASE_PIOB->PIO_BSR = - AT91C_PB12_ETX2 | AT91C_PB13_ETX3 | AT91C_PB14_ETXER | - AT91C_PB15_ERX2 | AT91C_PB16_ERX3 | AT91C_PB17_ERXDV | - AT91C_PB18_ECOL | AT91C_PB19_ERXCK; - AT91C_BASE_PIOB->PIO_PDR = - AT91C_PB12_ETX2 | AT91C_PB13_ETX3 | AT91C_PB14_ETXER | - AT91C_PB15_ERX2 | AT91C_PB16_ERX3 | AT91C_PB17_ERXDV | - AT91C_PB18_ECOL | AT91C_PB19_ERXCK; -#endif - MAC_init = 1; - } - AT91F_EmacEntry(); GetServerAddress(); - lastAddress = address; dlAddress = (char*)address; lastSize = 0; - running = 1; - state = TFTP_WAITING_SERVER_MAC; timeout = 10; thisSeconds = GetSeconds(); serverPort = SWAP16(69); ++localPort; ackBlock = -1; - while (running && timeout) { - int newpacket; - - newpacket = CheckForNewPacket(&IpHeader); - - tickUpdate = 0; - - if (!newpacket && thisSeconds != GetSeconds()) { - tickUpdate = 1; + while (timeout) { + if (CheckForNewPacket(&IpHeader)) { + if (ackBlock == -2) + break; + timeout = 10; + } else if (thisSeconds != GetSeconds()) { --timeout; thisSeconds = GetSeconds(); - } else if (newpacket) - timeout = 10; - - switch (state) { - - case TFTP_WAITING_SERVER_MAC: - if (serverMACSet) { - state = TFTP_SEND_REQUEST; - break; - } - - if (tickUpdate) - GetServerAddress(); - break; - - case TFTP_SEND_REQUEST: - // send request for file - if (ackBlock != -1) { - state = TFTP_GET_DATA; - break; - } - - if (tickUpdate) - TFTP_RequestFile(filename); - break; - - case TFTP_GET_DATA: - // receiving data - if (ackBlock == -2) { - state = TFTP_COMPLETE; - break; - } - break; - - case TFTP_COMPLETE: - default: - running = 0; - break; + if (!serverMACSet) + GetServerAddress(); + else if (ackBlock == -1) + TFTP_RequestFile(filename); + else { + // Be sure to send a NAK, which is done by + // ACKing the last block we got. + TFTP_ACK_Data(0, ackBlock, 512); + printf("\nNAK\r\n"); + } } } if (timeout == 0) @@ -697,7 +657,6 @@ localIPSet = 0; serverIPSet = 0; localPort = SWAP16(0x8002); - lastAddress = 0; lastSize = 0; MAC_init = 0; } ==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac.h#5 (text+ko) ==== @@ -104,16 +104,12 @@ unsigned char data[512]; } __attribute__((__packed__)) tftp_header_t; -#define TFTP_RRQ_OPCODE 1 -#define TFTP_WRQ_OPCODE 2 -#define TFTP_DATA_OPCODE 3 -#define TFTP_ACK_OPCODE 4 -#define TFTP_ERROR_OPCODE 5 - -#define TFTP_WAITING_SERVER_MAC 1 -#define TFTP_SEND_REQUEST 2 -#define TFTP_GET_DATA 3 -#define TFTP_COMPLETE 4 +// Preswap bytes +#define TFTP_RRQ_OPCODE 0x0100 +#define TFTP_WRQ_OPCODE 0x0200 +#define TFTP_DATA_OPCODE 0x0300 +#define TFTP_ACK_OPCODE 0x0400 +#define TFTP_ERROR_OPCODE 0x0500 /* MII registers definition */ #define MII_STS_REG 0x01