Changes between Version 65 and Version 66 of Developer/Simulators/QEMU

Sep 24, 2016, 10:15:56 PM (3 years ago)
Pavel Pisa

Document QEMU setup with PCI NIC networking


  • Developer/Simulators/QEMU

    v65 v66  
    250 = Booting an RTEMS executable directly with qemu  =
     251= Booting an RTEMS executable directly with QEMU  =
    252253Qemu has a native multiboot implementation that is smart enough to load an ELF .exe into memory and transfer control to it. This makes it unnecessary to prepare a full floppy or harddisk image complete with MBR and boot loader. To use it, provide the -kernel option:
    268269= Running RTEMS TCP/IP Applications =
     271== Intel i82557b/e100 PCI Card Emulation ==
     273The following setup has been tested on actual master (future 4.12) branch
     274with i386 BSP on Linux host. But PCI driver should work with other architectures
     275as well if given BSP supports PCI and is supported by QEMU.
     277The Intel i82557b/e100 PCI NIC is supported by RTEMS [ FXP driver]. The driver is available in classic RTEMS integrated TCP/IP stack
     278when RTEMS build is configured with --enable-networking.
     280Example of selecting the driver in RTEMS application:
     283#include <rtems/rtems_bsdnet.h>
     284#include <rtems/rtems_dhcp_failsafe.h>
     285#include <bsp.h>
     287int rtems_fxp_attach(struct rtems_bsdnet_ifconfig *config, int attaching);
     289static char ethernet_address[6] = {0x00, 0x04, 0x9F, 0x00, 0x27, 0x50 };
     291static struct rtems_bsdnet_ifconfig netdriver_config = {
     292        .name = "fxp1" /*RTEMS_BSP_NETWORK_DRIVER_NAME*/,
     293        .attach = rtems_fxp_attach /*RTEMS_BSP_NETWORK_DRIVER_ATTACH*/,
     294        .next = NULL,
     295        .ip_address = "",
     296        .ip_netmask = "",
     297        .hardware_address = ethernet_address
     298        /* more options can follow */
     301struct rtems_bsdnet_config rtems_bsdnet_config = {
     302        .ifconfig = &netdriver_config,
     303        .bootp = rtems_bsdnet_do_dhcp_failsafe, /* fill if DHCP is used*/
     307Call to rtems_bsdnet_initialize_network() starts networking.
     309The most simple interconnection of emulated NIC to the host system networking
     310is by `user` option. This setup result in the full NAT or better say protocol
     311translation run by QEMU and does not require any elevated privileges
     312for QEMU process on the host system. It has disadvantage that it
     313is able only to repack TCP and UDP traffic to the host system network
     314(no ICMP/ping works). Because of NAT like style this allows only to
     315access/start connection from RTEMS to the outside world. It is not
     316possible to connect server on RTEMS from the host system.
     317The client (RTEMS application) is offered address and gateway
     318address is
     320Example of running QEMU with above described setup
     323qemu-system-x86_64 -enable-kvm -kernel $APP_BINARY \
     324      -vga cirrus \
     325      -net nic,vlan=1,macaddr=00:04:9F:00:27:50,model=i82557b \
     326      -net user,vlan=1  \
     327      -append "--console=/dev/com1" \
     328      -serial stdio
     331Substitute `$APP_BINARY` by your compiled RTEMS application image
     332(ELF 32-bit LSB executable). Setup select serial console for RTEMS
     333application and QEMU routes RTEMS serial to standard output.
     335If you do not intend to work with graphic at all then use
     338qemu-system-x86_64 -enable-kvm -kernel $APP_BINARY \
     339      -vga cirrus \
     340      -append "--console=/dev/com1" \
     341      -net nic,vlan=1,macaddr=be:be:be:10:00:01,model=i82557b \
     342      -net tap,ifname=tap1,vlan=1,script=no,downscript=no  \
     343      -nographic
     346The next example shows how to build isolates local network
     347to communicate between the host system and RTEMS application
     348on Linux. The example is intended for static address setup
     349without DNS etc. But it is ideal for drivers testing
     350and or server/protocol code testing.
     352Setup TAP device on host side with administrator privileges (run as root).
     353Select local address range which does not overlap with any network in your
     357  ip tuntap add tap1 mode tap user user_running_qemu
     358  ip link set tap1 up
     359  ip addr add dev tap1
     362Then QEMU can be run
     365qemu-system-x86_64 -enable-kvm -kernel $APP_BINARY \
     366      -vga cirrus \
     367      -net nic,vlan=1,macaddr=00:04:9F:00:27:50,model=i82557b \
     368      -net tap,ifname=tap1,vlan=1,script=no,downscript=no  \
     369      -append "--console=/dev/com1" \
     370      -serial stdio
     373and you can connect for example to RTEMS shell by
     379for example shown in OMK RTEMS
     380[ network application template].
     382== i386 with NE2000 ISA NIC Emulation ==
    270384You can run RTEMS applications that use TCP/IP on QEMU.  It requires getting a few very picky things just right so hang on and this section should help.  The RTEMS application running on QEMU is executing on a virtual machine and thus QEMU must provide a simulation of a real NIC whose I/O is relayed or tunneled through a virtual interface to the real world.  For most testing purposes, it is sufficient to have the connection work between just your QEMU session and the host computer running QEMU.  AFAIK, for this to work, you must execute qemu as root.  In all other cases of running QEMU with RTEMS, you can be a regular user.  So the lesson here is only turn on TCP/IP support in QEMU when you really need it.