Macで Xilinx/systemctlm-cosim-demo動かす(その3)
を 個人PC(Mac)で動かそうとしてます。
環境
- macOS Monterey 12.5
- Clang 14.0.6
前提
以下がインストールされている状態です。
動機
- 暇
(夏休み) - 面白そう
- 個人PC(Mac)で動くかやってみよう
構成
systemctlm-cosim-demo/docs/lmac-demos.md を見てみると必要な構成は以下の感じぽい
qemu-devicetrees
systemctlm-cosim-demo/docs/lmac-demos.md 記載を参考に
git clone https://github.com/Xilinx/qemu-devicetrees.git cd qemu-devicetrees make OUTDIR=~/dts/
dtc
コマンド(Device Tree Compiler)が必要なので、インストールする必要があります。
$ brew install dtc
$ ls ~/dts/ LATEST
配下に色々な dts
ファイルが入ってた。
続く
Macで Xilinx/systemctlm-cosim-demo動かす(その2)
を 個人PC(Mac)で動かそうとしてます。
環境
- macOS Monterey 12.5
- Clang 14.0.6
前提
以下がインストールされている状態です。
動機
- 暇
(夏休み) - 面白そう
- 個人PC(Mac)で動くかやってみよう
構成
systemctlm-cosim-demo/docs/lmac-demos.md を見てみると必要な構成は以下の感じぽい
systemctlm-cosim-demoのビルド
systemctlm-cosim-demo/docs/lmac-demos.md 記載を参考に
$ git clone https://github.com/Xilinx/systemctlm-cosim-demo.git $ cd systemctlm-cosim-demo $ git submodule update --init # .config.mkの作成があるが、環境変数で設定しているのでスルー $ make libsystemctlm-soc/libremote-port/safeio.c:92:27: error: unknown type name 'off64_t'; did you mean 'off_t'? int rp_safe_copyfd(int s, off64_t off, size_t olen, int d) ^~~~~~~ off_t /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/sys/_types/_off_t.h:31:33: note: 'off_t' declared here typedef __darwin_off_t off_t; ^ libsystemctlm-soc/libremote-port/safeio.c:101:2: warning: implicit declaration of function 'lseek64' is invalid in C99 [-Wimplicit-function-declaration] lseek64(s, off, SEEK_SET); ^ 1 warning and 1 error generated. make: *** [libsystemctlm-soc/libremote-port/safeio.o] Error 1
とりあえず以下のように修正
diff --git a/libremote-port/safeio.c b/libremote-port/safeio.c index 8dd4f29..3dbc3f6 100644 --- a/libremote-port/safeio.c +++ b/libremote-port/safeio.c @@ -89,7 +89,7 @@ rp_safe_write(int fd, const void *wbuf, size_t count) } /* Try to splice if possible. */ -int rp_safe_copyfd(int s, off64_t off, size_t olen, int d) +int rp_safe_copyfd(int s, off_t off, size_t olen, int d) { static unsigned char buf[16 * 1024]; int len = olen; @@ -98,7 +98,7 @@ int rp_safe_copyfd(int s, off64_t off, size_t olen, int d) int tlen = 0; D(fprintf(stderr, "%s off=%lld len=%d\n", __func__, off, len)); - lseek64(s, off, SEEK_SET); + lseek(s, off, SEEK_SET); #if 0 long r; do diff --git a/libremote-port/safeio.h b/libremote-port/safeio.h index bbd1373..0fca973 100644 --- a/libremote-port/safeio.h +++ b/libremote-port/safeio.h @@ -28,6 +28,6 @@ ssize_t rp_safe_read(int fd, void *buf, size_t count); ssize_t rp_safe_write(int fd, const void *buf, size_t count); -ssize_t rp_safe_copyfd(int s, off64_t off, size_t len, int d); +ssize_t rp_safe_copyfd(int s, off_t off, size_t len, int d); #endif
再度 make
$ make libsystemctlm-soc/libremote-port/remote-port-proto.c:61:12: fatal error: 'byteswap.h' file not found # include <byteswap.h> ^~~~~~~~~~~~ 1 error generated. make: *** [libsystemctlm-soc/libremote-port/remote-port-proto.o] Error 1
調べてみると、
Macだとbyteswap.h
の代わりに machine/endian.h
が該当するもよう。
ただ machine/endian.h
をみると、htobe64
やbe64toh
といったマクロが見つからないので適当に以下のような感じで対応した。(後日 GitHubの Issueで聞いてみようと思う)
--- a/libremote-port/remote-port-proto.c +++ b/libremote-port/remote-port-proto.c @@ -54,6 +54,15 @@ # define be64toh(x) _byteswap_uint64(x) # define be32toh(x) _byteswap_ulong(x) # define be16toh(x) _byteswap_ushort(x) +#elif defined(__APPLE__) +# include <machine/endian.h> +# define htobe64(x) htonll(x) +# define htobe32(x) htonl(x) +# define htobe16(x) htons(x) + +# define be64toh(x) ntohll(x) +# define be32toh(x) ntohl(x) +# define be16toh(x) ntohs(x) #endif /* Fallback for ancient Linux systems. */
再度 make
$ make
$ ls *_demo
versal_demo versal_mrmac_demo zynq_demo zynqmp_demo
いくつか Warningがあったもののビルドできたみたい。
前回単体でビルドしたやつだとエラーでなかったのはなぜだろう!?
続く
Macで Xilinx/systemctlm-cosim-demo動かす(その1)
を 個人PC(Mac)で動かそうとしてます。
環境
- macOS Monterey 12.5
- Clang 14.0.6
前提
以下がインストールされている状態です。
動機
- 暇
(夏休み) - 面白そう
- 個人PC(Mac)で動くかやってみよう
構成
systemctlm-cosim-demo/docs/lmac-demos.md を見てみると必要な構成は以下の感じぽい
LibSystemCTLM-SoC
QEMUとは libremote-port
で接続するようです、
概念的な理解は Xilinx Wikiに記載がありますので、
そちらの図を引用します。
QEMU無しの単体で動作できるぽいのでやってみました。
$ git clone https://github.com/Xilinx/libsystemctlm-soc.git $ cd libsystemctlm-soc/tests $ make examples-run # : Info: /OSCI/SystemC: Simulation stopped by user. . =========== 3 passed, 25 deselected in 0.24s ==============
pytest
使っているので $ pip or pip3 install pytest
でインストールしてます。
example-rtl-axi4/example-rtl-axi4.vcd
の波形はこんな感じでした。
続く
即席 APBアクセスのテスト作ってみた
せっかくなので、自分で一から勉強がてら作ってみました。
※ただし即席なので使用する場合は自己責任で。
題材としては、APBアクセスモジュールのテスト。
コード一式はこちらにあげてます。
説明
環境やテスト内容については sc_main.cpp
にまとめて記載されてます。
ビルドと実行についてはこちらのコマンドでできると思います。
$ mkdir build; cd build $ cmake .. $ make
+trace
を実行引数に追加すると、RTL側のVCD波形が dumpされます。
$ ./run.x +trace SystemC 2.3.3-Accellera --- Aug 16 2022 12:13:48 Copyright (c) 1996-2018 by all Contributors, ALL RIGHTS RESERVED Enabling waves into vlt_dump.vcd... *** Start Simulation *** Release Reset at 301 ns *** WakeUp at 601 ns *** End Simulation at 1051 ns $ ls CMakeCache.txt CMakeFiles Makefile cmake_install.cmake coverage.dat run.x vlt_dump.vcd
vlt_dump.vcd
ファイルは GTKwaveなどでみれます。
こんな感じです。
↓
余談:SystemC側の波形
SystemC側の波形については、SystemCの sc_trace_file
, sc_create_vcd_trace_file
などを使って取得することが出来ます。
こちらの trace.h/cc
を活用すると、割と楽に波形が dumpできます。
trace.cc
には以下を追加してください。
sc_trace_template < sc_core::sc_signal < uint32_t > > (tf,obj); sc_trace_template < sc_core::sc_in < uint32_t > > (tf,obj); sc_trace_template < sc_core::sc_out < uint32_t > > (tf,obj);
また、sc_main.cpp
への追加はこんな感じです。
@@ -1,4 +1,5 @@ #include "Vdut_top.h" +#include "trace.h" #include "apb_req.hpp" #if VM_TRACE @@ -13,6 +14,8 @@ Verilated::commandArgs(argc, argv); + sc_trace_file *trace_fp = NULL; + sc_clock clk{"clk", 10, SC_NS, 0.5, 3, SC_NS, true}; sc_signal<bool> presetn; sc_signal<uint32_t> paddr ; @@ -58,6 +61,7 @@ apb->pslverr(pslverr); apb->pwakeup(pwakeup); + // You must do one evaluation before enabling waves, in order to allow // SystemC to interconnect everything for testing. sc_start(1, SC_NS); @@ -75,6 +79,11 @@ } #endif + // Trace waves + trace_fp = sc_create_vcd_trace_file("sc_trace"); + trace(trace_fp, *top, top->name()); + trace(trace_fp, *apb, apb->name()); + // Start Simulation // while (!Verilated::gotFinish()) { sc_start(1, SC_NS); } @@ -104,6 +113,9 @@ std::cout << "*** End Simulation at " << sc_time_stamp() << std::endl; + if (trace_fp) { + sc_close_vcd_trace_file(trace_fp); + } #if VM_TRACE if (tfp) { tfp->close(); tfp = nullptr; } #endif
VerilatorインストールとSystemC実行(Mac)
SystemCインストールしたので、Verilatorと一緒に動かしてみる。
環境
- macOS Monterey 12.5
前提
以下がインストールされている状態です。
インストール
versionにこだわりなかったので、brew
でインストールした。
$ brew install verilator
$ verilator --version Verilator 4.224 2022-06-19 rev UNKNOWN.REV
実行
基本的には、Verilatorのマニュアルを参考にした。
SystemCの環境変数として、以下が設定されている必要がある。
SYSTEMC_INCLUDE
SYSTEMC_LIBDIR
基本的には、上記で出来たけど面白味にかけるので CMake
でできるようにしてみた。
マニュアルとしては、以下を参考にした。
$ ls
CMakeLists.txt our.v sc_main.cpp
CMakeLists.txt
の中身はこちら
cmake_minimum_required (VERSION 3.1) project(cmake_example) set(target run.x) find_package(verilator HINTS $ENV{VERILATOR_ROOT}) add_executable(${target} sc_main.cpp) verilate(${target} SYSTEMC SOURCES our.v) verilator_link_systemc(${target})
あとの手順は以下の通り。
$ mkdir build; cd build $ cmake .. $ make [ 10%] Building CXX object CMakeFiles/run.x.dir/sc_main.cpp.o [ 20%] Building CXX object CMakeFiles/run.x.dir/CMakeFiles/run.x.dir/Vour.dir/Vour.cpp.o [ 30%] Building CXX object CMakeFiles/run.x.dir/CMakeFiles/run.x.dir/Vour.dir/Vour___024root__DepSet_hd6c43f43__0.cpp.o [ 40%] Building CXX object CMakeFiles/run.x.dir/CMakeFiles/run.x.dir/Vour.dir/Vour___024root__Slow.cpp.o [ 50%] Building CXX object CMakeFiles/run.x.dir/CMakeFiles/run.x.dir/Vour.dir/Vour___024root__DepSet_hd6c43f43__0__Slow.cpp.o [ 60%] Building CXX object CMakeFiles/run.x.dir/CMakeFiles/run.x.dir/Vour.dir/Vour__Syms.cpp.o [ 70%] Building CXX object CMakeFiles/run.x.dir/usr/local/share/verilator/include/verilated.cpp.o [ 80%] Linking CXX executable run.x [100%] Built target run.x $ ./run.x SystemC 2.3.3-Accellera --- Aug 16 2022 12:13:48 Copyright (c) 1996-2018 by all Contributors, ALL RIGHTS RESERVED Hello World - our.v:4: Verilog $finish
という感じでおしまい。