Hello World

This guide will walkthrough the creation and compilation of a Hello World executable intended to run directly on the phyCORE-AM57x Development Kit running Linux.

Native Compilation (On the Target)

Target Image Setup

By default, the BSP-Yocto-AM57x-PD23.1.0 phytec-qt5demo-image doesn’t include build tools such as gcc, make, git, etc. In order to build your applications on the target natively, these packages will have to be added to your target image first.

First, complete the setup steps outlined in the Build the BSP guide.

Once setup, modify your $BUILDDIR/conf/local.conf:

Host (Ubuntu)

vi $BUILDDIR/conf/local.conf

Add the following line to the end of the file:

$BUILDDIR/conf/local.conf

IMAGE_INSTALL_append = " packagegroup-core-buildessential"

Now rebuild your target image and then use it to boot your phyCORE-AM57x Development Kit into Linux.

Host (Ubuntu)

bitbake phytec-qt5demo-image

Write your HelloWorld Code

Let’s make a project directory to contain the Hello World source code:

Target (Linux)

mkdir ~/helloworld-project
cd ~/helloworld-project

Create the main Hello World application source code file using your favorite text editor, this guide will leverage ‘vi’ but ‘nano’ is a more beginner friendly option:

Target (Linux)

vi helloworld.c

Note

The vi text editor begins in “Command Mode” and you must first hit the ‘i’ key in order to enter “Insert Mode”. Using the arrow keys to navigate, make the necessary changes and then hit ESC to go back to “Command mode”. Now enter “:wq” to write the file and quit.

Pro Tip: Use the right click on your mouse to paste! This will only work if you are in “Insert Mode” first.

Edit the contents of the file to reflect the following and remember to save your changes when you are done!

#include <stdio.h>

int main()
{
        printf("Hello World!\n");
}

Compile the project.

Target (Linux)

gcc -O helloworld.c -o helloworld

Run the binary:

Target (Linux)

./helloworld

You should see the following output:

Example Output

root@phycore-am57xx-1:~# ./helloworld
Hello World!

Cross-Compilation (On a Linux Host Machine)

Once you follow the Build the BSP guide to help you build a SDK installer (or install a pre-built one), and then run through the Install The SDK guide to install it and then source it, you can leverage the computing resources and development tools available to your Linux Host Machine to compile applications intended to run on the phyCORE-AM57x Development Kit.

Basically, you can create the helloworld.c file using the same steps above using your Linux Host Machine’s Terminal and then use the cross-compilation toolchain to compile your application to run on a different architecture (in this case it would be the ARM architecture):

Host (Ubuntu)

$CC -O helloworld.c -o helloworld

Once built, you can confirm the target architecture the binary is intended for using the ‘file’ utility:

Host (Ubuntu)

phytec@ubuntu:~$ file helloworld
hello: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=dc8a85866d965e6a45eff08156df82c14faac5db, for GNU/Linux 3.2.0, with debug_info, not stripped

You’ll notice errors if you try to run this binary on the Host Machine. Check out the Copying Files to the Device Guide to help you transfer it to the phyCORE-AM57x Development Kit such that you can execute it.