wiki:Developer/VirtualMachines/VirtualBox

Version 17 (modified by Chris Johns, on Mar 15, 2015 at 9:48:25 PM) (diff)

Update TOC after rename.

RTEMS on Virtualbox

You can run RTEMS in the VirtualBox x86 emulator.

The main advantage of VirtualBox over other emulators is that it provides several board/controller emulation options, including a SATA controller and several network adapters.

Introduction

This page describes how to setup a “one click solution” for booting RTEMS in VirtualBox; if the RTEMS application gets updated, it is just a matter of rebooting the virtual machine to boot the new updated application.

A solution for debugging RTEMS remotely through VirtualBox serial port is also described. = What we will need? =

  • VirtualBox
  • Etherboot
  • Opentftp
  • Socat relay= Get Virtual Box =

The first step is to get and install VirtualBox.

You can get Virtual box from here; you can download the file suited for your Linux distribution or setup the VirtualBox repository.

The pre-requirements for this installation are:

  • Qt 4.4.0 or higher;
  • SDL 1.2.7 or higher (this graphics library is typically called libsdl or similar)
  • DKMS

They should be already installed, if not install them from your distro’s repository:

yum install qt
yum install SDL
yum install dkms

Assuming that you added the VirtualBox repository you only have to issue:

yum install VirtualBox

VirtualBox installations can become quite tricky because a kernel module needs to be installed, so please refer to the VirtualBox documentation if you have any problem.

Get opentftp

Opentftp is a tftp(Trivial File Transfer Protocol) server that will enable us to boot a file from the host computer(the RTEMS application) on the virtual machine.

You can get opentftp from here. The opentftp server comes already compiled, so you only need to run it. The README explains various options for the server, including how to run it as a linux service.

We need to change the directory that is mapped in the server to the directory where our rtems applications is( In my case /home/cdcs/testbed-build/). You can do this be opening the opentftp.ini file that stores the server options. In this file find the "[HOME]" marker and place there the path to your application. This is how my file looked:

[HOME]
#You should specify home directory(s) here
#The home directory can be specified
#in two different ways, with alias or 
#bare names without aliases. Using alias you
#can specify upto 8 directories like
#routers=c:/RouterImages/Images
#without aliases, only one directory can
#be specified, which will become root
#directory for tftp.
#mixup of bare names and aliases not allowed
#default will be home directory of user
/home/cdcs/testbed-build/

This option will map the root of the server to "/home/cdcs/testbed-build/". This means that when you access "tftp://127.0.0.1/test.exe" you are accessing "/home/cdcs/testbed-build/test.exe"; similarly "tftp://127.0.0.1/apps/test.exe" will access "/home/cdcs/testbed-build/apps/test.exe". You can also specify up to 8 aliases, eg: "myhome=/home/cdcs" will map "tftp://127.0.0.1/myhome/test.exe" to "/home/cdcs/test.exe".

You also need to change the "username=" option in "[TFTP-OPTIONS]" to your username. eg:"username=cdcs"

Once you have made these changes you are ready to run the server (you may need to use root privileges):

./opentftp -v -i opentftp.ini

This command should produce a similar output to the following one:

[root@cdcs opentftp]# ./opentftpd -v -i opentftpd.ini 
TFTP Server MultiThreaded Version 1.62 Unix Built 1621

starting TFTP...
username: cdcs
alias / is mapped to /home/cdcs/testbed-build/
permitted clients: all
server port range: all
max blksize: 65464
default blksize: 512
default timeout: 3
file read allowed: Yes
file create allowed: No
file overwrite allowed: No
thread pool size: 1
listening on: 0.0.0.0:69

Now that we have the tftp server up and running let's go to the next step...

Get the bootloader

Now we must get the bootloader that will fetch our application remotely and boot it. For this purpose we will use the etherboot bootloader.

A floppy image with the bootloader can be configured and obtained online. To do so you need to go here and select the most recent production release of gPXE.

This will lead to a configuration page with several bootloader options. For the time being just get sure that the first option(Choose an output format:) is in "Floppy bootable image" and press "Get Image".

The virtual machine

Now we must configure a virtual machine for RTEMS use.

Start VirtualBox and choose "New".

File:Main.png? Give a name to the virtual machine and select "Other"/"Other(Unknown)" in the first page of the virtual machine configuration.

