···11+QEMU CAN bus emulation support
22+==============================
33+44+The CAN bus emulation provides mechanism to connect multiple
55+emulated CAN controller chips together by one or multiple CAN busses
66+(the controller device "canbus" parameter). The individual busses
77+can be connected to host system CAN API (at this time only Linux
88+SocketCAN is supported).
99+1010+The concept of busses is generic and different CAN controllers
1111+can be implemented for it but at this time only SJA1000 chip
1212+controller is implemented.
1313+1414+The PCI addon card hardware has been selected as the first CAN
1515+interface to implement because such device can be easily connected
1616+to systems with different CPU architectures (x86, PowerPC, ARM, etc.).
1717+1818+The project has been initially started in frame of RTEMS GSoC 2013
1919+slot by Jin Yang under our mentoring The initial idea was to provide generic
2020+CAN subsystem for RTEMS. But lack of common environment for code and RTEMS
2121+testing lead to goal change to provide environment which provides complete
2222+emulated environment for testing and RTEMS GSoC slot has been donated
2323+to work on CAN hardware emulation on QEMU.
2424+2525+Examples how to use CAN emulation
2626+=================================
2727+2828+When QEMU with CAN PCI support is compiled then one of the next
2929+CAN boards can be selected
3030+3131+ (1) CAN bus Kvaser PCI CAN-S (single SJA1000 channel) boad. QEMU startup options
3232+ -object can-bus,id=canbus0
3333+ -device kvaser_pci,canbus=canbus0
3434+ Add "can-host-socketcan" object to connect device to host system CAN bus
3535+ -object can-host-socketcan,id=canhost0,if=can0,canbus=canbus0
3636+3737+ (2) CAN bus PCM-3680I PCI (dual SJA1000 channel) emulation
3838+ -object can-bus,id=canbus0
3939+ -device pcm3680_pci,canbus0=canbus0,canbus1=canbus0
4040+4141+ another example:
4242+ -object can-bus,id=canbus0
4343+ -object can-bus,id=canbus1
4444+ -device pcm3680_pci,canbus0=canbus0,canbus1=canbus1
4545+4646+ (3) CAN bus MIOe-3680 PCI (dual SJA1000 channel) emulation
4747+ -device mioe3680_pci,canbus0=canbus0
4848+4949+5050+The ''kvaser_pci'' board/device model is compatible with and has been tested with
5151+''kvaser_pci'' driver included in mainline Linux kernel.
5252+The tested setup was Linux 4.9 kernel on the host and guest side.
5353+Example for qemu-system-x86_64:
5454+5555+ qemu-system-x86_64 -enable-kvm -kernel /boot/vmlinuz-4.9.0-4-amd64 \
5656+ -initrd ramdisk.cpio \
5757+ -virtfs local,path=shareddir,security_model=none,mount_tag=shareddir \
5858+ -object can-bus,id=canbus0 \
5959+ -object can-host-socketcan,id=canhost0,if=can0,canbus=canbus0 \
6060+ -device kvaser_pci,canbus=canbus0 \
6161+ -nographic -append "console=ttyS0"
6262+6363+Example for qemu-system-arm:
6464+6565+ qemu-system-arm -cpu arm1176 -m 256 -M versatilepb \
6666+ -kernel kernel-qemu-arm1176-versatilepb \
6767+ -hda rpi-wheezy-overlay \
6868+ -append "console=ttyAMA0 root=/dev/sda2 ro init=/sbin/init-overlay" \
6969+ -nographic \
7070+ -virtfs local,path=shareddir,security_model=none,mount_tag=shareddir \
7171+ -object can-bus,id=canbus0 \
7272+ -object can-host-socketcan,id=canhost0,if=can0,canbus=canbus0 \
7373+ -device kvaser_pci,canbus=canbus0,host=can0 \
7474+7575+The CAN interface of the host system has to be configured for proper
7676+bitrate and set up. Configuration is not propagated from emulated
7777+devices through bus to the physical host device. Example configuration
7878+for 1 Mbit/s
7979+8080+ ip link set can0 type can bitrate 1000000
8181+ ip link set can0 up
8282+8383+Virtual (host local only) can interface can be used on the host
8484+side instead of physical interface
8585+8686+ ip link add dev can0 type vcan
8787+8888+The CAN interface on the host side can be used to analyze CAN
8989+traffic with "candump" command which is included in "can-utils".
9090+9191+ candump can0
9292+9393+Links to other resources
9494+========================
9595+9696+ (1) Repository with development branch can-pci at Czech Technical University
9797+ https://gitlab.fel.cvut.cz/canbus/qemu-canbus
9898+ (2) GitHub repository with can-pci and our other changes included
9999+ https://gitlab.fel.cvut.cz/canbus/qemu-canbus
100100+ (3) RTEMS page describing project
101101+ https://devel.rtems.org/wiki/Developer/Simulators/QEMU/CANEmulation
102102+ (4) RTLWS 2015 article about the projevt and its use with CANopen emulation
103103+ http://rtime.felk.cvut.cz/publications/public/rtlws2015-qemu-can.pdf
104104+ Slides
105105+ http://rtime.felk.cvut.cz/publications/public/rtlws2015-qemu-can-slides.pdf
106106+ (5) Linux SocketCAN utilities
107107+ https://github.com/linux-can/can-utils/