Create your own layer

The RITY SDK is composed of several Yocto Layers:

  • meta-arm: Layer maintained by ARM Inc., it provides the recipes for Trusted-Firmware A and OPTEE-OS.

  • meta-mediatek-bsp: Layer maintained by BayLibre SAS, it provides the BSP support for the RITY SDK.

  • meta-openembedded: Collection of Layers that provides many networking tools, python3 packages, and multimedia packages.

  • meta-rity: Layer maintained by BayLibre SAS, it provides images to make it easier to test and evaluate the MediaTek BSP

  • poky: integration of various component enabling to build customized embedded device images.

It is advised to never modify layers that you don’t own because it will make maintenance much harder when trying to update these layers. The recommended way is to instead create a new Yocto layer that will complement (overlay) these other layers. This helps keep everything well compartementalized and will make upgrade easier.

This chapter will provide a small guide on how build a new layer on top of the RITY SDK. The code from this chapter can be found under: meta-rity/meta-rity-skeleton.

1. Basic layer structure

The most basic layer is composed of the following files:

meta-rity-skeleton
└── conf
    ├── bblayers.conf.sample
    ├── layer.conf
    └── local.conf.sample

In theory only the file layer.conf is required but in general it is often very useful to ship the two sample files bblayers.conf.sample and local.conf.sample.

1.1. layer.conf

The layer.conf file is mostly used to define the layer name, dependencies, priority and where to find recipes inside it.

 1# We have a conf and classes directory, add to BBPATH
 2BBPATH .= ":${LAYERDIR}"
 3
 4# We have recipes-* directories, add to BBFILES
 5BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"
 6
 7BBFILE_COLLECTIONS += "rity-skeleton"
 8BBFILE_PATTERN_rity-skeleton = "^${LAYERDIR}/"
 9BBFILE_PRIORITY_rity-skeleton = "9"
10
11# This should only be incremented on significant changes that will
12# cause compatibility issues with other layers
13LAYERVERSION_rity-skeleton = "1"
14
15LAYERDEPENDS_rity-skeleton = "rity core mediatek-bsp multimedia-layer"
16
17LAYERSERIES_COMPAT_rity-skeleton = "dunfell gatesgarth"

If you copy this file in your own layer, make sure to replace everywhere rity-skeleton to the name of your own layer.

1.2. bblayers.conf.sample and local.conf.sample

Before being able to build an image, the configuration must be generated. When the script src/poky/oe-init-build-env is being sourced, it will try to create the build/conf/local.conf and build/conf/bblayers.conf if these files do not yet exist. By setting the TEMPLATECONF variable you can specify where the script will look for when trying to find the sample files.

2. Creating your own image recipe

It is often useful to create your own image recipe in order to choose which applications and daemon are going to be part of your image.

meta-rity-skeleton
├── conf
│   ├── bblayers.conf.sample
│   ├── layer.conf
│   └── local.conf.sample
└── recipes-skeleton
        └── images
                └── rity-skeleton-image.bb
recipes-skeleton/images/rity-skeleton-image.bb
 1DESCRIPTION = "RITY Skeleton Image"
 2
 3IMAGE_INSTALL += " \
 4	packagegroup-base \
 5	packagegroup-core-boot \
 6	packagegroup-core-full-cmdline \
 7	packagegroup-rity-zeroconf \
 8"
 9
10require recipes-rity/images/rity-image.inc

You can add packages to your image by adding them to the IMAGE_INSTALL variable.

3. Modidying the kernel

meta-rity-skeleton
├── conf
│   ├── bblayers.conf.sample
│   ├── layer.conf
│   └── local.conf.sample
├── recipes-kernel
│   ├── dtbo
│   │   ├── dtbo
│   │   │   └── skeleton.dts
│   │   └── dtbo.bbappend
│   └── linux-mtk
│       ├── linux-mtk
│       │   ├── 0001-arm64-dts-mediatek-add-MT8183-skeleton-dts.patch
│       │   └── skeleton.cfg
│       └── linux-mtk_%.bbappend
└── recipes-skeleton
        └── images
                └── rity-skeleton-image.bb

3.1. Adding patches on top of linux-mtk

One way to modify the kernel is to apply patches on top of the linux-mtk kernel. You can add custom patches by creating a linux-mtk_%.bbappend file as below to modify the recipe provided by meta-mediatek-bsp.

recipes-kernel/linux-mtk/linux-mtk_%.bbappend
1FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
2
3SRC_URI:append:i500-skeleton =  " \
4	file://0001-arm64-dts-mediatek-add-MT8183-skeleton-dts.patch \
5	file://skeleton.cfg \
6"

Here the patch 0001-arm64-dts-mediatek-add-MT8183-skeleton-dts.patch was added by setting the file into SRC_URI.

3.2. Changing the kernel configuration

If you need to enable/disable configuration in the kernel you can create a configuration fragment.

