Skip to content

Commit 0ef51dd

Browse files
klutchellalexgg
authored andcommitted
meta-kernel-block: add layer
Signed-off-by: Alex Gonzalez <alexg@balena.io>
1 parent 08fceb1 commit 0ef51dd

9 files changed

Lines changed: 317 additions & 8 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# kernel-extension.bbclass
2+
#
3+
# Builds a kernel extension block containing a self-consistent kernel image
4+
# PLUS its matching modules.
5+
#
6+
# Unlike kernel-modules-extension.bbclass, this class makes NO ABI-compat
7+
# guarantees against the base OS kernel. The extension is meant to be kexec'd
8+
# into from balena-bootloader, so the running kernel is the one shipped here.
9+
#
10+
# Strategy:
11+
# 1. After do_kernel_resin_injectconfig runs (balena defconfig + BALENA_CONFIGS
12+
# are already merged into .config), apply kernel-extension.cfg via
13+
# scripts/kconfig/merge_config.sh.
14+
# 2. Run olddefconfig to resolve dependencies.
15+
# 3. Let the normal do_compile / do_install flow proceed.
16+
#
17+
# Usage:
18+
# inherit kernel-extension
19+
# # Place kernel-extension.cfg in a FILESEXTRAPATHS-reachable directory.
20+
21+
python do_kernel_extend_config() {
22+
import os
23+
import subprocess
24+
25+
S = d.getVar("S")
26+
B = d.getVar("B")
27+
base_config = os.path.join(B, ".config")
28+
29+
make_cmd = d.getVar("KERNEL_MAKE_CMD") or "make"
30+
make_opts = d.getVar("EXTRA_OEMAKE") or ""
31+
arch = d.getVar("ARCH")
32+
if not arch:
33+
bb.fatal("kernel-extension: ARCH variable not set")
34+
35+
# 1. Locate kernel-extension.cfg via FILESEXTRAPATHS.
36+
extension_cfg = None
37+
filesextrapaths = d.getVar("FILESEXTRAPATHS") or ""
38+
for path in filesextrapaths.split(":"):
39+
candidate = os.path.join(path, "kernel-extension.cfg")
40+
if os.path.exists(candidate):
41+
extension_cfg = candidate
42+
break
43+
44+
if not extension_cfg:
45+
bb.fatal(
46+
"kernel-extension: kernel-extension.cfg not found.\n"
47+
"Place it in a directory reachable via FILESEXTRAPATHS.\n"
48+
f"Searched paths: {filesextrapaths}"
49+
)
50+
51+
bb.note(f"Using kernel extension fragment: {extension_cfg}")
52+
53+
# 2. Merge the fragment into .config.
54+
merge_script = os.path.join(S, "scripts", "kconfig", "merge_config.sh")
55+
cmd = f'{merge_script} -m -O {B} {base_config} {extension_cfg}'
56+
bb.note("Merging kernel-extension.cfg")
57+
ret = subprocess.run(cmd, shell=True, capture_output=True, text=True)
58+
if ret.returncode != 0:
59+
bb.fatal(f"merge_config.sh failed:\n{ret.stderr}")
60+
61+
# 3. Resolve dependencies.
62+
cmd = f'{make_cmd} {make_opts} -C {S} O={B} ARCH={arch} olddefconfig'
63+
bb.note("Running olddefconfig")
64+
ret = subprocess.run(cmd, shell=True, capture_output=True, text=True)
65+
if ret.returncode != 0:
66+
bb.fatal(f"olddefconfig failed:\n{ret.stderr}")
67+
}
68+
69+
addtask kernel_extend_config after do_kernel_resin_injectconfig before do_compile
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BBPATH .= ":${LAYERDIR}"
2+
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"
3+
BBFILE_COLLECTIONS += "meta-kernel-block"
4+
BBFILE_PATTERN_meta-kernel-block = "^${LAYERDIR}/"
5+
LAYERSERIES_COMPAT_meta-kernel-block = "kirkstone scarthgap"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
2+
# changes incompatibly
3+
POKY_BBLAYERS_CONF_VERSION = "2"
4+
5+
BBPATH = "${TOPDIR}"
6+
BBFILES ?= ""
7+
8+
BBLAYERS ?= " \
9+
${TOPDIR}/../layers/meta-balena/meta-balena-rust \
10+
${TOPDIR}/../layers/meta-balena/meta-balena-common \
11+
${TOPDIR}/../layers/meta-balena/meta-balena-kirkstone \
12+
${TOPDIR}/../layers/meta-balena-raspberrypi \
13+
${TOPDIR}/../layers/poky/meta \
14+
${TOPDIR}/../layers/poky/meta-poky \
15+
${TOPDIR}/../layers/meta-openembedded/meta-oe \
16+
${TOPDIR}/../layers/meta-openembedded/meta-filesystems \
17+
${TOPDIR}/../layers/meta-openembedded/meta-networking \
18+
${TOPDIR}/../layers/meta-openembedded/meta-python \
19+
${TOPDIR}/../layers/meta-openembedded/meta-perl \
20+
${TOPDIR}/../layers/meta-raspberrypi \
21+
${TOPDIR}/../layers/meta-cyclonedx \
22+
${TOPDIR}/../layers/meta-kernel-block \
23+
"
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Supported machines
2+
#MACHINE ?= "raspberrypi"
3+
#MACHINE ?= "raspberrypi2"
4+
#MACHINE ?= "raspberrypi3"
5+
#MACHINE ?= "raspberrypi3-64"
6+
#MACHINE ?= "revpi-connect"
7+
#MACHINE ?= "revpi-connect-s"
8+
#MACHINE ?= "revpi-connect-4"
9+
#MACHINE ?= "revpi-core-3"
10+
#MACHINE ?= "raspberrypi4-64"
11+
#MACHINE ?= "raspberrypi400-64"
12+
#MACHINE ?= "raspberrypicm4-ioboard"
13+
#MACHINE ?= "npe-x500-m3"
14+
#MACHINE ?= "rt-rpi-300"
15+
#MACHINE ?= "raspberrypi3-unipi-neuron"
16+
#MACHINE ?= "raspberrypi4-superhub"
17+
#MACHINE ?= "raspberrypi4-unipi-neuron"
18+
#MACHINE ?= "raspberrypi5"
19+
20+
# More info meta-resin/README.md
21+
#TARGET_REPOSITORY ?= ""
22+
#TARGET_TAG ?= ""
23+
24+
# RaspberryPi specific variables
25+
GPU_MEM = "16"
26+
27+
# for the moment, we disable vc4 graphics for all but the 64 bits machines
28+
DISABLE_VC4GRAPHICS = "1"
29+
DISABLE_VC4GRAPHICS:remove:raspberrypi3-64 = "1"
30+
DISABLE_VC4GRAPHICS:remove:raspberrypi4-64 = "1"
31+
DISABLE_VC4GRAPHICS:remove:raspberrypi5 = "1"
32+
DISABLE_VC4GRAPHICS:remove:raspberrypi0-2w-64 = "1"
33+
DISABLE_VC4GRAPHICS:remove:revpi-connect-s = "1"
34+
35+
# RPI BSP uses uncompressed kernel images by default
36+
KERNEL_IMAGETYPE="zImage"
37+
KERNEL_BOOTCMD="bootz"
38+
39+
# When u-boot is enabled we need to use the "Image" format and the "booti"
40+
# command to load the kernel for 64 bits machines
41+
KERNEL_IMAGETYPE:raspberrypi3-64="Image.gz"
42+
KERNEL_BOOTCMD:raspberrypi3-64 = "booti"
43+
KERNEL_IMAGETYPE:raspberrypi4-64="Image.gz"
44+
KERNEL_BOOTCMD:raspberrypi4-64 = "booti"
45+
KERNEL_IMAGETYPE:raspberrypi5="Image.gz"
46+
KERNEL_BOOTCMD:raspberrypi5 = "booti"
47+
KERNEL_IMAGETYPE:raspberrypi0-2w-64 = "Image.gz"
48+
KERNEL_BOOTCMD:raspberrypi0-2w-64 = "booti"
49+
50+
# RPI Use u-boot. This needs to be 1 as we use u-boot
51+
RPI_USE_U_BOOT = "1"
52+
53+
# Set this to 1 to disable quiet boot and allow bootloader shell access
54+
#OS_DEVELOPMENT = "1"
55+
56+
# Set this to make build system generate resinhup bundles
57+
#RESINHUP ?= "yes"
58+
59+
# Set this to change the supervisor tag used
60+
#SUPERVISOR_TAG ?= "master"
61+
62+
# Compress final raw image
63+
#BALENA_RAW_IMG_COMPRESSION ?= "xz"
64+
65+
# Parallelism Options
66+
BB_NUMBER_THREADS ?= "${@oe.utils.cpu_count()}"
67+
PARALLEL_MAKE ?= "-j ${@oe.utils.cpu_count()}"
68+
69+
# Resin specific distros
70+
DISTRO ?= "resin-systemd"
71+
72+
# Custom downloads directory
73+
#DL_DIR ?= "${TOPDIR}/downloads"
74+
75+
# Custom sstate directory
76+
#SSTATE_DIR ?= "${TOPDIR}/sstate-cache"
77+
78+
# Inheriting this class has shown to speed up builds due to significantly lower
79+
# amounts of data stored in the data cache as well as on disk.
80+
# http://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html#ref-classes-rm-work
81+
#INHERIT += "rm_work"
82+
83+
# Remove the old image before the new one is generated to save disk space when RM_OLD_IMAGE is set to 1, this is an easy way to keep the DEPLOY_DIR_IMAGE clean.
84+
RM_OLD_IMAGE = "1"
85+
86+
# Additional image features
87+
USER_CLASSES ?= "buildstats"
88+
89+
# By default disable interactive patch resolution (tasks will just fail instead):
90+
PATCHRESOLVE = "noop"
91+
92+
# Disk Space Monitoring during the build
93+
BB_DISKMON_DIRS = "\
94+
STOPTASKS,${TMPDIR},1G,100K \
95+
STOPTASKS,${DL_DIR},1G,100K \
96+
STOPTASKS,${SSTATE_DIR},1G,100K \
97+
HALT,${TMPDIR},100M,1K \
98+
HALT,${DL_DIR},100M,1K \
99+
HALT,${SSTATE_DIR},100M,1K"
100+
101+
CONF_VERSION = "2"
102+
103+
HOSTTOOLS += "docker iptables"
104+
105+
LICENSE_FLAGS_ACCEPTED = "synaptics-killswitch"
106+
107+
# CycloneDX SBOM and VEX generation
108+
INHERIT += "cyclonedx-export"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
DESCRIPTION = "Kernel block image containing a full kernel + matching modules"
2+
LICENSE = "MIT"
3+
4+
inherit balena-hostapp-extension
5+
6+
IMAGE_INSTALL = "kernel-modules kernel-image kernel-devicetree"
7+
8+
IMAGE_LINGUAS = ""
9+
VIRTUAL-RUNTIME_init_manager = ""
10+
INITRAMFS_IMAGE = ""
11+
IMAGE_FSTYPES = "tar.gz"
12+
13+
remove_unnecessary_files() {
14+
rm -f ${IMAGE_ROOTFS}/bin ${IMAGE_ROOTFS}/sbin
15+
rm -rf ${IMAGE_ROOTFS}/etc
16+
rm -rf ${IMAGE_ROOTFS}/run
17+
rm -rf ${IMAGE_ROOTFS}/usr/bin
18+
}
19+
IMAGE_PREPROCESS_COMMAND += "remove_unnecessary_files;"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Kernel extension fragment for balena-kernel-block
2+
#
3+
# This fragment is merged on top of the balena defconfig and the
4+
# BALENA_CONFIGS overrides. Unlike kernel-modules-extension, this layer
5+
# permits BOTH =m and =y changes here, because the extension ships its own
6+
# kernel binary (no ABI-compat constraint against a base OS kernel).
7+
#
8+
# Add new entries freely. olddefconfig will resolve dependencies; there is
9+
# no post-merge stability check.
10+
11+
# CAN bus - additional controllers (platform, SPI, USB)
12+
CONFIG_CAN_M_CAN_PLATFORM=m
13+
CONFIG_CAN_M_CAN_TCAN4X5X=m
14+
CONFIG_CAN_CAN327=m
15+
CONFIG_CAN_ESD_USB=m
16+
CONFIG_CAN_ETAS_ES58X=m
17+
CONFIG_CAN_MCBA_USB=m
18+
CONFIG_CAN_UCAN=m
19+
20+
# GNSS/GPS receiver drivers (u-blox, MediaTek, SiRF, USB)
21+
CONFIG_GNSS_UBX_SERIAL=m
22+
CONFIG_GNSS_MTK_SERIAL=m
23+
CONFIG_GNSS_SIRF_SERIAL=m
24+
CONFIG_GNSS_USB=m
25+
26+
# IIO Sensors - newer Bosch IMUs
27+
CONFIG_BMI088_ACCEL=m
28+
CONFIG_BMI323_I2C=m
29+
CONFIG_BMI323_SPI=m
30+
31+
# IIO Sensors - ST gyroscope, magnetometer, pressure, 9-axis
32+
CONFIG_IIO_ST_GYRO_3AXIS=m
33+
CONFIG_IIO_ST_MAGN_3AXIS=m
34+
CONFIG_IIO_ST_LSM9DS0=m
35+
CONFIG_IIO_ST_PRESS=m
36+
37+
# IEEE 802.15.4 / Zigbee/Thread (additional hardware)
38+
CONFIG_IEEE802154_CA8210=m
39+
CONFIG_IEEE802154_MCR20A=m
40+
CONFIG_IEEE802154_ADF7242=m
41+
CONFIG_IEEE802154_HWSIM=m
42+
43+
# 1-Wire slave devices
44+
CONFIG_W1_SLAVE_DS2405=m
45+
CONFIG_W1_SLAVE_DS2805=m
46+
CONFIG_W1_SLAVE_DS250X=m
47+
CONFIG_W1_MASTER_UART=m
48+
49+
# NFC (NXP PN5xx family)
50+
CONFIG_NFC_PN533_USB=m
51+
CONFIG_NFC_PN533_I2C=m
52+
CONFIG_NFC_PN532_UART=m
53+
54+
# GPIO expanders (I2C)
55+
CONFIG_GPIO_PCA9570=m
56+
57+
# HID - USB-to-I2C/SPI bridge (useful for sensor prototyping)
58+
CONFIG_HID_CP2112=m
59+
CONFIG_HID_FT260=m
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Kernel extension block configuration
2+
#
3+
# Builds a self-consistent kernel + modules tree for the kernel-providing
4+
# hostapp extension. See classes/kernel-extension.bbclass.
5+
6+
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
7+
8+
# Track kernel-extension.cfg in the task hash so changes trigger re-execution.
9+
# NOT in SRC_URI because Yocto would auto-merge .cfg files into the kernel
10+
# config — the bbclass applies it manually.
11+
do_kernel_extend_config[file-checksums] += "${THISDIR}/files/kernel-extension.cfg:True"
12+
13+
inherit kernel-extension

raspberrypi4-64.hostapp.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# yaml-language-server: $schema=https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json
22
version: '2.4'
33
services:
4-
5-
hostapp:
4+
kernel-modules:
65
image: __BUILD_OUTPUT__
7-
x-build: {}
8-
labels:
9-
io.balena.image.store: 'root'
10-
io.balena.image.class: 'hostapp'
11-
io.balena.update.requires-reboot: '1'
12-
io.balena.private.hostapp.board-rev: '${DEVICE_REPO_REV}'
6+
x-build:
7+
recipe: balena-kernel-block
8+
build_args:
9+
- "-t"
10+
- "layers/meta-kernel-block/conf/samples"
11+
profiles:
12+
- kernel-modules

raspberrypi5.hostapp.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json
2+
version: '2.4'
3+
services:
4+
5+
kernel-modules:
6+
image: __BUILD_OUTPUT__
7+
x-build:
8+
recipe: balena-kernel-block
9+
build_args:
10+
- "-t"
11+
- "layers/meta-kernel-block/conf/samples"
12+
profiles:
13+
- kernel-modules

0 commit comments

Comments
 (0)