Sep 18

Now that GDB-Server is installed on the FB it is time to see if the Hello_World application can be debugged on my development PC over the network to the FB.

On the Axis developer site there is mentioning of special make commands to compile the target code in such a way that debug information is added to the executable. Since I want to make use of my own make file in order to fully understand how this works the make file must be changed to include more compiler flags. Open Geany, load the HelloWorld project and change the make file as listed below (only the CFLAGS definition changes):

COMPILER = /usr/local/cris/bin/gcc-cris
CFLAGS = -g -fno-omit-frame-pointer -O0 -mlinux -o
SOURCES = main.c MyUnit.c
TARGET = Hello_World
DESTINATION = root@FOXBoard:/mnt/flash/bin/HelloWorld

# top-level rule to create the program, executed by default if no params are provided
all: compile

# Called by pressing the Compile or Build button in Geanny
compile: $(SOURCES)
<TAB>$(COMPILER) $(CFLAGS) $(TARGET) $(SOURCES)

build: compile

<TAB>scp $(TARGET) $(DESTINATION)

Press the execute button in Geany so that the HelloWorld application is compiled with the new settings and copied to the FB. Using a SSH, navigate to /mnt/flash/bin/HelloWorld and execute ./Hello_World to verify if the application works.

In a different terminal, check what IP address is used by the development PC, in my case 10.0.0.157. This needs to be used on the FB in GDB-Server so it knows to whom to listen. In the folder /mnt/flash/bin/HelloWorld on the FB enter the command gdbserver 10.0.0.157:1234 Hello_World, as a response the a process is started for Hello_World and GDB-Server will use port 1234 to listen if 10.0.0.157 sends commands.

In a terminal on the development PC, navigate to /usr/local/gdb-cris and enter the command ./gdb-cris /home/jan/FOXBoard/HelloWorld/Hello_World, this will start GDB and the prompt will change into (gdb). Enter the command target remote FOXBoard:1234, some warnings are given that GDB is not able to debug shared libraries but for now let’s ignore those since in the terminal for the FB a message will appears Remote debugging from host 10.0.0.157 so it seems that communication between host and target has been made.

In order to set a breakpoint on the first line of the main () function, enter the command break main in GDB-Server. The response shows it could set the breakpoint in main.c on line 6, so far so good. Enter the command help running will give a list of possible commands to step through the program. One of them is continue that runs until a breakpoint is encountered. Entering this command shows some errors that /lib/ld.so.1 can not be found, seems that this is the shared library that triggered the previous warning. GDB stops at line 6 showing the source line. Next command is step that executes one line of code. In the FB terminal the Hello world message appears. Use the step command repeatly to step line by line through the code until GDB states the program exited normally and GDB-Server states that the Child exited with retcode 0.

Not bad!

Sep 17

After 5 days of exchanging messages with Jesper from the Axis Customer Service I finally managed to build a distribution with GDBServer enabled. It’s a very long process how to get there, below the steps needed.

Next to the cris compiler and path modifications several packages must be installed in Ubuntu 8.04 using the Synaptic Package Manager. Select below listed packages:

  • GCC
  • bash
  • make
  • wget
  • gawk
  • bc
  • byacc
  • flex
  • perl
  • sed
  • tar
  • zlib1g
  • zlib1g-dev
  • libncurses5
  • libncurses5-dev
  • bison

Since some of the shell scripts used by the Axis build system are not POSIX compliant, the system shell must be able to handle the exceptions. Ubuntu uses by default a shell called “dash” and can not handle the exception; for this reason the shell must be changed to “bash” which can handle them. In a terminal execute below three commands:

  • cd /bin
  • sudo rm sh (followed by your password)
  • ln -s bash sh

When completed you will need to reboot the PC. In order to verify if bash is now used as the default shell enter the command ls -al /bin/sh, this should should result in a line similar like this:

lrwxrwxrwx 1 root root 4 2008-09-15 20:55 /bin/sh -> bash

In order to install the build system, download the file devboard-R2_10.tar.gz by selecting the Install Package Version 2.10 March 9, 2007 and save this in a separate folder (in my case /home/jan/FOXBoard/Install/BuildSystems). Navigate to this folder and enter the command tar xfz devboard-R2_10.tar.gz, this will create a folder devboard-R2_10. Navigate into this folder and execute the command ./configure, this will whole lot of fetching, checking and unpacking messages and finally prompt for a product configuration to use. Enter 5 to select the FOXBoard LX832 and when a question is displayed if you would like to configure the SDK now enter y. A three step overview is displayed on which steps to take in order to build the distribution after which the configure application is stopped.

Enter the command make menuconfig, this will compile a whole bunch of applications on your PC, the process will take several minutes to finish. There are a lot of warnings flying by, these are apparantly ok as long as the process continues and does not display any errors. If so, verify that all packages have been installed as listed above, remove the devboard-R2_10 folder using the rm -r devboard-R2_10 command and extract the folder again using the tar command.

