Build your own Linux for LitSpin

Today, I will teach you how to bake a Linux for your LitSpin project

Requirements needed

  • A tested Linux distribution (list). For this recipe, Ubuntu 19.10 seems to work even if it is not tested
  • A lot of packages. Here the list depending on your distribution

Tools needed

Clone those repositories in the same working directory

Creation of the meta-litspin layer

With the different tools, we can build a Linux distribution for the MCV evaluation kit (MCVEVK) and the MCV development board (MCVEVP). However, we will not use those boards so we have to change but also add or delete features and parameters for our own board. So we have to create a new layer to add our changes.

Our new layer is called, in the Yocto jargon, a Board Support Package layer because it changes parameters and features at the hardware level. In the opposite, you can realize a layer to just compile java for a device, this layer is not a BSP layer. Every BSP layer must have meta- as the prefix so, our layer will be called meta-litspin.

To do so, we will use Yocto tools. First, we must configure the environment: go to the working directory and execute the command source poky/oe-init-build-env build_directory. Then execute the command: bitbake-layers create-layer ../meta-litspin. This will create a new layer named meta-litspin. This layer follows the following structure:

meta-litspin
├── conf
│   └─ layer.conf
├── COPYING.MIT
├── README
└── recipes-example
    └── example
        └── example_0.1.bb

The layer.conf, COPYING.MIT and README are automatically generated. The README needs to be completed with information about the layer.

# We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"

# We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
            ${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_COLLECTIONS += "meta-litspin"
BBFILE_PATTERN_meta-litspin = "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-litspin = "6"

LAYERDEPENDS_meta-litspin = "core"
LAYERSERIES_COMPAT_meta-litspin = "thud"

The layer.conf gives the configuration of the layer. We don’t need to modify it because we follow the Yocto standard for the file organization.

After this, you have to add this layer to compile it. Use bitbake-layers add-layer ../meta-litspin to do so.

Creation of recipes

As you can see above, there is a recipe example in a folder recipes-example. According to the variable BBFILES, every recipe is in a directory and this directory in another which the name should have the prefix “recipes-“.

We will build a recipe to compile a module for a USB Dongle available on Github.

Don’t forget to set the environment with the source command like above. Then, you can execute this command from the build directory: recipetool create -o ../meta-litspin/recipes-kernel/usb-dongle-module/rtl8812au_0.1.bb -x ../meta-litspin/recipes-kernel/usb-dongle-module/rtl8812au_src "https://github.com/gnab/rtl8812au.git"

This command will create the recipe rtl8812au_0.1.bb. The source files will be download from GitHub and place in the rtl8812au_src repository. And we have the following recipe:

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# Unable to find any files that looked like license statements. Check the accompanying
# documentation and source headers and set LICENSE and LIC_FILES_CHKSUM accordingly.
#
# NOTE: LICENSE is being set to "CLOSED" to allow you to at least start building - if
# this is not accurate with respect to the licensing of the software being built (it
# will not be in most cases) you must specify the correct value before using this
# recipe for anything other than initial testing/development!
LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""

SRC_URI = "git://github.com/gnab/rtl8812au.git;protocol=https"

# Modify these as desired
PV = "0.1+git${SRCPV}"
SRCREV = "40eafac156c1ce5e736f9767b27dd967a4ae5cbe"

S = "${WORKDIR}/git"

inherit module

EXTRA_OEMAKE_append_task-install = " -C ${STAGING_KERNEL_DIR} M=${S}"
EXTRA_OEMAKE += "KSRC=${STAGING_KERNEL_DIR}"

The LICENSE is set to close because there is no license file on the GitHub repository. The SRC_URI value specifies different things: git:// is here to specify it is a git repository and protocol=https to specify it has to be download in https. The product version (PV) is set to be REPO_PV + 0.1. SRCEV is here to store the revision of the source code used to build the package. S = “${WORKDIR}/git” to tell where the sources must be found. The default value is ${WORKDIR}. inherit module specifies this recipe inherits rules and parameters from module class. This class contains rules to download, build and install a module.

However, we cannot build the module for now because the Makefile is not set with good values. So we have to modify the Makefile. But how can we modify a file available on a GitHub repository?

Creation of a patch

As I explained above, during the creation of the recipe, the git repository was downloaded. However, it is not used for the compilation. In fact, this local version of the repository is used to make our own modifications and create patches.

To build the module we have to modify the Makefile. We have to replace CONFIG_PLATFORM_I386_PC = y by CONFIG_PLATFORM_I386_PC = n, we have to add CONFIG_PLATFORM_ARM_LITSPIN = y and

ifeq ($(CONFIG_PLATFORM_ARM_LITSPIN), y)
EXTRA_CFLAGS += -DCONFIG_LITTLE_ENDIAN
KSRC ?= $(KERNEL_SRC)
MODDESTDIR := $(MODLIB)
endif

Then place into the rtl8812au_src repository and commit your changes. As you can see you seem to have an isolated git repository. When you realized every commits you need, execute the following command: git format-patch -n where n is the number of commits you want to take into account to realize your patch. One patch will be realized for each commit and they will be named to be executed into the good order by Yocto. For instance, we realized 2 commits, so we have two patches to do. Then place every patch file in a files directory and add them to the recipe. So at the end, we have this structure and this recipe:

meta-litspin
├── conf
│   ├── layer.conf
│   └── machine
│       └── litspin.conf
├── COPYING.MIT
├── README
├── recipes-example
│   └── example
│       └── example_0.1.bb
├── recipes-extended
│   └── litspin-image.bb
└── recipes-kernel
    └── usb-dongle-module
        ├── files
        │   ├── 0001-Configure-Makefile-for-LitSpin.patch
        │   └── 0002-Remove-redefined-parameter.patch
        ├── rtl8812au_0.1.bb
        └── rtl8812au_src
# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# Unable to find any files that looked like license statements. Check the accompanying
# documentation and source headers and set LICENSE and LIC_FILES_CHKSUM accordingly.
#
# NOTE: LICENSE is being set to "CLOSED" to allow you to at least start building - if
# this is not accurate with respect to the licensing of the software being built (it
# will not be in most cases) you must specify the correct value before using this
# recipe for anything other than initial testing/development!
LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""

SRC_URI = "git://github.com/gnab/rtl8812au.git;protocol=https \
           file://0001-Configure-Makefile-for-LitSpin.patch \
           file://0002-Remove-redefined-parameter.patch"

# Modify these as desired
PV = "0.1+git${SRCPV}"
SRCREV = "40eafac156c1ce5e736f9767b27dd967a4ae5cbe"

S = "${WORKDIR}/git"

inherit module

EXTRA_OEMAKE_append_task-install = " -C ${STAGING_KERNEL_DIR} M=${S}"
EXTRA_OEMAKE += "KSRC=${STAGING_KERNEL_DIR}"

Finally, execute bitbake rtl8812au from the build directory to build the module.

Leave a Reply

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