Build a Raspberry Pi 2 Minimal Image with The Yocto Project

The Yocto Project is a build system that allows developers to make custom Linux distributions matching their exact needs. I’ve already shown how to build a 12MB Compressed image for the Raspberry Pi with Yocto, but the Raspberry Pi 2 has recently been added to the project, so I’ve tried to build it too in a machine running Ubuntu 14.04.

Raspberry_Pi_2_Yocto_ProjectI’ll use poky since it’s the default, but you could also build the system for Angstrom or without distributions (OpenEmbedded Core only). The steps to get the code is just the same as for the Raspberry Pi:

You just need to checkout master, and not any branch (like dizzy) since R-Pi 2 is not yet supported in any release. Initialize some environment variables and the build directory:

Now edit conf/local.conf with vim or nano to set the machine to raspberrypi2 instead of qemux86:

There are more Raspberry Pi specific option in the README for setting the GPU memory, overclocking, adding VC-1 or/and MPEG-2 licenses, and so on.

You also need to add the path to meta-raspberrypi in conf/bblayers file, so that it looks like:

Two minimal images are available: rpi-basic-image and rpi-hwup-image. I’ve built rpi-basic-image, which adds ssh-server-dropbear (for ssh server support) and splash (for the splash screen).

This will take a while, possibly over one or more hours, and upon completion the log shown in the terminal windows should look similar to:

The step “0: bcm2835-bootfiles-20150206-r3 do_fetch (pid 25484)” may take a long time as it’s cloning a few gigabytes of data for the firmware stored in GitHub. Just be patient, this step took several hours on my machine.

You can now flash the image to a micro SD card with:

Where you need to replace X with the letter of your SD card, which you can check with lsblk. Alternatively, you could also flash the image with Win32DiskImager in Windows. Here’s the compiled image for your reference: rpi-basic-image-raspberrypi2-20150227091441.rootfs.rpi-sdimg (104 MB). You’ll also need to use tools like gparted to expand the ext-4 partition to make use of all the space on your micro SD card.

You’d then just have to insert the micro SD card into your Raspberry Pi 2, boot, and login as root without password. I have not tried, since I don’t have a Raspberry Pi 2 yet.

Share this:
FacebookTwitterHacker NewsSlashdotRedditLinkedInPinterestFlipboardMeWeLineEmailShare

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX RK3588 mini-ITX motherboard