When the process stops a program is launched in the terminal that allows you to select all the options that are available to include in the distribution. For now I’m only interested in adding the GDBServer application that can be found in the Debug Configuration menu option, scroll to this option and press enter, scroll to the Enable GDB server support option and press y in order to select it. Use the right arrow to navigate to the Exit button and again to the Exit button to stop the configuration program. Selecting the yes button will save the configuation and return to the terminal.

On the prompt type again the command ./configure, the same process of fetching, checking and unpacking will start again, only this time with a lot more packages to fetch. Some of them are big so it seems the program hangs but give it a few minutes. The final message should be that the configuration of the SDK is done and the make command must be executed. If you though that all previous step took a long time, this will is even longer. It takes 50 minutes on my mini-ITX board, Axis advices to sit back and drink a cup of coffee, I can only agree.

Also this process should end without any errors. As a result a file called fimage is created in the folder dev_board-R2_10. This is the flash file that needs to be programmed in the FB using programming tools that can be downloaded from the AcmeSystems site, they are called boot_linux and etrax100boot. Save them a separate folder (in my case /home/jan/FOXBoard/Install/Distributions) and in this folder execute the command chmod a+x boot_linux etrax100boot in order to be able to execute them later. Copy the flash file fimage in to this folder using a more descriptive name (in my case fimage832_GDBServer).

Remove the power supply from the FB and place a jumper on the two outer pins of header J8. Switch on the power supply again, due to the jumper the FB will enter a programming state, only the green LED will light up. Navigate to the Distributions folder containing the flash image. In the terminal execute the command arp -n in order to find the ethernet interface of the PC, mine states eth0. This is the interface you will need to use in the next command in combination with the flash file that needs to be programmed: sudo ./boot_linux -F -d eth0 -i fimage832_GDBServer followed by the password of your account on the PC. The boot_linux program will program the FB over the network, when the verify result is OK it will exit with code 0.

At that moment the red LED will start flashing on the FB, the reason for this is that the FB serial number is not configured. In order to fix this a secure shell must be opened, however due to the reflash the IP address of the FB is reset to it’s default address 192.168.0.90. Since my network uses 10.x.x.x the serial RS232 adapter is used with the Serial Port Terminal to get access to the FB.

In the serial terminal, navigate to the folder /etc/conf.d folder and enter the command easyedit net.eth0. Modify the IP address and save the file. Next enter the command bootblocktool -a SERNO 00408CCD0000 which will fix the serial number issue although the red LED will continue to flash.

Remove the jumper (very important!) and enter the reboot command or cycle the power. The FB should now boot normal and after a few seconds the ping 10.0.0.180 command will show it’s running the new distribution.

To prevent typing the password when starting the SSH connection you will first need to remove the fingerprint from the old FB distribution on your PC using the command sudo rm /home/jan/.ssh/known_hosts and store the public key of the PC again on the FB. After this the command ssh root@FOXBoard can be given that starts an SSH terminal without requesting the password. Typing the command gdbserver shows now the usage of gdbserver which tells me it is indeed part of the distribution.

Thank you Jesper!

Sep 12

After a post to the Axis support team it seems libncurses5-dev must be installed also. After installing the series of messages changed but still no success in launching the configuration menu. More posts to the Axis team followed and info is needed. A day later, typing make menuconfig to log the messages it miraculously works! It seems a reboot is needed after installing the lib-stuff.

A blue window appears with a user interface that looks like the first applications I build using Turbo Pascal many years ago.  Navigating through the various options I leave all the settings as is except checking all the options in the Debug Configuration menu.

After saving the configuration using the default filename .config and exiting the application the command ./configure must be given. This now completes without any errors, it’s time to test building my own configuration with the command make.

No, not a success. Now only one error appears so progress is made. It states Makefile:96: *** missing separator. Stop. Posting this message to the Axis team result in a comment that the build system is not fully posix compliant, the solution should be to change the system shell. The command echo $SHELL shows I’m already using bash. I posted the feedback and the Makefile to the Axis team for feedback.

Sep 10

In order to debug a remote application two things are required: a debugger running on the development machine and a debug server running on the actual hardware that interfaces between the application and the development machine. The basic debugger for Linux is called GNU Debugger (GDB for short) that provides the basic interfacing with applications to do proper debugging. There are several graphical user interfaces that make use of the GDB engine to make life more easy.

On the FB an application call GDBServer is required that controls the local running application and receives commands from the remove running GDB. According the Axis site this is part of the software distribution but not installed by default. I’m not sure why, but the site states it’s easy to configure this. Let’s try.

