[RFC PATCH 08/10] Add a function upgrade the firmware in the OSTC3

Anton Lundin glance at acc.umu.se
Fri Nov 14 09:01:37 PST 2014


This function triggers a reboot into the bootloader which flashes the
new firmware to Prom.

This code is inspired by JeanDo ostc-companion.

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 src/hw_ostc3.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c
index ff65677..5cea5b9 100644
--- a/src/hw_ostc3.c
+++ b/src/hw_ostc3.c
@@ -57,6 +57,7 @@
 #define ERASE_RANGE 0x42
 #define S_READY    0x4C
 #define READY      0x4D
+#define FLASH_FIRM 0x50
 #define HEADER     0x61
 #define CLOCK      0x62
 #define CUSTOMTEXT 0x63
@@ -891,3 +892,41 @@ hw_ostc3_device_write_block (dc_device_t *abstract, unsigned int addr, unsigned
 
 	return DC_STATUS_SUCCESS;
 }
+
+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);
+
+	// Make sure everything is in a sane state.
+	serial_sleep (device->port, 100);
+	serial_flush (device->port, SERIAL_QUEUE_BOTH);
+
+	rc = hw_ostc3_transfer(device, NULL, FLASH_FIRM, buffer, sizeof(buffer), NULL, 0);
+	if (rc != DC_STATUS_SUCCESS) {
+		ERROR (context, "Failed to send flash firmware command");
+		return rc;
+	}
+
+	// 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?
+
+	return DC_STATUS_SUCCESS;
+}
-- 
1.9.1



More information about the devel mailing list