f64f934fab
from Alexander Shiryaev (MAINTAINER)
223 lines
13 KiB
Plaintext
223 lines
13 KiB
Plaintext
$OpenBSD: patch-lpcprog_c,v 1.2 2011/10/19 11:38:47 jasper Exp $
|
|
--- lpcprog.c.orig Tue Aug 2 16:45:04 2011
|
|
+++ lpcprog.c Wed Oct 19 13:22:21 2011
|
|
@@ -1,3 +1,4 @@
|
|
+#include <assert.h>
|
|
/******************************************************************************
|
|
|
|
Project: Portable command line ISP for NXP LPC1000 / LPC2000 family
|
|
@@ -495,7 +496,7 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
strippedsize--;
|
|
}
|
|
|
|
- sprintf(tmp_string, "StrippedAnswer(Length=%d): '", strippedsize);
|
|
+ int rCheckSNPrintF0 = snprintf(tmp_string, sizeof(tmp_string), "StrippedAnswer(Length=%d): '", strippedsize); assert( rCheckSNPrintF0 < sizeof(tmp_string) );
|
|
DumpString(3, strippedAnswer, strippedsize, tmp_string);
|
|
|
|
tStartUpload = time(NULL);
|
|
@@ -542,13 +543,13 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
|
|
DebugPrintf(3, "Setting oscillator\n");
|
|
|
|
- sprintf(temp, "%s\n", IspEnvironment->StringOscillator);
|
|
+ int rCheckSNPrintF1 = snprintf(temp, sizeof(temp), "%s\n", IspEnvironment->StringOscillator); assert( rCheckSNPrintF1 < sizeof(temp) );
|
|
|
|
SendComPort(IspEnvironment, temp);
|
|
|
|
ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2, 1000);
|
|
|
|
- sprintf(temp, "%s\nOK\r\n", IspEnvironment->StringOscillator);
|
|
+ int rCheckSNPrintF2 = snprintf(temp, sizeof(temp), "%s\nOK\r\n", IspEnvironment->StringOscillator); assert( rCheckSNPrintF2 < sizeof(temp) );
|
|
|
|
if (strcmp(Answer, temp) != 0)
|
|
{
|
|
@@ -771,7 +772,7 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
{
|
|
DebugPrintf(2, "Wiping Device. ");
|
|
|
|
- sprintf(tmpString, "P %d %d\n", 0, LPCtypes[IspEnvironment->DetectedDevice].FlashSectors-1);
|
|
+ int rCheckSNPrintF3 = snprintf(tmpString, sizeof(tmpString), "P %d %d\n", 0, LPCtypes[IspEnvironment->DetectedDevice].FlashSectors-1); assert( rCheckSNPrintF3 < sizeof(tmpString) );
|
|
|
|
if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
|
|
{
|
|
@@ -779,7 +780,7 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
return (WRONG_ANSWER_PREP + GetAndReportErrorNumber(Answer));
|
|
}
|
|
|
|
- sprintf(tmpString, "E %d %d\n", 0, LPCtypes[IspEnvironment->DetectedDevice].FlashSectors-1);
|
|
+ int rCheckSNPrintF4 = snprintf(tmpString, sizeof(tmpString), "E %d %d\n", 0, LPCtypes[IspEnvironment->DetectedDevice].FlashSectors-1); assert( rCheckSNPrintF4 < sizeof(tmpString) );
|
|
|
|
if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
|
|
{
|
|
@@ -792,7 +793,7 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
//no wiping requested: erasing sector 0 first
|
|
DebugPrintf(2, "Erasing sector 0 first, to invalidate checksum. ");
|
|
|
|
- sprintf(tmpString, "P %d %d\n", 0, 0);
|
|
+ int rCheckSNPrintF5 = snprintf(tmpString, sizeof(tmpString), "P %d %d\n", 0, 0); assert( rCheckSNPrintF5 < sizeof(tmpString) );
|
|
|
|
if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
|
|
{
|
|
@@ -800,7 +801,7 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
return (WRONG_ANSWER_PREP + GetAndReportErrorNumber(Answer));
|
|
}
|
|
|
|
- sprintf(tmpString, "E %d %d\n", 0, 0);
|
|
+ int rCheckSNPrintF6 = snprintf(tmpString, sizeof(tmpString), "E %d %d\n", 0, 0); assert( rCheckSNPrintF6 < sizeof(tmpString) );
|
|
|
|
if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
|
|
{
|
|
@@ -822,7 +823,7 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
|
|
if (IspEnvironment->BinaryOffset < ReturnValueLpcRamStart(IspEnvironment)) // Skip Erase when running from RAM
|
|
{
|
|
- sprintf(tmpString, "P %ld %ld\n", Sector, Sector);
|
|
+ int rCheckSNPrintF7 = snprintf(tmpString, sizeof(tmpString), "P %ld %ld\n", Sector, Sector); assert( rCheckSNPrintF7 < sizeof(tmpString) );
|
|
|
|
if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
|
|
{
|
|
@@ -834,7 +835,7 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
fflush(stdout);
|
|
if (IspEnvironment->WipeDevice == 0 && (Sector!=0)) //Sector 0 already erased
|
|
{
|
|
- sprintf(tmpString, "E %ld %ld\n", Sector, Sector);
|
|
+ int rCheckSNPrintF8 = snprintf(tmpString, sizeof(tmpString), "E %ld %ld\n", Sector, Sector); assert( rCheckSNPrintF8 < sizeof(tmpString) );
|
|
|
|
if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
|
|
{
|
|
@@ -882,7 +883,7 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
CopyLength += ((45 * 4) - (CopyLength % (45 * 4)));
|
|
}
|
|
|
|
- sprintf(tmpString, "W %ld %ld\n", ReturnValueLpcRamBase(IspEnvironment), CopyLength);
|
|
+ int rCheckSNPrintF9 = snprintf(tmpString, sizeof(tmpString), "W %ld %ld\n", ReturnValueLpcRamBase(IspEnvironment), CopyLength); assert( rCheckSNPrintF9 < sizeof(tmpString) );
|
|
|
|
if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
|
|
{
|
|
@@ -982,13 +983,13 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
|
|
// printf("block_CRC = %ld\n", block_CRC);
|
|
|
|
- sprintf(tmpString, "%ld\n", block_CRC);
|
|
+ int rCheckSNPrintF10 = snprintf(tmpString, sizeof(tmpString), "%ld\n", block_CRC); assert( rCheckSNPrintF10 < sizeof(tmpString) );
|
|
|
|
SendComPort(IspEnvironment, tmpString);
|
|
|
|
ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2,5000);
|
|
|
|
- sprintf(tmpString, "%ld\nOK\r\n", block_CRC);
|
|
+ int rCheckSNPrintF11 = snprintf(tmpString, sizeof(tmpString), "%ld\nOK\r\n", block_CRC); assert( rCheckSNPrintF11 < sizeof(tmpString) );
|
|
|
|
if (strcmp(Answer, tmpString) != 0)
|
|
{
|
|
@@ -1009,12 +1010,12 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
}
|
|
#else
|
|
// printf("block_CRC = %ld\n", block_CRC);
|
|
- sprintf(tmpString, "%ld\r\n", block_CRC);
|
|
+ int rCheckSNPrintF12 = snprintf(tmpString, sizeof(tmpString), "%ld\r\n", block_CRC); assert( rCheckSNPrintF12 < sizeof(tmpString) );
|
|
SendComPort(IspEnvironment, tmpString);
|
|
|
|
ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2,5000);
|
|
|
|
- sprintf(tmpString, "%ld\r\nOK\r\n", block_CRC);
|
|
+ int rCheckSNPrintF13 = snprintf(tmpString, sizeof(tmpString), "%ld\r\nOK\r\n", block_CRC); assert( rCheckSNPrintF13 < sizeof(tmpString) );
|
|
if (strcmp(Answer, tmpString) != 0)
|
|
{
|
|
DebugPrintf(1, "Error on writing block_CRC (2)\n");
|
|
@@ -1032,13 +1033,13 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
#if !defined COMPILE_FOR_LPC21
|
|
for (repeat = 0; repeat < 3; repeat++)
|
|
{
|
|
- sprintf(tmpString, "%ld\n", block_CRC);
|
|
+ int rCheckSNPrintF10 = snprintf(tmpString, sizeof(tmpString), "%ld\n", block_CRC); assert( rCheckSNPrintF10 < sizeof(tmpString) );
|
|
|
|
SendComPort(IspEnvironment, tmpString);
|
|
|
|
ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2,5000);
|
|
|
|
- sprintf(tmpString, "%ld\nOK\r\n", block_CRC);
|
|
+ int rCheckSNPrintF11 = snprintf(tmpString, sizeof(tmpString), "%ld\nOK\r\n", block_CRC); assert( rCheckSNPrintF11 < sizeof(tmpString) );
|
|
|
|
if (strcmp(Answer, tmpString) != 0)
|
|
{
|
|
@@ -1058,12 +1059,12 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
return (ERROR_WRITE_CRC2);
|
|
}
|
|
#else
|
|
- sprintf(tmpString, "%ld\r\n", block_CRC);
|
|
+ int rCheckSNPrintF12 = snprintf(tmpString, sizeof(tmpString), "%ld\r\n", block_CRC); assert( rCheckSNPrintF12 < sizeof(tmpString) );
|
|
SendComPort(IspEnvironment, tmpString);
|
|
|
|
ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2,5000);
|
|
|
|
- sprintf(tmpString, "%ld\r\nOK\r\n", block_CRC);
|
|
+ int rCheckSNPrintF13 = snprintf(tmpString, sizeof(tmpString), "%ld\r\nOK\r\n", block_CRC); assert( rCheckSNPrintF13 < sizeof(tmpString) );
|
|
if (strcmp(Answer, tmpString) != 0)
|
|
{
|
|
DebugPrintf(1, "Error on writing block_CRC (4)\n");
|
|
@@ -1075,7 +1076,7 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
if (IspEnvironment->BinaryOffset < ReturnValueLpcRamStart(IspEnvironment))
|
|
{
|
|
// Prepare command must be repeated before every write
|
|
- sprintf(tmpString, "P %ld %ld\n", Sector, Sector);
|
|
+ int rCheckSNPrintF7 = snprintf(tmpString, sizeof(tmpString), "P %ld %ld\n", Sector, Sector); assert( rCheckSNPrintF7 < sizeof(tmpString) );
|
|
|
|
if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
|
|
{
|
|
@@ -1107,7 +1108,7 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
CopyLength = LPCtypes[IspEnvironment->DetectedDevice].MaxCopySize;
|
|
}
|
|
|
|
- sprintf(tmpString, "C %ld %ld %ld\n", SectorStart + SectorOffset, ReturnValueLpcRamBase(IspEnvironment), CopyLength);
|
|
+ int rCheckSNPrintF14 = snprintf(tmpString, sizeof(tmpString), "C %ld %ld %ld\n", SectorStart + SectorOffset, ReturnValueLpcRamBase(IspEnvironment), CopyLength); assert( rCheckSNPrintF14 < sizeof(tmpString) );
|
|
|
|
if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
|
|
{
|
|
@@ -1123,11 +1124,11 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
//and the compare result may not be correct.
|
|
if (SectorStart + SectorOffset<64)
|
|
{
|
|
- sprintf(tmpString, "M %d %ld %ld\n", 64, ReturnValueLpcRamBase(IspEnvironment) + (64 - SectorStart - SectorOffset), CopyLength-(64 - SectorStart - SectorOffset));
|
|
+ int rCheckSNPrintF15 = snprintf(tmpString, sizeof(tmpString), "M %d %ld %ld\n", 64, ReturnValueLpcRamBase(IspEnvironment) + (64 - SectorStart - SectorOffset), CopyLength-(64 - SectorStart - SectorOffset)); assert( rCheckSNPrintF15 < sizeof(tmpString) );
|
|
}
|
|
else
|
|
{
|
|
- sprintf(tmpString, "M %ld %ld %ld\n", SectorStart + SectorOffset, ReturnValueLpcRamBase(IspEnvironment), CopyLength);
|
|
+ int rCheckSNPrintF16 = snprintf(tmpString, sizeof(tmpString), "M %ld %ld %ld\n", SectorStart + SectorOffset, ReturnValueLpcRamBase(IspEnvironment), CopyLength); assert( rCheckSNPrintF16 < sizeof(tmpString) );
|
|
}
|
|
|
|
if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
|
|
@@ -1169,13 +1170,13 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
|
|
if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC2XXX)
|
|
{
|
|
- sprintf(tmpString, "G %ld A\n", IspEnvironment->StartAddress);
|
|
+ int rCheckSNPrintF17 = snprintf(tmpString, sizeof(tmpString), "G %ld A\n", IspEnvironment->StartAddress); assert( rCheckSNPrintF17 < sizeof(tmpString) );
|
|
}
|
|
else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC17XX ||
|
|
LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC13XX ||
|
|
LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC11XX)
|
|
{
|
|
- sprintf(tmpString, "G %ld T\n", IspEnvironment->StartAddress & ~1);
|
|
+ int rCheckSNPrintF18 = snprintf(tmpString, sizeof(tmpString), "G %ld T\n", IspEnvironment->StartAddress & ~1); assert( rCheckSNPrintF18 < sizeof(tmpString) );
|
|
}
|
|
else
|
|
{
|
|
@@ -1198,13 +1199,13 @@ int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
|
|
*/
|
|
if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC2XXX)
|
|
{
|
|
- sprintf(ExpectedAnswer, "G %ld A\n0", IspEnvironment->StartAddress);
|
|
+ int rCheckSNPrintF19 = snprintf(ExpectedAnswer, sizeof(ExpectedAnswer), "G %ld A\n0", IspEnvironment->StartAddress); assert( rCheckSNPrintF19 < sizeof(ExpectedAnswer) );
|
|
}
|
|
else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC17XX ||
|
|
LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC13XX ||
|
|
LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC11XX)
|
|
{
|
|
- sprintf(ExpectedAnswer, "G %ld T\n0", IspEnvironment->StartAddress & ~1);
|
|
+ int rCheckSNPrintF20 = snprintf(ExpectedAnswer, sizeof(ExpectedAnswer), "G %ld T\n0", IspEnvironment->StartAddress & ~1); assert( rCheckSNPrintF20 < sizeof(ExpectedAnswer) );
|
|
}
|
|
else
|
|
{
|