1
/* Copyright (c) 1996-2004, Adaptec Corporation
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* - Redistributions of source code must retain the above copyright notice, this
8
* list of conditions and the following disclaimer.
9
* - Redistributions in binary form must reproduce the above copyright notice,
10
* this list of conditions and the following disclaimer in the documentation
11
* and/or other materials provided with the distribution.
12
* - Neither the name of the Adaptec Corporation nor the names of its
13
* contributors may be used to endorse or promote products derived from this
14
* software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
* POSSIBILITY OF SUCH DAMAGE.
29
/****************************************************************************
33
*****************************************************************************
35
* File Name: Flash.cpp
37
* Contributors: Mark Salyzyn
39
* Description: This command flashes the specified controller
45
*****************************************************************************/
48
#include "command.hpp"
50
#include "listdev.hpp"
51
#include "intlist.hpp"
53
#include "ctlr_map.hpp"
67
#if defined _DPT_WIN_NT
68
# include <strstrea.h>
74
# include <strstream.h>
79
extern char* EventStrings[];
84
OUTPUT_MULTI_LINED_TAB_HEADER,
85
OUTPUT_END_OF_TAB_SCOPE,
91
STATE_MULTI_LINE_COLUMNAR,
98
typedef struct _FW_MODEL_MAPPING
100
char controllerModel[8];
101
char fileDescriptionModel[8];
106
/*** STATIC DATA ***/
108
// This array contains the valid mappings of the model number representing the
109
// class of adapters that a firmware file is for and the model numbers which
110
// represent that class. This is used to validate that a firmware file can
111
// legitimately be flashed to an adapter before the flash is performed.
113
// This mapping does NOT contain the mirror mappings where the fileDescriptionModel
114
// is the same as the productIdModel, e.g. "2554" and "2554".
115
static FW_MODEL_MAPPING modelMappings[] =
135
#define min(x, y) ((x) < (y) ? (x) : (y))
141
extern void Flush( String_List * );
153
ENTER( "Flash::Flash(" );
155
(void)strcpy (source = new char [ strlen (sourceFile) + 1 ], (const char *) sourceFile);
167
memset (ScanBuild, 0, sizeof(ScanBuild));
168
memset (ScanVersion, 0, sizeof(ScanVersion));
169
memset (ScanType, 0, sizeof(ScanType));
170
memset (ScanDescriptionHba, 0, sizeof(ScanDescriptionHba));
176
Flash::Flash( const Flash &right )
178
ENTER( "Flash::Flash(" );
180
#if defined _DPT_UNIXWARE || defined _DPT_SCO
181
Flash( right.source, right.Resync, right.hba_Num );
183
Flash::Flash( right.source, right.Resync, right.hba_Num );
193
ENTER( "Flash::~Flash()" );
198
source = (char *) NULL;
205
Command::Dpt_Error Flash::execute( String_List **output )
207
ENTER( "Command::Dpt_Error Flash::execute( String_List **output )" );
211
// allocate this object once for all functions.
212
*output = new String_List();
214
// Try to open the file specified. If it can't be opened then output
215
// an error message and return.
217
// The stupid Borland compiler for DOS sets up an unbuffered stream by
218
// default so under DOS attach a buffer to the stream so that we get
219
// decent performance. Otherwise, performance is truely abysmal.
220
std::fstream firmwareStream;
223
char firmwareStreamBuf[BYTES_PER_TRANSFER];
224
streambuf *pBuf = firmwareStream.rdbuf();
225
pBuf->setbuf(firmwareStreamBuf, sizeof(firmwareStreamBuf));
228
#if defined _DPT_BSDI
229
firmwareStream.open(source, std::ios::in | std::ios::bin);
230
#elif defined (_DPT_SCO) || defined (_DPT_UNIXWARE)
231
firmwareStream.open(source, std::ios::in);
233
firmwareStream.open(source, std::ios::in | std::ios::binary);
235
if (!firmwareStream.good())
237
(**output).add_Item(EventStrings[STR_FAILURE]);
238
(**output).add_Item(EventStrings[STR_BLANK]);
239
(**output).add_Item( source );
243
// Get the size of the file.
244
firmwareStream.seekg(0, std::ios::end);
245
imageSize = firmwareStream.tellg();
246
firmwareStream.seekg(0);
250
(**output).add_Item(EventStrings[STR_FAILURE]);
251
(**output).add_Item(EventStrings[STR_BLANK]);
252
(**output).add_Item( source );
256
m_FlashFileProcessorFamily = -1;
257
// Determine the type of file provided.
258
unsigned long InitialOffset = (unsigned long)-1L;
259
unsigned long ScanFwType = 0L;
260
//Changed because this initialization isn't supported undes SCO 3.2.4.2
261
// unsigned char InitialType[16] = { 0 };
262
unsigned char InitialType[16];
265
unsigned long Offset = 0L;
266
// Apparently 8K is the smallest of any flash size, which can only be NVRAM
267
if (imageSize <= MAX_FLASH_NVRAM_SIZE)
268
// if ( ( imageSize == 128 ) || ( imageSize == FLASH_NVRAM_SIZE ) )
271
InitialOffset = ScanOffset = FLASH_NVRAM_OFFSET;
272
ScanSize = imageSize;
273
strcpy ( (char *)InitialType, EventStrings[STR_NVRAM] );
274
strcpy ( (char *)ScanType, (const char *)InitialType );
275
sprintf (Buffer, EventStrings[STR_SCAN_TYPE_SIZE], ScanType, ScanSize);
276
(**output).add_Item( Buffer );
278
else for (unsigned long count = 0; count < imageSize; ++count)
280
uCHAR ch = firmwareStream.get();
281
if (( DetermineOffset(ch))
282
|| (( ScanState == 21 ) && (count >= (Offset + ScanSize)))
283
|| ((count + 1) == imageSize))
285
if (InitialOffset == (unsigned long)-1L)
287
InitialOffset = ScanOffset;
288
strcpy ( (char *)InitialType, (const char *)ScanType );
290
if (ScanFwType == 0L)
292
ScanFwType = ScanFwId;
294
if (( Offset += ScanSize ) > count)
296
count = (Offset - 1);
302
char version[sizeof(ScanVersion)+sizeof(ScanBuild)+1];
304
memset (date, ' ', sizeof(date)-1);
305
date[sizeof(date)-1] = '\0';
306
if (ScanMonth || ScanDay || ScanYear)
308
sprintf (date, EventStrings[STR_FILLIN_DATE],
309
ScanMonth, ScanDay, ScanYear);
311
memset (version, 0, sizeof(version));
314
sprintf (version, EventStrings[STR_FILLIN_VERSION],
315
ScanVersion, ScanBuild[0] ? "/" : "", ScanBuild);
317
if (Offset > imageSize)
319
ScanSize -= Offset - imageSize;
321
sprintf (Buffer, EventStrings[STR_SCAN_TYPE_SIZE_DATE_VERSION],
322
ScanType, ScanSize, date, version);
323
(**output).add_Item( Buffer );
332
memset (ScanBuild, 0, sizeof(ScanBuild));
333
memset (ScanVersion, 0, sizeof(ScanVersion));
334
memset (ScanType, 0, sizeof(ScanType));
338
ScanOffset = InitialOffset;
339
strcpy ( (char *)ScanType, (const char *)InitialType );
341
Init_Engine(1); // only scan hbas
343
(**output).add_Item(EventStrings[STR_LIST_DEV_CTLR_HEADER]);
344
(**output).add_Item( STR_DEV_DIVIDING_LINE );
346
bool anyControllerFound = false;
347
bool more_Devs_Left = true;
348
bool flashedData = false;
350
for (int dev_Index = 0; more_Devs_Left; dev_Index++)
352
DPT_TAG_T tempHbaTag=Get_HBA_by_Index(dev_Index, &more_Devs_Left);
358
if (( hba_Num == -1 ) || ( hba_Num == dev_Index ))
360
anyControllerFound = true;
361
// if this is firmware, make sure the image matches the hba
362
if (!memcmp(ScanType, EventStrings[STR_FIRMWARE], 8))
364
// find out the hba type
365
err = engine->Send( MSG_GET_INFO, hbaTag );
366
uSHORT fwType = engine->hbaInfo_P->fwType;
368
memset (tempStr, 0, sizeof(tempStr));
369
memcpy (tempStr, Strip_Trailing_Whitespace(engine->devInfo_P->productID), sizeof(tempStr));
372
err = PrintHBA(**output);
375
if (ScanFwType != 0L)
377
if (ScanFwType != fwType)
379
err = Dpt_Error::DPT_CMD_ERR_INVALID_FLASH_IMAGE;
380
(**output).add_Item(EventStrings[STR_FILE_NOT_MATCH_HBA]);
385
else if (((tempStr[0] == '1') || (tempStr[0] == '2') ||
386
(tempStr[0] == '3') || (tempStr[0] == '5')) &&
389
// The second digit matters if it's 2XXX series (ie. Pimento = 2400, Catapult = 2100) E.E. 3/5/2001
390
if (ScanDescriptionHba[1] != 'M' && ScanDescriptionHba[0] != '2')
392
tempStr[1] = ScanDescriptionHba[1];
396
if (!ValidFlashFileForController(ScanDescriptionHba, tempStr))
398
err = Dpt_Error::DPT_CMD_ERR_INVALID_FLASH_IMAGE;
399
(**output).add_Item(EventStrings[STR_FILE_NOT_MATCH_HBA]);
408
err = PrintHBA(**output);
413
err |= Flash_This_HBA( **output, firmwareStream );
420
if (!anyControllerFound)
422
err = Dpt_Error::DPT_CMD_ERR_CANT_FIND_HBA_INDEX;
423
(**output).add_Item(EventStrings[STR_CTLR_NOT_FOUND]);
430
(**output).add_Item(EventStrings[STR_FLASH_COMPLETE]);
435
(**output).add_Item(EventStrings[STR_REBOOT]);
436
(**output).add_Item(EventStrings[STR_REMMODEZERO]);
442
engine->Insert ((uLONG) 0x01); // perform a complete init
443
err2 = engine->Send (MSG_I2O_RESYNC, hbaTag);
446
(**output).add_Item(EventStrings[STR_RESYNC_SUCCESS_NO_REBOOT]);
448
else if (err2 == Dpt_Error::DPT_MSG_RTN_IGNORED)
449
(**output).add_Item(EventStrings[STR_RESYNC_NOT_SUPPORTED_REBOOT]);
451
(**output).add_Item(EventStrings[STR_RESYNC_FAILED_REBOOT]);
463
bool Flash::ValidFlashFileForController(
464
const char *fileDescriptionModel,
465
const char *controllerModel
469
bool validFlashFileForController = false;
471
// Do the special case check if the two are the same then there is a match.
472
if (strcmp(fileDescriptionModel, controllerModel) == 0)
474
validFlashFileForController = true;
478
// Loop through the mappings looking for a controller model that matches the controller
480
for (unsigned mapIndex = 0; mapIndex < sizeof(modelMappings)/sizeof(modelMappings[0]); mapIndex++)
482
if (strcmp(modelMappings[mapIndex].controllerModel, controllerModel) == 0)
484
if (strcmp(modelMappings[mapIndex].fileDescriptionModel, fileDescriptionModel) == 0)
486
validFlashFileForController = true;
493
if ((validFlashFileForController == false) && (inMode0 == true))
495
#if defined _DPT_LEGACY // dptutil (only DOS/dptutil defines _DPT_LEGACY)
496
if ((strcmp(controllerModel, "PM2865") == 0) &&
497
(fileDescriptionModel[0] == '3') &&
498
(fileDescriptionModel[2] == '0') && (fileDescriptionModel[3] == '0'))
499
validFlashFileForController = true;
501
if ((strcmp(fileDescriptionModel, "PM2865") == 0) &&
502
(controllerModel[0] == '3') &&
503
(controllerModel[2] == '0') && (controllerModel[3] == '0'))
504
validFlashFileForController = true;
510
// Return to the caller.
511
return(validFlashFileForController);
514
// The mother of all state machines.
515
// This state machine will return a value of 1 if all the information
516
// about the file has been determined. The information is the Offset
517
// expected within the flash region, the size of the image (so we could
518
// reset and look at a concatonated image) and the version of the
520
int Flash::DetermineOffset(int c)
526
ScanSize = FLASH_FIRMWARE_SIZE;
529
ScanOffset = 180224L; // EATA Card
530
(void)strcpy ((char *)ScanType, "SMOR");
536
ScanOffset = 819200L; // I2O Card
537
(void)strcpy ((char *)ScanType, "SMOR");
545
{ // ROM image, or SMOR compressed image
552
ScanSize = (unsigned long)c;
553
if ((c < 16) || (128 < c) || ((c & 7) != 0))
555
ScanState = 156; // SMOR compressed image or FCODE image
559
ScanState = 149; // ROM image or SMOR compressed image
581
ScanVersion[ScanState-5] = c;
584
case 10:// ' v00X.XX'
586
ScanVersion[6] = '\0';
603
if (('0' <= c) && (c <= '9'))
614
ScanMonth = (unsigned char)ScanYear;
623
if (('0' <= c) && (c <= '9'))
626
ScanMonth += c - '0';
635
if (('0' <= c) && (c <= '9'))
641
ScanState = 133; // BIOS rom has no build number (yet)
644
if (('0' <= c) && (c <= '9'))
654
if (('0' <= c) && (c <= '9'))
660
ScanState = 133; // BIOS rom has no build number (yet)
665
ScanState = 21; // Some random image ...
671
ScanSize = (unsigned long)c;
674
case 19: // SMOR image
675
case 149: // ROM Image or SMOR compressed image
676
case 156: // SMOR compressed image
677
ScanSize |= (unsigned long)((unsigned)c << 8);
680
case 20: // SMOR image
681
case 150: // ROM image or SMOR compressed image
682
case 157: // SMOR compressed image
683
ScanSize |= ((unsigned long)c) << 16L;
686
case 158: // SMOR compressed image
687
ScanSize |= ((unsigned long)c) << 24L;
692
{ // Could be an FCODE image?
694
ScanState = 21; // unlikely that a SMOR compressed image could
695
break; // acquire the DPTSIG structure, but hey!
697
ScanState = 159; // FCODE image;
701
case 161: // SMOR compressed image or FCODE image?
705
ScanState = 21; // SMOR compressed image.
712
(void)strcpy ((char *)ScanType, "?");
786
case 194: // FCODE length
787
(void)strcpy((char *)ScanType, "FCODE");
788
ScanOffset = FLASH_BIOS_OFFSET; // I2O Card
789
ScanSize = (unsigned long)c;
792
case 195: // FCODE length
793
ScanSize |= ((unsigned long)c) << 8L;
795
ScanState = 21; // See if we can get more from a concatenated SIG
797
case 151: // ROM image or SMOR compressed image
798
ScanSize |= ((unsigned long)c) << 24L;
801
case 152: // ROM image or SMOR compressed image
803
{ // SMOR compressed image or FCODE image?
810
ScanState = 21; // SMOR compressed image
815
case 153: // ROM image
816
case 154: // ROM image
820
ScanState = 21; // SMOR compressed image
825
case 155: // ROM image
829
ScanState = 21; // SMOR compressed image
832
ScanSize = (ScanSize & 0xFF) * BYTES_PER_TRANSFER;
833
if (ScanSize > 16384L)
835
ScanOffset = FLASH_BIOS_OFFSET; // I2O Card
839
ScanOffset = 163840L; // EATA Card
841
strcpy ((char *)ScanType, "BIOS");
842
ScanState = 3; // Get the ROM signature if we can!
851
case 21: // Search for DPTSIG
887
case 28: // dsProcessorFamily
888
if ((c == PROC_i960) // i960
889
|| (c == PROC_MIPS)) // MIPS
891
ScanOffset = 0L; // Make doubly sure it
892
(void)strcpy ((char *)ScanType, EventStrings[STR_FIRMWARE]);
893
} // resides in firmware
894
m_FlashFileProcessorFamily = c;
895
case 27: // dsSigVersion
896
case 29: // dsProcessor
897
case 31: // dsFiletypeFlags
904
case 38: // dsCapabilities
906
case 40: // dsDeviceSupp
908
case 42: // dsAdapterSupp
909
case 45: // dsRequirements
912
case 30: // dsFileType
913
if (c == FT_FIRMWARE)
915
ScanOffset = 0L; // Make doubly sure it
916
(void)strcpy ((char *)ScanType, EventStrings[STR_FIRMWARE]);
918
/* More FT_ flags should be used. */
925
case 44: // dsApplication
926
loadInfo |= (c << 8);
929
case 46: // dsVersion
930
ScanVersion[0] = (c / 100) + '0';
931
ScanVersion[1] = ((c / 10) % 10) + '0';
932
ScanVersion[2] = (c % 10) + '0';
933
ScanVersion[3] = '.';
936
case 47: // dsRevision
940
case 48: // dsSubRevision
942
ScanVersion[6] = '\0';
957
case 52: // dsDescription
958
if (( c == 'P' ) || ( c == 'p' ))
960
// ScanDescriptionHba[0] = 'P';
961
ScanDescriptionHba[ScanDescrIdx++] = 'P';
966
if (( c == 'M' ) || ( c == 'm' ))
968
// ScanDescriptionHba[1] = 'M';
969
ScanDescriptionHba[ScanDescrIdx++] = 'M';
976
// ScanDescriptionHba[2] = c;
977
ScanDescriptionHba[ScanDescrIdx++] = c;
984
// ScanDescriptionHba[3] = c;
985
ScanDescriptionHba[ScanDescrIdx++] = c;
993
// ScanDescriptionHba[4] = c;
994
ScanDescriptionHba[ScanDescrIdx++] = c;
996
else if (c == 'A' || c == 'a')
997
ScanDescriptionHba[ScanDescrIdx++] = 'A';
998
else if (c == 'S' || c == 's')
999
ScanDescriptionHba[ScanDescrIdx++] = 'S';
1007
// ScanDescriptionHba[5] = c;
1008
ScanDescriptionHba[ScanDescrIdx++] = c;
1092
if ((c == 'b') || (c == 'B'))
1148
if (('0' <= c) && (c <= '9'))
1150
ScanBuild[ScanState - 139] = c;
1155
// Convert Build Number to Base 36 value within version string.
1156
{ unsigned char * cp = ScanBuild;
1157
unsigned short Value = 0;
1165
// we will overflow at 1296 builds, Historically we manage up
1166
// to about 150 builds before the revision is bumped.
1167
ScanVersion[5] = (Value / 36) + '0';
1168
ScanVersion[6] = (Value % 36) + '0';
1170
if (ScanVersion[6] > '9')
1172
ScanVersion[6] += 'A' - '9' - 1;
1174
if (ScanVersion[5] > '9')
1176
ScanVersion[5] += 'A' - '9' - 1;
1178
ScanVersion[7] = '\0';
1179
ScanBuild[0] = '\0';
1182
case 197: // Look for the end of the description string.
1187
case 198: // End of the Description String means FwId is here?
1194
case 133: // Ignore remaining, allows us to count size now.
1196
case 199: // Discovered the F where we expect the FwId signature.
1204
case 200: // Discovered the Fw where we expect the FwId signature.
1212
case 201: // Discovered the FwI where we expect the FwId signature.
1225
ScanFwId |= (unsigned short)c << 8;
1229
ScanFwId |= (unsigned long)c << 16;
1233
ScanFwId |= (unsigned long)c << 24;
1237
if ((('0' <= c) && (c <= '9')) || (c == '.'))
1252
if ((('0' <= c) && (c <= '9'))
1253
|| (('A' <= c) && (c <= 'F')))
1255
ScanBuild[ScanState - 145] = c;
1265
Command::Dpt_Error Flash::GetFlashStatus(
1266
dptFlashStatus_S &flashStatus
1269
// Send the command to the engine to get the flash status of the
1270
// associated controller.
1272
Dpt_Error status = engine->Send(MSG_FLASH_STATUS, hbaTag);
1274
// If the command succeeded then extract the returned data.
1275
if (status.Success())
1277
// There really should be a structure which describes ALL
1278
// of the data returned by this command. Like so many other
1279
// things this was apparently just hacked together (sigh...)
1280
uLONG ioOffset, fwStatus;
1281
engine->Extract(&ioOffset, sizeof(ioOffset));
1282
engine->Extract(&fwStatus, sizeof(fwStatus));
1283
engine->Extract(&flashStatus, sizeof(flashStatus));
1286
// Return the status to the caller.
1291
Command::Dpt_Error Flash::SetFlashRegion(
1295
// Send the command to the engine to set the region of flash memory to use.
1297
engine->Insert((uLONG) region);
1298
engine->Insert((uLONG) loadInfo);
1299
engine->Insert((uLONG) imageSize);
1300
Dpt_Error status = engine->Send(MSG_FLASH_SET_REGION, hbaTag);
1302
// Return the status to the caller.
1307
Command::Dpt_Error Flash::ReadFlashMemory(
1313
// Send the command to the engine to read the flash memory.
1315
engine->Insert(offset);
1316
engine->Insert(bytesToRead);
1317
Dpt_Error status = engine->Send(MSG_FLASH_READ, hbaTag);
1319
// If the read succeeded then copy the data that was read from the flash
1320
// memory into the caller's buffer.
1321
if (status.Success())
1323
engine->Extract(buf, bytesToRead);
1326
// Return the status to the caller.
1331
Command::Dpt_Error Flash::WriteFlashMemory(
1336
// Send the command to the engine to read the flash memory.
1338
engine->Insert(buf, bytesToWrite);
1339
Dpt_Error status = engine->Send(MSG_FLASH_WR_NO_VERIFY, hbaTag);
1341
// Return the status to the caller.
1346
Command::Dpt_Error Flash::WriteFlashMemoryDone(
1350
// Send the command to the engine to stop writing flash memory.
1354
engine->Insert((uCHAR) 1);
1357
Dpt_Error status = engine->Send(MSG_FLASH_WRITE_DONE, hbaTag);
1359
// Return the status to the caller.
1363
//------------------------------------------------------------------//
1365
// START OF BIG KLUDGE //
1367
// Because the 2865 has such a large region for firmware there are //
1368
// several different sizes of firmware files. Because of how the //
1369
// 2865 is implemented if a firmware file smaller than the total //
1370
// firmware address space of the controller (~1.5MB) is flashed the //
1371
// image that is flashed must be adjusted so that it is aligned //
1372
// with the end of the firmware region, not the beginning. Because //
1373
// the engine provides no mechanism for seeking when writing to //
1374
// flash the code will read data and then write that data back to //
1375
// the same location. This makes flashing faster because the flash //
1376
// chip won't have to really do anything in that situation. //
1378
//------------------------------------------------------------------//
1379
Command::Dpt_Error Flash::GetStartingFlashIndex(
1380
const FlashRegion flashRegion,
1381
const uLONG imageSize,
1382
const int flashFileProcessorFamily,
1383
uLONG &startingIndex
1388
// Assume the starting index is 0. Its a special case if its not.
1391
// This is only an issue when flashing firmware.
1392
if (( flashRegion == FW ) && (loadInfo & FW_LOAD_TOP))
1394
// Get the flash status of the controller. This contains a field which
1395
// has the size of the firmware region of flash memory.
1396
dptFlashStatus_S flashStatus;
1397
status = GetFlashStatus(flashStatus);
1399
if (status.Success())
1401
// Need the 'burn size' field. This field is misnamed - it is
1402
// really the size of the firmware region of flash memory.
1403
const uLONG firmwareSize = dptFlashStatus_getBurnSize(&flashStatus);
1404
if (imageSize < firmwareSize)
1406
// Calculate the starting index in flash memory.
1407
startingIndex = firmwareSize - imageSize;
1412
// Return the status to the caller.
1416
Command::Dpt_Error Flash::WriteSeekToIndex(
1422
// Create an I/O buffer and zero it out.
1423
char ioBuf[BYTES_PER_TRANSFER];
1424
memset(ioBuf, 0, sizeof(ioBuf));
1426
// Skip the necessary space by writing zeros up to the specified
1427
// index. It is ASSUMED that the index is a multiple of 512.
1428
uLONG seekIndex = 0;
1429
while (( status.Success() ) && ( seekIndex < seekSize ))
1431
status = WriteFlashMemory(ioBuf, sizeof(ioBuf));
1432
if (status.Success())
1434
seekIndex += sizeof(ioBuf);
1438
// Return the status to the caller.
1441
//------------------------------------------------------------------//
1443
// END OF BIG KLUDGE //
1445
//------------------------------------------------------------------//
1449
Command::Dpt_Error Flash::PrintHBA(
1455
const long ONE_K = 1024;
1458
status = engine->Send( MSG_GET_INFO, hbaTag );
1459
if (status.Success())
1461
dptCaddr_S *addr_P = &engine->devInfo_P->addr;
1462
long cache_Size_in_Mb = -1;
1464
const int BUF_LEN = 256;
1465
char temp_Buf[ BUF_LEN ];
1467
dptHBAinfo_S *hba_Info = engine->hbaInfo_P;
1468
long cache_Size_in_Kb;
1469
cache_Size_in_Kb = hba_Info->memSize;
1470
cache_Size_in_Mb = cache_Size_in_Kb / ONE_K / ONE_K;
1473
sprintf ( temp_Buf, "d%d", addr_P->hba );
1474
output.add_Item( temp_Buf );
1476
DPTControllerMap map;
1477
for (int bus = 0; bus < 3; ++bus)
1479
char * String = map.getChannelString(addr_P->hba, bus);
1481
output.add_Item( ( *String == 'c' ) ? String
1482
: ( hba_Info->chanInfo[bus].flags ? "--" : " " ));
1486
output.add_Item(Strip_Trailing_Whitespace(engine->devInfo_P->vendorID));
1487
output.add_Item(Strip_Trailing_Whitespace(engine->devInfo_P->productID));
1489
sprintf(temp_Buf, "%ld%s", cache_Size_in_Mb, EventStrings[STR_MB]);
1490
output.add_Item(temp_Buf);
1491
output.add_Item(hba_Info->revision);
1494
engine->Insert( (uCHAR)0x2E ); // NVRAM page
1495
engine->Insert( (uCHAR)0x40 ); // Interpret and current
1497
// get the defaults page
1498
status = engine->Send( MSG_GET_MODE_PAGE, hbaTag );
1501
if (status.Success())
1503
if (( engine->Extract( temp_Buf, 108 ) == 0 )
1504
|| ( engine->Extract( temp_Buf, 8 ) == 0 ))
1516
output.add_Item( temp_Buf );
1519
if (status.Success())
1521
if (engine->Extract( temp_Buf, 15 ) == 0)
1527
char * String = temp_Buf;
1529
temp_Buf[15] = '\0';
1530
while (*String && ((('0' <= *String) && (*String <= '9'))
1531
|| (*String == '-')))
1540
output.add_Item( temp_Buf );
1543
Dpt_Status hbaStatus(hbaTag);
1544
output.add_Item((char *) hbaStatus);
1547
output.add_Item( "\n" );
1549
status = Dpt_Error::DPT_MSG_RTN_COMPLETED;
1557
// Flash the file into the HBA
1558
Command::Dpt_Error Flash::Flash_This_HBA(
1559
String_List &output,
1560
std::istream &firmwareStream
1564
ENTER( "Command::Dpt_Error Flash::Flash_This_HBA(" );
1566
const int BUF_LEN = 256;
1567
char temp_Buf[ BUF_LEN ];
1568
// Raptor BIOS rewrite.
1569
char Old_PCI_ID, BIOS_rewrite = 0;
1570
unsigned long BIOSsize;
1571
unsigned PCI_Data_Table_Offset;
1572
// Now, flash this card!
1574
bool failed = false;
1575
FlashRegion flashRegion = FW;
1577
if (strcmp ((const char *)ScanType, "SMOR") == 0)
1582
if ((strcmp ((const char *)ScanType, "BIOS") == 0)
1583
|| (strcmp ((const char *)ScanType, "FCODE") == 0))
1585
flashRegion = I2OBIOS;
1586
engine->Send( MSG_GET_INFO, hbaTag );
1587
if ((strncmp ((const char *)engine->devInfo_P->productID, "2005S", 5) == 0)
1588
|| (strncmp ((const char *)engine->devInfo_P->productID, "2000S", 5) == 0))
1592
PCI_Data_Table_Offset = 0;
1596
if (strcmp ((const char *)ScanType, EventStrings[STR_NVRAM]) == 0)
1598
flashRegion = NVRAM;
1601
if (strcmp ((const char *)ScanType, EventStrings[STR_FIRMWARE]) != 0)
1603
status = Dpt_Error::DPT_CMD_ERR_INVALID_FLASH_IMAGE;
1606
uLONG startingFlashMemoryIndex(0);
1607
if (status.Success())
1609
status = SetFlashRegion(flashRegion);
1611
// Kludge for 2865 and potentially other controllers that have
1613
if (status.Success())
1615
status = GetStartingFlashIndex(flashRegion, imageSize,
1616
m_FlashFileProcessorFamily, startingFlashMemoryIndex);
1617
if (( status.Success() ) && ( startingFlashMemoryIndex != 0 ))
1619
// kds taken out per Mark Salyzyn
1620
// status = WriteSeekToIndex(startingFlashMemoryIndex);
1625
// Copy the image file to flash memory.
1627
firmwareStream.seekg(0);
1628
for (uLONG imageIndex = 0; imageIndex < imageSize; imageIndex += readSize)
1630
if (status.Success())
1632
char fileBuf[BYTES_PER_TRANSFER];
1634
// Determine the amount of data to read from the file.
1635
// This is the minimum of the amount of data left in the
1636
// file and the size of a transfer buffer.
1637
readSize = min(sizeof(fileBuf), imageSize - imageIndex);
1639
// If the amount of data to read from the file is less
1640
// than the size of the transfer buffer then pre-read the
1641
// current contents of the flash memory. This is
1642
// necessary because data that is to be flashed must be
1643
// written in BYTES_PER_TRANSFER (512) byte chunks.
1644
if (readSize != BYTES_PER_TRANSFER)
1646
status = ReadFlashMemory(fileBuf,
1647
startingFlashMemoryIndex + imageIndex,
1648
BYTES_PER_TRANSFER);
1651
// Read in data from the file and if that's successful
1652
// write that data to flash memory.
1653
if (status.Success())
1655
firmwareStream.read(fileBuf, readSize);
1657
if (firmwareStream.good())
1659
/* Raptor BIOS rewrite handler */
1662
if (BIOS_rewrite == 1) /* Work with first signature */
1664
BIOSsize = (unsigned char)fileBuf[2] * 512L;
1666
PCI_Data_Table_Offset = (unsigned char)fileBuf[24]
1667
+ ((unsigned char)fileBuf[25] << 8);
1670
/* I know, `oodles' of bugs on readSize boundaries */
1671
if (BIOS_rewrite == 2) /* Work on the PCI Data table */
1673
if (PCI_Data_Table_Offset >= readSize)
1675
PCI_Data_Table_Offset -= readSize;
1679
if (strncmp((const char *)&fileBuf[PCI_Data_Table_Offset], "PCIR", 4) == 0)
1681
Old_PCI_ID = fileBuf[PCI_Data_Table_Offset + 6];
1682
fileBuf[PCI_Data_Table_Offset + 6] = 0x11;
1691
/* Work on correcting the checksum */
1692
if ((BIOS_rewrite == 3) && (BIOSsize <= readSize))
1694
fileBuf[BIOSsize - 1] -= 0x11 - Old_PCI_ID;
1697
if (BIOSsize >= readSize)
1699
BIOSsize -= readSize;
1702
status = WriteFlashMemory(fileBuf, BYTES_PER_TRANSFER);
1706
status = Dpt_Error::DPT_CMD_ERR_INVALID_FLASH_IMAGE;
1711
if (status.Failure())
1714
EventStrings[STR_FLASH_ERR_MSG],
1715
imageIndex, (int)status, (char *)status);
1717
output.add_Item (temp_Buf);
1724
// If we failed we don't want firmware to write a checksum
1725
// There is no reason to switch out of flash mode either
1726
// (firmware will go right back into it if there is no checksum)
1727
status |= WriteFlashMemoryDone(failed);
1728
if (status.Success() && !failed)
1731
engine->Send( MSG_FLASH_SWITCH_OUT_OF, hbaTag );
1734
// Verify that the file was written properly.
1736
/* We don't have to do this because it is done in eata2i2o */
1738
uLONG flashMemoryIndex = startingFlashMemoryIndex;
1739
firmwareStream.seekg(0);
1740
for ( uLONG imageIndex = 0; imageIndex < imageSize; imageIndex += BYTES_PER_TRANSFER )
1742
char flashMemoryBuf[BYTES_PER_TRANSFER];
1743
memset(flashMemoryBuf, 0, BYTES_PER_TRANSFER);
1744
char fileBuf[sizeof(flashMemoryBuf)];
1748
// First, read data from the file.
1750
readSize = min(sizeof(fileBuf), imageSize - imageIndex);
1751
firmwareStream.read(fileBuf, readSize);
1756
// If that succeeds then read data from flash memory.
1758
if ( firmwareStream.good() )
1761
// Don't verify the top 16K of firmware. This is the mode 0 boot area
1762
// and according to Mark Salyzyn it shouldn't be verified.
1764
if (( flashRegion != FW ) || ( imageIndex < imageSize - Mode0BootSize ))
1766
status = ReadFlashMemory(flashMemoryBuf, flashMemoryIndex,
1767
sizeof(flashMemoryBuf));
1771
status = Dpt_Error::DPT_MSG_RTN_COMPLETED;
1777
status = Dpt_Error::DPT_ERR_FLASH_ENG_VERIFY;
1783
// If the necessary data was read then compare the data.
1784
// If the data doesn't compare correctly that's a failure.
1786
if ( status.Success() )
1788
if ( memcmp(flashMemoryBuf, fileBuf, readSize) != 0 )
1790
status = Dpt_Error::DPT_ERR_FLASH_ENG_VERIFY;
1793
flashMemoryIndex += sizeof(flashMemoryBuf);
1799
// If a failure occurred then inform the user.
1801
if ( status.Failure() )
1803
sprintf (temp_Buf, EventStrings[STR_VERIFYING_ERR_MSG],
1804
imageIndex, (int)status, (char *)status );
1805
output.add_Item (temp_Buf);
1811
status = Dpt_Error::DPT_MSG_RTN_COMPLETED;
1820
Command &Flash::Clone() const
1822
ENTER ("Command &Flash::Clone() const");
1824
return(*new Flash (this->source, this->Resync, this->hba_Num));
1828
/*** END OF FILE ***/