📄 download.c
字号:
// // See if the timeout has expired. // if(lTimeout && ((tStart + lTimeout) < tNow)) { cChar = 0; break; } } // // Return the character read from the serial port. // return(cChar);#endif}//****************************************************************************//// WaitTillEmpty waits until the serial port's output buffer is empty.////****************************************************************************voidWaitTillEmpty(void){#ifdef _WIN32 // // Wait for 10ms so the output buffer can drain. // Sleep(10);#endif#ifdef __linux__ // // Wait until the output buffer is empty. // tcdrain(lSerialPort);#endif}//****************************************************************************//// WaitFor waits until a specific character is read from the serial port.////****************************************************************************voidWaitFor(char cWaitChar){ char cChar; // // Wait until we read a specific character from the serial port. // while(1) { // // Read a character. // cChar = ReceiveChar(0); // // Stop waiting if we received the character. // if(cChar == cWaitChar) { break; } }}//****************************************************************************//// Prints out a usage message for the program.////****************************************************************************voidUsage(void){ fprintf(stderr, "\Usage: download {-b <baud>} {-h} {-n <number>} {-o <offset>} {-p <port>}\n\ {-s} {-t <type>} {-v} <filename>\n\\n\Downloads a program image into the NOR FLASH of a Cirrus Logic EP73xx or\n\EP93xx board, or into the serial EEPROM of a EP93xx board. The Intel B3\n\(sizes 512KB through 4MB), C3 (sizes 1MB through 8MB), and J3(Strata) (sizes\n\4MB through 16MB) FLASH devices are supported in either 16 or 32 bit wide\n\configurations. The Atmel 25F1024 serial EEPROM is supported.\n\\n\ -b <baud> Use the specified baud rate (default is \"115200\"). Valid\n\ values are 9600, 19200, 38400, 57600, and 115200.\n\\n\ -h Prints this usage message.\n\\n\ -n <number> The board number, which implies the Ethernet MAC address, to\n\ be programmed into the EEPROM. This implies -s.\n\\n\ -o <offset> Start programming at the given offset into the FLASH/EEPROM.\n\\n\ -p <port> Use the specified serial port (default is \"1\"). Valid\n");#ifdef _WIN32 fprintf(stderr, "\ values are 1 (COM1), 2 (COM2), 3 (COM3), and 4 (COM4).\n");#endif#ifdef __linux__ fprintf(stderr, "\ values are 1 (/dev/ttyS0), 2 (/dev/ttyS1), 3 (/dev/ttyS2),\n\ and 4 (/dev/ttyS3).\n");#endif fprintf(stderr, "\\n\ -s Program the EEPROM instead of the NOR FLASH (only valid for\n\ an EP93xx).\n\\n\ -t Specifies the board type, used in conjunction with -n\n\ (default is \"9312\"). Valid values are 9301, 9302, 9307,\n\ 9312, or 9315.\n\\n\ -v Prints the version of this program.\n\\n\When -n is used to specify the board number, the board type and number are\n\used together to generate the Ethernet MAC address. This information is\n\placed at offset 0x1000 in the EEPROM; the 32 bytes of file data at that\n\position will be overwritten (or the data will be padded with zeros up to\n\that offset). It is valid to not specify a file when the Ethernet MAC\n\address is being programmed, in which case the first 0x1000 bytes of the\n\EEPROM will be filled with zeros.\n\\n");}//****************************************************************************//// This program waits for the '<' character from the boot ROM, sends the boot// code, waits for the '>' from the boot ROM, waits for the '?' from the boot// code, changes the serial port rate (preferably to 115200), downloads the// user data file, and then prints out progress status as the boot code writes// the user data file to the NOR FLASH.////****************************************************************************intmain(int argc, char *argv[]){ long lPort = 1, lRate = 115200, lFileSize, lIdx, lLoop, lSum, lOffset = 0; long lType = 9312, lNumber; char cChar, cFirstChar, cRateChar, cBuffer[1024], *pcString; int bError = 0, bEEPROM = 0, bMAC = 0, bHaveFile = 0; FILE *pFile; // // First, set stdout to be unbuffered, so that our status messages are // always displayed immediately. // setbuf(stdout, NULL); // // Prevent getopt from printing out any errors. // opterr = 0; // // See if there are any flags specified on the command line. // while((cChar = getopt(argc, argv, "b:hn:o:p:st:v")) != -1) { // // Determine which flag was specified. // switch(cChar) { // // See if this argument is "-b". // case 'b': { // // Get the baud rate from the command line. // lRate = atoi(optarg); // // Make sure that the specified baud rate is valid. // if((lRate != 9600) && (lRate != 19200) && (lRate != 38400) && (lRate != 57600) && (lRate != 115200)) { // // Tell the user that the baud rate is invalid. // fprintf(stderr, "Invalid baud rate '%s'.\n\n", optarg); // // Print the usage message. // Usage(); // // We're done. // return(1); } // // We're done handling this argument. // break; } // // See if this argument is "-h". // case 'h': { // // Print the usage message. // Usage(); // // We're done. // return(1); } // // See if this argument is "-n". // case 'n': { // // Get the board number from the command line. // lNumber = atoi(optarg); // // Make sure that the specified board number is valid. // if((lNumber < 1) || (lNumber > 65535)) { // // Tell the user that the board number is invalid. // fprintf(stderr, "Invalid board number '%s'.\n\n", optarg); // // Print the usage message. // Usage(); // // We're done. // return(1); } // // Indicate that the EEPROM is to be programmed, and that we // have a MAC address. // bEEPROM = 1; bMAC = 1; // // We're done handling this argument. // break; } // // See if this argument is "-o". // case 'o': { // // Get the starting offset. // lOffset = strtol(optarg, &pcString, 0); // // If the offset is followed by a "k", then multiply the value // by 1K. // if((*pcString == 'k') || (*pcString == 'K')) { lOffset *= 1024; } // // If the offset is followed by a "m", then multiply the value // by 1M. // if((*pcString == 'm') || (*pcString == 'M')) { lOffset *= 1048576; } // // We're done handling this argument. // break; } // // See if this argument is "-p". // case 'p': { // // Get the port number from the command line. // lPort = atoi(optarg); // // Make sure that the specified port number is valid. // if((lPort != 1) && (lPort != 2) && (lPort != 3) && (lPort != 4)) { // // Tell the user that the port number is invalid. // fprintf(stderr, "Invalid serial port '%s'.\n\n", optarg); // // Print the usage message. // Usage(); // // We're done. // return(1); } // // We're done handling this argument. // break; } // // See if this argument is "-s". // case 's': { // // Indicate that the EEPROM should be programmed. // bEEPROM = 1; // // We're done handling this argument. // break; } // // See if this argument is "-t". // case 't': { // // Get the board type from the command line. // lType = atoi(optarg); // // Make sure that the specified board type is valid. // if((lType != 9301) && (lType != 9302) && (lType != 9307) && (lType != 9312) && (lType != 9315)) { // // Tell the user that the board type is invalid. // fprintf(stderr, "Invalid board type '%s'.\n\n", optarg); // // Print the usage message. // Usage(); // // We're done. // return(1); } // // We done handling this argument. // break; } // // See if this argument is "-v". // case 'v': { // // Print the version of this program. // printf("Cirrus Logic FLASH Programmer for ARM Processors, " "Version 3.10 for ");#ifdef _WIN32 printf("Win32.\n");#endif#ifdef __linux__ printf("Linux.\n");#endif printf("Copyright (c) 1999,2000,2001,2002,2003,2004 Cirrus " "Logic, Inc.\n\n"); printf("Report bugs to <epdmkt@cirrus.com>.\n"); // // We're done. // return(0); } // // An unrecognized flag was specifed. // default: { // // Print the usage message. // Usage(); // // We're done. // return(1); } } } // // See if a filename was specified. // bHaveFile = ((optind + 1) == argc); // // Make sure that a filename was specified or that the MAC address should // be programmed. // if(!bHaveFile && !bMAC) { // // A filename or MAC address was not specified, so print the usage // message. // Usage(); // // We're done. // return(1); } // // Open the serial port to be used. // if(OpenPort(lPort) != 1) { return(1); } // // See if there is a file. // if(bHaveFile) { // // Open the file to be downloaded. // pFile = fopen(argv[argc - 1], "rb"); if(!pFile) { fprintf(stderr, "Could not open file '%s'.\n", argv[argc - 1]); ClosePort(lPort); return(1); } // // Get the size of the file. // fseek(pFile, 0, SEEK_END); lFileSize = ftell(pFile); fseek(pFile, 0, SEEK_SET); } else { // // Only the MAC address is to be programmed, so set the file size to // the size of the board info structure. // lOffset = 0; lFileSize = 0x1020; } // // Round the file size up to the next 1K boundary. // lFileSize = (lFileSize + 1023) & ~1023; // // Program the initial baud rate of 9600, 8 data bits, and no parity. // SetBaud(9600); //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -