[PATCH] Dump function for the OSTC3
Anton Lundin
glance at acc.umu.se
Sat Apr 25 09:33:28 PDT 2015
This adds a dump function for the ostc3 series computers. This function
dumps the whole external eprom, that contains the dive-headers and the
dive data.
Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
I haven't seen the code for the simulator, but the relevant parts are
that the dive headers are located at:
; 1st: 200000h-2000FFh
; 2nd: 201000h-2010FFh
; 3rd: 202000h-2020FFh
; 100: 264000h-2640FFh
; 256: 2FF000h-2FF0FFh
And in those headers at byte 2 and 5 are the pointers to where in the memory
the actual dive profile are, in little endian.
It shouldn't be too hard to write simulator code for that.
src/hw_ostc3.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 62 insertions(+), 1 deletion(-)
diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c
index a5f96bf..4487d15 100644
--- a/src/hw_ostc3.c
+++ b/src/hw_ostc3.c
@@ -109,15 +109,17 @@ static const unsigned char ostc3_key[16] = {
};
static dc_status_t hw_ostc3_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
+static dc_status_t hw_ostc3_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t hw_ostc3_device_close (dc_device_t *abstract);
+static dc_status_t hw_ostc3_firmware_block_read (hw_ostc3_device_t *device, unsigned int addr, unsigned char block[], unsigned int block_size);
static const dc_device_vtable_t hw_ostc3_device_vtable = {
DC_FAMILY_HW_OSTC3,
hw_ostc3_device_set_fingerprint, /* set_fingerprint */
NULL, /* read */
NULL, /* write */
- NULL, /* dump */
+ hw_ostc3_device_dump, /* dump */
hw_ostc3_device_foreach, /* foreach */
hw_ostc3_device_close /* close */
};
@@ -443,6 +445,65 @@ hw_ostc3_device_set_fingerprint (dc_device_t *abstract, const unsigned char data
}
+static dc_status_t
+hw_ostc3_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
+{
+ hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract;
+
+ // Erase the current contents of the buffer.
+ if (!dc_buffer_clear (buffer)) {
+ ERROR (abstract->context, "Insufficient buffer space available.");
+ return DC_STATUS_NOMEMORY;
+ }
+
+ // Make sure the device is in service mode
+ dc_status_t rc = hw_ostc3_device_init (device, SERVICE);
+ if (rc != DC_STATUS_SUCCESS) {
+ return rc;
+ }
+
+ // Enable progress notifications.
+ dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
+ //unsigned int size = (RB_LOGBOOK_SIZE * RB_LOGBOOK_COUNT) + SZ_MEMORY;
+ unsigned int size = 0x400000;
+ progress.maximum = size;
+ device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
+
+ // Allocate the required amount of memory.
+ if (!dc_buffer_resize (buffer, size)) {
+ ERROR (abstract->context, "Insufficient buffer space available.");
+ return DC_STATUS_NOMEMORY;
+ }
+
+ unsigned char *data = dc_buffer_get_data (buffer);
+
+ unsigned int nbytes = 0;
+ while (nbytes < size) {
+ // packet size. Can be almost arbetary size.
+ unsigned int len = 4096;
+
+ // Limit the packet size to the total size.
+ if (nbytes + len > size)
+ len = size - nbytes;
+
+ // Read a block
+ rc = hw_ostc3_firmware_block_read (device, nbytes, data + nbytes, len);
+ if (rc != DC_STATUS_SUCCESS) {
+ ERROR (abstract->context, "Failed to read block.");
+ return rc;
+ }
+
+ // Update and emit a progress event.
+ progress.current += len;
+ device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
+
+ nbytes += len;
+ }
+
+ return DC_STATUS_SUCCESS;
+}
+
+
dc_status_t
hw_ostc3_device_version (dc_device_t *abstract, unsigned char data[], unsigned int size)
{
--
2.1.0
More information about the devel
mailing list