forked from Imagelibrary/littlefs
Added dbgtag.py for easy tag decoding on the command-line
Example: $ ./scripts/dbgtag.py 0x3001 cksum 0x01 dbgtag.py inherits most of crc32c.py's decoding options. The most useful probably being -x/--hex: $ ./scripts/dbgtag.py -x e1 00 01 8a 09 altbgt 0x100 w1 -1162 dbgtag.py also supports reading from a block device if either -b/--block-size or --off are provided. This is mainly for consistency with the other dbg*.py scripts: $ ./scripts/dbgtag.py disk -b4096 0x2.1e4 bookmark w1 1 This should help when debugging and finding a raw tag/alt in some register. Manually decoding is just an unnecessary road bump when this happens.
This commit is contained in:
@@ -155,14 +155,14 @@ def xxd(data, width=16):
|
||||
b if b >= ' ' and b <= '~' else '.'
|
||||
for b in map(chr, data[i:i+width])))
|
||||
|
||||
def tagrepr(tag, w, size, off=None):
|
||||
if (tag & 0xefff) == TAG_NULL:
|
||||
def tagrepr(tag, w=None, size=None, off=None):
|
||||
if (tag & 0x6fff) == TAG_NULL:
|
||||
return '%snull%s%s' % (
|
||||
'shrub' if tag & TAG_SHRUB else '',
|
||||
' w%d' % w if w else '',
|
||||
' %d' % size if size else '')
|
||||
elif (tag & 0xef00) == TAG_CONFIG:
|
||||
return '%s%s%s %d' % (
|
||||
elif (tag & 0x6f00) == TAG_CONFIG:
|
||||
return '%s%s%s%s' % (
|
||||
'shrub' if tag & TAG_SHRUB else '',
|
||||
'magic' if (tag & 0xfff) == TAG_MAGIC
|
||||
else 'version' if (tag & 0xfff) == TAG_VERSION
|
||||
@@ -174,16 +174,16 @@ def tagrepr(tag, w, size, off=None):
|
||||
else 'namelimit' if (tag & 0xfff) == TAG_NAMELIMIT
|
||||
else 'config 0x%02x' % (tag & 0xff),
|
||||
' w%d' % w if w else '',
|
||||
size)
|
||||
elif (tag & 0xef00) == TAG_GDELTA:
|
||||
return '%s%s%s %d' % (
|
||||
' %s' % size if size is not None else '')
|
||||
elif (tag & 0x6f00) == TAG_GDELTA:
|
||||
return '%s%s%s%s' % (
|
||||
'shrub' if tag & TAG_SHRUB else '',
|
||||
'grmdelta' if (tag & 0xfff) == TAG_GRMDELTA
|
||||
else 'gdelta 0x%02x' % (tag & 0xff),
|
||||
' w%d' % w if w else '',
|
||||
size)
|
||||
elif (tag & 0xef00) == TAG_NAME:
|
||||
return '%s%s%s %d' % (
|
||||
' %s' % size if size is not None else '')
|
||||
elif (tag & 0x6f00) == TAG_NAME:
|
||||
return '%s%s%s%s' % (
|
||||
'shrub' if tag & TAG_SHRUB else '',
|
||||
'name' if (tag & 0xfff) == TAG_NAME
|
||||
else 'reg' if (tag & 0xfff) == TAG_REG
|
||||
@@ -192,9 +192,9 @@ def tagrepr(tag, w, size, off=None):
|
||||
else 'bookmark' if (tag & 0xfff) == TAG_BOOKMARK
|
||||
else 'name 0x%02x' % (tag & 0xff),
|
||||
' w%d' % w if w else '',
|
||||
size)
|
||||
elif (tag & 0xef00) == TAG_STRUCT:
|
||||
return '%s%s%s %d' % (
|
||||
' %s' % size if size is not None else '')
|
||||
elif (tag & 0x6f00) == TAG_STRUCT:
|
||||
return '%s%s%s%s' % (
|
||||
'shrub' if tag & TAG_SHRUB else '',
|
||||
'data' if (tag & 0xfff) == TAG_DATA
|
||||
else 'block' if (tag & 0xfff) == TAG_BLOCK
|
||||
@@ -208,43 +208,47 @@ def tagrepr(tag, w, size, off=None):
|
||||
else 'mtree' if (tag & 0xfff) == TAG_MTREE
|
||||
else 'struct 0x%02x' % (tag & 0xff),
|
||||
' w%d' % w if w else '',
|
||||
size)
|
||||
elif (tag & 0xef00) == TAG_UATTR:
|
||||
return '%suattr 0x%02x%s %d' % (
|
||||
' %s' % size if size is not None else '')
|
||||
elif (tag & 0x6e00) == TAG_UATTR:
|
||||
return '%suattr 0x%02x%s%s' % (
|
||||
'shrub' if tag & TAG_SHRUB else '',
|
||||
((tag & 0x100) >> 1) | (tag & 0xff),
|
||||
' w%d' % w if w else '',
|
||||
size)
|
||||
elif (tag & 0xef00) == TAG_SATTR:
|
||||
return '%ssattr 0x%02x%s %d' % (
|
||||
' %s' % size if size is not None else '')
|
||||
elif (tag & 0x6e00) == TAG_SATTR:
|
||||
return '%ssattr 0x%02x%s%s' % (
|
||||
'shrub' if tag & TAG_SHRUB else '',
|
||||
((tag & 0x100) >> 1) | (tag & 0xff),
|
||||
' w%d' % w if w else '',
|
||||
size)
|
||||
elif (tag & 0xff00) == TAG_CKSUM:
|
||||
return 'cksum 0x%02x%s %d' % (
|
||||
' %s' % size if size is not None else '')
|
||||
elif (tag & 0x7f00) == TAG_CKSUM:
|
||||
return 'cksum 0x%02x%s%s' % (
|
||||
tag & 0xff,
|
||||
' w%d' % w if w > 0 else '',
|
||||
size)
|
||||
elif (tag & 0xff00) == TAG_ECKSUM:
|
||||
return 'ecksum%s%s %d' % (
|
||||
' w%d' % w if w else '',
|
||||
' %s' % size if size is not None else '')
|
||||
elif (tag & 0x7f00) == TAG_ECKSUM:
|
||||
return 'ecksum%s%s%s' % (
|
||||
' 0x%02x' % (tag & 0xff) if tag & 0xff else '',
|
||||
' w%d' % w if w > 0 else '',
|
||||
size)
|
||||
' w%d' % w if w else '',
|
||||
' %s' % size if size is not None else '')
|
||||
elif tag & TAG_ALT:
|
||||
return 'alt%s%s%s w%d %s' % (
|
||||
return 'alt%s%s%s%s%s' % (
|
||||
'r' if tag & TAG_R else 'b',
|
||||
'a' if tag & 0x0fff == 0 and tag & TAG_GT
|
||||
else 'n' if tag & 0x0fff == 0
|
||||
else 'gt' if tag & TAG_GT
|
||||
else 'le',
|
||||
' 0x%x' % (tag & 0x0fff) if tag & 0x0fff != 0 else '',
|
||||
w,
|
||||
'0x%x' % (0xffffffff & (off-size))
|
||||
if off is not None
|
||||
else '-%d' % off)
|
||||
' w%d' % w if w is not None else '',
|
||||
' 0x%x' % (0xffffffff & (off-size))
|
||||
if size is not None and off is not None
|
||||
else ' -%d' % size if size is not None
|
||||
else '')
|
||||
else:
|
||||
return '0x%04x w%d %d' % (tag, w, size)
|
||||
return '0x%04x%s%s' % (
|
||||
tag,
|
||||
' w%d' % w if w is not None else '',
|
||||
' %d' % size if size is not None else '')
|
||||
|
||||
|
||||
def dbg_log(data, block_size, rev, eoff, weight, *,
|
||||
|
||||
Reference in New Issue
Block a user