- Timestamp:
-
09/15/13 11:54:58 (11 years ago)
- Author:
-
Jinyang
- Comment:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v73
|
v74
|
|
9 | 9 | = Environment = |
10 | 10 | |
11 | | The OS will be Linux and the current CAN driver to test will be Socket CAN (as it's maintlined into Linux) |
| 11 | 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. The OS will be Linux and the current CAN driver to test will be Socket CAN (as it's maintlined into Linux) |
12 | 12 | * Host: The host is Ubuntu-13.04 including the basic building tools and some other softwares. |
13 | 13 | * 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. |
… |
… |
|
29 | 29 | |
30 | 30 | 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. 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. |
31 | | = CAN project example = |
32 | | |
33 | | The section below is largely based upon http://jin-yang.github.io/2013/07/24/build-minimal-linux-environment.html by Jin-Yang during the summer of 2013. 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. |
34 | 31 | = Installing Qemu = |
35 | 32 | |
… |
… |
|
43 | 40 | First, we should configure QEMU using the following command, this will take about two minutes. QEMU has two modes to simulate a platform, the user mode and the system mode. We only need the i386 system simulation environment here, so only system mode (i386-softmmu) is needed. In order to save time, we just compile the source-code that relates to i386-softmmu. |
44 | 41 | |
45 | | '''Note:''' For simplicity of coding, we select the hard-coded --prefix=/opt/qemu so we can write scripts assuming that's where our installed qemu is. |
| 42 | '''NOTE:''' For simplicity of coding, we select the hard-coded --prefix=/opt/qemu so we can write scripts assuming that's where our installed qemu is. |
46 | 43 | |
47 | 44 | ./configure --prefix=/opt/qemu --target-list="i386-softmmu" --enable-sdl && make && sudo make install |
… |
… |
|
51 | 48 | * --enable-sdl: we also need the sdl (Simple DirectMedia Layer) support. |
52 | 49 | |
53 | | To call the just installed qemu you can add ''/opt/qemu/bin'' to the PATH environment variable or just use ''/opt/qemu/bin/qemu-system-i386'' to start QEMU. |
| 50 | To call the just installed qemu you can add ''/opt/qemu/bin'' to the PATH environment variable or just use ''/opt/qemu/bin/qemu-system-i386'' to start QEMU. Here, we just write a simple shell script and you can start the qemu just use command ''sudo ./qemu.sh'' |
54 | 51 | = Building Linux Environment = |
55 | 52 | == Building the Kernel == |
… |
… |
|
59 | 56 | In this section, the environment is based on [https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.4.48.tar.bz2 linux-3.4.48], [http://www.busybox.net/downloads/busybox-1.21.0.tar.bz2 busybox-1.21.0] and Ubuntu 13.04. You can get those source file from their official website. |
60 | 57 | |
61 | | The simplest way to compile a effective kernel is to generate a default one by typing ''make i386_defconfig; make bzImage''. However, this will waste a lot of time on compiling and running something which we do not need. So, we build a minimal kernel through the following commands. |
62 | | cd linux-3.4.48 |
63 | | make mrproper |
64 | | make allnoconfig |
65 | | make menuconfig # '''Note:''' Detailed instructions below |
66 | | make bzImage # make the kernel image |
67 | | make modules |
68 | | make modules_install INSTALL_MOD_PATH=temp |
| 58 | The simplest way to compile a effective kernel is to generate a default one by typing ''make i386_defconfig; make bzImage''. However, this will waste a lot of time on compiling and running something which we do not need yet. So, we will build a minimal kernel through the following commands. |
| 59 | cd linux-3.4.48 # change to the linux kernel directory |
| 60 | make mrproper # clean up the source code |
| 61 | make allnoconfig # disable all configure options |
| 62 | make menuconfig # '''NOTE:''' Detailed instructions below |
| 63 | make bzImage # compile the kernel image |
| 64 | make modules # compile the linux modules |
| 65 | make modules_install INSTALL_MOD_PATH=temp # install the linux modules to a temperary directory |
69 | 66 | find -name bzImage # find the kernel image |
70 | | cp ./arch/i386/boot/bzImage ~qemu/. # put in the working directory |
71 | | |
72 | | Then, the modules has installed to ''temp'' directory. |
73 | | |
74 | | In the 'make menuconfig' step we will chose |
75 | | |
76 | | - General setup |
| 67 | cp ./arch/i386/boot/bzImage ~qemu/. # copy it to the working directory |
| 68 | |
| 69 | Then, the modules has installed to ''temp'' directory, so you can copy them to the necessary directory if need. |
| 70 | |
| 71 | In the 'make menuconfig' step we will chose the following options |
| 72 | |
| 73 | - General setup # for convenience |
77 | 74 | - (-QEMU) Local version - append to kernel release |
78 | 75 | |
79 | | - Enable loadable module support |
| 76 | - Enable loadable module support # support for the modules |
80 | 77 | - Forced module loading |
81 | 78 | - Module unloading |
82 | 79 | |
83 | | - Bus options (PCI etc.) |
| 80 | - Bus options (PCI etc.) # a PCI device developed here, so we need the kernel supports |
84 | 81 | - PCI support |
85 | 82 | - PCI Express support |
86 | 83 | - Root Port Advanced Error Reporting support |
87 | 84 | |
88 | | - Executable file formats / Emulations |
| 85 | - Executable file formats / Emulations # to run examples |
89 | 86 | - Kernel support for ELF binaries |
90 | 87 | |
91 | | - Networking support |
| 88 | - Networking support # we using NFS, maybe some of the options don't need |
92 | 89 | - Networking options |
93 | 90 | - Packet socket |
… |
… |
|
110 | 107 | - TCP: advanced congestion control |
111 | 108 | - CUBIC TCP |
112 | | - <M> CAN bus subsystem support |
| 109 | |
| 110 | - <M> CAN bus subsystem support # actually we build a new CAN driver, not necessary |
113 | 111 | - <M> Raw CAN Protocol (raw access with CAN-ID filtering) |
114 | 112 | - <M> Broadcast Manager CAN Protocol (with contest filtering) |
… |
… |
|
123 | 121 | - Device Drivers |
124 | 122 | - Character devices |
125 | | - Serial drivers |
| 123 | - Serial drivers # for serial test |
126 | 124 | - <M> 8250/16550 and compatible serial support |
127 | | - Network device support |
| 125 | - Network device support # for NFS |
128 | 126 | - Network core driver support |
129 | 127 | - Universal TUN/TAP device driver support |
… |
… |
|
149 | 147 | cd busybox-1.20.0 |
150 | 148 | make defconfig |
151 | | make menuconfig # Note: ''Busybox Settings -> Build options -> Build Busybox as a static binary'' |
| 149 | make menuconfig # '''NOTE:''' ''Busybox Settings -> Build options -> Build Busybox as a static binary'' |
152 | 150 | make |
153 | 151 | make install CONFIG_PREFIX=~/qemu/rootfs # choose this hard coded value for simplicity when writing scripts |
| 152 | |
| 153 | We also need some necessary directories and some files to build the root file system. However, it's not the main part of the project, you can get more help from google. You can just get the from a public repository https://github.com/Jin-Yang/LINUX-QEMU.git |
| 154 | |
154 | 155 | == Set up network environment == |
155 | 156 | |
156 | 157 | We use TUN/TAP to connect host with qemu. We start by writing the '''ifup-qemu''' script. We will put it in the ''~/qemu'' directory so it will be in the correct place relative to the other files. |
| 158 | |
| 159 | '''NOTE:''' this need the root privilege. |
157 | 160 | |
158 | 161 | #!/bin/sh |
… |
… |
|
173 | 176 | -net tap,vlan=0,ifname=tap0,script=~/qemu/ifup-qemu |
174 | 177 | |
| 178 | If you have got a copy from https://github.com/Jin-Yang/LINUX-QEMU.git, then you can start the qemu just by command ''sudo ./qemu.sh'' |
175 | 179 | |
176 | 180 | = Step 2: Introduce SocketCAN and SJA1000 = |
177 | 181 | |
178 | | We have built a minimal linux environment now. Before we built the PCI-CAN device in QEMU, we will introduce the Linux driver SocketCAN and CAN device SJA1000. |
| 182 | We have built a minimal linux environment now. Before we built the PCI-CAN device in QEMU, we will introduce the Linux driver SocketCAN and CAN device SJA1000 at first. |
179 | 183 | = SocketCAN = |
180 | 184 | |
181 | | The SocketCAN package is an implementation of CAN protocols (Controller Area Network) for Linux. You can get a manual from the source of Linux Kernel at Documention/networking/can.txt . |
182 | | |
183 | | Simplely, we only need to insert the vcan module. Following is what we need to do. |
| 185 | The SocketCAN package is a Linux driver of CAN (Controller Area Network) protocols for Linux. You can get a manual from the source of Linux Kernel at Documention/networking/can.txt |
| 186 | |
| 187 | Simplely, we only need to insert the vcan module and use virtual socketcan device to test the socketcan. Following is what we need to do. |
184 | 188 | $ sudo insmod /lib/modules/`uname -r`/kernel/drivers/net/can/vcan.ko |
185 | 189 | $ sudo ip link add type vcan |
… |
… |
|
193 | 197 | The SJA1000, a stand-alone CAN controller, is produced by Philips Semiconductors which is more than a simple replacement of the PCA82C200. You can get more useful information from [http://www.nxp.com/documents/data_sheet/SJA1000.pdf SJA1000 Datasheet] and [http://www.mct.net/download/philips/can_appnote.pdf SJA1000 Application Note]. |
194 | 198 | |
195 | | SJA1000 is intended to replace the PCA82C200 because it is hardware and software compatible. It has two modes including BasicCAN mode and PeliCAN mode. |
| 199 | SJA1000 is intended to replace the PCA82C200 because it is hardware and software compatible. It has two modes including BasicCAN mode and PeliCAN mode, the details you can get from the above two documents. |
196 | 200 | |
197 | 201 | |