On 2020-06-24 19:22, Joel Sherrill wrote:

Hi Does someone have a qemu command line handy for running libbsd network applications on Qemu? I have lots of notes and old examples but can't seem to trip the right combination today. Thanks. --joel _______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

To boot epics I was setting up DHCP, ntp and nfs on my development host,
run this script: [h1@earth utilities (master *+)]$ more setUpNetworkForQemu.py ## @brief This Python file uses the following encoding: utf-8 # Documentation for this module. # # More details. ## Documentation for a function. # import netifaces import subprocess import dns.resolver import subprocess from string import Template brNet = '10.1.0.0' brNetMask = '255.255.255.0' brLeaseRange = '10.1.0.100 10.1.0.120' br0Ip = '10.1.0.1' ethNet = '10.0.0.0' ethNetMask = '255.255.255.0' ethLeaseRange = '10.0.0.100 10.0.0.120' eth0Ip = '10.0.0.1' def setupAndStartDhcpd(): dhcpdConfStr = ('\n' + 'default-lease-time 600;\n' + 'max-lease-time 7200;\n' + 'option ntp-servers $ntpIp;\n' + 'option rtems-cmdline code 129=string;\n' + 'option rtems-cmdline "Ich DIch doch auch";\n' + 'filename "RtemsForever";\n' + 'option domain-name "rtems";\n' + '\n' + 'subnet ' + brNet + ' netmask ' + brNetMask + ' {\n' + 'range ' + brLeaseRange + ';\n' + 'option routers ' + br0Ip + ';\n' + 'option domain-name-servers $dnsIp;\n' + '}\n' + 'subnet ' + ethNet + ' netmask ' + ethNetMask + ' {\n' + 'range ' + ethLeaseRange + ';\n' + 'option routers ' + eth0Ip + ';\n' + 'option domain-name-servers $dnsIp;\n' + '}\n' ) # stop dhcp-server subprocess.run(['/bin/systemctl', 'stop', 'isc-dhcp-server.service']) dnsResolver = dns.resolver.Resolver() print("will setup dhcpd with dhcp-server at : ", dnsResolver.nameservers[0]) s = Template(dhcpdConfStr) txtToFile = s.substitute(dnsIp = dnsResolver.nameservers[0], ntpIp = '10.1.0.1') with open('/etc/dhcp/dhcpd.conf', 'w') as f: print(txtToFile, file=f) f.close() s = 'INTERFACESv4="br0"' with open('/etc/default/isc-dhcp-server', 'w') as f: print(s, file=f) f.close() # start dhcp-server subprocess.run(['/bin/systemctl', 'start', 'isc-dhcp-server.service']) def main(): print("\nWill setup qemu network\n") #setup a bridge subprocess.run(['/sbin/brctl', 'addbr', 'br0']) subprocess.run(['/sbin/ifconfig', 'br0', br0Ip, 'netmask', brNetMask, 'up']) subprocess.run(['/usr/bin/tunctl', '-t', 'tap0']) subprocess.run(['/usr/bin/tunctl', '-t', 'tap1']) subprocess.run(['/sbin/brctl', 'addif', 'br0', 'tap0', 'tap1']) subprocess.run(['/sbin/ifconfig', 'tap0']) subprocess.run(['/sbin/ifconfig', 'tap1']) # check for default gateway and interface used gws = netifaces.gateways() defaultGw = gws['default'][netifaces.AF_INET] gwAddress = defaultGw[0] gwInterface = defaultGw[1] print ("Default gateway : ", gwAddress, " on interface : ", gwInterface) if 'wlan' in gwInterface : print("Wlan interface used!? (", gwInterface, ")\n") print("dummy eth mit ip_forwarding must be put in place") #bridging wlan0 to eth0 s = '1' with open('/proc/sys/net/ipv4/ip_forward', 'w') as f: print(s, file=f) f.close() subprocess.run(['/sbin/iptables', '-t', 'nat', '-A', 'POSTROUTING', '-o', 'wlan0', '-j', 'MASQUERADE']) subprocess.run(['/sbin/brctl', 'addif', 'br0', 'eth0']) subprocess.run(['ifconfig', 'eth0', eth0Ip, 'netmask', ethNetMask, 'up']) setupAndStartDhcpd() subprocess.run(['/sbin/ifconfig', 'tap0', 'up']) print("ready for qemu")
main()

and then start a exe file with [h1@earth QtC-epics-base (7.0 *)]$ more startQemu #!/bin/bash echo Script name: $0 if [ $# -ne 1 ]; then echo "Please name the exe file" exit 2 fi #-net nic -net tap,ifname=tap1,script=no \ #-net nic,model=cadence_gem -net tap,ifname=tap1,script=no \ # -s -no-reboot sudo qemu-system-aarch64 -s -no-reboot \ -net nic,model=cadence_gem -net tap,ifname=tap0,script=no \ -serial null -serial mon:stdio -nographic -M xilinx-zynq-a9 -m 256M \ -kernel bin/RTEMS-xilinx_zynq_a9_qemu/$1

HTH, Heinz
_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to