Skip to content

Commit 3867fa3

Browse files
authored
doc: Add documentation for build nuclei toolchain
1 parent baa6372 commit 3867fa3

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

Build_Nuclei.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Build RISC-V GNU Toolchain For Nuclei
2+
3+
This guide is used to provide steps for build windows and linux version of **RISC-V GNU Toolchain for Nuclei**.
4+
5+
## Get toolchain sources
6+
7+
This repository uses submodules. You need the `--recursive` option to fetch the submodules automatically.
8+
9+
The Nuclei maintained source code is located in **nuclei-multilib** branch, please use this branch.
10+
11+
~~~
12+
cd ~
13+
git clone https://github.com/riscv-mcu/riscv-gnu-toolchain
14+
git checkout nuclei-multilib
15+
git submodule update --init --recursive
16+
~~~
17+
18+
## Install prerequisites
19+
20+
To build windows or linux version, you need to choose a proper version of linux distribution, here we recommend to use **Ubuntu 16.04 64bit** version, you can use docker tool to easily get this version if you already have installed Ubuntu.
21+
22+
You also need to install extra packages to build toolchain:
23+
24+
* To build linux toolchain, you need to install following packages using this command below:
25+
26+
~~~shell
27+
sudo apt-get install autoconf automake autotools-dev bc bison \
28+
build-essential curl dejagnu expect flex gawk gperf libtool patchutils texinfo
29+
~~~
30+
31+
* To build windows toolchain, you need to install following packages using this command below:
32+
33+
~~~shell
34+
sudo apt-get install autoconf automake autotools-dev bc bison \
35+
build-essential curl dejagnu expect flex gawk gperf \
36+
libtool patchutils texinfo python3 zip \
37+
mingw-w64 gdb-mingw-w64 libz-mingw-w64-dev
38+
~~~
39+
40+
For windows build, you also need to build `libexpat` using command below:
41+
42+
~~~shell
43+
wget https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.bz2
44+
tar -xjf expat-2.2.9.tar.bz2
45+
cd expat-2.2.9
46+
./configure --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32/
47+
make -j4
48+
sudo make install
49+
~~~
50+
51+
And then remove `zlib1.dll` and `libexpat-1.dll` using commands below(**execute using sudo**):
52+
53+
~~~shell
54+
for i in `find /usr/i686-w64-mingw32/ -name "*.dll"`; do sudo mv $i $i.bak; done
55+
[ -f /usr/x86_64-w64-mingw32/lib/zlib1.dll ] && sudo mv /usr/x86_64-w64-mingw32/lib/zlib1.dll /usr/x86_64-w64-mingw32/lib/zlib1.dll.bak
56+
[ -f /usr/i686-w64-mingw32/lib/libexpat.dll.a ] && sudo mv /usr/i686-w64-mingw32/lib/libexpat.dll.a /usr/i686-w64-mingw32/lib/libexpat.dll.a.bak
57+
[ -f /usr/i686-w64-mingw32/lib/libz.dll.a ] && sudo mv /usr/i686-w64-mingw32/lib/libz.dll.a /usr/i686-w64-mingw32/lib/libz.dll.a.bak
58+
[ -f /usr/x86_64-w64-mingw32/lib/libz.dll.a ] && sudo mv /usr/x86_64-w64-mingw32/lib/libz.dll.a /usr/x86_64-w64-mingw32/lib/libz.dll.a.bak
59+
~~~
60+
61+
## Build Linux Toolchain
62+
63+
**Make sure you have installed the required prerequisites and downloaded toolchain source code before build toolchain.**
64+
65+
Assumed your toolchain source code located in `~/riscv-gnu-toolchain`, and you want to build toolchain to `$HOME/riscv_lin`.
66+
67+
1. You can execute the following commands to build for **linux baremetal/newlib** toolchain:
68+
69+
~~~shell
70+
cd ~/riscv-gnu-toolchain
71+
export PREFIX=${HOME}/riscv_lin
72+
# Configure linux newlibc x64 build and enable multilib
73+
./configure --with-arch=rv32gc --enable-multilib --prefix=$PREFIX --with-cmodel=medany
74+
# Download extra prerequisites(GMP, MPFR and MPC libraries)
75+
# see https://gcc.gnu.org/install/download.html
76+
cd ./riscv-gcc/ && ./contrib/download_prerequisites
77+
cd -
78+
# change toolchain name to nuclei
79+
sed -i -e 's/make_tuple = riscv$(1)-unknown-$(2)/make_tuple = riscv-nuclei-$(2)/g' Makefile
80+
# If you want to build faster, you can change -j4 to -j
81+
export MAKE="make -j4"
82+
# Build toolchain, may cost about 1 hour depend on your machine
83+
make
84+
~~~
85+
86+
2. You can strip unused symbols to downsize the binaries using commands below if toolchain is built successfully, and tar the toolchain to `nuclei_gcc_lin64.tar.bz2`:
87+
88+
~~~shell
89+
cd $PREFIX
90+
set +e
91+
# Strip unused symbols in toolchain binaries
92+
for i in `find libexec bin -type f`; do strip -s $i ; done
93+
cd ..
94+
# archive the toolchain
95+
tar -jcf nuclei_gcc_lin64.tar.bz2 riscv_lin
96+
~~~
97+
98+
3. Then you can use this toolchain in linux 64bit environment with your riscv software.
99+
100+
If you want to check for sample build log, you can check our successful github ci build, such as https://github.com/riscv-mcu/riscv-gnu-toolchain/runs/1315017585
101+
102+
If you want to build for **linux glibc toolchain**, you can replace the **step 1** above with commands below, toolchain installed to `$HOME/riscv_glibc_lin`:
103+
104+
~~~shell
105+
cd ~/riscv-gnu-toolchain
106+
export PREFIX=${HOME}/riscv_glibc_lin
107+
# Configure linux glibc x64 build and enable multilib
108+
./configure --prefix=$PREFIX --with-arch=rv64gc --with-abi=lp64d --enable-multilib --with-cmodel=medany
109+
# Download extra prerequisites(GMP, MPFR and MPC libraries)
110+
# see https://gcc.gnu.org/install/download.html
111+
cd ./riscv-gcc/ && ./contrib/download_prerequisites
112+
cd -
113+
# change toolchain name to nuclei
114+
sed -i -e 's/make_tuple = riscv$(1)-unknown-$(2)/make_tuple = riscv-nuclei-$(2)/g' Makefile
115+
# If you want to build faster, you can change -j4 to -j
116+
export MAKE="make -j4"
117+
# Build toolchain, may cost about 1 hour depend on your machine
118+
make linux
119+
~~~
120+
121+
## Build Windows Toolchain
122+
123+
**Make sure you have installed the required prerequisites and downloaded toolchain source code before building toolchain.**
124+
125+
**You already build nuclei riscv toolchain for linux, and installed it into `$HOME/riscv_lin`.**
126+
127+
Assumed your toolchain source code located in `~/riscv-gnu-toolchain`, and you want to build toolchain to `$HOME/riscv_win`.
128+
129+
1. Export riscv nuclei linux toolchain to path to build newlib library for **windows baremetal/newlib** toolchain.
130+
131+
~~~shell
132+
export PATH=$HOME/riscv_lin/bin:$PATH
133+
~~~
134+
135+
2. You can execute the following commands to build for windows toolchain:
136+
137+
~~~shell
138+
cd ~/riscv-gnu-toolchain
139+
export PREFIX=${HOME}/riscv_win
140+
# Configure w32 newlibc build and enable multilib
141+
./configure --with-arch=rv32gc --enable-multilib --prefix=$PREFIX --with-host=i686-w64-mingw32 --with-cmodel=medany
142+
# Download extra prerequisites(GMP, MPFR and MPC libraries)
143+
# see https://gcc.gnu.org/install/download.html
144+
cd ./riscv-gcc/ && ./contrib/download_prerequisites
145+
cd -
146+
# change toolchain name to nuclei
147+
sed -i -e 's/make_tuple = riscv$(1)-unknown-$(2)/make_tuple = riscv-nuclei-$(2)/g' Makefile
148+
# If you want to build faster, you can change -j4 to -j
149+
export MAKE="make -j4"
150+
# Build toolchain, may cost about 1 hour depend on your machine
151+
make
152+
~~~
153+
154+
2. You can strip unused symbols to downsize the binaries using commands below if toolchain is built successfully, and zip the toolchain to `nuclei_gcc_win32.zip`:
155+
156+
~~~shell
157+
cd $PREFIX
158+
# Strip unused symbols in toolchain binaries
159+
for i in `find . -name *.dll`; do i686-w64-mingw32-strip -s $i ; done
160+
for i in `find . -name *.exe`; do i686-w64-mingw32-strip -s $i ; done
161+
cd ..
162+
# zip the toolchain
163+
zip -r -9 nuclei_gcc_win32.zip riscv_win
164+
~~~
165+
166+
3. Then you can use this toolchain in windows with your riscv software.
167+
168+
If you want to check for sample build log, you can check our successful github ci build, such as https://github.com/riscv-mcu/riscv-gnu-toolchain/runs/1315673828

0 commit comments

Comments
 (0)