Building Spike simulator for RISC-V

Hi,

I am trying to build toolchain for RISC-V Spike simulator. I use the repository https://github.com/riscv/riscv-tools. Here while building openocd, i get following error

: not founder/bin2char.sh: 2: …/src/helper/bin2char.sh:
: not founder/bin2char.sh: 5: …/src/helper/bin2char.sh: echo
make: *** [src/startup_tcl.inc] 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/bin2char.sh > src/startup_tcl.inc || { rm -f src/startup_tcl.inc; false; }
Makefile:4659: recipe for target ‘src/startup_tcl.inc’ 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/bin2char.sh 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 bin2char.sh shell script. But now while building ISA, i am getting following error in the file riscv/dts.cc in the function
string dts_compile(const string&). The error is

…/riscv/dts.cc: In function ‘std::__cxx11::string dts_compile(const string&)’:
…/riscv/dts.cc:133:12: error: ‘DTC’ was not declared in this scope
execlp(DTC, DTC, “-O”, “dtb”, 0);
^~~
…/riscv/dts.cc:134:35: 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.

Hi,

Thanks for the answer.

Currently i am trying to build Spike simulator from https://github.com/riscv/riscv-tools 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 build-spike-only.sh i am getting following error

…/fesvr/elfloader.cc:9:10: 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

/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/mingw64/include:/mingw64/usr/include:/usr/include:/usr/include/sys:C:/msys64/usr/include/

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.

Hi,

Thanks for the reply.
For building SPIKE simulator with the shell script provided in riscv-tools repository build-spike-only.sh, 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.