Learning Yocto Basics Part 2 [Getting Started with Poky]

    In this Post we shall learn how to download Poky project and understand its folder structiure and how to work with it. And we will create a minimal linux poky image and run it on a emulator which comes with poky called as quick emulator{QEMU}. SO if you follow the instructon given in this post the you can start from scratch and build a image and get a feel of ot running. Once you get the feel of poky build and running then you can learn more on that. We are using Ubuntu platform for this but any famous Linux based OS works fine for poky. Not that Windows or MAC etc wont work for poky as they are not linux based.

    In part1 post of this Yocto Series [Link Here] you got to understand basics of Yocto project and that Poky is a reference or example distro under Yocto project, it is time to download Poky and understand its structure. 

Note: The demo of the steps explained in this blog post is sown in the video at the end of the post.

Below are the pre-requisites for you to start with Poky

1. 50 Gbytes of free disk space
 
2. Runs a supported Linux distribution (i.e. recent releases of Fedora, openSUSE, CentOS, Debian, or Ubuntu). 
 
3. Softwares shown below must be installed
    Git 1.8.3.1 or greater
    tar 1.27 or greater
    Python 3.4.0 or greater.

Packages and package installation vary depending on your development system.

(*) Install the required packages for Yocto to Work from
        https://www.yoctoproject.org/docs/latest/ref-manual/ref-manual.html#ubuntu-packages

$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \
    build-essential chrpath socat cpio python python3 python3-pip python3-pexpect \
    xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev \
    pylint3 xterm

If these Prerequisites are satisfies then you can download the poky as below

Step1: Download the Poky project 

Open the terminal in the folder where you want to download the poky. you can download the poky fro git with below shown command

git clone git://git.yoctoproject.org/poky 

With this command the poky will be downloaded from git repository into your folder 

Then with Ls Listing command you can see the contents of poky folder. This would look something like as show in below snapshot.


 The contents of the poky folder are as shown below

 

Step 2: Setup the build environment

    You have to setup the build environment first before doing anything. You already know that the build system of Yocto or poky is bit-bake. But Since the bitbake command is specific for Yocto project and not recognized by the Ubuntu or any Linux platform you are working on, you will not be able to build the poky project and get the linux embedded image. So first you need to register the bitbake commands and other scripts into Environmental path variable. 
 
    To put it in simple terms, Bitbake is the build system which takes ll your metadata and source files and downloads the packages and fetch it and build it and schedule them and form a bootable image. But to use bitbake you need to register it in the underlying platform. This process of setting up bitbake and making it ready to use is called setting up the build environment. The build system bitbake is setup i the environmental variable $PATH so that bitbake commands are recognized and executed by your PC. 
 
    The good news is you dont have to do much circus to setup the evnironment yourself. Yocto project already has a script file in poky folder named oe-init-build-env which will take care of setting up the build environment for you. You just have to invoke it from terminal using the below command. 

source oe-init-build-env

This script file is a shell scripting file which will add 2 paths to the environment $PATH variable. They are
  • poky/scripts
  • poky/bitbake/bin
So upon running this script the build environment is setup and now we can use the bitbake build system. We can see these commands in action from below snapshot where you can see these commands and how the environmenta variable is updated clearly. 

Also you can note that a build folder is created in the poky directory with build environment related files. as shown below

This build folder has 3 files [poky-->build-->conf--> Here]
  • bblayers.conf
  • local.conf 
  • templateconf.cfg


Step 3: Building a minimal image

    Now since the Build environment is setup, the build tool bitbake can be used. So you can build a basic poky image by running the below command


bitbake core-image-minimal

This command will create a minimal linux image. Bitbake will download all the packages specified in recipes and configure them and install them and form a base image. For the first time it takes long time to build as all the packages have to be downloaded. Consecutive times with minor changes the time taken will be less. Make sure that you have un-interupted internet connection as it will have to download various packages and install them in build folder to create the embedded linux poky image. So after giving this command just leave it to build and take rest. If any problems occur then bitbake will exit and errors will be displayed in the terminal. Make sure that you have sufficient memory on disk allocated to it. Once the image is created, bitbake is successfully completed and it looks something like screenshot shown below:
 

 Once the image is built for qemu, you can run the image on qemu. IN the snapshot aboe you can note that the image can be run on intel x86 machine and for qemu. So you don't need any external embedded system to try out this image. SO you do it with an emulator called as quick emulator or qemu for short which comes with poky project itself to test the working of the image. So that is the next step.


Step 4: Running the Image on Quick Emulator [QEMU]

    Since the image is built, we can now run it on our quick emulator and check if it works fine. The command to run the image on the emulator is simple and is shown below.


runqemu

When you give this command, the console will promt for the password as you need to be sudoer to run the emulator and you need to enter your password as shown below:
 

 
Once the Qemu is run, the image will be bootup and the image will be running in a Qemu Pop up as shown in below screenshot:


    For the emulator, the pop up has appeared and as shown above after booting up of the image first thing it asks is the login credentials. By default the root user doesn't have any password so you ca login as root and no password needed. 

    So once logged in you can execute normal linux commands. For example I have executed the date command in above screenshot and you ca see that the command is executes successfully.  

    If you want to exit the emulator you can either give the command poweroff or just close the window manually.

Demo Video of steps explained in this post is shown below
 

So in this blog post, you learnt how to download a poky project from git repository of yocto project and build a minimal image for x-86 (Default) machine and run the image on a emulator (qemu). So eve though you did not make any modification, you got a feel of Poky project and image. IN next parts of this Yocto Series, we shall learn how to modify configurations and slowly reach our goal of designing our own application and running it on Qemu or a board.

Comments

Popular posts from this blog

Learning Yocto Basics Part 1 [Understanding basics terms]