Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Getting Verilator working on Mac #2975

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 63 additions & 2 deletions boards/opentitan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for more details.
Programming
-----------

Tock on OpenTitan requires
Tock on OpenTitan requires using OpenTitan_SHA
lowRISC/opentitan@199d45626f8a7ae2aef5d9ff73793bf9a4233711 or newer. In
general it is recommended that users start with the latest OpenTitan bitstream
and if that results in issues try the one mentioned above.
Expand Down Expand Up @@ -127,14 +127,75 @@ A quick summary on how to do this is included below though
```shell
git clone https://github.com/lowRISC/opentitan.git
cd opentitan
git checkout <OpenTitan_SHA>
git checkout <OpenTitan_SHA> # Changes, see current SHA at top of this README
pip3 install --user -r python-requirements.txt

LANG="en_US.UTF-8" fusesoc --cores-root . run --flag=fileset_top --target=sim --setup --build lowrisc:dv:chip_verilator_sim
```

<details>
<summary>Modifications to build on OS X</summary>

OpenTitan doesn't have a configuration to set elf header path correctly, so you have to fix the path:
```diff
diff --git a/hw/dv/verilator/cpp/dpi_memutil.cc b/hw/dv/verilator/cpp/dpi_memutil.cc
index ab14462d9..69117cf5e 100644
--- a/hw/dv/verilator/cpp/dpi_memutil.cc
+++ b/hw/dv/verilator/cpp/dpi_memutil.cc
@@ -8,7 +8,7 @@
#include <cstring>
#include <fcntl.h>
#include <iostream>
-#include <libelf.h>
+#include <libelf/libelf.h>
#include <sstream>
#include <sys/stat.h>
#include <unistd.h>
diff --git a/hw/ip/otbn/dv/memutil/otbn_memutil.cc b/hw/ip/otbn/dv/memutil/otbn_memutil.cc
index 176d628c5..435c71577 100644
--- a/hw/ip/otbn/dv/memutil/otbn_memutil.cc
+++ b/hw/ip/otbn/dv/memutil/otbn_memutil.cc
@@ -6,9 +6,9 @@

#include <cassert>
#include <cstring>
-#include <gelf.h>
+#include <libelf/gelf.h>
#include <iostream>
-#include <libelf.h>
+#include <libelf/libelf.h>
#include <limits>
#include <regex>
#include <sstream>
```

You need a (very) recent version of Verilator.
If you see errors about `verilator_deplist.tmp`, you've hit this old bug where
[Verilator didn't support BSD `ar`](https://github.com/verilator/verilator/issues/2999).
Unfortunately, modern OS X doesn't work with GNU `ar`, so you need a version of
verilator which includes [this fix](https://github.com/verilator/verilator/pull/3256).
Upgrading to at least `Verilator 4.218 2022-01-17` worked as of Feb 16, 2022.

</details>

### Build Boot Rom/OTP Image

<details>
<summary>Modifications to build on OS X</summary>

OT build assumes old toolchains (i.e. `riscv32-*`), but homebrew only installs
binaries of `riscv64-*`. They're all multilib, so they work fine, just need to
add symlinks:

> `cd /usr/local/Cellar/riscv-gnu-toolchain/main/bin`
> `for f in $(ls); do ln -s $f riscv32-$(echo $f | cut -d'-' -f2-10); done`

</details>

Build only the targets we care about.

```shell
./meson_init.sh
ninja -C build-out sw/device/lib/testing/test_rom/test_rom_export_sim_verilator
ninja -C build-out sw/device/otp_img/otp_img_sim_verilator.vmem
```
Expand Down