Skip to content

[RFC] sim: implement proper Firehose protocol state machine#192

Open
igoropaniuk wants to merge 1 commit intolinux-msm:masterfrom
igoropaniuk:feat/simulation_mode_extended
Open

[RFC] sim: implement proper Firehose protocol state machine#192
igoropaniuk wants to merge 1 commit intolinux-msm:masterfrom
igoropaniuk:feat/simulation_mode_extended

Conversation

@igoropaniuk
Copy link
Contributor

Replace the stub sim_read()/sim_write() with a simulator that parses incoming XML commands and enqueues matching XML responses, mirroring the real Firehose device protocol. This decreases divergence in behavior between the real HW and the dry-run mode, giving better validation of the flashing process in dry-run mode.

sim_write() now dispatches based on the command tag:

  • configure: enqueue log + ACK echoing the same max payload size so firehose_try_configure() does not trigger a redundant exchange
  • program/read: enqueue log + rawmode=true ACK and transition to SIM_STATE_RAW_IN/RAW_OUT to track the raw binary transfer
  • erase/patch/setbootablestoragedrive/ufs: enqueue log + ACK
  • power: enqueue log + ACK and mark the simulator as closed

sim_read() first drains the XML response queue (ensuring protocol responses are delivered before any raw data), then serves zero-filled sector data in SIM_STATE_RAW_OUT, and returns -EIO once closed so the trailing drain in firehose_reset() completes immediately.

Since the simulator now produces correct protocol responses, remove the QDL_DEVICE_SIM early-return guards in firehose_read() and firehose_try_configure() that previously bypassed response parsing.

Pre-initialize qdl->sector_size = 4096 in sim_init() and only probe sector size in firehose_try_configure() if unset. Previously, the probe commands were executed during --createdigest dry-runs and included in the VIP digest table, but not issued during real VIP flashing (where probing is gated on VIP_DISABLED). This caused all subsequent digest entries to shift, resulting in hash mismatches on the device.

Replace the stub sim_read()/sim_write() with a simulator that parses
incoming XML commands and enqueues matching XML responses, mirroring the
real Firehose device protocol. This decreases divergence in behavior
between the real HW and the dry-run mode, giving better validation of the
flashing process in dry-run mode.

sim_write() now dispatches based on the command tag:
 - configure: enqueue log + ACK echoing the same max payload size so
   firehose_try_configure() does not trigger a redundant exchange
 - program/read: enqueue log + rawmode=true ACK and transition to
   SIM_STATE_RAW_IN/RAW_OUT to track the raw binary transfer
 - erase/patch/setbootablestoragedrive/ufs: enqueue log + ACK
 - power: enqueue log + ACK and mark the simulator as closed

sim_read() first drains the XML response queue (ensuring protocol responses
are delivered before any raw data), then serves zero-filled sector data in
SIM_STATE_RAW_OUT, and returns -EIO once closed so the trailing drain in
firehose_reset() completes immediately.

Since the simulator now produces correct protocol responses, remove the
QDL_DEVICE_SIM early-return guards in firehose_read() and
firehose_try_configure() that previously bypassed response parsing.

Pre-initialize qdl->sector_size = 4096 in sim_init() and only probe sector
size in firehose_try_configure() if unset. Previously, the probe <read>
commands were executed during --createdigest dry-runs and included in the
VIP digest table, but not issued during real VIP flashing (where probing is
gated on VIP_DISABLED). This caused all subsequent digest entries to shift,
resulting in hash mismatches on the device.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Copy link
Contributor

@lumag lumag left a comment

Choose a reason for hiding this comment

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

LGTM!

@igoropaniuk
Copy link
Contributor Author

Friendly ping 🙂 Please let me know if there are any additional concerns or comments. If everything looks good, this might be ready to land.

@lumag lumag requested review from andersson and konradybcio March 6, 2026 13:56
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