[PATCH 06/11] Add a function to erase the memory of the OSTC3

Anton Lundin glance at acc.umu.se
Fri Nov 21 12:28:33 PST 2014


This is the fist step in the firmware upgrade process.

This code is inspired by JeanDo ostc-companion.

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

diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c
index 4d6bf83..f647179 100644
--- a/src/hw_ostc3.c
+++ b/src/hw_ostc3.c
@@ -46,10 +46,13 @@
 #define SZ_MEMORY     0x200000
 #define SZ_CONFIG     4
 #define SZ_FIRMWARE   0x01E000        // 120KB
+#define SZ_FIRMWARE_BLOCK    0x1000   //   4KB
+#define FIRMWARE_AREA      0x3E0000
 
 #define RB_LOGBOOK_SIZE  256
 #define RB_LOGBOOK_COUNT 256
 
+#define ERASE_RANGE 0x42
 #define S_READY    0x4C
 #define READY      0x4D
 #define HEADER     0x61
@@ -871,3 +874,18 @@ hw_ostc3_device_service_mode (dc_device_t *abstract)
 
 	return DC_STATUS_SUCCESS;
 }
+
+static dc_status_t
+hw_ostc3_device_erase_range (hw_ostc3_device_t *device, unsigned int addr, unsigned int size)
+{
+	dc_status_t rc = DC_STATUS_SUCCESS;
+	// Convert size to number of pages, rounded up.
+	unsigned char blocks = ((size + SZ_FIRMWARE_BLOCK - 1) / SZ_FIRMWARE_BLOCK);
+
+	// Erase just the needed pages.
+	unsigned char buffer[4];
+	uint24_be_array(addr, buffer);
+	buffer[3] = blocks;
+
+	return hw_ostc3_transfer (device, NULL, ERASE_RANGE, buffer, sizeof(buffer), NULL, 0);
+}
-- 
1.9.1



More information about the devel mailing list