orangecrab-fpga / orangecrab-hardware

ECP5 breakout board in a feather physical format
Other
491 stars 60 forks source link

Restoration of DFU bootloader #57

Open jrsa opened 6 months ago

jrsa commented 6 months ago

I made the regrettable mistake of overwriting the DFU bootloader by leaving out the "offset" parameter when invoking dfu-util and I am trying to restore it via JTAG with an FT2232H breakout board, and the ecpprog tool. I have the 25F variant, revision 0.2.1.

I tried flashing the bootloader bitstream from here and get the following output:

ecpprog -I B  foboot-v3.0-orangecrab-r0.2-25F.bit  -a
init..
IDCODE: 0x41111043 (LFE5U-25)
ECP5 Status Register: 0x00200100
reset..
flash ID: 0xEF 0x40 0x18
file size: 266307
erase 64kB sector at 0x000000..
erase 64kB sector at 0x010000..
erase 64kB sector at 0x020000..
erase 64kB sector at 0x030000..
erase 64kB sector at 0x040000..
programming..  266307/266307
verify..       266307/266307  VERIFY OK
rebooting ECP5...
Bye.

That seems... good. However after the device resets there is a red breathing pattern on the RGB LED and no DFU device shows up. I am assuming the red LED indicates an error with the bootloader. The result is the same whether I plug in the device with the button pressed or not. I am successfully able to load the blink example in this manner so I think my process for uploading a bitstream to flash is OK. My only other idea is that I am using the wrong bitstream for the hardware I have, but I don't see any on github that might be a closer match.

jrsa commented 6 months ago

I also tried this bitstream with the same result https://github.com/orangecrab-fpga/production-test-sw/blob/main/prebuilt/foboot-v3.1-orangecrab-r0.2-25F.bit

gregdavill commented 6 months ago

That should be all that's needed to load the bootloader via JTAG.

Are you holding the button when connecting USB? That's needed to "stay" in the bootloader, otherwise it tries to run the user application.

jrsa commented 6 months ago

yes @gregdavill I am pressing btn0 and then inserting the USB-C. The RGB LED blinks red immediately after the cable is inserted. I looked through what I believe to be the bootloader source here to see why the red blinking occurs (I am assuming that I see the results of rgb_mode_error) I see several calls once inside the dfu handling code, but I am assuming that is not getting reached because it never enumerates on USB. I believe USB is physically working because I am able to load and run the CDC ACM verilog example. The line I linked above is the only other rgb_mode_error which seems to indicate failing to reboot to the CPU (the LED state is set right before doing so). Is it possible the firmware is trying to reboot from flash memory, and failing, because I haven't written any firmware to flash? Not entirely sure how this is supposed to work, but I was expecting if this bitstream was loaded, that would be enough to do DFU bitstream uploading.