RISC-V GNU 工具链:安装与使用
1. 安装Wmware和unbuntu,我安装的是Wmware workstation pro 12.1.1 build-3770994, unbuntu 是18.04.2 amd版本, ubuntu-18.04.2-desktop-amd64.iso
2. 安装好unbuntu后,在/home/{username}目录里面创建目录riscv, 我的用户名是kaguo,所以创建的目录就是/home/kaguo/riscv
3. cd /home/kaguo/riscv , 进入riscv目录后,执行以下命令,安装一些编译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
详见:https://github.com/riscv/riscv-gnu-toolchain
建议把ubuntu的源镜像改为阿里云的,我开始用默认的会遇到 libtool库不能更新的问题。请参考
https://yq.aliyun.com/articles/639051
可以用下面命令先安装vim和gvim
sudo apt-get install vim
sudo apt-get install vim-gtk
4. 在riscv目录中执行以下命令,
sudo apt install git //首先安装git
git clone https://github.com/riscv/riscv-tools.git
接着你可以用下面的命令
$ git submodule update --init --recursive
将会下载下面的几个模块
- Spike, the ISA simulator
- riscv-tests, a battery of ISA-level tests
- riscv-opcodes, the enumeration of all RISC-V opcodes executable by the simulator
- riscv-pk, which contains
bbl, a boot loader for Linux and similar OS kernels, andpk, a proxy kernel that services system calls for a target-machine application by forwarding them to the host machine
但是如果网络环境不好,可以使用下面命令一个模块一个模块单独下载:
git clone --recursive https://github.com/riscv/riscv-openocd.git
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
5.下载riscv gun toolchain,
在目录/home/kaguo/riscv,执行
git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
或者
git clone https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
git submodule update --init --recursive
将会下载riscv gun工具链,网络环境不好的化,可以按下面的方法,一个模块一个模块单独下载:
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
因为这样下载的目录和前一种方式不同,主要是qemu和gdb,binutils三个模块,可以进行一些copy工作,使得qemu, riscv-binutils,riscv-gdb三个目录有数据,否则编译会出错。
cd riscv-qemu
cp -a * ../qemu
cd riscv-binutils-gdb
cp -a * ../riscv-gdb
cp -a * ../riscv-binutils
6.先编译riscv gun toolchain,再编译riscv tools,否则pk模块会编译出错
cd /home/kaguo/riscv/riscv-tools/riscv-tools/riscv-gnu-toolchain,
vim ~/.bashrc
在最后增加两行,
export RISCV="/home/kaguo/riscv/riscv-tools/riscv-gnu-toolchain"
export PATH=$PATH:$RISCV/bin
然后source ~/.bashrc
现在用下面的命令开始编译riscv gun tool chain
./configure --prefix=$RISCV
make
https://github.com/riscv/riscv-gnu-toolchain
这样会编译出64位的gcc riscv工具链,如果想同时产生32位工具链,可以用下面的命令
./configure --prefix=$RISCV --with-arch=rv32gc --with-abi=ilp32d
make
如果出现ifconfig不能找问题,安装net-tools
sudo apt-get install net-tools
7. 回到上一级目录,cd /home/kaguo/riscv/riscv-tools/riscv-tools/
执行下面命令编译riscv tools
./build.sh
编译完后,大部分可以执行文件都会安装到$RISCV/bin目录,单似乎pk的默认没有安装。
如果遇到下面错误,可以删除openocd 目录,用git clone --recursive https://github.com/riscv/riscv-opcodes.git 重新下载。
Configuring project riscv-openocd
configure: error: cannot find install-sh, install.sh, or shtool in ".." "../.." "../../.."
进入 cd /home/kaguo/riscv/riscv-tools/riscv-tools/riscv-pk/build
cp pk dummy_payload config.status bbl_payload bbl /home/kaguo/riscv/riscv-tools/riscv-tools/riscv-gnu-toolchain/bin
把pk的可执行文件copy到$RISCV/bin目录。
8. 最后一步,测试运行。
编写hello.c文件
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
编译hello.c,生产riscv的可执行文件hello
riscv64-unknown-elf-gcc -o hello hello.c
这时候的 hello,并不能用./hello执行,因为它是riscv asi的机器码,而我们的计算机是x86平台,我们可以spike模拟器来执行该文件。
spike pk hello
结果为:
kaguo@ubuntu:~/riscv/riscv-tools/riscv-tools$ spike pk hello
bbl loader
Hello World!
注意:因为spike默认要分配2G的内存,所以我们要给虚拟机分配2G以上的内存空间,否则会出现下面的错误,我为ubuntu分配的内存是4G。
kaguo@ubuntu:~/riscv/riscv-tools/riscv-tools/riscv-gnu-toolchain$ spike
terminate called after throwing an instance of 'std::runtime_error'
what(): couldn't allocate 2147483648 bytes of target memory
Aborted (core dumped)
spike -m128 pk hello或者我们可以用m参数,每次制定为spike分配的内存数量。
RISC-V GNU 工具链:安装与使用的更多相关文章
- 使用GNU工具链进行嵌入式裸机开发
Embedded-Programming-with-the-GNU-Toolchain Vijay Kumar B. vijaykumar@bravegnu.org 翻译整理:thammer gith ...
- GNU工具链学习笔记
GNU工具链学习笔记 1..so为动态链接库,.a为静态连接库.他们在Linux下按照ELF格式存储.ELF有四种文件类型.可重定位文件(Relocatable file,*.o,*.a),包含代码和 ...
- hisiv100交叉编译工具链安装
hisi交叉编译工具链安装 一. 摘要: 交叉编译简单的说,就是A机器上编译生成,运行在B机器上.那么在A机器上的编译工具安装,就是本文所要描述的内容. 工欲善其事必先利其器,所以交叉 ...
- Linux简单程序实例(GNU工具链,进程,线程,无名管道pipe,基于fd的文件操作,信号,scoket)
一, GNU工具链简介: (1)编译代码步骤: 预处理 -> 编译 -> 汇编 -> 链接: 预处理:去掉注释,进行宏替换,头文件包含等工作: gcc -E test.c -o te ...
- Ubuntu16.04交叉工具链安装
前言: 开发环境是64位的ubuntu16.04,交叉工具链是通过sudo apt-get install ....安装的,移植uboot2014.10,但是很奇怪,按照网上的介绍在start.s里面 ...
- linux 学习笔记 GNU工具链简介
我们通常无法直接通过Linux内核,而需要借助Linux内核之上的GUN工具链来进行 文件处理 文本操作 进程管理 等操作. GNU/Linux shell为用户提供了 启动程序 管理文件系统上的文件 ...
- Linux交叉工具链安装
这篇博文http://blog.csdn.net/u010957054/article/details/58056863 提到了一个好的百度网盘,里面有各个版本的交叉工具链. http://www.3 ...
- DIY FRDM-KL25Z开发环境 -- 基于GNU工具链
IDE大行其道的今天,一键make极大的便利了开发的同时,也每每让各种半路出家的猿们遇到工具链的问题感到束手无策(不就是说自己嘛?^_^!!!).也玩过不少板子了,始终没去深究工具链方面的问题,对于嵌 ...
- 64位的ubuntu14.04 LTS安装 Linux交叉编译工具链及32位“ia32-libs”依赖库
ubuntu又迎来了其新一代的长期支持版本 14.04 LTS,其带来了许多令人期待的新特新,遂决定进行升级. 装好了64位版本及安装 Linux交叉编译工具链 运行GCC,${CROSS_COMPI ...
随机推荐
- 每天一套题打卡|河南省第八届ACM/ICPC
A 挑战密室 化学方程式求分子量 这题我懒得写了 可以用map<string,int>哈希表,表示每种分子的相对分子质量 之后,从头遍历到尾. 1.数字:连读直到不是数字 2.字母:连读直 ...
- 201777010217-金云馨《面向对象程序设计Java》第八周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...
- String强制转换为Date,freemarker标签里date数据的显示问题
String强制转换为Date,freemarker标签里date数据的显示问题 http://blog.sina.com.cn/s/blog_617f5d090101ut63.html (2014- ...
- echars 实现多曲线,多Y轴,曲线单选切换,并且跟随切换指定Y轴
html代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- [RN] react-native FlatList 实现列表选中的最佳方式(刷新指定Item)
效果如下: 核心思路就是往数据源里面 给每条数据加一个选中状态. 如图在网络请求完成之后,给每条数据添加一个select的状态: data.list.forEach(item => item.s ...
- <BackTracking> Combination, DFS :216 DP: 377
216. Combination Sum III 保证subset.size( ) == k && target == 0的时候结束DFS subset.size( ) > k ...
- 端口转发之 lcx
lcx.exe是一个端口转发工具,有Windows版和Linux版两个版本,Windows版是lcx.exe,Linux版为portmap Windows版使用方法如下: lcx有两大功能: )端口转 ...
- Nginx配置max_fails fail_timeout
目的: 通过配置max_fails.fail_timeout来达到当一台服务器访问出现非200时可以跳转到另一台服务器 操作: 配置nginx.conf文件 具体配置如下 upstream Site ...
- (九)golang--标识符的命名规则
标识符的概念: (1)各种变量.方法等命名时使用的字符序列被称为标识符: (2)凡是可以自己起名字的都可以叫标识符: 标识符的命名规则: (1)由26个英文字母大小写,0-9,_组成 (2)数字不可以 ...
- Oracle性能调优之物化视图用法简介
目录 一.物化视图简介 二.实践:创建物化视图 一.物化视图简介 物化视图分类 物化视图分类,物化视图语法和as后面的sql分为: (1) 基于主键的物化视图(主键物化视图) (2)基于Rowid的物 ...