Skip to contentSkip to conversation

kernel_devicetree_vendor_dtb: Backport kernel-devicetree.bbclass

PATCH Superseded Ryan Eatmon 3 participants 6 messages May 18, 2023

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 kernel_devicetree_vendor_dtb: Backport kernel-devicetree.bbclass

There is a series of patches [1] [2] [3] that were submitted to oe-core master that have gone through some iterations. It has partially stalled in the upstreaming process but we need the effective changes to continue our LTS plans for u-boot 2023.

This backports the effective changes of that patch against the kirkstone version of the two classes, but renames them to make it obvious that we are overriding them. This should be a temporary change as we expect the changes to be backported to oe-core kirkstone once the stall is gone. This patch will be removed once it makes it into oe-core kirkstone.

[1] https://lists.openembedded.org/g/openembedded-core/message/180753
[2] https://lists.openembedded.org/g/openembedded-core/message/181190
[2] https://lists.openembedded.org/g/openembedded-core/message/181191

---
v2: - Fixed syntax of "0"
- Changed name of class to be yocto compliant (it did not like the - in kernel-vendor-dtb.bbclass).
- Fixed name of kernel_do_* functions to match the new name of the class.

 .../kernel_devicetree_vendor_dtb.bbclass      | 134 +++
 meta-ti-bsp/classes/kernel_vendor_dtb.bbclass | 837 ++++++++++++++++++
 2 files changed, 971 insertions(+)
 create mode 100644 meta-ti-bsp/classes/kernel_devicetree_vendor_dtb.bbclass
 create mode 100644 meta-ti-bsp/classes/kernel_vendor_dtb.bbclass
meta-ti-bsp/classes/kernel_devicetree_vendor_dtb.bbclass new file +134 -0
new file mode 100644
index 00000000..eaa73c4d
@@ -0,0 +1,134 @@
+# Support for device tree generation
+python () {
+    if not bb.data.inherits_class('nopackages', d):
+        d.appendVar("PACKAGES", " ${KERNEL_PACKAGE_NAME}-devicetree")
+        if d.getVar('KERNEL_DEVICETREE_BUNDLE') == '1':
+            d.appendVar("PACKAGES", " ${KERNEL_PACKAGE_NAME}-image-zimage-bundle")
+}
+
+# recursivly search for devicetree files
+def find_device_trees(d):
+    import glob
+    import os
+
+    file_paths = []
+    dest_dir = d.getVar('D')
+    full_dtb_dir = dest_dir + '/' + d.getVar('KERNEL_DTBDEST')
+
+    for file in glob.glob(full_dtb_dir + '/**/*.dtb*', recursive=True):
+        file_paths.append('/' + os.path.relpath(file, dest_dir))
+
+    return ' '.join(file_paths)
+
+FILES:${KERNEL_PACKAGE_NAME}-devicetree = "${@find_device_trees(d)}"
+FILES:${KERNEL_PACKAGE_NAME}-image-zimage-bundle = "/${KERNEL_IMAGEDEST}/zImage-*.dtb.bin"
+
+# Generate kernel+devicetree bundle
+KERNEL_DEVICETREE_BUNDLE ?= "0"
+
+# dtc flags passed via DTC_FLAGS env variable
+KERNEL_DTC_FLAGS ?= ""
+
+normalize_dtb () {
+	dtb="$1"
+	if echo $dtb | grep -q '/dts/'; then
+		bbwarn "$dtb contains the full path to the the dts file, but only the dtb name should be used."
+		dtb=`basename $dtb | sed 's,\.dts$,.dtb,g'`
+	fi
+	echo "$dtb"
+}
+
+get_real_dtb_path_in_kernel () {
+	dtb="$1"
+	dtb_path="${B}/arch/${ARCH}/boot/dts/$dtb"
+	if [ ! -e "$dtb_path" ]; then
+		dtb_path="${B}/arch/${ARCH}/boot/$dtb"
+	fi
+	echo "$dtb_path"
+}
+
+do_configure:append() {
+	if [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
+		if echo ${KERNEL_IMAGETYPE_FOR_MAKE} | grep -q 'zImage'; then
+			case "${ARCH}" in
+				"arm")
+				config="${B}/.config"
+				if ! grep -q 'CONFIG_ARM_APPENDED_DTB=y' $config; then
+					bbwarn 'CONFIG_ARM_APPENDED_DTB is NOT enabled in the kernel. Enabling it to allow the kernel to boot with the Device Tree appended!'
+					sed -i "/CONFIG_ARM_APPENDED_DTB[ =]/d" $config
+					echo "CONFIG_ARM_APPENDED_DTB=y" >> $config
+					echo "# CONFIG_ARM_ATAG_DTB_COMPAT is not set" >> $config
+				fi
+				;;
+				*)
+				bberror "KERNEL_DEVICETREE_BUNDLE is not supported for ${ARCH}. Currently it is only supported for 'ARM'."
+			esac
+		else
+			bberror 'The KERNEL_DEVICETREE_BUNDLE requires the KERNEL_IMAGETYPE to contain zImage.'
+		fi
+	fi
+}
+
+do_compile:append() {
+	if [ -n "${KERNEL_DTC_FLAGS}" ]; then
+		export DTC_FLAGS="${KERNEL_DTC_FLAGS}"
+	fi
+
+	for dtbf in ${KERNEL_DEVICETREE}; do
+		dtb=`normalize_dtb "$dtbf"`
+		oe_runmake $dtb CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS}
+	done
+}
+
+do_install:append() {
+	install -d ${D}/${KERNEL_DTBDEST}
+	for dtbf in ${KERNEL_DEVICETREE}; do
+		dtb=`normalize_dtb "$dtbf"`
+		dtb_path=`get_real_dtb_path_in_kernel "$dtb"`
+		if "${@'false' if oe.types.boolean(d.getVar('KERNEL_DTBVENDORED')) else 'true'}"; then
+			dtb_ext=${dtb##*.}
+			dtb_base_name=`basename $dtb .$dtb_ext`
+			dtb=$dtb_base_name.$dtb_ext
+		fi
+		install -Dm 0644 $dtb_path ${D}/${KERNEL_DTBDEST}/$dtb
+	done
+}
+
+do_deploy:append() {
+	for dtbf in ${KERNEL_DEVICETREE}; do
+		dtb=`normalize_dtb "$dtbf"`
+		dtb_ext=${dtb##*.}
+		dtb_base_name=`basename $dtb .$dtb_ext`
+		install -d $deployDir
+		if "${@'false' if oe.types.boolean(d.getVar('KERNEL_DTBVENDORED')) else 'true'}"; then
+			dtb=$dtb_base_name.$dtb_ext
+		fi
+		install -m 0644 ${D}/${KERNEL_DTBDEST}/$dtb $deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext
+		if [ "${KERNEL_IMAGETYPE_SYMLINK}" = "1" ] ; then
+			ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name.$dtb_ext
+		fi
+		if [ -n "${KERNEL_DTB_LINK_NAME}" ] ; then
+			ln -sf $dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext $deployDir/$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext
+		fi
+		for type in ${KERNEL_IMAGETYPE_FOR_MAKE}; do
+			if [ "$type" = "zImage" ] && [ "${KERNEL_DEVICETREE_BUNDLE}" = "1" ]; then
+				cat ${D}/${KERNEL_IMAGEDEST}/$type \
+					$deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \
+					> $deployDir/$type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
+				if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then
+					ln -sf $type-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} \
+						$deployDir/$type-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
+				fi
+				if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then
+					cat ${KERNEL_OUTPUT_DIR}/${type}.initramfs \
+						$deployDir/$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext \
+						>  $deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
+					if [ -n "${KERNEL_DTB_LINK_NAME}" ]; then
+						ln -sf ${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT} \
+							$deployDir/${type}-${INITRAMFS_NAME}-$dtb_base_name-${KERNEL_DTB_LINK_NAME}.$dtb_ext${KERNEL_DTB_BIN_EXT}
+					fi
+				fi
+			fi
+		done
+	done
+}
meta-ti-bsp/classes/kernel_vendor_dtb.bbclass new file +837 -0

837 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 2/2 linux-ti-staging: Use vendored kernel-devicetree.bbclass

Change over to using the kernel_devicetree_vendor_dtb.bbclass to have the DTBs installed into the same vendored subdirectory that is in the kernel.

---
v2: - Fixed syntax of "1"
- Fixed name of custom kernel class to match the other patch.

 meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +4 -1
index cdee548f..7c992ac5 100644
@@ -3,7 +3,7 @@ SUMMARY = "Linux kernel for TI devices"
 LICENSE = "GPL-2.0-only"
 LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46"
 
-inherit kernel
+inherit kernel_vendor_dtb
 
 require recipes-kernel/linux/setup-defconfig.inc
 require recipes-kernel/linux/kernel-rdepends.inc
@@ -18,6 +18,9 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}-6.1:"
 KERNEL_EXTRA_ARGS += "LOADADDR=${UBOOT_ENTRYPOINT} \
 		      ${EXTRA_DTC_ARGS}"
 
