This README provides a structured guide to setting up and working with Yocto, a powerful build system for creating custom Linux distributions for embedded devices. It includes steps for installing necessary prerequisites, downloading recipes, building images, and adding additional layers.
For more detailed documentation, refer to the Yocto Project Documentation.
- Install Prerequisites
- Downloading and Setting Up Yocto
- Building an Image
- Adding More Layers
- Post-Build Steps
- QEMU Monitor and Running QEMU
- Saving the Kernel and Root Filesystem
- Resources
Before setting up Yocto, ensure you have the required packages installed on your system. Follow the instructions provided in the Yocto Project Quick Start Guide.
Run the following command to install the prerequisites:
sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \
build-essential chrpath socat libsdl1.2-dev xterm lz4
-
Clone the Poky Repository
Download the Yocto recipes by cloning the Poky repository. Make sure to use the appropriate branch (e.g., scarthgap):
git clone -b <release-name> git://git.yoctoproject.org/poky
-
Set Up the Build Environment
Navigate to the poky directory and set up the build environment:
cd poky source oe-init-build-env ../build-qemux86-64
-
Configure Local Settings
Inside the build directory, update the machine and download directories in
conf/local.conf
:MACHINE ??= "qemux86-64" DL_DIR ?= "/home/mahmoud/yocto2024/<release-name>/downloads"
-
Build the Image
In the build directory, issue the following command to build a minimal core image:
bitbake core-image-minimal
You can add more layers to enhance your Yocto build. While this is not necessary, it is recommended.
-
Clone Additional Layers
For example, to add the
meta-odroid
layer, clone the repository:cd poky git clone https://github.com/akuster/meta-odroid
-
Check Out the Correct Branch
Ensure that the layer is on the same release branch as Yocto (Poky). For instance, if Poky is on the
scarthgap
branch:cd meta-odroid git checkout scarthgap
-
Update
bblayers.conf
Update
conf/bblayers.conf
to include the new layer:BBLAYERS ?= " \ /home/mahmoud/yocto2024/<release-name>/poky/meta \ /home/mahmoud/yocto2024/<release-name>/poky/meta-poky \ /home/mahmoud/yocto2024/<release-name>/poky/meta-yocto-bsp \ /home/mahmoud/yocto2024/<release-name>/poky/meta-odroid \ "
The first three layers are added by default by Poky.
-
Build Finished
After the build is finished, you will find the image in
tmp/deploy/images/
. -
Navigate to the Image Directory
cd tmp/deploy/images/qemux86-64
-
Run the Image
runqemu core-image-minimal-qemux86-64 nographic
-
Save the Image File System and Your Information
It is recommended to copy the
bzImage-qemux86-64.bin
andcore-image-minimal-qemux86-64.ext4
files to a new directory. This is because any further changes you make in the Yocto build environment may overwrite your current image:mkdir -p ~/yocto2024/<release-name>/qemux86-64-demo cp tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.ext4 ~/yocto2024/<release-name>/qemux86-64-demo cp tmp/deploy/images/qemux86-64/bzImage-qemux86-64.bin ~/yocto2024/<release-name>/qemux86-64-demo
-
Run Your Saved Image
runqemu ~/yocto2024/<release-name>/qemux86-64-demo/core-image-minimal-qemux86-64.ext4 ~/yocto2024/<release-name>/qemux86-64-demo/bzImage-qemux86-64.bin nographic
QEMU Monitor is a command-line interface that allows you to control and interact with QEMU while it is running. It provides various commands to manage the virtual machine.
To run QEMU with a graphical interface (default mode), you can use the following command:
runqemu core-image-minimal-qemux86-64
This will launch the QEMU emulator with a graphical interface where you can interact with your running image.
In some cases, such as when you are working on a server without a graphical interface or when you want to run QEMU in the background, you can use the nographic
option:
runqemu core-image-minimal-qemux86-64 nographic
This will run QEMU without opening a graphical window. You can interact with the virtual machine through the terminal.
When running QEMU, you can access the QEMU Monitor by pressing Ctrl + Alt + 2
. This will switch the terminal to the QEMU Monitor interface. To switch back to the guest console, press Ctrl + Alt + 1
.
In the QEMU Monitor, you can use various commands to control the VM, such as:
info
: Display information about the VM.stop
: Stop the VM.cont
: Continue running the VM.quit
: Quit QEMU.
Example commands:
info status
stop
cont
quit
After building the image with Yocto, it is recommended to save the kernel and root filesystem files (bzImage-qemux86-64.bin
and core-image-minimal-qemux86-64.ext4
) to a separate directory. This helps prevent any changes made in the Yocto environment from affecting your built image.
-
Create a New Directory:
mkdir -p ~/yocto2024/<release-name>/saved-images
-
Copy the Image Files:
cp tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.ext4 ~/yocto2024/<release-name>/saved-images cp tmp/deploy/images/qemux86-64/bzImage-qemux86-64.bin ~/yocto2024/<release-name>/saved-images
-
Run Your Saved Image:
runqemu ~/yocto2024/<release-name>/saved-images/core-image-minimal-qemux86-64.ext4 ~/yocto2024/<release-name>/saved-images/bzImage-qemux86-64.bin nographic
By following these steps, you will be able to set up and work with Yocto to create custom Linux distributions tailored to your needs. This guide covers the essentials of installing prerequisites, downloading and setting up Yocto, building images, adding additional layers, and using QEMU Monitor for managing your virtual machines.