Changes between Version 81 and Version 82 of Developer/Simulators/QEMU/CANEmulation


Ignore:
Timestamp:
Aug 11, 2014, 6:20:15 PM (5 years ago)
Author:
PavelPisa
Comment:

CAN PCI board support for QEMU v2.1

Legend:

Unmodified
Added
Removed
Modified
  • Developer/Simulators/QEMU/CANEmulation

    v81 v82  
    11= QEMU with CAN Emulation =
    22
    3 =  Introduction  =
    4 
    5 Actually this is a project of GSoC2013. At first I tried to port a CAN driver LinCAN to RTEMS.
    6 But we don't have a common hardware platform to test the driver, so how to test the driver become the most significant problem here.
    7 Finally, we decide to build a software environment to test the driver.
    8 This environment is built using the open source machine emulator QEMU and SJA1000 is simulated to test the driver.
    9 For the sake of simplicity, we test it in Linux(as it's familiar) and use SocketCAN(as it's mainlined into Linux) as a driver.
    10 
    11 Also, we decide to use a PCI CAN controller and simulate on x86 Linux platform.
    12 Since, PCI as a general standard is easy to extend and pci devices can be separate from others.
    13 Then this PCI device can be used with x86, so QEMU (with KVM) would be much faster and use less resources than other platform such as ARM.
    14 
    15 =  Environment  =
    16 
    17 The CAN simulation environment is based on QEMU-1.4.2, because 1.5.0 was just released, and we wanted a solid starting point.
    18 The OS will be Linux and the current CAN driver tested will be Socket CAN (as it's mainlined into Linux)
    19  *  Host: The host is Ubuntu-13.04 including the basic building tools and some other software.
     3=  Introduction to CAN QEMU support  =
     4
     5The intention to provide generic CAN subsystem for RTEMS was initial idea for Jin Yang GSoC 2013 project. But lack
     6of common environment for code and RTEMS testing lead to goal change to provide environment which provides
     7complete emulated environment for testing and RTEMS GSoC slot has been donated to work on CAN hardware
     8emulation on QEMU.
     9
     10The PCI addon card hardware has been selected as the first CAN interface to implement because
     11such device can be easily connected to systems with different CPU architectures (x86, PowerPC, ARM, etc.).
     12We decided to focus on SJA1000 chip, because it is spread standalone controller variant. As for the
     13concrete card we have selected Kvaser PCI which we (mentors from [http://www.cvut.cz/ Czech Technical University][http://dce.fel.cvut.cz/en/department/organizational-structure/industrial-informatics-group IIG group]) because we have more these cards in
     14our project and can compare emulated HW behavior with real hardware. We selected interfacing
     15to SocketCAN (Linux kernel standard CAN API/drivers) on QEMU host side to connect emulated controler
     16CAN bus to virtual CAN network, monitoring tools or to real CAN hardware bus.
     17=  CAN QEMU Sources and Testing  =
     18
     19
     20The sources of QEMU with CAN PCI board and SocketCAN interfacing can be found in branch "[https://github.com/CTU-IIG/qemu/tree/can-pci can-pci]"
     21[http://dce.fel.cvut.cz/en/department/organizational-structure/industrial-informatics-group IIG group]
     22QEMU repository at github [https://github.com/CTU-IIG/qemu]. Actual version is based on QEMU v2.1.
     23
     24When QEMU with CAN PCI support is compiled then next two CAN boards can be selected
     25
     26 *  simple PCI memory space mapped SJA1000 which maps directly into first BAR of emulated device. QEMU startup options
     27
     28  -device pci_can,chardev=canbus0,model=SJA1000
     29
     30 *  CAN bus Kvaser PCI CAN-S (single SJA1000 channel) boad. QEMU startup options
     31
     32  -device kvaser_pci,canbus=canbus0,host=vcan0
     33
     34The ''kvaser_pci'' board/device model is compatible with and has been tested with ''kvaser_pci'' driver included
     35in mainline Linux kernel for 3 years already. The tested setup was Linux 3.12 kernel on the host and guest
     36side.
     37
     38Next parameters has been used for qemu-system-x86_64
     39
     40   qemu-system-x86_64 -enable-kvm -kernel /boot/vmlinuz-3.2.0-4-amd64 \
     41      -initrd ramdisk.cpio \
     42      -virtfs local,path=shareddir,security_model=none,mount_tag=shareddir \
     43      -vga cirrus \
     44      -device kvaser_pci,canbus=canbus0,host=can0 \
     45      -nographic -append "console=ttyS0"
     46
     47The list of parameters for qemu-system-arm
     48
     49  qemu-system-arm -cpu arm1176 -m 256 -M versatilepb \
     50      -kernel kernel-qemu-arm1176-versatilepb \
     51      -hda rpi-wheezy-overlay \
     52      -append "console=ttyAMA0 root=/dev/sda2 ro init=/sbin/init-overlay" \
     53      -nographic \
     54      -virtfs local,path=shareddir,security_model=none,mount_tag=shareddir \
     55      -device kvaser_pci,canbus=canbus0,host=can0 \
     56=  The previous CAN for QEMU versions  =
     57
     58The Jin Yang initial effort has targeted stable version QEMU-1.4.2 and Linux with mainline provided SocketCAN
     59has been used on host side.
     60 *  Host: The host was Ubuntu-13.04 including the basic building tools and some other software.
    2061 *  Guest: This is also a Linux environment which we build from scratch. The Linux kernel is [https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.4.48.tar.bz2 Linux-3.4.48], the commands are statically compiled using [http://www.busybox.net/downloads/busybox-1.21.0.tar.bz2 Busybox-1.21.0] and also some other files including configure files, start scripts, etc.
    2162 *  Others: [http://wiki.qemu-project.org/download/qemu-1.4.2.tar.bz2 Qemu-1.4.2]
    2263
    23 '''Updated version for QEMU-2.x available'''
    24 
    25  *  Updated version patches at qemu-devel list archive [http://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg01861.html]
    26 =  Use Cases / Testing  =
    2764The best option is to implement that as simple device
    2865  -chardev can,id=sja1000,port=vcan0
     
    3572 *  '''-device pci-can,chardev=sja1000,model=SJA1000''' we use pci-can device. ''chardev'' the value '''MUST''' equal to the id specified in chardev option; ''model'' is an optional parameter, default value is SJA1000 and we only support SJA1000 now.
    3673
    37 '''Options for updated QEMU-2.x experimental version'''
    38 
    39   -device pci_can,chardev=canbus0,model=SJA1000
    40 
    41 or
    42 
    43   -device kvaser_pci,canbus=canbus0,host=vcan0
    44 
    45 The ''kvaser_pci'' board/device model is compatible with ''kvaser_pci'' driver included in mainline Linux kernel for 3 years already.
    46 =  Step 1: Building a Minimal Linux Environment in Qemu  =
    47 
    48 The purpose of starting with a minimal Linux (as opposed to RTEMS) environment in qemu is the software configurations have been more thoroughly tested and documented.
    49 The first phase of the project should start out using the last stable release... unless it's minor digit is a 0... usually the minor digit being anything above a 0 means the free and open source software FOSS had some bug-fix releases.
     74The QEMU CAN infrastructure has been rewritten and SJA1000 code updated to QEMU 2.0 version
     75
     76 *  Updated version patches at qemu-devel list archive [http://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg01861.html]
    5077=  Installing Qemu  =
    5178