scripts: dbgbmap[d3].py: Disabled gcksum checking by default

By default, we don't actually do anything if we find an invalid gcksum,
so there's no reason to calculate it everytime.

Though this performance improvement may not be very noticeable:

  dbgbmap.py w/  crc32c lib w/  no_ck --no-ckdata: 0m0.221s
  dbgbmap.py w/  crc32c lib w/o no_ck --no-ckdata: 0m0.269s
  dbgbmap.py w/o crc32c lib w/  no_ck --no-ckdata: 0m0.388s
  dbgbmap.py w/o crc32c lib w/o no_ck --no-ckdata: 0m0.490s
  dbgbmap.old.py:                                  0m0.231s

Note that there's no point in adopting this in dbgbmapd3.py: 1. svg
rendering dominates (probably, I haven't measured this), and 2. we
default to showing the littlefs mount string instead of mdir/btree/data
percentages.
This commit is contained in:
Christopher Haster
2025-04-07 15:57:35 -05:00
parent 3820be180d
commit 3ff25a4fdf
3 changed files with 109 additions and 52 deletions
+39 -18
View File
@@ -2733,6 +2733,7 @@ class Gstate:
locals()[g.__name__.lower()] = ft.cached_property(_parser(g)) locals()[g.__name__.lower()] = ft.cached_property(_parser(g))
# TODO sync
# high-level littlefs representation # high-level littlefs representation
class Lfs: class Lfs:
def __init__(self, bd, mtree, config=None, gstate=None, cksum=None, *, def __init__(self, bd, mtree, config=None, gstate=None, cksum=None, *,
@@ -2766,18 +2767,6 @@ class Lfs:
# is the filesystem corrupt? # is the filesystem corrupt?
self.corrupt = corrupt self.corrupt = corrupt
# check mroot
if not self.corrupt and not self.ckmroot():
self.corrupt = True
# check magic
if not self.corrupt and not self.ckmagic():
self.corrupt = True
# check gcksum
if not self.corrupt and not self.ckcksum():
self.corrupt = True
# create the root directory, this is a bit of a special case # create the root directory, this is a bit of a special case
self.root = self.Root(self) self.root = self.Root(self)
@@ -2870,11 +2859,41 @@ class Lfs:
@classmethod @classmethod
def fetch(cls, bd, blocks=None, trunk=None, *, def fetch(cls, bd, blocks=None, trunk=None, *,
depth=None): depth=None,
no_ck=False,
no_ckmroot=False,
no_ckmagic=False,
no_ckgcksum=False):
# Mtree does most of the work here # Mtree does most of the work here
mtree = Mtree.fetch(bd, blocks, trunk, mtree = Mtree.fetch(bd, blocks, trunk,
depth=depth) depth=depth)
return cls(bd, mtree)
# create lfs object
lfs = cls(bd, mtree)
# don't check anything?
if no_ck:
return lfs
# check mroot
if (not no_ckmroot
and not lfs.corrupt
and not lfs.ckmroot()):
lfs.corrupt = True
# check magic
if (not no_ckmagic
and not lfs.corrupt
and not lfs.ckmagic()):
lfs.corrupt = True
# check gcksum
if (not no_ckgcksum
and not lfs.corrupt
and not lfs.ckgcksum()):
lfs.corrupt = True
return lfs
# check that the mroot is valid # check that the mroot is valid
def ckmroot(self): def ckmroot(self):
@@ -2887,7 +2906,7 @@ class Lfs:
return self.config.magic.data == b'littlefs' return self.config.magic.data == b'littlefs'
# check that the gcksum checks out # check that the gcksum checks out
def ckcksum(self): def ckgcksum(self):
return crc32ccube(self.cksum) == int(self.gstate.gcksum) return crc32ccube(self.cksum) == int(self.gstate.gcksum)
# read custom attrs # read custom attrs
@@ -4367,7 +4386,9 @@ def main_(f, disk, mroots=None, *,
# fetch the filesystem # fetch the filesystem
bd = Bd(f_, block_size, block_count) bd = Bd(f_, block_size, block_count)
lfs = Lfs.fetch(bd, mroots, trunk) lfs = Lfs.fetch(bd, mroots, trunk,
# don't bother to check things if we're not reporting errors
no_ck=not args.get('error_on_corrupt'))
corrupted = not bool(lfs) corrupted = not bool(lfs)
# if we can't figure out the block_count, guess # if we can't figure out the block_count, guess
@@ -4676,7 +4697,7 @@ def main_(f, disk, mroots=None, *,
'mrweight': lfs.mrweightrepr(), 'mrweight': lfs.mrweightrepr(),
'cksum': '%08x%s' % ( 'cksum': '%08x%s' % (
lfs.cksum, lfs.cksum,
'' if lfs.ckcksum() else '?'), '' if lfs.ckgcksum() else '?'),
'mdir_count': mdir_count, 'mdir_count': mdir_count,
'mdir_percent': '%.1f%%' % (100*(mdir_count / len(bmap))), 'mdir_percent': '%.1f%%' % (100*(mdir_count / len(bmap))),
'btree_count': btree_count, 'btree_count': btree_count,
@@ -4694,7 +4715,7 @@ def main_(f, disk, mroots=None, *,
lfs.addr(), lfs.addr(),
lfs.mbweightrepr(), lfs.mrweightrepr(), lfs.mbweightrepr(), lfs.mrweightrepr(),
lfs.cksum, lfs.cksum,
'' if lfs.ckcksum() else '?')) '' if lfs.ckgcksum() else '?'))
else: else:
f.writeln('bd %sx%s, %6s mdir, %6s btree, %6s data' % ( f.writeln('bd %sx%s, %6s mdir, %6s btree, %6s data' % (
lfs.block_size if lfs.block_size is not None else '?', lfs.block_size if lfs.block_size is not None else '?',
+36 -18
View File
@@ -2795,18 +2795,6 @@ class Lfs:
# is the filesystem corrupt? # is the filesystem corrupt?
self.corrupt = corrupt self.corrupt = corrupt
# check mroot
if not self.corrupt and not self.ckmroot():
self.corrupt = True
# check magic
if not self.corrupt and not self.ckmagic():
self.corrupt = True
# check gcksum
if not self.corrupt and not self.ckcksum():
self.corrupt = True
# create the root directory, this is a bit of a special case # create the root directory, this is a bit of a special case
self.root = self.Root(self) self.root = self.Root(self)
@@ -2899,11 +2887,41 @@ class Lfs:
@classmethod @classmethod
def fetch(cls, bd, blocks=None, trunk=None, *, def fetch(cls, bd, blocks=None, trunk=None, *,
depth=None): depth=None,
no_ck=False,
no_ckmroot=False,
no_ckmagic=False,
no_ckgcksum=False):
# Mtree does most of the work here # Mtree does most of the work here
mtree = Mtree.fetch(bd, blocks, trunk, mtree = Mtree.fetch(bd, blocks, trunk,
depth=depth) depth=depth)
return cls(bd, mtree)
# create lfs object
lfs = cls(bd, mtree)
# don't check anything?
if no_ck:
return lfs
# check mroot
if (not no_ckmroot
and not lfs.corrupt
and not lfs.ckmroot()):
lfs.corrupt = True
# check magic
if (not no_ckmagic
and not lfs.corrupt
and not lfs.ckmagic()):
lfs.corrupt = True
# check gcksum
if (not no_ckgcksum
and not lfs.corrupt
and not lfs.ckgcksum()):
lfs.corrupt = True
return lfs
# check that the mroot is valid # check that the mroot is valid
def ckmroot(self): def ckmroot(self):
@@ -2916,7 +2934,7 @@ class Lfs:
return self.config.magic.data == b'littlefs' return self.config.magic.data == b'littlefs'
# check that the gcksum checks out # check that the gcksum checks out
def ckcksum(self): def ckgcksum(self):
return crc32ccube(self.cksum) == int(self.gstate.gcksum) return crc32ccube(self.cksum) == int(self.gstate.gcksum)
# read custom attrs # read custom attrs
@@ -4969,7 +4987,7 @@ def main(disk, output, mroots=None, *,
'mrweight': lfs.mrweightrepr(), 'mrweight': lfs.mrweightrepr(),
'cksum': '%08x%s' % ( 'cksum': '%08x%s' % (
lfs.cksum, lfs.cksum,
'' if lfs.ckcksum() else '?'), '' if lfs.ckgcksum() else '?'),
})) }))
else: else:
f.write('littlefs%s v%s.%s %sx%s %s w%s.%s, cksum %08x%s' % ( f.write('littlefs%s v%s.%s %sx%s %s w%s.%s, cksum %08x%s' % (
@@ -4981,7 +4999,7 @@ def main(disk, output, mroots=None, *,
lfs.addr(), lfs.addr(),
lfs.mbweightrepr(), lfs.mrweightrepr(), lfs.mbweightrepr(), lfs.mrweightrepr(),
lfs.cksum, lfs.cksum,
'' if lfs.ckcksum() else '?')) '' if lfs.ckgcksum() else '?'))
f.write('</tspan>') f.write('</tspan>')
if not no_mode and not no_javascript: if not no_mode and not no_javascript:
f.write('<tspan id="mode" x="%(x)d" y="1.1em" ' f.write('<tspan id="mode" x="%(x)d" y="1.1em" '
@@ -5660,7 +5678,7 @@ def main(disk, output, mroots=None, *,
lfs.addr(), lfs.addr(),
lfs.mbweightrepr(), lfs.mrweightrepr(), lfs.mbweightrepr(), lfs.mrweightrepr(),
lfs.cksum, lfs.cksum,
'' if lfs.ckcksum() else '?')) '' if lfs.ckgcksum() else '?'))
if args.get('error_on_corrupt') and corrupted: if args.get('error_on_corrupt') and corrupted:
sys.exit(2) sys.exit(2)
+34 -16
View File
@@ -2723,18 +2723,6 @@ class Lfs:
# is the filesystem corrupt? # is the filesystem corrupt?
self.corrupt = corrupt self.corrupt = corrupt
# check mroot
if not self.corrupt and not self.ckmroot():
self.corrupt = True
# check magic
if not self.corrupt and not self.ckmagic():
self.corrupt = True
# check gcksum
if not self.corrupt and not self.ckcksum():
self.corrupt = True
# create the root directory, this is a bit of a special case # create the root directory, this is a bit of a special case
self.root = self.Root(self) self.root = self.Root(self)
@@ -2827,11 +2815,41 @@ class Lfs:
@classmethod @classmethod
def fetch(cls, bd, blocks=None, trunk=None, *, def fetch(cls, bd, blocks=None, trunk=None, *,
depth=None): depth=None,
no_ck=False,
no_ckmroot=False,
no_ckmagic=False,
no_ckgcksum=False):
# Mtree does most of the work here # Mtree does most of the work here
mtree = Mtree.fetch(bd, blocks, trunk, mtree = Mtree.fetch(bd, blocks, trunk,
depth=depth) depth=depth)
return cls(bd, mtree)
# create lfs object
lfs = cls(bd, mtree)
# don't check anything?
if no_ck:
return lfs
# check mroot
if (not no_ckmroot
and not lfs.corrupt
and not lfs.ckmroot()):
lfs.corrupt = True
# check magic
if (not no_ckmagic
and not lfs.corrupt
and not lfs.ckmagic()):
lfs.corrupt = True
# check gcksum
if (not no_ckgcksum
and not lfs.corrupt
and not lfs.ckgcksum()):
lfs.corrupt = True
return lfs
# check that the mroot is valid # check that the mroot is valid
def ckmroot(self): def ckmroot(self):
@@ -2844,7 +2862,7 @@ class Lfs:
return self.config.magic.data == b'littlefs' return self.config.magic.data == b'littlefs'
# check that the gcksum checks out # check that the gcksum checks out
def ckcksum(self): def ckgcksum(self):
return crc32ccube(self.cksum) == int(self.gstate.gcksum) return crc32ccube(self.cksum) == int(self.gstate.gcksum)
# read custom attrs # read custom attrs
@@ -4531,7 +4549,7 @@ def main(disk, mroots=None, paths=None, *,
lfs.mbweightrepr(), lfs.mrweightrepr(), lfs.mbweightrepr(), lfs.mrweightrepr(),
lfs.rev, lfs.rev,
lfs.cksum, lfs.cksum,
'' if lfs.ckcksum() else '?')) '' if lfs.ckgcksum() else '?'))
# dynamically size the id field # dynamically size the id field
w_width = max( w_width = max(