qemu交叉编译arm内核_4.3.1 使用qemu进行arm64仿真

fb56c6e740719ba97f0edef79f306eaf.png

前篇文章介绍了fastmodel如何安装,但是fastmodel安装复杂,不适合linux初学者(绝对不是因为我还没画好能启动最小arm64系统的仿真图),所以这篇介绍qemu启动arm64系统。

系统环境:ubuntu-14.04.4

交叉编译工具链:aarch64-linux-gnu-

qemu安装

sudo apt-get install qemu

安装完毕后,qemu-system-aarch64命令存在

$ which qemu-system-aarch64
/usr/bin/qemu-system-aarch64

下载linux,编译arm64内核

1.下载

社区linux下载命令:

git clone https://github.com/torvalds/linux

当然如果你无法访问或者下载非常慢,国内可以fork我的码云仓库:cbx/linux

此时下载命令:

git clone https://gitee.com/cuibixuan/linux.git

2. 下载完毕切换到5.0分支(19年算起v5.0分支比较新),并编译

cd linux
git checkout v5.0
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image -j8

编译完毕,内核文件:arch/arm64/boot/Image

使用busybox制作简易文件系统

busybox下载地址:Index of /downloads

下载命令

wget https://busybox.net/downloads/busybox-1.31.0.tar.bz2

解压

tar -jxvf busybox-1.31.0.tar.bz2

设置交叉编译工具链以及Build static binary

cd busybox-1.31.0
make menuconfig

-> Settings

[*] Build static binary (no shared libs)

(aarch64-linux-gnu-) Cross compiler prefix

982ac173a507c86fa79cdbebe5e2d5ed.png

编译安装

make && make install

编译完毕后busybox生成如下_install目录:

790789f7ee15d27af4e888321e5c699f.png

文件系统创建console

cd _install
mkdir dev
cd dev
sudo mknod console c 5 1
sudo mknod null c 1 3

压缩成cpio.gz文件系统

find . | cpio -o -H newc |gzip > ../rootfs.cpio.gz

启动arm64内核

可以参考我这样将Image,rootfs.cpio.gz和启动脚本qemu.sh放在同个目录

dc6a77fc754a3f8518bee9274ad5febc.png
$ cat qemu.sh
qemu-system-aarch64 
        -machine virt,virtualization=true,gic-version=3 
        -nographic 
        -m size=1024M 
        -cpu cortex-a57 
        -smp 2 
        -kernel Image 
        -initrd rootfs.cpio.gz 
        --append "console=ttyAMA0 rdinit=/linuxrc"

启动qemu

$ sh qemu.sh

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd070]
[    0.000000] Linux version 5.0.0 (cuibixuan@hulk-ubuntu) (gcc version 7.4.1 20181213 [linaro-7.4-2019.02 revision 56ec6f6b99cc167ff0c2f8e1a2eed33b1edc85d4] (Linaro GCC 7.4-2019.02)) #3 SMP PREEMPT Sun Aug 11 07:47:37 CST 2019
[    0.000000] Machine model: linux,dummy-virt
[    0.000000] efi: Getting EFI parameters from FDT:
[    0.000000] efi: UEFI not found.
[    0.000000] cma: Reserved 32 MiB at 0x000000007e000000
[    0.000000] NUMA: No NUMA configuration found
[    0.000000] NUMA: Faking a node at [mem 0x0000000040000000-0x000000007fffffff]
[    0.000000] NUMA: NODE_DATA [mem 0x7ddf4840-0x7ddf5fff]
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000040000000-0x000000007fffffff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000040000000-0x000000007fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000040000000-0x000000007fffffff]
[    0.000000] psci: probing for conduit method from DT.
[    0.000000] psci: PSCIv0.2 detected in firmware.
[    0.000000] psci: Using standard PSCI v0.2 function IDs
[    0.000000] psci: Trusted OS migration not required
...
[    2.099820] Loading compiled-in X.509 certificates
[    2.112983] input: gpio-keys as /devices/platform/gpio-keys/input/input0
[    2.117698] rtc-pl031 9010000.pl031: setting system clock to 2019-08-11T14:43:32 UTC (1565534612)
[    2.119838] ALSA device list:
[    2.120508]   No soundcards found.
[    2.123408] uart-pl011 9000000.pl011: no DMA platform data
[    2.209212] Freeing unused kernel memory: 1408K
[    2.214516] Run /linuxrc as init process

can't open /dev/tty2: No such file or directory
can't open /dev/tty3: No such file or directory
can't open /dev/tty4: No such file or directory
can't open /dev/tty2: No such file or directory
can't open /dev/tty4: No such file or directory
can't open /dev/tty3: No such file or directory
can't open /dev/tty2: No such file or directory
can't open /dev/tty4: No such file or directory
can't open /dev/tty3: No such file or directory

/ #
/ #

打印“can't open /dev/tty2: No such file or directory”说明文件系统没做好

解决办法

ln -sf /dev/null /dev/tty2

ln -sf /dev/null /dev/tty3

ln -sf /dev/null /dev/tty4

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值