How can I debug the HiFive board by JTAG?

Hi Huangwanneng, suggest that you first take a look at the RISC-V Debug Spec:

And then you can look at the implementation of OpenOCD here:

In particular, when the program is loaded to the SPI Flash, GDB’s load command examines the ELF file, sees that it linked in the Flash region, then requests OpenOCD to uses the appropriate driver to program the SPI Flash. For Freedom E platforms, that’s the fespi driver that we’ve also added to OpenOCD. OpenOCD is causing the processor to execute little code snippets to program the SPI Flash.

1 Like