bouffalolab / bouffalo_sdk

BouffaloSDK is the IOT and MCU software development kit provided by the Bouffalo Lab Team, supports all the series of Bouffalo chips. Also it is the combination of bl_mcu_sdk and bl_iot_sdk
Apache License 2.0
349 stars 121 forks source link

How to reset CPU via JTAG #96

Open gamelaster opened 1 year ago

gamelaster commented 1 year ago

BL808: I want to flash firmware via JTAG, but I need to go to ISP mode. How to do this via CK-Link? reset, sreset or nreset dones't work.

JF002 commented 1 year ago

I had the same issue with the BL618 and found the answer in the .launch file (config file for Eclipse, I think) in bl_mcu_sdk. According to CKLink_BL808.launch, you can reset the BL808 by issuing the following commands over GDB:

set $pc=0x58000000
set $mie=0
set $mstatus=0x1880

thb main

To make things easier, I defined a function and a hook in .gdbinit:

define bl-reset
set $pc=0xA0000000
set $mie=0
set $mstatus=0x1880
thb main
end

define target hookpost-remote
bl-reset
end

bl-reset allows you to manually reset the MCU, and the hook automatically resets it when the debugger connects to the board. If I remember correctly, it was not perfect, but it's the best I could do.

I put all my notes together in this blog post. Let me know if it works for you on the BL808!

sakumisu commented 1 year ago

As @JF002 said, only this way, risc-v do not have register for hardware reset, and cklink do not support nrst and rst.

gamelaster commented 1 year ago

@sakumisu yes, I know about this method, but the goal is to get into BootROM (0x90000000), so it is possible to flash the firmware via JTAG, without reseting board with buttons. set $pc=0x90000000 doesn't work, probably because of PMP? GLB_SW_System_Reset reset's CPU, but also JTAG core :frowning_face:.

sakumisu commented 1 year ago

please in boot mode then you can use set $pc=0x90000000

madushan1000 commented 1 year ago

You can get it to halt in the bootrom by following this (https://gist.github.com/madushan1000/bb985be6e9f4b7c69ee16216f0060ece). I used pine64 jtag adapter(ft232hl chip). I think rv debugger plus will work too. Didn't check.