Skip to content

Commit 6792629

Browse files
quic-bjorandeandersson
authored andcommitted
sahara: Deal with QUD discarding the HELLO request
When running on modern platforms it's observed that the Qualcomm USB Drivers will discard the HELLO request from the device, so we're forced to speculatively send a HELLO response on an initial timeout. In the event that the device is already in Firehose mode (from a previous --skip-reset run), the HELLO response will result in a XML parse error in the programmer, for which we catch the "<?xml" prefix and return to Firehose mode. Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
1 parent 908e3a7 commit 6792629

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

sahara.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,23 @@ static void sahara_send_reset(struct qdl_device *qdl)
124124
qdl_write(qdl, &resp, resp.length, SAHARA_CMD_TIMEOUT_MS);
125125
}
126126

127-
static int sahara_hello(struct qdl_device *qdl, struct sahara_pkt *pkt)
127+
static int sahara_send_hello_resp(struct qdl_device *qdl, unsigned int mode)
128128
{
129129
struct sahara_pkt resp = {};
130130

131+
resp.cmd = SAHARA_HELLO_RESP_CMD;
132+
resp.length = SAHARA_HELLO_LENGTH;
133+
resp.hello_resp.version = SAHARA_VERSION;
134+
resp.hello_resp.compatible = 1;
135+
resp.hello_resp.status = SAHARA_SUCCESS;
136+
resp.hello_resp.mode = mode;
137+
138+
qdl_write(qdl, &resp, resp.length, SAHARA_CMD_TIMEOUT_MS);
139+
return 0;
140+
}
141+
142+
static int sahara_hello(struct qdl_device *qdl, struct sahara_pkt *pkt)
143+
{
131144
if (pkt->length != SAHARA_HELLO_LENGTH) {
132145
ux_err("unexpected HELLO packet length %u\n", pkt->length);
133146
sahara_send_reset(qdl);
@@ -137,15 +150,7 @@ static int sahara_hello(struct qdl_device *qdl, struct sahara_pkt *pkt)
137150
ux_debug("HELLO version: 0x%x compatible: 0x%x max_len: %d mode: %d\n",
138151
pkt->hello_req.version, pkt->hello_req.compatible, pkt->hello_req.max_len, pkt->hello_req.mode);
139152

140-
resp.cmd = SAHARA_HELLO_RESP_CMD;
141-
resp.length = SAHARA_HELLO_LENGTH;
142-
resp.hello_resp.version = SAHARA_VERSION;
143-
resp.hello_resp.compatible = 1;
144-
resp.hello_resp.status = SAHARA_SUCCESS;
145-
resp.hello_resp.mode = pkt->hello_req.mode;
146-
147-
qdl_write(qdl, &resp, resp.length, SAHARA_CMD_TIMEOUT_MS);
148-
return 0;
153+
return sahara_send_hello_resp(qdl, pkt->hello_req.mode);
149154
}
150155

151156
static int sahara_read(struct qdl_device *qdl, struct sahara_pkt *pkt,
@@ -538,6 +543,19 @@ int sahara_run(struct qdl_device *qdl, const struct sahara_image *images,
538543
n = qdl_read(qdl, buf, sizeof(buf), SAHARA_CMD_TIMEOUT_MS);
539544
if (n < 0) {
540545
if (first_read && detect_firehose && n == -ETIMEDOUT) {
546+
/*
547+
* The QUD driver will eat the HELLO request on
548+
* many modern targets, so send an unsolicited
549+
* HELLO response.
550+
* If the device is already in Firehose mode,
551+
* the programmer will fail to parse the "XML"
552+
* message and report an error, which will
553+
* trigger below detection of a <?xml response.
554+
*/
555+
if (qdl->dev_type == QDL_DEVICE_QUD || qdl->dev_type == QDL_DEVICE_AUTO) {
556+
sahara_send_hello_resp(qdl, 0);
557+
continue;
558+
}
541559
ux_info("no Sahara HELLO received; assuming Firehose programmer is already running\n");
542560
return 0;
543561
}

0 commit comments

Comments
 (0)