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.
CAN Emulation Infrastructure
Generic part of QEMU CAN virtual CAN devices interconnection is implemented in file net/can/can_core.c
SJA1000 emulation code can be found in file hw/net/can/can_sja1000.c. Se the functions
The device state which are known to QEMU is registered field by filed in
Old version CAN QEMU Sources and Testing
The sources of QEMU with CAN PCI board and SocketCAN interfacing can be found in branch "can-pci" of this QEMU development fork repository. DCE FEE Czech Technical University in Prague. Actual version is based on QEMU v2.10.
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
CAN bus Kvaser PCI CAN-S (single SJA1000 channel) boad. QEMU startup options
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://gitlab.fel.cvut.cz/canbus/qemu-canbus
- RTEMS page describing project https://devel.rtems.org/wiki/Developer/Simulators/QEMU/CANEmulation