This page is no longer updated. Please refer to http://canbus.pages.fel.cvut.cz/ for more up-to-date information.
Introduction to CAN QEMU support
The PCI addon card hardware has been selected as the first CAN interface to implement because such device can be easily connected to systems with different CPU architectures (x86, PowerPC, ARM, etc.). We decided to focus on SJA1000 chip, because it is spread standalone controller variant. As for the concrete card we have selected Kvaser PCI because we have used more these cards in our project and can compare emulated HW behavior with real hardware. We selected interfacing to SocketCAN (Linux kernel standard CAN API/drivers) on QEMU host side to connect emulated controller CAN bus to virtual CAN network, monitoring tools or to real CAN hardware bus.
The project has been started in frame of RTEMS GSoC 2013 slot by Jin Yang under our mentoring The initial idea was to provide generic CAN subsystem for RTEMS. But lack of common environment for code and RTEMS testing lead to goal change to provide environment which provides complete emulated environment for testing and RTEMS GSoC slot has been donated to work on CAN hardware emulation on QEMU.
More details can be found in article presented on RTLWS 2015 (PDF), (Slides).
CAN QEMU Sources and Testing
The sources of QEMU with CAN PCI board and SocketCAN interfacing can be found in branch "can-pci" of the IIG group QEMU repository at github https://github.com/CTU-IIG/qemu. Actual version is based on QEMU v2.1.
When QEMU with CAN PCI support is compiled then next two CAN boards can be selected
simple PCI memory space mapped SJA1000 which maps directly into first BAR of emulated device. QEMU startup options
-device pci_can,chardev=canbus0,model=SJA1000
CAN bus Kvaser PCI CAN-S (single SJA1000 channel) boad. QEMU startup options
-device kvaser_pci,canbus=canbus0,host=vcan0
The ''kvaser_pci'' board/device model is compatible with and has been tested with ''kvaser_pci'' driver included in mainline Linux kernel for 3 years already. The tested setup was Linux 3.12 kernel on the host and guest side.
Next parameters has been used for qemu-system-x86_64
qemu-system-x86_64 -enable-kvm -kernel /boot/vmlinuz-3.2.0-4-amd64 \
-initrd ramdisk.cpio \
-virtfs local,path=shareddir,security_model=none,mount_tag=shareddir \
-vga cirrus \
-device kvaser_pci,canbus=canbus0,host=can0 \
-nographic -append "console=ttyS0"
The list of parameters for qemu-system-arm
qemu-system-arm -cpu arm1176 -m 256 -M versatilepb \
-kernel kernel-qemu-arm1176-versatilepb \
-hda rpi-wheezy-overlay \
-append "console=ttyAMA0 root=/dev/sda2 ro init=/sbin/init-overlay" \
-nographic \
-virtfs local,path=shareddir,security_model=none,mount_tag=shareddir \
-device kvaser_pci,canbus=canbus0,host=can0 \
Links to other resources
- GitHub repository with can-pci and our other changes included https://github.com/CTU-IIG/qemu/
- RTEMS page describing project https://devel.rtems.org/wiki/Developer/Simulators/QEMU/CANEmulation