Introduction

Last week, I had to develop integration tests on a SAMC-514 (a µTCA i7 CPU) running Fedora 17 to confirm proper assembly of a PicoSDR system. In order to reduce the system configuration duration, test time execution and, avoid test operator mistakes, I decided to wrap all commands that would have been typed manually by the tester in bash scripts and prepared a “software test kit”, so that the tester could launch all configuration scripts and tests using only few bash scripts and from a unique folder.

Furthermore, in order to simplify my test development on the embedded system, I also identified and configured methods allowing remote connection to the µTCA computer, so I was able to work with embedded Fedora directly from my Windows PC.

After a quick training to the test production team, I realized how wrapping the tests and commands in bash scripts paid off in reducing the effort at different levels, as described above, and I then decided to write this blog post presenting an overview of bash file scripting, some bash script examples (downloadable), and how to setup remote connection to a Fedora 17 embedded system.

 

Wrapping multiple commands and executing all at once using bash scripts.

A quick tour of bash scripts

The bash script allows executing automatic shell/command line instructions. As a text file format, it allows gathering multiple shell commands, but also performing conditional and loop operations, arithmetic operations, define and uses variables, user interface, and more.

To create a bash script, create a new text file using your preferred text editor, write all the commands you it will have to execute, and save the file with the file extension “.sh”

When your bash script is written, you just need to open a command terminal, navigate to the directory where your script is saved, and execute it using one of the following commands. (Note: In many cases, it is recommended to be logged in the terminal as superuser.)

– bash your-script-name

– sh your-script-name

– ./ your-script-name*

*(Note: prior to using this method, you have to set your file as executable using command “chmod +x your-script-name”)

The idea behind this first section was mainly to highlight that the bash scripting is a powerful tool provided in Linux. If you want to learn more about bash scripting, I suggest the following references which present bash scripting in greater detail.

 

1.         Bash scripting for beginnershttp://www.tldp.org/LDP/Bash-Beginners-Guide/html/
2.         Introduction to bash scriptinghttp://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
3.         Simple tutorial to create a script to backup files with timestampshttp://www.howtogeek.com/67469/the-beginners-guide-to-shell-scripting-the-basics/

B. Basic scripts, examples and explanations

In this section, I provide examples of a few bash scripts I created in the context of the PicoSDR bring-up and ADP examples execution. I describe each script, provide details about the commands they include and provide the scripts as downloadable content, so you can reuse it and modify it for your needs.

Script 1: Installation of the ADP release 6.3 for Linux

This script makes updates, installs the necessary development tools and libraries, installs the ADP software suite, and modifies the rights to the ADP working folders. This bash script is directly inspired from the installation instructions provided at: http://nutaq.com/en/support/latest-utca-edition/.

Note:

– You must be logged in as a superuser in the terminal (use command “su”)

– The computer must be connected to the internet, so it can launch the updates.

– The “nutaq-adp6-microtca-sdk-6-3-0-1-fc17-x86-64.rpm” package must be in the same directory as the bash script.

install_nutaq_adp_6.3.0.sh Comments
# !/bin/bash

# Update systems and   install necessary dev. libs

yum -y update

yum -y install libpcap-devel

yum -y install libtool

yum -y groupinstall development-libs development-tools

 

# Installation of ADP6.3.0   software suite

rpm -Uhv   nutaq-adp6-microtca-sdk-6-3-0-1-fc17-x86-64.rpm

 

# Modify directories   permissions

chown -R nutaq //opt/Nutaq

chgrp -R nutaq //opt/Nutaq

chmod -R +x //opt/Nutaq

chown -R nutaq //var/cache

Typical header to   identify it is a bash script

 

 “yum” : command for Installing, removing,   and updating packages of the Linux communities.

 

 

“rpm” : command to   install rpm package

 

 

“chmod” : change permission   of a directory

“chgrp” : change   group associated with a file

“chown”: change   owner of a file

· Downloadable content: install_nutaq_adp_6.3.0_kit.zip

 

Script 2: Configure, build, and launch the Perseus6010 RTDEx PCIe example.

This script is used to configure, build, and launch the Perseus6010 RTDEx PCIe example. This demo tests the PCIe data exchange integrity between the Perseus and a Host µTCA computer (running Fedora 17).

This script first installs the PCIe driver in the µTCA computer. It then replaces source and make files to configure the RTDEx PCIe example. It then executes the build_demo.sh bash script provided in the example folder to build the demo with the newly replaced files. Finally, it launches the demo.

This bash script is mostly inspired from the example user guide instructions provided in the documentation of the ADP software suite.

Note:

– You must be logged in as a superuser in the terminal (use command “su”)

– The Nutaq ADP software suite must be installed on the system and you must have the appropriate hardware

– The µTCA computer must have an Ethernet link with the Perseus.

– The Perseus must have the IP address: 192.168.0.101

– The Perseus must be programmed with the bitstream associated with this example.

– Due to PCIe protocol, the Perseus must be configured and powered-up before the host computer.

In brief, please refer to the example documentation for the setup details.

 

Launch_pcie_demo.sh
#!/bin/bash

 

# Install the PCIe driver   using the installation bash script.

bash   install_pcie_driver.sh

 

# Copy files necessary to   configure the example.

cp Makefile_PCIe //opt/Nutaq/ADP6/ADP_MicroTCA/sdk/examples/perseus6010_rtdex_record_playback   /host/prj_linux/Makefile

 

