目次: Linux
前回はLinuxマシンだけを使って、OpenOCDとGDBでRISC-Vボードをデバッグする方法を紹介しました。
今回はそのおまけです。VSCodeのデバッグの話を見たい方はその4をご覧ください。
デバッグ対象は何でも良いと書きました。その例として、別のソフトウェア、別のボードを使うパターン(Akaria BSP + NS31 on Arty 7)を紹介します。
FPGAへの書き込み方は以前の日記(2023年4月24日の日記参照)でご紹介しました。そちらをご覧ください。
ツールチェーンのインストールをします。ディレクトリはどこでも良いですが、ここでは~/workで作業しているものとします。
$ cd ~/work $ wget https://github.com/nsitexe/akaria-riscv-toolchain/releases/download/nsitexe-20231117/riscv64-unknown-elf_ubuntu22.tar.gz $ tar xf riscv64-unknown-elf_ubuntu22.tar.gz $ export PATH=~/work/riscv64-unknown-elf/bin:$PATH $ riscv64-unknown-elf-gdb --version GNU gdb (GDB) 13.0.50.20220805-git Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
次にAkaria BSPのビルドをします。
$ git clone https://github.com/nsitexe/akaria-bmetal $ cd akaria-bmetal/ $ rm -r build $ cmake -B build -G Ninja -DARCH=riscv \ -DCROSS_COMPILE=riscv64-unknown-elf- \ -DCC=gcc \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_INSTALL_PREFIX=test/sysroot/ \ -DDEFCONF=riscv_nsitexe_ns31_arty CMake Warning (dev) at CMakeLists.txt:3 (project): cmake_minimum_required() should be called prior to this top-level project() call. Please see the cmake-commands(7) manual for usage documentation of both commands. This warning is for project developers. Use -Wno-dev to suppress it. -- The C compiler identification is GNU 13.2.0 -- The CXX compiler identification is GNU 13.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/lib/ccache/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/lib/ccache/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- The ASM compiler identification is GNU -- Found assembler: /usr/lib/ccache/cc ---- CC is 'gcc' ---- Compiler is 'riscv64-unknown-elf-gcc' ---- CCASM is 'gcc' ---- Assembler is 'riscv64-unknown-elf-gcc' ---- DEFCONF is 'riscv_nsitexe_ns31_arty' ---- CONF dir is '/home/katsuhiro/work/akaria-bmetal/config' ---- ARCH dir is '/home/katsuhiro/work/akaria-bmetal/arch/riscv' ---- SOC dir is '/home/katsuhiro/work/akaria-bmetal/arch/riscv/nsitexe_ns31' ---- BOARD dir is '/home/katsuhiro/work/akaria-bmetal/board/riscv/nsitexe_ns31_arty' ---- arch is riscv ---- march is 'rv32imafc_zicsr_zifencei' ---- mabi is 'ilp32f' -- Found Doxygen: /usr/bin/doxygen (found version "1.9.4") found components: doxygen dot -- Configuring done (0.3s) -- Generating done (0.0s) -- Build files have been written to: /home/katsuhiro/work/akaria-bmetal/build $ ninja -C build install ninja: Entering directory `build' [46/47] Install the project... -- Install configuration: "RelWithDebInfo" -- Installing: /home/katsuhiro/work/akaria-bmetal/test/sysroot/bin/add_auxdata -- Installing: /home/katsuhiro/work/akaria-bmetal/test/sysroot/lib/libbmetal_crt.a -- Installing: /home/katsuhiro/work/akaria-bmetal/test/sysroot/include/bmetal -- Installing: /home/katsuhiro/work/akaria-bmetal/test/sysroot/include/bmetal/bmetal.h -- Up-to-date: /home/katsuhiro/work/akaria-bmetal/test/sysroot/include/bmetal -- Installing: /home/katsuhiro/work/akaria-bmetal/test/sysroot/include/bmetal/generated -- Installing: /home/katsuhiro/work/akaria-bmetal/test/sysroot/include/bmetal/generated/autoconf.h -- Installing: /home/katsuhiro/work/akaria-bmetal/test/sysroot/include/bmetal/generated/linker_gen.ld
テストアプリをビルドします。
$ cd ~/work/akaria-bmetal/test $ make USE_NEWLIB=y
ビルドできました。1つ目の端末にてOpenOCDを起動します。
$ sudo openocd -c 'bindto 0.0.0.0' -f tcl/interface/jlink.cfg -f ./openocd-ns31.cfg
JTAGインタフェース用の設定ファイルtcl/interface/jlink.cfgはその2(2023年12月30日の日記参照)にてご紹介しています。SEGGER J-Link以外のインタフェースをご利用の場合は適宜変更をお願いします。
NS31 on Arty 7用の設定ファイルopenocd-ns31.cfgは以前の日記(2023年4月7日の日記参照)にてご紹介しています。
2つ目の端末にてGDBを使ってロード&実行します。
$ riscv64-unknown-elf-gdb hello (gdb) target remote :3333 (gdb) monitor reset halt (gdb) load (gdb) continue
UARTから出力されていることを確認します。
$ pyserial-miniterm /dev/ttyUSB1 9600 --raw --- Miniterm on /dev/ttyUSB1 9600,8,N,1 --- --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H --- hello world! good bye world!
Zephyr + HiFive1のときとロード&実行方法は一緒です。最初はとっつきにくいかもしれませんが、OpenOCDとGDBの組み合わせであれば他のソフトウェア、他のボードでもほぼ一緒の使い勝手で便利です。
< | 2023 | > | ||||
<< | < | 12 | > | >> | ||
日 | 月 | 火 | 水 | 木 | 金 | 土 |
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |
合計:
本日: