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

Anton Lundin glance at acc.umu.se
Fri Nov 21 12:28:36 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 | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c
index df537be..5ca26f2 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
@@ -956,3 +957,37 @@ hw_ostc3_device_write_block (dc_device_t *abstract, unsigned int addr, unsigned
 	return DC_STATUS_SUCCESS;
 #endif
 }
+
+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);
+
+	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