In this blog post, I will explain how I built the world’s worst gaming console (at least by today’s standards but it makes it one of the best anti-gaming consoles today in my opinion):

As you can see from the picture above, the user experience is terrible and this console is extremely poorly portable because of cabling and jumper wires used to connect the Wii Nunchuck and the STM32MP157D-DK1 board. Other than that there is only one game you can play and it’s nInvaders - a ncurses Space Invaders clone.
This is exactly why it’s one of the best anti-gaming consoles.
Table of Contents
- Introduction
- Writing a recipe to support nInvaders and integrating it to an existing layer
- Creating and integrating a custom Yocto layer into the build
- Applying patches to an existing recipe by adding joystick support
Introduction
In this blog post, I will be using the setup I described in my Setting up workspace for developing and building custom Linux-based distributions with Yocto blog post.
Similarly to my previous posts, this writeup is based on Bootlin’s Yocto labs. And as always, thanks to Bootlin for making their materials free and open source!
Before we continue, I would like to give a quick refresher of some basic terms used when working with Yocto as described in my previous post with regards to the Setting up Yocto for efficient embedded Linux systems development:
bitbake: Yocto’s main build engine that functions like a task scheduler parsing text files (i.e. recipes) to what to build and how to build itrecipe: a text file that describes how to fetch and build a software component - program, library or an imagetask: a specific step of the build process / a smaller execution unit of a recipe being built- for example:
fetch,configure,compile,package
- for example:
metadata: configuration files, recipes, classes and include files organized inlayerswhich act as an input tobitbakelayer: a set of configuration files, recipes, classes and include files with a common purpose- for example,
meta-stm32mp15xfor STM32MP157x board support package openembedded-coreis the core layer that all other layers a built on top of
- for example,
poky: Yocto’s reference distribution (tools and metadata) which serves as a starting point for building custom embedded Linux system
If you want more details, either check out the previous blog post or better yet, check out the official Yocto Project terms.
Writing a recipe to support nInvaders and integrating it to an existing layer
Before downloading nInvaders, make sure you run the following command in poky’s root directory:
source oe-init-build-env
This now lets you use bitbake for your builds.
Next, locate the recipes-extended directory and create a directory for nInvaders where you will download the source code of the game. In my case, this was:
/yocto-stm32-labs/meta-openembedded/meta-oe/recipes-extended/ninvaders
Next, inside the same directory, create a recipe which will tell bitbake how to handle building nInvaders. The recipe name should follow the Yocto nomenclature - {recipe_name}_{recipe_version}.bb. More info on Yocto naming conventions can be found here.
The link to my recipe can be found on my corresponding GitHub page. Here is a preview of how I’ve written the recipe:
myosotis@myosotis:~/yocto-stm32-labs/build$ cat ../meta-openembedded /meta-oe/recipes-extended/ninvaders/ninvaders_0.1.1.bb include ninvaders.inc SRC_URI[md5sum] = "97b2c3fb082241ab5c56ab728522622b" SRC_URI[sha256sum] = \ "bfbc5c378704d9cf5e7fed288dac88859149bee5ed0850175759d310b61fd30b" myosotis@myosotis:~/yocto-stm32-labs/build$
myosotis@myosotis:~/yocto-stm32-labs$ cat meta-openembedded/meta-oe/ recipes-extended/ninvaders/ninvaders.inc SUMMARY = "nInvaders game" DESCRIPTION = "nInvaders is a Space Invaders clone based on ncurses for ASCII output" HOMEPAGE = "http://ninvaders.sourceforge.net/" SECTION = "console/utils" LICENSE = "GPLv2" LIC_FILES_CHKSUM = "file://gpl.txt;md5=393a5ca445f6965873eca0259a17f 833" DEPENDS = "ncurses" SRC_URI = "https://sourceforge.net/projects/ninvaders/files/ninvader s/0.1.1/ninvaders-0.1.1.tar.gz" S = "${WORKDIR}/ninvaders-0.1.1" EXTRA_OEMAKE = "-e" # Add -fcommon to CFLAGS CFLAGS += " -fcommon" do_compile(){ oe_runmake } do_install() { install -d ${D}${bindir} install -m 0755 ${S}/nInvaders ${D}${bindir} } myosotis@myosotis:~/yocto-stm32-labs$
You can now build the recipe by running:
bitbake ninvaders
Output of the build process should look something like:
myosotis@myosotis:~/yocto-stm32-labs/build$ bitbake ninvaders Loading cache: 100% |########################################################################################################################################| Time: 0:00:01 Loaded 4379 entries from dependency cache. NOTE: Resolving any missing task queue dependencies Build Configuration: BB_VERSION = "2.8.0" BUILD_SYS = "x86_64-linux" NATIVELSBSTRING = "universal" TARGET_SYS = "arm-poky-linux-gnueabi" MACHINE = "stm32mp1" DISTRO = "poky" DISTRO_VERSION = "5.0.1" TUNE_FEATURES = "arm vfp cortexa7 neon vfpv4 thumb callconvention-hard" TARGET_FPU = "hard" meta meta-poky meta-yocto-bsp = "heads/scarthgap-5.0.1:4b07a5316ed4b858863dfdb7cab63859d46d1810" meta-oe meta-python = "scarthgap:727811eaf256b88fd135be99559f2cbf14c82fce" meta-st-stm32mp = "HEAD:b820cf3a1a855d2bd95969251e6465e281502759" meta-bootlinlabs = "<unknown>:<unknown>" Sstate summary: Wanted 79 Local 79 Mirrors 0 Missed 0 Current 1288 (100% match, 100% complete)################################################# | ETA: 0:00:00 Initialising tasks: 100% |###################################################################################################################################| Time: 0:00:01 NOTE: Executing Tasks NOTE: Tasks Summary: Attempted 3019 tasks of which 3019 didn't need to be rerun and all succeeded. myosotis@myosotis:~/yocto-stm32-labs/build$
Build files of the recipe we have now built are in tmp/work/... folder:
myosotis@myosotis:~/yocto-stm32-labs/build$ ls tmp/work/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/ninva ders/0.1.1/temp/ log.do_create_runtime_spdx_setscene run.do_populate_sysroot_setscene log.do_create_runtime_spdx_setscene.64504 run.do_populate_sysroot_setscene.64508 log.do_create_spdx_setscene run.do_recipe_qa_setscene log.do_create_spdx_setscene.64598 run.do_recipe_qa_setscene.64638 log.do_packagedata_setscene run.do_rm_work log.do_packagedata_setscene.64618 run.do_rm_work.64652 log.do_package_qa_setscene run.sstate_hardcode_path_unpack.64504 log.do_package_qa_setscene.64505 run.sstate_hardcode_path_unpack.64505 log.do_package_write_rpm_setscene run.sstate_hardcode_path_unpack.64506 log.do_package_write_rpm_setscene.64506 run.sstate_hardcode_path_unpack.64507 log.do_populate_lic_setscene run.sstate_hardcode_path_unpack.64508 log.do_populate_lic_setscene.64507 run.sstate_hardcode_path_unpack.64598 log.do_populate_sysroot_setscene run.sstate_hardcode_path_unpack.64618 log.do_populate_sysroot_setscene.64508 run.sstate_hardcode_path_unpack.64638 log.do_recipe_qa_setscene run.sstate_unpack_package.64504 log.do_recipe_qa_setscene.64638 run.sstate_unpack_package.64505 log.do_rm_work run.sstate_unpack_package.64506 log.do_rm_work.64652 run.sstate_unpack_package.64507 log.task_order run.sstate_unpack_package.64508 run.do_create_runtime_spdx_setscene run.sstate_unpack_package.64598 run.do_create_runtime_spdx_setscene.64504 run.sstate_unpack_package.64618 run.do_create_spdx_setscene run.sstate_unpack_package.64638 run.do_create_spdx_setscene.64598 run.uninative_changeinterp.64504 run.do_packagedata_setscene run.uninative_changeinterp.64505 run.do_packagedata_setscene.64618 run.uninative_changeinterp.64506 run.do_package_qa_setscene run.uninative_changeinterp.64507 run.do_package_qa_setscene.64505 run.uninative_changeinterp.64508 run.do_package_write_rpm_setscene run.uninative_changeinterp.64598 run.do_package_write_rpm_setscene.64506 run.uninative_changeinterp.64618 run.do_populate_lic_setscene run.uninative_changeinterp.64638 run.do_populate_lic_setscene.64507 myosotis@myosotis:~/yocto-stm32-labs/build$
A good practice before generating a new image which will end up on the target board is to verify in which layer is the recipe which contains our application present as well as is the application built for proper architecture which is arm in our case.
Running bitbake-layers show-recipes ninvaders from the build folder will show where is our recipe present:
myosotis@myosotis:~/yocto-stm32-labs/build$ bitbake-layers show-recipes ninvaders NOTE: Starting bitbake server... Loading cache: 100% |####################################################################| Time: 0:00:01 Loaded 4378 entries from dependency cache. === Matching recipes: === ninvaders: meta-oe 0.1.1 myosotis@myosotis:~/yocto-stm32-labs/build$
Great, our recipe is included in the meta-oe layer. Even though this is not the best practice (and we will fix that quite soon), we can be sure that it is included in the build since meta-oe is definitely included in the build:
myosotis@myosotis:~/yocto-stm32-labs/build$ bitbake-layers show-layers NOTE: Starting bitbake server... layer path priority ======================================================================================================== core /home/myosotis/yocto-stm32-labs/poky/meta 5 yocto /home/myosotis/yocto-stm32-labs/poky/meta-poky 5 yoctobsp /home/myosotis/yocto-stm32-labs/poky/meta-yocto-bsp 5 openembedded-layer /home/myosotis/yocto-stm32-labs/meta-openembedded/meta-oe 5 meta-python /home/myosotis/yocto-stm32-labs/meta-openembedded/meta-python 5 stm-st-stm32mp /home/myosotis/yocto-stm32-labs/meta-st-stm32mp 6 workspacelayer /home/myosotis/yocto-stm32-labs/build/workspace 99 myosotis@myosotis:~/yocto-stm32-labs/build$ bitbake-layers show-overlayed NOTE: Starting bitbake server... Loading cache: 100% |####################################################################| Time: 0:00:01 Loaded 4377 entries from dependency cache. === Overlayed recipes === libb64: meta-st-stm32mp 1.4.1+git meta-oe 2.0.0.1+2.0.0.2+git myosotis@myosotis:~/yocto-stm32-labs/build$
Finally, let’s verify that the ninvaders recipe has been built for proper architecture by running bitbake -e ninvaders | grep ^TARGET_ARCH=:
myosotis@myosotis:~/yocto-stm32-labs/build$ bitbake -e ninvaders | grep ^TARGET_ARCH= TARGET_ARCH="arm" myosotis@myosotis:~/yocto-stm32-labs/build$
Once nInvaders recipe has been successfully built, generate a new rootfs image which will contain nInvaders by running:
bitbake core-image-minimal
The image with our ninvaders application is now in /tmp/deploy/images... and we can now extract the image to our NFS root directory on the host machine (/nfs):
log.do_packagedata_setscene.64618 run.do_rm_work.64652 log.do_package_qa_setscene run.sstate_hardcode_path_unpack.64504 log.do_package_qa_setscene.64505 run.sstate_hardcode_path_unpack.64505 log.do_package_write_rpm_setscene run.sstate_hardcode_path_unpack.64506 log.do_package_write_rpm_setscene.64506 run.sstate_hardcode_path_unpack.64507 log.do_populate_lic_setscene run.sstate_hardcode_path_unpack.64508 log.do_populate_lic_setscene.64507 run.sstate_hardcode_path_unpack.64598 log.do_populate_sysroot_setscene run.sstate_hardcode_path_unpack.64618 log.do_populate_sysroot_setscene.64508 run.sstate_hardcode_path_unpack.64638 log.do_recipe_qa_setscene run.sstate_unpack_package.64504 log.do_recipe_qa_setscene.64638 run.sstate_unpack_package.64505 log.do_rm_work run.sstate_unpack_package.64506 log.do_rm_work.64652 run.sstate_unpack_package.64507 log.task_order run.sstate_unpack_package.64508 run.do_create_runtime_spdx_setscene run.sstate_unpack_package.64598 run.do_create_runtime_spdx_setscene.64504 run.sstate_unpack_package.64618 run.do_create_spdx_setscene run.sstate_unpack_package.64638 run.do_create_spdx_setscene.64598 run.uninative_changeinterp.64504 run.do_packagedata_setscene run.uninative_changeinterp.64505 run.do_packagedata_setscene.64618 run.uninative_changeinterp.64506 run.do_package_qa_setscene run.uninative_changeinterp.64507 run.do_package_qa_setscene.64505 run.uninative_changeinterp.64508 run.do_package_write_rpm_setscene run.uninative_changeinterp.64598 run.do_package_write_rpm_setscene.64506 run.uninative_changeinterp.64618 run.do_populate_lic_setscene run.uninative_changeinterp.64638 run.do_populate_lic_setscene.64507 myosotis@myosotis:~/yocto-stm32-labs/build$ sudo tar xpf tmp/deploy/images/stm32mp1/core-image-minimal-s tm32mp1.rootfs.tar.xz -C /nfs [sudo] password for myosotis: myosotis@myosotis:~/yocto-stm32-labs/build$ ls /nfs/usr/bin/ '[' dirname last.sysvinit passwd ssh unzip '[[' du less patch strings update-alternatives ascii dumpleases logger pgrep tail uptime awk env logname printf tee users basename expr lzcat readbootlog telnet utmpdump bunzip2 find md5sum readlink test utmpdump.sysvinit bzcat flock mesg realpath tftp vlock bzip2 free mesg.sysvinit renice time wall chvt fuser microcom reset top wall.sysvinit clear groups mkfifo resize tr wc cmp head nc scp traceroute wget crc32 hexdump ninvaders seq ts which cut id nohup setsid tty who dbclient killall nproc sha1sum udevadm whoami dc last nslookup sha256sum udpsvd xargs deallocvt lastb od shuf uniq xzcat diff lastb.sysvinit openvt sort unlink yes myosotis@myosotis:~/yocto-stm32-labs/build$
where we see our ninvaders app in the third column in the lower mid section. Great!
We can now just connect over ssh to the board, and run nInvaders from /usr/bin by running /usr/bin/ninvaders:
____ __
___ / _/__ _ _____ ___/ /__ _______
/ _ \_/ // _ \ |/ / _ `/ _ / -_) __(_-<
/_//_/___/_//_/___/\_,_/\_,_/\__/_/ /___/
<o o> = 500
,^, = 200
_O- = 150
-o- = 100
Press SPACE to start
,^,,^,,^,,^,,^,,^,,^,,^,,^,
_O-_O-_O-_O-_O-_O-_O-_O-_O-_O-
_O-_O-_O-_O-_O-_O-_O-_O-_O-_O-
-o--o--o--o--o--o--o--o--o--o-
-o--o--o--o--o--o--o--o--o--o-
!
### ### ### ###
##### ##### ##### #####
####### ####### ####### #######
## ## ## ## ## ## ## ##
/-^-\
Level: 01 Score: 0000200 Lives: /-\ /-\
We can now use the keyboard to play nInvaders on STM32MP157D-DK1!
Creating and integrating a custom Yocto layer into the build
It is a good practice to leave your custom software fully decoupled from basic Yocto project files. This goes for both adding new recipes or customizing the existing ones. This is why I will go through explaining how to create a new layer with our application which we will integrate into the build.
Let’s add a new layer into the build. This can be done by running:
bitbake-layers create-layer meta-bootlinlabs --priority 7
You can now verify that the layer has been added by running bitbake-layers show-layers:
myosotis@myosotis:~/yocto-stm32-labs/build$ ^C myosotis@myosotis:~/yocto-stm32-labs/build$ bitbake-layers show-layers NOTE: Starting bitbake server... layer path priority ======================================================================================================== core /home/myosotis/yocto-stm32-labs/poky/meta 5 yocto /home/myosotis/yocto-stm32-labs/poky/meta-poky 5 yoctobsp /home/myosotis/yocto-stm32-labs/poky/meta-yocto-bsp 5 openembedded-layer /home/myosotis/yocto-stm32-labs/meta-openembedded/meta-oe 5 meta-python /home/myosotis/yocto-stm32-labs/meta-openembedded/meta-python 5 stm-st-stm32mp /home/myosotis/yocto-stm32-labs/meta-st-stm32mp 6 workspacelayer /home/myosotis/yocto-stm32-labs/build/workspace 99 meta-bootlinlabs /home/myosotis/yocto-stm32-labs/meta-bootlinlabs 7 myosotis@myosotis:~/yocto-stm32-labs/build$ bitbake-layers show-recipes ninvaders NOTE: Starting bitbake server... Loading cache: 100% |####################################################################| Time: 0:00:01 Loaded 4379 entries from dependency cache. === Matching recipes: === ninvaders: meta-bootlinlabs 0.1.1 meta-oe 0.1.1 myosotis@myosotis:~/yocto-stm32-labs/build$
To integrate this newly created layer into the build, add it to the conf/bblayers.conf file:
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf # changes incompatibly POKY_BBLAYERS_CONF_VERSION = "2" BBPATH = "${TOPDIR}" BBFILES ?= "" BBLAYERS ?= " \ /home/myosotis/yocto-stm32-labs/poky/meta \ /home/myosotis/yocto-stm32-labs/poky/meta-poky \ /home/myosotis/yocto-stm32-labs/poky/meta-yocto-bsp \ /home/myosotis/yocto-stm32-labs/meta-openembedded/meta-oe \ /home/myosotis/yocto-stm32-labs/meta-openembedded/meta-python \ /home/myosotis/yocto-stm32-labs/meta-st-stm32mp \ /home/myosotis/yocto-stm32-labs/build/workspace \ /home/myosotis/yocto-stm32-labs/meta-bootlinlabs \ " ~ conf/bblayers.conf 1,1 All
We can now move the ninvaders recipe into our custom meta-bootlinlabs layer by simply copying all of the contents from /yocto-stm32-labs/meta-openembedded/meta-oe/recipes-extended/ninvaders to yocto-stm32-labs/meta-bootlinlabs. You can now either delete old files from the recipes-extended directory or leave them as they are. bitbake will build the ninvaders recipe with the higher priority first anyway. You can now check that ninvaders recipe is part of our new meta-bootlinlabs layer by running:
bitbake-layers show-recipes ninvaders
myosotis@myosotis:~/yocto-stm32-labs/build$ ^C myosotis@myosotis:~/yocto-stm32-labs/build$ bitbake-layers show-layers NOTE: Starting bitbake server... layer path priority ======================================================================================================== core /home/myosotis/yocto-stm32-labs/poky/meta 5 yocto /home/myosotis/yocto-stm32-labs/poky/meta-poky 5 yoctobsp /home/myosotis/yocto-stm32-labs/poky/meta-yocto-bsp 5 openembedded-layer /home/myosotis/yocto-stm32-labs/meta-openembedded/meta-oe 5 meta-python /home/myosotis/yocto-stm32-labs/meta-openembedded/meta-python 5 stm-st-stm32mp /home/myosotis/yocto-stm32-labs/meta-st-stm32mp 6 workspacelayer /home/myosotis/yocto-stm32-labs/build/workspace 99 meta-bootlinlabs /home/myosotis/yocto-stm32-labs/meta-bootlinlabs 7 myosotis@myosotis:~/yocto-stm32-labs/build$ bitbake-layers show-recipes ninvaders NOTE: Starting bitbake server... Loading cache: 100% |####################################################################| Time: 0:00:01 Loaded 4379 entries from dependency cache. === Matching recipes: === ninvaders: meta-bootlinlabs 0.1.1 meta-oe 0.1.1 myosotis@myosotis:~/yocto-stm32-labs/build$
Applying patches to an existing recipe by adding joystick support
bitbake allows users to extend recipes by the means of .bbappend files. In this chapter we will go through extending the linux-stm32mp recipe by applying a patch and including it into the build. This patch will enable us to play nInvaders with Wii’s Nunchuck joystick.
First, we will create a linux-stm32mp_6.1.bbappend file in the /yocto-stm32-labs/meta-bootlinlabs/recipes-kernel/linux directory.
You can now run bitbake-layers show-appends to see all the available bbappend files and the recipe they apply to. There you can see the .bbappend file we have created for our kernel recipe:
myosotis@myosotis:~/yocto-stm32-labs/meta-bootlinlabs/recipes-kernel/linux$ ^C myosotis@myosotis:~/yocto-stm32-labs/meta-bootlinlabs/recipes-kernel/linux$ bitbake-layers show-appends NOTE: Starting bitbake server... Loading cache: 100% |####################################################################| Time: 0:00:01 Loaded 4379 entries from dependency cache. Parsing recipes: 100% |##################################################################| Time: 0:00:00 Parsing of 2514 .bb files complete (2513 cached, 1 parsed). 4379 targets, 141 skipped, 0 masked, 0 error s. === Appended recipes === alsa-lib_1.2.11.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-bsp/alsa/alsa-lib_%.bbappend base-files_3.0.14.bb: /home/myosotis/yocto-stm32-labs/poky/meta-poky/recipes-core/base-files/base-files_%.bbappend /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-core/base-files/base-files_%.bbappend busybox_1.36.1.bb: /home/myosotis/yocto-stm32-labs/poky/meta-poky/recipes-core/busybox/busybox_%.bbappend /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-core/busybox/busybox_%.bbappend cmsis-svd_git.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-devtools/cmsis-svd/cmsis-svd_git.bbappend formfactor_0.0.bb: /home/myosotis/yocto-stm32-labs/poky/meta-yocto-bsp/recipes-bsp/formfactor/formfactor_0.0.bbappend gcc-source_13.2.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-devtools/gcc/gcc-source_13.2.bbappend gdb-cross_14.2.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-devtools/gdb/gdb-cross_%.bbappend gdb-cross-canadian_14.2.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-devtools/gdb/gdb-cross-canadian_%.bbappend lcms_2.16.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-support/lcms/lcms_%.bbappend libdrm_2.4.120.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-graphics/drm/libdrm_2.4.120.bbappend linux-firmware_20240312.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-kernel/linux-firmware/linux-firmware_%.bbappen d linux-stm32mp_6.1.bb: /home/myosotis/yocto-stm32-labs/meta-bootlinlabs/recipes-kernel/linux/linux-stm32mp_6.1.bbappend mesa_24.0.3.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-graphics/mesa/mesa_%.bbappend openjpeg_2.5.3.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-graphics/openjpeg/openjpeg_%.bbappend openssl_3.2.1.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-connectivity/openssl/openssl_%.bbappend packagegroup-core-tools-profile.bb: /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-core/packagegroups/packagegroup-core-tools-pro file.bbappend packagegroup-meta-oe.bb: /home/myosotis/yocto-stm32-labs/meta-openembedded/meta-oe/dynamic-layers/meta-python/recipes-core/pack agegroups/packagegroup-meta-oe.bbappend
The content of the .bbappend file can be seen here, and here is the preview for illustrative purposes:
FILESEXTRAPATHS:prepend := "${THISDIR}/files:" SRC_URI += " \ file://0001-Add-nunchuk-driver.patch \ file://0002-ARM-dts-stm32mp157a-dk1-add-description-of-Nunchuk-o.patch \ file://0003-ARM-dts-stm32mp157d-dk1-add-description-of-Nunchuk-o.patch \ file://defconfig \ " KERNEL_DEFCONFIG = "" KERNEL_EXTERNAL_DEFCONFIG = "defconfig" ~ linux-stm32mp_6.1.bbappend 1,1 All
Notice how the .bbappend file matches the exact recipe name of a file we want to extend. The needed patch for using the Nunchuck joystick as input to our console was provided by Bootlin and is present on this link.
As you can see, defconfig and patches are present in the source file list. Last two lines are used as an indication to the linux-stm32mp recipe to use kernel configuration as defined by defconfig.
Treeview of the directory responsible for handling the nunchuck at the kernel level is now:
myosotis@myosotis:~/yocto-stm32-labs/meta-bootlinlabs/recipes-kernel/linux$ tree . ├── files │ ├── 0001-Add-nunchuk-driver.patch │ ├── 0002-ARM-dts-stm32mp157a-dk1-add-description-of-Nunchuk-o.patch │ ├── 0003-ARM-dts-stm32mp157d-dk1-add-description-of-Nunchuk-o.patch │ └── defconfig └── linux-stm32mp_6.1.bbappend 2 directories, 5 files myosotis@myosotis:~/yocto-stm32-labs/meta-bootlinlabs/recipes-kernel/linux$
You can now rebuild the kernel to verify that the patches have been included into the build by running cat ... after rebuilding the kernel with bitbake virtual/kernel:
myosotis@myosotis:~/yocto-stm32-labs/build$ cat /home/myosotis/yocto-stm32-labs/build/tmp/work/stm32mp1- poky-linux-gnueabi/linux-stm32mp/6.1.28-stm32mp-r1.1/temp/log.do_patch | grep 0001 DEBUG: Searching for 6.1/6.1.28/0001-v6.1-stm32mp-r1-BUS.patch in paths: DEBUG: Using /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-kernel/linux/linux-stm32mp/6.1/6.1. 28/0001-v6.1-stm32mp-r1-BUS.patch for 6.1/6.1.28/0001-v6.1-stm32mp-r1-BUS.patch DEBUG: Searching for 0001-Add-nunchuk-driver.patch in paths: DEBUG: Using /home/myosotis/yocto-stm32-labs/meta-bootlinlabs/recipes-kernel/linux/files/0001-Add-nunchu k-driver.patch for 0001-Add-nunchuk-driver.patch NOTE: Applying patch '0001-v6.1-stm32mp-r1-BUS.patch' (../meta-st-stm32mp/recipes-kernel/linux/linux-stm 32mp/6.1/6.1.28/0001-v6.1-stm32mp-r1-BUS.patch) NOTE: Applying patch '0001-Add-nunchuk-driver.patch' (../meta-bootlinlabs/recipes-kernel/linux/files/000 1-Add-nunchuk-driver.patch) /home/myosotis/yocto-stm32-labs/meta-st-stm32mp/recipes-kernel/linux/linux-stm32mp/6.1/6.1.28/0001-v6.1- stm32mp-r1-BUS.patch /home/myosotis/yocto-stm32-labs/meta-bootlinlabs/recipes-kernel/linux/files/0001-Add-nunchuk-driver.patc h myosotis@myosotis:~/yocto-stm32-labs/build$
.bbappend file responsible for handling the nunchuck at the application level is here and looks like:
FILESEXTRAPATHS:prepend := "${THISDIR}/files:" SRC_URI += "file://joystick-support.patch" ~ ninvaders_0.1.1.bbappend 1,1 All
Treeview of the directory responsible for using the nunchuck in the game is now:
myosotis@myosotis:~/yocto-stm32-labs/meta-bootlinlabs/recipes-extended/ninvaders$ tree . ├── files │ └── joystick-support.patch ├── ninvaders-0.1.1 │ ├── aliens.c │ ├── aliens.h │ ├── ChangeLog │ ├── globals.c │ ├── globals.h │ ├── gpl.txt │ ├── Makefile │ ├── nInvaders.c │ ├── nInvaders.h │ ├── player.c │ ├── player.h │ ├── README │ ├── ufo.c │ ├── ufo.h │ ├── view.c │ └── view.h ├── ninvaders_0.1.1.bb ├── ninvaders_0.1.1.bbappend ├── ninvaders-0.1.1.tar.gz └── ninvaders.inc 3 directories, 21 files myosotis@myosotis:~/yocto-stm32-labs/meta-bootlinlabs/recipes-extended/ninvaders$
Transferring kernel image and device tree blob to TFTP
We can now rebuild the whole core-image-minimal and copy the newly generated kernel and device tree images to the TFTP server home directory (/srv/tftp in my case). Files you are looking for and that you want to transfer to the directory are:
- zImage
- stm32mp157d-dk1.dtb
myosotis@myosotis:~/yocto-stm32-labs/build/tmp/deploy/images/stm32mp1/kernel$ ls zImage zImage myosotis@myosotis:~/yocto-stm32-labs/build/tmp/deploy/images/stm32mp1/kernel$ ls stm32mp157d-dk1.dtb stm32mp157d-dk1.dtb myosotis@myosotis:~/yocto-stm32-labs/build/tmp/deploy/images/stm32mp1/kernel$
With these files now present, the board’s bootloader can now load the proper image with proper hardware support.
We can now reset the board and observe the boot logs until we have access to the command line. Near the end of the boot, we should now observe the following.
[ 1.809955] stpmic1 2-0033: PMIC Chip Version: 0x21 [ 1.819065] stm32f7-i2c 5c002000.i2c: STM32F7 I2C-2 bus adapter [ 1.828562] stm32-ipcc 4c001000.mailbox: ipcc rev:1.0 enabled, 6 chans, proc 0 [ 1.836032] stm32-rproc 10000000.m4: wdg irq registered [ 1.840678] remoteproc remoteproc0: m4 is available [ 1.850451] input: pmic_onkey as /devices/platform/soc/5c007000.etzpc/5c002000.i2c/i2c-2/2-0033/5c002000.i2c:stpmic@33:onkey/input/input1 [ 1.873566] stm32-dwmac 5800a000.ethernet eth0: Register MEM_TYPE_PAGE_POOL RxQ-0 [ 1.994661] stm32-dwmac 5800a000.ethernet eth0: PHY [stmmac-0:00] driver [RTL8211F Gigabit Ethernet] (irq=POLL) [ 2.013428] dwmac4: Master AXI performs any burst length [ 2.017333] stm32-dwmac 5800a000.ethernet eth0: No Safety Features support found [ 2.024751] stm32-dwmac 5800a000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported [ 2.033434] stm32-dwmac 5800a000.ethernet eth0: registered PTP clock [ 2.040215] stm32-dwmac 5800a000.ethernet eth0: configuring for phy/rgmii-id link mode [ 5.198997] stm32-dwmac 5800a000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx [ 5.206075] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready [ 5.234652] IP-Config: Guessing netmask 255.255.255.0 [ 5.238319] IP-Config: Complete: [ 5.241556] device=eth0, hwaddr=10:e7:7a:e1:90:24, ipaddr=192.168.2.100, mask=255.255.255.0, gw=255.255.255.255 [ 5.252091] host=192.168.2.100, domain=, nis-domain=(none) [ 5.257969] bootserver=255.255.255.255, rootserver=192.168.2.1, rootpath= [ 5.289445] VFS: Mounted root (nfs filesystem) on device 0:16. [ 5.302115] devtmpfs: mounted [ 5.305948] Freeing unused kernel image (initmem) memory: 1024K [ 5.334965] Run /sbin/init as init process INIT: version 3.04 booting Starting udev [ 6.190314] udevd[111]: starting version 3.2.14 [ 6.357540] udevd[112]: starting eudev-3.2.14 [ 6.673056] wiichuck 1-0052: Connected Nunchuk INIT: Entering runlevel: 5 Configuring network interfaces... ip: RTNETLINK answers: File exists ifup skipped for nfsroot interface eth0 run-parts: /etc/network/if-pre-up.d/nfsroot: exit status 1 ip: SIOCGIFFLAGS: No such device Starting Dropbear SSH server: dropbear. Starting syslogd/klogd: done Poky (Yocto Project Reference Distro) 5.0.1 stm32mp1 /dev/ttySTM0 stm32mp1 login: [ 15.836317] mmci-pl18x 58005000.mmc: Got CD GPIO [ 15.880559] platform cpufreq-dt: deferred probe pending [ 15.884444] amba 58005000.mmc: deferred probe pending [ 15.889467] platform 5a006000.usbphyc: deferred probe pending [ 15.895160] platform 5800d000.usb: deferred probe pending [ 15.900525] platform 5a001000.display-controller: deferred probe pending [ 15.907318] platform 49000000.usb-otg: deferred probe pending [ 15.912981] i2c 0-0039: deferred probe pending
Testing the Nunchuck
Connection diagram for the Nunchuck can be seen on following images provided by Bootlin:


