From视频:https://www.bilibili.com/video/av24252815?from=search&seid=10660750066815842067
From文档:https://wenku.baidu.com/view/42e93544dcccda38376baf1ffc4ffe473368fdbf.html
https://blog.csdn.net/linyt/article/details/42504975
1.安装gnu
sudo apt-get install gcc-arm-linux-gnueabi
sudo apt-get install g++-arm-linux-gnueabi
2.安装qemu
sudo apt-get install qemuqemu-system qemu-utils
3.编译uboot
ftp://ftp.denx.de/pub/u-boot/下载最新源码
解压Makefile添加两行
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-gnueabi-
然后
make vexpress_ca9x4_defconfig
vexpress_ca9x4_defconfig是定义在./board/armltd/vexpress/MAINTAINERS中的一个板子
然后make
然后qemu-system-arm -M vexpress-a9 -m 256M -nographic -kernel u-boot 或者 qemu-system-arm -M vexpress-a9 -m 256M-serial stdio -kernel u-boot,这里使用第一个 ,得到ERROR: can't get kernel image!
4.编译linux
从www.kernel.org下载最新linux内核,解压,修改Makefile中的ARCH和CROSS_COMPILE为
ARCH = arm
CROSS_COMPILE=arm-linux-gnueabi- (这句没有的话新增)
然后 make vexpress_defconfig
然后make menuconfig,报错
*
* Unable to find the ncurses package.
* Install ncurses (ncurses-devel or libncurses-dev
* depending on your distribution).
*
scripts/kconfig/Makefile:208: recipe for target 'scripts/kconfig/mconf-cfg' failed
make[1]: *** [scripts/kconfig/mconf-cfg] Error 1
Makefile:567: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 2
sudo apt-get install libncurses-dev,继续make menuconfig,System Type 把 Enable the L2x0 outer cache controller 取消,
然后make,会在arch/arm/boot/ 目录下生成zImage内核映像文件,这就是我们需要的内核映像。
5.编译busybox
从www.busybox.net下载最新源码
修改Makefile,还是
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-gnueabi-
make menuconfig,选择 busybox setting -> build options -> build busybox with static library (no shared library)
然后make 然后 make install
6.形成根目录结构
cd..,回到上层目录.创建rootfs目录(根目录),根文件系统内的文件全部放到这里
mkdir -p rootfs/{dev,etc/init.d,mnt,lib}
形成如下目录
sun@pc:~/learn/qemu$ tree rootfs rootfs ├── dev ├── etc │ └── init.d ├── lib └── mnt
拷贝busybox命令到根目录下
sudo cp busybox-1.31.1/_install/* -r rootfs/
从工具链中拷贝运行库到lib目录下
sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
创建4个tty端终设备
sun@pc:~/learn/qemu$ sudo mknod rootfs/dev/tty1 c 4 1 sun@pc:~/learn/qemu$ sudo mknod rootfs/dev/tty2 c 4 2 sun@pc:~/learn/qemu$ sudo mknod rootfs/dev/tty3 c 4 3 sun@pc:~/learn/qemu$ sudo mknod rootfs/dev/tty4 c 4 4
(弹出没有那个文件或目录可能是复制的命令有问题,把空格部分重新打一遍)
7.制作根文件系统镜像
生成32M大小的镜像
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=32
格式化成ext3文件系统
mkfs.ext3 a9rootfs.ext3
编译passwd
vim rootfs/etc/passwd
插入
root:x:0:0:root:/root:/bin/bash
编辑group
vim rootfs/etc/group
插入
root:x:0:root
将文件拷贝到镜像中
sudo mkdir tmpfs
sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop
sudo cp -r rootfs/* tmpfs/
sudo umount tmpfs
8.在目标机(Linux系统)中运行应用程序
用户应用程序在目标机上运行有两种方法:
①将编译后的可执行文件放入到根文件系统中,在做成根文件系统的镜像后,由内核调用并执行。
②使用NFS(网络文件系统)在本地机和目标机之间建立通信。
1)QEMU与Ubuntu之间的通信
1. 首先在Ubuntu上安装NFS网络文件系统apt-get install nfs-kernel-server
2. 在NFS服务的配置文件/etc/exports中添加:
/ *(rw,no_root_squash,insecure)
3. 关闭Ubuntu的网关,避免连接不上:
在/etc/resolv.conf中全部注释掉,不要DNS服务器地址。
4. 在宿主机Ubuntu中开启NFS服务:
/etc/init.d/nfs-kernel-server start
5. 再次启动Qemu,在最后面添加如下命令
-net user -net nic–s
qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/sun/learn/qemu/linux-5.4.10/arch/arm/boot/zImage -dtb /home/sun/learn/qemu/linux-5.4.10/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -append "root=/dev/mmcblk0 rw console=tty" -sd a9rootfs.ext3 -net user -net nic -s
弹出个黑框Qemu,进行不下去了..............................
6. 最后,在目标机中配置网络、挂载NFS文件系统、切换根文件系统:
ifconfig eth0 10.0.2.15 up
route add default gw 10.0.2.2
mount -t nfs -o nolock 192.168.1.241:/ /mnt
这样就可将192.168.1.241的主机的文件系统挂载到/mnt目录下。
(注:192.168.1.241是我的Ubuntu的IP地址,,可用ifconfig查看本地机的IP地址。)