Cross-compiling code for the Apalix i.MX8

Hi,

I have an Apalis i.MX8 and an Ixora carrier board. I installed the minimal Linux image using the Toradex Easy Installer.

I didn’t found a clear/proper documentation to help me cross-compile C/C++ programs for the embedded system.

In fact, I have downloaded the cross-compiler from ARM website but I don’t have a proper sysroot (the compiler can’t find stdio.h). The /usr/include is empty (on both an archive I downloaded from Toradex, the OS image I guess, and in the embedded system file system).

Can someone explain me how to set up the toolchain so I can build C/C++ applications for the Apalis i.MX8 running the minimal Linux image ?

Linux apalis-imx8-06548561 5.4.193-5.7.0+git.f78299297185 #1 SMP PREEMPT Mon Jul 11 14:42:03 UTC 2022 aarch64 GNU/Linux

Thanks.

Hello @embeddedmz ,
Here you can find a guide to set up your development environment:

Best regards,
Josep

What’s the file corresponding to the Apalis i.MX8 of this one :

http://files.toradex.com/Colibri/Linux/Images/Colibri_T20_LinuxImageV2.4Beta1_20150518.tar.bz2

I didn’t not find an archive in the “binary images” link Linux BSPs - Toradex Colibri and Apalis System on Modules

Hello @embeddedmz ,
It seems that the article that I gave to you will need some reworking. In the meantime ,here you can find the image you are looking for:

Best regards,
Josep

I have already downloaded this : https://artifacts.toradex.com/artifactory/tdxref-oe-prod-frankfurt/dunfell-5.x.y/release/20/apalis-imx8/tdx-xwayland/tdx-reference-minimal-image/oedeploy/Apalis-iMX8_Reference-Minimal-Image-Tezi_5.7.0+build.20.tar but I can’t use it as a sysroot path for gcc since /usr/include is empty.

This way is nowhere recommended, but you may like it on Ubuntu to cross compile avoiding the need to build commonish -dev libraries from sources. Those dev libs may be installed via apt

sudo apt install g++-aarch64-linux-gnu
sudo apt install binutils-aarch64-linux-gnu
sudo dpkg --add-architecture arm64

From now your Eclipse new Empty Project->Cross GCC project should be buildable when you specify in project settings C/C++ Build → Cross Settings → Prefix = aarch64-linux-gnu-

Then

# backup /etc/apt/sources.list first
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

sudo gedit /etc/apt/sources.list

and 1) edit all uncommented deb ... lines specifying your host machine architecture like

deb [arch=amd64,i386] http://archive.ubuntu.com/ focal main restricted

and 2) clone the same deb lines with changed url to ports.ubuntu.com and specifying your target architecture, like

deb [arch=arm64] http://ports.ubuntu.com/ focal main restricted

Check that apt update completes without issues:

sudo apt update

Then you should be able to install for example static link library for socketcan for your target arm64:

sudo apt install libsocketcan-dev:arm64

You should be able to find list of available arm64 packages grepping output of apt list | grep arm64

1 Like

Thank you for your answer. But usually, how people develop programs for the Toradex minimal Linux kernel ? Until now, I only tested .NET Core but I do need to have some programs on my system (pppd for example).

Do they use Yocto to build an image that contains the programs/libraries they need ?

Toradex docs are outdated/missing for the Apalis i.MX8. I know they want people to use the containers but we are going to choose a SoM that doesn’t have enough memory for Torizon and that’s why I’m trying to understand how to build libraries/programs for a minimalist Linux system. I don’t know Yocto, I’ve played a bit with buildroot in the past.

Can’t say I’m doing things right way, but yes, Yocto is the way to build target image with pppd and other required components. Once you know component list it is ± just a matter of creating bb or bbappend file for image with required packages listed in IMAGE_INSTALL. Lazy way you may try editing layers/meta-toradex-demos/recipes-images/images/tdx-reference-minimal-image.bb and add there missing packages to IMAGE_INSTALL. If you don’t know whole set of packages, you may look in yocto build/deploy/ipk folder for required ipk’s. Some of rootfs-missing packages still may be built. Ones, which are not present in deploy/ipk can be built with bitbake your_package. Then you scp those packages to target and opkg install them. Not very convenien but OK way for packages with no or short dependency list. Don’t try to install something like python the same way, it’s better to bitbake image.

For C/C++ I’m using eclipse, proper debugger setup scp’s executable / library and other files I specify to target and uses gdb for debug as usual. Of course gdbserver should be present on target.

Once your executables are done, you still need to get in touch with Yocto creating your own recipes. Or… take rootfs *.xz file from your TEZI files set, uncompress it, add your files and compress back rootfs to *.xz :-).

2 Likes

Is there a non-dispersed, non-outdated, clear and straightforward documentation that explains how to create a minimal Linux image with Yocto for the Apalis i.MX8? Yocto seems to me very complex and initimidating. I don’t know where to start.

Build a Reference Image with the Yocto Project/OpenEmbedded - Toradex System/Computer on Modules

1 Like

Hi @embeddedmz, how are you?

In addition to the link that @Edward sent you, you may be interested in having a look at our webinars: Toradex | Embedded Computing Solutions - Webinars. There you can find some hands-on presentations that show you how to build your custom image.

On our documentation, you can also find other Yocto examples according to your specific needs. For instance, there is this page Custom meta layers, recipes and images in Yocto Project (hello-world examples) | Toradex Developer Center that gives an example on how to load a custom C Program/device trees to your Yocto image.

You can also open any thread that you wish here in the community or contact us by e-mail if you have any blocking points on Yocto.

And thanks a lot Edward for helping out :smiley:

1 Like

I have reached the Build an Image chapter.

I didn’t run this command yet :

