15 #pragma warning(disable: 4305) // Initialization warnings. 16 #pragma warning(disable: 4309) 17 #pragma warning(disable: 4800) 18 #pragma warning(disable: 4996) 21 #define ENUM_CASE_RETURN_VAL_OR_ENUM_STR(condition, retail_name, enum_name)\ 22 case(enum_name): return condition ? retail_name : #enum_name 26 #define KFPDBUG(__x__) AJA_sDEBUG (AJA_DebugUnit_Firmware, AJAFUNC << ": " << __x__) 27 #define KFPWARN(__x__) AJA_sWARNING (AJA_DebugUnit_Firmware, AJAFUNC << ": " << __x__) 28 #define KFPERR(__x__) do {ostringstream oss; oss << AJAFUNC << ": " << __x__; cerr << "## ERROR: " << oss.str() << endl; AJA_sERROR (AJA_DebugUnit_Firmware, oss.str());} while(false) 29 #define KFPNOTE(__x__) do {ostringstream oss; oss << AJAFUNC << ": " << __x__; if (!_bQuiet) cout << "## NOTE: " << oss.str() << endl; AJA_sNOTICE (AJA_DebugUnit_Firmware, oss.str());} while(false) 35 oss <<
xHEX0N(uint16_t(mac[0]),2) <<
":" <<
xHEX0N(uint16_t(mac[1]),2) <<
":" <<
xHEX0N(uint16_t(mac[2]),2)
36 <<
":" <<
xHEX0N(uint16_t(mac[3]),2) <<
":" <<
xHEX0N(uint16_t(mac[4]),2) <<
":" <<
xHEX0N(uint16_t(mac[5]),2);
77 _numSectorsFailSafe (0),
85 _hasExtendedCommandSupport (
false)
105 _numSectorsFailSafe (0),
111 _failSafePadding (0),
113 _hasExtendedCommandSupport (
false)
160 UWord runningYear(0), runningMonth(0), runningDay(0);
161 outIsRunning =
false;
167 outMsgs <<
"## WARNING: Failed to get running firmware date/time" << endl;
172 std::tm tm; ::memset(&tm, 0,
sizeof(tm));
173 tm.tm_year = int(runningYear) - 1900;
174 tm.tm_mon = int(runningMonth) - 1;
175 tm.tm_mday = int(runningDay);
178 std::time_t tRunning (std::mktime(&tm));
182 {outMsgs <<
"## WARNING: Failed to ReadHeader or ParseHeader" << endl;
return false;}
184 string installedBuildDate(
GetDate());
188 if (installedBuildDate.empty() || installedBuildDate.length() < 10 || installedBuildDate.at(4) !=
'/')
189 {outMsgs <<
"## WARNING: Bad installed firmware date '" << installedBuildDate <<
"'" << endl;
return false;}
192 tm.tm_year = int(
aja::stol(installedBuildDate.substr(0, 4))) - 1900;
193 tm.tm_mon = int(
aja::stol(installedBuildDate.substr(5, 2))) - 1;
194 tm.tm_mday = int(
aja::stol(installedBuildDate.substr(8, 2)));
197 std::time_t tInstalled (std::mktime(&tm));
200 ULWord secsApart (
ULWord(::difftime(tInstalled, tRunning)));
203 else if (secsApart <= 86400)
204 {outMsgs <<
"## WARNING: Installed firmware date is 1 day past running firmware date" << endl; outIsRunning =
true;}
217 uint32_t ledMask =
BIT(16)+
BIT(17);
218 uint32_t ledShift = 16;
225 bool knownChip =
false;
438 {outMsgs <<
"Invalid flash block ID " <<
DEC(blockID);
return false;}
442 stat(inBitfileName.c_str(), &fsinfo);
444 pFile = fopen(inBitfileName.c_str(),
"rb");
446 {outMsgs <<
"Cannot open bitfile '" << inBitfileName <<
"'";
return false;}
450 {outMsgs <<
"Allocate " <<
DEC(
_bitFileSize+512) <<
"-byte buffer failed";
return false;}
453 fseek(pFile, 0, SEEK_SET);
463 {outMsgs <<
"Device not recognized";
return false;}
470 if (bitFileName.find(
"_fs_") != string::npos)
479 const int dwordSizeCount (
int(bitFileHeader.
GetByteCount()) / 4);
480 for (
int count(0); status && count < dwordSizeCount; count++, baseAddress += 4)
495 vector<uint8_t> mcsInfoData;
502 _mcsInfo.assign(mcsInfoData.begin(), mcsInfoData.end());
519 for (uint32_t count(0); count < dwordSizeCount; count++, baseAddress += 4)
525 if (mcsInfoPtr.
U32(
int(count)) == 0)
532 size_t ffPos(
_mcsInfo.find(
"\xFF\xFF"));
533 if (ffPos != string::npos)
541 return "Bitfile not open";
544 return "Device not open";
561 uint32_t twoFixtysixBlockSizeCount ((
_bitFileSize + 256) / 256);
562 uint32_t percentComplete(0);
565 for (uint32_t count(0); count < twoFixtysixBlockSizeCount; count++, baseAddress += 256, bitFilePtr += 64)
573 percentComplete = (count*100)/twoFixtysixBlockSizeCount;
577 cout <<
"Program status: " <<
DEC(percentComplete) <<
"% \r" << flush;
580 cout <<
"Program status: 100% " << endl;
586 return "Program Didn't Verify";
623 for ( uint32_t count=0; count < 64; count++ )
636 uint32_t deviceID = 0;
643 return (deviceID & 0xFFFFFF);
657 uint32_t percentComplete = 0;
663 uint32_t bankCount = 0;
664 for (uint32_t sectorCount = 0; sectorCount < numSectors; sectorCount++ )
681 percentComplete = (sectorCount*100)/numSectors;
684 cout <<
"Erase status: " <<
DEC(percentComplete) <<
"%\r" << flush;
688 cout <<
"Erase status: 100% " << endl;
719 uint32_t errorCount = 0;
723 uint32_t percentComplete(0), lastPercentComplete(999);
728 for (uint32_t count = 0; count < dwordSizeCount; )
740 uint32_t bitFileValue = *bitFilePtr;
741 if (flashValue != bitFileValue)
743 cerr <<
"Error " <<
DEC(count) <<
" E(" <<
HEX0N(bitFileValue,8) <<
"),R(" <<
HEX0N(flashValue,8) <<
")" << endl;
748 percentComplete = (count*100)/dwordSizeCount;
752 if (percentComplete != lastPercentComplete)
754 cout <<
"Program verify: " <<
DEC(percentComplete) <<
"%\r" << flush;
755 lastPercentComplete = percentComplete;
758 count += fullVerify ? 1 : 64;
759 baseAddress += fullVerify ? 4 : 256;
760 bitFilePtr += fullVerify ? 1 : 64;
768 cout <<
"Program verify failed: " <<
DEC(percentComplete) <<
"%" << endl;
772 cout <<
"Program verify: 100% " << endl;
783 {
KFPERR(
"Unable to resize target buffer (not alloc'd by SDK)");
return false;}
784 if (!outBuffer.
Allocate(numDWords * 4))
785 {
KFPERR(
"Failed to allocate " <<
DEC(numDWords*4) <<
"-byte target buffer");
return false;}
788 size_t lastPercent(0), percent(0);
803 for (uint32_t dword(0); dword < numDWords; )
824 outBuffer.
U32(
int(dword)) = flashValue;
828 percent = dword * 100 / numDWords;
829 if (percent != lastPercent)
832 lastPercent = percent;
833 if ((dword % 0x10000) == 0) cerr <<
xHEX0N(dword,8) <<
" of " <<
xHEX0N(numDWords,8) << endl;
856 if (!(regValue &
BIT(8)))
871 uint32_t dwordSizeCount = (numSectors*
_sectorSize)/4;
872 uint32_t percentComplete = 0;
875 for (uint32_t count = 0; count < dwordSizeCount; count++, baseAddress += 4)
882 if ( flashValue != 0xFFFFFFFF )
884 count = dwordSizeCount;
888 percentComplete = (count*100)/dwordSizeCount;
890 cout <<
"Erase verify: " <<
DEC(percentComplete) <<
"%\r" << flush;
893 cout <<
"Erase verify: 100% " << endl;
903 uint32_t baseAddress = 0;
905 uint32_t partitionOffset = 0;
907 cout <<
"S0030000FC" << endl;
909 for ( uint32_t count = 0; count <
_flashSize; count+=32)
915 partitionOffset = count;
916 switch (partitionOffset)
926 uint32_t recordSize = 32;
935 uint32_t cc (recordSize + 5);
939 uint32_t addr = baseAddress+partitionOffset;
940 UWord aa = ((addr >> 24) &0xff);
944 aa = ((addr >> 16) & 0xff);
948 aa = ((addr >> 8) & 0xff);
958 while(i < recordSize)
968 UWord dd = (flashValue & 0xff);
972 dd = ((flashValue >> 8) & 0xff);
976 dd = ((flashValue >> 16) & 0xff);
980 dd = ((flashValue >> 24) & 0xff);
988 checksum = ~checksum;
991 cout << sRec.str() << endl;
996 cout <<
"S705FFF001000A" << endl;
1003 uint32_t baseAddress = 0;
1005 uint32_t partitionOffset = 0;
1007 cout <<
"S0030000FC" << endl;
1009 for (uint32_t count = 0; count <
_bankSize; count += 32)
1016 uint32_t recordSize = 32;
1025 sRec <<
Hex0N(cc,2);
1028 uint32_t addr = baseAddress + partitionOffset;
1029 UWord aa = ((addr >> 24) & 0xff);
1030 sRec <<
Hex0N(aa,2);
1033 aa = ((addr >> 16) & 0xff);
1034 sRec <<
Hex0N(aa,2);
1037 aa = ((addr >> 8) & 0xff);
1038 sRec <<
Hex0N(aa,2);
1042 sRec <<
Hex0N(aa,2);
1047 while (i < recordSize)
1052 uint32_t flashValue;
1056 UWord dd = (flashValue & 0xff);
1057 sRec <<
Hex0N(dd,2);
1060 dd = ((flashValue >> 8) & 0xff);
1061 sRec <<
Hex0N(dd,2);
1064 dd = ((flashValue >> 16) & 0xff);
1065 sRec <<
Hex0N(dd,2);
1068 dd = ((flashValue >> 24) & 0xff);
1069 sRec <<
Hex0N(dd,2);
1076 checksum = ~checksum;
1079 cout << sRec.str() << endl;
1084 cout <<
"S705FFF001000A" << endl;
1092 int32_t recordSize = 16;
1093 UWord baseAddress = 0x0000;
1095 UByte recordType = 0x00;
1096 UByte byteCount = 0x10;
1098 uint32_t i2cVal = 0x02000050;
1100 for(int32_t x = 0; x < 16; x++)
1109 checksum += byteCount;
1111 UWord addr = baseAddress;
1112 UByte aa = ((addr >> 8) & 0xff);
1116 aa = ((addr) & 0xff);
1130 uint32_t flashValue;
1133 UByte dd = ((flashValue >> 8) & 0xff);
1139 i2cVal += 0x00000100;
1142 baseAddress += 0x0010;
1143 checksum = (checksum ^ 0xFF)+1;
1146 cout << iRec.str() << endl;
1149 cout <<
":00000001FF" << endl;
1165 vector<uint8_t> macData;
1166 macData.push_back(mac1->
mac[3]);
1167 macData.push_back(mac1->
mac[2]);
1168 macData.push_back(mac1->
mac[1]);
1169 macData.push_back(mac1->
mac[0]);
1170 macData.push_back(0);
1171 macData.push_back(0);
1172 macData.push_back(mac1->
mac[5]);
1173 macData.push_back(mac1->
mac[4]);
1175 macData.push_back(mac2->
mac[3]);
1176 macData.push_back(mac2->
mac[2]);
1177 macData.push_back(mac2->
mac[1]);
1178 macData.push_back(mac2->
mac[0]);
1179 macData.push_back(0);
1180 macData.push_back(0);
1181 macData.push_back(mac2->
mac[5]);
1182 macData.push_back(mac2->
mac[4]);
1209 lo |= uint32_t((mac1->
mac[0]) << 24) & 0xff000000;
1210 lo |= uint32_t((mac1->
mac[1]) << 16) & 0x00ff0000;
1211 lo |= uint32_t((mac1->
mac[2]) << 8) & 0x0000ff00;
1212 lo |= uint32_t(mac1->
mac[3]) & 0x000000ff;
1215 hi |= uint32_t((mac1->
mac[4]) << 24) & 0xff000000;
1216 hi |= uint32_t((mac1->
mac[5]) << 16) & 0x00ff0000;
1219 lo2 |= uint32_t((mac2->
mac[0]) << 24) & 0xff000000;
1220 lo2 |= uint32_t((mac2->
mac[1]) << 16) & 0x00ff0000;
1221 lo2 |= uint32_t((mac2->
mac[2]) << 8) & 0x0000ff00;
1222 lo2 |= uint32_t(mac2->
mac[3]) & 0x000000ff;
1225 hi2 |= uint32_t((mac2->
mac[4]) << 24) & 0xff000000;
1226 hi2 |= uint32_t((mac2->
mac[5]) << 16) & 0x00ff0000;
1256 vector<uint8_t> macData;
1263 if (macData.size() < 16)
1266 mac1.
mac[0] = macData.at(3);
1267 mac1.
mac[1] = macData.at(2);
1268 mac1.
mac[2] = macData.at(1);
1269 mac1.
mac[3] = macData.at(0);
1270 mac1.
mac[4] = macData.at(7);
1271 mac1.
mac[5] = macData.at(6);
1273 mac2.
mac[0] = macData.at(8+3);
1274 mac2.
mac[1] = macData.at(8+2);
1275 mac2.
mac[2] = macData.at(8+1);
1276 mac2.
mac[3] = macData.at(8+0);
1277 mac2.
mac[4] = macData.at(8+7);
1278 mac2.
mac[5] = macData.at(8+6);
1289 uint32_t lo, hi, lo2, hi2;
1321 mac1.
mac[0] = (lo & 0xff000000) >> 24;
1322 mac1.
mac[1] = (lo & 0x00ff0000) >> 16;
1323 mac1.
mac[2] = (lo & 0x0000ff00) >> 8;
1324 mac1.
mac[3] = lo & 0x000000ff;
1325 mac1.
mac[4] = (hi & 0xff000000) >> 24;
1326 mac1.
mac[5] = (hi & 0x00ff0000) >> 16;
1328 mac2.
mac[0] = (lo2 & 0xff000000) >> 24;
1329 mac2.
mac[1] = (lo2 & 0x00ff0000) >> 16;
1330 mac2.
mac[2] = (lo2 & 0x0000ff00) >> 8;
1331 mac2.
mac[3] = lo2 & 0x000000ff;
1332 mac2.
mac[4] = (hi2 & 0xff000000) >> 24;
1333 mac2.
mac[5] = (hi2 & 0x00ff0000) >> 16;
1345 vector<uint8_t> licenseData;
1346 for (string::const_iterator it(licenseString.begin()); it != licenseString.end(); ++it)
1347 licenseData.push_back(uint8_t(*it));
1348 licenseData.push_back(0);
1354 if (
_spiFlash->
Write(offset, licenseData, uint32_t(licenseData.size())))
1370 size_t len (licenseString.size());
1371 size_t words ((len/4) + 2);
1375 strcat(data8,licenseString.c_str());
1379 for (
size_t i(0); i < words; i++)
1403 const uint32_t maxSize = 100;
1409 vector<uint8_t> licenseData;
1417 if (licenseData.size() < 4)
1419 else if (licenseData[0] == 0xff && licenseData[1] == 0xff && licenseData[2] == 0xff && licenseData[3] == 0xff)
1423 serialString.assign(licenseData.begin(), licenseData.end());
1426 size_t found = serialString.find(
'\0');
1427 if (found != string::npos)
1428 serialString.resize(found);
1440 memset (license,0x0,
sizeof(license));
1445 bool terminated =
false;
1447 for(uint32_t i = 0; i < maxSize; i++)
1453 if (license[i] == 0xffffffff)
1458 if (license[i] == 0)
1469 res =
reinterpret_cast<char*
>(license);
1481 if (
int(bankNumber) >
int(
BANK_3))
1496 uint32_t bankNumber = 0;
1503 return bankNumber&0xf;
1509 cout <<
"Parsing MCS File" << endl;
1516 {cerr <<
"MCS bitfile not open" << endl;
return false;}
1518 {cerr <<
"Device not open" << endl;
return false;}
1523 {cerr <<
"MCS file not ready" << endl;
return false;}
1528 vector<uint8_t> fpgaData;
1529 uint16_t fpgaPartitionOffset = 0;
1541 {cerr <<
"Can't parse header" << endl << msgs.str() << endl;
return false;}
1549 bool hasErasedSOCs =
false;
1550 uint16_t linearOffsetToBankOffset = 0x0000;
1551 uint16_t basePartitionAddress = linearOffsetToBankOffset;
1552 bool bPartitionValid =
true;
1553 uint32_t partitionCount = 0;
1554 while (bPartitionValid)
1560 uint16_t partitionOffset = 0;
1563 if (basePartitionAddress < 0x0100)
1566 linearOffsetToBankOffset = 0x0000;
1569 cout <<
"Erase Main Bitfile Bank" << endl;
1574 else if (basePartitionAddress >= 0x0100 && basePartitionAddress < 0x0200)
1577 linearOffsetToBankOffset = 0x0100;
1580 cout <<
"Erase Package Info Block" << endl;
1585 else if (basePartitionAddress >= 0x0200 && basePartitionAddress < 0x0400)
1590 cout <<
"Erase SOC Bank 1" << endl;
1594 cout <<
"Erase SOC Bank 2" << endl;
1597 hasErasedSOCs =
true;
1599 if (basePartitionAddress >= 0x0200 && basePartitionAddress < 0x0300)
1602 linearOffsetToBankOffset = 0x0200;
1608 linearOffsetToBankOffset = 0x0300;
1617 uint16_t baseOffset = basePartitionAddress - linearOffsetToBankOffset;
1618 uint32_t programOffset = uint32_t(baseOffset) << 16 | partitionOffset;
1622 bPartitionValid =
false;
1631 uint32_t bufferIndex = 0;
1632 uint32_t blockSize = 512;
1633 uint32_t dwordsPerBlock = blockSize / 4;
1634 uint32_t totalBlockCount ((uint32_t(
_partitionBuffer.size()) + blockSize) / blockSize);
1635 uint32_t percentComplete = 0;
1638 for (uint32_t blockCount = 0; blockCount < totalBlockCount; blockCount++)
1641 if (baseAddress == 0x01000000 && blockCount > 0 && blockID ==
SOC1_FLASHBLOCK)
1648 uint32_t remainderBytes =
static_cast<uint32_t
>(
_partitionBuffer.size() - bufferIndex);
1652 for (uint32_t dwordCount = 0; dwordCount < dwordsPerBlock; dwordCount++)
1654 uint32_t partitionValue = 0xFFFFFFFF;
1655 if (remainderBytes >= 4)
1662 remainderBytes -= 4;
1666 switch (remainderBytes)
1669 partitionValue = 0xff;
1675 partitionValue = 0xffff;
1680 partitionValue = 0xffffff;
1696 baseAddress += blockSize;
1698 percentComplete = (blockCount * 100) / totalBlockCount;
1700 cout <<
"Partition " <<
DEC(partitionCount) <<
" program status: " <<
DEC(percentComplete) <<
"%\r" << flush;
1703 cout <<
"Partition " <<
DEC(partitionCount) <<
" program status: 100% " << endl;
1727 cerr <<
"Verify Error" << endl;
1736 bPartitionValid =
false;
1763 {cerr <<
"MCS bitfile not open" << endl;
return false;}
1768 {cerr <<
"Device not open" << endl;
return false;}
1770 {cerr <<
"MCS bitfile not ready" << endl;
return false;}
1772 vector<uint8_t> ubootData;
1773 vector<uint8_t> imageData;
1774 vector<uint8_t> mcsInfoData;
1775 uint16_t ubootPartitionOffset = 0;
1776 uint16_t imagePartitionOffset = 0;
1777 uint16_t mcsInfoPartitionOffset = 0;
1779 if (ubootData.empty())
1780 {cerr <<
"Could not find uboot data in MCS file" << endl;
return false;}
1783 if (imageData.empty())
1784 {cerr <<
"Could not find kernel data in MCS file" << endl;
return false;}
1787 if (mcsInfoData.empty())
1788 {cerr <<
"Could not find mcs info in MCS file" << endl;
return false;}
1794 uint32_t ubootSize = uint32_t(ubootData.size());
1795 uint32_t imageSize = uint32_t(imageData.size());
1796 uint32_t mcsInfoSize = uint32_t(mcsInfoData.size());
1832 {cerr <<
"Device not open" << endl;
return false;}
1834 cout <<
"Erase SOC Bank 1" << endl;
1837 cout <<
"Erase SOC Bank 2" << endl;
1843 uint16_t partition32M = 0x0200;
1844 uint16_t basePartitionAddress = partition32M;
1845 bool bPartitionValid =
true;
1846 uint32_t partitionCount = 0;
1847 while (bPartitionValid)
1849 uint16_t partitionOffset = 0;
1851 uint16_t baseOffset = basePartitionAddress - partition32M;
1852 uint32_t programOffset = uint32_t(baseOffset) << 16 | partitionOffset;
1855 if (programOffset >= 0x01000000)
1863 uint32_t bufferIndex = 0;
1864 uint32_t blockSize = 512;
1865 uint32_t dwordsPerBlock = blockSize / 4;
1866 uint32_t totalBlockCount =
static_cast<uint32_t
>((
_partitionBuffer.size() + blockSize) / blockSize);
1867 uint32_t percentComplete = 0;
1868 for (uint32_t blockCount = 0; blockCount < totalBlockCount; blockCount++)
1870 if (baseAddress == 0x01000000 && blockCount > 0)
1875 uint32_t remainderBytes =
static_cast<uint32_t
>(
_partitionBuffer.size() - bufferIndex);
1879 for (uint32_t dwordCount = 0; dwordCount < dwordsPerBlock; dwordCount++)
1881 uint32_t partitionValue = 0xFFFFFFFF;
1882 if (remainderBytes >= 4)
1889 remainderBytes -= 4;
1893 switch (remainderBytes)
1896 partitionValue = 0xff;
1902 partitionValue = 0xffff;
1907 partitionValue = 0xffffff;
1923 baseAddress += blockSize;
1925 percentComplete = (blockCount * 100) / totalBlockCount;
1927 cout <<
"Partition " <<
DEC(partitionCount+2) <<
" program status: " <<
DEC(percentComplete) <<
"%\r" << flush;
1930 cout <<
"Partition " <<
DEC(partitionCount+2) <<
" program status: 100% " << endl;
1935 cerr <<
"Verify failed" << endl;
1943 bPartitionValid =
false;
1964 static bool getFileSize (
const string & fileName,
size_t & outSizeBytes)
1967 ifstream ifs(fileName.c_str(), ios::binary | ios::in);
1972 ifstream::pos_type curOffset(ifs.tellg());
1973 if (
int(curOffset) == -1)
1975 outSizeBytes = size_t(curOffset);
1982 {outMsgs <<
"Device not open" << endl;
return false;}
1986 vector<uint8_t> writeData;
1990 {outMsgs <<
"getFileSize failed for '" << sCustomFileName <<
"'" << endl;
return false;}
1991 if (sz > maxFlashSize)
1992 {outMsgs <<
"File size " <<
DEC(sz) <<
" exceeds max flash size " <<
DEC(maxFlashSize) << endl;
return false;}
1994 ifstream ifs(sCustomFileName.c_str(), ios::binary | ios::in);
1996 {outMsgs <<
"Unable to open file '" << sCustomFileName <<
"'" << endl;
return false;}
1998 writeData.resize(sz);
1999 ifs.read(reinterpret_cast<char*>(&writeData[0]), streamsize(sz));
2001 {outMsgs <<
"Error reading data from file '" << sCustomFileName <<
"'" << endl;
return false;}
2004 uint32_t writeSize = uint32_t(writeData.size());
2007 {outMsgs <<
"Error erasing sectors, addr=" <<
xHEX0N(addr,8) <<
" length=" <<
DEC(writeSize) << endl;
return false;}
2012 bool result =
true, verify =
true;
2021 static const size_t MAX_CUSTOM_FILE_SIZE (8<<20);
2022 NTV2Buffer customFileBuffer(MAX_CUSTOM_FILE_SIZE);
2023 size_t customSize(0), sz(0);
2027 {outMsgs <<
"Custom write spans banks -- unsupported";
return false;}
2029 {outMsgs <<
"Write not on sector boundary -- unsupported";
return false;}
2031 {outMsgs <<
"Error getting file size for '" << sCustomFileName <<
"'";
return false;}
2032 if (sz > MAX_CUSTOM_FILE_SIZE)
2033 {outMsgs <<
"File size " <<
DEC(sz) <<
" exceeds max supported size " <<
DEC(MAX_CUSTOM_FILE_SIZE);
return false;}
2035 ifstream ifs(sCustomFileName.c_str(), ios::binary | ios::in);
2037 {outMsgs <<
"Unable to open file '" << sCustomFileName <<
"'" << endl;
return false;}
2039 customSize = size_t(ifs.readsome(customFileBuffer, streamsize(customFileBuffer.
GetByteCount())));
2041 {outMsgs <<
"No data read from custom file '" << sCustomFileName <<
"'" << endl;
return false;}
2053 for (uint32_t i(0); i < customSectors; i++)
2056 cout <<
"Erasing sectors - " <<
DECN(i,3) <<
" of " <<
DECN(customSectors,3) <<
"\r" << flush;
2063 uint32_t blockSize (512);
2064 uint32_t dwordsPerBlock (blockSize / 4);
2065 uint32_t totalBlockCount ((uint32_t(customSize) + blockSize - 1) / blockSize);
2066 uint32_t percentComplete (0);
2067 uint32_t baseAddress (offset);
2068 size_t remainderBytes (customSize);
2069 uint32_t bufferIndex (0);
2070 for (uint32_t blockCount(0); blockCount < totalBlockCount; blockCount++)
2075 for (uint32_t dwordCount(0); dwordCount < dwordsPerBlock; dwordCount++)
2077 uint32_t partitionValue = 0xFFFFFFFF;
2078 if (remainderBytes >= 4)
2085 remainderBytes -= 4;
2087 else switch (remainderBytes)
2090 partitionValue = 0xff;
2097 partitionValue = 0xffff;
2103 partitionValue = 0xffffff;
2117 baseAddress += blockSize;
2119 percentComplete = (blockCount * 100) / totalBlockCount;
2121 cout <<
"Program status: " <<
DEC(percentComplete) <<
"% (" <<
DECN(blockCount,4) <<
" of " <<
DECN(totalBlockCount,4) <<
" blocks)\r" << flush;
2190 bool getnext =
false;
2191 if (address != 0x0000 && address != 0x0200)
2202 uint32_t errorCount = 0;
2203 uint32_t baseAddress = flashBlockOffset;
2205 uint32_t dwordsPerPartition =
_bankSize / 4;
2206 uint32_t percentComplete = 0;
2207 uint32_t bufferIndex = 0;
2209 for (uint32_t dwordCount = 0; dwordCount < dwordsPerPartition; dwordCount += 100)
2215 uint32_t flashValue;
2217 uint32_t partitionValue = uint32_t(
_partitionBuffer[bufferIndex + 0]) << 24
2225 if (flashValue != partitionValue)
2227 cerr <<
"Error " <<
DEC(dwordCount) <<
" E(" <<
xHEX0N(partitionValue,8) <<
"),R(" <<
xHEX0N(flashValue,8) <<
")" << endl;
2233 percentComplete = (dwordCount * 100) / dwordsPerPartition;
2235 cout <<
"Program verify: " <<
DEC(percentComplete) <<
"%\r" << flush;
2241 cerr <<
"Program verify failed: " <<
DEC(percentComplete) <<
"%" << endl;
2245 cout <<
"Program verify: 100% " << endl;
2251 const uint32_t WORDS_PER_LINE(4);
2252 uint32_t addr(address), bank(999), offset(addr %
_bankSize);
2255 uint32_t lineCount(0);
2256 for (uint32_t words(0); words < wordCount; words++, offset += 4, addr += 4)
2259 if (newBank != bank)
2271 uint32_t flashValue;
2274 cout <<
Hex0N(flashValue,8) <<
" ";
2275 if (++lineCount == WORDS_PER_LINE)
2291 uint32_t baseAddress = 0;
2293 cout <<
"Erasing ROM" << endl;
2298 uint32_t* bitFilePtr =
reinterpret_cast<uint32_t*
>(dataBuffer.data());
2299 uint32_t twoFixtysixBlockSizeCount = uint32_t((dataBuffer.size()+256)/256);
2300 uint32_t percentComplete = 0;
2303 for ( uint32_t count = 0; count < twoFixtysixBlockSizeCount; count++, baseAddress += 256, bitFilePtr += 64 )
2318 percentComplete = (count*100)/twoFixtysixBlockSizeCount;
2321 if(!
_bQuiet && (count%100 == 0))
2322 cout <<
"Program status: " <<
DEC(percentComplete) <<
"%\r" << flush;
2325 cout <<
"Program status: 100% " << endl;
2350 if(mac1.
mac[1] != 0x0C || mac2.
mac[1] != 0x0c)
2353 cout <<
"Reprogramming the Mac Addresses!" << endl;
2354 string serialString;
2366 if (strstr(sSerialNumber,
"demo") == sSerialNumber)
2369 if (sscanf(sSerialNumber + 4,
"%d", &demoNum) != 1)
2371 if ((demoNum < 1) || (demoNum > 128))
2372 {cerr <<
"WARNING: Outside serial numbers demo0001 to demo0128" << endl;
return false;}
2373 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2374 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2375 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2376 pMac2->
mac[3] = pMac1->
mac[3] = 0x88;
2377 pMac2->
mac[4] = pMac1->
mac[4] = 0x12;
2378 pMac1->
mac[5] = uint8_t((demoNum - 1) * 2);
2379 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2382 else if (strstr(sSerialNumber,
"1IP") == sSerialNumber)
2389 if (sscanf(sSerialNumber + 4,
"%d", &serNum) != 1)
2391 if ((serNum < 50) || (serNum > 8241))
2392 {cerr <<
"WARNING: Outside serial numbers 1IP00050 to 1IP08241" << endl;
return false;}
2394 int mac16LSBs = (0xA000) + (serNum - 50) * 2;
2396 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2397 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2398 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2399 pMac2->
mac[3] = pMac1->
mac[3] = 0x42;
2400 pMac2->
mac[4] = pMac1->
mac[4] = uint8_t(mac16LSBs >> 8);
2401 pMac2->
mac[5] = pMac1->
mac[5] = mac16LSBs & 0x0ff;
2404 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2407 else if (strstr(sSerialNumber,
"ENG") == sSerialNumber)
2414 if (sscanf(sSerialNumber + 5,
"%d", &serNum) != 1)
2418 {cerr <<
"WARNING: Outside serial numbers ENG00000 to ENG00127" << endl;
return false;}
2420 int mac16LSBs = (0x1B00) + (serNum * 2);
2422 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2423 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2424 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2425 pMac2->
mac[3] = pMac1->
mac[3] = 0x88;
2426 pMac2->
mac[4] = pMac1->
mac[4] = uint8_t(mac16LSBs >> 8);
2427 pMac2->
mac[5] = pMac1->
mac[5] = mac16LSBs & 0xff;
2430 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2433 else if (strstr(sSerialNumber,
"6XT") == sSerialNumber)
2441 if (sscanf(sSerialNumber + 4,
"%d", &serNum) != 1)
2444 if ((serNum < 250) || (serNum > 8441))
2445 {cerr <<
"WARNING: Outside serial numbers range 250 to 8441" << endl;
return false;}
2450 if (strstr(sSerialNumber,
"6XT0") == sSerialNumber)
2452 mac24LSBs = (0x48A000) + ((serNum - 250) * 2);
2454 else if (strstr(sSerialNumber,
"6XT2") == sSerialNumber)
2456 mac24LSBs = (0x48E000) + ((serNum - 250) * 2);
2458 else if (strstr(sSerialNumber,
"6XT1") == sSerialNumber)
2460 mac24LSBs = (0x4B2000) + ((serNum - 250) * 2);
2462 else if (strstr(sSerialNumber,
"6XT3") == sSerialNumber)
2464 mac24LSBs = (0x4B6000) + ((serNum - 250) * 2);
2471 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2472 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2473 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2474 pMac2->
mac[3] = pMac1->
mac[3] = (mac24LSBs & 0xFF0000) >> 16;
2475 pMac2->
mac[4] = pMac1->
mac[4] = (mac24LSBs & 0x00FF00) >> 8;
2476 pMac2->
mac[5] = pMac1->
mac[5] = (mac24LSBs & 0x0000FF) >> 0;
2479 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2483 cerr <<
"Unrecognized or unspecified serial number '" << sSerialNumber <<
"'" << endl;
2490 #pragma warning(default: 4800) static std::string FlashBlockIDToString(const FlashBlockID inID, const bool inShortDisplay=(0))
Defines the KonaIP/IoIP registers.
long stol(const std::string &str, std::size_t *idx, int base)
uint32_t GetBaseAddressForProgramming(FlashBlockID flashBlockNumber)
bool CreateEDIDIntelRecord()
bool Allocate(const size_t inByteCount, const bool inPageAligned=false)
Allocates (or re-allocates) my user-space storage using the given byte count. I assume full responsib...
IntelRecordType recordType
I interrogate and control an AJA video/audio capture/playout device.
Declares the AJADebug class.
virtual UWord GetIndexNumber(void) const
uint32_t U32(const int inIndex) const
#define DEVICE_IS_KONAX(__d__)
#define MAXBITFILE_HEADERSIZE
ULWord GetByteCount(void) const
Declares the AJATime class.
void DisplayData(const uint32_t address, const uint32_t len)
std::string GetDate(void) const
#define kRegSarekSpiSelect
#define DEVICE_IS_IOIP(__d__)
Defines a number of handy byte-swapping macros.
virtual uint32_t Size(SpiFlashSection sectionID=SPI_FLASH_SECTION_TOTAL)=0
CNTV2SpiFlash * _spiFlash
bool SetMCSFile(const std::string &sMCSFileName)
virtual class DeviceCapabilities & features(void)
bool EraseSector(uint32_t sectorAddress)
bool SetBankSelect(BankSelect bankNumber)
virtual bool Verify(const uint32_t address, const std::vector< uint8_t > &dataWritten)=0
virtual bool Read(const uint32_t address, std::vector< uint8_t > &data, uint32_t maxBytes=1)=0
static bool getFileSize(const string &fileName, size_t &outSizeBytes)
bool NTV2DeviceROMHasBankSelect(const NTV2DeviceID inDeviceID)
virtual bool Erase(const uint32_t address, uint32_t bytes)=0
#define NTV2_ASSERT(_expr_)
bool VerifySOCPartition(FlashBlockID flashID, uint32_t FlashBlockOffset)
virtual bool SetWarmBootFirmwareReload(bool enable)
bool Fill(const T &inValue)
Fills me with the given scalar value.
bool Deallocate(void)
Deallocates my user-space storage (if I own it – i.e. from a prior call to Allocate).
bool SetBitFile(const std::string &inBitfileName, std::ostream &outMsgs, const FlashBlockID blockNumber=AUTO_FLASHBLOCK)
bool WaitForFlashNOTBusy()
bool IsAllocatedBySDK(void) const
NTV2DeviceID _boardID
My cached device ID.
virtual bool IsOpen(void) const
bool SetFlashBlockIDBank(FlashBlockID blockID)
bool CreateBankRecord(BankSelect bankID)
virtual bool GetSerialNumberString(std::string &outSerialNumberString)
Answers with a string that contains my human-readable serial number.
bool VerifyFlash(FlashBlockID flashBlockNumber, bool fullVerify=(0))
virtual bool Write(const uint32_t address, const std::vector< uint8_t > data, uint32_t maxBytes=1)=0
bool _hasExtendedCommandSupport
virtual bool SetBoard(uint32_t index=0)
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
virtual ~CNTV2KonaFlashProgram()
bool ReadLicenseInfo(std::string &licenseString)
virtual bool isReady(void) const
bool ProgramLicenseInfo(const std::string &licenseString)
static CNTV2FlashProgress gNullUpdater
virtual NTV2DeviceID GetDeviceID(void)
bool WriteCommand(_FLASH_COMMAND inCommand)
virtual bool ReadRegister(const ULWord inRegNum, ULWord &outValue, const ULWord inMask=0xFFFFFFFF, const ULWord inShift=0)
Reads all or part of the 32-bit contents of a specific register (real or virtual) on the AJA device...
bool NTV2DeviceCanReportRunningFirmwareDate(const NTV2DeviceID inDeviceID)
virtual bool Open(const std::string &inMCSFilePath)
Opens the bitfile at the given path, then parses its header.
Describes a user-space buffer on the host computer. I have an address and a length, plus some optional attributes (allocated by SDK?, page-aligned? etc.).
NTV2BitfileHeaderParser _parser
bool ProgramMACAddresses(MacAddr *mac1, MacAddr *mac2)
virtual bool GetVerbosity()
uint32_t GetNumberOfSectors(FlashBlockID flashBlockNumber)
virtual bool GetCurrentParsedRecord(IntelRecordInfo &recordInfo)
bool ReadHeader(FlashBlockID flashBlock)
std::string Program(bool fullVerify=(0))
#define NTV2_UNUSED(__p__)
bool ProgramFlashValue(uint32_t address, uint32_t value)
bool EraseChip(UWord chip=0)
bool FullProgram(std::vector< uint8_t > &dataBuffer)
std::vector< uint8_t > _partitionBuffer
virtual bool WriteRegister(const ULWord inRegNum, const ULWord inValue, const ULWord inMask=0xFFFFFFFF, const ULWord inShift=0)
Updates or replaces all or part of the 32-bit contents of a specific register (real or virtual) on th...
virtual uint32_t Offset(SpiFlashSection sectionID=SPI_FLASH_SECTION_TOTAL)=0
#define xHEX0N(__x__, __n__)
bool FastProgramFlash256(uint32_t address, uint32_t *buffer)
uint8_t * _customFileBuffer
bool IsInstalledFWRunning(bool &outIsRunning, std::ostream &outErrorMsgs)
Declares the CNTV2KonaFlashProgram class.
#define ENUM_CASE_RETURN_VAL_OR_ENUM_STR(condition, retail_name, enum_name)
bool ProgramSOC(bool verify=(!(0)))
bool CheckFlashErasedWithBlockID(FlashBlockID flashBlockNumber)
Private include file for all ajabase sources.
void ParsePartitionFromFileLines(uint32_t address, uint16_t &partitionOffset)
bool ProgramFromMCS(bool verify)
std::string AsString(void) const
virtual bool UpdatePercentage(const size_t inPercentage)
UWord NTV2DeviceGetSPIFlashVersion(const NTV2DeviceID inDeviceID)
bool EraseBlock(FlashBlockID blockNumber)
void * GetHostPointer(void) const
#define HEX0N(__x__, __n__)
bool SetDeviceProperties()
bool ReadFlash(NTV2Buffer &outBuffer, const FlashBlockID flashID, CNTV2FlashProgress &inFlashProgress=CNTV2FlashProgress::nullUpdater)
uint32_t _numSectorsFailSafe
NTV2Buffer _bitFileBuffer
virtual void SetVerbosity(bool verbose)
#define DECN(__x__, __n__)
uint32_t _failSafePadding
#define Hex0N(__x__, __n__)
bool ProgramKonaxMB(const std::string &sCustomFileName, const uint32_t addr, std::ostream &outMsgs)
void DetermineFlashTypeAndBlockNumberFromFileName(const std::string &bitFileName)
bool ProgramCustom(const std::string &sCustomFileName, const uint32_t addr, std::ostream &outMsgs)
#define NTV2EndianSwap32(__val__)
bool CreateSRecord(bool bChangeEndian)
uint32_t ReadBankSelect()
virtual bool GetRunningFirmwareDate(UWord &outYear, UWord &outMonth, UWord &outDay)
Reports the (local Pacific) build date of the currently-running firmware.
virtual uint32_t GetPartition(UByteSequence &patitionBuffer, uint16_t baseELARaddress, uint16_t &partitionOffset, bool nextPartition=false)
static CNTV2FlashProgress & nullUpdater
bool ReadMACAddresses(MacAddr &mac1, MacAddr &mac2)
bool MakeMACsFromSerial(const char *sSerialNumber, MacAddr *pMac1, MacAddr *pMac2)