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());
512 if (
_deviceID != 0x010220 || !IsIPDevice())
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;
1261 vector<uint8_t> macData;
1268 if (macData.size() < 16)
1271 mac1.
mac[0] = macData.at(3);
1272 mac1.
mac[1] = macData.at(2);
1273 mac1.
mac[2] = macData.at(1);
1274 mac1.
mac[3] = macData.at(0);
1275 mac1.
mac[4] = macData.at(7);
1276 mac1.
mac[5] = macData.at(6);
1278 mac2.
mac[0] = macData.at(8+3);
1279 mac2.
mac[1] = macData.at(8+2);
1280 mac2.
mac[2] = macData.at(8+1);
1281 mac2.
mac[3] = macData.at(8+0);
1282 mac2.
mac[4] = macData.at(8+7);
1283 mac2.
mac[5] = macData.at(8+6);
1325 mac1.
mac[0] = (lo & 0xff000000) >> 24;
1326 mac1.
mac[1] = (lo & 0x00ff0000) >> 16;
1327 mac1.
mac[2] = (lo & 0x0000ff00) >> 8;
1328 mac1.
mac[3] = lo & 0x000000ff;
1329 mac1.
mac[4] = (hi & 0xff000000) >> 24;
1330 mac1.
mac[5] = (hi & 0x00ff0000) >> 16;
1332 mac2.
mac[0] = (lo2 & 0xff000000) >> 24;
1333 mac2.
mac[1] = (lo2 & 0x00ff0000) >> 16;
1334 mac2.
mac[2] = (lo2 & 0x0000ff00) >> 8;
1335 mac2.
mac[3] = lo2 & 0x000000ff;
1336 mac2.
mac[4] = (hi2 & 0xff000000) >> 24;
1337 mac2.
mac[5] = (hi2 & 0x00ff0000) >> 16;
1350 vector<uint8_t> licenseData;
1351 for (string::const_iterator it(licenseString.begin()); it != licenseString.end(); ++it)
1352 licenseData.push_back(uint8_t(*it));
1353 licenseData.push_back(0);
1359 if (
_spiFlash->
Write(offset, licenseData, uint32_t(licenseData.size())))
1376 size_t len (licenseString.size());
1377 size_t words ((len/4) + 2);
1381 strcat(data8,licenseString.c_str());
1385 for (
size_t i(0); i < words; i++)
1409 const uint32_t maxSize = 100;
1416 vector<uint8_t> licenseData;
1424 if (licenseData.size() < 4)
1426 else if (licenseData[0] == 0xff && licenseData[1] == 0xff && licenseData[2] == 0xff && licenseData[3] == 0xff)
1430 serialString.assign(licenseData.begin(), licenseData.end());
1433 size_t found = serialString.find(
'\0');
1434 if (found != string::npos)
1435 serialString.resize(found);
1447 memset (license,0x0,
sizeof(license));
1452 bool terminated =
false;
1454 for(uint32_t i = 0; i < maxSize; i++)
1460 if (license[i] == 0xffffffff)
1465 if (license[i] == 0)
1476 res =
reinterpret_cast<char*
>(license);
1488 if (
int(bankNumber) >
int(
BANK_3))
1503 uint32_t bankNumber = 0;
1510 return bankNumber&0xf;
1516 cout <<
"Parsing MCS File" << endl;
1523 {cerr <<
"MCS bitfile not open" << endl;
return false;}
1525 {cerr <<
"Device not open" << endl;
return false;}
1530 {cerr <<
"MCS file not ready" << endl;
return false;}
1535 vector<uint8_t> fpgaData;
1536 uint16_t fpgaPartitionOffset = 0;
1548 {cerr <<
"Can't parse header" << endl << msgs.str() << endl;
return false;}
1556 bool hasErasedSOCs =
false;
1557 uint16_t linearOffsetToBankOffset = 0x0000;
1558 uint16_t basePartitionAddress = linearOffsetToBankOffset;
1559 bool bPartitionValid =
true;
1560 uint32_t partitionCount = 0;
1561 while (bPartitionValid)
1567 uint16_t partitionOffset = 0;
1570 if (basePartitionAddress < 0x0100)
1573 linearOffsetToBankOffset = 0x0000;
1576 cout <<
"Erase Main Bitfile Bank" << endl;
1581 else if (basePartitionAddress >= 0x0100 && basePartitionAddress < 0x0200)
1584 linearOffsetToBankOffset = 0x0100;
1587 cout <<
"Erase Package Info Block" << endl;
1592 else if (basePartitionAddress >= 0x0200 && basePartitionAddress < 0x0400)
1597 cout <<
"Erase SOC Bank 1" << endl;
1601 cout <<
"Erase SOC Bank 2" << endl;
1604 hasErasedSOCs =
true;
1606 if (basePartitionAddress >= 0x0200 && basePartitionAddress < 0x0300)
1609 linearOffsetToBankOffset = 0x0200;
1615 linearOffsetToBankOffset = 0x0300;
1624 uint16_t baseOffset = basePartitionAddress - linearOffsetToBankOffset;
1625 uint32_t programOffset = uint32_t(baseOffset) << 16 | partitionOffset;
1629 bPartitionValid =
false;
1638 uint32_t bufferIndex = 0;
1639 uint32_t blockSize = 512;
1640 uint32_t dwordsPerBlock = blockSize / 4;
1641 uint32_t totalBlockCount ((uint32_t(
_partitionBuffer.size()) + blockSize) / blockSize);
1642 uint32_t percentComplete = 0;
1645 for (uint32_t blockCount = 0; blockCount < totalBlockCount; blockCount++)
1648 if (baseAddress == 0x01000000 && blockCount > 0 && blockID ==
SOC1_FLASHBLOCK)
1655 uint32_t remainderBytes =
static_cast<uint32_t
>(
_partitionBuffer.size() - bufferIndex);
1659 for (uint32_t dwordCount = 0; dwordCount < dwordsPerBlock; dwordCount++)
1661 uint32_t partitionValue = 0xFFFFFFFF;
1662 if (remainderBytes >= 4)
1669 remainderBytes -= 4;
1673 switch (remainderBytes)
1676 partitionValue = 0xff;
1682 partitionValue = 0xffff;
1687 partitionValue = 0xffffff;
1703 baseAddress += blockSize;
1705 percentComplete = (blockCount * 100) / totalBlockCount;
1707 cout <<
"Partition " <<
DEC(partitionCount) <<
" program status: " <<
DEC(percentComplete) <<
"%\r" << flush;
1710 cout <<
"Partition " <<
DEC(partitionCount) <<
" program status: 100% " << endl;
1734 cerr <<
"Verify Error" << endl;
1743 bPartitionValid =
false;
1770 {cerr <<
"MCS bitfile not open" << endl;
return false;}
1775 {cerr <<
"Device not open" << endl;
return false;}
1777 {cerr <<
"MCS bitfile not ready" << endl;
return false;}
1779 vector<uint8_t> ubootData;
1780 vector<uint8_t> imageData;
1781 vector<uint8_t> mcsInfoData;
1782 uint16_t ubootPartitionOffset = 0;
1783 uint16_t imagePartitionOffset = 0;
1784 uint16_t mcsInfoPartitionOffset = 0;
1786 if (ubootData.empty())
1787 {cerr <<
"Could not find uboot data in MCS file" << endl;
return false;}
1790 if (imageData.empty())
1791 {cerr <<
"Could not find kernel data in MCS file" << endl;
return false;}
1794 if (mcsInfoData.empty())
1795 {cerr <<
"Could not find mcs info in MCS file" << endl;
return false;}
1801 uint32_t ubootSize = uint32_t(ubootData.size());
1802 uint32_t imageSize = uint32_t(imageData.size());
1803 uint32_t mcsInfoSize = uint32_t(mcsInfoData.size());
1839 {cerr <<
"Device not open" << endl;
return false;}
1841 cout <<
"Erase SOC Bank 1" << endl;
1844 cout <<
"Erase SOC Bank 2" << endl;
1850 uint16_t partition32M = 0x0200;
1851 uint16_t basePartitionAddress = partition32M;
1852 bool bPartitionValid =
true;
1853 uint32_t partitionCount = 0;
1854 while (bPartitionValid)
1856 uint16_t partitionOffset = 0;
1858 uint16_t baseOffset = basePartitionAddress - partition32M;
1859 uint32_t programOffset = uint32_t(baseOffset) << 16 | partitionOffset;
1862 if (programOffset >= 0x01000000)
1870 uint32_t bufferIndex = 0;
1871 uint32_t blockSize = 512;
1872 uint32_t dwordsPerBlock = blockSize / 4;
1873 uint32_t totalBlockCount =
static_cast<uint32_t
>((
_partitionBuffer.size() + blockSize) / blockSize);
1874 uint32_t percentComplete = 0;
1875 for (uint32_t blockCount = 0; blockCount < totalBlockCount; blockCount++)
1877 if (baseAddress == 0x01000000 && blockCount > 0)
1882 uint32_t remainderBytes =
static_cast<uint32_t
>(
_partitionBuffer.size() - bufferIndex);
1886 for (uint32_t dwordCount = 0; dwordCount < dwordsPerBlock; dwordCount++)
1888 uint32_t partitionValue = 0xFFFFFFFF;
1889 if (remainderBytes >= 4)
1896 remainderBytes -= 4;
1900 switch (remainderBytes)
1903 partitionValue = 0xff;
1909 partitionValue = 0xffff;
1914 partitionValue = 0xffffff;
1930 baseAddress += blockSize;
1932 percentComplete = (blockCount * 100) / totalBlockCount;
1934 cout <<
"Partition " <<
DEC(partitionCount+2) <<
" program status: " <<
DEC(percentComplete) <<
"%\r" << flush;
1937 cout <<
"Partition " <<
DEC(partitionCount+2) <<
" program status: 100% " << endl;
1942 cerr <<
"Verify failed" << endl;
1950 bPartitionValid =
false;
1971 static bool getFileSize (
const string & fileName,
size_t & outSizeBytes)
1974 ifstream ifs(fileName.c_str(), ios::binary | ios::in);
1979 ifstream::pos_type curOffset(ifs.tellg());
1980 if (
int(curOffset) == -1)
1982 outSizeBytes = size_t(curOffset);
1989 {outMsgs <<
"Device not open" << endl;
return false;}
1993 vector<uint8_t> writeData;
1997 {outMsgs <<
"getFileSize failed for '" << sCustomFileName <<
"'" << endl;
return false;}
1998 if (sz > maxFlashSize)
1999 {outMsgs <<
"File size " <<
DEC(sz) <<
" exceeds max flash size " <<
DEC(maxFlashSize) << endl;
return false;}
2001 ifstream ifs(sCustomFileName.c_str(), ios::binary | ios::in);
2003 {outMsgs <<
"Unable to open file '" << sCustomFileName <<
"'" << endl;
return false;}
2005 writeData.resize(sz);
2006 ifs.read(
reinterpret_cast<char*
>(&writeData[0]), streamsize(sz));
2008 {outMsgs <<
"Error reading data from file '" << sCustomFileName <<
"'" << endl;
return false;}
2011 uint32_t writeSize = uint32_t(writeData.size());
2014 {outMsgs <<
"Error erasing sectors, addr=" <<
xHEX0N(addr,8) <<
" length=" <<
DEC(writeSize) << endl;
return false;}
2019 bool result =
true, verify =
true;
2028 static const size_t MAX_CUSTOM_FILE_SIZE (8<<20);
2029 NTV2Buffer customFileBuffer(MAX_CUSTOM_FILE_SIZE);
2030 size_t customSize(0), sz(0);
2034 {outMsgs <<
"Custom write spans banks -- unsupported";
return false;}
2036 {outMsgs <<
"Write not on sector boundary -- unsupported";
return false;}
2038 {outMsgs <<
"Error getting file size for '" << sCustomFileName <<
"'";
return false;}
2039 if (sz > MAX_CUSTOM_FILE_SIZE)
2040 {outMsgs <<
"File size " <<
DEC(sz) <<
" exceeds max supported size " <<
DEC(MAX_CUSTOM_FILE_SIZE);
return false;}
2042 ifstream ifs(sCustomFileName.c_str(), ios::binary | ios::in);
2044 {outMsgs <<
"Unable to open file '" << sCustomFileName <<
"'" << endl;
return false;}
2046 customSize = size_t(ifs.readsome(customFileBuffer, streamsize(customFileBuffer.
GetByteCount())));
2048 {outMsgs <<
"No data read from custom file '" << sCustomFileName <<
"'" << endl;
return false;}
2060 for (uint32_t i(0); i < customSectors; i++)
2063 cout <<
"Erasing sectors - " <<
DECN(i,3) <<
" of " <<
DECN(customSectors,3) <<
"\r" << flush;
2070 uint32_t blockSize (512);
2071 uint32_t dwordsPerBlock (blockSize / 4);
2072 uint32_t totalBlockCount ((uint32_t(customSize) + blockSize - 1) / blockSize);
2073 uint32_t percentComplete (0);
2074 uint32_t baseAddress (offset);
2075 size_t remainderBytes (customSize);
2076 uint32_t bufferIndex (0);
2077 for (uint32_t blockCount(0); blockCount < totalBlockCount; blockCount++)
2082 for (uint32_t dwordCount(0); dwordCount < dwordsPerBlock; dwordCount++)
2084 uint32_t partitionValue = 0xFFFFFFFF;
2085 if (remainderBytes >= 4)
2092 remainderBytes -= 4;
2094 else switch (remainderBytes)
2097 partitionValue = 0xff;
2104 partitionValue = 0xffff;
2110 partitionValue = 0xffffff;
2124 baseAddress += blockSize;
2126 percentComplete = (blockCount * 100) / totalBlockCount;
2128 cout <<
"Program status: " <<
DEC(percentComplete) <<
"% (" <<
DECN(blockCount,4) <<
" of " <<
DECN(totalBlockCount,4) <<
" blocks)\r" << flush;
2197 bool getnext =
false;
2198 if (address != 0x0000 && address != 0x0200)
2209 uint32_t errorCount = 0;
2210 uint32_t baseAddress = flashBlockOffset;
2212 uint32_t dwordsPerPartition =
_bankSize / 4;
2213 uint32_t percentComplete = 0;
2214 uint32_t bufferIndex = 0;
2216 for (uint32_t dwordCount = 0; dwordCount < dwordsPerPartition; dwordCount += 100)
2222 uint32_t flashValue;
2224 uint32_t partitionValue = uint32_t(
_partitionBuffer[bufferIndex + 0]) << 24
2232 if (flashValue != partitionValue)
2234 cerr <<
"Error " <<
DEC(dwordCount) <<
" E(" <<
xHEX0N(partitionValue,8) <<
"),R(" <<
xHEX0N(flashValue,8) <<
")" << endl;
2240 percentComplete = (dwordCount * 100) / dwordsPerPartition;
2242 cout <<
"Program verify: " <<
DEC(percentComplete) <<
"%\r" << flush;
2248 cerr <<
"Program verify failed: " <<
DEC(percentComplete) <<
"%" << endl;
2252 cout <<
"Program verify: 100% " << endl;
2258 const uint32_t WORDS_PER_LINE(4);
2259 uint32_t addr(address), bank(999), offset(addr %
_bankSize);
2262 uint32_t lineCount(0);
2263 for (uint32_t words(0); words < wordCount; words++, offset += 4, addr += 4)
2266 if (newBank != bank)
2278 uint32_t flashValue;
2281 cout <<
Hex0N(flashValue,8) <<
" ";
2282 if (++lineCount == WORDS_PER_LINE)
2298 uint32_t baseAddress = 0;
2300 cout <<
"Erasing ROM" << endl;
2305 uint32_t* bitFilePtr =
reinterpret_cast<uint32_t*
>(dataBuffer.data());
2306 uint32_t twoFixtysixBlockSizeCount = uint32_t((dataBuffer.size()+256)/256);
2307 uint32_t percentComplete = 0;
2310 for ( uint32_t count = 0; count < twoFixtysixBlockSizeCount; count++, baseAddress += 256, bitFilePtr += 64 )
2325 percentComplete = (count*100)/twoFixtysixBlockSizeCount;
2328 if(!
_bQuiet && (count%100 == 0))
2329 cout <<
"Program status: " <<
DEC(percentComplete) <<
"%\r" << flush;
2332 cout <<
"Program status: 100% " << endl;
2357 if(mac1.
mac[1] != 0x0C || mac2.
mac[1] != 0x0c)
2360 cout <<
"Reprogramming the Mac Addresses!" << endl;
2361 string serialString;
2373 if (strstr(sSerialNumber,
"demo") == sSerialNumber)
2376 if (sscanf(sSerialNumber + 4,
"%d", &demoNum) != 1)
2378 if ((demoNum < 1) || (demoNum > 128))
2379 {cerr <<
"WARNING: Outside serial numbers demo0001 to demo0128" << endl;
return false;}
2380 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2381 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2382 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2383 pMac2->
mac[3] = pMac1->
mac[3] = 0x88;
2384 pMac2->
mac[4] = pMac1->
mac[4] = 0x12;
2385 pMac1->
mac[5] = uint8_t((demoNum - 1) * 2);
2386 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2389 else if (strstr(sSerialNumber,
"1IP") == sSerialNumber)
2396 if (sscanf(sSerialNumber + 4,
"%d", &serNum) != 1)
2398 if ((serNum < 50) || (serNum > 8241))
2399 {cerr <<
"WARNING: Outside serial numbers 1IP00050 to 1IP08241" << endl;
return false;}
2401 int mac16LSBs = (0xA000) + (serNum - 50) * 2;
2403 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2404 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2405 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2406 pMac2->
mac[3] = pMac1->
mac[3] = 0x42;
2407 pMac2->
mac[4] = pMac1->
mac[4] = uint8_t(mac16LSBs >> 8);
2408 pMac2->
mac[5] = pMac1->
mac[5] = mac16LSBs & 0x0ff;
2411 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2414 else if (strstr(sSerialNumber,
"ENG") == sSerialNumber)
2421 if (sscanf(sSerialNumber + 5,
"%d", &serNum) != 1)
2425 {cerr <<
"WARNING: Outside serial numbers ENG00000 to ENG00127" << endl;
return false;}
2427 int mac16LSBs = (0x1B00) + (serNum * 2);
2429 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2430 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2431 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2432 pMac2->
mac[3] = pMac1->
mac[3] = 0x88;
2433 pMac2->
mac[4] = pMac1->
mac[4] = uint8_t(mac16LSBs >> 8);
2434 pMac2->
mac[5] = pMac1->
mac[5] = mac16LSBs & 0xff;
2437 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2440 else if (strstr(sSerialNumber,
"6XT") == sSerialNumber)
2448 if (sscanf(sSerialNumber + 4,
"%d", &serNum) != 1)
2451 if ((serNum < 250) || (serNum > 8441))
2452 {cerr <<
"WARNING: Outside serial numbers range 250 to 8441" << endl;
return false;}
2457 if (strstr(sSerialNumber,
"6XT0") == sSerialNumber)
2459 mac24LSBs = (0x48A000) + ((serNum - 250) * 2);
2461 else if (strstr(sSerialNumber,
"6XT2") == sSerialNumber)
2463 mac24LSBs = (0x48E000) + ((serNum - 250) * 2);
2465 else if (strstr(sSerialNumber,
"6XT1") == sSerialNumber)
2467 mac24LSBs = (0x4B2000) + ((serNum - 250) * 2);
2469 else if (strstr(sSerialNumber,
"6XT3") == sSerialNumber)
2471 mac24LSBs = (0x4B6000) + ((serNum - 250) * 2);
2478 pMac2->
mac[0] = pMac1->
mac[0] = 0x0;
2479 pMac2->
mac[1] = pMac1->
mac[1] = 0x0c;
2480 pMac2->
mac[2] = pMac1->
mac[2] = 0x17;
2481 pMac2->
mac[3] = pMac1->
mac[3] = (mac24LSBs & 0xFF0000) >> 16;
2482 pMac2->
mac[4] = pMac1->
mac[4] = (mac24LSBs & 0x00FF00) >> 8;
2483 pMac2->
mac[5] = pMac1->
mac[5] = (mac24LSBs & 0x0000FF) >> 0;
2486 pMac2->
mac[5] = pMac1->
mac[5] + 1;
2490 cerr <<
"Unrecognized or unspecified serial number '" << sSerialNumber <<
"'" << endl;
2497 #pragma warning(default: 4800)