Date: Fri, 4 Aug 2006 23:12:43 GMT From: Warner Losh <imp@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 103211 for review Message-ID: <200608042312.k74NChHp068633@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608042312.k74NChHp068633>