Constructing Embedded Linux Image for Raspberry Pi4 using yocto project

 Hello All,

In my previous article we have seen that how we can construct an embedded linux image for beaglebone black using yocto project and how to build a toolchain for cross compilation using yocto project.

In case if you have missed my previous articles, you can find them here:

https://learnyoctowithme.blogspot.com/2022/03/constructing-embedded-linux-image-for.html

https://learnyoctowithme.blogspot.com/2022/03/building-toolchain-for-beaglebone-black.html

In this article we are going to see how we can construct an embedded linux image for raspberry Pi4-64 using yocto project.

pre-requisites:

you need to be familiar with my previous articles mentioned above as it contains the setup details and environment settings to build the image.  

Building an embedded linux image for Raspberry Pi4-64:

Step 1: Download the Poky Source code

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

step 2 : checkout to the branch dunfell
 
$ git checkout dunfell 

step 3: download the meta-openembedded source code from github

$ git clone https://github.com/openembedded/meta-openembedded
 
$ cd meta-openembedded 

$ git checkout dunfell

$ cd ..

step 4: Inside poky folder, clone the meta-raspberrypi layer 

$ git clone git://git.yoctoproject.org/meta-raspberrypi

$ git checkout dunfell

NOTE:  meta-raspberrypi layer is a general hardware specific BSP overlay for the raspberrypi device

step 5: inside the poky folder , source the oe-init-build-env script 

$ source ./oe-init-build-env build_rpi

NOTE : This will create a build environment inside the folder build_rpi

step 6:  Go to folder build_rpi and inside build_rpi folder you can observe conf directory with two files named as bblayers.conf and local.conf

step 7 : edit the local.conf file as below
    
    set the MACHINE variable as  MACHINE ?? = "raspberrypi4-64"


and append the following line to local.conf file as INHERIT+="rm_work" and ENABLE_UART = "1"


INHERIT+="rm_work" will saves the disk space while building the image

ENABLE_UART = "1" will enable the UART configuration for raspberry Pi device

Step 8 : Now add the openembedded layers to bblayers.conf file as

Inside build_rpi folder , type the following commands:

$ bitbake-layers add-layer /home/shashank/poky/meta-openembedded/meta-oe/
$ bitbake-layers add-layer /home/shashank/poky/meta-openembedded/meta-python/
$ bitbake-layers add-layer /home/shashank/poky/meta-openembedded/meta-networking/
$ bitbake-layers add-layer /home/shashank/poky/meta-openembedded/meta-multimedia/
$ bitbake-layers add-layer /home/shashank/poky/meta-openembedded/meta-filesystem/
$ bitbake-layers add-layer /home/shashank/poky/meta-openembedded/meta-perl/
$ bitbake-layers add-layer /home/shashank/poky/meta-raspberrypi/

 and the final bblayers.conf file should look as 


Step 9: Now inside the build_rpi folder, run the command as

$ bitbake core-image-base



NOTE: The build will take enough amount of time based on your system configuration.
                for me it took 2hrs to complete the build as I have 8 core 16 threads CPU

Step 10 : you can find your complete image under tmp/deploy/images/raspberrypi-64/ folder

$ cd tmp/deploy/images/raspberrypi-64/


image name is "core-image-base-raspberrypi4-64.wic.bz2" which is an complete rpi4-64 image used for booting rpi4 hardware.

Step 11: flashing the image on SD card

Images are present in tmp/deploy/images/raspberrypi4-64 folder

please insert the SD card in to your sytsem and type command

$ lsblk 

this will shows the SD card mount partition , for me its detected as sdb

Step 12 : use dd command to flash the image on SD card

$ dd if = core-image-base-raspberrypi4-64.wic.bz2 of = /dev/sdb bs =4096  && sync

This will flash the complete image on to SD card

Step 13 : insert the SD card in to raspberrypi4 device and power it ON


By default the username is root and password is empty


That's it now you have constructed your own embedded linux image for Rpi4 hardware.


Errors I faced while building the image:

The build of binutils was aborted and binutils was not compiling successfully because of the bug in binutils Makefiles

I made the following changes in binutils.inc file as

LDGOLD ?= "${@bb.utils.contains('DISTRO_FEATURES', 'ld-is-gold', '--enable-gold=default --enable-threads', '--disable-gold --enable-ld=default --enable-threads', d)}"



This will disable the gold package and compilation has been successful.

you can find binutils.inc file under poky/meta/recipes-devtools/binutils folder






 

Comments

Popular posts from this blog

Adding custom splash screen to yocto image

Adding libraries (pciutils,usbutils and util-linux) to our image using yocto project

Adding custom python script(to findout system info) to rootfs using yocto project