Changes between Version 60 and Version 61 of Developer/Simulators/QEMU


Ignore:
Timestamp:
03/10/15 23:40:01 (9 years ago)
Author:
Chris Johns
Comment:

Moved and updated.

Legend:

Unmodified
Added
Removed
Modified
  • Developer/Simulators/QEMU

    v60 v61  
    11= QEMU =
    22
    3 
    4 
    5 [[TOC(TBR/UserManual/QEMU, depth=2)]]
     3[[TOC(Developer/Simulators/QEMU, depth=2)]]
    64
    75You can run RTEMS in the open source processor emulator [http://www.nongnu.org/qemu/ QEMU]. The QEMU emulator runs on a number of hosts including Linux and Windows. It also supports a number of [http://www.nongnu.org/qemu/status.html processors].
     
    97= QEMU On Windows =
    108
    11 
    12 Install the RTEMS [wiki:TBR/UserManual/MinGW_Tools_for_Windows MinGW Tools for Windows]. Download the processor emulator you wish to use and install. For example we will install the i368 emulator to '''c:\rtems\i386\qemu-0.8.2-windows'''. Download the boot floppy image http://www.rtems.org/ftp/pub/rtems/qemu/i386-pc/rtems-boot.img to '''c:\rtems\i386'''. To run QEMU create the batch file '''c:\rtems\i386\qemu.bat''' with:
    13 
    14  rem @echo off
    15  set QEMU=C:\rtems\i386\qemu-0.8.2-windows
    16  %QEMU%\qemu -L %QEMU% -m 128 -boot a -fda c:\rtems\i386\rtems-boot.img -hda fat:%1
    17 
    18 You can download this batch file from http://www.rtems.org/ftp/pub/rtems/qemu/i386-pc/qemu.bat.
     9Install the RTEMS [wiki:TBR/UserManual/MinGW_Tools_for_Windows MinGW Tools for Windows]. Download the processor emulator you wish to use and install. For example we will install the i368 emulator to '''c:\rtems\i386\qemu-0.8.2-windows'''. Download the boot floppy image https://ftp.rtems.org/pub/rtems/qemu/i386-pc/rtems-boot.img to '''c:\rtems\i386'''. To run QEMU create the batch file '''c:\rtems\i386\qemu.bat''' with:
     10
     11{{{
     12rem @echo off
     13set QEMU=C:\rtems\i386\qemu-0.8.2-windows
     14%QEMU%\qemu -L %QEMU% -m 128 -boot a -fda c:\rtems\i386\rtems-boot.img -hda fat:%1
     15}}}
     16
     17You can download this batch file from https://ftp.rtems.org/pub/rtems/qemu/i386-pc/qemu.bat.
    1918
    2019The boot floppy will look in the root directory the QEMU C: drive for a file called '''rtems-grub.cfg'''. The QEMU C: is a directory on your hard disk passed to QEMU on its command line and can be seen in the '''qemu.bat''' file we created as the '''-hda fat:%1''' option. The command line option we pass to '''qemu.bat''' is a directory that is the root directory the QEMU C: drive. For example download and build RTEMS for the i386 target as described on the [wiki:TBR/UserManual/MinGW_Tools_for_Windows MinGW Tools for Windows] page. Then install http://www.rtems.org/ftp/pub/rtems/qemu/i386-pc/rtems-grub.cfg into the '''c:\rtems\src\i386\i386-rtems4.7\c\pc586\testsuites\samples''' directory. Open the '''RTEMS (i386)''' command window by running '''c:\rtems\i386\rtems-cmd.bat''' then enter:
    2120
    22  RTEMS(i386) C:\rtems\i386>qemu c:\rtems\src\i386\i386-rtems4.7\c\pc586\testsuites\samples
     21{{{
     22RTEMS(i386) C:\rtems\i386>qemu c:\rtems\src\i386\i386-rtems4.7\c\pc586\testsuites\samples
     23}}}
    2324
    2425The QEMU windows will open and GRUB will provide you with a menu of the RTEMS sample applications. Select an application and watch it run.
     26
    2527= QEMU PC (i386) Emulator =
    2628
    2729
    2830The RTEMS PC BSP runs in the QEMU emulator (it also runs in the [wiki:RTEMS_on_Virtualbox_  VirtualBox emulator]). The QEMU emulator needs a boot image that will load RTEMS and we use GRUB for this. The simplest may to do this is to create a floppy disk image and tell QEMU to boot from a floppy disk.
     31
    2932= Making a Boot Floppy Disk =
    3033
    3134
    32 We run RTEMS in QEMU by first booting from a floppy disk image containing the GRUB boot loader. You can use the [http://www.rtems.org/ftp/pub/rtems/people/chrisj/grub/rtems-boot.img image] we have made by downloading it from the RTEMS ftp server. The script builds the floppy disk, the grub source as per GPL, and the boot image.
     35We run RTEMS in QEMU by first booting from a floppy disk image containing the GRUB boot loader. You can use the [https://ftp.rtems.org/pub/rtems/people/chrisj/grub/rtems-boot.img image] we have made by downloading it from the RTEMS ftp server. The script builds the floppy disk, the grub source as per GPL, and the boot image.
    3336
    3437Instructions on how to built the image and were run on a Fedora Core 5 Linux host can be found at [http://www.rtems.org/wiki/index.php/Building_Grub http://www.rtems.org/wiki/index.php/Building_Grub]
    3538
    3639Now we need to setup some disk drivers for Qemu:
    37 {{{$ dd if=/dev/zero of=hda.img count=1000
    38 $ ls -las hda.img
     40
     41{{{
     42 $ dd if=/dev/zero of=hda.img count=1000
     43 $ ls -las hda.img
    3944}}}
    4045
    4146The first creates a disk and second shows you the details of the disk you just created.
    4247
    43 The default '''grub.cfg''' file will attempt to read a GRUB configuration file called '''[http://www.rtems.org/ftp/pub/rtems/qemu/i386-pc/rtems-grub.cfg rtems-grub.cfg]''' from the root directory of the harddisk. This lets you create a specific GRUB configuration for you testing without needing to rebuild the floppy image.
     48The default '''grub.cfg''' file will attempt to read a GRUB configuration file called '''[https://ftp.rtems.org/pub/rtems/qemu/i386-pc/rtems-grub.cfg rtems-grub.cfg]''' from the root directory of the hard-disk. This lets you create a specific GRUB configuration for you testing without needing to rebuild the floppy image.
    4449An example configuration that lets you run the RTEMS Samples is:
    4550
    46 {{{# RTEMS Grub configuration for the Samples
     51{{{
     52# RTEMS Grub configuration for the Samples
    4753
    4854set default=0
    49 
     55 
    5056menuentry "RTEMS - Hello" {
    5157 set root=(hd1,1)
     
    123129List of the options explained:
    124130
    125  '''-m 128''' sets the memory size to 128M
    126  '''-boot a''' boot from the floppy disk a (best option)
    127  '''-fda <path to rtems-boot.img>''' defines the second best floppy disk image
    128  '''-hda <path to hda.img>''' defines the first hard disk image
    129  '''-hdb fat:.''' says hdb is fat disk and . is the directory to make the root of that disk and
    130      '''-hdb''' is the mapping to the local disk so we can read the RTEMS executable into memory
    131  '''-serial stdio''' directs the serial port to the stdio of qemu
    132  '''-no-reboot''' tells Qemu to not reboot if the code running wants to.
    133             Stops an error looping over and over.
    134  '''-s''' tells Qemu to start a GDB server
    135 = "Couldn't open file" =
    136 
     131 -m 128::
     132    sets the memory size to 128M
     133 -boot a::
     134    boot from the floppy disk a (best option)
     135 -fda <path to rtems-boot.img>::
     136    defines the second best floppy disk image
     137 -hda <path to hda.img>::
     138    defines the first hard disk image
     139  -hdb fat::
     140   says hdb is fat disk and . is the directory to make the root of that disk and
     141   '''-hdb''' is the mapping to the local disk so we can read the RTEMS executable into memory
     142 -serial stdio::
     143   directs the serial port to the stdio of qemu
     144 -no-reboot'::
     145   tells Qemu to not reboot if the code running wants to. Stops an error looping over and over.
     146 -s::
     147  tells Qemu to start a GDB server
     148
     149= "Couldn't open file" GRUB Error Message =
    137150
    138151If GRUB gives this error while trying to load a menu entry, press 'c' on the keyboard at the GRUB menu screen to open the GRUB command prompt.
     
    140153Then type:
    141154
    142   grub> ls
     155{{{
     156grub> ls
     157}}}
    143158
    144159which should give you a list of the devices currently on the system.
     
    146161Try the following for every device until you find the application you want:
    147162
    148   grub> ls DEVICE/
     163{{{
     164grub> ls DEVICE/
     165}}}
    149166
    150167Now edit the entry that gave you the error (press 'e' at the GRUB menu screen) and correct the path.
     168
    151169= Running Other Images =
    152 
    153170
    154171Instead of adding menu entries to the rtems-grub.cfg file, you can instead boot an RTEMS image directly from the GRUB command prompt.
     
    157174the keyboard to switch from the menu to the GRUB command prompt.  At the prompt type:
    158175
    159   grub> set root=(hd1,1)/
    160   grub> multiboot (hd1,1)/myimage.exe
     176{{{
     177grub> set root=(hd1,1)/
     178grub> multiboot (hd1,1)/myimage.exe
     179}}}
    161180
    162181where myimage.exe should be replaced with the name of the RTEMS image that you want to run.
     
    166185Then just type
    167186
    168   grub> boot
     187{{{
     188grub> boot
     189}}}
    169190
    170191to load and run your image.
     192
    171193= Using the rtems-testing Module =
    172194
     
    180202
    181203Create two directories, ~/qemu and ~/qemu/hd.
    182   mkdir ~/qemu
    183   mkdir ~/qemu/hd
     204{{{
     205mkdir ~/qemu
     206mkdir ~/qemu/hd
     207}}}
    184208
    185209There is a qemu-support directory in rtems-testing with a boot floppy image. Copy rtems-testing/qemu-support/pc386_fda.bz2 to ~/qemu. 
    186   cp ./qemu-support/pc386_fda.bz2 ~/qemu
     210
     211{{{
     212cp ./qemu-support/pc386_fda.bz2 ~/qemu
     213}}}
    187214
    188215Unzip (bunzip or bzip2) pc386_fda.bz2.
    189   bunzip ~/qemu/pc386_fda*
     216
     217{{{
     218bunzip ~/qemu/pc386_fda*
     219}}}
    190220
    191221Run make at the root of the rtems-testing module.  This should create a pc386 script in ./sim-scripts.
     
    193223To use these scripts for pc386, you have to build RTEMS with USE_COM1_AS_CONSOLE=1 and BSP_PRESS_KEY_FOR_RESET=0 on the configure command line.
    194224For example, if rtems is checked out at /home/user/rtems/rtems and you build in /home/user/rtems/b-rtems, then from b-rtems you will configure rtems as:
     225
    195226{{{
    196227../rtems/configure --target=i386-rtems4.10 \
     
    205236}}}
    206237
    207 If you run
    208   ./sim-script/pc386 -i PATH_TO_MY_EXE
     238If you run:
     239{{{
     240./sim-script/pc386 -i PATH_TO_MY_EXE
     241}}}
     242
    209243The pc386 script will copy your executable to ~/qemu/hd/test.exe, which is what pc386_fda boots. You should see the result in your console.  Scripts to run other simulators are in the sim-scripts directory.
    210244
     
    215249= Booting an RTEMS executable directly with qemu  =
    216250
    217 
    218251Qemu has a native multiboot implementation that is smart enough to load an ELF .exe into memory and transfer control to it. This makes it unnecessary to prepare a full floppy or harddisk image complete with MBR and boot loader. To use it, provide the -kernel option:
    219252
     
    221254qemu-system-i386 -kernel hello/hello.exe
    222255}}}
     256
    223257= Running RTEMS TCP/IP Applications =
    224 
    225258
    226259You can run RTEMS applications that use TCP/IP on QEMU.  It requires getting a few very picky things just right so hang on and this section should help.  The RTEMS application running on QEMU is executing on a virtual machine and thus QEMU must provide a simulation of a real NIC whose I/O is relayed or tunneled through a virtual interface to the real world.  For most testing purposes, it is sufficient to have the connection work between just your QEMU session and the host computer running QEMU.  AFAIK, for this to work, you must execute qemu as root.  In all other cases of running QEMU with RTEMS, you can be a regular user.  So the lesson here is only turn on TCP/IP support in QEMU when you really need it.
     
    253286
    254287This matches the defaults as presented in the QEMU manual. The single network interface available to the RTEMS application will have the IP address 10.0.2.5.  All of the RTEMS network demos can run in this environment given proper configuration.
     288
    255289== "isa irq 9 already assigned" ==
    256290
    257 
    258291With a more recent QEMU (0.13), I needed to add the "-M isapc" flag to make this error message go away.
    259292
    260293--[wiki:User:SimonPerreault User:SimonPerreault] Mon Nov 29 16:43:38 EST 2010
     294
    261295== Setting the IRQ number ==
    262296
     
    291325--ne2k-irq=9
    292326}}}
     327
    293328to the grub command line to let RTEMS' ne driver know it should use interrupt 9.
     329
    294330= Running CAN Applications =
    295331
    296332See the [wiki:TBR/UserManual/QEMU_with_CAN_Emulation QEMU with CAN Emulation] page for more details.
     333
    297334= Debugging with QEMU =
    298335
    299 
    300336You can connect a debugger to QEMU and debug your application. If you start QEMU and load your application then switch consoles by pressing Ctl-Alt-2 to the QEMU command console then enter the command ''gdbserver''. After this start '''gdb''' for your target with the ELF image for the execute. Once gdb has started enter the remote target command for ''localhost:1234''. On Windows with and the i386 target the commands are:
    301337
     338{{{
    302339 RTEMS(i386) C:\rtems\src\i386\i386-rtems4.7\c\pc586\testsuites\samples\capture>i386-rtems4.7-gdb capture.elf
    303340 GNU gdb 6.5
     
    325362 117             addl    $4, esp
    326363 (gdb)
     364}}}
    327365
    328366Do not forget to build RTEMS with the ''--enable-rtems-debug'' configure option to get debug information built into RTEMS.
     
    330368=  QEMU and USB  =
    331369
    332 
    333370As of 10 March 2007, RTEMS does not support USB.  One of the issues in RTEMS supporting USB is finding a target BSP where it is easy to debug the USB stack initially.  QEMU appears to be a viable candidate for this task. QEMU is supposed to support USB emulation and there are reports on the Internet that it does work.  My experimentation was not so lucky.
    334371
    335372Since my effort was all about making sure I knew how to setup and use QEMU's emulated USB, I used a Knoppix LiveCD image.  I thought that if I could get Knoppix to access a USB mouse and a USB flash drive, I would be happy in the capabilities in QEMU.
    336373
    337 The USB mouse emulation worked well enough that Knoppix recognized it automatically and it worked.
    338 
    339 I could never figure out a way to get the USB flash drive recognized.  There are comments that there might be a patch needed but I wasn't very confident.
     374The USB mouse emulation worked well enough that Knoppix recognised it automatically and it worked.
     375
     376I could never figure out a way to get the USB flash drive recognised.  There are comments that there might be a patch needed but I wasn't very confident.
    340377
    341378I saw a report that someone got a USB GPS working with Windows XP running under QEMU (http://jw.n--tree.net/blog/dev/qemu-usb-garmin) so there must be a magic combination of things that actually make this work
    342379
    343 
    344380So that's my report. Maybe someone can follow up and make more work.
    345381
    346382--[wiki:User:JoelSherrill Dr. Joel] 13:25, 10 March 2007 (CST)
     383
    347384=  Emulating Other Platforms with QEMU  =
    348 =  == PowerPC PReP Emulation ===
    349 
    350 See [wiki:TBR/BSP/Qemuprep qemuprep].
     385
     386=== PowerPC PReP Emulation ===
     387
     388See [wiki:Developer/Simulators/Qemu/Preparation].
     389
    351390=== Motorola Coldfire Emulation ===
    352391
    353392I have this also working but need to document.
     393
    354394--[[User:Strauman|Strauman]] 16:43, 18 July 2011 (CDT)
    355395=== LEON3 Emulation ===