Stuck on 'barys' building for custom board

I’m trying to create support for our boards for BalenaOS, so I’m following the instructions here:

I’m comfortable working with Yocto/OE as I’m the maintainer for our BSPs.

Having created all these files and repos, I attempted to start my build with “barys” as instructed. However, the tool refuses to run and only outputs this cryptic error:

$ ./balena-yocto-scripts/build/barys
Building JSON manifest…
/…/balena-topic/balena-yocto-scripts/build/node_modules/@resin.io/device-types/build.js:26
throw new Error("Ignored " + typeDefinition.slug + “: " + field + " is not set”);
^

Error: Ignored tdkzu6: state is not set
at Object.module.exports [as buildManifest] (/home/mike/projects/balena-topic/balena-yocto-scripts/build/node_modules/@resin.io/device-types/build.js:26:17)
at [stdin]:5:28
at ContextifyScript.Script.runInThisContext (vm.js:50:33)
at Object.runInThisContext (vm.js:139:38)
at Object. ([stdin]-wrapper:6:22)
at Module._compile (module.js:652:30)
at evalScript (bootstrap_node.js:463:27)
at ReadStream. (bootstrap_node.js:234:15)
at emitNone (events.js:111:20)
at ReadStream.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

/…/balena-topic/balena-yocto-scripts/build/build-device-type-json.sh: ERROR - Please check your nodejs installation. The ‘nodejs’ binary did not generate a proper .json.
[000000001][ERROR]Could not generate .json file(s).

I added an entry “state: ‘released’” to the “coffee” file, but that didn’t make any difference.

What now?

Hello @milo

Welcome to the balena Forums.

It is worth comparing the contents of your coffee file to the examples in our balena-raspberrypi repository to check that you have the basics correct. If your problems still persist after this then please feel free to post your coffee file here so that we can review it.

Regards - Mark

My coffee file:

module.exports =
	yocto:
		machine: 'tdkzu6'
		image: 'balena-image'
		fstype: 'balenaos-img'
		version: 'yocto-zeus'
		deployArtifact: 'balena-image-tdkzu6.balenaos-img'
		compressed: true
		state: 'released'

(I’m adding “zeus” support myself - for Xilinx boards, there’s support for zeus or gatesgarth, neither dunfell nor warrior are available there…)

Using the plain vanilla bitbake development flow, I got pretty far compiling the image. Only issue is with your “kernel-modules-headers.bb” recipe, it bails out with this cryptic message:

| DEBUG: Executing shell function do_compile
| gen_mod_headers: Missing kernel configuration.
| WARNING: /.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/temp/run.do_compile.22722:1 exit 1 from '/.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/gen_mod_headers ./kernel_modules_headers /.../build/tmp/work-shared/tdkzu6/kernel-source /.../build/tmp/deploy/images/tdkzu6 arm64 aarch64-poky-linux- "aarch64-poky-linux-gcc  -fstack-protector-strong  -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/recipe-sysroot" "gcc  -isystem/.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/recipe-sysroot-native/usr/include -O2 -pipe -L/.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/recipe-sysroot-native/usr/lib                         -L/.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/recipe-sysroot-native/lib                         -Wl,--enable-new-dtags                         -Wl,-rpath-link,/.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/recipe-sysroot-native/usr/lib                         -Wl,-rpath-link,/.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/recipe-sysroot-native/lib                         -Wl,-rpath,/.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/recipe-sysroot-native/usr/lib                         -Wl,-rpath,/.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/recipe-sysroot-native/lib                         -Wl,-O1 -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=/.../build/tmp/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2"'
| ERROR: Execution of '/.../build/tmp/work/tdkzu6-poky-linux/kernel-modules-headers/1.0-r0/temp/run.do_compile.22722' failed with exit code 1:
| gen_mod_headers: Missing kernel configuration.

Apparently the recipe passes the wrong parameter to the script, this fixes it:

diff --git a/meta-balena-common/recipes-devtools/kernel-modules-headers/kernel-modules-headers.bb b/meta-balena-common/recipes-devtools/kernel-modules-headers/kernel-modules-headers.bb
index ead4a8eb..f1540504 100644
--- a/meta-balena-common/recipes-devtools/kernel-modules-headers/kernel-modules-headers.bb
+++ b/meta-balena-common/recipes-devtools/kernel-modules-headers/kernel-modules-headers.bb
@@ -32,7 +32,7 @@ do_configure[noexec] = "1"
 
 do_compile() {
     mkdir -p kernel_modules_headers
-    ${S}/gen_mod_headers ./kernel_modules_headers ${STAGING_KERNEL_DIR} ${DEPLOY_DIR_IMAGE} ${ARCH} ${TARGET_PREFIX} "${CC}" "${HOSTCC}"
+    ${S}/gen_mod_headers ./kernel_modules_headers ${STAGING_KERNEL_DIR} ${STAGING_KERNEL_BUILDDIR} ${ARCH} ${TARGET_PREFIX} "${CC}" "${HOSTCC}"
 
     # Sanity test

Hmm, only issue left now is that balena-image wants to install some initramfs package which clashes with ther kernel itself:

 * check_data_file_clashes: Package kernel-image-image-4.19.0-xilinx-v2019.2 wants to install file /.../build/tmp/work/tdkzu6-poky-linux/balena-image/1.0-r0/rootfs/boot/Image
	But that file is already provided by package  * kernel-image-initramfs

The boards do not need any initramfs for booting. Looks like it’s the DISTRO that forces this initramfs stuff, is this something that’s required for BalenaOS?

Ah, the docs above said I had to
inherit kernel-balena
but that class doesn’t exist anywhere. From the raspberrypi repo one glorks that the proper incantation is:
inherit kernel-resin

This solved the initramfs clash at rootfs time

Almost there. What’s the “json” file it’s looking for? I can’t find anything like that in the rpi repo, maybe it’s something that brays would have generated?

Handling /.../layers/meta-balena/meta-balena-common/../../../tdkzu6.json:/device-type.json .

It fails on that now.

Nice work progressing along here @milo! And sorry for the troubles along the way. I see that device-type comes from here: balena-yocto-scripts/build-device-type-json.sh at master · balena-os/balena-yocto-scripts · GitHub

However, I have never run into this exact issue when doing a build, so I can’t say with certainty what is causing your failure. Do you get the same issue/error when running a build on a “regular” repo or supported device type. For example, if you clone and build the Raspberry Pi, does it also crash?

What is best way to solve this?
Is it possible to patch kernel-modules-headers.bb or should I create a kernel-modules-headers.bbappend that is only overriding the modified do_compile() snipet?