Yocto MACHINE customization best practice

Hello,
I have the following hardware

SoM: Apalis-iMX8 QP and
Carrier board : Ixora 1.1
BSP: Toradex 5.4.0

I need to customize the MACHINE apalis-imx8.conf creating my new one with some settings like changing the DT overlays and whatever.
With Yocto Project it is possible to override almost everything in a custom layer and therefore I expected to be able to do the same even in this case.
Unfortunately I am facing to problems when trying to override the variable TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT into my new machine configuration file.
This is an unexpected behavior, and therefore I am asking what is the Yocto MACHINE customization best practice suggested by Toradex?
Thank you

Hi @koan ,

Thank you for the question.

We will reach out to you soon.

Best Regards
Kevin

Hi @koan ,

To answer your question first:

I would create my own machine, preferably starting the machine name with our machine name, include the original .conf and extend the MACHINE_OVERRIDES with the original machine name.

Then add whatever is needed to get the desired result.
E.g. have a look at what we did to have a machine suitable for a now obsolete silicon revision of the SoC [1].


However for TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT you do not need to do that. The overlay recipe is the only consumer of that variable. Since the content of the variable is machine specific we do set it in the machine configuration.

I would add a bbappend to the overlay recipe setting that variable to whatever you need, e.g. to not have any overlay applied by default I would create a file as follows:

recipes-kernel/linux/device-tree-overlays_git.bbappend:

TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT_apalis-imx8 = ""

Max

[1] colibri-imx8x-v10b.conf « machine « conf - meta-toradex-nxp.git - Toradex BSP layer, recipes for NXP based modules

Hi @max.tx ,
I already tried that solution which is the ‘standard way’ to extend an existing MACHINE but unfortunately I’m facing to an issue.

I already overridden device-tree-overlays_git.bb creating my own device-tree-overlays_%.bbappend

# device-tree-overlays_%.bbappend
TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT = "apalis-imx8_lvds_overlay.dtbo apalis-imx8_atmel-mxt_overlay.dtbo display-lt170410_overlay.dtbo"

And it worked so far.

Now I need to go further, therefore I created my (very trivial) machine marco.conf

# marco.conf
require conf/machine/apalis-imx8.conf

Changed the machine in local.conf

MACHINE = "marco"

And rebuilt

$ bitbake core-image-minimal 
Parsing recipes: 100% |##########################| Time: 0:00:34
...
Build Configuration:
BB_VERSION           = "1.46.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "aarch64-linux"
MACHINE              = "marco"
DISTRO               = "tdx-xwayland"
DISTRO_VERSION       = "5.4.0-devel-20211011132126+build.0"
TUNE_FEATURES        = "aarch64"
TARGET_FPU           = ""
meta-toradex-nxp     = "HEAD:4a074b05bad21ac438a398bb036ec0e8da41513c"
meta-freescale       = "HEAD:12c3eed6a90b436565126d8ba6934f794b816e25"
meta-freescale-3rdparty = "HEAD:537cb85e4db17d1f6b356a92112b32ae2e39b235"
meta-toradex-tegra   = "HEAD:d4ef0a4584e04b14a6ba368b8cdf8592af43d3bb"
meta-toradex-bsp-common = "HEAD:276a8e076225332b336e41eb2c62375ddc6989bf"
meta-oe              
...
Initialising tasks: 100% |###########################################################| Time: 0:00:07
Sstate summary: Wanted 1025 Found 772 Missed 253 Current 2449 (75% match, 92% complete)
NOTE: Executing Tasks
ERROR: device-tree-overlays-toradex_5.4-2.3.x-imx+gitAUTOINC+a52d315e89-r0 do_deploy: apalis-imx8_lvds_overlay.dtbo is not installed in your boot filesystem, please make sure it's in TEZI_EXTERNAL_KERNEL_DEVICETREE or being provided by virtual/dtb.
ERROR: device-tree-overlays-toradex_5.4-2.3.x-imx+gitAUTOINC+a52d315e89-r0 do_deploy: Execution of '/home/works/yocto/build/tmp/work/marco-tdx-xwayland-linux/device-tree-overlays/toradex_5.4-2.3.x-imx+gitAUTOINC+a52d315e89-r0/temp/run.do_deploy.2843' failed with exit code 1:
ls: cannot access '*.dtb': No such file or directory
WARNING: exit code 1 from a shell command.