In the second page you have to select the available memory for RTEMS(eg:128Mb).

The third configuration page will allow you to create or select a virtual disk. If you want a virtual harddisk create one and select its size. Creating a Virtual disk is not mandatory, you can still boot RTEMS without having one.

Now that we have concluded creating the virtual machine, we will need to change some options. Select the virtual machine in VirtualBox and press "Settings".The virtual machine settings page will open. This page allows to add disks, change allocated memory, change number of processors among other options.

Select "Storage" on the right panel and then press "Empty" that is underneath the "Floppy Controller". Now press the Browse button that is in front of "Floppy Device" and a new window will open. Press "Add", then change the "Filter:" option in the browse windows from "Image Files" to "All files" and select the .dsk floppy image file that you downloaded earlier.

This is how it should look:

File:Settings.png? File:Add floppy.png?

In the "Network" options the "Adapter-1" shall be attached to "NAT".

Now we are ready to the next step.= First boot =

You shall now have the virtual machine configured with the bootloader floppy image and the opentftp server configured and running with the path to your application.

In VirtualBox press Start to initiate the virtual machine. The bootloader should start to run, and you have to press "Ctrl+B" to start the gPXE command line.

Once in the command line issue:

dhcp net0
config

Then a set of network parameters will be printed. Write Down the "gateway" parameter(eg:10.0.2.2)

Now it is the time to test if everything is as expected... Issue the following commands:

kernel tftp://10.0.2.2/test.exe
boot

Where 10.0.2.2 is the gateway parameter you wrote down earlier and test.exe is the name of your application. If everything is running fine the RTEMS application should boot.

If it fails with a "permision denied" please chown and chmod your executable. If it fails with "not found" or similar please check your tftp server configuration(check your server root).

Automate the boot loader

Now we will automate the booting process.

First go back to the bootloader configuration page, but this time select the "Customize" option. If you know what you are doing you can deselect several drivers and protocols, if not let it be.

Now go to the "Embedded Script:" area in the bottom of the page and add this:

Error: Failed to load processor gpxe
No macro or processor named 'gpxe' found

Where 10.0.2.2 is the gateway parameter you wrote down earlier and test.exe is the name of your application.

Now press "Get Image" and replace the old one in the virtual machine. Next Time you boot the virtual machine the booting process will be fully automated and will be no need for interaction.

Serial Port Access

We can use the VirtualBox serial port for remote console or for debugging purposes. If your application is compiled with the RTEMS gdbstub you can remotely debug it from the gdb on your host computer.

To achieve this we will need to activate the serial port in VirtualBox.Go to your virtual machine settings and choose “Serial Ports”. Enable the serial port as “COM1” with the Mode “Host Pipe”. Select create Pipe and select the place where to create the pipe (eg:/tmp/vboxsp)

Now we will need to install socat. You can obtain it from here or install from your disto’s repositories:

yum install socat 

Now lets use socat to create a pseudo terminal. Run the Virtual Machine and open a terminal in your host. Issue the folowing command:

socat -d -d /tmp/vboxsp pty

You should obtain a output similar to the following one:

[root@cdcs testbed]# socat -d -d /tmp/vboxsp pty
2010/06/10 15:08:54 socat[3331] N opening connection to AF=1 "/tmp/vboxsp"
2010/06/10 15:08:54 socat[3331] N successfully connected from local address AF=1 "\xB@\xAE<\xA9\xB@\xAEA\xA9\xB@\xAEA\xA9\xB@\xAE,\xBA\x06\bB\xA9\xB@\xAE"
2010/06/10 15:08:54 socat[3331] N successfully connected via 
2010/06/10 15:08:54 socat[3331] N PTY is /dev/pts/4
2010/06/10 15:08:54 socat[3331] N starting data transfer loop with FDs [3,3] and [4,4]

Write down the PTY that outputted by socat; in this case /dev/pts/4.

Now if your application has the RTEMS gdb stub you can start i386-rtems4.10-gdb and issue the following commands to start debugging the application remotely:

set remotebaud 115200
target remote /dev/pts/4

You can also use socat to channel the serial port to a network connection( for connecting with telnet or similar):

socat UNIX-CONNECT:/tmp/vboxsp TCP-LISTEN:7777
telnet localhost 7777

Networking Applications

XXX: Determine if/how to run RTEMS network applications with the VirtualBox emulator.