Yocto - How to
Yocto |
---|
What is Yocto |
Tools |
How to |
Contact Us |
Introduction
In here you can see how to make various specific things with Yocto
Create Custom Image
Instead of changing the features and packages of an image through conf.local
, you can create a custom image recipe, where you set all your preferred features and packages.
In this example, we will inherit from core-image-minimal
, and will just add openssh
.
Let's go to the directory where the core images are located:
cd poky/meta/recipes-core/images
Create a new file (let's say, my-cool-image.bb
) with the following contents:
SUMMARY = "A very cool image (just core-image-minimal + ssh)" LICENSE = "MIT" inherit core-image IMAGE_FEATURES += "ssh-server-openssh"
Now let's build our custom image:
bitbake my-cool-image
Test it with qemu:
runqemu my-cool-image
Login as root, and try to run:
ssh
You will see the usage message. It means that our image has openssh.
You can even get the ip
of the image running the emulator and try to connect to it using ssh from your computer.
Create Custom Distro
Similar to a custom image, you can also create a custom distribution, which takes out the overhead of adding everything to the local.conf of the build.
To do so, follows these steps:
1. Create or use a new layer and modify its conf, in this case, we use meta-mydistro
bitbake-layers create-layer meta-mydistro cd meta-mydistro mkdir -p conf/distro
2. Create a configuration file distro-name.conf
for the distro with the following content:
DISTRO = "distro-name" DISTROOVERRIDES = "poky" require conf/distro/poky.conf
Here you can add any new configuration you want to add for the distribution, as if it was you local.conf of the build.
3. In you local.conf just use this new distro by adding:
DISTRO ?= "distro-name"
Preferred Recipe Version
To set a preferred version you can for example:
Add the curl package to conf/local.conf
IMAGE_INSTALL_append += " curl"
And then choose the version we just copied (conf/local.conf
too):
PREFERRED_VERSION_curl ?= "7.64.1"
Build your image:
bitbake core-image-minimal
Now let's run qemu to be sure our version was added:
runqemu core-image-minimal
Login as root and then run:
curl --version
You should see a message with version 7.64.1, which indicates we installed the version we set at the config file.
List the packages in an image
To get a list of the software packages included in an image, you can use the bitbake -g command, this will generate a text file called pn-buildlist with all the package names built for this image and a task-depends.dot with the dependency tree information for the image.
Since we are interested in the software packages included in the image for our target, we can filter out all the package names with the -native suffix, since these produce binaries intended for the host machine. Therefore, you can use the following command to generate the list of packages included in the image:
bitbake -g <image name> && cat pn-buildlist | grep -ve "native" | sort | uniq
Find the recipe used to build a package
In some cases, there are multiple recipes for the same package. For instance, the following command shows the recipes for GStreamer plugins base:
bitbake-layers show-recipes gstreamer1.0-plugins-base
The output may show more than one recipe:
NOTE: Starting bitbake server... Loading cache: 100% |###################################################################################################################################################| Time: 0:00:00 Loaded 4099 entries from dependency cache. === Matching recipes: === gstreamer1.0-plugins-base: meta 1.18.6 meta-freescale 1.18.0.imx
According to the documentation, the preferred package version/recipe is listed first. However, to confirm the recipe being used, one can use the bitbake -e command to show the complete environment for the package and look for the FILE variable value, which is set to the recipe file being used. For example:
bitbake -e gstreamer1.0-plugins-base | grep ^FILE=
The command above returns the full path to the recipe used to build the GStreamer plugins base package.