bist: decode more infos from identify data

This commit is contained in:
Florent Kermarrec 2015-01-20 12:12:51 +01:00
parent a5ae470ec9
commit faef2319ad
1 changed files with 29 additions and 17 deletions

View File

@ -2,6 +2,10 @@ import time
import argparse import argparse
from config import * from config import *
KB = 1024
MB = 1024*KB
GB = 1024*MB
logical_sector_size = 512 logical_sector_size = 512
class LiteSATABISTUnitDriver: class LiteSATABISTUnitDriver:
@ -44,7 +48,10 @@ class LiteSATABISTIdentifyDriver:
def read_fifo(self): def read_fifo(self):
self.data = [] self.data = []
while self.source_stb.read(): while self.source_stb.read():
self.data.append(self.source_data.read()) dword = self.source_data.read()
word_lsb = dword & 0xffff
word_msb = (dword >> 16) & 0xffff
self.data += [word_lsb, word_msb]
self.source_ack.write(1) self.source_ack.write(1)
def run(self): def run(self):
@ -57,25 +64,30 @@ class LiteSATABISTIdentifyDriver:
def decode(self): def decode(self):
self.serial_number = "" self.serial_number = ""
for i, dword in enumerate(self.data[10:20]): for i, word in enumerate(self.data[10:20]):
try: s = word.to_bytes(2, byteorder='big').decode("utf-8")
s = dword.to_bytes(4, byteorder='big').decode("utf-8") self.serial_number += s
self.serial_number += s[2:] + s[:2] self.firmware_revision = ""
except: for i, word in enumerate(self.data[23:27]):
self.serial_number += " " s = word.to_bytes(2, byteorder='big').decode("utf-8")
self.firmware_revision += s
self.model_number = ""
for i, word in enumerate(self.data[27:46]):
s = word.to_bytes(2, byteorder='big').decode("utf-8")
self.model_number += s
self.total_sectors = self.data[100]
self.total_sectors += (self.data[101] << 16)
self.total_sectors += (self.data[102] << 32)
self.total_sectors += (self.data[103] << 48)
def hdd_info(self): def hdd_info(self):
info = "Serial Number: " + self.serial_number info = "Serial Number: " + self.serial_number + "\n"
# XXX: enhance decode function info += "Firmware Revision: " + self.firmware_revision + "\n"
info += "Model Number: " + self.model_number + "\n"
info += "Capacity: %3.2f GB\n" %((self.total_sectors*logical_sector_size)/GB)
print(info) print(info)
KB = 1024
MB = 1024*KB
GB = 1024*MB
# Note: use IDENTIFY command to find numbers of sectors
hdd_max_sector = (32*MB)/logical_sector_size
def _get_args(): def _get_args():
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
description="""\ description="""\
@ -104,7 +116,7 @@ if __name__ == "__main__":
random = int(args.random) random = int(args.random)
continuous = int(args.continuous) continuous = int(args.continuous)
try: try:
while (sector*logical_sector_size < length) or continuous: while ((sector*logical_sector_size < length) or continuous) and (sector < identify.total_sectors):
# generator (write data to HDD) # generator (write data to HDD)
write_speed, write_errors = generator.run(sector, count, random) write_speed, write_errors = generator.run(sector, count, random)