Using EMAC OE SDK Example Projects

From wiki.emacinc.com
Revision as of 22:40, 1 October 2013 by Mdean (talk | contribs)
Jump to: navigation, search
TODO: {{#todo:Make sure there is an OE 4 and OE 5 version; OE 5 will use CMake|Michael Gloff|oe 4,oe 5,mg}}
Table 1: Conventions
/download/directory/ The directory to which the SDK archive will be downloaded.
/path/to/sdk/ The directory to which the SDK will be extracted.
EMAC-OE-arm-linux-gnueabi-SDK_XX.YY.rZZ.tar.bz2
EMAC-OE-arm-linux-gnueabi-SDK_XX.YY
XX - the SDK major version
YY - the SDK minor version
ZZ - the SDK current revision
target_program The program executable created to run on the target device.
developer@ldc:~$
Prompt and commands to be run on a development machine that will run compliation tasks.
root@emac-oe:~#
Prompt and commands to be run on a target machine.

The EMAC OE SDK is distributed with a set of example projects intended to demonstrate how to use the EMAC OE toolchain and libraries. This guide demonstrates the process of compiling one of the example projects and running it on the target machine. NOTE: It is assumed that the procedure in the EMAC OE SDK Configuration Guide has been followed prior to reading this page.

This guide consists of two example files, a C file and a Makefile. They are located within Listing 2 and Listing 3, respectively.

Tools

  • GNU make. Manages project dependencies.
  • EMAC OE SDK. [See the EMAC OE SDK Install Page].
  • wput, Provides FTP capability to the build process.

EMAC SDK Example: Compile the "hello" Project

This procedure provides an overview of how to compile and run C applications for EMAC products. It assumes familiarity with the C programming language and is intended to be used by experienced programmers who are looking to learn the EMAC SDK. The “hello” example project source can be found in the projects/ subdirectory of the EMAC OE SDK root directory. The full path to the source is as follows:

/path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/hello/

Cross-compile the program using GNU Make.

developer@ldc:~$ cd /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/hello/
developer@ldc:~$ make all

all is a make target. This command is the equivalent to the commonly seen, Build All command found in most IDE's. The build system will only compile files which have been modified since the last build.

Alternatively, you can simply run:

developer@ldc:~$ make

When make is run by itself, it chooses its default make target. In this example, all is the default make target. In any normal project, the default make target will be the one which builds the project. This allows a programmer to simply run make most of the time they are doing development work.

The Makefile based build system fully supports incremental builds. Should you desire a full rebuild, two steps will need to be followed instead of one:

developer@ldc:~$ make clean
developer@ldc:~$ make

The make clean command will delete any object files (these have the .o extension in the gcc on Linux build system), debugger information files (with the .gdb extension), executable binaries (generally, no extension) and any other files which are generated during the build process. Once this cleaning step is complete, the build system will attempt to rebuild everything.

For a more in-depth explanation on how gcc approaches the incremental build process, see the GNU "make" Manual.

EMAC SDK Example: Uploading and Running the "hello" Project"

Uploading the Program to the Target Machine

developer@ldc:~$ make upload

upload is another make target. This command will send your freshly compiled binary to the target machine.

This make target uses the development system's wput program to send the binary to the target machine through FTP. This is accomplished using variables stored in the global.properties file, which is included in the Makefile using the include keyword. The global.properties file also contains variables which make passes to the compiler to ensure that the executable produced is compatible with the target CPU architecture.

Running the Program on the Target Machine

Connect remotely to the target machine. Run the program as shown in Listing 1 using the remote connection.

root@emac-oe:~# chmod u+x /tmp/hello
root@emac-oe:~# /tmp/hello

Listing 1. Running the Remote Application

If the file compiles without trouble but has runtime bugs, you can remotely debug the application using gdbserver. Read the EMAC OE SDK Remote Debugging Guide to learn more.

Example C File

This C file can be used by programmers as an example to ensure their build configuration for EMAC products is functioning correctly.

/**
 * @file hello.c
 *
 * Simple Hello World application for EMAC OE.
 *
 * @author EMAC, Inc. <support@emacinc.com>
 */
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
 
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
    printf("Hello EMAC OE!\n");
    exit(EXIT_SUCCESS);
}

Listing 2. "Hello World" example project

Example Makefile

Listing 3 shows the default Makefile used for the hello example project. This is a necessary component of the EMAC SDK which directs GNU Make in resolving source code dependencies before calling the cross-compiler to create a binary for the target platform. It also provides a convenient upload target which utilizes the development system's wput command to send the compiled binary to the target system.

include ../global.properties
 
TARGET=hello
CFILES=hello.c
 
 
OBJS=$(CFILES:.c=.o)
DEPS=$(OBJS:.o=.d)
 
all: $(TARGET)
 
$(TARGET): $(OBJS) Makefile
  $(CC) $(VERBOSE) $(OBJS) $(OFLAGS) $(LIBFLAGS) $(SLIBS) -o $@
 
%.o: %.c
  $(CC) $(VERBOSE) $(CFLAGS) -o $@ -c $<
 
clean:
  $(RM) *.o *.gdb $(TARGET) $(DEPS)
 
upload: all
  $(WPUT) $(TARGET) ftp://$(LOGIN):$(PASSWORD)@$(TARGET_IP)/../../tmp/$(TARGET)
 
 
-include $(DEPS)

Listing 3. Example EMAC OE SDK Makefile

Next Steps

After compiling and running an example project, the next step is to create a new project. The EMAC OE SDK New Project Guide details this process from start to finish.