Personal tools

Yocto for VisionSOM-6ULL/6UL

From SomLabs Wiki

Revision as of 18:21, 24 April 2018 by Admin (talk | contribs)
Jump to: navigation, search

Building SoMLabs Systems for VisionSOM-6ULL/6UL with Yocto



Yocto is a set of tools for building a custom embedded Linux distributions. Systems are usually targeted at particular applications like commercial products.

Yocto uses meta-layers to define the configuration for a system build. Within each meta-layer there are recipes, classes and configuration files that support the primary build tool, a python framework called bitbake.

The Yocto system, while very powerful, does have a substantial learning curve. You may want to look at another popular tool for building embedded systems - Buildroot.

The meta-somlabs layer generates some basic systems with packages that support C, C++, Qt5, Perl and Python development. Other languages are supported too.

Following approach can be used as a template when starting new SoMLabs projects.

System Info

By default Linux Kernel 4.9.11 is used. The u-boot version is 2017.09. These are sysvinit systems using eudev.

The Qt version is 5.9.4. There is no X11 and no desktop installed. Qt GUI applications can be run using the linuxfb platform plugin.

For the 4.9.11 following device tree binaries are built that support:

  1. somlabs-visionsom-6ul.dtb
  2. somlabs-visionsom-6ul-emmc.dtb
  3. somlabs-visionsom-6ull.dtb
  4. somlabs-visionsom-6ull-emmc.dtb
  5. somlabs-visionsom-6ull-nand.dtb
  6. somlabs-visionsom-6ul-nand.dtb

Note: Currently it is not possible to change dtb file name. U-boot uses hard-coded somlabs-visionsom-6ul.dtb or somlabs-visionsom-6ull.dtb (depending on CPU type). In future this option will be modified, to be able use custom dtb file.

Ubuntu Setup

Ubuntu 16.04 is recommended operating system to build images using Yocto. When using other version or Linux type warning can appears.

Yocto to proper work needs following packages installed

  • build-essential
  • chrpath
  • diffstat
  • gawk
  • libncurses5-dev
  • texinfo

Invoke console using left CTRL+left SHIFT+T keys or by clicking on Terminal icon. When terminal appears type following command:

sudo apt-get install build-essential chrpath diffstat gawk libncurses5-dev texinfo git u-boot-tools

For 16.04 you also need to install the python 2.7 package:

sudo apt-get install python2.7

And then create some links for it in /usr/bin:

sudo ln -sf /usr/bin/python2.7 /usr/bin/python
sudo ln -sf /usr/bin/python2.7 /usr/bin/python2

For all versions of Ubuntu, you should change the default Ubuntu shell from dash to bash by running this command from a shell:

sudo dpkg-reconfigure dash

Choose No to dash when prompted.

Clone the repositories

In home directory create directory named yocto and enter it:

cd ~
mkdir yocto
cd yocto

Create build directory for our SoMLabs project:

mkdir somlabs_build
git clone -b rocko git://git.yoctoproject.org/poky.git poky
cd poky
git clone -b rocko git://git.openembedded.org/meta-openembedded
git clone -b rocko https://github.com/meta-qt5/meta-qt5.git
git clone -b rocko https://github.com/Freescale/meta-freescale.git
git clone -b rocko https://github.com/SoMLabs/meta-somlabs.git

Initialize the build directory

Be sure that terminal is in poky directory and set directories structures and path for current opened console only, type following command:

source oe-init-build-env ~/yocto/somlabs_build

Customize the configuration files

There are few sample configuration files in the meta-somlabs/conf directory. Copy them to the build/conf directory (removing the ‘-sample’)

cp ~/yocto/poky/meta-somlabs/conf/local.conf.sample ~/yocto/somlabs_build/conf/local.conf
cp ~/yocto/poky/meta-somlabs/conf/bblayers.conf.sample ~/yocto/somlabs_build/conf/bblayers.conf

It is necessary to modify a bit copied files.

Edit bblayers.conf

If directories structure is different then proposed above (home/user_name/yocto...) it is necessary to modify path in bblayers.conf:

	BBLAYERS ?= " \
 		${HOME}/yocto/poky/meta \
 		${HOME}/yocto/poky/meta-poky \
		${HOME}/yocto/poky/meta-openembedded/meta-oe \
 		${HOME}/yocto/poky/meta-openembedded/meta-networking \
 		${HOME}/yocto/poky/meta-openembedded/meta-python \
  		${HOME}/yocto/poky/meta-freescale \
 		${HOME}/yocto/poky/meta-qt5 \
 		${HOME}/yocto/poky/meta-somlabs \
 	"

Provide path to poky with meta-layer accordingly.

Edit local.conf

