Let us have a look on basic cross compilation of Helloworld program for warp7 board.
There are 3 steps in this tutorial:
1) Installation of cross compilation tool:
2) Writing a helloworld and cross compiling for the target board
3) To copy the executable into the warp7 and execute it.
The cross-toolchain consists of a cross-compiler, cross-linker, and cross-debugger that are used to develop user-space applications for targeted hardware. This toolchain is created either by running the ADT Installer script, a toolchain installer script, or through aBuild Directory that is based on your metadata configuration or extension for your targeted device. The cross-toolchain works with a matching target sysroot.
Step-1:
$bitbake <image> -c populate_sdk
In my case image is “fsl-image-machine-test”
i.e
$ bitbake fsl-image-machine-test -c populate_sdk
or
$ bitbake meta-toolchain
Then you can find the poky installation at
/home/bheema/fsl-warp7-yocto/build-x11-machine-test/tmp/deploy/sdk/
Next we need to install the tool chain, by giving below command:
root@Bheema:~/warp_appln# cd /home/bheema/fsl-warp7-yocto/build-x11-machine-test/tmp/deploy/sdk
root@Bheema:~/fsl-warp7-yocto/build-x11-machine-test/tmp/deploy/sdk# ./poky-glibc-x86_64-meta-toolchain-cortexa7hf-neon-toolchain-2.1.2.sh
the installation will ask default location /opt/poky/2.1.2
proceed further as shown below snap
now the toolchain has been installed in /opt/poky/2.1.2 folder
Step-2 :
I have created my working folder as “warp_appln” under home directory create helloworld.c with below contents inside this directory:
root@Bheema:~/warp_appln# gedit helloworld.c
#include <stdio.h>
int main()
{
printf("hello world\n");
return 0;
}
in order to compile we need to source the toolchain to working folder
root@Bheema:~/warp_appln# source /opt/poky/2.1.2/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
we can compile the helloworld.c in 3 different ways as shown below:
a:
root@Bheema:~/warp_appln# ${CC} helloworld.c -o helloworld1.out
The cross-toolchain works with a matching target sysroot.
${CC} is macro defined while we source the toolchain. 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
is the path of installed toolchain:
SDKTARGETSYSROOT =
/opt/poky/2.1.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi/
The matching target sysroot contains needed headers and libraries for generating binaries that run on the target architecture. The sysroot is based on the target root filesystem image that is built by the OpenEmbedded build system Poky and uses the same metadata configuration used to build the cross-toolchain.
b:
Optionally to compile our helloworld you can give below command
root@Bheema:~/warp_appln# arm-poky-linux-gnueabi-gcc -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/poky/2.1.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi helloworld.c -o helloworld2.out
c:
Another method is to create “Makefile” inside “warp_appln” working folder with below contents
root@Bheema:~/warp_appln# gedit Makefile
CROSS=arm-poky-linux-gnueabi-
all:
${CC} helloworld.c -o helloworld3.out
clean:
@rm -vf helloworld *.o *~
Now compile it using make command
root@Bheema:~/warp_appln# make
arm-poky-linux-gnueabi-gcc -march=armv7ve -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/poky/2.1.2/sysroots/cortexa7hf-neon-poky-linux-gnueabi helloworld.c -o helloworld3.out
root@Bheema:~/warp_appln# ls
helloworld1.out helloworld2.out helloworld3.out helloworld.c helloworld.zip Makefile
now you can see all the three *.out files which has been created
Step-3 :
copying the helloworld.out to warp board using u-boot command
Note: we are proceeding further assuming your warp7 board is already loaded with pre-built image (which is working board)
now plug on the warp7 board to your computer and open a serial port terminal by using picocom command
root@Bheema:~/warp_appln# picocom -b 115200 /dev/ttyUSB0
now type below command at u-boot prompt
=>ums 0 mmc 0
you can see the warp7 emmc memory gets detected as shown below:
these are mounted on “/dev/sdc” with 3 partitions:
Boot: ~9 MB: “/media/bheema/Boot imx7s-” which is u-boot for warp7 and
rootfs: ~700MB: “/media/bheema/84804b4b-bc0e-4b3d-ac36-870eae0aca0f” where our linux kernel is loaded
/dev/sdc is available to user to copy the compiled executable files
root@Bheema:~/warp_appln# cp *.out /media/bheema/84804b4b-bc0e-4b3d-ac36-870eae0aca0f/
you can see that we have copied / transfered all the 3 executables to warp7 board
you can verify the exact file has been copied to target board by checking crc checksum
root@Bheema:~/warp_appln# md5sum helloworld1.out
2e5191e3cd9134b78192fff8426d9ba8 helloworld1.out
root@Bheema:~/warp_appln# md5sum /media/bheema/84804b4b-bc0e-4b3d-ac36-870eae0aca0f/helloworld1.out
2e5191e3cd9134b78192fff8426d9ba8 /media/bheema/84804b4b-bc0e-4b3d-ac36-870eae0aca0f/helloworld1.out
root@Bheema:~/warp_appln#
now type ctrl+c on u-boot window and type reset
=> ctrl+c
=> reset
=> ums 0 mmc 0
UMS: LUN 0, dev 0, hwpart 0, sector 0x0, count 0xe18000
CTRL+C - Operation aborted
=> reset
warp board will be reset with changes wait till login screen occurs
you can execute the helloworld.out as shown below:
root@imx7s-warp:/# ./helloworld1.out
hello world
root@imx7s-warp:/# ./helloworld2.out
hello world
root@imx7s-warp:/# ./helloworld3.out
hello world
root@imx7s-warp:/#