public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH v5 0/9] Avoid using shell environment during the build
@ 2022-02-13  7:41 Uladzimir Bely
  2022-02-13  7:41 ` [PATCH v5 1/9] template: Copy template attributes on transform Uladzimir Bely
                   ` (9 more replies)
  0 siblings, 10 replies; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-13  7:41 UTC (permalink / raw)
  To: isar-users

This patchset is a subseries of 'Sbuild/Schroot migration' patchset
including only preparation patches. It doesn't require any changes
in host machine configuration for downstreams (meta-iot2050 and
xenomai-images were tested) so can be merged independently.

In this patchset the main topic is a migration to template files that
allows to use cleaner build environment.

When this patchset is merged, it will make maintenance of remaining
sbuild-related patches easier and will shorten their number.

Changes since v5:
- Removed "ifneq ($(KDIR),)" workaround for dh_auto_clean override
for "linux-module" patch (while latter sbuild patchset moved to using
.dsc file).

Changes since v4:
- Added patch for optee-os-stm32mp15x to avoid shell exports.

Changes since v2:
- Removed `dpkg_build_export` while a way to continue using
shell exports for sbuild was found.

Changes since v1:
- Introduced `dpkg_build_export` function to be used for passing
variables to build environment;
- Linux kernel framgments handling is done in Debian way.

Anton Mikanovich (6):
  linux-module: Do not use shell environment
  u-boot: Do not use shell environment
  trusted-firmware: Do not use shell environment
  optee-os: Do not use shell environment
  kselftest: Do not use shell environment
  linux-mainline: Move cfg fragment test to debian/rules

Uladzimir Bely (3):
  template: Copy template attributes on transform
  optee-os-stm32mp15x: Do not use shell environment
  linux-custom: Move cfg fragments applying to debian/rules

 .../optee-os/optee-os-stm32mp15x_3.11.0.bb    |  5 +-
 .../linux/linux-mainline_5.4.70.bb            | 16 ++---
 meta/classes/template.bbclass                 |  4 +-
 .../files/debian/{rules => rules.tmpl}        |  4 +-
 meta/recipes-bsp/optee-os/optee-os-custom.inc |  9 +--
 .../files/debian/{rules => rules.tmpl}        |  4 +-
 .../trusted-firmware-a-custom.inc             |  9 +--
 .../u-boot/files/debian/{rules => rules.tmpl} |  2 +-
 meta/recipes-bsp/u-boot/u-boot-custom.inc     |  9 +--
 .../kselftest/files/{rules => rules.tmpl}     |  0
 meta/recipes-kernel/kselftest/kselftest.inc   | 21 +++----
 .../linux-module/files/debian/rules           | 37 ------------
 .../linux-module/files/debian/rules.tmpl      | 60 +++++++++++++++++++
 meta/recipes-kernel/linux-module/module.inc   | 34 +----------
 .../linux/files/debian/isar/configure.tmpl    | 19 ++++++
 .../linux/files/debian/rules.tmpl             |  3 +
 meta/recipes-kernel/linux/linux-custom.inc    | 53 +++++++++-------
 17 files changed, 153 insertions(+), 136 deletions(-)
 rename meta/recipes-bsp/optee-os/files/debian/{rules => rules.tmpl} (75%)
 rename meta/recipes-bsp/trusted-firmware-a/files/debian/{rules => rules.tmpl} (77%)
 rename meta/recipes-bsp/u-boot/files/debian/{rules => rules.tmpl} (94%)
 rename meta/recipes-kernel/kselftest/files/{rules => rules.tmpl} (100%)
 delete mode 100755 meta/recipes-kernel/linux-module/files/debian/rules
 create mode 100755 meta/recipes-kernel/linux-module/files/debian/rules.tmpl
 create mode 100644 meta/recipes-kernel/linux/files/debian/isar/configure.tmpl

-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v5 1/9] template: Copy template attributes on transform
  2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
@ 2022-02-13  7:41 ` Uladzimir Bely
  2022-02-13  7:41 ` [PATCH v5 2/9] linux-module: Do not use shell environment Uladzimir Bely
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-13  7:41 UTC (permalink / raw)
  To: isar-users

Output file should have exactly the same flags as input one,
which is usefull for the cases like debian/rules or other executables.
So we should copy this part of metadata after the conversion.

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 meta/classes/template.bbclass | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/meta/classes/template.bbclass b/meta/classes/template.bbclass
index fb9d1186..e6bcc362 100644
--- a/meta/classes/template.bbclass
+++ b/meta/classes/template.bbclass
@@ -8,7 +8,7 @@ TEMPLATE_VARS ?= "PN PV DESCRIPTION HOMEPAGE MAINTAINER DISTRO_ARCH"
 
 do_transform_template[vardeps] = "TEMPLATE_FILES ${TEMPLATE_VARS}"
 python do_transform_template() {
-    import subprocess, contextlib
+    import subprocess, contextlib, shutil
 
     workdir = os.path.normpath(d.getVar('WORKDIR', True))
 
@@ -56,5 +56,7 @@ python do_transform_template() {
                                           stdout=output, env=env))
             if process.wait() != 0:
                 bb.fatal("processing of template failed")
+
+        shutil.copymode(template_file, output_file)
 }
 addtask do_transform_template after do_unpack
