Qemu搭建ARM vexpress開發(fā)環(huán)境(一)
標(biāo)簽(空格分隔): Qemu ARM Linux
嵌入式軟件開發(fā)依賴于嵌入式硬件設(shè)備拌屏,比如:開發(fā)板罚攀、外部模塊設(shè)備等党觅,但是如果只是想學(xué)習(xí)、研究Linux內(nèi)核斋泄,想學(xué)習(xí)Linux內(nèi)核的架構(gòu)杯瞻,工作模式,需要修改一些代碼炫掐,重新編譯并燒寫到開發(fā)板中進(jìn)行驗證魁莉,這樣未必有些復(fù)雜,并且為此專門購買各種開發(fā)版,浪費(fèi)資金旗唁,開會演示效果還需要攜帶一大串的板子和電線畦浓,不勝其煩。然而Qemu的使用可以避免頻繁在開發(fā)板上燒寫版本检疫,如果進(jìn)行的調(diào)試工作與外設(shè)無關(guān)讶请,僅僅是內(nèi)核方面的調(diào)試,Qemu模擬ARM開發(fā)環(huán)境完全可以完美地勝任屎媳。
[TOC]
下面簡單介紹下我的Qemu開發(fā)環(huán)境搭建過程
1. 環(huán)境
由于在開發(fā)過程中也需要Windows系統(tǒng)下的一些工具夺溢,雙系統(tǒng)環(huán)境切換操作系統(tǒng)時必須重啟,于是放棄了以前搭建的雙系統(tǒng)環(huán)境烛谊,而采用在PC的Windows10系統(tǒng)下通過VirtualBox虛擬機(jī)安裝Xubuntu系統(tǒng)進(jìn)行開發(fā)风响,避免了雙系統(tǒng)開發(fā)中需要不斷重啟切換PC系統(tǒng)的問題。Xubuntu系統(tǒng)和Ubuntu系統(tǒng)大同小異晒来,只是桌面封裝更加簡潔钞诡。
1.1 所使用環(huán)境
Ubuntu-18.04.1
或:
PC系統(tǒng):Windows10
虛擬機(jī):VirtualBox-5.18
虛擬機(jī)系統(tǒng):Xubuntu
模擬的開發(fā)板:vexpress
1.2 搭建環(huán)境時使用的工具
qemu-4.2.0
linux-4.14.172(Linux Kernel)
u-boot-2017.05
busybox-1.31.1
arm-linux-gnueabi-gcc (Linaro 7.5.0-3)
為了將Qemu搭建開發(fā)環(huán)境資料統(tǒng)一放到一起郑现,創(chuàng)建~/qemu目錄湃崩,所有相關(guān)文件全部放置在一起;
2. 安裝交叉編譯工具
# sudo apt install gcc-arm-linux-gnueabi
查看安裝是否成功:
$ arm-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabi/7/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --with-target-system-zlib --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv5t --with-float=soft --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include
Thread model: posix
gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
3. 安裝Qemu工具
有兩種方法可以在Linux環(huán)境下安裝Qemu工具接箫,第一種直接使用XUbuntu系統(tǒng)的apt工具安裝攒读,但是這種方法安裝的Qemu系統(tǒng)版本不是最新的,如果需要安裝最新版本的Qemu工具辛友,就需要第二種方法薄扁,通過Git工具下載源碼,切換到最新分支再去編譯安裝了废累;但是一般情況下通過git下載代碼速度極慢邓梅,我們可以使用第三種方法,找到要下載的qemu版本邑滨,使用迅雷下載日缨;具體操作如下所述:
3.1 快速安裝Qemu
# sudo apt install qemu
這種情況下安裝的qemu版本可能不是最新版本;如果想要安裝最新版本的qemu掖看,還得使用下邊介紹的使用源代碼編譯安裝的方法匣距;
3.2 下載Qemu源碼編譯安裝
3.2.1 下載Qemu源碼
- 從Git服務(wù)器下載Qemu代碼,記著在下載之前選擇并切換需要的源碼分支:
# git clone git://git.qemu-project.org/qemu.git
# cd qemu
# git checkout -b stable-*** remotes/origin/stable-***
-
在windows系統(tǒng)下使用迅雷下載
登陸download.qemu.org網(wǎng)站哎壳,選擇需要的版本毅待,點(diǎn)擊下載,或者右鍵后選使用迅雷下載归榕,速度會更快:
在這里選擇qemu-4.2.0.tar.xz使用尸红;
3.2.2 安裝
在配置qemu之前,需要安裝一些依賴的庫或者軟件包:
# sudo apt-get install zlib1g-dev
# sudo apt-get install libglib2.0-0
# sudo apt-get install libglib2.0-dev
# sudo apt-get install libtool
# sudo apt-get install libsdl1.2-dev
# sudo apt-get install autoconf
解壓源代碼:
# tar -xvf qemu-4.2.0.tar.xz
為了防止編譯后文件比較亂,選擇創(chuàng)建build目錄作為編譯中間目標(biāo)路徑:
# cd qemu-4.2.0/
# mkdir build
# cd build/
配置外里、編譯并安裝Qemu:
# ../configure --target-list=arm-softmmu --audio-drv-list=
# make
# make install
3.2.3 在編譯過程中可能出現(xiàn)的問題
# ../configure --target-list=arm-softmmu --audio-drv-list=
ERROR: pkg-config binary 'pkg-config' not found
缺少庫文件邑飒,按照上一步中的步驟安裝庫文件;
# ../configure --target-list=arm-softmmu --audio-drv-list=
ERROR: pixman >= 0.21.8 not present.
Please install the pixman devel package.
可以通過apt-cache查詢?nèi)鄙俚囊蕾噹欤?/p>
# apt-cache search pixman
libpixman-1-0 - pixel-manipulation library for X and cairo
libpixman-1-dev - pixel-manipulation library for X and cairo (development files)
安裝缺少的依賴庫:
# sudo apt-get install libpixman-1-0
# sudo apt-get install libpixman-1-dev
3.3 查看Qemu版本
# qemu-system-arm --version
QEMU emulator version 4.2.0
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers
3.4 查看Qemu支持的開發(fā)板
Qemu工具支持大量開發(fā)板的虛擬级乐,現(xiàn)存的大部分常用開發(fā)板都能很好地支持疙咸。通過下面的命令操作可以看到當(dāng)前版本的Qemu工具支持的開發(fā)板列表:
# qemu-system-arm -M help
......
vexpress-a15 ARM Versatile Express for Cortex-A15
vexpress-a9 ARM Versatile Express for Cortex-A9
......
3.5 運(yùn)行Qemu
該操作目前還不能運(yùn)行,因為還沒有編譯內(nèi)核风科,如果手邊有編譯好的別的版本的zImage文件撒轮,可以通過下面命令嘗試運(yùn)行看下效果。
# qemu-system-arm -M vexpress-a9 -m 512M -kernel ./zImage -dtb ./vexpress-v2p-ca9.dtb -nographic -append "console=ttyAMA0"
-M 指定開發(fā)板
-m 指定內(nèi)存大小
-kernel 指定內(nèi)核文件
-dtb 指定dtb文件
-nographic 指定不需要圖形界面
-append 指定擴(kuò)展顯示界面贼穆,串口或者LCD
實例參考:
# qemu-system-arm -M vexpress-a9 -m 512M -kernel ~/qemu/zImage -dtb ~/qemu/vexpress-v2p-ca9.dtb -nographic -append "console=ttyAMA0"
-M vexpress-a9 模擬vexpress-a9板题山,可以使用-M ?參數(shù)來查詢qemu支持的所有單板
-m 512M 單板物理內(nèi)存512M
-kernel ~/qemu/zImage 指定內(nèi)和鏡像及路徑
-dtb ~/qemu/vexpress-v2p-ca9.dtb 指定單板的設(shè)備樹文件
-nographic 不使用圖形界面,使用串口
-append "console=ttyAMA0" 指定內(nèi)核啟動參數(shù)故痊,串口設(shè)備使用ttyAMA0
4. 配置并編譯Linux內(nèi)核
4.1 下載Linux內(nèi)核
通過眾所周知的內(nèi)核下載網(wǎng)站www.kernel.org下載需要的內(nèi)核版本顶瞳,這里我下載的是相對來說最新的長期支持的內(nèi)核版本linux-4.4.157。
4.2 解壓Linux內(nèi)核
# tar -xvf linux-4.4.157.tar.xz
4.3 編譯Linux內(nèi)核
配置
$ make vexpress_defconfig ARCH=arm O=./object
make[1]: Entering directory '/home/xiami/tool/linux-4.14.172/object'
HOSTCC scripts/basic/fixdep
GEN ./Makefile
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
make[1]: Leaving directory '/home/xiami/tool/linux-4.14.172/object'
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig -j4 O=./object
全編譯
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j4 O=./object
或者在Makefile中配置默認(rèn)值愕秫,指定ARCH和CROSS_COMPILE慨菱,免得每次編譯都需要帶參數(shù);
# make vexpress_defconfig
# make zImage -j4
# make modules -j4 // 編譯驅(qū)動模塊
# make dtbs // 編譯設(shè)備樹
得到編譯文件:
arch/arm/boot/zImage
arch/arm/boot/dts/vexpress-v2p-ca9.dtb
分別將編譯生成的zImage和vexpress-v2p-ca9.dtb文件放到~/qemu目錄戴甩;
# cp arch/arm/boot/zImage ~/qemu
# cp arch/arm/boot/dts/vexpress-v2p-ca9.dtb ~/qemu
4.4 Qemu啟動命令
# qemu-system-arm -M vexpress-a9 -m 512M -kernel kernel/linux-4.4.157/arch/arm/boot/zImage -dtb kernel/linux-4.4.157/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "console=ttyAMA0"
Qemu的啟動命令需要帶好幾個參數(shù)符喝,完成啟動命令比較長,每次都輸入很可能會出現(xiàn)錯誤甜孤,為了使用方便协饲,可以將該命令放到shell腳本中執(zhí)行:
# cat boot.sh
#! /bin/sh
qemu-system-arm \
-M vexpress-a9 \
-m 512M \
-kernel kernel/linux-4.4.157/arch/arm/boot/zImage \
-dtb kernel/linux-4.4.157/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \
-nographic \
-append "console=ttyAMA0"
啟動日志
內(nèi)核成功啟動,內(nèi)核的啟動打印信息非常多缴川。啟動最后出錯是因為沒有掛載根文件系統(tǒng)茉稠。
$ qemu-system-arm -M vexpress-a9 -m 512M -kernel ~/qemu/zImage -dtb ~/qemu/vexpress-v2p-ca9.dtb -nographic -append "console=ttyAMA0"
Booting Linux on physical CPU 0x0
Linux version 4.14.172 (xiami@xiami) (gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)) #1 SMP Sun Mar 15 12:27:54 CST 2020
CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
OF: fdt: Machine model: V2P-CA9
Memory policy: Data cache writeback
CPU: All CPU(s) started in SVC mode.
percpu: Embedded 15 pages/cpu s32396 r8192 d20852 u61440
Built 1 zonelists, mobility grouping on. Total pages: 130048
Kernel command line: console=ttyAMA0
log_buf_len individual max cpu contribution: 4096 bytes
log_buf_len total cpu_extra contributions: 12288 bytes
log_buf_len min size: 16384 bytes
log_buf_len: 32768 bytes
early log buf free: 15044(91%)
PID hash table entries: 2048 (order: 1, 8192 bytes)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 509580K/524288K available (6144K kernel code, 403K rwdata, 1372K rodata, 1024K init, 161K bss, 14708K reserved, 0K cma-reserved)
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
vmalloc : 0xa0800000 - 0xff800000 (1520 MB)
lowmem : 0x80000000 - 0xa0000000 ( 512 MB)
modules : 0x7f000000 - 0x80000000 ( 16 MB)
.text : 0x80008000 - 0x80700000 (7136 kB)
.init : 0x80900000 - 0x80a00000 (1024 kB)
.data : 0x80a00000 - 0x80a64f90 ( 404 kB)
.bss : 0x80a6bd00 - 0x80a94468 ( 162 kB)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
Hierarchical RCU implementation.
RCU event tracing is enabled.
RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
......
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/smb@4000000/smb@4000000:motherboard/smb@4000000:motherboard:iofpga@7,00000000/10007000.kmi/serio1/input/input2
VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6
Please append a correct "root=" boot option; here are the available partitions:
1f00 131072 mtdblock0
(driver?)
1f01 32768 mtdblock1
(driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.14.172 #1
Hardware name: ARM-Versatile Express
[<8010f180>] (unwind_backtrace) from [<8010b444>] (show_stack+0x10/0x14)
[<8010b444>] (show_stack) from [<806616cc>] (dump_stack+0x94/0xa8)
[<806616cc>] (dump_stack) from [<8011d67c>] (panic+0xdc/0x248)
[<8011d67c>] (panic) from [<8090129c>] (mount_block_root+0x1d4/0x2a8)
[<8090129c>] (mount_block_root) from [<80901490>] (mount_root+0x120/0x128)
[<80901490>] (mount_root) from [<809015e8>] (prepare_namespace+0x150/0x198)
[<809015e8>] (prepare_namespace) from [<80900ea0>] (kernel_init_freeable+0x244/0x254)
[<80900ea0>] (kernel_init_freeable) from [<80674538>] (kernel_init+0x8/0x114)
[<80674538>] (kernel_init) from [<801076a8>] (ret_from_fork+0x14/0x2c)
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
最后的Kernel panic是因為沒有掛載根文件系統(tǒng),下一布制作一個簡易文件系統(tǒng)把夸。
5. 制作簡易根文件系統(tǒng)
使用busybox制作簡易的根文件系統(tǒng)
5.1 下載busybox工具
從https://busybox.net/downloads/下載最新的busybox而线。
同樣,建議在windows系統(tǒng)下使用迅雷下載扎即,先找到合適的busybox版本吞获,再用右鍵,選擇用迅雷下載谚鄙,這樣速度會很快各拷;
5.2 解壓busybox
# tar -xvf busybox-1.31.1.tar.bz2
5.3 配置并編譯busybox
5.3.1 配置
# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
編譯選擇使用glibc動態(tài)庫,因為靜態(tài)庫可能會出現(xiàn)一些未知的問題
# make menuconfig
Settings --->
Build Options --->
[ ] Build static binary (no shared libs)
默認(rèn)的安裝目錄是./_install闷营,如果需要指定安裝目錄烤黍,可以在下邊修改:
Settings --->
Installation Options ("make install" behavior)
(./_install) Destination path for 'make install'
5.3.2 編譯
# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
5.3.3 安裝
# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- install
提示下邊信息颅湘,表示安裝成功:
--------------------------------------------------
You will probably need to make your busybox binary
setuid root to ensure all configured applets will
work properly.
--------------------------------------------------
安裝完成之后菲宴,生成的目標(biāo)文件默認(rèn)在./_install目錄柿赊,這個目標(biāo)文件目錄就是下邊要制作根文件系統(tǒng)需要用到的工具:
$ ls _install/
bin linuxrc sbin usr
或者直接使用CONFIG_PREFIX指定安裝目錄:
# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- CONFIG_PREFIX=/.../rootfs/ install
5.3.4 提前設(shè)置好編譯默認(rèn)值
編譯安裝過程中乖仇,一直輸入ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-比較麻煩,可以在Makefile中設(shè)置好默認(rèn)值规哲;
修改Makefile:
# vim Makefile
ARCH = arm
CROSS_COMPILE = arm-linux-gnueabi-
之后的編譯跟啤、安裝命令就簡單了:
# make
# make install
5.4 生成簡易根文件系統(tǒng)
制作一個簡易的根文件系統(tǒng),該文件系統(tǒng)包含的功能極其簡陋唉锌,僅為了驗證Qemu啟動Linux內(nèi)核后掛載跟文件系統(tǒng)的過程隅肥。以后會根據(jù)具體需要進(jìn)一步完善該文件系統(tǒng)。
1) 編譯并安裝busybox
將busybox編譯生成的_install目錄下的文件全部拷貝到根文件系統(tǒng)目標(biāo)rootfs/目錄:
# mkdir rootfs
# cp /.../busybox-1.29.3/_install/* rootfs/ -rfd
也可以在指定busybox的安裝目錄直接安裝:
# make CONFIG_PREFIX=/.../rootfs/ install
2) 添加glibc庫
在根文件系統(tǒng)中添加加載器和動態(tài)庫:
# mkdir rootfs/lib
# cp /usr/arm-linux-gnueabi/lib/* rootfs/lib/ -rfp
3) 靜態(tài)創(chuàng)建設(shè)備文件
# mkdir rootfs/dev
# cd rootfs/dev
# mknod -m 666 tty1 c 4 1
# mknod -m 666 tty2 c 4 2
# mknod -m 666 tty3 c 4 3
# mknod -m 666 tty4 c 4 4
# mknod -m 666 console c 5 1
# mknod -m 666 null c 1 3
至此袄简,簡易版根文件系統(tǒng)就制作完成腥放,該根文件系統(tǒng)只含有最基本的功能,一些其他功能在以后的操作中會進(jìn)行添加绿语,如有興趣可以繼續(xù)參考下一篇文章《》《》秃症。
5.5 制作SD卡文件系統(tǒng)鏡像
1) 生成一個空的SD卡鏡像:
# dd if=/dev/zero of=rootfs.ext3 bs=1M count=32
32+0 records in
32+0 records out
33554432 bytes (34 MB, 32 MiB) copied, 0.0236764 s, 1.4 GB/s
2) 將SD卡格式化為exts文件系統(tǒng):
# mkfs.ext3 rootfs.ext3
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: done
Creating filesystem with 32768 1k blocks and 8192 inodes
Filesystem UUID: 51ab1063-a137-48e5-a6f4-4552dad3b898
Superblock backups stored on blocks:
8193, 24577
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
3) 將rootfs燒寫到SD卡:
# sudo mount -t ext3 rootfs.ext3 /mnt -o loop
# sudo cp -rf rootfs/* /mnt/
# sudo umount /mnt
在開發(fā)過程中,如果需要修改SD卡中的內(nèi)容吕粹,可以將SD卡的鏡像rootfs.ext3掛載到/mnt目錄下种柑,直接操作/mnt來修改;
# sudo mount -t ext3 rootfs.ext3 /mnt -o loop
# cp rootfs.ext3 ~/qemu
6. 驗證
1) Qemu啟動命令:
# qemu-system-arm -M vexpress-a9 -m 512M -kernel ~/qemu/zImage -dtb ~/qemu/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0 rw console=ttyAMA0" -sd rootfs.ext3
2) 啟動腳本:
# boot.sh
#! /bin/sh
qemu-system-arm \
-M vexpress-a9 \
-m 512M \
-kernel ~/qemu/zImage \
-dtb ~/qemu/vexpress-v2p-ca9.dtb \
-nographic \
-append "root=/dev/mmcblk0 rw console=ttyAMA0" \
-sd rootfs.ext3
以上為在串口終端啟動系統(tǒng)昂芜,按照以下的啟動命令可以使用LCD屏作為輸出啟動系統(tǒng)莹规。
3) 圖形化啟動內(nèi)核:
qemu-system-arm -M vexpress-a9 -m 512M -kernel ~/qemu/zImage -dtb ~/qemu/vexpress-v2p-ca9.dtb -append "root=/dev/mmcblk0 rw console=tty0" -sd rootfs.ext3
4) 啟動驗證:
request_module: kmod_concurrent_max (0) close to 0 (max_modprobes: 50), for module binfmt-464c, throttling...
request_module: modprobe binfmt-464c cannot be processed, kmod busy with 50 threads for more than 5 seconds now
Starting init: /sbin/init exists but couldn't execute it (error -8)
request_module: kmod_concurrent_max (0) close to 0 (max_modprobes: 50), for module binfmt-464c, throttling...
request_module: modprobe binfmt-464c cannot be processed, kmod busy with 50 threads for more than 5 seconds now
Starting init: /bin/sh exists but couldn't execute it (error -8)
Kernel panic - not syncing: No working init found. Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.14.172 #1
Hardware name: ARM-Versatile Express
[<8010f180>] (unwind_backtrace) from [<8010b444>] (show_stack+0x10/0x14)
[<8010b444>] (show_stack) from [<806616cc>] (dump_stack+0x94/0xa8)
[<806616cc>] (dump_stack) from [<8011d67c>] (panic+0xdc/0x248)
[<8011d67c>] (panic) from [<80674634>] (kernel_init+0x104/0x114)
[<80674634>] (kernel_init) from [<801076a8>] (ret_from_fork+0x14/0x2c)
---[ end Kernel panic - not syncing: No working init found. Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.
QEMU: Terminated
如上問題是由于編譯生成的busybox工具赔蒲,是x86環(huán)境下使用的:
# file bin/busybox
bin/busybox: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=7fe433943e201f5337be6116a883d54fc1a4a349, stripped
是因為在安裝busybox的時候泌神,使用了make install,應(yīng)該使用
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- install
編譯工具生成arm平臺使用的busybox工具:
# file rootfs/bin/busybox
rootfs/bin/busybox: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 3.2.0, BuildID[sha1]=cbcd33b8d6c946cb19408a5e8e714de554c87f52, stripped
再次驗證:
rtc-pl031 10017000.rtc: setting system clock to 2018-09-24 13:22:14 UTC (1537795334)
ALSA device list:
#0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 33
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/smb/smb:motherboard/smb:motherboard:iofpga@7,00000000/10007000.kmi/serio1/input/input2
EXT4-fs (mmcblk0): mounting ext3 file system using the ext4 subsystem
EXT4-fs (mmcblk0): recovery complete
EXT4-fs (mmcblk0): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext3 filesystem) on device 179:0.
Freeing unused kernel memory: 284K
random: nonblocking pool is initialized
can't run '/etc/init.d/rcS': No such file or directory
Please press Enter to activate this console.
/ #
/ #
/ # uname -a
Linux (none) 4.4.157 #1 SMP Sun Sep 23 21:11:22 CST 2018 armv7l GNU/Linux
至此舞虱,Qemu啟動Linux內(nèi)核并掛載跟文件系統(tǒng)已經(jīng)啟動成功欢际,通過串口終端可以正常和系統(tǒng)進(jìn)行簡單功能的交互。
打印中提示的不能運(yùn)行/etc/init.d/rcS問題矾兜,只需要添加/etc/init.d/rcS文件即可损趋,文件內(nèi)容可以是提示語句。
# cat /etc/init.d/rcS
Hello Qemu Linux!
注意椅寺,要在創(chuàng)建/etc/init.d/rcS文件時浑槽,記著修改該文件的可執(zhí)行權(quán)限,否則啟動過程中會報錯:
Freeing unused kernel memory: 1024K
random: crng init done
can't run '/etc/init.d/rcS': Permission denied
Please press Enter to activate this console.
7. 退出Qemu環(huán)境
Qemu環(huán)境搭建好之后返帕,在出錯時需要關(guān)閉并重新啟動Qemu桐玻,不用的時候需要關(guān)閉Qemu。
1)手動退出Qemu
Ctrl + A; X
操作之后荆萤,終端上會打幽餮ァ:
QEMU: Terminated
2)強(qiáng)制退出Qemu
有時候會發(fā)現(xiàn)無法通過shutdown等工具關(guān)閉铣卡,因為Qemu也是一個進(jìn)程,可以通過殺掉Qemu進(jìn)程的方法關(guān)閉Qemu模擬環(huán)境偏竟。
# ps -a
# kill xxx
如下可以采用腳本運(yùn)行:
# cat kill_qemu.sh
#! /bin/sh
ps -a | grep qemu-system-arm | awk '{print $1}' | xargs sudo kill -9
本文講述了Qemu環(huán)境啟動Linux內(nèi)核煮落,并掛載SD卡中的根文件系統(tǒng)的一些操作步驟。如果需要在Qemu環(huán)境下以ARM開發(fā)板的正常啟動流程來加載Linux內(nèi)核并掛載根文件系統(tǒng)踊谋,可以參考下一篇文章《Qemu搭建ARM vexpress開發(fā)環(huán)境(二)----通過u-boot啟動Linux內(nèi)核》。