qemu+kernel (1) 搭建arm64 linux kernel环境

1)pre:

1.交叉编译工具链

2.qemu

2)编译kernel:

不详述,这个比较容易

只需vmlinux和Image

vmlinux:所生成的kernel Image

Image:vmlinux是gdb调试使用

3)根文件系统制作

3.1)busybox配置编译

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

tar -xf busybox-1.35.0.tar.bz2

cd busybox-1.35.0/

export ARCH=arm64

export CROSS_COMPILE=aarch64-linux-gnu-

make menuconfig(通过图形化菜单界面配置编译选项)

//选上 Settings –> Build Options –> [*] Build static binary(no share libs)

make(编译源码,生成可执行文件)

make install(安装编译结果到目标目录, 并不会重新编译,只是复制文件)

3.2)rootfs image制作

构建ext4 image

qemu-img create rootfs.img 512m

mkfs.ext4 rootfs.img

挂载rootfs.img到rootfs目录

mkdir rootfs

sudo mount rootfs.img rootfs

拷贝busybox的编译结果_install,同时创建关键目录(挂载虚拟文件系统需要)

sudo cp -rf _install/* rootfs

cd rootfs

sudo mkdir proc sys dev etc etc/init.d

sudo vim etc/init.d/rcS

rcS中的内容,主要是挂载常使用的虚拟文件系统

#!/bin/sh

mount -t proc none /proc

mount -t sysfs none /sys

mount -t debugfs none /sys/kernel/debug

然后给rcS增加执行权限

sudo chmod +x etc/init.d/rcS

最后umount rootfs

cd ..

sudo umount rootfs

4) qemu启动

qemu-system-aarch64

-machine virt,virtualization=true,gic-version=3

-nographic

-m size=1024M

-cpu cortex-a72

-smp 2

-kernel <path>/Image

-drive format=raw,file=rootfs.img

-append "root=/dev/vda rw"

5)流程图

Bootloader → Kernel:Bootloader 加载kernel;

Kernel → rootfs.img:kernel挂载 rootfs.img 作为根文件系统 /;

Kernel → BusyBox (/init):内核在 rootfs 中执行 /init,通常是 BusyBox 提供的。

参考专栏:https://blog.csdn.net/yanghao23/category_12567843.html

#打工人的桌面壁纸都是啥样的?##通信硬件人笔面经互助##牛客创作赏金赛#

秋招之旅结束大半,目前也拿到了一些公司的offer,各种方向的: 芯片公司:兆芯,联发科,大普微等 产品公司:小米,联想,影石,虹软,诺瓦等 汽车公司:长安,博世,经纬恒润等 国央企研究所:32所,52所,712,星网,航空工业上电所 接下来会分享一些面试经验和学习经验

全部评论

相关推荐

05-20 14:22
广州大学 后端
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务