源码编译risc-v虚拟机和编译器 riscv-gnu-toolchain 和 riscv-tools 在ubuntu 22.04

1. 编译 riscv-gnu-toolchain

1.1 预备环境

$ 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

1.2 下载源代码
https://github.com/riscv-collab/riscv-gnu-toolchain

git clone --recursive https://github.com/riscv-collab/riscv-gnu-toolchain.git

1.3 编译elf 工具

cd riscv-gnu-toolchain/for  riscv64-unknown-elf-gcc:
./configure --prefix=/opt/riscv
sudo make -j

1.4 编译 linux 工具


for riscv64-unknown-linux-gnu-gcc:

./configure --prefix=/opt/riscv --enable-multilib
sudo make linux -jexport PATH=/opt/riscv/bin:$PATH

2. 编译 riscv-tools

for Spike, the ISA simulator:

2.1 预备环境

$ sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev libusb-1.0-0-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev device-tree-compiler pkg-config libexpat-dev
$ sudo apt-get install device-tree-compiler

2.2 下载代码
https://github.com/riscv-software-src/riscv-tools

git clone --recursive https://github.com/riscv-software-src/riscv-tools.git 

2.3 编译并处理编译错误

cd riscv-tools \
&& git submodule update --init --recursive \
&& export RISCV=/opt/riscv  \
&& sudo  ./build.sh

-1. 设置了PATH
export PATH=/opt/riscv/bin:$PATH

0. 指定安装目录
第一行加入RISCV

vim build.sh
RISCV=/opt/riscv

1. 重复定义变量
/home/hipper/ex/RISC-V_source_codes/riscv-tools/riscv-openocd/build/../src/jtag/drivers/bitbang.h:60: multiple definition of `bitbang_swd';
 

//LL:: 60 line 注释掉 .h 文件中的这个变量定义声明

2. 忘记包含头文件
../fesvr/dtm.cc:488:16: error: ‘runtime_error’ is not a member of ‘std’
 

vim riscv-isa-sim/fesvr/dtm.cc
#include <stdexcept>

3. 忘记包含头文件
../riscv/devices.h:45:18: error: ‘runtime_error’ is not a member of ‘std’
 

vim riscv-isa-sim/riscv/devices.h
#include <stdexcept>

4. 指定架构 rv64gc_zifencei

../machine/flush_icache.c:4: Error: unrecognized opcode `fence.i', extension `zifencei' required

vim ./riscv-tools/build.sh
CC= CXX= build_project riscv-pk --prefix=$RISCV --host=riscv64-unknown-elf --with-arch=rv64gc_zifencei


5.
 multiple definition of `tohost'; /tmp/ccMXpCzH.o:(.sbss+0x10): first defined here

 extern 


 
6.
multiple definition of `fromhost'; /tmp/ccMXpCzH.o:(.sbss+0x8): first defined here

 extern 


 3. 示例


 3.1 源码 example:

用如下编译器指示语句包一下

#pragma GCC push_options
#pragma GCC optimize ("no-tree-loop-distribute-patterns")

... ...

#pragma GCC pop_options

#include <stdio.h>
#pragma GCC push_options
#pragma GCC optimize ("no-tree-loop-distribute-patterns")int main(void)
{ //printf("Hello RISC-V World!\n");int a = 2;int b = 3;int c = 2;c = a+b;printf("c=%d\n", c);return 0;
}#pragma GCC pop_options

3.2 编译示例
 

$ riscv64-unknown-elf-gcc ./hello_world.c -o hello_world
$ spike pk ./hello_world

3.3 运行
 

$ spike pk ./hello_world
<stdin>:20.39-24.9: Warning (interrupt_provider): /cpus/cpu@0/interrupt-controller: Missing #address-cells in interrupt provider
bbl loader
c=5
(base) hipper@hipper-G21:~/ex/RISC-V_source_codes/ex_tmp_riscv_tools$

大家都这么来建立测试c代码文件:


 

$echo -e '#include <stdio.h>\n int main(void) { printf("Hello RISC-V World!\\n"); return 0; }' > hello_world.c

参考文件:

./riscv-tools/regression.sh

4. 显摆显摆成果

