Creating a custom Yocto Layer and Image
Introduction
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.
- cd to Yoctro dir
- init env:
$ source poky/oe-init-build-env - leave build dir, do not change it, it's volatile:
$ cd .. - create custom layer:
$ bitbake-layers create-layer meta-custom - enter new layer directory:
$ cd meta-mistysom - create directory structure for custom image inside new recipe:
$ mkdir -p recipes-core/images(naming is important here) - Copy "core-image-minimal" recipe as template to customize:
$ cp ../poky/meta/recipes-core/images/core-image-minimal.bb recipes-core/images/custom-image.bb - Open
recipes-core/images/custom-image.bbfor customization:
$ vi recipes-core/images/custom-image.bb - Edit the file to look as depicted below:
SUMMARY = "My custom Linux image."
IMAGE_INSTALL = "packagegroup-core-boot ${CORE_IMAGE_EXTRA_INSTALL}"
IMAGE_LINGUAS = " "
LICENSE = "MIT"
inherit core-image
inherit extrausers
#Set rootfs to 200MiB by default
IMAGE_OVERHEAD_FACTOR ?= "1.0"
IMAGE_ROOTFS_SIZE ?= "294800"
# Change root password (note the capital -P)
EXTRA_USERS_PARAMS = "usermod -P 'toor' root"
Changes are:
- Changed
SUMMARYchanged to descripe the custom image - Added
inherit extrausersto haave access to theusermodcommand - Added
IMAGE_OVERHEAD_FACTOR, for more details, see here - Changed
IMAGE_ROOTFS_SIZEto294800which equals a rootfs of about 200MiB (it's not exact) - Added
EXTRA_USERS_PARAMS = "usermod -P 'toor' rootto set the root password totoor(as an example - bad security practice, don't deploy!) (to edit the file hitito enter insert mode where the cursor is) - save the file and exit ([ESC] +
:x)
- Return to
builddirectory:
$ cd ../build/ - Modify
bblayers.confto add the layer to the build process:
$ vi conf/bblayers.confand 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)
- 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.confand comment out theEXTRA_IMAGE_FEATURESline as follows:
( invisearch by entering/EXTRA_IMAGE_FEATURES, hitIto enter insert mode at beginning of line to insert the comment marker:#)#EXTRA_IMAGE_FEATURES ?= “debug-tweaks”
- save the file and exit ([ESC] +
:x)
- Invoke bitbake to build the custom-image:
$ bitbake custom-image(this will take a while to build & generate the output) - Upon completion, the custom images can be found in the output directory at
tmp/deploy/images/smarc-[boardname]