It starts with downloading the debugger for cris in the file gdb-cris_6.3.50-cvs20050523-1_i386.deb, since there are instructions how to install it select the save to file option. In a terminal, navigate to the folder in which the file was stored and enter the command sudo dpkg –install gdb-cris_6.3.50-cvs20050523-1_i386.deb, after providing your password it installs the package in /usr/local/gdb-cris. This folder needs to be added to the PATH variable to make the debugger available in the local folder that holds the application to debug.

Next step would be to compile the GDBServer and install it on the FB. For this the file devboard-R2_10.tar.gz must be downloaded. This is stored in the folder /home/jan/FOXBoard/Install/BuildSystem, in this folder the command tar xfz devboard-R2_10.tar.gz is given that creates the folder devboard-R_10. In this folder execute ./configure, this will extract all other files and ask for which board the system needs to be build. Number 5 is for the fox_832 board, type y to configure the SDK now. This creates the different make files.

In order to build the distribution there are three possible options to pass to make. Axis advices to use make menuconfig, this triggers a whole list of commands and finally terminates with an error that Ncurses could not be found. It advices to use make config that does not depend on Ncurses. Typing make config results in a simulair list of command, but (oops) it also results in the same error that Ncursus could not be found.

Using System | Administration | Synaptic Package Manager, typing your password and searching for Ncurses actually indicates that this is installed in Ubuntu 8. Ncurses-bin and Ncurses-hexedit are not, to be sure these two are installed aswell after which the make process is repeated. Still the error.


Sep 7

Since a specific dependency can be passed as parameter when the makefile is called I guess an IDE uses this to execute the required command. For example:

COMPILER = /usr/local/cris/bin/gcc-cris
CFLAGS = -mlinux -o
SOURCES = main.c
TARGET = Hello_World
DESTINATION = root@FOXBoard:/mnt/flash/bin/HelloWorld

# top-level rule to create the program, executed by default if no params are provided
all: compile

# Called by pressing the Compile or Build button in Geanny
compile: $(SOURCES)
<TAB>$(COMPILER) $(CFLAGS) $(TARGET) $(SOURCES)

build: compile

<TAB>scp $(TARGET) $(DESTINATION)

When the command make compile is executed, the code is only compiled. When the command make build it first executes the compile dependency and than copies the executable to the target. I would expect that the IDE provides the basic menu structure and allows the programmer to enter the command to execute when the menu item is selected. In that case, it’s easy to integrate custom compilers or special target needs in the default IDE.

After spending a hour searching how this works in Anjuta I could not find how to make this work. It might be that Anjuta is already to complex for what I want, it is designed for working with huge open source projects, in my case it will be a couple of local files that need to be managed.

Searching the internet for a simple Linux IDE results in several hits refering to Geany. The home page states “It was developed to provide a small and fast IDE, which has only a few dependencies from other packages”. Sounds like this is what I’m looking for. Using the Applications | Add/Remove… menu in Ubuntu shows that Geany can automaticly be installed.

After installation and starting Geany it is easy to find your way in this program. First guess is that I will be needing to setup a new project, using the Project | New menu option. It asks for a project name (HelloWorld), the file to store the project settings in (HelloWorld.geany) and the base folder of the project (/home/jan/FOXBoard/HelloWorld). After pressing the create button I can open the files that I already created before manually (main.c).

After opening the main.c file the Build menu options are enabled. Selection the Build | Compile menu command shows that gcc is used for compiling the application and that no errors are found. Nice, but I don’t want gcc but I want gcc-cris to be used, or actually I want that make is called with my own parameter.

In the Build menu there is an option available Set includes and arguments, selecting this option shows a dialog that offers three input fields to enter commands for Compile, Build and Execute. Here the gcc command is listed, I guess these commands are indeed given to Linux to execute so entering make compile in the Compile field, make build in the Build field and make build in the Execute field should do the trick. After pressing the OK button and selecting Build | Compile the Compiler shows in blue the execute command (make compile (in directory:/home/jan/FOXBoard/HelloWorld)) and the output of the make program (/usr/local/cris/bin/gcc-cris -mlinux -o Hello_World main.c). After a second a blue message indicates that the Compilation finished successfully. The Build | Build menu command or the Build | Execute command does the same with the addition of executing the secure copy as well.

In the Edit | Preferences menu you can select in the Toolbar tab the option to display a Compile and Run button. These buttons call the Build | Compile menu (and so make compile) and the Build | Execute menu (and so make build) to make life even more easy.

On purpose a mistake is made in main.c to check how errors are handled. The printf is replaced by pri ntf, after pressing compile it shows an error in the Compiler tab and highlights the error in main.c. Very, very nice! It looks like I found my base for the developing code, next step would be to include a debugger as well.

Sep 6

