[PATCH v2 0/3] Deploy DTBs with separate recipe

10 views
Skip to first unread message

Uladzimir Bely

unread,
Jul 12, 2024, 1:43:36 AMJul 12
to isar-...@googlegroups.com
Image task "do_copy_boot_files" is used to deploy kernel, initrd and
devicetree binaries to deploy directory.

When different images for the same target are built (e.g., "-base" and
"-debug") in parallel, this causes issues with DTB deployment since
they have no any image_name-specific stuff in the path, unlike kernel
and initrd.

Here we make a separate recipe responcible for DTB deployment. DTBs are
extracted from a kernel package (provided by distro or self-built).

First (RFC) version of the patchset directly used linux recipes for
this, but such approach still had "multiple execution" issues in case
the same linux recipe was used by different machines. This required
per-machine linux build splitting that increases build time and brings
some other problems (e.g. with kernel modules dependencies).

The recipe 'dtb-files' is MACHINE-dependent, so different DTB_FILES
may be deployed for different machines. At the same time, all these
'dtb-files-${MACHINE}' targets depend on the same kernel package, so
it's built only once.

The case when different distros (e.g., bullseye/bookworm) use the same
name for DTB binaries is covered by a separate patch.

Related topics on maillist:

https://groups.google.com/g/isar-users/c/ht3YmKZcJlM
https://groups.google.com/g/isar-users/c/4BRDM02xC40
https://groups.google.com/g/isar-users/c/qAnjahjjfsw
https://groups.google.com/g/isar-users/c/ZMD4XY4dKWQ
https://groups.google.com/g/isar-users/c/PSGU_AcdPZ8
https://groups.google.com/g/isar-users/c/Va0Ue-ISYeA

Changes since v1:
- Separate `dtb-files` recipe used instead of linux one
- Included older "[PATCH] Fix do_copy_boot_files error" into the
series ( https://groups.google.com/g/isar-users/c/Va0Ue-ISYeA )

Ilia Skochilov (1):
meta: Fix do_copy_boot_files error for different distros of same
machine

Uladzimir Bely (2):
testsuite: Build also debug images for some targets
meta: Move DTB deployment to a separate dtb-files recipe

RECIPE-API-CHANGELOG.md | 8 ++++
meta/classes/image.bbclass | 16 +++-----
meta/conf/bitbake.conf | 2 +-
meta/recipes-kernel/dtb-files/dtb-files.bb | 45 ++++++++++++++++++++++
testsuite/citest.py | 3 ++
5 files changed, 62 insertions(+), 12 deletions(-)
create mode 100644 meta/recipes-kernel/dtb-files/dtb-files.bb

--
2.44.2

Uladzimir Bely

unread,
Jul 12, 2024, 1:43:37 AMJul 12
to isar-...@googlegroups.com
Activate building "-debug" images for the targets using DTB_FILES.
This helps to detect potential "multiple execution" conflicts when
different images for the same machine/distro are built in parallel.

Signed-off-by: Uladzimir Bely <ub...@ilbers.de>
---
testsuite/citest.py | 3 +++
1 file changed, 3 insertions(+)

diff --git a/testsuite/citest.py b/testsuite/citest.py
index 8dd907d0..39e06bbd 100755
--- a/testsuite/citest.py
+++ b/testsuite/citest.py
@@ -192,7 +192,9 @@ class NoCrossTest(CIBaseTest):
'mc:qemuamd64-bullseye:isar-initramfs',
'mc:qemumipsel-bullseye:isar-image-base',
'mc:imx6-sabrelite-bullseye:isar-image-base',
+ 'mc:imx6-sabrelite-bullseye:isar-image-debug',
'mc:phyboard-mira-bullseye:isar-image-base',
+ 'mc:phyboard-mira-bullseye:isar-image-debug',
'mc:hikey-bullseye:isar-image-base',
'mc:virtualbox-bullseye:isar-image-base',
'mc:virtualbox-bookworm:isar-image-base',
@@ -252,6 +254,7 @@ class NoCrossTest(CIBaseTest):
'mc:qemuriscv64-sid:isar-image-base',
'mc:sifive-fu540-sid:isar-image-base',
'mc:starfive-visionfive2-sid:isar-image-base',
+ 'mc:starfive-visionfive2-sid:isar-image-debug',
]

