-
Notifications
You must be signed in to change notification settings - Fork 136
qdl: add QUD backend so on Windows flashing via the official QDLoader 9008 driver works #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
igoropaniuk
wants to merge
5
commits into
linux-msm:master
Choose a base branch
from
igoropaniuk:feat/qud-backend
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
184dd21
qdl: add --backend selector and QUD backend skeleton
igoropaniuk 75e030b
qud: add Windows backend for the QDLoader 9008 driver
igoropaniuk 3556c31
firehose: parse multi-document and rawmode-trailed reads
igoropaniuk 8763ba1
qdl: add auto backend that resolves USB/QUD inside the wait loop
igoropaniuk 6590558
usb: drop per-device open warning during enumeration
igoropaniuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| /* | ||
| * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| * | ||
| * QDL_DEVICE_AUTO: meta-backend that defers transport selection to the | ||
| * wait loop. Each 250 ms tick it runs both the libusb open attempt and | ||
| * (on Windows) a QUD SetupAPI probe; whichever first reaches an EDL | ||
| * device wins, and its concrete qdl_device is bound as the inner. All | ||
| * subsequent qdl_read/write/close calls on the outer forward to the | ||
| * inner. | ||
| */ | ||
|
|
||
| #include <errno.h> | ||
| #include <stdbool.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include "qdl.h" | ||
|
|
||
| struct qdl_device_auto { | ||
| struct qdl_device base; | ||
| struct qdl_device *inner; | ||
| long pending_chunk_size; | ||
| bool chunk_size_set; | ||
| }; | ||
|
|
||
| static struct qdl_device_auto *to_auto(struct qdl_device *qdl) | ||
| { | ||
| return container_of(qdl, struct qdl_device_auto, base); | ||
| } | ||
|
|
||
| static void auto_bind_inner(struct qdl_device_auto *wrap, struct qdl_device *inner) | ||
| { | ||
| wrap->inner = inner; | ||
| wrap->base.max_payload_size = inner->max_payload_size; | ||
| if (wrap->chunk_size_set) | ||
| inner->set_out_chunk_size(inner, wrap->pending_chunk_size); | ||
| } | ||
|
|
||
| static int auto_open(struct qdl_device *qdl, const char *serial) | ||
| { | ||
| struct qdl_device_auto *wrap = to_auto(qdl); | ||
| struct qdl_device *usb_dev; | ||
| #ifdef _WIN32 | ||
| struct qdl_device *qud_dev; | ||
| int qud_count; | ||
| #endif | ||
| int visible_prev = -1; | ||
| int visible; | ||
| int ret; | ||
|
|
||
| usb_dev = usb_init(); | ||
| if (!usb_dev) | ||
| return -1; | ||
|
|
||
| #ifdef _WIN32 | ||
| qud_dev = qud_init(); | ||
| if (!qud_dev) { | ||
| qdl_deinit(usb_dev); | ||
| return -1; | ||
| } | ||
| #endif | ||
|
|
||
| for (;;) { | ||
| ret = try_usb_open(usb_dev, serial, &visible); | ||
| if (ret == 0) { | ||
| #ifdef _WIN32 | ||
| qdl_deinit(qud_dev); | ||
| #endif | ||
| auto_bind_inner(wrap, usb_dev); | ||
| return 0; | ||
| } | ||
| if (ret == -EIO) | ||
| goto fail; | ||
|
|
||
| #ifdef _WIN32 | ||
| qud_count = qud_probe_present(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Been jumping back and forth in the patch here... It would be nice if the try_usb_open() and the qud path were symmetrical, but I haven't convinced myself if that's possible or not. |
||
| if (qud_count > 0 || ret == -EBUSY) { | ||
| if (qud_dev->open(qud_dev, serial) == 0) { | ||
| qdl_deinit(usb_dev); | ||
| auto_bind_inner(wrap, qud_dev); | ||
| return 0; | ||
| } | ||
| } | ||
| visible += qud_count; | ||
| #endif | ||
|
|
||
| if (visible != visible_prev) { | ||
| if (visible == 0) | ||
| ux_info("Waiting for EDL device\n"); | ||
| else if (serial) | ||
| ux_info("%d EDL device(s) visible, none match serial \"%s\"\n", | ||
| visible, serial); | ||
| else | ||
| ux_info("%d EDL device(s) visible, none could be opened\n", | ||
| visible); | ||
| visible_prev = visible; | ||
| } | ||
|
|
||
| usleep(250000); | ||
| } | ||
|
|
||
| fail: | ||
| qdl_deinit(usb_dev); | ||
| #ifdef _WIN32 | ||
| qdl_deinit(qud_dev); | ||
| #endif | ||
| return -1; | ||
| } | ||
|
|
||
| static int auto_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout) | ||
| { | ||
| struct qdl_device *inner = to_auto(qdl)->inner; | ||
|
|
||
| return inner->read(inner, buf, len, timeout); | ||
| } | ||
|
|
||
| static int auto_write(struct qdl_device *qdl, const void *buf, size_t len, unsigned int timeout) | ||
| { | ||
| struct qdl_device *inner = to_auto(qdl)->inner; | ||
|
|
||
| return inner->write(inner, buf, len, timeout); | ||
| } | ||
|
|
||
| static void auto_close(struct qdl_device *qdl) | ||
| { | ||
| struct qdl_device_auto *wrap = to_auto(qdl); | ||
|
|
||
| if (!wrap->inner) | ||
| return; | ||
| wrap->inner->close(wrap->inner); | ||
| qdl_deinit(wrap->inner); | ||
| wrap->inner = NULL; | ||
| } | ||
|
|
||
| static void auto_set_out_chunk_size(struct qdl_device *qdl, long size) | ||
| { | ||
| struct qdl_device_auto *wrap = to_auto(qdl); | ||
|
|
||
| if (wrap->inner) { | ||
| wrap->inner->set_out_chunk_size(wrap->inner, size); | ||
| return; | ||
| } | ||
| wrap->pending_chunk_size = size; | ||
| wrap->chunk_size_set = true; | ||
| } | ||
|
|
||
| struct qdl_device *auto_init(void) | ||
| { | ||
| struct qdl_device_auto *wrap = calloc(1, sizeof(*wrap)); | ||
|
|
||
| if (!wrap) | ||
| return NULL; | ||
|
|
||
| wrap->base.dev_type = QDL_DEVICE_AUTO; | ||
| wrap->base.open = auto_open; | ||
| wrap->base.read = auto_read; | ||
| wrap->base.write = auto_write; | ||
| wrap->base.close = auto_close; | ||
| wrap->base.set_out_chunk_size = auto_set_out_chunk_size; | ||
| wrap->base.max_payload_size = 1048576; | ||
|
|
||
| return &wrap->base; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can drop this _WIN32 later, when there is support for Linux QUD driver