OpenCores
URL https://opencores.org/ocsvn/steelcore/steelcore/trunk

Subversion Repositories steelcore

[/] [docs/] [software.md] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 rafaelcalc
# Compiling software for Steel
2
 
3
The [RISC-V GNU Toolchain](https://github.com/riscv/riscv-gnu-toolchain) provides the Newlib cross-compiler, which can be used to compile software for Steel. To configure the compiler for Steel and install it follow these steps:
4
 
5
**1 - Clone the toolchain repo and all its submodules:**
6
```
7
$ git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
8
```
9
**2 - Install the prerequisites, according to your OS:**
10
 
11
On Ubuntu:
12
```
13
$ sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev
14
```
15
On Fedora/CentOS/RHEL OS:
16
```
17
$ sudo yum install autoconf automake python3 libmpc-devel mpfr-devel gmp-devel gawk  bison flex texinfo patchutils gcc gcc-c++ zlib-devel expat-devel
18
```
19
On Arch Linux:
20
```
21
$ pacman -Syyu autoconf automake curl python3 mpc mpfr gmp gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib expat
22
```
23
On OS X:
24
```
25
$ brew install python3 gawk gnu-sed gmp mpfr libmpc isl zlib expat
26
```
27
**3 - Configure the installation for Steel (the toolchain will be installed in the path /opt/riscv):**
28
```
29
$ cd riscv-gnu-toolchain
30
$ ./configure --prefix=/opt/riscv --with-arch=rv32i --with-abi=ilp32
31
```
32
**4 - Make the compiler:**
33
```
34
$ make
35
```
36
 
37

Compiling your program

38
 
39
A program can be compiled to run on Steel with the following command (assuming you have installed the toolchain in the path `/opt/riscv`):
40
```
41
$ cd /opt/riscv/bin
42
$ riscv32-unknown-elf-gcc --with-arch=rv32i --with-abi=ilp32 myprogram.c -o myprogram
43
```
44
The compiler will output an ELF file named **myprogram**. The flags `--with-arch=rv32i` and `--with-abi=ilp32` are optional if you have configured the compiler following the instructions in the section above.
45
 
46
To relocate the code to start at a specific address you can use the flag `-Ttext`. For example:
47
```
48
$ cd /opt/riscv/bin
49
$ riscv32-unknown-elf-gcc --with-arch=rv32i --with-abi=ilp32 -Ttext 0x00000000 myprogram.c -o myprogram
50
```
51
 
52
> **Tip:** If you are using an FPGA and your system's RAM is an array of memory, you may need to transform your program (which is an ELF file) into an .hex file. By doing this, you can use the .hex file with Verilog's **$readmemh** function to fill the memory array. To generate an .hex file from your compiled program, execute the following commands:
53
```
54
$ cd /opt/riscv/bin
55
$ riscv32-unknown-elf-objcopy -O binary myprogram myprogram.bin
56
$ od -t x4 -v -An -w1 myprogram.bin > myprogram.dump
57
$ cut -c2- myprogram.dump > myprogram.hex
58
$ rm myprogram.bin myprogram.dump
59
```
60
> The **util** directory has a script called **elf2hex** that transforms an ELF into an .hex file. See the contents of the file **soc/ram.v** to learn how to build a RAM memory using Verilog arrays.

powered by: WebSVN 2.1.0

© copyright 1999-2021 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.