Support Dediprog SF100 bulk read.

Packet size is 512 bytes. Depending on your USB hardware and the
Dediprog firmware version, this may not work at all.
Untested, experimental, may hang/crash the programmer.

Read tests of random images are appreciated.

Signed-off-by: Carl-Daniel Hailfinger <[email protected]>

Index: flashrom-dediprog_read_bulk/dediprog.c
===================================================================
--- flashrom-dediprog_read_bulk/dediprog.c      (Revision 1225)
+++ flashrom-dediprog_read_bulk/dediprog.c      (Arbeitskopie)
@@ -26,6 +26,7 @@
 
 #define DEFAULT_TIMEOUT 3000
 static usb_dev_handle *dediprog_handle;
+static int dediprog_endpoint;
 
 #if 0
 /* Might be useful for other pieces of code as well. */
@@ -148,9 +149,36 @@
 
 int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int 
len)
 {
+       int ret;
+       int i;
+       int chunksize = 0x200; /* 512 */
+       int count = flash->total_size * 1024 / chunksize;
+       /* Guessed. */
+       const char count_and_chunk[] = {(count >> 8) & 0xff,
+                               count & 0xff,
+                               (chunksize >> 8) & 0xff,
+                               chunksize & 0xff};
+
        msg_pspew("%s, start=0x%x, len=0x%x\n", __func__, start, len);
-       /* Chosen read length is 16 bytes for now. */
-       return spi_read_chunked(flash, buf, start, len, 16);
+       if ((len != flash->total_size * 1024) || (start != 0)) {
+               msg_perr("Only a full chip read is supported for now. Wanted "
+                        "start=%i, length=%i\n.", start, len);
+               return 1;
+       }
+
+       /* Command Read SPI Bulk. No idea which read command is used on the SPI 
side. */
+       usb_control_msg(dediprog_handle, 0x42, 0x20, 0x0000, 0x0000, (char 
*)count_and_chunk, 0x0004, DEFAULT_TIMEOUT);
+
+       for (i = 0; i < count; i++) {
+               ret = usb_bulk_read(dediprog_handle, dediprog_endpoint, (char 
*)buf + i * chunksize, chunksize, DEFAULT_TIMEOUT);
+               if (ret != chunksize) {
+                       msg_perr("SPI bulk read failed, expected %i, got %i 
%s!\n",
+                                chunksize, ret, usb_strerror());
+                       return 1;
+               }
+       }
+
+       return 0;
 }
 
 int dediprog_spi_send_command(unsigned int writecnt, unsigned int readcnt,
@@ -301,6 +329,7 @@
        dediprog_handle = usb_open(dev);
        usb_set_configuration(dediprog_handle, 1);
        usb_claim_interface(dediprog_handle, 0);
+       dediprog_endpoint = 2;
        /* URB 6. Command A. */
        if (dediprog_command_a())
                return 1;


-- 
http://www.hailfinger.org/


_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to