VxWorks 7 SDK for QEMU (sabrelite)

Introduction

QEMU (sabrelite) is a 32 bit VxWorks QEMU target based on NXP® i.MX6Q SABRE Lite.

The VxWorks 7 SDK is a development environment dedicated to VxWorks application developers which includes the following features:

This guide helps you get up and running with developing applications for platforms running VxWorks. You can use it for creating new applications, or just exploration of VxWorks capabilities.

Setting up the development environment

You should start by downloading a VxWorks SDK for your platform of choice from https://labs.windriver.com and unpacking it. Refer to the documentation in docs in the unpacked SDK for additional information on creating and debugging applications.

OS requirements

The SDKs are meant to run on Linux hosts. Some of the examples in this document are specific to Debian derivatives.

Prerequisite(s)

Host dependencies

On Debian derivatives, the following packages need to be installed:

$ sudo apt install build-essential libc6:i386

Having an FTP server installed on your development host will make application deployment easier and allow you to access the host file system from a VxWorks target.

To accommodate for the varying runtime configurations of the VxWorks kernel images included in the SDKs, you may be interested in using an FTP server option based on pyftpdlib.

Install pyftpdlib:

$ sudo apt install python-pip
$ sudo pip install pyftpdlib

Starting a local FTP server on port 21 with user "target" and password "vxtarget" and FTP root in the current user's home can be done as follows

$ sudo python -m pyftpdlib -p 21 -u target -P vxTarget -i 127.0.0.1 -d $HOME

Running the VxWorks kernel and the applications created with the SDK requires installing QEMU

$ sudo apt install qemu-system-arm

Important:

For Ubuntu hosts this PPA (ppa:jacob/virtualisation) includes multiple versions of common virtualization tools, including QEMU.

$ sudo add-apt-repository ppa:jacob/virtualisation
$ sudo apt update
$ sudo apt install qemu-system-arm

Booting VxWorks on QEMU (sabrelite)

QEMU can be used to run the VxWorks kernel included in the SDK and to deploy VxWorks applications.

Start by opening a Linux terminal window and going to the location of your unpacked VxWorks SDK. The following commands can be used to start a VxWorks guest in QEMU.

For host file system access from the VxWorks guest, start an FTP server and enable user "target" with password "vxTarget". These are the built-in credentials for the VxWorks kernel image for QEMU (sabrelite).

$ sudo python -m pyftpdlib -p 21 -u target -P vxTarget -i 127.0.0.1 -d $HOME &
$ qemu-system-arm -machine sabrelite -m 1024 -smp 4 -serial /dev/null \
 -serial stdio -kernel vxsdk/bsps/fsl_imx6_2_0_4_0/vxWorks \
 -net nic,model=imx.enet,netdev=net0 \
 -netdev user,id=net0,hostfwd=tcp:127.0.0.1:1534-:1534,hostfwd=tcp:127.0.0.1:2345-:2345 \
 -monitor none -nographic

Application development

Start by opening a Linux terminal window and going to the location of your unpacked VxWorks SDK.

Source the SDK development environment before using the SDK.

$ source sdkenv.sh

Developing applications from the command line

The VxWorks compiler driver (wr-cc/wr-c++) utility lets you invoke VxWorks toolchains to compile your real time process (RTP) application from command line. The SDK development environment includes a set of environment variables (CC, CXX, CPP, etc) which match the various compiler driver utilities.

Procedure:

  1. Create a C source file foo.c:
#include <stdio.h>

int main(void)
    {
    printf("hello, world!\n");
    return 0;
    }
  1. Compile the source file foo.c to create a Real Time Process application.
$ wr-cc -rtp foo.c -static -o foo.vxe

or

$ $CC -rtp foo.c -static -o foo.vxe

Alternatively, you can also create a Makefile and then call make to compile the source file.

all:
    $CC -rtp foo.c -static -o foo.vxe
$ make

Developing applications using CMake

By default, a generated VxWorks SDK includes CMake. When the application developer sources the SDK environment, they will automatically have access to CMake. There is no need to download, install and configure CMake separately. With VxWorks CMake, you can build existing CMake examples that are included in the generated SDK, or you can create your own projects.

CMake examples can be found in the directories /examples/rtp/hello_cmake_rtp and /examples/dkm/hello_cmake_dkm

Procedure: 1. Create a project directory, called my_project.

$ mkdir my_project
  1. Create the CMakeLists.txt file in the project folder.

  2. To build your project, run the following command:

$ cmake -D CMAKE_TOOLCHAIN_FILE=${WIND_SDK_HOME}/vxsdk/sysroot/mk/rtp.toolchain.cmake .

Note: RTP is used in the example. If you would like to build a DKM project instead, change the toolchain name to dkm.toolchain.cmake.

Running applications

Start an FTP server on port 21 with user "target" and password "vxtarget" and FTP root in the current user's home.

$ sudo python -m pyftpdlib -p 21 -u target -P vxTarget -d $HOME &

After booting VxWorks on your target, switching to the "cmd" shell will allow you to navigate to the location of your application with greater ease.

E.g.

-> cmd
[vxWorks *]# 

Placing the application in a location accessible over FTP will make it visible with minimal configuration to the VxWorks instance.

Assuming the application is located in $HOME/opt and the FTP server uses a minimal configuration which provides FTP access to $HOME:

[vxWorks *]# cd opt
[vxWorks *]# ls
opt/./hello
opt/./hello.c
[vxWorks *]# more hello.c
#include <stdio.h>

int main(int argc, char **argv) {
    printf("Hello World\n");
    return 0;
}
[vxWorks *]# hello
Launching process 'hello' ...
Process 'hello' (process Id = 0x2057f5e8) launched.
Hello World