Application Development
Cross-Compiling Applications Running make cross-compiles your applications according to the environment settings. By installing a Cross-Compilation Toolchain for your target, the environment variables are set up for cross-compilation. For more details, see . Once the cross-compilation environment is set up, you can make your applications as usual and get them compiled for your target. Below you see how to cross-compile from the command line. If Eclipse is installed, you can also cross-compile your code from the Eclipse IDE. For more details, see . Create a Makefile for your application. Example of a simple Makefile and application: helloworld:helloworld.o $(CC) -o helloworld helloworld.o clean: rm -f *.o helloworld #include <stdio.h> int main(void) { printf("Hello World\n"); return 0; } Run make to cross-compile your application according to the environment set up: $ make If the build fails, check if the GNU Make workaround solves your problem. Copy the helloworld program to your target and run it: # ./helloworld Hello World
Cross-Compiling Kernel modules Running make cross-compiles your kernel modules according to the environment settings. By installing a Cross-Compilation Toolchain for your target, the environment variables are set up for cross-compilation. For more details, see . Before cross-compiling kernel modules, you need to make sure the installed toolchain includes the kernel source tree, which should be available at: <sdkdir>/sysroots/<targetarch>-enea-linux/usr/src/kernel. If the kernel source tree is not included in the toolchain, you need to add the kernel-dev package into the image recipe enea-image-<name> and build the toolchain again. Once the cross-compilation environment is set up, you can make your kernel modules as usual and get them compiled for your target. Below you see how to cross-compile a kernel module. Create a Makefile for the kernel module. Example of a simple Makefile and kernel module: obj-m := hello.o PWD := $(shell pwd) KERNEL_SRC := <full path to kernel source tree> all: scripts $(MAKE) -C $(KERNEL_SRC) M=$(PWD) LDFLAGS="" modules scripts: $(MAKE) -C $(KERNEL_SRC) scripts clean: $(MAKE) -C $(KERNEL_SRC) M=$(PWD) LDFLAGS="" clean #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ #include <linux/init.h> /* Needed for the macros */ static int __init hello_start(void) { printk(KERN_INFO "Loading hello module...\n"); printk(KERN_INFO "Hello, world\n"); return 0; } static void __exit hello_end(void) { printk(KERN_INFO "Goodbye, world\n"); } module_init(hello_start); module_exit(hello_end); MODULE_LICENSE("GPL"); Run make to cross-compile your kernel module according to the environment set up: $ make Copy the kernel module hello.ko to your target and install/remove it: # insmod hello.ko # rmmod hello.ko # dmesg [...] Loading hello module... [...] Hello, world [...] Goodbye, world
Add an Application using devtool As a prerequisite, you need to install the SDK and set up the environment. For this, see . The following section, Use devtool add to Add an Application, in Yocto Project Software Development Kit (SDK) Developer's Guide, explains how to use devtool to generate recipes from existing application code, edit and build recipes, and deploy the output on target. If needed, replace the Yocto version in the link. This example will show how to generate a recipe from the existing application code and Makefile, edit the recipe in order to provide an installation path for the application, build the recipe, and deploy the output on a target, or create a DEB package from the recipe and install the package. Create a simple application and Makefile in <workspace_dir>/my_app: <workspace_dir>/my_app/my_hello_app.c #include <stdio.h> int main(void) { printf("Hello world!\n"); return 0; } <workspace_dir>/my_app/Makefile my_hello_app: Generate a recipe (my-hello-recipe) using the source tree of the application (<workspace_dir>/my_app): $ devtool add my-hello-recipe <workspace_dir>/my_app NOTE: Using source tree as build directory since that would be the default for this recipe NOTE: Recipe <SDK_dir>/workspace/recipes/my-hello-recipe/my-hello-recipe.bb has been automatically created; further editing may be required to make it fully functional $ cat <SDK_dir>/workspace/recipes/my-hello-recipe/my-hello-recipe.bb # Recipe created by recipetool # This is the basis of a recipe and may need further editing in order to be fully # functional. # (Feel free to remove these comments when editing.) # # Unable to find any files that looked like license statements. Check the # accompanying documentation and source headers and set LICENSE and # LIC_FILES_CHKSUM accordingly. # # NOTE: LICENSE is being set to "CLOSED" to allow you to at least start building - if # this is not accurate with respect to the licensing of the software being built (it # will not be in most cases) you must specify the correct value before using this # recipe for anything other than initial testing/development! LICENSE = "CLOSED" LIC_FILES_CHKSUM = "" # No information for SRC_URI yet (only an external source tree was specified) SRC_URI = "" # NOTE: this is a Makefile-only piece of software, so we cannot generate much of the # recipe automatically - you will need to examine the Makefile yourself and ensure # that the appropriate arguments are passed in. do_configure () { # Specify any needed configure commands here : } do_compile () { # You will almost certainly need to add additional arguments here oe_runmake } do_install () { # NOTE: unable to determine what to put here - there is a Makefile but no # target named "install", so you will need to define this yourself : } Edit the recipe to provide an installation path for the application: $ devtool edit-recipe my-hello-recipe $ cat <SDK_dir>/workspace/recipes/my-hello-recipe/my-hello-recipe.bb ... do_install () { # NOTE: unable to determine what to put here - there is a Makefile but no # target named "install", so you will need to define this yourself install -d ${D}${bindir} install -m 0777 ${S}/my_hello_app ${D}${bindir} } ... Build the recipe: $ devtool build my-hello-recipe The recipe build results can be seen here: <SDK_dir>/tmp/work/<arch>-enea-linux/my-hello-recipe/1.0-r0/ Deploy the output (in this case, the application) on target: $ devtool deploy-target my-hello-recipe root@<target_ip_address> Parsing recipes..done. NOTE: Successfully deployed <SDK_dir>/tmp/work/<arch>-enea-linux/my-hello-recipe/1.0-r0/image As an alternative you can create a DEB package: $ devtool package my-hello-recipe ... NOTE: Your packages are in <SDK_dir>/tmp/deploy/deb Then copy the DEB package on the target and install it using dpkg: # dpkg -i my-hello-recipe-1.0-r0.1.<arch>.deb