Howto | Setup an ARM Linux system for QEMU

來源:互聯網
上載者:User

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 調試了

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.