# Move to the example   directory and build the demo

cd   //opt/Nutaq/ADP6/ADP_MicroTCA/sdk/examples/perseus6010_rtdex_record_playback/host/prj_linux/

./build_demo.sh

 

# Launch the demo bash   file provided in the ADP software suite.

./Launch_rtdex_host_to_perseus_pcie.sh

 

 

· Downloadable content: http://nutaq.com/sites/default/files/blog-downloads/launch_pcie_demo_kit_1.zip

 

Script 3: Configure, build, and launch the HDD PCIe streaming example.

This script is used to configure, build, and launch the HDD PCIe streaming example. This demo tests the PCIe data exchange integrity between the Perseus and a Host µTCA computer (running Fedora 17) while the host computer saves the data in real-time on an external hard drive disk.

This script first installs the PCIe driver in the µTCA computer. It then replaces source and make files to configure the RTDEx PCIe example. It executes the build_demo.sh bash script provided in the example folder to build the demo with the newly replaced files.

Before launching the example, the bash requests some information from the user using the command “read” about the disk to mount and the location where the user wishes to mount the disk. Afterward, the bash will perform some verifications to properly mount the disk and allow read/write permissions.

With the disk now mounted, the system is now ready for the example execution. The example is launched a first time to perform a data exchange between the host and the Perseus in order to record a 2 Gig file on the external hard disk. It is then launched a second time, but this time to perform a playback of the recorded file and verify the data integrity. This will return the number of errors if any. Finally, the bash script cleans and unmounts the external hard drive if requested by the user.

Note:

– You must be logged in as a superuser in the terminal (use command “su”)

– The external Hard disk must be formatted and have an existing partition.

– The Nutaq ADP software suite must be installed on the system and you must have the appropriate hardware

– The µTCA computer must have an Ethernet link with the Perseus.

– The Perseus must have the IP address: 192.168.0.101

– The Perseus must be programmed with the bitstream associated with this example.

– Due to the PCIe protocol, the Perseus must be configured and powered-up before the host computer.

 

launch_hdd_pcie_streaming.sh
#!/bin/bash

 

# Install the PCIe driver   using the installation bash script.

bash   install_pcie_driver.sh

 

# Copy files necessary to   build the test.

cp   hdd_streaming_6.3_corrected.c   /opt/Nutaq/ADP6/ADP_MicroTCA/sdk/examples/perseus6010_rtdex_record_playback/host/src/hdd_streaming.c

cp Makefile_PCIe   //opt/Nutaq/ADP6/ADP_MicroTCA/sdk/examples/perseus6010_rtdex_record_playback/host/prj_linux/Makefile

cd /opt/Nutaq/ADP6/ADP_MicroTCA/sdk/examples/perseus6010_rtdex_record_playback/host/prj_linux/

./build_demo.sh

 

# Get the required user   inputs

echo ” “

echo ” “

read -p ‘Please, enter the   disk partition to use for test (e.g.: /dev/sda1): ‘ DEVDISK

read -p ‘Please, enter   where to mount the disk (e.g.: /HDD): ‘ HDDDISK

 

# Verify if the disk is   already mounted somewhere… if yes, unmount it…

if mount | grep $DEVDISK   > /dev/null; then

echo “Disk is   already mounted, unmounting the disk from the current location…”

umount $DEVDISK

echo “Disk is now   unmounted.”

fi

 

# Verify if the disk   mounting directory already exists

if

[ -d   “$HDDDISK” ]; then

read -p ‘The mounting   directory already exists, do you want to clear it (y/n)?’ YESNO

 if [ “$YESNO” == “y”   ]; then

echo “Clearing   folder…”

chmod 777 -R $HDDDISK

rmdir $HDDDISK

mkdir $HDDDISK

fi

else

mkdir $HDDDISK

fi

 

# Mount the user-defined   disk at the user-defined directory

echo ” “

echo “Mounting   disk $DEVDISK in folder $HDDDISK…”

mount $DEVDISK $HDDDISK

chmod 777 $HDDDISK

 

# Executing hdd streaming example

echo ” “

echo “Launching   hdd rtdex streaming pcie test [Slot A]”

cd   /opt/Nutaq/ADP6/ADP_MicroTCA/sdk/examples/perseus6010_rtdex_record_playback/host/bin

 

echo ” “

echo “step 1/3: Launching a recording of 2gig and   saving file on the external hdd…”

./hdd_streaming_pcie   -r -d $HDDDISK -s 2g -a 192.168.0.101 0

 

echo ” “

echo “step 2/3: Launching a playback to verify the   previously recorded file…”

./hdd_streaming_pcie   -d $HDDDISK -s 2g -a 192.168.0.101 0

 

echo ” “

echo “Showing file   on disk:”

ls -l $HDDDISK

 

echo ” “

echo “step 3/3: Cleaning…”

read -p ‘Do you want to   clear and unmount the hard drive (y/n)?’ YESNO

if [   “$YESNO” == “y” ]; then

chmod 777 -R $HDDDISK

rm $HDDDISK/*

umount -l $DEVDISK

rmdir $HDDDISK

fi

echo “Test   completed”

· Downloadable content: http://nutaq.com/sites/default/files/blog-downloads/launch_hdd_pcie_streaming_demo_kit_1.zip

In our next post we will discuss enabling SSH connections and remote desktop access.