@@ -47,7 +47,7 @@ extern void logerror(const char *format, ...)
4747 * The Cypress FX parts are largely compatible with the Anchorhip ones.
4848 */
4949
50- int verbose ;
50+ int verbose = 1 ;
5151
5252/*
5353 * return true if [addr,addr+len] includes external RAM
@@ -127,7 +127,7 @@ static int ezusb_write(libusb_device_handle *device, const char *label,
127127{
128128 int status ;
129129
130- if (verbose )
130+ if (verbose > 1 )
131131 logerror ("%s, addr 0x%08x len %4u (0x%04x)\n" , label , addr , (unsigned )len , (unsigned )len );
132132 status = libusb_control_transfer (device ,
133133 LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE ,
@@ -150,7 +150,7 @@ static int ezusb_read(libusb_device_handle *device, const char *label,
150150{
151151 int status ;
152152
153- if (verbose )
153+ if (verbose > 1 )
154154 logerror ("%s, addr 0x%08x len %4u (0x%04x)\n" , label , addr , (unsigned )len , (unsigned )len );
155155 status = libusb_control_transfer (device ,
156156 LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE ,
@@ -194,6 +194,33 @@ static bool ezusb_cpucs(libusb_device_handle *device, uint32_t addr, bool doRun)
194194 return true;
195195}
196196
197+ /*
198+ * Send an FX3 jumpt to address command
199+ * Returns false on error.
200+ */
201+ static bool ezusb_fx3_jump (libusb_device_handle * device , uint32_t addr )
202+ {
203+ int status ;
204+
205+ if (verbose )
206+ logerror ("transfer execution to Program Entry at 0x%08x\n" , addr );
207+ status = libusb_control_transfer (device ,
208+ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE ,
209+ RW_INTERNAL , addr & 0xFFFF , addr >> 16 ,
210+ NULL , 0 , 1000 );
211+ /* We may get an I/O error from libusbx as the device disappears */
212+ if ((status != 0 ) && (status != LIBUSB_ERROR_IO ))
213+ {
214+ const char * mesg = "failed to send jump command" ;
215+ if (status < 0 )
216+ logerror ("%s: %s\n" , mesg , libusb_error_name (status ));
217+ else
218+ logerror ("%s\n" , mesg );
219+ return false;
220+ } else
221+ return true;
222+ }
223+
197224/*****************************************************************************/
198225
199226/*
@@ -527,14 +554,14 @@ static int ram_poke(void *context, uint32_t addr, bool external,
527554}
528555
529556/*
530- * Load an Cypress Image file into target RAM.
531- * The file is assumed to be in Cypress IMG format .
557+ * Load a Cypress Image file into target RAM.
558+ * See http://www.cypress.com/?docID=41351 (AN76405 PDF) for more info .
532559 */
533560static int fx3_load_ram (libusb_device_handle * device , const char * path )
534561{
535562 uint32_t dCheckSum , dExpectedCheckSum , dAddress , i , dLen , dLength ;
536563 uint32_t * dImageBuf ;
537- unsigned char * bBuf , hBuf [4 ], rBuf [4096 ];
564+ unsigned char * bBuf , hBuf [4 ], blBuf [ 4 ], rBuf [4096 ];
538565 FILE * image ;
539566
540567 image = fopen (path , "rb" );
@@ -555,12 +582,36 @@ static int fx3_load_ram(libusb_device_handle *device, const char *path)
555582 logerror ("image doesn't have a CYpress signature\n" );
556583 return -3 ;
557584 }
558- if (hBuf [3 ] != 0xB0 ) {
559- logerror ("invalid file format 0x%02X, expected 0xB0\n" , hBuf [3 ]);
585+
586+ // Check bImageType
587+ switch (hBuf [3 ]) {
588+ case 0xB0 :
589+ if (verbose )
590+ logerror ("normal FW binary %s image with checksum\n" , (hBuf [2 ]& 0x01 )?"data" :"executable" );
591+ break ;
592+ case 0xB1 :
593+ logerror ("security binary image is not currently supported\n" );
560594 return -3 ;
595+ case 0xB2 :
596+ logerror ("VID:PID image is not currently supported\n" );
597+ return -3 ;
598+ default :
599+ logerror ("invalid image type 0x%02X\n" , hBuf [3 ]);
600+ return -3 ;
601+ }
602+
603+ // Read the bootloader version
604+ if (verbose ) {
605+ if ((ezusb_read (device , "read bootloader version" , RW_INTERNAL , 0xFFFF0020 , blBuf , 4 ) < 0 )) {
606+ logerror ("Could not read bootloader version\n" );
607+ return -8 ;
608+ }
609+ logerror ("FX3 bootloader version: 0x%02X%02X%02X%02X\n" , blBuf [3 ], blBuf [2 ], blBuf [1 ], blBuf [0 ]);
561610 }
562611
563612 dCheckSum = 0 ;
613+ if (verbose )
614+ logerror ("writing image...\n" );
564615 while (1 ) {
565616 if ((fread (& dLength , sizeof (uint32_t ), 1 , image ) != 1 ) || // read dLength
566617 (fread (& dAddress , sizeof (uint32_t ), 1 , image ) != 1 )) { // read dAddress
@@ -621,8 +672,7 @@ static int fx3_load_ram(libusb_device_handle *device, const char *path)
621672 }
622673
623674 // transfer execution to Program Entry
624- if (ezusb_write (device , "Jump command" , RW_INTERNAL , dAddress , NULL , 0 ) < 0 ) {
625- logerror ("failed to send jump command\n" );
675+ if (!ezusb_fx3_jump (device , dAddress )) {
626676 return -6 ;
627677 }
628678
@@ -659,7 +709,7 @@ int ezusb_load_ram(libusb_device_handle *device, const char *path, int fx_type,
659709 if (image == NULL ) {
660710 logerror ("%s: unable to open for input.\n" , path );
661711 return -2 ;
662- } else if (verbose )
712+ } else if (verbose > 1 )
663713 logerror ("open firmware image %s for RAM upload\n" , path );
664714
665715 if (img_type == IMG_TYPE_IIC ) {
0 commit comments