This is the fist step in the firmware upgrade process.
This code is inspired by JeanDo ostc-companion.
Signed-off-by: Anton Lundin glance@acc.umu.se --- src/hw_ostc3.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index 6bc50d5..a4f2141 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 @@ -793,3 +796,28 @@ hw_ostc3_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; + + // 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, ERASE_RANGE, buffer, sizeof(buffer), NULL, 0); + + // Good wait formula taken from ostc-companion + // Wait (120/4)ms by block of 4K, plus 3% VAT to be sure. + serial_sleep (device->port, 40 + blocks * 31); + + return rc; +}