Personal tools

Yocto for VisionSOM-6ULL/6UL: Difference between revisions

From SomLabs Wiki

Jump to: navigation, search
Created page with "{{PageHeader|Building SoMLabs Systems for VisionSOM-6ULL/6UL with Yocto}} __toc__ Yocto is a set of tools for building a custom embedded Linux distributions. Systems are usu..."
 
No edit summary
 
(7 intermediate revisions by one other user not shown)
Line 18: Line 18:
The [http://www.qt.io/ 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.
The [http://www.qt.io/ 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:
For the 4.9.11 following device tree binaries are built:


# somlabs-visionsom-6ul.dtb
# somlabs-visionsom-6ul.dtb
Line 31: Line 31:
= Ubuntu Setup =
= Ubuntu Setup =


Ubuntu 16.04 is recommended operating system to build images using Yocto. When using other version or Linux type warning can appears.
Ubuntu 16.04 is a recommended operating system for building images using Yocto. While using other versions of Linux warnings can appear.


Yocto to proper work needs following packages installed
For proper operation Yocto needs following packages installed:


* build-essential
* build-essential
Line 42: Line 42:
* texinfo
* texinfo


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


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


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


<pre>sudo apt-get install python2.7</pre>
<pre>sudo apt-get install python2.7</pre>


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


<pre>sudo ln -sf /usr/bin/python2.7 /usr/bin/python
<pre>sudo ln -sf /usr/bin/python2.7 /usr/bin/python
Line 68: Line 68:
cd yocto</pre>
cd yocto</pre>
Create ''build'' directory for our SoMLabs project:
Create ''build'' directory for SoMLabs project:


<pre>mkdir somlabs_build
<pre>mkdir somlabs_build
Line 74: Line 74:
cd poky
cd poky
git clone -b rocko git://git.openembedded.org/meta-openembedded
git clone -b rocko git://git.openembedded.org/meta-openembedded
git clone https://github.com/meta-qt5/meta-qt5.git
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/Freescale/meta-freescale.git
git clone -b rocko https://github.com/SoMLabs/meta-somlabs.git</pre>
git clone -b rocko https://github.com/SoMLabs/meta-somlabs.git</pre>
Line 80: Line 80:
= Initialize the build directory =
= 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:
Be sure that terminal is in the ''poky'' directory and set directories structures and path for current opened console only, type following command:
<pre>source oe-init-build-env ~/yocto/somlabs_build</pre>
<pre>source oe-init-build-env ~/yocto/somlabs_build</pre>


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


<pre>cp ~/yocto/poky/meta-somlabs/conf/local.conf.sample ~/yocto/somlabs_build/conf/local.conf
<pre>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</pre>
cp ~/yocto/poky/meta-somlabs/conf/bblayers.conf.sample ~/yocto/somlabs_build/conf/bblayers.conf</pre>


It is necessary to modify a bit copied files.
It is necessary to modify copied files.


== Edit bblayers.conf ==
== Edit bblayers.conf ==


If directories structure is different then proposed above (''home/user_name/yocto...'') it is necessary to modify path in ''bblayers.conf'':
If directories structure is different than proposed above (''home/user_name/yocto...'') it is necessary to modify path in ''bblayers.conf'':
<pre> BBLAYERS ?= " \
<pre> BBLAYERS ?= " \
  ${HOME}/yocto/poky/meta \
  ${HOME}/yocto/poky/meta \
Line 120: Line 119:
== TMPDIR ==
== 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.
This is where temporary build files and the final build binaries will end up. Expect to use at least 35GB. 50GB of free disk space is recommended.
The default location is in the build directory, in this example ''~/yocto/somlabs_build/tmp''.
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.
If you specify an alternative location in the example conf file make sure the directory is writable by the user running the build.


== DL_DIR ==
== 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.
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''.
The default location is the build directory: ''~/yocto/somlabs_build/sources''.


== SSTATE_DIR ==
== SSTATE_DIR ==
Line 136: Line 135:
== ROOT PASSWORD ==
== 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:
By default “debug-tweaks” options are used, so root will be able to login without password, but if password is necessary then you need to modify ''local.conf'' file:


<pre>#EXTRA_IMAGE_FEATURES = "debug-tweaks"
<pre>#EXTRA_IMAGE_FEATURES = "debug-tweaks"
Line 144: Line 143:
Password can be changed at any time after log in.
Password can be changed at any time after log in.


= Run the build =
= Building images =


Before running bitbake command make sure that following action was taken:
Before running bitbake command make sure that following action was taken:
Line 150: Line 149:
<pre>source oe-init-build-env ~/yocto/somlabs_build</pre>
<pre>source oe-init-build-env ~/yocto/somlabs_build</pre>


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


SoMLabs prepared custom images:
SoMLabs prepared custom images:
Line 160: Line 159:


== console-image ==
== 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
A basic console developer image. See the recipe meta-somlabs/recipes-images/lab/console-image.bb for details, some of the installed programs are:
* ssh/scp server and client
* ssh/scp server and client
* memtest
* memtest
* kernel modules
* kernel modules
* some wifi and network applications
* some WiFi and network applications


The console-image contains a line:
The console-image contains a line:
Line 170: Line 169:
<pre>inherit core-image</pre>
<pre>inherit core-image</pre>


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.
which is ''poky/meta/classes/core-image.bbclass'' and pulls in some required base packages. This is useful to know when you create your own image recipe.


== qt5-image ==
== qt5-image ==
This image contains Qt5 runtime libraries and similar application like in console-image.
This image contains Qt5 runtime libraries and similar applications like the console-image.


 
== Build ==
= Build =
Execute:
Execute:


<pre>bitbake console-image</pre>
<pre>bitbake console-image</pre>


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
or:
<pre>bitbake qt5-image</pre>
 
After some time in directory ''~/yocto/tmp/deploy/images/visionsom6ull'' image files will appear with symbolic links. For SD Card use ''*.rootfs.wic.gz'' file.


= Write image to SD Card =
= 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
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 simplest is


<pre>sudo fdisk -l</pre>
<pre>sudo fdisk -l</pre>


Feedback message can looks as follow
Output will be similar to this:
<pre>
<pre>
Disk /dev/sdb: 7,2 GiB, 7744782336 bytes, 15126528 sectors
...
...
 
Disk /dev/sdc: 7,4 GiB, 7969177600 bytes, 15564800 sectors
Units: sectors of 1 * 512 = 512 bytes
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disklabel type: dos
Disk identifier: 0x21de5e7e
Disk identifier: 0x9de2d76a
 
Device    Boot Start    End Sectors  Size Id Type
/dev/sdc1      16384 1628159 1611776  787M 83 Linux
 
...
...


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


In this example SD card is /dev/sdb.
In this example SD card is /dev/sdc.


''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.
'''NOTE:''' Double-check /dev/sdx identifier, '''wrong identifier can damage data on your host drive!!!'''


Now it’s time to unpack image and write into SD Card. To unpack and write image use following:
Now it’s time to unpack image and write it on SD card, to do that use following commands:


For qt5 image:  
For qt5 image:  
<pre>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</pre>
<pre>gunzip -c '/home/user_name/yocto/tmp/deploy/images/visionsom6ull/qt5-image-visionsom6ull.wic.gz' | sudo dd of=/dev/sdx bs=1M iflag=fullblock oflag=direct conv=fsync</pre>


For console image:
For console image:
<pre>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</pre>
<pre>gunzip -c '/home/user_name/yocto/tmp/deploy/images/visionsom6ull/console-image-visionsom6ull.wic.gz' | sudo dd of=/dev/sdx bs=1M iflag=fullblock oflag=direct conv=fsync</pre>


'''NOTE:''' Before unpacking and writing an image provide valid user_name to your own
'''NOTE:''' Replace user_name in paths to your user name.
'''NOTE:''' Be aware that /dev/sdx needs to be checked twice, wrong id can damage your data!!!
 
After image is written to SD card you might want to resize partition to fit SD card, to do that you can follow [[How_to_resize_Debian_9.2_root_partition_to_fit_SD_card|this guide]].


= Customizing the Kernel =
= Customizing the Kernel =


To customize Kernel use:
To customize Kernel use:
<pre>bitbake -c menuconfig linux-imx
bitbake -c compile -f linux-imx
bitbake -c deploy linux-imx</pre>


or just:
<pre>bitbake -c menuconfig linux-imx</pre>
<pre>bitbake -c menuconfig linux-imx
 
bitbake -c compile -f console-image</pre>
and for console-image:
 
<pre>bitbake console-image</pre>


or:
or for qt5-image:
<pre>bitbake -c compile -f console-image</pre>
<pre>bitbake qt5-image</pre>


When new Kernel configuration needs to be stored it is necessary to copy contents of hidden file ''.config'' into ''defconfig'' in ''linux-imx'' directory
When new Kernel configuration needs to be stored it is necessary to copy contents of hidden file ''.config'' into ''defconfig'' in ''linux-imx'' directory
Line 239: Line 247:
''defconfig'' is stored in ''~/yocto/poky/meta-somlabs/recipes-kernel/linux/linux-imx.4.9.11/imx''.
''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.
After copying content of ''.config'' into ''defconfig'' kernel will compile from scratch with patch applying etc., so if any work on drivers or any other actions were made, they will be cleared. It is mandatory to remember to make copy of work before this activity.

Latest revision as of 18:23, 26 May 2018

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:

  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 a recommended operating system for building images using Yocto. While using other versions of Linux warnings can appear.

For proper operation Yocto needs following packages installed:

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

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

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

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

sudo apt-get install python2.7

And then create 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 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 the 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 some sample configuration files in the meta-somlabs/conf directory. Copy them to the build/conf directory (removing the ‘-sample’ part):

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 copied files.

Edit bblayers.conf

If directories structure is different than 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. 50GB of free disk space is recommended. The default location is in the build directory, in this example ~/yocto/somlabs_build/tmp. If you specify an alternative location 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 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 root will be able to login without password, 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.

Building images

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 locally 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 details, 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 when you create your own image recipe.

qt5-image

This image contains Qt5 runtime libraries and similar applications like the console-image.

Build

Execute:

bitbake console-image

or:

bitbake qt5-image

After some time in directory ~/yocto/tmp/deploy/images/visionsom6ull image files will appear with symbolic links. For SD Card use *.rootfs.wic.gz file.

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 simplest is

sudo fdisk -l

Output will be similar to this:

...
...

Disk /dev/sdc: 7,4 GiB, 7969177600 bytes, 15564800 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: 0x9de2d76a

Device     Boot Start     End Sectors  Size Id Type
/dev/sdc1       16384 1628159 1611776  787M 83 Linux

...
...

In this example SD card is /dev/sdc.

NOTE: Double-check /dev/sdx identifier, wrong identifier can damage data on your host drive!!!

Now it’s time to unpack image and write it on SD card, to do that use following commands:

For qt5 image:

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

NOTE: Replace user_name in paths to your user name.

After image is written to SD card you might want to resize partition to fit SD card, to do that you can follow this guide.

Customizing the Kernel

To customize Kernel use:

bitbake -c menuconfig linux-imx

and for console-image:

bitbake console-image

or for qt5-image:

bitbake qt5-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 from scratch with patch applying etc., so if any work on drivers or any other actions were made, they will be cleared. It is mandatory to remember to make copy of work before this activity.