Since sshfs and NFS are both not working I’m stuck with copying any executable program to the FB using the scp command. This not very convenient since the executable is expected to change many times during development.

In order to compile and link C-programs normally a MAKE file is used, this is also the case when using Anjuta. A make file is in principle nothing else than a batch file containing several commands that are executed depending the current state of any source file. They look very complex, but when the programs remain simple using only a couple of privatly controlled source files than the complexity reduces very quickly. It might be an option to create my own make file and include all required actions that need to take place after compiling.

In that case the work flow would be:

  • Start an ssh terminal ones and leave it running during the development session
  • Create the code, execute the make file that compiles, links and copies the result to the FB
  • In the ssh a new file is available that can be executed to see the results
  • If not OK, switch back to the editor, change the code and run make again

This can only work if all commands that must be executed do not requeire any user input during the execution. The scp command however does prompt for a password, so this must be fixed first.

A typical makefile contains lines of the following types:

  • Comments, any line beginning with a “#” sign, or any line that contains only white-space

For example:

# This is a makefile for the Hello_World application

  • Variable Definitions, these lines define values for variables

For example:

CFLAGS = -mlinux -o
SRCS = main.c file1.c file2.c
CC = gcc-cris
TARGET = Hello_World

  • Dependency Rules, these lines define under what conditions a given file (or a type of file) needs to be re-compiled, and how to compile it

For example:

main.o: main.c
gcc-cris -mlinux -o Hello_World main.c

This rule means that main.o has to be recompiled whenever main.c is modified. The rule continues to tell us that in order to compile main.o, the command gcc-cris -mlinux -o Hello_World main.c needs to be executed. Note that each line in the commands list must begin with a TAB character. Make is quite picky about the makefile’s syntax.

The definited variables can be used in any statement using $(variable name), the previous example of the main.o dependancy can be rewritten as follows:

main.o: main.c
$(CC) $(CFLAGS) $(TARGET) main.c

The benefit of this is clear, when multiple source files are use a change in the compiler flags only needs to be made in one place. Also it is very easy to change the compiler into gcc so that the output is now compiled for the development PC.

As a result, the basic makefile for the HelloWorld application is:

COMPILER = gcc-cris
CFLAGS = -mlinux -o
SOURCES = main.c
TARGET = Hello_World

# top-level rule to create the program, executed by default if no parameters are provided
all: compile

# compiling the source file.
compile: $(SOURCES)
<TAB>$(COMPILER) $(CFLAGS) $(TARGET) $(SOURCES)

Save the file in the same folder as the source files using the filename Makefile. In a terminal window navigate to the folder in which the makefile was stored and enter the command make. Since no parameter is given, make executes the first dependency it finds; in this case all. Since this depends compile is searches for the compile dependency. Compile depends on the variable SOURCES (main.c) and the associated command is executed.

Next the copy command is included:

COMPILER = gcc-cris
CFLAGS = -mlinux -o
SOURCES = main.c MyUnit.c
TARGET = Hello_World
DESTINATION = root@FOXBoard:/mnt/flash/bin/HelloWorld

# top-level rule to create the program, executed by default if no params are provided
all: compile

# compiling the source file.

compile: $(SOURCES)

<TAB>$(COMPILER) $(CFLAGS) $(TARGET) $(SOURCES)
<TAB>scp $(TARGET) $(DESTINATION)

When executed, the application is now compiled and copied to the FB and the really cool part is that if during execution of the commands an error is detected all next commands are ignored! This might happen if (by accident of course) an error is made in the source code. The compiler than exits with a non-zero exit value, this prevents make from executing all other commands.

Sep 6

During every secure transaction with the FB the root password is requested. This is because the FB does not trust the public key of the development PC that is passed to the FB during any secure operation (e.g. ssh or scp). To prevent typing the password all the time the public key of the development PC can be added to the list of key that are authorized by the FB to gain access.

On the development PC, make sure you are logged in as the user that will also be used for development of FB applications. In a terminal window, enter the command ssh-keygen -t rsa, this will generate a public and private key pair. When prompted for the file in which the key will be save, press enter. Same for the prompts to enter a passphrase and to enter it for confirmation. This will generate the file id_rsa.pub in the /home/jan/.ssh folder. Copy this file to the FB using the scp /home/jan/.ssh/id_rsa.pub root@FOXBoard:/root/.ssh command. Now you still need to enter the password pass. In a second terminal, start a ssh terminal to the FB. In the folder /root/.ssh add the id_rsa.pub file to the file containing all authorization keys using the command cat id_rsa.pub >> authorized_keys. When finished, remove the public key using the command rm id_rsa.pub.

Now all secure actions should no longer ask for a password (e.g ssh and scp). This can be tested by closing the ssh terminal using the exit command and starting again the terminal using ssh root@FOXBoard, indeed, it is started without the password prompt.