12MB Minimal Image for Raspberry Pi using the Yocto Project

Orange Pi Development Boards

Last year, I wrote instructions and provided a download link about a minimal image for Raspberry Pi based on Raspbian. The compressed image is 84MB, and the good thing about it is that you can just use apt-get to install packages. The problem is that it’s not actually that small as once it is uncompressed the rootfs is still a massive 414 MB.

So today, I’ll explain how to create a smaller (and custom) image using the Yocto Project, a platform that let you build an embedded Linux distribution matching exactly your project’s requirements. Other advantages are that the build is configurable with config files, so it’s easily reproducible with a few command lines, and it might turn out to be useful to learn more about the Yocto Project as many boards and SoC are now making use of the framework, including Freescale i.MX6 (Wandboard, Olinuxino-imx233, Sabrelite, etc…), the Beagleboard, and Minnowboard to name a few.

If you just want the image, you can download the compressed image (12MB), extract it, use dd to copy it to your SD card, and gparted to resize the rootfs. This is an image that’s only useful for (headless) embedded systems, but more likely than not, you’d want to customize it with the instructions below.

I got started with instructions from pimpmypi, but these are a little old, and now everything seems much simpler. I’ve performed the steps below in a PC running Ubuntu 12.04 LTS, and with most dependencies required (e.g. build-essentials, git) already installed.

First you need to get poky and the meta layer for Raspberry Pi:


dylan is the codename of the latest Yocto Project release (Version 1.4).

Then you can run the following command line to initialize some environment variables and the build directory:


Now edit conf/local.conf with vim or nano to optimize the build speed depending on your PC processor (generally number of threads/cores +1), set the machine as Raspberry Pi, and possibly adjust the GPU memory, by updating or adding the corresponding lines:


You may want to check the README if you want to overclock your R-Pi board, change the rootfs type, add VC-1 or/and MPEG-2 licenses, or disable overscan. All those extra options, including GPU_MEM, can be added by editing config.txt directly in the SD card, but doing it before the build makes the steps automatically reproducible.

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


Now we’re ready to build the image. There are two images possible: rpi-basic-image and rpi-hwup-image, both of will provide a minimal image, but rpi-basic-image will add ssh-server-dropbear (for ssh server support) and splash (for the splash screen). Let’s go with rpi-basic-image:


It took just over one hour in my computer, but it may take less or much more time depending on your computer and/or Internet connection.

Once the build is complete you should see a file called tmp/deploy/images/rpi-basic-image-raspberrypi.rpi-sdimg, which is a symlink to the binary image you want to dump on your SD card. The file size is 80MB, but it can be compressed to 12MB if you want to distribute over the Internet:


Now insert an SD card in your Linux computer, and check the device name:


Since I have a USB hard drive attached to my computer I do this all the time, because sometimes the SD card is /dev/sdb, and other times /dev/sdc, and if I use the wrong one, all my data will be lost.

Let’s copy the image with dd or dd.sh:


Now remove the SD card, and reinsert it. The ext-3 partition in the image is only 55MB, so to make full use of your SD card storage capacity, you need to resize the partition with the command line, or easier, with gparted. Resizing from the Raspberry Pi won’t work with this image, as resize2fs utility is not available.

We’re now ready to try it out. Let’s insert the SD card into the Raspberry Pi, and connect the power. You can access the console via HDMI, the UART port, or if you’ve connected an Ethernet cable via ssh.

Near the end of the boot, or when you access the board with SSH, you should see:


Login with as root without password.

Let’s check some details about the kernel:


busybox:


available space:


and available memory:


We’ve got a recent kernel, only 42.8MB of the root file system is used, and 232MB RAM available on a Raspberry Pi Model B with 256 MB RAM.

Let’s check the kernel config on the board:


You can download the kernel config for details.

If you want to save even more memory, or add features, you can change the kernel configuration with:


and build the kernel with:


Busybox can also be tuned with the commands:


The images recipes are located in poky/meta-raspberrypi/recipes-core/images, and you you could copy rpi-basic-image.bb to rpi-myappliance-image.bb, and edit the later to add the recipes/packages you need.

But this may be difficult, if you don’t know exactly what you need, and luckily the Yocto Project also have a graphical interface called “hob” that you can just start from the build directory. Let’s start with rpi-hwup-image for the Raspberry Pi by selecting the corresponding machine and base image:

Raspberry_Pi-Yocto_Hob

You can then either select “Edit Image” to add recipes and/or package groups, or simply click “Build Image” to start the build. Let’s just do that. The build is now much faster since most packages have already been built when we ran “bitbake rpi-basic-image”.

