如何在MIPS64 Release 6 CPU上運行QEMU的Linux SMP
在發(fā)表第一篇關于QEMU的文章之后,許多人都紛紛詢問如何在QEMU上運行MIPS64 Release 6 CPU(MIPS64r6)的軟件以及QEMU中實施MIPSr6多線程模塊的現(xiàn)狀。
本文我將針對這一系列的疑問進行解答。我將以教程的形式展示如何從零開始配置及構建64位Linux并使之在QEMU模擬器上運行。此外,我將使用支持VP(虛擬處理器)的MIPS64r6處理器,其是MIPSr6多線程的組成部分。
MIPS相干處理系統(tǒng)(CPS)是QEMU模擬所需的關鍵功能之一,其允許Linux 啟用VP。盡管該功能的實現(xiàn)工作仍在進行中,但我們可以進行一個早期試驗。
這個簡短的教程所描述的配置和構建過程非常簡單,使用臺式電腦半個小時內(nèi)便可以完成。我們將使用Linux內(nèi)核的4.7 rc1版 (一旦v4.7最終版本可用,建議使用最終版本)及穩(wěn)定的Buildroot 2016.02版,以此來生成根文件系統(tǒng)及可以早期使用的Codescape MIPS SDK QEMU。
設置QEMU
首先,我們需要在平臺上運行操作系統(tǒng)。我們將使用QEMU建立涵括MIPS CPU的虛擬硬件平臺:
$ wget https://github.com/prplfoundaTIon/qemu/archive/rel/2.5.0.2.0.tar.gz$ tar -zxf 2.5.0.2.0.tar.gz$ mkdir build && cd build$ ../qemu-rel-2.5.0.2.0/configure --target-list=mips64el-softmmu$ make -j8
如果一切運行良好,則會出現(xiàn)./mips64el-softmmu/qemu-system-mips64el 二進位。這時,平臺一切準備就緒。
Buildroot生成的根文件系統(tǒng)
有了Buildroot,嵌入式系統(tǒng)中Linux的構建過程將非常簡單。它是高度可配置的,但我們使用僅僅只為生成最小的根文件系統(tǒng)。
$ wget https://buildroot.org/downloads/buildroot-2016.02.tar.gz$ tar -zxf buildroot-2016.02.tar.gz && cd buildroot-2016.02$ make qemu_mips64el_malta_defconfig$ make menuconfig
我們剛剛申請了Malta開發(fā)板的默認配置,并設置了小端字節(jié)序MIPS64目標。不過,還需要進行進一步的定制??梢钥吹降慕缑嫒缦拢?/p>
Target options --->Target Architecture Variant (mips 64r6)[ ] Use soft-float
Toolchain --->Toolchain type (External toolchain)Toolchain (Codescape IMG GNU Linux Toolchain 2015.10)
System configuration ---> [*] Run a getty (login prompt) after boot --->(tty0) TTY port
Kernel --->[ ] Linux Kernel
Target packages --->Debugging, profiling and benchmark --->[*] stress-ngShell and utilities --->[*] screenSystem tools --->[*] htop
我篩選了一個目標及一個外部工具鏈并改變了TTY端口。同時,我禁止了內(nèi)核的構建(這部分將單獨完成),并添加了三個目標包用于最后的測試。最后的測試將進行系統(tǒng)壓力測試并觀察當前的負載情況。配置完成后,便可以開始構建:
$ make
Buildroot可以下載及構建任何你想要的東西。幾分鐘后,便可以在 ./output/images/rootfs.ext2.中使用rootfs圖像。
Linux內(nèi)核
下載內(nèi)核并設置所需的環(huán)境變量(我們將使用Buildroot下載的工具鏈):
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git$ cd linux && git checkout v4.7-rc1$ export ARCH=mips$ export CROSS_COMPILE=/output/host/opt/ext-toolchain/bin/mips-img-linux-gnu-$ make malta_defconfig$ make menuconfig
這里我進行了一些額外的變更:CPU selection --->CPU type (MIPS64 Release 6)
Kernel type --->Kernel code model (64-bit kernel)[*] MIPS Coherent Processing System support[*] Support for the MIPS SIMD Architecture
Device Drivers --->Generic Driver Options --->[*] Automount devtmpfs at /dev, after the kernel mounted the rootfsGraphics support ---><*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) ---><*> DRM Support for bochs dispi vga interface (qemu stdvga)Console display driver support --->[*] VGA text console[*] Bootup logo --->Virtio drivers ---><*> PCI driver for virTIo devices<*> VirTIo input driver
我篩選了一些CPU功能,并激活了用于鍵盤的VGA本文控制臺和VirTIo。最后生成的是:
$ make –j8
接下來便是耐心的等待。幾分鐘后,vmlinux圖像便產(chǎn)生了。
是否會正常工作?
此時,操作系統(tǒng)的運行一切準備就緒。我們可以跳過引導裝載程序的構建工作。但如果沒有提供引導裝載程序,那么QEMU將確定內(nèi)核的入口地址,并在用戶啟用前用偽靜態(tài)引導裝載程序填滿Malta的閃存。本質上來說,這是跳轉至內(nèi)核。
以下展示的是如何啟動系統(tǒng):