一些git diff的输出:

(base) hipper@hipper-G21:~/ex/RISC-V_source_codes/riscv-tools$ git diff
diff --git a/build.sh b/build.sh
index 2ebe825..1ba0fe7 100755
--- a/build.sh
+++ b/build.sh
@@ -3,6 +3,7 @@# Script to build RISC-V ISA simulator, proxy kernel, and GNU toolchain.# Tools will be installed to $RISCV.+RISCV=/opt/riscv. build.commonecho "Starting RISC-V Toolchain build process"
@@ -19,7 +20,7 @@ check_version autoconf 2.64 "OpenOCD build"build_project riscv-openocd --prefix=$RISCV --enable-remote-bitbang --enable-jtag_vpi --disable-werrorbuild_project riscv-isa-sim --prefix=$RISCV
-CC= CXX= build_project riscv-pk --prefix=$RISCV --host=riscv64-unknown-elf
+CC= CXX= build_project riscv-pk --prefix=$RISCV --host=riscv64-unknown-elf --with-arch=rv64gc_zifenceibuild_project riscv-tests --prefix=$RISCV/riscv64-unknown-elfecho -e "\\nRISC-V Toolchain installation completed!"
diff --git a/riscv-isa-sim b/riscv-isa-sim
--- a/riscv-isa-sim
+++ b/riscv-isa-sim
@@ -1 +1 @@
-Subproject commit 2710fe575e7e6a4e2418224f8d254d5ca31f6c0e
+Subproject commit 2710fe575e7e6a4e2418224f8d254d5ca31f6c0e-dirty
diff --git a/riscv-openocd b/riscv-openocd
--- a/riscv-openocd
+++ b/riscv-openocd
@@ -1 +1 @@
-Subproject commit 35eed36ffdd082f5abfc16d4cc93511f6e225284
+Subproject commit 35eed36ffdd082f5abfc16d4cc93511f6e225284-dirty
diff --git a/riscv-tests b/riscv-tests
--- a/riscv-tests
+++ b/riscv-tests
@@ -1 +1 @@
-Subproject commit 79064081503b53fdb44094e32ff54a3ab20a9bf2
+Subproject commit 79064081503b53fdb44094e32ff54a3ab20a9bf2-dirty
(base) hipper@hipper-G21:~/ex/RISC-V_source_codes/riscv-tools$


____________________________________________________________________________
 

(base) hipper@hipper-G21:~/ex/RISC-V_source_codes/riscv-tools$ cd riscv-openocd/
(base) hipper@hipper-G21:~/ex/RISC-V_source_codes/riscv-tools/riscv-openocd$ git diff
diff --git a/src/jtag/drivers/bitbang.h b/src/jtag/drivers/bitbang.h
index 577717ebd..32eb69f53 100644
--- a/src/jtag/drivers/bitbang.h
+++ b/src/jtag/drivers/bitbang.h
@@ -57,7 +57,7 @@ struct bitbang_interface {void (*swdio_drive)(bool on);};-const struct swd_driver bitbang_swd;
+//LL::  const struct swd_driver bitbang_swd;extern bool swd_mode;(base) hipper@hipper-G21:~/ex/RISC-V_source_codes/riscv-tools/riscv-openocd$


____________________________________________________________________________

(base) hipper@hipper-G21:~/ex/RISC-V_source_codes/riscv-tools$ cd riscv-isa-sim/
(base) hipper@hipper-G21:~/ex/RISC-V_source_codes/riscv-tools/riscv-isa-sim$ git diff
diff --git a/fesvr/dtm.cc b/fesvr/dtm.cc
index 5409321a..7c8f83c8 100644
--- a/fesvr/dtm.cc
+++ b/fesvr/dtm.cc
@@ -6,7 +6,7 @@#include <string.h>#include <assert.h>#include <pthread.h>
-
+#include <stdexcept>#define RV_X(x, s, n) \(((x) >> (s)) & ((1 << (n)) - 1))#define ENCODE_ITYPE_IMM(x) \
diff --git a/riscv/devices.h b/riscv/devices.h
index 4e4d27ff..aee50892 100644
--- a/riscv/devices.h
+++ b/riscv/devices.h
@@ -6,7 +6,7 @@#include <string>#include <map>#include <vector>
-
+#include <stdexcept>class processor_t;class abstract_device_t {
(base) hipper@hipper-G21:~/ex/RISC-V_source_codes/riscv-tools/riscv-isa-sim$


