Creating a custom Yocto Layer and Image


This tutorial explains how a custom Yocto layer and a custom bitbake image can be created. It's only for display purposes and should not be used & deployed as is as setting the root password as shown below, is insecure.

  1. cd to Yoctro dir
  2. init env:
    $ source poky/oe-init-build-env
  3. leave build dir, do not change it, it's volatile:
    $ cd ..
  4. create custom layer:
    $ bitbake-layers create-layer meta-custom
  5. enter new layer directory:
    $ cd meta-mistysom
  6. create directory structure for custom image inside new recipe:
    $ mkdir -p recipes-core/images (naming is important here)
  7. Copy "core-image-minimal" recipe as template to customize:
    $ cp ../poky/meta/recipes-core/images/ recipes-core/images/
  8. Open recipes-core/images/ for customization:
    $ vi recipes-core/images/
  9. Edit the file to look as depicted below:
SUMMARY = "My custom Linux image."

IMAGE_INSTALL = "packagegroup-core-boot ${CORE_IMAGE_EXTRA_INSTALL}"



inherit core-image
inherit extrausers

#Set rootfs  to 200MiB by default

# Change root password (note the capital -P)
EXTRA_USERS_PARAMS = "usermod -P 'toor' root"

Changes are:

  • Changed SUMMARY changed to descripe the custom image
  • Added inherit extrausers to haave access to the usermod command
  • Added IMAGE_OVERHEAD_FACTOR, for more details, see here
  • Changed IMAGE_ROOTFS_SIZE to 294800 which equals a rootfs of about 200MiB (it's not exact)
  • Added EXTRA_USERS_PARAMS = "usermod -P 'toor' root to set the root password to toor (as an example - bad security practice, don't deploy!) (to edit the file hit i to enter insert mode where the cursor is)
  • save the file and exit ([ESC] + :x)
  1. Return to build directory:
    $ cd ../build/
  2. Modify bblayers.conf to add the layer to the build process:
    $ vi conf/bblayers.conf and add the path to new layer on the bottom of the list of existing layers: ${TOPDIR}/../meta-custom \
  • save the file and exit ([ESC] + :x)
  1. There is a variable assignment that conflicts with the default password and as a result, the login does not work properly. In order to get around this, open build/local.conf:
    vi build/local.conf and comment out the EXTRA_IMAGE_FEATURES line as follows:
    ( in vi search by entering /EXTRA_IMAGE_FEATURES, hit I to enter insert mode at beginning of line to insert the comment marker:#) #EXTRA_IMAGE_FEATURES ?= “debug-tweaks”
  • save the file and exit ([ESC] + :x)
  1. Invoke bitbake to build the custom-image:
    $ bitbake custom-image (this will take a while to build & generate the output)
  2. Upon completion, the custom images can be found in the output directory at tmp/deploy/images/smarc-[boardname]