-
Notifications
You must be signed in to change notification settings - Fork 54
Cross Compile with Yocto SDK
Cross-compiling and remote debugging for Gumstix COMs right on your workstation is the desired method to do application development. This article describes how to obtain, install and use the cross development kit - Yocto SDK.
You can download the SDK from Gumstix website. It is built based on the gumstix-console-image
. It contains the same tool-chains used to build the image.
We will create a directory called workspace
where you will not only install the SDK, but also compile the example code in. Choose a convenient location for you.
$ mkdir workspace
$ cd workspace
$ wget http://gumstix-yocto.s3.amazonaws.com/sdk.sh
Pro Tip: You can run bitbake gumstix-console-image -c populate_sdk
to create your own SDK.
Within the workspace
directory, let's install the SDK:
#Install it to `workspace/sdk`
$ ./sdk.sh
Enter target directory for SDK (default: /opt/poky/1.7.2): ~/home/workspace/sdk/
You will notice these files in the workspace/sdk
directory:
* environment-setup-cortexa8hf-vfp-neon-poky-linux-gnueabi
* site-config-cortexa8hf-vfp-neon-poky-linux-gnueabi
* sysroots
* version-cortexa8hf-vfp-neon-poky-linux-gnueabi
The first file is the environment setup file which exports important paths and variables. And the sysroots
directory contains the target and the host system root file systems.
Before we can use the SDK, you need to source the environment:
$ source sdk/environment-setup-cortexa8hf-vfp-neon-poky-linux-gnueabi
Let's create an empty file helloworld.c
and paste the following in:
#include <stdio.h>
int main(void)
{
printf ("Hello World!\n");
return 0;
}
Now we can compile it:
$ make helloworld
The output of the above is:
arm-poky-linux-gnueabi-gcc -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8
--sysroot=/opt/poky/1.7.2/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi -O2 -pipe -g -feliminate-unused
debug-types -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed helloworld.c -o helloworld
The magical make
expands to this command because it is using the SDK environment variables which you sourced earlier:
* CC="arm-poky-linux-gnueabi-gcc -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8
--sysroot=$SDKTARGETSYSROOT"
* SDKTARGETSYSROOT=/home/workspace/sdk/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi
* CFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types"
* LDFLAGS="-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed"
You should notice the output binary.
$ ls
helloworld helloworld.c
We first need to install the GDB Server on the COM:
$ smart update
$ smart install packagegroup-core-tools-debug
Copy the binary over to your Gumstix COM:
$ scp helloworld [email protected]:/usr/bin/helloworld
Start the GDB server on your COM:
root@overo:~# gdbserver localhost:2345 /usr/bin/helloworld
Process /usr/bin/helloworld created; pid = 1896
Listening on port 2345
From your host machine (workstation), you can run cross-gdb:
$ arm-poky-linux-gnueabi-gdb helloworld
If arm-poky-linux-genuabi-gdb
is not found, be sure to source the SDK environment file again.
Now you can connect GDB to the GDB Server running on the COM. Type the following command from GDB using your COM's IP address:
# Substitute the ip address '192.168.1.125' with your COM's address
(gdb) target remote 192.168.1.125:2345
We can put a breakpoint at main()
:
(gdb) break main
Breakpoint 1 at 0x82f4: file helloworld.c, line 4.
It will then stop at main():
(gdb) continue
continue
Continuing.
Breakpoint 1, main () at helloworld.c:4
4 printf ("Hello World!\n");
(gdb)