From 57aa513163d5aa987dbec218f227578bf844fdde Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 10 Oct 2023 17:31:43 -0500 Subject: [PATCH] Tweaked debug prints to show more information during mount Now when you mount littlefs, the debug print shows a bit more info: lfs.c:7881:debug: Mounted littlefs v2.0 0x{0,1}.c63 w43.256, bd 4096x256 To dissassemble this a bit: littlefs v2.0 0x{0,1}.c63 w43.256, bd 4096x256 ^ ^ '-+-' ^ ^ ^ ^ ^ '-|-----|----|---|---|--------|---|-- major version '-----|----|---|---|--------|---|-- minor version '----|---|---|--------|---|-- mroot blocks | | | | | (1st is active) '---|---|--------|---|-- mroot trunk '---|--------|---|-- mtree weight '--------|---|-- mleaf weight '---|-- block size '-- block count dbglfs.py also shows the block device geometry now, as read from the mroot: $ ./scripts/dbglfs.py disk -B4096 littlefs v2.0 0x{0,1}.c63, rev 1, weight 43.256, bd 4096x256 ... This may be over-optimizing for testing, but the reason the mount debug is only one line is to avoid slowing down/messying test output. Both powerloss testing and remounts completely fill the output with mount prints that aren't actually all that useful. Also switching to prefering parens in debug info mainly for mismatched things. --- lfs.c | 27 +++++++++++++++++---------- scripts/dbglfs.py | 5 +++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lfs.c b/lfs.c index 5865c514..c90af525 100644 --- a/lfs.c +++ b/lfs.c @@ -2384,8 +2384,8 @@ static int lfsr_rbyd_fetchvalidate(lfs_t *lfs, lfsr_rbyd_t *rbyd, int err = lfsr_rbyd_fetch(lfs, rbyd, block, trunk); if (err) { if (err == LFS_ERR_CORRUPT) { - LFS_ERROR("Found corrupted rbyd " - "(0x%"PRIx32".%"PRIx32", 0x%08"PRIx32")", + LFS_ERROR("Found corrupted rbyd 0x%"PRIx32".%"PRIx32", " + "cksum 0x%08"PRIx32, block, trunk, cksum); } return err; @@ -2397,8 +2397,8 @@ static int lfsr_rbyd_fetchvalidate(lfs_t *lfs, lfsr_rbyd_t *rbyd, // above fetch failing, since that would require the rbyd to have the // same trunk and pass its internal cksum if (rbyd->cksum != cksum) { - LFS_ERROR("Found rbyd cksum mismatch " - "(0x%"PRIx32".%"PRIx32", 0x%08"PRIx32" != 0x%08"PRIx32")", + LFS_ERROR("Found rbyd cksum mismatch rbyd 0x%"PRIx32".%"PRIx32", " + "cksum 0x%08"PRIx32" (!= 0x%08"PRIx32")", rbyd->block, rbyd->trunk, rbyd->cksum, cksum); return LFS_ERR_CORRUPT; } @@ -6955,7 +6955,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *traversal, traversal->mdir.u.m.blocks, traversal->u.mtortoise.blocks) == 0) { LFS_ERROR("Cycle detected during mtree traversal " - "(0x{%"PRIx32",%"PRIx32"})", + "0x{%"PRIx32",%"PRIx32"}", traversal->mdir.u.m.blocks[0], traversal->mdir.u.m.blocks[1]); return LFS_ERR_CORRUPT; @@ -7041,7 +7041,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *traversal, return 0; } else { - LFS_ERROR("Weird mtree entry? (0x%"PRIx32")", tag); + LFS_ERROR("Weird mtree entry? 0x%"PRIx32, tag); return LFS_ERR_CORRUPT; } @@ -7119,7 +7119,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *traversal, return 0; } else { - LFS_ERROR("Weird mtree entry? (0x%"PRIx32")", binfo.tag); + LFS_ERROR("Weird mtree entry? 0x%"PRIx32, binfo.tag); return LFS_ERR_CORRUPT; } @@ -7878,9 +7878,16 @@ int lfsr_mount(lfs_t *lfs, const struct lfs_config *cfg) { // TODO this should use any configured values LFS_DEBUG("Mounted littlefs v%"PRId32".%"PRId32" " - "(bs=%"PRId32", bc=%"PRId32")", + "0x{%"PRIx32",%"PRIx32"}.%"PRIx32" " + "w%"PRId32".%"PRId32", " + "bd %"PRId32"x%"PRId32, LFS_DISK_VERSION_MAJOR, LFS_DISK_VERSION_MINOR, + lfs->mroot.u.m.blocks[0], + lfs->mroot.u.m.blocks[1], + lfs->mroot.u.m.trunk, + lfsr_mtree_weight(lfs) / lfsr_mleafweight(lfs), + lfsr_mleafweight(lfs), lfs->cfg->block_size, lfs->cfg->block_count); @@ -7897,8 +7904,8 @@ int lfsr_format(lfs_t *lfs, const struct lfs_config *cfg) { return err; } - LFS_DEBUG("Formatting littlefs v%"PRId32".%"PRId32" " - "(bs=%"PRId32", bc=%"PRId32")", + LFS_DEBUG("Formatting littlefs v%"PRId32".%"PRId32", " + "bd %"PRId32"x%"PRId32, LFS_DISK_VERSION_MAJOR, LFS_DISK_VERSION_MINOR, lfs->cfg->block_size, diff --git a/scripts/dbglfs.py b/scripts/dbglfs.py index 0f3b6236..784d6e41 100755 --- a/scripts/dbglfs.py +++ b/scripts/dbglfs.py @@ -1760,10 +1760,11 @@ def main(disk, mroots=None, *, #### actual debugging begins here # print some information about the filesystem - print('littlefs v%s.%s %s, rev %d, weight %d.%d' % ( + print('littlefs v%s.%s %s, rev %d, weight %d.%d, bd %dx%d' % ( config.version[0] if config.version[0] is not None else '?', config.version[1] if config.version[1] is not None else '?', - mroot.addr(), mroot.rev, bweight//mleaf_weight, 1*mleaf_weight)) + mroot.addr(), mroot.rev, bweight//mleaf_weight, 1*mleaf_weight, + config.block_limit+1, config.disk_limit+1)) # dynamically size the id field w_width = max(