bjoernQ / blash

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

Add support for Pine64 JTAG adapter? #1

Closed JF002 closed 2 years ago

JF002 commented 2 years ago

Hi!

I'm currently experimenting on the Pine64 BL602 board from Pine64. I tried Blash using my Sipeed JTAG adapter and it works perfectly, thanks a lot for creating this tool!

Now, I was wondering what would it take to add support for the Pine64 JTAG adapter? It should be pretty similar to the Sipeed one, but have a different PID/VID :

Any idea if that would be possible? I would be happy to help but I don't know Rust, and I don't know where to start :/

Here the output of blash when I tried using the Pine64 adapter:

$ /home/jf/.cargo/bin/blash --port /dev/ttyUSB0 --monitor-baud 2000000 -- /home/jf/git/bl60cmake_mcusdk/cmake-build-debug/bl602_cmake_mcusdk.bin 
[TRACE blash] Downloading eflasher
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Probe(ProbeSpecific(Custom { kind: Other, error: "libusb error code -1" }))', src/main.rs:129:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ RUST_BACKTRACE=1 /home/jf/.cargo/bin/blash --port /dev/ttyUSB0 --monitor-baud 2000000 -- /home/jf/git/bl602_cmake_mcusdk/cmake-build-debug/bl602_cmake_mcusdk.bin 
[TRACE blash] Downloading eflasher
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Probe(ProbeSpecific(Custom { kind: Other, error: "libusb error code -1" }))', src/main.rs:129:47
stack backtrace:
   0: rust_begin_unwind
             at /build/rust/src/rustc-1.54.0-src/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /build/rust/src/rustc-1.54.0-src/library/core/src/panicking.rs:92:14
   2: core::result::unwrap_failed
             at /build/rust/src/rustc-1.54.0-src/library/core/src/result.rs:1355:5
   3: blash::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
$ RUST_BACKTRACE=full /home/jf/.cargo/bin/blash --port /dev/ttyUSB0 --monitor-baud 2000000 -- /home/jf/git/bl602_cmake_mcusdk/cmake-build-debug/bl602_cmake_mcusdk.bin 
[TRACE blash] Downloading eflasher
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Probe(ProbeSpecific(Custom { kind: Other, error: "libusb error code -1" }))', src/main.rs:129:47
stack backtrace:
   0:     0x55ad7bf5e2d0 - std::backtrace_rs::backtrace::libunwind::trace::h930cf0be2ce43851
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x55ad7bf5e2d0 - std::backtrace_rs::backtrace::trace_unsynchronized::he8c90b95546147bf
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55ad7bf5e2d0 - std::sys_common::backtrace::_print_fmt::h2d518076e7529961
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x55ad7bf5e2d0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc03afe5108b924f5
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x55ad7bf7fefc - core::fmt::write::h03501fd186e1f342
                               at /build/rust/src/rustc-1.54.0-src/library/core/src/fmt/mod.rs:1110:17
   5:     0x55ad7bf5bce5 - std::io::Write::write_fmt::he6bd3203a99cf841
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/io/mod.rs:1588:15
   6:     0x55ad7bf6032b - std::sys_common::backtrace::_print::h6d8d274cdb4b9345
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x55ad7bf6032b - std::sys_common::backtrace::print::hdbba7107ed5db727
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x55ad7bf6032b - std::panicking::default_hook::{{closure}}::h69616457d96cfc5a
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/panicking.rs:208:50
   9:     0x55ad7bf5fe01 - std::panicking::default_hook::h10bbc125f6ee1853
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/panicking.rs:225:9
  10:     0x55ad7bf60a04 - std::panicking::rust_panic_with_hook::h6eb033573a515ade
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/panicking.rs:622:17
  11:     0x55ad7bf604d7 - std::panicking::begin_panic_handler::{{closure}}::hffa4a3da6bf48f5f
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/panicking.rs:519:13
  12:     0x55ad7bf5e7cc - std::sys_common::backtrace::__rust_end_short_backtrace::h8245d4af937e663d
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/sys_common/backtrace.rs:141:18
  13:     0x55ad7bf60439 - rust_begin_unwind
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/panicking.rs:515:5
  14:     0x55ad7bd653f1 - core::panicking::panic_fmt::h497201afa0408fa6
                               at /build/rust/src/rustc-1.54.0-src/library/core/src/panicking.rs:92:14
  15:     0x55ad7bd654e3 - core::result::unwrap_failed::h7d766b1c7851f7a7
                               at /build/rust/src/rustc-1.54.0-src/library/core/src/result.rs:1355:5
  16:     0x55ad7bd9f4d0 - blash::main::h49a3cdd7b6c1e98f
  17:     0x55ad7bd91433 - std::sys_common::backtrace::__rust_begin_short_backtrace::hcf2eda9647c8b481
  18:     0x55ad7bda3e49 - std::rt::lang_start::{{closure}}::hb2a2d3efeeaaef23
  19:     0x55ad7bf60f09 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h23da4485ce9c2fa2
                               at /build/rust/src/rustc-1.54.0-src/library/core/src/ops/function.rs:259:13
  20:     0x55ad7bf60f09 - std::panicking::try::do_call::h26656c7c8049ab32
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/panicking.rs:401:40
  21:     0x55ad7bf60f09 - std::panicking::try::hafa31606aae6b61d
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/panicking.rs:365:19
  22:     0x55ad7bf60f09 - std::panic::catch_unwind::h12fc93c48e24c0bf
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/panic.rs:434:14
  23:     0x55ad7bf60f09 - std::rt::lang_start_internal::hb67ef9ab47b75f78
                               at /build/rust/src/rustc-1.54.0-src/library/std/src/rt.rs:34:21
  24:     0x55ad7bd9f982 - main
  25:     0x7f60d927cb25 - __libc_start_main
  26:     0x55ad7bd65bce - _start
  27:                0x0 - <unknown>

Thanks!

bjoernQ commented 2 years ago

Thanks for the detailed description and nice to hear it's working fine with the Sipeed adapter.

From the logs it seems that connecting to the probe works fine and also the first commands went through - it fails however when downloading the eflasher binary to RAM.

The error seems to originate from a dependency of a dependency (libusb used by probe-rs). I did some optimization in probe-rs to make bulk memory writes and reads reasonable fast - maybe it tries to batch too many commands for the FT232H but that is just guessing.

I just ordered the Pine64 JTAG adapter but I guess it will take a while to ship to my country unfortunately.

Probably just changing something and have you try my shots in the dark isn't very practical. Anyway, I really want to make this (and probe-rs) work fine with the Pine64 adapter

JF002 commented 2 years ago

Awesome! Keep us up to date when you receive your adapter, then! In the meantime, feel free to ping me if you want me to test something :-)

bjoernQ commented 2 years ago

I finally got my Pine64 JTAG adapter and the issue was exactly what I thought of. I created a PR for probe-rs - if it gets accepted, I will update blash.

JF002 commented 2 years ago

Yay! Thank you very much for your work!

bjoernQ commented 2 years ago

The PR got merged and blash is updated to use it - Pine64 jtag adapter should now work