self.init()
--
2.44.2

Uladzimir Bely

unread,
Jul 12, 2024, 1:43:37 AMJul 12
to isar-...@googlegroups.com
From: Ilia Skochilov <iskoc...@ilbers.de>

When building different distros with the same machine (e.g.,
phyboard-mira-bullseye and phyboard-mira-bookworm) it happens that
some files with the same name (e.g, DTB files) are deployed
to the same location and this causes build error.

Use DISTRO-dependent deploy directory.

Signed-off-by: Ilia Skochilov <iskoc...@ilbers.de>
Signed-off-by: Uladzimir Bely <ub...@ilbers.de>
---
RECIPE-API-CHANGELOG.md | 8 ++++++++
meta/conf/bitbake.conf | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index 12ea93ec..15337a63 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -629,3 +629,11 @@ into kernel kbuild package.
Only the "host" specific package is built automatically at cross builds.

* Support emulated module build with cross-compiled kernel for linux-module
+
+### Change DEPLOY_DIR_IMAGE
+Change DEPLOY_DIR_IMAGE from ${DEPLOY_DIR}/images/${MACHINE} to
+${DEPLOY_DIR}/images/${MACHINE}-${DISTRO}. When building different distros
+with the same machine the following error occurs:
+do_copy_boot_files: The recipe isar-image-base is trying to install files
+into a shared area when those files already exists. It happens when some
+files have the same names (e.g., dtb files) for different distros.
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 4cfa8b10..1087ca0f 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -56,7 +56,7 @@ WORKDIR = "${TMPDIR}/work/${DISTRO}-${DISTRO_ARCH}/${PN}/${PV}-${PR}"
GIT_DL_LINK_DIR = "${TMPDIR}/work/${DISTRO}-${DISTRO_ARCH}"
DEPLOY_DIR_BOOTSTRAP = "${DEPLOY_DIR}/bootstrap"
DEPLOY_DIR_SDKCHROOT = "${DEPLOY_DIR}/sdkchroot"
-DEPLOY_DIR_IMAGE = "${DEPLOY_DIR}/images/${MACHINE}"
+DEPLOY_DIR_IMAGE = "${DEPLOY_DIR}/images/${MACHINE}-${DISTRO}"
DL_DIR ?= "${TOPDIR}/downloads"
SSTATE_DIR ?= "${TOPDIR}/sstate-cache"
SSTATE_MANIFESTS = "${TMPDIR}/sstate-control/${DISTRO}-${DISTRO_ARCH}"
--
2.44.2

Uladzimir Bely

unread,
Jul 12, 2024, 1:43:38 AMJul 12
to isar-...@googlegroups.com
Task do_copy_boot_files deploys DTB files into the same location
for different images (e.g. -base or -debug). This causes build issue.

Introduce `dtb-files` recipe responcible for extraction DTBs from
linux-image package (distro or self-built) and their deployment.

Different images for the same machine now depend on this recipe and
don't cause parallell execution issue.

Signed-off-by: Uladzimir Bely <ub...@ilbers.de>
---
meta/classes/image.bbclass | 16 +++-----
meta/recipes-kernel/dtb-files/dtb-files.bb | 45 ++++++++++++++++++++++
2 files changed, 50 insertions(+), 11 deletions(-)
create mode 100644 meta/recipes-kernel/dtb-files/dtb-files.bb

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index c29d9e26..3644183e 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -328,6 +328,11 @@ INITRD_IMG = "${PP_DEPLOY}/${INITRD_DEPLOY_FILE}"
# only one dtb file supported, pick the first
DTB_IMG = "${PP_DEPLOY}/${@(d.getVar('DTB_FILES').split() or [''])[0]}"