Variables you may want to customize are the following:

  • TMPDIR
  • DL_DIR
  • SSTATE_DIR

The defaults for all of these variables work fine, adjustments are optional.

TMPDIR

This is where temporary build files and the final build binaries will end up. Expect to use at least 35GB. You probably want at least 50GB available. The default location is in the build directory, in this example ~/yocto/somlabs_build/tmp. If you specify an alternative location as I do in the example conf file make sure the directory is writable by the user running the build.

DL_DIR

This is where the downloaded source files will be stored. You can share this among configurations and build files so we create a common location for this outside the project directory. Make sure the build user has write permission to the directory you use. The default location is in the build directory: ~/yocto/somlabs_build/sources.

SSTATE_DIR

This is another Yocto build directory that can get pretty big, greater than 5GB. You will often put this somewhere else other than your home directory as well. The default location is in the build directory: ~/yocto/somlabs_build/sstate-cache.

ROOT PASSWORD

By default “debug-tweaks” options are used, so password will not be used, but if password is necessary then you need to modify local.conf file:

#EXTRA_IMAGE_FEATURES = "debug-tweaks"
INHERIT += "extrausers"
EXTRA_USERS_PARAMS = "usermod -P password root;"

Password can be changed at any time after log in.

Run the build

Before running bitbake command make sure that following action was taken:

source oe-init-build-env ~/yocto/somlabs_build

It is necessary always when new terminal console is invoked, because source only applies changes in PATH localy for current console.

SoMLabs prepared custom images:

  • console-image
  • qt5-image

If it is necessary add own custom images to the same directory.

console-image

A basic console developer image. See the recipe meta-somlabs/recipes-images/lab/console-image.bb for specifics, but some of the installed programs are

  • ssh/scp server and client
  • memtest
  • kernel modules
  • some wifi and network applications

The console-image contains a line:

inherit core-image

which is poky/meta/classes/core-image.bbclass and pulls in some required base packages. This is useful to know if you create your own image recipe.

qt5-image

This image contains Qt5 runtime libraries and similar application like in console-image.


Build

Execute:

bitbake console-image

After some time in directory ~/yocto/build/tmp/deploy/images/visionsom6ull there will appear many images with symbolic links. For SD Card *.rootfs.wic.gz is necessary

Write image to SD Card

For above images (console and qt5) 1GB SD Card is sufficient. Connect SD Card to HOST machine, it is necessary to check device ID. It can be done in many ways, the simpliest is

sudo fdisk -l

Feedback message can looks as follow

Disk /dev/sdb: 7,2 GiB, 7744782336 bytes, 15126528 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x21de5e7e

Urządzenie Rozruch Start   Koniec  Sektory  Size Id Typ
/dev/sdb1          16384 15126527 15110144  7,2G 83 Linux

In this example SD card is /dev/sdb.

NOTE: Remember that hot plug devices are usually not mounted as sda. sda are usually reserved for main hard drive. Never use sda identificator with application like dd.

Now it’s time to unpack image and write into SD Card. To unpack and write image use following:

For qt5 image:

gunzip -c '/home/user_name/yocto/tmp/deploy/images/visionom6ull/qt5-image-visionsom6ull.wic.gz' | sudo dd of=/dev/sdx bs=1M iflag=fullblock oflag=direct conv=fsync

For console image:

gunzip -c '/home/user_name/yocto/tmp/deploy/images/visionom6ull/console-image-visionsom6ull.wic.gz' | sudo dd of=/dev/sdx bs=1M iflag=fullblock oflag=direct conv=fsync

NOTE: Before unpacking and writing an image provide valid user_name to your own NOTE: Be aware that /dev/sdx needs to be checked twice, wrong id can damage your data!!!

Customizing the Kernel

To customize Kernel use:

bitbake -c menuconfig linux-imx
bitbake -c compile -f linux-imx
bitbake -c deploy linux-imx

or just:

bitbake -c menuconfig linux-imx
bitbake -c compile -f console-image

or:

bitbake -c compile -f console-image

When new Kernel configuration needs to be stored it is necessary to copy contents of hidden file .config into defconfig in linux-imx directory

.config is sotred in ~/yocto/tmp/work/visionsom6ull-poky-linux-gnueabi/linux-imx/4.9.11-r0/build.

Remember to select see hidden files in View.

defconfig is stored in ~/yocto/poky/meta-somlabs/recipes-kernel/linux/linux-imx.4.9.11/imx.

After copying content of .config into defconfig kernel will compile as fresh with patch applying etc. So when some work on drivers or any other actions was made will be cleared. It is mandatory to remember to make copy of work before this activity.

NXP Partner ST Partner Renesas Partner