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)
162 UWord runningYear(0), runningMonth(0), runningDay(0);
163 outIsRunning =
false;
169 outMsgs <<
"## WARNING: Failed to get running firmware date/time" << endl;
174 std::tm tm; ::memset(&tm, 0,
sizeof(tm));
175 tm.tm_year = int(runningYear) - 1900;
176 tm.tm_mon = int(runningMonth) - 1;
177 tm.tm_mday = int(runningDay);
180 std::time_t tRunning (std::mktime(&tm));
184 {outMsgs <<
"## WARNING: Failed to ReadHeader or ParseHeader" << endl;
return false;}
186 string installedBuildDate(
GetDate());
190 if (installedBuildDate.empty() || installedBuildDate.length() < 10 || installedBuildDate.at(4) !=
'/')
191 {outMsgs <<
"## WARNING: Bad installed firmware date '" << installedBuildDate <<
"'" << endl;
return false;}
194 tm.tm_year = int(
aja::stol(installedBuildDate.substr(0, 4))) - 1900;
195 tm.tm_mon = int(
aja::stol(installedBuildDate.substr(5, 2))) - 1;
196 tm.tm_mday = int(
aja::stol(installedBuildDate.substr(8, 2)));
199 std::time_t tInstalled (std::mktime(&tm));
202 ULWord secsApart (
ULWord(::difftime(tInstalled, tRunning)));
205 else if (secsApart <= 86400)
206 {outMsgs <<
"## WARNING: Installed firmware date is 1 day past running firmware date" << endl; outIsRunning =
true;}
219 uint32_t ledMask =
BIT(16)+
BIT(17);
220 uint32_t ledShift = 16;
227 bool knownChip =
false;
440 {outMsgs <<
"Invalid flash block ID " <<
DEC(blockID);
return false;}
444 stat(inBitfileName.c_str(), &fsinfo);
446 pFile = fopen(inBitfileName.c_str(),
"rb");
448 {outMsgs <<
"Cannot open bitfile '" << inBitfileName <<
"'";
return false;}
452 {outMsgs <<
"Allocate " <<
DEC(
_bitFileSize+512) <<
"-byte buffer failed";
return false;}
455 fseek(pFile, 0, SEEK_SET);
464 {outMsgs <<
"Device not recognized";
return false;}
471 if (bitFileName.find(
"_fs_") != string::npos)
480 const uint32_t dwordSizeCount (bitFileHeader.
GetByteCount() / 4);
481 for (uint32_t count(0); count < dwordSizeCount; count++, baseAddress += 4)
498 vector<uint8_t> mcsInfoData;
505 _mcsInfo.assign(mcsInfoData.begin(), mcsInfoData.end());
515 if (
_deviceID != 0x010220 || !IsIPDevice())
522 for (uint32_t count(0); count < dwordSizeCount; count++, baseAddress += 4)
528 if (mcsInfoPtr.
U32(
int(count)) == 0)
535 size_t ffPos(
_mcsInfo.find(
"\xFF\xFF"));
536 if (ffPos != string::npos)
544 return "Bitfile not open";
547 return "Device not open";
564 uint32_t twoFixtysixBlockSizeCount ((
_bitFileSize + 256) / 256);
565 uint32_t percentComplete(0);
568 for (uint32_t count(0); count < twoFixtysixBlockSizeCount; count++, baseAddress += 256, bitFilePtr += 64)
576 percentComplete = (count*100)/twoFixtysixBlockSizeCount;
580 cout <<
"Program status: " <<
DEC(percentComplete) <<
"% \r" << flush;
583 cout <<
"Program status: 100% " << endl;
589 return "Program Didn't Verify";
626 for ( uint32_t count=0; count < 64; count++ )
639 uint32_t deviceID = 0;
646 return (deviceID & 0xFFFFFF);
660 uint32_t percentComplete = 0;
666 uint32_t bankCount = 0;
667 for (uint32_t sectorCount = 0; sectorCount < numSectors; sectorCount++ )
684 percentComplete = (sectorCount*100)/numSectors;
687 cout <<
"Erase status: " <<
DEC(percentComplete) <<
"%\r" << flush;
691 cout <<
"Erase status: 100% " << endl;
722 uint32_t errorCount = 0;
726 uint32_t percentComplete(0), lastPercentComplete(999);
731 for (uint32_t count = 0; count < dwordSizeCount; )
743 uint32_t bitFileValue = *bitFilePtr;
744 if (flashValue != bitFileValue)
746 cerr <<
"Error " <<
DEC(count) <<
" E(" <<
HEX0N(bitFileValue,8) <<
"),R(" <<
HEX0N(flashValue,8) <<
")" << endl;
751 percentComplete = (count*100)/dwordSizeCount;
755 if (percentComplete != lastPercentComplete)
757 cout <<
"Program verify: " <<
DEC(percentComplete) <<
"%\r" << flush;
758 lastPercentComplete = percentComplete;
761 count += fullVerify ? 1 : 64;
762 baseAddress += fullVerify ? 4 : 256;
763 bitFilePtr += fullVerify ? 1 : 64;
771 cout <<
"Program verify failed: " <<
DEC(percentComplete) <<
"%" << endl;
775 cout <<
"Program verify: 100% " << endl;
786 {
KFPERR(
"Unable to resize target buffer (not alloc'd by SDK)");
return false;}
787 if (!outBuffer.
Allocate(numDWords * 4))
788 {
KFPERR(
"Failed to allocate " <<
DEC(numDWords*4) <<
"-byte target buffer");
return false;}
791 size_t lastPercent(0), percent(0);
806 for (uint32_t dword(0); dword < numDWords; )
827 outBuffer.
U32(
int(dword)) = flashValue;
831 percent = dword * 100 / numDWords;
832 if (percent != lastPercent)
835 lastPercent = percent;
836 if ((dword % 0x10000) == 0) cerr <<
xHEX0N(dword,8) <<
" of " <<
xHEX0N(numDWords,8) << endl;
859 if (!(regValue &
BIT(8)))
874 uint32_t dwordSizeCount = (numSectors*
_sectorSize)/4;
875 uint32_t percentComplete = 0;
878 for (uint32_t count = 0; count < dwordSizeCount; count++, baseAddress += 4)
885 if ( flashValue != 0xFFFFFFFF )
887 count = dwordSizeCount;
891 percentComplete = (count*100)/dwordSizeCount;
893 cout <<
"Erase verify: " <<
DEC(percentComplete) <<
"%\r" << flush;
896 cout <<
"Erase verify: 100% " << endl;
905 cout << pSRecord << endl;
910 uint32_t baseAddress = 0;
912 uint32_t partitionOffset = 0;
916 for ( uint32_t count = 0; count <
_flashSize; count+=32)
921 partitionOffset = count;
922 switch (partitionOffset)
932 uint32_t recordSize = 32;
942 uint32_t cc (recordSize + 5);
943 sprintf(&sRecord[2],
"%02x", cc);
946 uint32_t addr = baseAddress+partitionOffset;
947 UWord aa = ((addr >> 24) &0xff);
948 sprintf(&sRecord[4],
"%02x", aa);
951 aa = ((addr >> 16) & 0xff);
952 sprintf (&sRecord[6],
"%02x", aa);
955 aa = ((addr >> 8) & 0xff);
956 sprintf (&sRecord[8],
"%02x", aa);
960 sprintf (&sRecord[10],
"%02x", aa);
965 while(i < recordSize)
975 UWord dd = (flashValue & 0xff);
976 sprintf(&sRecord[index],
"%02x", dd);
979 dd = ((flashValue >> 8) & 0xff);
980 sprintf(&sRecord[index+2],
"%02x", dd);
983 dd = ((flashValue >> 16) & 0xff);
984 sprintf(&sRecord[index+4],
"%02x", dd);
987 dd = ((flashValue >> 24) & 0xff);
988 sprintf(&sRecord[index+6],
"%02x", dd);
995 checksum = ~checksum;
996 sprintf(&sRecord[index],
"%02x", checksum);
1010 uint32_t baseAddress = 0;
1012 uint32_t partitionOffset = 0;
1016 for (uint32_t count = 0; count <
_bankSize; count += 32)
1023 uint32_t recordSize = 32;
1033 sprintf(&sRecord[2],
"%02x", cc);
1036 uint32_t addr = baseAddress + partitionOffset;
1037 UWord aa = ((addr >> 24) & 0xff);
1038 sprintf(&sRecord[4],
"%02x", aa);
1041 aa = ((addr >> 16) & 0xff);
1042 sprintf(&sRecord[6],
"%02x", aa);
1045 aa = ((addr >> 8) & 0xff);
1046 sprintf(&sRecord[8],
"%02x", aa);
1050 sprintf(&sRecord[10],
"%02x", aa);
1055 while (i < recordSize)
1060 uint32_t flashValue;
1064 UWord dd = (flashValue & 0xff);
1065 sprintf(&sRecord[index],
"%02x", dd);
1068 dd = ((flashValue >> 8) & 0xff);
1069 sprintf(&sRecord[index + 2],
"%02x", dd);
1072 dd = ((flashValue >> 16) & 0xff);
1073 sprintf(&sRecord[index + 4],
"%02x", dd);
1076 dd = ((flashValue >> 24) & 0xff);
1077 sprintf(&sRecord[index + 6],
"%02x", dd);
1084 checksum = ~checksum;
1085 sprintf(&sRecord[index],
"%02x", checksum);
1100 int32_t recordSize = 16;
1101 UWord baseAddress = 0x0000;
1103 UByte recordType = 0x00;
1104 UByte byteCount = 0x10;
1106 uint32_t i2cVal = 0x02000050;
1108 for(int32_t x = 0; x < 16; x++)
1116 sprintf(&iRecord[1],
"%02x", byteCount);
1117 checksum += byteCount;
1119 UWord addr = baseAddress;
1120 UByte aa = ((addr >> 8) & 0xff);
1121 sprintf(&iRecord[3],
"%02x", aa);
1124 aa = ((addr) & 0xff);
1125 sprintf(&iRecord[5],
"%02x", aa);
1128 sprintf (&iRecord[7],
"%02x", recordType);
1138 uint32_t flashValue;
1141 UByte dd = ((flashValue >> 8) & 0xff);
1142 sprintf(&iRecord[index],
"%02x", dd);
1147 i2cVal += 0x00000100;
1150 baseAddress += 0x0010;
1151 checksum = (checksum ^ 0xFF)+1;
1152 sprintf(&iRecord[index],
"%02x", checksum);
1173 vector<uint8_t> macData;
1174 macData.push_back(mac1->
mac[3]);
1175 macData.push_back(mac1->
mac[2]);
1176 macData.push_back(mac1->
mac[1]);
1177 macData.push_back(mac1->
mac[0]);
1178 macData.push_back(0);
1179 macData.push_back(0);
1180 macData.push_back(mac1->
mac[5]);
1181 macData.push_back(mac1->
mac[4]);
1183 macData.push_back(mac2->
mac[3]);
1184 macData.push_back(mac2->
mac[2]);
1185 macData.push_back(mac2->
mac[1]);
1186 macData.push_back(mac2->
mac[0]);
1187 macData.push_back(0);
1188 macData.push_back(0);
1189 macData.push_back(mac2->
mac[5]);
1190 macData.push_back(mac2->
mac[4]);
1217 lo |= uint32_t((mac1->
mac[0]) << 24) & 0xff000000;
1218 lo |= uint32_t((mac1->
mac[1]) << 16) & 0x00ff0000;
1219 lo |= uint32_t((mac1->
mac[2]) << 8) & 0x0000ff00;
1220 lo |= uint32_t(mac1->
mac[3]) & 0x000000ff;
1223 hi |= uint32_t((mac1->
mac[4]) << 24) & 0xff000000;
1224 hi |= uint32_t((mac1->
mac[5]) << 16) & 0x00ff0000;
1227 lo2 |= uint32_t((mac2->
mac[0]) << 24) & 0xff000000;
1228 lo2 |= uint32_t((mac2->
mac[1]) << 16) & 0x00ff0000;
1229 lo2 |= uint32_t((mac2->
mac[2]) << 8) & 0x0000ff00;
1230 lo2 |= uint32_t(mac2->
mac[3]) & 0x000000ff;
1233 hi2 |= uint32_t((mac2->
mac[4]) << 24) & 0xff000000;
1234 hi2 |= uint32_t((mac2->
mac[5]) << 16) & 0x00ff0000;
1269 vector<uint8_t> macData;
1276 if (macData.size() < 16)
1279 mac1.
mac[0] = macData.at(3);
1280 mac1.
mac[1] = macData.at(2);
1281 mac1.
mac[2] = macData.at(1);
1282 mac1.
mac[3] = macData.at(0);
1283 mac1.
mac[4] = macData.at(7);
1284 mac1.
mac[5] = macData.at(6);
1286 mac2.
mac[0] = macData.at(8+3);
1287 mac2.
mac[1] = macData.at(8+2);
1288 mac2.
mac[2] = macData.at(8+1);
1289 mac2.
mac[3] = macData.at(8+0);
1290 mac2.
mac[4] = macData.at(8+7);
1291 mac2.
mac[5] = macData.at(8+6);
1333 mac1.
mac[0] = (lo & 0xff000000) >> 24;
1334 mac1.
mac[1] = (lo & 0x00ff0000) >> 16;
1335 mac1.
mac[2] = (lo & 0x0000ff00) >> 8;
1336 mac1.
mac[3] = lo & 0x000000ff;
1337 mac1.
mac[4] = (hi & 0xff000000) >> 24;
1338 mac1.
mac[5] = (hi & 0x00ff0000) >> 16;
1340 mac2.
mac[0] = (lo2 & 0xff000000) >> 24;
1341 mac2.
mac[1] = (lo2 & 0x00ff0000) >> 16;
1342 mac2.
mac[2] = (lo2 & 0x0000ff00) >> 8;
1343 mac2.
mac[3] = lo2 & 0x000000ff;
1344 mac2.
mac[4] = (hi2 & 0xff000000) >> 24;
1345 mac2.
mac[5] = (hi2 & 0x00ff0000) >> 16;
1358 vector<uint8_t> licenseData;
1359 for (string::const_iterator it(licenseString.begin()); it != licenseString.end(); ++it)
1360 licenseData.push_back(uint8_t(*it));
1361 licenseData.push_back(0);
1367 if (
_spiFlash->
Write(offset, licenseData, uint32_t(licenseData.size())))
1384 size_t len (licenseString.size());
1385 size_t words ((len/4) + 2);
1389 strcat(data8,licenseString.c_str());
1393 for (
size_t i(0); i < words; i++)
1417 const uint32_t maxSize = 100;
1424 vector<uint8_t> licenseData;
1432 if (licenseData.size() < 4)
1434 else if (licenseData[0] == 0xff && licenseData[1] == 0xff && licenseData[2] == 0xff && licenseData[3] == 0xff)
1438 serialString.assign(licenseData.begin(), licenseData.end());
1441 size_t found = serialString.find(
'\0');
1442 if (found != string::npos)
1443 serialString.resize(found);
1455 memset (license,0x0,
sizeof(license));
1460 bool terminated =
false;
1462 for(uint32_t i = 0; i < maxSize; i++)
1468 if (license[i] == 0xffffffff)
1473 if (license[i] == 0)
1484 res =
reinterpret_cast<char*
>(license);
1509 uint32_t bankNumber = 0;
1516 return bankNumber&0xf;
1522 cout <<
"Parsing MCS File" << endl;
1529 {cerr <<
"MCS bitfile not open" << endl;
return false;}
1531 {cerr <<
"Device not open" << endl;
return false;}
1536 {cerr <<
"MCS file not ready" << endl;
return false;}
1541 vector<uint8_t> fpgaData;
1542 uint16_t fpgaPartitionOffset = 0;
1554 {cerr <<
"Can't parse header" << endl << msgs.str() << endl;
return false;}
1562 bool hasErasedSOCs =
false;
1563 uint16_t linearOffsetToBankOffset = 0x0000;
1564 uint16_t basePartitionAddress = linearOffsetToBankOffset;
1565 bool bPartitionValid =
true;
1566 uint32_t partitionCount = 0;
1567 while (bPartitionValid)
1573 uint16_t partitionOffset = 0;
1576 if (basePartitionAddress < 0x0100)
1579 linearOffsetToBankOffset = 0x0000;
1582 cout <<
"Erase Main Bitfile Bank" << endl;
1587 else if (basePartitionAddress >= 0x0100 && basePartitionAddress < 0x0200)
1590 linearOffsetToBankOffset = 0x0100;
1593 cout <<
"Erase Package Info Block" << endl;
1598 else if (basePartitionAddress >= 0x0200 && basePartitionAddress < 0x0400)
1603 cout <<
"Erase SOC Bank 1" << endl;
1607 cout <<
"Erase SOC Bank 2" << endl;
1610 hasErasedSOCs =
true;
1612 if (basePartitionAddress >= 0x0200 && basePartitionAddress < 0x0300)
1615 linearOffsetToBankOffset = 0x0200;
1621 linearOffsetToBankOffset = 0x0300;
1630 uint16_t baseOffset = basePartitionAddress - linearOffsetToBankOffset;
1631 uint32_t programOffset = uint32_t(baseOffset) << 16 | partitionOffset;
1635 bPartitionValid =
false;
1644 uint32_t bufferIndex = 0;
1645 uint32_t blockSize = 512;
1646 uint32_t dwordsPerBlock = blockSize / 4;
1647 uint32_t totalBlockCount ((uint32_t(
_partitionBuffer.size()) + blockSize) / blockSize);
1648 uint32_t percentComplete = 0;
1651 for (uint32_t blockCount = 0; blockCount < totalBlockCount; blockCount++)
1654 if (baseAddress == 0x01000000 && blockCount > 0 && blockID ==
SOC1_FLASHBLOCK)
1661 uint32_t remainderBytes =
static_cast<uint32_t
>(
_partitionBuffer.size() - bufferIndex);
1665 for (uint32_t dwordCount = 0; dwordCount < dwordsPerBlock; dwordCount++)
1667 uint32_t partitionValue = 0xFFFFFFFF;
1668 if (remainderBytes >= 4)
1675 remainderBytes -= 4;
1679 switch (remainderBytes)
1682 partitionValue = 0xff;
1688 partitionValue = 0xffff;
1693 partitionValue = 0xffffff;
1709 baseAddress += blockSize;
1711 percentComplete = (blockCount * 100) / totalBlockCount;
1713 cout <<
"Partition " <<
DEC(partitionCount) <<
" program status: " <<
DEC(percentComplete) <<
"%\r" << flush;
1716 cout <<
"Partition " <<
DEC(partitionCount) <<
" program status: 100% " << endl;
1740 cerr <<
"Verify Error" << endl;
1749 bPartitionValid =
false;
1776 {cerr <<
"MCS bitfile not open" << endl;
return false;}
1781 {cerr <<
"Device not open" << endl;
return false;}
1783 {cerr <<
"MCS bitfile not ready" << endl;
return false;}
1785 vector<uint8_t> ubootData;
1786 vector<uint8_t> imageData;
1787 vector<uint8_t> mcsInfoData;
1788 uint16_t ubootPartitionOffset = 0;
1789 uint16_t imagePartitionOffset = 0;
1790 uint16_t mcsInfoPartitionOffset = 0;
1792 if (ubootData.empty())
1793 {cerr <<
"Could not find uboot data in MCS file" << endl;
return false;}
1796 if (imageData.empty())
1797 {cerr <<
"Could not find kernel data in MCS file" << endl;
return false;}
1800 if (mcsInfoData.empty())
1801 {cerr <<
"Could not find mcs info in MCS file" << endl;
return false;}
1807 uint32_t ubootSize = uint32_t(ubootData.size());
1808 uint32_t imageSize = uint32_t(imageData.size());
1809 uint32_t mcsInfoSize = uint32_t(mcsInfoData.size());
1845 {cerr <<
"Device not open" << endl;
return false;}
1847 cout <<
"Erase SOC Bank 1" << endl;
1850 cout <<
"Erase SOC Bank 2" << endl;
1856 uint16_t partition32M = 0x0200;
1857 uint16_t basePartitionAddress = partition32M;
1858 bool bPartitionValid =
true;
1859 uint32_t partitionCount = 0;
1860 while (bPartitionValid)
1862 uint16_t partitionOffset = 0;
1864 uint16_t baseOffset = basePartitionAddress - partition32M;
1865 uint32_t programOffset = uint32_t(baseOffset) << 16 | partitionOffset;
1868 if (programOffset >= 0x01000000)
1876 uint32_t bufferIndex = 0;
1877 uint32_t blockSize = 512;
1878 uint32_t dwordsPerBlock = blockSize / 4;
1879 uint32_t totalBlockCount =
static_cast<uint32_t
>((
_partitionBuffer.size() + blockSize) / blockSize);
1880 uint32_t percentComplete = 0;
1881 for (uint32_t blockCount = 0; blockCount < totalBlockCount; blockCount++)
1883 if (baseAddress == 0x01000000 && blockCount > 0)
1888 uint32_t remainderBytes =
static_cast<uint32_t
>(
_partitionBuffer.size() - bufferIndex);
1892 for (uint32_t dwordCount = 0; dwordCount < dwordsPerBlock; dwordCount++)
1894 uint32_t partitionValue = 0xFFFFFFFF;
1895 if (remainderBytes >= 4)
1902 remainderBytes -= 4;
1906 switch (remainderBytes)
1909 partitionValue = 0xff;
1915 partitionValue = 0xffff;
1920 partitionValue = 0xffffff;
1936 baseAddress += blockSize;
1938 percentComplete = (blockCount * 100) / totalBlockCount;
1940 cout <<
"Partition " <<
DEC(partitionCount+2) <<
" program status: " <<
DEC(percentComplete) <<
"%\r" << flush;
1943 cout <<
"Partition " <<
DEC(partitionCount+2) <<
" program status: 100% " << endl;
1948 cerr <<
"Verify failed" << endl;
1956 bPartitionValid =
false;
1977 static bool getFileSize (
const string & fileName,
size_t & outSizeBytes)
1980 ifstream ifs(fileName.c_str(), ios::binary | ios::in);
1983 if (!ifs.seekg (0, ios::end))
1985 ifstream::pos_type curOffset(ifs.tellg());
1986 if (
int(curOffset) == -1)
1988 outSizeBytes = size_t(curOffset);
1995 {outMsgs <<
"Device not open" << endl;
return false;}
1999 vector<uint8_t> writeData;
2003 {outMsgs <<
"getFileSize failed for '" << sCustomFileName <<
"'" << endl;
return false;}
2004 if (sz > maxFlashSize)
2005 {outMsgs <<
"File size " <<
DEC(sz) <<
" exceeds max flash size " <<
DEC(maxFlashSize) << endl;
return false;}
2007 ifstream ifs(sCustomFileName.c_str(), ios::binary | ios::in);
2009 {outMsgs <<
"Unable to open file '" << sCustomFileName <<
"'" << endl;
return false;}
2011 writeData.resize(sz);
2012 ifs.read(
reinterpret_cast<char*
>(&writeData[0]), streamsize(sz));
2014 {outMsgs <<
"Error reading data from file '" << sCustomFileName <<
"'" << endl;
return false;}
2017 uint32_t writeSize = uint32_t(writeData.size());
2020 {outMsgs <<
"Error erasing sectors, addr=" <<
xHEX0N(addr,8) <<
" length=" <<
DEC(writeSize) << endl;
return false;}
2025 bool result =
true, verify =
true;
2034 static const size_t MAX_CUSTOM_FILE_SIZE (8<<20);
2035 NTV2Buffer customFileBuffer(MAX_CUSTOM_FILE_SIZE);
2036 size_t customSize(0), sz(0);
2040 {outMsgs <<
"Custom write spans banks -- unsupported";
return false;}
2042 {outMsgs <<
"Write not on sector boundary -- unsupported";
return false;}
2044 {outMsgs <<
"Error getting file size for '" << sCustomFileName <<
"'";
return false;}
2045 if (sz > MAX_CUSTOM_FILE_SIZE)
2046 {outMsgs <<
"File size " <<
DEC(sz) <<
" exceeds max supported size " <<
DEC(MAX_CUSTOM_FILE_SIZE);
return false;}
2048 ifstream ifs(sCustomFileName.c_str(), ios::binary | ios::in);
2050 {outMsgs <<
"Unable to open file '" << sCustomFileName <<
"'" << endl;
return false;}
2052 customSize = size_t(ifs.readsome(customFileBuffer, streamsize(customFileBuffer.
GetByteCount())));
2054 {outMsgs <<
"No data read from custom file '" << sCustomFileName <<
"'" << endl;
return false;}
2066 for (uint32_t i(0); i < customSectors; i++)
2069 cout <<
"Erasing sectors - " <<
DECN(i,3) <<
" of " <<
DECN(customSectors,3) <<
"\r" << flush;
2076 uint32_t blockSize (512);
2077 uint32_t dwordsPerBlock (blockSize / 4);
2078 uint32_t totalBlockCount ((uint32_t(customSize) + blockSize - 1) / blockSize);
2079 uint32_t percentComplete (0);
2080 uint32_t baseAddress (offset);
2081 size_t remainderBytes (customSize);
2082 uint32_t bufferIndex (0);
2083 for (uint32_t blockCount(0); blockCount < totalBlockCount; blockCount++)
2088 for (uint32_t dwordCount(0); dwordCount < dwordsPerBlock; dwordCount++)
2090 uint32_t partitionValue = 0xFFFFFFFF;
2091 if (remainderBytes >= 4)
2098 remainderBytes -= 4;
2100 else switch (remainderBytes)
2103 partitionValue = 0xff;
2110 partitionValue = 0xffff;
2116 partitionValue = 0xffffff;
2130 baseAddress += blockSize;
2132 percentComplete = (blockCount * 100) / totalBlockCount;
2134 cout <<
"Program status: " <<
DEC(percentComplete) <<
"% (" <<
DECN(blockCount,4) <<
" of " <<
DECN(totalBlockCount,4) <<
" blocks)\r" << flush;
2203 bool getnext =
false;
2204 if (address != 0x0000 && address != 0x0200)
2215 uint32_t errorCount = 0;
2216 uint32_t baseAddress = flashBlockOffset;
2218 uint32_t dwordsPerPartition =
_bankSize / 4;
2219 uint32_t percentComplete = 0;
2220 uint32_t bufferIndex = 0;
2222 for (uint32_t dwordCount = 0; dwordCount < dwordsPerPartition; dwordCount += 100)
2228 uint32_t flashValue;
2230 uint32_t partitionValue = uint32_t(
_partitionBuffer[bufferIndex + 0]) << 24
2238 if (flashValue != partitionValue)
2240 cerr <<
"Error " <<
DEC(dwordCount) <<
" E(" <<
xHEX0N(partitionValue,8) <<
"),R(" <<
xHEX0N(flashValue,8) <<
")" << endl;
2246 percentComplete = (dwordCount * 100) / dwordsPerPartition;
2248 cout <<
"Program verify: " <<
DEC(percentComplete) <<
"%\r" << flush;
2254 cerr <<
"Program verify failed: " <<
DEC(percentComplete) <<
"%" << endl;
2258 cout <<
"Program verify: 100% " << endl;
2264 #define WORDS_PER_LINE 4
2271 memset(line, 0, 1024);
2272 char * pLine = &line[0];
2273 pLine += sprintf(pLine,
"%08x: ", uint32_t((bank *
_bankSize) + offset));
2275 int32_t lineCount = 0;
2276 for (uint32_t i = 0; i < count; i++, offset += 4)
2281 uint32_t flashValue;
2284 pLine += sprintf(pLine,
"%08x ", uint32_t(flashValue));
2288 cout << line << endl;
2289 memset(line, 0, 1024);
2291 pLine += sprintf(pLine,
"%08x: ", uint32_t((bank *
_bankSize) + offset + 4));
2295 if (!
_bQuiet && lineCount != 0)
2296 cout << line << endl;
2303 uint32_t baseAddress = 0;
2305 cout <<
"Erasing ROM" << endl;
2310 uint32_t* bitFilePtr =
reinterpret_cast<uint32_t*
>(dataBuffer.data());
2311 uint32_t twoFixtysixBlockSizeCount = uint32_t((dataBuffer.size()+256)/256);
2312 uint32_t percentComplete = 0;
2315 for ( uint32_t count = 0; count < twoFixtysixBlockSizeCount; count++, baseAddress += 256, bitFilePtr += 64 )
2330 percentComplete = (count*100)/twoFixtysixBlockSizeCount;
2333 if(!
_bQuiet && (count%100 == 0))
2334 cout <<
"Program status: " <<
DEC(percentComplete) <<
"%\r" << flush;
2337 cout <<
"Program status: 100% " << endl;
2362 if(mac1.
mac[1] != 0x0C || mac2.
mac[1] != 0x0c)
2365 cout <<
"Reprogramming the Mac Addresses!" << endl;
2366 string serialString;
2378 if (strstr(sSerialNumber,
"demo") == sSerialNumber)
2381 if (sscanf(sSerialNumber + 4,
"%d", &demoNum) != 1)
2383 if ((demoNum < 1) || (demoNum > 128))
2384 {cerr <<
"WARNING: Outside serial numbers demo0001 to demo0128" << endl;
return false;}
2385 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2386 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2387 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2388 pMac2->
mac[3] = pMac1->
mac[3] = 0x88;
2389 pMac2->
mac[4] = pMac1->
mac[4] = 0x12;
2390 pMac1->
mac[5] = uint8_t((demoNum - 1) * 2);
2391 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2394 else if (strstr(sSerialNumber,
"1IP") == sSerialNumber)
2401 if (sscanf(sSerialNumber + 4,
"%d", &serNum) != 1)
2403 if ((serNum < 50) || (serNum > 8241))
2404 {cerr <<
"WARNING: Outside serial numbers 1IP00050 to 1IP08241" << endl;
return false;}
2406 int mac16LSBs = (0xA000) + (serNum - 50) * 2;
2408 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2409 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2410 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2411 pMac2->
mac[3] = pMac1->
mac[3] = 0x42;
2412 pMac2->
mac[4] = pMac1->
mac[4] = uint8_t(mac16LSBs >> 8);
2413 pMac2->
mac[5] = pMac1->
mac[5] = mac16LSBs & 0x0ff;
2416 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2419 else if (strstr(sSerialNumber,
"ENG") == sSerialNumber)
2426 if (sscanf(sSerialNumber + 5,
"%d", &serNum) != 1)
2430 {cerr <<
"WARNING: Outside serial numbers ENG00000 to ENG00127" << endl;
return false;}
2432 int mac16LSBs = (0x1B00) + (serNum * 2);
2434 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2435 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2436 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2437 pMac2->
mac[3] = pMac1->
mac[3] = 0x88;
2438 pMac2->
mac[4] = pMac1->
mac[4] = uint8_t(mac16LSBs >> 8);
2439 pMac2->
mac[5] = pMac1->
mac[5] = mac16LSBs & 0xff;
2442 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2445 else if (strstr(sSerialNumber,
"6XT") == sSerialNumber)
2453 if (sscanf(sSerialNumber + 4,
"%d", &serNum) != 1)
2456 if ((serNum < 250) || (serNum > 8441))
2457 {cerr <<
"WARNING: Outside serial numbers range 250 to 8441" << endl;
return false;}
2462 if (strstr(sSerialNumber,
"6XT0") == sSerialNumber)
2464 mac24LSBs = (0x48A000) + ((serNum - 250) * 2);
2466 else if (strstr(sSerialNumber,
"6XT2") == sSerialNumber)
2468 mac24LSBs = (0x48E000) + ((serNum - 250) * 2);
2470 else if (strstr(sSerialNumber,
"6XT1") == sSerialNumber)
2472 mac24LSBs = (0x4B2000) + ((serNum - 250) * 2);
2474 else if (strstr(sSerialNumber,
"6XT3") == sSerialNumber)
2476 mac24LSBs = (0x4B6000) + ((serNum - 250) * 2);
2483 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2484 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2485 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2486 pMac2->
mac[3] = pMac1->
mac[3] = (mac24LSBs & 0xFF0000) >> 16;
2487 pMac2->
mac[4] = pMac1->
mac[4] = (mac24LSBs & 0x00FF00) >> 8;
2488 pMac2->
mac[5] = pMac1->
mac[5] = (mac24LSBs & 0x0000FF) >> 0;
2491 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2495 cerr <<
"Unrecognized or unspecified serial number '" << sSerialNumber <<
"'" << endl;
2502 #pragma warning(default: 4800)