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 | |
| 5 | The intention to provide generic CAN subsystem for RTEMS was initial idea for Jin Yang GSoC 2013 project. But lack |
| 6 | of common environment for code and RTEMS testing lead to goal change to provide environment which provides |
| 7 | complete emulated environment for testing and RTEMS GSoC slot has been donated to work on CAN hardware |
| 8 | emulation on QEMU. |
| 9 | |
| 10 | The PCI addon card hardware has been selected as the first CAN interface to implement because |
| 11 | such device can be easily connected to systems with different CPU architectures (x86, PowerPC, ARM, etc.). |
| 12 | We decided to focus on SJA1000 chip, because it is spread standalone controller variant. As for the |
| 13 | concrete 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 |
| 14 | our project and can compare emulated HW behavior with real hardware. We selected interfacing |
| 15 | to SocketCAN (Linux kernel standard CAN API/drivers) on QEMU host side to connect emulated controler |
| 16 | CAN bus to virtual CAN network, monitoring tools or to real CAN hardware bus. |
| 17 | = CAN QEMU Sources and Testing = |
| 18 | |
| 19 | |
| 20 | The 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] |
| 22 | QEMU repository at github [https://github.com/CTU-IIG/qemu]. Actual version is based on QEMU v2.1. |
| 23 | |
| 24 | When 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 | |
| 34 | The ''kvaser_pci'' board/device model is compatible with and has been tested with ''kvaser_pci'' driver included |
| 35 | in mainline Linux kernel for 3 years already. The tested setup was Linux 3.12 kernel on the host and guest |
| 36 | side. |
| 37 | |
| 38 | Next 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 | |
| 47 | The 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 | |
| 58 | The Jin Yang initial effort has targeted stable version QEMU-1.4.2 and Linux with mainline provided SocketCAN |
| 59 | has been used on host side. |
| 60 | * Host: The host was Ubuntu-13.04 including the basic building tools and some other software. |