meta-rity-skeleton
├── conf
│   ├── bblayers.conf.sample
│   ├── layer.conf
│   └── local.conf.sample
├── recipes-kernel
│   ├── dtbo
│   │   ├── dtbo
│   │   │   └── skeleton.dts
│   │   └── dtbo.bbappend
│   └── linux-mtk
│       ├── linux-mtk
│       │   ├── 0001-arm64-dts-mediatek-add-MT8183-skeleton-dts.patch
│       │   └── skeleton.cfg
│       └── linux-mtk_%.bbappend
└── recipes-skeleton
        └── images
                └── rity-skeleton-image.bb

You can add the configuration fragment by adding it to the SRC_URI variable of the linux-mtk_%.bbappend file.

recipes-kernel/linux-mtk/linux-mtk_%.bbappend
3SRC_URI:append:i500-skeleton =  " \
4	file://0001-arm64-dts-mediatek-add-MT8183-skeleton-dts.patch \
5	file://skeleton.cfg \
6"
recipes-kernel/linux-mtk/linux-mtk/skeleton.cfg
1CONFIG_BT_MTKSDIO=m

3.3. Creating an overlay

Overlays allow you to selectively modify the device-tree. It is often used to add functionality to board, such as optional peripherals like DSI displays.

meta-rity-skeleton
├── conf
│   ├── bblayers.conf.sample
│   ├── layer.conf
│   └── local.conf.sample
├── recipes-kernel
│   ├── dtbo
│   │   ├── dtbo
│   │   │   └── skeleton.dts
│   │   └── dtbo.bbappend
│   └── linux-mtk
│       ├── linux-mtk
│       │   ├── 0001-arm64-dts-mediatek-add-MT8183-skeleton-dts.patch
│       │   └── skeleton.cfg
│       └── linux-mtk_%.bbappend
└── recipes-skeleton
        └── images
                └── rity-skeleton-image.bb
recipes-kernel/dtbo/dtbo.bbappend
1FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
2
3SRC_URI:i500-skeleton += " \
4	file://skeleton.dts \
5"

Warning

It is hightly recommended to use the SRC_URI_<machine> syntax like on line 4 in order to only ship the device-tree for that specific machine. Not setting the machine would mean the overlay would be ship for every machine.

4. Create a new machine

meta-rity-skeleton
├── conf
│   ├── bblayers.conf.sample
│   ├── layer.conf
│   ├── local.conf.sample
│   └── machine
│       └── i500-skeleton.conf
├── recipes-kernel
│   ├── dtbo
│   │   ├── dtbo
│   │   │   └── skeleton.dts
│   │   └── dtbo.bbappend
│   └── linux-mtk
│       ├── linux-mtk
│       │   ├── 0001-arm64-dts-mediatek-add-MT8183-skeleton-dts.patch
│       │   └── skeleton.cfg
│       └── linux-mtk_%.bbappend
└── recipes-skeleton
        └── images
                └── rity-skeleton-image.bb

A new machine can be created by adding a new file in conf/machine/. The MediaTek BSP is defining machine under the following pattern “<SoC>-<Board>”.

conf/machine/i500-skeleton.conf
 1require conf/machine/include/mt8183.inc
 2
 3# Kernel
 4KERNEL_DEVICETREE = "mediatek/mt8183-skeleton.dtb"
 5
 6# U-Boot
 7UBOOT_MACHINE = "mt8183_pumpkin_defconfig"
 8
 9DISTRO_FEATURES:append = " dtbo "
10MACHINE_FEATURES:append = " alsa usbgadget usbhost"
11
12MACHINEOVERRIDES =. "mt8183-skeleton:mt8385-skeleton:i500-skeleton:"

You can specify the desired kernel device by setting KERNEL_DEVICETREE. For the meta-rity-skeleton layer, this device-tree is defined in the kernel patch recipes-kernel/linux-mtk/linux-mtk/0001-arm64-dts-mediatek-add-MT8183-skeleton-dts.patch.

5. Create a custom DISTRO

meta-rity-skeleton
├── conf
│   ├── bblayers.conf.sample
│   ├── distro
│   │   └── rity-skeleton.conf
│   ├── layer.conf
│   ├── local.conf.sample
│   └── machine
│       └── i500-skeleton.conf
├── recipes-kernel
│   ├── dtbo
│   │   ├── dtbo
│   │   │   └── skeleton.dts
│   │   └── dtbo.bbappend
│   └── linux-mtk
│       ├── linux-mtk
│       │   ├── 0001-arm64-dts-mediatek-add-MT8183-skeleton-dts.patch
│       │   └── skeleton.cfg
│       └── linux-mtk_%.bbappend
└── recipes-skeleton
        └── images
                └── rity-skeleton-image.bb
conf/distro/rity-skeleton.conf
1require conf/distro/rity.inc
2
3DISTRO = "rity-skeleton"
4DISTRO_NAME = "RITY skeleton"

In order to use your new distro, you can modify the DISTRO variable in your local.conf.sample.