Skip to content

Commit 7aabd4b

Browse files
committed
Heinrichs Weikamp: Fix Firmware Upload when the OSTC4 is in the
Bootloader. Fix the firmware upload sequence in the case of the OSTC4 being in the Bootloader (e.g. no firmware installed, recovery from failed firmware upload). The command 0x60 (HARDWARE2) results is buggy in the bootloader, so we resort to trying 0x69 (HARDWARE) first. Signed-off-by: Michael Keller <[email protected]>
1 parent ecf7e4e commit 7aabd4b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/hw_ostc3.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,19 @@ hw_ostc3_device_id (hw_ostc3_device_t *device, unsigned char data[], unsigned in
488488
if (size != SZ_HARDWARE && size != SZ_HARDWARE2)
489489
return DC_STATUS_INVALIDARGS;
490490

491-
// Send the command.
491+
// We need to try the HARDWARE command first, as HARDWARE2 results
492+
// in a bluetooth disconnect when the OSTC4 is in bootloader mode.
492493
unsigned char hardware[SZ_HARDWARE2] = {0};
493-
status = hw_ostc3_transfer (device, NULL, HARDWARE2, NULL, 0, hardware, SZ_HARDWARE2, NULL, NODELAY);
494-
if (status == DC_STATUS_UNSUPPORTED) {
495-
status = hw_ostc3_transfer (device, NULL, HARDWARE, NULL, 0, hardware + 1, SZ_HARDWARE, NULL, NODELAY);
494+
status = hw_ostc3_transfer(device, NULL, HARDWARE, NULL, 0, hardware + 1, SZ_HARDWARE, NULL, NODELAY);
495+
if (size == SZ_HARDWARE2 && array_uint16_be(hardware) != OSTC4) {
496+
// HARDWARE2 returns additional information
497+
unsigned char hardware2[SZ_HARDWARE2] = {0};
498+
status = hw_ostc3_transfer(device, NULL, HARDWARE2, NULL, 0, hardware2, SZ_HARDWARE2, NULL, NODELAY);
499+
if (status == DC_STATUS_SUCCESS) {
500+
memcpy(hardware, hardware2, SZ_HARDWARE2);
501+
}
496502
}
503+
497504
if (status != DC_STATUS_SUCCESS)
498505
return status;
499506

@@ -615,8 +622,10 @@ hw_ostc3_device_init (hw_ostc3_device_t *device, hw_ostc3_state_t state)
615622

616623
// Cache the descriptor.
617624
device->hardware = array_uint16_be(hardware + 0);
618-
device->feature = array_uint16_be(hardware + 2);
619-
device->model = hardware[4];
625+
if (device->hardware != OSTC4) {
626+
device->feature = array_uint16_be(hardware + 2);
627+
device->model = hardware[4];
628+
}
620629
device->serial = array_uint16_le (version + 0);
621630
if (device->hardware == OSTC4) {
622631
device->firmware = array_uint16_le (version + 2);

0 commit comments

Comments
 (0)