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


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

Document QEMU setup with PCI NIC networking

Legend:

Unmodified
Added
Removed
Modified
  • Developer/Simulators/QEMU

    v65 v66  
    248248--console=/dev/com1
    249249}}}
    250 = Booting an RTEMS executable directly with qemu  =
     250
     251= Booting an RTEMS executable directly with QEMU  =
    251252
    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:
     
    267268
    268269= Running RTEMS TCP/IP Applications =
     270
     271== Intel i82557b/e100 PCI Card Emulation ==
     272
     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.
     276
     277The Intel i82557b/e100 PCI NIC is supported by RTEMS [https://git.rtems.org/rtems/tree/c/src/libchip/network/if_fxp.c FXP driver]. The driver is available in classic RTEMS integrated TCP/IP stack
     278when RTEMS build is configured with --enable-networking.
     279
     280Example of selecting the driver in RTEMS application:
     281
     282{{{
     283#include <rtems/rtems_bsdnet.h>
     284#include <rtems/rtems_dhcp_failsafe.h>
     285#include <bsp.h>
     286
     287int rtems_fxp_attach(struct rtems_bsdnet_ifconfig *config, int attaching);
     288
     289static char ethernet_address[6] = {0x00, 0x04, 0x9F, 0x00, 0x27, 0x50 };
     290
     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 = "192.168.3.66",
     296        .ip_netmask = "255.255.255.0",
     297        .hardware_address = ethernet_address
     298        /* more options can follow */
     299};
     300
     301struct rtems_bsdnet_config rtems_bsdnet_config = {
     302        .ifconfig = &netdriver_config,
     303        .bootp = rtems_bsdnet_do_dhcp_failsafe, /* fill if DHCP is used*/
     304}
     305}}}
     306
     307Call to rtems_bsdnet_initialize_network() starts networking.
     308
     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 10.0.2.15 and gateway
     318address is 10.0.2.2.
     319
     320Example of running QEMU with above described setup
     321
     322{{{
     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
     329}}}
     330
     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.
     334
     335If you do not intend to work with graphic at all then use
     336
     337{{{
     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
     344}}}
     345
     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.
     351
     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
     354neighborhood.
     355
     356{{{
     357  ip tuntap add tap1 mode tap user user_running_qemu
     358  ip link set tap1 up
     359  ip addr add 192.168.3.1/24 dev tap1
     360}}}
     361
     362Then QEMU can be run
     363
     364{{{
     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
     371}}}
     372
     373and you can connect for example to RTEMS shell by
     374
     375{{{
     376telnet 192.168.3.66
     377}}}
     378
     379for example shown in OMK RTEMS
     380[http://rtime.felk.cvut.cz/gitweb/rtems-devel.git/tree/HEAD:/rtems-omk-template/appnet network application template].
     381
     382== i386 with NE2000 ISA NIC Emulation ==
    269383
    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.