Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

As we said earlier, there are many way to develop for Linux.  

This page covers development of a minimal application and show you how to get setup, build, deploy and debug it - Hello World, no less!

We take you through setup, building, deployment and debugging this app on Opal-6.

This is a simple C/C++ application, developed on a Linux PC.  There are many other ways to develop applications for Linux, but this is a good starting point.

Setting up the Tools 

This section covers how to: 

  1. Setup a Toolchain (compiler etc)
  2. Setup an IDE (CodeBlocks) to buld applications
  3. Setup CodeBlocks to debug applications

Toolchain Setup

A toolchain is needed to build custom applications. You can use:

  1. A pre-built toolchain for our XFCE demo image, or
  2. Build one yourself using the YOCTO tools we provide.

Using the Demo Toolchain

The download link for this is on the releases page.  Grab the latest version and put it XXXX.

****

Building a Toolchain

If you have the YOCTO bits installed from this page, you can use it to generate a toolchain.

Execute the following commands:

$ cd fsl-community-bsp
$ source setup-environment build
$ bitbake opal6-image-base -c populate_sdk

To install, do the following:

$ cd ~/fsl-community-bsp/build/tmp/deploy/sdk
$ ./poky-glibc-x86_64-meta-toolchain-cortexa9hf-vfp-neon-toolchain-2.0.1.sh

The actual installer name may be different to that used above. Just follow the prompts to complete the installation. In most cases you can simply accept the defaults.

IDE Setup

We use the CodeBlocks IDE for development and this section details how to set it up.  

First, download and install CodeBlocks.  Use the Ubuntu Software Centre, or the following command line:

$ sudo apt-get install codeblocks codeblocks-contrib

To configure CodeBlocks for our toolchain:

We need to configure CodeBlocks to use our toolchain and sysroot so do the following:

  1. Start CodeBlocks
  2. Open Settings->Compiler
  3. Choose ‘GNU GCC for ARM’ from ‘Selected Compiler’ and click ‘Copy’
  4. Give your new compiler a name e.g. YOCTO compiler for Opal-6
  5. Now click the ‘Toolchain executables’ tab and browse to your sdk installation directory. You are looking for the parent to the compilers bin directory which in our case is: /opt/poky/2.0.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi
  6. Now fill in the Program Files by prepending ‘arm-poky-linux-gnueabi-’ to each of gcc, g++ and ar. You should end up with the following:

 Image Added

Debugger Setup

Debugging applications on Opal-6 requires two components:

  1. gdbserver running on Opal-6
  2. gdb client running on the VM

The Opal-6 images include the gdbserver components, so we just need to configure CodeBlocks to connect via the gdb client:

  1. Start CodeBlocks
  2. Open Settings->Deugger
  3. Click the 'GDB/CDG debugger' option from the left side menu
  4. Click 'Creage Config' button and enter a name for this debugger.  e.g. "Opal-6" and press ENTER.
  5. Click "Opal-6" on the left hand menu and paste the path of your Opal-6 toolchain debugger into the Executable Path text box:
    e.g. /opt/poky/2.0.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdbPress OK

Image Added

6. You setup should look like the above image. Click OK to finish.

 

To set this debugger as the default for Opal-6, do the following:

  1. Open Settings→Compiler
  2. Click the Toolchain Executables tab.
  3. Select the Opal-6 compuler from the menu
  4. Change Debugger to Opal-6 from the meny and click OK.

Image Added

Creating a Linux Application

These steps will show how to create and compile a simple project for Opal-6.

First we will create the project and configure it to use the Opal-6 tools:

  1. Start CodeBlocks
  2. Select File->New->Project from the menu, then select Empty ProjectSet .   Press Go.
    Image Added 
  3. Use the wizard and set the title as Hello World and choose a project folder.
    Image Added 
  4. Click Next and set the compiler to YOCTO Compiler for Opal-6.  Debug and Release configurations will be created.
     Image Added
  5. Click Finish.

Now we need to add a file:

  1. Select File->New->File  and select C/C++ SourcePress Next and select C. Press Go.
    Image Added 
  2. Use the wizard and seslect the language for the file - in this case we want to use C.  Press Next.
    Image Added
  3. Press '...' and enter the file name helloworld.c, and then Save, followed by Finish
     Image Added
  4. Paste the following code into the editor: 
Code Block
languagecpp
#include <stdio.h>

int main(int argc, char **argv)
{
    printf("Hello World!\n");
    return 0;
}

5.  Press Build (gearwheel icon) Select Build→Build from the menu to compile the project.

Deploying the Application

You can deploy your application manually to Opal-6, or configure CodeBlocks to automatically deploy when you build.

These steps require Opal-6 to be connected to the same network as your development PC.  You also need to know the IP address of the Opal-6.  You can determine this by entering

$ ifconfig

in a terminal window on Opal-6. You will see...

****

Manually Deployment

You can manually deploy applications to Opal-6 using scp.  

To deploy your Hello World application, open a terminal on your PC and type the following commands:

$ cd Projects/HelloWorld
$ scp bin/Debug/helloworld root@<opal-6 IP address>:~/

Your Opal-6 needs to be connected to your network.  Change the IP address in the line above to match the address of your board.

Execute the following in an Opal-6 terminal window to run the application:

$ ./helloworld

Deployment using CodeBlocks

To setup CodeBlocks to automatically deploy when it builds:

  1. Right-click on the project in the Management pane on the left and select Build options...
  2. Click on the Pre/post build steps tab
  3. Paste the following into the post build steps window (with the correct IP address for your board).
     scp $(TARGET_OUTPUT_FILE) root@<opal-6 IP address>:~/
     
  4. Repeat the step above for each target build type (debug, release etc)
  5. Click OK

Now, whenever you successfully compile your project, it will be copied to Opal-6.

Debugging 

It's pretty hard to make a mistake in "Hello World", but let's take a look at how the debugger works.

First, check that your build target is set to Debug, so that all the debug symbols are included.

Next, start gdbserver on Opal-6 but typing the following in an Opal-6 terminal window:

$ gdbserver localhost:12345 helloworld

You can set the port to whatever you like but to make sure you aren’t using a port already in use, it is best to use numbers above 10000.

This command will cause gdbserver to wait for a remote connection.

In CodeBlocks you can start debugging your application.  

  1. Click on the printf line in the source code and press F5 to toggle a breakpoint.  
  2. Start the debugging session by clicking Debug/Continue  from the Debug toolbar or the Debug menu.  Note that the Debug menu shows shortcut keys.
  3. The code will be executed on Opal-6 and break on the line specified.

When you close your application, gdbserver will automatically close.  You must start it again before debugging again.

 

 

Panel
titleOn this page

Table of Contents