tftp 引导所需的 qemu 网络不工作

qemu network not working needed for tftp booting

嗨,我试图让网络在 qemu-system-arm uboot 上工作以进行 tftp/dhcp 引导,无法理解 QEMU 5.0。需要 0 个网络配置,你能帮忙吗。

$qemu-system-arm --version QEMU 模拟器版本 5.0.0

使用的 Yocto BSP:https://github.com/ahmedkassem56/meta-qemuarma9.git

$猫/etc/qemu-ifup

#!/bin/sh
set -x
/sbin/ip a add 192.168.0.1/255.255.255.0 dev 
/sbin/ip link set  up

$sudo chmod +x /etc/qemu-ifup

$ sudo qemu-system-arm -M vexpress-a9 -m 256 -kernel u-boot.elf -nographic -net tap,id=tap1,script=/etc/qemu-ifup -net nic,id=nic1

+ /sbin/ip a add 192.168.0.1/255.255.255.0 dev tap1
+ /sbin/ip link set tap1 up

U-Boot 2020.01 (Jan 06 2020 - 20:56:31 +0000)

DRAM:  256 MiB
WARNING: Caches not enabled
Flash: 128 MiB
MMC:   MMC: 0
Loading Environment from EXT4... Card did not respond to voltage select!
In:    serial
Out:   serial
Err:   serial
Net:   smc911x-0
Hit any key to stop autoboot:  0 
=> setenv serverip 192.168.0.1
=> setenv ipaddr 192.168.0.2
=> setenv netmask 255.255.255.0
=> setenv gatewayip 192.168.1.0
=> ping 192.168.0.1
smc911x: MAC 52:54:00:12:34:56
smc911x: detected LAN9118 controller
smc911x: phy initialized
smc911x: MAC 52:54:00:12:34:56
Using smc911x-0 device

ARP Retry count exceeded; starting again
smc911x: MAC 52:54:00:12:34:56
ping failed; host 192.168.0.1 is not alive
=> 

幸运的是 qemu 网络现在可以使用以下设置..

参考:Build a complete virtual ARM development environment based on QEMU (uboot+linux+rootfs)

~/ProjectWork/bin/$猫tuntap.sh

set -x

ETH=enp2s0   #Ethernet interface in your HOST 
USR=junno    #User name- whoami

if test -z  ; then
        echo need a arg: down/up
        exit
fi

if [ "up" =  ] ; then

        brctl addbr br0

        ifconfig $ETH down
        brctl addif br0 $ETH

        #Close Spanning Tree Protocol
        brctl stp br0 off

        ifconfig br0 10.8.8.1 netmask 255.255.255.0 promisc up  #3
        ifconfig $ETH 10.8.8.10 netmask 255.255.255.0 promisc up #2

        tunctl -t tap0 -u $USR
        ifconfig tap0 10.8.8.11 netmask 255.255.255.0 promisc up #4
        brctl addif br0 tap0
else
        ifconfig tap0 down
        brctl delif br0 tap0

        ifconfig $ETH down
        brctl delif br0 enp2s0

        ifconfig br0 down
        brctl delbr br0

        ifconfig $ETH 10.8.8.10 netmask 255.255.255.0  #2
fi

在下面添加行 $vi ~/.bashrc

alias ifup_tap='sudo ~/ProjectWork/bin/tuntap.sh up'
alias ifdown_tap='sudo ~/ProjectWork/bin/tuntap.sh down'

$ source ~/.bashrc

主机:

cp zImage-initramfs-qemuarma9.bin /tftpboot/
cp vexpress-v2p-ca9-qemuarma9.dtb /tftpboot/

~/ProjectWork/bin$ ifdown_tap
~/ProjectWork/bin$ ifup_tap

目标:

~/ProjectWork/bin$ sudo qemu-system-arm -M vexpress-a9 -m 512 -nographic -net nic -net tap,ifname=tap0,script=no -kernel u -boot.elf

U-Boot 2020.01 (Jan 06 2020 - 20:56:31 +0000)

DRAM:  512 MiB
WARNING: Caches not enabled
Flash: 128 MiB
MMC:   MMC: 0
Loading Environment from EXT4... Card did not respond to voltage select!
In:    serial
Out:   serial
Err:   serial
Net:   smc911x-0
Hit any key to stop autoboot:  1 
=>
=>setenv serverip 10.8.8.1; setenv ipaddr 10.8.8.2; setenv netmask 255.255.255.0; 
=>ping 10.8.8.1
 host 10.8.8.1 is alive
    
//For initramfs
=>setenv bootargs "console=ttyAMA0,115200 root=/dev/ram rw"
=>tftp 0x60000000 zImage-initramfs-qemuarma9.bin
=>tftp 0x70000000 vexpress-v2p-ca9-qemuarma9.dtb
=>bootz 0x60000000 - 0x70000000