better dpctl output for persistent storage

This commit is contained in:
Triss 2021-08-26 21:39:02 +02:00
parent 383dcc4ea9
commit 493be92bd2
2 changed files with 15 additions and 3 deletions

View File

@ -88,7 +88,14 @@ def set_mode(dev: DPDevice, mode: int) -> int:
def storage_info(dev: DPDevice) -> int:
try:
res = dev.storage_info()
print(repr(res)) # TODO
print("magic: %s, version=%04x, current mode=%d, #modes=%d, DJB2(table)=%d" \
% (('OK' if res.magic == b'\xf0\x9f\x8f\xb3\xef\xb8\x8f\xe2\x80\x8d\xe2\x9a\xa7\xef\xb8\x8f' else 'BAD!'),
res.version, res.curmode, res.nmodes, res.table_djb2))
for md in res.mode_data:
print("\tmode %d version %04x: 0x%x..+0x%x, DJB2=%d" % \
(md.mode, md.version, md.offset, md.datasize, md.data_djb2))
if len(res.mode_data) == 0:
print("No mode data");
return 0
except Exception as e:
print("Could not get storage info: %s" % str(e))

View File

@ -54,7 +54,7 @@ class StorageInfo(NamedTuple):
mag = b[:16]
ver, cm, nm = struct.unpack('<HBB', b[16:20])
res = b[20:28] + b[245-32:]
d2tab = struct.unpack('<I', b[28:32])
d2tab = struct.unpack('<I', b[28:32])[0]
mdat = StorageInfoMode.list_from_bytes(b[32:256-32])
@ -62,6 +62,11 @@ class StorageInfo(NamedTuple):
return StorageInfo(mag, ver, cm, nm, res, d2tab, mdat)
def __str__(self):
return "StorageInfo(magic=%s, version=%d, curmode=%d, nmodes=%d, table_djb2=%d, mode_data=%s)" \
% (' '.join(hex(b) for b in self.magic), self.version,
self.curmode, self.nmodes, self.table_djb2, repr(self.mode_data))
class JtagMatch(NamedTuple):
tck: int
@ -302,7 +307,7 @@ class DPDevice:
cmd[1] = mode
self.write(cmd)
stat, pl = self.read_resp()
check_statpl(stat, pl, "get storage data", -1, -1)
check_statpl(stat, pl, "get storage data", None, None)
return pl # TODO: parse