+KERNEL_DTBDEST = "${KERNEL_IMAGEDEST}/dtbs"
+KERNEL_DTBVENDORED = "1"
+
 S = "${WORKDIR}/git"
 
 BRANCH = "ti-linux-6.1.y"
Signature · 1 line
2.17.1
#2 lore raw

Re: [meta-ti][kirkstone][PATCH v2 2/2] linux-ti-staging: Use vendored kernel-devicetree.bbclass

Quoted 26 lines · Ryan Eatmon via lists.yoctoproject.org

Change over to using the kernel_devicetree_vendor_dtb.bbclass to have the DTBs installed into the same vendored subdirectory that is in the kernel.

---
v2: - Fixed syntax of "1"
- Fixed name of custom kernel class to match the other patch.

  meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +1 -1
index cdee548f..7c992ac5 100644
@@ -3,7 +3,7 @@ SUMMARY = "Linux kernel for TI devices"
  LICENSE = "GPL-2.0-only"
  LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46"
 
-inherit kernel
+inherit kernel_vendor_dtb
 
  require recipes-kernel/linux/setup-defconfig.inc
  require recipes-kernel/linux/kernel-rdepends.inc

meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}-6.1:" · line 23

Quoted 6 lines
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +3 -0
@@ -18,6 +18,9 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}-6.1:"
  KERNEL_EXTRA_ARGS += "LOADADDR=${UBOOT_ENTRYPOINT} \
  		      ${EXTRA_DTC_ARGS}"
 
+KERNEL_DTBDEST = "${KERNEL_IMAGEDEST}/dtbs"
+KERNEL_DTBVENDORED = "1"
+

We will want this for all kernels, not just ti-6.1, is there a more common place to put these defines so we get the same for -next and -mainline too?

Andrew

Quoted 14 lines
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +0 -1
  S = "${WORKDIR}/git"
 
  BRANCH = "ti-linux-6.1.y"
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#16558): https://lists.yoctoproject.org/g/meta-ti/message/16558
Mute This Topic: https://lists.yoctoproject.org/mt/98994752/3619733
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-ti/leave/6695306/3619733/2033773410/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw

Re: [meta-ti][kirkstone][PATCH v2 2/2] linux-ti-staging: Use vendored kernel-devicetree.bbclass

Quoted 26 lines · Andrew Davis via lists.yoctoproject.org
Quoted 25 lines · Ryan Eatmon via lists.yoctoproject.org

Change over to using the kernel_devicetree_vendor_dtb.bbclass to have the DTBs installed into the same vendored subdirectory that is in the kernel.

---
v2: - Fixed syntax of "1"
- Fixed name of custom kernel class to match the other patch.

 meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +1 -1
index cdee548f..7c992ac5 100644
@@ -3,7 +3,7 @@ SUMMARY = "Linux kernel for TI devices"
 LICENSE = "GPL-2.0-only"
 LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46"
-inherit kernel
+inherit kernel_vendor_dtb
 require recipes-kernel/linux/setup-defconfig.inc
 require recipes-kernel/linux/kernel-rdepends.inc
@@ -18,6 +18,9 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}-6.1:"
 KERNEL_EXTRA_ARGS += "LOADADDR=${UBOOT_ENTRYPOINT} \
Quoted 8 lines

meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}-6.1:" · line 23

Quoted 4 lines
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +3 -0
 		      ${EXTRA_DTC_ARGS}"
+KERNEL_DTBDEST = "${KERNEL_IMAGEDEST}/dtbs"
+KERNEL_DTBVENDORED = "1"
+

We will want this for all kernels, not just ti-6.1, is there a more common place to put these defines so we get the same for -next and -mainline too?

Only ti-kernel.inc is also included by -mainline and -next.

Signature · 1 line
Denys
#4 lore raw

Re: [meta-ti][kirkstone][PATCH v2 2/2] linux-ti-staging: Use vendored kernel-devicetree.bbclass

