Autodetect lfs partition + geometry subcommand action#388
Conversation
…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.
|
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 :) |
| class Partition(NamedTuple): | ||
| address: int | ||
| size: int | ||
| type: str |
There was a problem hiding this comment.
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.
| uint32_t address; | ||
| uint32_t size; | ||
| char type[16]; | ||
| } gnwmanager_partition_t; |
There was a problem hiding this comment.
Add a comment pointing at what python code needs to know about this struct size (just so they don't drift).
| context->response_ready = 1; | ||
| } | ||
|
|
||
| static inline bool safe_memcmp(volatile const uint8_t *p1, const uint8_t *p2, size_t len) { |
There was a problem hiding this comment.
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.
| return true; | ||
| } | ||
|
|
||
| static bool is_lfs_superblock(uint32_t addr, uint32_t flash_size) { |
There was a problem hiding this comment.
I think this function should just be directly using lfs_fsinfo? But I'm not sure
| if (count < max_count) { | ||
| partitions[count].address = p_start; | ||
| partitions[count].size = p_size; | ||
| strcpy(partitions[count].type, "LittleFS"); |
There was a problem hiding this comment.
Each place where we have a "magic" string, we should reference which bit in python needs to match it.
| 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; |
There was a problem hiding this comment.
duplicate logic with is_lfs_superblock
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.