-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v5 2/9] linux-module: Do not use shell environment
  2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
  2022-02-13  7:41 ` [PATCH v5 1/9] template: Copy template attributes on transform Uladzimir Bely
@ 2022-02-13  7:41 ` Uladzimir Bely
  2022-02-13  7:41 ` [PATCH v5 3/9] u-boot: " Uladzimir Bely
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-13  7:41 UTC (permalink / raw)
  To: isar-users

From: Anton Mikanovich <amikan@ilbers.de>

To make package build process independent of the shell environment we
should remove KDIR and PN passing through export call.
KDIR can be prepared during package build. This also will allow not to
rely on previous builddeps install task.
To pass PN variable we can just migrate to template-based debian/rules
file.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 .../linux-module/files/debian/rules           | 37 ------------
 .../linux-module/files/debian/rules.tmpl      | 60 +++++++++++++++++++
 meta/recipes-kernel/linux-module/module.inc   | 34 +----------
 3 files changed, 63 insertions(+), 68 deletions(-)
 delete mode 100755 meta/recipes-kernel/linux-module/files/debian/rules
 create mode 100755 meta/recipes-kernel/linux-module/files/debian/rules.tmpl

diff --git a/meta/recipes-kernel/linux-module/files/debian/rules b/meta/recipes-kernel/linux-module/files/debian/rules
deleted file mode 100755
index 59720b37..00000000
--- a/meta/recipes-kernel/linux-module/files/debian/rules
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/make -f
-
-# Debian rules for custom kernel module build
-#
-# This software is a part of ISAR.
-# Copyright (c) Siemens AG, 2018
-#
-# SPDX-License-Identifier: MIT
-
-export DEB_BUILD_OPTIONS=parallel=$(shell nproc)
-
-export CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)-
-
-ifeq ($(DEB_HOST_GNU_CPU), arm)
-export ARCH=arm
-endif
-ifeq ($(DEB_HOST_GNU_CPU), aarch64)
-export ARCH=arm64
-endif
-ifeq ($(DEB_HOST_GNU_CPU), riscv64)
-export ARCH=riscv
-endif
-ifneq (,$(findstring 86,$(DEB_HOST_GNU_CPU)))
-export ARCH=x86
-endif
-
-override_dh_auto_clean:
-	$(MAKE) -C $(KDIR) M=$(PWD) clean
-
-override_dh_auto_build:
-	$(MAKE) -C $(KDIR) M=$(PWD) modules
-
-override_dh_auto_install:
-	$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(PWD)/debian/$(PN) modules_install
-
-%:
-	CFLAGS= LDFLAGS= dh $@ --parallel
diff --git a/meta/recipes-kernel/linux-module/files/debian/rules.tmpl b/meta/recipes-kernel/linux-module/files/debian/rules.tmpl
new file mode 100755
index 00000000..d3bd7dc3
--- /dev/null
+++ b/meta/recipes-kernel/linux-module/files/debian/rules.tmpl
@@ -0,0 +1,60 @@
+#!/usr/bin/make -f
+
+# Debian rules for custom kernel module build
+#
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2018
+#
+# SPDX-License-Identifier: MIT
+
+export DEB_BUILD_OPTIONS=parallel=$(shell nproc)
+
+export CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)-
+
+ifeq ($(DEB_HOST_GNU_CPU), arm)
+export ARCH=arm
+endif
+ifeq ($(DEB_HOST_GNU_CPU), aarch64)
+export ARCH=arm64
+endif
+ifeq ($(DEB_HOST_GNU_CPU), riscv64)
+export ARCH=riscv
+endif
+ifneq (,$(findstring 86,$(DEB_HOST_GNU_CPU)))
+export ARCH=x86
+endif
+
+ifeq (${KERNEL_TYPE}, raspios)
+# In RaspiOS one package provides several headers
+KERNEL_SUFFIX := "+"
+ifeq (${KERNEL_NAME}, kernel8)
+KERNEL_SUFFIX := "-v8+"
+else ifeq (${KERNEL_NAME}, kernel7l)
+KERNEL_SUFFIX := "-v7l+"
+else ifeq (${KERNEL_NAME}, kernel7)
+KERNEL_SUFFIX := "-v7+"
+endif
+KDIR := $(shell dpkg -L ${KERNEL_HEADERS_PKG} | grep "/lib/modules/.*${KERNEL_SUFFIX}/build" | head -n1)
+endif
+
+ifeq ($(KDIR),)
+# Custom kernels contain the build folder directly.
+KDIR := $(shell dpkg -L ${KERNEL_HEADERS_PKG} | grep "/lib/modules/.*/build")
+endif
+ifeq ($(KDIR),)
+# Debian kernels install that folder indirectly via a dependency.
+KERNEL_DEP := $(shell dpkg-query -W -f '$${Depends}' ${KERNEL_HEADERS_PKG} | sed 's/.*\(linux-headers-[[:graph:]]*\).*/\1/')
+KDIR := $(shell dpkg -L $(KERNEL_DEP) | grep "/lib/modules/.*/build")
+endif
+
+override_dh_auto_clean:
+	$(MAKE) -C $(KDIR) M=$(PWD) clean
+
+override_dh_auto_build:
+	$(MAKE) -C $(KDIR) M=$(PWD) modules
+
+override_dh_auto_install:
+	$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(PWD)/debian/${PN} modules_install
+
+%:
+	CFLAGS= LDFLAGS= dh $@ --parallel
diff --git a/meta/recipes-kernel/linux-module/module.inc b/meta/recipes-kernel/linux-module/module.inc
index 968ac4c7..75dc4374 100644
--- a/meta/recipes-kernel/linux-module/module.inc
+++ b/meta/recipes-kernel/linux-module/module.inc
@@ -24,8 +24,9 @@ AUTOLOAD ?= ""
 inherit dpkg
 
 TEMPLATE_FILES = "debian/control.tmpl \
-                  debian/changelog.tmpl"
-TEMPLATE_VARS += "KERNEL_IMAGE_PKG KERNEL_HEADERS_PKG"
+                  debian/changelog.tmpl \
+                  debian/rules.tmpl"
+TEMPLATE_VARS += "KERNEL_NAME KERNEL_TYPE KERNEL_IMAGE_PKG KERNEL_HEADERS_PKG PN"
 
 do_prepare_build() {
     cp -r ${WORKDIR}/debian ${S}/
@@ -34,32 +35,3 @@ do_prepare_build() {
         echo "echo $module >> /etc/modules" >> ${S}/debian/postinst
     done
 }
-
-dpkg_runbuild_prepend() {
-    if [ "${KERNEL_TYPE}" = "raspios" ]; then
-        # In RaspiOS one package provides several headers
-        KERNEL_SUFFIX="+"
-        if [ "${KERNEL_NAME}" = "kernel8" ]; then
-            KERNEL_SUFFIX="-v8+"
-        elif [ "${KERNEL_NAME}" = "kernel7l" ]; then
-            KERNEL_SUFFIX="-v7l+"
-        elif [ "${KERNEL_NAME}" = "kernel7" ]; then
-            KERNEL_SUFFIX="-v7+"
-        fi
-        export KDIR=$(dpkg -L --root=${BUILDCHROOT_DIR} ${KERNEL_HEADERS_PKG} | \
-                      grep "/lib/modules/.*${KERNEL_SUFFIX}/build" | head -n1)
-    fi
-    if [ -z "$KDIR" ]; then
-        # Custom kernels contain the build folder directly.
-        export KDIR=$(dpkg -L --root=${BUILDCHROOT_DIR} ${KERNEL_HEADERS_PKG} | \
-                      grep "/lib/modules/.*/build")
-    fi
-    if [ -z "$KDIR" ]; then
-        # Debian kernels install that folder indirectly via a dependency.
-        KERNEL_DEP=$(dpkg-query -W -f '${Depends}' --admindir=${BUILDCHROOT_DIR}/var/lib/dpkg \
-                     ${KERNEL_HEADERS_PKG} | sed 's/.*\(linux-headers-[[:graph:]]*\).*/\1/')
-        export KDIR=$(dpkg -L --root=${BUILDCHROOT_DIR} ${KERNEL_DEP} | \
-                      grep "/lib/modules/.*/build")
-    fi
-    export PN=${PN}
-}
-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v5 3/9] u-boot: Do not use shell environment
  2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
  2022-02-13  7:41 ` [PATCH v5 1/9] template: Copy template attributes on transform Uladzimir Bely
  2022-02-13  7:41 ` [PATCH v5 2/9] linux-module: Do not use shell environment Uladzimir Bely
@ 2022-02-13  7:41 ` Uladzimir Bely
  2022-02-13  7:41 ` [PATCH v5 4/9] trusted-firmware: " Uladzimir Bely
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-13  7:41 UTC (permalink / raw)
  To: isar-users

From: Anton Mikanovich <amikan@ilbers.de>

To make package build process independent of the shell environment we
should remove U_BOOT_CONFIG and U_BOOT_BIN passing through export call.
So we migrate to template-based debian/rules file.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 .../u-boot/files/debian/{rules => rules.tmpl}            | 2 +-
 meta/recipes-bsp/u-boot/u-boot-custom.inc                | 9 ++-------
 2 files changed, 3 insertions(+), 8 deletions(-)
 rename meta/recipes-bsp/u-boot/files/debian/{rules => rules.tmpl} (94%)

diff --git a/meta/recipes-bsp/u-boot/files/debian/rules b/meta/recipes-bsp/u-boot/files/debian/rules.tmpl
similarity index 94%
rename from meta/recipes-bsp/u-boot/files/debian/rules
rename to meta/recipes-bsp/u-boot/files/debian/rules.tmpl
index 3d667620..806b01fe 100755
--- a/meta/recipes-bsp/u-boot/files/debian/rules
+++ b/meta/recipes-bsp/u-boot/files/debian/rules.tmpl
@@ -13,7 +13,7 @@ SET_CROSS_BUILD_TOOLS=CROSS_BUILD_TOOLS=y
 endif
 
 override_dh_auto_build:
-	$(MAKE) $(PARALLEL_MAKE) $(U_BOOT_CONFIG)
+	$(MAKE) $(PARALLEL_MAKE) ${U_BOOT_CONFIG}
 	$(MAKE) $(PARALLEL_MAKE) ${U_BOOT_BIN}
 	$(MAKE) -n u-boot-initial-env >/dev/null 2>&1; if [ $$? -ne 2 ]; then \
 		$(MAKE) $(PARALLEL_MAKE) u-boot-initial-env; \
diff --git a/meta/recipes-bsp/u-boot/u-boot-custom.inc b/meta/recipes-bsp/u-boot/u-boot-custom.inc
index 9984d8cc..2af7ada1 100644
--- a/meta/recipes-bsp/u-boot/u-boot-custom.inc
+++ b/meta/recipes-bsp/u-boot/u-boot-custom.inc
@@ -26,8 +26,8 @@ python() {
 
 DEBIAN_BUILD_DEPENDS ?= "bc, bison, flex, device-tree-compiler, git"
 
-TEMPLATE_FILES = "debian/control.tmpl"
-TEMPLATE_VARS += "MACHINE DEBIAN_BUILD_DEPENDS"
+TEMPLATE_FILES = "debian/control.tmpl debian/rules.tmpl"
+TEMPLATE_VARS += "MACHINE DEBIAN_BUILD_DEPENDS U_BOOT_CONFIG U_BOOT_BIN"
 
 U_BOOT_TOOLS_PACKAGE ?= "0"
 U_BOOT_CONFIG_PACKAGE ?= "0"
@@ -71,8 +71,3 @@ fw_env.config      /etc
 EOF
     fi
 }
-
-dpkg_runbuild_prepend() {
-    export U_BOOT_CONFIG="${U_BOOT_CONFIG}"
-    export U_BOOT_BIN="${U_BOOT_BIN}"
-}
-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v5 4/9] trusted-firmware: Do not use shell environment
  2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
                   ` (2 preceding siblings ...)
  2022-02-13  7:41 ` [PATCH v5 3/9] u-boot: " Uladzimir Bely
@ 2022-02-13  7:41 ` Uladzimir Bely
  2022-02-13  7:41 ` [PATCH v5 5/9] optee-os: " Uladzimir Bely
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-13  7:41 UTC (permalink / raw)
  To: isar-users

From: Anton Mikanovich <amikan@ilbers.de>

To make package build process independent of the shell environment we
should remove TF_A_PLATFORM and TF_A_EXTRA_BUILDARGS passing through
export call. So we migrate to template-based debian/rules file.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 .../files/debian/{rules => rules.tmpl}                   | 4 ++--
 .../trusted-firmware-a/trusted-firmware-a-custom.inc     | 9 ++-------
 2 files changed, 4 insertions(+), 9 deletions(-)
 rename meta/recipes-bsp/trusted-firmware-a/files/debian/{rules => rules.tmpl} (77%)

diff --git a/meta/recipes-bsp/trusted-firmware-a/files/debian/rules b/meta/recipes-bsp/trusted-firmware-a/files/debian/rules.tmpl
similarity index 77%
rename from meta/recipes-bsp/trusted-firmware-a/files/debian/rules
rename to meta/recipes-bsp/trusted-firmware-a/files/debian/rules.tmpl
index 70e1dd66..6dbf44db 100755
--- a/meta/recipes-bsp/trusted-firmware-a/files/debian/rules
+++ b/meta/recipes-bsp/trusted-firmware-a/files/debian/rules.tmpl
@@ -12,8 +12,8 @@ export CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)-
 endif
 
 override_dh_auto_build:
-	CFLAGS= LDFLAGS= $(MAKE) $(PARALLEL_MAKE) PLAT=$(TF_A_PLATFORM) \
-		$(TF_A_EXTRA_BUILDARGS)
+	CFLAGS= LDFLAGS= $(MAKE) $(PARALLEL_MAKE) PLAT=${TF_A_PLATFORM} \
+		${TF_A_EXTRA_BUILDARGS}
 
 %:
 	dh $@
diff --git a/meta/recipes-bsp/trusted-firmware-a/trusted-firmware-a-custom.inc b/meta/recipes-bsp/trusted-firmware-a/trusted-firmware-a-custom.inc
index 1142bfce..64153c6b 100644
--- a/meta/recipes-bsp/trusted-firmware-a/trusted-firmware-a-custom.inc
+++ b/meta/recipes-bsp/trusted-firmware-a/trusted-firmware-a-custom.inc
@@ -22,8 +22,8 @@ DEBIAN_BUILD_DEPENDS ?= ""
 
 PROVIDES += "trusted-firmware-a-${TF_A_NAME}"
 
-TEMPLATE_FILES = "debian/control.tmpl"
-TEMPLATE_VARS += "TF_A_NAME DEBIAN_BUILD_DEPENDS"
+TEMPLATE_FILES = "debian/control.tmpl debian/rules.tmpl"
+TEMPLATE_VARS += "TF_A_NAME DEBIAN_BUILD_DEPENDS TF_A_PLATFORM TF_A_EXTRA_BUILDARGS"
 
 do_prepare_build() {
     cp -r ${WORKDIR}/debian ${S}/
@@ -36,8 +36,3 @@ do_prepare_build() {
             ${S}/debian/trusted-firmware-a-${TF_A_NAME}.install
     done
 }
-
-dpkg_runbuild_prepend() {
-    export TF_A_PLATFORM="${TF_A_PLATFORM}"
-    export TF_A_EXTRA_BUILDARGS="${TF_A_EXTRA_BUILDARGS}"
-}
-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v5 5/9] optee-os: Do not use shell environment
  2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
                   ` (3 preceding siblings ...)
  2022-02-13  7:41 ` [PATCH v5 4/9] trusted-firmware: " Uladzimir Bely
@ 2022-02-13  7:41 ` Uladzimir Bely
  2022-02-13  7:41 ` [PATCH v5 6/9] optee-os-stm32mp15x: " Uladzimir Bely
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-13  7:41 UTC (permalink / raw)
  To: isar-users

From: Anton Mikanovich <amikan@ilbers.de>

To make package build process independent of the shell environment we
should remove OPTEE_PLATFORM and OPTEE_EXTRA_BUILDARGS passing through
export call. So we migrate to template-based debian/rules file.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 .../optee-os/files/debian/{rules => rules.tmpl}          | 4 ++--
 meta/recipes-bsp/optee-os/optee-os-custom.inc            | 9 ++-------
 2 files changed, 4 insertions(+), 9 deletions(-)
 rename meta/recipes-bsp/optee-os/files/debian/{rules => rules.tmpl} (75%)

diff --git a/meta/recipes-bsp/optee-os/files/debian/rules b/meta/recipes-bsp/optee-os/files/debian/rules.tmpl
similarity index 75%
rename from meta/recipes-bsp/optee-os/files/debian/rules
rename to meta/recipes-bsp/optee-os/files/debian/rules.tmpl
index d2e9900f..9ab80dfe 100755
--- a/meta/recipes-bsp/optee-os/files/debian/rules
+++ b/meta/recipes-bsp/optee-os/files/debian/rules.tmpl
@@ -12,8 +12,8 @@ export CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)-
 endif
 
 override_dh_auto_build:
-	CFLAGS= LDFLAGS= $(MAKE) $(PARALLEL_MAKE) PLATFORM=$(OPTEE_PLATFORM) \
-		$(OPTEE_EXTRA_BUILDARGS)
+	CFLAGS= LDFLAGS= $(MAKE) $(PARALLEL_MAKE) PLATFORM=${OPTEE_PLATFORM} \
+		${OPTEE_EXTRA_BUILDARGS}
 
 %:
 	dh $@
diff --git a/meta/recipes-bsp/optee-os/optee-os-custom.inc b/meta/recipes-bsp/optee-os/optee-os-custom.inc
index 1bd51969..23612d81 100644
--- a/meta/recipes-bsp/optee-os/optee-os-custom.inc
+++ b/meta/recipes-bsp/optee-os/optee-os-custom.inc
@@ -22,8 +22,8 @@ DEBIAN_BUILD_DEPENDS ?= "python3-pycryptodome:native, python3-pyelftools"
 
 PROVIDES += "optee-os-${OPTEE_NAME}"
 
-TEMPLATE_FILES = "debian/control.tmpl"
-TEMPLATE_VARS += "OPTEE_NAME DEBIAN_BUILD_DEPENDS"
+TEMPLATE_FILES = "debian/control.tmpl debian/rules.tmpl"
+TEMPLATE_VARS += "OPTEE_NAME DEBIAN_BUILD_DEPENDS OPTEE_PLATFORM OPTEE_EXTRA_BUILDARGS"
 
 # split strip platform flavor, if any, from the specified platform string
 OPTEE_PLATFORM_BASE = "${@d.getVar('OPTEE_PLATFORM').split('-')[0]}"
@@ -39,8 +39,3 @@ do_prepare_build() {
             ${S}/debian/optee-os-${OPTEE_NAME}.install
     done
 }
-
-dpkg_runbuild_prepend() {
-    export OPTEE_PLATFORM="${OPTEE_PLATFORM}"
-    export OPTEE_EXTRA_BUILDARGS="${OPTEE_EXTRA_BUILDARGS}"
-}
-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v5 6/9] optee-os-stm32mp15x: Do not use shell environment
  2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
                   ` (4 preceding siblings ...)
  2022-02-13  7:41 ` [PATCH v5 5/9] optee-os: " Uladzimir Bely
@ 2022-02-13  7:41 ` Uladzimir Bely
  2022-02-22  6:49   ` Jan Kiszka
  2022-02-13  7:41 ` [PATCH v5 7/9] kselftest: " Uladzimir Bely
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-13  7:41 UTC (permalink / raw)
  To: isar-users

Move export of TEE_IMPL_VERSION variable directly to debian/rules.

This makes building process more Debian-like.

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb b/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
index 0fa2005d..9c0efaf1 100644
--- a/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
+++ b/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
@@ -21,5 +21,8 @@ OPTEE_BINARIES = "tee-header_v2.stm32 tee-pageable_v2.stm32 tee-pager_v2.stm32"
 # Set version manually to PV, the tarball does not contain any hint.
 # Alternative: pull from git and add git as build dependency.
 dpkg_runbuild_prepend() {
-    export TEE_IMPL_VERSION=${PV}
+    cat << EOF >> ${S}/debian/rules
+
+export TEE_IMPL_VERSION=${PV}
+EOF
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v5 7/9] kselftest: Do not use shell environment
  2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
                   ` (5 preceding siblings ...)
  2022-02-13  7:41 ` [PATCH v5 6/9] optee-os-stm32mp15x: " Uladzimir Bely
@ 2022-02-13  7:41 ` Uladzimir Bely
  2022-02-13  7:41 ` [PATCH v5 8/9] linux-mainline: Move cfg fragment test to debian/rules Uladzimir Bely
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-13  7:41 UTC (permalink / raw)
  To: isar-users

From: Anton Mikanovich <amikan@ilbers.de>

To make package build process independent of the shell environment we
should remove KSELFTEST_ARGS passing through export call. The same
logic can be done by internal recipe parser and then pass variable to
template-based debian/rules file.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 .../kselftest/files/{rules => rules.tmpl}     |  0
 meta/recipes-kernel/kselftest/kselftest.inc   | 21 +++++++------------
 2 files changed, 8 insertions(+), 13 deletions(-)
 rename meta/recipes-kernel/kselftest/files/{rules => rules.tmpl} (100%)

diff --git a/meta/recipes-kernel/kselftest/files/rules b/meta/recipes-kernel/kselftest/files/rules.tmpl
similarity index 100%
rename from meta/recipes-kernel/kselftest/files/rules
rename to meta/recipes-kernel/kselftest/files/rules.tmpl
diff --git a/meta/recipes-kernel/kselftest/kselftest.inc b/meta/recipes-kernel/kselftest/kselftest.inc
index 2a76028b..6187d8e4 100644
--- a/meta/recipes-kernel/kselftest/kselftest.inc
+++ b/meta/recipes-kernel/kselftest/kselftest.inc
@@ -33,26 +33,21 @@ DEBIAN_BUILD_DEPENDS ?= " \
     llvm:native, \
 "
 