R-Pi_Yocto_Hob_Task

After a few minutes, you should the “Your image is ready” window below with easy access to the binaries and log files:

Yocto_Hob_Raspberry_Pi_Build_Complete

If instead of clicking “Build Image”, you clicked on “Edit image” you’d have access to the list of included recipes, all recipes and package groups. In the screenshot below I searched for recipes with “bcm” and “rpi” names. bcm2835 is used for GPIO support, so you may want to include it in the build.

Yocto_Rpi_Edit_Recipes

Once you’ve selected the required packages, click on “Build Packages”, and after a while, Step 2 window will appear and let you click on “Build Image”. Your custom SD card image will be available in tmp/deploy/images/ directory with the name hob-image-raspberrypi.rpi-sdimg.

That’s just a small overview of what’s possible with the Yocto Project for the Raspberry Pi board. For further details you may want to check the project’s documentation, and you may also read Hob’s manual for specific details about Yocto’s GUI.

Support CNX Software - Donate via PayPal or become a Patron on Patreon

72
Leave a Reply

avatar
72 Comment threads
0 Thread replies
2 Followers
 
Most reacted comment
Hottest comment thread
22 Comment authors
Dr. Sherif OmranAdrian[OE] Build một bản Linux cho Raspberry PI B+ sử dụng OpenEmbedded | ===Write to read next===Don PedroSomasekhar Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
manuti
Guest

Incredible, congratulations. This summer if I have enough time I try to prepare my own little distro with your instructions.

trackback

[…] (E, para quem quer fazer sua própria distro Pi pra dar asas à imaginação, como fazer uma distro mínima graças ao Yocto Project) […]

Vinicius Tinti
Guest
Vinicius Tinti

Hi,

Should not it be?

mkdir yocto
cd yocto
git clone -b dylan git://git.yoctoproject.org/poky.git
cd poky
git clone -b dylan git://git.yoctoproject.org/meta-raspberrypi

Regards

Rich
Guest
Rich

Thanks for pointing me in this direction. I already have a nice custom build for my Pi thanks to this. I do have some issue though – on first boot ethernet is working fine, but on subsequent boots it doesnt. I have to goto a prompt (using a monitor etc) and manually do “ifdown eth0” then “ifup eth0” and it is working again.

Have you seen this happen, and if so how did you fix it?

Eduardo
Guest

i tried your commands but bitbake is failing here:

Pseudo is not present but is required, building this first before the main build
ERROR: Unable to parse /home/edsiper/coding/yocto/poky/meta-raspberry/conf/layer.conf: [Errno 2] No such file or directory: ‘/home/edsiper/coding/yocto/poky/meta-raspberry/conf/layer.conf’

i cannot find the missing dependency package…

trackback

[…] to use a minimal image built with Yocto instead. I’ve already written the instructions to use Yocto for Raspberry Pi previously, but I won’t use the exact Yocto image I generated in that post, as I’ll […]

trackback

[…] I’ve recently used Yocto to build Linux for the Raspberry Pi, I’ve created a new image recipe in meta-raspberrypi/recipes-core/images/rpi-ble-image.bb: # […]

danial smith
Guest
danial smith

please teal me how can i install gui interface (Desktop) and install other application on it ???

kazaar
Guest
kazaar

I tried to follow the steps to the letter, tried under Fedora and Ubuntu distributions.
Every time bitbake stops at this point:

0: linux-raspberrypi-3.6.11+git31a951046155b27361127d9cf85a1f58719fe9b3-r6 do_fetch (pid 1705)
1: linux-libc-headers-raspberrypi-3.2.27-r0 do_fetch (pid 1690)
2: bcm2835-bootfiles-20130107-r3 do_fetch (pid 1706)

It seems to be unable to get those files and I don’t know how to get them in other way. Tried to google for the problem without luck.

Any Ideas?

Luke
Guest
Luke

Thank you very much for this. I have reconstructed your described build process and flashed the resulting image. After dding it to the SD, inserting SD, HDMI and uUSB power, the green ACT LED flashes up once, red LED lights up permanently, nothing is visible on the HDMI Monitor. Plugging in USB keyboard, caps lock LED does not react. I tried the same with your prebuilt image with the same result. Using a rasbian as reference from the same SD works well. Any hints would be most appreciated.

Luke
Guest
Luke

@kazaar
Just wait until bitbake finished cloning those git repositories. Especially the kernel might take a while, maybe hours. A workaround would be to modify the kernel recipe changing the original SRC_URI to a mirror.

