[PATCH 09/11] Add a function upgrade the firmware in the OSTC3

Jef Driesen jef at libdivecomputer.org
Tue Dec 16 07:51:46 PST 2014


On 2014-11-21 21:28, Anton Lundin wrote:
> +static dc_status_t
> +hw_ostc3_device_upgrade_firmware (dc_device_t *abstract, unsigned int 
> checksum)
> +{
> +	dc_status_t rc = DC_STATUS_SUCCESS;
> +	hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract;
> +	dc_context_t *context = (abstract ? abstract->context : NULL);
> +	unsigned char buffer[5];
> +	uint32_le_array(checksum, buffer);
> +
> +	// Compute a one byte checksum, so the device can validate the 
> firmware image.
> +	buffer[4] = 0x55;
> +	buffer[4] ^= buffer[0];
> +	buffer[4]  = (buffer[4]<<1 | buffer[4]>>7);
> +	buffer[4] ^= buffer[1];
> +	buffer[4]  = (buffer[4]<<1 | buffer[4]>>7);
> +	buffer[4] ^= buffer[2];
> +	buffer[4]  = (buffer[4]<<1 | buffer[4]>>7);
> +	buffer[4] ^= buffer[3];
> +	buffer[4]  = (buffer[4]<<1 | buffer[4]>>7);

Can you change this into a loop? It's already more than cryptic enough. 
Any idea whether this is some known checksum?

> +	// Now the device resets, and if everything is well, it reprograms.
> +	serial_sleep (device->port, 500);
> +
> +	// FIXME: How should we force the application to close the device 
> here?

Why do we need to wait here? If the device is rebooting, then the 
firmware update is successful, right? Since we won't get any 
confirmation from the ostc, what's the point of waiting here? It only 
blocks the caller from calling close. Or am I missing something else?

What happens at this point? Does the usb-serial device node (e.g. 
/dev/ttyUSBx) disappear? Setting the state to REBOOTING (as you changed 
the FIXME in one of the other patches) prevents to do anything, except 
for calling close. That's probably the right thing to do, but I just 
wonder what's going on under the hood.

This might be different for the ostc3 (usb-serial) and sport 
(bluetooth), because I suspect the sport will terminate the bluetooth 
during the reboot, while for the ostc3 the usb-serial chip is still 
there.

Jef



More information about the devel mailing list