Skip to content

Add Qualcomm IQ9075 recovery support and improve sparse image handling - #94

Open
BakyarajM wants to merge 2 commits into
bootlin:mainfrom
BakyarajM:qcom-iq9075-upstream
Open

Add Qualcomm IQ9075 recovery support and improve sparse image handling#94
BakyarajM wants to merge 2 commits into
bootlin:mainfrom
BakyarajM:qcom-iq9075-upstream

Conversation

@BakyarajM

Copy link
Copy Markdown

snagrecover: qcom: Add IQ9075 support

Add support for Qualcomm IQ9075 devices in snagrecover.

Implement Qualcomm Sahara protocol support to communicate with
Qualcomm devices in EDL mode and perform device recovery.

Reference:
https://github.com/torvalds/linux/blob/master/drivers/accel

_Note:
The U-Boot changes required to support snagrecover are currently
under review. Therefore, the U-Boot image preparation section in
docs/snagrecover.md is marked as TBD.

The documentation will be updated and the TBD item resolved before
the final upstream submission._

snagflash: Improve sparse file handling

Handle sparse chunks larger than max-download-size and preserve
DONT_CARE prefix and suffix regions when splitting sparse images.

Ignore CRC32 chunks from the source sparse image during splitting,
as the original CRC32 is no longer valid once the image is split or
modified.

Fix fastboot flash argument parsing for UFS flash type by splitting
only on the first ':' character, preserving target identifiers in
the format : while maintaining compatibility with
other flash types.

Replace the existing split() implementation with the streaming-based
split_streaming() generator to enable more memory-efficient
processing of large sparse images.

_Future enhancements:

  • Generate and append a new CRC32 chunk for each split sparse image
    based on its modified content.
  • Convert raw images to sparse format and flash them as multiple
    sparse images when the image size exceeds the target's
    max-download-size limit._

Reference:
https://android.googlesource.com/platform/system/core/+/refs/heads/main/libsparse/

Signed-off-by: Bakyaraj Moorthy bmoorthy@qti.qualcomm.com

@rgantois rgantois left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi, thanks a lot for the contribution! I've requested a few modifications. For the changes in snagflash/android_sparse_file/utils.py, I'll do a more in depth review once you've implemented the formatting changes I've requested. For all other files, no further review should be required once the current requested changes are implemented.

Comment thread docs/snagrecover.md Outdated

### Qualcomm

#### IQ9075

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since there is only one Qualcomm SoC family supported for now, you can save a title level and just do ### Qualcomm IQ9075

@BakyarajM BakyarajM Aug 9, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, merged the two heading levels into a single ### Qualcomm IQ9075 heading.

Comment thread docs/snagrecover.md
#### IQ9075

To set up the board in recovery mode, refer to the section *"Force the device
into Emergency Download mode"* in the reference [documentation](https://docs.qualcomm.com/doc/80-70023-261/topic/iq9-ug-update-the-sw.html#panel-0-VWJ1bnR1tab$force-the-device-into-emergency-download-mode)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Snagrecover is supposed to be SoC agnostic; of course it's completely fine to add a board-specific example, but you should specify that it's board-specific (in this case for the EVK).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added a note clarifying that the reference documentation steps are the same for both EVK and non-EVK boards, except for the DIP switch position — which is EVK-specific and requires checking the board schematic. Other boards should refer to their vendor's documentation for the equivalent step.

Comment thread docs/snagrecover.md Outdated

### For Qualcomm devices

#### IQ9075

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ditto, you can have a single title level here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

Comment thread docs/snagrecover.md

**xbl:** XBL is a Qualcomm proprietary image, which can be downloaded using the following steps:

