In this article, we are going to set up LTIB on a Linux machine to do cross compilation for the SABRE Lite (i.MX6)SABRE Lite (i.MX6). Then we are going to use LTIB to compile the standard Hello World program and test to make sure that everything works as expected.
The Linux Target Image Builder (LTIB) is an open source project that lets you compile applications on your Linux machine that will run on a different platform. This comes in handy when you are developing a new application and all of your tools reside on your desktop Linux machine. This way you can use all of your normal tools, in a familiar environment, and target a single board computer like the SABRE Lite (i.MX6).
Prerequisites
Before we get going, it is always a good idea to make sure that your system is up to date:
Once that completes, then you need to install the LTIB dependencies which are:
If your desktop PC is running a 64 bit version of Linux, then you need one more library:
Getting LTIB Source
The first step is to get the LTIB source that lets you target the SABRE Lite (i.MX6). It can be found here:
http://community.freescale.com/docs/DOC-95560
The file that you want is labeled L3.0.35_4.1.0_SOURCE_BSP.
Once the download has completed, then unzip the source with:
Inside the directory that was created you should find an install script, run that and accept the EULA.
Getting Extra Libraries
If you try to run LTIB right now, it will error out trying to find some packages that it can’t locate. Unfortunately, the list of packages that it needs but can’t find is pretty long. So, to make it easier, I’ve attached a zip to this post that contains most of the missing packages. Download that file and then put its contents into:
/opt/freescale/pkgs
I’m not really sure why the packages can’t be resolved. The fact that they can’t be resolved really make me think that I’m either doing something wrong, or that the preferred way is now to use the yocto project. (Yocto is another tool for doing cross compilation.)
Building LTIB
Now that you have all of the required packages, you can build LTIB by typing:
If this completes successfully, then you will be presented with a screen that looks like this:
Using this screen you can set the platform that you would like to compile to. This setting is already correct by default, so you don’t need to make any changes here. So, hit the right arrow on your keyboard and select “Exit” and press enter. It will then prompt you asking whether or not you would like to save.
After you save, then you will be prompted with another screen that looks similar to the first one:
On this screen there are some changes that need to be made. You need to change the platform type from imx25_3stack to be imx6q. To do this, highlight the “Selection (imx25_3stack) --->” line and hit enter. This will bring up another form that looks like this:
Find the imx6q option and hit enter. This is the only change that is required for this form, so Exit and save just like we did before.
This will bring up one more dialog:
On this dialog, we need to change the board from mx6q_arm2 to mx6q_sabrelite. The procedure for this is similar to the last change that we made. After you make this change, exit and save.
This will kick off a building process. Unfortunately, this process initially fails for me with an error about a package called busybox.
This is fairly easy to fix. Within your LTIB directory there will be a file called:
dist/lfs-5.1/base_libs/base_libs.spec
Open up this file and make a small modification. First, find the lines that look like this:
What you want to do is to remove the last two lines:
Once they are deleted, then rerun ./ltib. When you run it a second time, you will not have to go through the previous screens, it will just start building where it left off. This time busybox should succeed and you will eventually see a screen that looks like this:
Great success!
Compiling Hello World
Now that we have LTIB set up to do cross-compilation, let’s test it out and see if it works. To do this we are going to use the classic hello world example:
Once you have that code into a file, let’s call it test.cpp, then fire up LTIB in shell mode:
This will give you a prompt that acts like you are on the SABRE Lite (i.MX6). So, when you compile within this shell, the executable will be compiled for the SABRE Lite (i.MX6) instead of the machine that you are on. So, compile the program like you normally would:
As a quick test, you can inspect what type of file the executable is by doing:
This inspects the file’s “magic numbers” that describes what type of file it is. This command should print out:
ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.31, not stripped
Excellent, now copy over the executable to the SABRE Lite and you should see the program run and print out “Hello World!”.
Summary
In this article, we got LTIB up and running on our desktop PC so that we could cross compile applications for the SABRE Lite (i.MX6). We then used LTIB to compile a Hello World program and run it on the SABRE Lite (i.MX6)SABRE Lite (i.MX6).
With all of the work around to get LTIB set up, I’m not sure this is the best way to go about it. Seems like the yocto project has become the preferred way to go, but that’s just a guess. I haven’t given that one a try yet, so I’m not sure it is easier to set up.