[1/3] meta: Add class for building custom OpenSBI firmware

Message ID c2d7f863fbce0d38531c0313158f5085530ca0cb.1761761297.git.jan.kiszka@siemens.com
State New
Headers show
Series Simplify OpenSBI builds | expand

Commit Message

Jan Kiszka Oct. 29, 2025, 6:08 p.m. UTC
From: Jan Kiszka <jan.kiszka@siemens.com>

This is supposed to simplify this customization task.

For the first time, this deviates from the *-custom.inc pattern used for
many other targets, using a class which is shorter to inherit. Other
targets should be converted to this pattern later on.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 RECIPE-API-CHANGELOG.md             |  6 ++++++
 meta/classes/opensbi.bbclass        | 28 ++++++++++++++++++++++++++++
 meta/recipes-bsp/opensbi/rules.tmpl | 19 +++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 meta/classes/opensbi.bbclass
 create mode 100644 meta/recipes-bsp/opensbi/rules.tmpl

Patch

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index cf04fa5c..1826667a 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -791,3 +791,9 @@  Set `Rules-Requires-Root: no` in `debian/control` files to prevent unnecessary
 invocation of fakeroot during package builds. This follows Debian guidelines
 recommending not to use fakeroot when no privileged operations (e.g., `chown`,
 root file modifications) are required. 
+
+### Add opensbi class to simplify custom OpenSBI builds
+
+A new class called `opensbi` has been introduced that shall help writing
+shorter recipes for custom OpenSBI builds. Usage examples can be found in
+`meta-isar/recipes/bsp/opensbi`.
diff --git a/meta/classes/opensbi.bbclass b/meta/classes/opensbi.bbclass
new file mode 100644
index 00000000..4475bd95
--- /dev/null
+++ b/meta/classes/opensbi.bbclass
@@ -0,0 +1,28 @@ 
+# Custom OpenSBI build
+#
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2025
+#
+# SPDX-License-Identifier: MIT
+
+inherit dpkg
+
+DESCRIPTION ?= "Custom OpenSBI"
+
+FILESPATH:append = ":${LAYERDIR_core}/recipes-bsp/opensbi"
+SRC_URI += "file://rules.tmpl"
+
+OPENSBI_PLATFORM ?= "generic"
+OPENSBI_EXTRA_BUILDARGS ?= ""
+
+TEMPLATE_FILES = "rules.tmpl"
+TEMPLATE_VARS += "OPENSBI_PLATFORM OPENSBI_EXTRA_BUILDARGS"
+
+do_prepare_build[cleandirs] += "${S}/debian"
+do_prepare_build() {
+    deb_debianize
+
+    for bin in ${OPENSBI_BIN}; do
+        echo "build/platform/${OPENSBI_PLATFORM}/firmware/$bin /usr/lib/opensbi/${MACHINE}/" >> ${S}/debian/install
+    done
+}
diff --git a/meta/recipes-bsp/opensbi/rules.tmpl b/meta/recipes-bsp/opensbi/rules.tmpl
new file mode 100644
index 00000000..935d033e
--- /dev/null
+++ b/meta/recipes-bsp/opensbi/rules.tmpl
@@ -0,0 +1,19 @@ 
+#!/usr/bin/make -f
+
+# Debian rules for custom OpenSBI build
+#
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2025
+#
+# SPDX-License-Identifier: MIT
+
+ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
+export CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)-
+endif
+
+override_dh_auto_build:
+	CFLAGS= LDFLAGS= $(MAKE) $(PARALLEL_MAKE) PLATFORM=${OPENSBI_PLATFORM} \
+		${OPENSBI_EXTRA_BUILDARGS}
+
+%:
+	dh $@