1. Download the [ZIP](https://softwarecenter.qualcomm.com/nexus/generic/product/chip/tech-package/QCS9100_bootbinaries.1.0/qcs9100_bootbinaries.1.0-test-device-public/00133/QCS9100_bootbinaries.zip) file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this binary identical for all boards using this SoC? If not, please specify that this binary only works with board xyz and provide a generic description of how to get the binary for other boards such as "request the binary from your board vendor".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, this XBL binary is generic to the IQ9075 SoC and is identical across all boards using it, so no board-specific note is needed here.

Comment thread docs/snagrecover.md Outdated
configuration:
* path

**u-boot:** TBD: U-Boot support for Snagboot recovery is currently under upstream review

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fine by me, but maybe provide a link to the patch series in question so that people can test it if they want to?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added a link to the patch series: https://marc.info/?l=u-boot&m=178577211945398&w=2

Comment thread src/snagrecover/protocols/fastboot.py Outdated
if maxsize == 0:
raise FastbootError("Fastboot variable max-download-size is 0")
arg_list = args.split(":")
arg_list = args.split(":",1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: space between function arguments.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

Comment thread src/snagrecover/protocols/fastboot.py Outdated

for split_file in split_streaming(fname, temppath, maxsize):
split_count += 1
logger.info(f"Processing split {split_count}: Downloading {split_file}")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be nice to also have the total number of slices for each log.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, added the total split count to all per-split log/error messages, e.g. "split 3/12".

# SPDX-License-Identifier: GPL-2.0+
#
# Author: Arnaud Patard <arnaud.patard@collabora.com>
#

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a Modified-by: line, similarly to what we did in other files in the codebase. This helps represent the timeline of modifications more accurately.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

However, I could not find any other files in this repository that use a Modified-by: entry. If there are existing examples that follow this convention, could you please point me to them? I may have overlooked them.

# Reserve space for the trailing DONT_CARE suffix chunk header
_SUFFIX_RESERVE = SPARSE_CHUNKHEADER_LEN

def ensure_prefix_skip():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please don't use inline function definitions, it adds unnecessary indentation levels and makes things harder to read IMO.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, removed the inline nested functions and replaced them with module-level functions using an explicit state object instead of closures.


return dest

try:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please factor this part into multiple functions, currently it's quite hard to review.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, factored the chunk-processing loop into three separate functions, one per chunk type (process_raw_chunk, process_dontcare_chunk, process_fill_chunk). split_streaming() now just orchestrates the dispatch between them.

Add support for Qualcomm IQ9075 in snagrecover.

Implement Qualcomm Sahara protocol support to communicate with
Qualcomm devices in EDL mode and perform device recovery.

Reference:
https://github.com/torvalds/linux/blob/master/drivers/accel/qaic/sahara.c

Signed-off-by: Bakyaraj Moorthy <bmoorthy@qti.qualcomm.com>
Handle sparse chunks larger than max-download-size and preserve
DONT_CARE prefix and suffix regions when splitting sparse images.

Ignore CRC32 chunks from the source sparse image during splitting,
as the original CRC32 is no longer valid once the image is split or
modified.

Fix fastboot flash argument parsing for UFS flash type by splitting
only on the first ':' character, preserving target identifiers in
the format <lun>:<partition> while maintaining compatibility with
other flash types.

Replace the existing split() implementation with the streaming-based
split_streaming() generator to enable more memory-efficient
processing of large sparse images.

Future enhancements:
- Generate and append a new CRC32 chunk for each split sparse image
  based on its modified content.
- Convert raw images to sparse format and flash them as multiple
  sparse images when the image size exceeds the target's
  max-download-size limit.

Reference:
https://android.googlesource.com/platform/system/core/+/refs/heads/main/libsparse/

Signed-off-by: Bakyaraj Moorthy <bmoorthy@qti.qualcomm.com>
@BakyarajM
BakyarajM force-pushed the qcom-iq9075-upstream branch from 35aa3e4 to 407669e Compare August 9, 2026 11:11
@BakyarajM

Copy link
Copy Markdown
Author

Hi, thanks a lot for the contribution! I've requested a few modifications. For the changes in snagflash/android_sparse_file/utils.py, I'll do a more in depth review once you've implemented the formatting changes I've requested. For all other files, no further review should be required once the current requested changes are implemented.

@BakyarajM BakyarajM closed this Aug 9, 2026
@BakyarajM BakyarajM reopened this Aug 9, 2026
@BakyarajM

Copy link
Copy Markdown
Author

Hi, thanks for the detailed review!
I've replied individually to each review comment thread with more details. All addressed changes for the comments are now pushed — please take another look.

@BakyarajM
BakyarajM requested a review from rgantois August 9, 2026 11:52
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