wutiejun / workspace

My workspace.
7 stars 3 forks source link

U-boot for ARM on QEMU #4

Open wutiejun opened 8 years ago

wutiejun commented 8 years ago

https://balau82.wordpress.com/2010/03/10/u-boot-for-arm-on-qemu/

http://processors.wiki.ti.com/index.php/Kernel_-_Common_Problems_Booting_Linux

http://opensourceforu.com/2011/08/qemu-for-embedded-systems-development-part-3/

wutiejun commented 8 years ago

Embedded Programming with the GNU Toolchain

http://www.bravegnu.org/gnu-eprog/

U-Boot – Multi image booting scenarios

http://www.denx.de/wiki/pub/U-Boot/Documentation/multi_image_booting_scenarios.pdf

wutiejun commented 8 years ago

QEMU Binaries for Windo

https://qemu.weilnetz.de/w64/2015/

wutiejun commented 8 years ago

Virtual Development Board

http://elinux.org/Virtual_Development_Board

这一篇文档还不错, 可以参考实现一个ARM的虚拟机.

这里使用的是versatilepb单板,且使用uboot来引导内核。 versatilepb这块单板的好处是支持1G速率的虚拟网卡。

当前模拟的单板不支持1G速率的网卡,仅支持最高100M的网卡,实际使用时,感觉只有10M左右。

wutiejun commented 8 years ago

Run ARM Linux on QEMU-emulated vexpress platform

http://wiki.ecg.rice.edu/doku.php?id=xzl:tutorial:arm_qemu

wutiejun commented 8 years ago

System emulation using QEMU

https://gmplib.org/~tege/qemu.html

Documentation/Networking

http://wiki.qemu.org/Documentation/Networking

wutiejun commented 8 years ago

ramfs, rootfs and initramfs

https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt

wutiejun commented 8 years ago

Ubuntu Installation/QemuEmulator

https://help.ubuntu.com/community/Installation/QemuEmulator#Preparation_of_the_QEMU_virtual_environment

wutiejun commented 8 years ago

QemuARMVexpress

Instructions on how to successfully setup qemu to emulate an arm vexpress a9/a15 board (and possibly any other arm hw that qemu emulates):

1) setup the rootfs

sudo apt-get install qemu-user-static qemu-system-arm

mkdir vexpress
cd vexpress
mkdir qemu-img

# 4GBs should be enough
dd if=/dev/zero of=./vexpress-4G.img bs=4M count=1024
sudo losetup -f ./vexpress-4G.img
sudo mkfs.ext4 /dev/loop0
sudo mount /dev/loop0 qemu-img

# let's bootstrap a saucy armhf rootfs in the qemu-img directory
sudo qemu-debootstrap --arch=armhf saucy qemu-img
sudo cp `which qemu-arm-static` qemu-img/usr/bin/

# setup serial console, apt repositories and network
sudo chroot qemu-img
sed 's/tty1/ttyAMA0/g' /etc/init/tty1.conf > /etc/init/ttyAMA0.conf
echo "deb  http://ports.ubuntu.com saucy main restricted multiverse universe" > /etc/apt/sources.list
apt-get update
echo -e "\nauto eth0\niface eth0 inet dhcp" >> /etc/network/interfaces

# root password
passwd

2) pick and install a kernel

open a web browser and navigate to this page:

https://launchpad.net/ubuntu/+source/linux

pick a kernel that suites your need (e.g. 3.10.0-6.17), download and install it:

apt-get install wget ca-certificates
wget https://launchpad.net/ubuntu/+archive/primary/+files/linux-image-3.10.0-6-generic-lpae_3.10.0-6.17_armhf.deb
dpkg -i linux-image-3.10.0-6-generic-lpae_3.10.0-6.17_armhf.deb

# press CTRL+D to exit the chroot

3) boot it up

# copy kernel, initrd and dtb files
cp qemu-img/boot/vmlinuz-3.10.0-6-generic-lpae .
cp qemu-img/boot/initrd.img-3.10.0-6-generic-lpae .
cp qemu-img/lib/firmware/3.10.0-6-generic-lpae/device-tree/vexpress-v2p-ca15-tc1.dtb .
# umount the rootfs img
sudo umount qemu-img
# and finally boot it up!
qemu-system-arm -kernel vmlinuz-3.10.0-6-generic-lpae -initrd initrd.img-3.10.0-6-generic-lpae -M vexpress-a15 -serial stdio -m 1024 -append 'root=/dev/mmcblk0 rw mem=1024M raid=noautodetect rootwait console=ttyAMA0,38400n8 devtmpfs.mount=0' -sd vexpress-4G.img -dtb ./vexpress-v2p-ca15-tc1.dtb
wutiejun commented 8 years ago

Compile Linux kernel 3.2 for ARM and emulate with QEMU