+python() {
+ if d.getVar('DTB_FILES'):
+ d.appendVarFlag("do_copy_boot_files", "depends", "dtb-files-${MACHINE}:do_deploy")
+}
+
do_copy_boot_files[cleandirs] += "${DEPLOYDIR}"
do_copy_boot_files[sstate-inputdirs] = "${DEPLOYDIR}"
do_copy_boot_files[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
@@ -351,17 +356,6 @@ do_copy_boot_files() {
cp -f "$initrd" '${DEPLOYDIR}/${INITRD_DEPLOY_FILE}'
fi
fi
-
- for file in ${DTB_FILES}; do
- dtb="$(find '${IMAGE_ROOTFS}/usr/lib' -type f \
- -iwholename '*linux-image-*/'${file} | head -1)"
-
- if [ -z "$dtb" -o ! -e "$dtb" ]; then
- die "${file} not found"
- fi
-
- cp -f "$dtb" "${DEPLOYDIR}/"
- done
}
addtask copy_boot_files before do_rootfs_postprocess after do_rootfs_install

diff --git a/meta/recipes-kernel/dtb-files/dtb-files.bb b/meta/recipes-kernel/dtb-files/dtb-files.bb
new file mode 100644
index 00000000..49f0d584
--- /dev/null
+++ b/meta/recipes-kernel/dtb-files/dtb-files.bb
@@ -0,0 +1,45 @@
+# This software is a part of Isar.
+# Copyright (C) 2024 ilbers GmbH
+
+inherit dpkg-raw
+
+PN:append = "-${MACHINE}"
+
+KERNEL_IMAGE_PKG ??= "${@ ("linux-image-" + d.getVar("KERNEL_NAME")) if d.getVar("KERNEL_NAME") else ""}"
+
+DEPENDS = "${KERNEL_IMAGE_PKG}"
+DEBIAN_BUILD_DEPENDS = "${KERNEL_IMAGE_PKG}"
+
+do_prepare_build:prepend() {
+ mkdir -p ${D}/usr/lib/${PN}
+}
+
+do_prepare_build:append() {
+ cat <<EOF >> ${S}/debian/rules
+
+override_dh_auto_build:
+EOF
+ for dtb in ${DTB_FILES}; do
+ mkdir -p ${D}/usr/lib/${PN}/$(dirname ${dtb})
+ ppdir=${PP}/image/usr/lib/${PN}/$(dirname ${dtb})
+ cat <<EOF >> ${S}/debian/rules
+ find /usr/lib/linux-image* -path "*${dtb}" -print -exec cp {} ${ppdir} \;
+EOF
+ done
+}
+
+DTB_PACKAGE ??= "${PN}_${CHANGELOG_V}_${DISTRO_ARCH}.deb"
+
+do_deploy[dirs] = "${DEPLOY_DIR_IMAGE}"
+do_deploy[cleandirs] = "${WORKDIR}/deploy"
+do_deploy() {
+ dpkg --fsys-tarfile ${WORKDIR}/${DTB_PACKAGE} | \
+ tar --wildcards --extract --directory ${WORKDIR}/deploy ./usr/lib/${PN}
+ for dtb in ${DTB_FILES}; do
+ mkdir -p ${DEPLOY_DIR_IMAGE}/$(dirname ${dtb})
+ find ${WORKDIR}/deploy/usr/lib/${PN} -path "*${dtb}" -print \
+ -exec cp {} ${DEPLOY_DIR_IMAGE}/${dtb} \;
+ done
+}
+
+addtask deploy before do_deploy_deb after do_dpkg_build
--
2.44.2

Cedric Hombourger

unread,
Jul 12, 2024, 11:06:52 AMJul 12
to isar-users
since layers may have multiple kernels (e.g. rt and non-rt) for the same machine (and ${DISTRO}), you may need to append -${KERNEL_NAME}
I otherwise fear that some deployments will continue to fail

Florian Bezdeka

unread,
Jul 15, 2024, 2:45:23 AM (13 days ago) Jul 15
to Cedric Hombourger, isar-users, Ilia Skochilov, Uladzimir Bely
Correct. In addition I'm expecting a lot of trouble due to necessary
adjustments. I think nearly every CI deployment expects the output at
the current location.

Thanks for mentioning that in the API changelog. This is a very good
first step. Is there something else that we could do to help all users
find the necessary adjustment? Probably not...

Florian
Reply all
Reply to author
Forward
0 new messages