12|QEMU:支持RISC-V的QEMU如何构建?
主环境
- 深入了解
- 翻译
- 解释
- 总结
本文详细介绍了在Linux环境下构建支持RISC-V的QEMU的过程。作者首先介绍了主环境的概念,强调了Linux系统对开发者友好的特点。然后,文章解释了为什么需要交叉编译,以及交叉编译的基本原理,引出了在x86平台上生成RISC-V平台可执行程序的需求。接着,文章详细介绍了构建RISC-V交叉编译器的步骤,包括安装依赖工具、下载RISC-V工具链的源代码、配置和编译RISC-V工具链等。整体而言,本文以清晰的逻辑结构和详细的步骤指导,为读者提供了构建支持RISC-V的QEMU的实用指南。文章内容涵盖了手动配置环节、子模块下载、配置工具链、编译工具链等关键步骤,为读者提供了全面的指导。文章还提出了思考题,鼓励读者分享实验笔记并与作者交流讨论。整体而言,本文是一篇技术性较强的实用指南,适合对RISC-V开发感兴趣的读者阅读学习。
《计算机基础实战课》,新⼈⾸单¥68
全部留言(16)
- 最新
- 精选
- Vic置顶host使用的是Ubuntu 20.04 Desktop, 在Windows 11的笔记本, 用Virtualbox 6.1 搭建的虚机 (cpu 2 cores, 40GB 存储,4GB内存) ,按照老师的教程,以下是我的实验笔记: 1. 在我的环境就只有一个libpython-dev 报错,因为有提示换成libpython2-dev,不碍事,而且不同的os,不同的版本,可能不会有这个问题,可以先用老师的命令。 sudo apt-get install git autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf patchutils bc libexpat-dev libglib2.0-dev ninja-build zlib1g-dev pkg-config libboost-all-dev libtool libssl-dev libpixman-1-dev libpython2-dev virtualenv libmount-dev libsdl2-dev 2. mkdir RISCV_TOOLS; cd RISCV_TOOLS 3. git clone https://gitee.com/mirrors/riscv-gnu-toolchain cd riscv-gnu-toolchain 4. mkdir build cd build ../configure --prefix=/opt/riscv/gcc --enable-multilib --target=riscv64-multlib-elf 5. 因为我的host环境是建在2cpu core的虚机上 sudo make -j 2 6. 大约3个多小时,终于完成了。 7. cd /opt/riscv/gcc/bin ./riscv64-unknown-elf-gcc -v 8. 结果输出: Using built-in specs. COLLECT_GCC=./riscv64-unknown-elf-gcc COLLECT_LTO_WRAPPER=/opt/riscv/gcc/libexec/gcc/riscv64-unknown-elf/12.1.0/lto-wrapper Target: riscv64-unknown-elf Configured with: /home/vic/RISCV_TOOLS/riscv-gnu-toolchain/build/../gcc/configure --target=riscv64-unknown-elf --prefix=/opt/riscv/gcc --disable-shared --disable-threads --enable-languages=c,c++ --with-pkgversion= --with-system-zlib --enable-tls --with-newlib --with-sysroot=/opt/riscv/gcc/riscv64-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=/home/vic/RISCV_TOOLS/riscv-gnu-toolchain/gcc --enable-multilib --with-abi=lp64d --with-arch=rv64imafdc --with-tune=rocket --with-isa-spec=2.2 'CFLAGS_FOR_TARGET=-Os -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medlow' Thread model: single Supported LTO compression algorithms: zlib gcc version 12.1.0 () 9. 收工。
作者回复: 66666
2022-08-22归属地:湖北35 - 光华路小霸王编译中会卡在 Cloning into '/home/qing/RISCV_TOOLS/riscv-gnu-toolchain/gcc'... 还是会去下载仓库,应该是我们下载的文件夹名称不是默认的,查看 README.md 文件,在最后说明了如何指定子模块的路径,在配置环节添加配置之后,戴尔笔记本双核 i5-4200U CPU @ 1.60GHz 编译,编译完成四十多分钟,系统使用 Debian 4.19.181-1 ../configure --prefix=/opt/riscv/gcc \ --enable-multilib \ --target=riscv64-multlib-elf \ --with-gcc-src=/home/name/RISCV_TOOLS/riscv-gnu-toolchain/riscv-gcc \ --with-binutils-src=/home/name/RISCV_TOOLS/riscv-gnu-toolchain/riscv-binutils \ --with-newlib-src=/home/name/RISCV_TOOLS/riscv-gnu-toolchain/riscv-newlib \ --with-glibc-src=/home/name/RISCV_TOOLS/riscv-gnu-toolchain/riscv-glibc \ --with-gdb-src=/home/name/RISCV_TOOLS/riscv-gnu-toolchain/riscv-gdb
作者回复: 哈哈 成功了 吧
2022-08-27归属地:湖北34 - 筱琲用虚拟机的需要注意下,CPU核数,内存,磁盘,都要尽可能大一些,我设置的是4核/8G/100G,这样才能一路通关。不然要么卡死要么到最后提示空间不足,你连系统都启动不了。
作者回复: 哈哈 你在虚拟机中弄的吗
2022-11-02归属地:湖北21 - bubblemkdir -p stamps/ && touch stamps/build-gdb-newlib 卡住一直不动了。 riscv-gnu-toolchain git:(master) ✗ ps -aux | grep make root 580153 0.1 0.0 19764 4876 pts/1 S+ 15:36 0:00 sudo make -j8 root 580156 0.0 0.0 19764 748 pts/2 Ss 15:36 0:00 sudo make -j8 root 580157 0.0 0.0 11792 2356 pts/2 S+ 15:36 0:00 make -j8 paralle+ 621310 0.0 0.0 12120 1844 pts/3 S+ 15:38 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox make
作者回复: 可能是网络问题
2022-09-01归属地:湖北21 - gzh4869直接sudo apt install gcc-riscv64-unknown-elf 是不是也行
编辑回复: 试一试~
2023-01-11归属地:黑龙江 - Geekysl17请问我在ubuntu20上运行sudo make -j8后为什么出现下面的问题啊,怎么解决呢? Submodule 'gcc' (https://gcc.gnu.org/git/gcc.git) registered for path 'gcc' Submodule 'binutils' (https://sourceware.org/git/binutils-gdb.git) registered for path 'binutils' Cloning into '/home/ysl/code/OS/RISCV_TOOLS/riscv-gnu-toolchain/gcc'... Submodule 'newlib' (https://sourceware.org/git/newlib-cygwin.git) registered for path 'newlib' Cloning into '/home/ysl/code/OS/RISCV_TOOLS/riscv-gnu-toolchain/binutils'... Cloning into '/home/ysl/code/OS/RISCV_TOOLS/riscv-gnu-toolchain/newlib'... Submodule 'gdb' (https://sourceware.org/git/binutils-gdb.git) registered for path 'gdb' Cloning into '/home/ysl/code/OS/RISCV_TOOLS/riscv-gnu-toolchain/gdb'... fatal: unable to access 'https://sourceware.org/git/binutils-gdb.git/': gnutls_handshake() failed: Error in the pull function. fatal: clone of 'https://sourceware.org/git/binutils-gdb.git' into submodule path '/home/ysl/code/OS/RISCV_TOOLS/riscv-gnu-toolchain/binutils' failed Failed to clone 'binutils'. Retry scheduled
作者回复: 是不是 网络问题
2022-12-05归属地:湖北 - miraclezhb/home/miraclezhb/projects/RISCV_TOOLS/riscv-gnu-toolchain/build/../riscv-gdb/gdb/ada-exp.y: In function ‘int ada_parse(parser_state*)’: /home/miraclezhb/projects/RISCV_TOOLS/riscv-gnu-toolchain/build/../riscv-gdb/gdb/ada-exp.y:736:15: error: ‘yyin’ was not declared in this scope; did you mean ‘yyrline’? 736 | lexer_init (yyin); /* (Re-)initialize lexer. */ | ^~~~ | yyrline /home/miraclezhb/projects/RISCV_TOOLS/riscv-gnu-toolchain/build/../riscv-gdb/gdb/ada-exp.y:736:3: error: ‘lexer_init’ was not declared in this scope; did you mean ‘pex_init’? 736 | lexer_init (yyin); /* (Re-)initialize lexer. */ | ^~~~~~~~~~ | pex_init 老师我在编译时一直报这个错误,这个该怎么处理啊?
作者回复: 安装 库 sudo apt-get install git autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf patchutils bc libexpat-dev libglib2.0-dev ninja-build zlib1g-dev pkg-config libboost-all-dev libtool libssl-dev libpixman-1-dev libpython-dev virtualenv libmount-dev libsdl2-dev
2022-11-25归属地:湖北 - bubble老师我在M1的环境下用虚拟机折腾,一直编译不过去,我可以用其他环境吗?比如直接在M1的环境下学习
作者回复: M1可能不行,我没有试过
2022-09-02归属地:湖北3 - 肖水平sean@sean-VirtualBox:/opt/riscv/gcc/bin$ ./riscv64-minicpu-elf-gcc -v Using built-in specs. COLLECT_GCC=./riscv64-minicpu-elf-gcc COLLECT_LTO_WRAPPER=/opt/riscv/gcc/libexec/gcc/riscv64-minicpu-elf/10.2.0/lto-wrapper Target: riscv64-minicpu-elf Configured with: /home/sean/risc-v/RISCV_TOOLS/riscv-gnu-toolchain/riscv-gcc/configure --target=riscv64-minicpu-elf --prefix=/opt/riscv/gcc --disable-shared --disable-threads --enable-languages=c,c++ --with-pkgversion=gca312387ab1 --with-system-zlib --enable-tls --with-newlib --with-sysroot=/opt/riscv/gcc/riscv64-minicpu-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=/home/sean/risc-v/RISCV_TOOLS/riscv-gnu-toolchain/riscv-gcc --enable-multilib --with-abi=lp64d --with-arch=rv64imafdc --with-tune=rocket --with-isa-spec=2.2 'CFLAGS_FOR_TARGET=-Os -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medlow' Thread model: single Supported LTO compression algorithms: zlib gcc version 10.2.0 (gca312387ab1)
作者回复: 这是成功了
2022-08-31归属地:湖北3 - Abcd以前玩ARM的时候我记得有crosstool_ng?
作者回复: 嗯 嗯
2022-08-22归属地:湖北