Step 1:安装一些编译riscv需要的库:

  

sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev

  但是如果遇到了install失败的时候,可以选择使用其他的镜像:

  进入 https://mirrors.ustc.edu.cn/repogen/ 选择自己的linux版本,比如说Ubuntu的apt/sources.list右击Download复制连接地址;

touch sources.list-backup
rm sources.list
wget https://mirrors.ustc.edu.cn/repogen/conf/ubuntu-https-4-kinetic
apt-get update
apt-get upgrad

  之后应该就可以安装成功了

Step 2:安装工具riscv-tool和riscv-gnu-tools

   因为都是比较大的,所以我选择先git然后对子目录进行--recursive

git clone https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
git clone --recursive https://github.com/riscv/riscv-qemu.git
git clone --recursive https://github.com/riscv/riscv-newlib.git
git clone --recursive https://github.com/riscv/riscv-binutils-gdb.git
git clone --recursive https://github.com/riscv/riscv-dejagnu.git
git clone --recursive https://github.com/riscv/riscv-glibc.git
git clone --recursive https://github.com/riscv/riscv-gcc.git 
git clone https://github.com/riscv/riscv-tools.git
cd riscv-tool
git clone --recursive https://github.com/riscv/riscv-isa-sim.git
git clone --recursive https://github.com/riscv/riscv-opcodes.git
git clone --recursive https://github.com/riscv/riscv-pk.git
git clone --recursive https://github.com/riscv/riscv-tests.git

Step 3: 编译工具链

vi ~/.bashrc
# 添加:
exprort RISCV="~/riscv_related/riscv-gnu-toolchain"
export PATH=$PATH:$RISCV/bin
# 退出执行
source ~/.bashrc
mkdir riscv-gnu-toolchain-build
cd riscv-gnu-toolchain-build
../riscv-gnu-toolchain/configure --prefix=$RISCV
make linux

  这里configure和make的选项有很多 

  如果希望是搭建linux上的话环境需要make linux;否则到时候会提示找不到elf文件等

  过程中可能会提示已经 directory not empty:

  可以进入相应的文件夹中:

rm -rf riscv-binutils
rm -rf riscv-gdb
cd riscv-binutils-gdb
cp -a * ../riscv-binutils
cp -a * ../riscv-dbd

Step 4:编译工具riscv-tool

cd riscv-tools
./build.sh
# 问题1 :undefined macro AC_DEFINED
apt-get install libsys-dev
apt-get install pkg-config
# 问题2:No rule to make target all
apt-get install fesvr
# 问题3:runtimeerror is not a member of std
vi fesvr/dtm.cd
#include<stdexcept>

Step 5:安装qemu:

# 首先git安装qemu
# 我的提示没有python
apt-get install python-is-python3
# 查看版本
whereis python
# 安装glib,gthread:
apt-get install libglib2.0-dev
apt-get install libpixman-1-dev
./configure -disable-werror
make
make install

Step 6: 安装busybear

mkdir linux
git clone https://github.com/michaeljclark/busybear-linux.git
cd busybear-linux
make
# 问题1: stime有问题 --> 好像已经被废弃了
# 暴力解决方法:更换版本:但是不能直接将新的替换
# 查勘Makefile会发现每次都是会重新下载busybox的
cd conf
vi busybear.config
BUSYBOX_VERSION = 1.34.0
# 问题2:multiple definition of yylloc
# 是gcc版本太高的原因:
cd riscv-gnu-toolchain
cd riscv-gcc
cd gcc
vi BASE-VER
# 修改为9.5.0(小于10就可以)

Step 7:下载RISCV-Linux

cd linux
git clone https://github.com/riscv/riscv-linux.git
cd riscv-linux
git checkout riscv-linux-4.14
cp ../busybear-linux/conf/linux.config .config
make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- olddefconfig
make ARCH=riscv vmlinux

Step 8:安装BBL

git clone https://github.com/riscv/riscv-pk.git
cd riscv-pk
mkdir build
cd build
../configure --enable-logo --host=riscv64-unknown-linux-gnu- --with-payload=../../riscv-linux/vmlinux

Step 9:使用二进制文件:

mkdir release
cd release
wget https://github.com/michaeljclark/busybear-linux/releases/download/v1.0/bbl.bz2
wget https://github.com/michaeljclark/busybear-linux/releases/download/v1.0/busybear.bin.bz2
bzip2 -d *.bz2

Step 9 :登录:

sudo qemu-system-riscv64 -nographic -machine virt   -kernel bbl -append "root=/dev/vda ro console=ttyS0"  -drive file=busybear.bin,format=raw,id=hd0   -device virtio-blk-device,drive=hd0 -device virtio-net-device,netdev=net0

登录用户名:root

登录密码:busybear

然后就可以运行啦

# 测试命令
uname -a
# 结束退出
halt

最新文章

  1. phpstorm的使用教程
  2. Win10 Build9926 更新问题解决
  3. iocp还是select
  4. JQuery基础教程:选择元素(中)
  5. 关于select @@IDENTITY的初识
  6. Redis 三:存储类型之字符串
  7. 如何在版本控制工具中管理Sencha Architect的項目
  8. Exception in thread "main" org.hibernate.TransientObjectException: object references an unsaved tran
  9. 百度统计的JS脚本原理分析
  10. 【开发技术】Beyond Compare
  11. 抓取Android应用的log
  12. iOS 如何查看APP的jetsamEvent日志
  13. input reset 重置时间
  14. 跟随我在oracle学习php(6)
  15. CodeForces - 444C
  16. 面象对象设计原则之五:依赖倒置原则(The Dependency Inversion Principle,DIP)
  17. printf、fprintf、sprintf和snprintf 区别
  18. javascript与 ios通讯解决办法
  19. WebLogic(12C)——几个基本概念
  20. shell基本认识

热门文章

  1. Array list练习
  2. Grafana 系列文章(九):开源云原生日志解决方案 Loki 简介
  3. 带你读AI论文丨S&amp;P21 Survivalism: Living-Off-The-Land 经典离地攻击
  4. redis使用bitmap实现签到
  5. Nginx01 简介和安装
  6. Java 如何通过JDBC 操作数据库
  7. LG P3768 简单的数学题
  8. Nacos服务调用(基于Openfeign)
  9. 代码随想录算法训练营day01 | leetcode 704/27
  10. 登峰造极,师出造化,Pytorch人工智能AI图像增强框架ControlNet绘画实践,基于Python3.10