-
Notifications
You must be signed in to change notification settings - Fork 107
ks: Add support for libusb communication #100
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,28 +21,17 @@ static struct qdl_device qdl; | |
|
||
bool qdl_debug; | ||
|
||
int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout) | ||
{ | ||
return read(qdl->fd, buf, len); | ||
} | ||
|
||
int qdl_write(struct qdl_device *qdl, const void *buf, size_t len) | ||
{ | ||
|
||
return write(qdl->fd, buf, len); | ||
} | ||
|
||
static void print_usage(void) | ||
{ | ||
extern const char *__progname; | ||
fprintf(stderr, | ||
"%s -p <sahara dev_node> -s <id:file path> ...\n", | ||
"%s [--debug] [--serial <NUM>] [--port <sahara dev_node>] -s <id:file path> ...\n", | ||
__progname); | ||
fprintf(stderr, | ||
" -p --port Sahara device node to use\n" | ||
" -s <id:file path> --sahara <id:file path> Sahara protocol file mapping\n" | ||
"\n" | ||
"One -p instance is required. One or more -s instances are required.\n" | ||
"One or more -s instances are required\n" | ||
"\n" | ||
"Example: \n" | ||
"ks -p /dev/mhi0_QAIC_SAHARA -s 1:/opt/qti-aic/firmware/fw1.bin -s 2:/opt/qti-aic/firmware/fw2.bin\n"); | ||
|
@@ -52,6 +41,7 @@ int main(int argc, char **argv) | |
{ | ||
bool found_mapping = false; | ||
char *dev_node = NULL; | ||
char *serial = NULL; | ||
long file_id; | ||
char *colon; | ||
int opt; | ||
|
@@ -62,6 +52,7 @@ int main(int argc, char **argv) | |
{"version", no_argument, 0, 'v'}, | ||
{"port", required_argument, 0, 'p'}, | ||
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. This is still listed as required, but the documentation changes above suggest that this PR is making it optional 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. Thats the |
||
{"sahara", required_argument, 0, 's'}, | ||
{"serial", required_argument, 0, 'S'}, | ||
{0, 0, 0, 0} | ||
}; | ||
|
||
|
@@ -80,49 +71,60 @@ int main(int argc, char **argv) | |
case 's': | ||
found_mapping = true; | ||
file_id = strtol(optarg, NULL, 10); | ||
if (file_id < 0) { | ||
print_usage(); | ||
return 1; | ||
} | ||
if (file_id >= MAPPING_SZ) { | ||
fprintf(stderr, | ||
"ID:%ld exceeds the max value of %d\n", | ||
file_id, | ||
MAPPING_SZ - 1); | ||
return 1; | ||
} | ||
if (file_id < 0 || file_id >= MAPPING_SZ) | ||
errx(1, "ID:%ld has to be in range of 0 - %d\n", file_id, MAPPING_SZ - 1); | ||
|
||
colon = strchr(optarg, ':'); | ||
if (!colon) { | ||
print_usage(); | ||
return 1; | ||
} | ||
if (!colon) | ||
errx(1, "Sahara mapping requires ID and file path to be divided by a colon"); | ||
|
||
qdl.mappings[file_id] = &optarg[colon - optarg + 1]; | ||
printf("Created mapping ID:%ld File:%s\n", file_id, qdl.mappings[file_id]); | ||
break; | ||
case 'S': | ||
serial = optarg; | ||
break; | ||
default: | ||
print_usage(); | ||
return 1; | ||
} | ||
} | ||
|
||
// -p and -s is required | ||
if (!dev_node || !found_mapping) { | ||
// -s is required | ||
if (!found_mapping) { | ||
print_usage(); | ||
return 1; | ||
} | ||
|
||
if (qdl_debug) | ||
print_version(); | ||
|
||
qdl.fd = open(dev_node, O_RDWR); | ||
if (qdl.fd < 0) { | ||
fprintf(stderr, "Unable to open %s\n", dev_node); | ||
return 1; | ||
if (dev_node) { | ||
qdl.fd = open(dev_node, O_RDWR); | ||
if (qdl.fd < 0) { | ||
ret = 0; | ||
printf("Unable to open %s\n", dev_node); | ||
goto out_cleanup; | ||
} | ||
} | ||
else { | ||
ret = qdl_open(&qdl, serial); | ||
if (ret) { | ||
printf("Failed to find edl device\n"); | ||
goto out_cleanup; | ||
} | ||
} | ||
|
||
|
||
ret = sahara_run(&qdl, qdl.mappings, false, NULL, NULL); | ||
if (ret < 0) | ||
return 1; | ||
goto out_cleanup; | ||
|
||
out_cleanup: | ||
if (dev_node) | ||
close(qdl.fd); | ||
else | ||
qdl_close(&qdl); | ||
|
||
return 0; | ||
return !!ret; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,6 +217,9 @@ int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout | |
int actual; | ||
int ret; | ||
|
||
if (qdl->fd != 0) | ||
return read(qdl->fd, buf, len); | ||
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. I think defining a separate simple |
||
|
||
ret = libusb_bulk_transfer(qdl->usb_handle, qdl->in_ep, buf, len, &actual, timeout); | ||
if ((ret != 0 && ret != LIBUSB_ERROR_TIMEOUT) || | ||
(ret == LIBUSB_ERROR_TIMEOUT && actual == 0)) | ||
|
@@ -234,6 +237,9 @@ int qdl_write(struct qdl_device *qdl, const void *buf, size_t len) | |
int xfer; | ||
int ret; | ||
|
||
if (qdl->fd != 0) | ||
return write(qdl->fd, buf, len); | ||
|
||
while (len > 0) { | ||
xfer = (len > qdl->out_chunk_size) ? qdl->out_chunk_size : len; | ||
|
||
|
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.
How does removing these definitions not cause a compile error?
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.
These functions are defined in
qdl.h
and already implemented inusb.c
, I edited theusb.c
implementation so that if thefd
field inqdl
struct is defined the file descriptor is used instead of libusb. This solution is not ideal, but its the best I could come up with without more extensive changes to the codebase, which seem pointless as onlyks
uses file descriptors.