Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RAMDUMP_SRCS := ramdump.c sahara.c usb.c util.c ux.c
RAMDUMP_OBJS := $(RAMDUMP_SRCS:.c=.o)

KS_OUT := ks
KS_SRCS := ks.c sahara.c util.c ux.c
KS_SRCS := ks.c sahara.c util.c ux.c usb.c
KS_OBJS := $(KS_SRCS:.c=.o)

default: $(QDL) $(RAMDUMP) $(KS_OUT)
Expand Down
74 changes: 38 additions & 36 deletions ks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Copy link
Contributor

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?

Copy link
Author

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 in usb.c, I edited the usb.c implementation so that if the fd field in qdl 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 only ks uses file descriptors.


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");
Expand All @@ -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;
Expand All @@ -62,6 +52,7 @@ int main(int argc, char **argv)
{"version", no_argument, 0, 'v'},
{"port", required_argument, 0, 'p'},
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

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

Thats the has_args field, which states that the flag requires argument not that the flag itself is required

{"sahara", required_argument, 0, 's'},
{"serial", required_argument, 0, 'S'},
{0, 0, 0, 0}
};

Expand All @@ -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;
}
6 changes: 6 additions & 0 deletions usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Choose a reason for hiding this comment

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

I think defining a separate simple chardev backend would make more sense.. this works, but is not pretty


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))
Expand All @@ -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;

Expand Down
Loading