Hi
I create program for 32bit of Sifife E300.
I try to use the freedom-e-sdk.
Clone https://github.com/sifive/freedom-e-sdk and try create demo_gpio by
make software BSP=legacy PROGRAM=demo_gpio BOARD=freedom-e300-hifive1
Compiler say error.
I corrected:
a) Makefile #CROSS_COMPILE ?= riscv64-unknown-elf
CROSS_COMPILE ?= riscv32-unknown-elf
You didn’t specify the error you got from the toolchain, forcing me to guess what went wrong. You will get a better answer if you provide a more complete bug report.
A multilib 64-bit toolchain can produce 32-bit code with the right options. The toolchains that SiFive releases are all multilib enabled. The right options are -march=rv32imac -mabi=ilp32. The bsp/env/freedom-e300-hifive1/settings.mk file defins RISCV_ARCH and RISCV_ABI to get the right result.
If you built your own toolchain, then perhaps you didn’t enable the multilib support. Use --enable-multilib when configuring the toolchain.
If you did use our toolchain, then you perhaps hit a bug in freedom-e-sdk. A major rewrite of freedom-e-sdk started in December, and there have been various problems with it since. I would suggest trying the last known good commit, before the rewrite started, which was in September.
$ ./configure --prefix=/home/petr.andreev/rv32 --with-arch=rv32imac --with-abi=ilp32 --enable-multilib
make linux
After finish “~/rv32/bin” contained only riscv32-unknown-linux-gnu-*".
If I try compile demo_gpio freedom-e-sdk make say:
make[1]: riscv64-unknown-elf-gcc: Command don’t found
I see problem - riscv64-unknown-elf-gcc don’t generated for me.
I need extra option for configuring the toolchain.
Drop the --with-arch and --with-abi options, keep the --enable-multilib option. That will give you a rv64 compiler that emits rv64/lp64d by default, but which can also emit rv32 code. When compiling, invoke the rv64 compiler with -march=rv32imac -mabi=ilp32. This is how freedom-e-sdk and other SiFive software expects the compiler to be configured.
You can of course change the makefiles to use a riscv32 compiler instead if you want.
You typed “make linux”. That builds a linux compiler. “make newlib” will build an elf compiler. However, I would suggest using just plain “make” instead, and using --disable-linux or --enable-linux configure options to choose whether you want to build an embedded elf or linux toolchain by default, and using different build trees for your linux and elf compilers… --disable-linux is the default.
I don’t recommend using “make linux” or “make newlib” because it can give confusing results. E.g. if you use “make linux” and then “make check” , then the make check will first build an elf compiler and test it which is confusing. You would have to remember to use “make check-linux” to test the linux compiler. However, if you use --enable-linux, then it is just “make” and “make check” to build and test the linux compiler.
Note that you can have build trees separate from the source tree. So you can do something like
mkdir X-rv64-lp64d-linux
cd X-rv64-lp64d-linux
../riscv-gnu-toolchain/configure --enable-linux --with-arch=rv64 --with-abi=lp64d --prefix=whatever
make
If you do builds this way, you can have multiple build trees for the same source tree. And if you make a mistake, you can fix it with rm -rf. Most all GNU tools support configuring outside the source dir.