Moving from VxWorks to Wind River Linux

Wind River has taken a thorough approach in providing a complete development environment for Linux. For a developer familiar with Wind River's VxWorks on Windows, there's a familiarisation exercise to go through, and hopefully this blog can reduce the gradient along that curve. It’s not designed to be a replacement for the documentation that comes with Wind River Linux (WRL), instead offers words of advice, and a guide to getting WRL running on a target.

How do I install Wind River Linux?

Ideally you will have Red Hat Enterprise Linux (RHEL) installed, which is what Wind River recommend (although it might work on other distributions). This can be on a virtual PC such as VmWare player if you only have a single development workstation. Get the install media and using a command line terminal as the user who will run WRL, change directory to where it’s mounted. Then run ./setup_linux, and follow the GUI that appears. Follow this by adding updates or BSPs etc in the same manner, or with other instructions provided with them.

If you have installed and used VxWorks Workbench, the Linux version is similar. For a developer who has familiar Windows tools, and wants to continue using them, at least initially, it makes a lot of sense to configure Samba to allow access to the home directory, or add a new share dedicated to ~/WindRiver.

What do you get on a fresh install?

As a developer used to VxWorks on Windows, it’s diving into the deep end to switch to using WRL on Linux. There are some similarities as both use the Workbench eclipse environment. The documentation focuses on command line usage, where it’s easier to communicate a precise command. Both VxWorks and Linux use makefiles and the accompanying make command.

The source tree is very different, so no longer can you go into target/config/xxx and configure the BSP. Instead you create a project using the configure tool. WRL uses the project build directory (just like with VxWorks 6.x) that resides under WindRiver/workspace. The configure tool runs on the command line and its options can specify the board, CPU, boot image, compiler options, parallel jobs, debug or production build, host, kernel, root filesystem etc.

If the configure command is not found, then add it to your path with:
PATH=$PATH:/home/username/WindRiver/wrlinux-2.0/wrlinux/

For more details of the configure command run configure -h.

Of course, a project is not the only part of WRL. There are packages and source code for all the different boards, CPUs etc that can be specified. They can be found under WindRiver/wrlinux-2.0/wrlinux, with the kernel itself being distributed as a tar file under WindRiver/wrlinux-2.0/layers/wrll-linux-2.6.21/packages.

Building

From the project directory, with a valid configuration, running make -C build linux will build just the kernel, whereas make all will run a minimal build using pre-built RPMS where available, and make build-all will build everything from source.


Running and Installing on a target

WRL can be run and/or installed to a target in several ways. The following assumes that a common x86 PC with hard drive, CD/DVD and ethernet connection is used to run and install WRL. It also assumes that the host is running RHEL. This is because it’s common to have spare PC hardware around, and it makes a good Linux target to learn more.

Create the bootable CD

The project needs to be configured to build an ISO image to boot from.

cd ~/WindRiver/workspace/Project
configure --enable-board=PentiumM --enable-kernel=standard+squashfs --enable-rootfs=glibc_std --enable-bootimage=iso

Then build the project with the make fs command:

make fs

Kernel Configuration

It’s possible to Configure the kernel with WRL configuration files, or as shown here, using the kernel configurator:

cd build
make linux.menuconfig

Select the following options as follows (It’s important to set the modules as modules, otherwise the ISO image won’t get built):

ISO9660_FSy
JOLIETy
UDF_FSm
UNION_FSm
SQUASHFSm

 

 

 

 

 

Then rebuild the kernel.

cd ..
make -C build linux.rebuild

Create the ISO image with the command:

make boot-image

Burn the ISO image onto a CD or DVD with an authoring tool of your choice.

Booting from the CD

Simply set the target to boot from the CD, and then let it load up. Any errors may indicate an incorrect configuration. Once booted, login as user root with password root.

Partition, Format, Mount

The next step is to partition, format and mount the hard drive of the target. The default tool to format is fdisk, used as follows:

fdisk /dev/hda

fdisk is a common Linux tool, so there is usage instruction available online for those unfamiliar with it.

Create the partition table to use a Linux ext2 partition at the start of the drive, and a swap partition at the end. Their size will be target dependant, but as an example, the / partition could be 5GB and swap 500MB. To Format the swap, use the command

mkswap /dev/hda2

Reboot the target to make sure the partition table is re-read correctly and then format the ext2 Linux partition with

mkfs /dev/hda1

Mount the / partition:

mount /mnt/hda1

Copy Files

There are several ways to copy over the file system, kernel and GRUB files. This explains using an FTP server on the host system. Prerequisites are a working IP connection (usually ethernet). Check with the standard ifconfig tool, and if eth0 isn’t available then it may require the following command:

ifconfig eth0 up

Assuming that there is a DHCP server on the local network that will assign an IP address, use dhclient.

dhclient

Simply change to the mounted Linux partition and ftp the host (substitute the correct IP address):

cd /mnt/hda1
ftp 192.168.4.5

Copy using mget from the export directory on the host (where the ISO file was created) the large file ending in dist.tar.bz2, and the file whose name contains bzImage. These are the compressed filesystem and kernel.
Also copy from the host file system /usr/share/grub/i386-redhat the GRUB files stage1, stage2 and e2fs_stage1_5. Finally copy the grub* files from the host /sbin directory.

The next step is to expand the compressed archive containing the file system.

tar -xvjpf *dist.tar.bz2

Then move the kernel to the boot drive, the grub files to the grub directory and finally the GRUB binaries to the /sbin directory.

mv *bzImage* boot/bzImage
mv stage1 boot/grub/
mv stage2 boot/grub/
mv e2fs_stage1_5 boot/grub/
mv gru* sbin/

Edit the etc/fstab file to add the hard drive partitions, and optionally the CD and floppy:

/dev/hda1 /
ext3
defaults 1
1
/dev/hda2swap
swap
 0 0
/dev/hdc/mnt/cd
autonoauto00
/dev/fd0
/mnt/floppy
auto
noauto
00

Make sure the mnt/cd and /mnt/floppy directories are created!

Edit the boot/grub/grub.conf file:

default=0
timeout=5
title    target
        root (hd0,0)
        kernel (hd0,0)/boot/bzImage root=/dev/hda1 fastboot
        boot /boot/bzImage

Install GRUB to the MBR

To be able to boot directly from the hard drive, GRUB needs to be installed in the Master Boot Record (MBR). The bootable CD should contain grub, so it's then a case of using the /mnt/hda1/sbin/grub executable to set the root device and install it:

cd /mnt/hda1/sbin/grub
./grub
grub> root (hd0,0)
grub> setup (hd0)
grub> quit

The grub executable that's been copied from the host should be used, not any grub executable on the CD. If permissions on the grub executable mean it cannot run, then use chmod to set them correctly

Automatically starting the network

It's a good idea to automatically have the target ready to use when it boots, and therefore it needs to enable networking and get an IP Address. Edit /mnt/hda1/etc/rc.d/rc.local to add

ifconfig eth0 up
dhclient

Then all that's needed is to reboot, and make sure the target boots from the hard drive!