美文网首页GoCoding
RISC-V 软件环境

RISC-V 软件环境

作者: GoCodingInMyWay | 来源:发表于2023-02-05 09:50 被阅读0次

RISC-V 想玩起来,第一步,可以先准备软件环境。

官方仓库的 GNU 工具链 riscv-gnu-toolchain 里,有 Spike pkQEMU 的仿真环境,可以一次性把编译和仿真环境都准备好。

准备工具链

前提

如果是 Windows / WSL2 环境,在获取代码前,请确认工作目录属性是区分大小写的。因为 glibc 只能在区分大小写的文件系统上编译。不然,编译时会遇到链接错误,如 undefined reference to 'rtld_errno'

# 以管理员权限打开 Windows 终端
#  https://github.com/microsoft/terminal

# 查询工作目录区分大小写属性
fsutil.exe file queryCaseSensitiveInfo D:\wslcodes
已禁用目录 D:\wslcodes 的区分大小写属性。

# 启用工作目录区分大小写属性
fsutil.exe file setCaseSensitiveInfo D:\wslcodes enable
已启用目录 D:\wslcodes 的区分大小写属性。

如果是 Linux / Ubuntu 环境,那已经是区分大小写的了。

获取代码

git clone --depth 1 -b master https://github.com/riscv-collab/riscv-gnu-toolchain.git
cd riscv-gnu-toolchain
git submodule update --init --recursive

如果不用 QEMU 仿真,可以删除该子模块,加快下载:

git rm --cached qemu
git submodule update --init --recursive

编译安装

Ubuntu 20 上的编译过程。其他操作系统,请见工具链的 README。

# 依赖
sudo apt update -y
sudo apt 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 ninja-build -y
#  for spike
sudo apt install device-tree-compiler -y

# 配置
#  --enable-multilib 支持 32-bit 与 64-bit,默认 64-bit
#  --with-sim=spike 带上 Spike 模拟器 (only support rv64* bare-metal/elf toolchain)
./configure --prefix=/opt/riscv --enable-multilib --with-sim=spike

# 编译
sudo make linux build-sim

# 环境
#  可以进 ~/.bashrc,但影响系统 gcc 环境
export RISCV_HOME=/opt/riscv
export PATH=$RISCV_HOME/bin:$RISCV_HOME/riscv64-unknown-elf/bin:$PATH

# 测试
riscv64-unknown-elf-gcc --version
spike -h

编译程序并运行

编写文件 hello.c:

#include <stdio.h>

int main(int argc, char const *argv[]) {
  printf("hello riscv\n");
  return 0;
}

编译程序:

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

Spike 运行:

# 默认 64-bit,故用 pk64,另有 pk32
$ spike $(which pk64) hello
bbl loader
hello riscv

# spike debug 运行
$ spike -d $(which pk64) hello
: h

更多资料

GoCoding 个人实践的经验分享,可关注公众号!

相关文章

  • RISC-V 软件环境

    RISC-V[https://riscv.org/] 想玩起来,第一步,可以先准备软件环境。 官方仓库的 GNU ...

  • RISC-V简介

    简介 MIT6.004课程中的指令集使用的是RISC-V。 RISC-V(发音为“risk-five”)是一个基于...

  • Open Source RISC – Eclipse with

    Open Source RISC – Eclipse with RISC-V on the SiFive HiFi...

  • RISC-V 官网漫游

    RISC-V (pronounced “risk-five”) is an open, free ISA enab...

  • windows下RISC-V编译调试环境搭建

    前言 当开源变得越来越流行,开放的标准,开源的语言,开源的操作系统(Linux、freeBSD、freeRTOS)...

  • RISC-V

    sifive freedom-u-sdk attribute ((section(".text")))的测试 Bo...

  • 软件开发环境简介

    软件开发环境简介 软件开发环境SDE(Software Development Environment)是指在基本...

  • 造价 | 软件环境

    内容目录 前言 系统要求 加密锁 常用软件以及一些私货推荐 常见问题 前言 对于造价工程师而言,PC端软件的应用已...

  • 软件与环境

    软件与环境 软件 服务器系统:Ubuntu 最新 LTS PHP:PHP 7 MySQL:MySQL 5.7 其他...

  • linux系统安装go环境

    centos 安装 go 环境 环境与软件包名称 系统环境: centos7.5go软件包: go1.17....

网友评论

    本文标题:RISC-V 软件环境

    本文链接:https://www.haomeiwen.com/subject/ndvahdtx.html