Unless it encounters an error and notifies you about that, bitbake won’t stop.

Luke
Guest
Luke

@cnxsoft
Thanks, same symptoms writing your image to an old 2GB SD. Also, with the other SDHC card, rasbian works, yocto images don’t. So I guess I cannot blame the SD. Looks like I will have to recover my old FTDI cable.
Do you get any output on your HDMI display and usb function by default in the posted image?

Luke
Guest
Luke

@cnxsoft
Ok. So I hooked up the FTDI cable.
16 GB SanDisk Class 100 SDHC

2013-09-25-wheezy-raspbian.img will give a bunch regular linux boot kernel messages in the terminal. I can connect usb hdmi and everything works instantly.

rpi-basic-image-raspberrypi-20130702123605.rootfs.rpi-sdimg will give this �<� in terminal and no hdmi or usb interaction.

Might this be related to different hardware revisions ? A sticker on the back of my RPI says E1613RS2V13B1.0
Do you have a similar identifier?

Luke
Guest
Luke

That’s great! Something similar here http://blog.rogiervandenberg.nl/2013/05/how-to-fix-boot-problems-with-hynix.html

In fact I do have a newer version with hynix memory. Will update once tested

Luke
Guest
Luke

@cnxsoft
Win 🙂

So for everybody who encounters the no boot problem:

Using

bootcode.bin
cmdline.txt
config.txt
*.elf

from

http://downloads.raspberrypi.org/images/raspbian/2013-02-09-wheezy-raspbian/2013-02-09-wheezy-raspbian.zip

fixes the yocto 1.4 images on my newer 512MB hynix memory raspberry pi.

phil
Guest
phil

@cnxsoft
Hi,

I tried with dora for both poky and meta-raspberrypi and I’ve this error when I bitbake basic image:
ERROR: No recipes available for:
/home/plegal/svn/rpi/poky/meta-raspberrypi/recipes-graphics/mesa/mesa_9.2.2.bbappend
ERROR: Command execution failed: Exited with 1

So I tried dora for poky and dylan for meta-raspberrypi and I still have the no boot problem.

One solution is to replace the bootcode.bin, start.elf and start_cd.elf from the deploy img with the same files in the last noobs_v1.3.2 image.

After that it boots.

phil
Guest
phil

@phil
OK, it’s compile and boot fine if we change mesa_9.2.2 to mesa_9.1.6 and if we change the preferred kernel to 3.8.%

trackback

[…] a Wandboard or Raspberry Pi for instance Have a look at Getting started with Yocto on Wandboard or 12MB Minimal Image for Raspberry Pi using the Yocto Project to get […]

Paul
Guest

Hello, I created the minimal rpi-hwup-image image and it boots great. Problem is in eclipse for my c project I am using tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabi-raspbian I have used the normal or hard floating point.
The hard floating point creates an executable that when I run on this build it just says “not found” like it doesn’t even understand it. So I changed it to soft floating point and I get “segmentation fault”. My only linker entry is for pthread. What compiler works with this build? I would really appreciate your help. Thanks.

Filip
Guest
Filip

Is it possible to configure yocto to be build for raspberrypi with hard-float support set?

Sheeru
Guest
Sheeru

I am currently trying to add new packages to rpi-basic-image and build my custom distribution. I started with hello world package. I created a new meta layer and I wanted to add additional packages to the image in that layer.

I tried testing with the hello world auto tooled package. This hello
world is the hello world autotooled package downloaded from
ftp://ftp.gnu.org/gnu/hello/hello-2.7.tar.gz. When trying
to execute that bb, am getting the error as follows,

