Bitstream bitstream = cmdLineParser.parseRequiredBitstreamFromOptionsExitOnError(options, true);
/////////////////////////////////////////////////////////////////////
// 2. Obtain part information
/////////////////////////////////////////////////////////////////////
XilinxConfigurationSpecification partInfo = cmdLineParser.getPartInfoExitOnError(options, bitstream, true);
// 3. Create FPGA object
FPGA fpga = new FPGA(partInfo);
// Configure FPGA
fpga.configureBitstream(bitstream);
String outputBitstreamFileName = cmdLineParser.getOutputFileNameStringExitOnError(options);
/////////////////////////////////////////////////////////////////////
// Perform Bitstreams Operations
/////////////////////////////////////////////////////////////////////
if (options.has(XOR_STRING) || options.has(OVERWRITE_STRING) ||options.has(CLEAR_STRING) ||
options.has(AND_STRING) ||options.has(NOT_STRING) ||options.has(OR_STRING)
|| options.has(APPEND_OPTION_STRING)) {
if (!options.has("r")) {
System.err.println("Operational bitfile name needed for bitstream operation");
cmdLineParser.printUsageAndExit();
}
String operationalBitstreamFileName = (String) options.valueOf("r");
// load operational bitstream (this is an odd way of doing it but I am copying Ben's code)
Bitstream opBitstream = BitstreamParser.parseBitstreamExitOnError(operationalBitstreamFileName);
System.out.print("Successfully loaded operational bitstream - ");
// TODO: Make sure the two bitstreams are the same size. Same part?
FPGA fpga2 = new FPGA(partInfo);
fpga2.configureBitstream(opBitstream);
if(options.has(XOR_STRING))
{
FPGAOperation.operation(fpga, fpga2, FPGAOperation.OPERATORS.XOR );
System.out.println("XOR operation performed"); // use this to find differences in BRAM data.
}
else if(options.has(AND_STRING))
{
FPGAOperation.operation(fpga, fpga2, FPGAOperation.OPERATORS.AND );
System.out.println("AND operation performed");
}
else if(options.has(OR_STRING))
{
FPGAOperation.operation(fpga, fpga2, FPGAOperation.OPERATORS.OR );
System.out.println("OR operation performed");
}
else if(options.has(NOT_STRING))
{
FPGAOperation.operation(fpga, fpga2, FPGAOperation.OPERATORS.NOT );
System.out.println("NOT operation performed");
}
else if(options.has(OVERWRITE_STRING))
{
fpga.configureBitstream(opBitstream);
System.out.println("Overwrite operation performed");
}
else if(options.has(CLEAR_STRING))
{
// Find all of the frames that are configured on fpga2
ArrayList<Frame> fpga2configuredFrames = fpga2.getConfiguredFrames();
// Clear all the corresponding frames on fpga1
for (Frame fd : fpga2configuredFrames) {
fd.clear();
}
System.out.println("Clear operation performed\n");
}
else if(options.has(APPEND_OPTION_STRING)) {
// Append the packets of the operational bitstream to the packets of the original bitstream
PacketList opPackets = opBitstream.getPackets();
PacketList inPackets = bitstream.getPackets();
inPackets.addAll(opPackets);
if (writeBitstreamToBIT(bitstream, outputBitstreamFileName) == 0) {
System.out.println("Generated BRAM Bitstream:"+outputBitstreamFileName);
} else {
System.err.println("Problem generating BRAM bitstream");
System.exit(1);
}
System.out.println("Append operation performed");
}
}
/////////////////////////////////////////////////////////////////////
// Perform Bitstreams Write Operations
/////////////////////////////////////////////////////////////////////
// create the bitstream
Bitstream newBitstream = null;
BitstreamHeader newHeader = null;
if (options.has(NEW_ALGORITHM)) {
// TODO
// for the new algorithm, create a new header with different values
newHeader = bitstream.getHeader();
} else {
// for the old algorithm, copy the header from the original bitstream
newHeader = bitstream.getHeader();
}
// BRAM operation
if (options.has(BRAM_OPTION_STRING)) {
if (options.has(NEW_ALGORITHM)) {
// New algorithm
System.err.println("New Algorithm not yet supported");
System.exit(1);
} else {
// Use old algorithm
newBitstream = partInfo.getBitstreamGenerator().createPartialBRAMBitstream(fpga, newHeader);
}
if (writeBitstreamToBIT(newBitstream, outputBitstreamFileName) == 0) {
System.out.println("Generated BRAM Bitstream:"+outputBitstreamFileName);
} else {
System.err.println("Problem generating BRAM bitstream");
System.exit(1);
}
}
// PARTIAL operation
if (options.has(PARTIAL_OPTION_STRING)) {
if (newBitstream != null) {
System.err.println("Only one write can be performed.");
System.exit(1);
}
if (options.has(NEW_ALGORITHM)) {
// New algorithm (currently same as old algorithm)
newBitstream = partInfo.getBitstreamGenerator().createPartialBitstream(fpga, newHeader);
} else {
// Use old algorithm
newBitstream = partInfo.getBitstreamGenerator().createPartialBitstream(fpga, newHeader);
}
if (writeBitstreamToBIT(newBitstream, outputBitstreamFileName) == 0) {
System.out.println("Generated Partial Bitstream:"+outputBitstreamFileName);
} else {
System.err.println("Problem generating Partial bitstream");
System.exit(1);
}
}
if (options.has(FULL_OPTION_STRING)) {
if (newBitstream != null) {
System.err.println("Only one write can be performed. Option -f ignored");
System.exit(1);
}
newBitstream = partInfo.getBitstreamGenerator().createFullBitstream(fpga, bitstream.getHeader());
if (writeBitstreamToBIT(newBitstream, outputBitstreamFileName) == 0) {
System.out.println("Generated Full Bitstream:"+outputBitstreamFileName);
} else {
System.err.println("Problem generating Full bitstream");
System.exit(1);