mirror of
https://github.com/littlefs-project/littlefs.git
synced 2025-12-01 12:20:02 +00:00
Tweaked tracebd.py in a couple of ways, adopted bdgeom/--off/-n
- Tried to do the rescaling a bit better with truncating divisions, so there shouldn't be weird cross-pixel updates when things aren't well aligned. - Adopted optional -B<block_size>x<block_count> flag for explicitly specifying the block-device geometry in a way that is compatible with other scripts. Should adopt this more places. - Adopted optional <block>.<off> argument for start of range. This should match dbgblock.py. - Adopted '-' for noop/zero-wear. - Renamed a few internal things. - Dropped subscript chars for wear, this didn't really add anything and can be accomplished by specifying the --wear-chars explicitly. Also changed dbgblock.py to match, this mostly affects the --off/-n/--size flags. For example, these are all the same: ./scripts/dbgblock.py disk -B4096 --off=10 --size=5 ./scripts/dbgblock.py disk -B4096 --off=10 -n5 ./scripts/dbgblock.py disk -B4096 --off=10,15 ./scripts/dbgblock.py disk -B4096 -n10,15 ./scripts/dbgblock.py disk -B4096 0.10 -n5 Also also adopted block-device geometry argument across scripts, where the -B flag can optionally be a full <block_size>x<block_count> geometry: ./scripts/tracebd.py disk -B4096x256 Though this is mostly unused outside of tracebd.py right now. It will be useful for anything that formats littlefs (littlefs-fuse?) and allowing the format everywhere is a bit of a nice convenience.
This commit is contained in:
@ -51,10 +51,34 @@ TAG_GT = 0x2000
|
||||
TAG_R = 0x1000
|
||||
|
||||
|
||||
# some ways of block geometry representations
|
||||
# 512 -> 512
|
||||
# 512x16 -> (512, 16)
|
||||
# 0x200x10 -> (512, 16)
|
||||
def bdgeom(s):
|
||||
s = s.strip()
|
||||
b = 10
|
||||
if s.startswith('0x') or s.startswith('0X'):
|
||||
s = s[2:]
|
||||
b = 16
|
||||
elif s.startswith('0o') or s.startswith('0O'):
|
||||
s = s[2:]
|
||||
b = 8
|
||||
elif s.startswith('0b') or s.startswith('0B'):
|
||||
s = s[2:]
|
||||
b = 2
|
||||
|
||||
if 'x' in s:
|
||||
s, s_ = s.split('x', 1)
|
||||
return (int(s, b), int(s_, b))
|
||||
else:
|
||||
return int(s, b)
|
||||
|
||||
# parse some rbyd addr encodings
|
||||
# 0xa -> [0xa]
|
||||
# 0xa.b -> ([0xa], b)
|
||||
# 0x{a,b} -> [0xa, 0xb]
|
||||
# 0xa -> [0xa]
|
||||
# 0xa.c -> [(0xa, 0xc)]
|
||||
# 0x{a,b} -> [0xa, 0xb]
|
||||
# 0x{a,b}.c -> [(0xa, 0xc), (0xb, 0xc)]
|
||||
def rbydaddr(s):
|
||||
s = s.strip()
|
||||
b = 10
|
||||
@ -525,6 +549,7 @@ class Rbyd:
|
||||
|
||||
def main(disk, roots=None, *,
|
||||
block_size=None,
|
||||
block_count=None,
|
||||
trunk=None,
|
||||
color='auto',
|
||||
**args):
|
||||
@ -536,6 +561,12 @@ def main(disk, roots=None, *,
|
||||
else:
|
||||
color = False
|
||||
|
||||
# is bd geometry specified?
|
||||
if isinstance(block_size, tuple):
|
||||
block_size, block_count_ = block_size
|
||||
if block_count is None:
|
||||
block_count = block_count_
|
||||
|
||||
# flatten roots, default to block 0
|
||||
if not roots:
|
||||
roots = [[0]]
|
||||
@ -983,8 +1014,12 @@ if __name__ == "__main__":
|
||||
help="Block address of the roots of the tree.")
|
||||
parser.add_argument(
|
||||
'-B', '--block-size',
|
||||
type=bdgeom,
|
||||
help="Block size/geometry in bytes.")
|
||||
parser.add_argument(
|
||||
'--block-count',
|
||||
type=lambda x: int(x, 0),
|
||||
help="Block size in bytes.")
|
||||
help="Block count in blocks.")
|
||||
parser.add_argument(
|
||||
'--trunk',
|
||||
type=lambda x: int(x, 0),
|
||||
|
||||
Reference in New Issue
Block a user