| make: *** No rule to make target `install’. Stop.
| ERROR: oe_runmake failed

My bb file is as follows,

DESCRIPTION = “Dummy”
SECTION = “package”
LICENSE = “CLOSED”
PR = “r0”
SRC_URI = “file://hello/”
inherit autotools gettext

After executing this bb file, i took a look at the logs of configure.
It says nothing to configure.

Please help me with what’s wrong with this process am following?

Aananth C N
Guest
Aananth C N

The image generated out of “bitbake rpi-basic-image” works well on Raspberry Pi Rev B model. But it does not work on Rev B+ model hardware. Any one verified this?

Aananth C N
Guest
Aananth C N

@cnxsoft
Thank you. It worked after updating the firmware as per the link above.

Vincent Wang
Guest
Vincent Wang

Hi @cnxsoft , thank you very much for the share. I’m using “bitbake busybox -c menuconfig” and customized the utilities working good. But when I trying to add telnetd utility via busybox, I find that I need to add some configuration in rootfs, for telnetd to auto launch and configure itself. How can I find the way to add my own files to rootfs and let bitbake compile it together with the whole rootfs?

Deepak
Guest
Deepak

Hi

I have Rasberry Pi B+ board and downloaded the 12 Mb compressed image from the link specified in your blog.
After decompressing it I issued following command from terminal of my Ubuntu 14.04
sudo dd if=./rpi-basic-image-raspberrypi-20130702123605.rootfs.rpi-sdimg of=/dev/sdb bs=1M

Bow I have inserted the SD card on my board and attached Keyboard and Monitor to it.

My issue is When I give power to the board then nothing comes up. Can anyone help ??

Oolav
Guest
Oolav

Hi,

I ran a bitbake rpi-base-image then tweaked a few things with hob. Problem is I don’t get any *.rpi-sdimg in my deploy dirtectory now.

Do you know how to build an sd card image from just Image-*.bin and rpi-basic-image-raspberrypi.rootfs.* files ?

Regards.

Oolav
Guest
Oolav

@Oolav
I found the solution to my problem :

using hob adds a few lines to your local.conf file.
add to comment the lines below :

#added by hob
#IMAGE_FSTYPES = “ext3 tar.bz2”

Then bibake rpi-basic-img creates the *.rpi-sdimg file.

Do you think I could add “rpi-sdimg” to the IMAGE_FSTYPES variable ? would it work ?

Peter
Guest
Peter

bitbake rpi-basic-image results in:

ERROR: Function failed: Unpack failure for URL: ‘http://www.rpm5.org/files/rpm/rpm-5.4/rpm-5.4.9-0.20120508.src.rpm;extract=rpm-5.4.9.tar.gz’. Unpack command PATH=”/home/yocto/poky.git/scripts/native-intercept:/home/yocto/poky.git/scripts:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin/armv6-vfp-linux:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/sbin:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/sbin:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux//bin:/home/yocto/poky.git/scripts:/home/yocto/poky.git/bitbake/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.3″ rpm2cpio.sh /home/yocto/my-rpi-build/downloads/rpm-5.4.9-0.20120508.src.rpm | cpio -id rpm-5.4.9.tar.gz failed with return value 1
ERROR: Logfile of failure stored in: /home/yocto/my-rpi-build/tmp/work/x86_64-linux/rpm-native/5.4.9-r63/temp/log.do_unpack.28861
Log data follows:
| DEBUG: Executing python function do_unpack
| DEBUG: Executing python function base_do_unpack
| NOTE: Unpacking /home/yocto/my-rpi-build/downloads/rpm-5.4.9-0.20120508.src.rpm to /home/yocto/my-rpi-build/tmp/work/x86_64-linux/rpm-native/5.4.9-r63/
| /home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin/unlzma: /lib64/liblzma.so.5: no version information available (required by /home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin/unlzma)
| /home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin/unlzma: /lib64/liblzma.so.5: no version information available (required by /home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin/unlzma)
| /home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin/unlzma: (stdin): File format not recognized
| cpio: premature end of archive
| DEBUG: Python function base_do_unpack finished
| DEBUG: Python function do_unpack finished
| ERROR: Function failed: Unpack failure for URL: ‘http://www.rpm5.org/files/rpm/rpm-5.4/rpm-5.4.9-0.20120508.src.rpm;extract=rpm-5.4.9.tar.gz’. Unpack command PATH=”/home/yocto/poky.git/scripts/native-intercept:/home/yocto/poky.git/scripts:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin/armv6-vfp-linux:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/sbin:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/sbin:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux//bin:/home/yocto/poky.git/scripts:/home/yocto/poky.git/bitbake/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.3″ rpm2cpio.sh /home/yocto/my-rpi-build/downloads/rpm-5.4.9-0.20120508.src.rpm | cpio -id rpm-5.4.9.tar.gz failed with return value 1
ERROR: Task 74 (virtual:native:/home/yocto/poky.git/meta/recipes-devtools/rpm/rpm_5.4.9.bb, do_unpack) failed with exit code ‘1’
NOTE: Tasks Summary: Attempted 529 tasks of which 523 didn’t need to be rerun and 1 failed.
Waiting for 0 running tasks to finish:

Summary: 1 task failed:
virtual:native:/home/yocto/poky.git/meta/recipes-devtools/rpm/rpm_5.4.9.bb, do_unpack
Summary: There was 1 WARNING message shown.
Summary: There was 1 ERROR message shown, returning a non-zero exit code.

Which is a little odd as running the command manually seem to work:

../poky.git/scripts/rpm2cpio.sh /home/yocto/my-rpi-build/downloads/rpm-5.4.9-0.20120508.src.rpm | cpio -id rpm-5.4.9.tar.gz
15071 blocks

Peter
Guest
Peter

I tried on a different host where I got a different error message but still related to unpacking:

| ERROR: Function failed: Unpack failure for URL: ‘http://www.python.org/ftp/pyt
hon/2.7.3/Python-2.7.3.tar.bz2’. Unpack command PATH=”/home/yocto/poky.git/scrip
ts/native-intercept:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin/b
zip2-native:/home/yocto/poky.git/scripts:/home/yocto/my-rpi-build/tmp/sysroots/x
86_64-linux/usr/bin/armv6-vfp-linux:/home/yocto/my-rpi-build/tmp/sysroots/x86_64
-linux/usr/bin:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/sbin:/home
/yocto/my-rpi-build/tmp/sysroots/x86_64-linux/usr/bin:/home/yocto/my-rpi-build/t
mp/sysroots/x86_64-linux/sbin:/home/yocto/my-rpi-build/tmp/sysroots/x86_64-linux
//bin:/home/yocto/poky.git/scripts:/home/yocto/poky.git/bitbake/bin:/usr/local/b
in:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.3″ bzip2 -dc /hom
e/yocto/my-rpi-build/downloads/Python-2.7.3.tar.bz2 | tar x –no-same-owner -f –
failed with return value 2
ERROR: Task 783 (/home/yocto/poky.git/meta/recipes-devtools/python/python-native
_2.7.3.bb, do_unpack) failed with exit code ‘1’
NOTE: Tasks Summary: Attempted 426 tasks of which 422 didn’t need to be rerun an
d 1 failed.
Waiting for 0 running tasks to finish:

Summary: 1 task failed:
/home/yocto/poky.git/meta/recipes-devtools/python/python-native_2.7.3.bb, do_unpack

Still this seem to work fine:
bzip2 -dc /home/yocto/my-rpi-build/downloads/Python-2.7.3.tar.bz2 | tar tvf –

I’ve successfully built core-image-minimal on both of the hosts (using the dizzy branch)

Abhishek
Guest
Abhishek

I am not able to download using git clone -b dora git://git.yoctoproject.org/poky.git
gives connection timeout error

please update your post for Ubuntu 14.04 as well

Thank you

Abhishek
Guest
Abhishek

How could i come to know that what packages are already available in final image ?actually I wanted to customize as per my requirement, with minimum possible size !
In case I need to add some additional packages, how can i do so?

Thank you

Abhishek
Guest
Abhishek

@cnxsoft
i am getting these warming while doing “bitbake rpi-basic-image”. Is it OK? how can i remove these warnings?

WARNING: Failed to fetch URL http://zlib.net/pigz/pigz-2.3.tar.gz, attempting MIRRORS if available
WARNING: Failed to fetch URL http://www.apache.org/dist/apr/apr-1.4.8.tar.bz2, attempting MIRRORS if available
WARNING: Failed to fetch URL http://www.apache.org/dist/apr/apr-util-1.5.2.tar.gz, attempting MIRRORS if available
WARNING: Failed to fetch URL http://www.apache.org/dist/subversion/subversion-1.7.10.tar.bz2, attempting MIRRORS if available
WARNING: Failed to fetch URL ftp://ftp.debian.org/debian/pool/main/n/netbase/netbase_5.1.tar.gz, attempting MIRRORS if available
WARNING: Failed to fetch URL ftp://ftp.debian.org/debian/pool/main/d/dpkg/dpkg_1.17.1.tar.xz, attempting MIRRORS if available
WARNING: Failed to fetch URL ftp://ftp.uni-erlangen.de/pub/Linux/LOCAL/dosfstools/dosfstools-2.11.src.tar.gz, attempting MIRRORS if available
WARNING: Failed to fetch URL http://ftp.de.debian.org/debian/pool/main/m/mklibs/mklibs_0.1.38.tar.gz, attempting MIRRORS if available

I have used git clone -b dora git://git.yoctoproject.org/poky.git & git clone -b dora git://git.yoctoproject.org/meta-raspberrypi

Abhishek
Guest
Abhishek

bitbake get stuck with this

0: linux-raspberrypi-3.6.11+git63b69a8806ce1890711ff55280c90673ea415933-r7 do_fetch (pid 26599)
1: bcm2835-bootfiles-20130819-r3 do_fetch (pid 17868)

no further improvements no matter how much time is given……….

please help