Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

Changes between Version 73 and Version 74 of Developer/Simulators/QEMU/CANEmulation


Ignore:
Timestamp:
09/15/13 11:54:58 (11 years ago)
Author:
Jinyang
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Developer/Simulators/QEMU/CANEmulation

    v73 v74  
    99=  Environment  =
    1010
    11 The OS will be Linux and the current CAN driver to test will be Socket CAN (as it's maintlined into Linux)
     11The 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)
    1212 *  Host: The host is Ubuntu-13.04 including the basic building tools and some other softwares.
    1313 *  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.
     
    2929
    3030The 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.
    3431=  Installing Qemu  =
    3532
     
    4340First, 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.
    4441
    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.
    4643
    4744  ./configure --prefix=/opt/qemu --target-list="i386-softmmu" --enable-sdl && make && sudo make install
     
    5148 *  --enable-sdl: we also need the sdl (Simple DirectMedia Layer) support.
    5249
    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.
     50To 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''
    5451=  Building Linux Environment  =
    5552==  Building the Kernel  ==
     
    5956In 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.
    6057
    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
     58The 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
    6966   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
     69Then, the modules has installed to ''temp'' directory, so you can copy them to the necessary directory if need.
     70
     71In the 'make menuconfig' step we will chose the following options
     72
     73 - General setup                               # for convenience
    7774  - (-QEMU) Local version - append to kernel release
    7875 
    79  - Enable loadable module support
     76 - Enable loadable module support              # support for the modules
    8077  - Forced module loading
    8178  - Module unloading
    8279 
    83  - Bus options (PCI etc.)
     80 - Bus options (PCI etc.)                      # a PCI device developed here, so we need the kernel supports
    8481  - PCI support
    8582    - PCI Express support
    8683      - Root Port Advanced Error Reporting support
    8784 
    88  - Executable file formats / Emulations
     85 - Executable file formats / Emulations        # to run examples
    8986   - Kernel support for ELF binaries
    9087 
    91  - Networking support
     88 - Networking support                          # we using NFS, maybe some of the options don't need
    9289   - Networking options
    9390    - Packet socket
     
    110107      - TCP: advanced congestion control
    111108       - CUBIC TCP
    112   - <M> CAN bus subsystem support
     109   
     110  - <M> CAN bus subsystem support               # actually we build a new CAN driver, not necessary
    113111    - <M> Raw CAN Protocol (raw access with CAN-ID filtering)
    114112    - <M> Broadcast Manager CAN Protocol (with contest filtering)
     
    123121 - Device Drivers
    124122  - Character devices
    125     - Serial drivers
     123    - Serial drivers                            # for serial test
    126124      - <M> 8250/16550 and compatible serial support
    127   - Network device support
     125  - Network device support                      # for NFS
    128126    - Network core driver support
    129127    - Universal TUN/TAP device driver support
     
    149147   cd busybox-1.20.0
    150148   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''
    152150   make
    153151   make install CONFIG_PREFIX=~/qemu/rootfs # choose this hard coded value for simplicity when writing scripts
     152
     153We 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
    154155==  Set up network environment  ==
    155156
    156157We 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.
    157160
    158161 #!/bin/sh
     
    173176   -net tap,vlan=0,ifname=tap0,script=~/qemu/ifup-qemu
    174177
     178If 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''
    175179
    176180=  Step 2: Introduce SocketCAN and SJA1000  =
    177181
    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.
     182We 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.
    179183=  SocketCAN  =
    180184
    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.
     185The 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
     187Simplely, we only need to insert the vcan module and use virtual socketcan device to test the socketcan. Following is what we need to do.
    184188  $ sudo insmod /lib/modules/`uname -r`/kernel/drivers/net/can/vcan.ko
    185189  $ sudo ip link add type vcan
     
    193197The 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].
    194198
    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.
     199SJA1000 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.
    196200
    197201