-SRC_URI += "file://rules"
+SRC_URI += "file://rules.tmpl"
 S = "${WORKDIR}/linux-${PV}"
 
+TEMPLATE_FILES = "rules.tmpl"
+TEMPLATE_VARS += "KSELFTEST_ARGS"
+
 KSELFTEST_TARGETS ?= ""
 KSELFTEST_SKIP_TARGETS ?= ""
 KSELFTEST_FORCE_TARGETS ?= "0"
 
+KSELFTEST_ARGS = "${@ "TARGETS=\"${KSELFTEST_TARGETS}\"" if d.getVar('KSELFTEST_TARGETS', True) else ''}"
+KSELFTEST_ARGS_append = "${@ " FORCE_TARGETS=1" if d.getVar('KSELFTEST_FORCE_TARGETS', True) == '1' else ''}"
+KSELFTEST_ARGS_append .= "${@ " SKIP_TARGETS=\"${KSELFTEST_SKIP_TARGETS}\"" if d.getVar('KSELFTEST_SKIP_TARGETS', True) else ''}"
+
 do_prepare_build[cleandirs] += "${S}/debian"
 do_prepare_build() {
     deb_debianize
 }
-
-dpkg_runbuild_prepend() {
-    if [ -n "${KSELFTEST_TARGETS}" ];then
-        export KSELFTEST_ARGS="TARGETS=\"${KSELFTEST_TARGETS}\""
-    fi
-    if [ ${KSELFTEST_FORCE_TARGETS} -eq 1 ];then
-        export KSELFTEST_ARGS="${KSELFTEST_ARGS} FORCE_TARGETS=1"
-    fi
-    if [ -n "${KSELFTEST_SKIP_TARGETS}" ];then
-        export KSELFTEST_ARGS="${KSELFTEST_ARGS} SKIP_TARGETS=\"${KSELFTEST_SKIP_TARGETS}\""
-    fi
-}
-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v5 8/9] linux-mainline: Move cfg fragment test to debian/rules
  2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
                   ` (6 preceding siblings ...)
  2022-02-13  7:41 ` [PATCH v5 7/9] kselftest: " Uladzimir Bely
@ 2022-02-13  7:41 ` Uladzimir Bely
  2022-02-22  6:50   ` Jan Kiszka
  2022-02-13  7:41 ` [PATCH v5 9/9] linux-custom: Move cfg fragments applying " Uladzimir Bely
  2022-02-22  6:39 ` [PATCH v5 0/9] Avoid using shell environment during the build Anton Mikanovich
  9 siblings, 1 reply; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-13  7:41 UTC (permalink / raw)
  To: isar-users

From: Anton Mikanovich <amikan@ilbers.de>

Perform all config fragments checking in Debian way.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 .../linux/linux-mainline_5.4.70.bb               | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/meta-isar/recipes-kernel/linux/linux-mainline_5.4.70.bb b/meta-isar/recipes-kernel/linux/linux-mainline_5.4.70.bb
index 980e137b..28e51c0d 100644
--- a/meta-isar/recipes-kernel/linux/linux-mainline_5.4.70.bb
+++ b/meta-isar/recipes-kernel/linux/linux-mainline_5.4.70.bb
@@ -25,11 +25,13 @@ LINUX_VERSION_EXTENSION = "-isar"
 
 # For testing purposes only
 dpkg_configure_kernel_append() {
-    if ! grep "# CONFIG_MTD is not set" ${S}/${KERNEL_BUILD_DIR}/.config && \
-       ! grep "# CONFIG_MTD_UBI is not set" ${S}/${KERNEL_BUILD_DIR}/.config; then
-        grep "# CONFIG_UBIFS_FS is not set" ${S}/${KERNEL_BUILD_DIR}/.config || \
-            bbfatal "Self-check failed: CONFIG_UBIFS_FS still enabled"
-    fi
-    grep "CONFIG_ROOT_NFS=y" ${S}/${KERNEL_BUILD_DIR}/.config || \
-        bbfatal "Self-check failed: CONFIG_ROOT_NFS not enabled"
+cat << EOF | sed -i '/^override_dh_auto_build/ r /dev/stdin' ${S}/debian/rules
+	if ! grep "# CONFIG_MTD is not set" \$(O)/.config && \\
+	   ! grep "# CONFIG_MTD_UBI is not set" \$(O)/.config; then \\
+	    grep "# CONFIG_UBIFS_FS is not set" \$(O)/.config || \\
+	        (echo "Self-check failed: CONFIG_UBIFS_FS still enabled" && exit 1); \\
+	fi
+	grep "CONFIG_ROOT_NFS=y" \$(O)/.config || \\
+	    (echo "Self-check failed: CONFIG_ROOT_NFS not enabled" && exit 1)
+EOF
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v5 9/9] linux-custom: Move cfg fragments applying to debian/rules
  2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
                   ` (7 preceding siblings ...)
  2022-02-13  7:41 ` [PATCH v5 8/9] linux-mainline: Move cfg fragment test to debian/rules Uladzimir Bely
@ 2022-02-13  7:41 ` Uladzimir Bely
  2022-02-23 13:53   ` Henning Schild
  2022-02-22  6:39 ` [PATCH v5 0/9] Avoid using shell environment during the build Anton Mikanovich
  9 siblings, 1 reply; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-13  7:41 UTC (permalink / raw)
  To: isar-users

Prepare linux fragments applying in Debian way.

This allows to avoid pre-build chroot call used for merging
kernel config file and custom config fragments. Also, shell exports
are not used anymore in favor of template files.

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 .../linux/files/debian/isar/configure.tmpl    | 19 +++++++
 .../linux/files/debian/rules.tmpl             |  3 ++
 meta/recipes-kernel/linux/linux-custom.inc    | 53 ++++++++++++-------
 3 files changed, 55 insertions(+), 20 deletions(-)
 create mode 100644 meta/recipes-kernel/linux/files/debian/isar/configure.tmpl

diff --git a/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
new file mode 100644
index 00000000..83871baa
--- /dev/null
+++ b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
@@ -0,0 +1,19 @@
+#!/bin/bash
+# Copyright (c) Mentor Graphics, a Siemens business, 2019
+# SPDX-License-Identifier: MIT
+
+# Load common stuff
+. ${S}/debian/isar/common || exit ${?}
+
+do_configure() {
+
+    # Process kernel config target and fragments
+    ${MAKE} O=${KERNEL_BUILD_DIR} ${KERNEL_CONFIG_TARGET} || exit ${?}
+    ./scripts/kconfig/merge_config.sh -O ${KERNEL_BUILD_DIR}/ \
+    ${KERNEL_BUILD_DIR}/.config ${KERNEL_CONFIG_FRAGMENTS}
+
+    # Stop tracing
+    set +x
+}
+
+main configure ${*}
diff --git a/meta/recipes-kernel/linux/files/debian/rules.tmpl b/meta/recipes-kernel/linux/files/debian/rules.tmpl
index 05a26fe2..a1166287 100755
--- a/meta/recipes-kernel/linux/files/debian/rules.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/rules.tmpl
@@ -22,6 +22,9 @@ isar_env=$(strip \
 override_dh_auto_clean:
 	$(isar_env) && bash $(deb_top_dir)/isar/clean
 
+override_dh_auto_configure:
+	$(isar_env) && bash $(deb_top_dir)/isar/configure
+
 override_dh_auto_build:
 	$(isar_env) && bash $(deb_top_dir)/isar/build
 
diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
index 59d42c84..ea1abf76 100644
--- a/meta/recipes-kernel/linux/linux-custom.inc
+++ b/meta/recipes-kernel/linux/linux-custom.inc
@@ -52,6 +52,7 @@ TEMPLATE_FILES += "                  \
     debian/isar/build.tmpl           \
     debian/isar/clean.tmpl           \
     debian/isar/common.tmpl          \
+    debian/isar/configure.tmpl       \
     debian/isar/install.tmpl         \
     debian/isar/version.cfg.tmpl     \
     debian/linux-image.postinst.tmpl \
@@ -71,6 +72,8 @@ TEMPLATE_VARS += "                \
     KERNEL_HEADERS_DEBIAN_DEPENDS \
     LINUX_VERSION_EXTENSION       \
     KERNEL_NAME_PROVIDED          \
+    KERNEL_CONFIG_TARGET          \
+    KERNEL_CONFIG_FRAGMENTS       \
 "
 
 inherit dpkg
@@ -146,41 +149,51 @@ do_prepare_build_prepend() {
 # build directory for our "full" kernel build
 KERNEL_BUILD_DIR = "build-full"
 
+def get_kernel_config_target(d):
+    kernel_defconfig = d.getVar('KERNEL_DEFCONFIG', True)
+
+    config_target = kernel_defconfig
+
+    if kernel_defconfig:
+        workdir=d.getVar('WORKDIR', True)
+        if os.path.isfile(workdir + "/" + kernel_defconfig):
+            config_target = "olddefconfig"
+        else:
+            config_target = "defconfig KBUILD_DEFCONFIG=" + kernel_defconfig
+    else:
+        config_target = "defconfig"
+
+    return config_target
+
+KERNEL_CONFIG_TARGET = "${@get_kernel_config_target(d)}"
+
+def get_kernel_config_fragments(d):
+    src_frags = " ".join(config_fragments(d))
+    out_frags = " ".join(map(lambda frag: 'debian/fragments/' + frag, config_fragments(d)))
+
+    linux_version_extension = d.getVar('LINUX_VERSION_EXTENSION', True)
+    if linux_version_extension:
+        out_frags += " debian/isar/version.cfg"
+
+    return out_frags
+
+KERNEL_CONFIG_FRAGMENTS = "${@get_kernel_config_fragments(d)}"
+
 dpkg_configure_kernel() {
-	config_target="${KERNEL_DEFCONFIG}"
 	rm -rf ${S}/${KERNEL_BUILD_DIR} && mkdir -p ${S}/${KERNEL_BUILD_DIR}
 	if [ -n "${KERNEL_DEFCONFIG}" ]; then
 		if [ -e "${WORKDIR}/${KERNEL_DEFCONFIG}" ]; then
 			cp ${WORKDIR}/${KERNEL_DEFCONFIG} ${S}/${KERNEL_BUILD_DIR}/.config
-			config_target="olddefconfig"
-		else
-			config_target="defconfig KBUILD_DEFCONFIG=${KERNEL_DEFCONFIG}"
 		fi
-	else
-		config_target="defconfig"
 	fi
 
 	# copy config fragments over to the kernel tree
 	src_frags="${@ " ".join(config_fragments(d)) }"
-	out_frags="${@ " ".join(map(lambda frag: 'debian/fragments/' + frag, config_fragments(d))) }"
-	if [ -n "${LINUX_VERSION_EXTENSION}" ]; then
-		out_frags="${out_frags} debian/isar/version.cfg"
-	fi
 	rm -rf ${S}/debian/fragments
 	if [ -n "${src_frags}" ]; then
 		mkdir -p ${S}/debian/fragments
 		(cd ${WORKDIR} && cp ${src_frags} ${S}/debian/fragments/)
 	fi
-
-	sudo -E chroot --userspec=$(id -u):$(id -g) ${BUILDCHROOT_DIR} sh -c " \
-		export ARCH=${KERNEL_ARCH} &&                                  \
-		cd ${PP}/${PPS} &&                                             \
-		make O=${KERNEL_BUILD_DIR} ${config_target} &&                 \
-		./scripts/kconfig/merge_config.sh                              \
-			-O ${KERNEL_BUILD_DIR}/                                \
-			${KERNEL_BUILD_DIR}/.config                            \
-			${out_frags}                                           \
-        "
 }
 
 dpkg_runbuild_prepend() {
-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 0/9] Avoid using shell environment during the build
  2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
                   ` (8 preceding siblings ...)
  2022-02-13  7:41 ` [PATCH v5 9/9] linux-custom: Move cfg fragments applying " Uladzimir Bely
@ 2022-02-22  6:39 ` Anton Mikanovich
  9 siblings, 0 replies; 20+ messages in thread
From: Anton Mikanovich @ 2022-02-22  6:39 UTC (permalink / raw)
  To: Uladzimir Bely, isar-users

