Skip to content

Autodetect lfs partition + geometry subcommand action#388

Draft
slash-proc wants to merge 1 commit into
BrianPugh:mainfrom
slash-proc:autodetect-lfs-partition-geometry
Draft

Autodetect lfs partition + geometry subcommand action#388
slash-proc wants to merge 1 commit into
BrianPugh:mainfrom
slash-proc:autodetect-lfs-partition-geometry

Conversation

@slash-proc

@slash-proc slash-proc commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

This commit adds more robust LFS partition detection and a general partition geometry scanner that runs on-device by quickly checking for known signatures/partition data.

  • Add on-device flash geometry scan action to query stock/patched assets and OFW backups, FAT, FrogFS, and LittleFS partitions.
  • Scan geometry up to the end of flash, scanning for both forward and inverted LittleFS partition superblocks.
  • All LFS candidates, including overlapping or corrupt ones, are fully listed.
  • Only perform filesystem actions on a valid LFS partition
  • Multiple valid LFS partitions raise TooManyLFSPartitionsFoundError and explicitly tell the user to use "--offset" to specify which should be used (rare edge case)
  • Display LFS integrity test results (Active/Intact vs Corrupt/Stale) in geometry command notes and cleanly format output column widths.
image

…ction

- Add on-device flash geometry scan action to query stock/patched firmware assets, Pat(Int) backups, FAT, FrogFS, and LittleFS partitions.
- Avoid alignment HardFaults on STM32 OSPI memory by forcing byte-by-byte reads during LittleFS magic checks.
- Scan geometry up to the end of flash, scanning for both forward and inverted LittleFS partition superblocks.
- Bypass coverage-skip checks for LittleFS partitions to ensure all LFS candidates, including overlapping or corrupt ones, are fully listed.
- Resolve presentation-layer partition name mapping on the host side, suffixing patched filesystems/assets with "(Patched)" while keeping stock ones clean.
- Display LFS integrity test results (Active/Intact vs Corrupt/Stale) in geometry command notes and cleanly format output column widths.
- Gracefully catch and display user-friendly error messages for TooManyLFSPartitionsFoundError and MissingThirdPartyError instead of full tracebacks.
@slash-proc

Copy link
Copy Markdown
Contributor Author

do you have any thoughts on this? I know I've peppered you with PRs but this is the one I'm most cuious about :)

Comment thread gnwmanager/gnw.py
class Partition(NamedTuple):
address: int
size: int
type: str

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets make this some sort of StrEnum so it's easier to enumerate all of the different Partition types. I think this would also then replace the _PTYPE_MAP below.

Comment thread Core/Src/gnwmanager.c
uint32_t address;
uint32_t size;
char type[16];
} gnwmanager_partition_t;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment pointing at what python code needs to know about this struct size (just so they don't drift).

Comment thread Core/Src/gnwmanager.c
context->response_ready = 1;
}

static inline bool safe_memcmp(volatile const uint8_t *p1, const uint8_t *p2, size_t len) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just memcmp? Maybe the AI was attempting a constant-time memcmp (it saw sha256 hashes and was maybe thinking of security?) but still failed? In any case, this would be unnecessary.

Comment thread Core/Src/gnwmanager.c
return true;
}

static bool is_lfs_superblock(uint32_t addr, uint32_t flash_size) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function should just be directly using lfs_fsinfo? But I'm not sure

Comment thread Core/Src/gnwmanager.c
if (count < max_count) {
partitions[count].address = p_start;
partitions[count].size = p_size;
strcpy(partitions[count].type, "LittleFS");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each place where we have a "magic" string, we should reference which bit in python needs to match it.

Comment thread Core/Src/gnwmanager.c
const uint8_t *block = (const uint8_t *)sb_addr;
uint32_t block_size = block[24] | (block[25] << 8) | (block[26] << 16) | (block[27] << 24);
uint32_t block_count = block[28] | (block[29] << 8) | (block[30] << 16) | (block[31] << 24);
uint32_t p_size = block_size * block_count;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate logic with is_lfs_superblock

Comment thread Core/Src/gnwmanager.c
@slash-proc slash-proc marked this pull request as draft June 23, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants