How to create "riscv-gnu-toolchain" to allow freedom-e-sdk to create 32bit demo_gpio?

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

b)/bsp/env/common.mk
#LDFLAGS += -L$(ENV_DIR) --specs=nano.specs
#CFLAGS += -march=$(RISCV_ARCH)
#CFLAGS += -mabi=$(RISCV_ABI)

After this correction file demp_gpio was created.

How to create “riscv-gnu-toolchain” to allow freedom-e-sdk to create 32bit demo_gpio without correction /bsp/env and Makefile?

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.

Hi Jim.

$ ./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.

Thanks.

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.

Hi
$ ./configure --prefix=/scratch/rv32 --enable-multilib
make linux

In /scratch/rv32/bin only "riscv64-unknown-linux-gnu-".
There is no riscv64-unknown-elf-
as requared Makefile from freedom-e-sdk.

If I try compile demo_gpio freedom-e-sdk make say:
make[1]: riscv64-unknown-elf-gcc: Command don’t found

I substitute compiler
#CROSS_COMPILE ?= riscv64-unknown-elf
CROSS_COMPILE ?= riscv64-unknown-linux-gnu

Compilation started, but

/scratch/rv32/lib/gcc/riscv64-unknown-linux-gnu/8.2.0/…/…/…/…/riscv64-unknown-linux-gnu/bin/ld: /home/petr.andreev/work_pp/w550_riskv/freeRTOS/from_sifive/fr05/bsp/env/start.o: in function .L0 ': /home/petr.andreev/work_pp/w550_riskv/freeRTOS/from_sifive/fr05/bsp/env/start.S:42: undefined reference to__libc_fini_array’
/scratch/rv32/lib/gcc/riscv64-unknown-linux-gnu/8.2.0/…/…/…/…/riscv64-unknown-linux-gnu/bin/ld: /home/petr.andreev/work_pp/w550_riskv/freeRTOS/from_sifive/fr05/bsp/env/start.S:46: undefined reference to __libc_init_array' collect2: error: ld returned 1 exit status make[1]: *** [demo_gpio] Error 1 make[1]: exit from/home/petr.andreev/work_pp/w550_riskv/freeRTOS/from_sifive/fr05/software/demo_gpio’
make: *** [software] Error

Do you have any other suggestions?

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.

2 Likes

Thanks Jim!

$ ./configure --prefix=/scratch/rv32a --enable-multilib
make newlib

Then

make software BSP=legacy PROGRAM=demo_gpio BOARD=freedom-e300-hifive1

Sucsessfuly finished!

Yours
Peter Andreev