13.02.22 10:41, Uladzimir Bely wrote:
> This patchset is a subseries of 'Sbuild/Schroot migration' patchset
> including only preparation patches. It doesn't require any changes
> in host machine configuration for downstreams (meta-iot2050 and
> xenomai-images were tested) so can be merged independently.
>
> In this patchset the main topic is a migration to template files that
> allows to use cleaner build environment.
>
> When this patchset is merged, it will make maintenance of remaining
> sbuild-related patches easier and will shorten their number.
>
> Changes since v5:
> - Removed "ifneq ($(KDIR),)" workaround for dh_auto_clean override
> for "linux-module" patch (while latter sbuild patchset moved to using
> .dsc file).
>
> Changes since v4:
> - Added patch for optee-os-stm32mp15x to avoid shell exports.
>
> Changes since v2:
> - Removed `dpkg_build_export` while a way to continue using
> shell exports for sbuild was found.
>
> Changes since v1:
> - Introduced `dpkg_build_export` function to be used for passing
> variables to build environment;
> - Linux kernel framgments handling is done in Debian way.
>
> Anton Mikanovich (6):
>    linux-module: Do not use shell environment
>    u-boot: Do not use shell environment
>    trusted-firmware: Do not use shell environment
>    optee-os: Do not use shell environment
>    kselftest: Do not use shell environment
>    linux-mainline: Move cfg fragment test to debian/rules
>
> Uladzimir Bely (3):
>    template: Copy template attributes on transform
>    optee-os-stm32mp15x: Do not use shell environment
>    linux-custom: Move cfg fragments applying to debian/rules
>
>   .../optee-os/optee-os-stm32mp15x_3.11.0.bb    |  5 +-
>   .../linux/linux-mainline_5.4.70.bb            | 16 ++---
>   meta/classes/template.bbclass                 |  4 +-
>   .../files/debian/{rules => rules.tmpl}        |  4 +-
>   meta/recipes-bsp/optee-os/optee-os-custom.inc |  9 +--
>   .../files/debian/{rules => rules.tmpl}        |  4 +-
>   .../trusted-firmware-a-custom.inc             |  9 +--
>   .../u-boot/files/debian/{rules => rules.tmpl} |  2 +-
>   meta/recipes-bsp/u-boot/u-boot-custom.inc     |  9 +--
>   .../kselftest/files/{rules => rules.tmpl}     |  0
>   meta/recipes-kernel/kselftest/kselftest.inc   | 21 +++----
>   .../linux-module/files/debian/rules           | 37 ------------
>   .../linux-module/files/debian/rules.tmpl      | 60 +++++++++++++++++++
>   meta/recipes-kernel/linux-module/module.inc   | 34 +----------
>   .../linux/files/debian/isar/configure.tmpl    | 19 ++++++
>   .../linux/files/debian/rules.tmpl             |  3 +
>   meta/recipes-kernel/linux/linux-custom.inc    | 53 +++++++++-------
>   17 files changed, 153 insertions(+), 136 deletions(-)
>   rename meta/recipes-bsp/optee-os/files/debian/{rules => rules.tmpl} (75%)
>   rename meta/recipes-bsp/trusted-firmware-a/files/debian/{rules => rules.tmpl} (77%)
>   rename meta/recipes-bsp/u-boot/files/debian/{rules => rules.tmpl} (94%)
>   rename meta/recipes-kernel/kselftest/files/{rules => rules.tmpl} (100%)
>   delete mode 100755 meta/recipes-kernel/linux-module/files/debian/rules
>   create mode 100755 meta/recipes-kernel/linux-module/files/debian/rules.tmpl
>   create mode 100644 meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
>
Applied to next, thanks.


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 6/9] optee-os-stm32mp15x: Do not use shell environment
  2022-02-13  7:41 ` [PATCH v5 6/9] optee-os-stm32mp15x: " Uladzimir Bely
@ 2022-02-22  6:49   ` Jan Kiszka
  2022-02-22 12:29     ` Uladzimir Bely
  0 siblings, 1 reply; 20+ messages in thread
From: Jan Kiszka @ 2022-02-22  6:49 UTC (permalink / raw)
  To: Uladzimir Bely, isar-users, Anton Mikanovich

On 13.02.22 08:41, Uladzimir Bely wrote:
> Move export of TEE_IMPL_VERSION variable directly to debian/rules.
> 
> This makes building process more Debian-like.
> 
> Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
> ---
>  meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb b/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
> index 0fa2005d..9c0efaf1 100644
> --- a/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
> +++ b/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
> @@ -21,5 +21,8 @@ OPTEE_BINARIES = "tee-header_v2.stm32 tee-pageable_v2.stm32 tee-pager_v2.stm32"
>  # Set version manually to PV, the tarball does not contain any hint.
>  # Alternative: pull from git and add git as build dependency.
>  dpkg_runbuild_prepend() {
> -    export TEE_IMPL_VERSION=${PV}
> +    cat << EOF >> ${S}/debian/rules
> +
> +export TEE_IMPL_VERSION=${PV}
> +EOF
>  }

I think I commented on this anti-pattern elsewhere already: This can
lead to piled-up extra lines in the target file. Now that it's merged,
please fix up on top, e.g. using a sed rule that avoids duplicate
patching or appending to the unpack step.

Please also check if you used it elsewhere in fix those spots accordingly.

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 8/9] linux-mainline: Move cfg fragment test to debian/rules
  2022-02-13  7:41 ` [PATCH v5 8/9] linux-mainline: Move cfg fragment test to debian/rules Uladzimir Bely
@ 2022-02-22  6:50   ` Jan Kiszka
  0 siblings, 0 replies; 20+ messages in thread
From: Jan Kiszka @ 2022-02-22  6:50 UTC (permalink / raw)
  To: Uladzimir Bely, isar-users

On 13.02.22 08:41, Uladzimir Bely wrote:
> From: Anton Mikanovich <amikan@ilbers.de>
> 
> Perform all config fragments checking in Debian way.
> 
> Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
> ---
>  .../linux/linux-mainline_5.4.70.bb               | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/meta-isar/recipes-kernel/linux/linux-mainline_5.4.70.bb b/meta-isar/recipes-kernel/linux/linux-mainline_5.4.70.bb
> index 980e137b..28e51c0d 100644
> --- a/meta-isar/recipes-kernel/linux/linux-mainline_5.4.70.bb
> +++ b/meta-isar/recipes-kernel/linux/linux-mainline_5.4.70.bb
> @@ -25,11 +25,13 @@ LINUX_VERSION_EXTENSION = "-isar"
>  
>  # For testing purposes only
>  dpkg_configure_kernel_append() {
> -    if ! grep "# CONFIG_MTD is not set" ${S}/${KERNEL_BUILD_DIR}/.config && \
> -       ! grep "# CONFIG_MTD_UBI is not set" ${S}/${KERNEL_BUILD_DIR}/.config; then
> -        grep "# CONFIG_UBIFS_FS is not set" ${S}/${KERNEL_BUILD_DIR}/.config || \
> -            bbfatal "Self-check failed: CONFIG_UBIFS_FS still enabled"
> -    fi
> -    grep "CONFIG_ROOT_NFS=y" ${S}/${KERNEL_BUILD_DIR}/.config || \
> -        bbfatal "Self-check failed: CONFIG_ROOT_NFS not enabled"
> +cat << EOF | sed -i '/^override_dh_auto_build/ r /dev/stdin' ${S}/debian/rules
> +	if ! grep "# CONFIG_MTD is not set" \$(O)/.config && \\
> +	   ! grep "# CONFIG_MTD_UBI is not set" \$(O)/.config; then \\
> +	    grep "# CONFIG_UBIFS_FS is not set" \$(O)/.config || \\
> +	        (echo "Self-check failed: CONFIG_UBIFS_FS still enabled" && exit 1); \\
> +	fi
> +	grep "CONFIG_ROOT_NFS=y" \$(O)/.config || \\
> +	    (echo "Self-check failed: CONFIG_ROOT_NFS not enabled" && exit 1)
> +EOF
>  }

As commented on in patch 6: anti-pattern that we should avoid in Isar code.

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 6/9] optee-os-stm32mp15x: Do not use shell environment
  2022-02-22  6:49   ` Jan Kiszka
@ 2022-02-22 12:29     ` Uladzimir Bely
  2022-02-23 14:01       ` Jan Kiszka
  0 siblings, 1 reply; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-22 12:29 UTC (permalink / raw)
  To: isar-users, Jan Kiszka

In the email from Tuesday, 22 February 2022 09:49:38 +03 user Jan Kiszka 
wrote:
> On 13.02.22 08:41, Uladzimir Bely wrote:
> > Move export of TEE_IMPL_VERSION variable directly to debian/rules.
> > 
> > This makes building process more Debian-like.
> > 
> > Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
> > ---
> > 
> >  meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
> > b/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb index
> > 0fa2005d..9c0efaf1 100644
> > --- a/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
> > +++ b/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
> > @@ -21,5 +21,8 @@ OPTEE_BINARIES = "tee-header_v2.stm32
> > tee-pageable_v2.stm32 tee-pager_v2.stm32"> 
> >  # Set version manually to PV, the tarball does not contain any hint.
> >  # Alternative: pull from git and add git as build dependency.
> >  dpkg_runbuild_prepend() {
> > 
> > -    export TEE_IMPL_VERSION=${PV}
> > +    cat << EOF >> ${S}/debian/rules
> > +
> > +export TEE_IMPL_VERSION=${PV}
> > +EOF
> > 
> >  }
> 
> I think I commented on this anti-pattern elsewhere already: This can
> lead to piled-up extra lines in the target file. Now that it's merged,
> please fix up on top, e.g. using a sed rule that avoids duplicate
> patching or appending to the unpack step.
> 
> Please also check if you used it elsewhere in fix those spots accordingly.
> 
> Jan

I tried to see the problem with line duplicates you are talking about and I 
couldn't reproduce it. Any way to invalidate do_build (recipe modification, 
manual task invalidation by bitbake, etc) makes ${S} to be renewed, so "old" 
lines are not presented here. So, this kind of export appears only once.

-- 
Uladzimir Bely




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 9/9] linux-custom: Move cfg fragments applying to debian/rules
  2022-02-13  7:41 ` [PATCH v5 9/9] linux-custom: Move cfg fragments applying " Uladzimir Bely
@ 2022-02-23 13:53   ` Henning Schild
  2022-02-24  9:09     ` Uladzimir Bely
  0 siblings, 1 reply; 20+ messages in thread
From: Henning Schild @ 2022-02-23 13:53 UTC (permalink / raw)
  To: Uladzimir Bely; +Cc: isar-users

I just ran into an issue with that not actually finding my config in
WORKDIR and now trying to go the KBUILD_DEFCONFIG way

Am Sun, 13 Feb 2022 08:41:11 +0100
schrieb Uladzimir Bely <ubely@ilbers.de>:

> Prepare linux fragments applying in Debian way.
> 
> This allows to avoid pre-build chroot call used for merging
> kernel config file and custom config fragments. Also, shell exports
> are not used anymore in favor of template files.
> 
> Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
> ---
>  .../linux/files/debian/isar/configure.tmpl    | 19 +++++++
>  .../linux/files/debian/rules.tmpl             |  3 ++
>  meta/recipes-kernel/linux/linux-custom.inc    | 53
> ++++++++++++------- 3 files changed, 55 insertions(+), 20 deletions(-)
>  create mode 100644
> meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> 
> diff --git
> a/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl new file
> mode 100644 index 00000000..83871baa --- /dev/null
> +++ b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> @@ -0,0 +1,19 @@
> +#!/bin/bash
> +# Copyright (c) Mentor Graphics, a Siemens business, 2019
> +# SPDX-License-Identifier: MIT
> +
> +# Load common stuff
> +. ${S}/debian/isar/common || exit ${?}
> +
> +do_configure() {
> +
> +    # Process kernel config target and fragments
> +    ${MAKE} O=${KERNEL_BUILD_DIR} ${KERNEL_CONFIG_TARGET} || exit
> ${?}
> +    ./scripts/kconfig/merge_config.sh -O ${KERNEL_BUILD_DIR}/ \
> +    ${KERNEL_BUILD_DIR}/.config ${KERNEL_CONFIG_FRAGMENTS}
> +
> +    # Stop tracing
> +    set +x
> +}
> +
> +main configure ${*}
> diff --git a/meta/recipes-kernel/linux/files/debian/rules.tmpl
> b/meta/recipes-kernel/linux/files/debian/rules.tmpl index
> 05a26fe2..a1166287 100755 ---
> a/meta/recipes-kernel/linux/files/debian/rules.tmpl +++
> b/meta/recipes-kernel/linux/files/debian/rules.tmpl @@ -22,6 +22,9 @@
> isar_env=$(strip \ override_dh_auto_clean:
>  	$(isar_env) && bash $(deb_top_dir)/isar/clean
>  
> +override_dh_auto_configure:
> +	$(isar_env) && bash $(deb_top_dir)/isar/configure
> +
>  override_dh_auto_build:
>  	$(isar_env) && bash $(deb_top_dir)/isar/build
>  
> diff --git a/meta/recipes-kernel/linux/linux-custom.inc
> b/meta/recipes-kernel/linux/linux-custom.inc index 59d42c84..ea1abf76
> 100644 --- a/meta/recipes-kernel/linux/linux-custom.inc
> +++ b/meta/recipes-kernel/linux/linux-custom.inc
> @@ -52,6 +52,7 @@ TEMPLATE_FILES += "                  \
>      debian/isar/build.tmpl           \
>      debian/isar/clean.tmpl           \
>      debian/isar/common.tmpl          \
> +    debian/isar/configure.tmpl       \
>      debian/isar/install.tmpl         \
>      debian/isar/version.cfg.tmpl     \
>      debian/linux-image.postinst.tmpl \
> @@ -71,6 +72,8 @@ TEMPLATE_VARS += "                \
>      KERNEL_HEADERS_DEBIAN_DEPENDS \
>      LINUX_VERSION_EXTENSION       \
>      KERNEL_NAME_PROVIDED          \
> +    KERNEL_CONFIG_TARGET          \
> +    KERNEL_CONFIG_FRAGMENTS       \
>  "
>  
>  inherit dpkg
> @@ -146,41 +149,51 @@ do_prepare_build_prepend() {
>  # build directory for our "full" kernel build
>  KERNEL_BUILD_DIR = "build-full"
>  
> +def get_kernel_config_target(d):
> +    kernel_defconfig = d.getVar('KERNEL_DEFCONFIG', True)
> +
> +    config_target = kernel_defconfig
> +
> +    if kernel_defconfig:
> +        workdir=d.getVar('WORKDIR', True)
> +        if os.path.isfile(workdir + "/" + kernel_defconfig):

Doing that at parse-time when assigning the variable
KERNEL_CONFIG_TARGET can not work. Some task in the task chain might
need to create that file first ... fetch/unpack/fiddle-with

Checking if the file exists at parse time seems very wrong. I guess
this patch needs to be reverted and rewritten and i guess the test
suite does not properly cover kernels custom defconfig

This is how one can rebuild a debian kernel

KBUILD_DEPENDS += ",linux-config-${PV}"

KERNEL_DEFCONFIG="${P}.conf"

do_take_debian_config() {
    xzcat ${BUILDCHROOT_DIR}/usr/src/linux-config-${PV}/config.${DISTRO_ARCH}_none_${DISTRO_ARCH}.xz > ${S}/${KERNEL_DEFCONFIG}
}

addtask take_debian_config after do_install_builddeps before
do_dpkg_build

Maybe that could be used for writing a kernel test recipe actually going the "olddefconfig" way in case we do not yet have one.

Henning

> +            config_target = "olddefconfig"
> +        else:
> +            config_target = "defconfig KBUILD_DEFCONFIG=" +
> kernel_defconfig
> +    else:
> +        config_target = "defconfig"
> +
> +    return config_target
> +
> +KERNEL_CONFIG_TARGET = "${@get_kernel_config_target(d)}"
> +
> +def get_kernel_config_fragments(d):
> +    src_frags = " ".join(config_fragments(d))
> +    out_frags = " ".join(map(lambda frag: 'debian/fragments/' +
> frag, config_fragments(d))) +
> +    linux_version_extension = d.getVar('LINUX_VERSION_EXTENSION',
> True)
> +    if linux_version_extension:
> +        out_frags += " debian/isar/version.cfg"
> +
> +    return out_frags
> +
> +KERNEL_CONFIG_FRAGMENTS = "${@get_kernel_config_fragments(d)}"
> +
>  dpkg_configure_kernel() {
> -	config_target="${KERNEL_DEFCONFIG}"
>  	rm -rf ${S}/${KERNEL_BUILD_DIR} && mkdir -p
> ${S}/${KERNEL_BUILD_DIR} if [ -n "${KERNEL_DEFCONFIG}" ]; then
>  		if [ -e "${WORKDIR}/${KERNEL_DEFCONFIG}" ]; then
>  			cp ${WORKDIR}/${KERNEL_DEFCONFIG}
> ${S}/${KERNEL_BUILD_DIR}/.config
> -			config_target="olddefconfig"
> -		else
> -			config_target="defconfig
> KBUILD_DEFCONFIG=${KERNEL_DEFCONFIG}" fi
> -	else
> -		config_target="defconfig"
>  	fi
>  
>  	# copy config fragments over to the kernel tree
>  	src_frags="${@ " ".join(config_fragments(d)) }"
> -	out_frags="${@ " ".join(map(lambda frag: 'debian/fragments/'
> + frag, config_fragments(d))) }"
> -	if [ -n "${LINUX_VERSION_EXTENSION}" ]; then
> -		out_frags="${out_frags} debian/isar/version.cfg"
> -	fi
>  	rm -rf ${S}/debian/fragments
>  	if [ -n "${src_frags}" ]; then
>  		mkdir -p ${S}/debian/fragments
>  		(cd ${WORKDIR} && cp ${src_frags}
> ${S}/debian/fragments/) fi
> -
> -	sudo -E chroot --userspec=$(id -u):$(id -g)
> ${BUILDCHROOT_DIR} sh -c " \
> -		export ARCH=${KERNEL_ARCH} &&
>           \
> -		cd ${PP}/${PPS} &&
>           \
> -		make O=${KERNEL_BUILD_DIR} ${config_target} &&
>           \
> -		./scripts/kconfig/merge_config.sh
>           \
> -			-O ${KERNEL_BUILD_DIR}/
>           \
> -			${KERNEL_BUILD_DIR}/.config
>           \
> -			${out_frags}
>           \
> -        "
>  }
>  
>  dpkg_runbuild_prepend() {


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 6/9] optee-os-stm32mp15x: Do not use shell environment
  2022-02-22 12:29     ` Uladzimir Bely
