38 #ifndef WIN32_LEAN_AND_MEAN 39 #define WIN32_LEAN_AND_MEAN 1 59 void usage(
const char *programNameP)
61 fprintf(stderr,
"USAGE: %s <options>\n", programNameP);
62 fprintf(stderr,
"Where <options> are:\n");
63 fprintf(stderr,
"\t-a <ip_address> : IP address of device (default=10.66.171.21)\n");
64 fprintf(stderr,
"\t-p : Perform flash operation\n");
65 fprintf(stderr,
"\t-v : Perform verify operation\n");
66 fprintf(stderr,
"\t-b <bitstream_file> : The bitstream (.bin) file\n");
67 fprintf(stderr,
"\t-f <firmware_file> : The firmware (.srec) file\n");
70 bool verifyFileWithExtension(
const std::string& description,
71 const std::string& fileName,
72 const std::string& extension)
75 std::ifstream file(fileName.c_str(),
76 std::ios::in | std::ios::binary);
78 if (
false == file.good()) {
79 fprintf(stderr,
"Cannot open %s file \"%s\" for reading, aborting.\n",
80 description.c_str(), fileName.c_str());
84 }
catch (
const std::exception& e) {
85 fprintf(stderr,
"Exception accessing %s file \"%s\" for reading: %s.\n",
86 description.c_str(), fileName.c_str(), e.what());
90 std::string::size_type idx = fileName.rfind(
'.');
92 if (std::string::npos != idx &&
93 fileName.substr(idx+1) == extension)
96 fprintf(stderr,
"%s file \"%s\" is not a \".%s\" file, aborting.\n",
97 description.c_str(), fileName.c_str(), extension.c_str());
109 std::string ipAddress =
"10.66.171.21";
110 bool programOp =
false;
111 bool verifyOp =
false;
113 std::string bitstreamFile;
114 std::string firmwareFile;
121 while(-1 != (c =
getopt(argc, argvPP,
"a:epvb:f:")))
123 case 'a': ipAddress = std::string(
optarg);
break;
124 case 'p': programOp =
true;
break;
125 case 'v': verifyOp =
true;
break;
126 case 'b': bitstreamFile = std::string(
optarg);
break;
127 case 'f': firmwareFile = std::string(
optarg);
break;
128 default:
usage(*argvPP); exit(-1);
break;
134 if (
false == bitstreamFile.empty() &&
135 false == verifyFileWithExtension(
"Bitstream", bitstreamFile,
"bin"))
137 if (
false == firmwareFile.empty() &&
138 false == verifyFileWithExtension(
"Firmware", firmwareFile,
"srec"))
145 if (NULL == channelP) {
146 fprintf(stderr,
"Failed to establish communications with \"%s\"\n",
158 if (!bitstreamFile.empty()) {
160 fprintf(stderr,
"Programming bitstream: %s\n",
161 bitstreamFile.c_str());
165 fprintf(stderr,
"Programming bitstream failed: %s\n",
172 if (!firmwareFile.empty()) {
174 fprintf(stderr,
"Programming firmware: %s\n",
175 firmwareFile.c_str());
179 fprintf(stderr,
"Programming firmware failed: %s\n",
192 if (!bitstreamFile.empty()) {
194 fprintf(stderr,
"Verifying bitstream: %s\n",
195 bitstreamFile.c_str());
199 fprintf(stderr,
"Verify bitstream failed: %s\n",
206 if (!firmwareFile.empty()) {
208 fprintf(stderr,
"Verifying firmware: %s\n",
209 firmwareFile.c_str());
213 fprintf(stderr,
"Verify firmware failed: %s\n",
static const char * statusString(Status status)
virtual Status verifyFirmware(const std::string &file)=0
static Channel * Create(const std::string &sensorAddress)
int main(int argc, char **argvPP)
virtual Status verifyBitstream(const std::string &file)=0
int getopt(int argc, char **argv, char *opts)
static CRL_CONSTEXPR Status Status_Ok
virtual Status flashBitstream(const std::string &file)=0
static void Destroy(Channel *instanceP)
virtual Status flashFirmware(const std::string &file)=0