Add kernel command-line arguments in torizon yocto build

I would like to add various kernel command line arguments (e.g isolcpus=3) to the yocto build. I’ve searched the various layers/recipes in Yocto and can’t seem to find the correct location. What is the correct recipe to append/file to patch?

(I was able to do this using torizoncore-builder but would like to integrate it into our yocto build.)

Hi, I’m the Toradex AI Assistant.

I might make mistakes or occasionally get you wrong. Our support team will step in if needed.


To add kernel command line arguments to your Yocto build, you need to create a .bbappend file for the Linux kernel recipe in your custom meta layer. The approach depends on your System on Module (SoM) architecture(1).

Create the Kernel Recipe Append

For NXP-based SoMs:

Create the following directory structure and file in your custom meta layer(1):

$ cd ../layers/meta-customer/
$ mkdir -p recipes-kernel/linux/linux-toradex
$ touch recipes-kernel/linux/linux-toradex/linux-toradex%.bbappend

(1)

For TI-based SoMs:

Create the directory and append file for TI modules(1):

  • Directory: recipes-kernel/linux/linux-toradex-ti
  • .bbappend file: linux-toradex-ti%.bbappend

Configure the Kernel Arguments

In your .bbappend file (e.g., recipes-kernel/linux/linux-toradex%.bbappend), you can add kernel arguments through the kernel configuration. Here’s the basic structure(1):

FILESEXTRAPATHS:prepend := "${THISDIR}/linux-toradex:"

# Prevent the use of in-tree defconfig
unset KBUILD_DEFCONFIG

SRC_URI += "\
    file://defconfig \
    "

(1)

Add Your Custom Kernel Arguments

Create a defconfig file in your recipes-kernel/linux/linux-toradex/ directory and add your kernel command line arguments. For your specific example with isolcpus=3, you would modify the kernel configuration to include this parameter.

Alternative Approach for Torizon OS

If you’re building Torizon OS with Yocto, you can also reference how TorizonCore Builder handles kernel arguments. The tool uses device tree overlays to set custom kernel arguments(2), creating a custom-kargs_overlay.dts that gets compiled and applied(2).

Directory Structure

Your final directory structure should look like this(1):

meta-customer/
├── conf
│   └── layer.conf
└── recipes-kernel
    └── linux
        └── linux-toradex (or linux-toradex-ti for TI SoMs)
            ├── linux-toradex%.bbappend
            └── defconfig

Make sure your custom meta layer is properly initialized as a Git project if you’re building Torizon OS, as this is mandatory for OSTree integration(1).

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

Hi @ToradexAI

I would like to explore the device tree overlay method. Can you elaborate more on the contents of the dts file and the steps to integrate it into the torizon yocto build?

Device Tree Overlay Method for Kernel Arguments

You can use device tree overlays to set kernel command line arguments like isolcpus=3. Here’s how to create the overlay and integrate it into your Yocto build:

Creating the Device Tree Overlay

Create a device tree overlay source file (.dts) with the /plugin/ directive (1). Here’s the basic structure for adding kernel arguments:

/dts-v1/;
/plugin/;

/ {
    compatible = "toradex,<your-module>";
    
    fragment@0 {
        target-path = "/chosen";
        __overlay__ {
            bootargs-append = "isolcpus=3";
        };
    };
};

(1)

The overlay must be denoted with /plugin/; in the header (2). Replace <your-module> with your specific Toradex module (e.g., verdin-imx8mp, colibri-imx8x) (1).

Template Structure

You can use this template for pin muxing or other customizations (1):

/dts-v1/;
/plugin/; //Indicates a Device Tree Overlay

// Header file with pin definitions
#include <soc-pinfunc.h>

/ {
	compatible = "toradex,apalis-imx8"; // Set hardware compatibility
};
	
&iomuxc {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl-originally-in-device-tree>, <&pinctrl_my_pins>;  // Pin group available in userspace i.e. as GPIO

	name-of-som {
		pinctrl_my_pins: my_muxgrp {
			fsl,pins = <
				PIN_NAME_PIN_MUX   PAD_CTRL // PINS
			>;
		};
	};
};

&node {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_my_pins>;  // Pin group used in genericPeripheral
	status = "okay";
};

(1)

Integration into Yocto Build

Step 1: Add Your Overlays to the Yocto Project

There are two recipes that handle device tree overlays (2):

  • Upstream-based images: meta-toradex-bsp-common/recipes-kernel/linux/device-tree-overlays-mainline_git.bb (2)
  • Downstream-based images: meta-toradex-nxp/recipes-kernel/linux/device-tree-overlays_git.bb (2)

You can write your own bbappends to add your device tree overlays repository (2).

Step 2: Example bbappend

Create a bbappend file with this structure (2):

FILESEXTRAPATHS:prepend := "${THISDIR}/device-tree-overlays:"

CUSTOM_OVERLAYS_SOURCE = " \
    my-device-tree_overlay.dts \
"
CUSTOM_OVERLAYS_BINARY = " \
    my-device-tree_overlay.dtbo \
"

SRC_URI += " \
    file://my-device-tree_overlay.dts \
"

TEZI_EXTERNAL_KERNEL_DEVICETREE += " \
    ${CUSTOM_OVERLAYS_BINARY} \
"

TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT = " \
    ${CUSTOM_OVERLAYS_BINARY} \
"

do_collect_overlays:prepend() {
    for DTS in ${CUSTOM_OVERLAYS_SOURCE}; do
        cp ${WORKDIR}/${DTS} ${S}
    done
}

(2)

Step 3: Enable Your Overlays

The class meta-toradex-bsp-common/classes/image_type_tezi.bbclass uses the variable TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT to add overlays that will be applied during boot time (2).

You can find the variable settings using grep in the layers directory (2):

$ cd <yocto projet setup>
$ grep -nre "TEZI_EXTERNAL_KERNEL_DEVICETREE_BOOT" layers/*

(2)

Build Process

Using TorizonCore Builder for Testing

For evaluation and development, you can use TorizonCore Builder’s dto command (1):

$ torizoncore-builder dto apply device-trees/overlays/<your-custom-device-tree-overlay.dts>

(3)

Production Build with Yocto

For production, use the build.yaml file approach (1):

customization:
  device-tree:
    include-dirs:
      - device-trees/include/
    overlays:
      add:
        - device-trees/overlays/<your-custom-device-tree-overlay.dts>

(1)

This enables the build command to compile and deploy the DTOs to your customized image (1).

Important Notes

  • Raw NAND modules don’t support device tree overlays (2)
  • The overlay source file should be located in the device-tree-overlays folder at the same directory as your bbappend (2)
  • Make sure your custom meta layer is properly initialized as a Git project for OSTree integration (2)

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.