@ 2022-02-23 14:01       ` Jan Kiszka
  0 siblings, 0 replies; 20+ messages in thread
From: Jan Kiszka @ 2022-02-23 14:01 UTC (permalink / raw)
  To: Uladzimir Bely, isar-users

On 22.02.22 13:29, Uladzimir Bely wrote:
> In the email from Tuesday, 22 February 2022 09:49:38 +03 user Jan Kiszka 
> wrote:
>> On 13.02.22 08:41, Uladzimir Bely wrote:
>>> Move export of TEE_IMPL_VERSION variable directly to debian/rules.
>>>
>>> This makes building process more Debian-like.
>>>
>>> Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
>>> ---
>>>
>>>  meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb | 5 ++++-
>>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
>>> b/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb index
>>> 0fa2005d..9c0efaf1 100644
>>> --- a/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
>>> +++ b/meta-isar/recipes-bsp/optee-os/optee-os-stm32mp15x_3.11.0.bb
>>> @@ -21,5 +21,8 @@ OPTEE_BINARIES = "tee-header_v2.stm32
>>> tee-pageable_v2.stm32 tee-pager_v2.stm32"> 
>>>  # Set version manually to PV, the tarball does not contain any hint.
>>>  # Alternative: pull from git and add git as build dependency.
>>>  dpkg_runbuild_prepend() {
>>>
>>> -    export TEE_IMPL_VERSION=${PV}
>>> +    cat << EOF >> ${S}/debian/rules
>>> +
>>> +export TEE_IMPL_VERSION=${PV}
>>> +EOF
>>>
>>>  }
>>
>> I think I commented on this anti-pattern elsewhere already: This can
>> lead to piled-up extra lines in the target file. Now that it's merged,
>> please fix up on top, e.g. using a sed rule that avoids duplicate
>> patching or appending to the unpack step.
>>
>> Please also check if you used it elsewhere in fix those spots accordingly.
>>
>> Jan
> 
> I tried to see the problem with line duplicates you are talking about and I 
> couldn't reproduce it. Any way to invalidate do_build (recipe modification, 
> manual task invalidation by bitbake, etc) makes ${S} to be renewed, so "old" 
> lines are not presented here. So, this kind of export appears only once.
> 

Generally, such artifacts come from unpack or patch, and every
stand-along call of do_dpkg_build can cause such aggregation. But you
are right, in this case the debian folder is copied in from clean
source, and we do not see an aggregation. But we may see it if the
underlying include once changes and uses a different way to feed in debian/.

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 9/9] linux-custom: Move cfg fragments applying to debian/rules
  2022-02-23 13:53   ` Henning Schild
@ 2022-02-24  9:09     ` Uladzimir Bely
  2022-02-24 12:36       ` Henning Schild
  0 siblings, 1 reply; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-24  9:09 UTC (permalink / raw)
  To: Henning Schild; +Cc: isar-users

