Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build RISC-V compiling environment and running environment

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to build RISC-V compilation environment and running environment, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

Our chips are now choked by the United States, so RISC-V is the trend of the times. There is also RISC-V in the https://repo.huaweicloud.com/harmonyos/compiler/ provided by Huawei Hongmeng. Although there are few hardware resources, but through the software simulation environment, we can make preparations in advance.

RISC-V GNU Toolchain source code acquisition

To experience RISC-V, you first need to install a cross-compiler. However, the domestic network is very poor, so it is very difficult to get source code (https://github.com/riscv/riscv-gnu-toolchain) compilation on GitHub. Fortunately, there are mirrors (https://gitee.com/mirrors/riscv-gnu-toolchain) on Gitee, which are synchronized once a day.

Get the source code:

Git clone https://gitee.com/mirrors/riscv-gnu-toolchain.gitcd riscv-gnu-toolchaingit submodule update-init-recursive

However, when I get the code through Gitee, the download speed of the submodule is still very slow, especially one of the submodules in QEMU. So I removed QEMU from the synchronization because it didn't affect the compilation:

Git rm-cached QEMUgit submodule update-init-recursive

Considering the download speed, I put all the code I got on Gitee (https://gitee.com/yushulx/riscv-gnu-toolchain). This code base is not updated and is only available to people who are poor on the network and need to experience RISC-V. If you need the latest code, go to GitHub or Gitee image.

Compilation and installation

Next, follow the official tutorial to compile.

Dependent tool

Ubuntu

$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

Fedora/CentOS/RHEL OS

$sudo yum install autoconf automake python3 libmpc-devel mpfr-devel gmp-devel gawk bison flex texinfo patchutils gcc gcc-c++ zlib-devel expat-devel

Arch Linux

$pacman-Syyu autoconf automake curl python3 mpc mpfr gmp gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib expat

OS X

$brew install python3 gawk gnu-sed gmp mpfr libmpc isl zlib expat compiles GCC

Compile riscv64-unknown-elf-gcc:

. / configure-- prefix=/opt/riscvsudo make

Compile 64-bitriscv64-unknown-linux-gnu-gcc:

. / configure-- prefix=/opt/riscvsudo make linux

Compile 32-bit:

. / configure-- prefix=/opt/riscv-- with-arch=rv32gc-- with-abi=ilp32dsudo make linux

Compile 32-bit and 64-bit:

. / configure-prefix=/opt/riscv-enable-multilibsudo make linux

The difference between the two gcc is that elf-gcc is a static link and linux-gnu-gcc is a dynamic link.

RISC-V operating environment

The difference between Simulator and Emulator is that Emulator provides a complete simulation environment.

Simulator

First compile and install competition: https://github.com/riscv/riscv-pk.

Then compile and install spike: https://github.com/riscv/riscv-isa-sim

Compiler

Riscv64-unknown-elf-gcc-o hello hello.c

Running

Spike $(which Competition) hello

Note that if you compile with riscv64-unknown-linux-gnu-gcc, the run will report an error:

Bbl loadernot a statically linked ELF programEmulator

Download and install QEMU https://www.qemu.org/download/#source

Refer to the tutorial to run the simulation environment: https://wiki.qemu.org/Documentation/Platforms/RISCV

You can also use tinyemu: https://bellard.org/tinyemu/

Fedora image acquisition: https://dl.fedoraproject.org/pub/alt/risc-v/repo/virt-builder-images/images/

Decompress the image:

Unxz Fedora-Minimal-Rawhide-*-sda.raw.xz

Start the simulator:

Qemu-system-riscv64\-nographic\-machine virt\-smp 4\-m 2G\-kernel Fedora-Minimal-Rawhide-*-fw_payload-uboot-qemu-virt-smode.elf\-bios none\-object rng-random,filename=/dev/urandom,id=rng0\-device virtio-rng-device,rng=rng0\-device virtio-blk-device,drive=hd0\-drive file=Fedora-Minimal-Rawhide-20200108.n.0-sda.raw,format=raw Id=hd0\-device virtio-net-device,netdev=usernet\-netdev user,id=usernet,hostfwd=tcp::10000-:22

Login user name riscv, password fedora_rocks!

Copy the program to the simulator:

Scp @: /. /

Programs compiled by riscv64-unknown-elf-gcc and riscv64-unknown-linux-gnu-gcc can be run normally in the simulator environment.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report