📄 download.c
字号:
//
// 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;
}
if((lOffset%1024)!=0)
{
fprintf(stderr, "The offset 0x%x is not at a block address boundary\n",lOffset);
return (1);
}
//
// 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);
if(lPort==0)
{
//lUSBPort=strtol(optarg,&PortString,1);
strcpy(PortString,optarg);
if((strlen(PortString)==4)&&
((PortString[0]=='u')||(PortString[0]=='U'))&&
((PortString[1]=='s')||(PortString[1]=='S'))&&
((PortString[2]=='b')||(PortString[2]=='B'))
)
{
//lUSBPort = atoi(PortString);
if((PortString[3]<='9')&&(PortString[3]>='0'))
{
lUSBPort=PortString[3]-'0';
bUSBPort=1;
fprintf(stderr, "Using USB Serial Port %d\n",lUSBPort);
}
else
{
lUSBPort=10;
}
}
else if((strlen(PortString)==2)&&
((PortString[0]=='s')||(PortString[0]=='S'))
)
{
//lUSBPort = atoi(PortString);
if((PortString[1]<='9')&&(PortString[1]>='0'))
{
lPort=PortString[1]-'0';
lPort=lPort+1;
fprintf(stderr, "Using Serial Port %d\n",lPort);
}
else
{
lPort=0;
lUSBPort=10;
}
}
else
{
lUSBPort=10;
lPort=0;
}
}
else
{
fprintf(stderr, "Using Serial Port %d\n",lPort);
}
//
// Make sure that the specified port number is valid.
//
if((lPort != 1) && (lPort != 2) && (lPort != 3) &&
(lPort != 4) && (lPort != 5) && (lPort != 6) &&
(lPort != 7) && (lPort != 8) && (lPort != 9) &&
(lUSBPort != 1) && (lUSBPort != 2) && (lUSBPort != 3) &&
(lUSBPort != 4) && (lUSBPort != 5) && (lUSBPort != 6) &&
(lUSBPort != 7) && (lUSBPort != 8) && (lUSBPort != 9) &&
(lUSBPort != 0) && (lPort != 10)
)
{
//
// 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);
}
if(bUSBPort==1)
{
lPort=lUSBPort;
}
//
// We're done handling this argument.
//
break;
}
//
// See if this argument is "-s".
//
case 's':
{
int iDevice=0;
//
// Get the storage device from the command line.
//
iDevice = atoi(optarg);
if((lStorage==2)&&(iDevice==1))
{
//
// Tell the user that the storage device is invalid.
//
fprintf(stderr, "the -s and -n options conflict.\n\n");
fprintf(stderr, "The storage device should EEPROM.\n\n");
//
// Print the usage message.
//
//Usage();
//
// We're done.
//
return(1);
}
lStorage=iDevice;
//
// Make sure that the specified storage device is valid.
//
if((iDevice != 1) && (iDevice != 2))
{
//
// Tell the user that the storage device is invalid.
//
fprintf(stderr, "Invalid storage device '%s'.\n\n", optarg);
//
// Print the usage message.
//
Usage();
//
// We're done.
//
return(1);
}
if(lStorage==1)
{
bFlash =1;
}
else if(lStorage==2)
{
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.12 for ");
#ifdef _WIN32
printf("Win32.\n");
#endif
#ifdef __linux__
printf("Linux.\n");
#endif
printf("Copyright (c) 2005, 2006 Cirrus "
"Logic, Inc.\n\n");
printf("Report bugs to <epdmkt@cirrus.com>.\n");
//
// We're done.
//
return(0);
}
//
// An unrecognized flag was specifed.
//
default:
{
char cDeStr[10];
strcpy(cDeStr,argv[optind-1]);
if(cDeStr[1]=='n')
{
if(bFlash==1)
{
//
// Tell the user that the storage device is invalid.
//
fprintf(stderr, "the -s and -n options conflict.\n\n");
fprintf(stderr, "The storage device should flash.\n\n");
//
// Print the usage message.
//
//Usage();
//
// We're done.
//
return(1);
}
//fprintf(stderr, "Read MAC Address.\n\n");
//
// Indicate that the EEPROM is to be programmed, and that we
// have a MAC address.
//
bReadEEPROM = 1;
lStorage = 2;
bEEPROM = 1;
bMAC = 1;
//
// We're done handling this argument.
//
break;
}
else
{
//
// 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,bUSBPort) != 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,bUSBPort);
return(1);
}
//
// Get the size of the file.
//
fseek(pFile, 0, SEEK_END);
lFileSize = ftell(pFile);
fseek(pFile, 0, SEEK_SET);
}
//else
if(bMAC)
{
//
// Only the MAC address is to be programmed, so set the file size to
// the size of the board info structure.
// Base = 0x1000,length = 1024
//lOffset = 0;
//lFileSize = 0x1020;
mOffset = 0;
mFileSize = 0x1020;
}
if((bMAC==1)&&(bHaveFile==1))
{
if((lOffset>0x1400)||((lOffset+lFileSize)<0x1000))
{
}
else
{
printf("The combination of the file size 0x%x and the -o offset 0x%x should not overlap with the MAC address at offset 0x1000.\n",
lFileSize,lOffset);
return (1);
}
}
//
// 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);
//
// Tell the user to reset the board.
//
printf("Waiting for the board to wakeup...");
//
// Wait until we read a '<' from the serial port.
//
WaitFor('<');
//
// Tell the user that we are downloading the boot code.
//
printf("\r \r");
printf("Downloading first boot code...( 0%%)");
//
// Write the boot code to the serial port.
//
for(lIdx = 0; lIdx < 2048; lIdx++)
{
//
// Write this character.
//
SendChar(pcBoot[lIdx]);
//
// Periodically print out our progress.
//
//if((lIdx & 127) == 127)
if((lIdx & 15) == 15)
{
//
// Wait until the transmit buffer is empty.
//
WaitTillEmpty();
//
// Print the updated status.
//
printf("\b\b\b\b\b%3d%%)", ((lIdx + 1) * 100) / 2048);
}
}
printf("\r \r");
//
// Wait until we read a '>' from the serial port.
//
WaitFor('>');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -