From 2f6a47c4d4dc24135b69ed01e193740c24f269e8 Mon Sep 17 00:00:00 2001 From: Adrian Freihofer Date: Tue, 17 Mar 2020 16:26:50 +0100 Subject: runqemu: support multiple NICs Emulating more than one network interface with runqemu is a bit tricky, but possible. For example, the following leads to an emulated device with eth0 and eth1: QB_NETWORK_DEVICE_prepend = " \ -device virtio-net-device,mac=52:54:00:12:34:03 \ " or QB_NETWORK_DEVICE_append = " \ -device virtio-net-pci,mac=52:54:00:12:34:03 \ " When booting Qemu with two NICs, the kernel does not know which interface the specified ip=192.168.7.... command line argument should be applied. This delays the boot process for a very long time and a guest wihtout IP configuration. This add two new configuraton parameters to runqemu: QB_CMDLINE_IP_SLIRP and QB_CMDLINE_IP_TAP to explicitely specify the ip= kernel command line arguments for tap and slirp mode. Note: Simply adding "::eth0" broke some builds on the Yocto autobuilder. (From OE-Core rev: 59bfdc331c1494c05ab38804b281878a1f571f6d) Signed-off-by: Adrian Freihofer Signed-off-by: Richard Purdie --- scripts/runqemu | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/runqemu b/scripts/runqemu index dd0aa4b28f..6f24093d77 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -185,6 +185,8 @@ class BaseConfig(object): self.vmtypes = ('hddimg', 'iso') self.fsinfo = {} self.network_device = "-device e1000,netdev=net0,mac=@MAC@" + self.cmdline_ip_slirp = "ip=dhcp" + self.cmdline_ip_tap = "ip=192.168.7.@CLIENT@::192.168.7.@GATEWAY@:255.255.255.0" # Use different mac section for tap and slirp to avoid # conflicts, e.g., when one is running with tap, the other is # running with slirp. @@ -1032,7 +1034,9 @@ class BaseConfig(object): if self.fstype == 'nfs': self.setup_nfs() - self.kernel_cmdline_script += ' ip=dhcp' + netconf = " " + self.cmdline_ip_slirp + logger.info("Network configuration:%s", netconf) + self.kernel_cmdline_script += netconf # Port mapping hostfwd = ",hostfwd=tcp::2222-:22,hostfwd=tcp::2323-:23" qb_slirp_opt_default = "-netdev user,id=net0%s,tftp=%s" % (hostfwd, self.get('DEPLOY_DIR_IMAGE')) @@ -1147,9 +1151,11 @@ class BaseConfig(object): client = gateway + 1 if self.fstype == 'nfs': self.setup_nfs() - netconf = "192.168.7.%s::192.168.7.%s:255.255.255.0" % (client, gateway) - logger.info("Network configuration: %s", netconf) - self.kernel_cmdline_script += " ip=%s" % netconf + netconf = " " + self.cmdline_ip_tap + netconf = netconf.replace('@CLIENT@', str(client)) + netconf = netconf.replace('@GATEWAY@', str(gateway)) + logger.info("Network configuration:%s", netconf) + self.kernel_cmdline_script += netconf mac = "%s%02x" % (self.mac_tap, client) qb_tap_opt = self.get('QB_TAP_OPT') if qb_tap_opt: @@ -1171,8 +1177,10 @@ class BaseConfig(object): if self.net_bridge: self.setup_net_bridge() elif self.slirp_enabled: + self.cmdline_ip_slirp = self.get('QB_CMDLINE_IP_SLIRP') or self.cmdline_ip_slirp self.setup_slirp() else: + self.cmdline_ip_tap = self.get('QB_CMDLINE_IP_TAP') or self.cmdline_ip_tap self.setup_tap() def setup_rootfs(self): -- cgit v1.2.3-54-g00ecf