qemu模拟器下编译运行基于riscv指令集的Linux操作系统

qemu模拟器下编译运行基于riscv指令集的Linux操作系统

2023年7月6日发(作者:)

qemu模拟器下编译运⾏基于riscv指令集的Linux操作系统

基本原理:在物理服务器Ubuntu14.04上安装qemu模拟器,模拟器中运⾏基于riscv指令集编译的linux镜像⽂件。⽤到的⼯具包括:riscv-qemu(模拟器,可以模拟运⾏riscv指令集的程序或镜像)riscv-tools(基于riscv指令集的交叉编译⼯具)riscv-pk(⽤于包装内核⽂件vmlinux)busybox(⽤于给linux镜像安装基本命令,如ls,cat,mv等等)以上⼯具安装路径在我们的物理服务器⾥分别为:⼀、安装toolchain1.下载交叉编译⼯具:$ git clone --recursive2.安装运⾏库$ sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperflibtool patchutils bc zlib1g-dev3.配置安装路径$ ./configure --prefix=/opt/riscv4.编译(linux版本)$ make linux5.验证交叉编译⼯具:编译hello.c到hello 注:要加上-static 静态编译选项riscv64-unknown-linux-gnu-gcc -static hello.c -o hello在x86环境下执⾏hello(x86下的gcc⽆法执⾏hello,因为格式为riscv)./hello ⽆法执⾏不要紧,因为还没有安装qemu模拟器,我们继续操作⼆、安装qemu1.安装运⾏库$ sudo apt-get install gcc libc6-dev pkg-config bridge-utils uml-utilities zlib1g-dev libglib2.0-dev autoconf automake libtool libsdl1.2-dev2.下载master分⽀的qemu$ git clone /riscv/riscv-qemu$ cd riscv-qemu $ git submodule update --init pixman3.配置qemu,riscv-64-linux-user为⽤户模式,可以运⾏基于riscv指令集编译的程序⽂件,softmmu为镜像模拟器,可以运⾏基于riscv指令集编译的linux镜像,为了测试⽅便,这两个我都安装了$ ./configure --target-list=riscv64-linux-user,riscv64-softmmu [--prefix=INSTALL_LOCATION]4.编译qemu$ make5.安装qemu$ [make install] # if you supplied prefix above6.测试qemu⽤户模式:6.1使⽤交叉编译器编译⼀个helloword程序$ riscv64-unknown-linux-gnu-gcc hello.c -o hello6.2使⽤qemu的⽤户模式运⾏riscv指令集的hello⼆进制⽂件$ ./riscv64-linux-user/qemu-riscv64 -L $RISCV/sysroot hello7.测试qemu镜像模式:启动qemu,载⼊bbl⽰例镜像⽂件,下载地址:$ riscv-qemu/riscv64-softmmu/qemu-system-riscv64 -kernel /home/tank/bblvmlinuxinitramfs_dynamic -nographic出现riscv图案并且可以使⽤镜像,代表qemu镜像模拟器安装正常。三、安装riscv-pk1.下载对应分⽀的riscv-pk⼯具$ git clone -b bigbuf2.创建build⽬录,⽤于存放镜像bbl$ cd riscv-pk$ mkdir build $ cd build3.配置交叉编译⼯具路径,$RICSV代表交叉⼯具的路径 第⼀步中设置为了/opt/riscv$ ../configure --prefix=$RISCV --host=riscv64-unknown-linux-gcc4.编译$ make5.安装pk$ make install注:耗时较长,验证pk⼯具的⽅法是⽤pk包装镜像⽂件vmlinux成bbl,qemu启动bbl的时候出现如下图案,代表pk⼯具没有问题四、安装busybox1.下载对应版本的busybox$ curl -L /downloads/2 > 22.解压缩⽂件$ tar xvjf 2$ cd busybox-1.26.23.清空其它所以配置(这样可以⾃⼰添加需要的命令组件)$ make allnoconfig4.进⼊菜单页⾯配置$ sudo apt-get install libncurses5-dev$ make menuconfig下图中这⼏项为核⼼项,配置完成后只能使⽤ash init等⼏个命令如果想使⽤ls,cat等命令,参考配置链接5.采⽤16线程的速度进⾏编译$ make -j16编译完成后会在busybox-1.26.2⽬录下⽣成busybox⼆进制执⾏⽂件6.测试busybox,使⽤qemu的镜像模式载⼊busybox⽂件,启动模拟器$ ./riscv64-linux-user/qemu-riscv64 -L $RISCV/sysroot busybox ash如果出现以下界⾯代表busybox安装成功(即可以使⽤busybox的⼀些命令)五、编译linux内核1.下载对应分⽀的内核$ git clone -b fix-gcc-flags$ cd linux-4.6.22.配置内核信息$ make ARCH=riscv defconfig3.在内核⽬录下新建⽂件,并保存以下内容$ vi 4.在内核⽬录下新建inittab⽂件,并保存以下内容$ vi inittab5.进⼊菜单页⾯配置$ make ARCH=riscv menuconfig注:更改下⾯两个选项"General setup -> Initial " (CONFIG_BLK_DEV_INITRD=y)"General setup -> Initramfs source files = " (CONFIG_INITRAMFS_SRC=)6.编译内核,⽣成vmlinux⽂件$ make -j4 ARCH=riscv vmlinux注:编译完成在linux4-6.2⽂件夹下出现vmlinux六、使⽤pk包装vmlinux1.进⼊pk⼯具的build⽬录$ cd /path/to/risv-tools/riscv-pk/build$ rm -rf *2.配置要编译的内核⽂件以及使⽤的指令集路径及名称$ ../configure --prefix=$RISCV --with-payload=/path/to/linux-4.6.2/vmlinux --host=riscv64-unknown-linux-gnu3.包装⽣成bbl镜像⽂件$ make bbl七、qemu模拟运⾏镜像bbl$ riscv-qemu/riscv64-softmmu/qemu-system-riscv64 -kernel /home/tank/old3/riscv-pk/build/bbl -m 1024M -nographic可以使⽤ls cat等命令,代表运⾏成功

发布者:admin,转转请注明出处:http://www.yc00.com/news/1688591982a153110.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信