# How to create "riscv-gnu-toolchain" to allow freedom-e-sdk to create 32bit demo\_gpio?

**URL:** <https://forums.sifive.com/t/how-to-create-riscv-gnu-toolchain-to-allow-freedom-e-sdk-to-create-32bit-demo-gpio/1975>\
**Category:** Freedom E300\
**Created:** [January 15, 2019, 1:09pm UTC](https://forums.sifive.com/t/how-to-create-riscv-gnu-toolchain-to-allow-freedom-e-sdk-to-create-32bit-demo-gpio/1975 "2019-01-15T13:09:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_A](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@Peter\_A](https://forums.sifive.com/u/Peter_A)\
**Post date:** [January 15, 2019, 1:09pm UTC](https://forums.sifive.com/t/how-to-create-riscv-gnu-toolchain-to-allow-freedom-e-sdk-to-create-32bit-demo-gpio/1975/1 "2019-01-15T13:09:53Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![jimw](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jimw](https://forums.sifive.com/u/jimw)\
**Post date:** [January 15, 2019, 5:26pm UTC](https://forums.sifive.com/t/how-to-create-riscv-gnu-toolchain-to-allow-freedom-e-sdk-to-create-32bit-demo-gpio/1975/2 "2019-01-15T17:26:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Peter\_A](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@Peter\_A](https://forums.sifive.com/u/Peter_A)\
**Post date:** [January 17, 2019, 10:59am UTC](https://forums.sifive.com/t/how-to-create-riscv-gnu-toolchain-to-allow-freedom-e-sdk-to-create-32bit-demo-gpio/1975/3 "2019-01-17T10:59:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jimw](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jimw](https://forums.sifive.com/u/jimw)\
**Post date:** [January 17, 2019, 4:40pm UTC](https://forums.sifive.com/t/how-to-create-riscv-gnu-toolchain-to-allow-freedom-e-sdk-to-create-32bit-demo-gpio/1975/4 "2019-01-17T16:40:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Peter\_A](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@Peter\_A](https://forums.sifive.com/u/Peter_A)\
**Post date:** [January 18, 2019, 11:15am UTC](https://forums.sifive.com/t/how-to-create-riscv-gnu-toolchain-to-allow-freedom-e-sdk-to-create-32bit-demo-gpio/1975/5 "2019-01-18T11:15:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jimw](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jimw](https://forums.sifive.com/u/jimw)\
**Post date:** [January 18, 2019, 5:24pm UTC](https://forums.sifive.com/t/how-to-create-riscv-gnu-toolchain-to-allow-freedom-e-sdk-to-create-32bit-demo-gpio/1975/6 "2019-01-18T17:24:47Z")

</div>

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

```auto
  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.

---

<div class="post-metadata">

**Author:** ![Peter\_A](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@Peter\_A](https://forums.sifive.com/u/Peter_A)\
**Post date:** [January 22, 2019, 2:28pm UTC](https://forums.sifive.com/t/how-to-create-riscv-gnu-toolchain-to-allow-freedom-e-sdk-to-create-32bit-demo-gpio/1975/7 "2019-01-22T14:28:36Z")

</div>

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
