Getting Started with the EMAC OE SDK
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 page demonstrates the process of compiling an example project and running it on the target machine. Also, it provides a straightforward guide to the essential steps you need to follow to get started with cross compiling a simple program with gcc and running the program on your embedded machine.
 General Information
EMAC provides a toolchain you can extract and install The recent Ubuntu LTS releases have been thoroughly tested with the EMAC SDK and tools and are fully supported by EMAC. Given the large number of alternate Linux distributions available, EMAC is only able to provide limited support (in the form of a manually installed tarball) for other Linux distributions.
Each SDK includes the C/C++ header files and libraries compatible with the target hardware. It also includes the C/C++ cross-compiler toolchain components necessary to compile and debug custom application code. The links below will help you get started building and running the example projects on the target hardware.
More information on using Qt Creator with the EMAC SDK is available on the Getting Started With Qt Creator page.
 Getting Started with the EMAC OE SDK
 Installing EMAC SDK
 Connecting to a Target Board
A machine running EMAC OE Linux can be connected to through a serial port or through a network cable. EMAC OE Linux allows users to log in via getty, and SSH (Secure Shell). A getty can be accessed via a serial connection (through a console) while SSH utilizes a network connection. More information on establishing a physical connection to a board is available on the Serial Connections and Network Connections page.
The next step after establishing a physical connection to the board is logging in. For more information visit the System Log In page.
 Setting the Filesystem to Read-Write
The root filesystem on a machine running EMAC OE Linux is mounted read-only by default. In order to put files on the board, you may need to make the filesystem read-write. The Linux Filesystem Organization page has more information regarding which parts of the filesystem are mounted read-only by default versus which parts are always writeable. Note that EMAC recommends installing your program into a read-only portion of the filesystem (according to the guide) to safeguard it from filesystem corruption (such as may be caused by removing power from the board without shutting down the operating system first, which is normal in embedded systems).
To remount the root filesytem in read-write mode, enter the following into the terminal:
|This will only change the root filesystem to read-write for the current boot. When the system is rebooted, the root filesystem will once again be mounted read-only.|
 Transferring Files
The command line syntax for transferring a file using the SSH protocol is
scp file user@host:/directory. SCP, or Secure Copy, is a way of securely transferring files between a local and remote host. For example, to send the file example.text to the
/home directory of a system with the IP address 10.0.6.221, enter the following command:
Alternatively, you can leave off the path after the colon if you want the file to go directly into the home directory.
|This copy operation will fail if the filesystem on the remote machine is mounted read-only, which is the default on most EMAC systems. If you experience this failure, remount the root filesystem read-write (see above) and try again.|
 Remote Execution
SSH can also be used to execute programs on remote systems without logging in. The syntax for SSH remote execution is
ssh user@host "my_command -args file". The following is an example of a command to run a program on a board with the IP address 10.0.6.221.
 Basic Compiling
The two subsections below show the two common options for how to compile source code. The first subsection demonstrates how to use the EMAC CMake tool, while the second subsection demonstrates how to compile c code manually .
 CMake Compiling
 Host Machine Compiling
This section demonstrates how to use the EMAC CMake tool to generate CMake files automatically for a project. When using the EMAC SDK there are currently two options for cross compiling:
For the purposes of this guide, the arm option will be used for the listed examples.
Navigate to the directory where the project will be located. Then run the CMake new project script.
The executable, in this case, is now inside the
 Target Machine Compiling