https://balau82.wordpress.com/2012/03/31/compile-linux-kernel-3-2-for-arm-and-emulate-with-qemu/

The short story Create a clean directory, then create a file called “init.c“, which contains the following simple C code:

#include <stdio.h>

void main() {
  printf("Hello World!\n");
  while(1);
}

Then in the same directory execute the following commands in order:

wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.tar.bz2
tar xjf linux-3.2.tar.bz2
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
cd linux-3.2
make vexpress_defconfig
make all
cd ..
arm-linux-gnueabi-gcc -static init.c -o init
echo init|cpio -o --format=newc > initramfs
qemu-system-arm -M vexpress-a9 -kernel linux-3.2/arch/arm/boot/zImage -initrd initramfs -serial stdio -append "console=tty1"

The kernel compilation (the “make all” command) could take some minutes or hours depending on your host machine power. The last command opens a QEMU window, that shows a black background and many boot messages, and towards the end the “Hello World!” string is displayed.

wutiejun commented 8 years ago

一些错误处理

  1. 如果是使用VBOX再启动QEMU, 在VBOX里没有启动声卡, 则UBUNTU默认的QEMU无法启动, 即声卡驱动错误; 解决办法: 在VBOX里启用声卡;
wutiejun commented 8 years ago

NFS

https://www.howtoforge.com/nfs-server-on-ubuntu-14.10

http://www.krizna.com/ubuntu/setup-nfs-server-ubuntu-14-04/

http://www.linuxuser.co.uk/tutorials/boot-linux-from-an-nfs-server

apt-get update
apt-get install nfs-kernel-server

exportfs -a

service nfs-kernel-server start
wutiejun commented 8 years ago

修改了N久, 终于跑起来了:

#!/bin/bash

#NET="-net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=./qemu-ifup,downscript=./qemu-ifdown"

#FLAGS="-nographic -curses"

#FLAGS="-nographic -soundhw none"
FLAGS="-nographic"

MACH="-M versatilepb -name ARM -m 256M"

APPCMD="console=ttyAMA0 root=/dev/ram rdinit=/linuxrc"

#NET="-netdev tap,id=eth1"

#NFS="root=/dev/nfs nfsroot=10.0.2.2:/QEMU/rootfs_arm rw ip=10.0.2.15::10.0.2.1:255.255.255.0 init=/sbin/init"

#qemu-system-arm -m 256M -M $MACH -kernel zImage -initrd initramfs -serial stdio -append "console=tty1" $FLAGS

echo qemu-system-arm $MACH -kernel zImage -initrd rootfs.cpio.gz $FLAGS -append "$APPCMD" $NET

qemu-system-arm $MACH -kernel zImage -initrd rootfs.cpio.gz $FLAGS -append "$APPCMD" $NET
wutiejun commented 8 years ago

ifdown

#!/bin/bash

#/sbin/ifconfig $1 down
eth=eth0
IP=`ifconfig br0|grep "inet addr"|awk '{print $2}'|sed 's/addr://'`

GATEWAY=`ip route |grep default|awk '{print $3}'`

ip addr del $IP dev br0

ifconfig br0 down

brctl delbr br0

ifconfig $eth $IP up

ip route add default via $GATEWAY dev $eth

ifconfig $eth mtu 1500

ifup

#!/bin/bash
#/sbin/ifconfig $1 192.168.0.1 netmask 255.255.255.252
#/sbin/ifconfig $1 192.168.1.5 netmask 255.255.255.252

eth=eth0
IP=`ifconfig $eth |grep "inet addr"|awk '{print $2}'|sed 's/addr://'`
GATEWAY=`ip route |grep default |awk '{print $3}'`

ip addr del $IP dev $eth

ifconfig $1 up

ifconfig br0 down &>/dev/null

brctl delbr br0 &>/dev/null

brctl addbr br0

brctl addif br0 $eth

brctl addif br0 $1

ifconfig br0 $IP up

ifconfig $eth mtu 1600
#ip route add default via $GATEWAY dev br0 &>/dev/null
wutiejun commented 8 years ago

Virtual Box的HOST ONLY网络在重启Ubuntu之后才可用

  1. 正常启动VB, 发现HOST ONLY的网络怎么都ping不通, 检测配置配置等, 一切OK;
  2. 重启一下Gust系统, 网络恢复正常;

暂不清楚原因, 在google上找了一些信息, 说是VB的BUG, 但这个BUG发现了几年了, 应该修复了, 为什么还会存在? 看VB的版本号, 确实也应该修复了.

标记一下, 先暂时按手动复位一次来使用吧, 暂时没精力找原因了.

wutiejun commented 7 years ago

Qemu For Windows

http://wiki.qemu.org/Hosts/Windows

http://www.qemu.org/download/#source