Always calculate/show cksum in dbgblock.py
Now that most scripts show relevant cksums, it makes sense for dbgblock.py to just always show a cksum as well. It's not like this has any noticable impact on the script's runtime. Example: $ ./scripts/dbgblock.py disk -b4096 0 block 0x0, size 4096, cksum e6e3ad25 00000000: 01 00 00 00 80 03 00 08 6c 69 74 74 6c 65 66 73 ........littlefs 00000010: 80 04 00 02 00 00 80 05 00 02 fa 01 80 09 00 04 ................ ...
This commit is contained in:
+11
-16
@@ -124,26 +124,25 @@ def main(disk, block=None, *,
|
||||
else off[1] - off[0] if isinstance(off, tuple) and len(off) > 1
|
||||
else block_size)
|
||||
|
||||
# print the header
|
||||
print('block %s, size %d' % (
|
||||
'0x%x.%x' % (block, off)
|
||||
if off is not None
|
||||
else '0x%x' % block,
|
||||
size))
|
||||
|
||||
# read the block
|
||||
f.seek((block * block_size) + (off or 0))
|
||||
data = f.read(size)
|
||||
|
||||
# calculate checksum
|
||||
cksum = crc32c(data)
|
||||
|
||||
# print the header
|
||||
print('block %s, size %d, cksum %08x' % (
|
||||
'0x%x.%x' % (block, off)
|
||||
if off is not None
|
||||
else '0x%x' % block,
|
||||
size,
|
||||
cksum))
|
||||
|
||||
# render the hex view
|
||||
for o, line in enumerate(xxd(data)):
|
||||
print('%08x: %s' % ((off or 0) + 16*o, line))
|
||||
|
||||
# render the checksum if requested
|
||||
if cksum:
|
||||
cksum = crc32c(data)
|
||||
print('%8s: %08x' % ('crc32c', cksum))
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
import sys
|
||||
@@ -178,10 +177,6 @@ if __name__ == "__main__":
|
||||
int(x, 0) if x.strip() else None
|
||||
for x in x.split(',')),
|
||||
help="Show this many bytes, may be a range.")
|
||||
parser.add_argument(
|
||||
'-c', '--cksum', '--crc32c',
|
||||
action='store_true',
|
||||
help="Calculate and show the crc32c of the data.")
|
||||
sys.exit(main(**{k: v
|
||||
for k, v in vars(parser.parse_intermixed_args()).items()
|
||||
if v is not None}))
|
||||
|
||||
Reference in New Issue
Block a user