LIBUSB error when programming CW308T-FE310

Ok, this is the final comment from me

FINAL UPDATE

First of all, either FE310 is just really complicated or I’m not that good in the domain of embedded systems.

My objective was to program the FE310 and I figured that out, empirically, that to do so is (at least for me this what worked) :

1 - Plug the CW to the PC (duh)

2 - Connect the CW using the following code (this code should be executed as is and not by putting in a function, that didn’t work for me) :

scope = cw.scope()
scope.default_setup()
target = cw.target(scope)
target.flush()

scope.io.nrst = "low"
time.sleep(0.7)
scope.io.nrst = "high_z"

   return scope, target

3- Execute the function scope.enable_MPSSE() to enable MPSSE

4- Program the chipwhisperer :

  • In a terminal execute the following command :
    path/to/openocd -f /path/to/interface_cfg.cfg -c 'ftdi vid_pid 0x2b3e 0xace2' -c 'transport select jtag' -f /home/alkafa/chipwhisperer/openocd/fe310.cfg

  • In another terminal :
    `gdb-multiarch path/to/prog.elf

  • Then on the gdb command line :
    target extended-remote localhost:3333
    monitor reset halt
    load

5- After programming has been correctly, connecte again to the CW with the code above and execute scope.enable_MPSSE(0) to disable MPSSE

6- scope.dis()

7- ubplug cw from pc

I did this, it worked, I don’t know why, but it did

If gdb doesn’t talk with ocd because of timeout, it’s because ocd hasn’t ‘found’ the chip to be flashed on the target, sometimes it finds it quicly, sometimes no, we can only wait

Also, openocd sometimes might not be able to listen on 3333 simply because it’s used, for that :
sudo kill -9 sudo lsof -t -i:3333`

It should be noted the using run_openocd.sh to program the FE310 also worked, the problem is that this way takes sooooo much time

Here’s the code that I was able to flash, because I’m not sure anything can be flashed, this code has the password and glitch-loop functions to do the password bypassing exercise:

#include "hal.h"
#include <stdint.h>
#include <stdlib.h>

#include "simpleserial.h"

uint8_t password(uint8_t* pw, uint8_t len)

{
    char passwd[] = "touch";
    char passok = 1;
    int cnt;

    trigger_high();

    //Simple test - doesn't check for too-long password!
    for(cnt = 0; cnt < 5; cnt++){
        if (pw[cnt] != passwd[cnt]){
            passok = 0;
        }
    }

    trigger_low();

    simpleserial_put('r', 1, (uint8_t*)&passok);
    return 0x00;
}

uint8_t glitch_loop(uint8_t* in, uint8_t len)

{
    volatile uint16_t i, j;
    volatile uint32_t cnt;
    cnt = 0;
    trigger_high();
    for(i=0; i<50; i++){
        for(j=0; j<50; j++){
            cnt++;
        }
    }
    trigger_low();
    simpleserial_put('r', 4, (uint8_t*)&cnt);


    return (cnt != 2500);

}


int main(void)
{
    
    platform_init();   
    trigger_setup(); 
    simpleserial_init();  
    simpleserial_addcmd('p', 5, password);
    simpleserial_addcmd('g', 0, glitch_loop);

  

    while(1){
    simpleserial_get();
        }
}

I hope it helps someone.

Big Thanks to @Alex_Dewar :v: :v: :v: for all the help provided