<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p id="reply-intro">On 2020-06-24 19:22, Joel Sherrill wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div id="replybody1">
<div dir="ltr">Hi
<div> </div>
<div>Does someone have a qemu command line handy for running libbsd network applications on Qemu?</div>
<div> </div>
<div>I have lots of notes and old examples but can't seem to trip the right combination today.</div>
<div> </div>
<div>Thanks.</div>
<div> </div>
<div>--joel</div>
</div>
</div>
<br />
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">_______________________________________________<br />devel mailing list<br /><a href="mailto:devel@rtems.org">devel@rtems.org</a><br /><a href="http://lists.rtems.org/mailman/listinfo/devel" target="_blank" rel="noopener noreferrer">http://lists.rtems.org/mailman/listinfo/devel</a></div>
</blockquote>
<p>To boot epics I was setting up DHCP, ntp and nfs on my development host, run this script:</p>
<p><br /></p>
<p><span>[h1@earth utilities (master *+)]$ more setUpNetworkForQemu.py <br />## @brief This Python file uses the following encoding: utf-8 <br /># Documentation for this module. <br /># <br /># More details. <br /><br />## Documentation for a function. <br /># <br />import netifaces <br />import subprocess <br />import dns.resolver <br />import subprocess <br />from string import Template <br /><br />brNet = '10.1.0.0' <br />brNetMask = '255.255.255.0' <br />brLeaseRange = '10.1.0.100 10.1.0.120' <br />br0Ip = '10.1.0.1' <br /><br />ethNet = '10.0.0.0' <br />ethNetMask = '255.255.255.0' <br />ethLeaseRange = '10.0.0.100 10.0.0.120' <br />eth0Ip = '10.0.0.1' <br /><br />def setupAndStartDhcpd(): <br /> dhcpdConfStr = ('\n' + <br /> 'default-lease-time 600;\n' + <br /> 'max-lease-time 7200;\n' + <br /> 'option ntp-servers $ntpIp;\n' + <br /> 'option rtems-cmdline code 129=string;\n' + <br /> 'option rtems-cmdline "Ich DIch doch auch";\n' + <br /> 'filename "RtemsForever";\n' + <br /> 'option domain-name "rtems";\n' + <br /> '\n' + <br /> 'subnet ' + brNet + ' netmask ' + brNetMask + ' {\n' + <br /> 'range ' + brLeaseRange + ';\n' + <br /> 'option routers ' + br0Ip + ';\n' + <br /> 'option domain-name-servers $dnsIp;\n' + <br /> '}\n' + <br /> 'subnet ' + ethNet + ' netmask ' + ethNetMask + ' {\n' + <br /> 'range ' + ethLeaseRange + ';\n' + <br /> 'option routers ' + eth0Ip + ';\n' + <br /> 'option domain-name-servers $dnsIp;\n' + <br /> '}\n' ) <br /><br /> # stop dhcp-server <br /> subprocess.run(['/bin/systemctl', 'stop', 'isc-dhcp-server.service']) <br /><br /> dnsResolver = dns.resolver.Resolver() <br /> print("will setup dhcpd with dhcp-server at : ", dnsResolver.nameservers[0]) <br /> s = Template(dhcpdConfStr) <br /> txtToFile = s.substitute(dnsIp = dnsResolver.nameservers[0], ntpIp = '10.1.0.1') <br /> with open('/etc/dhcp/dhcpd.conf', 'w') as f: <br /> print(txtToFile, file=f) <br /> f.close() <br /><br /> s = 'INTERFACESv4="br0"' <br /> with open('/etc/default/isc-dhcp-server', 'w') as f: <br /> print(s, file=f) <br /> f.close() <br /><br /> # start dhcp-server <br /> subprocess.run(['/bin/systemctl', 'start', 'isc-dhcp-server.service']) <br /><br />def main(): <br /> print("\nWill setup qemu network\n") <br /><br /> #setup a bridge <br /> subprocess.run(['/sbin/brctl', 'addbr', 'br0']) <br /> subprocess.run(['/sbin/ifconfig', 'br0', br0Ip, 'netmask', brNetMask, 'up']) <br /> subprocess.run(['/usr/bin/tunctl', '-t', 'tap0']) <br /> subprocess.run(['/usr/bin/tunctl', '-t', 'tap1']) <br /> subprocess.run(['/sbin/brctl', 'addif', 'br0', 'tap0', 'tap1']) <br /> subprocess.run(['/sbin/ifconfig', 'tap0']) <br /> subprocess.run(['/sbin/ifconfig', 'tap1']) <br /><br /> # check for default gateway and interface used <br /> gws = netifaces.gateways() <br /> defaultGw = gws['default'][netifaces.AF_INET] <br /> gwAddress = defaultGw[0] <br /> gwInterface = defaultGw[1] <br /> print ("Default gateway : ", gwAddress, " on interface : ", gwInterface) <br /> if 'wlan' in gwInterface : <br /> print("Wlan interface used!? (", gwInterface, ")\n") <br /> print("dummy eth mit ip_forwarding must be put in place") <br /> #bridging wlan0 to eth0 <br /> s = '1' <br /> with open('/proc/sys/net/ipv4/ip_forward', 'w') as f: <br /> print(s, file=f) <br /> f.close() <br /> subprocess.run(['/sbin/iptables', '-t', 'nat', '-A', 'POSTROUTING', <br /> '-o', 'wlan0', '-j', 'MASQUERADE']) <br /> subprocess.run(['/sbin/brctl', 'addif', 'br0', 'eth0']) <br /> subprocess.run(['ifconfig', 'eth0', eth0Ip, 'netmask', ethNetMask, 'up']) <br /><br /> setupAndStartDhcpd() <br /> subprocess.run(['/sbin/ifconfig', 'tap0', 'up']) <br /> print("ready for qemu") <br /><br />main()<br /><br /></span></p>
<p><br /></p>
<p><span>and then start a exe file with</span></p>
<p><br /></p>
<p><span>[h1@earth QtC-epics-base (7.0 *)]$ more startQemu <br />#!/bin/bash <br />echo Script name: $0 <br />if [ $# -ne 1 ]; <br /> then echo "Please name the exe file" <br /> exit 2 <br />fi <br />#-net nic -net tap,ifname=tap1,script=no \ <br />#-net nic,model=cadence_gem -net tap,ifname=tap1,script=no \ <br /># -s -no-reboot <br />sudo qemu-system-aarch64 -s -no-reboot \ <br />-net nic,model=cadence_gem -net tap,ifname=tap0,script=no \ <br />-serial null -serial mon:stdio -nographic -M xilinx-zynq-a9 -m 256M \ <br />-kernel bin/RTEMS-xilinx_zynq_a9_qemu/$1<br /><br /></span></p>
<p><span>HTH, Heinz</span></p>
</body></html>