In the email from Wednesday, 23 February 2022 16:53:03 +03 user Henning Schild 
wrote:
> I just ran into an issue with that not actually finding my config in
> WORKDIR and now trying to go the KBUILD_DEFCONFIG way
> 
> Am Sun, 13 Feb 2022 08:41:11 +0100
> 
> schrieb Uladzimir Bely <ubely@ilbers.de>:
> > Prepare linux fragments applying in Debian way.
> > 
> > This allows to avoid pre-build chroot call used for merging
> > kernel config file and custom config fragments. Also, shell exports
> > are not used anymore in favor of template files.
> > 
> > Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
> > ---
> > 
> >  .../linux/files/debian/isar/configure.tmpl    | 19 +++++++
> >  .../linux/files/debian/rules.tmpl             |  3 ++
> >  meta/recipes-kernel/linux/linux-custom.inc    | 53
> > 
> > ++++++++++++------- 3 files changed, 55 insertions(+), 20 deletions(-)
> > 
> >  create mode 100644
> > 
> > meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > 
> > diff --git
> > a/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl new file
> > mode 100644 index 00000000..83871baa --- /dev/null
> > +++ b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > @@ -0,0 +1,19 @@
> > +#!/bin/bash
> > +# Copyright (c) Mentor Graphics, a Siemens business, 2019
> > +# SPDX-License-Identifier: MIT
> > +
> > +# Load common stuff
> > +. ${S}/debian/isar/common || exit ${?}
> > +
> > +do_configure() {
> > +
> > +    # Process kernel config target and fragments
> > +    ${MAKE} O=${KERNEL_BUILD_DIR} ${KERNEL_CONFIG_TARGET} || exit
> > ${?}
> > +    ./scripts/kconfig/merge_config.sh -O ${KERNEL_BUILD_DIR}/ \
> > +    ${KERNEL_BUILD_DIR}/.config ${KERNEL_CONFIG_FRAGMENTS}
> > +
> > +    # Stop tracing
> > +    set +x
> > +}
> > +
> > +main configure ${*}
> > diff --git a/meta/recipes-kernel/linux/files/debian/rules.tmpl
> > b/meta/recipes-kernel/linux/files/debian/rules.tmpl index
> > 05a26fe2..a1166287 100755 ---
> > a/meta/recipes-kernel/linux/files/debian/rules.tmpl +++
> > b/meta/recipes-kernel/linux/files/debian/rules.tmpl @@ -22,6 +22,9 @@
> > 
> > isar_env=$(strip \ override_dh_auto_clean:
> >  	$(isar_env) && bash $(deb_top_dir)/isar/clean
> > 
> > +override_dh_auto_configure:
> > +	$(isar_env) && bash $(deb_top_dir)/isar/configure
> > +
> > 
> >  override_dh_auto_build:
> >  	$(isar_env) && bash $(deb_top_dir)/isar/build
> > 
> > diff --git a/meta/recipes-kernel/linux/linux-custom.inc
> > b/meta/recipes-kernel/linux/linux-custom.inc index 59d42c84..ea1abf76
> > 100644 --- a/meta/recipes-kernel/linux/linux-custom.inc
> > +++ b/meta/recipes-kernel/linux/linux-custom.inc
> > @@ -52,6 +52,7 @@ TEMPLATE_FILES += "                  \
> > 
> >      debian/isar/build.tmpl           \
> >      debian/isar/clean.tmpl           \
> >      debian/isar/common.tmpl          \
> > 
> > +    debian/isar/configure.tmpl       \
> > 
> >      debian/isar/install.tmpl         \
> >      debian/isar/version.cfg.tmpl     \
> >      debian/linux-image.postinst.tmpl \
> > 
> > @@ -71,6 +72,8 @@ TEMPLATE_VARS += "                \
> > 
> >      KERNEL_HEADERS_DEBIAN_DEPENDS \
> >      LINUX_VERSION_EXTENSION       \
> >      KERNEL_NAME_PROVIDED          \
> > 
> > +    KERNEL_CONFIG_TARGET          \
> > +    KERNEL_CONFIG_FRAGMENTS       \
> > 
> >  "
> >  
> >  inherit dpkg
> > 
> > @@ -146,41 +149,51 @@ do_prepare_build_prepend() {
> > 
> >  # build directory for our "full" kernel build
> >  KERNEL_BUILD_DIR = "build-full"
> > 
> > +def get_kernel_config_target(d):
> > +    kernel_defconfig = d.getVar('KERNEL_DEFCONFIG', True)
> > +
> > +    config_target = kernel_defconfig
> > +
> > +    if kernel_defconfig:
> > +        workdir=d.getVar('WORKDIR', True)
> 
> > +        if os.path.isfile(workdir + "/" + kernel_defconfig):
> Doing that at parse-time when assigning the variable
> KERNEL_CONFIG_TARGET can not work. Some task in the task chain might
> need to create that file first ... fetch/unpack/fiddle-with
> 
> Checking if the file exists at parse time seems very wrong. I guess
> this patch needs to be reverted and rewritten and i guess the test
> suite does not properly cover kernels custom defconfig
> 

Yes, you are right, this moment is wrong.

I guess, it can be fixed by passing KERNEL_CONFIG_TARGET to 'debian/*' by 
direct appending from the recipe task (instead of template way).

I'll try prepare a solution soon.

> This is how one can rebuild a debian kernel
> 
> KBUILD_DEPENDS += ",linux-config-${PV}"
> 
> KERNEL_DEFCONFIG="${P}.conf"
> 
> do_take_debian_config() {
>     xzcat
> ${BUILDCHROOT_DIR}/usr/src/linux-config-${PV}/config.${DISTRO_ARCH}_none_${
> DISTRO_ARCH}.xz > ${S}/${KERNEL_DEFCONFIG} }
> 
> addtask take_debian_config after do_install_builddeps before
> do_dpkg_build
> 
> Maybe that could be used for writing a kernel test recipe actually going the
> "olddefconfig" way in case we do not yet have one.
> 
> Henning
> 
> > +            config_target = "olddefconfig"
> > +        else:
> > +            config_target = "defconfig KBUILD_DEFCONFIG=" +
> > kernel_defconfig
> > +    else:
> > +        config_target = "defconfig"
> > +
> > +    return config_target
> > +
> > +KERNEL_CONFIG_TARGET = "${@get_kernel_config_target(d)}"
> > +
> > +def get_kernel_config_fragments(d):
> > +    src_frags = " ".join(config_fragments(d))
> > +    out_frags = " ".join(map(lambda frag: 'debian/fragments/' +
> > frag, config_fragments(d))) +
> > +    linux_version_extension = d.getVar('LINUX_VERSION_EXTENSION',
> > True)
> > +    if linux_version_extension:
> > +        out_frags += " debian/isar/version.cfg"
> > +
> > +    return out_frags
> > +
> > +KERNEL_CONFIG_FRAGMENTS = "${@get_kernel_config_fragments(d)}"
> > +
> > 
> >  dpkg_configure_kernel() {
> > 
> > -	config_target="${KERNEL_DEFCONFIG}"
> > 
> >  	rm -rf ${S}/${KERNEL_BUILD_DIR} && mkdir -p
> > 
> > ${S}/${KERNEL_BUILD_DIR} if [ -n "${KERNEL_DEFCONFIG}" ]; then
> > 
> >  		if [ -e "${WORKDIR}/${KERNEL_DEFCONFIG}" ]; then
> >  		
> >  			cp ${WORKDIR}/${KERNEL_DEFCONFIG}
> > 
> > ${S}/${KERNEL_BUILD_DIR}/.config
> > -			config_target="olddefconfig"
> > -		else
> > -			config_target="defconfig
> > KBUILD_DEFCONFIG=${KERNEL_DEFCONFIG}" fi
> > -	else
> > -		config_target="defconfig"
> > 
> >  	fi
> >  	
> >  	# copy config fragments over to the kernel tree
> >  	src_frags="${@ " ".join(config_fragments(d)) }"
> > 
> > -	out_frags="${@ " ".join(map(lambda frag: 'debian/fragments/'
> > + frag, config_fragments(d))) }"
> > -	if [ -n "${LINUX_VERSION_EXTENSION}" ]; then
> > -		out_frags="${out_frags} debian/isar/version.cfg"
> > -	fi
> > 
> >  	rm -rf ${S}/debian/fragments
> >  	if [ -n "${src_frags}" ]; then
> >  	
> >  		mkdir -p ${S}/debian/fragments
> >  		(cd ${WORKDIR} && cp ${src_frags}
> > 
> > ${S}/debian/fragments/) fi
> > -
> > -	sudo -E chroot --userspec=$(id -u):$(id -g)
> > ${BUILDCHROOT_DIR} sh -c " \
> > -		export ARCH=${KERNEL_ARCH} &&
> > 
> >           \
> > 
> > -		cd ${PP}/${PPS} &&
> > 
> >           \
> > 
> > -		make O=${KERNEL_BUILD_DIR} ${config_target} &&
> > 
> >           \
> > 
> > -		./scripts/kconfig/merge_config.sh
> > 
> >           \
> > 
> > -			-O ${KERNEL_BUILD_DIR}/
> > 
> >           \
> > 
> > -			${KERNEL_BUILD_DIR}/.config
> > 
> >           \
> > 
> > -			${out_frags}
> > 
> >           \
> > 
> > -        "
> > 
> >  }
> >  
> >  dpkg_runbuild_prepend() {


-- 
Uladzimir Bely




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 9/9] linux-custom: Move cfg fragments applying to debian/rules
  2022-02-24  9:09     ` Uladzimir Bely
@ 2022-02-24 12:36       ` Henning Schild
  2022-02-24 14:49         ` Uladzimir Bely
  0 siblings, 1 reply; 20+ messages in thread
From: Henning Schild @ 2022-02-24 12:36 UTC (permalink / raw)
  To: Uladzimir Bely; +Cc: isar-users

Am Thu, 24 Feb 2022 12:09:00 +0300
schrieb Uladzimir Bely <ubely@ilbers.de>:

> In the email from Wednesday, 23 February 2022 16:53:03 +03 user
> Henning Schild wrote:
> > I just ran into an issue with that not actually finding my config in
> > WORKDIR and now trying to go the KBUILD_DEFCONFIG way
> > 
> > Am Sun, 13 Feb 2022 08:41:11 +0100
> > 
> > schrieb Uladzimir Bely <ubely@ilbers.de>:  
> > > Prepare linux fragments applying in Debian way.
> > > 
> > > This allows to avoid pre-build chroot call used for merging
> > > kernel config file and custom config fragments. Also, shell
> > > exports are not used anymore in favor of template files.
> > > 
> > > Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
> > > ---
> > > 
> > >  .../linux/files/debian/isar/configure.tmpl    | 19 +++++++
> > >  .../linux/files/debian/rules.tmpl             |  3 ++
> > >  meta/recipes-kernel/linux/linux-custom.inc    | 53
> > > 
> > > ++++++++++++------- 3 files changed, 55 insertions(+), 20
> > > deletions(-)
> > > 
> > >  create mode 100644
> > > 
> > > meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > > 
> > > diff --git
> > > a/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > > b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl new
> > > file mode 100644 index 00000000..83871baa --- /dev/null
> > > +++ b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > > @@ -0,0 +1,19 @@
> > > +#!/bin/bash
> > > +# Copyright (c) Mentor Graphics, a Siemens business, 2019
> > > +# SPDX-License-Identifier: MIT
> > > +
> > > +# Load common stuff
> > > +. ${S}/debian/isar/common || exit ${?}
> > > +
> > > +do_configure() {
> > > +
> > > +    # Process kernel config target and fragments
> > > +    ${MAKE} O=${KERNEL_BUILD_DIR} ${KERNEL_CONFIG_TARGET} || exit
> > > ${?}
> > > +    ./scripts/kconfig/merge_config.sh -O ${KERNEL_BUILD_DIR}/ \
> > > +    ${KERNEL_BUILD_DIR}/.config ${KERNEL_CONFIG_FRAGMENTS}
> > > +
> > > +    # Stop tracing
> > > +    set +x
> > > +}
> > > +
> > > +main configure ${*}
> > > diff --git a/meta/recipes-kernel/linux/files/debian/rules.tmpl
> > > b/meta/recipes-kernel/linux/files/debian/rules.tmpl index
> > > 05a26fe2..a1166287 100755 ---
> > > a/meta/recipes-kernel/linux/files/debian/rules.tmpl +++
> > > b/meta/recipes-kernel/linux/files/debian/rules.tmpl @@ -22,6
> > > +22,9 @@
> > > 
> > > isar_env=$(strip \ override_dh_auto_clean:
> > >  	$(isar_env) && bash $(deb_top_dir)/isar/clean
> > > 
> > > +override_dh_auto_configure:
> > > +	$(isar_env) && bash $(deb_top_dir)/isar/configure
> > > +
> > > 
> > >  override_dh_auto_build:
> > >  	$(isar_env) && bash $(deb_top_dir)/isar/build
> > > 
> > > diff --git a/meta/recipes-kernel/linux/linux-custom.inc
> > > b/meta/recipes-kernel/linux/linux-custom.inc index
> > > 59d42c84..ea1abf76 100644 ---
> > > a/meta/recipes-kernel/linux/linux-custom.inc +++
> > > b/meta/recipes-kernel/linux/linux-custom.inc @@ -52,6 +52,7 @@
> > > TEMPLATE_FILES += "                  \
> > > 
> > >      debian/isar/build.tmpl           \
> > >      debian/isar/clean.tmpl           \
> > >      debian/isar/common.tmpl          \
> > > 
> > > +    debian/isar/configure.tmpl       \
> > > 
> > >      debian/isar/install.tmpl         \
> > >      debian/isar/version.cfg.tmpl     \
> > >      debian/linux-image.postinst.tmpl \
> > > 
> > > @@ -71,6 +72,8 @@ TEMPLATE_VARS += "                \
> > > 
> > >      KERNEL_HEADERS_DEBIAN_DEPENDS \
> > >      LINUX_VERSION_EXTENSION       \
> > >      KERNEL_NAME_PROVIDED          \
> > > 
> > > +    KERNEL_CONFIG_TARGET          \
> > > +    KERNEL_CONFIG_FRAGMENTS       \
> > > 
> > >  "
> > >  
> > >  inherit dpkg
> > > 
> > > @@ -146,41 +149,51 @@ do_prepare_build_prepend() {
> > > 
> > >  # build directory for our "full" kernel build
> > >  KERNEL_BUILD_DIR = "build-full"
> > > 
> > > +def get_kernel_config_target(d):
> > > +    kernel_defconfig = d.getVar('KERNEL_DEFCONFIG', True)
> > > +
> > > +    config_target = kernel_defconfig
> > > +
> > > +    if kernel_defconfig:
> > > +        workdir=d.getVar('WORKDIR', True)  
> >   
> > > +        if os.path.isfile(workdir + "/" + kernel_defconfig):  
> > Doing that at parse-time when assigning the variable
> > KERNEL_CONFIG_TARGET can not work. Some task in the task chain might
> > need to create that file first ... fetch/unpack/fiddle-with
> > 
> > Checking if the file exists at parse time seems very wrong. I guess
> > this patch needs to be reverted and rewritten and i guess the test
> > suite does not properly cover kernels custom defconfig
> >   
> 
> Yes, you are right, this moment is wrong.
> 
> I guess, it can be fixed by passing KERNEL_CONFIG_TARGET to
> 'debian/*' by direct appending from the recipe task (instead of
> template way).
> 
> I'll try prepare a solution soon.

Cool,

i would even suggest a revert because that breaks kernel builds in
layers. I reverted just that one and my layer worked again.

I will look into writing a patch to the testsuite, covering the
olddefconfig path.

Henning

> > This is how one can rebuild a debian kernel
> > 
> > KBUILD_DEPENDS += ",linux-config-${PV}"
> > 
> > KERNEL_DEFCONFIG="${P}.conf"
> > 
> > do_take_debian_config() {
> >     xzcat
> > ${BUILDCHROOT_DIR}/usr/src/linux-config-${PV}/config.${DISTRO_ARCH}_none_${
> > DISTRO_ARCH}.xz > ${S}/${KERNEL_DEFCONFIG} }
> > 
> > addtask take_debian_config after do_install_builddeps before
> > do_dpkg_build
> > 
> > Maybe that could be used for writing a kernel test recipe actually
> > going the "olddefconfig" way in case we do not yet have one.
> > 
> > Henning
> >   
> > > +            config_target = "olddefconfig"
> > > +        else:
> > > +            config_target = "defconfig KBUILD_DEFCONFIG=" +
> > > kernel_defconfig
> > > +    else:
> > > +        config_target = "defconfig"
> > > +
> > > +    return config_target
> > > +
> > > +KERNEL_CONFIG_TARGET = "${@get_kernel_config_target(d)}"
> > > +
> > > +def get_kernel_config_fragments(d):
> > > +    src_frags = " ".join(config_fragments(d))
> > > +    out_frags = " ".join(map(lambda frag: 'debian/fragments/' +
> > > frag, config_fragments(d))) +
> > > +    linux_version_extension = d.getVar('LINUX_VERSION_EXTENSION',
> > > True)
> > > +    if linux_version_extension:
> > > +        out_frags += " debian/isar/version.cfg"
> > > +
> > > +    return out_frags
> > > +
> > > +KERNEL_CONFIG_FRAGMENTS = "${@get_kernel_config_fragments(d)}"
> > > +
> > > 
> > >  dpkg_configure_kernel() {
> > > 
> > > -	config_target="${KERNEL_DEFCONFIG}"
> > > 
> > >  	rm -rf ${S}/${KERNEL_BUILD_DIR} && mkdir -p
> > > 
> > > ${S}/${KERNEL_BUILD_DIR} if [ -n "${KERNEL_DEFCONFIG}" ]; then
> > > 
> > >  		if [ -e "${WORKDIR}/${KERNEL_DEFCONFIG}" ]; then
> > >  		
> > >  			cp ${WORKDIR}/${KERNEL_DEFCONFIG}
> > > 
> > > ${S}/${KERNEL_BUILD_DIR}/.config
> > > -			config_target="olddefconfig"
> > > -		else
> > > -			config_target="defconfig
> > > KBUILD_DEFCONFIG=${KERNEL_DEFCONFIG}" fi
> > > -	else
> > > -		config_target="defconfig"
> > > 
> > >  	fi
> > >  	
> > >  	# copy config fragments over to the kernel tree
> > >  	src_frags="${@ " ".join(config_fragments(d)) }"
> > > 
> > > -	out_frags="${@ " ".join(map(lambda frag:
> > > 'debian/fragments/'
> > > + frag, config_fragments(d))) }"
> > > -	if [ -n "${LINUX_VERSION_EXTENSION}" ]; then
> > > -		out_frags="${out_frags} debian/isar/version.cfg"
> > > -	fi
> > > 
> > >  	rm -rf ${S}/debian/fragments
> > >  	if [ -n "${src_frags}" ]; then
> > >  	
> > >  		mkdir -p ${S}/debian/fragments
> > >  		(cd ${WORKDIR} && cp ${src_frags}
> > > 
> > > ${S}/debian/fragments/) fi
> > > -
> > > -	sudo -E chroot --userspec=$(id -u):$(id -g)
> > > ${BUILDCHROOT_DIR} sh -c " \
> > > -		export ARCH=${KERNEL_ARCH} &&
> > > 
> > >           \
> > > 
> > > -		cd ${PP}/${PPS} &&
> > > 
> > >           \
> > > 
> > > -		make O=${KERNEL_BUILD_DIR} ${config_target} &&
> > > 
> > >           \
> > > 
> > > -		./scripts/kconfig/merge_config.sh
> > > 
> > >           \
> > > 
> > > -			-O ${KERNEL_BUILD_DIR}/
> > > 
> > >           \
> > > 
> > > -			${KERNEL_BUILD_DIR}/.config
> > > 
> > >           \
> > > 
> > > -			${out_frags}
> > > 
> > >           \
> > > 
> > > -        "
> > > 
> > >  }
> > >  
> > >  dpkg_runbuild_prepend() {  
> 
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 9/9] linux-custom: Move cfg fragments applying to debian/rules
  2022-02-24 12:36       ` Henning Schild
@ 2022-02-24 14:49         ` Uladzimir Bely
  2022-02-24 19:53           ` Henning Schild
  0 siblings, 1 reply; 20+ messages in thread