____________________________________________________________________________

参考:

最后解决example 代码包裹问题,借鉴了这位仁兄的记录,发现遇到的问题也如出一辙:

RSIC-V_h~k~f的博客-CSDN博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/77798.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

lv4 嵌入式开发-1 Linux文件IO

目录 1 文件的概念和类型 2 如何理解标准IO 3 流(FILE)的含义 3.1 流 3.2 文本流和二进制流 3.3 流的缓冲类型 4 小结 5 缓存区实验 1 文件的概念和类型 概念&#xff1a;一组相关数据的有序集合 文件类型&#xff1a; 常规文件 r 目录文件 d 字符设备文件 …

前端工程化小记

1.引言 工业界一直都是&#xff1a;能机器做的都交给机器&#xff0c;因为人更容易犯错。所以关于代码语法检查、代码格式化、commit注释规范、代码编译等等这些工作量繁杂且巨大的苦力活&#xff0c;除非你不想把人当马用&#xff0c;那还是交给机器去做&#xff0c;是吗&…

【尚硅谷】第05章:随堂复习与企业真题(数组)

来源&#xff1a;尚硅谷Java零基础全套视频教程(宋红康2023版&#xff0c;java入门自学必备) 基本都是宋老师发的资料里面的内容&#xff0c;只不过补充几个资料里没直接给出答案的问题的答案。 不想安装markdown笔记的app所以干脆在这里发一遍。 第05章&#xff1a;随堂复习…

ChatGPT AIGC 一键总结SQL优化所有知识点

SQL优化一直是程序员非常关注的内容,使用ChatGPT AIGC结合思维导图进行总结SQL优化的所有知识点内容。 非常简单实用的操作,就得到了如何进行SQL优化的所有细节。 更多内容见: AIGC ChatGPT ,BI商业智能, 可视化Tableau, PowerBI, FineReport, 数据库Mysql Oracle, Off…

Flink CDC 菜鸟教程 -环境篇

本教程将介绍如何使用 Flink CDC 来实现这个需求, 在 Flink SQL CLI 中进行,只涉及 SQL,无需一行 Java/Scala 代码,也无需安装 IDE。 系统的整体架构如下图所示: 环境篇 1、 准备一台Linux 2、准备教程所需要的组件 下载 flink-1.13.2 并将其解压至目录 flink-1.13.2 …

阿里后端开发:抽象建模经典案例【文末送书】

文章目录 写作前面1.抽象思维2.软件世界中的抽象3. 经典抽象案例4. 抽象并非一蹴而就&#xff01;需要不断假设、验证、完善5. 推荐一本书 写作末尾 写作前面 在互联网行业&#xff0c;软件工程师面对的产品需求大都是以具象的现实世界事物概念来描述的&#xff0c;遵循的是人…

微信小程序父子组件通讯方法

