Building Hello World on Freedem-E-SDK fails with "unknown CSR `mtvt'"

Hi, newbie here, I’m just trying to get started with Freedom-E-SDK. Building the Hello World example fails a few steps into the build process with the following:

…/freedom-e-sdk/freedom-metal/src/drivers/riscv,cpu.c: Assembler messages:
…/freedom-e-sdk/freedom-metal/src/drivers/riscv,cpu.c:139: Error: unknown CSR mtvt' .../freedom-e-sdk/freedom-metal/src/drivers/riscv,cpu.c:161: Error: unknown CSRmtvt’
…/freedom-e-sdk/freedom-metal/src/drivers/riscv,cpu.c:165: Error: unknown CSR `mtvt’
Makefile:1010: recipe for target ‘src/drivers/libriscv__mmachine__sifive-hifive1_a-riscv,cpu.o’ failed
make[1]: *** [src/drivers/libriscv__mmachine__sifive-hifive1_a-riscv,cpu.o] Error 1
make[1]: Leaving directory ‘…/freedom-e-sdk/bsp/sifive-hifive1/build/debug’
scripts/ recipe for target ‘…/freedom-e-sdk/bsp/sifive-hifive1/install/lib/debug/stamp’ failed
make: *** […/freedom-e-sdk/bsp/sifive-hifive1/install/lib/debug/stamp] Error 2

Any help on that would be greatly appreciated.

You have to use a SiFive toolchain, because freedom-e-sdk requires support for the proposed CLIC extension, which is only supported in SiFive toolchains currently, because it is still a proposal. mtvt is one of the CSRs added by the CLIC extension.

CLIC support is needed even if you are building for a target that doesn’t support the CLIC extension. There is an open issue for that problem, reported against freedom-metal I think.

You can download binaies from our web site. Or you can check out our repo and use that to build a compiler.

Thx. I can’t build the SiFive toolchain. I’ll put that in another question.

I had similar problem with the toolchain from riscv-gnu-toolchain repo.

@jimw I don’t think SiFive toolchain would work with FE310, which requires -march=rv32imac -mabi=ilp32 -mcmodel=medlow options, and a riscv64-unknown-elf toolchain can’t support that. The compiler shows that

/usr/local/lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /usr/local/
./../../riscv64-unknown-elf/lib/crt0.o: ABI is incompatible with that of the selected emulation:
  target emulation `elf64-littleriscv` does not match `elf32-littleriscv`

Sure, it works:

bruce@rip:~/riscv/tests$ riscv64-unknown-elf-gcc -march=rv32imac -mabi=ilp32 -mcmodel=medlow hello.c -o hello
bruce@rip:~/riscv/tests$ file hello
hello: ELF 32-bit LSB executable, UCB RISC-V, version 1 (SYSV), statically linked, not stripped
bruce@rip:~/riscv/tests$ ls -l hello
-rwxr-xr-x 1 bruce bruce 16408 Sep 20 08:39 hello

It seems that you don’t have the correct libraries. You need to build the toolchain either with the actual arch/abi you want to use, or else with --enable-multilib

./configure --prefix=/opt/riscv --enable-multilib
1 Like

The SiFive toolchain does support the FE310. That is the whole purpose of releasing our own toolchains to support our own hardware.

The error message suggests that you are invoking the compiler wrong, or else if you built the compiler yourself you built it wrong. So first question, did you download a binary from our web site or did you try to build your own? If you built your own, how did you configure it? You either need to use --enable-multilib to support multiple arch/abi combinations, or else you need to use --with-arch/–with-abi configure options to build a toolchain that supports the one arch/abi combination you care about. If you downloaded a toolchain, how exactly are you invoking the compiler? Are you passing the -march/-mabi options both when compiling and when linking? If you use them when compiling but not linking you will get this error.

1 Like

Thank you for your valuable feedback. After rebuilding the riscv-gnu-toolchain, I can reproduce Bruce’s successful compilation. I think the issue is with the environment variables I have, and the correct setting should be

export RISCV_PATH=/opt/riscv
# setting RISCV=/opt/riscv would not be helpful
export CROSS_COMPILE=riscv32-unknown-elf

setting CROS_COMPILE is necessary when I have compilers with riscv64-unknown-elf prefix.