From: Uladzimir Bely @ 2022-02-24 14:49 UTC (permalink / raw)
  To: Henning Schild; +Cc: isar-users

In the email from Thursday, 24 February 2022 15:36:57 +03 user Henning Schild 
wrote:
> Am Thu, 24 Feb 2022 12:09:00 +0300
> 
> schrieb Uladzimir Bely <ubely@ilbers.de>:
> > In the email from Wednesday, 23 February 2022 16:53:03 +03 user
> > 
> > Henning Schild wrote:
> > > I just ran into an issue with that not actually finding my config in
> > > WORKDIR and now trying to go the KBUILD_DEFCONFIG way
> > > 
> > > Am Sun, 13 Feb 2022 08:41:11 +0100
> > > 
> > > schrieb Uladzimir Bely <ubely@ilbers.de>:
> > > > Prepare linux fragments applying in Debian way.
> > > > 
> > > > This allows to avoid pre-build chroot call used for merging
> > > > kernel config file and custom config fragments. Also, shell
> > > > exports are not used anymore in favor of template files.
> > > > 
> > > > Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
> > > > ---
> > > > 
> > > >  .../linux/files/debian/isar/configure.tmpl    | 19 +++++++
> > > >  .../linux/files/debian/rules.tmpl             |  3 ++
> > > >  meta/recipes-kernel/linux/linux-custom.inc    | 53
> > > > 
> > > > ++++++++++++------- 3 files changed, 55 insertions(+), 20
> > > > deletions(-)
> > > > 
> > > >  create mode 100644
> > > > 
> > > > meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > > > 
> > > > diff --git
> > > > a/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > > > b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl new
> > > > file mode 100644 index 00000000..83871baa --- /dev/null
> > > > +++ b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > > > @@ -0,0 +1,19 @@
> > > > +#!/bin/bash
> > > > +# Copyright (c) Mentor Graphics, a Siemens business, 2019
> > > > +# SPDX-License-Identifier: MIT
> > > > +
> > > > +# Load common stuff
> > > > +. ${S}/debian/isar/common || exit ${?}
> > > > +
> > > > +do_configure() {
> > > > +
> > > > +    # Process kernel config target and fragments
> > > > +    ${MAKE} O=${KERNEL_BUILD_DIR} ${KERNEL_CONFIG_TARGET} || exit
> > > > ${?}
> > > > +    ./scripts/kconfig/merge_config.sh -O ${KERNEL_BUILD_DIR}/ \
> > > > +    ${KERNEL_BUILD_DIR}/.config ${KERNEL_CONFIG_FRAGMENTS}
> > > > +
> > > > +    # Stop tracing
> > > > +    set +x
> > > > +}
> > > > +
> > > > +main configure ${*}
> > > > diff --git a/meta/recipes-kernel/linux/files/debian/rules.tmpl
> > > > b/meta/recipes-kernel/linux/files/debian/rules.tmpl index
> > > > 05a26fe2..a1166287 100755 ---
> > > > a/meta/recipes-kernel/linux/files/debian/rules.tmpl +++
> > > > b/meta/recipes-kernel/linux/files/debian/rules.tmpl @@ -22,6
> > > > +22,9 @@
> > > > 
> > > > isar_env=$(strip \ override_dh_auto_clean:
> > > >  	$(isar_env) && bash $(deb_top_dir)/isar/clean
> > > > 
> > > > +override_dh_auto_configure:
> > > > +	$(isar_env) && bash $(deb_top_dir)/isar/configure
> > > > +
> > > > 
> > > >  override_dh_auto_build:
> > > >  	$(isar_env) && bash $(deb_top_dir)/isar/build
> > > > 
> > > > diff --git a/meta/recipes-kernel/linux/linux-custom.inc
> > > > b/meta/recipes-kernel/linux/linux-custom.inc index
> > > > 59d42c84..ea1abf76 100644 ---
> > > > a/meta/recipes-kernel/linux/linux-custom.inc +++
> > > > b/meta/recipes-kernel/linux/linux-custom.inc @@ -52,6 +52,7 @@
> > > > TEMPLATE_FILES += "                  \
> > > > 
> > > >      debian/isar/build.tmpl           \
> > > >      debian/isar/clean.tmpl           \
> > > >      debian/isar/common.tmpl          \
> > > > 
> > > > +    debian/isar/configure.tmpl       \
> > > > 
> > > >      debian/isar/install.tmpl         \
> > > >      debian/isar/version.cfg.tmpl     \
> > > >      debian/linux-image.postinst.tmpl \
> > > > 
> > > > @@ -71,6 +72,8 @@ TEMPLATE_VARS += "                \
> > > > 
> > > >      KERNEL_HEADERS_DEBIAN_DEPENDS \
> > > >      LINUX_VERSION_EXTENSION       \
> > > >      KERNEL_NAME_PROVIDED          \
> > > > 
> > > > +    KERNEL_CONFIG_TARGET          \
> > > > +    KERNEL_CONFIG_FRAGMENTS       \
> > > > 
> > > >  "
> > > >  
> > > >  inherit dpkg
> > > > 
> > > > @@ -146,41 +149,51 @@ do_prepare_build_prepend() {
> > > > 
> > > >  # build directory for our "full" kernel build
> > > >  KERNEL_BUILD_DIR = "build-full"
> > > > 
> > > > +def get_kernel_config_target(d):
> > > > +    kernel_defconfig = d.getVar('KERNEL_DEFCONFIG', True)
> > > > +
> > > > +    config_target = kernel_defconfig
> > > > +
> > > > +    if kernel_defconfig:
> > > > +        workdir=d.getVar('WORKDIR', True)
> > > 
> > > > +        if os.path.isfile(workdir + "/" + kernel_defconfig):
> > > Doing that at parse-time when assigning the variable
> > > KERNEL_CONFIG_TARGET can not work. Some task in the task chain might
> > > need to create that file first ... fetch/unpack/fiddle-with
> > > 
> > > Checking if the file exists at parse time seems very wrong. I guess
> > > this patch needs to be reverted and rewritten and i guess the test
> > > suite does not properly cover kernels custom defconfig
> > 
> > Yes, you are right, this moment is wrong.
> > 
> > I guess, it can be fixed by passing KERNEL_CONFIG_TARGET to
> > 'debian/*' by direct appending from the recipe task (instead of
> > template way).
> > 
> > I'll try prepare a solution soon.
> 
> Cool,
> 
> i would even suggest a revert because that breaks kernel builds in
> layers. I reverted just that one and my layer worked again.
> 
> I will look into writing a patch to the testsuite, covering the
> olddefconfig path.
> 
> Henning
> 

Please look at "linux-custom: Set KERNEL_CONFIG_TARGET at build time" patch 
that should solve the issue you've described.

While we have custom configs only for amd64 machines, but we have no in Isar 
amd64 machine with linux-mainline (or linux-cip) that define some custom 
config file in workdir, I just tested it on bullseye-amd64 with separate 
buildi linux-mainline by bitbake.

It seems now it works and properly detects and uses x86_64_defconfig in 
workdir, while the stuff is moved to dpkg_configure_kernel() which technically 
is a part of dpkg_runbuild.

> > > This is how one can rebuild a debian kernel
> > > 
> > > KBUILD_DEPENDS += ",linux-config-${PV}"
> > > 
> > > KERNEL_DEFCONFIG="${P}.conf"
> > > 
> > > do_take_debian_config() {
> > > 
> > >     xzcat
> > > 
> > > ${BUILDCHROOT_DIR}/usr/src/linux-config-${PV}/config.${DISTRO_ARCH}_none
> > > _${
> > > DISTRO_ARCH}.xz > ${S}/${KERNEL_DEFCONFIG} }
> > > 
> > > addtask take_debian_config after do_install_builddeps before
> > > do_dpkg_build
> > > 
> > > Maybe that could be used for writing a kernel test recipe actually
> > > going the "olddefconfig" way in case we do not yet have one.
> > > 
> > > Henning
> > > 
> > > > +            config_target = "olddefconfig"
> > > > +        else:
> > > > +            config_target = "defconfig KBUILD_DEFCONFIG=" +
> > > > kernel_defconfig
> > > > +    else:
> > > > +        config_target = "defconfig"
> > > > +
> > > > +    return config_target
> > > > +
> > > > +KERNEL_CONFIG_TARGET = "${@get_kernel_config_target(d)}"
> > > > +
> > > > +def get_kernel_config_fragments(d):
> > > > +    src_frags = " ".join(config_fragments(d))
> > > > +    out_frags = " ".join(map(lambda frag: 'debian/fragments/' +
> > > > frag, config_fragments(d))) +
> > > > +    linux_version_extension = d.getVar('LINUX_VERSION_EXTENSION',
> > > > True)
> > > > +    if linux_version_extension:
> > > > +        out_frags += " debian/isar/version.cfg"
> > > > +
> > > > +    return out_frags
> > > > +
> > > > +KERNEL_CONFIG_FRAGMENTS = "${@get_kernel_config_fragments(d)}"
> > > > +
> > > > 
> > > >  dpkg_configure_kernel() {
> > > > 
> > > > -	config_target="${KERNEL_DEFCONFIG}"
> > > > 
> > > >  	rm -rf ${S}/${KERNEL_BUILD_DIR} && mkdir -p
> > > > 
> > > > ${S}/${KERNEL_BUILD_DIR} if [ -n "${KERNEL_DEFCONFIG}" ]; then
> > > > 
> > > >  		if [ -e "${WORKDIR}/${KERNEL_DEFCONFIG}" ]; then
> > > >  		
> > > >  			cp ${WORKDIR}/${KERNEL_DEFCONFIG}
> > > > 
> > > > ${S}/${KERNEL_BUILD_DIR}/.config
> > > > -			config_target="olddefconfig"
> > > > -		else
> > > > -			config_target="defconfig
> > > > KBUILD_DEFCONFIG=${KERNEL_DEFCONFIG}" fi
> > > > -	else
> > > > -		config_target="defconfig"
> > > > 
> > > >  	fi
> > > >  	
> > > >  	# copy config fragments over to the kernel tree
> > > >  	src_frags="${@ " ".join(config_fragments(d)) }"
> > > > 
> > > > -	out_frags="${@ " ".join(map(lambda frag:
> > > > 'debian/fragments/'
> > > > + frag, config_fragments(d))) }"
> > > > -	if [ -n "${LINUX_VERSION_EXTENSION}" ]; then
> > > > -		out_frags="${out_frags} debian/isar/version.cfg"
> > > > -	fi
> > > > 
> > > >  	rm -rf ${S}/debian/fragments
> > > >  	if [ -n "${src_frags}" ]; then
> > > >  	
> > > >  		mkdir -p ${S}/debian/fragments
> > > >  		(cd ${WORKDIR} && cp ${src_frags}
> > > > 
> > > > ${S}/debian/fragments/) fi
> > > > -
> > > > -	sudo -E chroot --userspec=$(id -u):$(id -g)
> > > > ${BUILDCHROOT_DIR} sh -c " \
> > > > -		export ARCH=${KERNEL_ARCH} &&
> > > > 
> > > >           \
> > > > 
> > > > -		cd ${PP}/${PPS} &&
> > > > 
> > > >           \
> > > > 
> > > > -		make O=${KERNEL_BUILD_DIR} ${config_target} &&
> > > > 
> > > >           \
> > > > 
> > > > -		./scripts/kconfig/merge_config.sh
> > > > 
> > > >           \
> > > > 
> > > > -			-O ${KERNEL_BUILD_DIR}/
> > > > 
> > > >           \
> > > > 
> > > > -			${KERNEL_BUILD_DIR}/.config
> > > > 
> > > >           \
> > > > 
> > > > -			${out_frags}
> > > > 
> > > >           \
> > > > 
> > > > -        "
> > > > 
> > > >  }
> > > >  
> > > >  dpkg_runbuild_prepend() {


-- 
Uladzimir Bely




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 9/9] linux-custom: Move cfg fragments applying to debian/rules
  2022-02-24 14:49         ` Uladzimir Bely
@ 2022-02-24 19:53           ` Henning Schild
  0 siblings, 0 replies; 20+ messages in thread
From: Henning Schild @ 2022-02-24 19:53 UTC (permalink / raw)
  To: Uladzimir Bely; +Cc: isar-users

Am Thu, 24 Feb 2022 17:49:17 +0300
schrieb Uladzimir Bely <ubely@ilbers.de>:

> In the email from Thursday, 24 February 2022 15:36:57 +03 user
> Henning Schild wrote:
> > Am Thu, 24 Feb 2022 12:09:00 +0300
> > 
> > schrieb Uladzimir Bely <ubely@ilbers.de>:  
> > > In the email from Wednesday, 23 February 2022 16:53:03 +03 user
> > > 
> > > Henning Schild wrote:  
> > > > I just ran into an issue with that not actually finding my
> > > > config in WORKDIR and now trying to go the KBUILD_DEFCONFIG way
> > > > 
> > > > Am Sun, 13 Feb 2022 08:41:11 +0100
> > > > 
> > > > schrieb Uladzimir Bely <ubely@ilbers.de>:  
> > > > > Prepare linux fragments applying in Debian way.
> > > > > 
> > > > > This allows to avoid pre-build chroot call used for merging
> > > > > kernel config file and custom config fragments. Also, shell
> > > > > exports are not used anymore in favor of template files.
> > > > > 
> > > > > Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
> > > > > ---
> > > > > 
> > > > >  .../linux/files/debian/isar/configure.tmpl    | 19 +++++++
> > > > >  .../linux/files/debian/rules.tmpl             |  3 ++
> > > > >  meta/recipes-kernel/linux/linux-custom.inc    | 53
> > > > > 
> > > > > ++++++++++++------- 3 files changed, 55 insertions(+), 20
> > > > > deletions(-)
> > > > > 
> > > > >  create mode 100644
> > > > > 
> > > > > meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > > > > 
> > > > > diff --git
> > > > > a/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > > > > b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > > > > new file mode 100644 index 00000000..83871baa --- /dev/null
> > > > > +++
> > > > > b/meta/recipes-kernel/linux/files/debian/isar/configure.tmpl
> > > > > @@ -0,0 +1,19 @@ +#!/bin/bash
> > > > > +# Copyright (c) Mentor Graphics, a Siemens business, 2019
> > > > > +# SPDX-License-Identifier: MIT
> > > > > +
> > > > > +# Load common stuff
> > > > > +. ${S}/debian/isar/common || exit ${?}
> > > > > +
> > > > > +do_configure() {
> > > > > +
> > > > > +    # Process kernel config target and fragments
> > > > > +    ${MAKE} O=${KERNEL_BUILD_DIR} ${KERNEL_CONFIG_TARGET} ||
> > > > > exit ${?}
> > > > > +    ./scripts/kconfig/merge_config.sh -O
> > > > > ${KERNEL_BUILD_DIR}/ \
> > > > > +    ${KERNEL_BUILD_DIR}/.config ${KERNEL_CONFIG_FRAGMENTS}
> > > > > +
> > > > > +    # Stop tracing
> > > > > +    set +x
> > > > > +}
> > > > > +
> > > > > +main configure ${*}
> > > > > diff --git a/meta/recipes-kernel/linux/files/debian/rules.tmpl
> > > > > b/meta/recipes-kernel/linux/files/debian/rules.tmpl index
> > > > > 05a26fe2..a1166287 100755 ---
> > > > > a/meta/recipes-kernel/linux/files/debian/rules.tmpl +++
> > > > > b/meta/recipes-kernel/linux/files/debian/rules.tmpl @@ -22,6
> > > > > +22,9 @@
> > > > > 
> > > > > isar_env=$(strip \ override_dh_auto_clean:
> > > > >  	$(isar_env) && bash $(deb_top_dir)/isar/clean
> > > > > 
> > > > > +override_dh_auto_configure:
> > > > > +	$(isar_env) && bash $(deb_top_dir)/isar/configure
> > > > > +
> > > > > 
> > > > >  override_dh_auto_build:
> > > > >  	$(isar_env) && bash $(deb_top_dir)/isar/build
> > > > > 
> > > > > diff --git a/meta/recipes-kernel/linux/linux-custom.inc
> > > > > b/meta/recipes-kernel/linux/linux-custom.inc index
> > > > > 59d42c84..ea1abf76 100644 ---
> > > > > a/meta/recipes-kernel/linux/linux-custom.inc +++
> > > > > b/meta/recipes-kernel/linux/linux-custom.inc @@ -52,6 +52,7 @@
> > > > > TEMPLATE_FILES += "                  \
> > > > > 
> > > > >      debian/isar/build.tmpl           \
> > > > >      debian/isar/clean.tmpl           \
> > > > >      debian/isar/common.tmpl          \
> > > > > 
> > > > > +    debian/isar/configure.tmpl       \
> > > > > 
> > > > >      debian/isar/install.tmpl         \
> > > > >      debian/isar/version.cfg.tmpl     \
> > > > >      debian/linux-image.postinst.tmpl \
> > > > > 
> > > > > @@ -71,6 +72,8 @@ TEMPLATE_VARS += "                \
> > > > > 
> > > > >      KERNEL_HEADERS_DEBIAN_DEPENDS \
> > > > >      LINUX_VERSION_EXTENSION       \
> > > > >      KERNEL_NAME_PROVIDED          \
> > > > > 
> > > > > +    KERNEL_CONFIG_TARGET          \
> > > > > +    KERNEL_CONFIG_FRAGMENTS       \
> > > > > 
> > > > >  "
> > > > >  
> > > > >  inherit dpkg
> > > > > 
> > > > > @@ -146,41 +149,51 @@ do_prepare_build_prepend() {
> > > > > 
> > > > >  # build directory for our "full" kernel build
> > > > >  KERNEL_BUILD_DIR = "build-full"
> > > > > 
> > > > > +def get_kernel_config_target(d):
> > > > > +    kernel_defconfig = d.getVar('KERNEL_DEFCONFIG', True)
> > > > > +
> > > > > +    config_target = kernel_defconfig
> > > > > +
> > > > > +    if kernel_defconfig:
> > > > > +        workdir=d.getVar('WORKDIR', True)  
> > > >   
> > > > > +        if os.path.isfile(workdir + "/" + kernel_defconfig):
> > > > >  
> > > > Doing that at parse-time when assigning the variable
> > > > KERNEL_CONFIG_TARGET can not work. Some task in the task chain
> > > > might need to create that file first ...
> > > > fetch/unpack/fiddle-with
> > > > 
> > > > Checking if the file exists at parse time seems very wrong. I
> > > > guess this patch needs to be reverted and rewritten and i guess
> > > > the test suite does not properly cover kernels custom defconfig
> > > >  
> > > 
> > > Yes, you are right, this moment is wrong.
> > > 
> > > I guess, it can be fixed by passing KERNEL_CONFIG_TARGET to
> > > 'debian/*' by direct appending from the recipe task (instead of
> > > template way).
> > > 
> > > I'll try prepare a solution soon.  
> > 
> > Cool,
> > 
> > i would even suggest a revert because that breaks kernel builds in
> > layers. I reverted just that one and my layer worked again.
> > 
> > I will look into writing a patch to the testsuite, covering the
> > olddefconfig path.
> > 
> > Henning
> >   
> 
> Please look at "linux-custom: Set KERNEL_CONFIG_TARGET at build time"
> patch that should solve the issue you've described.
> 
> While we have custom configs only for amd64 machines, but we have no
> in Isar amd64 machine with linux-mainline (or linux-cip) that define
> some custom config file in workdir, I just tested it on
> bullseye-amd64 with separate buildi linux-mainline by bitbake.
> 
> It seems now it works and properly detects and uses x86_64_defconfig
> in workdir, while the stuff is moved to dpkg_configure_kernel() which
> technically is a part of dpkg_runbuild.

I failed to write a patch to test the "olddefconfig" path based on
mainline and cip. These recipes for some reason are not affected, i
guess that python function got executed multiple times.
Probably once before the template stuff kicks in.

One more thing i found is that they use "x86_64_defconfig" as a file
name, which unfortunately also is a valid "make target" which would
just work with no ".config" and not use our custom config.

But that turned out to not be a problem.

I bet there is room for better testing but i currently do not have an
idea on how to do that.

Let me think about it and i might come around with a patch, for now it
seems good and quick turn arounds on layer testing and next fixing seem
to work well. There is only so much that upstream can and should test.

Henning

> > > > This is how one can rebuild a debian kernel
> > > > 
> > > > KBUILD_DEPENDS += ",linux-config-${PV}"
> > > > 
> > > > KERNEL_DEFCONFIG="${P}.conf"
> > > > 
> > > > do_take_debian_config() {
> > > > 
> > > >     xzcat
> > > > 
> > > > ${BUILDCHROOT_DIR}/usr/src/linux-config-${PV}/config.${DISTRO_ARCH}_none
> > > > _${
> > > > DISTRO_ARCH}.xz > ${S}/${KERNEL_DEFCONFIG} }
> > > > 
> > > > addtask take_debian_config after do_install_builddeps before
> > > > do_dpkg_build
> > > > 
> > > > Maybe that could be used for writing a kernel test recipe
> > > > actually going the "olddefconfig" way in case we do not yet
> > > > have one.
> > > > 
> > > > Henning
> > > >   
> > > > > +            config_target = "olddefconfig"
> > > > > +        else:
> > > > > +            config_target = "defconfig KBUILD_DEFCONFIG=" +
> > > > > kernel_defconfig
> > > > > +    else:
> > > > > +        config_target = "defconfig"
> > > > > +
> > > > > +    return config_target
> > > > > +
> > > > > +KERNEL_CONFIG_TARGET = "${@get_kernel_config_target(d)}"
> > > > > +
> > > > > +def get_kernel_config_fragments(d):
> > > > > +    src_frags = " ".join(config_fragments(d))
> > > > > +    out_frags = " ".join(map(lambda frag:
> > > > > 'debian/fragments/' + frag, config_fragments(d))) +
> > > > > +    linux_version_extension =
> > > > > d.getVar('LINUX_VERSION_EXTENSION', True)
> > > > > +    if linux_version_extension:
> > > > > +        out_frags += " debian/isar/version.cfg"
> > > > > +
> > > > > +    return out_frags
> > > > > +
> > > > > +KERNEL_CONFIG_FRAGMENTS =
> > > > > "${@get_kernel_config_fragments(d)}" +
> > > > > 
> > > > >  dpkg_configure_kernel() {
> > > > > 
> > > > > -	config_target="${KERNEL_DEFCONFIG}"
> > > > > 
> > > > >  	rm -rf ${S}/${KERNEL_BUILD_DIR} && mkdir -p
> > > > > 
> > > > > ${S}/${KERNEL_BUILD_DIR} if [ -n "${KERNEL_DEFCONFIG}" ]; then
> > > > > 
> > > > >  		if [ -e "${WORKDIR}/${KERNEL_DEFCONFIG}" ];
> > > > > then 
> > > > >  			cp ${WORKDIR}/${KERNEL_DEFCONFIG}
> > > > > 
> > > > > ${S}/${KERNEL_BUILD_DIR}/.config
> > > > > -			config_target="olddefconfig"
> > > > > -		else
> > > > > -			config_target="defconfig
> > > > > KBUILD_DEFCONFIG=${KERNEL_DEFCONFIG}" fi
> > > > > -	else
> > > > > -		config_target="defconfig"
> > > > > 
> > > > >  	fi
> > > > >  	
> > > > >  	# copy config fragments over to the kernel tree
> > > > >  	src_frags="${@ " ".join(config_fragments(d)) }"
> > > > > 
> > > > > -	out_frags="${@ " ".join(map(lambda frag:
> > > > > 'debian/fragments/'
> > > > > + frag, config_fragments(d))) }"
> > > > > -	if [ -n "${LINUX_VERSION_EXTENSION}" ]; then
> > > > > -		out_frags="${out_frags}
> > > > > debian/isar/version.cfg"
> > > > > -	fi
> > > > > 
> > > > >  	rm -rf ${S}/debian/fragments
> > > > >  	if [ -n "${src_frags}" ]; then
> > > > >  	
> > > > >  		mkdir -p ${S}/debian/fragments
> > > > >  		(cd ${WORKDIR} && cp ${src_frags}
> > > > > 
> > > > > ${S}/debian/fragments/) fi
> > > > > -
> > > > > -	sudo -E chroot --userspec=$(id -u):$(id -g)
> > > > > ${BUILDCHROOT_DIR} sh -c " \
> > > > > -		export ARCH=${KERNEL_ARCH} &&
> > > > > 
> > > > >           \
> > > > > 
> > > > > -		cd ${PP}/${PPS} &&
> > > > > 
> > > > >           \
> > > > > 
> > > > > -		make O=${KERNEL_BUILD_DIR} ${config_target}
> > > > > &&
> > > > > 
> > > > >           \
> > > > > 
> > > > > -		./scripts/kconfig/merge_config.sh
> > > > > 
> > > > >           \
> > > > > 
> > > > > -			-O ${KERNEL_BUILD_DIR}/
> > > > > 
> > > > >           \
> > > > > 
> > > > > -			${KERNEL_BUILD_DIR}/.config
> > > > > 
> > > > >           \
> > > > > 
> > > > > -			${out_frags}
> > > > > 
> > > > >           \
> > > > > 
> > > > > -        "
> > > > > 
> > > > >  }
> > > > >  
> > > > >  dpkg_runbuild_prepend() {  
> 
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-02-24 19:53 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-13  7:41 [PATCH v5 0/9] Avoid using shell environment during the build Uladzimir Bely
2022-02-13  7:41 ` [PATCH v5 1/9] template: Copy template attributes on transform Uladzimir Bely
2022-02-13  7:41 ` [PATCH v5 2/9] linux-module: Do not use shell environment Uladzimir Bely
2022-02-13  7:41 ` [PATCH v5 3/9] u-boot: " Uladzimir Bely
2022-02-13  7:41 ` [PATCH v5 4/9] trusted-firmware: " Uladzimir Bely
2022-02-13  7:41 ` [PATCH v5 5/9] optee-os: " Uladzimir Bely
2022-02-13  7:41 ` [PATCH v5 6/9] optee-os-stm32mp15x: " Uladzimir Bely
2022-02-22  6:49   ` Jan Kiszka
2022-02-22 12:29     ` Uladzimir Bely
2022-02-23 14:01       ` Jan Kiszka
2022-02-13  7:41 ` [PATCH v5 7/9] kselftest: " Uladzimir Bely
2022-02-13  7:41 ` [PATCH v5 8/9] linux-mainline: Move cfg fragment test to debian/rules Uladzimir Bely
2022-02-22  6:50   ` Jan Kiszka
2022-02-13  7:41 ` [PATCH v5 9/9] linux-custom: Move cfg fragments applying " Uladzimir Bely
2022-02-23 13:53   ` Henning Schild
2022-02-24  9:09     ` Uladzimir Bely
2022-02-24 12:36       ` Henning Schild
2022-02-24 14:49         ` Uladzimir Bely
2022-02-24 19:53           ` Henning Schild
2022-02-22  6:39 ` [PATCH v5 0/9] Avoid using shell environment during the build Anton Mikanovich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox