Difference between revisions of "Creating a New EMAC OE SDK Project"
(Created page with "{| class="wikitable conventions" !colspan="2"|Table 1: Conventions |- | <code>/download/directory/</code> || Placeholder indicating the directory to which the SDK archive will...") |
|||
(10 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | {| | + | {{todo|SEOKWREV (11.26.13-20:35->MD+);(11.27.13-15:20-KY+);(12.5.13-18:20-MG+);(03.04.14-16:20->BS-);(03.20.14-15:45->BS+);(04.14.14-14:40->BS+)|Mike Dean|project=oe 4,oe 5,md,SEOKWREV,ky,mg,bs}} |
− | + | ||
− | + | {{#seo: | |
− | + | |title=Creating a New EMAC OE SDK Project | |
− | + | |titlemode=append | |
− | + | |keywords=Create EMAC SDK Project,Set Up EMACK Project | |
− | + | |description=EMAC OE SDK is a complete development kit for creating C/C++ applications for EMAC products. | |
− | + | }} | |
− | || | + | |
− | + | {{EMAC OE SDK Conventions}} | |
The EMAC OE SDK is a complete development kit for creating C/C++ applications for EMAC products. The SDK can be used to compile code anywhere in the development system. This procedure explains the process of creating and building a new project within the SDK. | The EMAC OE SDK is a complete development kit for creating C/C++ applications for EMAC products. The SDK can be used to compile code anywhere in the development system. This procedure explains the process of creating and building a new project within the SDK. | ||
Line 14: | Line 14: | ||
==New Project Procedure== | ==New Project Procedure== | ||
− | This guide assumes that the EMAC OE SDK has been | + | This guide assumes that the EMAC OE SDK has been installed and configured. It also assumes a basic familiarity with the C programming language and that a basic text editor is available. The example code calculates the perimeter of a right triangle given the length of its longest edge and the angle between that edge and one of the other edges. |
===Set Up the Project=== | ===Set Up the Project=== | ||
− | The first step | + | The first step is to create a project directory in <code>/path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects</code> directory. |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="console"> |
developer@ldc:~$ mkdir /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example | developer@ldc:~$ mkdir /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ||
+ | {{mbox | type=information | style = margin-bottom: 1em; | text = This directory is recommended to allow the user to easily leverage the use of the SDK. See the section below for [[Creating_a_New_EMAC_OE_SDK_Project#Alternate Project Locations | alternate project locations]].}} | ||
===Write the C Code=== | ===Write the C Code=== | ||
− | + | The C code for this example is listed below. Copy the code into a blank document and save as <code>example.c</code> in the project directory created above. | |
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
Line 56: | Line 57: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | '''Listing 1. example.c''' | ||
===Modify the Makefile=== | ===Modify the Makefile=== | ||
+ | |||
+ | Makefiles are used to tell the compiler what actions to perform. Makefiles are useful so that the developer does not have to remember a long list of compile options and source files that need to be compiled. | ||
====Create the New Makefile==== | ====Create the New Makefile==== | ||
− | + | The EMAC OE SDK provides a very basic Makefile that can be used for new projects and extended as needed. Navigate to the hello project in the SDK projects and copy the Makefile file to the current project directory. Or from the command line type: | |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="console"> |
developer@ldc:~$ cd /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example/ | developer@ldc:~$ cd /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example/ | ||
developer@ldc:~$ cp ../hello/Makefile ./ | developer@ldc:~$ cp ../hello/Makefile ./ | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | + | ====Configure What Source Files to Compile==== | |
+ | |||
+ | Open the Makefile in a text editor and modify the <code>CFILES</code> and <code>TARGET</code> variables as follows: | ||
* <code>CFILES=example.c</code> instead of <code>CFILES=hello.c</code> | * <code>CFILES=example.c</code> instead of <code>CFILES=hello.c</code> | ||
* <code>TARGET=example</code> instead of <code>TARGET=hello</code> | * <code>TARGET=example</code> instead of <code>TARGET=hello</code> | ||
− | This tells the Makefile that the source file used is <code>example.c</code>. | + | This tells the Makefile that the source file used is <code>example.c</code> and the resulting executable will be called <code>example</code>. The CFILES variable can be assigned a space-delimited list of C files for larger projects. |
+ | |||
+ | ====Configure Libraries to Link==== | ||
− | + | In order to use the trigonometric functions present in the source file, the math library must be included. To include the math library in the compilation process, add it to the LIBFLAGS variable on the line below CFILES. | |
− | |||
* <code>LIBFLAGS+=-lm</code> | * <code>LIBFLAGS+=-lm</code> | ||
− | + | The math library is <code>libm.so</code>. Other libraries may need to be included in custom projects that make use of advanced functions. | |
+ | |||
+ | {{mbox | type = notice | text = More detailed information on working with libraries and the linker under Linux can be found at [http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html YoLinux - Static, Shared Dynamic and Loadable Linux Libraries]}} | ||
− | |||
Listing 2 shows the complete modified makefile for the <code>example.c</code> project. | Listing 2 shows the complete modified makefile for the <code>example.c</code> project. | ||
Line 118: | Line 125: | ||
'''Listing 2. Modified Example Makefile''' | '''Listing 2. Modified Example Makefile''' | ||
+ | <!-- | ||
====Telling ''make'' About Make Targets==== | ====Telling ''make'' About Make Targets==== | ||
In <code>global.properties</code> there are also variables which must be modified in order for all the <code>make</code> targets to accomplish their purpose. For instructions on how to do this, please refer to the [[Remote Upload Set Up Guide]]. | In <code>global.properties</code> there are also variables which must be modified in order for all the <code>make</code> targets to accomplish their purpose. For instructions on how to do this, please refer to the [[Remote Upload Set Up Guide]]. | ||
+ | --> | ||
===Cross-Compile with the EMAC OE SDK=== | ===Cross-Compile with the EMAC OE SDK=== | ||
− | + | Using the Makefile created above, the GNU make utility will be used to compile the example source code into an application that can be run on the target machine. | |
+ | Change into the example project directory then execute the make targets as shown in Listing 3. For a description of each make target, read the bullet items below. | ||
− | + | <syntaxhighlight lang="console"> | |
− | |||
− | <syntaxhighlight lang=" | ||
developer@ldc:~$ cd /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example/ | developer@ldc:~$ cd /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example/ | ||
− | |||
− | |||
#### Target 1 #### | #### Target 1 #### | ||
− | |||
− | |||
developer@ldc:~$ make clean | developer@ldc:~$ make clean | ||
− | |||
− | |||
rm -f *.o *.gdb example example.d | rm -f *.o *.gdb example example.d | ||
#### Target 2 #### | #### Target 2 #### | ||
− | |||
− | |||
developer@ldc:~$ make all | developer@ldc:~$ make all | ||
− | |||
− | |||
../../gcc-4.2.4-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc -Wall -MMD -g -march=armv5te -mtune=arm926ej-s -o example.o -c example.c\ | ../../gcc-4.2.4-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc -Wall -MMD -g -march=armv5te -mtune=arm926ej-s -o example.o -c example.c\ | ||
../../gcc-4.2.4-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc example.o -lm -o example | ../../gcc-4.2.4-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc example.o -lm -o example | ||
#### Target 3 #### | #### Target 3 #### | ||
− | |||
− | |||
developer@ldc:~$ make upload | developer@ldc:~$ make upload | ||
− | |||
− | |||
wput --reupload --dont-continue sentence ftp://root:emac_inc@10.0.2.41/../../tmp/example | wput --reupload --dont-continue sentence ftp://root:emac_inc@10.0.2.41/../../tmp/example | ||
--16:52:48-- `app_name' | --16:52:48-- `app_name' | ||
Line 169: | Line 163: | ||
'''Listing 3. Example Make Target Invocation''' | '''Listing 3. Example Make Target Invocation''' | ||
− | * <code>make clean</code> removes all object, dependency, and executable files generated by previous invocations of make | + | |
− | * <code>make all</code> resolves dependencies for the source code necessary to cross-compile the target file. The <code>gcc</code> and <code>g++</code> | + | * <code>make clean</code> removes all object, dependency, and executable files generated by previous invocations of make. |
− | * <code>make upload</code> uses | + | * <code>make all</code> resolves dependencies for the source code necessary to cross-compile the target file and creates the target program provided there are no errors in the source code. The <code>gcc</code> and <code>g++</code> compilers used are specified in <code>global.properties</code>. |
+ | * <code>make upload</code> uses ftp to transfer the executable file to the target device. The username and password used to connect to the target device are stored in <code>global.properties</code> | ||
===Optional global.properties Modifications=== | ===Optional global.properties Modifications=== | ||
Line 177: | Line 172: | ||
In order to debug applications effectively, the <code>-g</code> debug flag must be specified when running the compiler. This is set up to occur automatically by its inclusion in the <code>global.properties CFLAGS</code> variable. | In order to debug applications effectively, the <code>-g</code> debug flag must be specified when running the compiler. This is set up to occur automatically by its inclusion in the <code>global.properties CFLAGS</code> variable. | ||
− | For release builds, however, this can be harmful to the application's performance | + | For release builds, however, this can be harmful to the application's performance. In a typical general-purpose computer this may not be noticeable, but for embedded systems there are typically memory and disk limitations. For production or release versions of an application it is recommended to replace <code>-g</code> with <code>-g0</code> which tells the compiler not to include debug information in the executable. |
− | + | To get information about a particular file, use the <code>file</code> command: | |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="console"> |
developer@ldc:~$ file myexecutable | developer@ldc:~$ file myexecutable | ||
+ | myexecutable: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | The stripped/not stripped field of the output tells weather the executable contains debugging symbols. Debugging symbols can be removed from an executable without recompiling using the <code>strip</code> command: | ||
+ | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
− | myexecutable | + | developer@ldc:~$ strip myexecutable |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ||
− | <syntaxhighlight lang=" | + | To verify that the executable was stripped, run <code>file</code> again: |
− | developer@ldc:~$ | + | |
+ | <syntaxhighlight lang="console"> | ||
+ | developer@ldc:~$ file myexecutable | ||
+ | myexecutable: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, stripped | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | If | + | |
+ | |||
+ | ==Alternate Project Locations== | ||
+ | If the project is created outside of the /path/to/sdk/projects directory, the paths present in the Makefile and the path to the SDK in the global.properties files will need to be modified as below. | ||
+ | |||
+ | <cl> | ||
+ | |||
+ | 1. Copy the correct ''global.properties'' file from the ''SDK/projects'' directory to the current project directory | ||
+ | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | developer@ldc:~$ | + | developer@ldc:~$ cp -L /path/to/sdk/projects/global.properties /path/to/project/hello |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | * Modify the ''include'' line at the top of the make file to refer to the new ''global.properties'' file | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
− | + | include global.properties | |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | * Change the value of <code>SDKBASE</code> in ''global.properties'' to point to the location of the SDK installation. | |
+ | |||
+ | </cl> | ||
==Next Steps== | ==Next Steps== | ||
− | Once the target binary has been compiled, the project is ready to be debugged. | + | Once the target binary has been compiled, the project is ready to be executed and debugged. |
− | + | [[Remote_Debugging_EMAC_OE_SDK_Projects_with_gdbserver | Remote Debugging with gdbserver ]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | <!--[[Category:EMAC OE SDK]]--> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 13:41, 14 April 2014
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 a complete development kit for creating C/C++ applications for EMAC products. The SDK can be used to compile code anywhere in the development system. This procedure explains the process of creating and building a new project within the SDK.
New Project Procedure
This guide assumes that the EMAC OE SDK has been installed and configured. It also assumes a basic familiarity with the C programming language and that a basic text editor is available. The example code calculates the perimeter of a right triangle given the length of its longest edge and the angle between that edge and one of the other edges.
Set Up the Project
The first step is to create a project directory in /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects
directory.
developer@ldc:~$ mkdir /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example
This directory is recommended to allow the user to easily leverage the use of the SDK. See the section below for alternate project locations. |
Write the C Code
The C code for this example is listed below. Copy the code into a blank document and save as example.c
in the project directory created above.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define HYP 10.0
#define DEG 30.0
int main(void)
{
float opp, adj;
opp = HYP * sin(DEG);
adj = HYP * cos(DEG);
printf("Hypotenuse: \t%3.2f\n", HYP);
printf("Angle: \t\t%3.2f\n", DEG);
printf("Opposite Side: \t%3.2f\n", opp);
printf("Adjacent Side: \t%3.2f\n", adj);
printf("%3.2f + %3.2f + %3.2f = %3.2f \n", HYP, opp, adj, (HYP + opp + adj));
exit(EXIT_SUCCESS);
}
Listing 1. example.c
Modify the Makefile
Makefiles are used to tell the compiler what actions to perform. Makefiles are useful so that the developer does not have to remember a long list of compile options and source files that need to be compiled.
Create the New Makefile
The EMAC OE SDK provides a very basic Makefile that can be used for new projects and extended as needed. Navigate to the hello project in the SDK projects and copy the Makefile file to the current project directory. Or from the command line type:
developer@ldc:~$ cd /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example/
developer@ldc:~$ cp ../hello/Makefile ./
Configure What Source Files to Compile
Open the Makefile in a text editor and modify the CFILES
and TARGET
variables as follows:
CFILES=example.c
instead ofCFILES=hello.c
TARGET=example
instead ofTARGET=hello
This tells the Makefile that the source file used is example.c
and the resulting executable will be called example
. The CFILES variable can be assigned a space-delimited list of C files for larger projects.
Configure Libraries to Link
In order to use the trigonometric functions present in the source file, the math library must be included. To include the math library in the compilation process, add it to the LIBFLAGS variable on the line below CFILES.
LIBFLAGS+=-lm
The math library is libm.so
. Other libraries may need to be included in custom projects that make use of advanced functions.
More detailed information on working with libraries and the linker under Linux can be found at YoLinux - Static, Shared Dynamic and Loadable Linux Libraries |
Listing 2 shows the complete modified makefile for the example.c
project.
include ../global.properties
TARGET=example
CFILES=example.c
LIBFLAGS+=-lm
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 2. Modified Example Makefile
Cross-Compile with the EMAC OE SDK
Using the Makefile created above, the GNU make utility will be used to compile the example source code into an application that can be run on the target machine. Change into the example project directory then execute the make targets as shown in Listing 3. For a description of each make target, read the bullet items below.
developer@ldc:~$ cd /path/to/sdk/EMAC-OE-arm-linux-gnueabi-SDK_XX.YY/projects/example/
#### Target 1 ####
developer@ldc:~$ make clean
rm -f *.o *.gdb example example.d
#### Target 2 ####
developer@ldc:~$ make all
../../gcc-4.2.4-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc -Wall -MMD -g -march=armv5te -mtune=arm926ej-s -o example.o -c example.c\
../../gcc-4.2.4-arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc example.o -lm -o example
#### Target 3 ####
developer@ldc:~$ make upload
wput --reupload --dont-continue sentence ftp://root:emac_inc@10.0.2.41/../../tmp/example
--16:52:48-- `app_name'
=> ftp://root:xxxxx@10.0.2.41:21/../../tmp/example
Connecting to 10.0.2.41:21... connected!
Logging in as root ... Logged in!
Length: 13,774
16:52:48 (example) - `350.6K/s' [13774]
FINISHED --16:52:48--
Transfered 13,774 bytes in 1 file at 107.3K/s
Listing 3. Example Make Target Invocation
make clean
removes all object, dependency, and executable files generated by previous invocations of make.make all
resolves dependencies for the source code necessary to cross-compile the target file and creates the target program provided there are no errors in the source code. Thegcc
andg++
compilers used are specified inglobal.properties
.make upload
uses ftp to transfer the executable file to the target device. The username and password used to connect to the target device are stored inglobal.properties
Optional global.properties Modifications
In order to debug applications effectively, the -g
debug flag must be specified when running the compiler. This is set up to occur automatically by its inclusion in the global.properties CFLAGS
variable.
For release builds, however, this can be harmful to the application's performance. In a typical general-purpose computer this may not be noticeable, but for embedded systems there are typically memory and disk limitations. For production or release versions of an application it is recommended to replace -g
with -g0
which tells the compiler not to include debug information in the executable.
To get information about a particular file, use the file
command:
developer@ldc:~$ file myexecutable
myexecutable: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped
The stripped/not stripped field of the output tells weather the executable contains debugging symbols. Debugging symbols can be removed from an executable without recompiling using the strip
command:
developer@ldc:~$ strip myexecutable
To verify that the executable was stripped, run file
again:
developer@ldc:~$ file myexecutable
myexecutable: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, stripped
Alternate Project Locations
If the project is created outside of the /path/to/sdk/projects directory, the paths present in the Makefile and the path to the SDK in the global.properties files will need to be modified as below.
-
Copy the correct global.properties file from the SDK/projects directory to the current project directory
developer@ldc:~$ cp -L /path/to/sdk/projects/global.properties /path/to/project/hello
-
Modify the include line at the top of the make file to refer to the new global.properties file
include global.properties
-
Change the value of
SDKBASE
in global.properties to point to the location of the SDK installation.
Next Steps
Once the target binary has been compiled, the project is ready to be executed and debugged.
Remote Debugging with gdbserver