使用Qemu模拟arm开发板
使用Qemu模拟arm开发板
环境:ubuntu18
1.安装qemu
sudo apt-get install zlib1g-dev libglib2.0-0 libglib2.0-dev qemu
安装完后在shell输入 qemu 按tab键如果出现自动补齐就证明成功安装
2.安装交叉编译链环境
sudo apt-get install gcc-arm-linux-gnueabi
验证安装
dpkg -l gcc-arm-linux-gnueabi
可以看到安装结果为
user@ubuntu18:~/Documents$ dpkg -l gcc-arm-linux-gnueabi
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-============================-===================-===================-==============================================================
ii gcc-arm-linux-gnueabi 4:7.4.0-1ubuntu2.3 amd64 GNU C compiler for the armel architecture
使用which来查看安装路径
user@ubuntu18:~/Documents$ which arm-linux-gnueabi-gcc
/usr/bin/arm-linux-gnueabi-gcc
对象的库的路径一般为/usr/arm-linux-gnueabi/lib/
3.编译linux busybox 镜像
3.1
编译linux
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig#make distclean#make menuconfig #make zImage -j8#make dtbs -j8make all -j8
可以在看arch/arm/boot/zImage是否存在,如果不存在则说明编译出错。在个人编译的过程中发现通过命令行指定交叉编译器前缀好像不管用,可以尝试直接修改Makefile来指定编译前缀。如下
#ARCH ?= $(SUBARCH)
ARCH = arm
#CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
CROSS_COMPILE = arm-linux-gnueabi-
上面注释的是原有的。
3.2 编译busybox
下载busybox
https://busybox.net/downloads/
下载的文件如果是以tar.bz2结尾的,使用tar xjvf 来解压。
解压busybox之后,输入以下命令来编译busybox
make defconfig
make CROSS_COMPILE=arm-linux-gnueabi- -j8
make install CROSS_COMPILE=arm-linux-gnueabi- -j8
编译后的文件在_install目录下,如下:
user@ubuntu18:~/Documents/busybox-1.35.0$ ls _install/
bin lib linuxrc sbin usr
可以看到有一些根文件系统必须的目录。
3.3 再新建脚本来制作镜像(切换到busybox的上级目录)
mkdir -p rootfs/{dev,etc/init.d,lib}
touch rootfs/etc/init.d/rcS
echo -e "#!/bin/sh\n" > rootfs/etc/init.d/rcScp busybox-1.35.0/_install/* -r rootfs/
sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
sudo mknod rootfs/dev/tty1 c 4 1sudo mknod rootfs/dev/tty2 c 4 2sudo mknod rootfs/dev/tty3 c 4 3sudo mknod rootfs/dev/tty4 c 4 4sudo chown root:root -R rootfs/*
sudo chmod 777 rootfs/etc/init.d/rcS
qemu-img create -f raw disk.img 512M
mkfs -t ext4 ./disk.img
mkdir -p tmpfs
sudo mount -o loop ./disk.img tmpfs/
sudo cp -r rootfs/* tmpfs/
sudo umount tmpfs
file disk.img
运行上述命令之后,可以得到一个file.img的文件,这就是镜像
3.4 启动虚拟的arm 开发板
使用一下命令来启动虚拟机
sudo chmod 777 disk.img
qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/user/Documents/linux_old1/arch/arm/boot/zImage -dtb /home/user/Documents/linux_old1/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0 console=ttyAMA0" -sd disk.img
上面的命令很长,可以新建一个shell脚本来运行。其中
-kernel 指定内核文件路径,-dtb 指定设备树的路径 ,-sd就是镜像了。
最后运行一下上面的命令,最后的结果如下,
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/smb/smb:motherboard/smb:motherboard:iofpga@7,00000000/10007000.kmi/serio1/input/input2
EXT2-fs (mmcblk0): error: couldn't mount because of unsupported optional features (2c0)
EXT4-fs (mmcblk0): couldn't mount as ext3 due to feature incompatibilities
EXT4-fs (mmcblk0): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext4 filesystem) readonly on device 179:0.
Freeing unused kernel memory: 280K (80614000 - 8065a000)
random: nonblocking pool is initializedPlease press Enter to activate this console.
此时按Enter就可以运行模拟arm开发板的shell了。
上面整个过程的命令如下:
#!/bin/bash
kernel_path=linux_old1
busybox_path=busybox-1.35.0
img_filename=disk.img
curDir=`pwd`
echo ${curDir}
isBuildKernel=0
isBuildBusybox=0
while getopts "kb" OPTNAME
docase "${OPTNAME}" in"k")isBuildKernel=1;;"b")isBuildBusybox=1;;"?")echo "UnKnown Option ${OPTARG}"exit 1;;"*")echo "UnKnow error while processing options"exit 1;;esac
echo "OPTIND is now ${OPTIND}"
donefunction build_kernel(){make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig#make distclean#make menuconfig #make zImage -j8#make dtbs -j8make all -j8
}function build_busybox(){make defconfigmake menuconfigmake CROSS_COMPILE=arm-linux-gnueabi- -j8make install CROSS_COMPILE=arm-linux-gnueabi- -j8
}
function build_resolv_conf(){touch ${curDir}/rootfs/etc/resolv.confecho -e "nameserver 114.114.114.114 \nnameserver 192.168.1.1" > ${curDir}/rootfs/etc/resolv.conf
}
function build_rcS(){touch rootfs/etc/init.d/rcSecho -e "#!/bin/sh\n" > rootfs/etc/init.d/rcSecho -e "PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH\n" >> rootfs/etc/init.d/rcSecho -e "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib:/usr/lib\n" >> rootfs/etc/init.d/rcSecho -e "export PATH LD_LIBRARY_PATH\n" >> rootfs/etc/init.d/rcSecho -e "mount -a\n" >> rootfs/etc/init.d/rcSecho -e "mkdir /dev/pts\n" >> rootfs/etc/init.d/rcSecho -e "mount -t devpts devpts /dev/pts\n" >> rootfs/etc/init.d/rcSecho -e "echo /sbin/mdev > /proc/sys/kernel/hotplug\n" >> rootfs/etc/init.d/rcSecho -e "mdev -s\n" >> rootfs/etc/init.d/rcS
}
function build_fstab(){file=${curDir}/rootfs/etc/fstabtouch ${file}echo -e "#<file system> <mount point> <type> <options> <dump> <pass>" > ${file}echo -e "proc /proc proc defaults 0 0" >> $fileecho -e "tmpfs /tmp tmpfs defaults 0 0" >> $fileecho -e "ysfs /sys sysfs defaults 0 0" >> $file}
function build_inittab(){file=${curDir}/rootfs/etc/inittabtouch ${file}echo -e "#etc/inittab" >> $fileecho -e "::sysinit:/etc/init.d/rcS">> $fileecho -e "console::askfirst:-/bin/sh">> $fileecho -e "::restart:/sbin/init">> $fileecho -e "::ctrlaltdel:/sbin/reboot">> $fileecho -e "::shutdown:/bin/umount -a -r">> $fileecho -e "::shutdown:/sbin/swapoff -a" >> $file
}
function build_img(){mkdir -p rootfs/{dev,etc/init.d,lib}cd rootfsmkdir -p dev etc mnt proc var tmp sys root homecd ..build_rcSbuild_resolv_confbuild_fstab#build_inittabcp busybox-1.35.0/_install/* -r rootfs/sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/ sudo mknod rootfs/dev/tty1 c 4 1sudo mknod rootfs/dev/tty2 c 4 2sudo mknod rootfs/dev/tty3 c 4 3sudo mknod rootfs/dev/tty4 c 4 4sudo chown root:root -R rootfs/*sudo chmod 777 rootfs/etc/init.d/rcSqemu-img create -f raw ${img_filename} 512M mkfs -t ext4 ./${img_filename}mkdir -p tmpfs sudo mount -o loop ./${img_filename} tmpfs/ sudo cp -r rootfs/* tmpfs/sudo umount tmpfs file ${img_filename}
}
if [ ${isBuildKernel} == 1 ] ;thencd ${kernel_path}build_kernelcd ..
fi
if [ ${isBuildBusybox} == 1 ] ;thencd ${busybox_path}build_busyboxcd ..
fi
sudo rm -rf rootfs/*
build_img
sudo chmod 777 ${img_filename}
使用Qemu模拟arm开发板相关推荐
- 用QEMU模拟ARM开发板,搭建Linux kernel运行环境
前言 有的时候我们想调试linux kernel或者linux应用程序,但是又没有硬件环境,这个时候可以选择用模拟器的方法,模拟出一个硬件环境. Android emulator Android系统的 ...
- Ubuntu 16.04 利用qemu模拟ARM开发板
QEMU目前可以模拟vexpress Cortex A9四核处理器开发板. 环境配置:Ubuntu 16.04,Kernel 4.4.1 内容参考了: http://blog.csdn.net/lin ...
- 从0开始使用QEMU模拟ARM开发环境之脚本制作分区镜像(rootfs+zImage+dtb)
文章目录 从0开始使用QEMU模拟ARM开发环境系列一览表 目录结构: 脚本介绍: 分区镜像制作脚本 qemu启动脚本 流程示例 从0开始使用QEMU模拟ARM开发环境系列一览表 文章中 u-boot ...
- 我是穷人,可以不买开发板了吗?---QEMU 模拟arm系统
文章目录 序言 准备工作 QEMU开始 Linux内核 U-boot 的修改及编译 构建根文件系统 busybox配置安装 制作根文件系统 启动QEMU模拟arm开发板 出现的问题 结束语 序言 一直 ...
- 一步步教你如何在Ubuntu虚拟机中安装QEMU并模拟模拟arm 开发环境(一)uImage u-boot
初次接触qemu是因为工作的需要,有时候下了班,可能需要在家研究一些东西,因为博主用到arm环境,这时候博主比较小气,不愿花钱买开发板,当然博主在这里给大家的建议是,如果要真正学懂arm构架的相关知识 ...
- 为 QEMU ARM 仿真器编译 Linux 内核:QEMU 模拟 ARM 环境
QEMU 是一套由法布里斯·贝拉(Fabrice Bellard)所编写的以 GPL 许可证分发源码的模拟处理器,在GNU/Linux 平台上使用广泛.简单来说,QEMU 是一个虚拟机,与常见的 Vm ...
- 嵌入式开发入门之经典 ARM开发板
嵌入式开发入门之经典 开始进入嵌入式世界,真是一头雾水,不知道如何入手!也不知道该如何学习,学习什么,最近从网上转载这篇文章,对我启发很大,对于初始进入嵌入式的人们很有帮组,好多嵌入式大侠都说这是入门 ...
- arm开发板用无线网卡连接ap
首先arm开发板上一定要有无线网卡的驱动!2.6内核支持10多种无线网卡芯片的驱动在买网卡的时候最后芯片是linux内核里有的! 要不找着合适的驱动很麻烦! 接下来就是命令来连接ap 我用vista系 ...
- 基于ARM开发板搭建物联网服务器
基于ARM开发板搭建物联网服务器 一.项目需求 1.1设备需求 1.2知识需求 1.3项目介绍 二.开发环境搭建 2.1阿里云服务器配置 2.2虚拟机交叉编译环境搭建 2.3下载相关应用压缩文件 三. ...
- 中国嵌入式高端ARM开发板的江湖故事——详细分析国内各家ARM11 S3C6410 开发板的选型以及竞争格局
// Topic:中国嵌入式高端ARM开发板的江湖故事--详细分析国内各家ARM11 S3C6410 开发板的选型以及竞争格局 //作者:gooogleman //版权:gooogleman 邮箱 ...
最新文章
- UVa 167(八皇后)、POJ2258 The Settlers of Catan——记两个简单回溯搜索
- 从做大牛那里整理的Python函数相关的学习笔记,希望对你有帮助
- 四旋翼姿态解算——基础理论及推导
- xil_printf打印遇到的问题
- Metronic学习之路
- ubuntu 符号连接的层数过多_Linux符号连接的层数过多解决
- ElasticSearch+NLog实现.net core分布式日志管理
- C语言isalnum函数介绍、示例和实现
- mysql中如何删除空记录表_mysql删除表中的记录
- Linux平台下裸设备的绑定:
- 解决Boost库链接出错问题
- ECharts柱状图图形标签间隔显示
- java学生成绩管理系统类图,学生成绩管理系统的用例类图.ppt
- 固定成本、可变成本、沉没成本、机会成本、边际成本
- 年产4000吨果味奶糖生产车间工艺设计
- 没有PPT,一文带你了解元宇宙
- 钉钉页面跳转_钉钉统一跳转协议
- pv 、uv、ip、vv、cv分别是什么
- ios系统安装包下载_iOS 屏蔽系统升级,描述文件版本已复活,无需越狱,请速度下载!...
- 微信的隐藏功能竟然可以一秒获取好友位置!这到底是神马操作
热门文章
- Qt编写邮件客户端IMAP4(一)收取邮件
- ppt技巧一四步法调整段落排版
- Landsat系列卫星
- 解决“桌面右键单击文件夹鼠标一直转圈”
- 二元回归方程matlab,matlab 多元非线性回归方程问题
- 20162328WJH实验五网络编程与安全实验报告
- 5028: 小Z的加油店2257: [Jsoi2009]瓶子和燃料
- 计算机音乐谱子 追光者,精选追光者简谱
- 计算机休眠设置xp系统,【xp怎么让电脑不休眠】xp怎么设置电脑不休眠_xp电脑休眠设置...
- 分布式定时任务框架选型,完美!