Building a QEMU Virtual Image of the NI Linux Real-Time OS

There is seemingly no way to test out and play with the NI Linux Real-Time OS without purchasing hardware from National Instruments. It would be useful if we could virtualize the operating system so that developers can play with the operating system before committing to purchasing the hardware. In addition, having only one piece of hardware to develop and test software is not conducive to the typical software development team. If each developer had a local NI Linux Real-Time virtual machine, then some software development and test can be completed without the hardware.

Since the NI Linux Real-Time OS is built using the Yocto Project and the source is availabe at https://github.com/ni/nilrt, creating a virtual machine is possible. One method of doing this is with QEMU.

According to their website, QEMU is a generic and open source machine emulator and virtualizer. It is very useful for virtualizing ARM architectures, which is what we are going to do.

References

Below is a list of references that I used to create this blog:

Prerequisites

Below is a list of prerequisites for building the NI Linux Real-Time OS with Yocto:

  • You will need a Linux distribution with enough space to build the image. I used XUbuntu 16.04 to successfully build my QEMU image. You will be downloading source files and compiling code packages, so the build could be rather large. Yocto recommends having at least 50GB if disk space available. See Yocto Project Quick Start in the section “The Linux Distribution” for more details.
  • Yocto requires that you have some programs installed prior to attempting to build a Linux distribution. See the list of programs required at Yocto Project Quick Start in the section “The Build Host Packages”.

    Obtaining the NI Linux Real-Time Source

The source can be found on github at https://github.com/ni/nilrt. We will need to clone the repository with git. Issue the following command to clone the repository:

git clone https://github.com/ni/nilrt

This will copy the source code base that we will start with into the folder nilrt. When referring to relative path locations in the rest of this document, paths will be relative to this directory.

You’ll notice that there is not much in this directory. The meat of this repository will be in a branch. As of the writing of this blog, the following branches are available:

origin/HEAD -> origin/master
origin/dev/mono_support
origin/master
origin/nilrt/14.0
origin/nilrt/14.1
origin/nilrt/15.0
origin/nilrt/16.0
origin/nilrt/17.0
origin/nilrt/18.0
origin/nilrt/comms-2.0

There is a branch for each version of LabVIEW that the operating system supports. For example, I used the origin/nilrt/17.0 branch to target LabVIEW 2017. You will need to checkout and track the branch that you are interested in building. For example, to checkout and track origin/nilrt/17.0 issue the following commands:

git checkout --track origin/nilrt/17.0
git checkout nilrt/17.0

The first command creates a local branch called nilrt/17.0 that tracks the remote branch origin/nilrt/17.0. The second command switches to the local nilrt/17.0. There should now be a sources and conf directory in the nilrt folder.

Run nibb.sh

National Instruments provides a script to download other repositories and configure the build. To build a image bootable with qemu with an ARM architecture use the following command:

MACHINE=qemuarm DISTRO=nilrt ./nibb.sh config

This will clone and checkout the necessary git repositories and will generate a file that we need to source when building the image. Once completed source the env-nilrt-qemuarm file using the following command:

source ./env-nilrt-qemuarm

Make Modifications to the Source

Next, we need to make some minor modifications to some source files.

Uncomment the line EXTRA_IMAGE_FEATURES = "debug-tweaks" in the config/local.conf file. I found this on line 136 of the config/local.conf file. This will allow you to login as root without a password.

Next, add ext4 as one of the image file types. This is found in sources/meta-nilrt/recipes-core/images/niconsole-image.bb file. Change the line IMAGE_FSTYPES = "tar.bz2" to IMAGE_FSTYPES = "tar.bz2 ext4". The root file system will now be built into a tar.bz2 archive and a ext4 image. QEMU defaults to using the ext4 image. If you have no need for the tar.bz2 archive, then you can change the line to IMAGE_FSTYPES = "ext4".

Build the console image

Use bitbake to build an image. I found images in sources/meta-nilrt/recipes-core/images/. The image that I was able to build successfully is niconsole-image.bb.

To build this image, issue the command bitbake niconsole-image to create the image. Now go get a cup of coffee or go get some exercise because bitbake will now download and build everything needed to create a bootable image of nilrt. This can take a couple of hours.

Execute QEMU

The default configuration to run qemu is to run using a local vnc server. You will need a VNC client like vinagre to connect to the VNC server. To execute qemu in the default mode issue the following command:

runqemu qemuarm

To execute qemu without the vnc server issue the following command:

runqemu nographic qemuarm

Notes:

  • Use localhost when connecting to the VNC server.
  • I had trouble using ssh when running qemu with nographic. ssh works well through the VNC server. * If you want to write to the ext4 image, you will need to resize the image using resize2fs and e2fst. See how to do this in the following link on Stack Exchange: How to Resize ext3 Image Files. The answer mentions ext3, but the same solution works for ext4.

Leave a Reply

Close Menu