8000 firehose: restrict XML <erase> to NAND to prevent whole-LUN wipes on … by marlgian · Pull Request #847 · bkerler/edl · GitHub
[go: up one dir, main page]

Skip to content

firehose: restrict XML <erase> to NAND to prevent whole-LUN wipes on … - #847

Open
marlgian wants to merge 1 commit into
bkerler:masterfrom
marlgian:fix/firehose-cmd-erase-whole-lun
Open

marlgian wants to merge 1 commit into
bkerler:masterfrom
marlgian:fix/firehose-cmd-erase-whole-lun

Conversation

@marlgian
Copy link
Copy Markdown

Summary

Restricts the XML <erase> branch in firehose.cmd_erase() to self.cfg.MemoryName.lower() == "nand" so that e, es, and ep continue using safe zero-writing via <program> on eMMC/UFS/spinor devices.

Problem / Root Cause

Commit b2b0982 (PR #745, addressing NAND issue #522) added:

if "erase" in self.supported_functions:

inside cmd_erase(), sending <erase SECTOR_SIZE_IN_BYTES=... num_partition_sectors=... physical_partition_number=... start_sector=.../>.

However, on many Qualcomm eMMC and UFS Firehose loaders, the <erase> handler only parses physical_partition_number and ignores start_sector / num_partition_sectors, silently wiping the entire physical partition (LUN) — including GPT, sbl1, aboot, modemst1/modemst2, persist, and system — and returning ACK.

  • Reproduced on real hardware: Vivo Y53 (PD1628F, MSM8917, eMMC) using Loaders/vivo/000560e100000000_60ba997fef6da9f0_fhprg_peek.bin. Running edl.py es 7605248 64 --memory=emmc (or edl.py e userdata --memory=emmc) wiped the entire 16 GB eMMC LUN 0 to 0x00.
  • Scope across Loaders/: Scanning the 878 loader binaries in Loaders/ shows at least 244 loaders with whole-LUN-only <erase> handlers:
    • 208 loaders with the legacy physical_partition_number-only handler (No physical_partition_number, covering MSM8917, MSM8937, MSM8940, MSM8953, SDM450, etc.)
    • 36 loaders with In handleErase Calling storage_device_erase() without start_sector/num_partition_sectors support (e.g., MSM8996)
  • Additionally, get_supported_functions() falls back to a generic list that includes 'erase', causing the <erase> path to trigger even when supported functions are not reported.

Fix

Gate the XML <erase> path on self.cfg.MemoryName.lower() == "nand" (matching nand_pages_attr() and configure() from b2b0982), keeping NAND block erases working for #522 while restoring the safe <program> zero-write path for eMMC/UFS/spinor.

Testing

  • Verified with unit tests mocking xmlsend/cdc across emmc/eMMC, ufs/UFS, spinor, and nand/NAND (with and without 'erase' in supported_functions):
    • emmc/ufs/spinor: sends <program> + exact num_partition_sectors * SECTOR_SIZE_IN_BYTES zero bytes; never sends <erase>.
    • nand with 'erase': sends <erase> with PAGES_PER_BLOCK when configured.
    • nand without 'erase': falls back to <program>.
  • Verified syntax with python -m py_compile edlclient/Library/firehose.py.

…eMMC/UFS

Commit b2b0982 (PR bkerler#745, for NAND issue bkerler#522) updated cmd_erase() to send XML <erase> whenever 'erase' is in supported_functions. However, many Qualcomm eMMC/UFS Firehose loaders (244+ loaders in Loaders/, including MSM8917/8937/8940/8953/8996/SDM450) ignore start_sector and num_partition_sectors in handleErase and wipe the entire physical_partition_number (LUN).

Restrict the XML <erase> path to MemoryName == 'nand' so NAND block erases continue to work while eMMC/UFS/spinor safely zero-write only the requested sector range via <program>.
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.

1 participant

0