自定义方法中发送命令 const app getApp() Component({options: {styleIsolation: isolated},data: {},properties: {},attached() {this.init()},methods: {init() {console.log(父组件执行子组件)},clickBtn() {this.triggerEvent(changeRoute, 发送数据到父组件, {})},} }…

typeScript--[函数定义]

一.TypesScript 函数的定义 函数的定义包括两种类型&#xff1a;函数声明和函数表达式。 1.函数声明 function hello(): string {return "hello" } 2.函数表达式 var hello1 function (): string {return "hello" } 二.函数之可选参数 参数后面的限…

Android Studio导入aosp源码

1、在 Ubuntu 系统下&#xff0c;进入源码根目录&#xff0c;运行如下命令&#xff1a; source build/envsetup.sh # 初始化环境变量。 lunch sdk_phone_x86_64 make idegen -j6 # 六核编译 idegen 模块 忽略此命令&#xff1a;mmm development/tools/idegen/ # 此命令可…

XL-LightHouse 与 Flink 和 ClickHouse 流式大数据统计系统

一个Flink任务只能并行处理一个或少数几个数据流&#xff0c;而XL-LightHouse一个任务可以并行处理数万个、几十万个数据流&#xff1b; 一个Flink任务只能实现一个或少数几个数据指标&#xff0c;而XL-LightHouse单个任务就能支撑大批量、数以万计的数据指标。 1、XL-LightHo…

2023计算机毕设选题 python毕业设计如何选题

文章目录 一、python 毕设 选题推荐二、选题注意事项2.1 难度怎么把控&#xff1f;2.2 题目名称怎么取&#xff1f; 三、开题指导3.1 起因3.2 如何避坑(重中之重)3.3 为什么这么说呢&#xff1f; 四、最后 一、python 毕设 选题推荐 以下为学长手动整理python 毕业设计 项目&a…

自动驾驶的区块链结合价值所在

区块链结合自动驾驶的价值所在 1.责任判定 车辆行驶发生事故时&#xff0c;需要进行责任判定&#xff0c; 目前的事故组合方式&#xff1a; 普通车-----普通车 自动驾驶车&#xff08;处于自动驾驶状态&#xff09;--------普通车 自动驾驶车&#xff08;人工驾驶状态&#x…

预测多基因扰动的转录结果

了解细胞对基因扰动的反应是许多生物医学应用的核心&#xff0c;从识别癌症中涉及的基因相互作用到开发再生医学方法。然而&#xff0c;可能的多基因扰动数量的组合爆炸严重限制了实验验证。在这里&#xff0c;作者提出了图增强的基因激活和抑制模拟器&#xff08;GEARS&#x…

06-mq

1、消息队列有什么优点和缺点? 优点&#xff1a; 解耦、异步、削峰填谷。 缺点&#xff1a; 系统可用性降低 系统复杂性提高 一致性问题 2、常见消息队列的比较 3、Kafka的特性 1.消息持久化 2.高吞吐量 3.扩展性强&#xff08;动态&#xff09;4集群&#xff0b;4台集群…

硬件【10】运放-1-理想运放与虚断虚短的来源

1 概述 今天开始&#xff0c;聊一聊运放吧&#xff0c;之前很多兄弟们也提了这个要求。正好我最近也想深入看看运放方面的&#xff0c;那么就借这个机会一步一步再搞一搞吧。 运放这个器件相对于电阻&#xff0c;电容&#xff0c;三极管&#xff0c;MOS管等器件算是比较复杂的…

Docker进阶:Docker Compose(容器编排) 管理多容器应用—实战案例演示

Docker进阶&#xff1a;Docker Compose&#xff08;容器编排&#xff09; 管理多容器应用—实战案例演示 一、Docker Compose简介二、Docker Compose安装三、Docker Compose卸载四、Docker Compose核心概念4.1、一文件原则&#xff08;docker-compose.yml&#xff09;4.2、服务…

CC2530中文数据手册

分享一下cc2530的中文数据手册 下载地址&#xff1a;【免费】CC2530中文数据手册完全版资源-CSDN文库 最近在学习ZigBee的开发&#xff0c;使用的是cc2530芯片&#xff0c;在网上找参考手册的时候&#xff0c;发现就各种收费&#xff0c;找到一个免费的太难了&#xff0c;就在这…

大数据课程M1——ELK的概述

文章作者邮箱:yugongshiye@sina.cn 地址:广东惠州 ▲ 本章节目的 ⚪ 了解ELK的定义; ⚪ 掌握ELK的使用; 一、什么是ELK 1. 简介 ELK 是elastic公司提供的一套完整的日志收集以及展示的解决方案,是三个产品的首字母缩写,分别是 ElasticSearch、Logstash…

vue交互

目录 交互 指有人参与的&#xff0c;程序并非按照一定的顺序去执行&#xff0c;可以人为介入&#xff0c;让程序或应用去根据输入选择执行流程&#xff0c;提供给我们需要的信息。 前、后端 前端&#xff1a;指客户端&#xff0c;浏览器 用户可以直接看到、操作&#xff0c;可…

t-SNE——高维特征可视化分析

无监督学习之t-SNEhttps://github.com/SarthakV7/Clustering-Barron-s-333-word-list-using-unsupervised-machine-learning