Skip to content

Commit

Permalink
exit if a program operation is already pending
Browse files Browse the repository at this point in the history
If flashing gets interrupted while the device is receiving the
firmware, it will stay in program mode. Inform the user about it
  • Loading branch information
dexter93 committed Sep 14, 2024
1 parent 021a655 commit a08fa7d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions sonixflasher.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ static void display_version(char *m_name) {
fprintf(stderr, "%s " PROJECT_VER "\n", m_name);
}

void cleanup(hid_device *handle) {
if (handle) hid_close(handle);
if (hid_exit() != 0) {
fprintf(stderr, "ERROR: Could not close the device.\n");
}
}

void error(hid_device *handle) {
cleanup(handle);
exit(1);
}

void clear_buffer(unsigned char *data, size_t length) {
for (int i = 0; i < length; i++)
data[i] = 0;
Expand Down Expand Up @@ -431,6 +443,10 @@ bool hid_get_feature(hid_device *dev, unsigned char *data, size_t data_size, uin
return true;
} else {
fprintf(stderr, "ERROR: Invalid response command: 0x%08x, expected command 0x%02x.\n", cmdreply, command & 0xFF);
if ((cmdreply == CMD_VERIFY(CMD_ENABLE_PROGRAM)) && (status == CMD_ACK)) {
printf("Device progam pending. Please power cycle the device.\n");
error(dev);
}
return false;
}
} else if (res < 0) {
Expand Down Expand Up @@ -809,18 +825,6 @@ long prepare_file_to_flash(const char *file_name, bool flash_jumploader) {
return file_size;
}

void cleanup(hid_device *handle) {
if (handle) hid_close(handle);
if (hid_exit() != 0) {
fprintf(stderr, "ERROR: Could not close the device.\n");
}
}

void error(hid_device *handle) {
cleanup(handle);
exit(1);
}

int main(int argc, char *argv[]) {
int opt, opt_index;
hid_device *handle;
Expand Down

0 comments on commit a08fa7d

Please sign in to comment.