ERROR: Logfile of failure stored in: /home/works/yocto/build/tmp/work/marco-tdx-xwayland-linux/device-tree-overlays/toradex_5.4-2.3.x-imx+gitAUTOINC+a52d315e89-r0/temp/log.do_deploy.2843
ERROR: Task (/home/works/yocto/build/../layers/meta-toradex-nxp/recipes-kernel/linux/device-tree-overlays_git.bb:do_deploy) failed with exit code '1'
NOTE: Tasks Summary: Attempted 9183 tasks of which 8695 didn't need to be rerun and 1 failed.

Is there anything hard coded somewhere you should get rid of?
Thanks

Hi @koan ,

I forgot some magic, sorry.

Of all the overlays built we only deploy those which do NOT contain imx[6-8] or tk1 in their filename, plus we do deploy all overlays which start with the string given by the MACHINE_PREFIX variable. MACHINE_PREFIX is set to the machine name by default. [1].

So you would need to additionally set MACHINE_PREFIX_marco = "apalis-imx8" in your overlay bbappend to additionally deploy the overlays specific to your module type.

Max

[1] toradex-devicetree.bbclass « classes - meta-toradex-bsp-common.git - Toradex BSP layer, recipes common to all modules

Hi @max.tx
that solved the issue.
Thanks

Hello @max.tx ,
I have the same problem when I am creating the meta-toolchain using a custom MACHINE.
In such case aarch64-linux-cpp is not built nor included in the sysroots.
Maybe do you need any other ‘magic’ setup?

Hi @koan

What ‘same’ problem? I cannot relate any issue discussed in this topic with the build of meta-toolchain.

I’m not aware of anything special needed to build meta-toolchain.

Albeit I tend to recommend bitbake <image_name> -c populate_sdk over bitbake meta-toolchain to have additionally the developer packages of whatever I already packaged into the <image_name> recipe.

Max

Hi @max.tx
‘same’ problem means ‘not working’.
Create a custom machine and use it in your local.conf (as stated above in this thread) and build bitbake meta-toolchain
or even bitbake <image_name> -c populate_sdk is the same.
The final result will be a toolchain/SDK that won’t contain the expected toolchain binaries like aarch64-linux-cpp.
Maybe I need any other ‘magic’ setup?

Thanks

Hi @koan

If it really is the same problem then the same solution should fix it, not?

Anyway, I created conf/machine/marco.conf

# keep the original machine as an override with high prio
MACHINEOVERRIDES =. "apalis-imx8:"

require conf/machine/apalis-imx8.conf

MACHINE_PREFIX_marco = "apalis-imx8"

Changed local.conf to have MACHINE = "marco"and did a bitbake meta-toolchain.
Then I installed the resulting sdk, sourced its environment and I have a toolchain. Albeit the toolchain is additionally decorated with the DISTRO name.

$ deploy/sdk/tdx-xwayland-glibc-x86_64-meta-toolchain-aarch64-marco-toolchain-5.5.0.sh
$ . /.../environment-setup-aarch64-tdx-linux

$ which aarch64-tdx-linux-cpp
.../sysroots/x86_64-tdxsdk-linux/usr/bin/aarch64-tdx-linux/aarch64-tdx-linux-cpp

$ aarch64-tdx-linux-cpp --version
aarch64-tdx-linux-cpp (GCC) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat << EOF > hello.c
#include <stdio.h>
int main(void) {printf("Hi\n");return 0;}
EOF

$ $CC hello.c -o hello
$ file hello
hello: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=aabaddf404cc497d9b9f06a77363796ff67b5888, for GNU/Linux 3.14.0, with debug_info, not stripped

So for me it works.

Max

Hi @max.tx
I had not considered to put this solution in the machine file.
Now it works, thanks.