linux4riscv-1: Install GNU toolchain for RISC-V
Recently, my instructor decided to update the project of operating system course. The new project is about porting Linux 0.11 to ARM64 and RISC-V as well as rewriting its interrupt, memory management, and file system, etc. My task is on RISC-V and I have no knowledge about it before, so I am to record what I have done and what I have learned. This is the first blog of this series. However, the source code will not be open-sourced as it will be used in operating system teaching in the future. Anyway, it’s a big project and hopefully I can finish it before the final exam.
Download source code of riscv-gnu-toochain
1 |
|
It may be too slow (50 KB/s) and too many problems (I downloaded it for a day, 我佛了), so I have uploaded it onto 浙大云盘 (Only ZJU students are allowed).
If you choose to download a prebuilt compiler, you can skip these three steps and go ahead to step Build qemu.
Prerequisites
1 |
|
Installation (Newlib)
1 |
|
Here we use /home/cliff/opt/riscv as default path of our toolchain. You can modify it as you like. It needs about 8GB spare space and takes a long time to compile. So I have uploaded the binary onto 浙大云盘 to reduce your workload. Now we can use riscv64-unknow-elf-gcc to compile programs for RISC-V.
Installation (Linux)
note: this step is not necessary as we need to write our own operating system rather than just run a program on the Linux. You can just skip this step.
1 |
|
We can find the compiler named riscv64-unknown-linux-gnu-gcc.
Build qemu
**Tips: **In this step, you may need to install some library. You can find related library package name you need use sudo apt-cache search package-name and then use sudo apt install package-name. For example, if you type sudo apt-cache search gcc, then you will get a series of packages with a string of gcc in its name.
1 |
|
If you get the following output, congratulations!
1 |
|
You can also download source file from qemu.org and build it by yourself.
Reference
[1] RISC-V GNU Compiler Toolchain
[2] Wiki.qemu