Hi
Proper Python Script for Calculate Seagate F3 drive Check sum.
Please note , Firmware check sum calculation and ROM write by boot code mode check sum calculation is different.
For rom write by boot code mode, need to calculate check sum after every 512 byte, then check sum, then next 512 byte, until finish. This CRC calculation Equation i am searching. if any one have it please Share with me.
FW CRC code
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Calculate a CRC the same way the CM/script code & self-test/IO code does # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def calcCRC(data,sizein,crc): for i in range(0,sizein): c1 = crc & 0x00AA c2 = c1 ^ ord(data[i]) crc = crc + (c2 & 0x00FF) return crc
def parseTestResultsNewHeader(data,currentTemp,drive5,drive12,collectParametric): """ Parser callback for DBLOG data parsing. """ global dblData if 'dexParserOn' in globals(): global dexHandler if dexHandler == None: dexHandler = getDexHandler() dexHandler(data,currentTemp,drive5,drive12,collectParametric) dbLogBlockCodes = [ 11000, 11002] dblDelim = ','
tableNameOff = 0 colOff = 1 colWidthOff = 2 tableTypeOff = 5
tableInfoBlock = { 'codes':[11000], 'format':"H" } tableDataRowBlock = { 'codes':[9002,10002, 11002], 'format':"HH" } try: from dex.tabledictionary import tableHeaders except: print "Unable to find tabledictionary for translation in paths %s" % (sys.path,) DBlogParserOff() return
# Cut off the one byte results key resultsSector = data[1:]
# Assume this is a new 5 byte firmware header # Every firmware header has 2 bytes test number, 2 bytes error code and 1 byte block type firmareHeaderFormat = ">hHb" firmareHeaderSize = struct.calcsize(firmareHeaderFormat)
# Validate the size if len(resultsSector) < firmareHeaderSize: print "Invalid firmware header. received: %s bytes, expected: >= %s bytes." % (len(resultsSector),firmareHeaderSize) return
testNumber, errorCode, blockType = struct.unpack(firmareHeaderFormat,resultsSector[:firmareHeaderSize])
# Is this a new style firmware header? if blockType in (1,): # On a new style record, the firmware CRC is the last 2 bytes of the firmware record crcFormat = ">H" crcSize = struct.calcsize(crcFormat) firmwareCRCCheck = struct.unpack(crcFormat,resultsSector[len(resultsSector)-crcSize:])[0]
# Calculate the firmware CRC # First two bytes (test num) and last two bytes (firmware CRC) are not included in the CRC calculation rec = resultsSector[2:-crcSize] # Pass the same arbitrary seed value (604 == throwing missiles) as firmware & tester do to ensure a CRC of 0's does not equal 0 crc = calcCRC(rec,len(rec),604) # Our function returns a 32 bit value, but firmware function returns a 16 bit value so mask it to get a 16 bit value crc = crc & 0xFFFF
# There is a slim chance an old header would be in this loop by mistake. Compare our calculated CRC with the firmware calculated CRC # If the CRC check fails, try to process the old style header if firmwareCRCCheck != crc: # Initialize index of binary data stream to 25 jump over the command portion of the results. # For all binary results, the first 25 bytes are made up of a single byte block code, # Two bytes containing the test number, Two bytes containing the Error code, # and Two bytes for each of the Ten Parameters, totaling 25 bytes. data = data[25:]
# New style 5 byte firmware record else: # From the data set, remove the firmware header from the beginning and the firmware CRC check at the end data = resultsSector[firmareHeaderSize:-crcSize]
# Old style 24 byte firmware header # Initialize index of binary data stream to 25 jump over the command portion of the results. # For all binary results, the first 25 bytes are made up of a single byte block code, # Two bytes containing the test number, Two bytes containing the Error code, # and Two bytes for each of the Ten Parameters, totaling 25 bytes. else: data = data[25:]
length = len(data) # Obtains Length of binary data stream
index = 0
while index < (length-4):
format = "HH" Block_Size,Block_Value = struct.unpack(format,data[index:index+struct.calcsize(format)]) if DEBUG > 0: print("Block_Value: %s" % str(Block_Value)) if Block_Value not in dbLogBlockCodes: if Block_Size == 0: Block_Size = 1 #Prevent the case of bad block header causing an infinite loop
else: if Block_Value in tableInfoBlock['codes'] or Block_Value in tableDataRowBlock['codes']: if Block_Value in tableInfoBlock['codes']: formatA = tableInfoBlock['format'] # Establishes the format for the Struct module to unpack the data in. tableCode, = struct.unpack(formatA,data[index+4:index+4+struct.calcsize(formatA)]) # unpaks the revision Type from the data list DriveVars['tableCode'] = tableCode binDataStartLoc = index+struct.calcsize(format)+struct.calcsize(formatA) else: tableCode = DriveVars['tableCode'] binDataStartLoc = index + struct.calcsize(format)
binData = data[binDataStartLoc:index+Block_Size]
if DEBUG >1: print("Table Info: tableCode=%s" % str(tableCode)) print("row data: %s" % (binData,))
try: tableName = tableHeaders[tableCode][tableNameOff] abort = 0 except KeyError: tableName = '' print("DBLOG Block code %s not defined in tabledictionary.py" % str(tableCode)) abort = 1
if not abort: rowData = binData.split(dblDelim)
tableColumns = tableHeaders[tableCode][colOff].split(dblDelim)
if len(rowData) > len(tableColumns): #expand tableColumns with dummy cols so user has some access to data. dummyCols = ['dummyCol%s' % (i,) for i in range(len(tableColumns),len(rowData))] tableColumns.extend(dummyCols)
#expand with nuls if more cols than row output rowData.extend(range(len(rowData),len(tableColumns)))
## Old Data Format ## dblData['P010_FORCE_CONSTANT'] = [ ## {'ITER': '255', 'ZTAB': '9598', 'BDRAG': '0', 'FORCE_CONSTANT': '0', 'POINT': '0'}, ## {'ITER': '255', 'ZTAB': '7638', 'BDRAG': '0', 'FORCE_CONSTANT': '0', 'POINT': '1'}, ## {'ITER': '0', 'ZTAB': '5878', 'BDRAG': '0', 'FORCE_CONSTANT': '0', 'POINT': '2'}, ## {'ITER': '0', 'ZTAB': '4503', 'BDRAG': '0', 'FORCE_CONSTANT': '0', 'POINT': '3'}, ## ] #dblData.setdefault(tableName,[]).append(dict(zip(tableColumns,rowData)))
## New Data Format ## dblData['P010_FORCE_CONSTANT'] = { ## 'ITER' : ['255', '255', '0', '0'], ## 'ZTAB' : ['9598', '7638', '5878', '4503'], ## 'BDRAG': ['0', '0', '0', '0'], ## 'FORCE_CONSTANT': ['0', '0', '0', '0'], ## 'POINT' : ['0', '1', '2', '3'] ## } dblData.setdefault(tableName,{}) for key,val in map(None,tableColumns,rowData): dblData[tableName].setdefault(key, []).append(val)
# Block Size, So index will now reference the start of the next data block. index = index+Block_Size
|