You can now check that the Nunchuck is present and working by checking the presence of the js0 device file by running:
cat /dev/input/js0
root@stm32mp1:~# ls /dev/input/js0
/dev/input/js0
root@stm32mp1:~# cat /dev/input/js0
[ 96.610497] wiichuck 1-0052: Connected Nunchuk
�������������������������������������������� �����
�����
�����
����������������������������������������������������� ������
�����
�����
���������������������������������: �����: ���������; �����; �����vd �����d �����d ������������������@ ���� @ ���� @ ���f �����I ���
�I ���������M ����M ����L ����������������
����J �����J �����vf �����f ���������p �����p �����JB �����B �����B ��������������
Notice the random characters that appear while both playing with the Nunchuck’s joystick or by even moving the controller since the driver we integrated also handles accelerometer events.
And now finally, simply run /usr/bin/ninvaders and use the C button on the joystick to confirm and fire and Z to pause the game:
,^,,^,,^,,^,,^,,^,,^,,^,,^,,^,
_O-_O-_O-_O-_O-_O-_O-_O-_O-_O-
_O-_O-_O-_O-_O-_O-_O-_O-_O-_O-
-o--o--o--o--o--o--o--o--o--o-
-o--o--o- -o--o- -o--o--o-
### ### ### ###
##### ##### ##### #####
####### ####### ####### #######
## ## !## ## ## ## ## ##
/-^-\
Level: 01 Score: 0000200 Lives: /-\ /-\
And that’s it.
If you would like to support my work, consider: