Howto | Setup an ARM Linux system for QEMU
2013-08-07 15:00
274 查看
I've been playing with QEMU lately and found that it's really awesome. To get started all you need is to create a root filesystem and cross compile a Kernel
which is quite easy to set up on a Debian/Ubuntu based system. Here is what I did:
0 prerequisites
sudo apt-get install debootstrap qemu-user-static qemu-system git gcc-arm-linux-gnueabihf
1 create the rootfs
# create the hard disk file
fallocate -l 2GiB ubuntu-armhf.ext3
mkfs.ext3 ubuntu-armhf.ext3
# mount the hard disk file
mkdir mnt
sudo mount -o loop ubuntu-armhf.ext3 mnt
# create an initial rootfs using debootstrap
HOSTNAME=ubuntu-armhf sudo debootstrap --variant=minbase --foreign --arch armhf precise ./mnt
# copy the statically linked QEMU binary into the rootfs
sudo cp /usr/bin/qemu-arm-static mnt/usr/bin/
# chroot into the rootfs and start a shell using qemu-arm-static
LANG=C sudo chroot mnt /usr/bin/qemu-arm-static -cpu cortex-a9 /bin/sh
# run the debootstrap second stage from within the chroot:
/debootstrap/debootstrap --second-stage
# create the sources.list files for apt:
echo "deb http://ports.ubuntu.com precise
main restricted universe
deb-src http://ports.ubuntu.com precise
main restricted universe" > /etc/apt/sources.list
echo "deb http://ddebs.ubuntu.com precise
main restricted universe multiverse" > /etc/apt/sources.list.d/ddebs.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys
428D7C01
# install some fundamental packages
apt-get update
apt-get install sudo apt-utils dialog less wget
# create configuration for the serial console
cp /etc/init/tty1.conf /etc/init/ttyAMA0.conf
sed -i "s/tty1/ttyAMA0/" /etc/init/ttyAMA0.conf
# add a user
adduser myuser
# add user to the sudo group
usermod -aG sudo myuser
# exit the chroot env
exit
# unmount the rootfs
sudo umount mnt
rmdir mnt
2 cross compile the Kernel
# check out the sources
git clone -depth=1 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
mkdir linux-build
cd linux
# create a .config based on the versatile express default configuration
make ARCH=arm O=../linux-build vexpress_defconfig
# compile the kernel
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- O=../linux-build -j`getconf _NPROCESSORS_ONLN` zImage
cd ..
3 boot the image using QEMU
qemu-system-arm \
-M vexpress-a9 -m 1024 \
-serial stdio -no-reboot \
-kernel linux-build/arch/arm/boot/zImage \
-drive file=ubuntu-armhf.ext3,if=sd,cache=writeback \
--append "rw console=ttyAMA0,38400n8 console=tty root=/dev/mmcblk0" -s -S
之后,你就可以用gdb 或者eclipse 调试了
which is quite easy to set up on a Debian/Ubuntu based system. Here is what I did:
0 prerequisites
sudo apt-get install debootstrap qemu-user-static qemu-system git gcc-arm-linux-gnueabihf
1 create the rootfs
# create the hard disk file
fallocate -l 2GiB ubuntu-armhf.ext3
mkfs.ext3 ubuntu-armhf.ext3
# mount the hard disk file
mkdir mnt
sudo mount -o loop ubuntu-armhf.ext3 mnt
# create an initial rootfs using debootstrap
HOSTNAME=ubuntu-armhf sudo debootstrap --variant=minbase --foreign --arch armhf precise ./mnt
# copy the statically linked QEMU binary into the rootfs
sudo cp /usr/bin/qemu-arm-static mnt/usr/bin/
# chroot into the rootfs and start a shell using qemu-arm-static
LANG=C sudo chroot mnt /usr/bin/qemu-arm-static -cpu cortex-a9 /bin/sh
# run the debootstrap second stage from within the chroot:
/debootstrap/debootstrap --second-stage
# create the sources.list files for apt:
echo "deb http://ports.ubuntu.com precise
main restricted universe
deb-src http://ports.ubuntu.com precise
main restricted universe" > /etc/apt/sources.list
echo "deb http://ddebs.ubuntu.com precise
main restricted universe multiverse" > /etc/apt/sources.list.d/ddebs.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys
428D7C01
# install some fundamental packages
apt-get update
apt-get install sudo apt-utils dialog less wget
# create configuration for the serial console
cp /etc/init/tty1.conf /etc/init/ttyAMA0.conf
sed -i "s/tty1/ttyAMA0/" /etc/init/ttyAMA0.conf
# add a user
adduser myuser
# add user to the sudo group
usermod -aG sudo myuser
# exit the chroot env
exit
# unmount the rootfs
sudo umount mnt
rmdir mnt
2 cross compile the Kernel
# check out the sources
git clone -depth=1 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
mkdir linux-build
cd linux
# create a .config based on the versatile express default configuration
make ARCH=arm O=../linux-build vexpress_defconfig
# compile the kernel
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- O=../linux-build -j`getconf _NPROCESSORS_ONLN` zImage
cd ..
3 boot the image using QEMU
qemu-system-arm \
-M vexpress-a9 -m 1024 \
-serial stdio -no-reboot \
-kernel linux-build/arch/arm/boot/zImage \
-drive file=ubuntu-armhf.ext3,if=sd,cache=writeback \
--append "rw console=ttyAMA0,38400n8 console=tty root=/dev/mmcblk0" -s -S
之后,你就可以用gdb 或者eclipse 调试了
相关文章推荐
- Compiling Linux kernel for QEMU ARM emulator
- (编译适用于ARM的linux内核并进行QEMU仿真)Compile Linux kernel 3.2 for ARM and emulate with QEMU
- How to build qemu-system-arm in Linux
- Running Linux for ARM processors under QEMU
- [已解决]在VMware-server for linux 下装centos错误:an error has occurred. - no valid devices were found on which to create new file system
- Error: No suitable device found: no device found for connection 'System eth0' 分类: Linux 2015-03-18 21:24 63人阅读 评论(0) 收藏
- 编译OpenCV for arm-linux
- arm-linux-gcc 4.1.1 编译 QT 4.7 for ARM 中的错误
- linux挂载硬盘重启后出现an error occurred during the file system check错误最有效的解决办法
- Linux Annoyances for Geeks : Getting the Most Flexible System in the World Just the Way You Want It
- linux 2.6.32 sytem call for arm
- Terminal Notes for Embedded Linux System
- Python for Unix and Linux System Administration
- qemu模拟arm运行linux,挂载nfs
- linux-3.2.36内核启动2-setup_arch中的内存初始化1(arm平台 分析高端内存和初始化memblock)
- linux-3.2.36内核启动2-setup_arch中的内存初始化1(arm平台 分析高端内存和初始化memblock)
- Setup_Eclipse_IDE_for_FFmpeg_(Linux)
- 30 Useful Linux Commands for System Administrators(这些命令均可以在centos服务器上运行)
- Archlinuxarm / AUR的国内镜像源(for Banana Pi / Raspberry Pi , etc)(更新)
- Setups For Debugging QEMU with GDB and DDD