bjoernQ / blash

A tool to flash BL602 via JTAG + serial without pressing buttons / setting jumpers
11 stars 2 forks source link

Download eflasher using OpenOCD? #2

Closed JF002 closed 2 years ago

JF002 commented 2 years ago

Hi!

I find this project really interesting, and I would like to reproduce the same functionality in an OpenOCD script, that would integrate more easily in my dev environment. I only need the part that downloads the eflasher bin into the RAM.

I hope you don't mind if I ask some help, even if it's not directly related to this project?

I tried to read the code (but I don't know Rust, unfortunately), and here's what I've tried so far:

halt
reset

mwb 0x22010000 0x73
mwb 0x22010001 0x13
mwb 0x22010002 0x0
mwb 0x22010003 0x30

reg t1 0x80000000
reg pc 0x22010000
step

load_image /home/jf/git/blash/bin/eflasher.bin 0x22010000 bin

reset

reg pc 0x22010000

resume

/home/jf/git/blash/bin/eflasher.bin is the file eflash_loader_40m.bin with the first 192 bytes stripped.

OpenOCD runs this script without error, but it doesn't seem to work, and the MCU does not run the bootloader code (I checked the serial output).

Is my understanding of the code from Blash correct? Did I miss anything?

Thanks!

bjoernQ commented 2 years ago

You are welcome!

Actually the idea of blash is based on an OpenOCD script found here: https://github.com/bouffalolab/bl_mcu_sdk/blob/master/tools/bflb_flash_tool/utils/openocd/image-loader.cfg

Generally your script looks good - in my application some things are more complicated since the probe-rs lib doesn't know about mstatus ... But I guess the original script should help.

I'm on a mobile phone right now but I can look deeper tomorrow if needed.

Hope this helps to get it to work

JF002 commented 2 years ago

Oh thanks for pointing me to the original script, I didn't know it existed! I've just tried it, with no success : the firmware is correctly stopped (I can see it on the serial output), the binary file seems to be correctly flashed (I checked with verify_image), but blfash ends with a timeout:

$ ./blflash-linux-amd64.1 flash /home/jf/git/bl602_cmake_mcusdk/cmake-build-debug/bl602_cmake_mcusdk.bin --port /dev/ttyUSB0
[INFO  blflash::flasher] Start connection...
[TRACE blflash::flasher] 5ms send count 55
[TRACE blflash::flasher] handshake sent elapsed 113.957µs
[INFO  blflash::flasher] Connection Succeed
Error: IO error: Operation timed out
caused by: Operation timed out

But now, I'm wondering... doesn't blflash also try to send the eflash_loader? Maybe your project uses a subset of blflash that only sends the firmware to the flash?

bjoernQ commented 2 years ago

Yeah ... blflash will first try to download eflasher so you need a custom version that omits that step. That's one of the reasons I shamelessly copied the code

Otherwise it looks quite good