Skip to main content
Version: v1

Create layer

Layers are prepares by OEM. They are shared by services and extend their rootfs. The layer consists of filesystem tree (files, folders) and a metadata that describes layer's content. See layer format for details.

Create layer using Yocto build​

AosCore Yocto meta layers provide mechanism to create and build layers automatically based on Yocto packages and recipes. AosCore meta-aos repo contains example layers recipes that can be used as reference for creating custom layers or can be used to extend services rootfs.

There are two types of layers: layers that depend only on host rootfs and layers that depend on other layer.

Create layer based on host rootfs​

In your Yocto meta layer, create layer recipe with the following path recipes-aos-layers/your-layer-name/your-layer-name.bb. This recipe should have the following content:

SUMMARY = "Description of your layer"

require recipes-aos-layers/aos-base-layer/aos-base-layer.inc

AOS_LAYER_FEATURES += " \
...
"

AOS_LAYER_VERSION = "1.0.0"
  • SUMMARY - add your layer description;
  • AOS_LAYER_FEATURES - add list of Yocto recipes that have to be included into this layer;
  • AOS_LAYER_VERSION - your layer version in Semantic Versioning format.

Except above variables the layer recipe should include base layer image:

require recipes-aos-layers/aos-base-layer/aos-base-layer.inc

The layer can be built using bitbake command:

bitbake your-layer-name

By default, your layer image will be located in default deploy directory in layers folder.

See aos-pylibs-layer for reference.

Create layer based on other layer​

In your Yocto meta layer, create layer recipe with the following path recipes-aos-layers/your-layer-name/your-layer-name.bb. This recipe should have the following content:

SUMMARY = "Description of your layer"

AOS_PARENT_LAYER = "parent-layer-name"

require recipes-aos-layers/parent-layer-name/parent-layer-name.bb

AOS_LAYER_FEATURES += " \
...
"

AOS_LAYER_VERSION = "1.0.0"
  • SUMMARY - add your layer description;
  • AOS_PARENT_LAYER - add parent layer name;
  • AOS_LAYER_FEATURES - add list of Yocto recipes that have to be included into this layer;
  • AOS_LAYER_VERSION - your layer version in Semantic Versioning format.

Except above variables the layer recipe should include parent layer recipe:

require recipes-aos-layers/parent-layer-name/parent-layer-name.bb

The layer can be built using bitbake command:

bitbake your-layer-name

By default, your layer image will be located in default deploy directory in layers folder.

See aos-libvis-layer for reference.

Add new layer to Aos VM​

Let's add new layer for Aos VM. For instance, your service requires python library matplotlib. Let's add this library as Aos layer.

Create aos-matplotlib-layer recipe​

Create a recipe for this layer with the following path:

yocto/meta-aos-vm/meta-aos-vm-common/recipes-aos-layers/aos-matplotlib-layer/aos-matplotlib-layer.bb.

Add the following content to the layer recipe:

SUMMARY = "python matplotlib layer"

require recipes-aos-layers/aos-base-layer/aos-base-layer.inc

AOS_LAYER_FEATURES += " \
python3-matplotlib \
"

AOS_LAYER_VERSION = "1.0.0"

We've added python3-matplotlib package to this layer using AOS_LAYER_FEATURES variable.

Add aos-matplotlib-layer to moulin configuration file​

Aos VM uses moulin build system. To add newly created layer to the list of Aos VM layers, edit aos-vm.yaml layers section in the following way:

  • add new layer image to target_images;
  • add new layer target item to layers items.

Your layers section should look like:

layers:
builder:
type: custom_script
work_dir: "workdir"
script: "../yocto/meta-aos/scripts/layer_builder.py"
target_images:
- "../output/layers/pylibs-layer.tar.gz"
- "../output/layers/libvis-layer.tar.gz"
- "../output/layers/matplotlib-layer.tar.gz"

additional_deps:
- "%{YOCTOS_WORK_DIR}/build-%{NODE_TYPE}/tmp/deploy/images/%{MACHINE}/%{AOS_BASE_IMAGE}-%{MACHINE}.rootfs.ext4"

layers:
yocto_dir: "../%{YOCTOS_WORK_DIR}"
build_dir: "build-%{NODE_TYPE}"
output_dir: "../output/layers"
base_image: "aos-image-vm"
items:
pylibs-layer:
target: "aos-pylibs-layer"

libvis-layer:
target: "aos-libvis-layer"

matplotlib-layer:
target: "aos-matplotlib-layer"

Build Aos VM layers​

To generate Aos VM layers, configure build for main node:

moulin aos-vm.yaml --NODE_TYPE=main

And generate all specified in aos-vm.yaml layers:

ninja layers

As result, you should see all layers images in output/layers folder.

See meta-aos-vm README.md for details.

How to use layers you may find here