In reply to Ryan Eatmon
Quoted 26 lines · Ryan Eatmon via lists.yoctoproject.org

Change over to using the kernel_devicetree_vendor_dtb.bbclass to have the DTBs installed into the same vendored subdirectory that is in the kernel.

---
v2: - Fixed syntax of "1"
- Fixed name of custom kernel class to match the other patch.

  meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +1 -1
index cdee548f..7c992ac5 100644
@@ -3,7 +3,7 @@ SUMMARY = "Linux kernel for TI devices"
  LICENSE = "GPL-2.0-only"
  LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46"
 
-inherit kernel
+inherit kernel_vendor_dtb
 
  require recipes-kernel/linux/setup-defconfig.inc
  require recipes-kernel/linux/kernel-rdepends.inc

meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}-6.1:" · line 21

Quoted 4 lines
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +1 -0
@@ -18,6 +18,9 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}-6.1:"
  KERNEL_EXTRA_ARGS += "LOADADDR=${UBOOT_ENTRYPOINT} \
  		      ${EXTRA_DTC_ARGS}"
 
+KERNEL_DTBDEST = "${KERNEL_IMAGEDEST}/dtbs"

Do we want this to be "dtbs" or "dtb"? Debian uses "dtb" which is the far more common distro today and the one we plan to support in the near term. I know I used "dtbs" in the U-Boot side patch for this, but I'm having second thoughts and it's easy to switch it over in U-Boot..

Andrew

Quoted 16 lines
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +2 -1
+KERNEL_DTBVENDORED = "1"
+
  S = "${WORKDIR}/git"
 
  BRANCH = "ti-linux-6.1.y"
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#16558): https://lists.yoctoproject.org/g/meta-ti/message/16558
Mute This Topic: https://lists.yoctoproject.org/mt/98994752/3619733
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-ti/leave/6695306/3619733/2033773410/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#5 lore raw

Re: [meta-ti][kirkstone][PATCH v2 2/2] linux-ti-staging: Use vendored kernel-devicetree.bbclass

Quoted 25 lines · Andrew Davis
Quoted 24 lines · Ryan Eatmon via lists.yoctoproject.org

Change over to using the kernel_devicetree_vendor_dtb.bbclass to have the DTBs installed into the same vendored subdirectory that is in the kernel.

---
v2: - Fixed syntax of "1"
     - Fixed name of custom kernel class to match the other patch.

  meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb | 5 ++++-

  1 file changed, 4 insertions(+), 1 deletion(-)
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +0 -0
index cdee548f..7c992ac5 100644
@@ -3,7 +3,7 @@ SUMMARY = "Linux kernel for TI devices"

  LICENSE = "GPL-2.0-only"
  LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46"

meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +1 -1
-inherit kernel
+inherit kernel_vendor_dtb

  require recipes-kernel/linux/setup-defconfig.inc require recipes-kernel/linux/kernel-rdepends.inc

meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +0 -0
@@ -18,6 +18,9 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}-6.1:"
Quoted 8 lines
Quoted 3 lines
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +0 -0
   KERNEL_EXTRA_ARGS += "LOADADDR=${UBOOT_ENTRYPOINT} \

                ${EXTRA_DTC_ARGS}"
+KERNEL_DTBDEST = "${KERNEL_IMAGEDEST}/dtbs"

Do we want this to be "dtbs" or "dtb"? Debian uses "dtb" which is the far more common distro today and the one we plan to support in the near term. I know I used "dtbs" in the U-Boot side patch for this, but I'm having second thoughts and it's easy to switch it over in U-Boot..

If debian does dtb then I vote dtb. I'll submit a V3 with that change and putting the logic in ti-kernel.inc.

Quoted 17 lines

Andrew

Quoted 15 lines
meta-ti-bsp/recipes-kernel/linux/linux-ti-staging_6.1.bb +2 -0
+KERNEL_DTBVENDORED = "1"
+

  S = "${WORKDIR}/git"
  BRANCH = "ti-linux-6.1.y"

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#16558): https://lists.yoctoproject.org/g/meta-ti/message/16558
Mute This Topic: https://lists.yoctoproject.org/mt/98994752/3619733
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-ti/leave/6695306/3619733/2033773410/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
Ryan Eatmon                [email protected]
-----------------------------------------
Texas Instruments, Inc.  -  LCPD  -  MGTS