The CMake project script has now made a project directory that contains the following:
- Source code file (hello.c in this case)
- README file
- Desktop Build Directory (hello_emac-build in this case)
The CMakeLists.txt contains the required information to automatically create a Makefile for a given architecture. This was created by the EMAC oe_init_project script, and will need to be modified over time as a project grows. The comments in the file generated by the EMAC tool will provide a good starting point for how to add additional source files and how to perform other common tasks related to maintaining your CMake build system as your project grows. The CMake project provides extensive documentation on how to work with these files.
The source code file generated by the script (hello.c) contains a basic Hello World style program.
The README file contains more information on using CMake with the EMAC 5.X SDK.
The Desktop Build Directory (hello_emac-build) contains the executable hello_emac, the Makefile, and various cache files. These were automatically created by CMake and by the build system, and can be recreated at any time.
It is useful to have a Desktop Build Directory because it is easier (in the beginning) to use the desktop to verify all code changes before cross-compiling for a target board. This will be useful until the application under development depends upon resources which are only available on the target hardware, such as certain devices drivers or the touchscreen (if so equipped).
Use the following steps to cross-compile the project and send it to a target board.
In a terminal, navigate to the base directory of the project.
NOTE If the target board being used is x86, then change all occurrences of arm in the following sections below to x86.
Create a build directory for cross compiling.
Change directories into the newly created directory.
Run cmake using the target architecture.
Compile the code using make.
makecommand creates the target executable in the
Now copy the executable to the target board. For information on copying the executable file, see the Transferring Files section.
 Manual Compiling
 Host Machine Compiling
|In these examples we are using the Ipac-9x25 board. Your board's processor's architecture will determine which file needs to be sourced. These files come from the EMAC SDK toolchain.|
Create a file called hello.c using a text editor such as vi, vim, nano, or gedit. Then copy and paste the source code from the Hello World System Log Example section in the text editor of your choice.
Once you've created and saved the file with the source code, use the following syntax to compile the program called hello.c:
If there is no error in your code then the compiler will successfully create an executable file called hello in the current directory.
To verify this, enter the following command:
To run the program, enter the following command:
 Target Board Compiling
To compile for the target board, you must
Once you are in the directory with the source file, enter the following command:
|Once you source the file in your current terminal, you can only use it to cross-compile your program for the target board. You can no longer compile it for your host machine. To compile it to your host machine, simply open a new terminal.|
After sourcing the file, copy the program over to the target board using
scp. Enter the following command:
After copying the program, you can now execute the program on the target board. Enter the following command:
 Linux Filesystem Organization
In order to prevent confusion and promote portability, a standard was created for the organization of the Linux filesystem. To ensure future portability of software created today, promote maintainability of software, and ensure proper utilization of available storage on an embedded machine, this standard should be followed as much as possible. This document covers parts of the standard and gives information about the customizations made to it by EMAC OE to accommodate embedded hardware. A link is provided to the standards document which covers the organization of the Linux filesystem at the end of this document. For more information visit the Linux Filesystem Organization page.
EMAC recommends /usr/local/bin as the location for software you deploy.
|It is important to pay attention to the filesystem structure in order to ensure that your application will work as expected when the filesystem is in production. Reasons for this include:
 Remote Debugging
When working with embedded systems the binary is usually compiled on a development machine with a different CPU architecture than what is on the target machine. This can be a problem when, as is typically the case, the target machine lacks the system resources to run a debugger. In these cases, it is possible to use the GNU debugger (gdb) on the development machine to remotely debug the target machine provided it has a flavor-matched version of a program named gdbserver. All EMAC OE builds are packaged with a flavor-matched gdbserver to simplify the setup process for developers.
|A flavor-matched gdbserver is one which is built against the same source code revision as the gdb client for your desktop, because gdb does not have a stable interface for attaching to the gdbserver. In fact, the interface changes slightly with almost every release, so if you find yourself having difficulty getting gdb and gdbserver to communicate with each other, make sure they're the exact same version before trying any other debugging steps.|
For more information visit the Remote Debugging EMAC OE SDK Projects with gdbserver page.
 Hello World System Log Example
This example will print
Hello EMAC OE! to the syslog facility as well as the console. This will allow you to log, debug, and send status messages to the system logger.
To compile and run this program, see the sections above.
int main(int argc, char** argv)
char message = "Hello EMAC OE!";
openlog("slog", LOG_PID|LOG_CONS, LOG_USER);
syslog(LOG_INFO, "%s", message);
This is extremely useful because it allows you to save a record of the output that you might not see first hand.
To verify the output of the program went into syslog, enter the following command:
As you can see on the bottom line, your program output has been recorded and date stamped in syslog.
For more information on system logging visit the System Logging page.