40 Replies to “Build a Raspberry Pi 2 Minimal Image with The Yocto Project”

  1. I got the Model B on raspbian to run with about 50Mb RAM usage only, acting as a router and bandwidth usage controller for about 9 people.

    Do you think Yocto will be a better choice for basic tasks?

  2. @Jean
    Rasbian will be easier to use since you can run apt-get to install packages.

    With the Yocto Project, I understand you need to add the required package at build time, or maybe opkg may be used to. If you need a small image booting from a 128MB SD card, Yocto/Poky may be the only option however.

  3. A better compromise between Yocto and Raspbian is Arch ARM Linux’s port… It runs Arch so you can use pacman to install the latest packages of software. It is a minimal install…no desktop bloatware no junk…install just what you need.

  4. There is no one best distro.

    If you need minimal or completely customised look at yocto/angstrom or build your own arch linux
    thing to remember is you need to maintain it and do any patching for security bugs etc

    For learning and newcomers to raspberry pi stick with raspian
    otherwise go for your favourite/prefered distro.

  5. If you need qt 4 or 5 on your board, plus a full cross compiling environnement with qtcreator, Yocto is the best option I found so far.
    (the other one is to cross compile qmake from source).

  6. For some reason I never seems to be able to build the image. I always get an error message :

    “ERROR: OE-core’s config sanity checker detected a potential misconfiguration.
    Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
    Following is the list of potential problems / advisories:

    Please set a valid MACHINE in your local.conf or environment”

    There must be something I’m missing and/or do not understand. Could you please give me a hint as to why the “MACHINE” argument “raspberrypi” and “raspberrypi2” are not accepted.

  7. @cnxsoft
    Yes I did.

    I think conf/local.conf doesn’t exist if you don’t run “. oe-init-build-env build” first.

    I tried to do what’s in your other post on the raspberrypi with the dylan branch of poky and I get the same error message.

  8. @cnxsoft
    Ok, My bad… I did a mistake in bblayers.conf

    I now get a lot of errors from bitbake. Seems to be python related… I’ll try to work thoses out.

    Thanks for the nice blog post

  9. Thanks for your articles really helped me to get started.

    I have found out that if you add these two parameters to your build/conf/local.conf file you get an image with free space so you don’t have to expand the size afterwards.

    IMAGE_EXTRA_SPACE = “4194304”

    This gives you 4GB free space on the file system.

    And another useful parameter is this one.


    It set the overhead factor to 50% default is 30% so this is another way to get more free space on the file system.

    But last and the best parameter in my opinion is this one.

    IMAGE_ROOTFS_SIZE = ” 4194304”

    That gives you a size of 4GB file system.
    Note that this 4GB file system (4*1024*1024*1024 bytes) and will not fit on a 4GB SD-card. So to get file system that fits on a 4GB card you should probably use something like this. (4*1000*1000*1000/1024=3906250)

    IMAGE_ROOTFS_SIZE = ”3906250”

    Note that the sdimg file will get this size so to distribute it you probably want to compress the file and end up with something around 19MB

  10. Hi
    I have trouble getting the thing to work for my rpi2 model B
    as soon as I start bitbake it shows an error after 4% parsing recipes “ERROR: Unable to determine endianness for architecture ‘armv7l’ … please add it to siteinfo.bbclass

    If I add the armv7l entry to meta/classes/siteinfo.bbclass by copying the regular arm entry and just changing it to armv7l
    bitbake starts to run and brings an error “can not map armv7l to a linux kernel architecture” but continuous!
    after it starts the tasks and it reaches task 4 of 2000somthing… it stops running with several errors

  11. Hi,

    The image generated by following the procedure mentioned above works without any issues on Raspberry Pi 2. Thanks.

    But when I tried to add some graphics application on top of this, I get following error:
    | No package ‘egl’ found
    | No package ‘glesv2’ found

    For the benefit of others like me, can you add a section on how to add these packages.

  12. Hi Aananth
    I followed the exact same procedure as mentioned above and get the error I described….
    Any idea why that might be?


  13. could it be that its not working for me because I try to do it via an Ubuntu 14.10 installation on the raspberry Pi2?

  14. @Eike
    Hi Elke,

    My 2 cents:

    The problem you stated above is related to endianness of the “target” architecture. The build system seems to be bit confused. So, I see it as a configuration problem than a environment or OS issue. Note: I did not face such issues. I used Ubuntu 14.04.

    Can you double confirm if you set the value of MACHINE as raspberrypi2?

    Also can you paste all your error messages in and copy the link to that page here. That should allow as to understand the issue in more detail.

  15. I followed the above directions,b ut for some reason the produced image does not include several critical packages, such as python. Are these not supposed to be included, or am I doing something wrong?

  16. I managed to fix my previous issue, but now I am having trouble with wiringPi. It appears to install successfully, but as near as I can tell, only the gpio portions make it into the image. the various header files, at least (wiringPi.h, ect.) are nowhere to be found. Please advise

  17. Hi,

    Thanks a ton for this! I was able to build and boot on a RPI2B:

    Poky (Yocto Project Reference Distro) 1.8+snapshot-20150527 raspberrypi2 /dev/ttyAMA0

    raspberrypi2 login: root
    root@raspberrypi2:~# uname -a
    Linux raspberrypi2 3.18.11 #1 SMP PREEMPT Wed May 27 01:41:03 CDT 2015 armv7l GNU/Linux

    How do I go about building a full file-system?


  18. Raphael :
    For some reason I never seems to be able to build the image. I always get an error message :
    “ERROR: OE-core’s config sanity checker detected a potential misconfiguration.
    Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
    Following is the list of potential problems / advisories:
    Please set a valid MACHINE in your local.conf or environment”
    There must be something I’m missing and/or do not understand. Could you please give me a hint as to why the “MACHINE” argument “raspberrypi” and “raspberrypi2″ are not accepted.

    I had this. Check you’r branchs! Keep in mind to be on master

  19. Ubuntu 15.04..

    Failed to create a file with a long name in TMPDIR. Please use a filesystem that does not unreasonably limit filename length.
    Failed to create a file with a long name in SSTATE_DIR. Please use a filesystem that does not unreasonably limit filename length.


  20. Hello,

    I tried to build the image following the above steps.
    Unfortunatly the “bitbake” process ends up with a compile error of the kernel:

    /home/kai/poky/build-raspberrypi2/tmp/work-shared/raspberrypi2/kernel-source/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c: In function ‘set_resume_state’:
    /home/kai/poky/build-raspberrypi2/tmp/work-shared/raspberrypi2/kernel-source/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c:1780:1: error: inlining failed in c
    all to always_inline ‘set_suspend_state’: function not inlinable
    set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
    /home/kai/poky/build-raspberrypi2/tmp/work-shared/raspberrypi2/kernel-source/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c:1836:3: error: called from here
    set_suspend_state(arm_state, VC_SUSPEND_IDLE);

    I’m using Yocto 1.8 and I have downloaded the latest raspberry meta files from git.
    Any idea how to fix it ?


  21. This short tutorial worked out of the box! Great!

    bitbake informed me to install some additional packages. Which i did.
    After “dd”, do not forget to call “sync”

    Simply ignore the:
    WARNING: Host distribution “openSUSE-project-13.2” has not been validated with this version of the build system; you may possibly experience unexpected failures. It is recommended that you use a tested distribution.

  22. @cnxsoft
    Well, I’ve just started with the Pi 2 now, so YMMV. But with the FreeScale units I deal with, I can create cross-compile tools to build software (whether GNU or in-house developed). It’s nowhere near as easy as “apt-get install bind9” so Raspbian would be a lot easier for a beginner.

    We use Yocto, however, since if we don’t specifically include it in the recipe, it never gets into the finished image. So the image is smaller, RAM use is tightly controlled, and the exploit exposure surface is kept as small as possible. All important considerations for production embedded development.

  23. @Raphael
    I had this error, but Yocto is pretty clear about what it is missing. It is saying it cannot find the specified machine.

    I looked over the instructions I had followed and they left out a rather important layer:
    /home/steveda/rpi2b/poky-fido-1.8/meta-raspberrypi \

    Adding that layer in bblayers.conf and that error goes away…

  24. About half-way through the build process, I am getting a missing file error:
    /home/mrush/yocto/poky/build/tmp/work/raspberrypi2-poky-linux-gnueabi/u-boot-rpi/git-r0/git/include/linux/compiler-gcc.h:87:30: fatal error: linux/compiler-gcc5.h: No such file or directory
    compilation terminated.

    Is anyone else experiencing this?

    I cloned both yocto:master branches as per the instructions above and am doing the build on a fresh install of Ubuntu 14.04 server:
    uname -a
    Linux buildsvr2 3.19.0-49-generic #55~14.04.1-Ubuntu SMP Fri Jan 22 11:24:31 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

    I did a simple “apt-get install build-essential”. Is there something more I should have done?

  25. @cnxsoft
    Thank you for the reply.

    That was actually the first thing that I did. However, when I copied the compiler-gcc5.h over to the location bitbake was expecting it, I then got a huge number of errors.
    That’s when I decided that the issue wasn’t simply a missing file, but rather some sort of set up problem on my machine.

    So, in my message, I specified that my build machine is a fresh Ubuntu 14.04 server in which I performed the following steps:
    sudo su
    apt-get update
    apt-get upgrade
    apt-get dist-upgrade
    sudo apt-get install build-essential git
    sudo apt-get install diffstat gawk chrpath texinfo
    mkdir yocto
    cd yocto/
    git clone git://
    cd poky/
    git clone git://
    . oe-init-build-env build
    cp ~/local.conf conf/.
    cp ~/bblayers.conf conf/.
    bitbake rpi-basic-image

    Clean, up to date machine, fresh repos. The correct headers are installed on the machine (compiler-gcc5.h is under /usr/src/…)
    So, it comes as a bit of a surprise that Yocto still needs some manual help here.

  26. @Mark Rush
    You can’t simply copy the file. You’d need to install linux-headers package, but since you’ve got the file already, you’ve probably done so already. I’m not sure what the exact problem may be then.

Leave a Reply

Your email address will not be published. Required fields are marked *

Khadas VIM4 SBC
Khadas VIM4 SBC