$ bitbake <image> # I will replace <image> by tdx-reference-minimal-image

since I don’t know how to tell OE to add some software packages (e.g. curl to the image).

In this file apparently used by the minimal image : packagegroup-tdx-cli.bb « images « recipes-images - meta-toradex-demos.git - Toradex BSP layer, recipes for the demo images we can see that it mentions “curl” but this last isn’t available in the miniamal Linux image that I’m running on my Apalis i.MX8.

curl is just an example, I don’t really need it. In fact, I need ppp (commands pon/poff), bash (I don’t know if it’s feasible) and maybe some I2C tools (not mandatory).

If it is easy to do, can someone give me the procedure to add packages to the image ? (conf files to modify + bitbake command).

I tried to install curl for arm64 but apt warned me that il will remove curl (amd64 obviously). isn’t it possible to have both ?

Hi @embeddedmz,

These packages groups are used by the overall image class to be built. You can see, however, that the minimal image class uses the packagegroup-base-tdx-cli: tdx-reference-minimal-image.bb « images « recipes-images - meta-toradex-demos.git - Toradex BSP layer, recipes for the demo images. This explain why it’s not available on the minimal.

Therefore, you may find three main options for adding your packages:

  1. Add them directly to the image class (tdx-reference-minimal-image.bb):
packagegroup-boot \
packagegroup-basic \
+ curl \
+ ppp \
+ ... \
  1. Add them to the packagegroup that you’re using (packagegroup-tdx-cli.bb):
RRECOMMENDS_packagegroup-base-tdx-cli = "\
    can-utils \
    dosfstools \
    e2fsprogs-mke2fs \
    iproute2 \
    libgomp \
    libgpiod-tools \
    libsoc \
    mtd-utils \
    set-hostname \
    u-boot-fw-utils \
    udev-toradex-rules \
    uhubctl \
    util-linux-fstrim \
+  curl \
+  ppp \
+ ... \
"
  1. Change the package group you’re using to something like (tdx-reference-minimal-image.bb):
    packagegroup-base-tdx-cli \
+  packagegroup-networking-tdx-cli \

Would any of these options work for you? Also, when you want to add a new package, it’s always worth checking if the recipes are already available. You can check this with: bitbake-layers show-recipes. This command will list all the recipes available. You can browse OpenEmbedded Layer Index - layers for any missing recipes.


Can you please tell us how did you try to install it?

Best regards,

1 Like

@embeddedmz,

Your original question was, as subject suggests, about cross-compile. My advice with apt install package:arm64 was only about -dev packages, which may be used to provide static compile libs and header files needed to cross-compile on your Ubuntu amd64 machine. Of course apt on Ubuntu can’t be used to install to your target machine rootfs, this is exactly what you see, either curl for amd64 or curl for arm64, but not both simultaneously. But -dev packages for both amd64 and arm64 can be installed, link libs and headers get installed to arm64 gcc folders, so no problems with them.

1 Like

I have a “Apalis-iMX8_Reference-Minimal-Image.rootfs.tar.xz” how can I install it ? I have already copied that file on a thumb drive, launched the Toradex Easy Installer, but the “mass storage” icon is still gray after I plugged the thumb drive.

Hi @embeddedmz,

Thanks for the update. The rootfs is just one of the folders that make your image. To install it, you should look for a file such as the following:

(base) ➜  images tree -L 2 | grep Tezi      
│   ├── Apalis-iMX8_Reference-Multimedia-Image-Tezi_5.7.0-devel-20220808180724+build.0.tar
│   ├── Colibri-iMX6_Reference-Multimedia-Image-Tezi_5.7.0-devel-20220808122045+build.0
│   ├── Colibri-iMX6_Reference-Multimedia-Image-Tezi_5.7.0-devel-20220808122045+build.0.tar
│   ├── Colibri-iMX8X_Reference-Multimedia-Image-Tezi_5.7.0-devel-20220808192538+build.0.tar
    ├── Verdin-iMX8MM_Reference-Multimedia-Image-Tezi_5.7.0-devel-20220728134551+build.0.tar

You can add the Apalis-iMX8...Tezi...tar to a USB Key and flash it to the module using Easy Installer. (Detailed Manual | Toradex Developer Center)

1 Like

Thank you very much.

Otherwise, I succeeded in cross-compiling a simple hello world program, this is what I have done :
I used this article How to setup environment for Embedded Linux application development | Toradex Developer Center to download an ARM compiler and this one Hello World application on Embedded Linux (C/C++) | Toradex Developer Center to compile the program. I used this path as a sysroot (compiler --sysroot argument, by the way this argument is not recognized by the aarch64-none-linux-gnu-gcc compiler : -mfloat-abi=hard) : /home/[user]/oe-core/build/tmp/work/apalis_imx8-tdx-linux/tdx-reference-minimal-image/1.0-r0/recipe-sysroot. Is this the official sysroot of the built image ?

I have one last request: is there a document that explains how to configure CMake to use the new compiler and sysroot ?

Hi @embeddedmz! I’m glad we could help you succeed in this task.

All the files that will be used on the final image will be inside the deploy folder. On the tmp you’ll have some temporary files that are used during the build process and may be deleted or changed once you run bitbake again.

Just to be sure, your final goal is to have a CMake application to be compiled with Yocto, right? If so, I found this link that may be useful to you: openembedded - Cmake with bitbake recipe - Stack Overflow.

1 Like

It was to know if I could use CMake to cross-compile a C/C++ program with the ARM compiler and the sysroot I found in tmp. We often program in C# .NET Core, I just tested that it works (SDK downloaded from Microsoft site, I saw that the ‘dotnet’ package is not available when I ran the bitbake command) and we can generate an image that contains the software packages we need so it’s not really important for the moment.

1 Like