Building Spike simulator for RISC-V


I am trying to build toolchain for RISC-V Spike simulator. I use the repository Here while building openocd, i get following error

: not founder/ 2: …/src/helper/
: not founder/ 5: …/src/helper/ echo
make: *** [src/] Error 1

Is the file src/startup_tcl.h created ?. Build.log has following output error

cat …/src/helper/startup.tcl …/src/jtag/startup.tcl …/src/target/startup.tcl …/src/server/startup.tcl …/src/flash/startup.tcl | …/src/helper/ > src/ || { rm -f src/; false; }
Makefile:4659: recipe for target ‘src/’ failed

Any idea what is the error here ?

The error message looks corrupted, so not clear what happened. Try debugging this. Do the …/src/* files all exist? What happens if you run the …/src/helper/ script by hand? It looks like it could be a problem with /bin/sh which is odd. What system are you building on? Linux? mingw?

Hi Ji

I could resolve this error. There was a line ending conversion needed for shell script. But now while building ISA, i am getting following error in the file riscv/ in the function
string dts_compile(const string&). The error is

…/riscv/ In function ‘std::__cxx11::string dts_compile(const string&)’:
…/riscv/ error: ‘DTC’ was not declared in this scope
execlp(DTC, DTC, “-O”, “dtb”, 0);
…/riscv/ error: expected ‘;’ before ‘DTC’
std::cerr << "Failed to run " DTC ": " << strerror(errno) << std::endl;

I have installed device-tree -compiler already, the version is 1.4.5-3. Basically i have entered some error condition i guess ? what is this DTC here ? is this some kind of macro?

I have attached the snapshot of build log of ISA simulator, and also the my ubuntu terminal snapshot (to know current status).

Can u please help me here ?

DTC is set by the configure script to the full pathname for the device tree compiler. This definition goes into config.h in the build tree. I have
/* Path to the device-tree-compiler */
#define DTC “/usr/bin/dtc”

The configure script will give an error if the device tree compiler is not found at configure time. The build script is simple and stupid though, and doesn’t check for configure errors, so it will go ahead and run make even though it won’t work.

If you installed the device tree compiler after running configure, then you will need to configure again, or rm -rf the build tree and rebuild from scratch.


Thanks for the answer.

Currently i am trying to build Spike simulator from repository in MSYS2 MINGW64. I was successfully able to build riscv gnu-toolchain on MSYS2 MINGW64 and able to generate riscv32-unknown-elf-gcc.exe. Now i want to build SPIKE simulator. While building riscv-isa-sim from the build script i am getting following error

…/fesvr/ fatal error: sys/mman.h: No such file or directory
9 | #include <sys/mman.h>
| ^~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:313: elfloader.o] Error 1

I have the file C:\msys64\usr\include\sys\mman.h> in the system. I have also included this include path in Path environmental varialbe. Here is my path variable


Anything else that i have to do here ?

If building SPIKE in msys2 mingw64 is not a good option, then shall i go ahead building SPIKE simulator in WSL Ubuntu 18.04 ?

My worry is, I have built riscv32-unknown-elf-gcc.exe as windows exe in MSYS2, and if i build SPIKE on WSL ubuntu, are these 2 compatible ?

Please help me to go ahead further.

Maybe try compiling a one line file including sys/mman.h to see if that works. And if not, then try to debug. You can add --verbose to gcc to the list of dirs it is searching for header files. You should find the failing build command in riscv-isa-sim/build/build.log.

A riscv32-unknown-elf-gcc and a spike built on different systems should be compatible, and they produce/read the same RISC-V ELF file format.


Thanks for the reply.
For building SPIKE simulator with the shell script provided in riscv-tools repository, is there a way to change default GCC include path? because currently i checked with verbose option -v with GCC for a small c program, in MSYS2 MINGW64, the include paths that GCC point to is C:/msys64/mingw64/include.
But all the include files which are necessary for building SPIKE simulator in riscv-sim-sim folder, are present in C:/msys64/include paths. i think if i open MINGW64 shell (provided by MSYS2), the default includes are pointing from/mingw64 but not from /msys64.

Specially to build SPIKE simulator, we need headers like unistd.h and mman.h and many more which are by default located in /msys64/include.

Is there a way to change GCC include path?

I’m not an expert on msys/mingw compilers. Maybe you should ask them for help, as this isn’t a RISC-V problem. Or maybe they have a FAQ somewhere that explains how this works.

You can use -I options to add user include paths, and -isystem to add new system include dirs, but adding these options won’t necessarily fix the problem.

There is also --sysroot to change the system root that all paths are relevant to, and -isysroot to only change the system root used for include dirs, but these are less likely to work unless msys/mingw was designed to work with them, and if it was, there should be docs or a faq that explains how to use them.